2016-03-06 20:59:39 +01:00
|
|
|
package techreborn.tiles;
|
|
|
|
|
|
|
|
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;
|
2016-03-25 10:47:34 +01:00
|
|
|
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;
|
2016-03-06 20:59:39 +01:00
|
|
|
import net.minecraft.item.crafting.FurnaceRecipes;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2016-03-13 17:08:30 +01:00
|
|
|
import net.minecraft.util.text.ITextComponent;
|
2016-03-06 20:59:39 +01:00
|
|
|
import net.minecraftforge.fml.common.registry.GameRegistry;
|
2016-04-11 18:43:54 +02:00
|
|
|
import reborncore.api.tile.IInventoryProvider;
|
2016-03-06 20:59:39 +01:00
|
|
|
import reborncore.common.blocks.BlockMachineBase;
|
|
|
|
import reborncore.common.tile.TileMachineBase;
|
|
|
|
import reborncore.common.util.Inventory;
|
|
|
|
|
2016-04-11 18:43:54 +02:00
|
|
|
public class TileIronFurnace extends TileMachineBase implements IInventoryProvider
|
2016-03-25 10:47:34 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
public int tickTime;
|
|
|
|
public Inventory inventory = new Inventory(3, "TileIronFurnace", 64, this);
|
|
|
|
public int fuel;
|
|
|
|
public int fuelGague;
|
|
|
|
public int progress;
|
|
|
|
public int fuelScale = 200;
|
|
|
|
int input1 = 0;
|
|
|
|
int output = 1;
|
|
|
|
int fuelslot = 2;
|
|
|
|
boolean active = false;
|
|
|
|
|
|
|
|
public static int getItemBurnTime(ItemStack stack)
|
|
|
|
{
|
|
|
|
if (stack == null)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
Item item = stack.getItem();
|
|
|
|
|
|
|
|
if (stack.getItem() instanceof ItemBlock && Block.getBlockFromItem(item) != null)
|
|
|
|
{
|
|
|
|
Block block = Block.getBlockFromItem(item);
|
|
|
|
|
|
|
|
if (block == Blocks.wooden_slab)
|
|
|
|
{
|
|
|
|
return 150;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (block == Blocks.log)
|
|
|
|
{
|
|
|
|
return 1200;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (block.getMaterial(block.getDefaultState()) == Material.wood)
|
|
|
|
{
|
|
|
|
return 300;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (block == Blocks.coal_block)
|
|
|
|
{
|
|
|
|
return 16000;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item instanceof ItemTool && ((ItemTool) item).getToolMaterialName().equals("WOOD"))
|
|
|
|
return 200;
|
|
|
|
if (item instanceof ItemSword && ((ItemSword) item).getToolMaterialName().equals("WOOD"))
|
|
|
|
return 200;
|
|
|
|
if (item instanceof ItemHoe && ((ItemHoe) item).getMaterialName().equals("WOOD"))
|
|
|
|
return 200;
|
|
|
|
if (item == Items.stick)
|
|
|
|
return 100;
|
|
|
|
if (item == Items.coal)
|
|
|
|
return 1600;
|
|
|
|
if (item == Items.lava_bucket)
|
|
|
|
return 20000;
|
|
|
|
if (item == new ItemStack(Blocks.sapling).getItem())
|
|
|
|
return 100;
|
|
|
|
if (item == Items.blaze_rod)
|
|
|
|
return 2400;
|
|
|
|
return GameRegistry.getFuelValue(stack);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public int gaugeProgressScaled(int scale)
|
|
|
|
{
|
|
|
|
return (progress * scale) / fuelScale;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int gaugeFuelScaled(int scale)
|
|
|
|
{
|
|
|
|
if (fuelGague == 0)
|
|
|
|
{
|
|
|
|
fuelGague = fuel;
|
|
|
|
if (fuelGague == 0)
|
|
|
|
{
|
|
|
|
fuelGague = fuelScale;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (fuel * scale) / fuelGague;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void updateEntity()
|
|
|
|
{
|
|
|
|
boolean burning = isBurning();
|
|
|
|
boolean updateInventory = false;
|
|
|
|
if (fuel > 0)
|
|
|
|
{
|
|
|
|
fuel--;
|
|
|
|
updateState();
|
|
|
|
}
|
|
|
|
if (fuel <= 0 && canSmelt())
|
|
|
|
{
|
2016-04-03 15:34:39 +02:00
|
|
|
fuel = fuelGague = getItemBurnTime(getStackInSlot(fuelslot));
|
2016-03-25 10:47:34 +01:00
|
|
|
if (fuel > 0)
|
|
|
|
{
|
|
|
|
if (getStackInSlot(fuelslot).getItem().hasContainerItem()) // Fuel
|
|
|
|
// slot
|
|
|
|
{
|
|
|
|
setInventorySlotContents(fuelslot,
|
|
|
|
new ItemStack(getStackInSlot(fuelslot).getItem().getContainerItem()));
|
|
|
|
} else if (getStackInSlot(fuelslot).stackSize > 1)
|
|
|
|
{
|
|
|
|
decrStackSize(fuelslot, 1);
|
|
|
|
} else if (getStackInSlot(fuelslot).stackSize == 1)
|
|
|
|
{
|
|
|
|
setInventorySlotContents(fuelslot, null);
|
|
|
|
}
|
|
|
|
updateInventory = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isBurning() && canSmelt())
|
|
|
|
{
|
|
|
|
progress++;
|
|
|
|
if (progress >= fuelScale)
|
|
|
|
{
|
|
|
|
progress = 0;
|
|
|
|
cookItems();
|
|
|
|
updateInventory = true;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
progress = 0;
|
|
|
|
}
|
|
|
|
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 fuel > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
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) != fuel > 0)
|
|
|
|
blockMachineBase.setActive(fuel > 0, worldObj, pos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-04-11 18:43:54 +02:00
|
|
|
public Inventory getInventory() {
|
|
|
|
return inventory;
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
2016-03-06 20:59:39 +01:00
|
|
|
}
|