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

Discussion in 'Mod Development' started by trajing, Dec 18, 2014.

  1. trajing

    trajing New Member

    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!
     
  2. Strikingwolf

    Strikingwolf New Member

    Welp there goes my thread :p
     
  3. trajing

    trajing New Member

    -whoops-
     
  4. VapourDrive

    VapourDrive New Member

    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 ;)
     
  5. squeek502

    squeek502 New Member

    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.
     
    VapourDrive likes this.
  6. VapourDrive

    VapourDrive New Member

    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?
     
  7. Elder Jürd

    Elder Jürd New Member

    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
     
  8. ratchet freak

    ratchet freak Well-Known Member

    eh no default initialization of float fields in java is 0.0f so if it's never set then it will be 0.0f
     
  9. Elder Jürd

    Elder Jürd New Member

    well there you go, that's the point :)
     
  10. VapourDrive

    VapourDrive New Member

    Maybe it was set to a default of something > 0.0 in previous Minecraft versions... I definitely thought it was something legitimate, maybe not.
     
  11. HeilMewTwo

    HeilMewTwo New Member

    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?
     
  12. VapourDrive

    VapourDrive New Member

    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?
     
  13. HeilMewTwo

    HeilMewTwo New Member

    3D as a model, a lot like the atomic dissembler.
     
  14. VapourDrive

    VapourDrive New Member

    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)
     
  15. HeilMewTwo

    HeilMewTwo New Member

    Thanks a lot, I'll look at it when I get back home. :D
     
  16. ljfa

    ljfa New Member

    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?
     
  17. ratchet freak

    ratchet freak Well-Known Member

    There is on item pickup but that doesn't cover other mods putting things into the inventory I think
     
  18. ljfa

    ljfa New Member

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

    CoolSquid New Member

    If there is, it's listed here (thanks to Vic).
     
  20. ljfa

    ljfa New Member

    I already looked at a list of Forge events but seems like ItemPickupEvent is all that Forge offers there.
     

Share This Page