@Override public void readFromNBT(NBTTagCompound nbtTags) { super.readFromNBT(nbtTags); isActive = nbtTags.getBoolean("isActive"); controlType = RedstoneControl.values()[nbtTags.getInteger("controlType")]; operatingTicks = nbtTags.getInteger("operatingTicks"); injectTank.read(nbtTags.getCompoundTag("injectTank")); outputTank.read(nbtTags.getCompoundTag("gasTank")); }
@Override public void writeToNBT(NBTTagCompound nbtTags) { super.writeToNBT(nbtTags); nbtTags.setBoolean("isActive", isActive); nbtTags.setInteger("controlType", controlType.ordinal()); nbtTags.setInteger("operatingTicks", operatingTicks); nbtTags.setTag("injectTank", injectTank.write(new NBTTagCompound())); nbtTags.setTag("gasTank", outputTank.write(new NBTTagCompound())); }
@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 void handlePacketData(ByteBuf data) { if (FMLCommonHandler.instance().getEffectiveSide().isClient()) { int gasID = data.readInt(); if (gasID < 0) { collectedGas.setGas(null); } else { collectedGas.setGas(new GasStack(gasID, data.readInt())); } } }
@Override public ArrayList<Object> getNetworkedData(ArrayList<Object> data) { if (collectedGas.getGasType() != null) { data.add(collectedGas.getGasType().getID()); data.add(collectedGas.getStored()); } else { data.add(-1); data.add(0); } return data; }
public boolean use( ItemStack[] inventory, int index, FluidTank fluidTank, GasTank gasTank, boolean deplete) { if (meets(new PressurizedInput(inventory[index], fluidTank.getFluid(), gasTank.getGas()))) { if (deplete) { inventory[index] = StackUtils.subtract(inventory[index], theSolid); fluidTank.drain(theFluid.amount, true); gasTank.draw(theGas.amount, true); } return true; } return false; }
@Override public int receiveGas(ForgeDirection side, GasStack stack) { if (canReceiveGas(side, stack.getGas())) { return injectTank.receive(stack, true); } return 0; }
public boolean canOperate() { if (inventory[1] == null) { return false; } GasStack stack = RecipeHandler.getItemToGasOutput( inventory[1], false, Recipe.CHEMICAL_DISSOLUTION_CHAMBER.get()); if (stack == null || (outputTank.getGas() != null && (outputTank.getGas().getGas() != stack.getGas() || outputTank.getNeeded() < stack.amount))) { return false; } return true; }
@Override public void readFromNBT(NBTTagCompound tag) { super.readFromNBT(tag); boolean formed = tag.getBoolean("formed"); if (formed) { setReactor(new FusionReactor(this)); getReactor().setPlasmaTemp(tag.getDouble("plasmaTemp")); getReactor().setCaseTemp(tag.getDouble("caseTemp")); getReactor().setInjectionRate(tag.getInteger("injectionRate")); getReactor().setBurning(tag.getBoolean("burning")); getReactor().updateTemperatures(); } fuelTank.read(tag.getCompoundTag("fuelTank")); deuteriumTank.read(tag.getCompoundTag("deuteriumTank")); tritiumTank.read(tag.getCompoundTag("tritiumTank")); waterTank.readFromNBT(tag.getCompoundTag("waterTank")); steamTank.readFromNBT(tag.getCompoundTag("steamTank")); }
@Override public ArrayList getNetworkedData(ArrayList data) { super.getNetworkedData(data); data.add(isActive); data.add(controlType.ordinal()); data.add(operatingTicks); if (injectTank.getGas() != null) { data.add(true); data.add(injectTank.getGas().getGas().getID()); data.add(injectTank.getStored()); } else { data.add(false); } if (outputTank.getGas() != null) { data.add(true); data.add(outputTank.getGas().getGas().getID()); data.add(outputTank.getStored()); } else { data.add(false); } return data; }
@Override public ArrayList getNetworkedData(ArrayList data) { super.getNetworkedData(data); data.add(getReactor() != null && getReactor().isFormed()); if (getReactor() != null) { data.add(getReactor().getPlasmaTemp()); data.add(getReactor().getCaseTemp()); data.add(getReactor().getInjectionRate()); data.add(getReactor().isBurning()); data.add(fuelTank.getStored()); data.add(deuteriumTank.getStored()); data.add(tritiumTank.getStored()); data.add(waterTank.getCapacity()); data.add(waterTank.getFluidAmount()); data.add(steamTank.getCapacity()); data.add(steamTank.getFluidAmount()); } return data; }
@Override public void handlePacketData(ByteBuf dataStream) { super.handlePacketData(dataStream); isActive = dataStream.readBoolean(); controlType = RedstoneControl.values()[dataStream.readInt()]; operatingTicks = dataStream.readInt(); if (dataStream.readBoolean()) { injectTank.setGas( new GasStack(GasRegistry.getGas(dataStream.readInt()), dataStream.readInt())); } else { injectTank.setGas(null); } if (dataStream.readBoolean()) { outputTank.setGas( new GasStack(GasRegistry.getGas(dataStream.readInt()), dataStream.readInt())); } else { outputTank.setGas(null); } MekanismUtils.updateBlock(worldObj, xCoord, yCoord, zCoord); }
@Override public void writeToNBT(NBTTagCompound tag) { super.writeToNBT(tag); tag.setBoolean("formed", isFormed()); if (isFormed()) { tag.setDouble("plasmaTemp", getReactor().getPlasmaTemp()); tag.setDouble("caseTemp", getReactor().getCaseTemp()); tag.setInteger("injectionRate", getReactor().getInjectionRate()); tag.setBoolean("burning", getReactor().isBurning()); } else { tag.setDouble("plasmaTemp", 0); tag.setDouble("caseTemp", 0); tag.setInteger("injectionRate", 0); tag.setBoolean("burning", false); } tag.setTag("fuelTank", fuelTank.write(new NBTTagCompound())); tag.setTag("deuteriumTank", deuteriumTank.write(new NBTTagCompound())); tag.setTag("tritiumTank", tritiumTank.write(new NBTTagCompound())); tag.setTag("waterTank", waterTank.writeToNBT(new NBTTagCompound())); tag.setTag("steamTank", steamTank.writeToNBT(new NBTTagCompound())); }
@Override public void onUpdate() { if (worldObj.isRemote) { Mekanism.proxy.registerSound(this); if (updateDelay > 0) { updateDelay--; if (updateDelay == 0 && clientActive != isActive) { isActive = clientActive; MekanismUtils.updateBlock(worldObj, xCoord, yCoord, zCoord); } } } if (!worldObj.isRemote) { if (updateDelay > 0) { updateDelay--; if (updateDelay == 0 && clientActive != isActive) { Mekanism.packetHandler.sendToAll( new TileEntityMessage(Coord4D.get(this), getNetworkedData(new ArrayList()))); } } ChargeUtils.discharge(3, this); if (inventory[0] != null && (injectTank.getGas() == null || injectTank.getStored() < injectTank.getMaxGas())) { injectTank.receive( GasTransmission.removeGas( inventory[0], GasRegistry.getGas("sulfuricAcid"), injectTank.getNeeded()), true); } if (inventory[2] != null && outputTank.getGas() != null) { outputTank.draw(GasTransmission.addGas(inventory[2], outputTank.getGas()), true); } boolean changed = false; if (canOperate() && getEnergy() >= MekanismUtils.getEnergyPerTick(this, ENERGY_USAGE) && injectTank.getStored() >= INJECT_USAGE && MekanismUtils.canFunction(this)) { setActive(true); setEnergy(getEnergy() - MekanismUtils.getEnergyPerTick(this, ENERGY_USAGE)); if (operatingTicks < MekanismUtils.getTicks(this, TICKS_REQUIRED)) { operatingTicks++; injectTank.draw(INJECT_USAGE, true); } else { GasStack stack = RecipeHandler.getItemToGasOutput( inventory[1], true, Recipe.CHEMICAL_DISSOLUTION_CHAMBER.get()); outputTank.receive(stack, true); injectTank.draw(INJECT_USAGE, true); operatingTicks = 0; if (inventory[1].stackSize <= 0) { inventory[1] = null; } markDirty(); } } else { if (prevEnergy >= getEnergy()) { changed = true; setActive(false); } } if (changed && !canOperate()) { operatingTicks = 0; } prevEnergy = getEnergy(); if (outputTank.getGas() != null) { GasStack toSend = new GasStack(outputTank.getGas().getGas(), Math.min(outputTank.getStored(), gasOutput)); TileEntity tileEntity = Coord4D.get(this).getFromSide(MekanismUtils.getRight(facing)).getTileEntity(worldObj); if (tileEntity instanceof IGasHandler) { if (((IGasHandler) tileEntity) .canReceiveGas( MekanismUtils.getRight(facing).getOpposite(), outputTank.getGas().getGas())) { outputTank.draw( ((IGasHandler) tileEntity) .receiveGas(MekanismUtils.getRight(facing).getOpposite(), toSend), true); } } } } }
@Override public GasStack drawGas(EnumFacing side, int amount, boolean doTransfer) { return collectedGas.draw(amount, doTransfer); }
public int getScaledInjectGasLevel(int i) { return injectTank.getGas() != null ? injectTank.getStored() * i / MAX_GAS : 0; }
public int getScaledOutputGasLevel(int i) { return outputTank.getGas() != null ? outputTank.getStored() * i / MAX_GAS : 0; }
@Override public boolean canDrawGas(EnumFacing side, Gas type) { return type == collectedGas.getGasType(); }