NMS. ContainerEnchantTable

Discussion in 'Plugin Development' started by guitargun, Oct 18, 2015.

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

    guitargun

    does anyone know how I get from CraftInventoryEnchanting to ContainerEnchantTable or from the enchanting block to it?
     
  2. @guitargun
    An Inventory is the real inventory, holding it's information, while a Container is uniquely created for each player that opens the Inventory, therefor you can only get the Container from a player (Retrieved from a field activeContainer inside EntityPlayer/EntityHuman (not sure)), and for the block, I believe you can use World#getTileEntity(BlockPosition) (NMS World class), cast to TileEntityEnchantTable (or something) and do stuff there.
     
  3. Offline

    guitargun

    cool. found it.. and how can I add those clickable options?
     
  4. Offline

    guitargun

    ok I need a bump. I know its only 24 hours in 2 hours but in 2 hours I can't work on it for another 48 hours
     
  5. @guitargun
    Which "Clickable" options? You mean the enchantment types on the right?
     
  6. Offline

    guitargun

    @megamichiel yup. it doesn't need to be a enchant or whatever. It just needs to be clickable and I need to set the costs of it.. (which has something to do with the costs field)....
    after the player clicks it I have something that should change the outcome.
     
  7. @guitargun
    For the clicking, you need to listen (using ProtocolLib) for this packet, and for the enchantment costs: There is a public field called 'costs' inside ContainerEnchantTable with type int[] and length 3 which contain the costs. Editing those does not automaticly send a packet, for that you need to send this packet with the right info.
     
  8. Offline

    guitargun

    @megamichiel. would you happen to know what this packet is called in nms? ordo I need to use protocollib for it?
     
  9. @guitargun
    PacketPlayInEnchantItem, ProtocolLib is just a useful library for intercepting incoming and outgoing packets, unless you have an alternative, I recommend it.
     
  10. Offline

    guitargun

    ehm I tried this but this disconnects the player...
    Code:
                       
    ContainerEnchantTable enchant = (ContainerEnchantTable) player.activeContainer;
                        enchant.costs[0] = 5;
                        enchant.costs[1] = 8;
                        enchant.costs[2] = 10;
                       
                        PacketPlayInEnchantItem p = new PacketPlayInEnchantItem();
                        try {
                            Field a = PacketPlayInEnchantItem.class.getDeclaredField("a");
                            a.setAccessible(true);
                            a.setInt(p, 0);
                            Field b = PacketPlayInEnchantItem.class.getDeclaredField("b");
                            b.setAccessible(true);
                            b.setInt(p, enchant.costs[0]);
                            player.playerConnection.sendPacket(p);
                        } catch (NoSuchFieldException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        } catch (SecurityException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        } catch (IllegalArgumentException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        } catch (IllegalAccessException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
    
    event when I use reflection to set the data it just kicks me out....
     
  11. @guitargun
    Oh oopsie I thought you ment the incoming packet, but the outgoing one is PacketPlayOutWindowData
     
  12. Offline

    guitargun

    @megamichiel ok so I have this
    Code:
    PacketPlayOutWindowData data = new PacketPlayOutWindowData(enchant.windowId, 0, enchant.costs[0]);
    hope I understand the packet, the first is the window id, then the slot of the enchant and then the cost of it?
    don't seem to work? tried with sending a list of packets with all the costs etc. still no succes.
     
    Last edited: Oct 21, 2015
  13. Offline

    guitargun

    bump?

    I also tried this:
    Code:
    ContainerEnchantTable enchant = (ContainerEnchantTable) player.activeContainer;
                        enchant.costs[0] = 5;
                        enchant.costs[1] = 8;
                        enchant.costs[2] = 10;
                        player.setContainerData(enchant, 0, enchant.costs[0]);
                        player.setContainerData(enchant, 1, enchant.costs[1]);
                        player.setContainerData(enchant, 2, enchant.costs[2]);
    also doesn't seem to do anything

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Oct 29, 2015
Thread Status:
Not open for further replies.

Share This Page