net.minecraftforge.fluids.FluidContainerRegistry Java Examples

The following examples show how to use net.minecraftforge.fluids.FluidContainerRegistry. 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: ECPrivatePatternInventory.java    From ExtraCells1 with MIT License 6 votes vote down vote up
@Override
public boolean isItemValidForSlot(int i, ItemStack itemstack)
{
	if (gridTE != null)
	{
		ICraftingPattern currentPattern = Util.getAssemblerPattern(itemstack);
		if (currentPattern == null || currentPattern.getRequirements() == null)
			return false;
		if (FluidContainerRegistry.isEmptyContainer(currentPattern.getOutput()))
			return false;

		for (ItemStack entry : currentPattern.getRequirements())
		{
			if (entry != null && entry.getItem() instanceof IFluidContainerItem || FluidContainerRegistry.isFilledContainer(entry))
			{
				return doesRecipeExist((ICraftingPatternMAC) currentPattern);
			}
		}
	}
	return false;
}
 
Example #2
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 #3
Source File: RecipeHandlerFluidRegistry.java    From NEI-Integration with MIT License 6 votes vote down vote up
@Override
public void loadCraftingRecipes(ItemStack result) {
    if (Utils.isFluidBlock(result)) {
        super.loadCraftingRecipes(result);
    }
    if (Config.handlerFluidRegistry) {
        for (Fluid fluid : this.getFluids()) {
            CachedFluidRegistryRecipe crecipe = new CachedFluidRegistryRecipe(fluid);
            if (crecipe.filledContainer != null && crecipe.filledContainer.contains(result)) {
                crecipe.setPermutation(crecipe.filledContainer, result);
                for (FluidContainerData data : FluidContainerRegistry.getRegisteredFluidContainerData()) {
                    if (Utils.areStacksSameTypeCraftingSafe(data.filledContainer, result)) {
                        crecipe.setPermutation(crecipe.emptyContainer, data.emptyContainer);
                    }
                }
                this.arecipes.add(crecipe);
            }
        }
    }
}
 
Example #4
Source File: RecipeHandlerFluidRegistry.java    From NEI-Integration with MIT License 6 votes vote down vote up
@Override
public void loadUsageRecipes(ItemStack ingredient) {
    super.loadUsageRecipes(ingredient);
    if (Config.handlerFluidRegistry) {
        for (Fluid fluid : this.getFluids()) {
            CachedFluidRegistryRecipe crecipe = new CachedFluidRegistryRecipe(fluid);
            if (crecipe.emptyContainer != null && crecipe.emptyContainer.contains(ingredient)) {
                crecipe.setPermutation(crecipe.emptyContainer, ingredient);
                for (FluidContainerData data : FluidContainerRegistry.getRegisteredFluidContainerData()) {
                    if (Utils.areStacksSameTypeCraftingSafe(data.emptyContainer, ingredient)) {
                        crecipe.setPermutation(crecipe.filledContainer, data.filledContainer);
                    }
                }
                this.arecipes.add(crecipe);
            }
        }
    }
}
 
Example #5
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 #6
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 #7
Source File: GTMetaItemEnhancer.java    From bartworks with MIT License 5 votes vote down vote up
private static void addFluidData(Materials m, ItemStack container, Item filled,int amount, int it, boolean empty){
    Fluid f = m.getFluid(1) != null ? m.getFluid(1).getFluid() : m.getGas(1).getFluid();
    final FluidContainerRegistry.FluidContainerData emptyData = new FluidContainerRegistry.FluidContainerData(new FluidStack(f, amount), new ItemStack(filled, 1, it), container);
    FluidContainerRegistry.registerFluidContainer(emptyData);
    GT_Utility.addFluidContainerData(emptyData);
    GT_Values.RA.addFluidCannerRecipe(container, new ItemStack(filled, 1, it), new FluidStack(f, amount), GT_Values.NF);
    GT_Values.RA.addFluidCannerRecipe(new ItemStack(filled, 1, it), empty ? GT_Values.NI : container, GT_Values.NF, new FluidStack(f, amount));
}
 
Example #8
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 #9
Source File: AchievementHandler.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
public static void giveAchievement(EntityPlayer player, ItemStack acquiredStack){
    try {
        if(FluidContainerRegistry.containsFluid(acquiredStack, new FluidStack(Fluids.oil, 1))) {
            giveAchievement(player, Fluids.getBucket(Fluids.oil).getUnlocalizedName().substring(5));
        }
        giveAchievement(player, acquiredStack.getItem().getUnlocalizedName().substring(5));
    } catch(Throwable e) {}
}
 
Example #10
Source File: RecipeFluid.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
public RecipeFluid(ShapedOreRecipe recipe, int fluidIndex){
    this.recipe = recipe;
    originalStack = (ItemStack)recipe.getInput()[fluidIndex];
    fluidStack = FluidContainerRegistry.getFluidForFilledItem(originalStack);
    if(fluidStack == null) throw new IllegalArgumentException("Recipe doesn't have fluid item at index " + fluidIndex + ". Item: " + originalStack);
    this.fluidIndex = fluidIndex;
}
 
Example #11
Source File: CraftingRegistrator.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
private static void scanForFluids(ShapedOreRecipe recipe){
    for(int i = 0; i < recipe.getRecipeSize(); i++) {
        Object o = recipe.getInput()[i];
        if(o instanceof ItemStack) {
            ItemStack stack = (ItemStack)o;
            FluidStack fluid = FluidContainerRegistry.getFluidForFilledItem(stack);
            if(fluid != null) {
                GameRegistry.addRecipe(new RecipeFluid(recipe, i));
            }
        }
    }
}
 
Example #12
Source File: Fluids.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
private static void initializeFluidBlocksAndBuckets(){
    for(final Fluid fluid : fluids) {
        //FluidRegistry.registerFluid(fluid); (The constructor of FluidPneumaticCrafts registers the fluid.
        Block fluidBlock = fluid.getBlock();
        Blockss.registerBlock(fluidBlock);
        fluidToBlockMap.put(fluid.getName(), fluidBlock);

        Item fluidBucket = new ItemBucket(fluidBlock){
            @Override
            public void addInformation(ItemStack p_77624_1_, net.minecraft.entity.player.EntityPlayer p_77624_2_, List p_77624_3_, boolean p_77624_4_){
                super.addInformation(p_77624_1_, p_77624_2_, p_77624_3_, p_77624_4_);
                ItemPneumatic.addTooltip(p_77624_1_, p_77624_2_, p_77624_3_);
            };

            @Override
            @SideOnly(Side.CLIENT)
            public void getSubItems(Item item, CreativeTabs creativeTab, List items){
                if(FluidRegistry.isFluidDefault(fluid)) super.getSubItems(item, creativeTab, items);
            }
        }.setContainerItem(Items.bucket).setCreativeTab(PneumaticCraft.tabPneumaticCraft).setTextureName(Textures.ICON_LOCATION + fluid.getName() + "Bucket").setUnlocalizedName(fluid.getName() + "Bucket");

        Itemss.registerItem(fluidBucket);

        fluidBlockToBucketMap.put(fluidBlock, fluidBucket);

        FluidContainerRegistry.registerFluidContainer(new FluidStack(fluid, 1000), new ItemStack(fluidBucket), new ItemStack(Items.bucket));
    }
}
 
Example #13
Source File: RecipeInputFluidContainer.java    From Electro-Magic-Tools with GNU General Public License v3.0 5 votes vote down vote up
@Override
public List<ItemStack> getInputs() {
    List<ItemStack> ret = new ArrayList<ItemStack>();

    for (FluidContainerData data : FluidContainerRegistry.getRegisteredFluidContainerData()) {
        if (data.fluid.getFluid() == fluid) ret.add(data.filledContainer);
    }

    return ret;
}
 
Example #14
Source File: RecipeInputFluidContainer.java    From Electro-Magic-Tools with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean matches(ItemStack subject) {
    FluidStack fs = FluidContainerRegistry.getFluidForFilledItem(subject);
    if (fs == null) return false;

    return fs.getFluid() == fluid;
}
 
Example #15
Source File: RecipeHandlerBottler.java    From NEI-Integration with MIT License 5 votes vote down vote up
@Override
public void prepare() {
    guiClass = Utils.getClass("forestry.factory.gui.GuiBottler");
    for (FluidContainerData container : FluidContainerRegistry.getRegisteredFluidContainerData()) {
        MachineBottler.Recipe recipe = MachineBottler.RecipeManager.findMatchingRecipe(container.fluid, container.emptyContainer);
        if (recipe != null) {
            recipes.add(recipe);
        }
    }
}
 
Example #16
Source File: RecipeHandlerFluidRegistry.java    From NEI-Integration with MIT License 5 votes vote down vote up
private void setContainerItems(Fluid fluid) {
    List<ItemStack> emptyContainers = new ArrayList<ItemStack>();
    List<ItemStack> filledContainers = new ArrayList<ItemStack>();
    for (FluidContainerData data : FluidContainerRegistry.getRegisteredFluidContainerData()) {
        if (data.fluid.getFluid() == fluid) {
            emptyContainers.add(data.emptyContainer);
            filledContainers.add(data.filledContainer);
        }
    }
    
    if (!emptyContainers.isEmpty() && !filledContainers.isEmpty()) {
        this.emptyContainer = new PositionedStack(emptyContainers, 71, 43);
        this.filledContainer = new PositionedStack(filledContainers, 112, 43);
    }
}
 
Example #17
Source File: FluidKineticGeneratorRecipes.java    From Production-Line with MIT License 5 votes vote down vote up
/**
 * @return Whether this item can process
 */
@Override
public boolean canProcess(ItemStack itemStack) {
    FluidStack fluidStack = FluidContainerRegistry.getFluidForFilledItem(itemStack);
    if (fluidStack != null) {
        for (RecipePart recipePart : this.processList) {
            if (((RecipePartFluidKineticGenerator) recipePart).fluidStack.isFluidEqual(fluidStack)) {
                return true;
            }
        }
    }

    return false;
}
 
Example #18
Source File: RecipeInputFluidContainer.java    From Electro-Magic-Tools with GNU General Public License v3.0 4 votes vote down vote up
public RecipeInputFluidContainer(Fluid fluid) {
    this(fluid, FluidContainerRegistry.BUCKET_VOLUME);
}
 
Example #19
Source File: SlotFullFluidContainer.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean isItemValid(ItemStack stack){
    return stack != null && (FluidContainerRegistry.getFluidForFilledItem(stack) != null || stack.getItem() instanceof IFluidContainerItem && ((IFluidContainerItem)stack.getItem()).getFluid(stack) != null);
}
 
Example #20
Source File: TileEntityLiquidCompressor.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean isItemValidForSlot(int slot, ItemStack stack){
    return slot == 5 ? false : stack != null && (FluidContainerRegistry.getFluidForFilledItem(stack) != null || stack.getItem() instanceof IFluidContainerItem && ((IFluidContainerItem)stack.getItem()).getFluid(stack) != null);
}
 
Example #21
Source File: TileEntityKeroseneLamp.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean isItemValidForSlot(int slot, ItemStack stack){
    return slot == 1 ? false : stack != null && (FluidContainerRegistry.getFluidForFilledItem(stack) != null || stack.getItem() instanceof IFluidContainerItem && ((IFluidContainerItem)stack.getItem()).getFluid(stack) != null);
}
 
Example #22
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 #23
Source File: TileEntityCyaniteReprocessor.java    From BigReactors with MIT License 4 votes vote down vote up
@Override
public int getTankSize(int tankIndex) {
	return FluidContainerRegistry.BUCKET_VOLUME * 5;
}
 
Example #24
Source File: BlockCertusTank.java    From ExtraCells1 with MIT License 4 votes vote down vote up
@Override
public boolean onBlockActivated(World worldObj, int x, int y, int z, EntityPlayer entityplayer, int blockID, float offsetX, float offsetY, float offsetZ)
{

	ItemStack current = entityplayer.inventory.getCurrentItem();

	if (entityplayer.isSneaking() && current == null)
	{
		dropBlockAsItem_do(worldObj, x, y, z, getDropWithNBT(worldObj, x, y, z));
		worldObj.destroyBlock(x, y, z, false);
		return true;
	}
	if (current != null)
	{
		FluidStack liquid = FluidContainerRegistry.getFluidForFilledItem(current);
		TileEntityCertusTank tank = (TileEntityCertusTank) worldObj.getBlockTileEntity(x, y, z);

		if (liquid != null)
		{
			int amountFilled = tank.fill(ForgeDirection.UNKNOWN, liquid, true);

			if (amountFilled != 0 && !entityplayer.capabilities.isCreativeMode)
			{
				if (current.stackSize > 1)
				{
					entityplayer.inventory.mainInventory[entityplayer.inventory.currentItem].stackSize -= 1;
					entityplayer.inventory.addItemStackToInventory(current.getItem().getContainerItemStack(current));
				} else
				{
					entityplayer.inventory.mainInventory[entityplayer.inventory.currentItem] = current.getItem().getContainerItemStack(current);
				}
			}

			return true;

			// Handle empty containers
		} else
		{

			FluidStack available = tank.getTankInfo(ForgeDirection.UNKNOWN)[0].fluid;
			if (available != null)
			{
				ItemStack filled = FluidContainerRegistry.fillFluidContainer(available, current);

				liquid = FluidContainerRegistry.getFluidForFilledItem(filled);

				if (liquid != null)
				{
					if (!entityplayer.capabilities.isCreativeMode)
					{
						if (current.stackSize > 1)
						{
							if (!entityplayer.inventory.addItemStackToInventory(filled))
							{
								tank.fill(ForgeDirection.UNKNOWN, new FluidStack(liquid, liquid.amount), true);
								return false;
							} else
							{
								entityplayer.inventory.mainInventory[entityplayer.inventory.currentItem].stackSize -= 1;
							}
						} else
						{
							entityplayer.inventory.mainInventory[entityplayer.inventory.currentItem] = filled;
						}
					}
					tank.drain(ForgeDirection.UNKNOWN, liquid.amount, true);
					return true;
				}
			}
		}
	}
	return false;
}
 
Example #25
Source File: StaticRecipeChangeLoaders.java    From bartworks with MIT License 4 votes vote down vote up
@SuppressWarnings("ALL")
private static void runMoltenUnificationEnfocement(Werkstoff werkstoff) {
    if (werkstoff.getGenerationFeatures().enforceUnification && werkstoff.hasItemType(WerkstoffLoader.cellMolten)) {
        try {
            FluidContainerRegistry.FluidContainerData data = new FluidContainerRegistry.FluidContainerData(new FluidStack(Objects.requireNonNull(molten.get(werkstoff)), 144), werkstoff.get(WerkstoffLoader.cellMolten), Materials.Empty.getCells(1));
            Field f = GT_Utility.class.getDeclaredField("sFilledContainerToData");
            f.setAccessible(true);
            Map<GT_ItemStack, FluidContainerRegistry.FluidContainerData> sFilledContainerToData = (Map<GT_ItemStack, FluidContainerRegistry.FluidContainerData>) f.get(null);
            HashSet torem = new HashSet<>();
            ItemStack toReplace = null;
            for (Map.Entry<GT_ItemStack, FluidContainerRegistry.FluidContainerData> entry : sFilledContainerToData.entrySet()) {
                final String MODID = GameRegistry.findUniqueIdentifierFor(data.filledContainer.getItem()).modId;
                if (MODID.equals(MainMod.MOD_ID) || MODID.equals(BartWorksCrossmod.MOD_ID))
                    continue;
                if (entry.getValue().fluid.equals(data.fluid) && !entry.getValue().filledContainer.equals(data.filledContainer)) {
                    toReplace = entry.getValue().filledContainer;
                    torem.add(entry);
                }
            }
            sFilledContainerToData.entrySet().removeAll(torem);
            torem.clear();
            if (toReplace != null) {
                for (GT_Recipe.GT_Recipe_Map map : GT_Recipe.GT_Recipe_Map.sMappings) {
                    torem.clear();
                    for (GT_Recipe recipe : map.mRecipeList) {
                        for (int i = 0; i < recipe.mInputs.length; i++) {
                            if (GT_Utility.areStacksEqual(recipe.mInputs[i], toReplace)) {
                                torem.add(recipe);
                                // recipe.mInputs[i] = data.filledContainer;
                            }
                        }
                        for (int i = 0; i < recipe.mOutputs.length; i++) {
                            if (GT_Utility.areStacksEqual(recipe.mOutputs[i], toReplace)) {
                                torem.add(recipe);
                                // recipe.mOutputs[i] = data.filledContainer;
                                if (map == GT_Recipe.GT_Recipe_Map.sFluidCannerRecipes && GT_Utility.areStacksEqual(recipe.mOutputs[i], data.filledContainer) && !recipe.mFluidInputs[0].equals(data.fluid)) {
                                    torem.add(recipe);
                                    // recipe.mOutputs[i] = data.filledContainer;
                                }
                            }
                        }
                        if (recipe.mSpecialItems instanceof ItemStack) {
                            if (GT_Utility.areStacksEqual((ItemStack) recipe.mSpecialItems, toReplace)) {
                                torem.add(recipe);
                                //  recipe.mSpecialItems = data.filledContainer;
                            }
                        }
                    }
                    map.mRecipeList.removeAll(torem);
                }
            }
            GT_Utility.addFluidContainerData(data);
        } catch (NoSuchFieldException | IllegalAccessException | ClassCastException e) {
            e.printStackTrace();
        }
    }
}
 
Example #26
Source File: ECPrivateInventory.java    From ExtraCells1 with MIT License 4 votes vote down vote up
@Override
public boolean isItemValidForSlot(int i, ItemStack itemstack)
{
	return FluidContainerRegistry.isContainer(itemstack) || (itemstack != null && itemstack.getItem() instanceof IFluidContainerItem && ((IFluidContainerItem) itemstack.getItem()).getFluid(itemstack) != null);
}