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.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;
|
2017-01-07 22:11:54 +01:00
|
|
|
|
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;
|
2017-01-07 22:11:54 +01:00
|
|
|
|
2017-01-08 20:34:46 +01:00
|
|
|
import techreborn.client.container.IContainerProvider;
|
|
|
|
import techreborn.client.container.builder.BuiltContainer;
|
|
|
|
import techreborn.client.container.builder.ContainerBuilder;
|
2016-02-20 04:07:56 +01:00
|
|
|
import techreborn.init.ModBlocks;
|
|
|
|
|
2017-01-08 20:34:46 +01:00
|
|
|
public class TileElectricFurnace extends TilePowerAcceptor
|
|
|
|
implements IWrenchable, IInventoryProvider, IContainerProvider {
|
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
|
|
|
|
2017-01-07 22:11:54 +01:00
|
|
|
public int gaugeProgressScaled(final int scale) {
|
|
|
|
return this.progress * scale / this.fuelScale;
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-07-21 17:22:56 +02:00
|
|
|
public void update() {
|
|
|
|
super.update();
|
2017-01-07 22:11:54 +01:00
|
|
|
final boolean burning = this.isBurning();
|
2016-03-25 10:47:34 +01:00
|
|
|
boolean updateInventory = false;
|
2017-01-07 22:11:54 +01:00
|
|
|
if (this.isBurning() && this.canSmelt()) {
|
|
|
|
this.updateState();
|
2016-03-25 10:47:34 +01:00
|
|
|
|
2017-01-07 22:11:54 +01:00
|
|
|
this.progress++;
|
|
|
|
if (this.progress % 10 == 0) {
|
|
|
|
this.useEnergy(this.cost);
|
2016-06-04 18:03:22 +02:00
|
|
|
}
|
2017-01-07 22:11:54 +01:00
|
|
|
if (this.progress >= this.fuelScale) {
|
|
|
|
this.progress = 0;
|
|
|
|
this.cookItems();
|
2016-03-25 10:47:34 +01:00
|
|
|
updateInventory = true;
|
|
|
|
}
|
2016-10-08 21:46:16 +02:00
|
|
|
} else {
|
2017-01-07 22:11:54 +01:00
|
|
|
this.progress = 0;
|
|
|
|
this.updateState();
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
2017-01-07 22:11:54 +01:00
|
|
|
if (burning != this.isBurning()) {
|
2016-03-25 10:47:34 +01:00
|
|
|
updateInventory = true;
|
|
|
|
}
|
2016-10-08 21:46:16 +02:00
|
|
|
if (updateInventory) {
|
2017-01-07 22:11:54 +01:00
|
|
|
this.markDirty();
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
public void cookItems() {
|
|
|
|
if (this.canSmelt()) {
|
2017-01-07 22:11:54 +01:00
|
|
|
final ItemStack itemstack = FurnaceRecipes.instance().getSmeltingResult(this.getStackInSlot(this.input1));
|
2016-03-25 10:47:34 +01:00
|
|
|
|
2017-01-07 22:11:54 +01:00
|
|
|
if (this.getStackInSlot(this.output) == ItemStack.EMPTY) {
|
|
|
|
this.setInventorySlotContents(this.output, itemstack.copy());
|
|
|
|
} else if (this.getStackInSlot(this.output).isItemEqual(itemstack)) {
|
|
|
|
this.getStackInSlot(this.output).grow(itemstack.getCount());
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
2017-01-07 22:11:54 +01:00
|
|
|
if (this.getStackInSlot(this.input1).getCount() > 1) {
|
|
|
|
this.decrStackSize(this.input1, 1);
|
2016-10-08 21:46:16 +02:00
|
|
|
} else {
|
2017-01-07 22:11:54 +01:00
|
|
|
this.setInventorySlotContents(this.input1, ItemStack.EMPTY);
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
public boolean canSmelt() {
|
2017-01-07 22:11:54 +01:00
|
|
|
if (this.getStackInSlot(this.input1) == ItemStack.EMPTY) {
|
2016-03-25 10:47:34 +01:00
|
|
|
return false;
|
2016-10-08 21:46:16 +02:00
|
|
|
} else {
|
2017-01-07 22:11:54 +01:00
|
|
|
final ItemStack itemstack = FurnaceRecipes.instance().getSmeltingResult(this.getStackInSlot(this.input1));
|
2016-12-06 19:22:18 +01:00
|
|
|
if (itemstack == ItemStack.EMPTY)
|
2016-03-25 10:47:34 +01:00
|
|
|
return false;
|
2017-01-07 22:11:54 +01:00
|
|
|
if (this.getStackInSlot(this.output) == ItemStack.EMPTY)
|
2016-03-25 10:47:34 +01:00
|
|
|
return true;
|
2017-01-07 22:11:54 +01:00
|
|
|
if (!this.getStackInSlot(this.output).isItemEqual(itemstack))
|
2016-03-25 10:47:34 +01:00
|
|
|
return false;
|
2017-01-07 22:11:54 +01:00
|
|
|
final int result = this.getStackInSlot(this.output).getCount() + itemstack.getCount();
|
|
|
|
return result <= this.getInventoryStackLimit() && result <= itemstack.getMaxStackSize();
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
public boolean isBurning() {
|
2017-01-07 22:11:54 +01:00
|
|
|
return this.getEnergy() > this.cost;
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
2017-01-07 22:11:54 +01:00
|
|
|
public ItemStack getResultFor(final ItemStack stack) {
|
|
|
|
final 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() {
|
2017-01-07 22:11:54 +01:00
|
|
|
final IBlockState BlockStateContainer = this.world.getBlockState(this.pos);
|
2016-10-08 21:46:16 +02:00
|
|
|
if (BlockStateContainer.getBlock() instanceof BlockMachineBase) {
|
2017-01-07 22:11:54 +01:00
|
|
|
final BlockMachineBase blockMachineBase = (BlockMachineBase) BlockStateContainer.getBlock();
|
|
|
|
if (BlockStateContainer.getValue(BlockMachineBase.ACTIVE) != this.progress > 0)
|
|
|
|
blockMachineBase.setActive(this.progress > 0, this.world, this.pos);
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-01-07 22:11:54 +01:00
|
|
|
public boolean wrenchCanSetFacing(final EntityPlayer entityPlayer, final EnumFacing side) {
|
2016-03-25 10:47:34 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public EnumFacing getFacing() {
|
2017-01-07 22:11:54 +01:00
|
|
|
return this.getFacingEnum();
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-01-07 22:11:54 +01:00
|
|
|
public boolean wrenchCanRemove(final 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
|
2017-01-07 22:11:54 +01:00
|
|
|
public ItemStack getWrenchDrop(final EntityPlayer entityPlayer) {
|
2017-01-01 08:29:32 +01:00
|
|
|
return new ItemStack(ModBlocks.ELECTRIC_FURNACE, 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
|
2017-01-07 22:11:54 +01:00
|
|
|
public int[] getSlotsForFace(final EnumFacing side) {
|
|
|
|
return side == EnumFacing.DOWN ? TileElectricFurnace.SLOTS_BOTTOM : side == EnumFacing.UP ? TileElectricFurnace.SLOTS_TOP : TileElectricFurnace.SLOTS_SIDES;
|
2016-08-10 01:45:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-01-07 22:11:54 +01:00
|
|
|
public boolean canInsertItem(final int slotIndex, final ItemStack itemStack, final EnumFacing side) {
|
2016-08-10 01:45:07 +02:00
|
|
|
if (slotIndex == 2)
|
|
|
|
return false;
|
2017-01-07 22:11:54 +01:00
|
|
|
return this.isItemValidForSlot(slotIndex, itemStack);
|
2016-08-10 01:45:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-01-07 22:11:54 +01:00
|
|
|
public boolean canExtractItem(final int slotIndex, final ItemStack itemStack, final 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() {
|
2017-01-07 22:11:54 +01:00
|
|
|
return this.capacity;
|
2016-08-10 01:45:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-01-07 22:11:54 +01:00
|
|
|
public boolean canAcceptEnergy(final EnumFacing direction) {
|
2016-08-10 01:45:07 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-01-07 22:11:54 +01:00
|
|
|
public boolean canProvideEnergy(final 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() {
|
2017-01-07 22:11:54 +01:00
|
|
|
return this.inventory;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getBurnTime() {
|
|
|
|
return this.progress;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setBurnTime(final int burnTime) {
|
|
|
|
this.progress = burnTime;
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
2017-01-08 20:34:46 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public BuiltContainer createContainer(final EntityPlayer player) {
|
|
|
|
return new ContainerBuilder("electricfurnace").player(player.inventory).inventory(8, 84).hotbar(8, 142)
|
|
|
|
.addInventory().tile(this).slot(0, 56, 34).outputSlot(1, 116, 34).upgradeSlot(2, 152, 8)
|
|
|
|
.upgradeSlot(3, 152, 26).upgradeSlot(4, 152, 44).upgradeSlot(5, 152, 62).syncEnergyValue()
|
|
|
|
.syncIntegerValue(this::getBurnTime, this::setBurnTime).addInventory().create();
|
|
|
|
}
|
2016-02-20 04:07:56 +01:00
|
|
|
}
|