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

Merge pull request #1194 from creeper123123321/dev

firework boost, set metatype to the newer class
Dieser Commit ist enthalten in:
Myles 2019-02-16 16:52:08 +00:00 committet von GitHub
Commit 755e8a007a
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
8 geänderte Dateien mit 75 neuen und 49 gelöschten Zeilen

Datei anzeigen

@ -18,14 +18,15 @@ public enum MetaType1_14 implements MetaType {
Slot(6, Type.FLAT_VAR_INT_ITEM), Slot(6, Type.FLAT_VAR_INT_ITEM),
Boolean(7, Type.BOOLEAN), Boolean(7, Type.BOOLEAN),
Vector3F(8, Type.ROTATION), Vector3F(8, Type.ROTATION),
Position(9, Type.POSITION), Position(9, Type.POSITION1_14),
OptPosition(10, Type.OPTIONAL_POSITION), OptPosition(10, Type.OPTIONAL_POSITION_1_14),
Direction(11, Type.VAR_INT), Direction(11, Type.VAR_INT),
OptUUID(12, Type.OPTIONAL_UUID), OptUUID(12, Type.OPTIONAL_UUID),
BlockID(13, Type.VAR_INT), BlockID(13, Type.VAR_INT),
NBTTag(14, Type.NBT), NBTTag(14, Type.NBT),
PARTICLE(15, Protocol1_13_2To1_13_1.PARTICLE_TYPE), PARTICLE(15, Protocol1_13_2To1_13_1.PARTICLE_TYPE),
VillagerData(16, Type.VILLAGER_DATA), VillagerData(16, Type.VILLAGER_DATA),
OptVarInt(17, Type.OPTIONAL_VAR_INT),
Discontinued(99, null); Discontinued(99, null);
private final int typeID; private final int typeID;

Datei anzeigen

@ -50,6 +50,7 @@ public abstract class Type<T> implements ByteBufReader<T>, ByteBufWriter<T> {
/* Variable Types */ /* Variable Types */
public static final Type<Integer> VAR_INT = new VarIntType(); 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[]> 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 = new VarLongType();
public static final Type<Long[]> VAR_LONG_ARRAY = new ArrayType<>(Type.VAR_LONG); public static final Type<Long[]> VAR_LONG_ARRAY = new ArrayType<>(Type.VAR_LONG);
/* Special Types */ /* 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<UUID> OPTIONAL_UUID = new OptUUIDType();
public static final Type<String> OPTIONAL_CHAT = new OptionalChatType(); 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 = 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 = new ItemType();
public static final Type<Item[]> ITEM_ARRAY = new ItemArrayType(); 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.PacketWrapper;
import us.myles.ViaVersion.api.minecraft.metadata.Metadata; 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.minecraft.metadata.types.MetaType1_13_2;
import us.myles.ViaVersion.api.protocol.Protocol; import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.remapper.PacketHandler; import us.myles.ViaVersion.api.remapper.PacketHandler;
@ -15,6 +14,15 @@ import us.myles.ViaVersion.packets.State;
public class EntityPackets { public class EntityPackets {
public static void register(Protocol protocol) { 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 // Spawn mob packet
protocol.registerOutgoing(State.PLAY, 0x3, 0x3, new PacketRemapper() { protocol.registerOutgoing(State.PLAY, 0x3, 0x3, new PacketRemapper() {
@Override @Override
@ -33,16 +41,7 @@ public class EntityPackets {
map(Type.SHORT); // 11 - Velocity Z map(Type.SHORT); // 11 - Velocity Z
map(Types1_13.METADATA_LIST, Types1_13_2.METADATA_LIST); // 12 - Metadata map(Types1_13.METADATA_LIST, Types1_13_2.METADATA_LIST); // 12 - Metadata
handler(new PacketHandler() { handler(metaTypeHandler);
@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);
}
}
}
});
} }
}); });
@ -59,16 +58,7 @@ public class EntityPackets {
map(Type.BYTE); // 6 - Pitch map(Type.BYTE); // 6 - Pitch
map(Types1_13.METADATA_LIST, Types1_13_2.METADATA_LIST); // 7 - Metadata map(Types1_13.METADATA_LIST, Types1_13_2.METADATA_LIST); // 7 - Metadata
handler(new PacketHandler() { handler(metaTypeHandler);
@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);
}
}
}
});
} }
}); });
@ -80,16 +70,7 @@ public class EntityPackets {
map(Type.VAR_INT); // 0 - Entity ID map(Type.VAR_INT); // 0 - Entity ID
map(Types1_13.METADATA_LIST, Types1_13_2.METADATA_LIST); // 1 - Metadata list map(Types1_13.METADATA_LIST, Types1_13_2.METADATA_LIST); // 1 - Metadata list
handler(new PacketHandler() { handler(metaTypeHandler);
@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

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

Datei anzeigen

@ -1,9 +1,6 @@
package us.myles.ViaVersion.protocols.protocol1_14to1_13_2.storage; package us.myles.ViaVersion.protocols.protocol1_14to1_13_2.storage;
import com.google.common.base.Optional; import com.google.common.base.Optional;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import com.google.common.collect.Maps;
import us.myles.ViaVersion.api.data.StoredObject; import us.myles.ViaVersion.api.data.StoredObject;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.entities.Entity1_14Types; import us.myles.ViaVersion.api.entities.Entity1_14Types;
@ -14,19 +11,16 @@ import java.util.concurrent.ConcurrentHashMap;
public class EntityTracker extends StoredObject { public class EntityTracker extends StoredObject {
private final Map<Integer, Entity1_14Types.EntityType> clientEntityTypes = new ConcurrentHashMap<>(); private final Map<Integer, Entity1_14Types.EntityType> clientEntityTypes = new ConcurrentHashMap<>();
private final BiMap<UUID, Integer> uuidToId = Maps.synchronizedBiMap(HashBiMap.<UUID, Integer>create());
public EntityTracker(UserConnection user) { public EntityTracker(UserConnection user) {
super(user); super(user);
} }
public void removeEntity(int entityId) { public void removeEntity(int entityId) {
uuidToId.inverse().remove(entityId);
clientEntityTypes.remove(entityId); clientEntityTypes.remove(entityId);
} }
public void addEntity(int entityId, UUID uuid, Entity1_14Types.EntityType type) { public void addEntity(int entityId, UUID uuid, Entity1_14Types.EntityType type) {
uuidToId.forcePut(uuid, entityId);
clientEntityTypes.put(entityId, type); clientEntityTypes.put(entityId, type);
} }
@ -37,8 +31,4 @@ public class EntityTracker extends StoredObject {
public Optional<Entity1_14Types.EntityType> get(int id) { public Optional<Entity1_14Types.EntityType> get(int id) {
return Optional.fromNullable(clientEntityTypes.get(id)); return Optional.fromNullable(clientEntityTypes.get(id));
} }
public Optional<UUID> getUUID(int id) {
return Optional.fromNullable(uuidToId.inverse().get(id));
}
} }