Updated the Industrial Sawmill to include a FluidTank and allow FluidStack input (someone make sure I did it right)
This commit is contained in:
parent
7790baaff8
commit
206f967d63
2 changed files with 103 additions and 2 deletions
|
@ -1,11 +1,16 @@
|
||||||
package techreborn.api.recipe.machines;
|
package techreborn.api.recipe.machines;
|
||||||
|
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.tileentity.TileEntity;
|
||||||
|
import net.minecraftforge.fluids.FluidStack;
|
||||||
import techreborn.api.recipe.BaseRecipe;
|
import techreborn.api.recipe.BaseRecipe;
|
||||||
|
import techreborn.tiles.TileIndustrialSawmill;
|
||||||
|
|
||||||
public class IndustrialSawmillRecipe extends BaseRecipe {
|
public class IndustrialSawmillRecipe extends BaseRecipe {
|
||||||
|
|
||||||
public IndustrialSawmillRecipe(ItemStack input1, ItemStack input2, ItemStack output1, ItemStack output2, ItemStack output3, int tickTime, int euPerTick) {
|
public FluidStack fluidStack;
|
||||||
|
|
||||||
|
public IndustrialSawmillRecipe(ItemStack input1, ItemStack input2, FluidStack fluidStack, ItemStack output1, ItemStack output2, ItemStack output3, int tickTime, int euPerTick) {
|
||||||
super("industrialSawmillRecipe", tickTime, euPerTick);
|
super("industrialSawmillRecipe", tickTime, euPerTick);
|
||||||
if (input1 != null)
|
if (input1 != null)
|
||||||
inputs.add(input1);
|
inputs.add(input1);
|
||||||
|
@ -17,5 +22,49 @@ public class IndustrialSawmillRecipe extends BaseRecipe {
|
||||||
addOutput(output2);
|
addOutput(output2);
|
||||||
if (output3 != null)
|
if (output3 != null)
|
||||||
addOutput(output3);
|
addOutput(output3);
|
||||||
|
this.fluidStack = fluidStack;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canCraft(TileEntity tile) {
|
||||||
|
if (fluidStack == null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (tile instanceof TileIndustrialSawmill) {
|
||||||
|
TileIndustrialSawmill sawmill = (TileIndustrialSawmill) tile;
|
||||||
|
if (sawmill.tank.getFluid() == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (sawmill.tank.getFluid().getFluidID() == fluidStack.getFluidID()) {
|
||||||
|
if (sawmill.tank.getFluidAmount() >= fluidStack.amount) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCraft(TileEntity tile) {
|
||||||
|
if (fluidStack == null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (tile instanceof TileIndustrialSawmill) {
|
||||||
|
TileIndustrialSawmill sawmill = (TileIndustrialSawmill) tile;
|
||||||
|
if (sawmill.tank.getFluid() == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (sawmill.tank.getFluid().getFluidID() == fluidStack.getFluidID()) {
|
||||||
|
if (sawmill.tank.getFluidAmount() >= fluidStack.amount) {
|
||||||
|
if (sawmill.tank.getFluidAmount() > 0) {
|
||||||
|
sawmill.tank.setFluid(new FluidStack(fluidStack.getFluid(), sawmill.tank.getFluidAmount() - fluidStack.amount));
|
||||||
|
} else {
|
||||||
|
sawmill.tank.setFluid(null);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,17 +9,21 @@ import net.minecraft.inventory.ISidedInventory;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
import net.minecraftforge.common.util.ForgeDirection;
|
||||||
|
import net.minecraftforge.fluids.*;
|
||||||
import techreborn.api.recipe.RecipeCrafter;
|
import techreborn.api.recipe.RecipeCrafter;
|
||||||
import techreborn.init.ModBlocks;
|
import techreborn.init.ModBlocks;
|
||||||
|
import techreborn.init.ModFluids;
|
||||||
import techreborn.util.Inventory;
|
import techreborn.util.Inventory;
|
||||||
|
import techreborn.util.Tank;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class TileIndustrialSawmill extends TileMachineBase implements IWrenchable, IEnergyTile, IInventory, ISidedInventory {
|
public class TileIndustrialSawmill extends TileMachineBase implements IWrenchable, IEnergyTile, IFluidHandler, IInventory, ISidedInventory {
|
||||||
|
|
||||||
public int tickTime;
|
public int tickTime;
|
||||||
public BasicSink energy;
|
public BasicSink energy;
|
||||||
public Inventory inventory = new Inventory(5, "TileIndustrialSawmill", 64);
|
public Inventory inventory = new Inventory(5, "TileIndustrialSawmill", 64);
|
||||||
|
public Tank tank = new Tank("TileGrinder", 16000, this);
|
||||||
public RecipeCrafter crafter;
|
public RecipeCrafter crafter;
|
||||||
|
|
||||||
public TileIndustrialSawmill()
|
public TileIndustrialSawmill()
|
||||||
|
@ -95,6 +99,7 @@ public class TileIndustrialSawmill extends TileMachineBase implements IWrenchabl
|
||||||
super.readFromNBT(tagCompound);
|
super.readFromNBT(tagCompound);
|
||||||
inventory.readFromNBT(tagCompound);
|
inventory.readFromNBT(tagCompound);
|
||||||
energy.readFromNBT(tagCompound);
|
energy.readFromNBT(tagCompound);
|
||||||
|
tank.readFromNBT(tagCompound);
|
||||||
crafter.readFromNBT(tagCompound);
|
crafter.readFromNBT(tagCompound);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,6 +109,7 @@ public class TileIndustrialSawmill extends TileMachineBase implements IWrenchabl
|
||||||
super.writeToNBT(tagCompound);
|
super.writeToNBT(tagCompound);
|
||||||
inventory.writeToNBT(tagCompound);
|
inventory.writeToNBT(tagCompound);
|
||||||
energy.writeToNBT(tagCompound);
|
energy.writeToNBT(tagCompound);
|
||||||
|
tank.writeToNBT(tagCompound);
|
||||||
crafter.writeToNBT(tagCompound);
|
crafter.writeToNBT(tagCompound);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,6 +136,52 @@ public class TileIndustrialSawmill extends TileMachineBase implements IWrenchabl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* IFluidHandler */
|
||||||
|
@Override
|
||||||
|
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
|
||||||
|
if(resource.getFluid() == FluidRegistry.WATER || resource.getFluid() == ModFluids.fluidMercury || resource.getFluid() == ModFluids.fluidSodiumpersulfate) {
|
||||||
|
int filled = tank.fill(resource, doFill);
|
||||||
|
tank.compareAndUpdate();
|
||||||
|
return filled;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) {
|
||||||
|
if (resource == null || !resource.isFluidEqual(tank.getFluid())) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
FluidStack fluidStack = tank.drain(resource.amount, doDrain);
|
||||||
|
tank.compareAndUpdate();
|
||||||
|
return fluidStack;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) {
|
||||||
|
FluidStack drained = tank.drain(maxDrain, doDrain);
|
||||||
|
tank.compareAndUpdate();
|
||||||
|
return drained;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canFill(ForgeDirection from, Fluid fluid) {
|
||||||
|
if(fluid == FluidRegistry.WATER) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canDrain(ForgeDirection from, Fluid fluid) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FluidTankInfo[] getTankInfo(ForgeDirection from) {
|
||||||
|
return new FluidTankInfo[] { tank.getInfo() };
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getSizeInventory() {
|
public int getSizeInventory() {
|
||||||
return inventory.getSizeInventory();
|
return inventory.getSizeInventory();
|
||||||
|
|
Loading…
Reference in a new issue