net.minecraftforge.fluids.IFluidHandler Java Examples

The following examples show how to use net.minecraftforge.fluids.IFluidHandler. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FluidUtils.java    From CodeChickenCore with MIT License 6 votes vote down vote up
public static boolean fillTankWithContainer(IFluidHandler tank, EntityPlayer player) {
    ItemStack stack = player.getCurrentEquippedItem();
    FluidStack liquid = FluidContainerRegistry.getFluidForFilledItem(stack);

    if (liquid == null)
        return false;

    if (tank.fill(null, liquid, false) != liquid.amount && !player.capabilities.isCreativeMode)
        return false;

    tank.fill(null, liquid, true);

    if (!player.capabilities.isCreativeMode)
        InventoryUtils.consumeItem(player.inventory, player.inventory.currentItem);

    player.inventoryContainer.detectAndSendChanges();
    return true;
}
 
Example #2
Source File: FluidUtils.java    From CodeChickenCore with MIT License 6 votes vote down vote up
public static boolean emptyTankIntoContainer(IFluidHandler tank, EntityPlayer player, FluidStack tankLiquid) {
    ItemStack stack = player.getCurrentEquippedItem();

    if (!FluidContainerRegistry.isEmptyContainer(stack))
        return false;

    ItemStack filled = FluidContainerRegistry.fillFluidContainer(tankLiquid, stack);
    FluidStack liquid = FluidContainerRegistry.getFluidForFilledItem(filled);

    if (liquid == null || filled == null)
        return false;

    tank.drain(null, liquid.amount, true);

    if (!player.capabilities.isCreativeMode) {
        if (stack.stackSize == 1)
            player.inventory.setInventorySlotContents(player.inventory.currentItem, filled);
        else if (player.inventory.addItemStackToInventory(filled))
            stack.stackSize--;
        else
            return false;
    }

    player.inventoryContainer.detectAndSendChanges();
    return true;
}
 
Example #3
Source File: BlockBusFluidStorage.java    From ExtraCells1 with MIT License 6 votes vote down vote up
@Override
public void onNeighborBlockChange(World world, int x, int y, int z, int neighbourID)
{
	TileEntity blockTE = world.getBlockTileEntity(x, y, z);
	if (blockTE instanceof TileEntityBusFluidStorage)
	{
		TileEntityBusFluidStorage storageBus = (TileEntityBusFluidStorage) blockTE;
		if (!world.isRemote)
		{
			storageBus.updateGrid();
			PacketDispatcher.sendPacketToAllPlayers(world.getBlockTileEntity(x, y, z).getDescriptionPacket());
			MinecraftForge.EVENT_BUS.post(new GridStorageUpdateEvent(world, new WorldCoord(x, y, z), storageBus.getGrid()));
		}
		ForgeDirection blockOrientation = ForgeDirection.getOrientation(world.getBlockMetadata(x, y, z));

		TileEntity fluidHandler = world.getBlockTileEntity(x + blockOrientation.offsetX, y + blockOrientation.offsetY, z + blockOrientation.offsetZ);
		storageBus.setFluidHandler(fluidHandler instanceof IFluidHandler ? (IFluidHandler) fluidHandler : null);
	}
}
 
Example #4
Source File: BlockBusFluidImport.java    From ExtraCells1 with MIT License 6 votes vote down vote up
@Override
public void onNeighborBlockChange(World world, int x, int y, int z, int neighborID)
{
	super.onNeighborBlockChange(world, x, y, z, neighborID);
	if (!world.isRemote)
	{
		if (world.getBlockTileEntity(x, y, z) instanceof TileEntityBusFluidImport)
			((TileEntityBusFluidImport) world.getBlockTileEntity(x, y, z)).setRedstoneStatus(world.isBlockIndirectlyGettingPowered(x, y, z) || world.isBlockIndirectlyGettingPowered(x, y + 1, z));
		PacketDispatcher.sendPacketToAllPlayers(world.getBlockTileEntity(x, y, z).getDescriptionPacket());
	}
	ForgeDirection blockOrientation = ForgeDirection.getOrientation(world.getBlockMetadata(x, y, z));
	TileEntity blockTE = world.getBlockTileEntity(x, y, z);
	if (blockTE instanceof TileEntityBusFluidImport)
	{
		TileEntity fluidHandler = world.getBlockTileEntity(x + blockOrientation.offsetX, y + blockOrientation.offsetY, z + blockOrientation.offsetZ);
		((TileEntityBusFluidImport) blockTE).setFluidHandler(fluidHandler instanceof IFluidHandler ? (IFluidHandler) fluidHandler : null);
	}
}
 
Example #5
Source File: BlockBusFluidExport.java    From ExtraCells1 with MIT License 6 votes vote down vote up
@Override
public void onNeighborBlockChange(World world, int x, int y, int z, int neighborID)
{
	super.onNeighborBlockChange(world, x, y, z, neighborID);
	if (!world.isRemote)
	{
		if (world.getBlockTileEntity(x, y, z) instanceof TileEntityBusFluidExport)
			PacketDispatcher.sendPacketToAllPlayers(world.getBlockTileEntity(x, y, z).getDescriptionPacket());
		((TileEntityBusFluidExport) world.getBlockTileEntity(x, y, z)).setRedstoneStatus(world.isBlockIndirectlyGettingPowered(x, y, z) || world.isBlockIndirectlyGettingPowered(x, y + 1, z));
	}
	ForgeDirection blockOrientation = ForgeDirection.getOrientation(world.getBlockMetadata(x, y, z));
	TileEntity blockTE = world.getBlockTileEntity(x, y, z);
	if (blockTE instanceof TileEntityBusFluidExport)
	{
		TileEntity fluidHandler = world.getBlockTileEntity(x + blockOrientation.offsetX, y + blockOrientation.offsetY, z + blockOrientation.offsetZ);
		((TileEntityBusFluidExport) blockTE).setFluidHandler(fluidHandler instanceof IFluidHandler ? (IFluidHandler) fluidHandler : null);
	}
}
 
Example #6
Source File: StaticUtils.java    From BigReactors with MIT License 6 votes vote down vote up
public static boolean fillTankWithContainer(World world, IFluidHandler handler, EntityPlayer player) {

	        ItemStack container = player.getCurrentEquippedItem();
	        FluidStack fluid = FluidContainerRegistry.getFluidForFilledItem(container);

	        if (fluid != null) {
	                if (handler.fill(ForgeDirection.UNKNOWN, fluid, false) == fluid.amount || player.capabilities.isCreativeMode) {
	                        if (world.isRemote) {
	                                return true;
	                        }
	                        handler.fill(ForgeDirection.UNKNOWN, fluid, true);

	                        if (!player.capabilities.isCreativeMode) {
	                                player.inventory.setInventorySlotContents(player.inventory.currentItem, Inventory.consumeItem(container));
	                        }
	                        return true;
	                }
	        }
	        return false;
		}
 
Example #7
Source File: AmadronOfferManager.java    From PneumaticCraft with GNU General Public License v3.0 6 votes vote down vote up
public void tryRestockCustomOffers(){

        for(AmadronOffer offer : allOffers) {
            if(offer instanceof AmadronOfferCustom) {
                AmadronOfferCustom custom = (AmadronOfferCustom)offer;
                TileEntity input = custom.getProvidingTileEntity();
                TileEntity output = custom.getReturningTileEntity();
                int possiblePickups = ContainerAmadron.capShoppingAmount(custom.invert(), 50, input instanceof IInventory ? (IInventory)input : null, output instanceof IInventory ? (IInventory)output : null, input instanceof IFluidHandler ? (IFluidHandler)input : null, output instanceof IFluidHandler ? (IFluidHandler)output : null, null);
                if(possiblePickups > 0) {
                    ChunkPosition pos = new ChunkPosition(input.xCoord, input.yCoord, input.zCoord);
                    EntityDrone drone = ContainerAmadron.retrieveOrderItems(custom, possiblePickups, input.getWorldObj(), pos, input.getWorldObj(), pos);
                    if(drone != null) {
                        drone.setHandlingOffer(custom.copy(), possiblePickups, null, "Restock");
                    }
                }
                custom.invert();
                custom.payout();
            }
        }
    }
 
Example #8
Source File: TileEntityBase.java    From PneumaticCraft with GNU General Public License v3.0 6 votes vote down vote up
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;
                }
            }
        }
    }
}
 
Example #9
Source File: LogisticsManager.java    From PneumaticCraft with GNU General Public License v3.0 6 votes vote down vote up
public static int getRequestedAmount(SemiBlockLogistics requester, FluidStack providingStack){
    int requestedAmount = requester instanceof ISpecificRequester ? ((ISpecificRequester)requester).amountRequested(providingStack) : providingStack.amount;
    if(requestedAmount == 0) return 0;
    providingStack = providingStack.copy();
    providingStack.amount = requestedAmount;
    FluidStack remainder = providingStack.copy();
    remainder.amount += requester.getIncomingFluid(remainder.getFluid());
    TileEntity te = requester.getTileEntity();
    if(te instanceof IFluidHandler) {
        IFluidHandler fluidHandler = (IFluidHandler)te;
        for(ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
            int fluidFilled = fluidHandler.fill(d, remainder, false);
            if(fluidFilled > 0) {
                remainder.amount -= fluidFilled;
                break;
            }
        }
    }
    providingStack.amount -= remainder.amount;
    if(providingStack.amount <= 0) return 0;
    return providingStack.amount;
}
 
Example #10
Source File: ItemAmadronTablet.java    From PneumaticCraft with GNU General Public License v3.0 6 votes vote down vote up
@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;

}
 
Example #11
Source File: FluidBusInventoryHandler.java    From ExtraCells1 with MIT License 5 votes vote down vote up
public FluidTankInfo[] getTankInfo(IFluidHandler tank)
{
	if (tank != null)
	{
		if (tank.getTankInfo(facing) != null && tank.getTankInfo(facing).length != 0)
		{
			return tank.getTankInfo(facing);
		} else if (tank.getTankInfo(ForgeDirection.UNKNOWN) != null && tank.getTankInfo(ForgeDirection.UNKNOWN).length != 0)
		{
			return tank.getTankInfo(ForgeDirection.UNKNOWN);
		}
	}
	return null;
}
 
Example #12
Source File: TileEnderTank.java    From EnderStorage with MIT License 5 votes vote down vote up
private void ejectLiquid() {
    for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) {
        TileEntity t = worldObj.getTileEntity(xCoord + side.offsetX, yCoord + side.offsetY, zCoord + side.offsetZ);
        if (!(t instanceof IFluidHandler))
            continue;

        IFluidHandler c = (IFluidHandler) t;
        FluidStack liquid = drain(null, 100, false);
        if (liquid == null)
            continue;
        int qty = c.fill(side.getOpposite(), liquid, true);
        if (qty > 0)
            drain(null, qty, true);
    }
}
 
Example #13
Source File: FluidBusInventoryHandler.java    From ExtraCells1 with MIT License 5 votes vote down vote up
public FluidBusInventoryHandler(IFluidHandler tank, ForgeDirection facing, int priority, List<ItemStack> filter)
{
	this.tank = tank;
	this.facing = facing;
	this.priority = priority;
	this.filter = filter;
}
 
Example #14
Source File: StaticUtils.java    From BigReactors with MIT License 5 votes vote down vote up
public static boolean fillContainerFromTank(World world, IFluidHandler handler, EntityPlayer player, FluidStack tankFluid) {
	ItemStack container = player.getCurrentEquippedItem();
	
	if (FluidContainerRegistry.isEmptyContainer(container)) {
	        ItemStack returnStack = FluidContainerRegistry.fillFluidContainer(tankFluid, container);
	        FluidStack fluid = FluidContainerRegistry.getFluidForFilledItem(returnStack);
	
	        if (fluid == null || returnStack == null) {
	                return false;
	        }
	        if (!player.capabilities.isCreativeMode) {
	                if (container.stackSize == 1) {
	                        container = container.copy();
	                        player.inventory.setInventorySlotContents(player.inventory.currentItem, returnStack);
	                } else if (!player.inventory.addItemStackToInventory(returnStack)) {
	                        return false;
	                }
	                handler.drain(ForgeDirection.UNKNOWN, fluid.amount, true);
	                container.stackSize--;
	
	                if (container.stackSize <= 0) {
	                        container = null;
	                }
	        } else {
	                handler.drain(ForgeDirection.UNKNOWN, fluid.amount, true);
	        }
	        return true;
	}
	return false;
}
 
Example #15
Source File: SemiBlockRequester.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int amountRequested(FluidStack stack){
    int totalRequestingAmount = getTotalRequestedAmount(stack);
    if(totalRequestingAmount > 0) {
        TileEntity te = getTileEntity();
        if(te instanceof IFluidHandler) {

            int count = 0;

            for(ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
                FluidTankInfo[] infos = ((IFluidHandler)te).getTankInfo(d);
                if(infos != null) {
                    for(FluidTankInfo info : infos) {
                        if(info.fluid != null && info.fluid.getFluid() == stack.getFluid()) {
                            count += info.fluid.amount;
                        }
                    }
                    if(count > 0) break;
                }
            }

            count += getIncomingFluid(stack.getFluid());
            int requested = Math.max(0, Math.min(stack.amount, totalRequestingAmount - count));
            return requested;
        }

    }
    return 0;
}
 
Example #16
Source File: ItemAmadronTablet.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
public static IFluidHandler getLiquidProvider(ItemStack tablet){
    ChunkPosition pos = getLiquidProvidingLocation(tablet);
    if(pos != null) {
        int dimension = getLiquidProvidingDimension(tablet);
        TileEntity te = PneumaticCraftUtils.getTileEntity(pos, dimension);
        if(te instanceof IFluidHandler) return (IFluidHandler)te;
    }
    return null;
}
 
Example #17
Source File: DroneAILiquidImport.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
private boolean emptyTank(ChunkPosition pos, boolean simulate){
    if(drone.getTank().getFluidAmount() == drone.getTank().getCapacity()) {
        drone.addDebugEntry("gui.progWidget.liquidImport.debug.fullDroneTank");
        abort();
        return false;
    } else {
        TileEntity te = drone.getWorld().getTileEntity(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ);
        if(te instanceof IFluidHandler) {
            IFluidHandler tank = (IFluidHandler)te;
            for(int i = 0; i < 6; i++) {
                if(((ISidedWidget)widget).getSides()[i]) {
                    FluidStack importedFluid = tank.drain(ForgeDirection.getOrientation(i), Integer.MAX_VALUE, false);
                    if(importedFluid != null && ((ILiquidFiltered)widget).isFluidValid(importedFluid.getFluid())) {
                        int filledAmount = drone.getTank().fill(importedFluid, false);
                        if(filledAmount > 0) {
                            if(((ICountWidget)widget).useCount()) filledAmount = Math.min(filledAmount, getRemainingCount());
                            if(!simulate) {
                                decreaseCount(drone.getTank().fill(tank.drain(ForgeDirection.getOrientation(i), filledAmount, true), true));
                            }
                            return true;
                        }
                    }
                }
            }
            drone.addDebugEntry("gui.progWidget.liquidImport.debug.emptiedToMax", pos);
        } else if(!((ICountWidget)widget).useCount() || getRemainingCount() >= 1000) {
            Fluid fluid = FluidRegistry.lookupFluidForBlock(drone.getWorld().getBlock(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ));
            if(fluid != null && ((ILiquidFiltered)widget).isFluidValid(fluid) && drone.getTank().fill(new FluidStack(fluid, 1000), false) == 1000 && FluidUtils.isSourceBlock(drone.getWorld(), pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ)) {
                if(!simulate) {
                    decreaseCount(1000);
                    drone.getTank().fill(new FluidStack(fluid, 1000), true);
                    drone.getWorld().setBlockToAir(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ);
                }
                return true;
            }
        }
        return false;
    }
}
 
Example #18
Source File: AmadronOfferCustom.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
public void returnStock(){
    TileEntity provider = getProvidingTileEntity();
    TileEntity returning = getReturningTileEntity();
    invert();
    while(inStock > 0) {
        int stock = Math.min(inStock, 50);
        stock = ContainerAmadron.capShoppingAmount(this, stock, returning instanceof IInventory ? (IInventory)returning : null, provider instanceof IInventory ? (IInventory)provider : null, returning instanceof IFluidHandler ? (IFluidHandler)returning : null, provider instanceof IFluidHandler ? (IFluidHandler)provider : null, null);
        if(stock > 0) {
            inStock -= stock;
            if(getInput() instanceof ItemStack) {
                ItemStack deliveringItems = (ItemStack)getInput();
                int amount = deliveringItems.stackSize * stock;
                List<ItemStack> stacks = new ArrayList<ItemStack>();
                while(amount > 0) {
                    ItemStack stack = deliveringItems.copy();
                    stack.stackSize = Math.min(amount, stack.getMaxStackSize());
                    stacks.add(stack);
                    amount -= stack.stackSize;
                }
                PneumaticRegistry.getInstance().deliverItemsAmazonStyle(provider.getWorldObj(), provider.xCoord, provider.yCoord, provider.zCoord, stacks.toArray(new ItemStack[stacks.size()]));
            } else {
                FluidStack deliveringFluid = ((FluidStack)getInput()).copy();
                deliveringFluid.amount *= stock;
                PneumaticRegistry.getInstance().deliverFluidAmazonStyle(provider.getWorldObj(), provider.xCoord, provider.yCoord, provider.zCoord, deliveringFluid);
            }
        } else {
            break;
        }
    }
}
 
Example #19
Source File: AmadronOfferCustom.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
public void payout(){
    TileEntity returning = getReturningTileEntity();
    TileEntity provider = getProvidingTileEntity();
    if(pendingPayments > 0) {
        int paying = Math.min(pendingPayments, 50);
        paying = ContainerAmadron.capShoppingAmount(this, paying, provider instanceof IInventory ? (IInventory)provider : null, returning instanceof IInventory ? (IInventory)returning : null, provider instanceof IFluidHandler ? (IFluidHandler)provider : null, returning instanceof IFluidHandler ? (IFluidHandler)returning : null, null);
        if(paying > 0) {
            pendingPayments -= paying;
            if(getInput() instanceof ItemStack) {
                ItemStack deliveringItems = (ItemStack)getInput();
                int amount = deliveringItems.stackSize * paying;
                List<ItemStack> stacks = new ArrayList<ItemStack>();
                while(amount > 0) {
                    ItemStack stack = deliveringItems.copy();
                    stack.stackSize = Math.min(amount, stack.getMaxStackSize());
                    stacks.add(stack);
                    amount -= stack.stackSize;
                }
                PneumaticRegistry.getInstance().deliverItemsAmazonStyle(returning.getWorldObj(), returning.xCoord, returning.yCoord, returning.zCoord, stacks.toArray(new ItemStack[stacks.size()]));
            } else {
                FluidStack deliveringFluid = ((FluidStack)getInput()).copy();
                deliveringFluid.amount *= paying;
                PneumaticRegistry.getInstance().deliverFluidAmazonStyle(returning.getWorldObj(), returning.xCoord, returning.yCoord, returning.zCoord, deliveringFluid);
            }
        }
    }
}
 
Example #20
Source File: BlockTranslocator.java    From Translocators with MIT License 5 votes vote down vote up
public static boolean canExistOnSide(World world, int x, int y, int z, int side, int meta) {
    BlockCoord pos = new BlockCoord(x, y, z).offset(side);
    switch (meta) {
        case 0:
            return world.getTileEntity(pos.x, pos.y, pos.z) instanceof IInventory;
        case 1:
            return world.getTileEntity(pos.x, pos.y, pos.z) instanceof IFluidHandler;
    }
    return false;
}
 
Example #21
Source File: ItemTranslocator.java    From Translocators with MIT License 5 votes vote down vote up
/**
 * Returns true if the given ItemBlock can be placed on the given side of the given block position.
 */
public boolean func_150936_a(World world, int x, int y, int z, int side, EntityPlayer player, ItemStack stack) {
    BlockCoord pos = new BlockCoord(x, y, z).offset(side);
    if (world.getBlock(pos.x, pos.y, pos.z) == field_150939_a && world.getBlockMetadata(pos.x, pos.y, pos.z) != stack.getItemDamage())
        return false;

    switch (stack.getItemDamage()) {
        case 0:
            return world.getTileEntity(x, y, z) instanceof IInventory;
        case 1:
            return world.getTileEntity(x, y, z) instanceof IFluidHandler;
    }
    return false;
}
 
Example #22
Source File: DroneAILiquidExport.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
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;
    }
}
 
Example #23
Source File: ContainerAmadron.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
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);
}
 
Example #24
Source File: ContainerAmadron.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
public static int capShoppingAmount(AmadronOffer offer, int wantedAmount, IInventory inv, IFluidHandler fluidHandler, ContainerAmadron container){
    return capShoppingAmount(offer, wantedAmount, inv, inv, fluidHandler, fluidHandler, container);
}
 
Example #25
Source File: TileEntityLiquidHopper.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
@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;
}
 
Example #26
Source File: SemiBlockLogistics.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean canPlace(){
    return getTileEntity() instanceof IInventory || getTileEntity() instanceof IFluidHandler;
}
 
Example #27
Source File: ItemJetpackFueller.java    From SimplyJetpacks with MIT License 4 votes vote down vote up
@Override
public void onUsingTick(ItemStack itemStack, EntityPlayer player, int count) {
    MovingObjectPosition blockPos = BlockHelper.getCurrentMovingObjectPosition(player, true);
    if (blockPos == null || blockPos.sideHit < 0) {
        player.setItemInUse(null, 1);
    } else {
        player.setItemInUse(itemStack, this.getMaxItemUseDuration(itemStack));
        if (player.worldObj.isRemote) {
            return;
        }
        
        ItemStack chestplate = player.getCurrentArmor(2);
        if (chestplate == null || !(chestplate.getItem() instanceof ItemPack)) {
            return;
        }
        ItemPack packItem = (ItemPack) chestplate.getItem();
        PackBase pack = packItem.getPack(chestplate);
        if (pack == null) {
            return;
        }
        FuelType fuelType = pack.fuelType;
        
        ForgeDirection pullSide = ForgeDirection.values()[blockPos.sideHit];
        player.worldObj.getBlock(blockPos.blockX, blockPos.blockY, blockPos.blockZ);
        TileEntity tile = player.worldObj.getTileEntity(blockPos.blockX, blockPos.blockY, blockPos.blockZ);
        int toPull = Math.min(pack.fuelPerTickIn, packItem.getMaxFuelStored(chestplate) - packItem.getFuelStored(chestplate));
        int pulled = 0;
        
        if (fuelType == FuelType.ENERGY && tile instanceof IEnergyProvider) {
            IEnergyProvider energyTile = (IEnergyProvider) tile;
            pulled = energyTile.extractEnergy(pullSide, toPull, false);
            
        } else if (fuelType == FuelType.FLUID) {
            if (tile instanceof IFluidHandler) {
                IFluidHandler fluidTile = (IFluidHandler) tile;
                FluidStack fluid = fluidTile.drain(pullSide, toPull, false);
                if (fluid == null || !fluid.getFluid().getName().equals(pack.fuelFluid)) {
                    return;
                }
                fluid = fluidTile.drain(pullSide, toPull, true);
                pulled = fluid.amount;
            }
        }
        
        if (pulled > 0) {
            packItem.addFuel(chestplate, pulled, false);
        }
    }
}
 
Example #28
Source File: BlockBRDevice.java    From BigReactors with MIT License 4 votes vote down vote up
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ) {
	TileEntity te = world.getTileEntity(x, y, z);
	if(te == null) { return false; }

	if(entityPlayer.isSneaking()) {

		// Wrench + Sneak = Dismantle
		if(StaticUtils.Inventory.isPlayerHoldingWrench(entityPlayer)) {
			// Pass simulate == true on the client to prevent creation of "ghost" item stacks
			dismantleBlock(entityPlayer, null, world, x, y, z, false, world.isRemote);
			return true;
		}

		return false;
	}
	
	if(te instanceof IWrenchable && StaticUtils.Inventory.isPlayerHoldingWrench(entityPlayer)) {
		return ((IWrenchable)te).onWrench(entityPlayer, side);
	}

	// Handle buckets
	if(te instanceof IFluidHandler)
	{
		if(FluidContainerRegistry.isEmptyContainer(entityPlayer.inventory.getCurrentItem())) {
			IFluidHandler fluidHandler = (IFluidHandler)te;
			FluidTankInfo[] infoz = fluidHandler.getTankInfo(ForgeDirection.UNKNOWN);
			for(FluidTankInfo info : infoz) {
				if(StaticUtils.Fluids.fillContainerFromTank(world, fluidHandler, entityPlayer, info.fluid)) {
					return true;
				}
			}
		}
		else if(FluidContainerRegistry.isFilledContainer(entityPlayer.inventory.getCurrentItem()))
		{
			if(StaticUtils.Fluids.fillTankWithContainer(world, (IFluidHandler)te, entityPlayer)) {
				return true;
			}
		}
	}

	// Show GUI
	if(te instanceof TileEntityBeefBase) {
		if(!world.isRemote) {
			entityPlayer.openGui(BRLoader.instance, 0, world, x, y, z);
		}
		return true;
	}
	
	return false;
}
 
Example #29
Source File: TankAccess.java    From CodeChickenCore with MIT License 4 votes vote down vote up
public TankAccess(IFluidHandler tank, int side) {
    this(tank, EnumFacing.values()[side]);
}
 
Example #30
Source File: TankAccess.java    From CodeChickenCore with MIT License 4 votes vote down vote up
public TankAccess(IFluidHandler tank, EnumFacing face) {
    this.tank = tank;
    this.face = face;
}