@Override public void onUpdate() { super.onUpdate(); if (getRunning()) run(); else postRun(); if (Config.useFuel && !worldObj.isRemote) { if (inventory.getStackInSlot(0) != null && TileEntityFurnace.isItemFuel(inventory.getStackInSlot(0)) && (fuel.get() + TileEntityFurnace.getItemBurnTime(inventory.getStackInSlot(0))) <= Config.maxFuelLevel) if (inventory.getStackInSlot(0).getItem().equals(Items.lava_bucket)) { fuel.modify(TileEntityFurnace.getItemBurnTime(inventory.decrStackSize(0, 1))); inventory.setInventorySlotContents(0, new ItemStack(Items.bucket)); } else { fuel.modify(TileEntityFurnace.getItemBurnTime(inventory.decrStackSize(0, 1))); } if (fuel.isDirty()) sync(); } lastTickPosX = posX; lastTickPosY = posY; lastTickPosZ = posZ; posX += motionX; posY += motionY; posZ += motionZ; setPosition(posX, posY, posZ); if (getTimeSinceHit() > 0) setTimeSinceHit(getTimeSinceHit() - 1); if (getDamageTaken() > 0) setDamageTaken(getDamageTaken() - 1); }
@Override public void readEntityFromNBT(NBTTagCompound tag) { setFacing(ForgeDirection.getOrientation(tag.getByte(TAG_FACING))); setRunning(tag.getBoolean(TAG_RUNNING)); fuel.readFromNBT(tag, TAG_FUEL); inventory.readFromNBT(tag); }
@Override public void writeEntityToNBT(NBTTagCompound tag) { tag.setByte(TAG_FACING, (byte) getFacing().ordinal()); tag.setBoolean(TAG_RUNNING, getRunning()); fuel.writeToNBT(tag, TAG_FUEL); inventory.writeToNBT(tag); }
private void run() { if (Config.useFuel) { if (fuel.get() < Config.fuelPerTick) { setRunning(false); setMotion(0, 0, 0); return; } fuel.modify(-Config.fuelPerTick); } setSineWave(getSineWave() + 1); if (!worldObj.isRemote) { setIsCentered( (String.format("%.1f", posX % 1).equals("0.5") || String.format("%.1f", posX % 1).equals("-0.5")) && (String.format("%.1f", posY % 1).equals("0.0") || String.format("%.1f", posY % 1).equals("1.0")) && (String.format("%.1f", posZ % 1).equals("0.5") || String.format("%.1f", posZ % 1).equals("-0.5"))); } if (getIsCentered()) { if (worldObj.isRemote) { worldObj.playAuxSFX(1001, (int) posX, (int) posY, (int) posZ, 0); } else { BlockCoord front = new BlockCoord( MathHelper.floor_double(posX) + getFacing().offsetX, Math.round(posY) + getFacing().offsetY, MathHelper.floor_double(posZ) + getFacing().offsetZ); BlockCoord back = new BlockCoord( MathHelper.floor_double(posX) - getFacing().offsetX, Math.round(posY) - getFacing().offsetY, MathHelper.floor_double(posZ) - getFacing().offsetZ); if (Config.useFuel) { if (fuel.get() >= Config.fuelPerBlockMined) { if (breakBlock(front)) fuel.modify(-Config.fuelPerBlockMined); } if (fuel.get() >= Config.fuelPerBlockExtruded) { if (placeBlock(back)) fuel.modify(-Config.fuelPerBlockExtruded); } } else { breakBlock(front); placeBlock(back); } if (worldObj .getBlock(front.x, front.y, front.z) .isBlockSolid( worldObj, front.x, front.y, front.z, worldObj.getBlockMetadata(front.x, front.y, front.z))) { setRunning(false); setMotion(0, 0, 0); } } } }