Simple Modding Help Thread (Ask a Simple Question Get a Simple Answer Forge & Java Edition)

  • The FTB Forum is now read-only, and is here as an archive. To participate in our community discussions, please join our Discord! https://ftb.team/discord

trajing

New Member
Jul 29, 2019
3,091
-14
1
Starting this because I've decided to try my hand at modding again! (Picking up an old project of @Strikingwolf's)
As the title implies, this is a cheap knockoff of the Ask a Simple Question Get a Simple Answer thread for modding! Merely ask a question about Forge or Java in general, and a person will come and attempt to answer it for you!
 

Strikingwolf

New Member
Jul 29, 2019
3,709
-26
1
Starting this because I've decided to try my hand at modding again! (Picking up an old project of @Strikingwolf's)
As the title implies, this is a cheap knockoff of the Ask a Simple Question Get a Simple Answer thread for modding! Merely ask a question about Forge or Java in general, and a person will come and attempt to answer it for you!
Welp there goes my thread :p
 

VapourDrive

New Member
Jul 29, 2019
536
-8
1
hmmm, what sort of packet handling to containers need to update what is happening in them when multiple people are accessing it on a server (1.7.10). That's simple right ;)
 

squeek502

New Member
Jul 29, 2019
146
0
0
hmmm, what sort of packet handling to containers need to update what is happening in them when multiple people are accessing it on a server (1.7.10). That's simple right ;)
In general terms, this is what needs to happen: Client changes something -> server gets updated with those changes -> server sends the changes to all affected clients. There are a few ways to do this:

In the Container class, you can implement detectAndSendChanges, keep track of the last value of any relevant variables, and then update all clients whenever they change. For values less than a byte, you can use the built-in ICrafting.sendProgressBarUpdate function, and catch it by implementing Container.updateProgressBar(int id, int value) [I'd have to check, but I believe the value gets sent over the network as a byte]. This is how most vanilla Minecraft containers update themselves. Here's an example of that method in the mod Refined Relocation, how it's caught, and how it's updated.

For anything over a byte, you'd want to send it as a packet. Here's an example of sending a string and how it's caught/updated.

You could also use TileEntity.getDescriptionPacket and TileEntity.onDataPacket to update things that are not GUI-specific.

I'm sure other people have come up with many different ways to achieve this sort of thing, though. These are just the methods I'm familiar with.
 
  • Like
Reactions: VapourDrive

VapourDrive

New Member
Jul 29, 2019
536
-8
1
Ok, in the constructor for a block, I always though it inherits properties (hardness, light value, opacity etc) from the material if they aren't specified (which is mandatory as it is required in the super call) it seems that for all of my blocks without a specified hardness get a 0.0F hardness... did I assume wrong?
 

Elder Jürd

New Member
Jul 29, 2019
16
0
0
Ok, in the constructor for a block, I always though it inherits properties (hardness, light value, opacity etc) from the material if they aren't specified (which is mandatory as it is required in the super call) it seems that for all of my blocks without a specified hardness get a 0.0F hardness... did I assume wrong?

I was looking at the code and it seems that Block class does not initialise blockHardness unless you use setBlockHardness, wich means it's null. That said, i assumethere is a function that says if (blockHardness==null) {blockHardness = 0.0F}. Maybe the function that breaks it?

In fact, i can't see that material's class has something to do with hardness :/ maybe i'm wrong
 

ratchet freak

Well-Known Member
Nov 11, 2012
1,198
243
79
I was looking at the code and it seems that Block class does not initialise blockHardness unless you use setBlockHardness, wich means it's null. That said, i assumethere is a function that says if (blockHardness==null) {blockHardness = 0.0F}. Maybe the function that breaks it?

In fact, i can't see that material's class has something to do with hardness :/ maybe i'm wrong
eh no default initialization of float fields in java is 0.0f so if it's never set then it will be 0.0f
 

VapourDrive

New Member
Jul 29, 2019
536
-8
1
Maybe it was set to a default of something > 0.0 in previous Minecraft versions... I definitely thought it was something legitimate, maybe not.
 

HeilMewTwo

New Member
Jul 29, 2019
1,179
-45
0
Hey I am trying to create a staff as a part of my mod, my friend wants it to be 3d but I am not sure how to do it. Can anyone point me to a step by step?
 

VapourDrive

New Member
Jul 29, 2019
536
-8
1
Hey I am trying to create a staff as a part of my mod, my friend wants it to be 3d but I am not sure how to do it. Can anyone point me to a step by step?
3d as in a model (like the mekanism dislocator thing), 3d as in rendered in the same orientation as the vanilla tools, or 3d as in like the arrow in the ground?
 

VapourDrive

New Member
Jul 29, 2019
536
-8
1
The closest I would be able to help with would be this:
(I've never looked into models myself, but it isn't a super simple thing)
 

ljfa

New Member
Jul 29, 2019
2,761
-46
0
Is there some event that detects if a player's inventory changes? I need to make sure that the player only has specific items in their inventory. Is there some way to do that besides scanning their inventory each tick?
 

ratchet freak

Well-Known Member
Nov 11, 2012
1,198
243
79
Is there some event that detects if a player's inventory changes? I need to make sure that the player only has specific items in their inventory. Is there some way to do that besides scanning their inventory each tick?
There is on item pickup but that doesn't cover other mods putting things into the inventory I think
 

ljfa

New Member
Jul 29, 2019
2,761
-46
0
There is on item pickup but that doesn't cover other mods putting things into the inventory I think
Yea and it doesn't cover the player accessing chests and stuff.
There is the hasChanged field, I did try that but it didn't seem to work properly. hasChanged would not be set to true when the player picks something up.