we have fission!

This commit is contained in:
Bob 2023-08-17 22:00:35 +02:00
parent fb97ffc88d
commit 24b883ec92
6 changed files with 147 additions and 54 deletions

View File

@ -23,7 +23,7 @@ public class ContainerPWR extends Container {
for(int i = 0; i < 3; i++) {
for(int j = 0; j < 9; j++) {
this.addSlotToContainer(new Slot(invPlayer, j + i * 9 + 9, 8 + j * 18, 108 + i * 18));
this.addSlotToContainer(new Slot(invPlayer, j + i * 9 + 9, 8 + j * 18, 106 + i * 18));
}
}

View File

@ -3,14 +3,19 @@ package com.hbm.inventory.gui;
import org.lwjgl.opengl.GL11;
import com.hbm.inventory.container.ContainerPWR;
import com.hbm.items.ModItems;
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;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.ResourceLocation;
public class GUIPWR extends GuiInfoContainer {
@ -36,17 +41,40 @@ 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)});
if(controller.typeLoaded != -1 && controller.amountLoaded > 0) {
ItemStack display = new ItemStack(ModItems.pwr_fuel, 1, controller.typeLoaded);
if(guiLeft + 88 <= x && guiLeft + 88 + 18 > x && guiTop + 4 < y && guiTop + 4 + 18 >= y) this.renderToolTip(display, x, y);
}
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 drawItemStack(ItemStack stack, int x, int y, String label) {
GL11.glPushMatrix();
GL11.glTranslatef(0.0F, 0.0F, 32.0F);
this.zLevel = 200.0F;
itemRender.zLevel = 200.0F;
FontRenderer font = null;
if(stack != null) font = stack.getItem().getFontRenderer(stack);
if(font == null) font = fontRendererObj;
itemRender.renderItemAndEffectIntoGUI(font, this.mc.getTextureManager(), stack, x, y);
GL11.glScaled(0.5, 0.5, 0.5);
itemRender.renderItemOverlayIntoGUI(font, this.mc.getTextureManager(), stack, (x + font.getStringWidth(label) / 4) * 2, (y + 15) * 2, label);
this.zLevel = 0.0F;
itemRender.zLevel = 0.0F;
GL11.glPopMatrix();
}
@Override
protected void drawGuiContainerForegroundLayer(int i, int j) {
this.fontRendererObj.drawString(I18n.format("container.inventory"), 8, this.ySize - 96 + 2, 4210752);
double scale = 1.25;
String flux = String.format("%,.1f", 10000.0D);
String flux = String.format("%,.1f", controller.flux);
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);
@ -61,7 +89,13 @@ public class GUIPWR extends GuiInfoContainer {
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);
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);
if(controller.typeLoaded != -1 && controller.amountLoaded > 0) {
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();
}
}
}

View File

@ -100,6 +100,19 @@ public abstract class GuiInfoContainer extends GuiContainer {
return this.fontRendererObj;
}
protected void drawItemStack(ItemStack stack, int x, int y, String label) {
GL11.glTranslatef(0.0F, 0.0F, 32.0F);
this.zLevel = 200.0F;
itemRender.zLevel = 200.0F;
FontRenderer font = null;
if(stack != null) font = stack.getItem().getFontRenderer(stack);
if(font == null) font = fontRendererObj;
itemRender.renderItemAndEffectIntoGUI(font, this.mc.getTextureManager(), stack, x, y);
itemRender.renderItemOverlayIntoGUI(font, this.mc.getTextureManager(), stack, x, y, label);
this.zLevel = 0.0F;
itemRender.zLevel = 0.0F;
}
protected void drawStackText(List lines, int x, int y, FontRenderer font) {
if(!lines.isEmpty()) {

View File

@ -1,5 +1,7 @@
package com.hbm.items.machine;
import java.util.List;
import com.hbm.items.ItemEnumMulti;
import com.hbm.util.EnumUtil;
import com.hbm.util.function.Function;
@ -8,8 +10,7 @@ import com.hbm.util.function.Function.FunctionSqrt;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraft.util.EnumChatFormatting;
public class ItemPWRFuel extends ItemEnumMulti {
@ -26,7 +27,7 @@ public class ItemPWRFuel extends ItemEnumMulti {
MOX( 07.5D, new FunctionLogarithmic(25)),
MEP( 07.5D, new FunctionLogarithmic(25)),
HEP239( 10.0D, new FunctionSqrt(25)),
HEP24( 10.0D, new FunctionSqrt(25)),
HEP241( 10.0D, new FunctionSqrt(25)),
MEA( 07.5D, new FunctionLogarithmic(25)),
HEA242( 10.0D, new FunctionSqrt(25)),
HES326( 15.0D, new FunctionSqrt(25)),
@ -41,48 +42,17 @@ public class ItemPWRFuel extends ItemEnumMulti {
this.function = function;
}
}
@Override
public boolean showDurabilityBar(ItemStack stack) {
return getDurabilityForDisplay(stack) > 0D;
}
@Override
public double getDurabilityForDisplay(ItemStack stack) {
return 1D - getEnrichment(stack);
}
public static double getEnrichment(ItemStack stack) {
@Override
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean bool) {
EnumPWRFuel num = EnumUtil.grabEnumSafely(EnumPWRFuel.class, stack.getItemDamage());
return getYield(stack) / num.yield;
}
public static double getYield(ItemStack stack) {
return getDouble(stack, "yield");
}
public static void setYield(ItemStack stack, double yield) {
setDouble(stack, "yield", yield);
}
public static void setDouble(ItemStack stack, String key, double yield) {
if(!stack.hasTagCompound()) setNBTDefaults(stack);
stack.stackTagCompound.setDouble(key, yield);
}
public static double getDouble(ItemStack stack, String key) {
if(!stack.hasTagCompound()) setNBTDefaults(stack);
return stack.stackTagCompound.getDouble(key);
}
private static void setNBTDefaults(ItemStack stack) {
EnumPWRFuel num = EnumUtil.grabEnumSafely(EnumPWRFuel.class, stack.getItemDamage());
stack.stackTagCompound = new NBTTagCompound();
setYield(stack, num.yield);
}
@Override
public void onCreated(ItemStack stack, World world, EntityPlayer player) {
setNBTDefaults(stack);
String color = EnumChatFormatting.GOLD + "";
String reset = EnumChatFormatting.RESET + "";
list.add(color + "Heat per flux: " + reset + num.heatEmission + " TU");
list.add(color + "Reacton function: " + reset + num.function.getLabelForFuel());
list.add(color + "Fuel type: " + reset + num.function.getDangerFromFuel());
}
}

View File

@ -12,14 +12,17 @@ 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.items.ModItems;
import com.hbm.items.machine.ItemPWRFuel.EnumPWRFuel;
import com.hbm.tileentity.IGUIProvider;
import com.hbm.tileentity.TileEntityMachineBase;
import com.hbm.util.EnumUtil;
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.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
@ -29,9 +32,10 @@ public class TileEntityPWRController extends TileEntityMachineBase implements IG
public FluidTank[] tanks;
public int coreHeat;
public int coreHeatCapacity;
public static final int coreHeatCapacity = 25_000_000;
public int hullHeat;
public int hullHeatCapacity;
public static final int hullHeatCapacity = 25_000_000;
public double flux;
public int rodLevel;
public int rodTarget;
@ -39,7 +43,7 @@ public class TileEntityPWRController extends TileEntityMachineBase implements IG
public int typeLoaded;
public int amountLoaded;
public double progress;
public int processTime;
public double processTime;
public int rodCount;
public int connections;
@ -58,6 +62,7 @@ public class TileEntityPWRController extends TileEntityMachineBase implements IG
this.tanks[1] = new FluidTank(Fluids.COOLANT_HOT, 128_000);
}
/** The initial creation of the reactor, does all the pre-calculation and whatnot */
public void setup(HashMap<BlockPos, Block> partMap, HashMap<BlockPos, Block> rodMap) {
rodCount = 0;
@ -136,22 +141,92 @@ public class TileEntityPWRController extends TileEntityMachineBase implements IG
this.tanks[0].setType(2, slots);
setupTanks();
if(typeLoaded == -1 || amountLoaded <= 0 && slots[0] != null && slots[0].getItem() == ModItems.pwr_fuel) {
if((typeLoaded == -1 || amountLoaded <= 0) && slots[0] != null && slots[0].getItem() == ModItems.pwr_fuel) {
typeLoaded = slots[0].getItemDamage();
amountLoaded++;
this.decrStackSize(0, 1);
this.markChanged();
} else if(slots[0] != null && slots[0].getItem() == ModItems.pwr_fuel && slots[0].getItemDamage() == typeLoaded && amountLoaded < rodCount){
amountLoaded++;
this.decrStackSize(0, 1);
this.markChanged();
}
if(this.rodTarget > this.rodLevel) this.rodLevel++;
if(this.rodTarget < this.rodLevel) this.rodLevel--;
int newFlux = this.sourceCount * 20;
if(typeLoaded != -1 && amountLoaded > 0) {
EnumPWRFuel fuel = EnumUtil.grabEnumSafely(EnumPWRFuel.class, typeLoaded);
double usedRods = getTotalProcessMultiplier();
double fluxPerRod = this.flux / this.rodCount;
double outputPerRod = fuel.function.effonix(fluxPerRod);
double totalOutput = outputPerRod * amountLoaded * usedRods;
double totalHeatOutput = totalOutput * fuel.heatEmission;
this.coreHeat += totalHeatOutput;
newFlux += totalOutput;
this.processTime = (int) fuel.yield;
this.progress += totalOutput;
if(this.progress >= this.processTime) {
this.progress -= this.processTime;
if(slots[1] == null) {
slots[1] = new ItemStack(ModItems.pwr_fuel_hot, 1, typeLoaded);
} else if(slots[1].getItem() == ModItems.pwr_fuel_hot && slots[1].getItemDamage() == typeLoaded && slots[1].stackSize < slots[1].getMaxStackSize()) {
slots[1].stackSize++;
}
this.markChanged();
}
}
if(this.amountLoaded <= 0) {
this.typeLoaded = -1;
}
/* CORE COOLING */
double coreCoolingApproachNum = getXOverE(this.heatexCount, 10) / 2D;
int averageCoreHeat = (this.coreHeat + this.hullHeat) / 2;
this.coreHeat -= (coreHeat - averageCoreHeat) * coreCoolingApproachNum;
this.hullHeat -= (hullHeat - averageCoreHeat) * coreCoolingApproachNum;
this.hullHeat *= 0.99D;
this.flux = newFlux;
NBTTagCompound data = new NBTTagCompound();
tanks[0].writeToNBT(data, "t0");
tanks[1].writeToNBT(data, "t1");
data.setInteger("rodCount", rodCount);
data.setInteger("coreHeat", coreHeat);
data.setInteger("hullHeat", hullHeat);
data.setDouble("flux", flux);
data.setDouble("processTime", processTime);
data.setDouble("progress", progress);
data.setInteger("typeLoaded", typeLoaded);
data.setInteger("amountLoaded", amountLoaded);
this.networkPack(data, 150);
}
}
public void networkUnpack(NBTTagCompound nbt) {
tanks[0].readFromNBT(nbt, "t0");
tanks[1].readFromNBT(nbt, "t1");
rodCount = nbt.getInteger("rodCount");
coreHeat = nbt.getInteger("coreHeat");
hullHeat = nbt.getInteger("hullHeat");
flux = nbt.getDouble("flux");
processTime = nbt.getDouble("processTime");
progress = nbt.getDouble("progress");
typeLoaded = nbt.getInteger("typeLoaded");
amountLoaded = nbt.getInteger("amountLoaded");
}
protected void setupTanks() {
FT_Heatable trait = tanks[0].getTankType().getTrait(FT_Heatable.class);
@ -171,11 +246,11 @@ public class TileEntityPWRController extends TileEntityMachineBase implements IG
}
public double connectinFunc(double connections) {
return connections * (1D - getXOverE(connections, 300D)) + connections / 2D * getXOverE(connections, 300D); //creates a curve that smoothly transitions from f(x)=x to f(x)=x/2
return connections / 10D * (1D - getXOverE(connections, 300D)) + connections / 150D * getXOverE(connections, 300D);
}
public double getXOverE(double x, double d) {
return -Math.pow(Math.E, -x / d);
return 1 - Math.pow(Math.E, -x / d);
}
@Override

View File

@ -15,6 +15,7 @@ public abstract class Function {
protected double div = 1D;
protected double off = 0;
//the german prononciation of f(x) - "F von X", tee hee
public abstract double effonix(double x);
public abstract String getLabelForFuel();
public abstract String getDangerFromFuel();