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

Spoiler

				
			package mercblk.blocks.maletin;				
			import java.util.ArrayList;
		import java.util.Optional;
		import java.util.function.Predicate;				
			import javax.annotation.Nullable;				
			import mercblk.blockentity.BlockEntityInit;
		import mercblk.blocks.BlockInit;
		import mercblk.entity.EntityInit;
		import mercblk.entity.aligner_entity;
		import mercblk.entity.red_hot_iron_entity;
		import mercblk.util.Postate;
		import mercblk.util.Target;
		import net.minecraft.core.BlockPos;
		import net.minecraft.core.Direction;
		import net.minecraft.core.particles.ParticleTypes;
		import net.minecraft.nbt.CompoundTag;
		import net.minecraft.nbt.ListTag;
		import net.minecraft.server.level.ServerPlayer;
		import net.minecraft.stats.Stats;
		import net.minecraft.tags.FluidTags;
		import net.minecraft.world.InteractionHand;
		import net.minecraft.world.InteractionResult;
		import net.minecraft.world.MenuProvider;
		import net.minecraft.world.entity.Entity;
		import net.minecraft.world.entity.LivingEntity;
		import net.minecraft.world.entity.item.ItemEntity;
		import net.minecraft.world.entity.player.Player;
		import net.minecraft.world.item.ItemStack;
		import net.minecraft.world.item.Items;
		import net.minecraft.world.item.context.BlockPlaceContext;
		import net.minecraft.world.level.BlockGetter;
		import net.minecraft.world.level.Explosion;
		import net.minecraft.world.level.Level;
		import net.minecraft.world.level.LevelAccessor;
		import net.minecraft.world.level.block.BaseEntityBlock;
		import net.minecraft.world.level.block.Block;
		import net.minecraft.world.level.block.Blocks;
		import net.minecraft.world.level.block.EntityBlock;
		import net.minecraft.world.level.block.RenderShape;
		import net.minecraft.world.level.block.SimpleWaterloggedBlock;
		import net.minecraft.world.level.block.entity.BlockEntity;
		import net.minecraft.world.level.block.entity.BlockEntityTicker;
		import net.minecraft.world.level.block.entity.BlockEntityType;
		import net.minecraft.world.level.block.entity.DispenserBlockEntity;
		import net.minecraft.world.level.block.entity.DropperBlockEntity;
		import net.minecraft.world.level.block.state.BlockState;
		import net.minecraft.world.level.block.state.StateDefinition;
		import net.minecraft.world.level.block.state.properties.BlockStateProperties;
		import net.minecraft.world.level.block.state.properties.BooleanProperty;
		import net.minecraft.world.level.block.state.properties.DirectionProperty;
		import net.minecraft.world.level.material.Fluid;
		import net.minecraft.world.level.material.FluidState;
		import net.minecraft.world.level.material.Fluids;
		import net.minecraft.world.level.pathfinder.PathComputationType;
		import net.minecraft.world.phys.AABB;
		import net.minecraft.world.phys.BlockHitResult;
		import net.minecraft.world.phys.Vec3;
		import net.minecraft.world.phys.shapes.CollisionContext;
		import net.minecraft.world.phys.shapes.VoxelShape;
		import net.minecraftforge.network.NetworkHooks;				
			//import net.minecraft.item.Item;				
			//https://youtu.be/jo0BTisGpJk?t=799				
			//########## ########## ########## ##########
		public class briefcase extends BaseEntityBlock implements SimpleWaterloggedBlock { // , EntityBlock				
			    // ########## ########## ########## ##########
		    public static final DirectionProperty FACING = BlockStateProperties.FACING;// .FACING;
		    public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
		    public static final String tipo = "panel";				
			    // six ways waterloggable panel				
			    // ########## ########## ########## ##########
		    // a una unidad
		    protected static final Double thickness = 4.0D;
		    protected static final Double nthicknes = 16.0D - thickness;				
			
		    
		    protected static final VoxelShape NS_AABB = Block.box(2.0D, 0.0D, 6.0D, 14.0D, 8.0D, 10.0D);
		    protected static final VoxelShape EW_AABB = Block.box(6.0D, 0.0D, 2.0D, 10.0D, 8.0D, 14.0D);
		    
		    
		    protected static final VoxelShape NO_AABB = Block.box(0.0D, 0.0D, 0.0D, 0.0D, 0.0D, 0.0D);				
			    // ########## ########## ########## ##########
		    public briefcase(Block.Properties properties) {
		        super(properties);
		        this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.NORTH).setValue(WATERLOGGED,
		                Boolean.valueOf(false)));
		    }				
			    // ########## ########## ########## ##########
		    @Override
		    protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
		        builder.add(FACING, WATERLOGGED);
		    }				
			    // ########## ########## ########## ##########
		    // @Override
		    public String get_tipo() {
		        return tipo;
		    }				
			    // ########## ########## ########## ##########
		    @Override
		    public boolean useShapeForLightOcclusion(BlockState p_220074_1_) {
		        return false;
		    }				
			    // ########## ########## ########## ##########
		    @Override
		    public RenderShape getRenderShape(BlockState blkstate) {
		        return RenderShape.MODEL;
		    }				
			    // ########## ########## ########## ##########
		    // @Override
		    public void onRemove(BlockState blkstate, BlockPos pos, Level warudo, BlockState nblkstate, boolean pismoving) {				
			        if (blkstate.getBlock() == nblkstate.getBlock()) {
		            BlockEntity ghost = warudo.getBlockEntity(pos);
		            if (ghost instanceof briefcase_ghost) {
		                ((briefcase_ghost) ghost).drops();
		            }
		        }
		        super.onRemove(blkstate, warudo, pos, nblkstate, pismoving);
		    }				
			    // ########## ########## ########## ##########
		    public InteractionResult use(BlockState blkstate, Level warudo, BlockPos pos, Player pe, InteractionHand hand,
		            BlockHitResult hit) {
		        if (warudo.isClientSide) {
		            return InteractionResult.SUCCESS;
		        } else {
		            BlockEntity blockentity = warudo.getBlockEntity(pos);				
			            if (blockentity instanceof briefcase_ghost) 
		            {				
			                briefcase_ghost ghost = (briefcase_ghost) blockentity;				
			                // pe.openMenu(ghost);				
			                NetworkHooks.openScreen((ServerPlayer) pe, ghost, pos);				
			                // pe.openMenu((DispenserBlockEntity)blockentity);
		            }				
			            if (blockentity instanceof DropperBlockEntity) {
		                // pe.awardStat(Stats.INSPECT_DROPPER);
		            } else {
		                // pe.awardStat(Stats.INSPECT_DISPENSER);
		            }				
			            // return InteractionResult.CONSUME;
		            return InteractionResult.SUCCESS;
		        }
		    }				
			    // https://www.youtube.com/watch?v=jo0BTisGpJk
		    // 7:35				
			    // ########## ########## ########## ##########
		    @Nullable
		    @Override
		    public BlockEntity newBlockEntity(BlockPos pos_, BlockState blkstate) {
		        return new briefcase_ghost(pos_, blkstate);
		    }				
			    public void setPlacedBy(Level p_52676_, BlockPos p_52677_, BlockState p_52678_, LivingEntity p_52679_,
		            ItemStack p_52680_) {
		        if (p_52680_.hasCustomHoverName()) {
		            BlockEntity blockentity = p_52676_.getBlockEntity(p_52677_);
		            if (blockentity instanceof DispenserBlockEntity) {
		                ((DispenserBlockEntity) blockentity).setCustomName(p_52680_.getHoverName());
		            }
		        }				
			    }				
			    // ########## ########## ########## ##########
		    @Override
		    public boolean triggerEvent(BlockState p_49226_, Level p_49227_, BlockPos p_49228_, int p_49229_, int p_49230_) {
		        super.triggerEvent(p_49226_, p_49227_, p_49228_, p_49229_, p_49230_);
		        BlockEntity blockentity = p_49227_.getBlockEntity(p_49228_);
		        return blockentity == null ? false : blockentity.triggerEvent(p_49229_, p_49230_);
		    }				
			    // ########## ########## ########## ##########
		    @Override
		    @Nullable
		    public MenuProvider getMenuProvider(BlockState p_49234_, Level p_49235_, BlockPos p_49236_) {
		        BlockEntity blockentity = p_49235_.getBlockEntity(p_49236_);
		        return blockentity instanceof MenuProvider ? (MenuProvider) blockentity : null;
		    }				
			    // ########## ########## ########## ##########
		    // aqui es donde se selecciona que bordes va a tener el pblocke basado en el
		    // block state
		    @Override
		    public VoxelShape getShape(BlockState blkstate, BlockGetter blockgetter, BlockPos blockpos,
		            CollisionContext collision) {				
			        // BlockState blkstate = blockgetter.getBlockState(blockpos);
		        Direction direction = blkstate.getValue(FACING);				
			        switch (direction) {
		        default:
		        case EAST:
		        case WEST:
		            return EW_AABB;				
			        case SOUTH:
		        case NORTH:
		            return NS_AABB;				
			        }
		        // return NO_AABB;
		    }				
			    // ########## ########## ########## ##########
		    @Override
		    public boolean canBeReplaced(BlockState p_56373_, BlockPlaceContext p_56374_) {
		        return false;
		    }				
			    // ########## ########## ########## ##########
		    @Override
		    @Nullable
		    public BlockState getStateForPlacement(BlockPlaceContext context) {				
			        BlockPos pos = context.getClickedPos();
		        Postate postate = new Postate(context.getLevel(), context.getClickedPos());
		        postate.setBlockState(this.defaultBlockState());
		        Level warudo = context.getLevel();				
			        Direction facing = null;				
			        if (facing == null) {
		            Target target = new Target(context.getLevel(), context.getPlayer(), 5);
		            facing = target.getFacing_h();
		        }				
			        if (facing == null) {
		            return this.defaultBlockState();
		        }				
			        postate.set_FACING(facing);
		        postate.update_WATERLOGGED();
		        return postate.getBlockState();
		    }				
			    // ########## ########## ########## ##########
		    // @Override
		    public Direction there_is_aligner_entitys_around(Level warudo, BlockPos pos) {
		        Direction direcion = null;				
			        AABB bb = new AABB(pos).inflate(1.0F);				
			        // Vec3 min = new Vec3( bb.minX, bb.minY, bb.minZ);
		        // Vec3 max = new Vec3( bb.maxX, bb.maxY, bb.maxZ);				
			        ArrayList<aligner_entity> list = new ArrayList<aligner_entity>();
		        Predicate<? super Entity> cosa = target -> (target instanceof aligner_entity);//				
			        // warudo.addParticle(ParticleTypes.HEART, min.x, min.y, min.z , 0.0D, 0.0D,
		        // 0.0D);
		        // warudo.addParticle(ParticleTypes.HEART, max.x, max.y, max.z , 0.0D, 0.0D,
		        // 0.0D);				
			        // for (Entity entity1 : warudo.getEntities(null, bb, cosa))
		        for (aligner_entity entity1 : warudo.getEntitiesOfClass(aligner_entity.class, bb)) {
		            // System.out.println("aligner_entity on " + entity1.position() + "=>" +
		            // entity1.get_direccion() );
		            direcion = entity1.get_direccion();
		        }				
			        return direcion;
		    }				
			    // ########## ########## ########## ##########
		    @Override
		    public FluidState getFluidState(BlockState blkstate) {
		        return blkstate.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(blkstate);
		    }				
			    // ########## ########## ########## ##########
		    @Override
		    public boolean canPlaceLiquid(BlockGetter p_56301_, BlockPos p_56302_, BlockState p_56303_, Fluid p_56304_) {
		        return !p_56303_.getValue(BlockStateProperties.WATERLOGGED) && p_56304_ == Fluids.WATER;
		    }				
			    // ########## ########## ########## ##########
		    @Override
		    public boolean placeLiquid(LevelAccessor p_56306_, BlockPos p_56307_, BlockState p_56308_, FluidState p_56309_) {
		        if (!p_56308_.getValue(BlockStateProperties.WATERLOGGED) && p_56309_.getType() == Fluids.WATER) {
		            if (!p_56306_.isClientSide()) {
		                p_56306_.setBlock(p_56307_, p_56308_.setValue(BlockStateProperties.WATERLOGGED, Boolean.valueOf(true)),
		                        3);
		                p_56306_.scheduleTick(p_56307_, p_56309_.getType(), p_56309_.getType().getTickDelay(p_56306_));
		            }				
			            return true;
		        } else {
		            return false;
		        }
		    }				
			    // ########## ########## ########## ##########
		    @Override
		    public ItemStack pickupBlock(LevelAccessor p_154560_, BlockPos p_154561_, BlockState p_154562_) {
		        if (p_154562_.getValue(BlockStateProperties.WATERLOGGED)) {
		            p_154560_.setBlock(p_154561_, p_154562_.setValue(BlockStateProperties.WATERLOGGED, Boolean.valueOf(false)),
		                    3);
		            if (!p_154562_.canSurvive(p_154560_, p_154561_)) {
		                p_154560_.destroyBlock(p_154561_, true);
		            }				
			            return new ItemStack(Items.WATER_BUCKET);
		        } else {
		            return ItemStack.EMPTY;
		        }
		    }				
			    // ########## ########## ########## ##########
		    @Override
		    public boolean isPathfindable(BlockState p_56376_, BlockGetter p_56377_, BlockPos p_56378_,
		            PathComputationType p_56379_) {
		        switch (p_56379_) {
		        case LAND:
		            return false;
		        case WATER:
		            return p_56377_.getFluidState(p_56378_).is(FluidTags.WATER);
		        case AIR:
		            return false;
		        default:
		            return false;
		        }
		    }				
			    // ########## ########## ########## ##########
		    public static int isloaded(ItemStack itemstack) {
		        CompoundTag compoundtag = itemstack.getOrCreateTag();				
			        int i = 0;				
			        if (compoundtag.contains("loaded")) {
		            byte[] biti = compoundtag.getByteArray("loaded");				
			            int b = 1;
		            for (int l = 0; l < biti.length; l++) {				
			                if (biti[l] > 0) {
		                    i += b;
		                }
		                b = b * 2;
		            }				
			        }
		        return i;
		    }				
			    // ########## ########## ########## ##########
		    public static void setloaded(ItemStack itemstack, int value) {
		        CompoundTag compoundtag = itemstack.getOrCreateTag();
		        byte[] biti = new byte[3];				
			        // and binario paa solo dejar el menor byte
		        biti[0] = (byte) ((value & 1));				
			        // and binario paa solo dejar el segundo byte >> correr todos los bites un lugar
		        biti[1] = (byte) ((value & 2) >> 1);				
			        // and binario paa solo dejar el tercer byte >> correr todos los bites dos lugar
		        biti[2] = (byte) ((value & 4) >> 2);				
			        // 0 0 0 0 0
		        // 16 8 4 2 1				
			        compoundtag.putByteArray("loaded", biti);
		        /*
		         * compoundtag.putBoolean("Charged", p_40886_); compoundtag.putByte("A", (byte)
		         * 0); compoundtag.putByte("B", (byte) 0);
		         */
		    }				
			    // ########## ########## ########## ##########
		    @Override
		    public void destroy(LevelAccessor accesor, BlockPos pos, BlockState blkstate) {
		        // System.out.println("\n\nvoid destroy()\\n\\n");
		        Level warudo = (Level) accesor;				
			        Postate briefcase_panel = new Postate(warudo, pos);
		        briefcase_panel.setBlockState(Blocks.AIR.defaultBlockState());				
			        BlockEntity blockentity = warudo.getBlockEntity(pos);
		        ItemStack dropstack = new ItemStack(BlockInit.BRIEFCASE_PANEL.get().asItem(), 1);				
			        if (blockentity instanceof briefcase_ghost) {
		            briefcase_ghost ghost = (briefcase_ghost) blockentity;				
			            ListTag listtag = ghost.read_items();				
			            CompoundTag compoundtag = dropstack.getOrCreateTag();
		            compoundtag.put("Items", listtag);				
			            dropstack.setTag(compoundtag);				
			            ItemEntity pdrop = new ItemEntity(warudo, pos.getX(), pos.getY() + 1, pos.getZ(), dropstack);
		            warudo.addFreshEntity(pdrop);
		        }				
			        briefcase_panel.update_WATERLOGGED();
		        briefcase_panel.setBlock(2);				
			        if (blockentity != null) {
		            blockentity.setRemoved();
		        }
		    }				
			    // ########## ########## ########## ##########
		    @Override
		    public void onBlockExploded(BlockState blkstate, Level warudo, BlockPos pos, Explosion explosion) {
		        // warudo.setBlock(pos, Blocks.AIR.defaultBlockState(), 3);
		        this.wasExploded(warudo, pos, explosion);
		    }				
			    // ########## ########## ########## ##########
		    @Override
		    public void wasExploded(Level warudo, BlockPos pos, Explosion explosion) {
		        // Level warudo = (Level) accesor;				
			        // explosion.
		        destroy(warudo, pos, warudo.getBlockState(pos));				
			    }				
			    // ########## ########## ########## ##########				
			    // ########## ########## ########## ##########
		    // ########## ########## ########## ##########
		    // ########## ########## ########## ##########
		    // ########## ########## ########## ##########				
			}
		 				
			

 

Mi briefcase ghost BlockEntity 

Spoiler

				
			package mercblk.blocks.maletin;				
			import javax.annotation.Nullable;
		import mercblk.blockentity.BlockEntityInit;
		import net.minecraft.core.BlockPos;
		import net.minecraft.core.Direction;
		import net.minecraft.core.NonNullList;
		import net.minecraft.nbt.CompoundTag;
		import net.minecraft.nbt.ListTag;
		import net.minecraft.world.ContainerHelper;
		import net.minecraft.world.Containers;
		import net.minecraft.world.MenuProvider;
		import net.minecraft.world.SimpleContainer;
		import net.minecraft.world.entity.item.ItemEntity;
		import net.minecraft.world.entity.player.Inventory;
		import net.minecraft.world.entity.player.Player;
		import net.minecraft.world.inventory.AbstractContainerMenu;
		import net.minecraft.world.inventory.ContainerData;
		import net.minecraft.world.inventory.DispenserMenu;
		import net.minecraft.world.item.ItemStack;
		import net.minecraft.world.level.Level;
		import net.minecraft.world.level.block.Block;
		import net.minecraft.world.level.block.entity.BlockEntity;
		import net.minecraft.world.level.block.entity.BlockEntityType;
		import net.minecraft.world.level.block.entity.ChestBlockEntity;
		import net.minecraft.world.level.block.entity.DispenserBlockEntity;
		import net.minecraft.world.level.block.entity.RandomizableContainerBlockEntity;
		import net.minecraft.world.level.block.state.BlockState;
		import net.minecraft.world.level.block.state.properties.BlockStateProperties;
		import net.minecraft.world.level.block.state.properties.BooleanProperty;
		import net.minecraft.world.level.block.state.properties.DirectionProperty;
		import net.minecraft.world.phys.shapes.VoxelShape;
		import net.minecraftforge.common.capabilities.Capability;
		import net.minecraftforge.common.util.LazyOptional;
		import net.minecraftforge.items.CapabilityItemHandler;
		import net.minecraftforge.items.ItemStackHandler;				
			import net.minecraft.network.chat.Component;
		import org.jetbrains.annotations.NotNull;				
			//########## ########## ########## ##########
		public class briefcase_ghost extends DispenserBlockEntity implements MenuProvider { // BlockEntity				
			    // ########## ########## ########## ##########
		    public static final int CONTAINER_SIZE = 9;
		    private NonNullList<ItemStack> items = NonNullList.withSize(9, ItemStack.EMPTY);				
			    // ########## ########## ########## ##########				
			    private BlockState blockState;
		    private final BlockPos worldPosition;				
			    // ########## ########## ########## ##########				
			    public briefcase_ghost(BlockPos pos, BlockState blkstate) {
		        super(BlockEntityInit.BRIEFCASE_GHOST.get(), pos, blkstate);				
			        // this.type = ghost;
		        this.worldPosition = pos.immutable();
		        this.blockState = blkstate;
		        this.gatherCapabilities();
		    }				
			    // ########## ########## ########## ##########				
			    @Override
		    public Component getDisplayName() {
		        return Component.literal("BriefCase ghost");
		    }				
			    // ########## ########## ########## ##########
		    @Override
		    public void load(CompoundTag p_155496_) {
		        super.load(p_155496_);
		        this.items = NonNullList.withSize(this.getContainerSize(), ItemStack.EMPTY);
		        if (!this.tryLoadLootTable(p_155496_)) {
		            ContainerHelper.loadAllItems(p_155496_, this.items);
		        }				
			    }				
			    // ########## ########## ########## ##########
		    @Override
		    protected void saveAdditional(CompoundTag p_187498_) {
		        super.saveAdditional(p_187498_);
		        if (!this.trySaveLootTable(p_187498_)) {
		            ContainerHelper.saveAllItems(p_187498_, this.items);
		        }
		    }				
			    // ########## ########## ########## ##########
		    // @Override
		    public ListTag read_items() {
		        ListTag listtag = new ListTag();				
			        for (int i = 0; i < this.items.size(); ++i) {
		            ItemStack itemstack = this.items.get(i);
		            if (!itemstack.isEmpty()) {
		                CompoundTag compoundtag = new CompoundTag();
		                compoundtag.putByte("Slot", (byte) i);
		                itemstack.save(compoundtag);
		                listtag.add(compoundtag);
		            }
		        }
		        // tags.put("Items", listtag);				
			        return listtag;
		    }				
			    // ########## ########## ########## ##########
		    // @Override
		    public void write_items(ListTag listtag) {
		        // ListTag listtag = p_18981_.getList("Items", 10);				
			        for (int i = 0; i < listtag.size(); ++i) {
		            CompoundTag compoundtag = listtag.getCompound(i);
		            int j = compoundtag.getByte("Slot") & 255;
		            if (j >= 0 && j < this.items.size()) {
		                this.items.set(j, ItemStack.of(compoundtag));
		            }
		        }
		    }				
			    // ########## ########## ########## ##########
		    @Override
		    public NonNullList<ItemStack> getItems() {
		        return this.items;
		    }				
			    // ########## ########## ########## ##########
		    @Override
		    public void setItems(NonNullList<ItemStack> p_59243_) {
		        this.items = p_59243_;
		    }				
			    // ########## ########## ########## ##########
		    @Override
		    protected AbstractContainerMenu createMenu(int p_59235_, Inventory p_59236_) {
		        return new DispenserMenu(p_59235_, p_59236_, this);
		    }				
			    // ########## ########## ########## ##########				
			    public void drops() {
		        ItemEntity pdrop;
		        for (int i = 0; i < this.items.size(); i++) {
		            // this.items.get(i);
		            pdrop = new ItemEntity(this.level, this.worldPosition.getX() + 0.5F, this.worldPosition.getY() + 1.0F,
		                    this.worldPosition.getZ() + 0.5F, this.items.get(i));
		            this.level.addFreshEntity(pdrop);
		        }
		    }				
			    // ########## ########## ########## ##########				
			    // ########## ########## ########## ##########
		    // ########## ########## ########## ##########
		    // ########## ########## ########## ##########
		    // ########## ########## ########## ##########				
			}
		 				
			 				
			

 

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

Spoiler

				
			package mercblk.blocks.maletin;				
			import net.minecraft.core.NonNullList;
		import net.minecraft.network.chat.Component;
		import net.minecraft.server.level.ServerPlayer;
		import net.minecraft.world.Container;
		import net.minecraft.world.InteractionHand;
		import net.minecraft.world.InteractionResult;
		import net.minecraft.world.InteractionResultHolder;
		import net.minecraft.world.MenuProvider;
		import net.minecraft.world.entity.player.Inventory;
		import net.minecraft.world.entity.player.Player;
		import net.minecraft.world.inventory.AbstractContainerMenu;
		import net.minecraft.world.inventory.DispenserMenu;
		import net.minecraft.world.inventory.MenuType;
		import net.minecraft.world.inventory.Slot;
		import net.minecraft.world.item.BlockItem;
		import net.minecraft.world.item.Item;
		import net.minecraft.world.item.ItemStack;
		import net.minecraft.world.item.context.BlockPlaceContext;
		import net.minecraft.world.item.context.UseOnContext;
		import net.minecraft.world.level.Level;
		import net.minecraft.world.level.block.Block;
		import net.minecraftforge.network.NetworkHooks;				
			public class blockitem_briefcase extends BlockItem  {
		   private static final String BLOCK_ENTITY_TAG = "BlockEntityTag";
		   public static final String BLOCK_STATE_TAG = "BlockStateTag";
		   /** @deprecated */
		   @Deprecated
		   private final Block block;
		   
		    // ########## ########## ########## ##########
		    public static final int CONTAINER_SIZE = 9;
		    private NonNullList<ItemStack> items = NonNullList.withSize(9, ItemStack.EMPTY);   
		   
		    // ########## ########## ########## ##########
		   public blockitem_briefcase(Block p_40565_, Item.Properties p_40566_) {
		      super(p_40565_, p_40566_);
		      this.block = p_40565_;
		   }
		   
		    // ########## ########## ########## ##########
		    @Override
		   public InteractionResult useOn(UseOnContext p_40581_) {
		      InteractionResult interactionresult = this.place(new BlockPlaceContext(p_40581_));
		      
		      
		      if (!interactionresult.consumesAction() && this.isEdible()) {
		         InteractionResult interactionresult1 = this.use(p_40581_.getLevel(), p_40581_.getPlayer(), p_40581_.getHand()).getResult();
		         return interactionresult1 == InteractionResult.CONSUME ? InteractionResult.CONSUME_PARTIAL : interactionresult1;
		      } else {
		         return interactionresult;
		      }
		   }				
			    // ########## ########## ########## ##########
		    @Override
		   public InteractionResultHolder<ItemStack> use(Level warudo, Player pe, InteractionHand hand) {
		        
		        
		        /*
		          ItemStack itemstack = pe.getItemInHand(hand);
		          if (itemstack.isEdible()) {
		             if (pe.canEat(itemstack.getFoodProperties(pe).canAlwaysEat())) {
		                pe.startUsingItem(hand);
		                return InteractionResultHolder.consume(itemstack);
		             } else {
		                return InteractionResultHolder.fail(itemstack);
		             }
		          } else {
		             return InteractionResultHolder.pass(pe.getItemInHand(hand));
		          }
		          
		          */
		        
		        if(!warudo.isClientSide) {
		            
		            //briefcase_ghost ghost = new briefcase_ghost(); //(briefcase_ghost) blockentity;				
			            // pe.openMenu(ghost);				
			            //NetworkHooks.openScreen((ServerPlayer) pe, ghost, pos);
		            
		            
		        }
		          
		          
		        return InteractionResultHolder.pass(pe.getItemInHand(hand));
		       }   				
			    				
			}				
			 				
			

 

 

 

Thanks for your time 

 

 

 

 




 

 

 

 

 

 

 

Posted
10 hours ago, 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  

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.

10 hours ago, perromercenary00 said:
		    private NonNullList<ItemStack> items = NonNullList.withSize(9, ItemStack.EMPTY);   

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;

Spoiler

 				
			package mercblk.blocks.maletin;				
			import java.util.ArrayList;
		import java.util.UUID;
		import java.util.function.Predicate;				
			import org.jetbrains.annotations.NotNull;
		import org.jetbrains.annotations.Nullable;				
			import mercblk.blocks.BlockInit;
		import mercblk.blocks.maletin.screen.menu9;
		import mercblk.entity.EntityInit;
		import mercblk.entity.toilet_entity;
		import mercblk.item.ItemInit;
		import mercblk.sound.SoundInit;
		import mercblk.util.Postate;
		import mercblk.util.Target;
		import net.minecraft.core.BlockPos;
		import net.minecraft.core.Direction;
		import net.minecraft.core.NonNullList;
		import net.minecraft.core.particles.ParticleTypes;
		import net.minecraft.nbt.CompoundTag;
		import net.minecraft.nbt.ListTag;
		import net.minecraft.network.chat.Component;
		import net.minecraft.server.level.ServerPlayer;
		import net.minecraft.sounds.SoundEvents;
		import net.minecraft.world.InteractionHand;
		import net.minecraft.world.InteractionResultHolder;
		import net.minecraft.world.MenuProvider;
		import net.minecraft.world.entity.Entity;
		import net.minecraft.world.entity.LivingEntity;
		import net.minecraft.world.entity.item.ItemEntity;
		import net.minecraft.world.entity.player.Inventory;
		import net.minecraft.world.entity.player.Player;
		import net.minecraft.world.inventory.AbstractContainerMenu;
		import net.minecraft.world.inventory.ContainerData;
		import net.minecraft.world.inventory.MenuType;
		import net.minecraft.world.item.Item;
		import net.minecraft.world.item.ItemStack;
		import net.minecraft.world.item.Items;
		import net.minecraft.world.level.Level;
		import net.minecraft.world.level.block.AbstractCauldronBlock;
		import net.minecraft.world.level.block.Blocks;
		import net.minecraft.world.level.block.entity.BlockEntity;
		import net.minecraft.world.level.block.state.properties.BlockStateProperties;
		import net.minecraft.world.level.block.state.properties.DirectionProperty;
		import net.minecraft.world.level.material.Material;
		import net.minecraft.world.phys.AABB;
		import net.minecraft.world.phys.Vec3;
		import net.minecraftforge.common.capabilities.Capability;
		import net.minecraftforge.common.util.LazyOptional;
		import net.minecraftforge.items.CapabilityItemHandler;
		import net.minecraftforge.items.IItemHandler;
		import net.minecraftforge.items.ItemStackHandler;
		import net.minecraftforge.network.NetworkHooks;
		import net.minecraftforge.registries.RegistryObject;				
			public class briefcase_item extends Item implements MenuProvider { // MenuProvider 
		    protected final ContainerData data;
		    private int progress = 0;
		    private int maxProgress = 78;
		    
		    private LazyOptional<IItemHandler> lazyItemHandler = LazyOptional.empty();
		    
		    private final ItemStackHandler itemHandler = new ItemStackHandler(9) {
		        @Override
		        protected void onContentsChanged(int slot) {
		            setChanged();
		        }
		    };				
			
		    // ########## ########## ########## ##########
		    public briefcase_item(Properties propiedad) {
		        super(propiedad);
		        
		        this.data = new ContainerData() {
		            @Override
		            public int get(int index) {
		                return switch (index) {
		                    case 0 -> briefcase_item.this.progress;
		                    case 1 -> briefcase_item.this.maxProgress;
		                    default -> 0;
		                };
		            }				
			            @Override
		            public void set(int index, int value) {
		                switch (index) {
		                    case 0 -> briefcase_item.this.progress = value;
		                    case 1 -> briefcase_item.this.maxProgress = value;
		                }
		            }				
			            @Override
		            public int getCount() {
		                return 2;
		            }
		        };        
		        
		    }				
			    protected void setChanged() {
		        // TODO Auto-generated method stub
		        
		    }				
			    // ########## ########## ########## ##########
		    public int getContainerSize() {
		        return 9;
		    }				
			    // ########## ########## ########## ##########
		    @Override
		    public InteractionResultHolder<ItemStack> use(Level warudo, Player pe, InteractionHand hand) {
		        System.out.println("use()");				
			        Target target = new Target(warudo, pe, 10);
		        Postate postate = target.get_relative_postate();
		        BlockPos pos = null;
		        ItemStack itemstack = pe.getItemInHand(hand);				
			        if (!warudo.isClientSide) {
		            pos = new BlockPos(135, 64, -19);// read_pos(itemstack);				
			            NetworkHooks.openScreen((ServerPlayer) pe, this );
		            
		            // container_ghost ghost = this.get_ghost(warudo, itemstack, pe);
		            // NetworkHooks.openScreen((ServerPlayer) pe, (this)itemstack );				
			            // pe.openMenu(ghost);
		            // NetworkHooks.openScreen((ServerPlayer) pe, ghost, pos);
		        }				
			        return InteractionResultHolder.pass(pe.getItemInHand(hand));
		    }				
			    // ########## ########## ########## ##########
		    // @Override
		    public NonNullList<ItemStack> read_items_from(ItemStack itemstack) {				
			        NonNullList<ItemStack> contained_items = NonNullList.withSize(this.getContainerSize(), ItemStack.EMPTY);				
			        if (itemstack.hasTag()) {
		            CompoundTag compoundtag = itemstack.getTag();
		            ListTag listtag = null;
		            int size = 0;				
			            if (compoundtag.contains("Items")) {
		                // ListTag listtag = new ListTag();
		                listtag = compoundtag.getList("Items", 10);
		                size = listtag.size();
		                // contained_items = NonNullList.withSize(size, ItemStack.EMPTY);				
			                for (int i = 0; i < listtag.size(); ++i) {
		                    CompoundTag itemstacktag = listtag.getCompound(i);
		                    int j = compoundtag.getByte("Slot") & 255;
		                    if (j >= 0 && j < contained_items.size()) {
		                        contained_items.set(j, ItemStack.of(itemstacktag));
		                    }
		                }
		            }
		        }
		        return contained_items;
		    }				
			    // ########## ########## ########## ##########
		    // @Override
		    public void write_items_to(ItemStack itemstack, NonNullList<ItemStack> contained_items) {				
			        CompoundTag compoundtag = null;				
			        if (itemstack.hasTag()) {
		            compoundtag = itemstack.getTag();
		        } else {
		            compoundtag = new CompoundTag();
		        }				
			        ListTag listtag = new ListTag();
		        int size = contained_items.size();				
			        for (int i = 0; i < size; ++i) {				
			            ItemStack itemslot = contained_items.get(i);
		            if (!itemslot.isEmpty()) {
		                CompoundTag itemcompound = new CompoundTag();
		                itemcompound.putByte("Slot", (byte) i);
		                itemslot.save(itemcompound);
		                listtag.add(itemcompound);
		            }
		        }
		        compoundtag.put("Items", listtag);
		        itemstack.setTag(compoundtag);
		    }				
			    // ########## ########## ########## ##########
		    @Override
		    public boolean onEntitySwing(ItemStack stack, LivingEntity le) {				
			        Level warudo = le.level;
		        System.out.println("onEntitySwing(" + warudo.isClientSide + ")");				
			        NonNullList<ItemStack> lista = this.read_items_from(stack);				
			        // if( lista == null || lista.size() < 1)
		        {
		            // lista = NonNullList.withSize(9, ItemStack.EMPTY);				
			            // lista.set(5, new ItemStack( Items.CARROT , 3 ) );				
			            // this.write_items_to(stack, lista);
		        }				
			        print(lista);				
			        return true;
		    }				
			    // ########## ########## ########## ##########
		    // @Override
		    public void print(NonNullList<ItemStack> lista) {				
			        int count = 0;
		        for (ItemStack cosa : lista) {
		            System.out
		                    .println("[" + count + "] => " + cosa.getItem().getName(cosa).getString() + ", " + cosa.getCount());
		            count++;
		        }				
			    }				
			    
		    @Nullable
		    @Override
		    public AbstractContainerMenu createMenu(int id, Inventory inventory, Player player) {
		        return new menu9(id, inventory, this, this.data);
		    }				
			
		    @Override
		    public Component getDisplayName() {
		        return Component.literal("BriefCase");
		    }				
			    
		    
		    
		    
		    
		    
		    //this part of here 
		    
		    public RegistryObject<MenuType<menu9>> getCapability(Capability<IItemHandler> itemHandlerCapability) {
		        // TODO Auto-generated method stub
		        return null;
		    }
		    
		    
		    
		    //@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();
		    }
		    
		    
		    
		    				
			    //@Override
		    public void onLoad() {
		        //super.onLoad();
		        lazyItemHandler = LazyOptional.of(() -> itemHandler);
		    }				
			    //@Override
		    public void invalidateCaps() {
		        //super.invalidateCaps();
		        lazyItemHandler.invalidate();
		    }				
			    //@Override
		    protected void saveAdditional(CompoundTag nbt) {
		        nbt.put("inventory", itemHandler.serializeNBT());
		        nbt.putInt("gem_infusing_station.progress", this.progress);				
			        //super.saveAdditional(nbt);
		    }				
			    //@Override
		    public void load(CompoundTag nbt) {
		        //super.load(nbt);
		        itemHandler.deserializeNBT(nbt.getCompound("inventory"));
		        progress = nbt.getInt("gem_infusing_station.progress");
		    }				
			
		    
		    
		    
		    
		    
		    
		    
		    
		    
		    // ########## ########## ########## ##########				
			    // ########## ########## ########## ##########
		    // ########## ########## ########## ##########				
			    // ########## ########## ########## ##########
		    // ########## ########## ########## ##########
		    // ########## ########## ########## ##########
		}
		 				
			

 

 

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;

 

Spoiler

				
			package mercblk.blocks.maletin.screen;				
			
		import mercblk.blocks.maletin.briefcase_item;
		import net.minecraft.core.NonNullList;
		import net.minecraft.nbt.CompoundTag;
		import net.minecraft.nbt.ListTag;
		import net.minecraft.network.FriendlyByteBuf;
		import net.minecraft.world.entity.player.Inventory;
		import net.minecraft.world.entity.player.Player;
		import net.minecraft.world.inventory.*;
		import net.minecraft.world.item.ItemStack;
		import net.minecraft.world.level.Level;
		import net.minecraft.world.level.block.entity.BlockEntity;
		import net.minecraftforge.items.CapabilityItemHandler;
		import net.minecraftforge.items.SlotItemHandler;				
			public class menu9 extends AbstractContainerMenu {
		    public static briefcase_item container_item = null;
		    private final Level level;
		    private final ContainerData data;				
			    
		    public menu9(int id, Inventory inv, FriendlyByteBuf extraData) {
		        this(id, inv, container_item, new SimpleContainerData(9)); 
		    }
		    				
			    public menu9(int id, Inventory inv, briefcase_item container_item, ContainerData data) {
		        super(MenuInit.MENU9.get(), id);
		        checkContainerSize(inv, 9);
		        this.container_item = container_item;
		        this.level = inv.player.level;
		        this.data = data;				
			        addPlayerInventory(inv);
		        addPlayerHotbar(inv);				
			        
		        //NonNullList<ItemStack> lista = read_items_from(container_item);
		              
		        /*
		  
		        this.container_item.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).ifPresent(handler -> {
		            //this.addSlot(new SlotItemHandler(handler, 0, 12, 15));
		            //this.addSlot(new SlotItemHandler(handler, 1, 86, 15));
		            //this.addSlot(new SlotItemHandler(handler, 2, 86, 60));
		        
		         //this cames from the dispenser 9 gui        
		        for(int i = 0; i < 3; ++i) {
		            for(int j = 0; j < 3; ++j) {
		               this.addSlot(new SlotItemHandler(handler, j + i * 3, 62 + j * 18, 17 + i * 18));
		            }
		         }				
			         for(int k = 0; k < 3; ++k) {
		            for(int i1 = 0; i1 < 9; ++i1) {
		               this.addSlot(new SlotItemHandler(handler, i1 + k * 9 + 9, 8 + i1 * 18, 84 + k * 18));
		            }
		         }				
			         for(int l = 0; l < 9; ++l) {
		            this.addSlot(new SlotItemHandler(handler, l, 8 + l * 18, 142));
		         }
		        
		        });
		        */				
			        addDataSlots(data);
		    }				
			    public boolean isCrafting() {
		        return data.get(0) > 0;
		    }				
			    public int getScaledProgress() {
		        int progress = this.data.get(0);
		        int maxProgress = this.data.get(1);  // Max Progress
		        int progressArrowSize = 26; // This is the height in pixels of your arrow				
			        return maxProgress != 0 && progress != 0 ? progress * progressArrowSize / maxProgress : 0;
		    }				
			    // CREDIT GOES TO: diesieben07 | https://github.com/diesieben07/SevenCommons
		    // must assign a slot number to each of the slots used by the GUI.
		    // For this container, we can see both the tile inventory's slots as well as the player inventory slots and the hotbar.
		    // Each time we add a Slot to the container, it automatically increases the slotIndex, which means
		    //  0 - 8 = hotbar slots (which will map to the InventoryPlayer slot numbers 0 - 
		    //  9 - 35 = player inventory slots (which map to the InventoryPlayer slot numbers 9 - 35)
		    //  36 - 44 = TileInventory slots, which map to our TileEntity slot numbers 0 - 
		    private static final int HOTBAR_SLOT_COUNT = 9;
		    private static final int PLAYER_INVENTORY_ROW_COUNT = 3;
		    private static final int PLAYER_INVENTORY_COLUMN_COUNT = 9;
		    private static final int PLAYER_INVENTORY_SLOT_COUNT = PLAYER_INVENTORY_COLUMN_COUNT * PLAYER_INVENTORY_ROW_COUNT;
		    private static final int VANILLA_SLOT_COUNT = HOTBAR_SLOT_COUNT + PLAYER_INVENTORY_SLOT_COUNT;
		    private static final int VANILLA_FIRST_SLOT_INDEX = 0;
		    private static final int TE_INVENTORY_FIRST_SLOT_INDEX = VANILLA_FIRST_SLOT_INDEX + VANILLA_SLOT_COUNT;				
			    // THIS YOU HAVE TO DEFINE!
		    private static final int TE_INVENTORY_SLOT_COUNT = 9;  // must be the number of slots you have!				
			    @Override
		    public boolean stillValid(Player player) {
		        return true;
		    }				
			    private void addPlayerInventory(Inventory playerInventory) {
		        for (int i = 0; i < 3; ++i) {
		            for (int l = 0; l < 9; ++l) {
		                this.addSlot(new Slot(playerInventory, l + i * 9 + 9, 8 + l * 18, 86 + i * 18));
		            }
		        }
		    }				
			    private void addPlayerHotbar(Inventory playerInventory) {
		        for (int i = 0; i < 9; ++i) {
		            this.addSlot(new Slot(playerInventory, i, 8 + i * 18, 144));
		        }
		    }
		    
		//what this does 
		    @Override
		    public ItemStack quickMoveStack(Player p_38941_, int p_38942_) {
		        // TODO Auto-generated method stub
		        return null;
		    }    
		    				
			
		}
		 				
			

 

the screen thing whit the background image 

Spoiler

				
			package mercblk.blocks.maletin.screen;				
			import com.mojang.blaze3d.systems.RenderSystem;
		import com.mojang.blaze3d.vertex.PoseStack;
		import mercblk.mercblk;
		import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
		import net.minecraft.client.renderer.GameRenderer;
		import net.minecraft.network.chat.Component;
		import net.minecraft.resources.ResourceLocation;
		import net.minecraft.world.entity.player.Inventory;				
			public class screen extends AbstractContainerScreen<menu9> {
		    private static final ResourceLocation TEXTURE =
		            new ResourceLocation(mercblk.MOD_ID,"textures/gui/gem_infusing_station_gui.png");				
			    public screen(menu9 menu, Inventory inventory, Component component) {
		        super(menu, inventory, component);
		    }				
			    @Override
		    protected void init() {
		        super.init();
		    }				
			    @Override
		    protected void renderBg(PoseStack pPoseStack, float pPartialTick, int pMouseX, int pMouseY) {
		        RenderSystem.setShader(GameRenderer::getPositionTexShader);
		        RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
		        RenderSystem.setShaderTexture(0, TEXTURE);
		        int x = (width - imageWidth) / 2;
		        int y = (height - imageHeight) / 2;				
			        this.blit(pPoseStack, x, y, 0, 0, imageWidth, imageHeight);				
			        renderProgressArrow(pPoseStack, x, y);
		    }				
			    private void renderProgressArrow(PoseStack pPoseStack, int x, int y) {
		        if(menu.isCrafting()) {
		            blit(pPoseStack, x + 105, y + 33, 176, 0, 8, menu.getScaledProgress());
		        }
		    }				
			    @Override
		    public void render(PoseStack pPoseStack, int mouseX, int mouseY, float delta) {
		        renderBackground(pPoseStack);
		        super.render(pPoseStack, mouseX, mouseY, delta);
		        renderTooltip(pPoseStack, mouseX, mouseY);
		    }
		}
		 				
			

 

 

MenuInit

Spoiler

				
			package mercblk.blocks.maletin.screen;				
			import mercblk.mercblk;
		import net.minecraft.world.inventory.AbstractContainerMenu;
		import net.minecraft.world.inventory.MenuType;
		import net.minecraftforge.common.extensions.IForgeMenuType;
		import net.minecraftforge.eventbus.api.IEventBus;
		import net.minecraftforge.network.IContainerFactory;
		import net.minecraftforge.registries.DeferredRegister;
		import net.minecraftforge.registries.ForgeRegistries;
		import net.minecraftforge.registries.RegistryObject;				
			public class MenuInit {
		    public static final DeferredRegister<MenuType<?>> MENUS = DeferredRegister.create(ForgeRegistries.MENU_TYPES,
		            mercblk.MOD_ID);				
			    public static final RegistryObject<MenuType<menu9>> MENU9 = registerMenuType(menu9::new, "menu9");				
			    private static <T extends AbstractContainerMenu> RegistryObject<MenuType<T>> registerMenuType(
		            IContainerFactory<T> factory, String name) {
		        return MENUS.register(name, () -> IForgeMenuType.create(factory));
		    }				
			    public static void register(IEventBus eventBus) {
		        MENUS.register(eventBus);
		    }
		}				
			

 

 

Well thanks for your time 

 

 

 

 

 

 

 

 

 

 

 

Posted
On 1/21/2023 at 9:44 AM, 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.

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
2 hours ago, perromercenary00 said:

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

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.

2 hours ago, perromercenary00 said:

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

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.