2015-04-24 16:01:19 +02:00
|
|
|
package techreborn.tiles;
|
|
|
|
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2015-06-08 23:12:11 +02:00
|
|
|
import net.minecraft.inventory.ISidedInventory;
|
2015-04-24 16:01:19 +02:00
|
|
|
import net.minecraft.item.ItemStack;
|
2015-05-09 21:29:26 +02:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2015-11-23 15:45:16 +01:00
|
|
|
import net.minecraft.util.EnumFacing;
|
2017-01-08 20:34:46 +01:00
|
|
|
|
2016-03-08 18:34:04 +01:00
|
|
|
import reborncore.api.power.EnumPowerTier;
|
2016-04-11 18:50:00 +02:00
|
|
|
import reborncore.api.recipe.IRecipeCrafterProvider;
|
2017-01-08 20:34:46 +01:00
|
|
|
import reborncore.api.recipe.RecipeHandler;
|
2016-04-11 18:43:54 +02:00
|
|
|
import reborncore.api.tile.IInventoryProvider;
|
2016-05-12 20:16:40 +02:00
|
|
|
import reborncore.common.IWrenchable;
|
2016-08-10 01:45:07 +02:00
|
|
|
import reborncore.common.powerSystem.TilePowerAcceptor;
|
2016-04-11 18:23:57 +02:00
|
|
|
import reborncore.common.recipes.RecipeCrafter;
|
2016-04-11 18:50:00 +02:00
|
|
|
import reborncore.common.util.Inventory;
|
2017-01-08 20:34:46 +01:00
|
|
|
import reborncore.common.util.ItemUtils;
|
|
|
|
|
2016-04-03 15:07:45 +02:00
|
|
|
import techreborn.api.Reference;
|
2017-01-08 20:34:46 +01:00
|
|
|
import techreborn.api.recipe.machines.AlloySmelterRecipe;
|
|
|
|
import techreborn.client.container.IContainerProvider;
|
|
|
|
import techreborn.client.container.builder.BuiltContainer;
|
|
|
|
import techreborn.client.container.builder.ContainerBuilder;
|
2016-04-11 18:50:00 +02:00
|
|
|
import techreborn.init.ModBlocks;
|
|
|
|
import techreborn.utils.upgrade.UpgradeHandler;
|
2015-04-24 16:01:19 +02:00
|
|
|
|
2017-01-08 20:34:46 +01:00
|
|
|
public class TileAlloySmelter 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, "TileAlloySmelter", 64, this);
|
|
|
|
public RecipeCrafter crafter;
|
2016-08-10 01:45:07 +02:00
|
|
|
public int capacity = 1000;
|
2016-03-25 10:47:34 +01:00
|
|
|
UpgradeHandler upgrades;
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
public TileAlloySmelter() {
|
2016-08-10 01:45:07 +02:00
|
|
|
super(1);
|
2016-03-25 10:47:34 +01:00
|
|
|
// Input slots
|
2017-01-08 20:34:46 +01:00
|
|
|
final int[] inputs = new int[2];
|
2016-03-25 10:47:34 +01:00
|
|
|
inputs[0] = 0;
|
|
|
|
inputs[1] = 1;
|
2017-01-08 20:34:46 +01:00
|
|
|
final int[] outputs = new int[1];
|
2016-03-25 10:47:34 +01:00
|
|
|
outputs[0] = 2;
|
2017-01-08 20:34:46 +01:00
|
|
|
this.crafter = new RecipeCrafter(Reference.alloySmelteRecipe, this, 2, 1, this.inventory, inputs, outputs);
|
|
|
|
this.upgrades = new UpgradeHandler(this.crafter, this.inventory, 4, 5, 6, 7);
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-07-21 17:22:56 +02:00
|
|
|
public void update() {
|
2016-07-27 12:51:03 +02:00
|
|
|
super.update();
|
2017-01-08 20:34:46 +01:00
|
|
|
this.crafter.updateEntity();
|
|
|
|
this.upgrades.tick();
|
|
|
|
this.charge(3);
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-01-08 20:34:46 +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-08 20:34:46 +01:00
|
|
|
return this.getFacingEnum();
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-01-08 20:34:46 +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-08 20:34:46 +01:00
|
|
|
public ItemStack getWrenchDrop(final EntityPlayer entityPlayer) {
|
2017-01-01 08:29:32 +01:00
|
|
|
return new ItemStack(ModBlocks.ALLOY_SMELTER, 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
|
2017-01-08 20:34:46 +01:00
|
|
|
public void readFromNBT(final NBTTagCompound tagCompound) {
|
2016-03-25 10:47:34 +01:00
|
|
|
super.readFromNBT(tagCompound);
|
2017-01-08 20:34:46 +01:00
|
|
|
this.inventory.readFromNBT(tagCompound);
|
|
|
|
this.crafter.readFromNBT(tagCompound);
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-01-08 20:34:46 +01:00
|
|
|
public NBTTagCompound writeToNBT(final NBTTagCompound tagCompound) {
|
2016-03-25 10:47:34 +01:00
|
|
|
super.writeToNBT(tagCompound);
|
2017-01-08 20:34:46 +01:00
|
|
|
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() + "/" +
|
|
|
|
// energy.getCapacity() +" EU");
|
|
|
|
// if(crafter.currentRecipe !=null){
|
|
|
|
// info.add("Power Usage " + crafter.currentRecipe.euPerTick() + " EU/t");
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
2016-08-10 01:45:07 +02:00
|
|
|
// ISidedInventory
|
|
|
|
@Override
|
2017-01-08 20:34:46 +01:00
|
|
|
public int[] getSlotsForFace(final EnumFacing side) {
|
2016-08-10 01:45:07 +02:00
|
|
|
return side == EnumFacing.DOWN ? new int[] { 0, 1, 2 } : new int[] { 0, 1, 2 };
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-01-08 20:34:46 +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-08 20:34:46 +01:00
|
|
|
return this.isItemValidForSlot(slotIndex, itemStack);
|
2016-08-10 01:45:07 +02:00
|
|
|
}
|
2016-03-25 10:47:34 +01:00
|
|
|
|
2016-08-10 01:45:07 +02:00
|
|
|
@Override
|
2017-01-08 20:34:46 +01:00
|
|
|
public boolean canExtractItem(final int slotIndex, final ItemStack itemStack, final EnumFacing side) {
|
2016-08-10 01:45:07 +02:00
|
|
|
return slotIndex == 2;
|
|
|
|
}
|
|
|
|
|
2017-01-08 20:34:46 +01:00
|
|
|
public int getProgressScaled(final int scale) {
|
|
|
|
if (this.crafter.currentTickTime != 0 && this.crafter.currentNeededTicks != 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() {
|
2017-01-08 20:34:46 +01:00
|
|
|
return this.capacity;
|
2016-08-10 01:45:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-01-08 20:34:46 +01:00
|
|
|
public boolean canAcceptEnergy(final EnumFacing direction) {
|
2016-08-10 01:45:07 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-01-08 20:34:46 +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;
|
|
|
|
}
|
|
|
|
|
|
|
|
@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-08 20:34:46 +01:00
|
|
|
return this.inventory;
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
2016-04-11 18:50:00 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public RecipeCrafter getRecipeCrafter() {
|
2017-01-08 20:34:46 +01:00
|
|
|
return this.crafter;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public BuiltContainer createContainer(final EntityPlayer player) {
|
|
|
|
return new ContainerBuilder("alloysmelter").player(player.inventory).inventory(8, 84).hotbar(8, 142)
|
|
|
|
.addInventory().tile(this)
|
|
|
|
.filterSlot(0, 47, 17,
|
|
|
|
stack -> RecipeHandler.recipeList.stream()
|
|
|
|
.anyMatch(recipe -> recipe instanceof AlloySmelterRecipe
|
2017-01-10 20:34:17 +01:00
|
|
|
&& ItemUtils.isInputEqual(recipe.getInputs().get(0), stack, true, true, true)))
|
2017-01-08 20:34:46 +01:00
|
|
|
.filterSlot(1, 65, 17,
|
|
|
|
stack -> RecipeHandler.recipeList.stream()
|
|
|
|
.anyMatch(recipe -> recipe instanceof AlloySmelterRecipe
|
2017-01-10 20:34:17 +01:00
|
|
|
&& ItemUtils.isInputEqual(recipe.getInputs().get(1), stack, true, true, true)))
|
2017-01-08 20:34:46 +01:00
|
|
|
.outputSlot(2, 116, 35).energySlot(3, 56, 53).upgradeSlot(4, 152, 8).upgradeSlot(5, 152, 26)
|
|
|
|
.upgradeSlot(6, 152, 44).upgradeSlot(7, 152, 62).syncEnergyValue().syncCrafterValue().addInventory()
|
|
|
|
.create();
|
2016-04-11 18:50:00 +02:00
|
|
|
}
|
2015-04-24 16:01:19 +02:00
|
|
|
}
|