Jump to content

Recommended Posts

Posted

I'm working on a plugin that will delete chest and put items somewhere else. But to do that, I need to first get a list of items that are inside chest.

Posted

Haven't tried a plugin myself, but inventories are stored as itemstack arrays as part of the tileentity used by the block.

How exactly they name that array depends on the mod. IC2 has all it's machines based off TileentityMachine.class which defines it as "inventory", while the vanilla chest uses "chestContents", furnace is "furnaceItemStacks", and so on...

There's probably a way to find every itemstack array attached to a tileentity derived class using reflection, but I's still new to java.

Posted

I have figured it out.

First, you have to add .zip of the mod to the build path. Then you can easily access stuff. For example alchemy chest:

            //block = Alchemist chest block

            TileEntity entity = ((CraftWorld) block.getWorld()).getTileEntityAt(block.getX(), block.getY(), block.getZ());

            if (!(entity instanceof TileAlchChest)) return;

            TileAlchChest chest = (TileAlchChest) entity;

           

            ItemStack[] items = chest.getContents();

Thanks for your help!

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...