Jump to content

How to store nested information that isn't tied to an item or entity


Recommended Posts

Posted

An implementation of IItem is used to generate an NBTTagCompound for an item, but the item only stores the generated information instead of all the information involved in the generation. I am doing it this way because the ModelMap will have a LOT of information and storing that information in every item is a massive waste of space.

 

This is the class structure/ information that I need to store:

Class Names were changed to simplify the example

None of the implementation classes will have more significant information than what is given.


    public class ItemExample implements IItem{
       private ModelMap map;
       private String name;
    }

    public class ModelMap {
       private HashMap<Coord, IPartType> map;
    }

    public class Coord {
       private int x,y,z;
    }

    public class PartExample implements IPartType {  
       private String name;                         
       private Purity purity;
    }

    public Enum Purity{
    }

Is using a Json file a good way of going about this? Is there a convention for doing something like this that I am just unaware of?

Current Project: Armerger 

Planned mods: Light Drafter  | Ore Swords

Looking for help getting a mod off the ground? Coding  | Textures

Posted

I really hope that you understand difference between Item - which is singleton ("description of what you are holding") and ItemStack ("the thing that is actually there").

 

Now if you know that I really hope you considered the fact that making and registering Item instances should happen in preInit of MOD, which is game load.

It is possible to not do it that way, but that introduces you to more problems.

 

1. Client will have to load server's Item singletons somehow - and I mean again - doing so NOT in preInit() of game (which happens waaay before even joining a server) will again introduce you to client sided problems - mainly rendering systems and registry-to-renderers compatibility.

 

2. Without even looking at client (which is one of biggest problems, since Vanilla/Forge is not designed to handle it), you will have corrupted data, useless packets "leaks" and who knows what when it comes to:

* Loading world (ItemStacks are loaded based on Item registry) - which will totally corrupt everything you have with possible slightest change to your (i think) Json-generated items.

* Syncing client - kinda 1st point - if server sends data about item which client doesn't have, it will not go well (pretty bad).

 

That is all ofc. if I an understanding correctly what you are after.

 

As to direct response to questions:

If not in ItemStack or Entity, you can store data in WorldSavedData (note that save/load is on-demand) or any self-made system (you could maybe utilize Capability system, but idk).

So yeah - Json can be fine if you don't want e.g NBT (WorldSavedData).

 

As to how it should be made:

Everything should be saved to ItemStack. If you really have a lot of data - you can easily wrap it up in short namings or ID system that can be stored in mentioned WorldSaveData and synced to client on logging in. Seriously, MC can handle quite some data in ItemStacks (I was once sending textures inside ItemStack, about MC 1.4-1.5).

1.7.10 is no longer supported by forge, you are on your own.

Posted

The example I gave is a little misleading with the names, I simplified everything down to the just the raw information I need to store. I have TypeCores(Melee, Mining, Ranged. etc) that extend Item and get registered during prInit() normally. I have a factory that knows how to generate an IBakedModel and relevant NBTTagCompound from this information and return that as an ItemStack for the appropriate TypeCore.

 

I preform the generation after the item has been designed/or a design was altered and uses copies of that to create ItemStack instances. I am not doing the generation each time an ItemStack is created.

 

This question is purely about how best to store the information and if there is an existing convention that people use, what is it?

Current Project: Armerger 

Planned mods: Light Drafter  | Ore Swords

Looking for help getting a mod off the ground? Coding  | Textures

Posted

As to direct response to questions:

If not in ItemStack or Entity, you can store data in WorldSavedData (note that save/load is on-demand) or any self-made system (you could maybe utilize Capability system, but idk).

So yeah - Json can be fine if you don't want e.g NBT (WorldSavedData).

1.7.10 is no longer supported by forge, you are on your own.

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I can't understand the logs, so I'm hoping someone could tell me what's causing the issues. https://pastebin.com/d1XPxCes
    • Hello I'm currently making an Item that thrusts you to viewing direction, and I referenced riptide code of trident for my item. @Override public InteractionResultHolder<ItemStack> use(Level pLevel, Player pPlayer, InteractionHand pUsedHand) { if(!pLevel.isClientSide() && pUsedHand == InteractionHand.MAIN_HAND && pPlayer.isOnGround()){ Impale(pPlayer, pUsedHand); pPlayer.getCooldowns().addCooldown(this, 40); } return super.use(pLevel, pPlayer, pUsedHand); } public void Impale(Player pPlayer, InteractionHand pUsedHand) { float playerYRot = pPlayer.getYRot(); float xForce = -Mth.sin(playerYRot * ((float)Math.PI / 180F)) * Mth.cos((float)Math.PI / 180F); float yForce = 100.6F; float zForce = Mth.cos(playerYRot * ((float)Math.PI / 180F)) * Mth.cos((float)Math.PI / 180F); float stabilizedForce = Mth.sqrt(xForce * xForce + zForce * zForce); xForce /= stabilizedForce; zForce /= stabilizedForce; pPlayer.push((double)xForce, (double)yForce, (double)zForce); pPlayer.sendSystemMessage(Component.literal(playerYRot + " " + xForce + " " + yForce + " " + zForce + " " + stabilizedForce + "shoo")); } I sure edited a lot from source code but this isn't working somehow? the sendSystemMessage works correctly. It prints value of variables and string, but the force isn't applying to player. how can I make this to work? Thanks.
    • i tried putting a modpack together and cant get this working no matter what i have tried log: https://pastebin.com/uqz1aKiY
    • We have an event for an Entity being struck by lighting, but doesn't look like we have one for Blocks. And unfortunately, looking at it, the LightingBolt entity doesn't have any context on why it was registered, so you wouldn't be able to get the source context. What are you trying to accomplish with this event?
    • Hey guys, I'm trying to use the simple planes mod https://www.curseforge.com/minecraft/mc-mods/simple-planes with a nuclear bombs mod https://www.curseforge.com/minecraft/mc-mods/nuclear-bombs . The simple planes mod has a cargo plane that can drop tnt, and i want it to work with the nuclear bombs. I added this JSON file from chatGPT to the payloads folder in simple planes (because the nukes couldn't even get stored in the plane in the first place), but this only allows the nuke to drop but doesn't explode: https://mclo.gs/3uEQIX2 . This nuke mod requires a redstone signal and then manual activation, which makes this tougher i imagine. If someone could write me a code for the payload folder for simpleplanes, something that even tampers with the nuke mod, or any general suggestions that would be great!  Many Thanks
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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