Problem with custom code procedure - no errors but it doesn't run

Started by HedzikKrecik on

Topic category: Help with modding (Java Edition)

Last seen on 20:29, 6. Sep 2023
Joined Aug 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Problem with custom code procedure - no errors but it doesn't run

Hello,
I'm creating a minecraft mod which basically gives you mining xp every time you mine something, and while reaching certain points you level up. I needed to create custom code at some point for getting xp needed for next level. Here's what I have so far:

firstprocedure1

 

...(more rewarding xp for certain blocks and at the end:)

firstprocedure2

MiningCheckMaxLevelProcedure:

And finally MiningLevelUp, which is custom code:

package net.mcreator.hrpgmod.procedures; 

import net.minecraft.world.entity.Entity; 

import net.mcreator.hrpgmod.network.HrpgmodModVariables;
import java.util.Map;
import java.util.HashMap; 

public class MiningLevelUpProcedure { 

    public static HashMap<Double, Double> requiredXp;

    public static void populateRequiredXp()
    {
        requiredXp = new HashMap<Double, Double>();
        requiredXp.put(2.0, 250.0);
        //bunch more of those puts, I know it's stupid but I'll do it the better way later on, or if u have any ideas how to do it better lemme know
        requiredXp.put(98.0, 485100.0);
        requiredXp.put(99.0, 492900.0);
        requiredXp.put(100.0, 448400.0);
    }
    
    public static void execute(Entity entity) { 
        if (entity == null) 
            return; 
        
        if ((entity.getCapability(HrpgmodModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new HrpgmodModVariables.PlayerVariables())).mining_xp == (entity.getCapability(HrpgmodModVariables.PLAYER_VARIABLES_CAPABILITY, null) 
                .orElse(new HrpgmodModVariables.PlayerVariables())).mining_maxxp) { 
            { 
                entity.getCapability(HrpgmodModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> { 
                    populateRequiredXp();
                    capability.mining_lvl = capability.mining_lvl + 1.0;
                    capability.mining_xp -= capability.mining_maxxp;
                    if(capability.mining_lvl==100.0)
                    {
                        capability.mining_maxxp = 9999999.0;
                    }
                    else
                    {
                        capability.mining_maxxp = requiredXp.get(capability.mining_lvl+1.0);
                    }
                    
                    capability.syncPlayerVariables(entity);
                }); 
            } 
        } 
    }
}

No procedure returns an error, but it doesn't seem to work. Xp is rewarded properly, but maxlvl is not increased. so the error must be inside either MiningCheckMaxLevelProcedure or MiningLevelUp code

Any insight will be much appreciated, thanks!