Adding onto a variable acts strange

Started by Luca76 on

Topic category: Help with modding (Java Edition)

Last seen on 11:29, 15. Jun 2022
Joined Jun 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Adding onto a variable acts strange

hello,

i'm making a mod with a mood variable and an effect that every time it goes up by 1 level, for a maximum of 7 levels, it adds 1 to the mood variable except level 5 wich removes 1 but whenever i add the effect to the player it adds 6 values and it remains that way but after some levels it removes 12 levels and then sets the value to -49, why is it doing that and how do i fix it,

here is the code (generated code viewer, i'm using blocks but i can't make 500 screnshots)

public class HighOnEffectActiveTickProcedure {
	public static void execute(LevelAccessor world, Entity entity) {
		if (entity == null)
			return;
		boolean HasNotGottenMoodBoostLevel1 = false;
		boolean HasNotGottenMoodBoostLevel2 = false;
		boolean HasNotGottenMoodBoostLevel3 = false;
		boolean HasNotGottenMoodBoostLevel4 = false;
		boolean HasNotGottenMoodBoostLevel5 = false;
		boolean HasNotGottenMoodBoostLevel6 = false;
		boolean HasNotGottenMoodBoostLevel7 = false;
		HasNotGottenMoodBoostLevel1 = true;
		HasNotGottenMoodBoostLevel2 = true;
		HasNotGottenMoodBoostLevel3 = true;
		HasNotGottenMoodBoostLevel4 = true;
		HasNotGottenMoodBoostLevel5 = true;
		HasNotGottenMoodBoostLevel6 = true;
		HasNotGottenMoodBoostLevel7 = true;
		if ((entity instanceof LivingEntity _livEnt && _livEnt.hasEffect(WeedModModMobEffects.HIGH.get())
				? _livEnt.getEffect(WeedModModMobEffects.HIGH.get()).getAmplifier()
				: 0) == 0) {
			if ((entity.getCapability(WeedModModVariables.PLAYER_VARIABLES_CAPABILITY, null)
					.orElse(new WeedModModVariables.PlayerVariables())).Mood < 6 && HasNotGottenMoodBoostLevel1) {
				{
					double _setval = (entity.getCapability(WeedModModVariables.PLAYER_VARIABLES_CAPABILITY, null)
							.orElse(new WeedModModVariables.PlayerVariables())).Mood + 1;
					entity.getCapability(WeedModModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
						capability.Mood = _setval;
						capability.syncPlayerVariables(entity);
					});
				}
				HasNotGottenMoodBoostLevel1 = false;
			}
			if (!(entity instanceof LivingEntity _livEnt ? _livEnt.hasEffect(MobEffects.MOVEMENT_SLOWDOWN) : false)) {
				if (entity instanceof LivingEntity _entity)
					_entity.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN,
							entity instanceof LivingEntity _livEnt && _livEnt.hasEffect(WeedModModMobEffects.HIGH.get())
									? _livEnt.getEffect(WeedModModMobEffects.HIGH.get()).getDuration()
									: 0,
							0));
			}
		} else if ((entity instanceof LivingEntity _livEnt && _livEnt.hasEffect(WeedModModMobEffects.HIGH.get())
				? _livEnt.getEffect(WeedModModMobEffects.HIGH.get()).getAmplifier()
				: 0) == 1) {
			if ((entity.getCapability(WeedModModVariables.PLAYER_VARIABLES_CAPABILITY, null)
					.orElse(new WeedModModVariables.PlayerVariables())).Mood < 6 && HasNotGottenMoodBoostLevel2) {
				{
					double _setval = (entity.getCapability(WeedModModVariables.PLAYER_VARIABLES_CAPABILITY, null)
							.orElse(new WeedModModVariables.PlayerVariables())).Mood + 1;
					entity.getCapability(WeedModModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
						capability.Mood = _setval;
						capability.syncPlayerVariables(entity);
					});
				}
				HasNotGottenMoodBoostLevel2 = false;
			}
			if (!(entity instanceof LivingEntity _livEnt ? _livEnt.hasEffect(MobEffects.MOVEMENT_SLOWDOWN) : false)) {
				if (entity instanceof LivingEntity _entity)
					_entity.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN,
							entity instanceof LivingEntity _livEnt && _livEnt.hasEffect(WeedModModMobEffects.HIGH.get())
									? _livEnt.getEffect(WeedModModMobEffects.HIGH.get()).getDuration()
									: 0,
							0));
			}
			if (Mth.nextInt(new Random(), 1, 600) == 1) {
				if (entity instanceof LivingEntity _entity)
					_entity.removeEffect(MobEffects.MOVEMENT_SLOWDOWN);
				if (entity instanceof LivingEntity _entity)
					_entity.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, 40, 255));
				if (entity instanceof Player _player && !_player.level.isClientSide())
					_player.displayClientMessage(new TextComponent("I wonder if a gorilla would like hamburgers "), (true));
			}
		} else if ((entity instanceof LivingEntity _livEnt && _livEnt.hasEffect(WeedModModMobEffects.HIGH.get())
				? _livEnt.getEffect(WeedModModMobEffects.HIGH.get()).getAmplifier()
				: 0) == 2) {
			if ((entity.getCapability(WeedModModVariables.PLAYER_VARIABLES_CAPABILITY, null)
					.orElse(new WeedModModVariables.PlayerVariables())).Mood < 6 && HasNotGottenMoodBoostLevel3) {
				{
					double _setval = (entity.getCapability(WeedModModVariables.PLAYER_VARIABLES_CAPABILITY, null)
							.orElse(new WeedModModVariables.PlayerVariables())).Mood + 1;
					entity.getCapability(WeedModModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
						capability.Mood = _setval;
						capability.syncPlayerVariables(entity);
					});
				}
				HasNotGottenMoodBoostLevel3 = false;
			}
			if (!(entity instanceof LivingEntity _livEnt ? _livEnt.hasEffect(MobEffects.MOVEMENT_SLOWDOWN) : false)) {
				if (entity instanceof LivingEntity _entity)
					_entity.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN,
							entity instanceof LivingEntity _livEnt && _livEnt.hasEffect(WeedModModMobEffects.HIGH.get())
									? _livEnt.getEffect(WeedModModMobEffects.HIGH.get()).getDuration()
									: 0,
							0));
			}
			if (Mth.nextInt(new Random(), 1, 600) == 1) {
				if (entity instanceof LivingEntity _entity)
					_entity.removeEffect(MobEffects.MOVEMENT_SLOWDOWN);
				if (entity instanceof LivingEntity _entity)
					_entity.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, 40, 255));
				{
					Entity _ent = entity;
					if (!_ent.level.isClientSide() && _ent.getServer() != null)
						_ent.getServer().getCommands().performCommand(_ent.createCommandSourceStack().withSuppressedOutput().withPermission(4),
								"say \"I wonder if a gorilla would like hamburgers\"");
				}
			}
		} else if ((entity instanceof LivingEntity _livEnt && _livEnt.hasEffect(WeedModModMobEffects.HIGH.get())
				? _livEnt.getEffect(WeedModModMobEffects.HIGH.get()).getAmplifier()
				: 0) == 3) {
			if ((entity.getCapability(WeedModModVariables.PLAYER_VARIABLES_CAPABILITY, null)
					.orElse(new WeedModModVariables.PlayerVariables())).Mood < 6 && HasNotGottenMoodBoostLevel4) {
				{
					double _setval = (entity.getCapability(WeedModModVariables.PLAYER_VARIABLES_CAPABILITY, null)
							.orElse(new WeedModModVariables.PlayerVariables())).Mood + 1;
					entity.getCapability(WeedModModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
						capability.Mood = _setval;
						capability.syncPlayerVariables(entity);
					});
				}
				HasNotGottenMoodBoostLevel4 = false;
			}
			if (!(entity instanceof LivingEntity _livEnt ? _livEnt.hasEffect(MobEffects.MOVEMENT_SLOWDOWN) : false)) {
				if (entity instanceof LivingEntity _entity)
					_entity.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN,
							entity instanceof LivingEntity _livEnt && _livEnt.hasEffect(WeedModModMobEffects.HIGH.get())
									? _livEnt.getEffect(WeedModModMobEffects.HIGH.get()).getDuration()
									: 0,
							0));
			}
			if (Mth.nextInt(new Random(), 1, 300) == 1) {
				if (entity instanceof LivingEntity _entity)
					_entity.removeEffect(MobEffects.MOVEMENT_SLOWDOWN);
				if (entity instanceof LivingEntity _entity)
					_entity.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, 40, 255));
				{
					Entity _ent = entity;
					if (!_ent.level.isClientSide() && _ent.getServer() != null)
						_ent.getServer().getCommands().performCommand(_ent.createCommandSourceStack().withSuppressedOutput().withPermission(4),
								"say \"I wonder if a gorilla would like hamburgers\"");
				}
			}
			while ((world.getBlockState(new BlockPos(
					entity.level.clip(new ClipContext(entity.getEyePosition(1f), entity.getEyePosition(1f).add(entity.getViewVector(1f).scale(5)),
							ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, entity)).getBlockPos().getX(),
					entity.level.clip(new ClipContext(entity.getEyePosition(1f), entity.getEyePosition(1f).add(entity.getViewVector(1f).scale(5)),
							ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, entity)).getBlockPos().getY(),
					entity.level.clip(new ClipContext(entity.getEyePosition(1f), entity.getEyePosition(1f).add(entity.getViewVector(1f).scale(5)),
							ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, entity)).getBlockPos().getZ())))
					.getBlock() == (new Object() {
						public BlockState with(BlockState _bs, String property, boolean newValue) {
							Property<?> _prop = _bs.getBlock().getStateDefinition().getProperty(property);
							return _prop instanceof BooleanProperty _bp ? _bs.setValue(_bp, newValue) : _bs;
						}
					}.with(Blocks.FURNACE.defaultBlockState(), "lit", (true))).getBlock()) {
				if (entity instanceof LivingEntity _entity)
					_entity.removeEffect(MobEffects.MOVEMENT_SLOWDOWN);
				if (entity instanceof LivingEntity _entity)
					_entity.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, 40, 255));
			}
		} else if ((entity instanceof LivingEntity _livEnt && _livEnt.hasEffect(WeedModModMobEffects.HIGH.get())
				? _livEnt.getEffect(WeedModModMobEffects.HIGH.get()).getAmplifier()
				: 0) == 4) {
			if ((entity.getCapability(WeedModModVariables.PLAYER_VARIABLES_CAPABILITY, null)
					.orElse(new WeedModModVariables.PlayerVariables())).Mood <= 6 && HasNotGottenMoodBoostLevel5) {
				{
					double _setval = (entity.getCapability(WeedModModVariables.PLAYER_VARIABLES_CAPABILITY, null)
							.orElse(new WeedModModVariables.PlayerVariables())).Mood - 1;
					entity.getCapability(WeedModModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
						capability.Mood = _setval;
						capability.syncPlayerVariables(entity);
					});
				}
				HasNotGottenMoodBoostLevel5 = false;
			}
			if (!(entity instanceof LivingEntity _livEnt ? _livEnt.hasEffect(MobEffects.MOVEMENT_SLOWDOWN) : false)) {
				if (entity instanceof LivingEntity _entity)
					_entity.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN,
							entity instanceof LivingEntity _livEnt && _livEnt.hasEffect(WeedModModMobEffects.HIGH.get())
									? _livEnt.getEffect(WeedModModMobEffects.HIGH.get()).getDuration()
									: 0,
							0));
			}
			if (Mth.nextInt(new Random(), 1, 300) == 1) {
				if (entity instanceof LivingEntity _entity)
					_entity.removeEffect(MobEffects.MOVEMENT_SLOWDOWN);
				if (entity instanceof LivingEntity _entity)
					_entity.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, 40, 255));
				{
					Entity _ent = entity;
					if (!_ent.level.isClientSide() && _ent.getServer() != null)
						_ent.getServer().getCommands().performCommand(_ent.createCommandSourceStack().withSuppressedOutput().withPermission(4),
								"say \"I wonder if a gorilla would like hamburgers\"");
				}
			}
			while ((world.getBlockState(new BlockPos(
					entity.level.clip(new ClipContext(entity.getEyePosition(1f), entity.getEyePosition(1f).add(entity.getViewVector(1f).scale(5)),
							ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, entity)).getBlockPos().getX(),
					entity.level.clip(new ClipContext(entity.getEyePosition(1f), entity.getEyePosition(1f).add(entity.getViewVector(1f).scale(5)),
							ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, entity)).getBlockPos().getY(),
					entity.level.clip(new ClipContext(entity.getEyePosition(1f), entity.getEyePosition(1f).add(entity.getViewVector(1f).scale(5)),
							ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, entity)).getBlockPos().getZ())))
					.getBlock() == (new Object() {
						public BlockState with(BlockState _bs, String property, boolean newValue) {
							Property<?> _prop = _bs.getBlock().getStateDefinition().getProperty(property);
							return _prop instanceof BooleanProperty _bp ? _bs.setValue(_bp, newValue) : _bs;
						}
					}.with(Blocks.FURNACE.defaultBlockState(), "lit", (true))).getBlock()) {
				if (entity instanceof LivingEntity _entity)
					_entity.removeEffect(MobEffects.MOVEMENT_SLOWDOWN);
				if (entity instanceof LivingEntity _entity)
					_entity.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, 40, 255));
			}
		} else if ((entity instanceof LivingEntity _livEnt && _livEnt.hasEffect(WeedModModMobEffects.HIGH.get())
				? _livEnt.getEffect(WeedModModMobEffects.HIGH.get()).getAmplifier()
				: 0) == 5) {
			if ((entity.getCapability(WeedModModVariables.PLAYER_VARIABLES_CAPABILITY, null)
					.orElse(new WeedModModVariables.PlayerVariables())).Mood < 6 && HasNotGottenMoodBoostLevel6) {
				{
					double _setval = (entity.getCapability(WeedModModVariables.PLAYER_VARIABLES_CAPABILITY, null)
							.orElse(new WeedModModVariables.PlayerVariables())).Mood + 1;
					entity.getCapability(WeedModModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
						capability.Mood = _setval;
						capability.syncPlayerVariables(entity);
					});
				}
				HasNotGottenMoodBoostLevel6 = false;
			}
			if (!(entity instanceof LivingEntity _livEnt ? _livEnt.hasEffect(MobEffects.MOVEMENT_SLOWDOWN) : false)) {
				if (entity instanceof LivingEntity _entity)
					_entity.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN,
							entity instanceof LivingEntity _livEnt && _livEnt.hasEffect(WeedModModMobEffects.HIGH.get())
									? _livEnt.getEffect(WeedModModMobEffects.HIGH.get()).getDuration()
									: 0,
							0));
			}
			if (Mth.nextInt(new Random(), 1, 300) == 1) {
				if (entity instanceof LivingEntity _entity)
					_entity.removeEffect(MobEffects.MOVEMENT_SLOWDOWN);
				if (entity instanceof LivingEntity _entity)
					_entity.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, 40, 255));
				{
					Entity _ent = entity;
					if (!_ent.level.isClientSide() && _ent.getServer() != null)
						_ent.getServer().getCommands().performCommand(_ent.createCommandSourceStack().withSuppressedOutput().withPermission(4),
								"say \"I wonder if a gorilla would like hamburgers\"");
				}
			}
			if (Mth.nextInt(new Random(), 1, 24000) == 1) {
				if (entity instanceof LivingEntity _entity)
					_entity.removeEffect(MobEffects.MOVEMENT_SLOWDOWN);
				if (entity instanceof LivingEntity _entity)
					_entity.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, 2400, 255));
			}
			while ((world.getBlockState(new BlockPos(
					entity.level.clip(new ClipContext(entity.getEyePosition(1f), entity.getEyePosition(1f).add(entity.getViewVector(1f).scale(5)),
							ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, entity)).getBlockPos().getX(),
					entity.level.clip(new ClipContext(entity.getEyePosition(1f), entity.getEyePosition(1f).add(entity.getViewVector(1f).scale(5)),
							ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, entity)).getBlockPos().getY(),
					entity.level.clip(new ClipContext(entity.getEyePosition(1f), entity.getEyePosition(1f).add(entity.getViewVector(1f).scale(5)),
							ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, entity)).getBlockPos().getZ())))
					.getBlock() == (new Object() {
						public BlockState with(BlockState _bs, String property, boolean newValue) {
							Property<?> _prop = _bs.getBlock().getStateDefinition().getProperty(property);
							return _prop instanceof BooleanProperty _bp ? _bs.setValue(_bp, newValue) : _bs;
						}
					}.with(Blocks.FURNACE.defaultBlockState(), "lit", (true))).getBlock()) {
				if (entity instanceof LivingEntity _entity)
					_entity.removeEffect(MobEffects.MOVEMENT_SLOWDOWN);
				if (entity instanceof LivingEntity _entity)
					_entity.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, 40, 255));
			}
		} else if ((entity instanceof LivingEntity _livEnt && _livEnt.hasEffect(WeedModModMobEffects.HIGH.get())
				? _livEnt.getEffect(WeedModModMobEffects.HIGH.get()).getAmplifier()
				: 0) == 6) {
			if ((entity.getCapability(WeedModModVariables.PLAYER_VARIABLES_CAPABILITY, null)
					.orElse(new WeedModModVariables.PlayerVariables())).Mood < 6 && HasNotGottenMoodBoostLevel7) {
				{
					double _setval = (entity.getCapability(WeedModModVariables.PLAYER_VARIABLES_CAPABILITY, null)
							.orElse(new WeedModModVariables.PlayerVariables())).Mood + 1;
					entity.getCapability(WeedModModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
						capability.Mood = _setval;
						capability.syncPlayerVariables(entity);
					});
				}
				HasNotGottenMoodBoostLevel7 = false;
			}
			if (!(entity instanceof LivingEntity _livEnt ? _livEnt.hasEffect(MobEffects.MOVEMENT_SLOWDOWN) : false)) {
				if (entity instanceof LivingEntity _entity)
					_entity.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN,
							entity instanceof LivingEntity _livEnt && _livEnt.hasEffect(WeedModModMobEffects.HIGH.get())
									? _livEnt.getEffect(WeedModModMobEffects.HIGH.get()).getDuration()
									: 0,
							1));
			}
			if (Mth.nextInt(new Random(), 1, 150) == 1) {
				if (entity instanceof LivingEntity _entity)
					_entity.removeEffect(MobEffects.MOVEMENT_SLOWDOWN);
				if (entity instanceof LivingEntity _entity)
					_entity.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, 40, 255));
			}
			if (Mth.nextInt(new Random(), 1, 24000) == 1) {
				if (entity instanceof LivingEntity _entity)
					_entity.removeEffect(MobEffects.MOVEMENT_SLOWDOWN);
				if (entity instanceof LivingEntity _entity)
					_entity.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, 2400, 255));
			}
			while ((world.getBlockState(new BlockPos(
					entity.level.clip(new ClipContext(entity.getEyePosition(1f), entity.getEyePosition(1f).add(entity.getViewVector(1f).scale(5)),
							ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, entity)).getBlockPos().getX(),
					entity.level.clip(new ClipContext(entity.getEyePosition(1f), entity.getEyePosition(1f).add(entity.getViewVector(1f).scale(5)),
							ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, entity)).getBlockPos().getY(),
					entity.level.clip(new ClipContext(entity.getEyePosition(1f), entity.getEyePosition(1f).add(entity.getViewVector(1f).scale(5)),
							ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, entity)).getBlockPos().getZ())))
					.getBlock() == (new Object() {
						public BlockState with(BlockState _bs, String property, boolean newValue) {
							Property<?> _prop = _bs.getBlock().getStateDefinition().getProperty(property);
							return _prop instanceof BooleanProperty _bp ? _bs.setValue(_bp, newValue) : _bs;
						}
					}.with(Blocks.FURNACE.defaultBlockState(), "lit", (true))).getBlock()) {
				if (entity instanceof LivingEntity _entity)
					_entity.removeEffect(MobEffects.MOVEMENT_SLOWDOWN);
				if (entity instanceof LivingEntity _entity)
					_entity.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, 40, 255));
			}
		}
	}
}

thanks in

advance

Luca76