Jump to content

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


perromercenary00

Recommended Posts

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 

 

 

 

 




 

 

 

 

 

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 ? 

 

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 

 

 

 

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

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

    • Hello. I've been having a problem when launching minecraft forge. It just doesn't open the game, and leaves me with this "(exit code 1)" error. Both regular and optifine versions of minecraft launch just fine, tried both with 1.18.2 and 1.20.1. I can assure that my drivers are updated so that can't be it, and i've tried using Java 17, 18 and 21 to no avail. Even with no mods installed, the thing won't launch. I'll leave the log here, although it's in spanish: https://jmp.sh/s/FPqGBSi30fzKJDt2M1gc My specs are this: Ryzen 3 4100 || Radeon R9 280x || 16gb ram || Windows 10 I'd appreciate any help, thank you in advance.
    • Hey, Me and my friends decided to start up a Server with "a few" mods, the last few days everything went well we used all the items we wanted. Now our Game crashes the moment we touch a Lava Bucket inside our Inventory. It just instantly closes and gives me an "Alc Cleanup"  Crash screen (Using GDLauncher). I honestly dont have a clue how to resolve this error. If anyone could help id really appreciate it, I speak German and Englisch so you can choose whatever you speak more fluently. Thanks in Advance. Plus I dont know how to link my Crash Report help for that would be nice too whoops
    • I hosted a minecraft server and I modded it, and there is always an error on the console which closes the server. If someone knows how to repair it, it would be amazing. Thank you. I paste the crash report down here: ---- Minecraft Crash Report ---- WARNING: coremods are present:   llibrary (llibrary-core-1.0.11-1.12.2.jar)   WolfArmorCore (WolfArmorAndStorage-1.12.2-3.8.0-universal-signed.jar)   AstralCore (astralsorcery-1.12.2-1.10.27.jar)   CreativePatchingLoader (CreativeCore_v1.10.71_mc1.12.2.jar)   SecurityCraftLoadingPlugin ([1.12.2] SecurityCraft v1.9.8.jar)   ForgelinPlugin (Forgelin-1.8.4.jar)   midnight (themidnight-0.3.5.jar)   FutureMC (Future-MC-0.2.19.jar)   SpartanWeaponry-MixinLoader (SpartanWeaponry-1.12.2-1.5.3.jar)   Backpacked (backpacked-1.4.3-1.12.2.jar)   LoadingPlugin (Reskillable-1.12.2-1.13.0.jar)   LoadingPlugin (Bloodmoon-MC1.12.2-1.5.3.jar) Contact their authors BEFORE contacting forge // There are four lights! Time: 3/28/24 12:17 PM Description: Exception in server tick loop net.minecraftforge.fml.common.LoaderException: java.lang.NoClassDefFoundError: net/minecraft/client/multiplayer/WorldClient     at net.minecraftforge.fml.common.AutomaticEventSubscriber.inject(AutomaticEventSubscriber.java:89)     at net.minecraftforge.fml.common.FMLModContainer.constructMod(FMLModContainer.java:612)     at sun.reflect.GeneratedMethodAccessor10.invoke(Unknown Source)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     at java.lang.reflect.Method.invoke(Method.java:498)     at com.google.common.eventbus.Subscriber.invokeSubscriberMethod(Subscriber.java:91)     at com.google.common.eventbus.Subscriber$SynchronizedSubscriber.invokeSubscriberMethod(Subscriber.java:150)     at com.google.common.eventbus.Subscriber$1.run(Subscriber.java:76)     at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:399)     at com.google.common.eventbus.Subscriber.dispatchEvent(Subscriber.java:71)     at com.google.common.eventbus.Dispatcher$PerThreadQueuedDispatcher.dispatch(Dispatcher.java:116)     at com.google.common.eventbus.EventBus.post(EventBus.java:217)     at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:219)     at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:197)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     at java.lang.reflect.Method.invoke(Method.java:498)     at com.google.common.eventbus.Subscriber.invokeSubscriberMethod(Subscriber.java:91)     at com.google.common.eventbus.Subscriber$SynchronizedSubscriber.invokeSubscriberMethod(Subscriber.java:150)     at com.google.common.eventbus.Subscriber$1.run(Subscriber.java:76)     at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:399)     at com.google.common.eventbus.Subscriber.dispatchEvent(Subscriber.java:71)     at com.google.common.eventbus.Dispatcher$PerThreadQueuedDispatcher.dispatch(Dispatcher.java:116)     at com.google.common.eventbus.EventBus.post(EventBus.java:217)     at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:136)     at net.minecraftforge.fml.common.Loader.loadMods(Loader.java:595)     at net.minecraftforge.fml.server.FMLServerHandler.beginServerLoading(FMLServerHandler.java:98)     at net.minecraftforge.fml.common.FMLCommonHandler.onServerStart(FMLCommonHandler.java:333)     at net.minecraft.server.dedicated.DedicatedServer.func_71197_b(DedicatedServer.java:125)     at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:486)     at java.lang.Thread.run(Thread.java:750) Caused by: java.lang.NoClassDefFoundError: net/minecraft/client/multiplayer/WorldClient     at java.lang.Class.getDeclaredMethods0(Native Method)     at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)     at java.lang.Class.privateGetPublicMethods(Class.java:2902)     at java.lang.Class.getMethods(Class.java:1615)     at net.minecraftforge.fml.common.eventhandler.EventBus.register(EventBus.java:82)     at net.minecraftforge.fml.common.AutomaticEventSubscriber.inject(AutomaticEventSubscriber.java:82)     ... 31 more Caused by: java.lang.ClassNotFoundException: net.minecraft.client.multiplayer.WorldClient     at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:191)     at java.lang.ClassLoader.loadClass(ClassLoader.java:418)     at java.lang.ClassLoader.loadClass(ClassLoader.java:351)     ... 37 more Caused by: net.minecraftforge.fml.common.asm.ASMTransformerWrapper$TransformerException: Exception in class transformer net.minecraftforge.fml.common.asm.transformers.SideTransformer@4e558728 from coremod FMLCorePlugin     at net.minecraftforge.fml.common.asm.ASMTransformerWrapper$TransformerWrapper.transform(ASMTransformerWrapper.java:260)     at net.minecraft.launchwrapper.LaunchClassLoader.runTransformers(LaunchClassLoader.java:279)     at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:176)     ... 39 more Caused by: java.lang.RuntimeException: Attempted to load class bsb for invalid side SERVER     at net.minecraftforge.fml.common.asm.transformers.SideTransformer.transform(SideTransformer.java:62)     at net.minecraftforge.fml.common.asm.ASMTransformerWrapper$TransformerWrapper.transform(ASMTransformerWrapper.java:256)     ... 41 more A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- System Details -- Details:     Minecraft Version: 1.12.2     Operating System: Linux (amd64) version 5.10.0-28-cloud-amd64     Java Version: 1.8.0_382, Temurin     Java VM Version: OpenJDK 64-Bit Server VM (mixed mode), Temurin     Memory: 948745536 bytes (904 MB) / 1564999680 bytes (1492 MB) up to 7635730432 bytes (7282 MB)     JVM Flags: 2 total; -Xmx8192M -Xms256M     IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0     FML: MCP 9.42 Powered by Forge 14.23.5.2860 63 mods loaded, 63 mods active     States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored     | State | ID                 | Version                 | Source                                                | Signature                                |     |:----- |:------------------ |:----------------------- |:----------------------------------------------------- |:---------------------------------------- |     | LC    | minecraft          | 1.12.2                  | minecraft.jar                                         | None                                     |     | LC    | mcp                | 9.42                    | minecraft.jar                                         | None                                     |     | LC    | FML                | 8.0.99.99               | forge-1.12.2-14.23.5.2860.jar                         | e3c3d50c7c986df74c645c0ac54639741c90a557 |     | LC    | forge              | 14.23.5.2860            | forge-1.12.2-14.23.5.2860.jar                         | e3c3d50c7c986df74c645c0ac54639741c90a557 |     | LC    | creativecoredummy  | 1.0.0                   | minecraft.jar                                         | None                                     |     | LC    | backpacked         | 1.4.2                   | backpacked-1.4.3-1.12.2.jar                           | None                                     |     | LC    | itemblacklist      | 1.4.3                   | ItemBlacklist-1.4.3.jar                               | None                                     |     | LC    | securitycraft      | v1.9.8                  | [1.12.2] SecurityCraft v1.9.8.jar                     | None                                     |     | LC    | aiimprovements     | 0.0.1.3                 | AIImprovements-1.12-0.0.1b3.jar                       | None                                     |     | LC    | jei                | 4.16.1.301              | jei_1.12.2-4.16.1.301.jar                             | None                                     |     | LC    | appleskin          | 1.0.14                  | AppleSkin-mc1.12-1.0.14.jar                           | None                                     |     | LC    | baubles            | 1.5.2                   | Baubles-1.12-1.5.2.jar                                | None                                     |     | LC    | astralsorcery      | 1.10.27                 | astralsorcery-1.12.2-1.10.27.jar                      | a0f0b759d895c15ceb3e3bcb5f3c2db7c582edf0 |     | LC    | attributefix       | 1.0.12                  | AttributeFix-Forge-1.12.2-1.0.12.jar                  | None                                     |     | LC    | atum               | 2.0.20                  | Atum-1.12.2-2.0.20.jar                                | None                                     |     | LC    | bloodmoon          | 1.5.3                   | Bloodmoon-MC1.12.2-1.5.3.jar                          | d72e0dd57935b3e9476212aea0c0df352dd76291 |     | LC    | forgelin           | 1.8.4                   | Forgelin-1.8.4.jar                                    | None                                     |     | LC    | bountiful          | 2.2.2                   | Bountiful-2.2.2.jar                                   | None                                     |     | LC    | camera             | 1.0.10                  | camera-1.0.10.jar                                     | None                                     |     | LC    | chisel             | MC1.12.2-1.0.2.45       | Chisel-MC1.12.2-1.0.2.45.jar                          | None                                     |     | LC    | collective         | 3.0                     | collective-1.12.2-3.0.jar                             | None                                     |     | LC    | reskillable        | 1.12.2-1.13.0           | Reskillable-1.12.2-1.13.0.jar                         | None                                     |     | LC    | compatskills       | 1.12.2-1.17.0           | CompatSkills-1.12.2-1.17.0.jar                        | None                                     |     | LC    | creativecore       | 1.10.0                  | CreativeCore_v1.10.71_mc1.12.2.jar                    | None                                     |     | LC    | customnpcs         | 1.12                    | CustomNPCs_1.12.2-(05Jul20).jar                       | None                                     |     | LC    | darknesslib        | 1.1.2                   | DarknessLib-1.12.2-1.1.2.jar                          | 220f10d3a93b3ff5fbaa7434cc629d863d6751b9 |     | LC    | dungeonsmod        | @VERSION@               | DungeonsMod-1.12.2-1.0.8.jar                          | None                                     |     | LC    | enhancedvisuals    | 1.3.0                   | EnhancedVisuals_v1.4.4_mc1.12.2.jar                   | None                                     |     | LC    | extrautils2        | 1.0                     | extrautils2-1.12-1.9.9.jar                            | None                                     |     | LC    | futuremc           | 0.2.6                   | Future-MC-0.2.19.jar                                  | None                                     |     | LC    | geckolib3          | 3.0.30                  | geckolib-forge-1.12.2-3.0.31.jar                      | None                                     |     | LC    | gottschcore        | 1.15.1                  | GottschCore-mc1.12.2-f14.23.5.2859-v1.15.1.jar        | None                                     |     | LC    | hardcorerevival    | 1.2.0                   | HardcoreRevival_1.12.2-1.2.0.jar                      | None                                     |     | LC    | waila              | 1.8.26                  | Hwyla-1.8.26-B41_1.12.2.jar                           | None                                     |     | LE    | imsm               | 1.12                    | Instant Massive Structures Mod 1.12.2.jar             | None                                     |     | L     | journeymap         | 1.12.2-5.7.1p2          | journeymap-1.12.2-5.7.1p2.jar                         | None                                     |     | L     | mobsunscreen       | @version@               | mobsunscreen-1.12.2-3.1.5.jar                         | None                                     |     | L     | morpheus           | 1.12.2-3.5.106          | Morpheus-1.12.2-3.5.106.jar                           | None                                     |     | L     | llibrary           | 1.7.20                  | llibrary-1.7.20-1.12.2.jar                            | None                                     |     | L     | mowziesmobs        | 1.5.8                   | mowziesmobs-1.5.8.jar                                 | None                                     |     | L     | nocubessrparmory   | 3.0.0                   | NoCubes_SRP_Combat_Addon_3.0.0.jar                    | None                                     |     | L     | nocubessrpnests    | 3.0.0                   | NoCubes_SRP_Nests_Addon_3.0.0.jar                     | None                                     |     | L     | nocubessrpsurvival | 3.0.0                   | NoCubes_SRP_Survival_Addon_3.0.0.jar                  | None                                     |     | L     | nocubesrptweaks    | V4.1                    | nocubesrptweaks-V4.1.jar                              | None                                     |     | L     | patchouli          | 1.0-23.6                | Patchouli-1.0-23.6.jar                                | None                                     |     | L     | artifacts          | 1.1.2                   | RLArtifacts-1.1.2.jar                                 | None                                     |     | L     | rsgauges           | 1.2.8                   | rsgauges-1.12.2-1.2.8.jar                             | None                                     |     | L     | rustic             | 1.1.7                   | rustic-1.1.7.jar                                      | None                                     |     | L     | silentlib          | 3.0.13                  | SilentLib-1.12.2-3.0.14+168.jar                       | None                                     |     | L     | scalinghealth      | 1.3.37                  | ScalingHealth-1.12.2-1.3.42+147.jar                   | None                                     |     | L     | lteleporters       | 1.12.2-3.0.2            | simpleteleporters-1.12.2-3.0.2.jar                    | None                                     |     | L     | spartanshields     | 1.5.5                   | SpartanShields-1.12.2-1.5.5.jar                       | None                                     |     | L     | spartanweaponry    | 1.5.3                   | SpartanWeaponry-1.12.2-1.5.3.jar                      | None                                     |     | L     | srparasites        | 1.9.18                  | SRParasites-1.12.2v1.9.18.jar                         | None                                     |     | L     | treasure2          | 2.2.0                   | Treasure2-mc1.12.2-f14.23.5.2859-v2.2.1.jar           | None                                     |     | L     | treeharvester      | 4.0                     | treeharvester_1.12.2-4.0.jar                          | None                                     |     | L     | twilightforest     | 3.11.1021               | twilightforest-1.12.2-3.11.1021-universal.jar         | None                                     |     | L     | variedcommodities  | 1.12.2                  | VariedCommodities_1.12.2-(31Mar23).jar                | None                                     |     | L     | voicechat          | 1.12.2-2.4.32           | voicechat-forge-1.12.2-2.4.32.jar                     | None                                     |     | L     | wolfarmor          | 3.8.0                   | WolfArmorAndStorage-1.12.2-3.8.0-universal-signed.jar | None                                     |     | L     | worldborder        | 2.3                     | worldborder_1.12.2-2.3.jar                            | None                                     |     | L     | midnight           | 0.3.5                   | themidnight-0.3.5.jar                                 | None                                     |     | L     | structurize        | 1.12.2-0.10.277-RELEASE | structurize-1.12.2-0.10.277-RELEASE.jar               | None                                     |     Loaded coremods (and transformers):  llibrary (llibrary-core-1.0.11-1.12.2.jar)   net.ilexiconn.llibrary.server.core.plugin.LLibraryTransformer   net.ilexiconn.llibrary.server.core.patcher.LLibraryRuntimePatcher WolfArmorCore (WolfArmorAndStorage-1.12.2-3.8.0-universal-signed.jar)    AstralCore (astralsorcery-1.12.2-1.10.27.jar)    CreativePatchingLoader (CreativeCore_v1.10.71_mc1.12.2.jar)    SecurityCraftLoadingPlugin ([1.12.2] SecurityCraft v1.9.8.jar)    ForgelinPlugin (Forgelin-1.8.4.jar)    midnight (themidnight-0.3.5.jar)   com.mushroom.midnight.core.transformer.MidnightClassTransformer FutureMC (Future-MC-0.2.19.jar)   thedarkcolour.futuremc.asm.CoreTransformer SpartanWeaponry-MixinLoader (SpartanWeaponry-1.12.2-1.5.3.jar)    Backpacked (backpacked-1.4.3-1.12.2.jar)   com.mrcrayfish.backpacked.asm.BackpackedTransformer LoadingPlugin (Reskillable-1.12.2-1.13.0.jar)   codersafterdark.reskillable.base.asm.ClassTransformer LoadingPlugin (Bloodmoon-MC1.12.2-1.5.3.jar)   lumien.bloodmoon.asm.ClassTransformer     Profiler Position: N/A (disabled)     Is Modded: Definitely; Server brand changed to 'fml,forge'     Type: Dedicated Server (map_server.txt)
    • When i add mods like falling leaves, visuality and kappas shaders, even if i restart Minecraft they dont show up in the mods menu and they dont work
    • Delete the forge-client.toml file in your config folder  
  • Topics

×
×
  • Create New...

Important Information

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