@Override public void handlePacketData(ByteBuf dataStream) { if (!worldObj.isRemote) { int type = dataStream.readInt(); switch (type) { case 0: if (getReactor() != null) getReactor().setInjectionRate(dataStream.readInt()); break; } return; } super.handlePacketData(dataStream); if (worldObj.isRemote) { boolean formed = dataStream.readBoolean(); if (formed) { if (getReactor() == null || !((FusionReactor) getReactor()).formed) { Mekanism.proxy.doGenericSparkle( this, new INodeChecker() { @Override public boolean isNode(TileEntity tile) { return tile instanceof TileEntityReactorBlock; } }); } if (getReactor() == null) { setReactor(new FusionReactor(this)); MekanismUtils.updateBlock(worldObj, xCoord, yCoord, zCoord); } ((FusionReactor) getReactor()).formed = true; getReactor().setPlasmaTemp(dataStream.readDouble()); getReactor().setCaseTemp(dataStream.readDouble()); getReactor().setInjectionRate(dataStream.readInt()); getReactor().setBurning(dataStream.readBoolean()); fuelTank.setGas(new GasStack(GasRegistry.getGas("fusionFuelDT"), dataStream.readInt())); deuteriumTank.setGas(new GasStack(GasRegistry.getGas("deuterium"), dataStream.readInt())); tritiumTank.setGas(new GasStack(GasRegistry.getGas("tritium"), dataStream.readInt())); waterTank.setCapacity(dataStream.readInt()); waterTank.setFluid(new FluidStack(FluidRegistry.getFluid("water"), dataStream.readInt())); steamTank.setCapacity(dataStream.readInt()); steamTank.setFluid(new FluidStack(FluidRegistry.getFluid("steam"), dataStream.readInt())); } else if (getReactor() != null) { setReactor(null); MekanismUtils.updateBlock(worldObj, xCoord, yCoord, zCoord); } } }
@Override public FluidTankInfo[] getTankInfo(ForgeDirection direction) { FluidTank compositeTank = new FluidTank(tank.getCapacity()); TileTank tile = getBottomTank(); int capacity = tank.getCapacity(); if (tile != null && tile.tank.getFluid() != null) { compositeTank.setFluid(tile.tank.getFluid().copy()); } else { return new FluidTankInfo[] {compositeTank.getInfo()}; } tile = getTankAbove(tile); while (tile != null) { FluidStack liquid = tile.tank.getFluid(); if (liquid == null || liquid.amount == 0) { // NOOP } else if (!compositeTank.getFluid().isFluidEqual(liquid)) { break; } else { compositeTank.getFluid().amount += liquid.amount; } capacity += tile.tank.getCapacity(); tile = getTankAbove(tile); } compositeTank.setCapacity(capacity); return new FluidTankInfo[] {compositeTank.getInfo()}; }
// called only clientside to sync with the server @SideOnly(Side.CLIENT) public void updateFluidTo(FluidStack fluid) { int oldAmount = tank.getFluidAmount(); tank.setFluid(fluid); if (fluid == null) { tank.setCapacity(0); recipe = null; } else if (recipe == null) { recipe = findRecipe(fluid.getFluid()); if (recipe != null) { tank.setCapacity(recipe.fluid.amount); } } renderOffset += tank.getFluidAmount() - oldAmount; }
protected void reset() { timer = 0; recipe = null; tank.setCapacity(0); tank.setFluid(null); if (!worldObj.isRemote && worldObj instanceof WorldServer) { TinkerNetwork.sendToClients((WorldServer) worldObj, pos, new FluidUpdatePacket(pos, null)); } }
@Override public void readFromNBT(NBTTagCompound nbtTags) { super.readFromNBT(nbtTags); tier = FluidTankTier.values()[nbtTags.getInteger("tier")]; clientActive = isActive = nbtTags.getBoolean("isActive"); editMode = ContainerEditMode.values()[nbtTags.getInteger("editMode")]; if (nbtTags.hasKey("fluidTank")) { fluidTank.setCapacity(tier.storage); fluidTank.readFromNBT(nbtTags.getCompoundTag("fluidTank")); } }
@Override public int fill(EnumFacing from, FluidStack resource, boolean doFill) { // this is where all the action happens if (!canFill(from, resource.getFluid())) { return 0; } // if empty, find a new recipe if (this.tank.getFluidAmount() == 0) { CastingRecipe recipe = findRecipe(resource.getFluid()); if (recipe == null) { // no recipe found -> can't fill return 0; } int capacity = recipe.fluid.amount; IFluidTank calcTank = new FluidTank(capacity); // no extra checks needed for the tank since it's empty and we have to set the capacity anyway if (doFill) { this.recipe = recipe; tank.setCapacity(capacity); calcTank = tank; } int filled = calcTank.fill(resource, doFill); if (filled > 0 && doFill) { renderOffset = filled; if (!worldObj.isRemote && worldObj instanceof WorldServer) { TinkerNetwork.sendToClients( (WorldServer) worldObj, pos, new FluidUpdatePacket(pos, tank.getFluid())); } } return filled; } // non-empty tank. just try to fill int filled = tank.fill(resource, doFill); if (filled > 0 && doFill) { renderOffset += filled; if (!worldObj.isRemote && worldObj instanceof WorldServer) { TinkerNetwork.sendToClients( (WorldServer) worldObj, pos, new FluidUpdatePacket(pos, tank.getFluid())); } } return filled; }
@Override public boolean upgrade(BaseTier upgradeTier) { if (upgradeTier.ordinal() != tier.ordinal() + 1) { return false; } tier = FluidTankTier.values()[upgradeTier.ordinal()]; fluidTank.setCapacity(tier.storage); Mekanism.packetHandler.sendToReceivers( new TileEntityMessage(Coord4D.get(this), getNetworkedData(new ArrayList())), new Range4D(Coord4D.get(this))); markDirty(); return true; }
@Override public void handlePacketData(ByteBuf dataStream) { super.handlePacketData(dataStream); if (FMLCommonHandler.instance().getEffectiveSide().isClient()) { FluidTankTier prevTier = tier; tier = FluidTankTier.values()[dataStream.readInt()]; fluidTank.setCapacity(tier.storage); clientActive = dataStream.readBoolean(); valve = dataStream.readInt(); editMode = ContainerEditMode.values()[dataStream.readInt()]; if (valve > 0) { valveFluid = FluidRegistry.getFluid(PacketHandler.readString(dataStream)); } else { valveFluid = null; } if (dataStream.readInt() == 1) { fluidTank.setFluid( new FluidStack( FluidRegistry.getFluid(PacketHandler.readString(dataStream)), dataStream.readInt())); } else { fluidTank.setFluid(null); } if (prevTier != tier || (updateDelay == 0 && clientActive != isActive)) { updateDelay = general.UPDATE_DELAY; isActive = clientActive; MekanismUtils.updateBlock(worldObj, getPos()); } } }
@Override public FluidTankInfo[] getTankInfo(ForgeDirection direction) { FluidTank compositeTank = new FluidTank(tank.getCapacity()); int capacity = tank.getCapacity(); if (tank.getFluid() != null) { compositeTank.setFluid(tank.getFluid().copy()); } else { return new FluidTankInfo[] {compositeTank.getInfo()}; } FluidStack liquid = tank.getFluid(); if (liquid == null || liquid.amount == 0) { } else { compositeTank.getFluid().amount += liquid.amount; } capacity += tank.getCapacity(); compositeTank.setCapacity(capacity); return new FluidTankInfo[] {compositeTank.getInfo()}; }
@Override public void updateEntity() { super.updateEntity(); oldCurX = curX; oldCurY = curY; oldCurZ = curZ; if (PneumaticCraftUtils.distBetween(getPosition(), targetX, targetY, targetZ) <= getSpeed()) { curX = targetX; curY = targetY; curZ = targetZ; } else { Vec3 vec = Vec3.createVectorHelper(targetX - curX, targetY - curY, targetZ - curZ).normalize(); curX += vec.xCoord * getSpeed(); curY += vec.yCoord * getSpeed(); curZ += vec.zCoord * getSpeed(); } if (!worldObj.isRemote) { getAIManager(); if (worldObj.getTotalWorldTime() % 40 == 0) { dispenserUpgrades = getUpgrades(ItemMachineUpgrade.UPGRADE_DISPENSER_DAMAGE); speedUpgrades = getUpgrades(ItemMachineUpgrade.UPGRADE_SPEED_DAMAGE); for (int i = getDroneSlots(); i < 36; i++) { ItemStack stack = getFakePlayer().inventory.getStackInSlot(i); if (stack != null) { worldObj.spawnEntityInWorld( new EntityItem(worldObj, xCoord + 0.5, yCoord + 1.5, zCoord + 0.5, stack)); getFakePlayer().inventory.setInventorySlotContents(i, null); } } tank.setCapacity((dispenserUpgrades + 1) * 16000); if (tank.getFluidAmount() > tank.getCapacity()) { tank.getFluid().amount = tank.getCapacity(); } } for (int i = 0; i < 4; i++) { getFakePlayer().theItemInWorldManager.updateBlockRemoving(); } if (getPressure(ForgeDirection.UNKNOWN) >= getMinWorkingPressure()) { if (!aiManager.isIdling()) addAir(-10, ForgeDirection.UNKNOWN); aiManager.onUpdateTasks(); } } else { if (drone == null || drone.isDead) { drone = new EntityProgrammableController(worldObj, this); drone.posX = curX; drone.posY = curY; drone.posZ = curZ; worldObj.spawnEntityInWorld(drone); } drone.setPosition(curX, curY, curZ); // drone.getMoveHelper().setMoveTo(curX, curY, curZ, 0); /* drone.prevPosX = oldCurX; drone.prevPosY = oldCurY; drone.prevPosZ = oldCurZ;*/ // drone.getMoveHelper().setMoveTo(curX, curY, curZ, getSpeed()); } }