2015-05-10 20:00:58 +02:00
|
|
|
package techreborn.tiles;
|
|
|
|
|
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;
|
2016-04-11 18:50:00 +02:00
|
|
|
import net.minecraft.item.*;
|
2016-01-07 11:46:13 +01:00
|
|
|
import net.minecraft.util.EnumFacing;
|
2015-11-23 20:19:18 +01:00
|
|
|
import net.minecraftforge.fml.common.registry.GameRegistry;
|
2016-04-11 18:50:00 +02:00
|
|
|
import reborncore.api.recipe.IBaseRecipeType;
|
|
|
|
import reborncore.api.recipe.RecipeHandler;
|
2016-04-11 18:43:54 +02:00
|
|
|
import reborncore.api.tile.IInventoryProvider;
|
2016-10-08 21:46:16 +02:00
|
|
|
import reborncore.common.IWrenchable;
|
2016-11-04 21:03:05 +01:00
|
|
|
import reborncore.common.tile.TileLegacyMachineBase;
|
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;
|
2016-04-03 15:07:45 +02:00
|
|
|
import techreborn.api.Reference;
|
2016-04-11 18:50:00 +02:00
|
|
|
import techreborn.init.ModBlocks;
|
2015-05-10 20:00:58 +02:00
|
|
|
|
2016-11-04 21:03:05 +01:00
|
|
|
public class TileAlloyFurnace extends TileLegacyMachineBase implements IWrenchable, IInventoryProvider {
|
2016-03-25 10:47:34 +01:00
|
|
|
|
|
|
|
public int tickTime;
|
|
|
|
public Inventory inventory = new Inventory(4, "TileAlloyFurnace", 64, this);
|
|
|
|
public int burnTime;
|
|
|
|
public int currentItemBurnTime;
|
|
|
|
public int cookTime;
|
|
|
|
int input1 = 0;
|
|
|
|
int input2 = 1;
|
|
|
|
int output = 2;
|
|
|
|
int fuel = 3;
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
public TileAlloyFurnace() {
|
2016-03-25 10:47:34 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the number of ticks that the supplied fuel item will keep the
|
|
|
|
* furnace burning, or 0 if the item isn't fuel
|
|
|
|
*/
|
2016-10-08 21:46:16 +02:00
|
|
|
public static int getItemBurnTime(ItemStack stack) {
|
|
|
|
if (stack == null) {
|
2016-03-25 10:47:34 +01:00
|
|
|
return 0;
|
2016-10-08 21:46:16 +02:00
|
|
|
} else {
|
2016-03-25 10:47:34 +01:00
|
|
|
Item item = stack.getItem();
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
if (item instanceof ItemBlock && Block.getBlockFromItem(item) != Blocks.AIR) {
|
2016-03-25 10:47:34 +01:00
|
|
|
Block block = Block.getBlockFromItem(item);
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
if (block == Blocks.WOODEN_SLAB) {
|
2016-03-25 10:47:34 +01:00
|
|
|
return 150;
|
|
|
|
}
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
if (block.getMaterial(block.getDefaultState()) == Material.WOOD) {
|
2016-03-25 10:47:34 +01:00
|
|
|
return 300;
|
|
|
|
}
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
if (block == Blocks.COAL_BLOCK) {
|
2016-03-25 10:47:34 +01:00
|
|
|
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).getToolMaterialName().equals("WOOD")) return 200;
|
2016-05-06 23:13:24 +02:00
|
|
|
if (item == Items.STICK)
|
2016-03-25 10:47:34 +01:00
|
|
|
return 100;
|
2016-05-06 23:13:24 +02:00
|
|
|
if (item == Items.COAL)
|
2016-03-25 10:47:34 +01:00
|
|
|
return 1600;
|
2016-05-06 23:13:24 +02:00
|
|
|
if (item == Items.LAVA_BUCKET)
|
2016-03-25 10:47:34 +01:00
|
|
|
return 20000;
|
2016-05-06 23:13:24 +02:00
|
|
|
if (item == Item.getItemFromBlock(Blocks.SAPLING))
|
2016-03-25 10:47:34 +01:00
|
|
|
return 100;
|
2016-05-06 23:13:24 +02:00
|
|
|
if (item == Items.BLAZE_ROD)
|
2016-03-25 10:47:34 +01:00
|
|
|
return 2400;
|
|
|
|
return GameRegistry.getFuelValue(stack);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public void updateEntity() {
|
2016-08-10 01:45:07 +02:00
|
|
|
super.updateEntity();
|
2016-03-25 10:47:34 +01:00
|
|
|
boolean flag = this.burnTime > 0;
|
|
|
|
boolean flag1 = false;
|
2016-10-08 21:46:16 +02:00
|
|
|
if (this.burnTime > 0) {
|
2016-03-25 10:47:34 +01:00
|
|
|
--this.burnTime;
|
|
|
|
}
|
2016-11-19 13:50:08 +01:00
|
|
|
if (!this.world.isRemote) {
|
2016-11-19 17:36:13 +01:00
|
|
|
if (this.burnTime != 0 || getStackInSlot(input1) != ItemStack.EMPTY && getStackInSlot(fuel) != ItemStack.EMPTY) {
|
2016-10-08 21:46:16 +02:00
|
|
|
if (this.burnTime == 0 && this.canSmelt()) {
|
2016-03-25 10:47:34 +01:00
|
|
|
this.currentItemBurnTime = this.burnTime = getItemBurnTime(getStackInSlot(fuel));
|
2016-10-08 21:46:16 +02:00
|
|
|
if (this.burnTime > 0) {
|
2016-03-25 10:47:34 +01:00
|
|
|
flag1 = true;
|
2016-11-19 17:36:13 +01:00
|
|
|
if (this.getStackInSlot(fuel) != ItemStack.EMPTY) {
|
2016-03-25 10:47:34 +01:00
|
|
|
decrStackSize(fuel, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-10-08 21:46:16 +02:00
|
|
|
if (this.isBurning() && this.canSmelt()) {
|
2016-03-25 10:47:34 +01:00
|
|
|
++this.cookTime;
|
2016-10-08 21:46:16 +02:00
|
|
|
if (this.cookTime == 200) {
|
2016-03-25 10:47:34 +01:00
|
|
|
this.cookTime = 0;
|
|
|
|
this.smeltItem();
|
|
|
|
flag1 = true;
|
|
|
|
}
|
2016-10-08 21:46:16 +02:00
|
|
|
} else {
|
2016-03-25 10:47:34 +01:00
|
|
|
this.cookTime = 0;
|
|
|
|
}
|
|
|
|
}
|
2016-10-08 21:46:16 +02:00
|
|
|
if (flag != this.burnTime > 0) {
|
2016-03-25 10:47:34 +01:00
|
|
|
flag1 = true;
|
|
|
|
// TODO sync on/off
|
|
|
|
}
|
|
|
|
}
|
2016-10-08 21:46:16 +02:00
|
|
|
if (flag1) {
|
2016-03-25 10:47:34 +01:00
|
|
|
this.markDirty();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
public boolean hasAllInputs(IBaseRecipeType recipeType) {
|
|
|
|
if (recipeType == null) {
|
2016-03-25 10:47:34 +01:00
|
|
|
return false;
|
|
|
|
}
|
2016-10-08 21:46:16 +02:00
|
|
|
for (ItemStack input : recipeType.getInputs()) {
|
2016-03-25 10:47:34 +01:00
|
|
|
Boolean hasItem = false;
|
2016-10-08 21:46:16 +02:00
|
|
|
for (int inputslot = 0; inputslot < 2; inputslot++) {
|
2016-03-25 10:47:34 +01:00
|
|
|
if (ItemUtils.isItemEqual(input, inventory.getStackInSlot(inputslot), true, true,
|
2016-11-19 13:50:08 +01:00
|
|
|
recipeType.useOreDic()) && inventory.getStackInSlot(inputslot).getCount() >= input.getCount()) {
|
2016-03-25 10:47:34 +01:00
|
|
|
hasItem = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!hasItem)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
private boolean canSmelt() {
|
2016-11-19 17:36:13 +01:00
|
|
|
if (this.getStackInSlot(input1) == ItemStack.EMPTY || this.getStackInSlot(input2) == ItemStack.EMPTY) {
|
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 = null;
|
2016-10-08 21:46:16 +02:00
|
|
|
for (IBaseRecipeType recipeType : RecipeHandler.getRecipeClassFromName(Reference.alloySmelteRecipe)) {
|
|
|
|
if (hasAllInputs(recipeType)) {
|
2016-03-25 10:47:34 +01:00
|
|
|
itemstack = recipeType.getOutput(0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (itemstack == null)
|
|
|
|
return false;
|
2016-11-19 17:36:13 +01:00
|
|
|
if (this.getStackInSlot(output) == ItemStack.EMPTY)
|
2016-03-25 10:47:34 +01:00
|
|
|
return true;
|
|
|
|
if (!this.getStackInSlot(output).isItemEqual(itemstack))
|
|
|
|
return false;
|
2016-11-19 13:50:08 +01:00
|
|
|
int result = getStackInSlot(output).getCount() + itemstack.getCount();
|
2016-03-25 10:47:34 +01:00
|
|
|
return result <= getInventoryStackLimit() && result <= this.getStackInSlot(output).getMaxStackSize(); // Forge
|
2016-10-08 21:46:16 +02:00
|
|
|
// BugFix:
|
|
|
|
// Make
|
|
|
|
// it
|
|
|
|
// respect
|
|
|
|
// stack
|
|
|
|
// sizes
|
|
|
|
// properly.
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Turn one item from the furnace source stack into the appropriate smelted
|
|
|
|
* item in the furnace result stack
|
|
|
|
*/
|
2016-10-08 21:46:16 +02:00
|
|
|
public void smeltItem() {
|
|
|
|
if (this.canSmelt()) {
|
2016-03-25 10:47:34 +01:00
|
|
|
ItemStack itemstack = null;
|
2016-10-08 21:46:16 +02:00
|
|
|
for (IBaseRecipeType recipeType : RecipeHandler.getRecipeClassFromName(Reference.alloySmelteRecipe)) {
|
|
|
|
if (hasAllInputs(recipeType)) {
|
2016-04-01 21:22:55 +02:00
|
|
|
itemstack = recipeType.getOutput(0);
|
|
|
|
break;
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
2016-11-19 17:36:13 +01:00
|
|
|
if (itemstack != ItemStack.EMPTY) {
|
2016-03-25 10:47:34 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-19 17:36:13 +01:00
|
|
|
if (this.getStackInSlot(output) == ItemStack.EMPTY) {
|
2016-03-25 10:47:34 +01:00
|
|
|
setInventorySlotContents(output, itemstack.copy());
|
2016-10-08 21:46:16 +02:00
|
|
|
} else if (this.getStackInSlot(output).getItem() == itemstack.getItem()) {
|
2016-11-19 13:50:08 +01:00
|
|
|
decrStackSize(output, -itemstack.getCount());
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
for (IBaseRecipeType recipeType : RecipeHandler.getRecipeClassFromName(Reference.alloySmelteRecipe)) {
|
2016-03-25 10:47:34 +01:00
|
|
|
boolean hasAllRecipes = true;
|
2016-10-08 21:46:16 +02:00
|
|
|
if (hasAllInputs(recipeType)) {
|
2016-03-25 10:47:34 +01:00
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
} else {
|
|
|
|
hasAllRecipes = false;
|
|
|
|
}
|
|
|
|
if (hasAllRecipes) {
|
|
|
|
for (ItemStack input : recipeType.getInputs()) {
|
|
|
|
for (int inputSlot = 0; inputSlot < 2; inputSlot++) {
|
2016-03-25 10:47:34 +01:00
|
|
|
if (ItemUtils.isItemEqual(input, inventory.getStackInSlot(inputSlot), true, true,
|
2016-10-08 21:46:16 +02:00
|
|
|
recipeType.useOreDic())) {
|
2016-11-19 13:50:08 +01:00
|
|
|
inventory.decrStackSize(inputSlot, input.getCount());
|
2016-03-25 10:47:34 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Furnace isBurning
|
|
|
|
*/
|
2016-10-08 21:46:16 +02:00
|
|
|
public boolean isBurning() {
|
2016-03-25 10:47:34 +01:00
|
|
|
return this.burnTime > 0;
|
|
|
|
}
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
public int getBurnTimeRemainingScaled(int scale) {
|
|
|
|
if (this.currentItemBurnTime == 0) {
|
2016-03-25 10:47:34 +01:00
|
|
|
this.currentItemBurnTime = 200;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.burnTime * scale / this.currentItemBurnTime;
|
|
|
|
}
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
public int getCookProgressScaled(int scale) {
|
2016-03-25 10:47:34 +01:00
|
|
|
return this.cookTime * scale / 200;
|
|
|
|
}
|
|
|
|
|
|
|
|
@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) {
|
2016-04-03 15:34:39 +02:00
|
|
|
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) {
|
2016-03-25 10:47:34 +01:00
|
|
|
return new ItemStack(ModBlocks.AlloyFurnace, 1);
|
|
|
|
}
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
public boolean isComplete() {
|
2016-03-25 10:47:34 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-04-11 18:43:54 +02:00
|
|
|
public Inventory getInventory() {
|
|
|
|
return inventory;
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
2016-07-21 17:22:56 +02:00
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
@Override
|
|
|
|
public int[] getSlotsForFace(EnumFacing side) {
|
|
|
|
return new int[] { 0, 1, 2 };
|
|
|
|
}
|
2016-07-27 12:51:03 +02:00
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
@Override
|
|
|
|
public boolean canInsertItem(int index, ItemStack itemStackIn, EnumFacing direction) {
|
|
|
|
return index == 0 || index == 1;
|
|
|
|
}
|
2016-07-27 12:51:03 +02:00
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
@Override
|
|
|
|
public boolean canExtractItem(int index, ItemStack stack, EnumFacing direction) {
|
|
|
|
return index == 2;
|
|
|
|
}
|
2016-07-27 12:51:03 +02:00
|
|
|
|
2015-05-10 20:00:58 +02:00
|
|
|
}
|