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

266 lines
7.1 KiB
Java
Raw Normal View History

2015-04-28 00:51:06 +02:00
package techreborn.tiles;
2016-05-12 20:16:40 +02:00
import reborncore.common.IWrenchable;
2015-04-28 00:51:06 +02:00
import net.minecraft.entity.player.EntityPlayer;
2015-06-09 00:22:06 +02:00
import net.minecraft.inventory.ISidedInventory;
2015-04-28 00:51:06 +02:00
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
2015-06-25 17:40:39 +02:00
import net.minecraft.tileentity.TileEntity;
2015-11-23 15:45:16 +01:00
import net.minecraft.util.EnumFacing;
2016-03-15 09:13:05 +01:00
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.fluids.*;
import reborncore.api.power.EnumPowerTier;
import reborncore.api.recipe.IRecipeCrafterProvider;
import reborncore.api.tile.IInventoryProvider;
import reborncore.common.recipes.RecipeCrafter;
import reborncore.common.tile.TilePowerAcceptor;
2015-11-11 18:12:59 +01:00
import reborncore.common.util.FluidUtils;
2015-11-08 13:15:45 +01:00
import reborncore.common.util.Inventory;
import reborncore.common.util.Tank;
import techreborn.api.Reference;
2016-04-03 15:25:46 +02:00
import techreborn.api.recipe.ITileRecipeHandler;
import techreborn.api.recipe.machines.IndustrialGrinderRecipe;
2015-05-10 22:45:43 +02:00
import techreborn.config.ConfigTechReborn;
2015-04-28 00:51:06 +02:00
import techreborn.init.ModBlocks;
import techreborn.init.ModFluids;
2015-04-28 00:51:06 +02:00
public class TileIndustrialGrinder extends TilePowerAcceptor implements IWrenchable, IFluidHandler, IInventoryProvider, ISidedInventory, ITileRecipeHandler<IndustrialGrinderRecipe>, IRecipeCrafterProvider {
2016-03-25 10:47:34 +01:00
public static final int TANK_CAPACITY = 16000;
public int tickTime;
public Inventory inventory = new Inventory(6, "TileGrinder", 64, this);
public Tank tank = new Tank("TileGrinder", TANK_CAPACITY, this);
public RecipeCrafter crafter;
public int connectionStatus;
public TileIndustrialGrinder() {
2016-03-25 10:47:34 +01:00
// TODO configs
int[] inputs = new int[2];
inputs[0] = 0;
inputs[1] = 1;
int[] outputs = new int[4];
outputs[0] = 2;
outputs[1] = 3;
outputs[2] = 4;
outputs[3] = 5;
crafter = new RecipeCrafter(Reference.industrialGrinderRecipe, this, 1, 4, inventory, inputs, outputs);
}
@Override
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, EnumFacing side) {
2016-03-25 10:47:34 +01:00
return false;
}
@Override
public EnumFacing getFacing() {
2016-03-25 10:47:34 +01:00
return getFacingEnum();
}
@Override
public boolean wrenchCanRemove(EntityPlayer entityPlayer) {
return entityPlayer.isSneaking();
2016-03-25 10:47:34 +01:00
}
@Override
public float getWrenchDropRate() {
2016-03-25 10:47:34 +01:00
return 1.0F;
}
@Override
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
2016-03-25 10:47:34 +01:00
return new ItemStack(ModBlocks.IndustrialGrinder, 1);
}
public boolean isComplete() {
2016-03-25 10:47:34 +01:00
return false;
}
public boolean getMutliBlock() {
for (EnumFacing direction : EnumFacing.values()) {
2016-03-25 10:47:34 +01:00
TileEntity tileEntity = worldObj.getTileEntity(new BlockPos(getPos().getX() + direction.getFrontOffsetX(),
getPos().getY() + direction.getFrontOffsetY(), getPos().getZ() + direction.getFrontOffsetZ()));
if (tileEntity instanceof TileMachineCasing) {
2016-03-25 10:47:34 +01:00
if (((TileMachineCasing) tileEntity).isConnected()
&& ((TileMachineCasing) tileEntity).getMultiblockController().isAssembled()
&& ((TileMachineCasing) tileEntity).getMultiblockController().height == 3) {
2016-03-25 10:47:34 +01:00
connectionStatus = 1;
return true;
}
}
}
connectionStatus = 0;
return false;
}
@Override
public void update() {
super.update();
if (getMutliBlock()) {
2016-03-25 10:47:34 +01:00
crafter.updateEntity();
}
FluidUtils.drainContainers(this, inventory, 0, 5);
FluidUtils.drainContainers(this, inventory, 1, 5);
}
@Override
public void readFromNBT(NBTTagCompound tagCompound) {
2016-03-25 10:47:34 +01:00
super.readFromNBT(tagCompound);
tank.readFromNBT(tagCompound);
crafter.readFromNBT(tagCompound);
}
@Override
public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) {
2016-03-25 10:47:34 +01:00
super.writeToNBT(tagCompound);
tank.writeToNBT(tagCompound);
crafter.writeToNBT(tagCompound);
2016-05-18 17:53:54 +02:00
return tagCompound;
2016-03-25 10:47:34 +01:00
}
@Override
public void invalidate() {
2016-03-25 10:47:34 +01:00
super.invalidate();
}
@Override
public void onChunkUnload() {
2016-03-25 10:47:34 +01:00
super.onChunkUnload();
}
/* IFluidHandler */
@Override
public int fill(EnumFacing from, FluidStack resource, boolean doFill) {
2016-03-25 10:47:34 +01:00
if (resource.getFluid() == FluidRegistry.WATER || resource.getFluid() == ModFluids.fluidMercury
|| resource.getFluid() == ModFluids.fluidSodiumpersulfate) {
2016-03-25 10:47:34 +01:00
int filled = tank.fill(resource, doFill);
tank.compareAndUpdate();
return filled;
}
return 0;
}
@Override
public FluidStack drain(EnumFacing from, FluidStack resource, boolean doDrain) {
if (resource == null || !resource.isFluidEqual(tank.getFluid())) {
2016-03-25 10:47:34 +01:00
return null;
}
FluidStack fluidStack = tank.drain(resource.amount, doDrain);
tank.compareAndUpdate();
return fluidStack;
}
@Override
public FluidStack drain(EnumFacing from, int maxDrain, boolean doDrain) {
2016-03-25 10:47:34 +01:00
FluidStack drained = tank.drain(maxDrain, doDrain);
tank.compareAndUpdate();
return drained;
}
@Override
public boolean canFill(EnumFacing from, Fluid fluid) {
return fluid == FluidRegistry.WATER || fluid == ModFluids.fluidMercury || fluid == ModFluids.fluidSodiumpersulfate;
2016-03-25 10:47:34 +01:00
}
@Override
public boolean canDrain(EnumFacing from, Fluid fluid) {
2016-03-25 10:47:34 +01:00
return false;
}
@Override
public FluidTankInfo[] getTankInfo(EnumFacing from) {
return new FluidTankInfo[]{tank.getInfo()};
2016-03-25 10:47:34 +01:00
}
// ISidedInventory
@Override
public int[] getSlotsForFace(EnumFacing side) {
return side == EnumFacing.DOWN ? new int[]{0, 1, 2, 3, 4, 5} : new int[]{0, 1, 2, 3, 4, 5};
2016-03-25 10:47:34 +01:00
}
@Override
public boolean canInsertItem(int slotIndex, ItemStack itemStack, EnumFacing side) {
2016-03-25 10:47:34 +01:00
if (slotIndex >= 2)
return false;
return isItemValidForSlot(slotIndex, itemStack);
}
@Override
public boolean canExtractItem(int slotIndex, ItemStack itemStack, EnumFacing side) {
2016-03-25 10:47:34 +01:00
return slotIndex == 2 || slotIndex == 3 || slotIndex == 4 || slotIndex == 5;
}
public int getProgressScaled(int scale) {
if (crafter.currentTickTime != 0) {
2016-03-25 10:47:34 +01:00
return crafter.currentTickTime * scale / crafter.currentNeededTicks;
}
return 0;
}
@Override
public double getMaxPower() {
return 64000;
2016-03-25 10:47:34 +01:00
}
@Override
public EnumPowerTier getTier() {
return EnumPowerTier.MEDIUM;
2016-03-25 10:47:34 +01:00
}
2016-04-03 15:25:46 +02:00
@Override
public boolean canCraft(TileEntity tile, IndustrialGrinderRecipe recipe) {
if (recipe.fluidStack == null) {
return true;
}
if (tile instanceof TileIndustrialGrinder) {
TileIndustrialGrinder grinder = (TileIndustrialGrinder) tile;
if (grinder.tank.getFluid() == null) {
return false;
}
if (grinder.tank.getFluid() == recipe.fluidStack) {
if (grinder.tank.getFluidAmount() >= recipe.fluidStack.amount) {
return true;
}
}
}
return false;
}
@Override
public boolean onCraft(TileEntity tile, IndustrialGrinderRecipe recipe) {
if (recipe.fluidStack == null) {
return true;
}
if (tile instanceof TileIndustrialGrinder) {
TileIndustrialGrinder grinder = (TileIndustrialGrinder) tile;
if (grinder.tank.getFluid() == null) {
return false;
}
if (grinder.tank.getFluid() == recipe.fluidStack) {
if (grinder.tank.getFluidAmount() >= recipe.fluidStack.amount) {
if (grinder.tank.getFluidAmount() > 0) {
grinder.tank.setFluid(new FluidStack(recipe.fluidStack.getFluid(),
grinder.tank.getFluidAmount() - recipe.fluidStack.amount));
} else {
grinder.tank.setFluid(null);
}
return true;
}
}
}
return false;
}
@Override
public Inventory getInventory() {
return inventory;
}
@Override
public RecipeCrafter getRecipeCrafter() {
return crafter;
}
2015-04-28 00:51:06 +02:00
}