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

Add EntityRewriter#registerBlockStateHandler (#3912)

Dieser Commit ist enthalten in:
EnZaXD 2024-06-06 11:00:18 +02:00 committet von GitHub
Ursprung 1ea27f1077
Commit bb48dc90f9
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: B5690EEEBB952194
15 geänderte Dateien mit 27 neuen und 67 gelöschten Zeilen

Datei anzeigen

@ -262,6 +262,9 @@ public class EntityPacketRewriter1_14 extends EntityRewriter<ClientboundPackets1
registerEntityDataTypeHandler(Types1_14.ENTITY_DATA_TYPES.itemType, Types1_14.ENTITY_DATA_TYPES.optionalBlockStateType, Types1_14.ENTITY_DATA_TYPES.particleType); registerEntityDataTypeHandler(Types1_14.ENTITY_DATA_TYPES.itemType, Types1_14.ENTITY_DATA_TYPES.optionalBlockStateType, Types1_14.ENTITY_DATA_TYPES.particleType);
filter().type(EntityTypes1_14.ENTITY).addIndex(6); filter().type(EntityTypes1_14.ENTITY).addIndex(6);
registerBlockStateHandler(EntityTypes1_14.ABSTRACT_MINECART, 10);
filter().type(EntityTypes1_14.LIVING_ENTITY).addIndex(12); filter().type(EntityTypes1_14.LIVING_ENTITY).addIndex(12);
filter().type(EntityTypes1_14.LIVING_ENTITY).index(8).handler((event, meta) -> { filter().type(EntityTypes1_14.LIVING_ENTITY).index(8).handler((event, meta) -> {
@ -309,11 +312,6 @@ public class EntityPacketRewriter1_14 extends EntityRewriter<ClientboundPackets1
} }
}); });
filter().type(EntityTypes1_14.ABSTRACT_MINECART).index(10).handler((event, meta) -> {
int data = meta.value();
meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
});
filter().type(EntityTypes1_14.HORSE).index(18).handler((event, meta) -> { filter().type(EntityTypes1_14.HORSE).index(18).handler((event, meta) -> {
event.cancel(); event.cancel();

Datei anzeigen

@ -109,10 +109,8 @@ public class EntityPacketRewriter1_13_1 extends EntityRewriter<ClientboundPacket
@Override @Override
protected void registerRewrites() { protected void registerRewrites() {
registerEntityDataTypeHandler(Types1_13.ENTITY_DATA_TYPES.itemType, Types1_13.ENTITY_DATA_TYPES.optionalBlockStateType, Types1_13.ENTITY_DATA_TYPES.particleType); registerEntityDataTypeHandler(Types1_13.ENTITY_DATA_TYPES.itemType, Types1_13.ENTITY_DATA_TYPES.optionalBlockStateType, Types1_13.ENTITY_DATA_TYPES.particleType);
filter().type(EntityTypes1_13.EntityType.ABSTRACT_MINECART).index(9).handler((event, meta) -> { registerBlockStateHandler(EntityTypes1_13.EntityType.ABSTRACT_MINECART, 9);
int data = meta.value();
meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
});
filter().type(EntityTypes1_13.EntityType.ABSTRACT_ARROW).addIndex(7); // Shooter UUID filter().type(EntityTypes1_13.EntityType.ABSTRACT_ARROW).addIndex(7); // Shooter UUID
} }

Datei anzeigen

@ -115,10 +115,7 @@ public class EntityPacketRewriter1_15 extends EntityRewriter<ClientboundPackets1
@Override @Override
protected void registerRewrites() { protected void registerRewrites() {
registerEntityDataTypeHandler(Types1_14.ENTITY_DATA_TYPES.itemType, Types1_14.ENTITY_DATA_TYPES.optionalBlockStateType, Types1_14.ENTITY_DATA_TYPES.particleType); registerEntityDataTypeHandler(Types1_14.ENTITY_DATA_TYPES.itemType, Types1_14.ENTITY_DATA_TYPES.optionalBlockStateType, Types1_14.ENTITY_DATA_TYPES.particleType);
filter().type(EntityTypes1_15.ABSTRACT_MINECART).index(10).handler((metadatas, meta) -> { registerBlockStateHandler(EntityTypes1_15.ABSTRACT_MINECART, 10);
int data = meta.value();
meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
});
filter().type(EntityTypes1_15.LIVING_ENTITY).addIndex(12); filter().type(EntityTypes1_15.LIVING_ENTITY).addIndex(12);
filter().type(EntityTypes1_15.WOLF).removeIndex(18); filter().type(EntityTypes1_15.WOLF).removeIndex(18);

Datei anzeigen

@ -208,10 +208,8 @@ public class EntityPacketRewriter1_16 extends EntityRewriter<ClientboundPackets1
protected void registerRewrites() { protected void registerRewrites() {
filter().mapDataType(Types1_16.ENTITY_DATA_TYPES::byId); filter().mapDataType(Types1_16.ENTITY_DATA_TYPES::byId);
registerEntityDataTypeHandler(Types1_16.ENTITY_DATA_TYPES.itemType, Types1_16.ENTITY_DATA_TYPES.optionalBlockStateType, Types1_16.ENTITY_DATA_TYPES.particleType); registerEntityDataTypeHandler(Types1_16.ENTITY_DATA_TYPES.itemType, Types1_16.ENTITY_DATA_TYPES.optionalBlockStateType, Types1_16.ENTITY_DATA_TYPES.particleType);
filter().type(EntityTypes1_16.ABSTRACT_MINECART).index(10).handler((metadatas, meta) -> { registerBlockStateHandler(EntityTypes1_16.ABSTRACT_MINECART, 10);
int data = meta.value();
meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
});
filter().type(EntityTypes1_16.ABSTRACT_ARROW).removeIndex(8); filter().type(EntityTypes1_16.ABSTRACT_ARROW).removeIndex(8);
filter().type(EntityTypes1_16.WOLF).index(16).handler((event, meta) -> { filter().type(EntityTypes1_16.WOLF).index(16).handler((event, meta) -> {
byte mask = meta.value(); byte mask = meta.value();

Datei anzeigen

@ -78,10 +78,8 @@ public class EntityPacketRewriter1_16_2 extends EntityRewriter<ClientboundPacket
@Override @Override
protected void registerRewrites() { protected void registerRewrites() {
registerEntityDataTypeHandler(Types1_16.ENTITY_DATA_TYPES.itemType, Types1_16.ENTITY_DATA_TYPES.optionalBlockStateType, Types1_16.ENTITY_DATA_TYPES.particleType); registerEntityDataTypeHandler(Types1_16.ENTITY_DATA_TYPES.itemType, Types1_16.ENTITY_DATA_TYPES.optionalBlockStateType, Types1_16.ENTITY_DATA_TYPES.particleType);
filter().type(EntityTypes1_16_2.ABSTRACT_MINECART).index(10).handler((metadatas, meta) -> { registerBlockStateHandler(EntityTypes1_16_2.ABSTRACT_MINECART, 10);
int data = meta.value();
meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
});
filter().type(EntityTypes1_16_2.ABSTRACT_PIGLIN).handler((metadatas, meta) -> { filter().type(EntityTypes1_16_2.ABSTRACT_PIGLIN).handler((metadatas, meta) -> {
if (meta.id() == 15) { if (meta.id() == 15) {
meta.setId(16); meta.setId(16);

Datei anzeigen

@ -148,11 +148,7 @@ public final class EntityPacketRewriter1_17 extends EntityRewriter<ClientboundPa
// Ticks frozen added with id 7 // Ticks frozen added with id 7
filter().type(EntityTypes1_17.ENTITY).addIndex(7); filter().type(EntityTypes1_17.ENTITY).addIndex(7);
filter().type(EntityTypes1_17.ABSTRACT_MINECART).index(11).handler((event, meta) -> { registerBlockStateHandler(EntityTypes1_17.ABSTRACT_MINECART, 11);
// Convert to new block id
int data = (int) meta.getValue();
meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
});
// Attachment position removed // Attachment position removed
filter().type(EntityTypes1_17.SHULKER).removeIndex(17); filter().type(EntityTypes1_17.SHULKER).removeIndex(17);

Datei anzeigen

@ -335,12 +335,7 @@ public final class EntityPacketRewriter1_19 extends EntityRewriter<ClientboundPa
}); });
registerEntityDataTypeHandler(Types1_19.ENTITY_DATA_TYPES.itemType, Types1_19.ENTITY_DATA_TYPES.optionalBlockStateType, null); registerEntityDataTypeHandler(Types1_19.ENTITY_DATA_TYPES.itemType, Types1_19.ENTITY_DATA_TYPES.optionalBlockStateType, null);
registerBlockStateHandler(EntityTypes1_19.ABSTRACT_MINECART, 11);
filter().type(EntityTypes1_19.ABSTRACT_MINECART).index(11).handler((event, meta) -> {
// Convert to new block id
final int data = (int) meta.getValue();
meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
});
filter().type(EntityTypes1_19.CAT).index(19).mapDataType(typeId -> Types1_19.ENTITY_DATA_TYPES.catVariantType); filter().type(EntityTypes1_19.CAT).index(19).mapDataType(typeId -> Types1_19.ENTITY_DATA_TYPES.catVariantType);
} }

Datei anzeigen

@ -153,6 +153,7 @@ public final class EntityPacketRewriter1_19_3 extends EntityRewriter<Clientbound
protected void registerRewrites() { protected void registerRewrites() {
filter().mapDataType(typeId -> Types1_19_3.ENTITY_DATA_TYPES.byId(typeId >= 2 ? typeId + 1 : typeId)); // Long added filter().mapDataType(typeId -> Types1_19_3.ENTITY_DATA_TYPES.byId(typeId >= 2 ? typeId + 1 : typeId)); // Long added
registerEntityDataTypeHandler(Types1_19_3.ENTITY_DATA_TYPES.itemType, Types1_19_3.ENTITY_DATA_TYPES.optionalBlockStateType, Types1_19_3.ENTITY_DATA_TYPES.particleType); registerEntityDataTypeHandler(Types1_19_3.ENTITY_DATA_TYPES.itemType, Types1_19_3.ENTITY_DATA_TYPES.optionalBlockStateType, Types1_19_3.ENTITY_DATA_TYPES.particleType);
registerBlockStateHandler(EntityTypes1_19_3.ABSTRACT_MINECART, 11);
filter().type(EntityTypes1_19_3.ENTITY).index(6).handler((event, meta) -> { filter().type(EntityTypes1_19_3.ENTITY).index(6).handler((event, meta) -> {
// Sitting pose added // Sitting pose added
@ -161,11 +162,6 @@ public final class EntityPacketRewriter1_19_3 extends EntityRewriter<Clientbound
meta.setValue(pose + 1); meta.setValue(pose + 1);
} }
}); });
filter().type(EntityTypes1_19_3.ABSTRACT_MINECART).index(11).handler((event, meta) -> {
// Convert to new block id
final int data = (int) meta.getValue();
meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
});
} }
@Override @Override

Datei anzeigen

@ -221,11 +221,7 @@ public final class EntityPacketRewriter1_19_4 extends EntityRewriter<Clientbound
protected void registerRewrites() { protected void registerRewrites() {
filter().mapDataType(typeId -> Types1_19_4.ENTITY_DATA_TYPES.byId(typeId >= 14 ? typeId + 1 : typeId)); // Optional block state (and map block state=14 to optional block state) filter().mapDataType(typeId -> Types1_19_4.ENTITY_DATA_TYPES.byId(typeId >= 14 ? typeId + 1 : typeId)); // Optional block state (and map block state=14 to optional block state)
registerEntityDataTypeHandler(Types1_19_4.ENTITY_DATA_TYPES.itemType, Types1_19_4.ENTITY_DATA_TYPES.blockStateType, Types1_19_4.ENTITY_DATA_TYPES.optionalBlockStateType, Types1_19_4.ENTITY_DATA_TYPES.particleType, null); registerEntityDataTypeHandler(Types1_19_4.ENTITY_DATA_TYPES.itemType, Types1_19_4.ENTITY_DATA_TYPES.blockStateType, Types1_19_4.ENTITY_DATA_TYPES.optionalBlockStateType, Types1_19_4.ENTITY_DATA_TYPES.particleType, null);
registerBlockStateHandler(EntityTypes1_19_4.ABSTRACT_MINECART, 11);
filter().type(EntityTypes1_19_4.ABSTRACT_MINECART).index(11).handler((event, meta) -> {
final int blockState = meta.value();
meta.setValue(protocol.getMappingData().getNewBlockStateId(blockState));
});
filter().type(EntityTypes1_19_4.BOAT).index(11).handler((event, meta) -> { filter().type(EntityTypes1_19_4.BOAT).index(11).handler((event, meta) -> {
final int boatType = meta.value(); final int boatType = meta.value();

Datei anzeigen

@ -129,6 +129,7 @@ public final class EntityPacketRewriter1_20 extends EntityRewriter<ClientboundPa
protected void registerRewrites() { protected void registerRewrites() {
filter().mapDataType(Types1_20.ENTITY_DATA_TYPES::byId); filter().mapDataType(Types1_20.ENTITY_DATA_TYPES::byId);
registerEntityDataTypeHandler(Types1_20.ENTITY_DATA_TYPES.itemType, Types1_20.ENTITY_DATA_TYPES.blockStateType, Types1_20.ENTITY_DATA_TYPES.optionalBlockStateType, Types1_20.ENTITY_DATA_TYPES.particleType, null); registerEntityDataTypeHandler(Types1_20.ENTITY_DATA_TYPES.itemType, Types1_20.ENTITY_DATA_TYPES.blockStateType, Types1_20.ENTITY_DATA_TYPES.optionalBlockStateType, Types1_20.ENTITY_DATA_TYPES.particleType, null);
registerBlockStateHandler(EntityTypes1_19_4.ABSTRACT_MINECART, 11);
// Rotate item display by 180 degrees around the Y axis // Rotate item display by 180 degrees around the Y axis
filter().type(EntityTypes1_19_4.ITEM_DISPLAY).handler((event, meta) -> { filter().type(EntityTypes1_19_4.ITEM_DISPLAY).handler((event, meta) -> {
@ -144,11 +145,6 @@ public final class EntityPacketRewriter1_20 extends EntityRewriter<ClientboundPa
final Quaternion quaternion = meta.value(); final Quaternion quaternion = meta.value();
meta.setValue(rotateY180(quaternion)); meta.setValue(rotateY180(quaternion));
}); });
filter().type(EntityTypes1_19_4.ABSTRACT_MINECART).index(11).handler((event, meta) -> {
final int blockState = meta.value();
meta.setValue(protocol.getMappingData().getNewBlockStateId(blockState));
});
} }
@Override @Override

Datei anzeigen

@ -135,11 +135,7 @@ public final class EntityPacketRewriter1_20_3 extends EntityRewriter<Clientbound
Types1_20_3.ENTITY_DATA_TYPES.optionalBlockStateType, Types1_20_3.ENTITY_DATA_TYPES.optionalBlockStateType,
Types1_20_3.ENTITY_DATA_TYPES.particleType, Types1_20_3.ENTITY_DATA_TYPES.particleType,
null); null);
registerBlockStateHandler(EntityTypes1_20_3.ABSTRACT_MINECART, 11);
filter().type(EntityTypes1_20_3.ABSTRACT_MINECART).index(11).handler((event, meta) -> {
final int blockState = meta.value();
meta.setValue(protocol.getMappingData().getNewBlockStateId(blockState));
});
} }
@Override @Override

Datei anzeigen

@ -413,6 +413,8 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter<Clientbound
Types1_20_5.ENTITY_DATA_TYPES.particleType, Types1_20_5.ENTITY_DATA_TYPES.particleType,
null null
); );
registerBlockStateHandler(EntityTypes1_20_5.ABSTRACT_MINECART, 11);
filter().dataType(Types1_20_5.ENTITY_DATA_TYPES.componentType).handler((event, meta) -> protocol.getComponentRewriter().processTag(event.user(), meta.value())); filter().dataType(Types1_20_5.ENTITY_DATA_TYPES.componentType).handler((event, meta) -> protocol.getComponentRewriter().processTag(event.user(), meta.value()));
filter().dataType(Types1_20_5.ENTITY_DATA_TYPES.optionalComponentType).handler((event, meta) -> protocol.getComponentRewriter().processTag(event.user(), meta.value())); filter().dataType(Types1_20_5.ENTITY_DATA_TYPES.optionalComponentType).handler((event, meta) -> protocol.getComponentRewriter().processTag(event.user(), meta.value()));
@ -479,11 +481,6 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter<Clientbound
meta.setValue(withAlpha(color)); meta.setValue(withAlpha(color));
} }
}); });
filter().type(EntityTypes1_20_5.ABSTRACT_MINECART).index(11).handler((event, meta) -> {
final int blockState = meta.value();
meta.setValue(protocol.getMappingData().getNewBlockStateId(blockState));
});
} }
private void addColor(@Nullable final EntityData particleMeta, final int color) { private void addColor(@Nullable final EntityData particleMeta, final int color) {

Datei anzeigen

@ -174,13 +174,9 @@ public final class EntityPacketRewriter1_20_2 extends EntityRewriter<Clientbound
protected void registerRewrites() { protected void registerRewrites() {
filter().mapDataType(Types1_20_2.ENTITY_DATA_TYPES::byId); filter().mapDataType(Types1_20_2.ENTITY_DATA_TYPES::byId);
registerEntityDataTypeHandler(Types1_20_2.ENTITY_DATA_TYPES.itemType, Types1_20_2.ENTITY_DATA_TYPES.blockStateType, Types1_20_2.ENTITY_DATA_TYPES.optionalBlockStateType, Types1_20_2.ENTITY_DATA_TYPES.particleType, null); registerEntityDataTypeHandler(Types1_20_2.ENTITY_DATA_TYPES.itemType, Types1_20_2.ENTITY_DATA_TYPES.blockStateType, Types1_20_2.ENTITY_DATA_TYPES.optionalBlockStateType, Types1_20_2.ENTITY_DATA_TYPES.particleType, null);
registerBlockStateHandler(EntityTypes1_19_4.ABSTRACT_MINECART, 11);
filter().type(EntityTypes1_19_4.DISPLAY).addIndex(10); filter().type(EntityTypes1_19_4.DISPLAY).addIndex(10);
filter().type(EntityTypes1_19_4.ABSTRACT_MINECART).index(11).handler((event, meta) -> {
final int blockState = meta.value();
meta.setValue(protocol.getMappingData().getNewBlockStateId(blockState));
});
} }
@Override @Override

Datei anzeigen

@ -223,6 +223,13 @@ public abstract class EntityRewriter<C extends ClientboundPacketType, T extends
}); });
} }
public void registerBlockStateHandler(final EntityType entityType, final int index) {
filter().type(entityType).index(index).handler((event, meta) -> {
final int data = (int) meta.getValue();
meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
});
}
public void registerTracker(C packetType) { public void registerTracker(C packetType) {
protocol.registerClientbound(packetType, new PacketHandlers() { protocol.registerClientbound(packetType, new PacketHandlers() {
@Override @Override

Datei anzeigen

@ -101,12 +101,8 @@ public final class EntityPacketRewriter1_99 extends EntityRewriter<ClientboundPa
Types1_20_5.ENTITY_DATA_TYPES.particleType, Types1_20_5.ENTITY_DATA_TYPES.particleType,
Types1_20_5.ENTITY_DATA_TYPES.particlesType Types1_20_5.ENTITY_DATA_TYPES.particlesType
); );
// Minecarts are special // Minecarts are special
filter().type(EntityTypes1_20_5.ABSTRACT_MINECART).index(11).handler((event, data) -> { registerBlockStateHandler(EntityTypes1_20_5.ABSTRACT_MINECART, 11);
final int blockState = data.value();
data.setValue(protocol.getMappingData().getNewBlockStateId(blockState));
});
} }
@Override @Override