copygirl / WearableBackpacks

Minecraft mod which adds beautiful, balanced backpacks
MIT License
61 stars 35 forks source link

[Integration] Get backpack and backpack content? #76

Closed Insane96 closed 6 years ago

Insane96 commented 6 years ago

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

copygirl commented 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.

Insane96 commented 6 years ago

Wait, am I missing something? IBackpack implements getData() but BackpackDataItems doesn't. It implements getItems(world, player)

copygirl commented 6 years ago
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);
Insane96 commented 6 years ago

The problem is that with reflection I can't return a type from your mod unless I set it as dependance

copygirl commented 6 years ago

ItemStackHandler is a Forge thing.

Insane96 commented 6 years ago

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 .

copygirl commented 6 years ago

I don't have Java stuff set up to write any actual code but there's two things you should do.

It's similar to what I do in IntermodUtils.

copygirl commented 6 years ago

Closing due to lack of activity.