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

The following examples show how to use us.myles.ViaVersion.api.minecraft.metadata.Metadata#getId() . 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: GuardianReplacement.java    From ViaRewind with MIT License 6 votes vote down vote up
public void updateMetadata() {
	PacketWrapper metadataPacket = new PacketWrapper(0x1C, null, user);
	metadataPacket.write(Type.INT, entityId);

	List<Metadata> metadataList = new ArrayList<>();
	for (Metadata metadata : datawatcher) {
		if (metadata.getId()==16 || metadata.getId()==17) continue;
		metadataList.add(new Metadata(metadata.getId(), metadata.getMetaType(), metadata.getValue()));
	}

	MetadataRewriter.transform(Entity1_10Types.EntityType.SQUID, metadataList);

	metadataPacket.write(Types1_7_6_10.METADATA_LIST, metadataList);

	PacketUtil.sendPacket(metadataPacket, Protocol1_7_6_10TO1_8.class);
}
 
Example 2
Source File: ShulkerReplacement.java    From ViaRewind with MIT License 6 votes vote down vote up
public void updateMetadata() {
	PacketWrapper metadataPacket = new PacketWrapper(0x1C, null, user);
	metadataPacket.write(Type.VAR_INT, entityId);

	List<Metadata> metadataList = new ArrayList<>();
	for (Metadata metadata : datawatcher) {
		if (metadata.getId()==11 || metadata.getId()==12 || metadata.getId()==13) continue;
		metadataList.add(new Metadata(metadata.getId(), metadata.getMetaType(), metadata.getValue()));
	}
	metadataList.add(new Metadata(11, MetaType1_9.VarInt, 2));

	MetadataRewriter.transform(Entity1_10Types.EntityType.MAGMA_CUBE, metadataList);

	metadataPacket.write(Types1_8.METADATA_LIST, metadataList);

	PacketUtil.sendPacket(metadataPacket, Protocol1_8TO1_9.class);
}
 
Example 3
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 4
Source File: MetaStorage.java    From ViaBackwards with MIT License 5 votes vote down vote up
@Nullable
public Metadata get(int index) {
    for (Metadata meta : this.metaDataList) {
        if (index == meta.getId()) {
            return meta;
        }
    }
    return null;
}
 
Example 5
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 6
Source File: MetaHandlerSettings.java    From ViaBackwards with MIT License 5 votes vote down vote up
/**
 * Returns true if the metadata should be handled by this object.
 *
 * @param type     entity type
 * @param metadata metadata
 * @return true if gucci
 */
public boolean isGucci(EntityType type, Metadata metadata) {
    if (!hasHandler()) return false;
    if (hasType() && (filterFamily ? !type.isOrHasParent(filterType) : !filterType.is(type))) {
        return false;
    }
    return !hasIndex() || metadata.getId() == filterIndex;
}
 
Example 7
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 8
Source File: MetadataRewriter1_14_1To1_14.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) {
    if (type == null) return;

    if (type == Entity1_14Types.EntityType.VILLAGER || type == Entity1_14Types.EntityType.WANDERING_TRADER) {
        if (metadata.getId() >= 15) {
            metadata.setId(metadata.getId() + 1);
        }
    }
}
 
Example 9
Source File: MetaHandlerEvent.java    From ViaBackwards with MIT License 5 votes vote down vote up
public Metadata getMetaByIndex(int index) {
    for (Metadata meta : storage.getMetaDataList()) {
        if (index == meta.getId()) {
            return meta;
        }
    }
    return null;
}
 
Example 10
Source File: Protocol1_10To1_9_3_4.java    From ViaVersion with MIT License 5 votes vote down vote up
@Override
public List<Metadata> transform(PacketWrapper wrapper, List<Metadata> inputValue) throws Exception {
    List<Metadata> metaList = new CopyOnWriteArrayList<>(inputValue);
    for (Metadata m : metaList) {
        if (m.getId() >= 5)
            m.setId(m.getId() + 1);
    }
    return metaList;
}
 
Example 11
Source File: MetadataRewriter1_12To1_11_1.java    From ViaVersion with MIT License 5 votes vote down vote up
@Override
protected void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) {
    if (metadata.getValue() instanceof Item) {
        // Apply rewrite
        BedRewriter.toClientItem((Item) metadata.getValue());
    }

    if (type == null) return;
    // Evocation Illager aggressive property became 13
    if (type == Entity1_12Types.EntityType.EVOCATION_ILLAGER) {
        if (metadata.getId() == 12) {
            metadata.setId(13);
        }
    }
}
 
Example 12
Source File: EntityTracker1_9.java    From ViaVersion with MIT License 4 votes vote down vote up
public Metadata getMetaByIndex(List<Metadata> list, int index) {
    for (Metadata meta : list)
        if (index == meta.getId())
            return meta;
    return null;
}
 
Example 13
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
}
 
Example 14
Source File: MetadataRewriter1_11To1_10.java    From ViaVersion with MIT License 4 votes vote down vote up
public static Optional<Metadata> getById(List<Metadata> metadatas, int id) {
    for (Metadata metadata : metadatas) {
        if (metadata.getId() == id) return Optional.of(metadata);
    }
    return Optional.empty();
}
 
Example 15
Source File: MetadataListType.java    From ViaRewind with MIT License 4 votes vote down vote up
private Metadata find(int id, String type, List<Metadata> list) {
	for (Metadata metadata : list) if (metadata.getId()==id && metadata.getMetaType().toString().equals(type)) return metadata;
	return null;
}
 
Example 16
Source File: Metadata1_8Type.java    From ViaVersion with MIT License 4 votes vote down vote up
@Override
public void write(ByteBuf buffer, Metadata meta) throws Exception {
    byte item = (byte) (meta.getMetaType().getTypeID() << 5 | meta.getId() & 0x1F);
    buffer.writeByte(item);
    meta.getMetaType().getType().write(buffer, meta.getValue());
}
 
Example 17
Source File: MetadataType.java    From ViaRewind with MIT License 4 votes vote down vote up
@Override
public void write(ByteBuf buffer, Metadata meta) throws Exception {
	int item = (meta.getMetaType().getTypeID() << 5 | meta.getId() & 31) & 255;
	buffer.writeByte(item);
	meta.getMetaType().getType().write(buffer, meta.getValue());
}