use of com.viaversion.viaversion.api.minecraft.VillagerData in project ViaVersion by ViaVersion.
the class MetadataRewriter1_14To1_13_2 method handleMetadata.
@Override
protected void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) throws Exception {
metadata.setMetaType(Types1_14.META_TYPES.byId(metadata.metaType().typeId()));
EntityTracker1_14 tracker = tracker(connection);
if (metadata.metaType() == Types1_14.META_TYPES.itemType) {
protocol.getItemRewriter().handleItemToClient((Item) metadata.getValue());
} else if (metadata.metaType() == Types1_14.META_TYPES.blockStateType) {
// Convert to new block id
int data = (int) metadata.getValue();
metadata.setValue(protocol.getMappingData().getNewBlockStateId(data));
} else if (metadata.metaType() == Types1_14.META_TYPES.particleType) {
rewriteParticle((Particle) metadata.getValue());
}
if (type == null)
return;
// Metadata 6 added to abstract_entity
if (metadata.id() > 5) {
metadata.setId(metadata.id() + 1);
}
if (metadata.id() == 8 && type.isOrHasParent(Entity1_14Types.LIVINGENTITY)) {
final float v = ((Number) metadata.getValue()).floatValue();
if (Float.isNaN(v) && Via.getConfig().is1_14HealthNaNFix()) {
metadata.setValue(1F);
}
}
// Metadata 12 added to living_entity
if (metadata.id() > 11 && type.isOrHasParent(Entity1_14Types.LIVINGENTITY)) {
metadata.setId(metadata.id() + 1);
}
if (type.isOrHasParent(Entity1_14Types.ABSTRACT_INSENTIENT)) {
if (metadata.id() == 13) {
tracker.setInsentientData(entityId, (byte) ((((Number) metadata.getValue()).byteValue() & ~0x4) | // New attacking metadata
(tracker.getInsentientData(entityId) & 0x4)));
metadata.setValue(tracker.getInsentientData(entityId));
}
}
if (type.isOrHasParent(Entity1_14Types.PLAYER)) {
if (entityId != tracker.clientEntityId()) {
if (metadata.id() == 0) {
byte flags = ((Number) metadata.getValue()).byteValue();
// Mojang overrides the client-side pose updater, see OtherPlayerEntity#updateSize
tracker.setEntityFlags(entityId, flags);
} else if (metadata.id() == 7) {
tracker.setRiptide(entityId, (((Number) metadata.getValue()).byteValue() & 0x4) != 0);
}
if (metadata.id() == 0 || metadata.id() == 7) {
metadatas.add(new Metadata(6, Types1_14.META_TYPES.poseType, recalculatePlayerPose(entityId, tracker)));
}
}
} else if (type.isOrHasParent(Entity1_14Types.ZOMBIE)) {
if (metadata.id() == 16) {
tracker.setInsentientData(entityId, (byte) ((tracker.getInsentientData(entityId) & ~0x4) | // New attacking
((boolean) metadata.getValue() ? 0x4 : 0)));
// "Are hands held up"
metadatas.remove(metadata);
metadatas.add(new Metadata(13, Types1_14.META_TYPES.byteType, tracker.getInsentientData(entityId)));
} else if (metadata.id() > 16) {
metadata.setId(metadata.id() - 1);
}
}
if (type.isOrHasParent(Entity1_14Types.MINECART_ABSTRACT)) {
if (metadata.id() == 10) {
// New block format
int data = (int) metadata.getValue();
metadata.setValue(protocol.getMappingData().getNewBlockStateId(data));
}
} else if (type.is(Entity1_14Types.HORSE)) {
if (metadata.id() == 18) {
metadatas.remove(metadata);
int armorType = (int) metadata.getValue();
Item armorItem = null;
if (armorType == 1) {
// iron armor
armorItem = new DataItem(protocol.getMappingData().getNewItemId(727), (byte) 1, (short) 0, null);
} else if (armorType == 2) {
// gold armor
armorItem = new DataItem(protocol.getMappingData().getNewItemId(728), (byte) 1, (short) 0, null);
} else if (armorType == 3) {
// diamond armor
armorItem = new DataItem(protocol.getMappingData().getNewItemId(729), (byte) 1, (short) 0, null);
}
PacketWrapper equipmentPacket = PacketWrapper.create(ClientboundPackets1_14.ENTITY_EQUIPMENT, null, connection);
equipmentPacket.write(Type.VAR_INT, entityId);
equipmentPacket.write(Type.VAR_INT, 4);
equipmentPacket.write(Type.FLAT_VAR_INT_ITEM, armorItem);
equipmentPacket.scheduleSend(Protocol1_14To1_13_2.class);
}
} else if (type.is(Entity1_14Types.VILLAGER)) {
if (metadata.id() == 15) {
// plains
metadata.setTypeAndValue(Types1_14.META_TYPES.villagerDatatType, new VillagerData(2, getNewProfessionId((int) metadata.getValue()), 0));
}
} else if (type.is(Entity1_14Types.ZOMBIE_VILLAGER)) {
if (metadata.id() == 18) {
// plains
metadata.setTypeAndValue(Types1_14.META_TYPES.villagerDatatType, new VillagerData(2, getNewProfessionId((int) metadata.getValue()), 0));
}
} else if (type.isOrHasParent(Entity1_14Types.ABSTRACT_ARROW)) {
if (metadata.id() >= 9) {
// New piercing
metadata.setId(metadata.id() + 1);
}
} else if (type.is(Entity1_14Types.FIREWORK_ROCKET)) {
if (metadata.id() == 8) {
metadata.setMetaType(Types1_14.META_TYPES.optionalVarIntType);
if (metadata.getValue().equals(0)) {
// https://bugs.mojang.com/browse/MC-111480
metadata.setValue(null);
}
}
} else if (type.isOrHasParent(Entity1_14Types.ABSTRACT_SKELETON)) {
if (metadata.id() == 14) {
tracker.setInsentientData(entityId, (byte) ((tracker.getInsentientData(entityId) & ~0x4) | // New attacking
((boolean) metadata.getValue() ? 0x4 : 0)));
// "Is swinging arms"
metadatas.remove(metadata);
metadatas.add(new Metadata(13, Types1_14.META_TYPES.byteType, tracker.getInsentientData(entityId)));
}
}
if (type.isOrHasParent(Entity1_14Types.ABSTRACT_ILLAGER_BASE)) {
if (metadata.id() == 14) {
tracker.setInsentientData(entityId, (byte) ((tracker.getInsentientData(entityId) & ~0x4) | // New attacking
(((Number) metadata.getValue()).byteValue() != 0 ? 0x4 : 0)));
// "Has target (aggressive state)"
metadatas.remove(metadata);
metadatas.add(new Metadata(13, Types1_14.META_TYPES.byteType, tracker.getInsentientData(entityId)));
}
}
if (type.is(Entity1_14Types.WITCH) || type.is(Entity1_14Types.RAVAGER) || type.isOrHasParent(Entity1_14Types.ABSTRACT_ILLAGER_BASE)) {
if (metadata.id() >= 14) {
// 19w13 added a new boolean (raid participant - is celebrating) with id 14
metadata.setId(metadata.id() + 1);
}
}
}
use of com.viaversion.viaversion.api.minecraft.VillagerData in project ViaBackwards by ViaVersion.
the class EntityPackets1_14 method registerRewrites.
@Override
protected void registerRewrites() {
mapTypes(Entity1_14Types.values(), Entity1_13Types.EntityType.class);
mapEntityTypeWithData(Entity1_14Types.CAT, Entity1_14Types.OCELOT).jsonName();
mapEntityTypeWithData(Entity1_14Types.TRADER_LLAMA, Entity1_14Types.LLAMA).jsonName();
mapEntityTypeWithData(Entity1_14Types.FOX, Entity1_14Types.WOLF).jsonName();
mapEntityTypeWithData(Entity1_14Types.PANDA, Entity1_14Types.POLAR_BEAR).jsonName();
mapEntityTypeWithData(Entity1_14Types.PILLAGER, Entity1_14Types.VILLAGER).jsonName();
mapEntityTypeWithData(Entity1_14Types.WANDERING_TRADER, Entity1_14Types.VILLAGER).jsonName();
mapEntityTypeWithData(Entity1_14Types.RAVAGER, Entity1_14Types.COW).jsonName();
filter().handler((event, meta) -> {
int typeId = meta.metaType().typeId();
if (typeId <= 15) {
meta.setMetaType(Types1_13_2.META_TYPES.byId(typeId));
}
MetaType type = meta.metaType();
if (type == Types1_13_2.META_TYPES.itemType) {
Item item = (Item) meta.getValue();
meta.setValue(protocol.getItemRewriter().handleItemToClient(item));
} else if (type == Types1_13_2.META_TYPES.blockStateType) {
int blockstate = meta.value();
meta.setValue(protocol.getMappingData().getNewBlockStateId(blockstate));
}
});
filter().type(Entity1_14Types.PILLAGER).cancel(15);
filter().type(Entity1_14Types.FOX).cancel(15);
filter().type(Entity1_14Types.FOX).cancel(16);
filter().type(Entity1_14Types.FOX).cancel(17);
filter().type(Entity1_14Types.FOX).cancel(18);
filter().type(Entity1_14Types.PANDA).cancel(15);
filter().type(Entity1_14Types.PANDA).cancel(16);
filter().type(Entity1_14Types.PANDA).cancel(17);
filter().type(Entity1_14Types.PANDA).cancel(18);
filter().type(Entity1_14Types.PANDA).cancel(19);
filter().type(Entity1_14Types.PANDA).cancel(20);
filter().type(Entity1_14Types.CAT).cancel(18);
filter().type(Entity1_14Types.CAT).cancel(19);
filter().type(Entity1_14Types.CAT).cancel(20);
filter().handler((event, meta) -> {
EntityType type = event.entityType();
if (type == null)
return;
if (type.isOrHasParent(Entity1_14Types.ABSTRACT_ILLAGER_BASE) || type == Entity1_14Types.RAVAGER || type == Entity1_14Types.WITCH) {
int index = event.index();
if (index == 14) {
event.cancel();
} else if (index > 14) {
event.setIndex(index - 1);
}
}
});
filter().type(Entity1_14Types.AREA_EFFECT_CLOUD).index(10).handler((event, meta) -> {
rewriteParticle((Particle) meta.getValue());
});
filter().type(Entity1_14Types.FIREWORK_ROCKET).index(8).handler((event, meta) -> {
meta.setMetaType(Types1_13_2.META_TYPES.varIntType);
Integer value = (Integer) meta.getValue();
if (value == null) {
meta.setValue(0);
}
});
filter().filterFamily(Entity1_14Types.ABSTRACT_ARROW).removeIndex(9);
// Head shake timer
filter().type(Entity1_14Types.VILLAGER).cancel(15);
MetaHandler villagerDataHandler = (event, meta) -> {
VillagerData villagerData = (VillagerData) meta.getValue();
meta.setTypeAndValue(Types1_13_2.META_TYPES.varIntType, villagerDataToProfession(villagerData));
if (meta.id() == 16) {
// decreased by 2 again in one of the following handlers
event.setIndex(15);
}
};
filter().type(Entity1_14Types.ZOMBIE_VILLAGER).index(18).handler(villagerDataHandler);
filter().type(Entity1_14Types.VILLAGER).index(16).handler(villagerDataHandler);
// Holding arms up - from bitfield into own boolean
filter().filterFamily(Entity1_14Types.ABSTRACT_SKELETON).index(13).handler((event, meta) -> {
byte value = (byte) meta.getValue();
if ((value & 4) != 0) {
event.createExtraMeta(new Metadata(14, Types1_13_2.META_TYPES.booleanType, true));
}
});
filter().filterFamily(Entity1_14Types.ZOMBIE).index(13).handler((event, meta) -> {
byte value = (byte) meta.getValue();
if ((value & 4) != 0) {
event.createExtraMeta(new Metadata(16, Types1_13_2.META_TYPES.booleanType, true));
}
});
filter().filterFamily(Entity1_14Types.ZOMBIE).addIndex(16);
// Remove bed location
filter().filterFamily(Entity1_14Types.LIVINGENTITY).handler((event, meta) -> {
int index = event.index();
if (index == 12) {
Position position = (Position) meta.getValue();
if (position != null) {
// Use bed
PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_13.USE_BED, null, event.user());
wrapper.write(Type.VAR_INT, event.entityId());
wrapper.write(Type.POSITION, position);
try {
wrapper.scheduleSend(Protocol1_13_2To1_14.class);
} catch (Exception ex) {
ex.printStackTrace();
}
}
event.cancel();
} else if (index > 12) {
event.setIndex(index - 1);
}
});
// Pose
filter().removeIndex(6);
filter().type(Entity1_14Types.OCELOT).index(13).handler((event, meta) -> {
event.setIndex(15);
meta.setTypeAndValue(Types1_13_2.META_TYPES.varIntType, 0);
});
filter().type(Entity1_14Types.CAT).handler((event, meta) -> {
if (event.index() == 15) {
meta.setValue(1);
} else if (event.index() == 13) {
meta.setValue((byte) ((byte) meta.getValue() & 0x4));
}
});
filter().handler((event, meta) -> {
if (meta.metaType().typeId() > 15) {
throw new IllegalArgumentException("Unhandled metadata: " + meta);
}
});
}
Aggregations