Techhider speed improvement
Dieser Commit ist enthalten in:
Ursprung
8459e187ea
Commit
b6d622b170
@ -16,6 +16,8 @@ import com.google.common.primitives.Bytes;
|
||||
import de.steamwar.fightsystem.FightSystem;
|
||||
import de.steamwar.fightsystem.fight.Fight;
|
||||
import de.steamwar.fightsystem.fight.FightTeam;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.UnpooledByteBufAllocator;
|
||||
import javafx.util.Pair;
|
||||
import net.minecraft.server.v1_12_R1.PacketPlayOutMapChunk;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -105,45 +107,49 @@ public class TechHider {
|
||||
|
||||
changed = false;
|
||||
byte [] data = byteArray.read(0);
|
||||
List<Byte> newData = new ArrayList<>(Bytes.asList(data));
|
||||
ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.directBuffer(data.length);
|
||||
int i = 0;
|
||||
|
||||
while(i < newData.size()){
|
||||
byte bitsPerBlock = newData.get(i++);
|
||||
while(i < data.length){
|
||||
byte bitsPerBlock = data[i++];
|
||||
buffer.writeByte(bitsPerBlock);
|
||||
if(bitsPerBlock < 4)
|
||||
bitsPerBlock = 4;
|
||||
else if(bitsPerBlock > 8){
|
||||
bitsPerBlock = 13;
|
||||
i++;
|
||||
buffer.writeByte(data[1]);
|
||||
}
|
||||
|
||||
if(bitsPerBlock != 13){
|
||||
int paletteLength = readVarInt(Bytes.toArray(newData), i);
|
||||
i += readVarIntLength(Bytes.toArray(newData), i);
|
||||
int paletteLength = readVarInt(data, i);
|
||||
int paletteLengthLength = readVarIntLength(data, i);
|
||||
buffer.writeBytes(data, i, paletteLengthLength);
|
||||
i += paletteLengthLength;
|
||||
for(int actPaletteId = 0; actPaletteId < paletteLength; actPaletteId++){
|
||||
int actPalette = readVarInt(Bytes.toArray(newData), i);
|
||||
int actPaletteLength = readVarIntLength(Bytes.toArray(newData), i);
|
||||
int actPalette = readVarInt(data, i);
|
||||
int actPaletteLength = readVarIntLength(data, i);
|
||||
|
||||
int blockId = actPalette >> 4;
|
||||
if(Config.HiddenBlocks.contains(blockId)){
|
||||
byte[] a = writeVarInt(obfuscateShift4);
|
||||
for(int j = 0; j < actPaletteLength; j++){
|
||||
newData.remove(i);
|
||||
}
|
||||
for(byte b : a){
|
||||
newData.add(i++, b);
|
||||
}
|
||||
buffer.writeBytes(a);
|
||||
changed = true;
|
||||
}else{
|
||||
i += actPaletteLength;
|
||||
buffer.writeBytes(data, i, actPaletteLength);
|
||||
}
|
||||
i += actPaletteLength;
|
||||
}
|
||||
int dataArrayLength = readVarInt(Bytes.toArray(newData), i);
|
||||
i += readVarIntLength(Bytes.toArray(newData), i);
|
||||
int dataArrayLength = readVarInt(data, i);
|
||||
int dataArrayLengthLength = readVarIntLength(data, i);
|
||||
buffer.writeBytes(data, i, dataArrayLength * 8 + dataArrayLengthLength);
|
||||
i += dataArrayLengthLength;
|
||||
i += dataArrayLength * 8;
|
||||
}else{
|
||||
int dataArrayLength = readVarInt(Bytes.toArray(newData), i);
|
||||
i += readVarIntLength(Bytes.toArray(newData), i);
|
||||
int dataArrayLength = readVarInt(data, i);
|
||||
int dataArrayLengthLength = readVarIntLength(data, i);
|
||||
buffer.writeBytes(data, i, dataArrayLength*8 + dataArrayLengthLength);
|
||||
i += dataArrayLengthLength;
|
||||
/*int arrayEnd = dataArrayLength * 8 + i;
|
||||
int bitsOver = 8; //9 bits (id) + 4 bits (metadata)
|
||||
while(i < arrayEnd){
|
||||
@ -165,11 +171,13 @@ public class TechHider {
|
||||
i += dataArrayLength * 8;
|
||||
}
|
||||
|
||||
buffer.writeBytes(data, i, 4096);
|
||||
i += 4096; //Skylight (Not in Nether/End!!!) 2048 + Blocklight 2048
|
||||
}
|
||||
|
||||
if(changed){
|
||||
byteArray.write(0, Bytes.toArray(newData));
|
||||
buffer.readBytes(data);
|
||||
byteArray.write(0, data);
|
||||
}
|
||||
}
|
||||
}).start(4 * threadMultiplier);
|
||||
@ -349,7 +357,7 @@ public class TechHider {
|
||||
}
|
||||
|
||||
private static byte[] writeVarInt(int value) {
|
||||
ArrayList<Byte> buffer = new ArrayList<>();
|
||||
List<Byte> buffer = new ArrayList<>(5);
|
||||
do {
|
||||
byte temp = (byte)(value & 0b01111111);
|
||||
// Note: >>> means that the sign bit is shifted with the rest of the number rather than being left alone
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren