I request that the following method be added to ItemStack
@javax.annotation.Nullable
public net.minecraftforge.common.capabilities.ICapabilityProvider getCapabilityProvider() {
return this.capabilityProvider;
}
Where capabilityProvider is the ICapabilityProvider instance returned by Item.initCapabilities(ItemStack, NBTTagCompound) or null.
public class FWItem extends Item implements IFWItem {
@Override
@Nullable
public FWItemCapabilityProvider initCapabilities(ItemStack stack, @Nullable NBTTagCompound nbt) {
nova.core.item.Item item = ItemConverter.instance().toNova(stack);
WrapperEvent.FWItemInitCapabilities event = new WrapperEvent.FWItemInitCapabilities(item, new FWItemCapabilityProvider(item));
Game.events().publish(event);
return event.capabilityProvider.hasCapabilities() ? event.capabilityProvider : null;
}
}
public class ItemConverter implements NativeConverter<nova.core.item.Item, ItemStack>, ForgeLoadable {
@Override
public nova.core.item.Item toNova(ItemStack stack) {
return getNovaItem(stack).setCount(itemStack.getCount());
}
public nova.core.item.Item getNovaItem(ItemStack stack) {
if (stack.getItemDamage() == net.minecraftforge.oredict.OreDictionary.WILDCARD_VALUE) {
return getNovaItem(new ItemStack(stack.getItem(), 1, 0));
}
if (stack.getTagCompound() instanceof FWNBTTagCompound) {
return ((FWNBTTagCompound) stack.getTagCompound()).getItem();
} else if (stack.getCapabilites() instanceof FWItemCapabilityProvider) {
// Here is where it would be used instead of reflection
return ((FWItemCapabilityProvider)stack.getCapabilityProvider()).item;
} else {
nova.core.item.ItemFactory itemFactory = registerMinecraftMapping(stack.getItem(), stack.getItemDamage());
Data data = stack.getTagCompound() != null ? Game.natives().toNova(stack.getTagCompound()) : new Data();
if (!stack.getHasSubtypes() && stack.getItemDamage() > 0) {
data.put("damage", stack.getItemDamage());
}
return itemFactory.build(data);
}
}
}
public class FWItemCapabilityProvider extends FWCapabilityProvider {
public final nova.core.item.Item item;
public FWItemCapabilityProvider(nova.core.item.Item item) {
this.item = item;
}
}
Can you reduce your use case to something simpler? As someone unfamiliar with nova I have no idea what's going on and why you need the method.
Also ItemStack is already an ICapabilityProvider, is it not? Why the need to get the internal object?
To get the instance of the ICapabilityProvider which was returned by Item.initCapabilities(ItemStack,NBTTagCompound)
I'll soon have a PR with this feature ready.
Why not use reflection? This doesn't seem like something that a normal mod needs.
Because the capabilities field in ItemStack is not the same instance as the result of Item.initCapabilities(ItemStack,NBTTagCompound), that being said, it should be possible to extract the original instance from the array in CapabilityDispatcher.
Again, why?
So far all you have said is "it should be possible". Adding features "just because" is not a good idea usually.
I don't understand why you need that.
Isn't it itemStack.capabilities.caps[0] anyway?
You are explaining things in a mechanical sense, I can get answers like that from the code you provided.
What I want to know is why, otherwise I can't understand the problem.
The ItemStack.capabilities field is private and the CapabilityDispatcher.caps field is also private.
Why not use reflection? This doesn't seem like something that a normal mod needs.
I鈥檝e created the PR, so now it is up to the Forge team to decide if this will be added to Forge.
Hello, I am the Forge PR review person.
Please answer my questions :\
No, it's unnecessary, and a massive no without explanation. From an external point of view you do not need to know about the internal implementation of ItemStacks ICapProvider.
Your example in the first post is the EXACT opposite of what you should be doing. You should use the init caps event, and add a "nova item holder" cap with one function on it "nova.Item getItem()" and in your example you'd use has/getCap instead of your instance of check
Most helpful comment
Hello, I am the Forge PR review person.
Please answer my questions :\