TechReborn/src/main/java/techreborn/tiles/teir1/TileElectricFurnace.java

240 lines
5 KiB
Java
Raw Normal View History

package techreborn.tiles.teir1;
2016-05-12 20:16:40 +02:00
import reborncore.common.IWrenchable;
2016-03-06 21:39:31 +01:00
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
2016-03-06 21:39:31 +01:00
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.util.EnumFacing;
import reborncore.api.power.EnumPowerTier;
import reborncore.api.tile.IInventoryProvider;
2016-03-06 21:39:31 +01:00
import reborncore.common.blocks.BlockMachineBase;
2016-02-24 09:18:21 +01:00
import reborncore.common.powerSystem.TilePowerAcceptor;
import reborncore.common.util.Inventory;
import techreborn.init.ModBlocks;
public class TileElectricFurnace extends TilePowerAcceptor implements IWrenchable,IInventoryProvider, ISidedInventory
2016-03-25 10:47:34 +01:00
{
2016-03-25 10:47:34 +01:00
public Inventory inventory = new Inventory(6, "TileElectricFurnace", 64, this);
public int capacity = 1000;
public int progress;
public int fuelScale = 100;
public int cost = 8;
2016-03-25 10:47:34 +01:00
int input1 = 0;
int output = 1;
2016-05-23 18:09:38 +02:00
private static final int[] SLOTS_TOP = new int[] {0};
private static final int[] SLOTS_BOTTOM = new int[] {1};
private static final int[] SLOTS_SIDES = new int[] {1};
2016-03-25 10:47:34 +01:00
public TileElectricFurnace()
{
super(1);
}
2016-03-25 10:47:34 +01:00
public int gaugeProgressScaled(int scale)
{
return (progress * scale) / fuelScale;
}
@Override
public void updateEntity()
{
boolean burning = isBurning();
boolean updateInventory = false;
if (isBurning() && canSmelt())
{
updateState();
progress++;
if(progress % 10 == 0){
useEnergy(cost);
}
2016-03-25 10:47:34 +01:00
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)
{
setInventorySlotContents(output, itemstack.copy());
} else if (getStackInSlot(output).isItemEqual(itemstack))
{
getStackInSlot(output).stackSize += itemstack.stackSize;
}
if (getStackInSlot(input1).stackSize > 1)
{
this.decrStackSize(input1, 1);
} else
{
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 BlockStateContainer = worldObj.getBlockState(pos);
if (BlockStateContainer.getBlock() instanceof BlockMachineBase)
{
BlockMachineBase blockMachineBase = (BlockMachineBase) BlockStateContainer.getBlock();
if (BlockStateContainer.getValue(BlockMachineBase.ACTIVE) != progress > 0)
blockMachineBase.setActive(progress > 0, worldObj, pos);
}
}
@Override
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, EnumFacing side)
{
return false;
}
@Override
public EnumFacing getFacing()
{
return getFacingEnum();
}
@Override
public boolean wrenchCanRemove(EntityPlayer entityPlayer)
{
return entityPlayer.isSneaking();
2016-03-25 10:47:34 +01:00
}
@Override
public float getWrenchDropRate()
{
return 1.0F;
}
@Override
public ItemStack getWrenchDrop(EntityPlayer entityPlayer)
{
return new ItemStack(ModBlocks.ElectricFurnace, 1);
2016-03-25 10:47:34 +01:00
}
public boolean isComplete()
{
return false;
}
// ISidedInventory
@Override
public int[] getSlotsForFace(EnumFacing side)
{
2016-05-23 18:09:38 +02:00
return side == EnumFacing.DOWN ? SLOTS_BOTTOM : (side == EnumFacing.UP ? SLOTS_TOP : SLOTS_SIDES);
2016-03-25 10:47:34 +01:00
}
@Override
public boolean canInsertItem(int slotIndex, ItemStack itemStack, EnumFacing side)
{
if (slotIndex == 2)
return false;
return isItemValidForSlot(slotIndex, itemStack);
}
@Override
public boolean canExtractItem(int slotIndex, ItemStack itemStack, EnumFacing side)
{
return slotIndex == 2;
}
@Override
public double getMaxPower()
{
return capacity;
}
@Override
public boolean canAcceptEnergy(EnumFacing direction)
{
return true;
}
@Override
public boolean canProvideEnergy(EnumFacing direction)
{
return false;
}
@Override
public double getMaxOutput()
{
return 0;
}
@Override
public double getMaxInput()
{
return 32;
}
@Override
public EnumPowerTier getTier()
{
return EnumPowerTier.LOW;
}
@Override
public Inventory getInventory() {
return inventory;
2016-03-25 10:47:34 +01:00
}
}