2016-02-20 04:07:56 +01:00
|
|
|
package techreborn.tiles.teir1;
|
|
|
|
|
2016-03-06 21:39:31 +01:00
|
|
|
import net.minecraft.block.state.IBlockState;
|
2016-02-20 04:07:56 +01:00
|
|
|
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;
|
2016-02-20 04:07:56 +01:00
|
|
|
import net.minecraft.util.EnumFacing;
|
2016-03-08 18:34:04 +01:00
|
|
|
import reborncore.api.power.EnumPowerTier;
|
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-03-06 21:39:31 +01:00
|
|
|
import reborncore.common.blocks.BlockMachineBase;
|
2016-08-10 01:45:07 +02:00
|
|
|
import reborncore.common.powerSystem.TilePowerAcceptor;
|
2016-02-20 04:07:56 +01:00
|
|
|
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-02-20 04:07:56 +01:00
|
|
|
|
2016-03-25 10:47:34 +01:00
|
|
|
public Inventory inventory = new Inventory(6, "TileElectricFurnace", 64, this);
|
2016-08-10 01:45:07 +02:00
|
|
|
public int capacity = 1000;
|
2016-03-25 10:47:34 +01:00
|
|
|
public int progress;
|
|
|
|
public int fuelScale = 100;
|
2016-06-04 18:03:22 +02:00
|
|
|
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-08-10 01:45:07 +02:00
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
public TileElectricFurnace() {
|
2016-08-10 01:45:07 +02:00
|
|
|
super(1);
|
|
|
|
}
|
2016-02-20 04:07:56 +01:00
|
|
|
|
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
|
2016-07-21 17:22:56 +02:00
|
|
|
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) {
|
2016-06-04 18:03:22 +02:00
|
|
|
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-11-19 17:36:13 +01:00
|
|
|
if (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 (getStackInSlot(output).isItemEqual(itemstack)) {
|
2016-11-19 13:50:08 +01:00
|
|
|
getStackInSlot(output).grow(itemstack.getCount());
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
2016-11-19 13:50:08 +01:00
|
|
|
if (getStackInSlot(input1).getCount() > 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() {
|
2016-11-19 17:36:13 +01:00
|
|
|
if (getStackInSlot(input1) == 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 = FurnaceRecipes.instance().getSmeltingResult(getStackInSlot(input1));
|
|
|
|
if (itemstack == null)
|
|
|
|
return false;
|
2016-11-19 17:36:13 +01:00
|
|
|
if (getStackInSlot(output) == ItemStack.EMPTY)
|
2016-03-25 10:47:34 +01:00
|
|
|
return true;
|
|
|
|
if (!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 <= 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-11-19 17:36:13 +01:00
|
|
|
if (result != ItemStack.EMPTY) {
|
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-11-19 13:50:08 +01:00
|
|
|
IBlockState BlockStateContainer = world.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)
|
2016-11-19 13:50:08 +01:00
|
|
|
blockMachineBase.setActive(progress > 0, world, pos);
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@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-12-05 10:40:55 +01:00
|
|
|
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
|
2016-08-10 01:45:07 +02:00
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public int[] getSlotsForFace(EnumFacing side) {
|
2016-08-10 01:45:07 +02:00
|
|
|
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) {
|
2016-08-10 01:45:07 +02:00
|
|
|
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) {
|
2016-08-27 09:02:44 +02:00
|
|
|
return slotIndex == 1;
|
2016-08-10 01:45:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public double getMaxPower() {
|
2016-08-10 01:45:07 +02:00
|
|
|
return capacity;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public boolean canAcceptEnergy(EnumFacing direction) {
|
2016-08-10 01:45:07 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public boolean canProvideEnergy(EnumFacing direction) {
|
2016-08-10 01:45:07 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public double getMaxOutput() {
|
2016-08-10 01:45:07 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2016-03-25 10:47:34 +01:00
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public double getMaxInput() {
|
2016-08-10 01:45:07 +02:00
|
|
|
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
|
2016-04-11 18:43:54 +02:00
|
|
|
public Inventory getInventory() {
|
|
|
|
return inventory;
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
2016-02-20 04:07:56 +01:00
|
|
|
}
|