Chest Inventory

Hello,
how can I get the inventory of a chest when I only know the location?

I tried it with the code below (at the location is a normal chest):

this.tileEntityCarrier = (TileEntityCarrier) this.location.getTileEntity().get();
this.tileEntityCarrier.getInventory();

but the code throws:

java.lang.AbstractMethodError: net.minecraft.tileentity.TileEntityChest.getInventory()Lorg/spongepowered/api/item/inventory/type/TileEntityInventory;

Did I do something wrong or isn’t it just implemented yet?

AbstractMethodError means it isn’t implemented yet.

Sadly the inventory API is still missing :frowning:

Ok. :slight_smile: Thank both of you.

Got the same error, is it still not implemented? Is there any source I can check the status by myself?

Greetz
scotty86

Correct, still not implemented.
You can see the progress here:
https://github.com/SpongePowered/SpongeCommon/compare/feature/inventorytemp

For the time being, you can just cast to the internal minecraft classes (you will need to configure your project with ForgeGradle for this)

1 Like

@simon816 Thank you for the link.

I assume, when using forge in my plugin, it won’t run on a sponge vanilla server?

Correct, forge-only methods/classes are only available in SpongeForge.

Thanks! Forge is not an option for me.

Why’s that?

Because I don’t want to code things twice. :wink:

Huh? But a sponge plugin will work on both SpongeForge and SpongeVanilla.

A sponge plugin with forge parts will only run on SpongeForge, however.

By using ForgeGradle you can easily add NMS that is readable but will still work for SpongeVanilla since you aren’t actually depending on Forge (or at least i’m assuming that’s what @simon816 is getting at)

I have setup Forge Gradle. How can I use it together with sponge?

Is it possible to open a chests inventory to a player using a Sponge plugin and minecraft/forge classes without having a client mod?

Add spongeforge as a dependency.
e.g. compile "org.spongepowered:spongeforge:1.8.9-1763-3.1.0-BETA-1174:dev"
See the SDK (needs updating, here’s the PR)

Yes, using player.openInventory(Inventory)

Please search the forums for an answer or create a new thread in future.

This is how I tried it:

Chest chest = (Chest)location.getTileEntity().get();
(e.getCause().last(Player.class).get()).openInventory(chest.getInventory());

And that’s the error I get:

java.lang.AbstractMethodError: Method net/minecraft/tileentity/TileEntityChest.g
etInventory()Lorg/spongepowered/api/item/inventory/type/TileEntityInventory; is
abstract

If I add that to my build.gradle, the dependency gets underlined with a red line in the Gradle-tab of IDEA.

AbstractMethodError means it’s not implemented yet.

I posted this topic because I knew InventoryApi was not implemented and I was looking for a way to do it using forge.

Also, what do I have to do to add the spongeforge dependeny?
compile "org.spongepowered:spongeforge:1.8.9-1763-3.1.0-BETA-1174:dev"; is not working. (maybe because of the redirection to minecraftforge.net)