The buff I created stacks infinitely. Please help.

Started by pondu on

Topic category: Help with modding (Java Edition)

Last seen on 11:44, 30. Oct 2023
Joined Sep 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
The buff I created stacks infinitely. Please help.
Tue, 09/12/2023 - 00:53 (edited)
Even after the tick ends, the potion effect remains.
If you use it again, it will overlap.
What should I do?      How do I set the limit for the potion effect?
https://imgur.com/S9AGh4h
Edited by pondu on Tue, 09/12/2023 - 00:53
Last seen on 05:40, 21. Jan 2024
Joined Aug 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
remove the last two blocks…
Sun, 09/17/2023 - 03:31
  1. remove the last two blocks regarding removing the potion effect. That does nothing.
  2. also remove all those status effects when the potion effect is no longer active.

You could use 3 integers instead of 2 (ie. 0, 1)

This way 0 = active

1 = inactive

2 = inactive but potion effect applied.

also only set the nbt tag "1" to 0 when its 2 or 0

Pseudo Code:

if (entity hasEffect("ABSORPTION") && (get int.NBT("eg") == 3)) {
			set int.NBT("eg") = ("0");
		}
		if ((entity hasEffect("ABSORPTION"))) {
			entity.getPersistentData().putDouble("eg", 1);
		}
		if (entity.getPersistentData().getDouble("eg") == 0) {
		
			setMaxUpStep(99);
			setHealth(9999);
			
			set int.NBT("eg") = ("2");
		}
public class AaProcedure {
	public static void execute(Entity entity) {
		if (entity == null)
			return;
		if (entity instanceof LivingEntity _livEnt0 && _livEnt0.hasEffect(MobEffects.ABSORPTION) && !(entity.getPersistentData().getDouble("eg") == 3)) {
			entity.getPersistentData().putDouble("eg", 0);
		}
		if (!(entity instanceof LivingEntity _livEnt3 && _livEnt3.hasEffect(MobEffects.ABSORPTION))) {
			entity.getPersistentData().putDouble("eg", 1);
		}
		if (entity.getPersistentData().getDouble("eg") == 0) {
			entity.setMaxUpStep(99);
			if (entity instanceof LivingEntity _entity)
				_entity.setHealth(9999);
			if (entity instanceof Player _player) {
				_player.getAbilities().flying = true;
				_player.onUpdateAbilities();
			}
			entity.getPersistentData().putDouble("eg", 2);
		}
	}
}
Last seen on 05:40, 21. Jan 2024
Joined Aug 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
remove the last two blocks…
Sun, 09/17/2023 - 03:33
  1. remove the last two blocks regarding removing the potion effect. That does nothing.
  2. also remove all those status effects when the potion effect is no longer active.

You could use 3 integers instead of 2 (ie. 0, 1)

This way 0 = active

1 = inactive

2 = inactive but potion effect applied.

also only set the nbt tag "1" to 0 when its 2 or 0

Psedo code:

Pseudo Code:

if (entity hasEffect("ABSORPTION") && (get int.NBT("eg") == 3)) {
			set int.NBT("eg") = ("0");
		}
		if ((entity hasEffect("ABSORPTION"))) {
			entity.getPersistentData().putDouble("eg", 1);
		}
		if (entity.getPersistentData().getDouble("eg") == 0) {
		
			setMaxUpStep(99);
			setHealth(9999);
			
			set int.NBT("eg") = ("2");
		}
		

 

Acual code:


public class AaProcedure {
	public static void execute(Entity entity) {
		if (entity == null)
			return;
		if (entity instanceof LivingEntity _livEnt0 && _livEnt0.hasEffect(MobEffects.ABSORPTION) && !(entity.getPersistentData().getDouble("eg") == 3)) {
			entity.getPersistentData().putDouble("eg", 0);
		}
		if (!(entity instanceof LivingEntity _livEnt3 && _livEnt3.hasEffect(MobEffects.ABSORPTION))) {
			entity.getPersistentData().putDouble("eg", 1);
		}
		if (entity.getPersistentData().getDouble("eg") == 0) {
			entity.setMaxUpStep(99);
			if (entity instanceof LivingEntity _entity)
				_entity.setHealth(9999);
			if (entity instanceof Player _player) {
				_player.getAbilities().flying = true;
				_player.onUpdateAbilities();
			}
			entity.getPersistentData().putDouble("eg", 2);
		}
	}
}
Last seen on 22:41, 16. Oct 2023
Joined Mar 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
You could do rusty's method…
Tue, 09/19/2023 - 15:29

You could do rusty's method or you can keep yours like my image below

Image

 

Just replace effect with yours. then change nbt tag to whatever you want, I do recommend using something longer then "1" to not run the risk of mods doing the same nbt. 
And then keep how you have your armor with armor value, just remove the extras. Unneeded. I used a local variable to help mimic your setup as I don't have the armor thing you have. 

Last seen on 05:40, 21. Jan 2024
Joined Aug 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
@SkylieTuff The effect would…
Wed, 09/20/2023 - 11:12

@SkylieTuff The effect would still stack since your constantly applying the operations on the variables which changed.

The result of this and the initial code hasn't changed

 

The metjod you've used is literally used to do incremental changes. Its used to make the operations performed STACK

 

Basically:

int hp = 1;
while (apply = 1) {
  hp = hp+1;
}

This is the same as

int hp = 1;
while (apply = 1) {
  hp++;
}

The code will store the changes in the same variable that it'll later chnage AGAIN.

 

Its like you store some boxes in your house. Later when you deposit more you aren't RESETTING the #boxes you're merely ADDING MORE TO THE CURRENT AMOUNT

the new value is #boxes + x

 

since you're storing in the same house you're constantly adding the boxes without reseting them.

 

The code doesn't know wether it has to stop changing/incrementing the variable until you tell it to.

Last seen on 22:41, 16. Oct 2023
Joined Mar 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
@rusty it wasn't for you &…
Fri, 09/22/2023 - 00:36

@rusty it wasn't for you & if you read, I used variables to make a monicker for op. But I also realize what he wants and I could give him a ten times better solution. Lol. If he wants one. And I just used his solution and removed some things and change things because I was too tired to realize what op was wanting when I did it.