3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-26 00:00:28 +01:00

firework boost, set metatype to the newer class

Dieser Commit ist enthalten in:
creeper123123321 2019-02-13 16:42:59 -02:00
Ursprung f38d753341
Commit 35bb80d67a
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 0AC57D54786721D1
7 geänderte Dateien mit 75 neuen und 39 gelöschten Zeilen

Datei anzeigen

@ -18,14 +18,15 @@ public enum MetaType1_14 implements MetaType {
Slot(6, Type.FLAT_VAR_INT_ITEM),
Boolean(7, Type.BOOLEAN),
Vector3F(8, Type.ROTATION),
Position(9, Type.POSITION),
OptPosition(10, Type.OPTIONAL_POSITION),
Position(9, Type.POSITION1_14),
OptPosition(10, Type.OPTIONAL_POSITION_1_14),
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),
VillagerData(16, Type.VILLAGER_DATA),
OptVarInt(17, Type.OPTIONAL_VAR_INT),
Discontinued(99, null);
private final int typeID;

Datei anzeigen

@ -50,6 +50,7 @@ public abstract class Type<T> implements ByteBufReader<T>, ByteBufWriter<T> {
/* Variable Types */
public static final Type<Integer> VAR_INT = new VarIntType();
public static final Type<Integer[]> VAR_INT_ARRAY = new ArrayType<>(Type.VAR_INT);
public static final Type<Integer> OPTIONAL_VAR_INT = new OptionalVarIntType();
public static final Type<Long> VAR_LONG = new VarLongType();
public static final Type<Long[]> VAR_LONG_ARRAY = new ArrayType<>(Type.VAR_LONG);
/* Special Types */
@ -65,6 +66,7 @@ public abstract class Type<T> implements ByteBufReader<T>, ByteBufWriter<T> {
public static final Type<UUID> OPTIONAL_UUID = new OptUUIDType();
public static final Type<String> OPTIONAL_CHAT = new OptionalChatType();
public static final Type<Position> OPTIONAL_POSITION = new OptPositionType();
public static final Type<Position> OPTIONAL_POSITION_1_14 = new OptPosition1_14Type();
public static final Type<Item> ITEM = new ItemType();
public static final Type<Item[]> ITEM_ARRAY = new ItemArrayType();

Datei anzeigen

@ -0,0 +1,25 @@
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 OptPosition1_14Type extends Type<Position> {
public OptPosition1_14Type() {
super(Position.class);
}
@Override
public Position read(ByteBuf buffer) throws Exception {
boolean present = buffer.readBoolean();
if (!present) return null;
return Type.POSITION1_14.read(buffer);
}
@Override
public void write(ByteBuf buffer, Position object) throws Exception {
buffer.writeBoolean(object != null);
if (object != null)
Type.POSITION1_14.write(buffer, object);
}
}

Datei anzeigen

@ -0,0 +1,23 @@
package us.myles.ViaVersion.api.type.types.minecraft;
import io.netty.buffer.ByteBuf;
import us.myles.ViaVersion.api.type.Type;
public class OptionalVarIntType extends Type<Integer> {
public OptionalVarIntType() {
super(Integer.class);
}
@Override
public Integer read(ByteBuf buffer) throws Exception {
int read = Type.VAR_INT.read(buffer);
if (read == 0) return null;
return read - 1;
}
@Override
public void write(ByteBuf buffer, Integer object) throws Exception {
if (object == null) Type.VAR_INT.write(buffer, 0);
else Type.VAR_INT.write(buffer, object + 1);
}
}

Datei anzeigen

@ -2,7 +2,6 @@ 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;
@ -15,6 +14,15 @@ import us.myles.ViaVersion.packets.State;
public class EntityPackets {
public static void register(Protocol protocol) {
final PacketHandler metaTypeHandler = new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
for (Metadata metadata : wrapper.get(Types1_13_2.METADATA_LIST, 0)) {
metadata.setMetaType(MetaType1_13_2.byId(metadata.getMetaType().getTypeID()));
}
}
};
// Spawn mob packet
protocol.registerOutgoing(State.PLAY, 0x3, 0x3, new PacketRemapper() {
@Override
@ -33,16 +41,7 @@ public class EntityPackets {
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);
}
}
}
});
handler(metaTypeHandler);
}
});
@ -59,16 +58,7 @@ public class EntityPackets {
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);
}
}
}
});
handler(metaTypeHandler);
}
});
@ -80,16 +70,7 @@ public class EntityPackets {
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);
}
}
}
});
handler(metaTypeHandler);
}
});
}

Datei anzeigen

@ -20,8 +20,11 @@ public class MetadataRewriter {
for (Metadata metadata : new ArrayList<>(metadatas)) {
try {
// Handle new MetaTypes
if (metadata.getMetaType().getTypeID() > 4)
if (metadata.getMetaType().getTypeID() > 4) {
metadata.setMetaType(MetaType1_13.byId(metadata.getMetaType().getTypeID() + 1));
} else {
metadata.setMetaType(MetaType1_13.byId(metadata.getMetaType().getTypeID()));
}
// Handle String -> Chat DisplayName
if (metadata.getId() == 2) {

Datei anzeigen

@ -6,7 +6,6 @@ import us.myles.ViaVersion.api.entities.Entity1_14Types;
import us.myles.ViaVersion.api.minecraft.VillagerData;
import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_13_2;
import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_14;
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.packets.InventoryPackets;
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.storage.EntityTracker;
@ -19,11 +18,13 @@ public class MetadataRewriter {
public static void handleMetadata(int entityId, Entity1_14Types.EntityType type, List<Metadata> metadatas, UserConnection connection) {
for (Metadata metadata : new ArrayList<>(metadatas)) {
try {
metadata.setMetaType(MetaType1_14.byId(metadata.getMetaType().getTypeID()));
EntityTracker tracker = connection.get(EntityTracker.class);
// 1.13 changed item to flat item (no data)
if (metadata.getMetaType() == MetaType1_13_2.Slot) {
if (metadata.getMetaType() == MetaType1_14.Slot) {
InventoryPackets.toClient((Item) metadata.getValue());
} else if (metadata.getMetaType() == MetaType1_13_2.BlockID) {
} else if (metadata.getMetaType() == MetaType1_14.BlockID) {
// Convert to new block id
int data = (int) metadata.getValue();
metadata.setValue(Protocol1_14To1_13_2.getNewBlockStateId(data));
@ -59,8 +60,8 @@ public class MetadataRewriter {
if (type.is(Entity1_14Types.EntityType.FIREWORKS_ROCKET)) {
if (metadata.getId() == 7) {
metadata.setValue(tracker.getUUID(((Number) metadata.getValue()).intValue()).orNull());
metadata.setMetaType(MetaType1_14.OptUUID);
if (metadata.getValue().equals(0)) metadata.setValue(null); // https://bugs.mojang.com/browse/MC-111480
metadata.setMetaType(MetaType1_14.OptVarInt);
}
}
} catch (Exception e) {