diff --git a/src/accessors/java/org/spongepowered/common/accessor/server/level/ChunkMap_TrackedEntityAccessor.java b/src/accessors/java/org/spongepowered/common/accessor/server/level/ChunkMap_TrackedEntityAccessor.java index da2d705b24f..f29cfd78c35 100644 --- a/src/accessors/java/org/spongepowered/common/accessor/server/level/ChunkMap_TrackedEntityAccessor.java +++ b/src/accessors/java/org/spongepowered/common/accessor/server/level/ChunkMap_TrackedEntityAccessor.java @@ -24,6 +24,7 @@ */ package org.spongepowered.common.accessor.server.level; +import net.minecraft.server.level.ServerEntity; import net.minecraft.server.level.ServerPlayer; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; @@ -40,4 +41,6 @@ public interface ChunkMap_TrackedEntityAccessor { @Invoker("removePlayer") void accessor$removePlayer(ServerPlayer param0); + @Accessor("serverEntity") ServerEntity accessor$getServerEntity(); + } diff --git a/src/mixins/java/org/spongepowered/common/mixin/core/server/level/ServerPlayerMixin.java b/src/mixins/java/org/spongepowered/common/mixin/core/server/level/ServerPlayerMixin.java index b2c084a1510..ee95f7f3aac 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/core/server/level/ServerPlayerMixin.java +++ b/src/mixins/java/org/spongepowered/common/mixin/core/server/level/ServerPlayerMixin.java @@ -44,6 +44,7 @@ import net.minecraft.network.protocol.game.ClientboundPlayerAbilitiesPacket; import net.minecraft.network.protocol.game.ClientboundPlayerCombatKillPacket; import net.minecraft.network.protocol.game.ClientboundRespawnPacket; +import net.minecraft.network.protocol.game.ClientboundSetEntityLinkPacket; import net.minecraft.network.protocol.game.ClientboundUpdateMobEffectPacket; import net.minecraft.network.protocol.game.CommonPlayerSpawnInfo; import net.minecraft.server.MinecraftServer; @@ -62,7 +63,11 @@ import net.minecraft.world.effect.MobEffectInstance; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.Mob; +import net.minecraft.world.entity.animal.AbstractFish; import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; import net.minecraft.world.level.ChunkPos; import net.minecraft.world.level.GameRules; import net.minecraft.world.level.GameType; @@ -119,6 +124,8 @@ import org.spongepowered.common.SpongeCommon; import org.spongepowered.common.accessor.network.ConnectionAccessor; import org.spongepowered.common.accessor.server.network.ServerCommonPacketListenerImplAccessor; +import org.spongepowered.common.accessor.server.level.ChunkMapAccessor; +import org.spongepowered.common.accessor.server.level.ChunkMap_TrackedEntityAccessor; import org.spongepowered.common.adventure.SpongeAdventure; import org.spongepowered.common.bridge.data.DataCompoundHolder; import org.spongepowered.common.bridge.permissions.SubjectBridge; @@ -793,9 +800,19 @@ public void sendMessage(final OutgoingChatMessage $$0, final boolean $$1, final protected void impl$onRightClickEntity( final Entity entityToInteractOn, final InteractionHand hand, final CallbackInfoReturnable cir ) { + final ItemStack itemInHand = this.shadow$getItemInHand(hand); final InteractEntityEvent.Secondary event = SpongeCommonEventFactory.callInteractEntityEventSecondary((net.minecraft.server.level.ServerPlayer) (Object) this, - this.shadow$getItemInHand(hand), entityToInteractOn, hand, null); + itemInHand, entityToInteractOn, hand, null); if (event.isCancelled()) { + this.containerMenu.sendAllDataToRemote(); + if (itemInHand.getItem() == Items.LEAD && entityToInteractOn instanceof Mob) { + this.connection.send(new ClientboundSetEntityLinkPacket(entityToInteractOn, ((Mob) entityToInteractOn).getLeashHolder())); + } else if (itemInHand.getItem() == Items.WATER_BUCKET && entityToInteractOn instanceof AbstractFish) { + final ChunkMap_TrackedEntityAccessor trackerAccessor = ((ChunkMapAccessor) ((ServerWorld) this.shadow$level()).chunkManager()).accessor$entityMap().get(entityToInteractOn.getId()); + if (trackerAccessor != null) { + trackerAccessor.accessor$getServerEntity().sendPairingData((net.minecraft.server.level.ServerPlayer) (Object) this, this.connection::send); + } + } cir.setReturnValue(InteractionResult.FAIL); } } diff --git a/src/mixins/java/org/spongepowered/common/mixin/tracker/server/level/ServerPlayerGameModeMixin_Tracker.java b/src/mixins/java/org/spongepowered/common/mixin/tracker/server/level/ServerPlayerGameModeMixin_Tracker.java index 3f3f1ac5e6d..d2aba5c0f25 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/tracker/server/level/ServerPlayerGameModeMixin_Tracker.java +++ b/src/mixins/java/org/spongepowered/common/mixin/tracker/server/level/ServerPlayerGameModeMixin_Tracker.java @@ -84,6 +84,7 @@ public abstract class ServerPlayerGameModeMixin_Tracker { ) { final InteractItemEvent.Secondary event = SpongeCommonEventFactory.callInteractItemEventSecondary(player, stack, hand); if (event.isCancelled()) { + player.inventoryMenu.sendAllDataToRemote(); cir.setReturnValue(InteractionResult.FAIL); } }