cn.nukkit.entity.item.EntityItem Java Examples

The following examples show how to use cn.nukkit.entity.item.EntityItem. 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: 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 #2
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();
    }
}
 
Example #3
Source File: EntitySpawnEvent.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public boolean isItem() {
    return this.entity instanceof EntityItem;
}
 
Example #4
Source File: InventoryPickupItemEvent.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public EntityItem getItem() {
    return item;
}
 
Example #5
Source File: InventoryPickupItemEvent.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public InventoryPickupItemEvent(Inventory inventory, EntityItem item) {
    super(inventory);
    this.item = item;
}
 
Example #6
Source File: EntitySpawnEvent.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public boolean isItem() {
    return this.entity instanceof EntityItem;
}
 
Example #7
Source File: ItemSpawnEvent.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public EntityItem getEntity() {
    return (EntityItem) this.entity;
}
 
Example #8
Source File: ItemSpawnEvent.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public ItemSpawnEvent(EntityItem item) {
    this.entity = item;
}
 
Example #9
Source File: ItemDespawnEvent.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public EntityItem getEntity() {
    return (EntityItem) this.entity;
}
 
Example #10
Source File: ItemDespawnEvent.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public ItemDespawnEvent(EntityItem item) {
    this.entity = item;
}
 
Example #11
Source File: EntityDespawnEvent.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public boolean isItem() {
    return this.entity instanceof EntityItem;
}
 
Example #12
Source File: NukkitEntityType.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean isItem() {
    return entity instanceof EntityItem;
}
 
Example #13
Source File: BlockEntityHopper.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public boolean pickupItems() {
    if (this.inventory.isFull()) {
        return false;
    }

    boolean pickedUpItem = false;

    for (Entity entity : this.level.getCollidingEntities(this.pickupArea)) {
        if (entity.isClosed() || !(entity instanceof EntityItem)) {
            continue;
        }

        EntityItem itemEntity = (EntityItem) entity;
        Item item = itemEntity.getItem();

        if (item.isNull()) {
            continue;
        }

        int originalCount = item.getCount();

        if (!this.inventory.canAddItem(item)) {
            continue;
        }

        InventoryMoveItemEvent ev = new InventoryMoveItemEvent(null, this.inventory, this, item, InventoryMoveItemEvent.Action.PICKUP);
        this.server.getPluginManager().callEvent(ev);

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

        Item[] items = this.inventory.addItem(item);

        if (items.length == 0) {
            entity.close();
            pickedUpItem = true;
            continue;
        }

        if (items[0].getCount() != originalCount) {
            pickedUpItem = true;
            item.setCount(items[0].getCount());
        }
    }

    //TODO: check for minecart
    return pickedUpItem;
}
 
Example #14
Source File: InventoryPickupItemEvent.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public EntityItem getItem() {
    return item;
}
 
Example #15
Source File: InventoryPickupItemEvent.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public InventoryPickupItemEvent(Inventory inventory, EntityItem item) {
    super(inventory);
    this.item = item;
}
 
Example #16
Source File: EntityDespawnEvent.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
public boolean isItem() {
    return this.entity instanceof EntityItem;
}
 
Example #17
Source File: ItemSpawnEvent.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public EntityItem getEntity() {
    return (EntityItem) this.entity;
}
 
Example #18
Source File: ItemSpawnEvent.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public ItemSpawnEvent(EntityItem item) {
    this.entity = item;
}
 
Example #19
Source File: ItemDespawnEvent.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public EntityItem getEntity() {
    return (EntityItem) this.entity;
}
 
Example #20
Source File: ItemDespawnEvent.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public ItemDespawnEvent(EntityItem item) {
    this.entity = item;
}
 
Example #21
Source File: EntityDespawnEvent.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public boolean isItem() {
    return this.entity instanceof EntityItem;
}
 
Example #22
Source File: InventoryPickupItemEvent.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
public EntityItem getItem() {
    return item;
}
 
Example #23
Source File: InventoryPickupItemEvent.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
public InventoryPickupItemEvent(Inventory inventory, EntityItem item) {
    super(inventory);
    this.item = item;
}
 
Example #24
Source File: EntitySpawnEvent.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
public boolean isItem() {
    return this.entity instanceof EntityItem;
}
 
Example #25
Source File: ItemSpawnEvent.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
@Override
public EntityItem getEntity() {
    return (EntityItem) this.entity;
}
 
Example #26
Source File: ItemSpawnEvent.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
public ItemSpawnEvent(EntityItem item) {
    this.entity = item;
}
 
Example #27
Source File: ItemDespawnEvent.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
@Override
public EntityItem getEntity() {
    return (EntityItem) this.entity;
}
 
Example #28
Source File: ItemDespawnEvent.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
public ItemDespawnEvent(EntityItem item) {
    this.entity = item;
}