Jump to content

[1.12.2] Entities inside of fluids


Corey

Recommended Posts

I have several fluids defined in my mod, that all work perfectly, except for the fact that entities pass through them as if they were air.  I've been looking at code from other mods with fluids, (IC2 applies potion effects, BC uses entity.setInWeb) but this can't be the "correct" way to do it, right?

 

I've searched for tutorials, and none seem to mention anything about having to code this entity interaction manually, which leads me to believe I may have done something wrong.  Can anyone point me in the right direction?

 

My registration code is fairly straight-forward:

  private static void registerFluidForMetal(final IForgeRegistry<Block> registry, final GradientMetals.Metal metal) {
    final Fluid fluid;
    
    if(FluidRegistry.isFluidRegistered(metal.name)) {
      fluid = FluidRegistry.getFluid(metal.name);
    } else {
      fluid = new Fluid(metal.name, GradientMod.resource("blocks/fluid_" + metal.name), GradientMod.resource("blocks/fluid_" + metal.name + "_flowing"))
          .setDensity(3000)
          .setLuminosity(9)
          .setViscosity(5000)
          .setTemperature((int)(metal.meltTemp + 273.15));
      
      FluidRegistry.registerFluid(fluid);
    }
    
    FluidRegistry.addBucketForFluid(fluid);
  
    final Block block = new BlockMetalFluid(fluid);
    
    if(fluid.getBlock() == null) {
      fluid.setBlock(block);
    }
    
    registry.register(block);
    
    metal.fluid = fluid;
  }

 

And the BlockMetalFluid code is as follows:

public class BlockMetalFluid extends BlockFluidClassic {
  public BlockMetalFluid(final Fluid fluid) {
    super(fluid, GradientBlocks.MATERIAL_LIQUID_METAL);
    this.setRegistryName(fluid.getUnlocalizedName());
    this.setUnlocalizedName(fluid.getUnlocalizedName());
    fluid.setBlock(this);
  }
}

 

Link to comment
Share on other sites

Entities swimming in water is handled by the entity class(es) and checks specifically for Material.WATER

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

The fact is that the Forge fluid system doesn't enable any of the behaviors of fluid (drowning due to lack of air, pushing entities according to flow, coloring the world according to the fluid color when submerged, and so forth).

 

The reason for this is that many vanilla classes specifically look for Material.WATER. So the easiest thing to do is to make sure your fluid has Material.WATER. This has some side effects though (map color will look like water) and as a modder you might not want all the behaviors -- like whether a sponge can soak it up, or whether it is swimmable.

 

So I have created some tutorials on how to use events to overcome this and selectively add the fluid behaviors you want. Check out my tutorial here: http://jabelarminecraft.blogspot.com/p/minecraft-modding-custom-fluid-blocks.html

 

I've also submitted a PR to implement this functionality in Forge directly, and it works well but I have some merge conflicts to fix but I've been traveling in Asia due to work and have other family obligations so realistically might not get it updated for another few weeks.

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

Link to comment
Share on other sites

  • 2 weeks later...

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.