use of net.minecraftforge.fluids.IFluidHandler in project PneumaticCraft by MineMaarten.
the class ContainerAmadron method capShoppingAmount.
public int capShoppingAmount(int offerId, int wantedAmount, EntityPlayer player) {
IInventory inv = ItemAmadronTablet.getItemProvider(player.getCurrentEquippedItem());
IFluidHandler fluidHandler = ItemAmadronTablet.getLiquidProvider(player.getCurrentEquippedItem());
return capShoppingAmount(offers.get(offerId), wantedAmount, inv, fluidHandler, this);
}
use of net.minecraftforge.fluids.IFluidHandler in project PneumaticCraft by MineMaarten.
the class ItemAmadronTablet method onItemUse.
@Override
public boolean onItemUse(ItemStack tablet, EntityPlayer player, World world, int x, int y, int z, int par7, float par8, float par9, float par10) {
TileEntity te = world.getTileEntity(x, y, z);
if (te instanceof IFluidHandler) {
if (!world.isRemote) {
setLiquidProvidingLocation(tablet, x, y, z, world.provider.dimensionId);
player.addChatComponentMessage(new ChatComponentTranslation("message.amadronTable.setLiquidProvidingLocation", x, y, z, world.provider.dimensionId, world.provider.getDimensionName()));
}
} else if (te instanceof IInventory) {
if (!world.isRemote) {
setItemProvidingLocation(tablet, x, y, z, world.provider.dimensionId);
player.addChatComponentMessage(new ChatComponentTranslation("message.amadronTable.setItemProvidingLocation", x, y, z, world.provider.dimensionId, world.provider.getDimensionName()));
}
} else {
return false;
}
return true;
}
use of net.minecraftforge.fluids.IFluidHandler in project PneumaticCraft by MineMaarten.
the class TileEntityBase method processFluidItem.
protected void processFluidItem(int inputSlot, int outputSlot) {
IInventory inv = (IInventory) this;
IFluidHandler fluidHandler = (IFluidHandler) this;
FluidTankInfo tankInfo = fluidHandler.getTankInfo(ForgeDirection.UNKNOWN)[0];
if (inv.getStackInSlot(inputSlot) != null) {
ItemStack fluidContainer = inv.getStackInSlot(inputSlot);
if (tankInfo.fluid == null || tankInfo.fluid.isFluidEqual(fluidContainer)) {
FluidStack fluid = FluidContainerRegistry.getFluidForFilledItem(fluidContainer);
int amount = FluidContainerRegistry.BUCKET_VOLUME;
if (fluid == null) {
if (fluidContainer.getItem() instanceof IFluidContainerItem) {
IFluidContainerItem containerItem = (IFluidContainerItem) fluidContainer.getItem();
fluid = containerItem.getFluid(fluidContainer);
if (fluid != null && fluidHandler.canFill(ForgeDirection.UNKNOWN, fluid.getFluid())) {
amount = fluid != null ? fluid.amount : 0;
int availableSpace = tankInfo.capacity - (tankInfo.fluid != null ? tankInfo.fluid.amount : 0);
if (availableSpace >= amount) {
ItemStack singleFuelItem = fluidContainer.copy();
singleFuelItem.stackSize = 1;
FluidStack drainedStack = containerItem.drain(singleFuelItem, availableSpace, true);
if (fluidContainer.stackSize == 1 || inv.getStackInSlot(outputSlot) == null || canStack(singleFuelItem, inv.getStackInSlot(outputSlot))) {
fluidHandler.fill(ForgeDirection.UNKNOWN, drainedStack, true);
if (fluidContainer.stackSize == 1) {
inv.setInventorySlotContents(inputSlot, singleFuelItem);
} else {
inv.getStackInSlot(inputSlot).stackSize--;
if (inv.getStackInSlot(outputSlot) == null) {
inv.setInventorySlotContents(outputSlot, singleFuelItem);
} else {
inv.getStackInSlot(outputSlot).stackSize++;
}
}
}
}
}
}
} else if (fluidHandler.canFill(ForgeDirection.UNKNOWN, fluid.getFluid())) {
if (tankInfo.capacity - (tankInfo.fluid != null ? tankInfo.fluid.amount : 0) >= amount) {
ItemStack returnedItem = null;
FluidContainerData[] allFluidData = FluidContainerRegistry.getRegisteredFluidContainerData();
for (FluidContainerData fluidData : allFluidData) {
if (fluidData.filledContainer.isItemEqual(fluidContainer)) {
returnedItem = fluidData.emptyContainer;
break;
}
}
if (returnedItem == null || inv.getStackInSlot(outputSlot) == null || canStack(returnedItem, inv.getStackInSlot(outputSlot))) {
if (returnedItem != null) {
if (inv.getStackInSlot(outputSlot) == null) {
inv.setInventorySlotContents(outputSlot, returnedItem.copy());
} else {
inv.getStackInSlot(outputSlot).stackSize += returnedItem.stackSize;
}
}
fluidHandler.fill(ForgeDirection.UNKNOWN, new FluidStack(fluid.getFluid(), amount, fluid.tag), true);
inv.getStackInSlot(inputSlot).stackSize--;
if (inv.getStackInSlot(inputSlot).stackSize <= 0)
inv.setInventorySlotContents(inputSlot, null);
}
}
}
}
if (fluidContainer.getItem() instanceof IFluidContainerItem) {
if (((IFluidContainerItem) fluidContainer.getItem()).getFluid(fluidContainer) == null && (inv.getStackInSlot(outputSlot) == null || canStack(fluidContainer, inv.getStackInSlot(outputSlot)))) {
if (inv.getStackInSlot(outputSlot) == null) {
inv.setInventorySlotContents(outputSlot, fluidContainer);
} else {
inv.getStackInSlot(outputSlot).stackSize += fluidContainer.stackSize;
}
inv.setInventorySlotContents(inputSlot, null);
}
}
}
}
use of net.minecraftforge.fluids.IFluidHandler in project PneumaticCraft by MineMaarten.
the class TileEntityLiquidHopper method suckInItem.
@Override
protected boolean suckInItem(int maxItems) {
TileEntity inputInv = IOHelper.getNeighbor(this, inputDir);
if (inputInv instanceof IFluidHandler) {
IFluidHandler fluidHandler = (IFluidHandler) inputInv;
FluidStack fluid = fluidHandler.drain(inputDir.getOpposite(), maxItems * 100, false);
if (fluid != null && fluidHandler.canDrain(inputDir.getOpposite(), fluid.getFluid())) {
int filledFluid = fill(inputDir, fluid, true);
if (filledFluid > 0) {
fluidHandler.drain(inputDir.getOpposite(), filledFluid, true);
return true;
}
}
}
if (worldObj.isAirBlock(xCoord + inputDir.offsetX, yCoord + inputDir.offsetY, zCoord + inputDir.offsetZ)) {
for (EntityItem entity : getNeighborItems(this, inputDir)) {
if (!entity.isDead) {
List<ItemStack> returnedItems = new ArrayList<ItemStack>();
if (FluidUtils.tryInsertingLiquid(this, entity.getEntityItem(), false, 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 && worldObj.getBlockMetadata(xCoord + inputDir.offsetX, yCoord + inputDir.offsetY, zCoord + inputDir.offsetZ) == 0) {
Fluid fluid = FluidRegistry.lookupFluidForBlock(worldObj.getBlock(xCoord + inputDir.offsetX, yCoord + inputDir.offsetY, zCoord + inputDir.offsetZ));
if (fluid != null) {
if (fill(ForgeDirection.UNKNOWN, new FluidStack(fluid, 1000), false) == 1000) {
fill(ForgeDirection.UNKNOWN, new FluidStack(fluid, 1000), true);
worldObj.setBlockToAir(xCoord + inputDir.offsetX, yCoord + inputDir.offsetY, zCoord + inputDir.offsetZ);
return true;
}
}
}
return false;
}
use of net.minecraftforge.fluids.IFluidHandler in project PneumaticCraft by MineMaarten.
the class FluidUtils method tryInsertingLiquid.
public static boolean tryInsertingLiquid(TileEntity te, ItemStack liquidContainer, boolean creative, List<ItemStack> returnedItems) {
if (te instanceof IFluidHandler) {
IFluidHandler fluidHandler = (IFluidHandler) te;
if (liquidContainer != null) {
FluidStack fluid = FluidContainerRegistry.getFluidForFilledItem(liquidContainer);
if (fluid != null) {
fluid.amount = 1000;
if (fluidHandler.canFill(ForgeDirection.UNKNOWN, fluid.getFluid()) && fluidHandler.fill(ForgeDirection.UNKNOWN, fluid, false) == 1000) {
fluidHandler.fill(ForgeDirection.UNKNOWN, fluid, true);
if (!creative) {
liquidContainer.stackSize--;
ItemStack returnedItem = null;
FluidContainerData[] allFluidData = FluidContainerRegistry.getRegisteredFluidContainerData();
for (FluidContainerData fluidData : allFluidData) {
if (fluidData.filledContainer.isItemEqual(liquidContainer)) {
returnedItem = fluidData.emptyContainer;
break;
}
}
if (returnedItem != null) {
returnedItems.add(returnedItem.copy());
}
}
return true;
}
} else if (liquidContainer.getItem() instanceof IFluidContainerItem) {
IFluidContainerItem container = (IFluidContainerItem) liquidContainer.getItem();
fluid = container.getFluid(liquidContainer);
if (fluid != null) {
fluid = fluid.copy();
if (fluidHandler.canFill(ForgeDirection.UNKNOWN, fluid.getFluid()) && fluidHandler.fill(ForgeDirection.UNKNOWN, fluid, false) == fluid.amount) {
ItemStack returnedItem = liquidContainer.copy();
returnedItem.stackSize = 1;
container.drain(returnedItem, fluid.amount, true);
fluidHandler.fill(ForgeDirection.UNKNOWN, fluid, true);
if (!creative) {
liquidContainer.stackSize--;
returnedItems.add(returnedItem.copy());
}
return true;
}
}
}
}
}
return false;
}
Aggregations