2015-05-10 20:00:58 +02:00
|
|
|
package techreborn.tiles;
|
|
|
|
|
2016-02-20 18:06:46 +01:00
|
|
|
import ic2.api.tile.IWrenchable;
|
2015-08-10 20:28:52 +02:00
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.block.material.Material;
|
2015-05-10 20:00:58 +02:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2015-08-10 20:28:52 +02:00
|
|
|
import net.minecraft.init.Blocks;
|
|
|
|
import net.minecraft.init.Items;
|
2015-06-07 10:38:12 +02:00
|
|
|
import net.minecraft.inventory.IInventory;
|
2015-08-10 20:28:52 +02:00
|
|
|
import net.minecraft.item.*;
|
2015-05-10 20:00:58 +02:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2016-01-07 11:46:13 +01:00
|
|
|
import net.minecraft.util.EnumFacing;
|
2015-11-23 21:27:06 +01:00
|
|
|
import net.minecraft.util.IChatComponent;
|
2015-11-23 20:19:18 +01:00
|
|
|
import net.minecraftforge.fml.common.registry.GameRegistry;
|
2016-02-20 17:59:31 +01:00
|
|
|
import reborncore.common.tile.TileMachineBase;
|
2015-11-08 13:15:45 +01:00
|
|
|
import reborncore.common.util.Inventory;
|
|
|
|
import reborncore.common.util.ItemUtils;
|
2015-08-10 20:28:52 +02:00
|
|
|
import techreborn.api.recipe.IBaseRecipeType;
|
|
|
|
import techreborn.api.recipe.RecipeHandler;
|
2015-05-10 20:00:58 +02:00
|
|
|
import techreborn.init.ModBlocks;
|
2015-08-10 20:28:52 +02:00
|
|
|
import techreborn.lib.Reference;
|
2015-05-10 20:00:58 +02:00
|
|
|
|
2015-08-09 12:05:32 +02:00
|
|
|
public class TileAlloyFurnace extends TileMachineBase implements IWrenchable, IInventory {
|
|
|
|
|
|
|
|
public int tickTime;
|
2015-11-23 21:27:06 +01:00
|
|
|
public Inventory inventory = new Inventory(4, "TileAlloyFurnace", 64, this);
|
2015-08-09 12:05:32 +02:00
|
|
|
|
2015-08-10 20:28:52 +02:00
|
|
|
int input1 = 0;
|
|
|
|
int input2 = 1;
|
|
|
|
|
|
|
|
int output = 2;
|
|
|
|
|
|
|
|
int fuel = 3;
|
|
|
|
|
|
|
|
|
|
|
|
public int burnTime;
|
|
|
|
|
|
|
|
public int currentItemBurnTime;
|
|
|
|
public int cookTime;
|
|
|
|
|
2015-08-09 12:05:32 +02:00
|
|
|
public TileAlloyFurnace() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void updateEntity() {
|
|
|
|
super.updateEntity();
|
2015-08-10 20:28:52 +02:00
|
|
|
boolean flag = this.burnTime > 0;
|
|
|
|
boolean flag1 = false;
|
2015-11-08 13:15:45 +01:00
|
|
|
if (this.burnTime > 0) {
|
2015-08-10 20:28:52 +02:00
|
|
|
--this.burnTime;
|
|
|
|
}
|
2015-11-08 13:15:45 +01:00
|
|
|
if (!this.worldObj.isRemote) {
|
|
|
|
if (this.burnTime != 0 || getStackInSlot(input1) != null && getStackInSlot(fuel) != null) {
|
|
|
|
if (this.burnTime == 0 && this.canSmelt()) {
|
2015-08-10 20:28:52 +02:00
|
|
|
this.currentItemBurnTime = this.burnTime = getItemBurnTime(getStackInSlot(fuel));
|
2015-11-08 13:15:45 +01:00
|
|
|
if (this.burnTime > 0) {
|
2015-08-10 20:28:52 +02:00
|
|
|
flag1 = true;
|
2015-11-08 13:15:45 +01:00
|
|
|
if (this.getStackInSlot(fuel) != null) {
|
2015-08-10 20:28:52 +02:00
|
|
|
decrStackSize(fuel, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-11-08 13:15:45 +01:00
|
|
|
if (this.isBurning() && this.canSmelt()) {
|
2015-08-10 20:28:52 +02:00
|
|
|
++this.cookTime;
|
2015-11-08 13:15:45 +01:00
|
|
|
if (this.cookTime == 200) {
|
2015-08-10 20:28:52 +02:00
|
|
|
this.cookTime = 0;
|
|
|
|
this.smeltItem();
|
|
|
|
flag1 = true;
|
|
|
|
}
|
2015-11-08 13:15:45 +01:00
|
|
|
} else {
|
2015-08-10 20:28:52 +02:00
|
|
|
this.cookTime = 0;
|
|
|
|
}
|
|
|
|
}
|
2015-11-08 13:15:45 +01:00
|
|
|
if (flag != this.burnTime > 0) {
|
2015-08-10 20:28:52 +02:00
|
|
|
flag1 = true;
|
|
|
|
//TODO sync on/off
|
|
|
|
}
|
|
|
|
}
|
2015-11-08 13:15:45 +01:00
|
|
|
if (flag1) {
|
2015-08-10 20:28:52 +02:00
|
|
|
this.markDirty();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-13 13:47:55 +02:00
|
|
|
public boolean hasAllInputs(IBaseRecipeType recipeType) {
|
|
|
|
if (recipeType == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
for (ItemStack input : recipeType.getInputs()) {
|
|
|
|
Boolean hasItem = false;
|
|
|
|
for (int inputslot = 0; inputslot < 2; inputslot++) {
|
|
|
|
if (ItemUtils.isItemEqual(input, inventory.getStackInSlot(inputslot), true, true, recipeType.useOreDic()) && inventory.getStackInSlot(inputslot).stackSize >= input.stackSize) {
|
|
|
|
hasItem = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!hasItem)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-11-08 13:15:45 +01:00
|
|
|
private boolean canSmelt() {
|
|
|
|
if (this.getStackInSlot(input1) == null || this.getStackInSlot(input2) == null) {
|
2015-08-10 20:28:52 +02:00
|
|
|
return false;
|
2015-11-08 13:15:45 +01:00
|
|
|
} else {
|
2015-08-10 20:28:52 +02:00
|
|
|
ItemStack itemstack = null;
|
2015-11-08 13:15:45 +01:00
|
|
|
for (IBaseRecipeType recipeType : RecipeHandler.getRecipeClassFromName(Reference.alloySmelteRecipe)) {
|
|
|
|
if (hasAllInputs(recipeType)) {
|
2015-08-13 13:47:55 +02:00
|
|
|
itemstack = recipeType.getOutput(0);
|
2015-08-10 20:28:52 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (itemstack == null) return false;
|
|
|
|
if (this.getStackInSlot(output) == null) return true;
|
|
|
|
if (!this.getStackInSlot(output).isItemEqual(itemstack)) return false;
|
|
|
|
int result = getStackInSlot(output).stackSize + itemstack.stackSize;
|
|
|
|
return result <= getInventoryStackLimit() && result <= this.getStackInSlot(output).getMaxStackSize(); //Forge BugFix: Make it respect stack sizes properly.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Turn one item from the furnace source stack into the appropriate smelted item in the furnace result stack
|
|
|
|
*/
|
2015-11-08 13:15:45 +01:00
|
|
|
public void smeltItem() {
|
|
|
|
if (this.canSmelt()) {
|
2015-08-10 20:28:52 +02:00
|
|
|
ItemStack itemstack = null;
|
2015-11-08 13:15:45 +01:00
|
|
|
for (IBaseRecipeType recipeType : RecipeHandler.getRecipeClassFromName(Reference.alloySmelteRecipe)) {
|
|
|
|
for (ItemStack input : recipeType.getInputs()) {
|
|
|
|
if (ItemUtils.isItemEqual(input, getStackInSlot(input1), true, true, true) || ItemUtils.isItemEqual(input, getStackInSlot(input2), true, true, true)) {
|
2015-08-10 20:28:52 +02:00
|
|
|
itemstack = recipeType.getOutput(0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-11-08 13:15:45 +01:00
|
|
|
if (itemstack != null) {
|
2015-08-10 20:28:52 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-08 13:15:45 +01:00
|
|
|
if (this.getStackInSlot(output) == null) {
|
2015-08-10 20:28:52 +02:00
|
|
|
setInventorySlotContents(output, itemstack.copy());
|
2015-11-08 13:15:45 +01:00
|
|
|
} else if (this.getStackInSlot(output).getItem() == itemstack.getItem()) {
|
2015-08-10 20:28:52 +02:00
|
|
|
decrStackSize(output, -itemstack.stackSize);
|
|
|
|
}
|
|
|
|
|
2015-11-08 13:15:45 +01:00
|
|
|
for (IBaseRecipeType recipeType : RecipeHandler.getRecipeClassFromName(Reference.alloySmelteRecipe)) {
|
2015-12-11 22:52:35 +01:00
|
|
|
boolean hasAllRecipes = true;
|
2015-11-08 13:15:45 +01:00
|
|
|
for (ItemStack input : recipeType.getInputs()) {
|
2015-12-11 22:52:35 +01:00
|
|
|
if (ItemUtils.isItemEqual(input, getStackInSlot(input1), true, true, true) || ItemUtils.isItemEqual(input, getStackInSlot(input2), true, true, true)) {
|
|
|
|
|
|
|
|
} else {
|
|
|
|
hasAllRecipes = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(hasAllRecipes){
|
|
|
|
for (ItemStack input : recipeType.getInputs()) {
|
|
|
|
for (int inputSlot = 0; inputSlot < 2; inputSlot++) {
|
|
|
|
if (ItemUtils.isItemEqual(input, inventory.getStackInSlot(inputSlot), true, true, recipeType.useOreDic())) {
|
|
|
|
inventory.decrStackSize(inputSlot, input.stackSize);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-08-13 13:47:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-10 20:28:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Furnace isBurning
|
|
|
|
*/
|
2015-11-08 13:15:45 +01:00
|
|
|
public boolean isBurning() {
|
2015-08-10 20:28:52 +02:00
|
|
|
return this.burnTime > 0;
|
|
|
|
}
|
|
|
|
|
2015-11-08 13:15:45 +01:00
|
|
|
public int getBurnTimeRemainingScaled(int scale) {
|
|
|
|
if (this.currentItemBurnTime == 0) {
|
2015-08-10 20:28:52 +02:00
|
|
|
this.currentItemBurnTime = 200;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.burnTime * scale / this.currentItemBurnTime;
|
|
|
|
}
|
|
|
|
|
2015-11-08 13:15:45 +01:00
|
|
|
public int getCookProgressScaled(int scale) {
|
2015-08-10 20:28:52 +02:00
|
|
|
return this.cookTime * scale / 200;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the number of ticks that the supplied fuel item will keep the furnace burning, or 0 if the item isn't
|
|
|
|
* fuel
|
|
|
|
*/
|
2015-11-08 13:15:45 +01:00
|
|
|
public static int getItemBurnTime(ItemStack stack) {
|
|
|
|
if (stack == null) {
|
2015-08-10 20:28:52 +02:00
|
|
|
return 0;
|
2015-11-08 13:15:45 +01:00
|
|
|
} else {
|
2015-08-10 20:28:52 +02:00
|
|
|
Item item = stack.getItem();
|
|
|
|
|
2015-11-08 13:15:45 +01:00
|
|
|
if (item instanceof ItemBlock && Block.getBlockFromItem(item) != Blocks.air) {
|
2015-08-10 20:28:52 +02:00
|
|
|
Block block = Block.getBlockFromItem(item);
|
|
|
|
|
2015-11-08 13:15:45 +01:00
|
|
|
if (block == Blocks.wooden_slab) {
|
2015-08-10 20:28:52 +02:00
|
|
|
return 150;
|
|
|
|
}
|
|
|
|
|
2015-11-08 13:15:45 +01:00
|
|
|
if (block.getMaterial() == Material.wood) {
|
2015-08-10 20:28:52 +02:00
|
|
|
return 300;
|
|
|
|
}
|
|
|
|
|
2015-11-08 13:15:45 +01:00
|
|
|
if (block == Blocks.coal_block) {
|
2015-08-10 20:28:52 +02:00
|
|
|
return 16000;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-08 13:15:45 +01:00
|
|
|
if (item instanceof ItemTool && ((ItemTool) item).getToolMaterialName().equals("WOOD")) return 200;
|
|
|
|
if (item instanceof ItemSword && ((ItemSword) item).getToolMaterialName().equals("WOOD")) return 200;
|
2015-11-23 21:27:06 +01:00
|
|
|
//if (item instanceof ItemHoe && ((ItemHoe) item).getToolMaterialName().equals("WOOD")) return 200;
|
2015-08-10 20:28:52 +02:00
|
|
|
if (item == Items.stick) return 100;
|
|
|
|
if (item == Items.coal) return 1600;
|
|
|
|
if (item == Items.lava_bucket) return 20000;
|
|
|
|
if (item == Item.getItemFromBlock(Blocks.sapling)) return 100;
|
|
|
|
if (item == Items.blaze_rod) return 2400;
|
|
|
|
return GameRegistry.getFuelValue(stack);
|
|
|
|
}
|
2015-08-09 12:05:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-01-07 11:46:13 +01:00
|
|
|
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, EnumFacing side) {
|
2015-08-09 12:05:32 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-01-07 11:46:13 +01:00
|
|
|
public EnumFacing getFacing() {
|
|
|
|
return getFacingEnum();
|
2015-08-09 12:05:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean wrenchCanRemove(EntityPlayer entityPlayer) {
|
|
|
|
if (entityPlayer.isSneaking()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public float getWrenchDropRate() {
|
|
|
|
return 1.0F;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
|
|
|
|
return new ItemStack(ModBlocks.AlloyFurnace, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isComplete() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void readFromNBT(NBTTagCompound tagCompound) {
|
2015-05-10 20:00:58 +02:00
|
|
|
super.readFromNBT(tagCompound);
|
|
|
|
inventory.readFromNBT(tagCompound);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-08-09 12:05:32 +02:00
|
|
|
public void writeToNBT(NBTTagCompound tagCompound) {
|
2015-05-10 20:00:58 +02:00
|
|
|
super.writeToNBT(tagCompound);
|
|
|
|
inventory.writeToNBT(tagCompound);
|
|
|
|
|
|
|
|
}
|
2015-06-07 10:38:12 +02:00
|
|
|
|
2015-08-09 12:05:32 +02:00
|
|
|
@Override
|
|
|
|
public int getSizeInventory() {
|
|
|
|
return inventory.getSizeInventory();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ItemStack getStackInSlot(int slot) {
|
|
|
|
return inventory.getStackInSlot(slot);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ItemStack decrStackSize(int slot, int amount) {
|
|
|
|
return inventory.decrStackSize(slot, amount);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-11-29 10:52:45 +01:00
|
|
|
public ItemStack removeStackFromSlot(int slot) {
|
|
|
|
return inventory.removeStackFromSlot(slot);
|
2015-08-09 12:05:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setInventorySlotContents(int slot, ItemStack stack) {
|
|
|
|
inventory.setInventorySlotContents(slot, stack);
|
|
|
|
}
|
|
|
|
|
2015-11-23 21:27:06 +01:00
|
|
|
|
2015-08-09 12:05:32 +02:00
|
|
|
@Override
|
2015-11-23 21:27:06 +01:00
|
|
|
public int getInventoryStackLimit() {
|
|
|
|
return inventory.getInventoryStackLimit();
|
2015-08-09 12:05:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-11-23 21:27:06 +01:00
|
|
|
public boolean isUseableByPlayer(EntityPlayer player) {
|
|
|
|
return inventory.isUseableByPlayer(player);
|
2015-08-09 12:05:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-11-23 21:27:06 +01:00
|
|
|
public boolean isItemValidForSlot(int slot, ItemStack stack) {
|
|
|
|
return inventory.isItemValidForSlot(slot, stack);
|
2015-08-09 12:05:32 +02:00
|
|
|
}
|
|
|
|
|
2015-11-23 21:27:06 +01:00
|
|
|
|
|
|
|
|
2015-08-09 12:05:32 +02:00
|
|
|
@Override
|
2015-11-23 21:27:06 +01:00
|
|
|
public void openInventory(EntityPlayer player) {
|
|
|
|
inventory.openInventory(player);
|
2015-08-09 12:05:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-11-23 21:27:06 +01:00
|
|
|
public void closeInventory(EntityPlayer player) {
|
|
|
|
inventory.closeInventory(player);
|
2015-08-09 12:05:32 +02:00
|
|
|
}
|
|
|
|
|
2015-11-23 21:27:06 +01:00
|
|
|
|
2015-08-09 12:05:32 +02:00
|
|
|
@Override
|
2015-11-23 21:27:06 +01:00
|
|
|
public int getField(int id) {
|
|
|
|
return inventory.getField(id);
|
2015-08-09 12:05:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-11-23 21:27:06 +01:00
|
|
|
public void setField(int id, int value) {
|
|
|
|
inventory.setField(id, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getFieldCount() {
|
|
|
|
return inventory.getFieldCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void clear() {
|
|
|
|
inventory.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-11-29 10:52:45 +01:00
|
|
|
public String getName() {
|
|
|
|
return inventory.getName();
|
2015-11-23 21:27:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean hasCustomName() {
|
|
|
|
return inventory.hasCustomName();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IChatComponent getDisplayName() {
|
|
|
|
return inventory.getDisplayName();
|
2015-08-09 12:05:32 +02:00
|
|
|
}
|
2015-05-10 20:00:58 +02:00
|
|
|
}
|