Jump to content

[1.12.2] How to make a normal bucket turn to a custom bucket after collecting a custom fluid?


Recommended Posts

Posted (edited)

.....

some of you might say "use universal bucket"

.....

But if I use universal bucket, it's pretty useless.

So I made a custom bucket that can DRAIN, after that, it returns a normal vanilla bucket.

Then, how to let the vanilla bucket accept my new fluid and return my CUSTOM bucket?

 

 

 

PS. FillBucketEvent is not working, so maybe I need a help at this too.

 

PPS. This is my bucket codecode.thumb.png.3233389471ee10a61da156dac3de2fdf.png

 

Edited by LeoCTH
add picture code
Posted (edited)

Use Event hooks from Forge.

So create an EventHandler, make sure it's registered and subscribe an event like so:

public static void onBucketUsed(FillBucketEvent event) {
    World eventWorld = event.getWorld();
    BlockPos hitPos = new BlockPos(event.getTarget().hitVec);
    if(eventWorld.getBlockState(hitPos) == yourBlockRegistry.theliquidVariable) {
        event.setFilledBucket(new ItemStack(yourItemRegistry.theBucketVariable, 1));
    }
}
	
Edited by hiotewdew
Fix formatting
Posted (edited)

If you want to drain it just add a check to see if the item held is your full bucket and run eventWorld.setBlockState to set the block at hitVec to your liquid.

Edited by hiotewdew
grammar
Posted
3 hours ago, hiotewdew said:

If you want to drain it just add a check to see if the item held is your full bucket and run eventWorld.setBlockState to set the block at hitVec to your liquid.

....

My problem is my REGISTERING process having problem...

It's not working

Posted

You never said it wasn't working for you. Only that it's useless. You should use the universal bucket and if you run into issues, post them here.

 

Only if you need your bucket to have custom functionality, would it make sense to make custom buckets.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Posted
15 hours ago, LeoCTH said:

....

My problem is my REGISTERING process having problem...

It's not working

Can I have more context than this? Or are you good and used a universal bucket?

Posted
1 hour ago, hiotewdew said:

Can I have more context than this? Or are you good and used a universal bucket?

I tried FluidRegistry.enableUniversalBucket in a static initializer

and  FluidRegistry.addBucketForFluid(myFluid)

It doesn't work

Posted

Show me the class you register your fluid in.

Posted
9 hours ago, larsgerrits said:

You never said it wasn't working for you. Only that it's useless. You should use the universal bucket and if you run into issues, post them here.

 

Only if you need your bucket to have custom functionality, would it make sense to make custom buckets.

I said "use" + "less" = "useless"

or my grammar have some problem I mean cannot (less) use

....

You misunderstanding my point.

Posted

You have to call enableUniversalBucket before the pre-initialization stage.

Here's a solved thread with an explanation.

Posted (edited)

While you do attempt to do the above it is not correct.

	static {
		FluidRegistry.enableUniversalBucket();
	}

	public static final String MODID = "mff";
	public static final String NAME = "My Food Factory";
	public static final String VERSION = "1.0.0";
	public static Logger LOGGER;
	@Mod.Instance(MyFoodFactory.MODID)
	public static MyFoodFactory instance;

Should be changed to this:

	public static final String MODID = "mff";
	public static final String NAME = "My Food Factory";
	public static final String VERSION = "1.0.0";
	public static Logger LOGGER;
	@Mod.Instance(MyFoodFactory.MODID)
	public static MyFoodFactory instance = createInstance();
	static MyFoodFactory createInstance() {
		FluidRegistry.enableUniversalBucket();
	}

 

Edited by hiotewdew
fix error
Posted (edited)
4 hours ago, hiotewdew said:

While you do attempt to do the above it is not correct.


	static {
		FluidRegistry.enableUniversalBucket();
	}

	public static final String MODID = "mff";
	public static final String NAME = "My Food Factory";
	public static final String VERSION = "1.0.0";
	public static Logger LOGGER;
	@Mod.Instance(MyFoodFactory.MODID)
	public static MyFoodFactory instance;

Should be changed to this:


	public static final String MODID = "mff";
	public static final String NAME = "My Food Factory";
	public static final String VERSION = "1.0.0";
	public static Logger LOGGER;
	@Mod.Instance(MyFoodFactory.MODID)
	public static MyFoodFactory instance = createInstance();
	static MyFoodFactory createInstance() {
		FluidRegistry.enableUniversalBucket();
	}

 

....

the "static initializer block" it SUPPOSED to be like

static {
	// TODO
}

in Oracle's Docs and this thread.

but it's totally NOT working (the bucket can be registered with no functionality)

Edited by LeoCTH
grammar
Posted

The way he does the static initializer block should be fine. 

 

Universal bucket works for me and I enable it the same way. You can try by looking/using/copying my example mod here: https://github.com/jabelar/ExampleMod-1.12

 

Perhaps the problem has to do with the fluid, or the order in which the fluid and bucket are instantiated or registered. But your code looks like it should work. The only thing you do that is kinda weird/different than most is that you instantiate an anonymous instance of your loader classes whereas I would normally make the loader methods static. I don't think that's really a problem, but maybe it is causing trouble.

 

 

 

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

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.