TechReborn/src/main/java/techreborn/tiles/TileIndustrialElectrolyzer.java

182 lines
4.9 KiB
Java
Raw Normal View History

package techreborn.tiles;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
2015-11-23 15:45:16 +01:00
import net.minecraft.util.EnumFacing;
import reborncore.api.power.EnumPowerTier;
import reborncore.api.recipe.IRecipeCrafterProvider;
import reborncore.api.tile.IInventoryProvider;
2016-10-08 21:46:16 +02:00
import reborncore.common.IWrenchable;
import reborncore.common.powerSystem.TilePowerAcceptor;
2016-04-11 18:23:57 +02:00
import reborncore.common.recipes.RecipeCrafter;
import reborncore.common.util.Inventory;
import reborncore.common.util.ItemUtils;
2016-04-03 15:07:45 +02:00
import techreborn.api.Reference;
import techreborn.client.container.IContainerProvider;
import techreborn.client.container.builder.BuiltContainer;
import techreborn.client.container.builder.ContainerBuilder;
import techreborn.init.ModBlocks;
import techreborn.items.DynamicCell;
public class TileIndustrialElectrolyzer extends TilePowerAcceptor
implements IWrenchable, IInventoryProvider, ISidedInventory, IRecipeCrafterProvider, IContainerProvider {
2016-03-25 10:47:34 +01:00
public int tickTime;
public Inventory inventory = new Inventory(8, "TileIndustrialElectrolyzer", 64, this);
public RecipeCrafter crafter;
2016-10-08 21:46:16 +02:00
public TileIndustrialElectrolyzer() {
super(2);
2016-03-25 10:47:34 +01:00
// Input slots
final int[] inputs = new int[2];
2016-03-25 10:47:34 +01:00
inputs[0] = 0;
inputs[1] = 1;
final int[] outputs = new int[4];
2016-03-25 10:47:34 +01:00
outputs[0] = 2;
outputs[1] = 3;
outputs[2] = 4;
outputs[3] = 5;
this.crafter = new RecipeCrafter(Reference.industrialElectrolyzerRecipe, this, 2, 4, this.inventory, inputs, outputs);
2016-03-25 10:47:34 +01:00
}
@Override
2016-10-08 21:46:16 +02:00
public void updateEntity() {
super.updateEntity();
this.crafter.updateEntity();
this.charge(6);
2016-03-25 10:47:34 +01:00
}
@Override
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() {
return this.getFacingEnum();
2016-03-25 10:47:34 +01:00
}
@Override
public boolean wrenchCanRemove(final EntityPlayer entityPlayer) {
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
public ItemStack getWrenchDrop(final EntityPlayer entityPlayer) {
return new ItemStack(ModBlocks.INDUSTRIAL_ELECTROLYZER, 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;
}
@Override
public void readFromNBT(final NBTTagCompound tagCompound) {
2016-03-25 10:47:34 +01:00
super.readFromNBT(tagCompound);
this.crafter.readFromNBT(tagCompound);
2016-03-25 10:47:34 +01:00
}
@Override
public NBTTagCompound writeToNBT(final NBTTagCompound tagCompound) {
2016-03-25 10:47:34 +01:00
super.writeToNBT(tagCompound);
this.crafter.writeToNBT(tagCompound);
2016-05-18 17:53:54 +02:00
return tagCompound;
2016-03-25 10:47:34 +01:00
}
// @Override
// public void addWailaInfo(List<String> info)
// {
// super.addWailaInfo(info);
// info.add("Power Stored " + energy.getEnergyStored() +" EU");
// if(crafter.currentRecipe !=null){
// info.add("Power Usage " + crafter.currentRecipe.euPerTick() + " EU/t");
// }
// }
// ISidedInventory
@Override
public int[] getSlotsForFace(final EnumFacing side) {
2016-03-25 10:47:34 +01:00
return side == EnumFacing.DOWN ? new int[] { 0, 1, 2, 3, 4, 5 } : new int[] { 0, 1, 2, 3, 4, 5 };
}
@Override
public boolean canInsertItem(final int slotIndex, final ItemStack stack, final EnumFacing side) {
if (slotIndex > 1)
2016-03-25 10:47:34 +01:00
return false;
if(slotIndex == 1)
return ItemUtils.isItemEqual(stack, DynamicCell.getEmptyCell(1), true, true);
return !ItemUtils.isItemEqual(stack, DynamicCell.getEmptyCell(1), true, true);
2016-03-25 10:47:34 +01:00
}
@Override
public boolean canExtractItem(final int slotIndex, final ItemStack itemStack, final EnumFacing side) {
2016-03-25 10:47:34 +01:00
return slotIndex == 2 || slotIndex == 3 || slotIndex == 4 || slotIndex == 5;
}
public int getProgressScaled(final int scale) {
if (this.crafter.currentTickTime != 0) {
return this.crafter.currentTickTime * scale / this.crafter.currentNeededTicks;
2016-03-25 10:47:34 +01:00
}
return 0;
}
@Override
2016-10-08 21:46:16 +02:00
public double getMaxPower() {
return 1000;
}
@Override
public boolean canAcceptEnergy(final EnumFacing direction) {
return true;
}
@Override
public boolean canProvideEnergy(final EnumFacing direction) {
return false;
}
@Override
2016-10-08 21:46:16 +02:00
public double getMaxOutput() {
return 0;
}
@Override
2016-10-08 21:46:16 +02:00
public double getMaxInput() {
return 128;
2016-03-25 10:47:34 +01:00
}
@Override
2016-10-08 21:46:16 +02:00
public EnumPowerTier getTier() {
return EnumPowerTier.LOW;
2016-03-25 10:47:34 +01:00
}
@Override
public Inventory getInventory() {
return this.inventory;
}
@Override
public RecipeCrafter getRecipeCrafter() {
return this.crafter;
}
@Override
public BuiltContainer createContainer(final EntityPlayer player) {
return new ContainerBuilder("industrialelectrolyzer").player(player.inventory).inventory(8, 84).hotbar(8, 142)
.addInventory().tile(this)
.filterSlot(1, 50, 51, stack -> ItemUtils.isItemEqual(stack, DynamicCell.getEmptyCell(1), true, true))
.filterSlot(0, 80, 51, stack -> !ItemUtils.isItemEqual(stack, DynamicCell.getEmptyCell(1), true, true))
.outputSlot(2, 50, 19).outputSlot(3, 70, 19).outputSlot(4, 90, 19).outputSlot(5, 110, 19)
.energySlot(6, 18, 51).syncEnergyValue().syncCrafterValue().addInventory().create();
}
}