Skip to content

Commit

Permalink
Fixes for desync from interaction cancellation
Browse files Browse the repository at this point in the history
  • Loading branch information
aromaa authored and Faithcaio committed Oct 13, 2023
1 parent d72f588 commit dc9a3ee
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -40,4 +41,6 @@ public interface ChunkMap_TrackedEntityAccessor {

@Invoker("removePlayer") void accessor$removePlayer(ServerPlayer param0);

@Accessor("serverEntity") ServerEntity accessor$getServerEntity();

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<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.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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down

0 comments on commit dc9a3ee

Please sign in to comment.