Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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<Boolean> 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<Boolean> cir) {
if (player != null && Vanish.INSTANCE.vanishedPlayers.isVanished(player.getEntityName())) {
((IServerWorld)world).setSilentBlockBreaking(false);
}
}
}
30 changes: 29 additions & 1 deletion src/main/java/eu/vanish/mixin/ServerWorldMixin.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
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;
import org.spongepowered.asm.mixin.injection.Inject;
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) {
Expand All @@ -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();
}
}
}
5 changes: 5 additions & 0 deletions src/main/java/eu/vanish/mixinterface/IServerWorld.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package eu.vanish.mixinterface;

public interface IServerWorld {
void setSilentBlockBreaking(boolean bool);
}
4 changes: 3 additions & 1 deletion src/main/resources/vanish.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
"PlayerManagerMixin",
"ServerMetadataMixin",
"ServerPlayNetworkHandlerMixin",
"ServerWorldMixin"
"ServerWorldMixin",

"ServerPlayerInteractionManagerMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down