mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
PWR GUI work, error messages, pre-calculation
This commit is contained in:
parent
f7dd3a0a93
commit
0332853822
@ -7,6 +7,8 @@ import com.hbm.blocks.ModBlocks;
|
||||
import com.hbm.blocks.machine.BlockPWR.TileEntityBlockPWR;
|
||||
import com.hbm.lib.RefStrings;
|
||||
import com.hbm.main.MainRegistry;
|
||||
import com.hbm.packet.AuxParticlePacketNT;
|
||||
import com.hbm.packet.PacketDispatcher;
|
||||
import com.hbm.tileentity.machine.TileEntityPWRController;
|
||||
import com.hbm.util.fauxpointtwelve.BlockPos;
|
||||
|
||||
@ -19,7 +21,9 @@ import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.MathHelper;
|
||||
@ -73,7 +77,7 @@ public class MachinePWRController extends BlockContainer {
|
||||
TileEntityPWRController controller = (TileEntityPWRController) world.getTileEntity(x, y, z);
|
||||
|
||||
if(!controller.assembled) {
|
||||
assemble(world, x, y, z);
|
||||
assemble(world, x, y, z, player);
|
||||
} else {
|
||||
FMLNetworkHandler.openGui(player, MainRegistry.instance, 0, world, x, y, z);
|
||||
}
|
||||
@ -89,17 +93,20 @@ public class MachinePWRController extends BlockContainer {
|
||||
private static boolean errored;
|
||||
private static final int maxSize = 1024;
|
||||
|
||||
public void assemble(World world, int x, int y, int z) {
|
||||
public void assemble(World world, int x, int y, int z, EntityPlayer player) {
|
||||
assembly.clear();
|
||||
fuelRods.clear();
|
||||
assembly.put(new BlockPos(x, y, z), this);
|
||||
|
||||
ForgeDirection dir = ForgeDirection.getOrientation(world.getBlockMetadata(x, y, z)).getOpposite();
|
||||
|
||||
errored = false;
|
||||
floodFill(world, x + dir.offsetX, y, z + dir.offsetZ);
|
||||
floodFill(world, x + dir.offsetX, y, z + dir.offsetZ, player);
|
||||
|
||||
if(fuelRods.size() == 0) errored = true;
|
||||
|
||||
TileEntityPWRController controller = (TileEntityPWRController) world.getTileEntity(x, y, z);
|
||||
|
||||
if(!errored) {
|
||||
for(Entry<BlockPos, Block> entry : assembly.entrySet()) {
|
||||
|
||||
@ -122,21 +129,23 @@ public class MachinePWRController extends BlockContainer {
|
||||
pwr.markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
controller.setup(assembly, fuelRods);
|
||||
}
|
||||
|
||||
TileEntityPWRController controller = (TileEntityPWRController) world.getTileEntity(x, y, z);
|
||||
controller.assembled = !errored;
|
||||
|
||||
assembly.clear();
|
||||
fuelRods.clear();
|
||||
}
|
||||
|
||||
private void floodFill(World world, int x, int y, int z) {
|
||||
private void floodFill(World world, int x, int y, int z, EntityPlayer player) {
|
||||
|
||||
BlockPos pos = new BlockPos(x, y, z);
|
||||
|
||||
if(assembly.containsKey(pos)) return;
|
||||
if(assembly.size() >= maxSize) {
|
||||
errored = true;
|
||||
sendError(world, x, y, z, "Max size exceeded", player);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -150,18 +159,32 @@ public class MachinePWRController extends BlockContainer {
|
||||
if(isValidCore(block)) {
|
||||
assembly.put(pos, block);
|
||||
if(block == ModBlocks.pwr_fuel) fuelRods.put(pos, block);
|
||||
floodFill(world, x + 1, y, z);
|
||||
floodFill(world, x - 1, y, z);
|
||||
floodFill(world, x, y + 1, z);
|
||||
floodFill(world, x, y - 1, z);
|
||||
floodFill(world, x, y, z + 1);
|
||||
floodFill(world, x, y, z - 1);
|
||||
floodFill(world, x + 1, y, z, player);
|
||||
floodFill(world, x - 1, y, z, player);
|
||||
floodFill(world, x, y + 1, z, player);
|
||||
floodFill(world, x, y - 1, z, player);
|
||||
floodFill(world, x, y, z + 1, player);
|
||||
floodFill(world, x, y, z - 1, player);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
sendError(world, x, y, z, "Non-reactor block", player);
|
||||
errored = true;
|
||||
}
|
||||
|
||||
private void sendError(World world, int x, int y, int z, String message, EntityPlayer player) {
|
||||
|
||||
if(player instanceof EntityPlayerMP) {
|
||||
NBTTagCompound data = new NBTTagCompound();
|
||||
data.setString("type", "marker");
|
||||
data.setInteger("color", 0xff0000);
|
||||
data.setInteger("expires", 5_000);
|
||||
data.setDouble("dist", 128D);
|
||||
if(message != null) data.setString("label", message);
|
||||
PacketDispatcher.wrapper.sendTo(new AuxParticlePacketNT(data, x, y, z), (EntityPlayerMP) player);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isValidCore(Block block) {
|
||||
if(block == ModBlocks.pwr_fuel || block == ModBlocks.pwr_control || block == ModBlocks.pwr_channel || block == ModBlocks.pwr_heatex || block == ModBlocks.pwr_neutron_source) return true;
|
||||
return false;
|
||||
|
||||
@ -489,8 +489,9 @@ 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_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));
|
||||
|
||||
@ -69,7 +69,8 @@ public class FT_Heatable extends FluidTrait {
|
||||
|
||||
public static enum HeatingType {
|
||||
BOILER("Boilable"),
|
||||
HEATEXCHANGER("Heatable");
|
||||
HEATEXCHANGER("Heatable"),
|
||||
PWR("PWR Coolant");
|
||||
|
||||
public String name;
|
||||
|
||||
|
||||
@ -4,6 +4,8 @@ import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.hbm.inventory.container.ContainerPWR;
|
||||
import com.hbm.lib.RefStrings;
|
||||
import com.hbm.render.util.GaugeUtil;
|
||||
import com.hbm.render.util.GaugeUtil.Gauge;
|
||||
import com.hbm.tileentity.machine.TileEntityPWRController;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
@ -24,11 +26,29 @@ public class GUIPWR extends GuiInfoContainer {
|
||||
this.ySize = 188;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int x, int y, float interp) {
|
||||
super.drawScreen(x, y, interp);
|
||||
|
||||
this.drawCustomInfoStat(x, y, guiLeft + 115, guiTop + 31, 18, 18, x, y, new String[] { "Core: " + String.format("%,d", controller.coreHeat) + " / " + String.format("%,d", controller.coreHeatCapacity) + " TU" });
|
||||
this.drawCustomInfoStat(x, y, guiLeft + 151, guiTop + 31, 18, 18, x, y, new String[] { "Hull: " + String.format("%,d", controller.hullHeat) + " / " + String.format("%,d", controller.hullHeatCapacity) + " TU" });
|
||||
|
||||
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)});
|
||||
|
||||
controller.tanks[0].renderTankInfo(this, x, y, guiLeft + 8, guiTop + 5, 16, 52);
|
||||
controller.tanks[1].renderTankInfo(this, x, y, guiLeft + 26, guiTop + 5, 16, 52);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerForegroundLayer(int i, int j) {
|
||||
String name = this.controller.hasCustomInventoryName() ? this.controller.getInventoryName() : I18n.format(this.controller.getInventoryName());
|
||||
this.fontRendererObj.drawString(name, this.xSize / 2 - this.fontRendererObj.getStringWidth(name) / 2, 6, 4210752);
|
||||
this.fontRendererObj.drawString(I18n.format("container.inventory"), 8, this.ySize - 96 + 2, 4210752);
|
||||
|
||||
double scale = 1.25;
|
||||
String flux = String.format("%,.1f", 10000.0D);
|
||||
GL11.glScaled(1 / scale, 1 / scale, 1);
|
||||
this.fontRendererObj.drawString(flux, (int) (165 * scale - this.fontRendererObj.getStringWidth(flux)), (int)(64 * scale), 0x00ff00);
|
||||
GL11.glScaled(scale, scale, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -36,5 +56,11 @@ public class GUIPWR extends GuiInfoContainer {
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
Minecraft.getMinecraft().getTextureManager().bindTexture(texture);
|
||||
drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
|
||||
|
||||
if(System.currentTimeMillis() % 1000 < 500)
|
||||
drawTexturedModalRect(guiLeft + 147, guiTop, 176, 14, 26, 26);
|
||||
|
||||
GaugeUtil.renderGauge(Gauge.ROUND_SMALL, guiLeft + 115, guiTop + 31, this.zLevel, 0.1D);
|
||||
GaugeUtil.renderGauge(Gauge.ROUND_SMALL, guiLeft + 151, guiTop + 31, this.zLevel, 0.4D);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,22 +1,119 @@
|
||||
package com.hbm.tileentity.machine;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import com.hbm.blocks.ModBlocks;
|
||||
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.HeatingType;
|
||||
import com.hbm.inventory.gui.GUIPWR;
|
||||
import com.hbm.tileentity.IGUIProvider;
|
||||
import com.hbm.tileentity.TileEntityMachineBase;
|
||||
import com.hbm.util.fauxpointtwelve.BlockPos;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public class TileEntityPWRController extends TileEntityMachineBase implements IGUIProvider {
|
||||
|
||||
public FluidTank[] tanks;
|
||||
public int coreHeat;
|
||||
public int coreHeatCapacity;
|
||||
public int hullHeat;
|
||||
public int hullHeatCapacity;
|
||||
public int rodLevel;
|
||||
public int rodTarget;
|
||||
public int progress;
|
||||
public int processTime;
|
||||
|
||||
public int rodCount;
|
||||
public int connections;
|
||||
public int connectionsControlled;
|
||||
public int heatexCount;
|
||||
public int channelCount;
|
||||
public int sourceCount;
|
||||
|
||||
public boolean assembled;
|
||||
|
||||
public TileEntityPWRController() {
|
||||
super(3);
|
||||
|
||||
this.tanks = new FluidTank[2];
|
||||
this.tanks[0] = new FluidTank(Fluids.COOLANT, 128_000);
|
||||
this.tanks[1] = new FluidTank(Fluids.COOLANT_HOT, 128_000);
|
||||
}
|
||||
|
||||
public void setup(HashMap<BlockPos, Block> partMap, HashMap<BlockPos, Block> rodMap) {
|
||||
|
||||
rodCount = 0;
|
||||
connections = 0;
|
||||
connectionsControlled = 0;
|
||||
heatexCount = 0;
|
||||
channelCount = 0;
|
||||
sourceCount = 0;
|
||||
|
||||
int connectionsDouble = 0;
|
||||
int connectionsControlledDouble = 0;
|
||||
|
||||
for(Entry<BlockPos, Block> entry : partMap.entrySet()) {
|
||||
Block block = entry.getValue();
|
||||
|
||||
if(block == ModBlocks.pwr_fuel) rodCount++;
|
||||
if(block == ModBlocks.pwr_heatex) heatexCount++;
|
||||
if(block == ModBlocks.pwr_channel) channelCount++;
|
||||
if(block == ModBlocks.pwr_neutron_source) sourceCount++;
|
||||
}
|
||||
|
||||
for(Entry<BlockPos, Block> entry : rodMap.entrySet()) {
|
||||
BlockPos fuelPos = entry.getKey();
|
||||
|
||||
for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
|
||||
|
||||
boolean controlled = false;
|
||||
|
||||
for(int i = 1; i < 16; i++) {
|
||||
BlockPos checkPos = fuelPos.offset(dir, i);
|
||||
Block atPos = partMap.get(checkPos);
|
||||
if(atPos == null || atPos == ModBlocks.pwr_casing) break;
|
||||
if(atPos == ModBlocks.pwr_control) controlled = true;
|
||||
if(atPos == ModBlocks.pwr_fuel) {
|
||||
if(controlled) {
|
||||
connectionsControlledDouble++;
|
||||
} else {
|
||||
connectionsDouble++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if(atPos == ModBlocks.pwr_reflector) {
|
||||
if(controlled) {
|
||||
connectionsControlledDouble += 2;
|
||||
} else {
|
||||
connectionsDouble += 2;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
connections = connectionsDouble / 2;
|
||||
connectionsControlled = connectionsControlledDouble / 2;
|
||||
|
||||
System.out.println("Finalized nuclear reactor!");
|
||||
System.out.println("Rods: " + rodCount);
|
||||
System.out.println("Connections: " + connections);
|
||||
System.out.println("Controlled connections: " + connectionsControlled);
|
||||
System.out.println("Heatex: " + heatexCount);
|
||||
System.out.println("Channels: " + channelCount);
|
||||
System.out.println("Sources: " + sourceCount);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -27,6 +124,27 @@ public class TileEntityPWRController extends TileEntityMachineBase implements IG
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
|
||||
if(!worldObj.isRemote) {
|
||||
|
||||
this.tanks[0].setType(2, slots);
|
||||
setupTanks();
|
||||
|
||||
NBTTagCompound data = new NBTTagCompound();
|
||||
tanks[0].writeToNBT(data, "t0");
|
||||
tanks[1].writeToNBT(data, "t1");
|
||||
}
|
||||
}
|
||||
|
||||
protected void setupTanks() {
|
||||
|
||||
FT_Heatable trait = tanks[0].getTankType().getTrait(FT_Heatable.class);
|
||||
|
||||
if(trait == null || trait.getEfficiency(HeatingType.PWR) <= 0) {
|
||||
tanks[0].setTankType(Fluids.NONE);
|
||||
tanks[1].setTankType(Fluids.NONE);
|
||||
}
|
||||
|
||||
tanks[1].setTankType(trait.getFirstStep().typeProduced);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user