Workbench Bukkit Glitch?

Discussion in 'Plugin Development' started by B3N909, May 16, 2015.

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

    B3N909

    Right now I have some simple code to have workbenches keep the items in the 3x3(Matrix). When you close the inventory, it saves the matrix(3x3 grid) and when you open it then it retrieves the matrix from the config for that location and sets it. The problem is when loading the matrix with a known crafting recipe then it does not display the output unless you update one of the blocks manually by a click. Say you have the ingredients of a iron block in the matrix(you see the output and it makes a iron block) and you leave the workbench and come back then there is no output as if the recipe does not exist unless you update the matrix by clicking a ingredient.
     
  2. Offline

    nverdier

    There's probably something you could do with NMS to update the output.
     
  3. Try calling Player#updateInventory(), it calls the same method as the one that's called when it recieves a window click packet from the player
     
  4. Offline

    B3N909

    Nope. Close but no cigar.
     
  5. @B3N909
    Hrm, I think I found something:
    Code:
    CraftingInventory inv; //The crafting inventory you have, I named it inv
    InventoryCrafting handle = (InventoryCrafting) ((CraftInventory)inv).getInventory();
    net.minecraft.server.<version>.World world = ((CraftWorld) <player>.getWorld()).getHandle();
    CraftingManager.getInstance().craft(handle, world);
     
  6. Offline

    B3N909

    @megamichiel , Hmm I've added this but using NMS seemed to break all of my existing code and act like the class is not even ran?

    EDIT: Yeah just a version mixup with nms... I got the code implemented using R1 so I had to change your code to this:

    Code:
                InventoryCrafting handle = (InventoryCrafting)((CraftInventory)inv).getInventory();
                WorldServer world = ((CraftWorld)Util.getDefWorld()).getHandle();
                CraftingManager.getInstance().craft(handle, world);
    
    It seems to work script wise just not graphically in game where I cannot see the result slot, although if I click it, then it acts as if it was there.
     
    Last edited: May 17, 2015
  7. @B3N909
    Oh if it's that you can't see it, try this:
    Code:
    InventoryCrafting handle = (InventoryCrafting)((CraftInventory)inv).getInventory();
    int id = 0;
    try {
      Field field = InventoryCrafting.class.getDeclaredField("d");
      field.setAccessible(true);
      Container container = (Container) field.get(handle);
      id = container.windowId;
    } catch (Exception ex) {
      ex.printStackTrace();
    }
    net.minecraft.server.<version>.ItemStack stack = CraftItemStack.asNMSCopy(inv.getItem(0));
    PacketPlayOutSetSlot packet = new PacketPlayOutSetSlot(id, 0, stack);
    ((CraftPlayer) <player>).getHandle().playerConnection.sendPacket(packet);
     
  8. Offline

    B3N909

    @megamichiel What is Field's package? There are several fields and getDeclaredField only returns a "Field" so I don't know what to import?

    @megamichiel Nope?? I have never messed with NMS or Packets outside of this plugin I am making so I am not that big of a help. Here is a pastebin with the whole class so you could see what is exactly happening.. http://pastebin.com/aatPrFac

    If you put some items in a crafting table and leave without crafting the items, when you come back the ingredients in the 3x3 will stay there, but the recipe output does not show. Adding this...
    Code:
    InventoryCrafting handle = (InventoryCrafting)((CraftInventory)inv).getInventory();
                WorldServer world = ((CraftWorld)Util.getDefWorld()).getHandle();
                CraftingManager.getInstance().craft(handle, world);
    
    At ln-85 makes it so that if you click the output slot you get the item, but you don't see the item in the slot. Adding the code you just pasted did nothing...

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 12, 2016
  9. @B3N909
    Oh I misunderstood, sorry about that, the only possible option I have left is call the part you just said with a little delay.
     
  10. Offline

    B3N909

    @megamichiel I was just testing something and I noticed that it is setting the 2x2 crafting table in my players inventory to the output and not what was in the workbench? Maybe using the wrong packet?
     
Thread Status:
Not open for further replies.

Share This Page