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

Add mob spawn rewriter function for pre 1.11 (#724)

Dieser Commit ist enthalten in:
EnZaXD 2024-04-23 10:45:12 +02:00 committet von GitHub
Ursprung 948c615622
Commit 87f2a6ba7b
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: B5690EEEBB952194
6 geänderte Dateien mit 26 neuen und 23 gelöschten Zeilen

Datei anzeigen

@ -113,7 +113,7 @@ public abstract class LegacyEntityRewriter<C extends ClientboundPacketType, T ex
registerMetadataRewriter(packetType, null, metaType);
}
protected PacketHandler getMobSpawnRewriter(Type<List<Metadata>> metaType) {
protected PacketHandler getMobSpawnRewriter(Type<List<Metadata>> metaType, IdSetter idSetter) {
return wrapper -> {
int entityId = wrapper.get(Type.VAR_INT, 0);
EntityType type = tracker(wrapper.user()).entityType(entityId);
@ -123,7 +123,7 @@ public abstract class LegacyEntityRewriter<C extends ClientboundPacketType, T ex
EntityData entityData = entityDataForType(type);
if (entityData != null) {
wrapper.set(Type.VAR_INT, 1, entityData.replacementId());
idSetter.setId(wrapper, entityData.replacementId());
if (entityData.hasBaseMeta()) {
entityData.defaultMeta().createMeta(new WrappedMetadata(metadata));
}
@ -131,6 +131,14 @@ 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() {
return wrapper -> addTrackedEntity(wrapper, wrapper.get(Type.VAR_INT, 0), objectTypeFromId(wrapper.get(Type.BYTE, 0)));
}
@ -165,4 +173,10 @@ public abstract class LegacyEntityRewriter<C extends ClientboundPacketType, T ex
protected void addTrackedEntity(PacketWrapper wrapper, int entityId, EntityType type) throws Exception {
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));
// Rewrite entity type / metadata
handler(getMobSpawnRewriter(Types1_9.METADATA_LIST));
// Sub 1.11 clients will error if the list is empty
handler(wrapper -> {
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
if (list.isEmpty()) {
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));
}
});
}

Datei anzeigen

@ -89,7 +89,7 @@ public class EntityPackets1_12 extends LegacyEntityRewriter<ClientboundPackets1_
handler(getTrackerHandler());
// Rewrite entity type / metadata
handler(getMobSpawnRewriter(Types1_12.METADATA_LIST));
handler(getMobSpawnRewriter1_11(Types1_12.METADATA_LIST));
}
});

Datei anzeigen

@ -78,7 +78,7 @@ public class EntityPackets1_11_1 extends LegacyEntityRewriter<ClientboundPackets
handler(getTrackerHandler());
// Rewrite entity type / metadata
handler(getMobSpawnRewriter(Types1_9.METADATA_LIST));
handler(getMobSpawnRewriter1_11(Types1_9.METADATA_LIST));
}
});

Datei anzeigen

@ -155,7 +155,7 @@ public class EntityPackets1_13 extends LegacyEntityRewriter<ClientboundPackets1_
});
// Rewrite entity type / metadata
handler(getMobSpawnRewriter(Types1_12.METADATA_LIST));
handler(getMobSpawnRewriter1_11(Types1_12.METADATA_LIST));
}
});

Datei anzeigen

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