use of net.minecraftforge.fluids.FluidStack in project PneumaticCraft by MineMaarten.
the class RecipeFluid method matches.
@Override
public boolean matches(InventoryCrafting inv, World world) {
if (fluidIndex >= inv.getSizeInventory())
return false;
ItemStack stack = inv.getStackInSlot(fluidIndex);
FluidStack otherFluid = FluidContainerRegistry.getFluidForFilledItem(stack);
if (otherFluid != null && otherFluid.isFluidEqual(fluidStack) && otherFluid.amount == fluidStack.amount) {
recipe.getInput()[fluidIndex] = stack.copy();
boolean matches = recipe.matches(inv, world);
recipe.getInput()[fluidIndex] = originalStack;
return matches;
} else {
return false;
}
}
use of net.minecraftforge.fluids.FluidStack in project PneumaticCraft by MineMaarten.
the class FarmLogicSquid method tryPlaceSoil.
private boolean tryPlaceSoil(int x, int y, int z, boolean isLast) {
if (housing.getWorld().getBlock(x, y, z).isReplaceable(housing.getWorld(), x, y, z)) {
if (!isLast && shouldTurnIntoWater(x, y, z)) {
if ((housing.getWorld().getBlock(x, y, z) != Blocks.water || housing.getWorld().getBlockMetadata(x, y, z) != 0) && housing.hasLiquid(new FluidStack(FluidRegistry.getFluid("water"), 1000))) {
housing.removeLiquid(new FluidStack(FluidRegistry.getFluid("water"), 1000));
housing.getWorld().setBlock(x, y, z, Blocks.water);
return true;
}
} else {
for (Block res : Forestry.farmStructureBlocks) {
if (housing.hasResources(new ItemStack[] { new ItemStack(res) })) {
housing.removeResources(new ItemStack[] { new ItemStack(res) });
housing.getWorld().setBlock(x, y, z, res);
return true;
}
}
}
}
return false;
}
use of net.minecraftforge.fluids.FluidStack in project PneumaticCraft by MineMaarten.
the class TileEntityBase method autoExportLiquid.
public void autoExportLiquid() {
FluidStack extractedStack = ((IFluidHandler) this).drain(ForgeDirection.UNKNOWN, Integer.MAX_VALUE, false);
if (extractedStack != null) {
for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
TileEntity te = getTileCache()[d.ordinal()].getTileEntity();
if (te instanceof IFluidHandler) {
if (((IFluidHandler) te).canFill(d.getOpposite(), extractedStack.getFluid())) {
int filledAmount = ((IFluidHandler) te).fill(d.getOpposite(), extractedStack, true);
((IFluidHandler) this).drain(ForgeDirection.UNKNOWN, filledAmount, true);
extractedStack.amount -= filledAmount;
if (extractedStack.amount <= 0)
break;
}
}
}
}
}
use of net.minecraftforge.fluids.FluidStack in project PneumaticCraft by MineMaarten.
the class TileEntityLiquidHopper method exportItem.
@Override
protected boolean exportItem(int maxItems) {
ForgeDirection dir = ForgeDirection.getOrientation(getBlockMetadata());
if (tank.getFluid() != null) {
TileEntity neighbor = IOHelper.getNeighbor(this, dir);
if (neighbor instanceof IFluidHandler) {
IFluidHandler fluidHandler = (IFluidHandler) neighbor;
if (fluidHandler.canFill(dir.getOpposite(), tank.getFluid().getFluid())) {
FluidStack fluid = tank.getFluid().copy();
fluid.amount = Math.min(maxItems * 100, tank.getFluid().amount - (leaveMaterial ? 1000 : 0));
if (fluid.amount > 0) {
tank.getFluid().amount -= fluidHandler.fill(dir.getOpposite(), fluid, true);
if (tank.getFluidAmount() <= 0)
tank.setFluid(null);
return true;
}
}
}
}
if (worldObj.isAirBlock(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ)) {
for (EntityItem entity : getNeighborItems(this, dir)) {
if (!entity.isDead) {
List<ItemStack> returnedItems = new ArrayList<ItemStack>();
if (FluidUtils.tryExtractingLiquid(this, entity.getEntityItem(), returnedItems)) {
if (entity.getEntityItem().stackSize <= 0)
entity.setDead();
for (ItemStack stack : returnedItems) {
EntityItem item = new EntityItem(worldObj, entity.posX, entity.posY, entity.posZ, stack);
item.motionX = entity.motionX;
item.motionY = entity.motionY;
item.motionZ = entity.motionZ;
worldObj.spawnEntityInWorld(item);
}
return true;
}
}
}
}
if (getUpgrades(ItemMachineUpgrade.UPGRADE_DISPENSER_DAMAGE) > 0) {
if (worldObj.isAirBlock(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ)) {
FluidStack extractedFluid = drain(ForgeDirection.UNKNOWN, 1000, false);
if (extractedFluid != null && extractedFluid.amount == 1000) {
Block fluidBlock = extractedFluid.getFluid().getBlock();
if (fluidBlock != null) {
drain(ForgeDirection.UNKNOWN, 1000, true);
worldObj.setBlock(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ, fluidBlock);
}
}
}
}
return false;
}
use of net.minecraftforge.fluids.FluidStack in project PneumaticCraft by MineMaarten.
the class FluidUtils method tryExtractingLiquid.
public static boolean tryExtractingLiquid(TileEntity te, ItemStack liquidContainer, List<ItemStack> returnedItems) {
if (te instanceof IFluidHandler) {
IFluidHandler fluidHandler = (IFluidHandler) te;
if (liquidContainer != null) {
int containerCapacity = FluidContainerRegistry.getContainerCapacity(liquidContainer);
if (containerCapacity > 0 || liquidContainer.getItem() == Items.bucket) {
if (containerCapacity == 0)
containerCapacity = 1000;
FluidStack extractedLiquid = fluidHandler.drain(ForgeDirection.UNKNOWN, containerCapacity, false);
if (extractedLiquid != null && extractedLiquid.amount == containerCapacity) {
ItemStack filledContainer = FluidContainerRegistry.fillFluidContainer(extractedLiquid, liquidContainer);
if (filledContainer != null) {
fluidHandler.drain(ForgeDirection.UNKNOWN, containerCapacity, true);
liquidContainer.stackSize--;
returnedItems.add(filledContainer.copy());
return true;
}
}
} else if (liquidContainer.getItem() instanceof IFluidContainerItem) {
IFluidContainerItem container = (IFluidContainerItem) liquidContainer.getItem();
ItemStack singleItem = liquidContainer.copy();
singleItem.stackSize = 1;
FluidStack extractedLiquid = fluidHandler.drain(ForgeDirection.UNKNOWN, container.getCapacity(singleItem), false);
if (extractedLiquid != null) {
int filledAmount = container.fill(singleItem, extractedLiquid, true);
if (filledAmount > 0) {
liquidContainer.stackSize--;
returnedItems.add(singleItem);
FluidStack fluid = extractedLiquid.copy();
fluid.amount = filledAmount;
fluidHandler.drain(ForgeDirection.UNKNOWN, fluid, true);
return true;
}
}
}
}
}
return false;
}
Aggregations