Posted June 2, 20178 yr Hello guys, well, I have a huge problem I can't answer with searching on forum or with Doc forge. I want to do a custom Inventory player, but for that I need to create a capability for stock this "inventory". Then I checked the doc here : https://mcforge.readthedocs.io/en/latest/datastorage/capabilities/ but, either I do not understand, or something is missing... (But I think I do not understand, I have a basic English, I find) Then, the best I can do is to show you what I already do, and what I do wrong. CapabilityHandler.class : Spoiler package fr.afraidofthedark.capability; import fr.afraidofthedark.AfraidOfTheDark; import fr.afraidofthedark.capability.darknight.DarkNightProvider; import fr.afraidofthedark.capability.inventory.CustomInventoryProvider; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.ResourceLocation; import net.minecraftforge.event.AttachCapabilitiesEvent; import net.minecraftforge.event.entity.player.EntityItemPickupEvent; import net.minecraftforge.fml.common.eventhandler.EventPriority; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; /** * Created by Mr. Dj on 10/05/2017. */ public class CapabilityHandler { public static final ResourceLocation ITEM_HANDLER_CAPABILITY = new ResourceLocation(AfraidOfTheDark.MODID, "custominv"); @SubscribeEvent(priority = EventPriority.HIGHEST) public void attachCapability(AttachCapabilitiesEvent.Entity event) { if (!(event.getEntity() instanceof EntityPlayer)) return; event.addCapability(ITEM_HANDLER_CAPABILITY, new CustomInventoryProvider()); //event.addCapability(CustomInventoryCap.ID, new CustomInventoryProvider(new CustomInventory())); } @SubscribeEvent public void itemPickup(EntityItemPickupEvent event) { // TEST capability if(event.getEntity() instanceof EntityPlayer) { System.out.println("inserting " + event.getItem().getEntityItem()); //event.getEntity().getCapability(CustomInventoryCap.CUSTOM_INVENTORY, null).insertItem(0, event.getItem().getEntityItem(), true); That was a test event.getItem().setDead(); } } } CustomInventoryProvider.class : Spoiler package fr.afraidofthedark.capability.inventory; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumFacing; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.CapabilityInject; import net.minecraftforge.common.capabilities.ICapabilityProvider; import net.minecraftforge.items.IItemHandler; import javax.annotation.Nonnull; import javax.annotation.Nullable; /** * Created by Mr. Dj on 22/05/2017. */ public class CustomInventoryProvider implements ICapabilityProvider, IItemHandler { @CapabilityInject(IItemHandler .class) static Capability<IItemHandler > ITEM_HANDLER_CAPABILITY = null; private IItemHandler instance = ITEM_HANDLER_CAPABILITY.getDefaultInstance(); @Override public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) { return capability == ITEM_HANDLER_CAPABILITY; } @Nullable @Override public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) { return capability == ITEM_HANDLER_CAPABILITY ? ITEM_HANDLER_CAPABILITY.<T> cast(this.instance) : null; } @Override public int getSlots() { return 5; } @Nonnull @Override public ItemStack getStackInSlot(int slot) { return null; } @Nonnull @Override public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) { return null; } @Nonnull @Override public ItemStack extractItem(int slot, int amount, boolean simulate) { return null; } @Override public int getSlotLimit(int slot) { return 0; } } CommonProxy.class : Spoiler package fr.afraidofthedark.proxy; import fr.afraidofthedark.AfraidOfTheDark; import fr.afraidofthedark.capability.CapabilityHandler; import fr.afraidofthedark.capability.inventory.CustomInventoryProvider; import fr.afraidofthedark.item.ItemHandler; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.capabilities.CapabilityManager; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import net.minecraftforge.fml.common.network.NetworkRegistry; import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.items.IItemHandler; /** * Created by Mr. Dj on 10/05/2017. */ public class CommonProxy { public void preInit(FMLPreInitializationEvent event) { CapabilityManager.INSTANCE.register(IItemHandler.class, new CustomInventoryProvider(), IItemHandler.class); MinecraftForge.EVENT_BUS.register(new CapabilityHandler()); } public void init(FMLInitializationEvent event) { } public void postInit(FMLPostInitializationEvent event) { } } Error on CommonProxy : line : "CapabilityManager.INSTANCE.register(IItemHandler.class, new IItemHandler(), IItemHandler.class);" Well, I hope there is everything you need for helping me ! I think there is so much things to change, but if I can understand where from the problem, that could be very cool. Thank you Edited June 2, 20178 yr by DjCtavia Add bold to class + line Error
June 2, 20178 yr Author 25 minutes ago, diesieben07 said: IItemHandler already has a capability associated with it. You need to use a different interface. The easiest way is to just make an empty marker interface for your item handler. Should I do a new interface who extends "IItemHandler" then ? Really, I don't see what class does I need, and how tu use it... I tried, but really I'm doing it really bad...
June 2, 20178 yr Author Well, get it, but in my Storage, how should I WriteNBT() and ReadNBT() ? There is a lot of NBT type, or maybe there is another way ? (Sorry to waste your time, look like understand nothing, but I really don't understand how to use correctly everything of Capabilities, I have created one for money who work very well, but when I want to doing with slot, that like I'm loosing every landmark.)
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.