Jump to content
  • Home
  • Files
  • Docs
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
  • [1.16.4] How i can open a container by clicking on my mob
Currently Supported: 1.16.X (Latest) and 1.15.X (LTS)
Sign in to follow this  
Followers 2
Klarks

[1.16.4] How i can open a container by clicking on my mob

By Klarks, January 16 in Modder Support

  • Reply to this topic
  • Start new topic
  • Prev
  • 1
  • 2
  • Next
  • Page 1 of 2  

Recommended Posts

Klarks    0

Klarks

Klarks    0

  • Stone Miner
  • Klarks
  • Members
  • 0
  • 95 posts
Posted January 16

I know that i have to somehow open gui on server but i dont know what exactly i need to do

Container



public class MyModContainer extends Container implements INamedContainerProvider {
    private  IItemHandler playerInventory;

    protected MyModContainer(int id, PlayerInventory playerInventory) {
        super(RegObj.MOD_CONTAINER.get(), id);

        this.playerInventory = new InvWrapper(playerInventory);
        playerInventory.player.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).ifPresent(h -> {

            addSlot(new SlotItemHandler(h,0,79,18));
        });
        layoutPlayerInventory(7,54);
    }


    private int addSlotRange(IItemHandler handler, int index, int x, int y, int amount, int dx)
    {
        for(int i = 0; i < amount;i++)
        {
            addSlot(new SlotItemHandler(handler,index,x,y));
            x+=dx;
            index++;
        }
        return index;
    }

    private int addSlotBox(IItemHandler handler,int index,int x,int y,int horAmount,int dx,int verAmount,int dy)
    {
        for (int j = 0;j<verAmount;j++)
        {
            index = addSlotRange(handler,index,x,y,horAmount,dx);
            y+=dy;
        }
        return index;
    }

    private void layoutPlayerInventory(int leftCol, int topRow)
    {
        addSlotBox(playerInventory,9,leftCol,topRow,9,18,3,18);
        topRow += 58;
        addSlotRange(playerInventory,0,leftCol,topRow,9,18);
    }


    @Override
    public boolean canInteractWith(PlayerEntity playerIn) {
        return true;
    }

    @Override
    public ITextComponent getDisplayName() {
        return new StringTextComponent("MY_INV");
    }

    @Nullable
    @Override
    public Container createMenu(int p_createMenu_1_, PlayerInventory p_createMenu_2_, PlayerEntity p_createMenu_3_) {
        return null;
    }
}

 

Screen

public class MyModInv extends ContainerScreen<MyModContainer> {
    private static final int WIDTH =179;
    private static final int HEIGHT =151;

    private ResourceLocation GUI = new ResourceLocation(Main.MODID,"textures/gui/my_inv.png");

    public MyModInv(MyModContainer screenContainer, PlayerInventory inv, ITextComponent titleIn) {
        super(screenContainer, inv, titleIn);
    }


    @Override
    public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) {
        super.render(matrixStack, mouseX, mouseY, partialTicks);
        this.renderBackground(matrixStack);
        this.renderHoveredTooltip(matrixStack, mouseX, mouseY);
    }

    @Override
    protected void drawGuiContainerBackgroundLayer(MatrixStack matrixStack, float partialTicks, int x, int y) {
        RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
        this.minecraft.getTextureManager().bindTexture(GUI);
        int i = (this.width - WIDTH) / 2;
        int j = (this.height - HEIGHT) / 2;
        this.blit(matrixStack, i, j, 0, 0, WIDTH, HEIGHT);
    }


    @Override
    public boolean isPauseScreen() {
        return false;
    }


}
  • Quote

Share this post


Link to post
Share on other sites

poopoodice    117

poopoodice

poopoodice    117

  • Dragon Slayer
  • poopoodice
  • Members
  • 117
  • 925 posts
Posted January 16

Override MobEntity#func_230254_b_ and the you can open the container via NetworkHooks.openGui().

  • Quote

Share this post


Link to post
Share on other sites

Klarks    0

Klarks

Klarks    0

  • Stone Miner
  • Klarks
  • Members
  • 0
  • 95 posts
Posted January 17 (edited)

How i can get my container here

public ActionResultType func_230254_b_(PlayerEntity playerEntity, Hand hand) {
    if (!this.world.isRemote) {
       String en = getOwner();
       String pl = playerEntity.getScoreboardName();





     if(en.equals(pl))

     {
         NetworkHooks.openGui((ServerPlayerEntity) playerEntity,*container*);
     }
     else
         playerEntity.sendMessage(new TranslationTextComponent("You are not  "+en),Util.DUMMY_UUID);

    }

    return ActionResultType.func_233537_a_(this.world.isRemote);
}
Edited January 17 by Klarks
  • Quote

Share this post


Link to post
Share on other sites

poopoodice    117

poopoodice

poopoodice    117

  • Dragon Slayer
  • poopoodice
  • Members
  • 117
  • 925 posts
Posted January 17

Make a new instance of your container.

  • Quote

Share this post


Link to post
Share on other sites

Klarks    0

Klarks

Klarks    0

  • Stone Miner
  • Klarks
  • Members
  • 0
  • 95 posts
Posted January 17

like this?


 

NetworkHooks.openGui((ServerPlayerEntity) playerEntity,new MyModContainer(0,playerEntity.inventory));
  • Quote

Share this post


Link to post
Share on other sites

Klarks    0

Klarks

Klarks    0

  • Stone Miner
  • Klarks
  • Members
  • 0
  • 95 posts
Posted January 17

it stil doest work

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    7695

diesieben07

diesieben07    7695

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7695
  • 56361 posts
Posted January 17

Show what you have tried.

  • Quote

Share this post


Link to post
Share on other sites

Klarks    0

Klarks

Klarks    0

  • Stone Miner
  • Klarks
  • Members
  • 0
  • 95 posts
Posted January 17

i am trying to show my gui by clicking on my entity

public ActionResultType func_230254_b_(PlayerEntity playerEntity, Hand hand) {
    if (!this.world.isRemote) {
       String en = getOwner();
       String pl = playerEntity.getScoreboardName();





     if(en.equals(pl))

     {
         NetworkHooks.openGui((ServerPlayerEntity) playerEntity,new MyModContainer(0,playerEntity.inventory));
     }
     else
         playerEntity.sendMessage(new TranslationTextComponent("You are not  "+en),Util.DUMMY_UUID);

    }

    return ActionResultType.func_233537_a_(this.world.isRemote);
}
  • Quote

Share this post


Link to post
Share on other sites

diesieben07    7695

diesieben07

diesieben07    7695

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7695
  • 56361 posts
Posted January 17
  • Storing the username is a bad idea - you should use UUIDs. Usernames can and will change.
  • openGui requires an INamedContainerProvider. It looks like you made your container implement that, which doesn't make much sense.
  • Quote

Share this post


Link to post
Share on other sites

Klarks    0

Klarks

Klarks    0

  • Stone Miner
  • Klarks
  • Members
  • 0
  • 95 posts
Posted January 17

where i can get uuid. from player entity? Should my entity implement it?

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    7695

diesieben07

diesieben07    7695

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7695
  • 56361 posts
Posted January 17
1 minute ago, Klarks said:

where i can get uuid. from player entity?

Yes, use getUniqueId instead of the name.

  • Quote

Share this post


Link to post
Share on other sites

Klarks    0

Klarks

Klarks    0

  • Stone Miner
  • Klarks
  • Members
  • 0
  • 95 posts
Posted January 17

Is it ok that i am saving a player uuid as a string in datamanager

private static final DataParameter<String> OWNER = EntityDataManager.createKey(MyEntity.class, DataSerializers.STRING);


@OnlyIn(Dist.CLIENT)

public UUID getOwner() {
    return UUID.fromString(this.dataManager.get(OWNER));
}

public void setOwner(UUID name) {
    this.dataManager.set(OWNER ,name.toString());

}
  • Quote

Share this post


Link to post
Share on other sites

Klarks    0

Klarks

Klarks    0

  • Stone Miner
  • Klarks
  • Members
  • 0
  • 95 posts
Posted January 17

So what needs to be implemented? My Entity?

 

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    7695

diesieben07

diesieben07    7695

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7695
  • 56361 posts
Posted January 17

Do not use @OnlyIn.

 

1 hour ago, Klarks said:

So what needs to be implemented? My Entity?

I do not understand this question.

  • Quote

Share this post


Link to post
Share on other sites

Klarks    0

Klarks

Klarks    0

  • Stone Miner
  • Klarks
  • Members
  • 0
  • 95 posts
Posted January 17
7 hours ago, diesieben07 said:
  • openGui requires an INamedContainerProvider. It looks like you made your container implement that, which doesn't make much sense.

What should implement INamedContainerProvider 

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    7695

diesieben07

diesieben07    7695

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7695
  • 56361 posts
Posted January 17
2 hours ago, Klarks said:

What should implement INamedContainerProvider 

Make a new class. An anonymous inner class is usually the most sensible choice here.

  • Quote

Share this post


Link to post
Share on other sites

Klarks    0

Klarks

Klarks    0

  • Stone Miner
  • Klarks
  • Members
  • 0
  • 95 posts
Posted January 17

I dont quite understand what you mean by this. I created a new class. 

 

 

NetworkHooks.openGui((ServerPlayerEntity) playerEntity,new MyModContainer(0,new anonymousInnerClass()
{

},playerEntity.inventory));

 

 



public class anonymousInnerClass implements INamedContainerProvider {

    @Override
    public ITextComponent getDisplayName() {
        return new StringTextComponent("Name");
    }

    @Nullable
    @Override
    public Container createMenu(int id, PlayerInventory playerInventory, PlayerEntity playerEntity) {
        return new MyModContainer(id,playerInventory);
    }
}
  • Quote

Share this post


Link to post
Share on other sites

diesieben07    7695

diesieben07

diesieben07    7695

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7695
  • 56361 posts
Posted January 17

Cool. An anonymous inner class is a Java concept - please learn Java before modding.


What is your issue now?

  • Quote

Share this post


Link to post
Share on other sites

Klarks    0

Klarks

Klarks    0

  • Stone Miner
  • Klarks
  • Members
  • 0
  • 95 posts
Posted January 17

I ve seen an example of it but i dont understand how i can apply this to my problem. Do I need to call createmenu from new class in networkhooks.opengui method? 

  • Quote

Share this post


Link to post
Share on other sites

poopoodice    117

poopoodice

poopoodice    117

  • Dragon Slayer
  • poopoodice
  • Members
  • 117
  • 925 posts
Posted January 17

No, it is looking for a container provider, so just pass an instance of it.

  • Quote

Share this post


Link to post
Share on other sites

Klarks    0

Klarks

Klarks    0

  • Stone Miner
  • Klarks
  • Members
  • 0
  • 95 posts
Posted January 18

is it correct
 

INamedContainerProvider in = new INamedContainerProvider() {
    @Override
    public ITextComponent getDisplayName() {
        return new StringTextComponent("Name");
    }

    @Nullable
    @Override
    public Container createMenu(int id, PlayerInventory playerInventory, PlayerEntity playerEntity) {
        return new MyModContainer(id,playerInventory);
    }
};

         if(en.equals(pl))

         {
             NetworkHooks.openGui((ServerPlayerEntity) playerEntity, in,(Consumer<PacketBuffer>) playerEntity.inventory);
         }
         else
             playerEntity.sendMessage(new TranslationTextComponent("You are not  "+en),Util.DUMMY_UUID);

        }
  • Quote

Share this post


Link to post
Share on other sites

diesieben07    7695

diesieben07

diesieben07    7695

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7695
  • 56361 posts
Posted January 18
57 minutes ago, Klarks said:

(Consumer<PacketBuffer>) playerEntity.inventory

How do you expect this to work at all, ever?

  • Quote

Share this post


Link to post
Share on other sites

Klarks    0

Klarks

Klarks    0

  • Stone Miner
  • Klarks
  • Members
  • 0
  • 95 posts
Posted January 18

With out it java gave an error "Cant resolve method openGui". What i did  wrong here?

1 hour ago, Klarks said:


 


INamedContainerProvider in = new INamedContainerProvider() {
    @Override
    public ITextComponent getDisplayName() {
        return new StringTextComponent("Name");
    }

    @Nullable
    @Override
    public Container createMenu(int id, PlayerInventory playerInventory, PlayerEntity playerEntity) {
        return new MyModContainer(id,playerInventory);
    }
};

         if(en.equals(pl))

         {
             NetworkHooks.openGui((ServerPlayerEntity) playerEntity, in,(Consumer<PacketBuffer>) playerEntity.inventory);
         }
         else
             playerEntity.sendMessage(new TranslationTextComponent("You are not  "+en),Util.DUMMY_UUID);

        }

 

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    7695

diesieben07

diesieben07    7695

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7695
  • 56361 posts
Posted January 18

Look at the parameters of openGui. Then give it the correct objects.

  • Quote

Share this post


Link to post
Share on other sites

Klarks    0

Klarks

Klarks    0

  • Stone Miner
  • Klarks
  • Members
  • 0
  • 95 posts
Posted January 18

Ok i messed up few things, idk where did i get a player inventory parameter in openGui. So thanks it's working now
But how i can correctly get the entity inside the container class to get capabilities to add a slot. I know how to do it with the player i can just get the player from the player inventory but with a mob i am not sure. Should i get the entity from world somehow?
 

  • Quote

Share this post


Link to post
Share on other sites
  • Prev
  • 1
  • 2
  • Next
  • Page 1 of 2  

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 2
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • TheMajorN
      Trying to make a crop have an "X" shape model

      By TheMajorN · Posted 7 minutes ago

      Heya,  So I created a crop and have everything in order with it, however I'm trying to change it from the square shape that it uses, as all crops use, to the X shape that flowers use.  How would I go about doing that? Any point in the right direction would be appreciated
    • Sepiceay
      RLCraft 2.8.2 Keeps crashing with the error code as follows

      By Sepiceay · Posted 29 minutes ago

      Unable to launch java.lang.RuntimeException: java.lang.ArrayIndexOutOfBoundsException: 6 at net.minecraftforge.fml.relauncher.CoreModManager$FMLPluginWrapper.injectIntoClassLoader(CoreModManager.java:169) at net.minecraft.launchwrapper.Launch.launch(Launch.java:115) at net.minecraft.launchwrapper.Launch.main(Launch.java:28) Caused by: java.lang.ArrayIndexOutOfBoundsException: 6 at org.objectweb.asm.ClassReader.readShort(Unknown Source) at org.objectweb.asm.ClassReader.<init>(Unknown Source) at org.objectweb.asm.ClassReader.<init>(Unknown Source) at net.minecraftforge.fml.common.asm.transformers.deobf.FMLDeobfuscatingRemapper.getFieldType(FMLDeobfuscatingRemapper.java:224) at net.minecraftforge.fml.common.asm.transformers.deobf.FMLDeobfuscatingRemapper.parseField(FMLDeobfuscatingRemapper.java:192) at net.minecraftforge.fml.common.asm.transformers.deobf.FMLDeobfuscatingRemapper.setup(FMLDeobfuscatingRemapper.java:161) at net.minecraftforge.fml.common.asm.FMLSanityChecker.injectData(FMLSanityChecker.java:187) at net.minecraftforge.fml.relauncher.CoreModManager$FMLPluginWrapper.injectIntoClassLoader(CoreModManager.java:164) ... 2 more I have restarted my computer and reinstalled the profile multiple times but I keep getting this error on startup. I can provide more lines if needed because all I need to do to replicate the logs is to try and open RLCraft. www
    • samjviana
      [1.16.5] How to make EnchantedBook go to Custom ItemGroup

      By samjviana · Posted 1 hour ago

      I making some custom emchantment, and would like them to show up on an Custom ItemGroup, but i don't know where to start, i tried looking into some classes and did some google about it, but can't find anything usefull.
    • ESCCarp
      Forge says this file does not have an app associated with it.

      By ESCCarp · Posted 1 hour ago

      i do  
    • LexManos
      forge a jar file not exe

      By LexManos · Posted 2 hours ago

      Some zip managers like to take control of the .jar file extension away from Java. Make sure you have Java installed and try running Jarfix once, then try the installer again.   Also, 1.12 is out of support, update.
  • Topics

    • TheMajorN
      0
      Trying to make a crop have an "X" shape model

      By TheMajorN
      Started 7 minutes ago

    • Sepiceay
      0
      RLCraft 2.8.2 Keeps crashing with the error code as follows

      By Sepiceay
      Started 29 minutes ago

    • samjviana
      0
      [1.16.5] How to make EnchantedBook go to Custom ItemGroup

      By samjviana
      Started 1 hour ago

    • ESCCarp
      2
      Forge says this file does not have an app associated with it.

      By ESCCarp
      Started 2 hours ago

    • Modder31
      1
      forge a jar file not exe

      By Modder31
      Started 2 hours ago

  • Who's Online (See full list)

    • TheMajorN
    • Loganator711
    • IDontCaboose
    • DWyvern
    • Chumbanotz
    • foxythesweat
    • redlynx
    • Sepiceay
    • -MCS_Gaming-
    • hammy3502
    • Daeruin
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.16.4] How i can open a container by clicking on my mob
  • Theme

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