From 21b271c01a9a0f8dbe0d389ac049592fed0eb876 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 9 Apr 2022 20:32:46 +0200 Subject: [PATCH] Fix 1.18 Techhider Signed-off-by: Lixfel --- .../fightsystem/utils/TechHider18.java | 38 ++++--------------- 1 file changed, 7 insertions(+), 31 deletions(-) diff --git a/FightSystem_18/src/de/steamwar/fightsystem/utils/TechHider18.java b/FightSystem_18/src/de/steamwar/fightsystem/utils/TechHider18.java index d17fb72..b22f4a2 100644 --- a/FightSystem_18/src/de/steamwar/fightsystem/utils/TechHider18.java +++ b/FightSystem_18/src/de/steamwar/fightsystem/utils/TechHider18.java @@ -26,12 +26,12 @@ import io.netty.buffer.UnpooledByteBufAllocator; import net.minecraft.core.IRegistry; import net.minecraft.network.protocol.game.ClientboundLevelChunkPacketData; import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket; +import net.minecraft.util.SimpleBitStorage; import net.minecraft.world.level.block.entity.TileEntityTypes; import org.bukkit.World; import org.bukkit.entity.Player; import java.nio.ByteBuffer; -import java.nio.LongBuffer; import java.util.List; import java.util.Set; import java.util.function.IntFunction; @@ -93,15 +93,17 @@ public class TechHider18 implements TechHider.ChunkHider { buffer.writeBytes(data, curI, dataArrayLength * 8); } else { ByteBuffer source = ByteBuffer.wrap(data, curI, dataArrayLength * 8); - VariableValueArray values = new VariableValueArray(bitsPerBlock, dataArrayLength, source.asLongBuffer()); + long[] array = new long[dataArrayLength]; + source.asLongBuffer().get(array); + SimpleBitStorage values = new SimpleBitStorage(bitsPerBlock, 4096, array); for (int pos = 0; pos < 4096; pos++) { - if (hiddenBlockIds.contains(values.get(pos))) { - values.set(pos, obfuscateWith); + if (hiddenBlockIds.contains(values.a(pos))) { + values.b(pos, obfuscateWith); } } - for (long l : values.backing) + for (long l : values.a()) buffer.writeLong(l); } }); @@ -145,30 +147,4 @@ public class TechHider18 implements TechHider.ChunkHider { return i; } - - private static final class VariableValueArray { - private final long[] backing; - private final int bitsPerValue; - private final long valueMask; - private final int valuesPerLong; - - public VariableValueArray(int bitsPerEntry, int dataArrayLength, LongBuffer buffer) { - this.bitsPerValue = bitsPerEntry; - this.backing = new long[dataArrayLength]; - buffer.get(backing); - this.valueMask = (1L << this.bitsPerValue) - 1; - this.valuesPerLong = 64 / bitsPerEntry; - } - - public int get(int index) { - return (int)((backing[index / valuesPerLong] >> ((index % valuesPerLong) * bitsPerValue)) & valueMask); - } - - public void set(int index, int value) { - int i0 = index / valuesPerLong; - int i1 = index % valuesPerLong; - - backing[i0] = backing[i0] & ~(this.valueMask << i1) | (value & valueMask) << i1; - } - } }