Jump to content

[1.7.10][and newer]How to get the speed part pushed by water?


D0431791

Recommended Posts

Entities can be pushed by water.

How to get the speed part pushed by water?

 

The code is expected as below:

public static Vec3 getSpeedPartByWater(Eneity x){
Vec3 y=㊣㊣㊣㊣㊣;
㊣㊣㊣㊣㊣
㊣㊣㊣㊣㊣
㊣㊣㊣㊣㊣
return y;
}

 

example : make a player move 2x in water

Vec3 playerSpeedPartByWater=getSpeedPartByWater(player);
player.moveEntity(player.motionX-playerSpeedPartByWater.xCoord , player.motionY-playerSpeedPartByWater.yCoord, player.motionZ-playerSpeedPartByWater.zCoord);

Link to comment
Share on other sites

The method that handles water acceleration is in the World class and is called #handleMaterialAcceleration.

 

If you determine the player is in water, you can do some math to reverse it and then reapply it, or you could probably get by with a simple player.motionX/Y/Z *= 2.

 

If you don't want the player to get pushed at all, you can make a method to reverse the applied motion.

Link to comment
Share on other sites

The method that handles water acceleration is in the World class and is called #handleMaterialAcceleration.

 

If you determine the player is in water, you can do some math to reverse it and then reapply it, or you could probably get by with a simple player.motionX/Y/Z *= 2.

 

If you don't want the player to get pushed at all, you can make a method to reverse the applied motion.

 

Now I can see the effect.

The code looks like this now:


public static Vec3 getSpeedPartByWater(Entity x,World xworld){
	Vec3 y=Vec3.createVectorHelper(0d,0d,0d);
	AxisAlignedBB zaabb=x.boundingBox.expand(0d,-0.40234375,0d).contract(0.001D, 0.001D, 0.001D);
	int i1=(int)Math.floor(zaabb.minX);
	int i2=(int)Math.floor(zaabb.maxX)+1;
	int j1=(int)Math.floor(zaabb.minY);
	int j2=(int)Math.floor(zaabb.maxY)+1;
	int k1=(int)Math.floor(zaabb.minZ);
	int k2=(int)Math.floor(zaabb.maxZ)+1;
	if (!xworld.checkChunksExist(i1,j1,k1,i2,j2,k2)) {return y;}
	int i,j,k;
	Block zblock=null;
	for(i=i1;i<i2;i++){
		for(j=j1;j<j2;j++){
			for(k=k1;k<k2;k++){
				zblock=xworld.getBlock(i,j,k);
				if(zblock==null){continue;}
				if(zblock.getMaterial()!=Material.water){continue;}
				if(j2<j+1-BlockLiquid.getLiquidHeightPercent(xworld.getBlockMetadata(i,j,k))){continue;}
				zblock.velocityToAddToEntity(xworld,i,j,k,x,y);
			}
		}
	}
	if(y.lengthVector()>0&&x.isPushedByWater()) {
		y=y.normalize();
		y.xCoord=x.motionX*0.15+y.xCoord*0.0119;
		y.yCoord=x.motionY*0.15+y.yCoord*0.0119;
		y.zCoord=x.motionZ*0.15+y.zCoord*0.0119;
	}
	return y;
}

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.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.