Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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);

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.

  • Author

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;
}

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.