3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-03 14:50:30 +01:00

Merge pull request #1173 from creeper123123321/dev

Fix item deserializing
Dieser Commit ist enthalten in:
Myles 2019-01-27 14:19:40 +00:00 committet von GitHub
Commit c57f0d90bb
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
15 geänderte Dateien mit 65 neuen und 20 gelöschten Zeilen

Datei anzeigen

@ -5,7 +5,7 @@
<parent>
<artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId>
<version>2.0.0-19w04a</version>
<version>2.0.0-19w04b</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Datei anzeigen

@ -5,7 +5,7 @@
<parent>
<artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId>
<version>2.0.0-19w04a</version>
<version>2.0.0-19w04b</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Datei anzeigen

@ -5,7 +5,7 @@
<parent>
<artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId>
<version>2.0.0-19w04a</version>
<version>2.0.0-19w04b</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Datei anzeigen

@ -1,6 +1,7 @@
package us.myles.ViaVersion.api.minecraft.item;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.google.gson.annotations.SerializedName;
import lombok.*;
@Getter
@ -10,6 +11,7 @@ import lombok.*;
@ToString
@EqualsAndHashCode
public class Item {
@SerializedName(value = "identifier", alternate = "id")
private int identifier;
private byte amount;
private short data;

Datei anzeigen

@ -67,7 +67,7 @@ public class ProtocolVersion {
register(v1_13 = new ProtocolVersion(393, "1.13"));
register(v1_13_1 = new ProtocolVersion(401, "1.13.1"));
register(v1_13_2 = new ProtocolVersion(404, "1.13.2"));
register(v1_14 = new ProtocolVersion(456, "1.14"));
register(v1_14 = new ProtocolVersion(457, "1.14"));
register(unknown = new ProtocolVersion(-1, "UNKNOWN"));
}

Datei anzeigen

@ -9,6 +9,7 @@ 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;
import java.util.ArrayList;
import java.util.List;
@ -18,6 +19,7 @@ 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 {
EntityTracker tracker = connection.get(EntityTracker.class);
// 1.13 changed item to flat item (no data)
if (metadata.getMetaType() == MetaType1_13_2.Slot) {
InventoryPackets.toClient((Item) metadata.getValue());
@ -26,7 +28,9 @@ public class MetadataRewriter {
int data = (int) metadata.getValue();
metadata.setValue(Protocol1_14To1_13_2.getNewBlockStateId(data));
}
if (type == null) continue;
if (type.isOrHasParent(Entity1_14Types.EntityType.MINECART_ABSTRACT) && metadata.getId() == 9) {
// New block format
int data = (int) metadata.getValue();
@ -46,6 +50,19 @@ public class MetadataRewriter {
metadata.setMetaType(MetaType1_14.VillagerData);
}
}
if (type.isOrHasParent(Entity1_14Types.EntityType.ARROW)) {
if (metadata.getId() >= 8) {
metadata.setId(metadata.getId() + 1);
}
}
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);
}
}
} catch (Exception e) {
metadatas.remove(metadata);
if (!Via.getConfig().isSuppressMetadataErrors() || Via.getManager().isDebug()) {

Datei anzeigen

@ -50,7 +50,7 @@ public class EntityTypeRewriter {
regEnt(45, 46); // tnt_minecart
regEnt(46, 47); // mule
regEnt(47, 48); // mooshroom
regEnt(48, 49); // ocelot
regEnt(48, 6); // ocelot -> cat TODO Remap untamed ocelot to ocelot?
regEnt(49, 50); // painting
regEnt(50, 52); // parrot
regEnt(51, 53); // pig

Datei anzeigen

@ -8,12 +8,15 @@ 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_2;
import us.myles.ViaVersion.api.type.types.version.Types1_14;
import us.myles.ViaVersion.packets.State;
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.MetadataRewriter;
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.Protocol1_14To1_13_2;
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.data.EntityTypeRewriter;
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.storage.EntityTracker;
import java.util.UUID;
public class EntityPackets {
public static void register(Protocol protocol) {
@ -37,6 +40,7 @@ public class EntityPackets {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int entityId = wrapper.get(Type.VAR_INT, 0);
UUID uuid = wrapper.get(Type.UUID, 0);
byte type = wrapper.get(Type.BYTE, 0);
Entity1_14Types.EntityType entType = Entity1_14Types.getTypeFromId(type, true);
@ -47,7 +51,7 @@ public class EntityPackets {
}
}
// Register Type ID
wrapper.user().get(EntityTracker.class).addEntity(entityId, entType);
wrapper.user().get(EntityTracker.class).addEntity(entityId, uuid, entType);
}
});
}
@ -69,13 +73,14 @@ public class EntityPackets {
map(Type.SHORT); // 9 - Velocity X
map(Type.SHORT); // 10 - Velocity Y
map(Type.SHORT); // 11 - Velocity Z
map(Types1_13_2.METADATA_LIST); // 12 - Metadata
map(Types1_13_2.METADATA_LIST, Types1_14.METADATA_LIST); // 12 - Metadata
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int entityId = wrapper.get(Type.VAR_INT, 0);
int type = wrapper.get(Type.VAR_INT, 1);
UUID uuid = wrapper.get(Type.UUID, 0);
type = EntityTypeRewriter.getNewId(type).or(type);
@ -84,9 +89,9 @@ public class EntityPackets {
wrapper.set(Type.VAR_INT, 1, type);
// Register Type ID
wrapper.user().get(EntityTracker.class).addEntity(entityId, entType);
wrapper.user().get(EntityTracker.class).addEntity(entityId, uuid, entType);
MetadataRewriter.handleMetadata(entityId, entType, wrapper.get(Types1_13_2.METADATA_LIST, 0), wrapper.user());
MetadataRewriter.handleMetadata(entityId, entType, wrapper.get(Types1_14.METADATA_LIST, 0), wrapper.user());
}
});
}
@ -115,17 +120,18 @@ public class EntityPackets {
map(Type.DOUBLE); // 4 - Z
map(Type.BYTE); // 5 - Yaw
map(Type.BYTE); // 6 - Pitch
map(Types1_13_2.METADATA_LIST); // 7 - Metadata
map(Types1_13_2.METADATA_LIST, Types1_14.METADATA_LIST); // 7 - Metadata
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
UUID uuid = wrapper.get(Type.UUID, 0);
int entityId = wrapper.get(Type.VAR_INT, 0);
Entity1_14Types.EntityType entType = Entity1_14Types.EntityType.PLAYER;
// Register Type ID
wrapper.user().get(EntityTracker.class).addEntity(entityId, entType);
MetadataRewriter.handleMetadata(entityId, entType, wrapper.get(Types1_13_2.METADATA_LIST, 0), wrapper.user());
wrapper.user().get(EntityTracker.class).addEntity(entityId, uuid, entType);
MetadataRewriter.handleMetadata(entityId, entType, wrapper.get(Types1_14.METADATA_LIST, 0), wrapper.user());
}
});
}
@ -161,14 +167,14 @@ public class EntityPackets {
@Override
public void registerMap() {
map(Type.VAR_INT); // 0 - Entity ID
map(Types1_13_2.METADATA_LIST); // 1 - Metadata list
map(Types1_13_2.METADATA_LIST, Types1_14.METADATA_LIST); // 1 - Metadata list
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int entityId = wrapper.get(Type.VAR_INT, 0);
Optional<Entity1_14Types.EntityType> type = wrapper.user().get(EntityTracker.class).get(entityId);
MetadataRewriter.handleMetadata(entityId, type.orNull(), wrapper.get(Types1_13_2.METADATA_LIST, 0), wrapper.user());
MetadataRewriter.handleMetadata(entityId, type.orNull(), wrapper.get(Types1_14.METADATA_LIST, 0), wrapper.user());
}
});
}

Datei anzeigen

@ -3,6 +3,7 @@ package us.myles.ViaVersion.protocols.protocol1_14to1_13_2.packets;
import com.google.common.primitives.Bytes;
import io.netty.buffer.ByteBuf;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.entities.Entity1_14Types;
import us.myles.ViaVersion.api.minecraft.BlockChangeRecord;
import us.myles.ViaVersion.api.minecraft.chunks.Chunk;
import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection;
@ -12,9 +13,11 @@ import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.remapper.ValueCreator;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State;
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.types.Chunk1_13Type;
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.Protocol1_14To1_13_2;
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.data.MappingData;
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.storage.EntityTracker;
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.types.Chunk1_14Type;
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
@ -244,6 +247,12 @@ public class WorldPackets {
ClientWorld clientChunks = wrapper.user().get(ClientWorld.class);
int dimensionId = wrapper.get(Type.INT, 1);
clientChunks.setEnvironment(dimensionId);
int entityId = wrapper.get(Type.INT, 0);
Entity1_14Types.EntityType entType = Entity1_14Types.EntityType.PLAYER;
// Register Type ID
wrapper.user().get(EntityTracker.class).addEntity(entityId, wrapper.user().get(ProtocolInfo.class).getUuid(), entType);
}
});
}

Datei anzeigen

@ -1,25 +1,32 @@
package us.myles.ViaVersion.protocols.protocol1_14to1_13_2.storage;
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.UserConnection;
import us.myles.ViaVersion.api.entities.Entity1_14Types;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
public class EntityTracker extends StoredObject {
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) {
super(user);
}
public void removeEntity(int entityId) {
uuidToId.inverse().remove(entityId);
clientEntityTypes.remove(entityId);
}
public void addEntity(int entityId, Entity1_14Types.EntityType type) {
public void addEntity(int entityId, UUID uuid, Entity1_14Types.EntityType type) {
uuidToId.forcePut(uuid, entityId);
clientEntityTypes.put(entityId, type);
}
@ -30,4 +37,8 @@ public class EntityTracker extends StoredObject {
public Optional<Entity1_14Types.EntityType> get(int id) {
return Optional.fromNullable(clientEntityTypes.get(id));
}
public Optional<UUID> getUUID(int id) {
return Optional.fromNullable(uuidToId.inverse().get(id));
}
}

Datei anzeigen

@ -5,7 +5,7 @@
<parent>
<artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId>
<version>2.0.0-19w04a</version>
<version>2.0.0-19w04b</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<name>viaversion-jar</name>

Datei anzeigen

@ -6,7 +6,7 @@
<groupId>us.myles</groupId>
<artifactId>viaversion-parent</artifactId>
<version>2.0.0-19w04a</version>
<version>2.0.0-19w04b</version>
<packaging>pom</packaging>
<name>viaversion-parent</name>

Datei anzeigen

@ -5,7 +5,7 @@
<parent>
<artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId>
<version>2.0.0-19w04a</version>
<version>2.0.0-19w04b</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Datei anzeigen

@ -5,7 +5,7 @@
<parent>
<artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId>
<version>2.0.0-19w04a</version>
<version>2.0.0-19w04b</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Datei anzeigen

@ -5,7 +5,7 @@
<parent>
<artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId>
<version>2.0.0-19w04a</version>
<version>2.0.0-19w04b</version>
</parent>
<modelVersion>4.0.0</modelVersion>