Jump to content

[1.7.10] [SOLVED] Picking up a custom fluid with a vanilla bucket?


Toastrackenigma

Recommended Posts

Hey forum,

I have been following this tutorial (http://www.minecraftforge.net/wiki/Create_a_Fluid) to create a custom liquid in forge 1.7.10. I have the source "block" which I can place in the world and it flows and works fine. I also have a custom bucket which can place down the liquid and then transforms into a vanilla bucket. The problem is that when I then proceed to right-click the liquid with a vanilla bucket to pick it up, I get a water bucket rather than a bucket of my custom liquid. Here is the code:

From the main class (in pre-int method):

Block diamondliquidblock = new DiamondLiquidBlock(diamondliquid);	
GameRegistry.registerBlock(diamondliquidblock, diamondliquidblock.getUnlocalizedName().substring(5));
Item diamondliquidbucket = new DiamondLiquidBucket(diamondliquidblock);
GameRegistry.registerItem(diamondliquidbucket, diamondliquidbucket.getUnlocalizedName().substring(5));
FluidContainerRegistry.registerFluidContainer(diamondliquid, new ItemStack(diamondliquidbucket), new ItemStack(Items.bucket));
BucketHandler.INSTANCE.buckets.put(diamondliquidblock, diamondliquidbucket);
MinecraftForge.EVENT_BUS.register(BucketHandler.INSTANCE);

DiamondLiquidBlock class:

package com.toastrackenigma.toastcraft;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fluids.BlockFluidClassic;
import net.minecraftforge.fluids.Fluid;

public class DiamondLiquidBlock extends BlockFluidClassic {
@SideOnly(Side.CLIENT)
    protected IIcon stillIcon;
    @SideOnly(Side.CLIENT)
    protected IIcon flowingIcon;
    
    public DiamondLiquidBlock(Fluid fluid) {
    super(fluid,Material.water);
    this.setCreativeTab(Main.maintab);
    this.setBlockName("liquiddiamond");
    }
    
    @Override
    public IIcon getIcon(int side, int meta) {
    	IIcon result = stillIcon;
    	if (side==1) {
    		result = flowingIcon;
    	}
    	return result;
    }
    
    @SideOnly(Side.CLIENT)
    @Override
    public void registerBlockIcons(IIconRegister iir) {
    	stillIcon = iir.registerIcon(Main.MODID + ":" + "diamondflowing");
    	flowingIcon = iir.registerIcon(Main.MODID + ":" + "diamondstill");
    }
    
    @Override
    public boolean canDisplace(IBlockAccess world, int x, int y, int z) {
        if (world.getBlock(x,  y,  z).getMaterial().isLiquid()) {
        	return false;
        }
        else {
        	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;
        }
        else {
        	return super.displaceIfPossible(world, x, y, z);
        }
    }

}

DiamondLiquidBucket Class:

package com.toastrackenigma.toastcraft;

import net.minecraft.block.Block;
import net.minecraft.init.Items;
import net.minecraft.item.ItemBucket;

public class DiamondLiquidBucket extends ItemBucket{

public DiamondLiquidBucket(Block fluidblock) {
	super(fluidblock);
	this.setCreativeTab(Main.maintab);
	this.setContainerItem(Items.bucket);
	this.setUnlocalizedName("diamondliquidbucket");
	this.setTextureName(Main.MODID + ":" + "diamondliquidbucket");
}

}

BucketHandler Class:

package com.toastrackenigma.toastcraft;

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

import cpw.mods.fml.common.eventhandler.Event.Result;
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>();

public void onBucketFill(FillBucketEvent event) {
    ItemStack result = fillBucket(event.world, event.target);
    if (result == null) {
            return;
    }
    event.result = result;
    event.setResult(Result.ALLOW);
}

private ItemStack fillBucket(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;
    }
}
}

I at one point tried to change the super(fluid,Material.water); line in DiamondLiquidBlock to super(fluid,Material.lava); and the empty bucket turned into a lava bucket instead, so the bucket that I get is obviously determined by the material that I use. Infact, inside the ItemBucket Class there is and if statement for what is returned (water or lava bucket) based off the material of the liquid:

if (material == Material.water && l == 0) {
    p_77659_2_.setBlockToAir(i, j, k);
    return this.func_150910_a(p_77659_1_, p_77659_3_, Items.water_bucket);
}

 

My question is, how to I override this default functionality and make an empty bucket pick up my liquid rather than water / lava?

 

I have searched the internet and have found some people having a similar problem, but their fixes didn't resolve my issue and most were for 1.6 and 1.5 and not 1.7.10.

 

Please help!

-Toastrackenigma

Link to comment
Share on other sites

I put a system.out.println("Hello World"); in the public void onBucketFill(FillBucketEvent event) { event and when I tried to pick up the liquid nothing was printed, so it's probably not getting called. I have tried changing the order in which I call my statements but it doesn't seem to do anything. Any advice on how to make that handler get called?

Link to comment
Share on other sites


public void onBucketFill(FillBucketEvent event) {

 

Uh.

 

There's something missing here...

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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