Jump to content

[1.12.1] placing a fluid block in the world which places flow blocks itself


pcblockgermany

Recommended Posts

Hello,

 

I've recently begun to get into modding and want to make a block that can register if there's a fluid block next to it and then make a copy of the fluid on free sides of the block, but with a reduced liquid height, as if the liquid would flow through it. Currently I'm having some problems though, at the moment it does create a copy of the fluid with a reduced liquid height (on the opposite site, I've reduced it to this case atm), this liquid, however, doesn't flow. Here's a picture of the problem: ntlkfu6.png

(I'll add the textures later, right now I'm just trying to get the main concept to work)

 

And here's what I've come up with so far:

public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos)
    {
		 for (EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL)
	        {
			 
	            if (worldIn.getBlockState(pos.offset(enumfacing)).getMaterial().isLiquid() && worldIn.getBlockState(pos.offset(enumfacing.getOpposite())).getMaterial() == Material.AIR)
	            {
	            	//Block BlockFacing = worldIn.getBlockState(pos.offset(enumfacing)).getBlock();
	            	IBlockState blockstate = worldIn.getBlockState(pos.offset(enumfacing));
	            	int LiquidHeightInt = (int) worldIn.getBlockState(pos.offset(enumfacing)).getProperties().get(BlockLiquid.LEVEL);
	                
	            	if(LiquidHeightInt <= 3)
	            	{
	            		//sets the blockstate on the opposite side of the block to be the one of the source, but with decreased fluid level by 2
	            		worldIn.setBlockState(pos.offset(enumfacing.getOpposite()), blockstate.cycleProperty(BlockLiquid.LEVEL).cycleProperty(BlockLiquid.LEVEL), 2);
	            		
	            		
	            		//updates the neighbouring blocks so that there will be no fluid on a side of the block if the initial source has been removed
	            		worldIn.getBlockState(pos.offset(enumfacing.getOpposite())).neighborChanged(worldIn, pos.offset(enumfacing.getOpposite()), worldIn.getBlockState(pos.offset(enumfacing.getOpposite())).getBlock(), pos);
	            		
	            	}
	            }
	            
	            // TODO add cases 
	            
	        }
		 
    }

 

I will probably later make a tileentity do this, so that the liquid can flow through multiple block etc., but I'd first like to get it to work at all. If you need it, here is my GitHub Repo.

I think the problem may be that the source fluid block creates other "flow" blocks, and b/c I'm not placing a fluid source block, it doesn't place the other "fllow" blocks. If this is the case, I have no idea though how to fix it. I've tried looking at BlockDynamicLiquid and BlockLiquid, but wasn't able to come up with a solution. Am I maybe approaching this wrong and should try to make a block that doesn't have a collision box so that a fluid can flow through it, but still somehow make it so that entities can't pass through it? Is it even possible to have two blocks in the same space? Anyway, thanks in advance!

 

Edited by pcblockgermany
Link to comment
Share on other sites

Quote

I think the problem may be that the source fluid block creates other "flow" blocks, and b/c I'm not placing a fluid source block, it doesn't place the other "fllow" blocks. If this is the case, I have no idea though how to fix it. I've tried looking at BlockDynamicLiquid and BlockLiquid, but wasn't able to come up with a solution.

I did, but it didn't help me a lot. I think I did find how Minecraft calculates where the fluid flows to, but I don't know how to apply that to the placed fluid block, b/c it theoretically should do that on its own.

 

Link to comment
Share on other sites

TL;DR:

I don't think you'll ever get this to work. Last I poked around with something similar, the newly spawned water block (the one you have that won't flow) updates, detects it doesn't have a neighbor that is itself, but with a higher amount of liquid, and so it sets itself to air.

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

Depending on what you're trying to achieve you might be able to create a custom fluid block or maybe a block that extends the liquid block that acts like water, but it would likely be a lot of work. Also, the key point would remain the same -- you need to place a source block. However, it might be worth a try -- create a custom block that extends BlockWater and change the behavior of the source so it could work at a reduced level.

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

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.