Solved Inventory Title Name?

Discussion in 'Plugin Development' started by Elimnator, Feb 12, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Elimnator

    Is there a way to rename the title text of a furnace to something else?
     
  2. Offline

    xTrollxDudex

    Elimnator
    Not unless you open a custom inventory, no.
     
  3. Offline

    MexMaster

    you sure? is using inventory.setName() not working in standard inventories?
    if not you could create a custom furnace inventory and set the name
     
  4. Offline

    Ronbo

    Elimnator xTrollxDudex
    Actually it can be done with a bit of nms. I'm about to go to sleep and I need to wake up early tomorrow so I can't give you full code, but here's what you do. Cast the Furnace block getState() to CraftFurnace. Use reflection to get to "furnace" in the CraftFurnace which is a TileEntityFurnace object. TileEntityFurnace has an a(String s) method which sets the title of the inventory. I haven't tried it for furnaces but I've done it with chests and it works fine.
    I haven't posted here in a while but if I remember correctly xTrollxDudex is pretty good with nms and stuff so he can probably help you now that I've outlined the process.
     
  5. Offline

    TeeePeee

  6. Offline

    Elimnator

    Ronbo TeeePeee

    Thanks, how do I use reflection to get to "furnace" in the CraftFurnace which is a TileEntityFurnace object?
     
  7. Offline

    werter318

    Field furnaceField = (craftfurnaceObject).getClass().getDeclaredField("furnace");
    furnaceField.setAccesible(true);
    furnaceField.get((craftfurnaceObject));

    Didn't test it, and wrote it in the forum so I hope it works :) Good luck!
     
  8. Offline

    Elimnator

    werter318
    I get "Field cannot be resolved to a type"
     
  9. Offline

    werter318

    Elimnator That's weird because it's in the default Java API, it's under lang.reflect.field;
     
  10. Offline

    Elimnator

    werter318 OK, I was mistaken because you misspelt "setAccessible"

    So where/how do I set the new name for the furnace?
     
  11. Offline

    xTrollxDudex

    Elimnator
    It's stored in a string titled "o" in TileEntityFurnace
     
  12. Offline

    Elimnator

    xTrollxDudex
    And how do I accesses this "o"?

    Sorry I don't know much about NMS yet. \:
     
  13. Offline

    xTrollxDudex

    Elimnator
    PHP:
    TileEntityFurnace furnace furnaceField.get(<CraftFurnace object>);
    Field name null;
    try {
        
    name furnace.getDeclaredField("o"):
        
    name.setAccessible(true);
        
    name.set(furnace, <Furnace name here>);
    } catch (
    Exception x) {
    }
     
  14. Offline

    Elimnator

    This is what I have so far:
    Code:java
    1. CraftFurnace craftfurnaceObject = (CraftFurnace) block.getState();
    2. Field furnaceField = (craftfurnaceObject).getClass().getDeclaredField("furnace");
    3. furnaceField.setAccessible(true);
    4. TileEntityFurnace furnace = furnaceField.get((craftfurnaceObject));
    5. Field name = null;
    6. try {
    7. name = furnace.getDeclaredField("o");
    8. name.setAccessible(true);
    9. name.set(furnace, "Analyzer");
    10. } catch (Exception x) {
    11. }
    But is has red under "furnaceField.get((craftfurnaceObject));"
    and "getDeclaredField"

    I tried casting "furnaceField.get((craftfurnaceObject));" to "TileEntityFurnace"
    but I still get "The method getDeclaredField(String) is undefined for the type TileEntityFurnace"
     
  15. Offline

    xTrollxDudex

    Elimnator
    Lol. Use furnace.getClass().getDeclaredField(...)
     
  16. Offline

    Elimnator

    xTrollxDudex Thanks, what DeclaredField do I have to get for a dispenser, "o" doesn't work.
     
  17. Offline

    xTrollxDudex

    ELIMINATOR
    It's the "a" field in TileEntityDispenser
     
  18. Offline

    Elimnator

    xTrollxDudex Actually it was "e" for me.


    Here is the code I used for anyone that finds this topic while looking for help:
    PHP:
                            CraftDispenser craftdispenserObject = (CraftDispenserblock.getState();
                            
    Field dispenserField = (craftdispenserObject).getClass().getDeclaredField("dispenser");
                            
    dispenserField.setAccessible(true);
                            
    TileEntityDispenser dispenser = (TileEntityDispenserdispenserField.get((craftdispenserObject));
                            
    Field name null;
                            try {
                                
    name dispenser.getClass().getDeclaredField("e");
                                
    name.setAccessible(true);
                                
    name.set(dispenser"Extractor");
                            } catch (
    Exception x) {
                            }
    Use "o' for a furnace.
     
Thread Status:
Not open for further replies.

Share This Page