3
0
Mirror von https://github.com/ViaVersion/ViaBackwards.git synchronisiert 2024-12-27 08:30:10 +01:00

Merge branch 'refs/heads/dev' into preview

Dieser Commit ist enthalten in:
Nassim Jahnke 2024-04-23 11:00:24 +02:00
Commit a4147a24f1
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: EF6771C01F6EF02F
8 geänderte Dateien mit 33 neuen und 34 gelöschten Zeilen

Datei anzeigen

@ -113,7 +113,7 @@ public abstract class LegacyEntityRewriter<C extends ClientboundPacketType, T ex
registerMetadataRewriter(packetType, null, metaType); registerMetadataRewriter(packetType, null, metaType);
} }
protected PacketHandler getMobSpawnRewriter(Type<List<Metadata>> metaType) { protected PacketHandler getMobSpawnRewriter(Type<List<Metadata>> metaType, IdSetter idSetter) {
return wrapper -> { return wrapper -> {
int entityId = wrapper.get(Type.VAR_INT, 0); int entityId = wrapper.get(Type.VAR_INT, 0);
EntityType type = tracker(wrapper.user()).entityType(entityId); EntityType type = tracker(wrapper.user()).entityType(entityId);
@ -123,7 +123,7 @@ public abstract class LegacyEntityRewriter<C extends ClientboundPacketType, T ex
EntityData entityData = entityDataForType(type); EntityData entityData = entityDataForType(type);
if (entityData != null) { if (entityData != null) {
wrapper.set(Type.VAR_INT, 1, entityData.replacementId()); idSetter.setId(wrapper, entityData.replacementId());
if (entityData.hasBaseMeta()) { if (entityData.hasBaseMeta()) {
entityData.defaultMeta().createMeta(new WrappedMetadata(metadata)); entityData.defaultMeta().createMeta(new WrappedMetadata(metadata));
} }
@ -131,8 +131,16 @@ public abstract class LegacyEntityRewriter<C extends ClientboundPacketType, T ex
}; };
} }
public PacketHandler getMobSpawnRewriter(Type<List<Metadata>> metaType) {
return getMobSpawnRewriter(metaType, (wrapper, id) -> wrapper.set(Type.UNSIGNED_BYTE, 0, (short) id));
}
public PacketHandler getMobSpawnRewriter1_11(Type<List<Metadata>> metaType) {
return getMobSpawnRewriter(metaType, (wrapper, id) -> wrapper.set(Type.VAR_INT, 1, id));
}
protected PacketHandler getObjectTrackerHandler() { protected PacketHandler getObjectTrackerHandler() {
return wrapper -> addTrackedEntity(wrapper, wrapper.get(Type.VAR_INT, 0), getObjectTypeFromId(wrapper.get(Type.BYTE, 0))); return wrapper -> addTrackedEntity(wrapper, wrapper.get(Type.VAR_INT, 0), objectTypeFromId(wrapper.get(Type.BYTE, 0)));
} }
protected PacketHandler getTrackerAndMetaHandler(Type<List<Metadata>> metaType, EntityType entityType) { protected PacketHandler getTrackerAndMetaHandler(Type<List<Metadata>> metaType, EntityType entityType) {
@ -161,12 +169,14 @@ public abstract class LegacyEntityRewriter<C extends ClientboundPacketType, T ex
}; };
} }
protected EntityType getObjectTypeFromId(int typeId) {
return typeFromId(typeId);
}
@Deprecated @Deprecated
protected void addTrackedEntity(PacketWrapper wrapper, int entityId, EntityType type) throws Exception { protected void addTrackedEntity(PacketWrapper wrapper, int entityId, EntityType type) throws Exception {
tracker(wrapper.user()).addEntity(entityId, type); tracker(wrapper.user()).addEntity(entityId, type);
} }
@FunctionalInterface
protected interface IdSetter {
void setId(PacketWrapper wrapper, int id) throws Exception;
}
} }

Datei anzeigen

@ -111,24 +111,13 @@ public class EntityPackets1_11 extends LegacyEntityRewriter<ClientboundPackets1_
handler(getTrackerHandler(Type.UNSIGNED_BYTE, 0)); handler(getTrackerHandler(Type.UNSIGNED_BYTE, 0));
// Rewrite entity type / metadata // Rewrite entity type / metadata
handler(wrapper -> { handler(getMobSpawnRewriter(Types1_9.METADATA_LIST));
int entityId = wrapper.get(Type.VAR_INT, 0);
EntityType type = tracker(wrapper.user()).entityType(entityId);
List<Metadata> list = wrapper.get(Types1_9.METADATA_LIST, 0);
handleMetadata(wrapper.get(Type.VAR_INT, 0), list, wrapper.user());
EntityData entityData = entityDataForType(type);
if (entityData != null) {
wrapper.set(Type.UNSIGNED_BYTE, 0, (short) entityData.replacementId());
if (entityData.hasBaseMeta()) {
entityData.defaultMeta().createMeta(new WrappedMetadata(list));
}
}
// Sub 1.11 clients will error if the list is empty // Sub 1.11 clients will error if the list is empty
if (list.isEmpty()) { handler(wrapper -> {
list.add(new Metadata(0, MetaType1_9.Byte, (byte) 0)); List<Metadata> metadata = wrapper.get(Types1_9.METADATA_LIST, 0);
if (metadata.isEmpty()) {
metadata.add(new Metadata(0, MetaType1_9.Byte, (byte) 0));
} }
}); });
} }
@ -380,7 +369,7 @@ public class EntityPackets1_11 extends LegacyEntityRewriter<ClientboundPackets1_
} }
@Override @Override
protected EntityType getObjectTypeFromId(int typeId) { public EntityType objectTypeFromId(int typeId) {
return EntityTypes1_11.getTypeFromId(typeId, true); return EntityTypes1_11.getTypeFromId(typeId, true);
} }
} }

Datei anzeigen

@ -89,7 +89,7 @@ public class EntityPackets1_12 extends LegacyEntityRewriter<ClientboundPackets1_
handler(getTrackerHandler()); handler(getTrackerHandler());
// Rewrite entity type / metadata // Rewrite entity type / metadata
handler(getMobSpawnRewriter(Types1_12.METADATA_LIST)); handler(getMobSpawnRewriter1_11(Types1_12.METADATA_LIST));
} }
}); });
@ -290,7 +290,7 @@ public class EntityPackets1_12 extends LegacyEntityRewriter<ClientboundPackets1_
} }
@Override @Override
protected EntityType getObjectTypeFromId(final int typeId) { public EntityType objectTypeFromId(int typeId) {
return EntityTypes1_12.getTypeFromId(typeId, true); return EntityTypes1_12.getTypeFromId(typeId, true);
} }
} }

Datei anzeigen

@ -78,7 +78,7 @@ public class EntityPackets1_11_1 extends LegacyEntityRewriter<ClientboundPackets
handler(getTrackerHandler()); handler(getTrackerHandler());
// Rewrite entity type / metadata // Rewrite entity type / metadata
handler(getMobSpawnRewriter(Types1_9.METADATA_LIST)); handler(getMobSpawnRewriter1_11(Types1_9.METADATA_LIST));
} }
}); });
@ -121,7 +121,7 @@ public class EntityPackets1_11_1 extends LegacyEntityRewriter<ClientboundPackets
} }
@Override @Override
protected EntityType getObjectTypeFromId(final int typeId) { public EntityType objectTypeFromId(int typeId) {
return EntityTypes1_11.getTypeFromId(typeId, true); return EntityTypes1_11.getTypeFromId(typeId, true);
} }
} }

Datei anzeigen

@ -155,7 +155,7 @@ public class EntityPackets1_13 extends LegacyEntityRewriter<ClientboundPackets1_
}); });
// Rewrite entity type / metadata // Rewrite entity type / metadata
handler(getMobSpawnRewriter(Types1_12.METADATA_LIST)); handler(getMobSpawnRewriter1_11(Types1_12.METADATA_LIST));
} }
}); });
@ -362,7 +362,7 @@ public class EntityPackets1_13 extends LegacyEntityRewriter<ClientboundPackets1_
} }
@Override @Override
protected EntityType getObjectTypeFromId(final int typeId) { public EntityType objectTypeFromId(int typeId) {
return EntityTypes1_13.getTypeFromId(typeId, true); return EntityTypes1_13.getTypeFromId(typeId, true);
} }

Datei anzeigen

@ -223,7 +223,7 @@ public class EntityPackets1_14 extends LegacyEntityRewriter<ClientboundPackets1_
}); });
// Handle entity type & metadata // Handle entity type & metadata
handler(getMobSpawnRewriter(Types1_13_2.METADATA_LIST)); handler(getMobSpawnRewriter1_11(Types1_13_2.METADATA_LIST));
} }
}); });

Datei anzeigen

@ -168,7 +168,7 @@ public class EntityPackets1_13_1 extends LegacyEntityRewriter<ClientboundPackets
} }
@Override @Override
protected EntityType getObjectTypeFromId(final int typeId) { public EntityType objectTypeFromId(int typeId) {
return EntityTypes1_13.getTypeFromId(typeId, true); return EntityTypes1_13.getTypeFromId(typeId, true);
} }
} }

Datei anzeigen

@ -165,7 +165,7 @@ public class EntityPackets1_10 extends LegacyEntityRewriter<ClientboundPackets1_
} }
@Override @Override
protected EntityType getObjectTypeFromId(int typeId) { public EntityType objectTypeFromId(int typeId) {
return EntityTypes1_10.getTypeFromId(typeId, true); return EntityTypes1_10.getTypeFromId(typeId, true);
} }
} }