Coded the basics of the steam gen

Will get to the rest of this when i get up
This commit is contained in:
Robert 2013-11-26 07:48:00 -05:00
parent e04aa0b7aa
commit ef70331d5f
3 changed files with 109 additions and 105 deletions

View file

@ -11,11 +11,9 @@ import cpw.mods.fml.client.registry.RenderingRegistry;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import dark.core.client.gui.GuiCoalGenerator;
import dark.core.client.renders.BlockRenderingHandler;
import dark.core.client.renders.RenderTestCar;
import dark.core.common.CommonProxy;
import dark.core.common.machines.TileEntitySteamGen;
import dark.core.prefab.ModPrefab;
import dark.core.prefab.vehicles.EntityTestCar;
@ -54,10 +52,6 @@ public class ClientProxy extends CommonProxy
if (tileEntity != null)
{
if (tileEntity instanceof TileEntitySteamGen)
{
return new GuiCoalGenerator(player.inventory, ((TileEntitySteamGen) tileEntity));
}
}
return null;

View file

@ -1,72 +0,0 @@
package dark.core.client.gui;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import org.lwjgl.opengl.GL11;
import universalelectricity.core.electricity.ElectricityDisplay;
import universalelectricity.core.electricity.ElectricityDisplay.ElectricUnit;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import dark.core.common.DarkMain;
import dark.core.common.machines.ContainerCoalGenerator;
import dark.core.common.machines.TileEntitySteamGen;
@SideOnly(Side.CLIENT)
public class GuiCoalGenerator extends GuiContainer
{
private static final ResourceLocation coalGeneratorTexture = new ResourceLocation(DarkMain.getInstance().DOMAIN, DarkMain.GUI_DIRECTORY + "coal_generator.png");
private TileEntitySteamGen tileEntity;
private int containerWidth;
private int containerHeight;
public GuiCoalGenerator(InventoryPlayer par1InventoryPlayer, TileEntitySteamGen tileEntity)
{
super(new ContainerCoalGenerator(par1InventoryPlayer, tileEntity));
this.tileEntity = tileEntity;
}
/** Draw the foreground layer for the GuiContainer (everything in front of the items) */
@Override
protected void drawGuiContainerForegroundLayer(int par1, int par2)
{
this.fontRenderer.drawString(this.tileEntity.getInvName(), 55, 6, 4210752);
String displayText = "Generating";
this.fontRenderer.drawString(displayText, 122 - this.fontRenderer.getStringWidth(displayText) / 2, 33, 4210752);
if (this.tileEntity.generateWatts <= 0)
{
displayText = "Not Generating";
}
else if (this.tileEntity.generateWatts < TileEntitySteamGen.MIN_GENERATE_WATTS)
{
displayText = "Hull Heat: " + (int) (this.tileEntity.generateWatts / TileEntitySteamGen.MIN_GENERATE_WATTS * 100) + "%";
}
else
{
displayText = ElectricityDisplay.getDisplay(tileEntity.generateWatts * 20, ElectricUnit.WATT);
}
this.fontRenderer.drawString(displayText, 122 - this.fontRenderer.getStringWidth(displayText) / 2, 45, 4210752);
displayText = "Voltage: " + (int) (this.tileEntity.getVoltage() * 1000);
this.fontRenderer.drawString(displayText, 122 - this.fontRenderer.getStringWidth(displayText) / 2, 60, 4210752);
this.fontRenderer.drawString(StatCollector.translateToLocal("container.inventory"), 8, this.ySize - 96 + 2, 4210752);
}
/** Draw the background layer for the GuiContainer (everything behind the items) */
@Override
protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3)
{
this.mc.renderEngine.bindTexture(coalGeneratorTexture);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
containerWidth = (this.width - this.xSize) / 2;
containerHeight = (this.height - this.ySize) / 2;
this.drawTexturedModalRect(containerWidth, containerHeight, 0, 0, this.xSize, this.ySize);
}
}

View file

@ -1,46 +1,128 @@
package dark.core.common.machines;
import java.util.EnumSet;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntityFurnace;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.core.electricity.ElectricityPack;
import com.google.common.io.ByteArrayDataInput;
import cpw.mods.fml.common.network.PacketDispatcher;
import cpw.mods.fml.common.network.Player;
import cpw.mods.fml.common.registry.LanguageRegistry;
import dark.core.network.PacketHandler;
import dark.core.prefab.machine.TileEntityEnergyMachine;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTank;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler;
import dark.core.prefab.machine.TileEntityMachine;
/** Simple compact generator designed to only power a few machines at a time
/** Simple steam gen designed to burn items to create steam to power a steam device directly above it
*
* @author DarkGuardsman */
public class TileEntitySteamGen extends TileEntityMachine
public class TileEntitySteamGen extends TileEntityMachine implements IFluidHandler
{
/** Maximum amount of energy needed to generate electricity */
public static float MAX_GENERATE_WATTS = 0.5f;
/** Amount of heat the coal generator needs before generating electricity. */
public static final float MIN_GENERATE_WATTS = MAX_GENERATE_WATTS * 0.1f;
private static float BASE_ACCELERATION = 0.000001f;
private static float BASE_DECCELERATION = 0.008f;
/** The number of ticks that a fresh copy of the currently-burning item would keep the furnace
* burning for */
public int itemCookTime = 0;
protected final int HEAT_TIME = 100, WATER_CONSUME_TIME = 100, WATER_CONSUME_SUM = 10;
protected int heatTicks = 0, waterTicks = 0;
protected boolean steamMachineConnected = false, isHeated = false, creatingSteam = false;
protected FluidTank tank = new FluidTank(2 * FluidContainerRegistry.BUCKET_VOLUME);
@Override
public void updateEntity()
{
super.updateEntity();
TileEntity entity = this.worldObj.getBlockTileEntity(xCoord, yCoord + 1, zCoord);
if (itemCookTime > 0)
{
itemCookTime--;
}
else
{
heatTicks--;
}
if (entity instanceof TileEntitySteamPiston)
{
steamMachineConnected = true;
if (itemCookTime < 10)
{
//TODO consume an item to keep us running
}
if (itemCookTime > 0 && this.heatTicks < HEAT_TIME)
{
heatTicks++;
}
if (this.isFunctioning())
{
if (this.tank != null && this.tank.getFluid() != null && this.tank.getFluidAmount() > WATER_CONSUME_SUM && this.tank.getFluid().getFluid() == FluidRegistry.WATER)
{
waterTicks++;
if (waterTicks % WATER_CONSUME_TIME == 0)
{
this.tank.drain(10, true);
}
}
else
{
//TODO start heating up machine and blow it up if left without water for too long
}
}
}
else
{
steamMachineConnected = false;
}
}
public boolean isCreatingSteam()
{
return creatingSteam;
}
@Override
public boolean canFunction()
{
return super.canFunction() && itemCookTime > 0 && steamMachineConnected && isHeated;
}
@Override
public int fill(ForgeDirection from, FluidStack resource, boolean doFill)
{
if(resource != null && resource.getFluid().equals(FluidRegistry.WATER))
{
this.tank.fill(resource, doFill);
}
return 0;
}
@Override
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain)
{
return null;
}
@Override
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain)
{
return null;
}
@Override
public boolean canFill(ForgeDirection from, Fluid fluid)
{
return fluid != null && fluid.equals(FluidRegistry.WATER);
}
@Override
public boolean canDrain(ForgeDirection from, Fluid fluid)
{
return false;
}
@Override
public FluidTankInfo[] getTankInfo(ForgeDirection from)
{
return new FluidTankInfo[] { this.tank.getInfo() };
}
}