mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-18 11:29:15 +00:00
Several bugfixes for PlayerInteractEvent (#2943)
* Don't change Result if setCanceled(false) called * Fix RightClickEmpty firing even when targeting a block or entity * Add a left click empty event * Move hook point for EntityInteractSpecific to the right place * Fix LeftClickBlock not firing clientside in creative, and clarify docs about creative
This commit is contained in:
1 parent
92914f82ae
commit
35cd9fe212
4 files changed
+66
-15
No files matched your search
@@ -987,6 +987,11 @@ public class ForgeHooks
|
||||
MinecraftForge.EVENT_BUS.post(new PlayerInteractEvent.RightClickEmpty(player, hand));
|
||||
}
|
||||
|
||||
public static void onEmptyLeftClick(EntityPlayer player, ItemStack stack)
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.post(new PlayerInteractEvent.LeftClickEmpty(player, stack));
|
||||
}
|
||||
|
||||
private static ThreadLocal<Deque<LootTableContext>> lootContext = new ThreadLocal<Deque<LootTableContext>>();
|
||||
private static LootTableContext getLootTableContext()
|
||||
{
|
||||
|
||||
@@ -182,8 +182,11 @@ public class PlayerInteractEvent extends PlayerEvent
|
||||
public void setCanceled(boolean canceled)
|
||||
{
|
||||
super.setCanceled(canceled);
|
||||
useBlock = DENY;
|
||||
useItem = DENY;
|
||||
if (canceled)
|
||||
{
|
||||
useBlock = DENY;
|
||||
useItem = DENY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -220,8 +223,12 @@ public class PlayerInteractEvent extends PlayerEvent
|
||||
* This event controls which of {@link net.minecraft.block.Block#onBlockClicked} and/or the item harvesting methods will be called
|
||||
* Canceling the event will cause none of the above noted methods to be called.
|
||||
* There are various results to this event, see the getters below.
|
||||
*
|
||||
* Note that if the event is canceled and the player holds down left mouse, the event will continue to fire.
|
||||
* This is due to how vanilla calls the left click handler methods.
|
||||
*
|
||||
* Also note that creative mode directly breaks the block without running any other logic.
|
||||
* Therefore, in creative mode, {@link #setUseBlock} and {@link #setUseItem} have no effect.
|
||||
*/
|
||||
@Cancelable
|
||||
public static class LeftClickBlock extends PlayerInteractEvent
|
||||
@@ -245,7 +252,7 @@ public class PlayerInteractEvent extends PlayerEvent
|
||||
}
|
||||
|
||||
/**
|
||||
* @return If {@link net.minecraft.block.Block#onBlockClicked} should be called
|
||||
* @return If {@link net.minecraft.block.Block#onBlockClicked} should be called. Changing this has no effect in creative mode
|
||||
*/
|
||||
public Result getUseBlock()
|
||||
{
|
||||
@@ -253,7 +260,7 @@ public class PlayerInteractEvent extends PlayerEvent
|
||||
}
|
||||
|
||||
/**
|
||||
* @return If the block should be attempted to be mined with the current item
|
||||
* @return If the block should be attempted to be mined with the current item. Changing this has no effect in creative mode
|
||||
*/
|
||||
public Result getUseItem()
|
||||
{
|
||||
@@ -274,8 +281,24 @@ public class PlayerInteractEvent extends PlayerEvent
|
||||
public void setCanceled(boolean canceled)
|
||||
{
|
||||
super.setCanceled(canceled);
|
||||
useBlock = DENY;
|
||||
useItem = DENY;
|
||||
if (canceled)
|
||||
{
|
||||
useBlock = DENY;
|
||||
useItem = DENY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This event is fired on the client side when the player left clicks empty space with any ItemStack.
|
||||
* The server is not aware of when the client left clicks empty space, you will need to tell the server yourself.
|
||||
* This event cannot be canceled.
|
||||
*/
|
||||
public static class LeftClickEmpty extends PlayerInteractEvent
|
||||
{
|
||||
public LeftClickEmpty(EntityPlayer player, ItemStack stack)
|
||||
{
|
||||
super(player, EnumHand.MAIN_HAND, stack, new BlockPos(player), null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user