Jump to content

[1.6.2] [Solved] Fluid system


Pow3rCut

Recommended Posts

Hi,

 

I am trying to update my mod to 1.6.2, all is going well apart from the liquid system, previously I had used ILiquid and extended BlockFlowing/BlockStill. This system is now gone, and I was wondering if anyone has an example (or can just point me in the right direction, at the moment I am running around like a headless chicken) for how to implement the new system using BlockFluidBase/Finite

 

From what I can see you need:

A fluid

Two blocks as usual - Source and Flowing

To Register the fluid in the FluidRegistery

 

What else do you need to add?

 

Thanks in advance,

- Pow3rCut

 

If I helped you click the Thank You button

Link to comment
Share on other sites

Going through the same process, and I think I just about have it working.

 

What you need:

 

  • Class extending Fluid for the registry
  • Class extending BlockFluidClassic (flowing and still are rolled into one) for the in-world block
  • Class extending ItemBucket if you want a custom container
  • @ForgeSubscribe'd FillBucketEvent handler function (can have its own class if you use MinecraftForge.EVENT_BUS.register())

 

The Fluid class is very simple. All you need is a constructor to set a couple of values. You can even register it within its constructor:

 

public FluidExample( int id )
{
	super( "example" );

	setDensity( 8 ); // used by the block to work out how much it slows entities
	setViscosity( 4000 ); // used by the block to work out how fast it flows

	FluidRegistry.registerFluid( this );
}

 

The BlockFluidClassic class is more similar to the old LiquidFlowing and Liquid Still classes. The main difference is that you give it a reference to the fluid, and it draws some information from that. Also, the textures are slightly different. Define private still and flowing icons in the class, and register them in your override of

registerIcons( IconRegister )

. Also, pass them to

getFluid().setIcons( Icon, Icon )

, since it's impossible to get a reference to the IconRegister elsewhere. Then, in your getIcon override, put this:

 

@Override
@SideOnly(Side.CLIENT)
public Icon getIcon( int side, int meta )
{
	if ( side <= 1 )
		return iconStill;
	else
		return iconFlowing;
}

 

This is getting quite long, so I'll put the bucket code in another comment.

Link to comment
Share on other sites

Before I get onto the bucket code, I almost forgot - register your BlockFluidClassic instance in your proxy like you would for any other block.

 

For the ItemBucket class, the only difference from a normal Item is that you pass the

super

constructor a second value: the id of your BlockFluidClassic class, which will be automatically placed when you right click.

 

Then, somewhere in initialisation, use the FluidContainerRegistry to register this item as a container holding one bucket's worth of that fluid:

 

FluidContainerRegistry.registerFluidContainer(
	new FluidContainerData(
		FluidRegistry.getFluidStack( ModExample.fluidExample.getName(), FluidContainerRegistry.BUCKET_VOLUME ),
		new ItemStack( ModExample.bucketExample ),
		new ItemStack( Item.bucketEmpty )
	)
);

 

Finally, we need to tell minecraft to fill a bucket with this fluid whenever it is right clicked on with a bucket in hand. Fortunately, Forge provides an event listener that fires when you right click with a bucket.

 

@ForgeSubscribe
public void onBucketFill( FillBucketEvent event )
{
	ItemStack result = attemptFill( event.world, event.target );

	if ( result != null )
	{
		event.result = result;
		event.setResult( Result.ALLOW );
	}
}

 

where attemptFill( World, MovingObjectPosition ) is a function that checks what the picked block is, and returns an ItemStack of the relevant filled container if applicable:

 

private ItemStack attemptFill( World world, MovingObjectPosition p )
{
	int id = world.getBlockId( p.blockX, p.blockY, p.blockZ );

	if ( id == ModExample.blockFluidExample.blockID )
	{
		if ( world.getBlockMetadata( p.blockX, p.blockY, p.blockZ ) == 0 ) // Check that it is a source block
		{
			world.setBlock( p.blockX, p.blockY, p.blockZ, 0 ); // Remove the fluid block

			return new ItemStack( ModExample.bucketExample );
		}
	}

	return null;
}

 

Phew. I think that's all, though. If it doesn't work, I'll check to see if I've missed anything.

Link to comment
Share on other sites

I'm not sure what I did wrong, but the texture on the liquid in game doesn't work. All I know is that the error is unhappy with the this.getFluid().setIcons(this.theIcon[0], this.theIcon[1]); Here's the whole class:

package mardiff.ethanol.fluids;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.BlockStationary;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.util.DamageSource;
import net.minecraft.util.Icon;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fluids.BlockFluidClassic;

public class BlockEthanolLiquid extends BlockFluidClassic
{
protected Icon[] theIcon;

public BlockEthanolLiquid(int i)
{
	super(i, ModFluids.ethanol, Material.water);
	this.setCreativeTab(CreativeTabs.tabMisc);
	ModFluids.ethanol.setBlockID(this);
	this.getFluid().setIcons(this.theIcon[0], this.theIcon[1]);
}

@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister iconRegister) {
	this.theIcon = new Icon[]{iconRegister.registerIcon("ethanol:ethanol_still"), iconRegister.registerIcon("ethanol:ethanol_flow")};
}

@Override
@SideOnly(Side.CLIENT)
public Icon getIcon(int side, int meta)
{
	if ( side <= 1 ) {
		return this.theIcon[0];
	} else {
		return this.theIcon[1];
	}
}
}

 

Edit: *facepalm* It wasn't the code, it was that I was using my 1.5 textures.... Everything works fine!

If you really want help, give that modder a thank you.

 

Modders LOVE thank yous.

Link to comment
Share on other sites

  • 4 weeks later...

I finally got the bucket to place the liquid but I can't get the the bucket to pick up the liquid, it keeps giving water bucket instead of darkness bucket.

this is my bucket code please help.

 

 

 

package kakarotvg.omega.items;

 

import kakarotvg.omega.ItemHandler;

import kakarotvg.omega.LiquidHandler;

import kakarotvg.omega.Reference;

import net.minecraft.client.renderer.texture.IconRegister;

import net.minecraft.item.ItemBucket;

import net.minecraft.item.ItemStack;

import net.minecraft.util.MovingObjectPosition;

import net.minecraft.world.World;

import net.minecraftforge.event.Event.Result;

import net.minecraftforge.event.EventPriority;

import net.minecraftforge.event.ForgeSubscribe;

import net.minecraftforge.event.entity.player.FillBucketEvent;

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

 

public class VgBucket extends ItemBucket {

 

    private String itemName;

 

    @SideOnly(Side.CLIENT)

    @Override

    public void registerIcons(IconRegister register) {

        this.itemIcon = register.registerIcon(Reference.MOD_ID + ":" + (this.getUnlocalizedName().substring(5)));

    }

 

    public VgBucket(int id, int par1, String name) {

        super(id, par1);

        this.itemName = name;

        this.setUnlocalizedName(name);

 

    }

 

    @ForgeSubscribe

    public void onBucketFill(FillBucketEvent event) {

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

 

        if (result != null) {

            event.result = result;

            event.setResult(Result.ALLOW);

        }

    }

 

    private ItemStack attemptFill(World world, MovingObjectPosition p) {

        int id = world.getBlockId(p.blockX, p.blockY, p.blockZ);

 

        if (id == LiquidHandler.Darknessliquid.blockID) {

            if (world.getBlockMetadata(p.blockX, p.blockY, p.blockZ) == 0) // Check that it is a source block

            {

                world.setBlock(p.blockX, p.blockY, p.blockZ, 0); // Remove the fluid block

 

                return new ItemStack(ItemHandler.darknessbucket); // Return the filled bucked item here.

            }

        }

 

        return null;

    }

 

}

 

 

 

if (You.likescoding == false){
      You.goaway;
}

Link to comment
Share on other sites

  • 2 months later...

@Kakarotvg you need to add this line:

MinecraftForge.EVENT_BUS.register(this);

to the constructor of the VgBucket:

public VgBucket(int id, int par1, String name) {
        super(id, par1);
        this.itemName = name;
        this.setUnlocalizedName(name);
        MinecraftForge.EVENT_BUS.register(this);
    }

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.