2016-07-24 21:26:15 +02:00
|
|
|
package techreborn.tiles.multiblock;
|
2015-04-28 00:51:06 +02:00
|
|
|
|
2016-07-24 21:26:15 +02:00
|
|
|
import net.minecraft.block.state.IBlockState;
|
2015-04-28 00:51:06 +02:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2016-07-24 21:26:15 +02:00
|
|
|
import net.minecraft.init.Blocks;
|
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;
|
2015-05-09 21:29:26 +02:00
|
|
|
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;
|
2016-04-11 18:50:00 +02:00
|
|
|
import net.minecraftforge.fluids.*;
|
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;
|
2016-04-11 18:43:54 +02:00
|
|
|
import reborncore.api.tile.IInventoryProvider;
|
2016-07-24 21:26:15 +02:00
|
|
|
import reborncore.common.IWrenchable;
|
2016-04-11 18:50:00 +02:00
|
|
|
import reborncore.common.recipes.RecipeCrafter;
|
2016-07-21 17:22:56 +02:00
|
|
|
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;
|
2016-04-11 18:50:00 +02:00
|
|
|
import techreborn.api.Reference;
|
2016-04-03 15:25:46 +02:00
|
|
|
import techreborn.api.recipe.ITileRecipeHandler;
|
|
|
|
import techreborn.api.recipe.machines.IndustrialGrinderRecipe;
|
2015-04-28 00:51:06 +02:00
|
|
|
import techreborn.init.ModBlocks;
|
2015-05-27 06:28:12 +02:00
|
|
|
import techreborn.init.ModFluids;
|
2015-04-28 00:51:06 +02:00
|
|
|
|
2016-07-24 21:26:15 +02:00
|
|
|
import static techreborn.tiles.multiblock.MultiblockChecker.*;
|
|
|
|
|
2016-07-21 17:22:56 +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 Inventory inventory = new Inventory(6, "TileGrinder", 64, this);
|
|
|
|
public Tank tank = new Tank("TileGrinder", TANK_CAPACITY, this);
|
|
|
|
public RecipeCrafter crafter;
|
2016-07-24 21:26:15 +02:00
|
|
|
public MultiblockChecker multiblockChecker;
|
2016-03-25 10:47:34 +01:00
|
|
|
|
2016-07-21 17:22:56 +02:00
|
|
|
public TileIndustrialGrinder() {
|
2016-07-24 21:26:15 +02:00
|
|
|
int[] inputs = new int[] {0};
|
|
|
|
int[] outputs = new int[] {2, 3, 4, 5};
|
2016-03-25 10:47:34 +01:00
|
|
|
crafter = new RecipeCrafter(Reference.industrialGrinderRecipe, this, 1, 4, inventory, inputs, outputs);
|
|
|
|
}
|
2016-07-24 21:26:15 +02:00
|
|
|
@Override
|
2016-07-21 17:22:56 +02:00
|
|
|
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, EnumFacing side) {
|
2016-07-24 21:26:15 +02:00
|
|
|
return true;
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-07-21 17:22:56 +02:00
|
|
|
public EnumFacing getFacing() {
|
2016-03-25 10:47:34 +01:00
|
|
|
return getFacingEnum();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-07-21 17:22:56 +02:00
|
|
|
public boolean wrenchCanRemove(EntityPlayer entityPlayer) {
|
2016-04-03 15:34:39 +02:00
|
|
|
return entityPlayer.isSneaking();
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-07-21 17:22:56 +02:00
|
|
|
public float getWrenchDropRate() {
|
2016-03-25 10:47:34 +01:00
|
|
|
return 1.0F;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-07-21 17:22:56 +02:00
|
|
|
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
|
2016-03-25 10:47:34 +01:00
|
|
|
return new ItemStack(ModBlocks.IndustrialGrinder, 1);
|
|
|
|
}
|
|
|
|
|
2016-07-21 17:22:56 +02:00
|
|
|
public boolean getMutliBlock() {
|
2016-07-24 21:26:15 +02:00
|
|
|
boolean down = multiblockChecker.checkRectY(1, 1, CASING_NORMAL, ZERO_OFFSET);
|
|
|
|
boolean up = multiblockChecker.checkRectY(1, 1, CASING_NORMAL, new BlockPos(0, 2, 0));
|
|
|
|
boolean blade = multiblockChecker.checkRingY(1, 1, CASING_REINFORCED, new BlockPos(0, 1, 0));
|
|
|
|
IBlockState centerBlock = multiblockChecker.getBlock(0, 1, 0);
|
|
|
|
boolean center = centerBlock.getBlock() == Blocks.WATER;
|
|
|
|
return down && center && blade && up;
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-07-21 17:22:56 +02:00
|
|
|
public void update() {
|
|
|
|
super.update();
|
2016-07-24 21:26:15 +02:00
|
|
|
|
|
|
|
if(multiblockChecker == null) {
|
|
|
|
BlockPos pos = getPos().offset(getFacing().getOpposite(), 2).down();
|
|
|
|
multiblockChecker = new MultiblockChecker(worldObj, pos);
|
|
|
|
}
|
|
|
|
|
2016-07-21 17:22:56 +02:00
|
|
|
if (getMutliBlock()) {
|
2016-03-25 10:47:34 +01:00
|
|
|
crafter.updateEntity();
|
|
|
|
}
|
|
|
|
FluidUtils.drainContainers(this, inventory, 1, 5);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-07-21 17:22:56 +02:00
|
|
|
public void readFromNBT(NBTTagCompound tagCompound) {
|
2016-03-25 10:47:34 +01:00
|
|
|
super.readFromNBT(tagCompound);
|
|
|
|
tank.readFromNBT(tagCompound);
|
|
|
|
crafter.readFromNBT(tagCompound);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-07-21 17:22:56 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/* IFluidHandler */
|
|
|
|
@Override
|
2016-07-21 17:22:56 +02:00
|
|
|
public int fill(EnumFacing from, FluidStack resource, boolean doFill) {
|
2016-07-24 21:26:15 +02:00
|
|
|
if (resource != null && canFill(from, resource.getFluid())) {
|
2016-03-25 10:47:34 +01:00
|
|
|
int filled = tank.fill(resource, doFill);
|
|
|
|
tank.compareAndUpdate();
|
|
|
|
return filled;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-07-21 17:22:56 +02:00
|
|
|
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
|
2016-07-21 17:22:56 +02:00
|
|
|
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
|
2016-07-21 17:22:56 +02:00
|
|
|
public boolean canFill(EnumFacing from, Fluid fluid) {
|
2016-04-03 15:34:39 +02:00
|
|
|
return fluid == FluidRegistry.WATER || fluid == ModFluids.fluidMercury || fluid == ModFluids.fluidSodiumpersulfate;
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-07-21 17:22:56 +02:00
|
|
|
public boolean canDrain(EnumFacing from, Fluid fluid) {
|
2016-03-25 10:47:34 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-07-21 17:22:56 +02:00
|
|
|
public FluidTankInfo[] getTankInfo(EnumFacing from) {
|
|
|
|
return new FluidTankInfo[]{tank.getInfo()};
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ISidedInventory
|
|
|
|
@Override
|
2016-07-21 17:22:56 +02:00
|
|
|
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
|
2016-07-21 17:22:56 +02:00
|
|
|
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
|
2016-07-21 17:22:56 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-07-21 17:22:56 +02:00
|
|
|
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
|
2016-07-21 17:22:56 +02:00
|
|
|
public double getMaxPower() {
|
|
|
|
return 64000;
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-07-21 17:22:56 +02:00
|
|
|
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) {
|
2016-07-24 21:26:15 +02:00
|
|
|
FluidStack recipeFluid = recipe.fluidStack;
|
|
|
|
FluidStack tankFluid = tank.getFluid();
|
|
|
|
if (recipe.fluidStack == null) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if(tankFluid == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (tankFluid.isFluidEqual(recipeFluid)) {
|
|
|
|
if (tankFluid.amount >= recipeFluid.amount) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2016-04-03 15:25:46 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onCraft(TileEntity tile, IndustrialGrinderRecipe recipe) {
|
2016-07-24 21:26:15 +02:00
|
|
|
FluidStack recipeFluid = recipe.fluidStack;
|
|
|
|
FluidStack tankFluid = tank.getFluid();
|
|
|
|
if (recipe.fluidStack == null) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if(tankFluid == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (tankFluid.isFluidEqual(recipeFluid)) {
|
|
|
|
if (tankFluid.amount >= recipeFluid.amount) {
|
|
|
|
if(tankFluid.amount == recipeFluid.amount)
|
|
|
|
tank.setFluid(null);
|
|
|
|
else tankFluid.amount -= recipeFluid.amount;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2016-04-03 15:25:46 +02:00
|
|
|
}
|
2016-04-11 18:43:54 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public Inventory getInventory() {
|
|
|
|
return inventory;
|
|
|
|
}
|
2016-04-11 18:50:00 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public RecipeCrafter getRecipeCrafter() {
|
|
|
|
return crafter;
|
|
|
|
}
|
2016-07-21 17:22:56 +02:00
|
|
|
|
2015-04-28 00:51:06 +02:00
|
|
|
}
|