Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Why cant I fill my bucket with a custom fluid?

Featured Replies

Posted

When I try to fill my bucket, it just fills with water. I've followed the instructions from scratchforfun's tutorials, but they haven't solved this issue

 

@EventHandler
    public void PreInit(FMLPreInitializationEvent event)
{
	makeTonic(blockTonic, fluidTonic, bucketTonic, bottleTonic, "tonic", 0, 0);
	MinecraftForge.EVENT_BUS.register(new FillContainerEvent());
}

public void makeTonic(Block block, Fluid fluid, Item bucket, Item bottle, String name, int id, int amp)
{
	fluid = new FluidTonic(name, id, amp).setBlock(block);
	FluidRegistry.registerFluid(fluid);

	block = new BlockTonic(fluid, 0, 0).setBlockName("block_"+name);
	GameRegistry.registerBlock(block, "block_"+name);

	bucket = new ItemBucket(block).setUnlocalizedName(name+"_bucket").setMaxStackSize(1).setContainerItem(Items.bucket).setCreativeTab(tab);
	FluidContainerRegistry.registerFluidContainer(fluid, new ItemStack(bucket), new ItemStack(Items.bucket));
	GameRegistry.registerItem(bucket, "bucket"+name);
	FillContainerEvent.INSTANCE.buckets.put(block, bucket);
	//FluidContainerRegistry.registerFluidContainer(new FluidStack(fluid, 500), new ItemStack(bottle), new ItemStack(Items.glass_bottle));
}

 

public class FillContainerEvent
{
public static FillContainerEvent INSTANCE = new FillContainerEvent();
public Map<Block, Item> buckets = new HashMap<Block, Item>();
public Map<Block, Item> bottles = new HashMap<Block, Item>();
public void fillBucket(FillBucketEvent e)
{
	if(e.current.getItem() != Items.bucket)
	{
		return;
	}

	ItemStack fullBucket = getLiquid(e.world, e.target);

	if (fullBucket == null) return;

	e.world.setBlockToAir(e.target.blockX, e.target.blockY, e.target.blockZ);
	e.result = fullBucket;
	e.setResult(Result.ALLOW);
}

private ItemStack getLiquid(World world, MovingObjectPosition pos)
{
	Block block = world.getBlock(pos.blockX, pos.blockY, pos.blockZ);
	return new ItemStack(buckets.get(block));

}
}

  • Author

okay, on further inspection I noticed that I forgot the @SubscribeEvent at the top of fill bucket. Now when I try to fill the bucket, the game crashes because of something to do with a ticking entity and the itemstack update animation

I don't know the tutorial you where following, but I had the same issues a few days ago. I'm now starting from the point, where you only have created and registered the fluid and the fluid block.

 

I expect your Fluid class to look like the following. It's the code from my fluid called "Gift".

package com.Abrynos.Fluids;

import java.io.IOException;
import java.util.Random;

import com.Abrynos.MainRegistry;
import com.Abrynos.CreativeTabs.CreativeTabRegistry;

import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.block.material.MaterialLiquid;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemSeeds;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fluids.BlockFluidClassic;
import net.minecraftforge.fluids.BlockFluidFinite;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry;

public class Gift extends BlockFluidClassic {

@SideOnly(Side.CLIENT)
protected IIcon blockIcon;
@SideOnly(Side.CLIENT)
protected IIcon flowingIcon;
@SideOnly(Side.CLIENT)
protected IIcon stillIcon;

public Gift() {
	super(AbrFluidRegistry.Gift, Material.water);
  }

  @EventHandler // used in 1.6.2
      public void preInit(FMLPreInitializationEvent event) throws IOException{ 

	  AbrFluidRegistry.Gift.setIcons(blockIcon).setBlock(AbrFluidRegistry.GiftBlock);
      }

  @Override
      public IIcon getIcon(int side, int meta) {
              return (side == 0 || side == 1)? stillIcon : flowingIcon;
      }

  @SideOnly(Side.CLIENT)
	public void registerBlockIcons(IIconRegister iconRegister){
	  this.blockIcon = iconRegister.registerIcon("Abrynos:Gift");
		this.flowingIcon = iconRegister.registerIcon("Abrynos:Gift_Flowing");
		this.stillIcon = iconRegister.registerIcon("Abrynos:Gift_Still");


	}

  public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity entity){
	  if(entity instanceof EntityLivingBase){
		  ((EntityLivingBase)entity).addPotionEffect(new PotionEffect(Potion.poison.id, 100, 0)); //100 = 5 Seconds , 20 = 1 Second
		  ((EntityLivingBase)entity).addPotionEffect(new PotionEffect(Potion.hunger.id, 100, 0));

	  }	  
  }

  @SideOnly(Side.CLIENT)
  public void randomDisplayTick(World worldObj, int posX, int posY, int posZ, Random rand) {
	  if (this.blockMaterial == Material.water && worldObj.getBlock(posX, posY + 1, posZ).getMaterial() == Material.air && !worldObj.getBlock(posX, posY + 1, posZ).isOpaqueCube()) {
		  int direction = worldObj.getBlockMetadata(posX, posY, posZ);
		  float x1 = (float)posX + rand.nextFloat();
		  float y1 = (float)posY + rand.nextFloat();
		  float z1 = (float)posZ + rand.nextFloat();
		  float f =  rand.nextFloat();
		  float f1 = rand.nextFloat();

		  if(direction == 4){
			  worldObj.spawnParticle("reddust", (double)(x1 - f), (double)(y1), (double)(z1 + f1), 1.0D /*red*/, 1.2D /*green*/, 1.6D /*blue*/);
		  }else if(direction == 5){
			  worldObj.spawnParticle("reddust", (double)(x1 + f), (double)(y1), (double)(z1 + f1), 1.0D /*red*/, 1.2D /*green*/, 1.6D /*blue*/);
		  }else if(direction == 2){
			  worldObj.spawnParticle("reddust", (double)(x1 + f1), (double)(y1), (double)(z1 - f), 1.0D /*red*/, 1.2D /*green*/, 1.6D /*blue*/);
		  }else if(direction == 3){
			  worldObj.spawnParticle("reddust", (double)(x1 + f1), (double)(y1), (double)(z1 + f), 1.0D /*red*/, 1.2D /*green*/, 1.6D /*blue*/);
		  }
	  }
  }
  
  @Override
      public boolean canDisplace(IBlockAccess world, int x, int y, int z) {
              if (world.getBlock(x,  y,  z).getMaterial().isLiquid()) return false;
              return super.canDisplace(world, x, y, z);
      }
      
      @Override
      public boolean displaceIfPossible(World world, int x, int y, int z) {
              if (world.getBlock(x,  y,  z).getMaterial().isLiquid()) return false;
              return super.displaceIfPossible(world, x, y, z);
      }
}

 

To fill a bucket with your fluid you have to register a BucketHandler.class. The code should be the same as following:

package com.Abrynos.Fluids;

import java.util.HashMap;
import java.util.Map;

import cpw.mods.fml.common.eventhandler.Event.Result;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
import net.minecraftforge.event.entity.player.FillBucketEvent;

public class BucketHandler {

    public static BucketHandler INSTANCE = new BucketHandler();
    public Map<Block, Item> buckets = new HashMap<Block, Item>();

    private BucketHandler() {
    }

    @SubscribeEvent
    public void onBucketFill(FillBucketEvent event) {

            ItemStack result = fillCustomBucket(event.world, event.target);

            if (result == null)
                    return;

            event.result = result;
            event.setResult(Result.ALLOW);
    }

    private ItemStack fillCustomBucket(World world, MovingObjectPosition pos) {

            Block block = world.getBlock(pos.blockX, pos.blockY, pos.blockZ);

            Item bucket = buckets.get(block);
            if (bucket != null && world.getBlockMetadata(pos.blockX, pos.blockY, pos.blockZ) == 0) {
                    world.setBlockToAir(pos.blockX, pos.blockY, pos.blockZ);
                    return new ItemStack(bucket);
            } else
                    return null;

    }
}

 

This BucketHandler.class has to be registered in your MainRegistry or in your FluidRegistry if you have given the register things in special classes like BlockRegistry.class or ItemRegistry.class. In your case it should be enough if you put the following line into the preInit part of the MainRegistry.

MinecraftForge.EVENT_BUS.register(BucketHandler.INSTANCE);

 

Next you have to registrer a new Item called "yourFluidBucket". The code as follows should do it:

public static Item yourFluidBucket;
yourFluidBucket= new yourFluidBucket(yourFluidBlock).setTextureName("MODID:TEXTURENAME");

 

If you don't import the yourFluidBucket class you'll get an Error so don't forget to create it as following:

public class Gifteimer extends ItemBucket {
public yourFluidBucket(Block p_i45331_1_){
	super(p_i45331_1_);
	this.setUnlocalizedName("yourFluidBucket");
	this.setCreativeTab(creativeTabs.SOMECREATIVETAB);
}
}

 

Now add one simple line to the preInit part of the MainRegistry or into your FluidRegistry. But don't put it above the other lines, because that won't work!

BucketHandler.INSTANCE.buckets.put(yourFluidBlock, yourFluidBucket);

 

Congratulations! You should now have a fully functional Bucket with your fluid in the creative Inventory, with wich you can also pick up other fluids, if you have emptied it before, with puting your fluid onto the floor. You can also pick up your Fluid from the ground with a normal Bucket.

 

[glow=red,2,300][shadow=red,left]Have you found a way to create lakes with your fluid in it? I'm searching for a way to do it for hours but i don't find it.[/shadow][/glow]

 

Btw. Sry for my bad english! I'm coming from Austria. (NO KANGAROOS!!!! It's in middle europe!) :P

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.