1.14 position changes

This commit is contained in:
Gerrygames 2018-10-26 18:36:35 +02:00
parent 28bb60244f
commit 2da9b99789
7 changed files with 241 additions and 96 deletions

View File

@ -59,6 +59,7 @@ public abstract class Type<T> implements ByteBufReader<T>, ByteBufWriter<T> {
public static final Type<Void> NOTHING = new VoidType(); // This is purely used for remapping.
/* MC Types */
public static final Type<Position> POSITION = new PositionType();
public static final Type<Position> POSITION1_14 = new Position1_14Type();
public static final Type<EulerAngle> ROTATION = new EulerAngleType();
public static final Type<Vector> VECTOR = new VectorType();
public static final Type<CompoundTag> NBT = new NBTType();

View File

@ -0,0 +1,26 @@
package us.myles.ViaVersion.api.type.types.minecraft;
import io.netty.buffer.ByteBuf;
import us.myles.ViaVersion.api.minecraft.Position;
import us.myles.ViaVersion.api.type.Type;
public class Position1_14Type extends Type<Position> {
public Position1_14Type() {
super(Position.class);
}
@Override
public Position read(ByteBuf buffer) {
long val = buffer.readLong();
long x = (val >> 38);
long y = val & 0xfff;
long z = (((val << 38) >> 38)) >> 12;
return new Position(x, y, z);
}
@Override
public void write(ByteBuf buffer, Position object) {
buffer.writeLong(((object.getX() & 0x3ffffff) << 38) | (object.getY() & 0xfff) | ((object.getZ() & 0x3ffffff) << 12));
}
}

View File

@ -9,6 +9,7 @@ import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State;
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.packets.EntityPackets;
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.packets.InventoryPackets;
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.packets.PlayerPackets;
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.packets.WorldPackets;
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.storage.EntityTracker;
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
@ -19,6 +20,7 @@ public class Protocol1_14To1_13_2 extends Protocol {
InventoryPackets.register(this);
EntityPackets.register(this);
WorldPackets.register(this);
PlayerPackets.register(this);
// Sound Effect
registerOutgoing(State.PLAY, 0x4D, 0x4D, new PacketRemapper() {

View File

@ -92,6 +92,18 @@ public class EntityPackets {
}
});
// Spawn painting
protocol.registerOutgoing(State.PLAY, 0x04, 0x04, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT);
map(Type.UUID);
map(Type.VAR_INT);
map(Type.POSITION, Type.POSITION1_14);
map(Type.BYTE);
}
});
// Spawn player packet
protocol.registerOutgoing(State.PLAY, 0x05, 0x05, new PacketRemapper() {
@Override
@ -119,6 +131,15 @@ public class EntityPackets {
}
});
// Use bed
protocol.registerOutgoing(State.PLAY, 0x33, 0x33, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT);
map(Type.POSITION, Type.POSITION1_14);
}
});
// Destroy entities
protocol.registerOutgoing(State.PLAY, 0x35, 0x35, new PacketRemapper() {
@Override

View File

@ -27,8 +27,7 @@ public class InventoryPackets {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
Item stack = wrapper.get(Type.FLAT_VAR_INT_ITEM, 0);
toClient(stack);
toClient(wrapper.get(Type.FLAT_VAR_INT_ITEM, 0));
}
});
}
@ -45,8 +44,7 @@ public class InventoryPackets {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
Item[] stacks = wrapper.get(Type.FLAT_VAR_INT_ITEM_ARRAY, 0);
for (Item stack : stacks)
toClient(stack);
for (Item stack : stacks) toClient(stack);
}
});
}
@ -69,12 +67,12 @@ public class InventoryPackets {
// Input Item
toClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM));
// Output Item
InventoryPackets.toClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM));
toClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM));
boolean secondItem = wrapper.passthrough(Type.BOOLEAN); // Has second item
if (secondItem) {
// Second Item
InventoryPackets.toClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM));
toClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM));
}
wrapper.passthrough(Type.BOOLEAN); // Trade disabled
@ -98,8 +96,7 @@ public class InventoryPackets {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
Item stack = wrapper.get(Type.FLAT_VAR_INT_ITEM, 0);
toClient(stack);
toClient(wrapper.get(Type.FLAT_VAR_INT_ITEM, 0));
}
});
}
@ -129,19 +126,22 @@ public class InventoryPackets {
int ingredientsNo = wrapper.passthrough(Type.VAR_INT);
for (int j = 0; j < ingredientsNo; j++) {
Item[] items = wrapper.passthrough(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT); // Ingredients
for (Item item : items) toClient(item);
}
wrapper.passthrough(Type.FLAT_VAR_INT_ITEM); // Result
toClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)); // Result
} else if (type.equals("crafting_shaped")) {
int ingredientsNo = wrapper.passthrough(Type.VAR_INT) * wrapper.passthrough(Type.VAR_INT);
wrapper.passthrough(Type.STRING); // Group
for (int j = 0; j < ingredientsNo; j++) {
wrapper.passthrough(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT); // Ingredients
Item[] items = wrapper.passthrough(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT); // Ingredients
for (Item item : items) toClient(item);
}
wrapper.passthrough(Type.FLAT_VAR_INT_ITEM); // Result
toClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)); // Result
} else if (type.equals("smelting")) {
wrapper.passthrough(Type.STRING); // Group
wrapper.passthrough(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT); // Ingredients
wrapper.passthrough(Type.FLAT_VAR_INT_ITEM);
Item[] items = wrapper.passthrough(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT); // Ingredients
for (Item item : items) toClient(item);
toClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM));
wrapper.passthrough(Type.FLOAT); // EXP
wrapper.passthrough(Type.VAR_INT); // Cooking time
}
@ -171,8 +171,7 @@ public class InventoryPackets {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
Item item = wrapper.get(Type.FLAT_VAR_INT_ITEM, 0);
toServer(item);
toServer(wrapper.get(Type.FLAT_VAR_INT_ITEM, 0));
}
});
}
@ -188,8 +187,7 @@ public class InventoryPackets {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
Item item = wrapper.get(Type.FLAT_VAR_INT_ITEM, 0);
toServer(item);
toServer(wrapper.get(Type.FLAT_VAR_INT_ITEM, 0));
}
});
}

View File

@ -0,0 +1,71 @@
package us.myles.ViaVersion.protocols.protocol1_14to1_13_2.packets;
import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State;
public class PlayerPackets {
public static void register(Protocol protocol) {
// Open Sign Editor
protocol.registerOutgoing(State.PLAY, 0x2C, 0x2C, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.POSITION, Type.POSITION1_14);
}
});
// Query Block NBT
protocol.registerIncoming(State.PLAY, 0x01, 0x01, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT);
map(Type.POSITION1_14, Type.POSITION);
}
});
// Player Digging
protocol.registerIncoming(State.PLAY, 0x18, 0x18, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT);
map(Type.POSITION1_14, Type.POSITION);
map(Type.BYTE);
}
});
// Update Command Block
protocol.registerIncoming(State.PLAY, 0x22, 0x22, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.POSITION1_14, Type.POSITION);
}
});
// Update Structure Block
protocol.registerIncoming(State.PLAY, 0x25, 0x25, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.POSITION1_14, Type.POSITION);
}
});
// Update Sign
protocol.registerIncoming(State.PLAY, 0x26, 0x26, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.POSITION1_14, Type.POSITION);
}
});
// Player Block Placement
protocol.registerIncoming(State.PLAY, 0x29, 0x29, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.POSITION1_14, Type.POSITION);
}
});
}
}

View File

@ -19,6 +19,78 @@ import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
public class WorldPackets {
public static void register(Protocol protocol) {
// Block break animation
protocol.registerOutgoing(State.PLAY, 0x08, 0x08, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT);
map(Type.POSITION, Type.POSITION1_14);
map(Type.BYTE);
}
});
// Update block entity
protocol.registerOutgoing(State.PLAY, 0x09, 0x09, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.POSITION, Type.POSITION1_14);
}
});
// Block Action
protocol.registerOutgoing(State.PLAY, 0x0A, 0x0A, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.POSITION, Type.POSITION1_14); // Location
map(Type.UNSIGNED_BYTE); // Action id
map(Type.UNSIGNED_BYTE); // Action param
map(Type.VAR_INT); // Block id - /!\ NOT BLOCK STATE
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
wrapper.set(Type.VAR_INT, 0, Protocol1_14To1_13_2.getNewBlockId(wrapper.get(Type.VAR_INT, 0)));
}
});
}
});
// Block Change
protocol.registerOutgoing(State.PLAY, 0xB, 0xB, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.POSITION, Type.POSITION1_14);
map(Type.VAR_INT);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int id = wrapper.get(Type.VAR_INT, 0);
wrapper.set(Type.VAR_INT, 0, Protocol1_14To1_13_2.getNewBlockStateId(id));
}
});
}
});
// Multi Block Change
protocol.registerOutgoing(State.PLAY, 0xF, 0xF, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.INT); // 0 - Chunk X
map(Type.INT); // 1 - Chunk Z
map(Type.BLOCK_CHANGE_RECORD_ARRAY); // 2 - Records
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
// Convert ids
for (BlockChangeRecord record : wrapper.get(Type.BLOCK_CHANGE_RECORD_ARRAY, 0)) {
int id = record.getBlockId();
record.setBlockId(Protocol1_14To1_13_2.getNewBlockStateId(id));
}
}
});
}
});
//Chunk
protocol.registerOutgoing(State.PLAY, 0x22, 0x22, new PacketRemapper() {
@Override
@ -98,66 +170,12 @@ public class WorldPackets {
}
});
// Block Action
protocol.registerOutgoing(State.PLAY, 0x0A, 0x0A, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.POSITION); // Location
map(Type.UNSIGNED_BYTE); // Action id
map(Type.UNSIGNED_BYTE); // Action param
map(Type.VAR_INT); // Block id - /!\ NOT BLOCK STATE
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
wrapper.set(Type.VAR_INT, 0, Protocol1_14To1_13_2.getNewBlockId(wrapper.get(Type.VAR_INT, 0)));
}
});
}
});
// Block Change
protocol.registerOutgoing(State.PLAY, 0xB, 0xB, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.POSITION);
map(Type.VAR_INT);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int id = wrapper.get(Type.VAR_INT, 0);
wrapper.set(Type.VAR_INT, 0, Protocol1_14To1_13_2.getNewBlockStateId(id));
}
});
}
});
// Multi Block Change
protocol.registerOutgoing(State.PLAY, 0xF, 0xF, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.INT); // 0 - Chunk X
map(Type.INT); // 1 - Chunk Z
map(Type.BLOCK_CHANGE_RECORD_ARRAY); // 2 - Records
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
// Convert ids
for (BlockChangeRecord record : wrapper.get(Type.BLOCK_CHANGE_RECORD_ARRAY, 0)) {
int id = record.getBlockId();
record.setBlockId(Protocol1_14To1_13_2.getNewBlockStateId(id));
}
}
});
}
});
// Effect packet
protocol.registerOutgoing(State.PLAY, 0x23, 0x23, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.INT); // Effect Id
map(Type.POSITION); // Location
map(Type.POSITION, Type.POSITION1_14); // Location
map(Type.INT); // Data
handler(new PacketHandler() {
@Override
@ -174,6 +192,35 @@ public class WorldPackets {
}
});
//spawn particle
protocol.registerOutgoing(State.PLAY, 0x24, 0x24, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.INT); // 0 - Particle ID
map(Type.BOOLEAN); // 1 - Long Distance
map(Type.FLOAT); // 2 - X
map(Type.FLOAT); // 3 - Y
map(Type.FLOAT); // 4 - Z
map(Type.FLOAT); // 5 - Offset X
map(Type.FLOAT); // 6 - Offset Y
map(Type.FLOAT); // 7 - Offset Z
map(Type.FLOAT); // 8 - Particle Data
map(Type.INT); // 9 - Particle Count
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int id = wrapper.get(Type.INT, 0);
if (id == 3 || id == 20) {
int data = wrapper.passthrough(Type.VAR_INT);
wrapper.set(Type.VAR_INT, 0, Protocol1_14To1_13_2.getNewBlockStateId(data));
} else if (id == 27) {
InventoryPackets.toClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM));
}
}
});
}
});
//join game
protocol.registerOutgoing(State.PLAY, 0x25, 0x25, new PacketRemapper() {
@Override
@ -210,32 +257,11 @@ public class WorldPackets {
}
});
//spawn particle
protocol.registerOutgoing(State.PLAY, 0x24, 0x24, new PacketRemapper() {
// Spawn position
protocol.registerOutgoing(State.PLAY, 0x49, 0x49, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.INT); // 0 - Particle ID
map(Type.BOOLEAN); // 1 - Long Distance
map(Type.FLOAT); // 2 - X
map(Type.FLOAT); // 3 - Y
map(Type.FLOAT); // 4 - Z
map(Type.FLOAT); // 5 - Offset X
map(Type.FLOAT); // 6 - Offset Y
map(Type.FLOAT); // 7 - Offset Z
map(Type.FLOAT); // 8 - Particle Data
map(Type.INT); // 9 - Particle Count
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int id = wrapper.get(Type.INT, 0);
if (id == 3 || id == 20) {
int data = wrapper.passthrough(Type.VAR_INT);
wrapper.set(Type.VAR_INT, 0, Protocol1_14To1_13_2.getNewBlockStateId(data));
} else if (id == 27) {
InventoryPackets.toClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM));
}
}
});
map(Type.POSITION, Type.POSITION1_14);
}
});
}