Solved net.minecraft.server Itemstack to bukkit itemstack?

Discussion in 'Plugin Development' started by bobacadodl, Dec 14, 2012.

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

    bobacadodl

    How would I convert a net.minecraft.server Itemstack to a bukkit itemstack?
     
  2. Offline

    Comphenix

    By using a constructor:
    Code:java
    1. new CraftItemStack(nmsItemStack);
     
  3. Offline

    bobacadodl

    I figured that out, but how would I go about converting the CraftItemStack into an org.bukkit.inventory.ItemStack itemstack?
     
  4. Offline

    Comphenix

    ItemStack is just an interface class which CraftItemStack implements extends. So you can simply assign it directly;
    Code:java
    1. org.bukkit.inventory.ItemStack bukkitStack = new CrafItemStack(nmsItemStack);
     
  5. Offline

    bobacadodl

    o_o didn't know that. Thanks
     
  6. Offline

    evilmidget38 Retired Staff

    ItemStack isn't an interface....
     
  7. Offline

    Comphenix

    evilmidget38: Yeah, you're right. I was thinking of Player. I guess it's getting a bit late ...
     
  8. Offline

    bobacadodl

    evilmidget38
    Comphenix
    This no longer seems to be working??

    Code:
    public ItemStack smelt(ItemStack raw) {
            net.minecraft.server.v1_4_6.ItemStack smeltNMS = net.minecraft.server.v1_4_6.RecipesFurnace.getInstance().getResult(raw.getTypeId());
            ItemStack smelted = (ItemStack)(new CraftItemStack(smeltNMS));
            return smelted;
    }
     
    
    says that the constructor CraftItemStack(ItemStack) is not visible..
     
  9. Offline

    evilmidget38 Retired Staff

    It got changed when Itemmeta came out. Not sure what it is now.
     
  10. Offline

    bobacadodl

    Is it still possible to do it?
     
  11. Offline

    Jogy34

    org.bukkit.inventory.ItemStack is = CraftItemStack.asBukkitCopy(net.minecraft.server.ItemStack original)
     
    bobacadodl likes this.
  12. Offline

    bobacadodl

    Thanks!
     
  13. Offline

    fireblast709

    Though you might want to use
    Code:
    CraftItemStack.asCraftMirror(net.minecraft.server.ItemStack original)
    as this is kinda the same as
    Code:
    new CraftItemStack(net.minecraft.server.ItemStack);
    (Literal copy of the minecraft stack, preserving any non-ItemMeta NBTTags)
     
  14. Offline

    thefiscster510

    What about converting back? From obs ItemStack to nms ItemStack?
     
  15. Offline

    Technius

    thefiscster510
    Please don't necro.

    Code:
    net.minecraft.server.v1_5_R3.ItemStack nms = CraftItemStack.asNMSCopy(youritemstack);
    
     
    bobacadodl likes this.
Thread Status:
Not open for further replies.

Share This Page