use of net.minecraftforge.fluids.IFluidHandler in project Minechem by iopleke.
the class MoleculeItem method onItemUseFirst.
@Override
public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
TileEntity te = world.getTileEntity(x, y, z);
boolean result = !world.isRemote;
if (te != null && te instanceof IFluidHandler && !player.isSneaking() && !(te instanceof IInventory)) {
int filled = 0;
for (int i = 0; i < 6; i++) {
FluidStack fluidStack = new FluidStack(FluidRegistry.WATER, 125);
if (getMolecule(stack) != MoleculeEnum.water) {
FluidMolecule fluid = FluidHelper.molecules.get(getMolecule(stack));
if (fluid == null) {
return super.onItemUseFirst(stack, player, world, x, y, z, side, hitX, hitY, hitZ);
}
fluidStack = new FluidStack(fluid, 125);
}
filled = ((IFluidHandler) te).fill(ForgeDirection.getOrientation(i), fluidStack, false);
if (filled > 0) {
if (result) {
((IFluidHandler) te).fill(ForgeDirection.getOrientation(i), fluidStack, true);
}
if (!player.capabilities.isCreativeMode) {
MinechemUtil.incPlayerInventory(stack, -1, player, new ItemStack(MinechemItemsRegistration.element, 1, 0));
}
return result || stack.stackSize <= 0;
}
}
return result;
}
return super.onItemUseFirst(stack, player, world, x, y, z, side, hitX, hitY, hitZ);
}
use of net.minecraftforge.fluids.IFluidHandler in project Minechem by iopleke.
the class ElementItem method onItemUseFirst.
@Override
public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
TileEntity te = world.getTileEntity(x, y, z);
boolean result = !world.isRemote;
if (te != null && te instanceof IFluidHandler && !player.isSneaking() && !(te instanceof IInventory)) {
if (stack.getItemDamage() != 0) {
int filled = 0;
for (int i = 0; i < 6; i++) {
FluidElement fluid = FluidHelper.elements.get(getElement(stack));
if (fluid == null) {
return super.onItemUseFirst(stack, player, world, x, y, z, side, hitX, hitY, hitZ);
}
filled = ((IFluidHandler) te).fill(ForgeDirection.getOrientation(i), new FluidStack(fluid, 125), false);
if (filled > 0) {
if (result) {
((IFluidHandler) te).fill(ForgeDirection.getOrientation(i), new FluidStack(FluidHelper.elements.get(getElement(stack)), 125), true);
}
if (!player.capabilities.isCreativeMode) {
MinechemUtil.incPlayerInventory(stack, -1, player, new ItemStack(MinechemItemsRegistration.element, 1, 0));
}
return result || stack.stackSize <= 0;
}
}
} else {
FluidStack drained = null;
Fluid fluid = MinechemUtil.getFluid((IFluidHandler) te);
ElementEnum element = MinechemUtil.getElement(fluid);
if (element != null) {
for (int i = 0; i < 6; i++) {
drained = ((IFluidHandler) te).drain(ForgeDirection.getOrientation(i), new FluidStack(fluid, 125), false);
if (drained != null && drained.amount > 0) {
if (result) {
((IFluidHandler) te).drain(ForgeDirection.getOrientation(i), new FluidStack(fluid, 125), true);
}
if (!player.capabilities.isCreativeMode) {
MinechemUtil.incPlayerInventory(stack, -1, player, new ItemStack(MinechemItemsRegistration.element, 1, element.atomicNumber()));
}
return result;
}
}
} else {
MoleculeEnum molecule = MinechemUtil.getMolecule(fluid);
if (fluid == FluidRegistry.WATER) {
molecule = MoleculeEnum.water;
}
if (molecule != null) {
for (int i = 0; i < 6; i++) {
drained = ((IFluidHandler) te).drain(ForgeDirection.getOrientation(i), new FluidStack(fluid, 125), false);
if (drained != null && drained.amount > 0) {
if (result) {
((IFluidHandler) te).drain(ForgeDirection.getOrientation(i), new FluidStack(fluid, 125), true);
}
if (!player.capabilities.isCreativeMode) {
MinechemUtil.incPlayerInventory(stack, -1, player, new ItemStack(MinechemItemsRegistration.molecule, 1, molecule.id()));
}
return result;
}
}
}
}
}
return result;
}
return super.onItemUseFirst(stack, player, world, x, y, z, side, hitX, hitY, hitZ);
}
use of net.minecraftforge.fluids.IFluidHandler in project PneumaticCraft by MineMaarten.
the class DroneAILiquidExport method fillTank.
private boolean fillTank(ChunkPosition pos, boolean simulate) {
if (drone.getTank().getFluidAmount() == 0) {
drone.addDebugEntry("gui.progWidget.liquidExport.debug.emptyDroneTank");
abort();
return false;
} else {
TileEntity te = drone.getWorld().getTileEntity(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ);
if (te instanceof IFluidHandler) {
IFluidHandler tank = (IFluidHandler) te;
FluidStack exportedFluid = drone.getTank().drain(Integer.MAX_VALUE, false);
if (exportedFluid != null && ((ILiquidFiltered) widget).isFluidValid(exportedFluid.getFluid())) {
for (int i = 0; i < 6; i++) {
if (((ISidedWidget) widget).getSides()[i]) {
int filledAmount = tank.fill(ForgeDirection.getOrientation(i), exportedFluid, false);
if (filledAmount > 0) {
if (((ICountWidget) widget).useCount())
filledAmount = Math.min(filledAmount, getRemainingCount());
if (!simulate) {
decreaseCount(tank.fill(ForgeDirection.getOrientation(i), drone.getTank().drain(filledAmount, true), true));
}
return true;
}
}
}
drone.addDebugEntry("gui.progWidget.liquidExport.debug.filledToMax", pos);
} else {
drone.addDebugEntry("gui.progWidget.liquidExport.debug.noValidFluid");
}
} else if (((ILiquidExport) widget).isPlacingFluidBlocks() && (!((ICountWidget) widget).useCount() || getRemainingCount() >= 1000)) {
Block fluidBlock = drone.getTank().getFluid().getFluid().getBlock();
if (drone.getTank().getFluidAmount() >= 1000 && fluidBlock != null && drone.getWorld().isAirBlock(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ)) {
if (!simulate) {
decreaseCount(1000);
drone.getTank().drain(1000, true);
drone.getWorld().setBlock(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ, fluidBlock);
}
return true;
}
}
return false;
}
}
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 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;
}
Aggregations