Closed Insane96 closed 6 years ago
You might have to reference the non-API class BackpackDataItems
or directly call its getItems(world, player)
method via reflection on the IBackpackData
return by IBackpack.getData()
. (Currently only BackpackDataItems
implements IBackpackData
, but there was plans for different types of backpacks.)
... Note to self: There is a possible NPE when calling getItems()
without the world argument when lootable backpacks have not generated their loot yet. Huh.
Wait, am I missing something? IBackpack implements getData()
but BackpackDataItems doesn't. It implements getItems(world, player)
IBackpack backpack = BackpackHelper.getBackpack(player);
if (backpack == null) return;
IBackpackData data = backpack.getData();
if (!(data instanceof BackpackDataItems)) return;
BackpackDataItems dataItems = (BackpackDataItems)data;
ItemStackHandler items = dataItems.getItems(world, player);
The problem is that with reflection I can't return a type from your mod unless I set it as dependance
ItemStackHandler
is a Forge thing.
IBackpackData is returned from getData()
On 13 Apr 2018 4:52 pm, "copygirl" notifications@github.com wrote:
ItemStackHandler is a Forge thing.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/copygirl/WearableBackpacks/issues/76#issuecomment-381160846, or mute the thread https://github.com/notifications/unsubscribe-auth/AG2i0F4YYKM2qj77AKxED92d6NiffNsZks5toLu7gaJpZM4TR4YQ .
I don't have Java stuff set up to write any actual code but there's two things you should do.
getData()
and make sure it's a BackpackDataItems
by comparing the type name.getItems(world, player)
using reflection on the object returned by getData()
.It's similar to what I do in IntermodUtils
.
Closing due to lack of activity.
I'm trying to add integration to my IguanaTweaks mod. I would like the read the content of the backpack (when worn) and change the weight of the player accordingly.
Seems like that to get the backpack I can use getBackpack(Entity): https://github.com/copygirl/WearableBackpacks/blob/master/src/main/java/net/mcft/copy/backpacks/api/BackpackHelper.java#L49