Posted August 7, 20205 yr Hi i'm new to minecraft modding so i'm trying to learn. I'm having issues with an LazyOptional<IItemHandler> variable what i want to do is get the boolean from itemhandler.isItemValid and put it in an condition. but when i do itemhandler.ifPresent(h -> h.isItemValid(1, state.getBlock().getItem(world, blockpos, state))); it says to me that itemhandler.ifPresent is a void method i understand but i can't find an other way to get to the return of h.isItemValid Thank u anyhelp would be cool and sry for bad english. here is the method: private void Looting(BlockState state, BlockPos blockpos, PlayerEntity player) { LazyOptional<IItemHandler> itemhandler; TileEntity chest; if(world.getBlockState(pos.add(0, 1, 0)) == BlockInit.harvest_chest.getDefaultState()) { chest = world.getTileEntity(pos.add(0, 1, 0)); itemhandler = chest.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null); //test itemhandler.ifPresent(h -> h.isItemValid(1, state.getBlock().getItem(world, blockpos, state))); //test for(io = 0; io < 36; io++) { //condition that needs test if(itemhandler) itemhandler.ifPresent(h -> h.insertItem(io, state.getBlock().getItem(world, blockpos, state), false)); //condition } } else if(getDistancetoBlock(player, pos)) { player.addItemStackToInventory(state.getBlock().getItem(world, blockpos, state)); player.sendStatusMessage(new StringTextComponent("HELLO"), true); } else { Block.spawnDrops(state, world, pos.add(0, 1, 0), this.getTileEntity(), null, ItemStack.EMPTY); } }
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.