cn.nukkit.block.BlockAir Java Examples

The following examples show how to use cn.nukkit.block.BlockAir. 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: 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 #2
Source File: PlayerInventory.java    From Jupiter 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 #3
Source File: BlockEntityItemFrame.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void initBlockEntity() {
    if (!namedTag.contains("Item")) {
        namedTag.putCompound("Item", NBTIO.putItemHelper(new ItemBlock(new BlockAir())));
    }
    if (!namedTag.contains("ItemRotation")) {
        namedTag.putByte("ItemRotation", 0);
    }
    if (!namedTag.contains("ItemDropChance")) {
        namedTag.putFloat("ItemDropChance", 1.0f);
    }

    this.level.updateComparatorOutputLevel(this);

    super.initBlockEntity();
}
 
Example #4
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 #5
Source File: BlockEntityItemFrame.java    From Jupiter 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 #6
Source File: BreakCommand.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;
    Block block = player.getTargetBlock(120, new Integer[]{Block.AIR});
    if (block == null) {
        sender.sendMessage(TextFormat.RED + Language.translate("commands.break.unreachable"));
        return false;
    }
    if (block.getId() == Block.BEDROCK && !sender.hasPermission("essentialsnk.break.bedrock")) {
        sender.sendMessage(TextFormat.RED + Language.translate("commands.break.bedrock"));
        return false;
    }
    player.getLevel().setBlock(block, new BlockAir(), true, true);
    return true;
}
 
Example #7
Source File: BlockEntityChest.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Item getItem(int index) {
    int i = this.getSlotIndex(index);
    if (i < 0) {
        return new ItemBlock(new BlockAir(), 0, 0);
    } else {
        CompoundTag data = (CompoundTag) this.namedTag.getList("Items").get(i);
        return NBTIO.getItemHelper(data);
    }
}
 
Example #8
Source File: BlockEntityChest.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Item getItem(int index) {
    int i = this.getSlotIndex(index);
    if (i < 0) {
        return new ItemBlock(new BlockAir(), 0, 0);
    } else {
        CompoundTag data = (CompoundTag) this.namedTag.getList("Items").get(i);
        return NBTIO.getItemHelper(data);
    }
}
 
Example #9
Source File: BlockEntityBrewingStand.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Item getItem(int index) {
    int i = this.getSlotIndex(index);
    if (i < 0) {
        return new ItemBlock(new BlockAir(), 0, 0);
    } else {
        CompoundTag data = (CompoundTag) this.namedTag.getList("Items").get(i);
        return NBTIO.getItemHelper(data);
    }
}
 
Example #10
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 #11
Source File: BlockEntityFurnace.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Item getItem(int index) {
    int i = this.getSlotIndex(index);
    if (i < 0) {
        return new ItemBlock(new BlockAir(), 0, 0);
    } else {
        CompoundTag data = (CompoundTag) this.namedTag.getList("Items").get(i);
        return NBTIO.getItemHelper(data);
    }
}
 
Example #12
Source File: BlockEntityHopper.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Item getItem(int index) {
    int i = this.getSlotIndex(index);
    if (i < 0) {
        return new ItemBlock(new BlockAir(), 0, 0);
    } else {
        CompoundTag data = (CompoundTag) this.namedTag.getList("Items").get(i);
        return NBTIO.getItemHelper(data);
    }
}
 
Example #13
Source File: BaseInventory.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean clear(int index, boolean send) {
    if (this.slots.containsKey(index)) {
        Item item = new ItemBlock(new BlockAir(), null, 0);
        Item old = this.slots.get(index);
        InventoryHolder holder = this.getHolder();
        if (holder instanceof Entity) {
            EntityInventoryChangeEvent ev = new EntityInventoryChangeEvent((Entity) holder, old, item, index);
            Server.getInstance().getPluginManager().callEvent(ev);
            if (ev.isCancelled()) {
                this.sendSlot(index, this.getViewers());
                return false;
            }
            item = ev.getNewItem();
        }

        if (item.getId() != Item.AIR) {
            this.slots.put(index, item.clone());
        } else {
            this.slots.remove(index);
        }

        this.onSlotChange(index, old, send);
    }

    return true;
}
 
Example #14
Source File: PlayerInventory.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public Item getItemInHand() {
    Item item = this.getItem(this.getHeldItemIndex());
    if (item != null) {
        return item;
    } else {
        return new ItemBlock(new BlockAir(), 0, 0);
    }
}
 
Example #15
Source File: Item.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public Block getBlock() {
    if (this.block != null) {
        return this.block.clone();
    } else {
        return new BlockAir();
    }
}
 
Example #16
Source File: BlockEntityDispenser.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Item getItem(int index) {
    int i = this.getSlotIndex(index);
    if (i < 0) {
        return new ItemBlock(new BlockAir(), 0, 0);
    } else {
        CompoundTag data = (CompoundTag) this.namedTag.getList("Items").get(i);
        return NBTIO.getItemHelper(data);
    }
}
 
Example #17
Source File: BlockEntityBrewingStand.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Item getItem(int index) {
    int i = this.getSlotIndex(index);
    if (i < 0) {
        return new ItemBlock(new BlockAir(), 0, 0);
    } else {
        CompoundTag data = (CompoundTag) this.namedTag.getList("Items").get(i);
        return NBTIO.getItemHelper(data);
    }
}
 
Example #18
Source File: BlockEntityItemFrame.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public BlockEntityItemFrame(FullChunk chunk, CompoundTag nbt) {
    super(chunk, nbt);
    if (!nbt.contains("Item")) {
        nbt.putCompound("Item", NBTIO.putItemHelper(new ItemBlock(new BlockAir())));
    }
    if (!nbt.contains("ItemRotation")) {
        nbt.putByte("ItemRotation", 0);
    }
    if (!nbt.contains("ItemDropChance")) {
        nbt.putFloat("ItemDropChance", 1.0f);
    }

    this.level.updateComparatorOutputLevel(this);
}
 
Example #19
Source File: BlockEntityFurnace.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Item getItem(int index) {
    int i = this.getSlotIndex(index);
    if (i < 0) {
        return new ItemBlock(new BlockAir(), 0, 0);
    } else {
        CompoundTag data = (CompoundTag) this.namedTag.getList("Items").get(i);
        return NBTIO.getItemHelper(data);
    }
}
 
Example #20
Source File: BlockEntityShulkerBox.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Item getItem(int index) {
    int i = this.getSlotIndex(index);
    if (i < 0) {
        return new ItemBlock(new BlockAir(), 0, 0);
    } else {
        CompoundTag data = (CompoundTag) this.namedTag.getList("Items").get(i);
        return NBTIO.getItemHelper(data);
    }
}
 
Example #21
Source File: BlockEntityHopper.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Item getItem(int index) {
    int i = this.getSlotIndex(index);
    if (i < 0) {
        return new ItemBlock(new BlockAir(), 0, 0);
    } else {
        CompoundTag data = (CompoundTag) this.namedTag.getList("Items").get(i);
        return NBTIO.getItemHelper(data);
    }
}
 
Example #22
Source File: BlockEntityDropper.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Item getItem(int index) {
    int i = this.getSlotIndex(index);
    if (i < 0) {
        return new ItemBlock(new BlockAir(), 0, 0);
    } else {
        CompoundTag data = (CompoundTag) this.namedTag.getList("Items").get(i);
        return NBTIO.getItemHelper(data);
    }
}
 
Example #23
Source File: BaseInventory.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean clear(int index, boolean send) {
    if (this.slots.containsKey(index)) {
        Item item = new ItemBlock(new BlockAir(), null, 0);
        Item old = this.slots.get(index);
        InventoryHolder holder = this.getHolder();
        if (holder instanceof Entity) {
            EntityInventoryChangeEvent ev = new EntityInventoryChangeEvent((Entity) holder, this, old, item, index);
            Server.getInstance().getPluginManager().callEvent(ev);
            if (ev.isCancelled()) {
                this.sendSlot(index, this.getViewers());
                return false;
            }
            item = ev.getNewItem();
        }

        if (item.getId() != Item.AIR) {
            this.slots.put(index, item.clone());
        } else {
            this.slots.remove(index);
        }

        this.onSlotChange(index, old, send);
    }

    return true;
}
 
Example #24
Source File: PlayerInventory.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public Item getItemInHand() {
    Item item = this.getItem(this.getHeldItemIndex());
    if (item != null) {
        return item;
    } else {
        return new ItemBlock(new BlockAir(), 0, 0);
    }
}
 
Example #25
Source File: Item.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public Block getBlock() {
    if (this.block != null) {
        return this.block.clone();
    } else {
        return new BlockAir();
    }
}
 
Example #26
Source File: EntityMetadata.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
public Item getSlot(int id) {
    return (Item) this.getOrDefault(id, new SlotEntityData(id, new ItemBlock(new BlockAir()))).getData();
}
 
Example #27
Source File: EntityMetadata.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public Item getSlot(int id) {
    return (Item) this.getOrDefault(id, new SlotEntityData(id, new ItemBlock(new BlockAir()))).getData();
}
 
Example #28
Source File: ItemBow.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public boolean onReleaseUsing(Player player) {
    Item itemArrow = Item.get(Item.ARROW, 0, 1);

    if (player.isSurvival() && !player.getInventory().contains(itemArrow)) {
        player.getInventory().sendContents(player);
        return false;
    }

    double damage = 2;
    boolean flame = false;

    if (this.hasEnchantments()) {
        Enchantment bowDamage = this.getEnchantment(Enchantment.ID_BOW_POWER);

        if (bowDamage != null && bowDamage.getLevel() > 0) {
            damage += 0.25 * (bowDamage.getLevel() + 1);
        }

        Enchantment flameEnchant = this.getEnchantment(Enchantment.ID_BOW_FLAME);
        flame = flameEnchant != null && flameEnchant.getLevel() > 0;
    }

    CompoundTag nbt = new CompoundTag()
            .putList(new ListTag<DoubleTag>("Pos")
                    .add(new DoubleTag("", player.x))
                    .add(new DoubleTag("", player.y + player.getEyeHeight()))
                    .add(new DoubleTag("", player.z)))
            .putList(new ListTag<DoubleTag>("Motion")
                    .add(new DoubleTag("", -Math.sin(player.yaw / 180 * Math.PI) * Math.cos(player.pitch / 180 * Math.PI)))
                    .add(new DoubleTag("", -Math.sin(player.pitch / 180 * Math.PI)))
                    .add(new DoubleTag("", Math.cos(player.yaw / 180 * Math.PI) * Math.cos(player.pitch / 180 * Math.PI))))
            .putList(new ListTag<FloatTag>("Rotation")
                    .add(new FloatTag("", (player.yaw > 180 ? 360 : 0) - (float) player.yaw))
                    .add(new FloatTag("", (float) -player.pitch)))
            .putShort("Fire", player.isOnFire() || flame ? 45 * 60 : 0)
            .putDouble("damage", damage);

    int diff = (Server.getInstance().getTick() - player.getStartActionTick());
    double p = (double) diff / 20;

    double f = Math.min((p * p + p * 2) / 3, 1) * 2;
    EntityShootBowEvent entityShootBowEvent = new EntityShootBowEvent(player, this, new EntityArrow(player.chunk, nbt, player, f == 2), f);

    if (f < 0.1 || diff < 5) {
        entityShootBowEvent.setCancelled();
    }

    Server.getInstance().getPluginManager().callEvent(entityShootBowEvent);
    if (entityShootBowEvent.isCancelled()) {
        entityShootBowEvent.getProjectile().kill();
        player.getInventory().sendContents(player);
    } else {
        entityShootBowEvent.getProjectile().setMotion(entityShootBowEvent.getProjectile().getMotion().multiply(entityShootBowEvent.getForce()));
        if (player.isSurvival()) {
            Enchantment infinity;

            if (!this.hasEnchantments() || (infinity = this.getEnchantment(Enchantment.ID_BOW_INFINITY)) == null || infinity.getLevel() <= 0)
                player.getInventory().removeItem(itemArrow);
            if (!this.isUnbreakable()) {
                Enchantment durability = this.getEnchantment(Enchantment.ID_DURABILITY);
                if (!(durability != null && durability.getLevel() > 0 && (100 / (durability.getLevel() + 1)) <= new Random().nextInt(100))) {
                    this.setDamage(this.getDamage() + 1);
                    if (this.getDamage() >= 385) {
                        player.getInventory().setItemInHand(new ItemBlock(new BlockAir(), 0, 0));
                    } else {
                        player.getInventory().setItemInHand(this);
                    }
                }
            }
        }
        if (entityShootBowEvent.getProjectile() instanceof EntityProjectile) {
            ProjectileLaunchEvent projectev = new ProjectileLaunchEvent(entityShootBowEvent.getProjectile());
            Server.getInstance().getPluginManager().callEvent(projectev);
            if (projectev.isCancelled()) {
                entityShootBowEvent.getProjectile().kill();
            } else {
                entityShootBowEvent.getProjectile().spawnToAll();
                player.level.addSound(player, Sound.RANDOM_BOW, 1, 1, player.getViewers().values());
            }
        } else {
            entityShootBowEvent.getProjectile().spawnToAll();
        }
    }

    return true;
}
 
Example #29
Source File: BaseInventory.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Item getItem(int index) {
    return this.slots.containsKey(index) ? this.slots.get(index).clone() : new ItemBlock(new BlockAir(), null, 0);
}
 
Example #30
Source File: BaseInventory.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Item getItem(int index) {
    return this.slots.containsKey(index) ? this.slots.get(index).clone() : new ItemBlock(new BlockAir(), null, 0);
}