Fixes for desync from interaction cancellation

This commit is contained in:
aromaa committed 2023-06-03 01:39:58 +03:00
1 parent 8eb76ac3db
commit e82e19c471
3 files changed
+21 -1

No files matched your search

@@ -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();
}
@@ -45,6 +45,7 @@ import net.minecraft.network.protocol.game.ClientboundLevelEventPacket;
import net.minecraft.network.protocol.game.ClientboundPlayerAbilitiesPacket;
import net.minecraft.network.protocol.game.ClientboundPlayerCombatPacket;
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.ServerboundClientInformationPacket;
import net.minecraft.server.MinecraftServer;
@@ -62,10 +63,13 @@ import net.minecraft.world.damagesource.DamageSource;
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.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.ResultSlot;
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;
@@ -123,6 +127,8 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.common.SpongeCommon;
import org.spongepowered.common.accessor.network.ConnectionAccessor;
import org.spongepowered.common.accessor.network.protocol.game.ServerboundClientInformationPacketAccessor;
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;
@@ -822,9 +828,19 @@ public abstract class ServerPlayerMixin extends PlayerMixin implements SubjectBr
protected void impl$onRightClickEntity(
final Entity entityToInteractOn, final InteractionHand hand, final CallbackInfoReturnable<InteractionResult> 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.shadow$refreshContainer(this.containerMenu);
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.level).chunkManager()).accessor$entityMap().get(entityToInteractOn.getId());
if (trackerAccessor != null) {
trackerAccessor.accessor$getServerEntity().sendPairingData(this.connection::send);
}
}
cir.setReturnValue(InteractionResult.FAIL);
}
}
@@ -80,6 +80,7 @@ public abstract class ServerPlayerGameModeMixin_Tracker {
) {
final InteractItemEvent.Secondary event = SpongeCommonEventFactory.callInteractItemEventSecondary(player, stack, hand);
if (event.isCancelled()) {
player.refreshContainer(player.inventoryMenu);
cir.setReturnValue(InteractionResult.FAIL);
}
}