Jump to content

[1.11.2] New inventory, capability


DjCtavia

Recommended Posts

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 by DjCtavia
Add bold to class + line Error
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.)

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Baba  Serege [[+27-73 590 8989]] has experience of 27 years in helping and guiding many people from all over the world. His psychic abilities may help you answer and resolve many unanswered questions. He specialize in helping women and men from all walks of life.. 1) – Bring back lost lover. even if lost for a long time. 2) – My lover is abusing alcohol, partying and cheating on me I urgently need help” 3) – Divorce or court issues. 4) – Is your love falling apart? 5) – Do you want your love to grow stronger? 6) – Is your partner losing interest in you? 7) – Do you want to catch your partner cheating on you? – We help to keep your partner faithful and loyal to you. 9) – We recover love and happiness when relationship breaks down. 10) – Making your partner loves you alone. 11) – We create loyalty and everlasting love between couples. 12) – Get a divorce settlement quickly from your ex-partner. 13) – We create everlasting love between couples. 14) – We help you look for the best suitable partner. 15) – We bring back lost lover even if lost for a long time. 16) – We strengthen bonds in all love relationship and marriages 17) – Are you an herbalist who wants to get more powers? 18) – Buy a house or car of your dream. 19) – Unfinished jobs by other doctors come to me. 20) – I help those seeking employment. 21) – Pensioners free treatment. 22) – Win business tenders and contracts. 23) – Do you need to recover your lost property? 24) – Promotion at work and better pay. 25) – Do you want to be protected from bad spirits and nightmares? 26) – Financial problems. 27) – Why you can’t keep money or lovers? 28) – Why you have a lot of enemies? 29) – Why you are fired regularly on jobs? 30) – Speed up money claim spell, delayed payments, pension and accident funds 31) – I help students pass their exams/interviews. 33) – Removal of bad luck and debts. 34) – Are struggling to sleep because of a spiritual wife or husband. 35- ) Recover stolen property
    • OLXTOTO adalah situs bandar togel online resmi terbesar dan terpercaya di Indonesia. Bergabunglah dengan OLXTOTO dan nikmati pengalaman bermain togel yang aman dan terjamin. Koleksi toto 4D dan togel toto terlengkap di OLXTOTO membuat para member memiliki pilihan taruhan yang lebih banyak. Sebagai situs togel terpercaya, OLXTOTO menjaga keamanan dan kenyamanan para membernya dengan sistem keamanan terbaik dan enkripsi data. Transaksi yang cepat, aman, dan terpercaya merupakan jaminan dari OLXTOTO. Nikmati layanan situs toto terbaik dari OLXTOTO dengan tampilan yang user-friendly dan mudah digunakan. Layanan pelanggan tersedia 24/7 untuk membantu para member. Bergabunglah dengan OLXTOTO sekarang untuk merasakan pengalaman bermain togel yang menyenangkan dan menguntungkan.
    • Baba  Serege [[+27-73 590 8989]] has experience of 27 years in helping and guiding many people from all over the world. His psychic abilities may help you answer and resolve many unanswered questions. He specialize in helping women and men from all walks of life.. 1) – Bring back lost lover. even if lost for a long time. 2) – My lover is abusing alcohol, partying and cheating on me I urgently need help” 3) – Divorce or court issues. 4) – Is your love falling apart? 5) – Do you want your love to grow stronger? 6) – Is your partner losing interest in you? 7) – Do you want to catch your partner cheating on you? – We help to keep your partner faithful and loyal to you. 9) – We recover love and happiness when relationship breaks down. 10) – Making your partner loves you alone. 11) – We create loyalty and everlasting love between couples. 12) – Get a divorce settlement quickly from your ex-partner. 13) – We create everlasting love between couples. 14) – We help you look for the best suitable partner. 15) – We bring back lost lover even if lost for a long time. 16) – We strengthen bonds in all love relationship and marriages 17) – Are you an herbalist who wants to get more powers? 18) – Buy a house or car of your dream. 19) – Unfinished jobs by other doctors come to me. 20) – I help those seeking employment. 21) – Pensioners free treatment. 22) – Win business tenders and contracts. 23) – Do you need to recover your lost property? 24) – Promotion at work and better pay. 25) – Do you want to be protected from bad spirits and nightmares? 26) – Financial problems. 27) – Why you can’t keep money or lovers? 28) – Why you have a lot of enemies? 29) – Why you are fired regularly on jobs? 30) – Speed up money claim spell, delayed payments, pension and accident funds 31) – I help students pass their exams/interviews. 33) – Removal of bad luck and debts. 34) – Are struggling to sleep because of a spiritual wife or husband. 35- ) Recover stolen property
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.