Merge pull request #1679 from KennyTV/abstraction

20w12a
This commit is contained in:
Myles 2020-03-18 18:26:34 +00:00 committed by GitHub
commit f245bb8263
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 13148 additions and 13059 deletions

View File

@ -80,7 +80,7 @@ public class ProtocolVersion {
register(v1_15 = new ProtocolVersion(573, "1.15"));
register(v1_15_1 = new ProtocolVersion(575, "1.15.1"));
register(v1_15_2 = new ProtocolVersion(578, "1.15.2"));
register(v1_16 = new ProtocolVersion(706, "1.16"));
register(v1_16 = new ProtocolVersion(707, "1.16"));
register(unknown = new ProtocolVersion(-1, "UNKNOWN"));
}

View File

@ -81,6 +81,7 @@ public abstract class Type<T> implements ByteBufReader<T>, ByteBufWriter<T> {
public static final Type<String[]> STRING_ARRAY = new ArrayType<>(Type.STRING);
public static final Type<UUID> UUID = new UUIDType();
public static final Type<UUID> UUID_INT_ARRAY = new UUIDIntArrayType();
public static final Type<UUID[]> UUID_ARRAY = new ArrayType<>(Type.UUID);
/* Variable Types */
public static final Type<Integer> VAR_INT = new VarIntType();

View File

@ -0,0 +1,45 @@
package us.myles.ViaVersion.api.type.types;
import io.netty.buffer.ByteBuf;
import us.myles.ViaVersion.api.type.Type;
import java.util.UUID;
public class UUIDIntArrayType extends Type<UUID> {
public UUIDIntArrayType() {
super(UUID.class);
}
@Override
public UUID read(ByteBuf buffer) {
int[] ints = {
buffer.readInt(),
buffer.readInt(),
buffer.readInt(),
buffer.readInt()
};
return uuidFromIntArray(ints);
}
@Override
public void write(ByteBuf buffer, UUID object) {
int[] ints = uuidToIntArray(object);
buffer.writeInt(ints[0]);
buffer.writeInt(ints[1]);
buffer.writeInt(ints[2]);
buffer.writeInt(ints[3]);
}
public static UUID uuidFromIntArray(int[] ints) {
return new UUID((long) ints[0] << 32 | ((long) ints[1] & 0xFFFFFFFFL), (long) ints[2] << 32 | ((long) ints[3] & 0xFFFFFFFFL));
}
public static int[] uuidToIntArray(UUID uuid) {
return bitsToIntArray(uuid.getMostSignificantBits(), uuid.getLeastSignificantBits());
}
public static int[] bitsToIntArray(long long1, long long2) {
return new int[]{(int) (long1 >> 32), (int) long1, (int) (long2 >> 32), (int) long2};
}
}

View File

@ -14,6 +14,8 @@ import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.packets.WorldPackets;
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.storage.EntityTracker1_16;
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
import java.util.UUID;
public class Protocol1_16To1_15_2 extends Protocol {
@Override
@ -25,6 +27,18 @@ public class Protocol1_16To1_15_2 extends Protocol {
WorldPackets.register(this);
InventoryPackets.register(this);
// Login Success
registerOutgoing(State.LOGIN, 0x02, 0x02, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
// Transform string to int array
UUID uuid = UUID.fromString(wrapper.read(Type.STRING));
wrapper.write(Type.UUID_INT_ARRAY, uuid);
});
}
});
// Entity Sound Effect
registerOutgoing(State.PLAY, 0x51, 0x51, new PacketRemapper() {
@Override
@ -123,6 +137,19 @@ public class Protocol1_16To1_15_2 extends Protocol {
});
}
});
registerOutgoing(State.PLAY, 0x43, 0x44);
registerOutgoing(State.PLAY, 0x45, 0x46);
registerOutgoing(State.PLAY, 0x46, 0x47);
registerOutgoing(State.PLAY, 0x48, 0x49);
registerOutgoing(State.PLAY, 0x49, 0x4A);
registerOutgoing(State.PLAY, 0x4A, 0x4B);
registerOutgoing(State.PLAY, 0x4B, 0x4C);
registerOutgoing(State.PLAY, 0x4C, 0x4D);
registerOutgoing(State.PLAY, 0x4D, 0x4E);
registerOutgoing(State.PLAY, 0x4E, 0x43);
}
public static int getNewBlockStateId(int id) {

View File

@ -21,7 +21,7 @@ public class EntityPackets {
metadataRewriter.registerTracker(0x05, 0x05, Entity1_16Types.EntityType.PLAYER);
// Metadata
metadataRewriter.registerMetadataRewriter(0x44, 0x44, Types1_14.METADATA_LIST);
metadataRewriter.registerMetadataRewriter(0x44, 0x45, Types1_14.METADATA_LIST);
// Entity Destroy
metadataRewriter.registerEntityDestroy(0x38, 0x38);

View File

@ -60,7 +60,7 @@ public class InventoryPackets {
itemRewriter.registerSetSlot(Type.FLAT_VAR_INT_ITEM, 0x17, 0x17);
// Entity Equipment Packet
itemRewriter.registerEntityEquipment(Type.FLAT_VAR_INT_ITEM, 0x47, 0x47);
itemRewriter.registerEntityEquipment(Type.FLAT_VAR_INT_ITEM, 0x47, 0x48);
// Declare Recipes
protocol.registerOutgoing(State.PLAY, 0x5B, 0x5B, new PacketRemapper() {