13
0
geforkt von Mirrors/Paper

Dont resend blocks on interactions

In general, the client now has an acknowledgment system which will prevent block changes made by the client to be reverted correctly.

It should be noted that this system does not yet support block entities, so those still need to resynced when needed.
Dieser Commit ist enthalten in:
Owen1212055 2023-06-27 21:09:11 -04:00
Ursprung ddbfcd4403
Commit 893616e851
3 geänderte Dateien mit 81 neuen und 71 gelöschten Zeilen

Datei anzeigen

@ -135,20 +135,20 @@
+ // Update any tile entity data for this block + // Update any tile entity data for this block
+ capturedBlockEntity = true; // Paper - Send block entities after destroy prediction + capturedBlockEntity = true; // Paper - Send block entities after destroy prediction
+ // CraftBukkit end + // CraftBukkit end
return; + return;
} + }
+
+ // CraftBukkit start + // CraftBukkit start
+ PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(this.player, Action.LEFT_CLICK_BLOCK, pos, direction, this.player.getInventory().getSelected(), InteractionHand.MAIN_HAND); + PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(this.player, Action.LEFT_CLICK_BLOCK, pos, direction, this.player.getInventory().getSelected(), InteractionHand.MAIN_HAND);
+ if (event.isCancelled()) { + if (event.isCancelled()) {
+ // Let the client know the block still exists + // Let the client know the block still exists
+ this.player.connection.send(new ClientboundBlockUpdatePacket(this.level, pos)); + // this.player.connection.send(new ClientboundBlockUpdatePacket(this.level, pos)); // Paper - Don't resync blocks
+ // Update any tile entity data for this block + // Update any tile entity data for this block
+ capturedBlockEntity = true; // Paper - Send block entities after destroy prediction + capturedBlockEntity = true; // Paper - Send block entities after destroy prediction
+ return; return;
+ } }
+ // CraftBukkit end + // CraftBukkit end
+
if (this.isCreative()) { if (this.isCreative()) {
this.destroyAndAck(pos, sequence, "creative destroy"); this.destroyAndAck(pos, sequence, "creative destroy");
return; return;
@ -157,7 +157,7 @@
+ // Spigot start - handle debug stick left click for non-creative + // Spigot start - handle debug stick left click for non-creative
+ if (this.player.getMainHandItem().is(net.minecraft.world.item.Items.DEBUG_STICK) + if (this.player.getMainHandItem().is(net.minecraft.world.item.Items.DEBUG_STICK)
+ && ((net.minecraft.world.item.DebugStickItem) net.minecraft.world.item.Items.DEBUG_STICK).handleInteraction(this.player, this.level.getBlockState(pos), this.level, pos, false, this.player.getMainHandItem())) { + && ((net.minecraft.world.item.DebugStickItem) net.minecraft.world.item.Items.DEBUG_STICK).handleInteraction(this.player, this.level.getBlockState(pos), this.level, pos, false, this.player.getMainHandItem())) {
+ this.player.connection.send(new ClientboundBlockUpdatePacket(this.level, pos)); + // this.player.connection.send(new ClientboundBlockUpdatePacket(this.level, pos)); // Paper - Don't resync block
+ return; + return;
+ } + }
+ // Spigot end + // Spigot end
@ -165,7 +165,7 @@
if (this.player.blockActionRestricted(this.level, pos, this.gameModeForPlayer)) { if (this.player.blockActionRestricted(this.level, pos, this.gameModeForPlayer)) {
this.player.connection.send(new ClientboundBlockUpdatePacket(pos, this.level.getBlockState(pos))); this.player.connection.send(new ClientboundBlockUpdatePacket(pos, this.level.getBlockState(pos)));
this.debugLogging(pos, false, sequence, "block action restricted"); this.debugLogging(pos, false, sequence, "block action restricted");
@@ -166,7 +232,19 @@ @@ -166,7 +232,21 @@
float f = 1.0F; float f = 1.0F;
iblockdata = this.level.getBlockState(pos); iblockdata = this.level.getBlockState(pos);
@ -173,27 +173,29 @@
+ // CraftBukkit start - Swings at air do *NOT* exist. + // CraftBukkit start - Swings at air do *NOT* exist.
+ if (event.useInteractedBlock() == Event.Result.DENY) { + if (event.useInteractedBlock() == Event.Result.DENY) {
+ // If we denied a door from opening, we need to send a correcting update to the client, as it already opened the door. + // If we denied a door from opening, we need to send a correcting update to the client, as it already opened the door.
+ BlockState data = this.level.getBlockState(pos); + // Paper start - Don't resync blocks
+ if (data.getBlock() instanceof DoorBlock) { + //BlockState data = this.level.getBlockState(pos);
+ // For some reason *BOTH* the bottom/top part have to be marked updated. + //if (data.getBlock() instanceof DoorBlock) {
+ boolean bottom = data.getValue(DoorBlock.HALF) == DoubleBlockHalf.LOWER; + // // For some reason *BOTH* the bottom/top part have to be marked updated.
+ this.player.connection.send(new ClientboundBlockUpdatePacket(this.level, pos)); + // boolean bottom = data.getValue(DoorBlock.HALF) == DoubleBlockHalf.LOWER;
+ this.player.connection.send(new ClientboundBlockUpdatePacket(this.level, bottom ? pos.above() : pos.below())); + // this.player.connection.send(new ClientboundBlockUpdatePacket(this.level, pos));
+ } else if (data.getBlock() instanceof TrapDoorBlock) { + // this.player.connection.send(new ClientboundBlockUpdatePacket(this.level, bottom ? pos.above() : pos.below()));
+ this.player.connection.send(new ClientboundBlockUpdatePacket(this.level, pos)); + //} else if (data.getBlock() instanceof TrapDoorBlock) {
+ } + // this.player.connection.send(new ClientboundBlockUpdatePacket(this.level, pos));
+ //}
+ // Paper end - Don't resync blocks
+ } else if (!iblockdata.isAir()) { + } else if (!iblockdata.isAir()) {
EnchantmentHelper.onHitBlock(this.level, this.player.getMainHandItem(), this.player, this.player, EquipmentSlot.MAINHAND, Vec3.atCenterOf(pos), iblockdata, (item) -> { EnchantmentHelper.onHitBlock(this.level, this.player.getMainHandItem(), this.player, this.player, EquipmentSlot.MAINHAND, Vec3.atCenterOf(pos), iblockdata, (item) -> {
this.player.onEquippedItemBroken(item, EquipmentSlot.MAINHAND); this.player.onEquippedItemBroken(item, EquipmentSlot.MAINHAND);
}); });
@@ -174,6 +252,26 @@ @@ -174,6 +254,26 @@
f = iblockdata.getDestroyProgress(this.player, this.player.level(), pos); f = iblockdata.getDestroyProgress(this.player, this.player.level(), pos);
} }
+ if (event.useItemInHand() == Event.Result.DENY) { + if (event.useItemInHand() == Event.Result.DENY) {
+ // If we 'insta destroyed' then the client needs to be informed. + // If we 'insta destroyed' then the client needs to be informed.
+ if (f > 1.0f) { + if (f > 1.0f) {
+ this.player.connection.send(new ClientboundBlockUpdatePacket(this.level, pos)); + // this.player.connection.send(new ClientboundBlockUpdatePacket(this.level, pos)); // Paper - Don't resync blocks
+ } + }
+ return; + return;
+ } + }
@ -201,7 +203,7 @@
+ +
+ if (blockEvent.isCancelled()) { + if (blockEvent.isCancelled()) {
+ // Let the client know the block still exists + // Let the client know the block still exists
+ this.player.connection.send(new ClientboundBlockUpdatePacket(this.level, pos)); + // this.player.connection.send(new ClientboundBlockUpdatePacket(this.level, pos)); // Paper - Don't resync block
+ return; + return;
+ } + }
+ +
@ -213,7 +215,7 @@
if (!iblockdata.isAir() && f >= 1.0F) { if (!iblockdata.isAir() && f >= 1.0F) {
this.destroyAndAck(pos, sequence, "insta mine"); this.destroyAndAck(pos, sequence, "insta mine");
} else { } else {
@@ -217,14 +315,18 @@ @@ -217,14 +317,18 @@
this.debugLogging(pos, true, sequence, "stopped destroying"); this.debugLogging(pos, true, sequence, "stopped destroying");
} else if (action == ServerboundPlayerActionPacket.Action.ABORT_DESTROY_BLOCK) { } else if (action == ServerboundPlayerActionPacket.Action.ABORT_DESTROY_BLOCK) {
this.isDestroyingBlock = false; this.isDestroyingBlock = false;
@ -236,7 +238,7 @@
} }
} }
@@ -242,19 +344,80 @@ @@ -242,19 +346,82 @@
public boolean destroyBlock(BlockPos pos) { public boolean destroyBlock(BlockPos pos) {
BlockState iblockdata = this.level.getBlockState(pos); BlockState iblockdata = this.level.getBlockState(pos);
@ -251,7 +253,7 @@
+ +
+ // Tell client the block is gone immediately then process events + // Tell client the block is gone immediately then process events
+ // Don't tell the client if its a creative sword break because its not broken! + // Don't tell the client if its a creative sword break because its not broken!
+ if (this.level.getBlockEntity(pos) == null && !isSwordNoBreak) { + if (false && this.level.getBlockEntity(pos) == null && !isSwordNoBreak) { // Paper - Don't resync block
+ ClientboundBlockUpdatePacket packet = new ClientboundBlockUpdatePacket(pos, Blocks.AIR.defaultBlockState()); + ClientboundBlockUpdatePacket packet = new ClientboundBlockUpdatePacket(pos, Blocks.AIR.defaultBlockState());
+ this.player.connection.send(packet); + this.player.connection.send(packet);
+ } + }
@ -277,13 +279,15 @@
+ if (isSwordNoBreak) { + if (isSwordNoBreak) {
+ return false; + return false;
+ } + }
+ // Paper start - Don't resync blocks
+ // Let the client know the block still exists + // Let the client know the block still exists
+ this.player.connection.send(new ClientboundBlockUpdatePacket(this.level, pos)); + //this.player.connection.send(new ClientboundBlockUpdatePacket(this.level, pos));
+ +
+ // Brute force all possible updates + // Brute force all possible updates
+ for (Direction dir : Direction.values()) { + //for (Direction dir : Direction.values()) {
+ this.player.connection.send(new ClientboundBlockUpdatePacket(this.level, pos.relative(dir))); + // this.player.connection.send(new ClientboundBlockUpdatePacket(this.level, pos.relative(dir)));
+ } + //}
+ // Paper end - Don't resync blocks
+ +
+ // Update any tile entity data for this block + // Update any tile entity data for this block
+ if (!captureSentBlockEntities) { // Paper - Send block entities after destroy prediction + if (!captureSentBlockEntities) { // Paper - Send block entities after destroy prediction
@ -319,7 +323,7 @@
BlockState iblockdata1 = block.playerWillDestroy(this.level, pos, iblockdata, this.player); BlockState iblockdata1 = block.playerWillDestroy(this.level, pos, iblockdata, this.player);
boolean flag = this.level.removeBlock(pos, false); boolean flag = this.level.removeBlock(pos, false);
@@ -262,20 +425,46 @@ @@ -262,20 +429,46 @@
block.destroy(this.level, pos, iblockdata1); block.destroy(this.level, pos, iblockdata1);
} }
@ -370,7 +374,7 @@
} }
} }
} }
@@ -321,15 +510,59 @@ @@ -321,15 +514,61 @@
} }
} }
@ -407,16 +411,18 @@
+ if (event.useInteractedBlock() == Event.Result.DENY) { + if (event.useInteractedBlock() == Event.Result.DENY) {
+ // If we denied a door from opening, we need to send a correcting update to the client, as it already opened the door. + // If we denied a door from opening, we need to send a correcting update to the client, as it already opened the door.
+ if (iblockdata.getBlock() instanceof DoorBlock) { + if (iblockdata.getBlock() instanceof DoorBlock) {
+ boolean bottom = iblockdata.getValue(DoorBlock.HALF) == DoubleBlockHalf.LOWER; + // Paper start - Don't resync blocks
+ player.connection.send(new ClientboundBlockUpdatePacket(world, bottom ? blockposition.above() : blockposition.below())); + // boolean bottom = iblockdata.getValue(DoorBlock.HALF) == DoubleBlockHalf.LOWER;
+ // player.connection.send(new ClientboundBlockUpdatePacket(world, bottom ? blockposition.above() : blockposition.below()));
+ // Paper end - Don't resync blocks
+ } else if (iblockdata.getBlock() instanceof CakeBlock) { + } else if (iblockdata.getBlock() instanceof CakeBlock) {
+ player.getBukkitEntity().sendHealthUpdate(); // SPIGOT-1341 - reset health for cake + player.getBukkitEntity().sendHealthUpdate(); // SPIGOT-1341 - reset health for cake
+ } else if (this.interactItemStack.getItem() instanceof DoubleHighBlockItem) { + } else if (this.interactItemStack.getItem() instanceof DoubleHighBlockItem) {
+ // send a correcting update to the client, as it already placed the upper half of the bisected item + // send a correcting update to the client, as it already placed the upper half of the bisected item
+ player.connection.send(new ClientboundBlockUpdatePacket(world, blockposition.relative(hitResult.getDirection()).above())); + //player.connection.send(new ClientboundBlockUpdatePacket(world, blockposition.relative(hitResult.getDirection()).above())); // Paper - Don't resync blocks
+ +
+ // send a correcting update to the client for the block above as well, this because of replaceable blocks (such as grass, sea grass etc) + // send a correcting update to the client for the block above as well, this because of replaceable blocks (such as grass, sea grass etc)
+ player.connection.send(new ClientboundBlockUpdatePacket(world, blockposition.above())); + //player.connection.send(new ClientboundBlockUpdatePacket(world, blockposition.above())); // Paper - Don't resync blocks
+ // Paper start - extend Player Interact cancellation // TODO: consider merging this into the extracted method + // Paper start - extend Player Interact cancellation // TODO: consider merging this into the extracted method
+ } else if (iblockdata.is(Blocks.JIGSAW) || iblockdata.is(Blocks.STRUCTURE_BLOCK) || iblockdata.getBlock() instanceof net.minecraft.world.level.block.CommandBlock) { + } else if (iblockdata.is(Blocks.JIGSAW) || iblockdata.is(Blocks.STRUCTURE_BLOCK) || iblockdata.getBlock() instanceof net.minecraft.world.level.block.CommandBlock) {
+ player.connection.send(new net.minecraft.network.protocol.game.ClientboundContainerClosePacket(this.player.containerMenu.containerId)); + player.connection.send(new net.minecraft.network.protocol.game.ClientboundContainerClosePacket(this.player.containerMenu.containerId));
@ -430,7 +436,7 @@
if (itileinventory != null) { if (itileinventory != null) {
player.openMenu(itileinventory); player.openMenu(itileinventory);
return InteractionResult.CONSUME; return InteractionResult.CONSUME;
@@ -359,7 +592,7 @@ @@ -359,7 +598,7 @@
} }
} }

Datei anzeigen

@ -37,7 +37,7 @@
+ PlayerBucketFillEvent event = CraftEventFactory.callPlayerBucketFillEvent((ServerLevel) world, user, blockposition, blockposition, movingobjectpositionblock.getDirection(), itemstack, dummyFluid.getItem(), hand); + PlayerBucketFillEvent event = CraftEventFactory.callPlayerBucketFillEvent((ServerLevel) world, user, blockposition, blockposition, movingobjectpositionblock.getDirection(), itemstack, dummyFluid.getItem(), hand);
+ if (event.isCancelled()) { + if (event.isCancelled()) {
+ ((ServerPlayer) user).connection.send(new ClientboundBlockUpdatePacket(world, blockposition)); // SPIGOT-5163 (see PlayerInteractManager) + // ((ServerPlayer) user).connection.send(new ClientboundBlockUpdatePacket(world, blockposition)); // SPIGOT-5163 (see PlayerInteractManager) // Paper - Don't resend blocks
+ ((ServerPlayer) user).getBukkitEntity().updateInventory(); // SPIGOT-4541 + ((ServerPlayer) user).getBukkitEntity().updateInventory(); // SPIGOT-4541
+ return InteractionResult.FAIL; + return InteractionResult.FAIL;
+ } + }
@ -117,7 +117,7 @@
+ if (flag2 && entityhuman != null) { + if (flag2 && entityhuman != null) {
+ PlayerBucketEmptyEvent event = CraftEventFactory.callPlayerBucketEmptyEvent((ServerLevel) world, entityhuman, blockposition, clicked, enumdirection, itemstack, enumhand); + PlayerBucketEmptyEvent event = CraftEventFactory.callPlayerBucketEmptyEvent((ServerLevel) world, entityhuman, blockposition, clicked, enumdirection, itemstack, enumhand);
+ if (event.isCancelled()) { + if (event.isCancelled()) {
+ ((ServerPlayer) entityhuman).connection.send(new ClientboundBlockUpdatePacket(world, blockposition)); // SPIGOT-4238: needed when looking through entity + // ((ServerPlayer) entityhuman).connection.send(new ClientboundBlockUpdatePacket(world, blockposition)); // SPIGOT-4238: needed when looking through entity // Paper - Don't resend blocks
+ ((ServerPlayer) entityhuman).getBukkitEntity().updateInventory(); // SPIGOT-4541 + ((ServerPlayer) entityhuman).getBukkitEntity().updateInventory(); // SPIGOT-4541
+ return false; + return false;
+ } + }

Datei anzeigen

@ -152,7 +152,7 @@
}); });
} }
} }
@@ -370,32 +418,196 @@ @@ -370,32 +418,198 @@
} }
public InteractionResult useOn(UseOnContext context) { public InteractionResult useOn(UseOnContext context) {
@ -169,7 +169,7 @@
+ DataComponentPatch oldData = this.components.asPatch(); + DataComponentPatch oldData = this.components.asPatch();
+ int oldCount = this.getCount(); + int oldCount = this.getCount();
+ ServerLevel world = (ServerLevel) context.getLevel(); + ServerLevel world = (ServerLevel) context.getLevel();
+
+ if (!(item instanceof BucketItem/* || item instanceof SolidBucketItem*/)) { // if not bucket // Paper - Fix cancelled powdered snow bucket placement + if (!(item instanceof BucketItem/* || item instanceof SolidBucketItem*/)) { // if not bucket // Paper - Fix cancelled powdered snow bucket placement
+ world.captureBlockStates = true; + world.captureBlockStates = true;
+ // special case bonemeal + // special case bonemeal
@ -200,7 +200,7 @@
+ structureEvent = new StructureGrowEvent(location, treeType, isBonemeal, (Player) entityhuman.getBukkitEntity(), (List< BlockState>) (List<? extends BlockState>) blocks); + structureEvent = new StructureGrowEvent(location, treeType, isBonemeal, (Player) entityhuman.getBukkitEntity(), (List< BlockState>) (List<? extends BlockState>) blocks);
+ org.bukkit.Bukkit.getPluginManager().callEvent(structureEvent); + org.bukkit.Bukkit.getPluginManager().callEvent(structureEvent);
+ } + }
+
+ BlockFertilizeEvent fertilizeEvent = new BlockFertilizeEvent(CraftBlock.at(world, blockposition), (Player) entityhuman.getBukkitEntity(), (List< BlockState>) (List<? extends BlockState>) blocks); + BlockFertilizeEvent fertilizeEvent = new BlockFertilizeEvent(CraftBlock.at(world, blockposition), (Player) entityhuman.getBukkitEntity(), (List< BlockState>) (List<? extends BlockState>) blocks);
+ fertilizeEvent.setCancelled(structureEvent != null && structureEvent.isCancelled()); + fertilizeEvent.setCancelled(structureEvent != null && structureEvent.isCancelled());
+ org.bukkit.Bukkit.getPluginManager().callEvent(fertilizeEvent); + org.bukkit.Bukkit.getPluginManager().callEvent(fertilizeEvent);
@ -252,10 +252,12 @@
+ world.preventPoiUpdated = false; + world.preventPoiUpdated = false;
+ +
+ // Brute force all possible updates + // Brute force all possible updates
+ BlockPos placedPos = ((CraftBlock) placeEvent.getBlock()).getPosition(); + // Paper start - Don't resync blocks
+ for (Direction dir : Direction.values()) { + // BlockPos placedPos = ((CraftBlock) placeEvent.getBlock()).getPosition();
+ ((ServerPlayer) entityhuman).connection.send(new ClientboundBlockUpdatePacket(world, placedPos.relative(dir))); + // for (Direction dir : Direction.values()) {
+ } + // ((ServerPlayer) entityhuman).connection.send(new ClientboundBlockUpdatePacket(world, placedPos.relative(dir)));
+ // }
+ // Paper end - Don't resync blocks
+ SignItem.openSign = null; // SPIGOT-6758 - Reset on early return + SignItem.openSign = null; // SPIGOT-6758 - Reset on early return
+ } else { + } else {
+ // Change the stack to its new contents if it hasn't been tampered with. + // Change the stack to its new contents if it hasn't been tampered with.
@ -354,7 +356,7 @@
ItemStack itemstack = this.copy(); ItemStack itemstack = this.copy();
boolean flag = this.getUseDuration(user) <= 0; boolean flag = this.getUseDuration(user) <= 0;
InteractionResult enuminteractionresult = this.getItem().use(world, user, hand); InteractionResult enuminteractionresult = this.getItem().use(world, user, hand);
@@ -490,8 +702,37 @@ @@ -490,27 +704,66 @@
return this.isDamageableItem() && this.getDamageValue() >= this.getMaxDamage() - 1; return this.isDamageableItem() && this.getDamageValue() >= this.getMaxDamage() - 1;
} }
@ -372,7 +374,7 @@
+ if (player instanceof final ServerPlayer serverPlayer) { // Paper - Add EntityDamageItemEvent + if (player instanceof final ServerPlayer serverPlayer) { // Paper - Add EntityDamageItemEvent
+ PlayerItemDamageEvent event = new PlayerItemDamageEvent(serverPlayer.getBukkitEntity(), CraftItemStack.asCraftMirror(this), j, originalDamage); // Paper - Add EntityDamageItemEvent + PlayerItemDamageEvent event = new PlayerItemDamageEvent(serverPlayer.getBukkitEntity(), CraftItemStack.asCraftMirror(this), j, originalDamage); // Paper - Add EntityDamageItemEvent
+ event.getPlayer().getServer().getPluginManager().callEvent(event); + event.getPlayer().getServer().getPluginManager().callEvent(event);
+
+ if (j != event.getDamage() || event.isCancelled()) { + if (j != event.getDamage() || event.isCancelled()) {
+ event.getPlayer().updateInventory(); + event.getPlayer().updateInventory();
+ } + }
@ -391,10 +393,10 @@
+ // Paper end - Add EntityDamageItemEvent + // Paper end - Add EntityDamageItemEvent
+ } + }
+ // CraftBukkit end + // CraftBukkit end
+
if (j != 0) { if (j != 0) {
this.applyDamage(this.getDamageValue() + j, player, breakCallback); this.applyDamage(this.getDamageValue() + j, player, breakCallback);
@@ -499,18 +740,28 @@ }
} }
@ -428,7 +430,7 @@
this.shrink(1); this.shrink(1);
breakCallback.accept(item); breakCallback.accept(item);
@@ -518,7 +769,7 @@ @@ -518,7 +771,7 @@
} }
@ -437,7 +439,7 @@
if (player instanceof ServerPlayer entityplayer) { if (player instanceof ServerPlayer entityplayer) {
int j = this.processDurabilityChange(amount, entityplayer.serverLevel(), entityplayer); int j = this.processDurabilityChange(amount, entityplayer.serverLevel(), entityplayer);
@@ -535,6 +786,11 @@ @@ -535,6 +788,11 @@
} }
public void hurtAndBreak(int amount, LivingEntity entity, EquipmentSlot slot) { public void hurtAndBreak(int amount, LivingEntity entity, EquipmentSlot slot) {
@ -449,7 +451,7 @@
Level world = entity.level(); Level world = entity.level();
if (world instanceof ServerLevel worldserver) { if (world instanceof ServerLevel worldserver) {
@@ -546,9 +802,9 @@ @@ -546,9 +804,9 @@
entityplayer = null; entityplayer = null;
} }
@ -462,7 +464,7 @@
} }
} }
@@ -580,11 +836,11 @@ @@ -580,11 +838,11 @@
return this.getItem().getBarColor(this); return this.getItem().getBarColor(this);
} }
@ -476,7 +478,7 @@
return this.getItem().overrideOtherStackedOnMe(this, stack, slot, clickType, player, cursorStackReference); return this.getItem().overrideOtherStackedOnMe(this, stack, slot, clickType, player, cursorStackReference);
} }
@@ -592,8 +848,8 @@ @@ -592,8 +850,8 @@
Item item = this.getItem(); Item item = this.getItem();
if (item.hurtEnemy(this, target, user)) { if (item.hurtEnemy(this, target, user)) {
@ -487,7 +489,7 @@
entityhuman.awardStat(Stats.ITEM_USED.get(item)); entityhuman.awardStat(Stats.ITEM_USED.get(item));
} }
@@ -608,7 +864,7 @@ @@ -608,7 +866,7 @@
this.getItem().postHurtEnemy(this, target, user); this.getItem().postHurtEnemy(this, target, user);
} }
@ -496,7 +498,7 @@
Item item = this.getItem(); Item item = this.getItem();
if (item.mineBlock(this, world, state, pos, miner)) { if (item.mineBlock(this, world, state, pos, miner)) {
@@ -617,11 +873,11 @@ @@ -617,11 +875,11 @@
} }
@ -510,7 +512,7 @@
return this.getItem().interactLivingEntity(this, user, entity, hand); return this.getItem().interactLivingEntity(this, user, entity, hand);
} }
@@ -736,7 +992,7 @@ @@ -736,7 +994,7 @@
} }
@ -519,7 +521,7 @@
player.awardStat(Stats.ITEM_CRAFTED.get(this.getItem()), amount); player.awardStat(Stats.ITEM_CRAFTED.get(this.getItem()), amount);
this.getItem().onCraftedBy(this, world, player); this.getItem().onCraftedBy(this, world, player);
} }
@@ -770,6 +1026,12 @@ @@ -770,6 +1028,12 @@
return this.getItem().useOnRelease(this); return this.getItem().useOnRelease(this);
} }
@ -532,10 +534,13 @@
@Nullable @Nullable
public <T> T set(DataComponentType<? super T> type, @Nullable T value) { public <T> T set(DataComponentType<? super T> type, @Nullable T value) {
return this.components.set(type, value); return this.components.set(type, value);
@@ -806,6 +1068,25 @@ @@ -803,8 +1067,27 @@
} this.components.restorePatch(datacomponentpatch1);
} } else {
this.getItem().verifyComponentsAfterLoad(this);
+ }
+ }
+
+ // Paper start - (this is just a good no conflict location) + // Paper start - (this is just a good no conflict location)
+ public org.bukkit.inventory.ItemStack asBukkitMirror() { + public org.bukkit.inventory.ItemStack asBukkitMirror() {
+ return CraftItemStack.asCraftMirror(this); + return CraftItemStack.asCraftMirror(this);
@ -550,15 +555,14 @@
+ public org.bukkit.inventory.ItemStack getBukkitStack() { + public org.bukkit.inventory.ItemStack getBukkitStack() {
+ if (bukkitStack == null || bukkitStack.handle != this) { + if (bukkitStack == null || bukkitStack.handle != this) {
+ bukkitStack = org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(this); + bukkitStack = org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(this);
+ } }
+ return bukkitStack; + return bukkitStack;
+ } }
+ // Paper end + // Paper end
+
public void applyComponents(DataComponentPatch changes) { public void applyComponents(DataComponentPatch changes) {
this.components.applyPatch(changes); this.components.applyPatch(changes);
this.getItem().verifyComponentsAfterLoad(this); @@ -858,7 +1141,7 @@
@@ -858,7 +1139,7 @@
} }
private <T extends TooltipProvider> void addToTooltip(DataComponentType<T> componentType, Item.TooltipContext context, Consumer<Component> textConsumer, TooltipFlag type) { private <T extends TooltipProvider> void addToTooltip(DataComponentType<T> componentType, Item.TooltipContext context, Consumer<Component> textConsumer, TooltipFlag type) {
@ -567,7 +571,7 @@
if (t0 != null) { if (t0 != null) {
t0.addToTooltip(context, textConsumer, type); t0.addToTooltip(context, textConsumer, type);
@@ -866,7 +1147,7 @@ @@ -866,7 +1149,7 @@
} }
@ -576,7 +580,7 @@
boolean flag = this.getItem().shouldPrintOpWarning(this, player); boolean flag = this.getItem().shouldPrintOpWarning(this, player);
if (!type.isCreative() && this.has(DataComponents.HIDE_TOOLTIP)) { if (!type.isCreative() && this.has(DataComponents.HIDE_TOOLTIP)) {
@@ -941,7 +1222,7 @@ @@ -941,7 +1224,7 @@
} }
} }
@ -585,7 +589,7 @@
ItemAttributeModifiers itemattributemodifiers = (ItemAttributeModifiers) this.getOrDefault(DataComponents.ATTRIBUTE_MODIFIERS, ItemAttributeModifiers.EMPTY); ItemAttributeModifiers itemattributemodifiers = (ItemAttributeModifiers) this.getOrDefault(DataComponents.ATTRIBUTE_MODIFIERS, ItemAttributeModifiers.EMPTY);
if (itemattributemodifiers.showInTooltip()) { if (itemattributemodifiers.showInTooltip()) {
@@ -966,7 +1247,7 @@ @@ -966,7 +1249,7 @@
} }
} }
@ -594,7 +598,7 @@
double d0 = modifier.amount(); double d0 = modifier.amount();
boolean flag = false; boolean flag = false;
@@ -1091,6 +1372,14 @@ @@ -1091,6 +1374,14 @@
EnchantmentHelper.forEachModifier(this, slot, attributeModifierConsumer); EnchantmentHelper.forEachModifier(this, slot, attributeModifierConsumer);
} }
@ -609,7 +613,7 @@
public Component getDisplayName() { public Component getDisplayName() {
MutableComponent ichatmutablecomponent = Component.empty().append(this.getHoverName()); MutableComponent ichatmutablecomponent = Component.empty().append(this.getHoverName());
@@ -1153,7 +1442,7 @@ @@ -1153,7 +1444,7 @@
} }
public void consume(int amount, @Nullable LivingEntity entity) { public void consume(int amount, @Nullable LivingEntity entity) {