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

I'm trying to make an item that speeds up the player in water using attribute modifiers, but it's massively restrained by the apparently unstoppable force of water lowering the player's movement speed. Is there any way to stop this? Would removing water's attribute modifier work? If so, where can I find its UUID?

  • Author

(shameless bump) If it'll help others understand what I'm trying to do, here's my code:

static final AttributeModifier attribute = new AttributeModifier(UUID.fromString("ABE2DC00-867B-4842-B773-FA91B0901CFE"), "movementSpeed", 1D, 2);
public void onArmorTick(World world, EntityPlayer player, ItemStack itemStack)
{
	if(player.getAir() < 300)
	{
		player.setAir(300);
	}

	if(KeyBindings.ability.isKeyDown())
	{
		if(player.isInWater())
		{
			if(player.getEntityAttribute(SharedMonsterAttributes.movementSpeed).getModifier(UUID.fromString("ABE2DC00-867B-4842-B773-FA91B0901CFE")) == null)
			{
				player.getEntityAttribute(SharedMonsterAttributes.movementSpeed).applyModifier(attribute);

			}
		}
		else
			player.getEntityAttribute(SharedMonsterAttributes.movementSpeed).removeModifier(attribute);
	}
}

(the AttributeModifier is created at the beginning of the class, I just cut out some unnecessary code)

The problem is that water and other fluids don't apply attribute modifiers, they modify the entity's motion directly in World#handleMaterialAcceleration.

 

The only way I've found to counteract this is to literally reverse it every single tick using a static helper method:

 

/**
 * Undoes whatever acceleration has been applied by materials such as flowing water (see {@link World#handleMaterialAcceleration})
 */
public static boolean reverseMaterialAcceleration(World world, AxisAlignedBB aabb, Material material, Entity entity) {
	int i = MathHelper.floor_double(aabb.minX);
	int j = MathHelper.floor_double(aabb.maxX + 1.0D);
	int k = MathHelper.floor_double(aabb.minY);
	int l = MathHelper.floor_double(aabb.maxY + 1.0D);
	int i1 = MathHelper.floor_double(aabb.minZ);
	int j1 = MathHelper.floor_double(aabb.maxZ + 1.0D);
	if (!WorldUtils.isAreaLoaded(world, i, k, i1, j, l, j1, true)) {
		return false;
	} else {
		boolean flag = false;
		Vec3 vec3 = new Vec3(0.0D, 0.0D, 0.0D);
		for (int k1 = i; k1 < j; ++k1) {
			for (int l1 = k; l1 < l; ++l1) {
				for (int i2 = i1; i2 < j1; ++i2) {
					BlockPos pos = new BlockPos(k1, l1, i2);
					IBlockState state = world.getBlockState(pos);
					Block block = state.getBlock();
					if (block.getMaterial() == material) {
						double liquidLevel = (double)((float)(l1 + 1) - BlockLiquid.getLiquidHeightPercent(((Integer) state.getValue(BlockLiquid.LEVEL)).intValue()));
						if ((double)l >= liquidLevel) {
							flag = true;
							vec3 = block.modifyAcceleration(world, pos, entity, vec3);
						}
					}
				}
			}
		}
		if (vec3.lengthVector() > 0.0D && entity.isPushedByWater()) {
			vec3 = vec3.normalize();
			double d1 = 0.014D;
			entity.motionX -= vec3.xCoord * d1;
			entity.motionY -= vec3.yCoord * d1;
			entity.motionZ -= vec3.zCoord * d1;
			entity.motionX *= 0.85D;
			entity.motionY *= 0.85D;
			entity.motionZ *= 0.85D;
		}
		return flag;
	}
}

 

That will let the player stand in any flowing liquid and be unmoved, but you do have to call it every tick for it to work, and let it run on both client and server side. In my own code for the heavy boots, I have it being called during Item#onArmorTick.

  • Author

Thanks so much! By looking at your code, I learned about using the player's motionX/Y/Z along with their LookVec, and now it works like a charm! (if a little differently to my plans)

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.