Jump to content

Recommended Posts

Posted

I am just really having issues with this capability system. To get to the point, my capabilities are resetting after unloading and loading the game. I have included images on prints I have set up, but basically I log in the game (variable at 0, because it reset lol) get 5 "points" (seen in image 2). Then I unload the world and log back in (image 3), and the variables are back to 0. Those are my observations. I have seen other posts on forums although they are outdated. I have looked at some other mods source code, however it is hard to find where they use this. But even when/if I find where they serialize the data I am lost between the complexity of all of the methods. All code obtaining to this problem is in the pastebin exept for when I register it in the Main class using;

	private void onCommonSetup(FMLCommonSetupEvent e)
	{
		CapabilityManager.INSTANCE.register(IPlayerHandler.class, new PlayerCapability.Storage(), PlayerCapability::new);
	}

I don't know what else you need, but will give/do anything to solve this. If I haven't said before, I am thankful for your time in this troubling time. Thanks

https://imgur.com/a/FwjGLyb

https://pastebin.com/RXLXdSHd

Posted
7 hours ago, TBroski said:

I am just really having issues with this capability system. To get to the point, my capabilities are resetting after unloading and loading the game. I have included images on prints I have set up, but basically I log in the game (variable at 0, because it reset lol) get 5 "points" (seen in image 2). Then I unload the world and log back in (image 3), and the variables are back to 0. Those are my observations. I have seen other posts on forums although they are outdated. I have looked at some other mods source code, however it is hard to find where they use this. But even when/if I find where they serialize the data I am lost between the complexity of all of the methods. All code obtaining to this problem is in the pastebin exept for when I register it in the Main class using;


	private void onCommonSetup(FMLCommonSetupEvent e)
	{
		CapabilityManager.INSTANCE.register(IPlayerHandler.class, new PlayerCapability.Storage(), PlayerCapability::new);
	}

I don't know what else you need, but will give/do anything to solve this. If I haven't said before, I am thankful for your time in this troubling time. Thanks

https://imgur.com/a/FwjGLyb

https://pastebin.com/RXLXdSHd

First of all, the way you're making keybinds is horriblehere's an example of how I make keybinds in my mod.

Your problem seems to be that you aren't SYNCING your capability to the CLIENT. Capabilities are stored only on the server by default, check out this example of how I sync capabilities in my mod (you also have to sync on the player logging in, changing dimensiom, leaving the end and respawning). Also, why do you have a public static class in you CapabilityHandler class, it serves no purpose at all, just remove it.

It's sad how much time mods spend saying "x is no longer supported on this forum. Please update to a modern version of Minecraft to receive support".

Posted

@TBroski You should use the nbt that is provided to you:

@Override
        public void readNBT(Capability<IPlayerHandler> capability, IPlayerHandler instance, Direction side, INBT nbt)
        {
            INBT tag = new CompoundNBT();
            instance.setjoinWorld(((CompoundNBT) tag).getBoolean("joined"));
            instance.setChakra(((CompoundNBT) tag).getFloat("chakra"));
            instance.setmaxChakra(((CompoundNBT) tag).getFloat("maxchakra"));
            instance.setregenChakra(((CompoundNBT) tag).getFloat("regenchakra"));
            instance.setcolorChakra(((CompoundNBT) tag).getInt("colorchakra"));
            instance.setTaijutsu(((CompoundNBT) tag).getInt("taijutsu"));
            instance.setplayerEyeSlot(((CompoundNBT) tag).getInt("playereyeslot"));
            instance.setBeNMPoints(((CompoundNBT) tag).getInt("benmpoints"));
            instance.setPlayerEntityAffiliation(((CompoundNBT) tag).getString("playeraffiliation"));
 
            //Keybinds for Jutsu
            instance.setKeybind1(((CompoundNBT) tag).getString("key1"));
            instance.setKeybind2(((CompoundNBT) tag).getString("key2"));
            instance.setKeybind3(((CompoundNBT) tag).getString("key3"));
            instance.setKeybind4(((CompoundNBT) tag).getString("key4"));
            instance.setKeybind5(((CompoundNBT) tag).getString("key5"));
            instance.setKeybind6(((CompoundNBT) tag).getString("key6"));
            instance.setKeybind7(((CompoundNBT) tag).getString("key7"));
            instance.setKeybind8(((CompoundNBT) tag).getString("key8"));
            instance.setKeybind9(((CompoundNBT) tag).getString("key9"));
 
            //Jutsu
            instance.setCloneJutsuBoolean(((CompoundNBT) tag).getBoolean("clone"));
            instance.setSummoningBoolean(((CompoundNBT) tag).getBoolean("summoning"));
            instance.setInvisibilityBoolean(((CompoundNBT) tag).getBoolean("invisibility"));
            instance.setBodyReplacementBoolean(((CompoundNBT) tag).getBoolean("replacement"));
            //Fire
            instance.setFireballJutsuBoolean(((CompoundNBT) tag).getBoolean("fireball"));
            //Water
            instance.setWaterShurikenJutsuBoolean(((CompoundNBT) tag).getBoolean("watershuriken"));
            //Lightning
            instance.setLightningBallJutsuBoolean(((CompoundNBT) tag).getBoolean("lightningball"));
            //Earth
            instance.setFlyingStonesJutsuBoolean(((CompoundNBT) tag).getBoolean("flyingstones"));
            //Wind
            instance.setGalePalmJutsuBoolean(((CompoundNBT) tag).getBoolean("galepalm"));
        }
    

You are creating a new CompoundNBT instead of using the nbt that is provided to you.

Posted
Quote

You are creating a new CompoundNBT instead of using the nbt that is provided to you.

That was it I believe, so thanks!

 

Quote

First of all, the way you're making keybinds is horrible, here's an example of how I make keybinds in my mod.

I have those "keys" in my capability to carry a string, and then when I press my keybind it checks for what the corresponding key string is equal to. Then does that function, if that makes sense. My actual keybinds are made using this below;

private static final String CATEGORY = "key.categories." + Main.MODID;
    public static KeyBinding HAND_INFUSION;
    public static KeyBinding BODY_INFUSION;
    public static KeyBinding LEG_INFUSION;
    public static KeyBinding SHINOBI_STATS;
    public static KeyBinding KEYBIND1;
    public static KeyBinding KEYBIND2;
    public static KeyBinding KEYBIND3;
    public static KeyBinding KEYBIND4;


    public static void register()
    {
        HAND_INFUSION = new KeyBinding("key." + Main.MODID + ".handinfusion", GLFW_KEY_R, CATEGORY);
        BODY_INFUSION = new KeyBinding("key." + Main.MODID + ".bodyinfusion", GLFW_KEY_F, CATEGORY);
        LEG_INFUSION = new KeyBinding("key." + Main.MODID + ".leginfusion", GLFW_KEY_C, CATEGORY);
        SHINOBI_STATS = new KeyBinding("key." + Main.MODID + ".shinobistats", GLFW_KEY_P, CATEGORY);
        KEYBIND1 = new KeyBinding("key." + Main.MODID + ".keybind1", GLFW_KEY_1, CATEGORY);
        KEYBIND2 = new KeyBinding("key." + Main.MODID + ".keybind2", GLFW_KEY_2, CATEGORY);
        KEYBIND3 = new KeyBinding("key." + Main.MODID + ".keybind3", GLFW_KEY_3, CATEGORY);
        KEYBIND4 = new KeyBinding("key." + Main.MODID + ".keybind4", GLFW_KEY_4, CATEGORY);


        ClientRegistry.registerKeyBinding(HAND_INFUSION);
        ClientRegistry.registerKeyBinding(BODY_INFUSION);
        ClientRegistry.registerKeyBinding(LEG_INFUSION);
        ClientRegistry.registerKeyBinding(SHINOBI_STATS);
        ClientRegistry.registerKeyBinding(KEYBIND1);
        ClientRegistry.registerKeyBinding(KEYBIND2);
        ClientRegistry.registerKeyBinding(KEYBIND3);
        ClientRegistry.registerKeyBinding(KEYBIND4);
    }
}
Quote

that you aren't SYNCING your capability to the CLIENT

            NetworkLoader.INSTANCE.send(PacketDistributor.PLAYER.with(() -> (ServerPlayerEntity) player), new PacketChakraSync(chakra));

That's how I do it, is that not correct?

 

Thanks for your responses though! I really appreciate it!

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.