Jump to content

[1.19.2] Item container / block briefcase, "how to make an dispenser like menu to pop up from an item ?"


Recommended Posts

Posted

Good days 

Im trying to remake the briefcase item from mi old mod i find and old video 

 

Maletines.gif

I made this armours whit pockets and a interface to interact whit those pockets 

i made this briefcase_item whit 9 slots if you right click whit the item in the hand its open a dispenser like interface from where you can interac and store items in the briefcase_item 
if you right click the floor while crounching the briefcase would become  a block and the items stored would go as nbtdata to the tileentity in the briefcase_block

if you right click the briefcase_block it would disapear returning as the briefcase_item to the player inventory whit all the items inside

all that was minecraft 1.8 before capabilities and that code is long lost 

 

//########## ########## ########## ########## 

now in 1.19.2

coping code from the dispenser and looking to the Kaupenjoe tutorials i manage to make this briefcase_panel and the item but im far from the behaveour of the 1.8 version 

 

whit the help of the Kaupenjoe tutorials i fix the invisible texture problem and the data now is saved to the world soo the stored items persist inside the blockentity after close/open the game 

but but but

###########

In this moment the menu pops when right clicking the block i want the dispenser menu to cameout but from the briefcase_item   but no idea how to call an menu from an item  

i need guidance whit that feature

can you help me with that 

 


mi briefcase_block

  Reveal hidden contents

 

Mi briefcase ghost BlockEntity 

  Reveal hidden contents

 

mi briefcase item is an stuff state a blockitem i dont know maibe this must  be a regular item 

  Reveal hidden contents

 

 

 

Thanks for your time 

 

 

 

 




 

 

 

 

 

 

 

Posted
  On 1/21/2023 at 3:44 AM, perromercenary00 said:

i want the dispenser menu to cameout but from the briefcase_item   but no idea how to call an menu from an item  

Expand  

Opening a menu from an item is pretty much the same way as doing so for a block: call `NetworkHooks#openScreen` and pass in the associated inventory which should be attached as a capability to the stack.

  On 1/21/2023 at 3:44 AM, perromercenary00 said:
		    private NonNullList<ItemStack> items = NonNullList.withSize(9, ItemStack.EMPTY);   
Expand  

You cannot just create the list on the item itself since that would apply globally to all instances of the item in the stack and be incorrectly synced.

Posted

i was looking on more code 

to open a menu  it force me to provide an MenuProvider 

NetworkHooks.openScreen((ServerPlayer) pe, ghost, pos); 

NetworkHooks.openScreen((ServerPlayer) pe, ghost); 

 

i dont understand the capability thing 
dispensers and chest still save the data as nbt tags  also networkhooks only has 2 openscreen methods asking for the player an a MenuProvider Entity 

 

where i can find a tutorial or code i can look at to make mi own code ? 

 

 

 

Posted

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Posted

jumm thanks you and

im currently stuck at this point 

briefcase00-edit.gif

 

i made a custome gui i made an itemstack class whit the "implements MenuProvider" thing pointing to that gui but 


- idont get how to read the inventory from the itemstack soo mi upper slots are just draw in the background but no funtionality 

    i dont find other items inside vainilla minecraft implementhing the capabilityt thing soo i letthing eclipse to fill the gap, no succes here

	
    //this part of here 
    
	//this one created by eclipse
    public RegistryObject<MenuType<menu9>> getCapability(Capability<IItemHandler> itemHandlerCapability) {
        // TODO Auto-generated method stub
        return null;
    }
    
    //this one copied from the    GemInfusingStationBlockEntity example 
    //@Override
    public @NotNull <T> LazyOptional<T> getCapability(@NotNull Capability<T> cap, @Nullable Direction side) {
        if(cap == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
            return lazyItemHandler.cast();
        }
        
        //return super.getCapability(cap, side);
        return lazyItemHandler.cast();
    }
	

 

-also a idont know how or where the gui will return the changes isee the player inventory gets the blocks i change of place

  soo i speculate the gui will return the inventory throught the "this.data = new ContainerData()" and gonna be recived inside the contructor of mi brief_case item class 

 

 

 

the plan here is to directly pass the itemstack to the custome gui

way the inventory gets store inside the brefcase_item as nbt data with no entity/tylenetity in the middle of the operation

 

mercblk.blocks.maletin.briefcase_item;

  Reveal hidden contents

 

 

this is the gui i made coping from kaupenjoe tutorial 

in the second constructor "public menu9(int id, Inventory inv, briefcase_item container_item, ContainerData data)" i need to extract the inventory from the container_item to create the slots but dont get how to make that part works 

mercblk.blocks.maletin.screen.menu9;

 

  Reveal hidden contents

 

the screen thing whit the background image 

  Reveal hidden contents

 

 

MenuInit

  Reveal hidden contents

 

 

Well thanks for your time 

 

 

 

 

 

 

 

 

 

 

 

Posted
  On 1/21/2023 at 2:44 PM, ChampionAsh5357 said:

Opening a menu from an item is pretty much the same way as doing so for a block: call `NetworkHooks#openScreen` and pass in the associated inventory which should be attached as a capability to the stack.

You cannot just create the list on the item itself since that would apply globally to all instances of the item in the stack and be incorrectly synced.

Expand  

ya i notice that but dont find an itemstack using the Capability<IItemHandler> to use as example  also theres the problem of geting the new inventory from the gui in the container datapart

Posted
  On 1/23/2023 at 11:40 AM, perromercenary00 said:

find an itemstack using the Capability<IItemHandler> to use as example

Expand  

I mean...you can use any capability as an example for attaching to an itemstack. First one that comes to mind is the one on BucketItem. Then just swap out with the IItemHandler. If you don't own the item, you just use AttachCapabilitiesEvent.

  On 1/23/2023 at 11:40 AM, perromercenary00 said:

theres the problem of geting the new inventory from the gui in the container datapart

Expand  

SlotItemHandler? Other than that, pretty much nothing changes.

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



×
×
  • Create New...

Important Information

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