use of cn.nukkit.item.Item in project Nukkit by Nukkit.
the class BlockOreCoal method getDrops.
@Override
public Item[] getDrops(Item item) {
if (item.isPickaxe() && item.getTier() >= ItemTool.TIER_WOODEN) {
int count = 1;
Enchantment fortune = item.getEnchantment(Enchantment.ID_FORTUNE_DIGGING);
if (fortune != null && fortune.getLevel() >= 1) {
int i = ThreadLocalRandom.current().nextInt(fortune.getLevel() + 2) - 1;
if (i < 0) {
i = 0;
}
count = i + 1;
}
return new Item[] { new ItemCoal(0, count) };
} else {
return new Item[0];
}
}
use of cn.nukkit.item.Item in project Nukkit by Nukkit.
the class BlockGlowstone method getDrops.
@Override
public Item[] getDrops(Item item) {
Random random = new Random();
int count = 2 + random.nextInt(3);
Enchantment fortune = item.getEnchantment(Enchantment.ID_FORTUNE_DIGGING);
if (fortune != null && fortune.getLevel() >= 1) {
count += random.nextInt(fortune.getLevel() + 1);
}
return new Item[] { new ItemGlowstoneDust(0, MathHelper.clamp(count, 1, 4)) };
}
use of cn.nukkit.item.Item in project Nukkit by Nukkit.
the class BlockEntityBrewingStand method updateBlock.
public void updateBlock() {
Block block = this.getLevelBlock();
if (!(block instanceof BlockBrewingStand)) {
return;
}
int meta = 0;
for (int i = 1; i <= 3; ++i) {
Item potion = this.inventory.getItem(i);
if (potion.getId() == Item.POTION && potion.getCount() > 0) {
meta |= 1 << i;
}
}
block.setDamage(meta);
this.level.setBlock(block, block, false, false);
}
use of cn.nukkit.item.Item in project Nukkit by Nukkit.
the class BlockEntityFurnace method onUpdate.
@Override
public boolean onUpdate() {
if (this.closed) {
return false;
}
this.timing.startTiming();
boolean ret = false;
Item fuel = this.inventory.getFuel();
Item raw = this.inventory.getSmelting();
Item product = this.inventory.getResult();
FurnaceRecipe smelt = this.server.getCraftingManager().matchFurnaceRecipe(raw);
boolean canSmelt = (smelt != null && raw.getCount() > 0 && ((smelt.getResult().equals(product, true) && product.getCount() < product.getMaxStackSize()) || product.getId() == Item.AIR));
if (burnTime <= 0 && canSmelt && fuel.getFuelTime() != null && fuel.getCount() > 0) {
this.checkFuel(fuel);
}
if (burnTime > 0) {
burnTime--;
burnDuration = (int) Math.ceil(burnTime / maxTime * 200);
if (smelt != null && canSmelt) {
cookTime++;
if (cookTime >= 200) {
product = Item.get(smelt.getResult().getId(), smelt.getResult().getDamage(), product.getCount() + 1);
FurnaceSmeltEvent ev = new FurnaceSmeltEvent(this, raw, product);
this.server.getPluginManager().callEvent(ev);
if (!ev.isCancelled()) {
this.inventory.setResult(ev.getResult());
raw.setCount(raw.getCount() - 1);
if (raw.getCount() == 0) {
raw = new ItemBlock(new BlockAir(), 0, 0);
}
this.inventory.setSmelting(raw);
}
cookTime -= 200;
}
} else if (burnTime <= 0) {
burnTime = 0;
cookTime = 0;
burnDuration = 0;
} else {
cookTime = 0;
}
ret = true;
} else {
if (this.getBlock().getId() == Item.BURNING_FURNACE) {
this.getLevel().setBlock(this, new BlockFurnace(this.getBlock().getDamage()), true);
}
burnTime = 0;
cookTime = 0;
burnDuration = 0;
}
for (Player player : this.getInventory().getViewers()) {
int windowId = player.getWindowId(this.getInventory());
if (windowId > 0) {
ContainerSetDataPacket pk = new ContainerSetDataPacket();
pk.windowId = windowId;
pk.property = ContainerSetDataPacket.PROPERTY_FURNACE_TICK_COUNT;
;
pk.value = cookTime;
player.dataPacket(pk);
pk = new ContainerSetDataPacket();
pk.windowId = windowId;
pk.property = ContainerSetDataPacket.PROPERTY_FURNACE_LIT_TIME;
pk.value = burnDuration;
player.dataPacket(pk);
}
}
this.lastUpdate = System.currentTimeMillis();
this.timing.stopTiming();
return ret;
}
use of cn.nukkit.item.Item in project Nukkit by Nukkit.
the class BlockEntityHopper method pickupDroppedItems.
public boolean pickupDroppedItems() {
if (this.inventory.isFull()) {
return false;
}
boolean update = false;
for (Entity entity : this.level.getCollidingEntities(this.pickupArea)) {
if (!(entity instanceof EntityItem)) {
continue;
}
EntityItem itemEntity = (EntityItem) entity;
Item item = itemEntity.getItem();
if (item.getId() == 0 || item.getCount() < 1) {
continue;
}
int originalCount = item.getCount();
Item[] items = this.inventory.addItem(item);
if (items.length == 0) {
entity.close();
update = true;
continue;
}
if (items[0].getCount() != originalCount) {
update = true;
}
}
BlockEntity blockEntity = this.level.getBlockEntity(this.up());
if (blockEntity instanceof InventoryHolder) {
Inventory inv = ((InventoryHolder) blockEntity).getInventory();
for (int i = 0; i < inv.getSize(); i++) {
Item item = inv.getItem(i);
if (item.getId() != 0 && item.getCount() > 0) {
Item itemToAdd = item.clone();
itemToAdd.count = 1;
Item[] items = this.inventory.addItem(itemToAdd);
if (items.length >= 1) {
continue;
}
item.count--;
if (item.count <= 0) {
item = Item.get(0);
}
inv.setItem(i, item);
update = true;
break;
}
}
}
// TODO: check for minecart
return update;
}
Aggregations