Java Code Examples for us.myles.ViaVersion.api.minecraft.item.Item#setAmount()

The following examples show how to use us.myles.ViaVersion.api.minecraft.item.Item#setAmount() . 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: ItemType.java    From ViaRewind with MIT License 5 votes vote down vote up
@Override
public Item read(ByteBuf buffer) throws Exception {
	int readerIndex = buffer.readerIndex();
	short id = buffer.readShort();
	if (id < 0) {
		return null;
	}
	Item item = new Item();
	item.setIdentifier(id);
	item.setAmount(buffer.readByte());
	item.setData(buffer.readShort());
	item.setTag((compressed ? Types1_7_6_10.COMPRESSED_NBT : Types1_7_6_10.NBT).read(buffer));
	return item;
}
 
Example 2
Source File: FlatItemType.java    From ViaVersion with MIT License 5 votes vote down vote up
@Override
public Item read(ByteBuf buffer) throws Exception {
    short id = buffer.readShort();
    if (id < 0) {
        return null;
    } else {
        Item item = new Item();
        item.setIdentifier(id);
        item.setAmount(buffer.readByte());
        item.setTag(Type.NBT.read(buffer));
        return item;
    }
}
 
Example 3
Source File: ItemType.java    From ViaVersion with MIT License 5 votes vote down vote up
@Override
public Item read(ByteBuf buffer) throws Exception {
    short id = buffer.readShort();
    if (id < 0) {
        return null;
    } else {
        Item item = new Item();
        item.setIdentifier(id);
        item.setAmount(buffer.readByte());
        item.setData(buffer.readShort());
        item.setTag(Type.NBT.read(buffer));
        return item;
    }
}
 
Example 4
Source File: FlatVarIntItemType.java    From ViaVersion with MIT License 5 votes vote down vote up
@Override
public Item read(ByteBuf buffer) throws Exception {
    boolean present = buffer.readBoolean();
    if (!present) {
        return null;
    } else {
        Item item = new Item();
        item.setIdentifier(Type.VAR_INT.readPrimitive(buffer));
        item.setAmount(buffer.readByte());
        item.setTag(Type.NBT.read(buffer));
        return item;
    }
}
 
Example 5
Source File: ItemRewriterBase.java    From ViaBackwards with MIT License 5 votes vote down vote up
@Nullable
public Item handleItemToServer(Item item) {
    if (item == null) return null;

    CompoundTag tag = item.getTag();
    if (tag == null) {
        if (toServerRewriter != null) {
            item.setIdentifier(toServerRewriter.rewrite(item.getIdentifier()));
        }
        return item;
    }

    CompoundTag viaTag = tag.remove(nbtTagName);
    if (viaTag != null) {
        short id = (short) viaTag.get("id").getValue();
        item.setIdentifier(id);

        Tag dataTag = viaTag.get("data");
        short data = dataTag != null ? (short) dataTag.getValue() : 0;
        item.setData(data);

        Tag amountTag = viaTag.get("amount");
        byte amount = amountTag != null ? (byte) amountTag.getValue() : 1;
        item.setAmount(amount);

        CompoundTag extras = viaTag.get("extras");
        if (extras != null) {
            item.setTag(CONVERTER.convert("", CONVERTER.convert(extras)));
        }
    } else {
        // Rewrite id normally
        if (toServerRewriter != null) {
            item.setIdentifier(toServerRewriter.rewrite(item.getIdentifier()));
        }
    }
    return item;
}
 
Example 6
Source File: EntityIdRewriter.java    From ViaVersion with MIT License 4 votes vote down vote up
public static void toClientItem(Item item, boolean backwards) {
    if (hasEntityTag(item)) {
        toClient(item.getTag().get("EntityTag"), backwards);
    }
    if (item != null && item.getAmount() <= 0) item.setAmount((byte) 1);
}