Jump to content

Recommended Posts

Posted

Hello, I am currently developing a Path-finding mod for 1.7.10. I have a function that tells me what is the block type and it works like that:

 

private static BlockType getBlockType(int[] blockLocation) {
	return 
			theWorld.getBlock(				
			blockLocation[Coords.X.ordinal()],
			blockLocation[Coords.Y.ordinal()],
			blockLocation[Coords.Z.ordinal()]).getBlockHardness(theWorld, blockLocation[Coords.X.ordinal()],
					blockLocation[Coords.Y.ordinal()],
					blockLocation[Coords.Z.ordinal()]) >= 0.01f				
			? BlockType.SOLID
			: BlockType.NON_SOLID;
}

 

The reason I used this method instead of using method such as isBlockNormalCubeDefault is because it identified some blocks (such as leaves) as non-solid.

Anyway, I want to check if a block has type of liquids in it, water/lava. it doesn't matter which or whether it's flowing or not, but I must know that it has liquids in it.

 

Any suggestions how?

Thanks in advance.

Posted

This would return true if its a water block ...or it is a block that has material as water (like underwater plants, which you can swim thru).

 

(aWorld.getBlock((int)xPos, (int)yPos+up, (int)zPos).getMaterial() == Material.water)

 

Posted

This would return true if its a water block ...or it is a block that has material as water (like underwater plants, which you can swim thru).

 

(aWorld.getBlock((int)xPos, (int)yPos+up, (int)zPos).getMaterial() == Material.water)

thank you, would it work with Material.Lava too?

and would it do any difference between water and flowing water?

 

Thanks!

Posted

You might instead test for instanceof BlockLiquid, but see what that does with ice. Checking instanceof might help your mod work with other mods that introduce their own liquids.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Posted

This would return true if its a water block ...or it is a block that has material as water (like underwater plants, which you can swim thru).

 

(aWorld.getBlock((int)xPos, (int)yPos+up, (int)zPos).getMaterial() == Material.water)

thank you, would it work with Material.Lava too?

and would it do any difference between water and flowing water?

 

Thanks!

 

I know it works with flowing water as I've tested it myself to make some plants that check for water blocks nearby with getMaterial material.water. So source/flowing.

 

I imagine lava works the same but haven't tested it yet. I will be soon though.

 

Also, farmland (fertilized or hydrated soil in vanilla) does this code. Checks material water, that's how come your farmland hydrates even if flowing water is nearby.

www.YouTube.com/WeiseGamer

www.twitter.com/WeiseGamer

Posted

You should check that the block is an instanceof BlockLiquidBase, then cast and get the Fluid field and examine it for its liquid properties

All mod added liquids should extend from that, but that includes gasses which you would want to treat as air (hence looking at the Fluid field's properties).

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.

Posted

When block is Block type, block.getMaterial().isLiquid() would be sufficient.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Posted

You should check that the block is an instanceof BlockLiquidBase, then cast and get the Fluid field and examine it for its liquid properties

All mod added liquids should extend from that, but that includes gasses which you would want to treat as air (hence looking at the Fluid field's properties).

 

Most mod fluid blocks will extend from

BlockFluidBase

(which you probably meant), but it's entirely possible that they'll implement

IFluidBlock

themselves and not use the reference implementation.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

I would use instanceof checks instead of material checks. I would check for both BlockLiquid and BlockFluidBase. That should cover most vanilla and mod "liquids". If you want an exception (like if there is some BlockLiquid you don't want to act the same way, then additionally check for whatever you want.

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

Posted

I would use instanceof checks instead of material checks. I would check for both BlockLiquid and BlockFluidBase. That should cover most vanilla and mod "liquids". If you want an exception (like if there is some BlockLiquid you don't want to act the same way, then additionally check for whatever you want.

There is some possibility that mod block uses IFluidBlock as Choonster said.

Vanilla checks if a block is liquid using block.getMaterial().isLiquid().

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Posted

You can instanceof IFluidBlock too.

The material check should be sufficient, but just look out for possible weirdnesses.  I don't recall offhand if gaseous materials return true for isLiquid() or not.

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.

Posted

You can instanceof IFluidBlock too.

The material check should be sufficient, but just look out for possible weirdnesses.  I don't recall offhand if gaseous materials return true for isLiquid() or not.

 

I agree that material should work with vanilla liquids but I think there is more chance that other mods create new materials for custom fluids whereas it is unlikely that they wouldn't extend or implement fluids. So I think maximum compatibility would be using instanceof.

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

Posted

You can instanceof IFluidBlock too.

The material check should be sufficient, but just look out for possible weirdnesses.  I don't recall offhand if gaseous materials return true for isLiquid() or not.

 

Vanilla has no concept of gases, so most gaseous fluids (at least the ones from Thermal Foundation, IC2 and Railcraft) just use

MaterialLiquid

(which returns

true

from

Material#isLiquid

).

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

You can instanceof IFluidBlock too.

The material check should be sufficient, but just look out for possible weirdnesses.  I don't recall offhand if gaseous materials return true for isLiquid() or not.

 

Vanilla has no concept of gases, so most gaseous fluids (at least the ones from Thermal Foundation, IC2 and Railcraft) just use

MaterialLiquid

(which returns

true

from

Material#isLiquid

).

 

That's what I thought.  Now that I have a chance to dig at my own code where I have my own gas...

Ah here we go

 

if(block instanceof IFluidBlock) {
    IFluidBlock fb = (IFluidBlock)block;
    Fluid fl = fb.getFluid();
    boolean isGaseous = fl.isGaseous();
}

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.

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.