Java Code Examples for us.myles.ViaVersion.api.minecraft.metadata.Metadata#getMetaType()

The following examples show how to use us.myles.ViaVersion.api.minecraft.metadata.Metadata#getMetaType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MetadataRewriter1_16To1_15_2.java    From ViaVersion with MIT License 6 votes vote down vote up
@Override
public void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) throws Exception {
    if (metadata.getMetaType() == MetaType1_14.Slot) {
        InventoryPackets.toClient((Item) metadata.getValue());
    } else if (metadata.getMetaType() == MetaType1_14.BlockID) {
        int data = (int) metadata.getValue();
        metadata.setValue(Protocol1_16To1_15_2.getNewBlockStateId(data));
    }

    if (type == null) return;

    if (type == Entity1_16Types.EntityType.AREA_EFFECT_CLOUD) {
        if (metadata.getId() == 10) {
            Particle particle = (Particle) metadata.getValue();
            particle.setId(WorldPackets.getNewParticleId(particle.getId()));
        }
    } else if (type.isOrHasParent(Entity1_16Types.EntityType.ABSTRACT_ARROW)) {
        if (metadata.getId() == 8) {
            metadatas.remove(metadata);
        } else if (metadata.getId() > 8) {
            metadata.setId(metadata.getId() - 1);
        }
    }
}
 
Example 2
Source File: ArmorStandReplacement.java    From ViaRewind with MIT License 5 votes vote down vote up
public void updateState() {
	byte flags = 0;
	byte armorStandFlags = 0;
	for (Metadata metadata : datawatcher) {
		if (metadata.getId() == 0 && metadata.getMetaType() == MetaType1_8.Byte) {
			flags = (byte) metadata.getValue();
		} else if (metadata.getId() == 2 && metadata.getMetaType() == MetaType1_8.String) {
			name = (String) metadata.getValue();
			if (name != null && name.equals("")) name = null;
		} else if (metadata.getId() == 10 && metadata.getMetaType() == MetaType1_8.Byte) {
			armorStandFlags = (byte) metadata.getValue();
		} else if (metadata.getId() == 3 && metadata.getMetaType() == MetaType1_8.Byte) {
			nameTagVisible = (byte) metadata.getId() != 0;
		}
	}
	invisible = (flags & 0x20) != 0;
	small = (armorStandFlags & 0x01) != 0;
	marker = (armorStandFlags & 0x10) != 0;

	State prevState = currentState;
	if (invisible && name != null) {
		currentState = State.HOLOGRAM;
	} else {
		currentState = State.ZOMBIE;
	}

	if (currentState != prevState) {
		despawn();
		spawn();
	} else {
		updateMetadata();
		updateLocation();
	}
}
 
Example 3
Source File: ModernMetaType.java    From ViaVersion with MIT License 5 votes vote down vote up
@Override
public void write(final ByteBuf buffer, final Metadata object) throws Exception {
    if (object == null) {
        buffer.writeByte(0xff);
    } else {
        buffer.writeByte(object.getId());
        final MetaType type = object.getMetaType();
        buffer.writeByte(type.getTypeID());
        type.getType().write(buffer, object.getValue());
    }
}
 
Example 4
Source File: MetadataRewriter1_15To1_14_4.java    From ViaVersion with MIT License 5 votes vote down vote up
@Override
public void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) throws Exception {
    if (metadata.getMetaType() == MetaType1_14.Slot) {
        InventoryPackets.toClient((Item) metadata.getValue());
    } else if (metadata.getMetaType() == MetaType1_14.BlockID) {
        // Convert to new block id
        int data = (int) metadata.getValue();
        metadata.setValue(Protocol1_15To1_14_4.getNewBlockStateId(data));
    }

    if (type == null) return;

    // Metadata 12 added to abstract_living
    if (metadata.getId() > 11 && type.isOrHasParent(Entity1_15Types.EntityType.LIVINGENTITY)) {
        metadata.setId(metadata.getId() + 1); //TODO is it 11 or 12? what is it for?
    }

    //NOTES:
    //new boolean with id 11 for trident, default = false, added in 19w45a
    //new boolean with id 17 for enderman

    if (type.isOrHasParent(Entity1_15Types.EntityType.WOLF)) {
        if (metadata.getId() == 18) {
            metadatas.remove(metadata);
        } else if (metadata.getId() > 18) {
            metadata.setId(metadata.getId() - 1);
        }
    }
}
 
Example 5
Source File: MetadataRewriter1_13To1_12_2.java    From ViaVersion with MIT License 4 votes vote down vote up
@Override
protected void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, Map<Integer, Metadata> metadataMap, UserConnection connection) throws Exception {
    // Handle new MetaTypes
    if (metadata.getMetaType().getTypeID() > 4) {
        metadata.setMetaType(MetaType1_13.byId(metadata.getMetaType().getTypeID() + 1));
    } else {
        metadata.setMetaType(MetaType1_13.byId(metadata.getMetaType().getTypeID()));
    }

    // Handle String -> Chat DisplayName
    if (metadata.getId() == 2) {
        metadata.setMetaType(MetaType1_13.OptChat);
        if (metadata.getValue() != null && !((String) metadata.getValue()).isEmpty()) {
            metadata.setValue(ChatRewriter.legacyTextToJson((String) metadata.getValue()));
        } else {
            metadata.setValue(null);
        }
    }

    // 1.13 changed item to flat item (no data)
    if (metadata.getMetaType() == MetaType1_13.Slot) {
        metadata.setMetaType(MetaType1_13.Slot);
        InventoryPackets.toClient((Item) metadata.getValue());
    } else if (metadata.getMetaType() == MetaType1_13.BlockID) {
        // 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.getId() == 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.getId() > 14)
            metadata.setId(metadata.getId() + 1);
    }

    // Handle Minecart inner block
    if (type.isOrHasParent(Entity1_13Types.EntityType.MINECART_ABSTRACT) && metadata.getId() == 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.getId() == 9) {
            int particleId = (int) metadata.getValue();
            int parameter1 = metadataMap.containsKey(10) ? (int) metadataMap.get(10).getValue() : 0;
            int parameter2 = metadataMap.containsKey(11) ? (int) metadataMap.get(11).getValue() : 0;

            Particle particle = ParticleRewriter.rewriteParticle(particleId, new Integer[]{parameter1, parameter2});
            if (particle != null && particle.getId() != -1) {
                metadatas.add(new Metadata(9, MetaType1_13.PARTICLE, particle));
            }
        }

        if (metadata.getId() >= 9)
            metadatas.remove(metadata); // Remove
    }

    if (metadata.getId() == 0) {
        metadata.setValue((byte) ((byte) metadata.getValue() & ~0x10)); // Previously unused, now swimming
    }

    // TODO: Boat has changed
}