Added logic to Electric furnace

This commit is contained in:
gigabit101 2016-03-06 20:39:31 +00:00
parent d02424070d
commit 5f1d059058
2 changed files with 135 additions and 28 deletions

View file

@ -34,10 +34,10 @@ public class GuiElectricFurnace extends GuiContainer {
int j = 0;
// j = furnace.getProgressScaled(24);
// if (j > 0) {
// this.drawTexturedModalRect(k + 50, l + 36, 176, 14, j + 1, 16);
// }
j = furnace.gaugeProgressScaled(24);
if (j > 0) {
this.drawTexturedModalRect(k + 78, l + 34, 176, 14, j + 1, 16);
}
j = furnace.getEnergyScaled(12);
if (j > 0) {

View file

@ -1,33 +1,158 @@
package techreborn.tiles.teir1;
import ic2.api.tile.IWrenchable;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemHoe;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemSword;
import net.minecraft.item.ItemTool;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.IChatComponent;
import net.minecraftforge.fml.common.registry.GameRegistry;
import reborncore.common.blocks.BlockMachineBase;
import reborncore.common.powerSystem.TilePowerAcceptor;
import reborncore.common.util.Inventory;
import techreborn.init.ModBlocks;
public class TileElectricFurnace extends TilePowerAcceptor implements IWrenchable, IInventory, ISidedInventory{
public class TileElectricFurnace extends TilePowerAcceptor implements IWrenchable, IInventory, ISidedInventory {
public Inventory inventory = new Inventory(6, "TileElectricFurnace", 64, this);
int input1 = 0;
int output = 1;
public int capacity = 1000;
public int progress;
public int fuelScale = 100;
public int cost = 10;
public TileElectricFurnace() {
super(1);
}
@Override
public void updateEntity()
public int gaugeProgressScaled (int scale)
{
super.updateEntity();
if(!worldObj.isRemote)
return (progress * scale) / fuelScale;
}
@Override
public void updateEntity ()
{
boolean burning = isBurning();
boolean updateInventory = false;
if (getEnergy() <= cost && canSmelt())
{
if (getEnergy() > cost)
{
updateInventory = true;
}
}
if (isBurning() && canSmelt())
{
updateState();
progress++;
if (progress >= fuelScale)
{
progress = 0;
cookItems();
updateInventory = true;
}
}
else
{
progress = 0;
updateState();
}
if (burning != isBurning())
{
updateInventory = true;
}
if (updateInventory)
{
markDirty();
}
}
public void cookItems ()
{
if (this.canSmelt())
{
ItemStack itemstack = FurnaceRecipes.instance().getSmeltingResult(getStackInSlot(input1));
if (getStackInSlot(output) == null)
{
useEnergy(cost);
setInventorySlotContents(output, itemstack.copy());
}
else if (getStackInSlot(output).isItemEqual(itemstack))
{
useEnergy(cost);
getStackInSlot(output).stackSize += itemstack.stackSize;
}
if(getStackInSlot(input1).stackSize > 1)
{
useEnergy(cost);
this.decrStackSize(input1, 1);
}
else
{
useEnergy(cost);
setInventorySlotContents(input1, null);
}
}
}
public boolean canSmelt ()
{
if (getStackInSlot(input1) == null)
{
return false;
}
else
{
ItemStack itemstack = FurnaceRecipes.instance().getSmeltingResult(getStackInSlot(input1));
if (itemstack == null)
return false;
if (getStackInSlot(output) == null)
return true;
if (!getStackInSlot(output).isItemEqual(itemstack))
return false;
int result = getStackInSlot(output).stackSize + itemstack.stackSize;
return (result <= getInventoryStackLimit() && result <= itemstack.getMaxStackSize());
}
}
public boolean isBurning ()
{
return getEnergy() > cost;
}
public ItemStack getResultFor (ItemStack stack)
{
ItemStack result = FurnaceRecipes.instance().getSmeltingResult(stack);
if (result != null)
{
return result.copy();
}
return null;
}
public void updateState(){
IBlockState blockState = worldObj.getBlockState(pos);
if(blockState.getBlock() instanceof BlockMachineBase){
BlockMachineBase blockMachineBase = (BlockMachineBase) blockState.getBlock();
if(blockState.getValue(BlockMachineBase.ACTIVE) != progress > 0)
blockMachineBase.setActive(progress > 0, worldObj, pos);
}
}
@ -67,25 +192,14 @@ public class TileElectricFurnace extends TilePowerAcceptor implements IWrenchabl
public void readFromNBT(NBTTagCompound tagCompound) {
super.readFromNBT(tagCompound);
inventory.readFromNBT(tagCompound);
// crafter.readFromNBT(tagCompound);
}
@Override
public void writeToNBT(NBTTagCompound tagCompound) {
super.writeToNBT(tagCompound);
inventory.writeToNBT(tagCompound);
// crafter.writeToNBT(tagCompound);
}
// @Override
// public void addWailaInfo(List<String> info){
// super.addWailaInfo(info);
// info.add("Power Stored " + energy.getEnergyStored() + "/" + energy.getCapacity() +" EU");
// if(crafter.currentRecipe !=null){
// info.add("Power Usage " + crafter.currentRecipe.euPerTick() + " EU/t");
// }
// }
@Override
public int getSizeInventory() {
return inventory.getSizeInventory();
@ -146,13 +260,6 @@ public class TileElectricFurnace extends TilePowerAcceptor implements IWrenchabl
return slotIndex == 2;
}
// public int getProgressScaled(int scale) {
// if (crafter.currentTickTime != 0) {
// return crafter.currentTickTime * scale / crafter.currentNeededTicks;
// }
// return 0;
// }
@Override
public double getMaxPower() {
return capacity;