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

EDIT: I just realised that I did the UUID thing wrong. Working on this...

EDIT2: It was indeed the issue. To anyone else coming across this: DO NOT use the player UUID for the modifier, use a custom one per modifier instead. For example, use UUID.fromString("<string goes here>") to generate it.

Hello, I have a problem: After reading up on other threads, I was made aware of the fact that instead of setting the base value of a SharedMonsterAttribute, it is better to add a modifier to it to keep compatibility.

This effect is applied to every player once after joining the world.

However, if I close the game and then re-launch it and join the same world again, the old effect does not seem to be deleted - in the case of the health effect (FIRE), the HP went back to 10 hearts after joining the world a third time, only to then jump to 13. Intended would be that the modifier can only be applied once at a time, for a maximum of 11 hearts (22 HP).

 

This is the code in use:

// Attribute modifiers - these serve to define modifiers (multiplicative for speed, additive for health; depends on operationIn)
AttributeModifier moveSpeedBonus = new AttributeModifier(evPlayer.getUniqueID(),"waterAirMoveBonus",0.15D,2);
AttributeModifier moveSpeedMalus = new AttributeModifier(evPlayer.getUniqueID(),"earthMoveMalus",-0.05D,2);
AttributeModifier healthBonus = new AttributeModifier(evPlayer.getUniqueID(),"fireHealthBonus",2.0D,0);
AttributeModifier healthMalus = new AttributeModifier(evPlayer.getUniqueID(),"waterHealthMalus",-2.0D,0);

// Get rid of any possible modifiers
if (evPlayer.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).hasModifier(moveSpeedBonus))
{
	evPlayer.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).removeModifier(moveSpeedBonus);
}
if (evPlayer.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).hasModifier(moveSpeedMalus))
{
	evPlayer.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).removeModifier(moveSpeedMalus);
}
if (evPlayer.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).hasModifier(healthBonus))
{
	evPlayer.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).removeModifier(healthBonus);
}
if (evPlayer.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).hasModifier(healthMalus))
{
	evPlayer.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).removeModifier(healthMalus);
}
// Apply where needed
switch(element)
{
	case FIRE:
		evPlayer.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).applyModifier(healthBonus);

		if (evPlayer.getHealth() == evPlayer.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).getBaseValue())
		{
			evPlayer.setHealth(evPlayer.getHealth() + 2); //This is to heal the player up by the 2 HP/1 heart if the element was just switched to.
		}
		break;

	case AIR:
		evPlayer.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).applyModifier(moveSpeedBonus);
		break;

	case WATER:
		evPlayer.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).applyModifier(healthMalus);
		evPlayer.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).applyModifier(moveSpeedBonus);
		break;

	case EARTH:
		evPlayer.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).applyModifier(moveSpeedMalus);
		break;

	default:
		break;
}

 

Edited by Alekseyev
solved

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.