mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-11-25 03:25:11 +01:00
Add EntityRewriter#registerBlockStateHandler (#3912)
This commit is contained in:
parent
1ea27f1077
commit
bb48dc90f9
@ -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);
|
||||
|
||||
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).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) -> {
|
||||
event.cancel();
|
||||
|
||||
|
@ -109,10 +109,8 @@ public class EntityPacketRewriter1_13_1 extends EntityRewriter<ClientboundPacket
|
||||
@Override
|
||||
protected void registerRewrites() {
|
||||
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) -> {
|
||||
int data = meta.value();
|
||||
meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
|
||||
});
|
||||
registerBlockStateHandler(EntityTypes1_13.EntityType.ABSTRACT_MINECART, 9);
|
||||
|
||||
filter().type(EntityTypes1_13.EntityType.ABSTRACT_ARROW).addIndex(7); // Shooter UUID
|
||||
}
|
||||
|
||||
|
@ -115,10 +115,7 @@ public class EntityPacketRewriter1_15 extends EntityRewriter<ClientboundPackets1
|
||||
@Override
|
||||
protected void registerRewrites() {
|
||||
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) -> {
|
||||
int data = meta.value();
|
||||
meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
|
||||
});
|
||||
registerBlockStateHandler(EntityTypes1_15.ABSTRACT_MINECART, 10);
|
||||
|
||||
filter().type(EntityTypes1_15.LIVING_ENTITY).addIndex(12);
|
||||
filter().type(EntityTypes1_15.WOLF).removeIndex(18);
|
||||
|
@ -208,10 +208,8 @@ public class EntityPacketRewriter1_16 extends EntityRewriter<ClientboundPackets1
|
||||
protected void registerRewrites() {
|
||||
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);
|
||||
filter().type(EntityTypes1_16.ABSTRACT_MINECART).index(10).handler((metadatas, meta) -> {
|
||||
int data = meta.value();
|
||||
meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
|
||||
});
|
||||
registerBlockStateHandler(EntityTypes1_16.ABSTRACT_MINECART, 10);
|
||||
|
||||
filter().type(EntityTypes1_16.ABSTRACT_ARROW).removeIndex(8);
|
||||
filter().type(EntityTypes1_16.WOLF).index(16).handler((event, meta) -> {
|
||||
byte mask = meta.value();
|
||||
|
@ -78,10 +78,8 @@ public class EntityPacketRewriter1_16_2 extends EntityRewriter<ClientboundPacket
|
||||
@Override
|
||||
protected void registerRewrites() {
|
||||
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) -> {
|
||||
int data = meta.value();
|
||||
meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
|
||||
});
|
||||
registerBlockStateHandler(EntityTypes1_16_2.ABSTRACT_MINECART, 10);
|
||||
|
||||
filter().type(EntityTypes1_16_2.ABSTRACT_PIGLIN).handler((metadatas, meta) -> {
|
||||
if (meta.id() == 15) {
|
||||
meta.setId(16);
|
||||
|
@ -148,11 +148,7 @@ public final class EntityPacketRewriter1_17 extends EntityRewriter<ClientboundPa
|
||||
// Ticks frozen added with id 7
|
||||
filter().type(EntityTypes1_17.ENTITY).addIndex(7);
|
||||
|
||||
filter().type(EntityTypes1_17.ABSTRACT_MINECART).index(11).handler((event, meta) -> {
|
||||
// Convert to new block id
|
||||
int data = (int) meta.getValue();
|
||||
meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
|
||||
});
|
||||
registerBlockStateHandler(EntityTypes1_17.ABSTRACT_MINECART, 11);
|
||||
|
||||
// Attachment position removed
|
||||
filter().type(EntityTypes1_17.SHULKER).removeIndex(17);
|
||||
|
@ -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);
|
||||
|
||||
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));
|
||||
});
|
||||
registerBlockStateHandler(EntityTypes1_19.ABSTRACT_MINECART, 11);
|
||||
|
||||
filter().type(EntityTypes1_19.CAT).index(19).mapDataType(typeId -> Types1_19.ENTITY_DATA_TYPES.catVariantType);
|
||||
}
|
||||
|
@ -153,6 +153,7 @@ public final class EntityPacketRewriter1_19_3 extends EntityRewriter<Clientbound
|
||||
protected void registerRewrites() {
|
||||
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);
|
||||
registerBlockStateHandler(EntityTypes1_19_3.ABSTRACT_MINECART, 11);
|
||||
|
||||
filter().type(EntityTypes1_19_3.ENTITY).index(6).handler((event, meta) -> {
|
||||
// Sitting pose added
|
||||
@ -161,11 +162,6 @@ public final class EntityPacketRewriter1_19_3 extends EntityRewriter<Clientbound
|
||||
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
|
||||
|
@ -221,11 +221,7 @@ public final class EntityPacketRewriter1_19_4 extends EntityRewriter<Clientbound
|
||||
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)
|
||||
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);
|
||||
|
||||
filter().type(EntityTypes1_19_4.ABSTRACT_MINECART).index(11).handler((event, meta) -> {
|
||||
final int blockState = meta.value();
|
||||
meta.setValue(protocol.getMappingData().getNewBlockStateId(blockState));
|
||||
});
|
||||
registerBlockStateHandler(EntityTypes1_19_4.ABSTRACT_MINECART, 11);
|
||||
|
||||
filter().type(EntityTypes1_19_4.BOAT).index(11).handler((event, meta) -> {
|
||||
final int boatType = meta.value();
|
||||
|
@ -129,6 +129,7 @@ public final class EntityPacketRewriter1_20 extends EntityRewriter<ClientboundPa
|
||||
protected void registerRewrites() {
|
||||
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);
|
||||
registerBlockStateHandler(EntityTypes1_19_4.ABSTRACT_MINECART, 11);
|
||||
|
||||
// Rotate item display by 180 degrees around the Y axis
|
||||
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();
|
||||
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
|
||||
|
@ -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.particleType,
|
||||
null);
|
||||
|
||||
filter().type(EntityTypes1_20_3.ABSTRACT_MINECART).index(11).handler((event, meta) -> {
|
||||
final int blockState = meta.value();
|
||||
meta.setValue(protocol.getMappingData().getNewBlockStateId(blockState));
|
||||
});
|
||||
registerBlockStateHandler(EntityTypes1_20_3.ABSTRACT_MINECART, 11);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -413,6 +413,8 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter<Clientbound
|
||||
Types1_20_5.ENTITY_DATA_TYPES.particleType,
|
||||
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.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));
|
||||
}
|
||||
});
|
||||
|
||||
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) {
|
||||
|
@ -174,13 +174,9 @@ public final class EntityPacketRewriter1_20_2 extends EntityRewriter<Clientbound
|
||||
protected void registerRewrites() {
|
||||
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);
|
||||
registerBlockStateHandler(EntityTypes1_19_4.ABSTRACT_MINECART, 11);
|
||||
|
||||
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
|
||||
|
@ -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) {
|
||||
protocol.registerClientbound(packetType, new PacketHandlers() {
|
||||
@Override
|
||||
|
@ -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.particlesType
|
||||
);
|
||||
|
||||
// Minecarts are special
|
||||
filter().type(EntityTypes1_20_5.ABSTRACT_MINECART).index(11).handler((event, data) -> {
|
||||
final int blockState = data.value();
|
||||
data.setValue(protocol.getMappingData().getNewBlockStateId(blockState));
|
||||
});
|
||||
registerBlockStateHandler(EntityTypes1_20_5.ABSTRACT_MINECART, 11);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user