Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Correct approach to store globally accessible values


DeadPix
 Share

Recommended Posts

Hello, 

in mod I am working on I have a need to store some values that I would need to check on in multiple places in my mod. I know that this value will be unique for every player (pretty much every instance of Minecraft running the mod will have this value different).

 

In Android, there are SharedPreferences into which one can store such information. Is there dedicated class/space in forge that I should take advantage of? Is there a recommended approach for this?

 

Or will it be okay just to create a public static class, let's say SharedPreferences with HashMap and getters and setters for indexes in the HashMap?

 

Thank you in advance.

Link to comment
Share on other sites

54 minutes ago, DeadPix said:

Hello, 

in mod I am working on I have a need to store some values that I would need to check on in multiple places in my mod. I know that this value will be unique for every player (pretty much every instance of Minecraft running the mod will have this value different).

 

In Android, there are SharedPreferences into which one can store such information. Is there dedicated class/space in forge that I should take advantage of? Is there a recommended approach for this?

 

Or will it be okay just to create a public static class, let's say SharedPreferences with HashMap and getters and setters for indexes in the HashMap?

 

Thank you in advance.

Are these values gonna be accessed on the server or is this a client only feature?

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

2 minutes ago, DeadPix said:

I am not sure how to exactly determine that. But probably only client side? It will be mostly client relevant values like 'is this thing on or off' and similar. Is that client side only?

Sounds like you need to read about sides.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

1 minute ago, DeadPix said:

So, what does it mean for my original question, please?

I would just store it in a static variable in your ClientProxy or an @SideOnly(Side.CLIENT) class.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

Actually the more important question is whether this value needs to persist between saves. If it does not, then you are free to create public static fields that store the values, and then regenerate them each time the game starts. But if you need to save them then generally you would add them either to the player or to the world in a saveable way, such as using the WorldSaveData mechanism. You can also pretty easily just create your own file format for saving the information -- like on client side you could store it along with config info.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

4 minutes ago, jabelar said:

You can also pretty easily just create your own file format for saving the information -- like on client side you could store it along with config info. 

@DeadPix Though I would only do this if, this value doesn't control anything important as it could be edited by the player.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

@jabelar@Animefan8888

Alright, thank you guys for your input - in the end, I decided to create a weaker version of aforementioned SharedPreferences (for boolean value only) and it seems to work exactly as I wanted it to. I need it only client side - and the scenario when player edits those values, is not a problem. I do not need it to persist between game loads, so I also do not save it anywhere, but in the future I will need some persistent functionality for something else, so I am also grateful for your suggestion on reading around it, jabelar. Thanks.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

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

 Share



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • today I was playing normal until my game crashed and returned to normal, after a while it crashed again and since then I can't play anymore I log in and the game closes with this error The game crashed whilst exception in server tick loop Error: java.util.ConcurrentModificationException Exit Code: -1 o crash completo : ---- Minecraft Crash Report ---- WARNING: coremods are present:   llibrary (llibrary-core-1.0.11-1.12.2.jar)   Inventory Tweaks Coremod (InventoryTweaks-1.63.jar)   EnderCorePlugin (EnderCore-1.12.2-0.5.76-core.jar)   AppleCore (AppleCore-mc1.12.2-3.2.0.jar)   CTMCorePlugin (CTM-MC1.12.2-1.0.1.30.jar)   ForgelinPlugin (Forgelin-1.8.4.jar)   MekanismCoremod (Mekanism-1.12.2-9.8.3.390.jar)   OpenModsCorePlugin (OpenModsLib-1.12.2-0.12.2.jar)   MalisisCorePlugin (malisiscore-1.12.2-6.5.1.jar) Contact their authors BEFORE contacting forge // Don't do that. Time: 10/17/21 2:26 AM Description: Exception in server tick loop java.util.ConcurrentModificationException     at java.util.HashMap$HashIterator.nextNode(HashMap.java:1429)     at java.util.HashMap$KeyIterator.next(HashMap.java:1453)     at net.minecraft.entity.EntityTracker.func_72788_a(EntityTracker.java:290)     at net.minecraft.server.MinecraftServer.func_71190_q(MinecraftServer.java:779)     at net.minecraft.server.MinecraftServer.func_71217_p(MinecraftServer.java:668)     at net.minecraft.server.integrated.IntegratedServer.func_71217_p(IntegratedServer.java:185)     at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:526)     at java.lang.Thread.run(Thread.java:745) A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- System Details -- Details:     Minecraft Version: 1.12.2     Operating System: Windows 10 (amd64) version 10.0     Java Version: 1.8.0_51, Oracle Corporation     Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation     Memory: 1647489200 bytes (1571 MB) / 4127195136 bytes (3936 MB) up to 5726797824 bytes (5461 MB)     JVM Flags: 4 total; -XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump -Xmx6144m -Xms256m -XX:PermSize=256m     IntCache: cache: 0, tcache: 0, allocated: 3, tallocated: 104     FML: MCP 9.42 Powered by Forge 14.23.5.2847 72 mods loaded, 72 mods active     States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored     | State  | ID                                | Version                  | Source                                          | Signature                                |     |:------ |:--------------------------------- |:------------------------ |:----------------------------------------------- |:---------------------------------------- |     | LCHIJA | minecraft                         | 1.12.2                   | minecraft.jar                                   | None                                     |     | LCHIJA | mcp                               | 9.42                     | minecraft.jar                                   | None                                     |     | LCHIJA | FML                               | 8.0.99.99                | forge-1.12.2-14.23.5.2847.jar                   | None                                     |     | LCHIJA | forge                             | 14.23.5.2847             | forge-1.12.2-14.23.5.2847.jar                   | None                                     |     | LCHIJA | openmodscore                      | 0.12.2                   | minecraft.jar                                   | None                                     |     | LCHIJA | securitycraft                     | v1.8.16                  | [1.12.2] SecurityCraft v1.8.16.jar              | None                                     |     | LCHIJA | applecore                         | 3.2.0                    | AppleCore-mc1.12.2-3.2.0.jar                    | None                                     |     | LCHIJA | ctm                               | MC1.12.2-1.0.1.30        | CTM-MC1.12.2-1.0.1.30.jar                       | None                                     |     | LCHIJA | appliedenergistics2               | rv6-stable-7             | appliedenergistics2-rv6-stable-7.jar            | dfa4d3ac143316c6f32aa1a1beda1e34d42132e5 |     | LCHIJA | biomesoplenty                     | 7.0.1.2441               | BiomesOPlenty-1.12.2-7.0.1.2441-universal.jar   | None                                     |     | LCHIJA | jei                               | 4.15.0.291               | jei_1.12.2-4.15.0.291.jar                       | None                                     |     | LCHIJA | chisel                            | MC1.12.2-1.0.1.44        | Chisel-MC1.12.2-1.0.1.44.jar                    | None                                     |     | LCHIJA | chiselsandbits                    | 14.33                    | chiselsandbits-14.33.jar                        | None                                     |     | LCHIJA | codechickenlib                    | 3.2.3.358                | CodeChickenLib-1.12.2-3.2.3.358-universal.jar   | f1850c39b2516232a2108a7bd84d1cb5df93b261 |     | LCHIJA | redstoneflux                      | 2.1.0                    | RedstoneFlux-1.12-2.1.0.6-universal.jar         | 8a6abf2cb9e141b866580d369ba6548732eff25f |     | LCHIJA | cofhcore                          | 4.6.3                    | CoFHCore-1.12.2-4.6.3.27-universal.jar          | None                                     |     | LCHIJA | cofhworld                         | 1.3.1                    | CoFHWorld-1.12.2-1.3.1.7-universal.jar          | 8a6abf2cb9e141b866580d369ba6548732eff25f |     | LCHIJA | crafttweaker                      | 4.1.20                   | CraftTweaker2-1.12-4.1.20.jar                   | None                                     |     | LCHIJA | ctgui                             | 1.0.0                    | CraftTweaker2-1.12-4.1.20.jar                   | None                                     |     | LCHIJA | crafttweakerjei                   | 2.0.3                    | CraftTweaker2-1.12-4.1.20.jar                   | None                                     |     | LCHIJA | cucumber                          | 1.1.3                    | Cucumber-1.12.2-1.1.3.jar                       | None                                     |     | LCHIJA | endercore                         | 1.12.2-0.5.76            | EnderCore-1.12.2-0.5.76.jar                     | None                                     |     | LCHIJA | thermalfoundation                 | 2.6.3                    | ThermalFoundation-1.12.2-2.6.3.27-universal.jar | 8a6abf2cb9e141b866580d369ba6548732eff25f |     | LCHIJA | thermalexpansion                  | 5.5.4                    | ThermalExpansion-1.12.2-5.5.4.43-universal.jar  | 8a6abf2cb9e141b866580d369ba6548732eff25f |     | LCHIJA | enderio                           | 5.3.70                   | EnderIO-1.12.2-5.3.70.jar                       | None                                     |     | LCHIJA | enderiointegrationtic             | 5.3.70                   | EnderIO-1.12.2-5.3.70.jar                       | None                                     |     | LCHIJA | enderiobase                       | 5.3.70                   | EnderIO-1.12.2-5.3.70.jar                       | None                                     |     | LCHIJA | enderioconduits                   | 5.3.70                   | EnderIO-1.12.2-5.3.70.jar                       | None                                     |     | LCHIJA | enderioconduitsappliedenergistics | 5.3.70                   | EnderIO-1.12.2-5.3.70.jar                       | None                                     |     | LCHIJA | enderioconduitsopencomputers      | 5.3.70                   | EnderIO-1.12.2-5.3.70.jar                       | None                                     |     | LCHIJA | enderioconduitsrefinedstorage     | 5.3.70                   | EnderIO-1.12.2-5.3.70.jar                       | None                                     |     | LCHIJA | enderiointegrationforestry        | 5.3.70                   | EnderIO-1.12.2-5.3.70.jar                       | None                                     |     | LCHIJA | enderiointegrationticlate         | 5.3.70                   | EnderIO-1.12.2-5.3.70.jar                       | None                                     |     | LCHIJA | enderioinvpanel                   | 5.3.70                   | EnderIO-1.12.2-5.3.70.jar                       | None                                     |     | LCHIJA | enderiomachines                   | 5.3.70                   | EnderIO-1.12.2-5.3.70.jar                       | None                                     |     | LCHIJA | enderiopowertools                 | 5.3.70                   | EnderIO-1.12.2-5.3.70.jar                       | None                                     |     | LCHIJA | extrautils2                       | 1.0                      | extrautils2-1.12-1.9.9.jar                      | None                                     |     | LCHIJA | zerocore                          | 1.12.2-0.1.2.8           | zerocore-1.12.2-0.1.2.8.jar                     | None                                     |     | LCHIJA | bigreactors                       | 1.12.2-0.4.5.67          | ExtremeReactors-1.12.2-0.4.5.67.jar             | None                                     |     | LCHIJA | fastleafdecay                     | v14                      | FastLeafDecay-v14.jar                           | None                                     |     | LCHIJA | forgelin                          | 1.8.4                    | Forgelin-1.8.4.jar                              | None                                     |     | LCHIJA | llibrary                          | 1.7.20                   | llibrary-1.7.20-1.12.2.jar                      | b9f30a813bee3b9dd5652c460310cfcd54f6b7ec |     | LCHIJA | fossil                            | 8.0.5                    | fossilsarcheology-8.0.5.jar                     | None                                     |     | LCHIJA | waila                             | 1.8.26                   | Hwyla-1.8.26-B41_1.12.2.jar                     | None                                     |     | LCHIJA | mekanism                          | 1.12.2-9.8.3.390         | Mekanism-1.12.2-9.8.3.390.jar                   | None                                     |     | LCHIJA | teslacorelib                      | 1.0.16                   | tesla-core-lib-1.12.2-1.0.16.jar                | d476d1b22b218a10d845928d1665d45fce301b27 |     | LCHIJA | industrialforegoing               | 1.12.2-1.12.2            | industrialforegoing-1.12.2-1.12.13-237.jar      | None                                     |     | LCHIJA | inventorytweaks                   | 1.63+release.109.220f184 | InventoryTweaks-1.63.jar                        | 55d2cd4f5f0961410bf7b91ef6c6bf00a766dcbe |     | LCHIJA | ironchest                         | 1.12.2-7.0.67.844        | ironchest-1.12.2-7.0.72.847.jar                 | None                                     |     | LCHIJA | journeymap                        | 1.12.2-5.5.9             | journeymap-1.12.2-5.5.9.jar                     | None                                     |     | LCHIJA | malisiscore                       | 1.12.2-6.5.1-SNAPSHOT    | malisiscore-1.12.2-6.5.1.jar                    | None                                     |     | LCHIJA | malisisdoors                      | 1.12.2-7.3.0             | malisisdoors-1.12.2-7.3.0 (1).jar               | None                                     |     | LCHIJA | mantle                            | 1.12-1.3.3.55            | Mantle-1.12-1.3.3.55.jar                        | None                                     |     | LCHIJA | mekanismgenerators                | 1.12.2-9.8.3.390         | MekanismGenerators-1.12.2-9.8.3.390.jar         | None                                     |     | LCHIJA | numina                            | 1.12.2-1.0.38            | Numina-1.12.2-1.0.38.jar                        | None                                     |     | LCHIJA | powersuits                        | 1.12.2-1.0.46            | ModularPowersuits-1.12.2-1.0.46.jar             | None                                     |     | LCHIJA | mousetweaks                       | 2.10                     | MouseTweaks-2.10-mc1.12.2.jar                   | None                                     |     | LCHIJA | mysticalagriculture               | 1.7.5                    | MysticalAgriculture-1.12.2-1.7.5.jar            | None                                     |     | LCHIJA | omlib                             | 3.1.4-249                | omlib-1.12.2-3.1.4-249.jar                      | None                                     |     | LCHIJA | ompd                              | 3.1.0-61                 | ompd-1.12.2-3.1.0-61.jar                        | None                                     |     | LCHIJA | openmods                          | 0.12.2                   | OpenModsLib-1.12.2-0.12.2.jar                   | d2a9a8e8440196e26a268d1f3ddc01b2e9c572a5 |     | LCHIJA | openblocks                        | 1.8.1                    | OpenBlocks-1.12.2-1.8.1.jar                     | d2a9a8e8440196e26a268d1f3ddc01b2e9c572a5 |     | LCHIJA | openmodularturrets                | 3.1.6-362                | openmodularturrets-1.12.2-3.1.6-362.jar         | None                                     |     | LCHIJA | oreexcavation                     | 1.4.143                  | OreExcavation-1.4.143.jar                       | None                                     |     | LCHIJA | harvestcraft                      | 1.12.2zb                 | Pam's HarvestCraft 1.12.2zf.jar                 | None                                     |     | LCHIJA | placebo                           | 1.6.0                    | Placebo-1.12.2-1.6.0.jar                        | None                                     |     | LCHIJA | reborncore                        | 3.18.0                   | RebornCore-1.12.2-3.18.1.514-universal.jar      | 8727a3141c8ec7f173b87aa78b9b9807867c4e6b |     | LCHIJA | thermaldynamics                   | 2.5.5                    | ThermalDynamics-1.12.2-2.5.5.21-universal.jar   | 8a6abf2cb9e141b866580d369ba6548732eff25f |     | LCHIJA | toastcontrol                      | 1.8.1                    | Toast Control-1.12.2-1.8.1.jar                  | None                                     |     | LCHIJA | wawla                             | 2.6.274                  | Wawla-1.12.2-2.6.274.jar                        | d476d1b22b218a10d845928d1665d45fce301b27 |     | LCHIJA | jurassicraft                      | 2.1.23                   | JurassiCraft-1.12.2-2.1.23.jar                  | None                                     |     | LCHIJA | teslacorelib_registries           | 1.0.16                   | tesla-core-lib-1.12.2-1.0.16.jar                | None                                     |     Loaded coremods (and transformers):  llibrary (llibrary-core-1.0.11-1.12.2.jar)   net.ilexiconn.llibrary.server.core.plugin.LLibraryTransformer   net.ilexiconn.llibrary.server.core.patcher.LLibraryRuntimePatcher Inventory Tweaks Coremod (InventoryTweaks-1.63.jar)   invtweaks.forge.asm.ContainerTransformer EnderCorePlugin (EnderCore-1.12.2-0.5.76-core.jar)   com.enderio.core.common.transform.EnderCoreTransformer   com.enderio.core.common.transform.SimpleMixinPatcher AppleCore (AppleCore-mc1.12.2-3.2.0.jar)   squeek.applecore.asm.TransformerModuleHandler CTMCorePlugin (CTM-MC1.12.2-1.0.1.30.jar)   team.chisel.ctm.client.asm.CTMTransformer ForgelinPlugin (Forgelin-1.8.4.jar)    MekanismCoremod (Mekanism-1.12.2-9.8.3.390.jar)   mekanism.coremod.KeybindingMigrationHelper OpenModsCorePlugin (OpenModsLib-1.12.2-0.12.2.jar)   openmods.core.OpenModsClassTransformer MalisisCorePlugin (malisiscore-1.12.2-6.5.1.jar)        GL info: ~~ERROR~~ RuntimeException: No OpenGL context found in the current thread.     OpenModsLib class transformers: [llama_null_fix:FINISHED],[horse_base_null_fix:FINISHED],[pre_world_render_hook:FINISHED],[player_render_hook:FINISHED],[horse_null_fix:FINISHED]     AE2 Version: stable rv6-stable-7 for Forge 14.23.5.2768     Ender IO: No known problems detected.     Authlib is : /C:/Users/User/Twitch/Minecraft/Install/libraries/com/mojang/authlib/1.5.25/authlib-1.5.25.jar     !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!     !!!You are looking at the diagnostics information, not at the crash.       !!!     !!!Scroll up until you see the line with '---- Minecraft Crash Report ----'!!!     !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!     RebornCore:          Plugin Engine: 0         RebornCore Version: 3.18.0         Runtime Debofucsation 1         RenderEngine: 0     AE2 Integration: IC2:OFF, RC:OFF, MFR:OFF, Waila:ON, InvTweaks:ON, JEI:ON, Mekanism:ON, OpenComputers:OFF, THE_ONE_PROBE:OFF, TESLA:OFF, CRAFTTWEAKER:ON     Profiler Position: N/A (disabled)     Player Count: 1 / 8; [EntityPlayerMP['AventureiroMax'/313, l='jurassic craft', x=231.44, y=90.00, z=117.46]]     Type: Integrated Server (map_client.txt)     Is Modded: Definitely; Client brand changed to 'fml,forge'    
    • I realized the error but I'm not sure how I'm supposed to solve it. Some vanilla feature in the biome I'm using in my dimensions uses an absolute upper bound but relative lower bound. So when I made the min built height of my dimension greater, the lower bound increased so much that it became higher than the upper bound. I'm not sure how to fix this other than change my dimension min height, but I was trying to center my dimension at about surface level so that the correct features were carved. 
    • The Forge team can't support every version of Minecraft in-perpetuity. No software company does that with their software. Forge has decided that they will support the most recent major version (1.17) and a single LTS version (1.15) 1.12 is 4 years old at this point.
    • I need help, I can't enter my server, from one day to another I couldn't connect anymore, that LOG is what I get when I log in, I already tried with another launcher and with another account but it marks the same error, my friends They can still play on the server, and I being the owner of the server I can't enter haha please help   [02:34:32] [Netty Epoll Server IO #2/ERROR] [ne.mi.fm.ne.NetworkRegistry/NETREGISTRY]: Channels [carryon:carryonpackets] rejected their client side version number[02:34:32] [Netty Epoll Server IO #2/ERROR] [ne.mi.fm.ne.FMLHandshakeHandler/FMLHANDSHAKE]: Terminating connection with client, mismatched mod list[02:34:32] [Server thread/INFO] [minecraft/ServerLoginNetHandler]: com.mojang.authlib.GameProfile@******[id=<null>,name=LeonardoRR,properties={},legacy=false] lost connection: Connection closed - mismatched mod channel list
    • I'm looking into UniformHeight because that seems to be the place where the message is logged. I'm not sure how the min > max thought because just finding usages of UniformHeight.of() shows that all the heights created seem to be constant. I'm not sure what's going on. 
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.