Java Code Examples for cn.nukkit.nbt.NBTIO#putItemHelper()

The following examples show how to use cn.nukkit.nbt.NBTIO#putItemHelper() . 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: 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 2
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 3
Source File: BlockEntityBrewingStand.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 4
Source File: BlockEntityFurnace.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 5
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 6
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 7
Source File: BlockEntityBrewingStand.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 8
Source File: BlockEntityFurnace.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 9
Source File: BlockEntityDropper.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 10
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 11
Source File: BlockEntityChest.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 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 slot, so we are going to overwrite the item in the list
        (this.namedTag.getList("Items", CompoundTag.class)).add(i, d);
    }
}
 
Example 12
Source File: BlockEntityDispenser.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 13
Source File: BlockEntityBrewingStand.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 14
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 15
Source File: BlockEntityShulkerBox.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 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 slot, so we are going to overwrite the item in the list
        (this.namedTag.getList("Items", CompoundTag.class)).add(i, d);
    }
}
 
Example 16
Source File: BlockEntityHopper.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 17
Source File: Level.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public void dropItem(Vector3 source, Item item, Vector3 motion, boolean dropAround, int delay) {
    if (motion == null) {
        if (dropAround) {
            float f = ThreadLocalRandom.current().nextFloat() * 0.5f;
            float f1 = ThreadLocalRandom.current().nextFloat() * ((float) Math.PI * 2);

            motion = new Vector3(-MathHelper.sin(f1) * f, 0.20000000298023224, MathHelper.cos(f1) * f);
        } else {
            motion = new Vector3(new java.util.Random().nextDouble() * 0.2 - 0.1, 0.2,
                    new java.util.Random().nextDouble() * 0.2 - 0.1);
        }
    }

    CompoundTag itemTag = NBTIO.putItemHelper(item);
    itemTag.setName("Item");

    if (item.getId() > 0 && item.getCount() > 0) {
        EntityItem itemEntity = (EntityItem) Entity.createEntity("Item",
                this.getChunk((int) source.getX() >> 4, (int) source.getZ() >> 4, true),
                new CompoundTag().putList(new ListTag<DoubleTag>("Pos").add(new DoubleTag("", source.getX()))
                        .add(new DoubleTag("", source.getY())).add(new DoubleTag("", source.getZ())))

                        .putList(new ListTag<DoubleTag>("Motion").add(new DoubleTag("", motion.x))
                                .add(new DoubleTag("", motion.y)).add(new DoubleTag("", motion.z)))

                        .putList(new ListTag<FloatTag>("Rotation")
                                .add(new FloatTag("", new Random().nextFloat() * 360))
                                .add(new FloatTag("", 0)))

                        .putShort("Health", 5).putCompound("Item", itemTag).putShort("PickupDelay", delay));

        if (itemEntity != null) {
            itemEntity.spawnToAll();
        }
    }
}
 
Example 18
Source File: Level.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public void dropItem(Vector3 source, Item item, Vector3 motion, boolean dropAround, int delay) {
    if (motion == null) {
        if (dropAround) {
            float f = ThreadLocalRandom.current().nextFloat() * 0.5f;
            float f1 = ThreadLocalRandom.current().nextFloat() * ((float) Math.PI * 2);

            motion = new Vector3(-MathHelper.sin(f1) * f, 0.20000000298023224, MathHelper.cos(f1) * f);
        } else {
            motion = new Vector3(new java.util.Random().nextDouble() * 0.2 - 0.1, 0.2,
                    new java.util.Random().nextDouble() * 0.2 - 0.1);
        }
    }

    CompoundTag itemTag = NBTIO.putItemHelper(item);
    itemTag.setName("Item");

    if (item.getId() > 0 && item.getCount() > 0) {
        EntityItem itemEntity = new EntityItem(
                this.getChunk((int) source.getX() >> 4, (int) source.getZ() >> 4, true),
                new CompoundTag().putList(new ListTag<DoubleTag>("Pos").add(new DoubleTag("", source.getX()))
                        .add(new DoubleTag("", source.getY())).add(new DoubleTag("", source.getZ())))

                        .putList(new ListTag<DoubleTag>("Motion").add(new DoubleTag("", motion.x))
                                .add(new DoubleTag("", motion.y)).add(new DoubleTag("", motion.z)))

                        .putList(new ListTag<FloatTag>("Rotation")
                                .add(new FloatTag("", new java.util.Random().nextFloat() * 360))
                                .add(new FloatTag("", 0)))

                        .putShort("Health", 5).putCompound("Item", itemTag).putShort("PickupDelay", delay));

        itemEntity.spawnToAll();
    }
}