[SPIGOT-4139] Add Material.isFluid() Created: 24/Jul/18  Updated: 25/Jul/18

Status: Open
Project: Spigot
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Minor
Reporter: Black Hole Assignee: Unassigned
Resolution: Unresolved Votes: 1
Labels: fluid, material

Version: 1.13

 Description   

In 1.13 there are blocks that are obviously fluids: WATER, LAVA. And then there are waterlogged blocks that can contain water. But then there are blocks like SEAGRASS that count as liquid, too.

There has to be some function in vanilla that checks that could be used to add that as Material.isFluid()



 Comments   
Comment by Lorenzo Lapucci [ 25/Jul/18 ]

Sorry, I've made a mistake in my comment, corrected.

Comment by Black Hole [ 25/Jul/18 ]

All the Materials I listet above always counts as water. You placed different coral variants, some of those variants are waterlogged. Please have a look at the F3 screen or use a debug stick.

All I'm asking is to add a helper method that is automatically generated like the other methods in the Material enum using vanilla methods. Since those are generated by some private tool, I can't create a PR for this.

Comment by Lorenzo Lapucci [ 25/Jul/18 ]

you can easily add another condition in the if or use a switch.

Anyway, those blocks, for example, cannot be checked with their Material.  

so those wouldn't count as "water"

 

Making a method in Material is not suitable for this kind of situation as you would need block states

Comment by Black Hole [ 25/Jul/18 ]

That code would make DIRT below SEAGRASS turn into GRASS_BLOCK. As said above, SEAGRASS always counts as water and is not waterlogged.

Comment by Lorenzo Lapucci [ 25/Jul/18 ]
Block block = //loc.y + 1;
Material material = block.getType();
BlockData = block.getBlockData();
if (material == Material.WATER || material == Material.LAVA || blockData instanceof Waterlogged && ((Waterlogged) blockData).isWaterlogged()) {
    // block is water, lava or waterlogged
} else {
    // it is not liquid
}

 

Comment by Black Hole [ 25/Jul/18 ]

My use case is a command similar to "//green" of WorldEdit that turns DIRT into GRASS_BLOCK. DIRT that has liquid above won't be turned.

This method should be useful for every plugin that up until now just checked for the two water blocks (and maybe lava).

Here is a list of Materials that always counts as water:
WATER, BUBBLE_COLUMN, KELP, KELP_PLANT, SEAGRASS, TALL_SEAGRASS, TUBE_CORAL, BRAIN_CORAL, BUBBLE_CORAL, FIRE_CORAL, CONDUIT

Comment by Lorenzo Lapucci [ 25/Jul/18 ]

So instanceof Waterlogged is not enough in your case?

Can you explain how and why you would use it?

Comment by Black Hole [ 25/Jul/18 ]

I would define fluid as "something you can swim in". Blocks like sea grass, kelp plant or conduits always contains water.
Material.isFluid() should return true only if all block states counts as fluid. So plugins could use that method and additionally test the BlockData of the block if it's of type Waterlogged and isWaterlogged() returns true.
So maybe a better method name could be Material.isAlwaysFluid().

Comment by Lorenzo Lapucci [ 25/Jul/18 ]

You need to check if a block is waterlogged, but you can't do that using Materials because you don't have a way to know if it is actually waterlogged or not.

Comment by md_5 [ 25/Jul/18 ]

How come you're calling SeaGrass a fluid?
If you define SeaGrass as a fluid, then everything Waterlogged is a fluid.

Generated at Fri Dec 19 04:09:44 UTC 2025 using Jira 10.3.15#10030015-sha1:909cc43d292ca09e774c1a243d9819be3f2628cd.