3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-27 08:30:09 +01:00

1.13.2-pre1 support

Dieser Commit ist enthalten in:
Gerrygames 2018-10-17 15:38:59 +02:00
Ursprung 8bfcc550f7
Commit 5cecfd14d9
14 geänderte Dateien mit 604 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,37 @@
package us.myles.ViaVersion.api.minecraft.metadata.types;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import us.myles.ViaVersion.api.minecraft.metadata.MetaType;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.protocols.protocol1_13_2to1_13_1.Protocol1_13_2To1_13_1;
@RequiredArgsConstructor
@Getter
public enum MetaType1_13_2 implements MetaType {
Byte(0, Type.BYTE),
VarInt(1, Type.VAR_INT),
Float(2, Type.FLOAT),
String(3, Type.STRING),
Chat(4, Type.STRING),
OptChat(5, Type.OPTIONAL_CHAT),
Slot(6, Type.FLAT_VAR_INT_ITEM),
Boolean(7, Type.BOOLEAN),
Vector3F(8, Type.ROTATION),
Position(9, Type.POSITION),
OptPosition(10, Type.OPTIONAL_POSITION),
Direction(11, Type.VAR_INT),
OptUUID(12, Type.OPTIONAL_UUID),
BlockID(13, Type.VAR_INT),
NBTTag(14, Type.NBT),
PARTICLE(15, Protocol1_13_2To1_13_1.PARTICLE_TYPE),
Discontinued(99, null);
private final int typeID;
private final Type type;
public static MetaType1_13_2 byId(int id) {
return values()[id];
}
}

Datei anzeigen

@ -13,6 +13,7 @@ import us.myles.ViaVersion.protocols.protocol1_11to1_10.Protocol1_11To1_10;
import us.myles.ViaVersion.protocols.protocol1_12_1to1_12.Protocol1_12_1TO1_12; import us.myles.ViaVersion.protocols.protocol1_12_1to1_12.Protocol1_12_1TO1_12;
import us.myles.ViaVersion.protocols.protocol1_12_2to1_12_1.Protocol1_12_2TO1_12_1; import us.myles.ViaVersion.protocols.protocol1_12_2to1_12_1.Protocol1_12_2TO1_12_1;
import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.Protocol1_12To1_11_1; import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.Protocol1_12To1_11_1;
import us.myles.ViaVersion.protocols.protocol1_13_2to1_13_1.Protocol1_13_2To1_13_1;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2;
import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.Protocol1_9_1_2TO1_9_3_4; import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.Protocol1_9_1_2TO1_9_3_4;
import us.myles.ViaVersion.protocols.protocol1_9_1to1_9.Protocol1_9_1TO1_9; import us.myles.ViaVersion.protocols.protocol1_9_1to1_9.Protocol1_9_1TO1_9;
@ -57,6 +58,7 @@ public class ProtocolRegistry {
registerProtocol(new Protocol1_13To1_12_2(), Collections.singletonList(ProtocolVersion.v1_13.getId()), ProtocolVersion.v1_12_2.getId()); registerProtocol(new Protocol1_13To1_12_2(), Collections.singletonList(ProtocolVersion.v1_13.getId()), ProtocolVersion.v1_12_2.getId());
registerProtocol(new Protocol1_13_1To1_13(), Arrays.asList(ProtocolVersion.v1_13_1.getId()), ProtocolVersion.v1_13.getId()); registerProtocol(new Protocol1_13_1To1_13(), Arrays.asList(ProtocolVersion.v1_13_1.getId()), ProtocolVersion.v1_13.getId());
registerProtocol(new Protocol1_13_2To1_13_1(), Arrays.asList(ProtocolVersion.v1_13_2.getId()), ProtocolVersion.v1_13_1.getId());
} }
/** /**

Datei anzeigen

@ -34,6 +34,7 @@ public class ProtocolVersion {
public static final ProtocolVersion v1_12_2; public static final ProtocolVersion v1_12_2;
public static final ProtocolVersion v1_13; public static final ProtocolVersion v1_13;
public static final ProtocolVersion v1_13_1; public static final ProtocolVersion v1_13_1;
public static final ProtocolVersion v1_13_2;
public static final ProtocolVersion unknown; public static final ProtocolVersion unknown;
private final int id; private final int id;
@ -64,6 +65,7 @@ public class ProtocolVersion {
register(v1_12_2 = new ProtocolVersion(340, "1.12.2")); register(v1_12_2 = new ProtocolVersion(340, "1.12.2"));
register(v1_13 = new ProtocolVersion(393, "1.13")); register(v1_13 = new ProtocolVersion(393, "1.13"));
register(v1_13_1 = new ProtocolVersion(401, "1.13.1")); register(v1_13_1 = new ProtocolVersion(401, "1.13.1"));
register(v1_13_2 = new ProtocolVersion(402, "1.13.2"));
register(unknown = new ProtocolVersion(-1, "UNKNOWN")); register(unknown = new ProtocolVersion(-1, "UNKNOWN"));
} }

Datei anzeigen

@ -76,8 +76,11 @@ public abstract class Type<T> implements ByteBufReader<T>, ByteBufWriter<T> {
/* 1.13 Flat Item (no data) */ /* 1.13 Flat Item (no data) */
public static final Type<Item> FLAT_ITEM = new FlatItemType(); public static final Type<Item> FLAT_ITEM = new FlatItemType();
public static final Type<Item> FLAT_VAR_INT_ITEM = new FlatVarIntItemType();
public static final Type<Item[]> FLAT_ITEM_ARRAY = new FlatItemArrayType(); public static final Type<Item[]> FLAT_ITEM_ARRAY = new FlatItemArrayType();
public static final Type<Item[]> FLAT_VAR_INT_ITEM_ARRAY = new FlatVarIntItemArrayType();
public static final Type<Item[]> FLAT_ITEM_ARRAY_VAR_INT = new ArrayType<>(FLAT_ITEM); public static final Type<Item[]> FLAT_ITEM_ARRAY_VAR_INT = new ArrayType<>(FLAT_ITEM);
public static final Type<Item[]> FLAT_VAR_INT_ITEM_ARRAY_VAR_INT = new ArrayType<>(FLAT_VAR_INT_ITEM);
/* Actual Class */ /* Actual Class */

Datei anzeigen

@ -0,0 +1,30 @@
package us.myles.ViaVersion.api.type.types.minecraft;
import io.netty.buffer.ByteBuf;
import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.type.Type;
public class FlatVarIntItemArrayType extends BaseItemArrayType {
public FlatVarIntItemArrayType() {
super("Flat Item Array");
}
@Override
public Item[] read(ByteBuf buffer) throws Exception {
int amount = Type.SHORT.read(buffer);
Item[] array = new Item[amount];
for (int i = 0; i < amount; i++) {
array[i] = Type.FLAT_VAR_INT_ITEM.read(buffer);
}
return array;
}
@Override
public void write(ByteBuf buffer, Item[] object) throws Exception {
Type.SHORT.write(buffer, (short) object.length);
for (Item o : object) {
Type.FLAT_VAR_INT_ITEM.write(buffer, o);
}
}
}

Datei anzeigen

@ -0,0 +1,37 @@
package us.myles.ViaVersion.api.type.types.minecraft;
import io.netty.buffer.ByteBuf;
import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.type.Type;
public class FlatVarIntItemType extends BaseItemType {
public FlatVarIntItemType() {
super("FlatVarIntItem");
}
@Override
public Item read(ByteBuf buffer) throws Exception {
boolean present = buffer.readBoolean();
if (!present) {
return null;
} else {
Item item = new Item();
item.setId(Type.VAR_INT.read(buffer).shortValue()); //TODO Maybe we should consider changing id field type to int
item.setAmount(buffer.readByte());
item.setTag(Type.NBT.read(buffer));
return item;
}
}
@Override
public void write(ByteBuf buffer, Item object) throws Exception {
if (object == null) {
buffer.writeBoolean(false);
} else {
buffer.writeBoolean(true);
Type.VAR_INT.write(buffer, (int) object.getId());
buffer.writeByte(object.getAmount());
Type.NBT.write(buffer, object.getTag());
}
}
}

Datei anzeigen

@ -0,0 +1,29 @@
package us.myles.ViaVersion.api.type.types.version;
import io.netty.buffer.ByteBuf;
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_13_2;
import us.myles.ViaVersion.api.type.types.minecraft.MetaTypeTemplate;
public class Metadata1_13_2Type extends MetaTypeTemplate {
@Override
public Metadata read(ByteBuf buffer) throws Exception {
short index = buffer.readUnsignedByte();
if (index == 0xff) return null; //End of metadata
MetaType1_13_2 type = MetaType1_13_2.byId(buffer.readByte());
return new Metadata(index, type, type.getType().read(buffer));
}
@Override
public void write(ByteBuf buffer, Metadata object) throws Exception {
if (object == null) {
buffer.writeByte(255);
} else {
buffer.writeByte(object.getId());
buffer.writeByte(object.getMetaType().getTypeID());
object.getMetaType().getType().write(buffer, object.getValue());
}
}
}

Datei anzeigen

@ -0,0 +1,32 @@
package us.myles.ViaVersion.api.type.types.version;
import io.netty.buffer.ByteBuf;
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
import us.myles.ViaVersion.api.type.types.minecraft.MetaListTypeTemplate;
import java.util.ArrayList;
import java.util.List;
public class MetadataList1_13_2Type extends MetaListTypeTemplate {
@Override
public List<Metadata> read(ByteBuf buffer) throws Exception {
List<Metadata> list = new ArrayList<>();
Metadata meta;
do {
meta = Types1_13_2.METADATA.read(buffer);
if (meta != null)
list.add(meta);
} while (meta != null);
return list;
}
@Override
public void write(ByteBuf buffer, List<Metadata> object) throws Exception {
for (Metadata m : object)
Types1_13_2.METADATA.write(buffer, m);
// Write end of list
Types1_13_2.METADATA.write(buffer, null);
}
}

Datei anzeigen

@ -0,0 +1,18 @@
package us.myles.ViaVersion.api.type.types.version;
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
import us.myles.ViaVersion.api.type.Type;
import java.util.List;
public class Types1_13_2 {
/**
* Metadata list type for 1.13
*/
public static final Type<List<Metadata>> METADATA_LIST = new MetadataList1_13_2Type();
/**
* Metadata type for 1.13
*/
public static final Type<Metadata> METADATA = new Metadata1_13_2Type();
}

Datei anzeigen

@ -0,0 +1,82 @@
package us.myles.ViaVersion.protocols.protocol1_13_2to1_13_1;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.remapper.PacketHandler;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State;
import us.myles.ViaVersion.protocols.protocol1_13_2to1_13_1.packets.EntityPackets;
import us.myles.ViaVersion.protocols.protocol1_13_2to1_13_1.packets.InventoryPackets;
import us.myles.ViaVersion.protocols.protocol1_13_2to1_13_1.packets.WorldPackets;
import us.myles.ViaVersion.protocols.protocol1_13_2to1_13_1.types.Particle1_13_2Type;
public class Protocol1_13_2To1_13_1 extends Protocol {
public static final Particle1_13_2Type PARTICLE_TYPE = new Particle1_13_2Type();
@Override
protected void registerPackets() {
InventoryPackets.register(this);
WorldPackets.register(this);
EntityPackets.register(this);
//Edit Book
registerIncoming(State.PLAY, 0x0B, 0x0B, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.FLAT_ITEM, Type.FLAT_VAR_INT_ITEM);
map(Type.BOOLEAN);
}
});
// Advancements
registerOutgoing(State.PLAY, 0x51, 0x51, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
wrapper.passthrough(Type.BOOLEAN); // Reset/clear
int size = wrapper.passthrough(Type.VAR_INT); // Mapping size
for (int i = 0; i < size; i++) {
wrapper.passthrough(Type.STRING); // Identifier
// Parent
if (wrapper.passthrough(Type.BOOLEAN))
wrapper.passthrough(Type.STRING);
// Display data
if (wrapper.passthrough(Type.BOOLEAN)) {
wrapper.passthrough(Type.STRING); // Title
wrapper.passthrough(Type.STRING); // Description
Item icon = wrapper.read(Type.FLAT_ITEM);
wrapper.write(Type.FLAT_VAR_INT_ITEM, icon);
wrapper.passthrough(Type.VAR_INT); // Frame type
int flags = wrapper.passthrough(Type.INT); // Flags
if ((flags & 1) != 0)
wrapper.passthrough(Type.STRING); // Background texture
wrapper.passthrough(Type.FLOAT); // X
wrapper.passthrough(Type.FLOAT); // Y
}
wrapper.passthrough(Type.STRING_ARRAY); // Criteria
int arrayLength = wrapper.passthrough(Type.VAR_INT);
for (int array = 0; array < arrayLength; array++) {
wrapper.passthrough(Type.STRING_ARRAY); // String array
}
}
}
});
}
});
}
@Override
public void init(UserConnection userConnection) {
}
}

Datei anzeigen

@ -0,0 +1,97 @@
package us.myles.ViaVersion.protocols.protocol1_13_2to1_13_1.packets;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_13;
import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_13_2;
import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.remapper.PacketHandler;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.api.type.types.version.Types1_13;
import us.myles.ViaVersion.api.type.types.version.Types1_13_2;
import us.myles.ViaVersion.packets.State;
public class EntityPackets {
public static void register(Protocol protocol) {
// Spawn mob packet
protocol.registerOutgoing(State.PLAY, 0x3, 0x3, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // 0 - Entity ID
map(Type.UUID); // 1 - Entity UUID
map(Type.VAR_INT); // 2 - Entity Type
map(Type.DOUBLE); // 3 - X
map(Type.DOUBLE); // 4 - Y
map(Type.DOUBLE); // 5 - Z
map(Type.BYTE); // 6 - Yaw
map(Type.BYTE); // 7 - Pitch
map(Type.BYTE); // 8 - Head Pitch
map(Type.SHORT); // 9 - Velocity X
map(Type.SHORT); // 10 - Velocity Y
map(Type.SHORT); // 11 - Velocity Z
map(Types1_13.METADATA_LIST, Types1_13_2.METADATA_LIST); // 12 - Metadata
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
for (Metadata metadata : wrapper.get(Types1_13_2.METADATA_LIST, 0)) {
if (metadata.getMetaType() == MetaType1_13.Slot) {
metadata.setMetaType(MetaType1_13_2.Slot);
}
}
}
});
}
});
// Spawn player packet
protocol.registerOutgoing(State.PLAY, 0x05, 0x05, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // 0 - Entity ID
map(Type.UUID); // 1 - Player UUID
map(Type.DOUBLE); // 2 - X
map(Type.DOUBLE); // 3 - Y
map(Type.DOUBLE); // 4 - Z
map(Type.BYTE); // 5 - Yaw
map(Type.BYTE); // 6 - Pitch
map(Types1_13.METADATA_LIST, Types1_13_2.METADATA_LIST); // 7 - Metadata
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
for (Metadata metadata : wrapper.get(Types1_13_2.METADATA_LIST, 0)) {
if (metadata.getMetaType() == MetaType1_13.Slot) {
metadata.setMetaType(MetaType1_13_2.Slot);
}
}
}
});
}
});
// Metadata packet
protocol.registerOutgoing(State.PLAY, 0x3F, 0x3F, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // 0 - Entity ID
map(Types1_13.METADATA_LIST, Types1_13_2.METADATA_LIST); // 1 - Metadata list
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
for (Metadata metadata : wrapper.get(Types1_13_2.METADATA_LIST, 0)) {
if (metadata.getMetaType() == MetaType1_13.Slot) {
metadata.setMetaType(MetaType1_13_2.Slot);
}
}
}
});
}
});
}
}

Datei anzeigen

@ -0,0 +1,151 @@
package us.myles.ViaVersion.protocols.protocol1_13_2to1_13_1.packets;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.remapper.PacketHandler;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State;
public class InventoryPackets {
public static void register(Protocol protocol) {
/*
Outgoing packets
*/
// Set slot packet
protocol.registerOutgoing(State.PLAY, 0x17, 0x17, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.BYTE); // 0 - Window ID
map(Type.SHORT); // 1 - Slot ID
map(Type.FLAT_ITEM, Type.FLAT_VAR_INT_ITEM); // 2 - Slot Value
}
});
// Window items packet
protocol.registerOutgoing(State.PLAY, 0x15, 0x15, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.UNSIGNED_BYTE); // 0 - Window ID
map(Type.FLAT_ITEM_ARRAY, Type.FLAT_VAR_INT_ITEM_ARRAY); // 1 - Window Values
}
});
// Plugin message
protocol.registerOutgoing(State.PLAY, 0x19, 0x19, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.STRING); // Channel
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
String channel = wrapper.get(Type.STRING, 0);
if (channel.equals("minecraft:trader_list") || channel.equals("trader_list")) {
wrapper.passthrough(Type.INT); // Passthrough Window ID
int size = wrapper.passthrough(Type.UNSIGNED_BYTE);
for (int i = 0; i < size; i++) {
// Input Item
wrapper.write(Type.FLAT_VAR_INT_ITEM, wrapper.read(Type.FLAT_ITEM));
// Output Item
wrapper.write(Type.FLAT_VAR_INT_ITEM, wrapper.read(Type.FLAT_ITEM));
boolean secondItem = wrapper.passthrough(Type.BOOLEAN); // Has second item
if (secondItem) {
wrapper.write(Type.FLAT_VAR_INT_ITEM, wrapper.read(Type.FLAT_ITEM));
}
wrapper.passthrough(Type.BOOLEAN); // Trade disabled
wrapper.passthrough(Type.INT); // Number of tools uses
wrapper.passthrough(Type.INT); // Maximum number of trade uses
}
}
}
});
}
});
// Entity Equipment Packet
protocol.registerOutgoing(State.PLAY, 0x42, 0x42, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // 0 - Entity ID
map(Type.VAR_INT); // 1 - Slot ID
map(Type.FLAT_ITEM, Type.FLAT_VAR_INT_ITEM); // 2 - Item
}
});
// Declare Recipes
protocol.registerOutgoing(State.PLAY, 0x54, 0x54, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int recipesNo = wrapper.passthrough(Type.VAR_INT);
for (int i = 0; i < recipesNo; i++) {
wrapper.passthrough(Type.STRING); // Id
String type = wrapper.passthrough(Type.STRING);
if (type.equals("crafting_shapeless")) {
wrapper.passthrough(Type.STRING); // Group
int ingredientsNo = wrapper.passthrough(Type.VAR_INT);
for (int i1 = 0; i1 < ingredientsNo; i1++) {
wrapper.write(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT, wrapper.read(Type.FLAT_ITEM_ARRAY_VAR_INT));
}
wrapper.write(Type.FLAT_VAR_INT_ITEM, wrapper.read(Type.FLAT_ITEM));
} 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 i1 = 0; i1 < ingredientsNo; i1++) {
wrapper.write(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT, wrapper.read(Type.FLAT_ITEM_ARRAY_VAR_INT));
}
wrapper.write(Type.FLAT_VAR_INT_ITEM, wrapper.read(Type.FLAT_ITEM));
} else if (type.equals("smelting")) {
wrapper.passthrough(Type.STRING); // Group
// Ingredient start
wrapper.write(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT, wrapper.read(Type.FLAT_ITEM_ARRAY_VAR_INT));
// Ingredient end
wrapper.write(Type.FLAT_VAR_INT_ITEM, wrapper.read(Type.FLAT_ITEM));
wrapper.passthrough(Type.FLOAT); // EXP
wrapper.passthrough(Type.VAR_INT); // Cooking time
}
}
}
});
}
});
/*
Incoming packets
*/
// Click window packet
protocol.registerIncoming(State.PLAY, 0x08, 0x08, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.UNSIGNED_BYTE); // 0 - Window ID
map(Type.SHORT); // 1 - Slot
map(Type.BYTE); // 2 - Button
map(Type.SHORT); // 3 - Action number
map(Type.VAR_INT); // 4 - Mode
map(Type.FLAT_VAR_INT_ITEM, Type.FLAT_ITEM); // 5 - Clicked Item
}
}
);
// Creative Inventory Action
protocol.registerIncoming(State.PLAY, 0x24, 0x24, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.SHORT); // 0 - Slot
map(Type.FLAT_VAR_INT_ITEM, Type.FLAT_ITEM); // 1 - Clicked Item
}
}
);
}
}

Datei anzeigen

@ -0,0 +1,40 @@
package us.myles.ViaVersion.protocols.protocol1_13_2to1_13_1.packets;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.remapper.PacketHandler;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State;
public class WorldPackets {
public static void register(Protocol protocol) {
//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 == 27) {
wrapper.write(Type.FLAT_VAR_INT_ITEM, wrapper.read(Type.FLAT_ITEM));
}
}
});
}
});
}
}

Datei anzeigen

@ -0,0 +1,44 @@
package us.myles.ViaVersion.protocols.protocol1_13_2to1_13_1.types;
import io.netty.buffer.ByteBuf;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.Particle;
public class Particle1_13_2Type extends Type<Particle> {
public Particle1_13_2Type() {
super("Particle", Particle.class);
}
@Override
public void write(ByteBuf buffer, Particle object) throws Exception {
Type.VAR_INT.write(buffer, object.getId());
for (Particle.ParticleData data : object.getArguments())
data.getType().write(buffer, data.getValue());
}
@Override
public Particle read(ByteBuf buffer) throws Exception {
int type = Type.VAR_INT.read(buffer);
Particle particle = new Particle(type);
switch (type) {
// Block / Falling Dust /
case 3:
case 20:
particle.getArguments().add(new Particle.ParticleData(Type.VAR_INT, Type.VAR_INT.read(buffer))); // Flat Block
break;
// Dust
case 11:
particle.getArguments().add(new Particle.ParticleData(Type.FLOAT, Type.FLOAT.read(buffer))); // Red 0 - 1
particle.getArguments().add(new Particle.ParticleData(Type.FLOAT, Type.FLOAT.read(buffer))); // Green 0 - 1
particle.getArguments().add(new Particle.ParticleData(Type.FLOAT, Type.FLOAT.read(buffer))); // Blue 0 - 1
particle.getArguments().add(new Particle.ParticleData(Type.FLOAT, Type.FLOAT.read(buffer)));// Scale 0.01 - 4
break;
// Item
case 27:
particle.getArguments().add(new Particle.ParticleData(Type.FLAT_VAR_INT_ITEM, Type.FLAT_VAR_INT_ITEM.read(buffer))); // Flat item
break;
}
return particle;
}
}