Add handling for container

This commit is contained in:
D4rkr34lm
2026-05-16 20:14:09 +02:00
parent 88de28ed68
commit 723a7dc0ca
@@ -11,6 +11,7 @@ import java.util.function.ToDoubleFunction;
import java.util.function.ToIntFunction;
import it.unimi.dsi.fastutil.ints.IntList;
import net.minecraft.server.packs.repository.Pack;
import net.minecraft.world.level.block.entity.BlockEntityType;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
@@ -377,11 +378,11 @@ public abstract class TechHider {
// --- Container packets ---
// 7.1.19 Set Container Content
processors.put(ClientboundContainerSetContentPacket.class, tossPacket);
processors.put(ClientboundContainerSetContentPacket.class, buildContainerPacketProcessor(ClientboundContainerSetContentPacket::containerId));
// 7.1.20 Set Container Property
processors.put(ClientboundContainerSetDataPacket.class, tossPacket);
processors.put(ClientboundContainerSetDataPacket.class, buildContainerPacketProcessor(ClientboundContainerSetDataPacket::getContainerId));
// 7.1.21 Set Container Slot
processors.put(ClientboundContainerSetSlotPacket.class, tossPacket);
processors.put(ClientboundContainerSetSlotPacket.class, buildContainerPacketProcessor(ClientboundContainerSetSlotPacket::getContainerId));
// --- Others ---
// 7.1.37 Explosion: position, affected blocks, and knockback can reveal
@@ -618,11 +619,25 @@ public abstract class TechHider {
}
private final ChunkHider chunkHider = new ChunkHider();
private ClientboundLevelChunkWithLightPacket processChunkWithLight(Player p, ClientboundLevelChunkWithLightPacket packet) {
return chunkHider.processLevelChunkWithLightPacket(p, blockEntitiesToHide, this::isPlayerPrivilegedToAccessBlockPos, blockToObfuscateTo, blockIdsToObfuscate, packet);
}
private Packet<? extends PacketListener> processContainerPacket(Player player, int containerId, Packet<? extends PacketListener> packet) {
if(isPlayerPrivilegedToAccessContainer(player, containerId)) {
return packet;
} else {
return null;
}
}
private <TTargetPacket extends Packet<?>> BiFunction<Player, Packet<?>, Packet<?>> buildContainerPacketProcessor(ToIntFunction<TTargetPacket> containerIdExtractor) {
return (p, rawPacket) -> {
TTargetPacket packet = (TTargetPacket) rawPacket;
return processContainerPacket(p, containerIdExtractor.applyAsInt(packet), packet);
};
}
public abstract boolean isPlayerPrivilegedToAccessPosition(Player p, int blockX, int blockY, int blockZ);
public abstract boolean isPlayerPrivilegedToAccessBlock(Player p, int blockX, int blockY, int blockZ, Block block);
public abstract boolean isPlayerPrivilegedToAccessEntity(Player p, int entityId);