Most of the work done on dieselgenerator

This commit is contained in:
Gig 2015-05-08 23:02:35 +01:00
parent ed99503fb2
commit b9d6b356c2
6 changed files with 396 additions and 0 deletions

View file

@ -18,7 +18,9 @@ import techreborn.client.GuiHandler;
import techreborn.client.TechRebornCreativeTab;
import techreborn.tiles.TileAlloySmelter;
import techreborn.tiles.TileBlastFurnace;
import techreborn.tiles.TileDieselGenerator;
import techreborn.tiles.TileMachineCasing;
import techreborn.tiles.TileThermalGenerator;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@ -49,6 +51,22 @@ public class BlockDieselGenerator extends BlockMachineBase {
this.iconBottom = icon.registerIcon("techreborn:machine/machine_bottom");
}
@Override
public TileEntity createNewTileEntity(World world, int p_149915_2_)
{
return new TileDieselGenerator();
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z,
EntityPlayer player, int side, float hitX, float hitY, float hitZ)
{
if (!player.isSneaking())
player.openGui(Core.INSTANCE, GuiHandler.dieselGeneratorID, world, x, y,
z);
return true;
}
@SideOnly(Side.CLIENT)
public IIcon getIcon(int side, int metadata)
{

View file

@ -7,6 +7,7 @@ import techreborn.client.container.ContainerAssemblingMachine;
import techreborn.client.container.ContainerBlastFurnace;
import techreborn.client.container.ContainerCentrifuge;
import techreborn.client.container.ContainerChunkloader;
import techreborn.client.container.ContainerDieselGenerator;
import techreborn.client.container.ContainerGrinder;
import techreborn.client.container.ContainerImplosionCompressor;
import techreborn.client.container.ContainerLathe;
@ -21,6 +22,7 @@ import techreborn.client.gui.GuiAssemblingMachine;
import techreborn.client.gui.GuiBlastFurnace;
import techreborn.client.gui.GuiCentrifuge;
import techreborn.client.gui.GuiChunkLoader;
import techreborn.client.gui.GuiDieselGenerator;
import techreborn.client.gui.GuiGrinder;
import techreborn.client.gui.GuiImplosionCompressor;
import techreborn.client.gui.GuiLathe;
@ -36,6 +38,7 @@ import techreborn.tiles.TileAssemblingMachine;
import techreborn.tiles.TileBlastFurnace;
import techreborn.tiles.TileCentrifuge;
import techreborn.tiles.TileChunkLoader;
import techreborn.tiles.TileDieselGenerator;
import techreborn.tiles.TileGrinder;
import techreborn.tiles.TileImplosionCompressor;
import techreborn.tiles.TileLathe;
@ -64,6 +67,7 @@ public class GuiHandler implements IGuiHandler {
public static final int assemblingmachineID = 12;
public static final int latheID = 13;
public static final int platecuttingmachineID = 14;
public static final int dieselGeneratorID = 15;
@ -127,6 +131,10 @@ public class GuiHandler implements IGuiHandler {
{
return new ContainerPlateCuttingMachine(
(TilePlateCuttingMachine) world.getTileEntity(x, y, z), player);
} else if (ID == dieselGeneratorID)
{
return new ContainerDieselGenerator(
(TileDieselGenerator) world.getTileEntity(x, y, z), player);
} else if (ID == pdaID)
{
return null;
@ -195,6 +203,10 @@ public class GuiHandler implements IGuiHandler {
{
return new GuiPlateCuttingMachine(player,
(TilePlateCuttingMachine) world.getTileEntity(x, y, z));
} else if (ID == dieselGeneratorID)
{
return new GuiDieselGenerator(player,
(TileDieselGenerator) world.getTileEntity(x, y, z));
} else if (ID == pdaID)
{
return new GuiPda(player);

View file

@ -0,0 +1,51 @@
package techreborn.client.container;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Slot;
import techreborn.client.SlotFake;
import techreborn.client.SlotOutput;
import techreborn.tiles.TileDieselGenerator;
import techreborn.tiles.TileThermalGenerator;
public class ContainerDieselGenerator extends TechRebornContainer {
public TileDieselGenerator tiledieselGenerator;
public EntityPlayer player;
public ContainerDieselGenerator(TileDieselGenerator tiledieselGenerator,
EntityPlayer player)
{
super();
this.tiledieselGenerator = tiledieselGenerator;
this.player = player;
this.addSlotToContainer(new Slot(tiledieselGenerator.inventory, 0, 80,
17));
this.addSlotToContainer(new SlotOutput(tiledieselGenerator.inventory,
1, 80, 53));
this.addSlotToContainer(new SlotFake(tiledieselGenerator.inventory, 2,
59, 42, false, false, 1));
int i;
for (i = 0; i < 3; ++i)
{
for (int j = 0; j < 9; ++j)
{
this.addSlotToContainer(new Slot(player.inventory, j + i * 9
+ 9, 8 + j * 18, 84 + i * 18));
}
}
for (i = 0; i < 9; ++i)
{
this.addSlotToContainer(new Slot(player.inventory, i, 8 + i * 18,
142));
}
}
@Override
public boolean canInteractWith(EntityPlayer player)
{
return true;
}
}

View file

@ -0,0 +1,49 @@
package techreborn.client.gui;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import techreborn.client.container.ContainerDieselGenerator;
import techreborn.client.container.ContainerThermalGenerator;
import techreborn.tiles.TileDieselGenerator;
import techreborn.tiles.TileThermalGenerator;
public class GuiDieselGenerator extends GuiContainer {
private static final ResourceLocation texture = new ResourceLocation(
"techreborn", "textures/gui/ThermalGenerator.png");
TileDieselGenerator tile;
public GuiDieselGenerator(EntityPlayer player, TileDieselGenerator tile)
{
super(new ContainerDieselGenerator(tile, player));
this.xSize = 176;
this.ySize = 167;
this.tile = tile;
}
@Override
protected void drawGuiContainerBackgroundLayer(float p_146976_1_,
int p_146976_2_, int p_146976_3_)
{
this.mc.getTextureManager().bindTexture(texture);
int k = (this.width - this.xSize) / 2;
int l = (this.height - this.ySize) / 2;
this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);
}
protected void drawGuiContainerForegroundLayer(int p_146979_1_,
int p_146979_2_)
{
this.fontRendererObj.drawString(StatCollector.translateToLocal("tile.techreborn.dieselgenerator.name"), 8, 6, 4210752);
this.fontRendererObj.drawString(
I18n.format("container.inventory", new Object[0]), 8,
this.ySize - 96 + 2, 4210752);
this.fontRendererObj.drawString("Liquid Amount", 10, 20, 16448255);
this.fontRendererObj.drawString(tile.tank.getFluidAmount() + "", 10,
30, 16448255);
}
}

View file

@ -56,6 +56,7 @@ import techreborn.tiles.TileAssemblingMachine;
import techreborn.tiles.TileBlastFurnace;
import techreborn.tiles.TileCentrifuge;
import techreborn.tiles.TileChunkLoader;
import techreborn.tiles.TileDieselGenerator;
import techreborn.tiles.TileDragonEggSiphoner;
import techreborn.tiles.TileGrinder;
import techreborn.tiles.TileImplosionCompressor;
@ -187,6 +188,7 @@ public class ModBlocks {
DieselGenerator = new BlockDieselGenerator(Material.rock);
GameRegistry.registerBlock(DieselGenerator, "dieselgenerator");
GameRegistry.registerTileEntity(TileDieselGenerator.class, "TileDieselGenerator");
IndustrialElectrolyzer = new BlockIndustrialElectrolyzer(Material.rock);
GameRegistry.registerBlock(IndustrialElectrolyzer, "industrialelectrolyzer");

View file

@ -0,0 +1,264 @@
package techreborn.tiles;
import ic2.api.energy.prefab.BasicSource;
import ic2.api.energy.tile.IEnergyTile;
import ic2.api.tile.IWrenchable;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler;
import techreborn.config.ConfigTechReborn;
import techreborn.init.ModBlocks;
import techreborn.util.FluidUtils;
import techreborn.util.Inventory;
import techreborn.util.Tank;
public class TileDieselGenerator extends TileEntity implements IWrenchable,
IFluidHandler, IInventory, IEnergyTile {
public Tank tank = new Tank("TileDieselGenerator",
FluidContainerRegistry.BUCKET_VOLUME * 10, this);
public Inventory inventory = new Inventory(3, "TileDieselGenerator", 64);
public BasicSource energySource;
public static final int euTick = ConfigTechReborn.ThermalGenertaorOutput;
public TileDieselGenerator()
{
this.energySource = new BasicSource(this,
ConfigTechReborn.ThermalGeneratorCharge,
ConfigTechReborn.ThermalGeneratorTier);
}
@Override
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, int side)
{
return false;
}
@Override
public short getFacing()
{
return 0;
}
@Override
public void setFacing(short facing)
{
}
@Override
public boolean wrenchCanRemove(EntityPlayer entityPlayer)
{
return true;
}
@Override
public float getWrenchDropRate()
{
return 1.0F;
}
@Override
public ItemStack getWrenchDrop(EntityPlayer entityPlayer)
{
return new ItemStack(ModBlocks.DieselGenerator, 1);
}
@Override
public int fill(ForgeDirection from, FluidStack resource, boolean doFill)
{
return tank.fill(resource, doFill);
}
@Override
public FluidStack drain(ForgeDirection from, FluidStack resource,
boolean doDrain)
{
return tank.drain(resource.amount, doDrain);
}
@Override
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain)
{
return tank.drain(maxDrain, doDrain);
}
@Override
public boolean canFill(ForgeDirection from, Fluid fluid)
{
if (fluid != null)
{
if (FluidRegistry.getFluidName(fluid.getID()).contentEquals("lava"))
{
return true;
}
}
return false;
}
@Override
public boolean canDrain(ForgeDirection from, Fluid fluid)
{
return tank.getFluid() == null || tank.getFluid().getFluid() == fluid;
}
@Override
public FluidTankInfo[] getTankInfo(ForgeDirection from)
{
return getTankInfo(from);
}
@Override
public void readFromNBT(NBTTagCompound tagCompound)
{
super.readFromNBT(tagCompound);
tank.readFromNBT(tagCompound);
inventory.readFromNBT(tagCompound);
energySource.readFromNBT(tagCompound);
}
@Override
public void writeToNBT(NBTTagCompound tagCompound)
{
super.writeToNBT(tagCompound);
tank.writeToNBT(tagCompound);
inventory.writeToNBT(tagCompound);
energySource.writeToNBT(tagCompound);
}
public Packet getDescriptionPacket()
{
NBTTagCompound nbtTag = new NBTTagCompound();
writeToNBT(nbtTag);
return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord,
this.zCoord, 1, nbtTag);
}
@Override
public void onDataPacket(NetworkManager net,
S35PacketUpdateTileEntity packet)
{
worldObj.markBlockRangeForRenderUpdate(xCoord, yCoord, zCoord, xCoord,
yCoord, zCoord);
readFromNBT(packet.func_148857_g());
}
@Override
public void updateEntity()
{
super.updateEntity();
FluidUtils.drainContainers(this, inventory, 0, 1);
energySource.updateEntity();
if (tank.getFluidAmount() > 0
&& energySource.getCapacity() - energySource.getEnergyStored() >= euTick)
{
tank.drain(1, true);
energySource.addEnergy(euTick);
}
if (tank.getFluidType() != null && getStackInSlot(2) == null)
{
inventory.setInventorySlotContents(2, new ItemStack(tank
.getFluidType().getBlock()));
} else if (tank.getFluidType() == null && getStackInSlot(2) != null)
{
setInventorySlotContents(2, null);
}
}
@Override
public int getSizeInventory()
{
return inventory.getSizeInventory();
}
@Override
public ItemStack getStackInSlot(int p_70301_1_)
{
return inventory.getStackInSlot(p_70301_1_);
}
@Override
public ItemStack decrStackSize(int p_70298_1_, int p_70298_2_)
{
return inventory.decrStackSize(p_70298_1_, p_70298_2_);
}
@Override
public ItemStack getStackInSlotOnClosing(int p_70304_1_)
{
return inventory.getStackInSlotOnClosing(p_70304_1_);
}
@Override
public void setInventorySlotContents(int p_70299_1_, ItemStack p_70299_2_)
{
inventory.setInventorySlotContents(p_70299_1_, p_70299_2_);
}
@Override
public String getInventoryName()
{
return inventory.getInventoryName();
}
@Override
public boolean hasCustomInventoryName()
{
return inventory.hasCustomInventoryName();
}
@Override
public int getInventoryStackLimit()
{
return inventory.getInventoryStackLimit();
}
@Override
public boolean isUseableByPlayer(EntityPlayer p_70300_1_)
{
return inventory.isUseableByPlayer(p_70300_1_);
}
@Override
public void openInventory()
{
inventory.openInventory();
}
@Override
public void closeInventory()
{
inventory.closeInventory();
}
@Override
public boolean isItemValidForSlot(int p_94041_1_, ItemStack p_94041_2_)
{
return inventory.isItemValidForSlot(p_94041_1_, p_94041_2_);
}
@Override
public void onChunkUnload()
{
energySource.onChunkUnload();
}
@Override
public void invalidate()
{
energySource.invalidate();
super.invalidate();
}
}