mirror of
https://github.com/ViaVersion/ViaBackwards.git
synced 2024-11-21 12:07:38 +01:00
Add mob spawn rewriter function for pre 1.11 (#724)
This commit is contained in:
parent
948c615622
commit
87f2a6ba7b
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -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));
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -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));
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -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));
|
||||
}
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user