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

203 lines
4.9 KiB
Java
Raw Normal View History

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