Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-26 16:12:42 +01:00
API: Work towards rewriting metadata, (This is nowhere near finished and I need to work on Item and NBT), Also change the names of a few classes to be more appropriate and implement transformation of the doubles.
(I probably messed up somewhere, nothing is tested as this is essentially API design)
Dieser Commit ist enthalten in:
Ursprung
7cff20f218
Commit
e19a2920b9
15
src/main/java/us/myles/ViaVersion2/api/metadata/Metadata.java
Normale Datei
15
src/main/java/us/myles/ViaVersion2/api/metadata/Metadata.java
Normale Datei
@ -0,0 +1,15 @@
|
|||||||
|
package us.myles.ViaVersion2.api.metadata;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import us.myles.ViaVersion2.api.type.Type;
|
||||||
|
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class Metadata {
|
||||||
|
private final int id;
|
||||||
|
private Type type;
|
||||||
|
private Object value;
|
||||||
|
}
|
@ -1,11 +1,21 @@
|
|||||||
package us.myles.ViaVersion2.api.protocol1_9to1_8;
|
package us.myles.ViaVersion2.api.protocol1_9to1_8;
|
||||||
|
|
||||||
import us.myles.ViaVersion2.api.data.UserConnection;
|
import us.myles.ViaVersion2.api.data.UserConnection;
|
||||||
|
import us.myles.ViaVersion2.api.metadata.Metadata;
|
||||||
import us.myles.ViaVersion2.api.protocol.Protocol;
|
import us.myles.ViaVersion2.api.protocol.Protocol;
|
||||||
import us.myles.ViaVersion2.api.protocol1_9to1_8.packets.SpawnPackets;
|
import us.myles.ViaVersion2.api.protocol1_9to1_8.packets.SpawnPackets;
|
||||||
import us.myles.ViaVersion2.api.protocol1_9to1_8.storage.EntityTracker;
|
import us.myles.ViaVersion2.api.protocol1_9to1_8.storage.EntityTracker;
|
||||||
|
import us.myles.ViaVersion2.api.protocol1_9to1_8.types.MetadataListType;
|
||||||
|
import us.myles.ViaVersion2.api.protocol1_9to1_8.types.MetadataType;
|
||||||
|
import us.myles.ViaVersion2.api.type.Type;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class Protocol1_9TO1_8 extends Protocol {
|
public class Protocol1_9TO1_8 extends Protocol {
|
||||||
|
public static Type<List<Metadata>> METADATA_LIST = new MetadataListType();
|
||||||
|
|
||||||
|
public static Type<Metadata> METADATA = new MetadataType();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerPackets() {
|
public void registerPackets() {
|
||||||
// Example PLAY_SPAWN_OBJECT(State.PLAY, Direction.OUTGOING, 0x0E, 0x00),
|
// Example PLAY_SPAWN_OBJECT(State.PLAY, Direction.OUTGOING, 0x0E, 0x00),
|
||||||
|
@ -3,12 +3,21 @@ package us.myles.ViaVersion2.api.protocol1_9to1_8.packets;
|
|||||||
import us.myles.ViaVersion.packets.State;
|
import us.myles.ViaVersion.packets.State;
|
||||||
import us.myles.ViaVersion2.api.PacketWrapper;
|
import us.myles.ViaVersion2.api.PacketWrapper;
|
||||||
import us.myles.ViaVersion2.api.protocol.Protocol;
|
import us.myles.ViaVersion2.api.protocol.Protocol;
|
||||||
|
import us.myles.ViaVersion2.api.protocol1_9to1_8.Protocol1_9TO1_8;
|
||||||
import us.myles.ViaVersion2.api.protocol1_9to1_8.storage.EntityTracker;
|
import us.myles.ViaVersion2.api.protocol1_9to1_8.storage.EntityTracker;
|
||||||
import us.myles.ViaVersion2.api.remapper.PacketRemapper;
|
import us.myles.ViaVersion2.api.remapper.PacketRemapper;
|
||||||
import us.myles.ViaVersion2.api.remapper.ValueCreator;
|
import us.myles.ViaVersion2.api.remapper.ValueCreator;
|
||||||
|
import us.myles.ViaVersion2.api.remapper.ValueTransformer;
|
||||||
import us.myles.ViaVersion2.api.type.Type;
|
import us.myles.ViaVersion2.api.type.Type;
|
||||||
|
|
||||||
public class SpawnPackets {
|
public class SpawnPackets {
|
||||||
|
private static ValueTransformer<Integer, Double> toNewDouble = new ValueTransformer<Integer, Double>(Type.DOUBLE) {
|
||||||
|
@Override
|
||||||
|
public Double transform(PacketWrapper wrapper, Integer inputValue) {
|
||||||
|
return inputValue / 32D;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
public static void register(Protocol protocol) {
|
public static void register(Protocol protocol) {
|
||||||
// Spawn Object Packet
|
// Spawn Object Packet
|
||||||
protocol.registerOutgoing(State.PLAY, 0x0E, 0x00, new PacketRemapper() {
|
protocol.registerOutgoing(State.PLAY, 0x0E, 0x00, new PacketRemapper() {
|
||||||
@ -26,9 +35,9 @@ public class SpawnPackets {
|
|||||||
});
|
});
|
||||||
map(Type.BYTE); // 2 - Type
|
map(Type.BYTE); // 2 - Type
|
||||||
|
|
||||||
map(Type.INT, Type.DOUBLE); // 3 - X - Needs to be divide by 32
|
map(Type.INT, toNewDouble); // 3 - X - Needs to be divide by 32
|
||||||
map(Type.INT, Type.DOUBLE); // 4 - Y - Needs to be divide by 32
|
map(Type.INT, toNewDouble); // 4 - Y - Needs to be divide by 32
|
||||||
map(Type.INT, Type.DOUBLE); // 5 - Z - Needs to be divide by 32
|
map(Type.INT, toNewDouble); // 5 - Z - Needs to be divide by 32
|
||||||
|
|
||||||
map(Type.BYTE); // 6 - Pitch
|
map(Type.BYTE); // 6 - Pitch
|
||||||
map(Type.BYTE); // 7 - Yaw
|
map(Type.BYTE); // 7 - Yaw
|
||||||
@ -63,9 +72,9 @@ public class SpawnPackets {
|
|||||||
public void registerMap() {
|
public void registerMap() {
|
||||||
map(Type.VAR_INT); // 0 - Entity ID
|
map(Type.VAR_INT); // 0 - Entity ID
|
||||||
|
|
||||||
map(Type.INT, Type.DOUBLE); // 1 - X - Needs to be divide by 32
|
map(Type.INT, toNewDouble); // 1 - X - Needs to be divide by 32
|
||||||
map(Type.INT, Type.DOUBLE); // 2 - Y - Needs to be divide by 32
|
map(Type.INT, toNewDouble); // 2 - Y - Needs to be divide by 32
|
||||||
map(Type.INT, Type.DOUBLE); // 3 - Z - Needs to be divide by 32
|
map(Type.INT, toNewDouble); // 3 - Z - Needs to be divide by 32
|
||||||
|
|
||||||
map(Type.INT); // 4 - Data
|
map(Type.INT); // 4 - Data
|
||||||
}
|
}
|
||||||
@ -78,9 +87,9 @@ public class SpawnPackets {
|
|||||||
map(Type.VAR_INT); // 0 - Entity ID
|
map(Type.VAR_INT); // 0 - Entity ID
|
||||||
map(Type.BYTE); // 1 - Type
|
map(Type.BYTE); // 1 - Type
|
||||||
|
|
||||||
map(Type.INT, Type.DOUBLE); // 2 - X - Needs to be divide by 32
|
map(Type.INT, toNewDouble); // 2 - X - Needs to be divide by 32
|
||||||
map(Type.INT, Type.DOUBLE); // 3 - Y - Needs to be divide by 32
|
map(Type.INT, toNewDouble); // 3 - Y - Needs to be divide by 32
|
||||||
map(Type.INT, Type.DOUBLE); // 4 - Z - Needs to be divide by 32
|
map(Type.INT, toNewDouble); // 4 - Z - Needs to be divide by 32
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -100,9 +109,9 @@ public class SpawnPackets {
|
|||||||
});
|
});
|
||||||
map(Type.UNSIGNED_BYTE); // 2 - Type
|
map(Type.UNSIGNED_BYTE); // 2 - Type
|
||||||
|
|
||||||
map(Type.INT, Type.DOUBLE); // 3 - X - Needs to be divide by 32
|
map(Type.INT, toNewDouble); // 3 - X - Needs to be divide by 32
|
||||||
map(Type.INT, Type.DOUBLE); // 4 - Y - Needs to be divide by 32
|
map(Type.INT, toNewDouble); // 4 - Y - Needs to be divide by 32
|
||||||
map(Type.INT, Type.DOUBLE); // 5 - Z - Needs to be divide by 32
|
map(Type.INT, toNewDouble); // 5 - Z - Needs to be divide by 32
|
||||||
|
|
||||||
map(Type.BYTE); // 6 - Yaw
|
map(Type.BYTE); // 6 - Yaw
|
||||||
map(Type.BYTE); // 7 - Pitch
|
map(Type.BYTE); // 7 - Pitch
|
||||||
@ -112,7 +121,8 @@ public class SpawnPackets {
|
|||||||
map(Type.SHORT); // 10 - Velocity Y
|
map(Type.SHORT); // 10 - Velocity Y
|
||||||
map(Type.SHORT); // 11 - Velocity Z
|
map(Type.SHORT); // 11 - Velocity Z
|
||||||
|
|
||||||
// TODO Read Metadata
|
// TODO Rewrite Metadata
|
||||||
|
map(Protocol1_9TO1_8.METADATA_LIST);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -145,16 +155,17 @@ public class SpawnPackets {
|
|||||||
map(Type.VAR_INT); // 0 - Entity ID
|
map(Type.VAR_INT); // 0 - Entity ID
|
||||||
map(Type.UUID); // 1 - Player UUID
|
map(Type.UUID); // 1 - Player UUID
|
||||||
|
|
||||||
map(Type.INT, Type.DOUBLE); // 2 - X - Needs to be divide by 32
|
map(Type.INT, toNewDouble); // 2 - X - Needs to be divide by 32
|
||||||
map(Type.INT, Type.DOUBLE); // 3 - Y - Needs to be divide by 32
|
map(Type.INT, toNewDouble); // 3 - Y - Needs to be divide by 32
|
||||||
map(Type.INT, Type.DOUBLE); // 4 - Z - Needs to be divide by 32
|
map(Type.INT, toNewDouble); // 4 - Z - Needs to be divide by 32
|
||||||
|
|
||||||
map(Type.BYTE); // 5 - Yaw
|
map(Type.BYTE); // 5 - Yaw
|
||||||
map(Type.BYTE); // 6 - Pitch
|
map(Type.BYTE); // 6 - Pitch
|
||||||
|
|
||||||
map(Type.SHORT, Type.NOTHING); // Current Item is discontinued
|
map(Type.SHORT, Type.NOTHING); // Current Item is discontinued
|
||||||
|
|
||||||
// TODO Read Metadata
|
// TODO Rewrite Metadata
|
||||||
|
map(Protocol1_9TO1_8.METADATA_LIST);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,38 @@
|
|||||||
|
package us.myles.ViaVersion2.api.protocol1_9to1_8.types;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import us.myles.ViaVersion2.api.metadata.Metadata;
|
||||||
|
import us.myles.ViaVersion2.api.protocol1_9to1_8.Protocol1_9TO1_8;
|
||||||
|
import us.myles.ViaVersion2.api.type.Type;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class MetadataListType extends Type<List<Metadata>> {
|
||||||
|
public MetadataListType() {
|
||||||
|
super(List.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Metadata> read(ByteBuf buffer) {
|
||||||
|
List<Metadata> list = new ArrayList<>();
|
||||||
|
Metadata m;
|
||||||
|
do {
|
||||||
|
m = Protocol1_9TO1_8.METADATA.read(buffer);
|
||||||
|
if (m != null) {
|
||||||
|
list.add(m);
|
||||||
|
}
|
||||||
|
} while (m != null);
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(ByteBuf buffer, List<Metadata> object) {
|
||||||
|
for(Metadata m:object){
|
||||||
|
Protocol1_9TO1_8.METADATA.write(buffer, m);
|
||||||
|
}
|
||||||
|
// Write end of list
|
||||||
|
Protocol1_9TO1_8.METADATA.write(buffer, null);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
package us.myles.ViaVersion2.api.protocol1_9to1_8.types;
|
||||||
|
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import us.myles.ViaVersion2.api.metadata.Metadata;
|
||||||
|
import us.myles.ViaVersion2.api.type.Type;
|
||||||
|
|
||||||
|
public class MetadataType extends Type<Metadata> {
|
||||||
|
|
||||||
|
public MetadataType() {
|
||||||
|
super(Metadata.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Metadata read(ByteBuf buffer) {
|
||||||
|
byte item = buffer.readByte();
|
||||||
|
if (item == 127) return null; // end of metadata
|
||||||
|
MetadataTypes type = MetadataTypes.byId((item & 0xE0) >> 5);
|
||||||
|
int id = item & 0x1F;
|
||||||
|
return new Metadata(id, type.getType(), type.getType().read(buffer));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(ByteBuf buffer, Metadata object) {
|
||||||
|
if (object == null) {
|
||||||
|
buffer.writeByte(127);
|
||||||
|
} else {
|
||||||
|
buffer.writeByte(object.getId());
|
||||||
|
object.getType().write(buffer, object.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
package us.myles.ViaVersion2.api.protocol1_9to1_8.types;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import us.myles.ViaVersion2.api.type.Type;
|
||||||
|
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Getter
|
||||||
|
public enum MetadataTypes {
|
||||||
|
Byte(0, Type.BYTE),
|
||||||
|
Short(1, Type.SHORT),
|
||||||
|
Int(2, Type.INT),
|
||||||
|
Float(3, Type.FLOAT),
|
||||||
|
String(4, Type.STRING),
|
||||||
|
Slot(5, Type.ITEM),
|
||||||
|
Position(6, Type.VECTOR),
|
||||||
|
Rotation(7, Type.ROTATION),
|
||||||
|
NonExistent(-1, Type.NOTHING);
|
||||||
|
|
||||||
|
private final int typeID;
|
||||||
|
private final Type type;
|
||||||
|
|
||||||
|
public static MetadataTypes byId(int id) {
|
||||||
|
return values()[id];
|
||||||
|
}
|
||||||
|
}
|
@ -1,14 +1,14 @@
|
|||||||
package us.myles.ViaVersion2.api.remapper;
|
package us.myles.ViaVersion2.api.remapper;
|
||||||
|
|
||||||
import us.myles.ViaVersion2.api.PacketWrapper;
|
import us.myles.ViaVersion2.api.PacketWrapper;
|
||||||
import us.myles.ViaVersion2.api.util.Pair;
|
|
||||||
import us.myles.ViaVersion2.api.type.Type;
|
import us.myles.ViaVersion2.api.type.Type;
|
||||||
|
import us.myles.ViaVersion2.api.util.Pair;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public abstract class PacketRemapper {
|
public abstract class PacketRemapper {
|
||||||
private List<Pair<ValueReader, ValueTransformer>> valueRemappers = new ArrayList<>();
|
private List<Pair<ValueReader, ValueWriter>> valueRemappers = new ArrayList<>();
|
||||||
|
|
||||||
public PacketRemapper() {
|
public PacketRemapper() {
|
||||||
registerMap();
|
registerMap();
|
||||||
@ -23,8 +23,12 @@ public abstract class PacketRemapper {
|
|||||||
map(new TypeRemapper(oldType), new TypeRemapper(newType));
|
map(new TypeRemapper(oldType), new TypeRemapper(newType));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T> void map(ValueReader<T> inputRemapper, ValueTransformer<T> outputRemapper) {
|
public <T1, T2> void map(Type<T1> oldType, ValueTransformer<T1, T2> transformer) {
|
||||||
valueRemappers.add(new Pair<ValueReader, ValueTransformer>(inputRemapper, outputRemapper));
|
map(new TypeRemapper(oldType), transformer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> void map(ValueReader<T> inputReader, ValueWriter<T> outputWriter) {
|
||||||
|
valueRemappers.add(new Pair<ValueReader, ValueWriter>(inputReader, outputWriter));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void create(ValueCreator transformer) {
|
public void create(ValueCreator transformer) {
|
||||||
@ -35,7 +39,7 @@ public abstract class PacketRemapper {
|
|||||||
|
|
||||||
public void remap(PacketWrapper packetWrapper) {
|
public void remap(PacketWrapper packetWrapper) {
|
||||||
// Read all the current values
|
// Read all the current values
|
||||||
for(Pair<ValueReader, ValueTransformer> valueRemapper : valueRemappers){
|
for (Pair<ValueReader, ValueWriter> valueRemapper : valueRemappers) {
|
||||||
Object object = valueRemapper.getKey().read(packetWrapper);
|
Object object = valueRemapper.getKey().read(packetWrapper);
|
||||||
// Convert object to write type :O!!!
|
// Convert object to write type :O!!!
|
||||||
// TODO: Data converter lol
|
// TODO: Data converter lol
|
||||||
|
@ -3,7 +3,7 @@ package us.myles.ViaVersion2.api.remapper;
|
|||||||
import us.myles.ViaVersion2.api.PacketWrapper;
|
import us.myles.ViaVersion2.api.PacketWrapper;
|
||||||
import us.myles.ViaVersion2.api.type.Type;
|
import us.myles.ViaVersion2.api.type.Type;
|
||||||
|
|
||||||
public class TypeRemapper<T> implements ValueReader<T>, ValueTransformer<T> {
|
public class TypeRemapper<T> implements ValueReader<T>, ValueWriter<T> {
|
||||||
private final Type<T> type;
|
private final Type<T> type;
|
||||||
|
|
||||||
public TypeRemapper(Type<T> type) {
|
public TypeRemapper(Type<T> type) {
|
||||||
|
@ -2,7 +2,7 @@ package us.myles.ViaVersion2.api.remapper;
|
|||||||
|
|
||||||
import us.myles.ViaVersion2.api.PacketWrapper;
|
import us.myles.ViaVersion2.api.PacketWrapper;
|
||||||
|
|
||||||
public abstract class ValueCreator implements ValueTransformer{
|
public abstract class ValueCreator implements ValueWriter {
|
||||||
public abstract void write(PacketWrapper wrapper);
|
public abstract void write(PacketWrapper wrapper);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,7 +1,19 @@
|
|||||||
package us.myles.ViaVersion2.api.remapper;
|
package us.myles.ViaVersion2.api.remapper;
|
||||||
|
|
||||||
import us.myles.ViaVersion2.api.PacketWrapper;
|
import us.myles.ViaVersion2.api.PacketWrapper;
|
||||||
|
import us.myles.ViaVersion2.api.type.Type;
|
||||||
|
|
||||||
public interface ValueTransformer<T> {
|
public abstract class ValueTransformer<T1, T2> implements ValueWriter<T1> {
|
||||||
public void write(PacketWrapper writer, T inputValue);
|
private final Type<T2> outputType;
|
||||||
|
|
||||||
|
public ValueTransformer(Type<T2> outputType) {
|
||||||
|
this.outputType = outputType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract T2 transform(PacketWrapper wrapper, T1 inputValue);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(PacketWrapper writer, T1 inputValue) {
|
||||||
|
writer.write(outputType, transform(writer, inputValue));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
7
src/main/java/us/myles/ViaVersion2/api/remapper/ValueWriter.java
Normale Datei
7
src/main/java/us/myles/ViaVersion2/api/remapper/ValueWriter.java
Normale Datei
@ -0,0 +1,7 @@
|
|||||||
|
package us.myles.ViaVersion2.api.remapper;
|
||||||
|
|
||||||
|
import us.myles.ViaVersion2.api.PacketWrapper;
|
||||||
|
|
||||||
|
public interface ValueWriter<T> {
|
||||||
|
public void write(PacketWrapper writer, T inputValue);
|
||||||
|
}
|
@ -1,9 +1,13 @@
|
|||||||
package us.myles.ViaVersion2.api.type;
|
package us.myles.ViaVersion2.api.type;
|
||||||
|
|
||||||
|
|
||||||
import javafx.geometry.Pos;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import org.bukkit.util.EulerAngle;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
import us.myles.ViaVersion2.api.type.types.*;
|
import us.myles.ViaVersion2.api.type.types.*;
|
||||||
|
import us.myles.ViaVersion2.api.type.types.minecraft.EulerAngleType;
|
||||||
|
import us.myles.ViaVersion2.api.type.types.minecraft.PositionType;
|
||||||
|
import us.myles.ViaVersion2.api.type.types.minecraft.VectorType;
|
||||||
import us.myles.ViaVersion2.api.util.Position;
|
import us.myles.ViaVersion2.api.util.Position;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -46,17 +50,21 @@ public abstract class Type<T> implements ByteBufReader<T>, ByteBufWriter<T> {
|
|||||||
/* Special Types */
|
/* Special Types */
|
||||||
public static final Type<Void> NOTHING = new VoidType(); // This is purely used for remapping.
|
public static final Type<Void> NOTHING = new VoidType(); // This is purely used for remapping.
|
||||||
/* MC Types */
|
/* MC Types */
|
||||||
public static final Type<Position> POSITION = new PositionType(); // This is purely used for remapping.
|
public static final Type<Position> POSITION = new PositionType();
|
||||||
|
public static final Type<EulerAngle> ROTATION = new EulerAngleType();
|
||||||
|
public static final Type<Vector> VECTOR = new VectorType();
|
||||||
|
|
||||||
|
public static final Type<Object> ITEM = null; // TODO
|
||||||
/* Actual Class */
|
/* Actual Class */
|
||||||
|
|
||||||
private final Class<T> outputClass;
|
private final Class<? super T> outputClass;
|
||||||
private final String typeName;
|
private final String typeName;
|
||||||
|
|
||||||
public Type(Class<T> outputClass) {
|
public Type(Class<? super T> outputClass) {
|
||||||
this(outputClass.getSimpleName(), outputClass);
|
this(outputClass.getSimpleName(), outputClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Type(String typeName, Class<T> outputClass) {
|
public Type(String typeName, Class<? super T> outputClass) {
|
||||||
this.outputClass = outputClass;
|
this.outputClass = outputClass;
|
||||||
this.typeName = typeName;
|
this.typeName = typeName;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,28 @@
|
|||||||
|
package us.myles.ViaVersion2.api.type.types.minecraft;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import org.bukkit.util.EulerAngle;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
import us.myles.ViaVersion2.api.type.Type;
|
||||||
|
|
||||||
|
public class EulerAngleType extends Type<EulerAngle> {
|
||||||
|
public EulerAngleType() {
|
||||||
|
super(EulerAngle.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EulerAngle read(ByteBuf buffer) {
|
||||||
|
float x = Type.FLOAT.read(buffer);
|
||||||
|
float y = Type.FLOAT.read(buffer);
|
||||||
|
float z = Type.FLOAT.read(buffer);
|
||||||
|
|
||||||
|
return new EulerAngle(x, y, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(ByteBuf buffer, EulerAngle object) {
|
||||||
|
Type.FLOAT.write(buffer, (float) object.getX());
|
||||||
|
Type.FLOAT.write(buffer, (float) object.getY());
|
||||||
|
Type.FLOAT.write(buffer, (float) object.getZ());
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package us.myles.ViaVersion2.api.type.types;
|
package us.myles.ViaVersion2.api.type.types.minecraft;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import us.myles.ViaVersion2.api.type.Type;
|
import us.myles.ViaVersion2.api.type.Type;
|
@ -0,0 +1,27 @@
|
|||||||
|
package us.myles.ViaVersion2.api.type.types.minecraft;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
import us.myles.ViaVersion2.api.type.Type;
|
||||||
|
|
||||||
|
public class VectorType extends Type<Vector> {
|
||||||
|
public VectorType() {
|
||||||
|
super(Vector.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Vector read(ByteBuf buffer) {
|
||||||
|
int x = Type.INT.read(buffer);
|
||||||
|
int y = Type.INT.read(buffer);
|
||||||
|
int z = Type.INT.read(buffer);
|
||||||
|
|
||||||
|
return new Vector(x, y, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(ByteBuf buffer, Vector object) {
|
||||||
|
Type.INT.write(buffer, object.getBlockX());
|
||||||
|
Type.INT.write(buffer, object.getBlockY());
|
||||||
|
Type.INT.write(buffer, object.getBlockZ());
|
||||||
|
}
|
||||||
|
}
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren