Jump to content
  • Home
  • Files
  • Docs
  • Merch
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • Custom Inventory Slot Help
1.13 Update Notes for Mod Creators
Sign in to follow this  
Followers 4
Electric

Custom Inventory Slot Help

By Electric, June 9, 2018 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

Electric    1

Electric

Electric    1

  • Tree Puncher
  • Electric
  • Members
  • 1
  • 30 posts
Posted June 9, 2018

I'm attempting to use capabilities to create 2 custom inventory slots for every player. So far I've attached the capability to the player with an event handler, but I don't know what to put in the capability provider's "return capability" method. My code is as follows, any help would be appreciated.

Event Handler:

@SubscribeEvent
    public void attachEntityCapabilities( AttachCapabilitiesEvent<Entity> event) {

        if ( !( event.getObject() instanceof EntityPlayer ) ) {
            return ;
        }

        event.addCapability(CapabilityHandler.INV, new CustomInvProvider());

    }

 

Non-working Capability provider:

 @Override
    public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) {

        return capability == CapabilityHandler.INV;
    }

    @Override
    public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
        if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
            return (T) inventory;
        }
        return super.getCapability(capability, facing);
    }

 

I don't understand what to return in the capability provider for hasCapability and getCapability. Any solutions? 

  • Quote

Share this post


Link to post
Share on other sites

Electric    1

Electric

Electric    1

  • Tree Puncher
  • Electric
  • Members
  • 1
  • 30 posts
Posted June 9, 2018

Any suggestions?

  • Quote

Share this post


Link to post
Share on other sites

larsgerrits    510

larsgerrits

larsgerrits    510

  • Reality Controller
  • larsgerrits
  • Members
  • 510
  • 3455 posts
Posted June 9, 2018
18 hours ago, Electric said:

return capability == CapabilityHandler.INV;

 

18 hours ago, Electric said:

if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)

 

Are these the same?

  • Quote

Share this post


Link to post
Share on other sites

Draco18s    2090

Draco18s

Draco18s    2090

  • Reality Controller
  • Draco18s
  • Members
  • 2090
  • 13999 posts
Posted June 9, 2018

Also:

 @Override
    public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) {

        return capability == CapabilityHandler.INV;
    }

What if another mod adds a separate capability to all TileEntities? Yours will always return false for it.

  • Quote

Share this post


Link to post
Share on other sites

Electric    1

Electric

Electric    1

  • Tree Puncher
  • Electric
  • Members
  • 1
  • 30 posts
Posted June 10, 2018

So I've fixed up the capability itself and it attaches to the player. Could someone go into more detail on how to add the extra slot itself to the inventory?

  • Quote

Share this post


Link to post
Share on other sites

Draco18s    2090

Draco18s

Draco18s    2090

  • Reality Controller
  • Draco18s
  • Members
  • 2090
  • 13999 posts
Posted June 10, 2018
59 minutes ago, Electric said:

So I've fixed up the capability itself and it attaches to the player. Could someone go into more detail on how to add the extra slot itself to the inventory?

You mean the GUI?

You need to replace it and use your own GUI instead.

  • Quote

Share this post


Link to post
Share on other sites

Electric    1

Electric

Electric    1

  • Tree Puncher
  • Electric
  • Members
  • 1
  • 30 posts
Posted June 10, 2018

Yes, how do I add the slot and how can I override the inventory Gui with a custom one?

  • Quote

Share this post


Link to post
Share on other sites

Daeruin    24

Daeruin

Daeruin    24

  • Diamond Finder
  • Daeruin
  • Members
  • 24
  • 390 posts
Posted June 11, 2018

To create the custom inventory, extend GuiInventory and supply your own texture that shows your custom slots. Then use the GuiOpenEvent, check if it's a GuiInventory, and if so, open your own custom inventory instead using GuiOpenEvent#setGui.

  • Quote

Share this post


Link to post
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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

  • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 4
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • DragonITA
      [1.14.4] Why minecraft with mod dont want start?

      By DragonITA · Posted just now

      i try with delete the entier Config Folder but it still dont work and the Folder come back.
    • plugsmustard
      on/off button for custom furnace

      By plugsmustard · Posted 1 minute ago

      what exactly is wrong with them. i was told to return a new packet?
    • JetCobblestone
      [1.14] moving item assignment to a separate function

      By JetCobblestone · Posted 3 minutes ago

      Hey everyone,   I'm trying to move my item assignment into a new class. I've stuck in into the same package as my main and called it ItemsLoader.   package jetcobblestone.firstmod; import jetcobblestone.firstmod.lists.itemList; import net.minecraft.item.Foods; import net.minecraft.item.Item; import net.minecraft.item.ItemGroup; import net.minecraft.util.ResourceLocation; import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; public class ItemsLoader { public static final String modid = "first_mod"; public static void Items() { @Mod.EventBusSubscriber(bus=Mod.EventBusSubscriber.Bus.MOD) public static class RegistryEvents { @SubscribeEvent public static void registerItems(final RegistryEvent.Register<Item> event) { event.getRegistry().registerAll ( itemList.hair_fibre = new Item(new Item.Properties().food(Foods.COOKIE).group(ItemGroup.FOOD).maxStackSize(1)).setRegistryName(location("hair_fibre")) ); } } private static ResourceLocation location(String name) { return new ResourceLocation(modid, name); } } }   This is the new class, however I'm running into an issue with the new Items function. It's giving me an error saying that it's expecting a volatile at the void token. Why is it trying to force me to do this? I don't want to send this to main memory? If I do replace void with volatile, it tells me there's a syntax error on the 'void' token, despite the fact there is no void. Any help would be much appreciated, thank you!
    • Draco18s
      on/off button for custom furnace

      By Draco18s · Posted 7 minutes ago

      Good. Now fix these two lines. https://github.com/drmdgg/marijuanacraft1.14.4/blob/a246b0229e61058b95672d7f4813b5c3deb28229/src/main/java/drmdgg/marijuanacraft/network/PacketButtonClicked.java#L28-L29
    • FaxeeK
      Can't launch the game with forge

      By FaxeeK · Posted 41 minutes ago

      Soo i've been having this problem ever since I factory restarted my computer, every time I launch the game with forge I get this pop op . I can launch stuff from technicLaunch but not twitch. Idk if this helps but I had it instaled before I reset my computer. Sorry for bad grammer i'm danish.
  • Topics

    • matt1999rd
      9
      [1.14-newer] deprecated method onBlockActivated

      By matt1999rd
      Started November 1

    • DragonITA
      1
      [1.14.4] Why minecraft with mod dont want start?

      By DragonITA
      Started 58 minutes ago

    • plugsmustard
      43
      on/off button for custom furnace

      By plugsmustard
      Started Wednesday at 03:11 PM

    • JetCobblestone
      0
      [1.14] moving item assignment to a separate function

      By JetCobblestone
      Started 4 minutes ago

    • FaxeeK
      0
      Can't launch the game with forge

      By FaxeeK
      Started 41 minutes ago

  • Who's Online (See full list)

    • matt1999rd
    • DragonITA
    • xVoidZx
    • Silverpool64
    • Lea9ue
    • Hendoor64
    • Vorquel
    • JetCobblestone
    • Atila1091
    • maycool12
    • vaartis
    • plugsmustard
    • Draco18s
    • FaxeeK
    • loordgek
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • Custom Inventory Slot Help
  • Theme
  • Contact Us
  • Discord

Copyright © 2019 ForgeDevelopment LLC · Ads by Curse Powered by Invision Community