PWR heat transfer

This commit is contained in:
Boblet 2023-08-18 14:18:24 +02:00
parent 24b883ec92
commit a7b741fe48
5 changed files with 163 additions and 10 deletions

View File

@ -3,12 +3,14 @@ package com.hbm.blocks.machine;
import java.util.Random;
import com.hbm.blocks.ModBlocks;
import com.hbm.inventory.fluid.FluidType;
import com.hbm.lib.RefStrings;
import com.hbm.render.block.ct.CT;
import com.hbm.render.block.ct.CTStitchReceiver;
import com.hbm.render.block.ct.IBlockCT;
import com.hbm.tileentity.machine.TileEntityPWRController;
import api.hbm.fluid.IFluidConnector;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
@ -22,6 +24,7 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
public class BlockPWR extends BlockContainer implements IBlockCT {
@ -91,7 +94,7 @@ public class BlockPWR extends BlockContainer implements IBlockCT {
super.breakBlock(world, x, y, z, block, meta);
}
public static class TileEntityBlockPWR extends TileEntity {
public static class TileEntityBlockPWR extends TileEntity implements IFluidConnector {
public Block block;
public int coreX;
@ -154,5 +157,46 @@ public class BlockPWR extends BlockContainer implements IBlockCT {
this.worldObj.markTileEntityChunkModified(this.xCoord, this.yCoord, this.zCoord, this);
}
}
@Override
public long transferFluid(FluidType type, int pressure, long fluid) {
if(this.getBlockMetadata() != 1) return fluid;
if(block == null) return fluid;
if(worldObj.getChunkProvider().chunkExists(coreX >> 4, coreZ >> 4)) {
TileEntity tile = worldObj.getTileEntity(coreX, coreY, coreZ);
if(tile instanceof TileEntityPWRController) {
TileEntityPWRController controller = (TileEntityPWRController) tile;
return controller.transferFluid(type, pressure, fluid);
}
}
return fluid;
}
@Override
public long getDemand(FluidType type, int pressure) {
if(this.getBlockMetadata() != 1) return 0;
if(block == null) return 0;
if(worldObj.getChunkProvider().chunkExists(coreX >> 4, coreZ >> 4)) {
TileEntity tile = worldObj.getTileEntity(coreX, coreY, coreZ);
if(tile instanceof TileEntityPWRController) {
TileEntityPWRController controller = (TileEntityPWRController) tile;
return controller.getDemand(type, pressure);
}
}
return 0;
}
@Override
public boolean canConnect(FluidType type, ForgeDirection dir) {
return this.getBlockMetadata() == 1;
}
}
}

View File

@ -490,8 +490,7 @@ public class Fluids {
HOTOIL.addTraits(new FT_Coolable(OIL, 1, 1, 10).setEff(CoolingType.HEATEXCHANGER, 1.0D));
HOTCRACKOIL.addTraits(new FT_Coolable(CRACKOIL, 1, 1, 10).setEff(CoolingType.HEATEXCHANGER, 1.0D));
COOLANT.addTraits(new FT_Heatable().setEff(HeatingType.HEATEXCHANGER, 1.0D).addStep(300, 1, COOLANT_HOT, 1));
COOLANT.addTraits(new FT_Heatable().setEff(HeatingType.PWR, 1.0D).addStep(300, 1, COOLANT_HOT, 1));
COOLANT.addTraits(new FT_Heatable().setEff(HeatingType.HEATEXCHANGER, 1.0D).setEff(HeatingType.PWR, 1.0D).addStep(300, 1, COOLANT_HOT, 1));
COOLANT_HOT.addTraits(new FT_Coolable(COOLANT, 1, 1, 300).setEff(CoolingType.HEATEXCHANGER, 1.0D));
MUG.addTraits(new FT_Heatable().setEff(HeatingType.HEATEXCHANGER, 1.0D).addStep(400, 1, MUG_HOT, 1));

View File

@ -41,6 +41,8 @@ public class GUIPWR extends GuiInfoContainer {
//TODO: calculate some prediction using extrapolation (or some math sector that ends with -ic)
//int timeLeft = (controller.processTime - controller.progress) / 20;
//this.drawCustomInfoStat(x, y, guiLeft + 52, guiTop + 31, 36, 18, x, y, new String[] { "Cycle: " + (timeLeft / 60) + ":" + String.format("%02d", timeLeft % 60)});
this.drawCustomInfoStat(x, y, guiLeft + 52, guiTop + 31, 36, 18, x, y, new String[] { ((int) (controller.progress * 100 / controller.processTime)) + "%" });
if(controller.typeLoaded != -1 && controller.amountLoaded > 0) {
@ -89,6 +91,9 @@ public class GUIPWR extends GuiInfoContainer {
if(System.currentTimeMillis() % 1000 < 500)
drawTexturedModalRect(guiLeft + 147, guiTop, 176, 14, 26, 26);
int p = (int) (controller.progress * 33 / controller.processTime);
drawTexturedModalRect(guiLeft + 54, guiTop + 33, 176, 0, p, 14);
GaugeUtil.renderGauge(Gauge.ROUND_SMALL, guiLeft + 115, guiTop + 31, this.zLevel, (double) controller.coreHeat / (double) controller.coreHeatCapacity);
GaugeUtil.renderGauge(Gauge.ROUND_SMALL, guiLeft + 151, guiTop + 31, this.zLevel, (double) controller.hullHeat / (double) controller.hullHeatCapacity);
@ -96,6 +101,10 @@ public class GUIPWR extends GuiInfoContainer {
ItemStack display = new ItemStack(ModItems.pwr_fuel, 1, controller.typeLoaded);
this.drawItemStack(display, guiLeft + 89, guiTop + 5, EnumChatFormatting.YELLOW + "" + controller.amountLoaded + "/" + controller.rodCount);
RenderHelper.enableGUIStandardItemLighting();
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
}
controller.tanks[0].renderTank(guiLeft + 8, guiTop + 57, this.zLevel, 16, 52);
controller.tanks[1].renderTank(guiLeft + 26, guiTop + 57, this.zLevel, 16, 52);
}
}

View File

@ -1,6 +1,7 @@
package com.hbm.inventory.recipes;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
@ -188,8 +189,9 @@ public class CentrifugeRecipes extends SerializableRecipe {
new ItemStack(ModItems.nugget_pu238, 6),
new ItemStack(ModItems.nuclear_waste, 2) });
if(OreDictionary.doesOreNameExist("nuggetNaquadria")) {
ItemStack nuggetNQR = OreDictionary.getOres("nuggetNaquadria").get(0);
ArrayList<ItemStack> naquadriaNuggets = OreDictionary.getOres("nuggetNaquadria");
if(naquadriaNuggets.size() != 0) {
ItemStack nuggetNQR = naquadriaNuggets.get(0);
ItemStack copy = nuggetNQR.copy();
copy.stackSize = 12;
recipes.put(new ComparableStack(DictFrame.fromOne(ModItems.watz_pellet_depleted, EnumWatzType.NQD)), new ItemStack[] {

View File

@ -1,6 +1,8 @@
package com.hbm.tileentity.machine;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
import com.hbm.blocks.ModBlocks;
@ -9,6 +11,7 @@ import com.hbm.inventory.container.ContainerPWR;
import com.hbm.inventory.fluid.Fluids;
import com.hbm.inventory.fluid.tank.FluidTank;
import com.hbm.inventory.fluid.trait.FT_Heatable;
import com.hbm.inventory.fluid.trait.FT_Heatable.HeatingStep;
import com.hbm.inventory.fluid.trait.FT_Heatable.HeatingType;
import com.hbm.inventory.gui.GUIPWR;
import com.hbm.items.ModItems;
@ -18,6 +21,7 @@ import com.hbm.tileentity.TileEntityMachineBase;
import com.hbm.util.EnumUtil;
import com.hbm.util.fauxpointtwelve.BlockPos;
import api.hbm.fluid.IFluidStandardTransceiver;
import net.minecraft.block.Block;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.entity.player.EntityPlayer;
@ -28,13 +32,13 @@ import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityPWRController extends TileEntityMachineBase implements IGUIProvider, IControlReceiver {
public class TileEntityPWRController extends TileEntityMachineBase implements IGUIProvider, IControlReceiver, IFluidStandardTransceiver {
public FluidTank[] tanks;
public int coreHeat;
public static final int coreHeatCapacity = 25_000_000;
public static final int coreHeatCapacity = 10_000_000;
public int hullHeat;
public static final int hullHeatCapacity = 25_000_000;
public static final int hullHeatCapacity = 10_000_000;
public double flux;
public int rodLevel;
@ -53,6 +57,8 @@ public class TileEntityPWRController extends TileEntityMachineBase implements IG
public int sourceCount;
public boolean assembled;
protected List<BlockPos> ports = new ArrayList();
public TileEntityPWRController() {
super(3);
@ -82,6 +88,7 @@ public class TileEntityPWRController extends TileEntityMachineBase implements IG
if(block == ModBlocks.pwr_heatex) heatexCount++;
if(block == ModBlocks.pwr_channel) channelCount++;
if(block == ModBlocks.pwr_neutron_source) sourceCount++;
if(block == ModBlocks.pwr_port) ports.add(entry.getKey());
}
for(Entry<BlockPos, Block> entry : rodMap.entrySet()) {
@ -141,6 +148,15 @@ public class TileEntityPWRController extends TileEntityMachineBase implements IG
this.tanks[0].setType(2, slots);
setupTanks();
for(BlockPos pos : ports) {
for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
BlockPos portPos = pos.offset(dir);
if(tanks[1].getFill() > 0) this.sendFluid(tanks[1], worldObj, portPos.getX(), portPos.getY(), portPos.getZ(), dir);
if(worldObj.getTotalWorldTime() % 20 == 0) this.trySubscribe(tanks[0].getTankType(), worldObj, portPos.getX(), portPos.getY(), portPos.getZ(), dir);
}
}
if((typeLoaded == -1 || amountLoaded <= 0) && slots[0] != null && slots[0].getItem() == ModItems.pwr_fuel) {
typeLoaded = slots[0].getItemDamage();
amountLoaded++;
@ -190,12 +206,14 @@ public class TileEntityPWRController extends TileEntityMachineBase implements IG
}
/* CORE COOLING */
double coreCoolingApproachNum = getXOverE(this.heatexCount, 10) / 2D;
double coreCoolingApproachNum = getXOverE((double) this.heatexCount / (double) this.rodCount, 2) / 2D;
int averageCoreHeat = (this.coreHeat + this.hullHeat) / 2;
this.coreHeat -= (coreHeat - averageCoreHeat) * coreCoolingApproachNum;
this.hullHeat -= (hullHeat - averageCoreHeat) * coreCoolingApproachNum;
this.hullHeat *= 0.99D;
updateCoolant();
this.hullHeat *= 0.999D;
this.flux = newFlux;
@ -214,6 +232,26 @@ public class TileEntityPWRController extends TileEntityMachineBase implements IG
}
}
protected void updateCoolant() {
FT_Heatable trait = tanks[0].getTankType().getTrait(FT_Heatable.class);
if(trait == null || trait.getEfficiency(HeatingType.PWR) <= 0) return;
double coolingEff = (double) this.channelCount / (double) this.rodCount * 0.1D; //10% cooling if numbers match
if(coolingEff > 1D) coolingEff = 1D;
int heatToUse = (int) (this.hullHeat * coolingEff);
HeatingStep step = trait.getFirstStep();
int coolCycles = tanks[0].getFill() / step.amountReq;
int hotCycles = (tanks[1].getMaxFill() - tanks[1].getFill()) / step.amountProduced;
int heatCycles = heatToUse / step.heatReq;
int cycles = Math.min(coolCycles, Math.min(hotCycles, heatCycles));
this.hullHeat -= step.heatReq * cycles;
this.tanks[0].setFill(tanks[0].getFill() - step.amountReq * cycles);
this.tanks[1].setFill(tanks[1].getFill() + step.amountProduced * cycles);
}
public void networkUnpack(NBTTagCompound nbt) {
tanks[0].readFromNBT(nbt, "t0");
tanks[1].readFromNBT(nbt, "t1");
@ -234,6 +272,7 @@ public class TileEntityPWRController extends TileEntityMachineBase implements IG
if(trait == null || trait.getEfficiency(HeatingType.PWR) <= 0) {
tanks[0].setTankType(Fluids.NONE);
tanks[1].setTankType(Fluids.NONE);
return;
}
tanks[1].setTankType(trait.getFirstStep().typeProduced);
@ -258,6 +297,29 @@ public class TileEntityPWRController extends TileEntityMachineBase implements IG
super.readFromNBT(nbt);
this.assembled = nbt.getBoolean("assembled");
this.coreHeat = nbt.getInteger("coreHeat");
this.hullHeat = nbt.getInteger("hullHeat");
this.flux = nbt.getDouble("flux");
this.rodLevel = nbt.getInteger("rodLevel");
this.rodTarget = nbt.getInteger("rodTarget");
this.typeLoaded = nbt.getInteger("typeLoaded");
this.amountLoaded = nbt.getInteger("amountLoaded");
this.progress = nbt.getDouble("progress");
this.processTime = nbt.getDouble("processTime");
this.rodCount = nbt.getInteger("rodCount");
this.connections = nbt.getInteger("connections");
this.connectionsControlled = nbt.getInteger("connectionsControlled");
this.heatexCount = nbt.getInteger("heatexCount");
this.channelCount = nbt.getInteger("channelCount");
this.sourceCount = nbt.getInteger("sourceCount");
ports.clear();
int portCount = nbt.getInteger("portCount");
for(int i = 0; i < portCount; i++) {
int[] port = nbt.getIntArray("p" + i);
ports.add(new BlockPos(port[0], port[1], port[2]));
}
}
@Override
@ -265,6 +327,28 @@ public class TileEntityPWRController extends TileEntityMachineBase implements IG
super.writeToNBT(nbt);
nbt.setBoolean("assembled", assembled);
nbt.setInteger("coreHeat", coreHeat);
nbt.setInteger("hullHeat", hullHeat);
nbt.setDouble("flux", flux);
nbt.setInteger("rodLevel", rodLevel);
nbt.setInteger("rodTarget", rodTarget);
nbt.setInteger("typeLoaded", typeLoaded);
nbt.setInteger("amountLoaded", amountLoaded);
nbt.setDouble("progress", progress);
nbt.setDouble("processTime", processTime);
nbt.setInteger("rodCount", rodCount);
nbt.setInteger("connections", connections);
nbt.setInteger("connectionsControlled", connectionsControlled);
nbt.setInteger("heatexCount", heatexCount);
nbt.setInteger("channelCount", channelCount);
nbt.setInteger("sourceCount", sourceCount);
nbt.setInteger("portCount", ports.size());
for(int i = 0; i < ports.size(); i++) {
BlockPos pos = ports.get(i);
nbt.setIntArray("p" + i, new int[] { pos.getX(), pos.getY(), pos.getZ() });
}
}
@Override
@ -289,4 +373,19 @@ public class TileEntityPWRController extends TileEntityMachineBase implements IG
public GuiScreen provideGUI(int ID, EntityPlayer player, World world, int x, int y, int z) {
return new GUIPWR(player.inventory, this);
}
@Override
public FluidTank[] getAllTanks() {
return tanks;
}
@Override
public FluidTank[] getSendingTanks() {
return new FluidTank[] { tanks[1] };
}
@Override
public FluidTank[] getReceivingTanks() {
return new FluidTank[] { tanks[0] };
}
}