mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-30 16:19:03 +01:00
Correctly handle interactions with items on cooldown
This commit is contained in:
parent
945f6ef6e6
commit
e56f757b1c
2 changed files with 16 additions and 4 deletions
|
@ -369,7 +369,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -321,15 +510,58 @@
|
@@ -321,15 +510,59 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -383,6 +383,7 @@
|
||||||
BlockPos blockposition = hitResult.getBlockPos();
|
BlockPos blockposition = hitResult.getBlockPos();
|
||||||
BlockState iblockdata = world.getBlockState(blockposition);
|
BlockState iblockdata = world.getBlockState(blockposition);
|
||||||
+ boolean cancelledBlock = false;
|
+ boolean cancelledBlock = false;
|
||||||
|
+ boolean cancelledItem = false; // Paper - correctly handle items on cooldown
|
||||||
|
|
||||||
if (!iblockdata.getBlock().isEnabled(world.enabledFeatures())) {
|
if (!iblockdata.getBlock().isEnabled(world.enabledFeatures())) {
|
||||||
return InteractionResult.FAIL;
|
return InteractionResult.FAIL;
|
||||||
|
@ -392,10 +393,10 @@
|
||||||
+ }
|
+ }
|
||||||
|
|
||||||
+ if (player.getCooldowns().isOnCooldown(stack)) {
|
+ if (player.getCooldowns().isOnCooldown(stack)) {
|
||||||
+ cancelledBlock = true;
|
+ cancelledItem = true; // Paper - correctly handle items on cooldown
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, blockposition, hitResult.getDirection(), stack, cancelledBlock, hand, hitResult.getLocation());
|
+ PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, blockposition, hitResult.getDirection(), stack, cancelledBlock, cancelledItem, hand, hitResult.getLocation()); // Paper - correctly handle items on cooldown
|
||||||
+ this.firedInteract = true;
|
+ this.firedInteract = true;
|
||||||
+ this.interactResult = event.useItemInHand() == Event.Result.DENY;
|
+ this.interactResult = event.useItemInHand() == Event.Result.DENY;
|
||||||
+ this.interactPosition = blockposition.immutable();
|
+ this.interactPosition = blockposition.immutable();
|
||||||
|
@ -428,7 +429,7 @@
|
||||||
if (itileinventory != null) {
|
if (itileinventory != null) {
|
||||||
player.openMenu(itileinventory);
|
player.openMenu(itileinventory);
|
||||||
return InteractionResult.CONSUME;
|
return InteractionResult.CONSUME;
|
||||||
@@ -359,7 +591,7 @@
|
@@ -359,7 +592,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -555,6 +555,12 @@ public class CraftEventFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PlayerInteractEvent callPlayerInteractEvent(net.minecraft.world.entity.player.Player who, Action action, BlockPos position, Direction direction, ItemStack itemstack, boolean cancelledBlock, InteractionHand hand, Vec3 targetPos) {
|
public static PlayerInteractEvent callPlayerInteractEvent(net.minecraft.world.entity.player.Player who, Action action, BlockPos position, Direction direction, ItemStack itemstack, boolean cancelledBlock, InteractionHand hand, Vec3 targetPos) {
|
||||||
|
// Paper start - cancelledItem param
|
||||||
|
return CraftEventFactory.callPlayerInteractEvent(who, action, position, direction, itemstack, cancelledBlock, false, hand, targetPos);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PlayerInteractEvent callPlayerInteractEvent(net.minecraft.world.entity.player.Player who, Action action, BlockPos position, Direction direction, ItemStack itemstack, boolean cancelledBlock, boolean cancelledItem, InteractionHand hand, Vec3 targetPos) {
|
||||||
|
// Paper end - cancelledItem param
|
||||||
Player player = (who == null) ? null : (Player) who.getBukkitEntity();
|
Player player = (who == null) ? null : (Player) who.getBukkitEntity();
|
||||||
CraftItemStack itemInHand = CraftItemStack.asCraftMirror(itemstack);
|
CraftItemStack itemInHand = CraftItemStack.asCraftMirror(itemstack);
|
||||||
|
|
||||||
|
@ -589,6 +595,11 @@ public class CraftEventFactory {
|
||||||
if (cancelledBlock) {
|
if (cancelledBlock) {
|
||||||
event.setUseInteractedBlock(Event.Result.DENY);
|
event.setUseInteractedBlock(Event.Result.DENY);
|
||||||
}
|
}
|
||||||
|
// Paper start
|
||||||
|
if (cancelledItem) {
|
||||||
|
event.setUseItemInHand(Result.DENY);
|
||||||
|
}
|
||||||
|
// Paper end
|
||||||
craftServer.getPluginManager().callEvent(event);
|
craftServer.getPluginManager().callEvent(event);
|
||||||
|
|
||||||
return event;
|
return event;
|
||||||
|
|
Loading…
Reference in a new issue