InventoryLargeChest Cast to Inventory?

Discussion in 'Plugin Development' started by WMisiedjan, Feb 28, 2011.

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

    WMisiedjan

    Hello,

    For some case (VirtualChests), I'm using this method:
    http://forums.bukkit.org/threads/virtual-chests-proof-of-concept.3917/

    As end result you end up with an InventoryLargeChest.

    I want to make that a Inventory, so it's easier to code with.

    When I cast it I get this error:
    20:11:03 [SEVERE] java.lang.ClassCastException: net.minecraft.server.InventoryLargeChest cannot be cast to org.bukkit.inventory.Inventory

    Does someone know's a way to get this working?

    Or can someone explain how I can add/remove items from an InventoryLargeChest?
    --- merged: Feb 28, 2011 7:15 PM ---
    Oops, Edited link to real thread.
     
  2. Offline

    Afforess

    Use the InventoryLargeChest to create a CraftInventory, then cast the CraftInventory to inventory.

    But that's a terrible, terrible way to do it. MM has fully written, extensible, and easy to use Inventory interface - that you can just ... borrow.
     
  3. Offline

    WMisiedjan

    You give me permissions for that? Because no source code is included in jar.
     
  4. Offline

    Afforess

    MM is licensed CC 3.0. It's a pretty noob-friendly license:http://creativecommons.org/licenses/by-sa/3.0/


    There is a link to the source here: https://github.com/Afforess/MinecartMania.

    Of course, the lazy mans route is simply to make MM a dependency and just use it as a library, instead of cutting and pasting source, but what you do it up to you!
     
  5. Offline

    WMisiedjan

    Thanks! I'll think I go with the Terrible way to do it. Because I don't really get Interfaces yet. And if I gonna use a interface, I need to like create custom methods right?
     
  6. Offline

    Afforess

    Well, you don't need to understand interfaces, it comes with an API. You could add Minecart Mania as a library (like you added Bukkit as a library), and then do this:

    MinecartManiaChest chest = MinecartManiaWorld.getMinecartManiaChestAt(someChest);
    chest.addItem(itemstack);

    It will add an to the single chest if there is room, and add it to the other neighbor chest if it's a double chest.
     
  7. Offline

    WMisiedjan

    The problem is that those chest doesn't exists in the world. As mentioned before, They are Virtual.
     
Thread Status:
Not open for further replies.

Share This Page