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

213 lines
4.9 KiB
Java

package techreborn.tiles;
import ic2.api.tile.IWrenchable;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import reborncore.api.power.EnumPowerTier;
import reborncore.api.recipe.IRecipeCrafterProvider;
import reborncore.api.tile.IInventoryProvider;
import reborncore.common.misc.Location;
import reborncore.common.powerSystem.TilePowerAcceptor;
import reborncore.common.recipes.RecipeCrafter;
import reborncore.common.util.Inventory;
import techreborn.api.Reference;
import techreborn.blocks.BlockMachineCasing;
import techreborn.init.ModBlocks;
public class TileImplosionCompressor extends TilePowerAcceptor implements IWrenchable,IInventoryProvider, ISidedInventory, IRecipeCrafterProvider
{
public int tickTime;
public Inventory inventory = new Inventory(4, "TileImplosionCompressor", 64, this);
public RecipeCrafter crafter;
public TileImplosionCompressor()
{
super(1);
// Input slots
int[] inputs = new int[2];
inputs[0] = 0;
inputs[1] = 1;
int[] outputs = new int[2];
outputs[0] = 2;
outputs[1] = 3;
crafter = new RecipeCrafter(Reference.implosionCompressorRecipe, this, 2, 2, inventory, inputs, outputs);
}
@Override
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, EnumFacing side)
{
return false;
}
@Override
public EnumFacing getFacing()
{
return getFacingEnum();
}
@Override
public boolean wrenchCanRemove(EntityPlayer entityPlayer)
{
return entityPlayer.isSneaking();
}
@Override
public float getWrenchDropRate()
{
return 1.0F;
}
@Override
public ItemStack getWrenchDrop(EntityPlayer entityPlayer)
{
return new ItemStack(ModBlocks.ImplosionCompressor, 1);
}
public boolean getMutliBlock()
{
for (EnumFacing direction : EnumFacing.values())
{
TileEntity tileEntity = worldObj.getTileEntity(new BlockPos(getPos().getX() + direction.getFrontOffsetX(),
getPos().getY() + direction.getFrontOffsetY(), getPos().getZ() + direction.getFrontOffsetZ()));
if (tileEntity instanceof TileMachineCasing)
{
if (!((TileMachineCasing) tileEntity).isConnected())
{
return false;
}
if ((tileEntity.getBlockType() instanceof BlockMachineCasing))
{
int heat;
BlockMachineCasing machineCasing = (BlockMachineCasing) tileEntity.getBlockType();
heat = machineCasing.getHeatFromState(tileEntity.getWorld().getBlockState(tileEntity.getPos()));
Location location = new Location(getPos().getX(), getPos().getY(), getPos().getZ(), direction);
location.modifyPositionFromSide(direction, 1);
if (worldObj.getBlockState(new BlockPos(location.getX(), location.getY(), location.getZ()))
.getBlock().getUnlocalizedName().equals("tile.lava"))
{
heat += 500;
}
return true;
}
}
}
return false;
}
@Override
public void updateEntity()
{
super.updateEntity();
if (getMutliBlock())
{
crafter.updateEntity();
}
}
@Override
public void readFromNBT(NBTTagCompound tagCompound)
{
super.readFromNBT(tagCompound);
crafter.readFromNBT(tagCompound);
}
@Override
public void writeToNBT(NBTTagCompound tagCompound)
{
super.writeToNBT(tagCompound);
crafter.writeToNBT(tagCompound);
}
// @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(EnumFacing side)
{
return side == EnumFacing.DOWN ? new int[] { 0, 1, 2, 3 } : new int[] { 0, 1, 2, 3 };
}
@Override
public boolean canInsertItem(int slotIndex, ItemStack itemStack, EnumFacing side)
{
if (slotIndex >= 2)
return false;
return isItemValidForSlot(slotIndex, itemStack);
}
@Override
public boolean canExtractItem(int slotIndex, ItemStack itemStack, EnumFacing side)
{
return slotIndex == 2 || slotIndex == 3;
}
public int getProgressScaled(int scale)
{
if (crafter.currentTickTime != 0)
{
return crafter.currentTickTime * scale / crafter.currentNeededTicks;
}
return 0;
}
@Override
public double getMaxPower()
{
return 100000;
}
@Override
public boolean canAcceptEnergy(EnumFacing direction)
{
return true;
}
@Override
public boolean canProvideEnergy(EnumFacing direction)
{
return false;
}
@Override
public double getMaxOutput()
{
return 0;
}
@Override
public double getMaxInput()
{
return 64;
}
@Override
public EnumPowerTier getTier()
{
return EnumPowerTier.LOW;
}
@Override
public Inventory getInventory() {
return inventory;
}
@Override
public RecipeCrafter getRecipeCrafter() {
return crafter;
}
}