use of com.viaversion.viaversion.api.minecraft.metadata.Metadata in project ViaBackwards by ViaVersion.
the class EntityRewriterBase method handleMetadata.
@Override
public void handleMetadata(int entityId, List<Metadata> metadataList, UserConnection connection) {
super.handleMetadata(entityId, metadataList, connection);
EntityType type = tracker(connection).entityType(entityId);
if (type == null) {
// Don't handle untracked entities - basically always the fault of a plugin sending virtual entities through concurrency-unsafe handling
return;
}
EntityData entityData = entityDataForType(type);
// Set the mapped entity name if there is no custom name set already
Metadata meta = getMeta(displayNameIndex, metadataList);
if (meta != null && entityData != null && entityData.mobName() != null && (meta.getValue() == null || meta.getValue().toString().isEmpty()) && meta.metaType().typeId() == displayNameMetaType.typeId()) {
meta.setValue(entityData.mobName());
if (ViaBackwards.getConfig().alwaysShowOriginalMobName()) {
removeMeta(displayVisibilityIndex, metadataList);
metadataList.add(new Metadata(displayVisibilityIndex, displayVisibilityMetaType, true));
}
}
// TODO only do this once for a first meta packet?
if (entityData != null && entityData.hasBaseMeta()) {
entityData.defaultMeta().createMeta(new WrappedMetadata(metadataList));
}
}
use of com.viaversion.viaversion.api.minecraft.metadata.Metadata in project ViaVersion by ViaVersion.
the class MetaListType method read.
@Override
public List<Metadata> read(final ByteBuf buffer) throws Exception {
final List<Metadata> list = new ArrayList<>();
Metadata meta;
do {
meta = this.type.read(buffer);
if (meta != null) {
list.add(meta);
}
} while (meta != null);
return list;
}
use of com.viaversion.viaversion.api.minecraft.metadata.Metadata in project ViaVersion by ViaVersion.
the class ModernMetaType method read.
@Override
public Metadata read(final ByteBuf buffer) throws Exception {
final short index = buffer.readUnsignedByte();
// End of metadata
if (index == END)
return null;
final MetaType type = this.getType(Type.VAR_INT.readPrimitive(buffer));
return new Metadata(index, type, type.type().read(buffer));
}
use of com.viaversion.viaversion.api.minecraft.metadata.Metadata in project ViaVersion by ViaVersion.
the class MetadataRewriter1_13To1_12_2 method handleMetadata.
@Override
protected void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) throws Exception {
// Handle new MetaTypes
if (metadata.metaType().typeId() > 4) {
metadata.setMetaType(Types1_13.META_TYPES.byId(metadata.metaType().typeId() + 1));
} else {
metadata.setMetaType(Types1_13.META_TYPES.byId(metadata.metaType().typeId()));
}
// Handle String -> Chat DisplayName
if (metadata.id() == 2) {
if (metadata.getValue() != null && !((String) metadata.getValue()).isEmpty()) {
metadata.setTypeAndValue(Types1_13.META_TYPES.optionalComponentType, ChatRewriter.legacyTextToJson((String) metadata.getValue()));
} else {
metadata.setTypeAndValue(Types1_13.META_TYPES.optionalComponentType, null);
}
}
// Remap held block to match new format for remapping to flat block
if (type == Entity1_13Types.EntityType.ENDERMAN && metadata.id() == 12) {
int stateId = (int) metadata.getValue();
int id = stateId & 4095;
int data = stateId >> 12 & 15;
metadata.setValue((id << 4) | (data & 0xF));
}
// 1.13 changed item to flat item (no data)
if (metadata.metaType() == Types1_13.META_TYPES.itemType) {
metadata.setMetaType(Types1_13.META_TYPES.itemType);
protocol.getItemRewriter().handleItemToClient((Item) metadata.getValue());
} else if (metadata.metaType() == Types1_13.META_TYPES.blockStateType) {
// Convert to new block id
metadata.setValue(WorldPackets.toNewId((int) metadata.getValue()));
}
// Skip type related changes when the type is null
if (type == null)
return;
// Handle new colors
if (type == Entity1_13Types.EntityType.WOLF && metadata.id() == 17) {
metadata.setValue(15 - (int) metadata.getValue());
}
// Handle new zombie meta (INDEX 15 - Boolean - Zombie is shaking while enabled)
if (type.isOrHasParent(Entity1_13Types.EntityType.ZOMBIE)) {
if (metadata.id() > 14)
metadata.setId(metadata.id() + 1);
}
// Handle Minecart inner block
if (type.isOrHasParent(Entity1_13Types.EntityType.MINECART_ABSTRACT) && metadata.id() == 9) {
// New block format
int oldId = (int) metadata.getValue();
int combined = (((oldId & 4095) << 4) | (oldId >> 12 & 15));
int newId = WorldPackets.toNewId(combined);
metadata.setValue(newId);
}
// Handle other changes
if (type == Entity1_13Types.EntityType.AREA_EFFECT_CLOUD) {
if (metadata.id() == 9) {
int particleId = (int) metadata.getValue();
Metadata parameter1Meta = metaByIndex(10, metadatas);
Metadata parameter2Meta = metaByIndex(11, metadatas);
int parameter1 = parameter1Meta != null ? (int) parameter1Meta.getValue() : 0;
int parameter2 = parameter2Meta != null ? (int) parameter2Meta.getValue() : 0;
Particle particle = ParticleRewriter.rewriteParticle(particleId, new Integer[] { parameter1, parameter2 });
if (particle != null && particle.getId() != -1) {
metadatas.add(new Metadata(9, Types1_13.META_TYPES.particleType, particle));
}
}
if (metadata.id() >= 9)
// Remove
metadatas.remove(metadata);
}
if (metadata.id() == 0) {
// Previously unused, now swimming
metadata.setValue((byte) ((byte) metadata.getValue() & ~0x10));
}
// TODO: Boat has changed
}
use of com.viaversion.viaversion.api.minecraft.metadata.Metadata 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);
}
}
}
Aggregations