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

Arrow and firework metadata rewriting, remap ocelot to cat for now

Dieser Commit ist enthalten in:
creeper123123321 2019-01-25 15:36:12 -02:00
Ursprung 25d1b08a6f
Commit e9198e7946
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 0AC57D54786721D1
5 geänderte Dateien mit 54 neuen und 11 gelöschten Zeilen

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_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 java.util.ArrayList; import java.util.ArrayList;
import java.util.List; 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) { 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 {
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_13_2.Slot) {
InventoryPackets.toClient((Item) metadata.getValue()); InventoryPackets.toClient((Item) metadata.getValue());
@ -26,7 +28,9 @@ public class MetadataRewriter {
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));
} }
if (type == null) continue; if (type == null) continue;
if (type.isOrHasParent(Entity1_14Types.EntityType.MINECART_ABSTRACT) && metadata.getId() == 9) { if (type.isOrHasParent(Entity1_14Types.EntityType.MINECART_ABSTRACT) && metadata.getId() == 9) {
// New block format // New block format
int data = (int) metadata.getValue(); int data = (int) metadata.getValue();
@ -46,6 +50,19 @@ public class MetadataRewriter {
metadata.setMetaType(MetaType1_14.VillagerData); 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) { } catch (Exception e) {
metadatas.remove(metadata); metadatas.remove(metadata);
if (!Via.getConfig().isSuppressMetadataErrors() || Via.getManager().isDebug()) { if (!Via.getConfig().isSuppressMetadataErrors() || Via.getManager().isDebug()) {

Datei anzeigen

@ -50,7 +50,7 @@ public class EntityTypeRewriter {
regEnt(45, 46); // tnt_minecart regEnt(45, 46); // tnt_minecart
regEnt(46, 47); // mule regEnt(46, 47); // mule
regEnt(47, 48); // mooshroom regEnt(47, 48); // mooshroom
regEnt(48, 49); // ocelot regEnt(48, 6); // ocelot -> cat TODO Remap untamed ocelot to ocelot?
regEnt(49, 50); // painting regEnt(49, 50); // painting
regEnt(50, 52); // parrot regEnt(50, 52); // parrot
regEnt(51, 53); // pig 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.remapper.PacketRemapper;
import us.myles.ViaVersion.api.type.Type; 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_13_2;
import us.myles.ViaVersion.api.type.types.version.Types1_14;
import us.myles.ViaVersion.packets.State; 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.MetadataRewriter;
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.Protocol1_14To1_13_2; 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.data.EntityTypeRewriter;
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.storage.EntityTracker; import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.storage.EntityTracker;
import java.util.UUID;
public class EntityPackets { public class EntityPackets {
public static void register(Protocol protocol) { public static void register(Protocol protocol) {
@ -37,6 +40,7 @@ public class EntityPackets {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
int entityId = wrapper.get(Type.VAR_INT, 0); int entityId = wrapper.get(Type.VAR_INT, 0);
UUID uuid = wrapper.get(Type.UUID, 0);
byte type = wrapper.get(Type.BYTE, 0); byte type = wrapper.get(Type.BYTE, 0);
Entity1_14Types.EntityType entType = Entity1_14Types.getTypeFromId(type, true); Entity1_14Types.EntityType entType = Entity1_14Types.getTypeFromId(type, true);
@ -47,7 +51,7 @@ public class EntityPackets {
} }
} }
// Register Type ID // 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); // 9 - Velocity X
map(Type.SHORT); // 10 - Velocity Y map(Type.SHORT); // 10 - Velocity Y
map(Type.SHORT); // 11 - Velocity Z 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() { handler(new PacketHandler() {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
int entityId = wrapper.get(Type.VAR_INT, 0); int entityId = wrapper.get(Type.VAR_INT, 0);
int type = wrapper.get(Type.VAR_INT, 1); int type = wrapper.get(Type.VAR_INT, 1);
UUID uuid = wrapper.get(Type.UUID, 0);
type = EntityTypeRewriter.getNewId(type).or(type); type = EntityTypeRewriter.getNewId(type).or(type);
@ -84,9 +89,9 @@ public class EntityPackets {
wrapper.set(Type.VAR_INT, 1, type); wrapper.set(Type.VAR_INT, 1, type);
// Register Type ID // 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.DOUBLE); // 4 - Z
map(Type.BYTE); // 5 - Yaw map(Type.BYTE); // 5 - Yaw
map(Type.BYTE); // 6 - Pitch 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() { handler(new PacketHandler() {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
UUID uuid = wrapper.get(Type.UUID, 0);
int entityId = wrapper.get(Type.VAR_INT, 0); int entityId = wrapper.get(Type.VAR_INT, 0);
Entity1_14Types.EntityType entType = Entity1_14Types.EntityType.PLAYER; Entity1_14Types.EntityType entType = Entity1_14Types.EntityType.PLAYER;
// Register Type ID // 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());
} }
}); });
} }
@ -161,14 +167,14 @@ public class EntityPackets {
@Override @Override
public void registerMap() { public void registerMap() {
map(Type.VAR_INT); // 0 - Entity ID 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() { handler(new PacketHandler() {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
int entityId = wrapper.get(Type.VAR_INT, 0); int entityId = wrapper.get(Type.VAR_INT, 0);
Optional<Entity1_14Types.EntityType> type = wrapper.user().get(EntityTracker.class).get(entityId); 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 com.google.common.primitives.Bytes;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import us.myles.ViaVersion.api.PacketWrapper; 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.BlockChangeRecord;
import us.myles.ViaVersion.api.minecraft.chunks.Chunk; import us.myles.ViaVersion.api.minecraft.chunks.Chunk;
import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection; 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.remapper.ValueCreator;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State; 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_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.Protocol1_14To1_13_2;
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.data.MappingData; 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_14to1_13_2.types.Chunk1_14Type;
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; 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); ClientWorld clientChunks = wrapper.user().get(ClientWorld.class);
int dimensionId = wrapper.get(Type.INT, 1); int dimensionId = wrapper.get(Type.INT, 1);
clientChunks.setEnvironment(dimensionId); 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; 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;
import java.util.Map; import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap; 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, 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);
} }
@ -30,4 +37,8 @@ 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));
}
} }