Java Code Examples for cn.nukkit.item.Item#setDamage()

The following examples show how to use cn.nukkit.item.Item#setDamage() . 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: NBTIO.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public static Item getItemHelper(CompoundTag tag) {
    if (!tag.contains("id") || !tag.contains("Count")) {
        return Item.get(0);
    }

    Item item;
    try {
        item = Item.get(tag.getShort("id"), !tag.contains("Damage") ? 0 : tag.getShort("Damage"), tag.getByte("Count"));
    } catch (Exception e) {
        item = Item.fromString(tag.getString("id"));
        item.setDamage(!tag.contains("Damage") ? 0 : tag.getShort("Damage"));
        item.setCount(tag.getByte("Count"));
    }

    Tag tagTag = tag.get("tag");
    if (tagTag instanceof CompoundTag) {
        item.setNamedTag((CompoundTag) tagTag);
    }

    return item;
}
 
Example 2
Source File: BlockBanner.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Item toItem() {
    BlockEntity blockEntity = this.getLevel().getBlockEntity(this);
    Item item = Item.get(Item.BANNER);
    if (blockEntity instanceof BlockEntityBanner) {
        BlockEntityBanner banner = (BlockEntityBanner) blockEntity;
        item.setDamage(banner.getBaseColor() & 0xf);
        item.setNamedTag((item.hasCompoundTag() ? item.getNamedTag() : new CompoundTag())
                .putInt("Base", banner.getBaseColor() & 0xf));
        int type = banner.namedTag.getInt("Type");
        if (type > 0) {
            item.setNamedTag((item.hasCompoundTag() ? item.getNamedTag() : new CompoundTag())
                    .putInt("Type", type));
        }
        ListTag<CompoundTag> patterns = banner.namedTag.getList("Patterns", CompoundTag.class);
        if (patterns.size() > 0) {
            item.setNamedTag((item.hasCompoundTag() ? item.getNamedTag() : new CompoundTag())
                    .putList(patterns));
        }
    }
    return item;
}
 
Example 3
Source File: NBTIO.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public static Item getItemHelper(CompoundTag tag) {
    if (!tag.contains("id") || !tag.contains("Count")) {
        return Item.get(0);
    }

    Item item;
    try {
        item = Item.get(tag.getShort("id"), !tag.contains("Damage") ? 0 : tag.getShort("Damage"), tag.getByte("Count"));
    } catch (Exception e) {
        item = Item.fromString(tag.getString("id"));
        item.setDamage(!tag.contains("Damage") ? 0 : tag.getShort("Damage"));
        item.setCount(tag.getByte("Count"));
    }

    if (tag.contains("tag") && tag.get("tag") instanceof CompoundTag) {
        item.setNamedTag(tag.getCompound("tag"));
    }

    return item;
}
 
Example 4
Source File: BlockAnvil.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Item[] getDrops(Item item) {
    int damage = this.getDamage();
    if (item.isPickaxe() && item.getTier() >= ItemTool.TIER_WOODEN) {
        Item drop = this.toItem();

        if (damage >= 4 && damage <= 7) { //Slightly Anvil
            drop.setDamage(drop.getDamage() & 0x04);
        } else if (damage >= 8 && damage <= 11) { //Very Damaged Anvil
            drop.setDamage(drop.getDamage() & 0x08);
        }
    }
    return new Item[0];
}
 
Example 5
Source File: BlockAnvil.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Item[] getDrops(Item item) {
    int damage = this.getDamage();
    if (item.isPickaxe() && item.getTier() >= ItemTool.TIER_WOODEN) {
        Item drop = this.toItem();

        if (damage >= 4 && damage <= 7) { //Slightly Anvil
            drop.setDamage(drop.getDamage() & 0x04);
        } else if (damage >= 8 && damage <= 11) { //Very Damaged Anvil
            drop.setDamage(drop.getDamage() & 0x08);
        }
    }
    return new Item[0];
}
 
Example 6
Source File: BlockEntityFurnace.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
protected void checkFuel(Item fuel) {

        FurnaceBurnEvent ev = new FurnaceBurnEvent(this, fuel, fuel.getFuelTime() == null ? 0 : fuel.getFuelTime());

        if (ev.isCancelled()) {
            return;
        }

        maxTime = ev.getBurnTime();
        burnTime = ev.getBurnTime();
        burnDuration = 0;
        if (this.getBlock().getId() == Item.FURNACE) {
            this.getLevel().setBlock(this, new BlockFurnaceBurning(this.getBlock().getDamage()), true);
        }

        if (burnTime > 0 && ev.isBurning()) {
            fuel.setCount(fuel.getCount() - 1);
            if (fuel.getCount() == 0) {
                if (fuel.getId() == Item.BUCKET && fuel.getDamage() == 10) {
                    fuel.setDamage(0);
                    fuel.setCount(1);
                } else {
                    fuel = new ItemBlock(new BlockAir(), 0, 0);
                }
            }
            this.inventory.setFuel(fuel);
        }
    }
 
Example 7
Source File: BlockStairs.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Item toItem() {
    Item item = super.toItem();
    item.setDamage(0);
    return item;
}
 
Example 8
Source File: BlockStairs.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Item toItem() {
    Item item = super.toItem();
    item.setDamage(0);
    return item;
}
 
Example 9
Source File: BlockStairs.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Item toItem() {
    Item item = super.toItem();
    item.setDamage(0);
    return item;
}