Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-09-16 01:01:21 +02:00
Revert "Remove indirection in byte array writing"
This reverts commit ba08c3ad2f
.
Breaks the API that ViaRewind and ViaBackwards depend on.
Dieser Commit ist enthalten in:
Ursprung
ba08c3ad2f
Commit
437463f1b4
@ -14,7 +14,7 @@ import java.util.UUID;
|
|||||||
public abstract class Type<T> implements ByteBufReader<T>, ByteBufWriter<T> {
|
public abstract class Type<T> implements ByteBufReader<T>, ByteBufWriter<T> {
|
||||||
/* Defined Types */
|
/* Defined Types */
|
||||||
public static final Type<Byte> BYTE = new ByteType();
|
public static final Type<Byte> BYTE = new ByteType();
|
||||||
public static final Type<byte[]> BYTE_ARRAY = new ByteArrayType();
|
public static final Type<Byte[]> BYTE_ARRAY = new ArrayType<>(Type.BYTE);
|
||||||
|
|
||||||
public static final Type<byte[]> REMAINING_BYTES = new RemainingBytesType();
|
public static final Type<byte[]> REMAINING_BYTES = new RemainingBytesType();
|
||||||
|
|
||||||
|
@ -1,27 +0,0 @@
|
|||||||
package us.myles.ViaVersion.api.type.types;
|
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
|
||||||
import io.netty.buffer.ByteBuf;
|
|
||||||
import us.myles.ViaVersion.api.type.Type;
|
|
||||||
|
|
||||||
public class ByteArrayType extends Type<byte[]> {
|
|
||||||
public ByteArrayType() {
|
|
||||||
super("Byte Array", byte[].class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public byte[] read(ByteBuf buffer) throws Exception {
|
|
||||||
int len = Type.VAR_INT.read(buffer);
|
|
||||||
|
|
||||||
Preconditions.checkArgument(buffer.isReadable(len), "Could not read %s bytes from buffer (have %s)", len, buffer.readableBytes());
|
|
||||||
byte[] data = new byte[len];
|
|
||||||
buffer.readBytes(data);
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void write(ByteBuf buffer, byte[] object) throws Exception {
|
|
||||||
Type.VAR_INT.write(buffer, object.length);
|
|
||||||
buffer.writeBytes(object);
|
|
||||||
}
|
|
||||||
}
|
|
@ -32,7 +32,7 @@ public class WorldPackets {
|
|||||||
private static final int VOID_AIR = MappingData.blockStateMappings.getNewBlock(8591);
|
private static final int VOID_AIR = MappingData.blockStateMappings.getNewBlock(8591);
|
||||||
private static final int CAVE_AIR = MappingData.blockStateMappings.getNewBlock(8592);
|
private static final int CAVE_AIR = MappingData.blockStateMappings.getNewBlock(8592);
|
||||||
public static final int SERVERSIDE_VIEW_DISTANCE = 64;
|
public static final int SERVERSIDE_VIEW_DISTANCE = 64;
|
||||||
private static final byte[] FULL_LIGHT = new byte[2048];
|
private static final Byte[] FULL_LIGHT = new Byte[2048];
|
||||||
|
|
||||||
static {
|
static {
|
||||||
Arrays.fill(FULL_LIGHT, (byte) 0xff);
|
Arrays.fill(FULL_LIGHT, (byte) 0xff);
|
||||||
@ -242,14 +242,14 @@ public class WorldPackets {
|
|||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
lightPacket.write(Type.BYTE_ARRAY, section.getSkyLight());
|
lightPacket.write(Type.BYTE_ARRAY, fromPrimitiveArray(section.getSkyLight()));
|
||||||
}
|
}
|
||||||
if (chunk.isGroundUp())
|
if (chunk.isGroundUp())
|
||||||
lightPacket.write(Type.BYTE_ARRAY, FULL_LIGHT); // chunk above 255
|
lightPacket.write(Type.BYTE_ARRAY, FULL_LIGHT); // chunk above 255
|
||||||
|
|
||||||
for (ChunkSection section : chunk.getSections()) {
|
for (ChunkSection section : chunk.getSections()) {
|
||||||
if (section == null) continue;
|
if (section == null) continue;
|
||||||
lightPacket.write(Type.BYTE_ARRAY, section.getBlockLight());
|
lightPacket.write(Type.BYTE_ARRAY, fromPrimitiveArray(section.getBlockLight()));
|
||||||
}
|
}
|
||||||
|
|
||||||
EntityTracker entityTracker = wrapper.user().get(EntityTracker.class);
|
EntityTracker entityTracker = wrapper.user().get(EntityTracker.class);
|
||||||
@ -268,6 +268,14 @@ public class WorldPackets {
|
|||||||
|
|
||||||
lightPacket.send(Protocol1_14To1_13_2.class, true, true);
|
lightPacket.send(Protocol1_14To1_13_2.class, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Byte[] fromPrimitiveArray(byte[] bytes) {
|
||||||
|
Byte[] newArray = new Byte[bytes.length];
|
||||||
|
for (int i = 0; i < bytes.length; i++) {
|
||||||
|
newArray[i] = bytes[i];
|
||||||
|
}
|
||||||
|
return newArray;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren