diff --git a/src/main/java/eu/vanish/mixin/ServerPlayerInteractionManagerMixin.java b/src/main/java/eu/vanish/mixin/ServerPlayerInteractionManagerMixin.java new file mode 100644 index 0000000..45050fe --- /dev/null +++ b/src/main/java/eu/vanish/mixin/ServerPlayerInteractionManagerMixin.java @@ -0,0 +1,39 @@ +package eu.vanish.mixin; + +import eu.vanish.Vanish; +import eu.vanish.mixinterface.IServerWorld; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.server.network.ServerPlayerInteractionManager; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.util.math.BlockPos; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(ServerPlayerInteractionManager.class) +public class ServerPlayerInteractionManagerMixin { + @Shadow private BlockPos miningPos; + @Shadow @Final protected ServerPlayerEntity player; + @Shadow protected ServerWorld world; + + public BlockPos getCurrentlyMining() { + return this.miningPos; + } + + @Inject(at=@At("HEAD"),method = "tryBreakBlock") + private void onStartBreak(BlockPos pos, CallbackInfoReturnable cir) { + if (player != null && Vanish.INSTANCE.vanishedPlayers.isVanished(player.getEntityName())) { + ((IServerWorld)world).setSilentBlockBreaking(true); + } + } + + @Inject(at=@At("RETURN"),method = "tryBreakBlock") + private void onEndBreak(BlockPos pos, CallbackInfoReturnable cir) { + if (player != null && Vanish.INSTANCE.vanishedPlayers.isVanished(player.getEntityName())) { + ((IServerWorld)world).setSilentBlockBreaking(false); + } + } +} diff --git a/src/main/java/eu/vanish/mixin/ServerWorldMixin.java b/src/main/java/eu/vanish/mixin/ServerWorldMixin.java index 3a84cc0..1f71838 100644 --- a/src/main/java/eu/vanish/mixin/ServerWorldMixin.java +++ b/src/main/java/eu/vanish/mixin/ServerWorldMixin.java @@ -1,10 +1,13 @@ package eu.vanish.mixin; import eu.vanish.Vanish; +import eu.vanish.mixinterface.IServerWorld; +import net.minecraft.entity.Entity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.server.world.ServerWorld; import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundEvent; +import net.minecraft.util.math.BlockPos; import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -12,7 +15,14 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(ServerWorld.class) -public class ServerWorldMixin { +public class ServerWorldMixin implements IServerWorld { + ServerWorld SW_Instance = (ServerWorld) (Object) this; + + private boolean silenceBlockBreaking = false; + + public void setSilentBlockBreaking(boolean bool) { + silenceBlockBreaking = bool; + } @Inject(at = @At("HEAD"), cancellable = true, method = "playSound") private void onPlaySound(@Nullable PlayerEntity player, double x, double y, double z, SoundEvent sound, SoundCategory category, float volume, float pitch, long seed, CallbackInfo ci) { @@ -23,4 +33,22 @@ private void onPlaySound(@Nullable PlayerEntity player, double x, double y, doub if(Vanish.INSTANCE.vanishedPlayers.isVanished(player.getEntityName())) ci.cancel(); } + + @Inject(at=@At("HEAD"),method="setBlockBreakingInfo",cancellable = true) + private void onUpdateBreakingInfo(int entityId, BlockPos pos, int progress, CallbackInfo ci) { + if (!Vanish.INSTANCE.isActive()) return; + Entity entity = SW_Instance.getEntityById(entityId); + if (!(entity instanceof PlayerEntity)) return; + + + if(Vanish.INSTANCE.vanishedPlayers.isVanished(entity.getEntityName())) + ci.cancel(); + } + + @Inject(at=@At("HEAD"),method="syncWorldEvent",cancellable = true) + private void onBreakBlock(PlayerEntity player, int eventId, BlockPos pos, int data, CallbackInfo ci) { + if (silenceBlockBreaking) { + ci.cancel(); + } + } } diff --git a/src/main/java/eu/vanish/mixinterface/IServerWorld.java b/src/main/java/eu/vanish/mixinterface/IServerWorld.java new file mode 100644 index 0000000..840e86d --- /dev/null +++ b/src/main/java/eu/vanish/mixinterface/IServerWorld.java @@ -0,0 +1,5 @@ +package eu.vanish.mixinterface; + +public interface IServerWorld { + void setSilentBlockBreaking(boolean bool); +} diff --git a/src/main/resources/vanish.mixins.json b/src/main/resources/vanish.mixins.json index 60863a8..d8c3148 100644 --- a/src/main/resources/vanish.mixins.json +++ b/src/main/resources/vanish.mixins.json @@ -18,7 +18,9 @@ "PlayerManagerMixin", "ServerMetadataMixin", "ServerPlayNetworkHandlerMixin", - "ServerWorldMixin" + "ServerWorldMixin", + + "ServerPlayerInteractionManagerMixin" ], "injectors": { "defaultRequire": 1