use of cn.nukkit.network.protocol.ContainerSetDataPacket in project Nukkit by Nukkit.
the class BlockEntityBrewingStand method sendBrewTime.
protected void sendBrewTime() {
ContainerSetDataPacket pk = new ContainerSetDataPacket();
pk.property = ContainerSetDataPacket.PROPERTY_BREWING_STAND_BREW_TIME;
pk.value = this.brewTime;
for (Player p : this.inventory.getViewers()) {
int windowId = p.getWindowId(this.inventory);
if (windowId > 0) {
pk.windowId = windowId;
p.dataPacket(pk);
}
}
}
use of cn.nukkit.network.protocol.ContainerSetDataPacket 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.network.protocol.ContainerSetDataPacket in project Nukkit by Nukkit.
the class BlockEntityBrewingStand method sendFuel.
protected void sendFuel() {
ContainerSetDataPacket pk = new ContainerSetDataPacket();
for (Player p : this.inventory.getViewers()) {
int windowId = p.getWindowId(this.inventory);
if (windowId > 0) {
pk.windowId = windowId;
pk.property = ContainerSetDataPacket.PROPERTY_BREWING_STAND_FUEL_AMOUNT;
pk.value = this.fuelAmount;
p.dataPacket(pk);
pk.property = ContainerSetDataPacket.PROPERTY_BREWING_STAND_FUEL_TOTAL;
pk.value = this.fuelTotal;
p.dataPacket(pk);
}
}
}
Aggregations