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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • how to make animated doors?, maybe geckolib, but i don't know how to code it?
    • For crash 1, set max-tick-time to -1 in your server.properties Crash 2 shows a conflict or incompatibility between LuckPerms and the mod boh-0.0.6.1-forge-1.20.1_2.jar
    • Add the crash-report or latest.log (logs-folder) with sites like https://mclo.gs/ and paste the link to it here  
    • so my minecraft crashes when opening my world, i played without any troubles for about 5 days and today it started tweaking.. pls help me
    • Hi guys! I am having some issues with the server crashing over and over and I was hoping to get some guidance.  Thanks in advance! Crash 1: java.lang.Error: ServerHangWatchdog detected that a single server tick took 60.00 seconds (should be max 0.05)     at net.minecraft.server.dedicated.ServerWatchdog.run(ServerWatchdog.java:43) ~[server-1.20.1-20230612.114412-srg.jar%23217!/:?] {re:classloading}     at java.lang.Thread.run(Thread.java:840) ~[?:?] { Crash 2: java.lang.IllegalStateException: Capability missing for eeb7f026-34b4-42f5-9164-e7736461df83     at me.lucko.luckperms.forge.capabilities.UserCapabilityImpl.lambda$get$0(UserCapabilityImpl.java:66) ~[?:?] {re:classloading,re:classloading,re:classloading}     at net.minecraftforge.common.util.LazyOptional.orElseThrow(LazyOptional.java:261) ~[forge-1.20.1-47.3.10-universal.jar%23222!/:?] {re:mixin,re:classloading}     at me.lucko.luckperms.forge.capabilities.UserCapabilityImpl.get(UserCapabilityImpl.java:66) ~[?:?] {re:classloading,re:classloading,re:classloading}     at me.lucko.luckperms.forge.util.BrigadierInjector$InjectedPermissionRequirement.test(BrigadierInjector.java:143) ~[?:?] {}     at me.lucko.luckperms.forge.util.BrigadierInjector$InjectedPermissionRequirement.test(BrigadierInjector.java:129) ~[?:?] {}     at com.mojang.brigadier.tree.CommandNode.canUse(CommandNode.java:65) ~[brigadier-1.1.8.jar%2376!/:?] {}     at com.mojang.brigadier.CommandDispatcher.parseNodes(CommandDispatcher.java:359) ~[brigadier-1.1.8.jar%2376!/:?] {}     at com.mojang.brigadier.CommandDispatcher.parse(CommandDispatcher.java:349) ~[brigadier-1.1.8.jar%2376!/:?] {}     at com.mojang.brigadier.CommandDispatcher.parse(CommandDispatcher.java:317) ~[brigadier-1.1.8.jar%2376!/:?] {}     at net.minecraft.commands.Commands.m_230957_(Commands.java:237) ~[server-1.20.1-20230612.114412-srg.jar%23217!/:?] {re:classloading}     at net.mcreator.boh.procedures.TeleportbenProcedure.lambda$execute$2(TeleportbenProcedure.java:65) ~[boh-0.0.6.1-forge-1.20.1_2.jar%23165!/:?] {re:classloading}     at net.mcreator.boh.BohMod.lambda$tick$2(BohMod.java:96) ~[boh-0.0.6.1-forge-1.20.1_2.jar%23165!/:?] {re:classloading}     at java.util.ArrayList.forEach(ArrayList.java:1511) ~[?:?] {re:mixin}     at net.mcreator.boh.BohMod.tick(BohMod.java:96) ~[boh-0.0.6.1-forge-1.20.1_2.jar%23165!/:?] {re:classloading}     at net.mcreator.boh.__BohMod_tick_ServerTickEvent.invoke(.dynamic) ~[boh-0.0.6.1-forge-1.20.1_2.jar%23165!/:?] {re:classloading,pl:eventbus:B}     at net.minecraftforge.eventbus.ASMEventHandler.invoke(ASMEventHandler.java:73) ~[eventbus-6.0.5.jar%2352!/:?] {}     at net.minecraftforge.eventbus.EventBus.post(EventBus.java:315) ~[eventbus-6.0.5.jar%2352!/:?] {}     at net.minecraftforge.eventbus.EventBus.post(EventBus.java:296) ~[eventbus-6.0.5.jar%2352!/:?] {}     at net.minecraftforge.event.ForgeEventFactory.onPostServerTick(ForgeEventFactory.java:950) ~[forge-1.20.1-47.3.10-universal.jar%23222!/:?] {re:classloading}     at net.minecraft.server.MinecraftServer.m_5705_(MinecraftServer.java:835) ~[server-1.20.1-20230612.114412-srg.jar%23217!/:?] {re:mixin,pl:accesstransformer:B,xf:fml:xaerominimap:xaero_minecraftserver,re:classloading,pl:accesstransformer:B,xf:fml:xaerominimap:xaero_minecraftserver,pl:mixin:A}     at net.minecraft.server.MinecraftServer.m_130011_(MinecraftServer.java:661) ~[server-1.20.1-20230612.114412-srg.jar%23217!/:?] {re:mixin,pl:accesstransformer:B,xf:fml:xaerominimap:xaero_minecraftserver,re:classloading,pl:accesstransformer:B,xf:fml:xaerominimap:xaero_minecraftserver,pl:mixin:A}     at net.minecraft.server.MinecraftServer.m_206580_(MinecraftServer.java:251) ~[server-1.20.1-20230612.114412-srg.jar%23217!/:?] {re:mixin,pl:accesstransformer:B,xf:fml:xaerominimap:xaero_minecraftserver,re:classloading,pl:accesstransformer:B,xf:fml:xaerominimap:xaero_minecraftserver,pl:mixin:A}     at java.lang.Thread.run(Thread.java:840) ~[?:?] {}
  • Topics

×
×
  • Create New...

Important Information

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