gas turbine time

This commit is contained in:
Boblet 2023-02-13 16:20:15 +01:00
parent 2f48734562
commit ab9fc80e74
13 changed files with 11266 additions and 16108 deletions

View File

@ -0,0 +1,56 @@
package com.hbm.blocks.machine;
import com.hbm.tileentity.TileEntityProxyCombo;
import com.hbm.tileentity.machine.TileEntityMachineTurbineGas;
import com.hbm.blocks.BlockDummyable;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
public class MachineTurbineGas extends BlockDummyable {
public MachineTurbineGas(Material mat) {
super(mat);
}
@Override
public TileEntity createNewTileEntity(World world, int meta) {
if(meta >= 12)
return new TileEntityMachineTurbineGas();
if(meta >= 6)
return new TileEntityProxyCombo(false, true, true);
return null;
}
@Override
public int[] getDimensions() {
return new int[] { 2, 0, 1, 1, 4, 5 };
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
return standardOpenBehavior(world, x, y, z, player, 0);
}
@Override
public int getOffset() {
return 1;
}
@Override
public void fillSpace(World world, int x, int y, int z, ForgeDirection dir, int o) {
super.fillSpace(world, x, y, z, dir, o);
this.makeExtra(world, x - dir.offsetX * 1 - dir.offsetZ * 4, y + 1, z + dir.offsetX * 4 - dir.offsetZ * 1); //power
this.makeExtra(world, x - dir.offsetZ * 1, y, z + dir.offsetX * 1); //gas in
this.makeExtra(world, x - dir.offsetX * 2 - dir.offsetZ * 1, y, z + dir.offsetX * 1 - dir.offsetZ * 2); //gas in
this.makeExtra(world, x + dir.offsetZ * 4, y, z - dir.offsetX * 4); //wa'er in
this.makeExtra(world, x + dir.offsetZ * 4 - dir.offsetX * 2, y, z - dir.offsetX * 4 - dir.offsetZ * 2); //wa'er in
this.makeExtra(world, x + dir.offsetZ * 5 - dir.offsetX * 1, y + 1, z - dir.offsetX * 5 - dir.offsetZ * 1); //steam out
}
}

View File

@ -0,0 +1,89 @@
package com.hbm.inventory.container;
import com.hbm.inventory.SlotMachineOutput;
import com.hbm.inventory.fluid.FluidType;
import com.hbm.inventory.fluid.Fluids;
import com.hbm.items.ModItems;
import com.hbm.items.machine.ItemFluidIdentifier;
import com.hbm.items.machine.ItemZirnoxRod;
import com.hbm.tileentity.machine.TileEntityMachineTurbineGas;
import api.hbm.energy.IBatteryItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
public class ContainerMachineTurbineGas extends Container {
private TileEntityMachineTurbineGas turbinegas;
public ContainerMachineTurbineGas(InventoryPlayer invPlayer, TileEntityMachineTurbineGas te) {
turbinegas = te;
//Battery
this.addSlotToContainer(new Slot(te, 0, 8, 109));
//Fluid ID
this.addSlotToContainer(new Slot(te, 1, 36, 17));
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, 141 + i * 18)); //player's inventory
}
}
for(int i = 0; i < 9; i++) {
this.addSlotToContainer(new Slot(invPlayer, i, 8 + i * 18, 199)); //shit in the hotbar
}
}
@Override
public ItemStack transferStackInSlot(EntityPlayer p_82846_1_, int par2) { //shit for shift clicking that works and idk how
ItemStack var3 = null;
Slot var4 = (Slot) this.inventorySlots.get(par2);
if(var4 != null && var4.getHasStack()) {
ItemStack var5 = var4.getStack();
var3 = var5.copy();
if(par2 <= 1) { //checks if the item is in the battery or fluidID slot
if(!this.mergeItemStack(var5, 2, this.inventorySlots.size(), true)) {
return null;
}
} else if(var5.getItem() instanceof IBatteryItem) { //only yeets batteries in the battery slot
if(!this.mergeItemStack(var5, 0, 1, true))
return null;
} else if(var5.getItem() instanceof ItemFluidIdentifier) {
FluidType type = ItemFluidIdentifier.getType(var5);
if (type != Fluids.GAS && type != Fluids.PETROLEUM && type != Fluids.LPG ) //doesn't let you yeet random identifiers in the identifier slot
return null;
if(!this.mergeItemStack(var5, 1, 2, true))
return null;
} else {
return null;
}
if(var5.stackSize == 0) {
var4.putStack((ItemStack) null);
} else {
var4.onSlotChanged();
}
}
return var3;
}
@Override
public boolean canInteractWith(EntityPlayer player) {
return turbinegas.isUseableByPlayer(player);
}
}

View File

@ -0,0 +1,318 @@
package com.hbm.inventory.gui;
import java.awt.event.MouseListener;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
import com.hbm.inventory.container.ContainerMachineTurbineGas;
import com.hbm.inventory.fluid.FluidType;
import com.hbm.inventory.fluid.Fluids;
import com.hbm.lib.RefStrings;
import com.hbm.packet.NBTControlPacket;
import com.hbm.packet.PacketDispatcher;
import com.hbm.tileentity.machine.TileEntityMachineTurbineGas;
import com.hbm.util.I18nUtil;
import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.PositionedSoundRecord;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
public class GUIMachineTurbineGas extends GuiInfoContainer {
private static ResourceLocation texture = new ResourceLocation(RefStrings.MODID + ":textures/gui/generators/gui_turbinegas.png");
private static ResourceLocation gauge_tex = new ResourceLocation(RefStrings.MODID + ":textures/gui/gauges/button_big.png");
private TileEntityMachineTurbineGas turbinegas;
int yStart;
int slidStart;
public GUIMachineTurbineGas(InventoryPlayer invPlayer, TileEntityMachineTurbineGas te) {
super(new ContainerMachineTurbineGas(invPlayer, te));
turbinegas = te;
this.xSize = 176;
this.ySize = 223;
}
//@Override
protected void mouseClicked(int x, int y, int i) {
super.mouseClicked(x, y, i);
slidStart = turbinegas.powerSliderPos;
yStart = y;
if(Math.sqrt(Math.pow((x - guiLeft - 88), 2) + Math.pow((y - guiTop - 40), 2)) <= 8) { //start-stop circular button
if(turbinegas.counter == 0 || turbinegas.counter == 579) {
int state = turbinegas.state - 1; //offline(0) to startup(-1), online(1) to offline(0)
mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F));
NBTTagCompound data = new NBTTagCompound();
data.setInteger("state", state);
PacketDispatcher.wrapper.sendToServer(new NBTControlPacket(data, turbinegas.xCoord, turbinegas.yCoord, turbinegas.zCoord));
}
else
return;
}
if(turbinegas.state == 1 && x > guiLeft + 74 && x <= guiLeft + 74 + 29 && y >= guiTop + 86 && y < guiTop + 86 + 13) { //auto mode button
boolean automode = !turbinegas.autoMode;
mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F));
NBTTagCompound data = new NBTTagCompound();
data.setBoolean("autoMode", automode);
PacketDispatcher.wrapper.sendToServer(new NBTControlPacket(data, turbinegas.xCoord, turbinegas.yCoord, turbinegas.zCoord));
}
if(turbinegas.state == 1 && (guiTop + 97 - slidStart) <= yStart && (guiTop + 103 - slidStart) > yStart && guiLeft + 36 < x && guiLeft + 52 >= x) { //power slider
NBTTagCompound data = new NBTTagCompound();
data.setBoolean("autoMode", false); //if you click the slider with automode on, turns off automode
PacketDispatcher.wrapper.sendToServer(new NBTControlPacket(data, turbinegas.xCoord, turbinegas.yCoord, turbinegas.zCoord));
mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F));
}
}
@Override
protected void mouseClickMove(int x, int y, int p_146273_3_, long p_146273_4_) {
super.mouseClickMove(x, y, p_146273_3_, p_146273_4_);
int slidPos = turbinegas.powerSliderPos;
if(!turbinegas.autoMode && turbinegas.state == 1 && guiLeft + 36 < x && guiLeft + 52 >= x && guiTop + 37 < y && guiTop + 103 >= y) { //area in which the slider can move
if((guiTop + 97 - slidStart) <= yStart && (guiTop + 103 - slidStart) > yStart) {
slidPos = guiTop + 100 - y;
if(slidPos > 60)
slidPos = 60;
else if(slidPos < 0)
slidPos = 0;
NBTTagCompound data = new NBTTagCompound();
data.setDouble("slidPos", slidPos);
PacketDispatcher.wrapper.sendToServer(new NBTControlPacket(data, turbinegas.xCoord, turbinegas.yCoord, turbinegas.zCoord));
}
}
}
@Override
public void drawScreen(int mouseX, int mouseY, float f) {
super.drawScreen(mouseX, mouseY, f);
this.drawElectricityInfo(this, mouseX, mouseY, guiLeft + 26, guiTop + 108, 142, 16, turbinegas.power, turbinegas.getMaxPower());
if(turbinegas.powerSliderPos == 0)
this.drawCustomInfoStat(mouseX, mouseY, guiLeft + 36, guiTop + 36, 16, 66, mouseX, mouseY, new String[] {"Turbine idle"});
else
this.drawCustomInfoStat(mouseX, mouseY, guiLeft + 36, guiTop + 36, 16, 66, mouseX, mouseY, new String[] {(turbinegas.powerSliderPos) * 100 / 60 + "% power"});
if(turbinegas.temp >= 20)
this.drawCustomInfoStat(mouseX, mouseY, guiLeft + 133, guiTop + 23, 8, 72, mouseX, mouseY, new String[] {"Temperature: " + (turbinegas.temp) + " °C"});
else
this.drawCustomInfoStat(mouseX, mouseY, guiLeft + 133, guiTop + 23, 8, 72, mouseX, mouseY, new String[] {"Temperature: 20 °C"});
turbinegas.tanks[0].renderTankInfo(this, mouseX, mouseY, guiLeft + 8, guiTop + 16, 16, 48);
turbinegas.tanks[1].renderTankInfo(this, mouseX, mouseY, guiLeft + 8, guiTop + 70, 16, 32);
turbinegas.tanks[2].renderTankInfo(this, mouseX, mouseY, guiLeft + 147, guiTop + 61, 16, 36);
turbinegas.tanks[3].renderTankInfo(this, mouseX, mouseY, guiLeft + 147, guiTop + 21, 16, 36);
String[] info = I18nUtil.resolveKeyArray("desc.gui.turbinegas.automode");
this.drawCustomInfoStat(mouseX, mouseY, guiLeft - 16, guiTop + 34, 16, 16, guiLeft - 8, guiTop + 44 + 16, info);
String[] fuels = I18nUtil.resolveKeyArray("desc.gui.turbinegas.fuels");
this.drawCustomInfoStat(mouseX, mouseY, guiLeft - 16, guiTop + 34 + 16, 16, 16, guiLeft - 8, guiTop + 44 + 16, fuels);
String[] warning = I18nUtil.resolveKeyArray("desc.gui.turbinegas.warning");
if(turbinegas.tanks[0].getFill() < 5000 || turbinegas.tanks[1].getFill() < 1000)
this.drawCustomInfoStat(mouseX, mouseY, guiLeft - 16, guiTop + 34 + 32, 16, 16, guiLeft - 8, guiTop + 44 + 16, warning);
}
@Override
protected void drawGuiContainerBackgroundLayer(float iinterpolation, int x, int y) {
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
Minecraft.getMinecraft().getTextureManager().bindTexture(texture);
drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize); //the main thing
if(turbinegas.autoMode)
drawTexturedModalRect(guiLeft + 74, guiTop + 86, 194, 11, 29, 13); //auto mode button
else
drawTexturedModalRect(guiLeft + 74, guiTop + 86, 194, 24, 29, 13);
switch(turbinegas.state) {
case 0:
drawTexturedModalRect(guiLeft + 80, guiTop + 32, 178, 38, 16, 16); //red button
break;
case -1:
drawTexturedModalRect(guiLeft + 80, guiTop + 32, 194, 38, 16, 16); //orange button
displayStartup();
break;
case 1:
drawTexturedModalRect(guiLeft + 80, guiTop + 32, 210, 38, 16, 16); //green button
drawPowerMeterDisplay((int) (20 * turbinegas.instantPowerOutput));
break;
default:
break;
}
drawTexturedModalRect(guiLeft + 36, guiTop + 97 - turbinegas.powerSliderPos, 178, 0, 16, 6); //power slider
int power = (int) (turbinegas.power * 142 / turbinegas.maxPower); //power storage
drawTexturedModalRect(guiLeft + 26, guiTop + 109, 0, 223, power, 16);
drawRPMGauge(turbinegas.rpm);
drawThermometer(turbinegas.temp);
this.drawInfoPanel(guiLeft - 16, guiTop + 34, 16, 16, 3); //info
this.drawInfoPanel(guiLeft - 16, guiTop + 34 + 16, 16, 16, 2); //fuels
if((turbinegas.tanks[0].getFill()) < 5000 || turbinegas.tanks[1].getFill() < 1000)
this.drawInfoPanel(guiLeft - 16, guiTop + 34 + 32, 16, 16, 7);
if(turbinegas.tanks[0].getFill() == 0 || turbinegas.tanks[1].getFill() == 0)
this.drawInfoPanel(guiLeft - 16, guiTop + 34 + 32, 16, 16, 6);
turbinegas.tanks[0].renderTank(guiLeft + 8, guiTop + 65, this.zLevel, 16, 48);
turbinegas.tanks[1].renderTank(guiLeft + 8, guiTop + 103, this.zLevel, 16, 32);
turbinegas.tanks[2].renderTank(guiLeft + 147, guiTop + 98, this.zLevel, 16, 36);
turbinegas.tanks[3].renderTank(guiLeft + 147, guiTop + 58, this.zLevel, 16, 36);
}
int numberToDisplay = 0; //for startup
int digitNumber = 0;
int exponent = 0;
public void displayStartup() {
boolean displayOn = true;
if(numberToDisplay < 888888 && turbinegas.counter < 60) { //48 frames needed to complete
digitNumber++;
if(digitNumber == 9) {
digitNumber = 1;
exponent++;
}
numberToDisplay += Math.pow(10, exponent);
}
if(turbinegas.counter > 50)
numberToDisplay = 0;
drawPowerMeterDisplay(numberToDisplay);
}
protected void drawPowerMeterDisplay(int number) { //display code
int firstDigitX = 66;
int firstDigitY = 62;
int width = 5;
int height = 11;
int spaceBetweenBumbers = 3;
int[] digit = new int[6];
for(int i = 5; i >= 0; i--) { //creates an array of digits that represent the numbers
digit[i] = (int) (number % 10);
number = number / 10;
drawTexturedModalRect(guiLeft + firstDigitX + i * 8, guiTop + 9 + firstDigitY, 194 + digit[i] * 5, 0, 5, 11);
}
int uselessZeros = 0;
for(int i = 0; i < 5; i++) { //counts how much zeros there are before the number, to display 57 instead of 000057
if(digit[i] == 0)
uselessZeros++;
else
break;
}
for(int i = 0; i < uselessZeros; i++) { //turns off the useless zeros
drawTexturedModalRect(guiLeft + firstDigitX + i * 8, guiTop + 9 + firstDigitY, 244, 0, 5, 11);
}
}
protected void drawThermometer(int temp) {
int xPos = guiLeft + 136;
int yPos = guiTop + 28;
int width = 2;
int height = 64;
int maxTemp = 800;
double uMin = (176D / 256D);
double uMax = (178D / 256D);
double vMin = ((64D - 64 * temp / maxTemp) / 256D);
double vMax = (64D / 256D);
GL11.glEnable(GL11.GL_BLEND);
Minecraft.getMinecraft().getTextureManager().bindTexture(texture);
Tessellator tessellator = Tessellator.instance;
tessellator.startDrawingQuads();
tessellator.addVertexWithUV(xPos, yPos + height, this.zLevel, uMin, vMax);
tessellator.addVertexWithUV(xPos + width, yPos + height, this.zLevel, uMax, vMax);
tessellator.addVertexWithUV(xPos + width, yPos + 64 - (64 * temp / maxTemp), this.zLevel,uMax, vMin);
tessellator.addVertexWithUV(xPos, yPos + 64 - (64 * temp / maxTemp), this.zLevel, uMin, vMin);
tessellator.draw();
GL11.glDisable(GL11.GL_BLEND);
}
protected void drawRPMGauge(int position) {
int xPos = guiLeft + 64;
int yPos = guiTop + 16;
int squareSideLenght = 48;
double uMin = (48D / 4848D) * position;
double uMax = (48D / 4848D) * (position + 1);
double vMin = 0D;
double vMax = 1D;
GL11.glEnable(GL11.GL_BLEND);
Minecraft.getMinecraft().getTextureManager().bindTexture(gauge_tex); //long boi
Tessellator tessellator = Tessellator.instance;
tessellator.startDrawingQuads();
tessellator.addVertexWithUV(xPos, yPos + squareSideLenght, this.zLevel, uMin, vMax);
tessellator.addVertexWithUV(xPos + squareSideLenght, yPos + squareSideLenght, this.zLevel, uMax, vMax);
tessellator.addVertexWithUV(xPos + squareSideLenght, yPos, this.zLevel,uMax, vMin);
tessellator.addVertexWithUV(xPos, yPos, this.zLevel, uMin, vMin);
tessellator.draw();
GL11.glDisable(GL11.GL_BLEND);
}
@Override
protected void drawGuiContainerForegroundLayer(int i, int j) {
//useless piece of shit, at least for now
String name = this.turbinegas.hasCustomInventoryName() ? this.turbinegas.getInventoryName() : I18n.format(this.turbinegas.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 - 94, 4210752);
}
}

View File

@ -84,10 +84,11 @@ public class ResourceManager {
public static final IModelCustom orbus = new HFRWavefrontObject(new ResourceLocation(RefStrings.MODID, "models/machines/orbus.obj"));
//Turbofan
public static final IModelCustom turbofan_body = AdvancedModelLoader.loadModel(new ResourceLocation(RefStrings.MODID, "models/turbofan_body.obj"));
public static final IModelCustom turbofan_blades = AdvancedModelLoader.loadModel(new ResourceLocation(RefStrings.MODID, "models/turbofan_blades.obj"));
public static final IModelCustom turbofan = new HFRWavefrontObject(new ResourceLocation(RefStrings.MODID, "models/machines/turbofan.obj"));
//Gas Turbine
public static final IModelCustom turbinegas = new HFRWavefrontObject(new ResourceLocation(RefStrings.MODID, "models/machines/turbinegas.obj"));
//Large Turbine
public static final IModelCustom steam_engine = new HFRWavefrontObject(new ResourceLocation(RefStrings.MODID, "models/machines/steam_engine.obj")).asDisplayList();
public static final IModelCustom turbine = new HFRWavefrontObject(new ResourceLocation(RefStrings.MODID, "models/machines/turbine.obj"));
@ -402,6 +403,9 @@ public class ResourceManager {
public static final ResourceLocation turbofan_tex = new ResourceLocation(RefStrings.MODID, "textures/models/machines/turbofan.png");
public static final ResourceLocation turbofan_back_tex = new ResourceLocation(RefStrings.MODID, "textures/models/machines/turbofan_back.png");
public static final ResourceLocation turbofan_afterburner_tex = new ResourceLocation(RefStrings.MODID, "textures/models/machines/turbofan_afterburner.png");
//Gas Turbine
public static final ResourceLocation turbinegas_tex = new ResourceLocation(RefStrings.MODID, "textures/models/machines/turbinegas.png");
//Large Turbine
public static final ResourceLocation steam_engine_tex = new ResourceLocation(RefStrings.MODID, "textures/models/machines/steam_engine.png");

View File

@ -0,0 +1,38 @@
package com.hbm.render.tileentity;
import org.lwjgl.opengl.GL11;
import com.hbm.blocks.BlockDummyable;
import com.hbm.main.ResourceManager;
import com.hbm.tileentity.machine.TileEntityMachineTurbineGas;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
public class RenderTurbineGas extends TileEntitySpecialRenderer {
@Override
public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float f) {
GL11.glPushMatrix();
GL11.glTranslated(x + 0.5D, y, z + 0.5D);
TileEntityMachineTurbineGas turbinegas = (TileEntityMachineTurbineGas) tileEntity;
switch(turbinegas.getBlockMetadata() - BlockDummyable.offset) {
case 2: GL11.glRotatef(90, 0F, 1F, 0F); break;
case 4: GL11.glRotatef(180, 0F, 1F, 0F); break;
case 3: GL11.glRotatef(270, 0F, 1F, 0F); break;
case 5: GL11.glRotatef(0, 0F, 1F, 0F); break;
}
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_CULL_FACE);
GL11.glShadeModel(GL11.GL_SMOOTH);
bindTexture(ResourceManager.turbinegas_tex);
ResourceManager.turbinegas.renderAll();
GL11.glShadeModel(GL11.GL_FLAT);
GL11.glPopMatrix();
}
}

View File

@ -91,6 +91,7 @@ public class TileMappings {
put(TileEntityFluidDuct.class, "tileentity_universal_duct");
put(TileEntityMachineFluidTank.class, "tileentity_fluid_tank");
put(TileEntityMachineTurbofan.class, "tileentity_machine_turbofan");
put(TileEntityMachineTurbineGas.class, "tileentity_machine_gasturbine");
put(TileEntityCrateIron.class, "tileentity_crate_iron");
put(TileEntityCrateSteel.class, "tileentity_crate_steel");
put(TileEntityCrateDesh.class, "tileentity_crate_desh");

View File

@ -0,0 +1,527 @@
package com.hbm.tileentity.machine;
import java.util.HashMap;
import com.hbm.blocks.BlockDummyable;
import com.hbm.interfaces.IControlReceiver;
import com.hbm.inventory.fluid.tank.FluidTank;
import com.hbm.inventory.fluid.trait.FT_Combustible;
import com.hbm.inventory.fluid.trait.FT_Flammable;
import com.hbm.inventory.fluid.FluidType;
import com.hbm.inventory.fluid.Fluids;
import com.hbm.items.machine.IItemFluidIdentifier;
import com.hbm.lib.Library;
import com.hbm.main.MainRegistry;
import com.hbm.sound.AudioWrapper;
import com.hbm.tileentity.TileEntityMachineBase;
import api.hbm.energy.IEnergyGenerator;
import api.hbm.fluid.IFluidStandardTransceiver;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.Vec3;
import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityMachineTurbineGas extends TileEntityMachineBase implements IFluidStandardTransceiver, IEnergyGenerator, IControlReceiver{
public long power;
public static final long maxPower = 1000000L;
public int rpm; //0-100
public int temp; //0-800
public int rpmIdle = 10;
public int tempIdle = 300;
public int powerSliderPos; //goes from 0 to 60, 0 is idle, 60 is max power
public int throttle; //the same thing, but goes from0 to 100
public boolean autoMode;
public int state = 0; //0 is offline, -1 is startup, 1 is online
public int counter = 0; //used to startup and shutdown
public int instantPowerOutput;
public FluidTank[] tanks;
private AudioWrapper audio;
public static HashMap<FluidType, Double> fuelMaxCons = new HashMap(); //fuel consumption per tick at max power
static {
fuelMaxCons.put(Fluids.GAS, 50D);
fuelMaxCons.put(Fluids.PETROLEUM, 5D);
fuelMaxCons.put(Fluids.LPG, 5D);
//fuelMaxCons.put(Fluids.BIOGAS, 1D); currently useless
}
public static HashMap<FluidType, Integer> fuelMaxTemp = new HashMap(); //power production at maxT is half the normal production multiplied by (maxtemp - 300) / 500
static {
fuelMaxTemp.put(Fluids.GAS, 600);
fuelMaxTemp.put(Fluids.PETROLEUM, 800);
fuelMaxTemp.put(Fluids.LPG, 400);
//fuelMaxTemp.put(Fluids.BIOGAS, 500);
}
//TODO particles from heat exchanger maybe? maybe in a future
public TileEntityMachineTurbineGas() {
super(2);
this.tanks = new FluidTank[4];
tanks[0] = new FluidTank(Fluids.GAS, 100000);
tanks[1] = new FluidTank(Fluids.LUBRICANT, 16000);
tanks[2] = new FluidTank(Fluids.WATER, 16000);
tanks[3] = new FluidTank(Fluids.HOTSTEAM, 160000);
}
@Override
public void updateEntity() {
if(!worldObj.isRemote) {
throttle = powerSliderPos * 100 / 60;
if(slots[1] != null && slots[1].getItem() instanceof IItemFluidIdentifier) {
FluidType fluid = ((IItemFluidIdentifier) slots[1].getItem()).getType(worldObj, xCoord, yCoord, zCoord, slots[1]);
if(fuelMaxTemp.get(fluid) != null)
tanks[0].setTankType(fluid);
}
switch(state) { //what to do when turbine offline, starting up and online
case 0:
shutdown();
break;
case -1:
isReady();
startup();
break;
case 1:
isReady();
run();
break;
default:
break;
}
if(autoMode) { //power production depending on power requirement
int powerSliderTarget = 60 - (int) (60 * power / maxPower);
if(powerSliderTarget > powerSliderPos) { //makes the auto slider slide instead of snapping into position
powerSliderPos++;
}
else if(powerSliderTarget < powerSliderPos) {
powerSliderPos--;
}
}
if(this.power > this.maxPower)
this.power = this.maxPower;
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset);
ForgeDirection rot = dir.getRotation(ForgeDirection.UP);
this.sendPower(worldObj, xCoord - dir.offsetZ * 5, yCoord + 1, zCoord + dir.offsetX * 5, dir); //sends out power
for(int i = 0; i < 2; i++) { //fuel and lube
this.trySubscribe(tanks[i].getTankType(), worldObj, xCoord - dir.offsetX * 2 - dir.offsetZ * 1, yCoord, zCoord + dir.offsetX * 1 - dir.offsetZ * 2, dir);
this.trySubscribe(tanks[i].getTankType(), worldObj, xCoord + dir.offsetX * 2 - dir.offsetZ * 1, yCoord, zCoord + dir.offsetX * 1 + dir.offsetZ * 2, dir);
}
//water
this.trySubscribe(tanks[2].getTankType(), worldObj, xCoord - dir.offsetX * 2 + dir.offsetZ * 4, yCoord, zCoord - dir.offsetX * 4 - dir.offsetZ * 2, dir);
this.trySubscribe(tanks[2].getTankType(), worldObj, xCoord + dir.offsetX * 2 + dir.offsetZ * 4, yCoord, zCoord - dir.offsetX * 4 + dir.offsetZ * 2, dir);
//steam
this.sendFluid(tanks[3].getTankType(), worldObj, xCoord + dir.offsetZ * 6, yCoord + 1, zCoord - dir.offsetX * 6, dir);
if(audio != null)
audio.updatePitch((float) (0.45 + 0.05 * rpm / 10));
power = Library.chargeItemsFromTE(slots, 0, power, maxPower);
NBTTagCompound data = new NBTTagCompound();
data.setLong("power", this.power);
data.setInteger("rpm", this.rpm);
data.setInteger("temp", this.temp);
data.setInteger("state", this.state);
data.setBoolean("automode", this.autoMode);
data.setInteger("throttle", this.throttle);
data.setInteger("slidpos", this.powerSliderPos);
if(state != 1)
data.setInteger("counter", this.counter); //sent during startup and shutdown
else
data.setInteger("instantPow", this.instantPowerOutput); //sent while running
tanks[0].writeToNBT(data, "fuel");
tanks[1].writeToNBT(data, "lube");
tanks[2].writeToNBT(data, "water");
tanks[3].writeToNBT(data, "steam");
this.networkPack(data, 150);
} else { //client side, for sounds n shit
if(rpm >= 10 && state != -1) { //if conditions are right, play thy sound
if(audio == null) { //if there is no sound playing, start it
audio = MainRegistry.proxy.getLoopedSound("hbm:block.turbinegasRunning", xCoord, yCoord, zCoord, 1.0F, 1.0F);
audio.startSound();
} else if(!audio.isPlaying()) {
audio.stopSound();
audio = MainRegistry.proxy.getLoopedSound("hbm:block.turbinegasRunning", xCoord, yCoord, zCoord, 1.0F, 1.0F);
audio.startSound();
}
audio.updatePitch((float) (0.55 + 0.1 * rpm / 10)); //dynamic pitch update based on rpm
audio.updateVolume(100F); //yeah i need this
} else {
if(audio != null) {
audio.stopSound();
audio = null;
}
}
}
}
private void isReady() { //checks if the turbine can make power, if not shutdown TODO make this a bool maybe?
if(tanks[0].getFill() == 0 || tanks[1].getFill() == 0) {
state = 0;
}
if (!hasAcceptableFuel())
state = 0;
}
public boolean hasAcceptableFuel() { //TODO useless check?
if (fuelMaxTemp.get(tanks[0].getTankType()) != null)
return true;
return false;
}
private void startup() {
counter++;
if(counter <= 20) //rpm gauge 0-100-0
rpm = 5 * counter;
else if (counter > 20 && counter <= 40)
rpm = 100 - 5 * (counter - 20);
else if (counter > 50 ) {
rpm = (int) (rpmIdle * (counter - 50) / 530); //slowly ramps up temp and RPM
temp = (int) (tempIdle * (counter - 50) / 530);
}
if(counter == 50) {
worldObj.playSoundEffect(xCoord, yCoord + 2, zCoord, "hbm:block.turbinegasStartup", 1F, 1.0F);
}
if(counter == 580) {
state = 1;
}
}
int rpmLast; //used to progressively slow down and cool the turbine without immediatly setting rpm and temp to 0
int tempLast;
private void shutdown() {
autoMode = false;
instantPowerOutput = 0;
if(powerSliderPos > 0)
powerSliderPos--;
if(rpm <= 10 && counter > 0) {
if(counter == 225) {
worldObj.playSoundEffect(xCoord, yCoord + 2, zCoord, "hbm:block.turbinegasShutdown", 1F, 1.0F);
rpmLast = rpm;
tempLast = temp;
}
counter--;
rpm = (int) (rpmLast * (counter) / 225);
temp = (int) (tempLast * (counter) / 225);
}
else if(rpm > 11) { //quickly slows down the turbine to idle before shutdown
counter = 42069; //absolutely necessary to avoid fuckeries on shutdown
rpm--;
return;
}
else if(rpm == 11) {
counter = 225;
rpm--;
}
}
private void run() {
if((int) (throttle * 0.9) > rpm - rpmIdle) { //simulates the rotor's moment of inertia
if(worldObj.getTotalWorldTime() % 5 == 0) {
rpm++;
}
} else if((int) (throttle * 0.9) < rpm - rpmIdle) {
if(worldObj.getTotalWorldTime() % 2 == 0) {
rpm--;
}
}
if(throttle * 5 * (fuelMaxTemp.get(tanks[0].getTankType()) - tempIdle) / 500 > temp - tempIdle) { //simulates the heat exchanger's resistance to temperature variation
if(worldObj.getTotalWorldTime() % 2 == 0) {
temp++;
}
} else if(throttle * 5 * (fuelMaxTemp.get(tanks[0].getTankType()) - tempIdle) / 500 < temp - tempIdle) {
if(worldObj.getTotalWorldTime() % 2 == 0) {
temp--;
}
}
makePower(fuelMaxCons.get(tanks[0].getTankType()), throttle);
}
double fuelToConsume; //used to consume 1 mb of fuel at a time when consumption is <1 mb/tick
double waterToBoil;
double waterPerTick = 0;
private void makePower(double consMax, int throttle) {
double idleConsumption = consMax * 0.05D;
double consumption = idleConsumption + consMax * throttle / 100;
fuelToConsume += consumption;
tanks[0].setFill(tanks[0].getFill() - (int) Math.floor(fuelToConsume));
fuelToConsume -= (int) Math.floor(fuelToConsume);
if(worldObj.getTotalWorldTime() % 10 == 0) //lube consumption
tanks[1].setFill(tanks[1].getFill() - 1);
if(tanks[0].getFill() < 0) { //avoids negative amounts of fluid
tanks[0].setFill(0);
state = 0;
}
if(tanks[1].getFill() < 0) {
tanks[1].setFill(0);
state = 0;
}
long energy; //energy per mb of fuel
if(tanks[0].getTankType().hasTrait(FT_Combustible.class)) {
FT_Combustible a = tanks[0].getTankType().getTrait(FT_Combustible.class);
energy = a.getCombustionEnergy() / 1000;
}
else {
FT_Flammable b = tanks[0].getTankType().getTrait(FT_Flammable.class);
energy = b.getHeatEnergy() / 1000;
}
//consMax*energy is equivalent to power production at 100%
if(instantPowerOutput < (consMax * energy * (rpm - rpmIdle) / 90)) { //this shit avoids power rising in steps of 2000 or so HE at a time, instead it does it smoothly
instantPowerOutput += Math.random() * 0.005 * consMax * energy;
if(instantPowerOutput > (consMax * energy * (rpm - rpmIdle) / 90))
instantPowerOutput = (int) (consMax * energy * (rpm - rpmIdle) / 90);
}
else if(instantPowerOutput > (consMax * energy * (rpm - rpmIdle) / 90)) {
instantPowerOutput -= Math.random() * 0.011 * consMax * energy;
if(instantPowerOutput < (consMax * energy * (rpm - rpmIdle) / 90))
instantPowerOutput = (int) (consMax * energy * (rpm - rpmIdle) / 90);
}
this.power += instantPowerOutput;
waterPerTick = (consMax * energy * (temp - tempIdle) / 220000); //it just works fuck you
if(tanks[2].getFill() >= Math.ceil(waterPerTick)) { //checks if there's enough water to boil
waterToBoil += waterPerTick;
if(tanks[3].getFill() <= 160000 - waterToBoil * 10) { //checks if there's room for steam in the tank
tanks[2].setFill(tanks[2].getFill() - (int) Math.floor(waterToBoil));
tanks[3].setFill(tanks[3].getFill() + 10 * (int) Math.floor(waterToBoil));
waterToBoil -= (int) Math.floor(waterToBoil);
}
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@Override
public void networkUnpack(NBTTagCompound nbt) {
this.power = nbt.getLong("power");
this.rpm = nbt.getInteger("rpm");
this.temp = nbt.getInteger("temp");
this.state = nbt.getInteger("state");
this.autoMode = nbt.getBoolean("automode");
this.powerSliderPos = nbt.getInteger("slidpos");
this.throttle = nbt.getInteger("throttle");
if(nbt.hasKey("counter"))
this.counter = nbt.getInteger("counter"); //state 0 and -1
else
this.instantPowerOutput = nbt.getInteger("instantPow"); //state 1
this.tanks[0].readFromNBT(nbt, "fuel");
this.tanks[1].readFromNBT(nbt, "lube");
this.tanks[2].readFromNBT(nbt, "water");
this.tanks[3].readFromNBT(nbt, "steam");
}
@Override
public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt);
this.tanks[0].readFromNBT(nbt, "gas");
this.tanks[1].readFromNBT(nbt, "lube");
this.tanks[2].readFromNBT(nbt, "water");
this.tanks[3].readFromNBT(nbt, "densesteam");
this.autoMode = nbt.getBoolean("automode");
this.power = nbt.getLong("power");
this.state = nbt.getInteger("state");
this.rpm = nbt.getInteger("rpm");
this.temp = nbt.getInteger("temperature");
this.powerSliderPos = nbt.getInteger("slidPos");
this.instantPowerOutput = nbt.getInteger("instPwr");
this.counter = nbt.getInteger("counter");
}
@Override
public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt);
tanks[0].writeToNBT(nbt, "gas");
tanks[1].writeToNBT(nbt, "lube");
tanks[2].writeToNBT(nbt, "water");
tanks[3].writeToNBT(nbt, "densesteam");
nbt.setBoolean("automode", autoMode);
nbt.setLong("power", power);
if(state == 1) {
nbt.setInteger("state", this.state);
nbt.setInteger("rpm", this.rpm);
nbt.setInteger("temperature", this.temp);
nbt.setInteger("slidPos", this.powerSliderPos);
nbt.setInteger("instPwr", instantPowerOutput);
nbt.setInteger("counter", 225);
} else {
nbt.setInteger("state", 0);
nbt.setInteger("rpm", 0);
nbt.setInteger("temperature", 20);
nbt.setInteger("slidPos", 0);
nbt.setInteger("instpwr", 0);
nbt.setInteger("counter", 0);
}
}
@Override
public void receiveControl(NBTTagCompound data) {
if(data.hasKey("slidPos"))
powerSliderPos = data.getInteger("slidPos");
if(data.hasKey("autoMode"))
autoMode = data.getBoolean("autoMode");
if(data.hasKey("state"))
state = data.getInteger("state");
this.markDirty();
}
@Override
public boolean hasPermission(EntityPlayer player) {
return Vec3.createVectorHelper(xCoord - player.posX, yCoord - player.posY, zCoord - player.posZ).lengthVector() < 20;
}
@Override
public void onChunkUnload() {
if(audio != null) {
audio.stopSound();
audio = null;
}
}
@Override
public void invalidate() {
super.invalidate();
if(audio != null) {
audio.stopSound();
audio = null;
}
}
@Override
public void setPower(long power) {
this.power = power;
}
@Override
public long getPower() {
return this.power;
}
@Override
public long getMaxPower() {
return this.maxPower;
}
AxisAlignedBB bb = null;
@Override
public AxisAlignedBB getRenderBoundingBox() {
return TileEntity.INFINITE_EXTENT_AABB;
}
@Override
@SideOnly(Side.CLIENT)
public double getMaxRenderDistanceSquared() {
return 65536.0D;
}
@Override
public String getName() {
return "container.turbinegas";
}
@Override
public FluidTank[] getAllTanks() {
return tanks;
}
@Override
public FluidTank[] getReceivingTanks() {
return new FluidTank[] { tanks[0], tanks[1], tanks[2] };
}
@Override
public FluidTank[] getSendingTanks() {
return new FluidTank[] { tanks[3] };
}
@Override
public boolean canConnect(ForgeDirection dir) {
return dir != ForgeDirection.DOWN;
}
@Override
public boolean canConnect(FluidType type, ForgeDirection dir) {
return dir != ForgeDirection.DOWN;
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB