Java Code Examples for cn.nukkit.item.Item#AIR

The following examples show how to use cn.nukkit.item.Item#AIR . 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: BlockEntityHopper.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void setItem(int index, Item item) {
    int i = this.getSlotIndex(index);

    CompoundTag d = NBTIO.putItemHelper(item, index);

    if (item.getId() == Item.AIR || item.getCount() <= 0) {
        if (i >= 0) {
            this.namedTag.getList("Items").getAll().remove(i);
        }
    } else if (i < 0) {
        (this.namedTag.getList("Items", CompoundTag.class)).add(d);
    } else {
        (this.namedTag.getList("Items", CompoundTag.class)).add(i, d);
    }
}
 
Example 2
Source File: BlockEntityShulkerBox.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void setItem(int index, Item item) {
    int i = this.getSlotIndex(index);

    CompoundTag d = NBTIO.putItemHelper(item, index);

    if (item.getId() == Item.AIR || item.getCount() <= 0) {
        if (i >= 0) {
            this.namedTag.getList("Items").remove(i);
        }
    } else if (i < 0) {
        (this.namedTag.getList("Items", CompoundTag.class)).add(d);
    } else {
        (this.namedTag.getList("Items", CompoundTag.class)).add(i, d);
    }
}
 
Example 3
Source File: BlockWallSign.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
@Override
public int onUpdate(int type) {
    int[] faces = {
            3,
            2,
            5,
            4,
    };
    if (type == Level.BLOCK_UPDATE_NORMAL) {
        if (this.meta >= 2 && this.meta <= 5) {
            if (this.getSide(BlockFace.fromIndex(faces[this.meta - 2])).getId() == Item.AIR) {
                this.getLevel().useBreakOn(this);
            }
            return Level.BLOCK_UPDATE_NORMAL;
        }
    }
    return 0;
}
 
Example 4
Source File: BlockEntityFurnace.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void setItem(int index, Item item) {
    int i = this.getSlotIndex(index);

    CompoundTag d = NBTIO.putItemHelper(item, index);

    if (item.getId() == Item.AIR || item.getCount() <= 0) {
        if (i >= 0) {
            this.namedTag.getList("Items").getAll().remove(i);
        }
    } else if (i < 0) {
        (this.namedTag.getList("Items", CompoundTag.class)).add(d);
    } else {
        (this.namedTag.getList("Items", CompoundTag.class)).add(i, d);
    }
}
 
Example 5
Source File: BlockEntityChest.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void setItem(int index, Item item) {
    int i = this.getSlotIndex(index);

    CompoundTag d = NBTIO.putItemHelper(item, index);

    // If item is air or count less than 0, remove the item from the "Items" list
    if (item.getId() == Item.AIR || item.getCount() <= 0) {
        if (i >= 0) {
            this.namedTag.getList("Items").remove(i);
        }
    } else if (i < 0) {
        // If it is less than i, then it is a new item, so we are going to add it at the end of the list
        (this.namedTag.getList("Items", CompoundTag.class)).add(d);
    } else {
        // If it is more than i, then it is an update on a inventorySlot, so we are going to overwrite the item in the list
        (this.namedTag.getList("Items", CompoundTag.class)).add(i, d);
    }
}
 
Example 6
Source File: CraftingManager.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
public void registerShapedRecipe(ShapedRecipe recipe) {
    Item result = recipe.getResult();
    this.recipes.put(recipe.getId(), recipe);
    Map<Integer, Map<Integer, Item>> ingredients = recipe.getIngredientMap();
    String hash = "";
    for (Map<Integer, Item> v : ingredients.values()) {
        for (Item item : v.values()) {
            if (item != null && item.getId() != Item.AIR) {
                hash += item.getId() + ":" + (!item.hasMeta() ? "?" : item.getDamage()) + "x" + item.getCount() + ",";
            }
        }

        hash += ";";
    }

    String index = result.getId() + ":" + (result.hasMeta() ? result.getDamage() : "");
    if (!this.recipeLookup.containsKey(index)) {
        this.recipeLookup.put(index, new HashMap<>());
    }

    this.recipeLookup.get(index).put(hash, recipe);
}
 
Example 7
Source File: PlayerInventory.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public void setArmorContents(Item[] items) {
    if (items.length < 4) {
        Item[] newItems = new Item[4];
        System.arraycopy(items, 0, newItems, 0, items.length);
        items = newItems;
    }

    for (int i = 0; i < 4; ++i) {
        if (items[i] == null) {
            items[i] = new ItemBlock(new BlockAir(), null, 0);
        }

        if (items[i].getId() == Item.AIR) {
            this.clear(this.getSize() + i);
        } else {
            this.setItem(this.getSize() + i, items[i]);
        }
    }
}
 
Example 8
Source File: MoreCommand.java    From EssentialsNK with GNU General Public License v3.0 6 votes vote down vote up
public boolean execute(CommandSender sender, String label, String[] args) {
    if (!this.testPermission(sender)) {
        return false;
    }
    if (!this.testIngame(sender)) {
        return false;
    }
    if (args.length != 0) {
        this.sendUsage(sender);
        return false;
    }
    Player player = (Player) sender;
    if (player.isCreative() || player.isSpectator()) {
        sender.sendMessage(TextFormat.RED + Language.translate("commands.more.notavalible"));
        return false;
    }
    Item item = player.getInventory().getItemInHand();
    if (item.getId() == Item.AIR) {
        sender.sendMessage(TextFormat.RED + Language.translate("commands.more.air"));
        return false;
    }
    item.setCount(item.getMaxStackSize());
    player.getInventory().setItemInHand(item);
    sender.sendMessage(Language.translate("commands.more.success"));
    return true;
}
 
Example 9
Source File: BlockWallSign.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public int onUpdate(int type) {
    int[] faces = {
            3,
            2,
            5,
            4,
    };
    if (type == Level.BLOCK_UPDATE_NORMAL) {
        if (this.getDamage() >= 2 && this.getDamage() <= 5) {
            if (this.getSide(BlockFace.fromIndex(faces[this.getDamage() - 2])).getId() == Item.AIR) {
                this.getLevel().useBreakOn(this);
            }
            return Level.BLOCK_UPDATE_NORMAL;
        }
    }
    return 0;
}
 
Example 10
Source File: BlockEntityItemFrame.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public CompoundTag getSpawnCompound() {
    if (!this.namedTag.contains("Item")) {
        this.setItem(new ItemBlock(new BlockAir()), false);
    }
    CompoundTag NBTItem = namedTag.getCompound("Item").copy();
    NBTItem.setName("Item");
    boolean item = NBTItem.getShort("id") == Item.AIR;
    return new CompoundTag()
            .putString("id", BlockEntity.ITEM_FRAME)
            .putInt("x", (int) this.x)
            .putInt("y", (int) this.y)
            .putInt("z", (int) this.z)
            .putCompound("Item", item ? NBTIO.putItemHelper(new ItemBlock(new BlockAir())) : NBTItem)
            .putByte("ItemRotation", item ? 0 : this.getItemRotation());
    // TODO: This crashes the client, why?
    // .putFloat("ItemDropChance", this.getItemDropChance());
}
 
Example 11
Source File: BaseInventory.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int firstEmpty(Item item) {
    for (int i = 0; i < this.size; ++i) {
        if (this.getItem(i).getId() == Item.AIR) {
            return i;
        }
    }

    return -1;
}
 
Example 12
Source File: BaseInventory.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int firstEmpty(Item item) {
    for (int i = 0; i < this.size; ++i) {
        if (this.getItem(i).getId() == Item.AIR) {
            return i;
        }
    }

    return -1;
}
 
Example 13
Source File: EntityMinecartChest.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void saveNBT() {
    super.saveNBT();

    this.namedTag.putList(new ListTag<CompoundTag>("Items"));
    if (this.inventory != null) {
        for (int slot = 0; slot < 27; ++slot) {
            Item item = this.inventory.getItem(slot);
            if (item != null && item.getId() != Item.AIR) {
                this.namedTag.getList("Items", CompoundTag.class)
                        .add(NBTIO.putItemHelper(item, slot));
            }
        }
    }
}
 
Example 14
Source File: BaseInventory.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int firstEmpty(Item item) {
    for (int i = 0; i < this.size; ++i) {
        if (this.getItem(i).getId() == Item.AIR) {
            return i;
        }
    }

    return -1;
}
 
Example 15
Source File: BlockCarpet.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int onUpdate(int type) {
    if (type == Level.BLOCK_UPDATE_NORMAL) {
        if (this.down().getId() == Item.AIR) {
            this.getLevel().useBreakOn(this);

            return Level.BLOCK_UPDATE_NORMAL;
        }
    }

    return 0;
}
 
Example 16
Source File: SimpleInventoryTransaction.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
protected boolean matchItems(List<Item> needItems, List<Item> haveItems) {
    for (InventoryAction action : this.actions) {
        if (action.getTargetItem().getId() != Item.AIR) {
            needItems.add(action.getTargetItem());
        }

        if (!action.isValid(this.source)) {
            return false;
        }

        if (action.getSourceItem().getId() != Item.AIR) {
            haveItems.add(action.getSourceItem());
        }
    }

    for (Item needItem : new ArrayList<>(needItems)) {
        for (Item haveItem : new ArrayList<>(haveItems)) {
            if (needItem.equals(haveItem)) {
                int amount = Math.min(haveItem.getCount(), needItem.getCount());
                needItem.setCount(needItem.getCount() - amount);
                haveItem.setCount(haveItem.getCount() - amount);
                if (haveItem.getCount() == 0) {
                    haveItems.remove(haveItem);
                }
                if (needItem.getCount() == 0) {
                    needItems.remove(needItem);
                    break;
                }
            }
        }
    }

    return haveItems.isEmpty() && needItems.isEmpty();
}
 
Example 17
Source File: InventoryTransaction.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
protected boolean matchItems(List<Item> needItems, List<Item> haveItems) {
    for (InventoryAction action : this.actions) {
        if (action.getTargetItem().getId() != Item.AIR) {
            needItems.add(action.getTargetItem());
        }

        if (!action.isValid(this.source)) {
            return false;
        }

        if (action.getSourceItem().getId() != Item.AIR) {
            haveItems.add(action.getSourceItem());
        }
    }

    for (Item needItem : new ArrayList<>(needItems)) {
        for (Item haveItem : new ArrayList<>(haveItems)) {
            if (needItem.equals(haveItem)) {
                int amount = Math.min(haveItem.getCount(), needItem.getCount());
                needItem.setCount(needItem.getCount() - amount);
                haveItem.setCount(haveItem.getCount() - amount);
                if (haveItem.getCount() == 0) {
                    haveItems.remove(haveItem);
                }
                if (needItem.getCount() == 0) {
                    needItems.remove(needItem);
                    break;
                }
            }
        }
    }

    return haveItems.isEmpty() && needItems.isEmpty();
}
 
Example 18
Source File: BlockCarpet.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
    Block down = this.down();
    if (down.getId() != Item.AIR) {
        this.getLevel().setBlock(block, this, true, true);
        return true;
    }
    return false;
}
 
Example 19
Source File: BlockCarpet.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
    Block down = this.down();
    if (down.getId() != Item.AIR) {
        this.getLevel().setBlock(block, this, true, true);
        return true;
    }
    return false;
}
 
Example 20
Source File: TreeGenerator.java    From Nukkit with GNU General Public License v3.0 2 votes vote down vote up
/**
 * returns whether or not a tree can grow into a block
 * For example, a tree will not grow into stone
 */
protected boolean canGrowInto(int id) {
    return id == Item.AIR || id == Item.LEAVES || id == Item.GRASS || id == Item.DIRT || id == Item.LOG || id == Item.LOG2 || id == Item.SAPLING || id == Item.VINE;
}