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

Few, mostly trival questions, to help me avoid mistakes and understand how to build a mod


Recommended Posts

I've started working on a mod and it's been a bit of a bumpy ride. Mostly due to lack of recent and decent information, examples or simple know-how about internal workings. Finding outdated tutorials doesn't help either, and from what I've already read and seen in code (looking at 1.16 mods at github was mostly helpful) I got a bit confused. So please help me understand few things.

 

Here's my questions:

  • I want to attach some simple data to some ItemStack and TileEntity, is using getOrCreateTag() for ItemStack and getTileData() for TileEntity the way to go? or should I use capabilities for it?
  • If I'm setting tag for ItemStack or TileEntity, should I do this on server side only or both?
  • I wanted to play a sound during onItemUse and I've used context.getPlayer().playSound() which is ran on render and server thread, but only player using item is hearing the sound, according to Forge documentation this method on render thread should play for current player (and it does) and on server side it should send play message to all other players (this doesn't work)
  • If I want to store some custom "world" data that isn't specific to any block/item/chunk I should use capabilities and attach it to the world?
Link to post
Share on other sites
52 minutes ago, GThoro said:

I want to attach some simple data to some ItemStack and TileEntity, is using getOrCreateTag() for ItemStack and getTileData() for TileEntity the way to go? or should I use capabilities for it?

Capabilities.

52 minutes ago, GThoro said:

If I want to store some custom "world" data that isn't specific to any block/item/chunk I should use capabilities and attach it to the world?

Yes.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to post
Share on other sites
32 minutes ago, Draco18s said:

Capabilities.

Even if it's like simple string or int value? For example I have an item that user can right click and his player UUID should be "stored in" the item, this should use capabilities too? What's NBT for then?

Link to post
Share on other sites

Yes, use Capabilities.

 

The NBT system is what vanilla uses and half the functions available don't do what you think they do. getTileData() for instance doesn't let you store data in the tile entity, it is the NBT representation of the tile entity so it can be stored in an ItemStack.

 

NBT is a serialized data format meant to store the (whatever) on disk. Its not meant to be run-time modified left and right. Vanilla uses it for arbitrary data storage on ItemStacks because Mojang doesn't have a better method.

Edited by Draco18s

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to post
Share on other sites
6 minutes ago, Draco18s said:

getTileData() for instance doesn't let you store data in the tile entity, it is the NBT representation of the tile entity so it can be stored in an ItemStack.

this is not true.

Link to post
Share on other sites
3 minutes ago, diesieben07 said:

this is not true.

Well darn. What is it for, then?
I know that the various functions don't do what one expects half the time, looks like I messed that one up again.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to post
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.



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • hm... when I had a similar issue the discord pointed me towards using baked models. but multiparts does seem way simpler, and with datagen I could even do it proceduraly
    • You don't need a custom baked model for this. Look at the composter model for an example.
    • whenever you find a solution by yourself, you can leave the original question, but add a comment mentioning that you fixed it, and how. so that if anyone comes accross the same problem, they can find your solution and try it without needing to make a new topic. also, I don't see how intellij syncing with github has anything to do with forge
    • you need to create a new class which implements IBakedModel, overwrite getQuads (the one which takes an IModelData) an make it return the quads for your model, the IModelData shouls contain the info on the list and you set the info on the IModelData by overwriting getModelData in your tile entity. you need to sync the data from, the Server tile entity, to the client, which you can do by overwriting getUpdatePacket (Server sends updated data to the client), and onDataPacket  (Client handles an update packet received). then, whenever that data changes you can call World#notifyUpdate, and whenever the client receives an update (so in the end of onDataPacket) you call requestModelUpdate().   for the BakedModel, what I do is: I pass in an existing IBakedModel (that works as a base that I can add quads to) to the constructor, and store it in a field. then I can call IBakedModel#getQuads on the base model, which gives a list of BakedQuads, and add any new quads to it. and you can create your quads by using FaceBakey#bakeQuad, it takes the start and end positions of the quad (in block space, so 0 -> 16), an instance of a BlockPartFace, the sprite you want to use, which you can get from an AtlasTexture, the Direction of that quad, a transform (I just use SimpleModelTransform.IDENTITY), a rotation, which you can just pass null, a boolean that tells wether that face should be shaded or not, and then a throwaway ResourceLocation. and you can decide on all those properties, and on what faces to add, given the IModelData   EDIT: oh, and to register it you can do so through the modelRegistry in the ModelBakeEvent (this event is client-side only (I think)) if you need some examples, I used this repo to learn how to use BakedModels: https://github.com/TheGreyGhost/MinecraftByExample/tree/master/src/main/java/minecraftbyexample/mbe04_block_dynamic_block_models
    • Your code works well, I should have used the yaw player instead of taking yaw from my projectile. Thank you again
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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