Items wont spawn in chest

Discussion in 'Spigot Help' started by Joto_is_here, Jul 18, 2021.

  1. I don't know what I'm doing wrong, here's my code, I know its sloppy so don't even mention
    Code (Text):
    public static void ChooseItems(){
            int RNetherite = r.nextInt(3);
            int Prot5 = r.nextInt(2);
            int enderPearls = r.nextInt(16);
            int RGhasttears = r.nextInt(5);
            int Diamonds = r.nextInt(8);
            int Obsidion = r.nextInt(32);
            int RSharpness5 = r.nextInt(2);
            int Ef5 = r.nextInt(2);
            int SoulSand = r.nextInt(30);
            int Sand = r.nextInt(100);
            int goldenapple = r.nextInt(6);
            int Egap = r.nextInt(2);
            int allprot = r.nextInt(2);

            ItemStack ghasttears = new ItemStack(Material.GHAST_TEAR,RGhasttears);
            ItemStack EnderPearls = new ItemStack(Material.ENDER_PEARL,enderPearls);
            ItemStack Netherite = new ItemStack(Material.NETHERITE_INGOT,RNetherite);
            ItemStack Diamondss = new ItemStack(Material.DIAMOND,Diamonds);
            ItemStack Obsidions = new ItemStack(Material.OBSIDIAN, Obsidion);
            ItemStack Soulsands = new ItemStack(Material.SOUL_SAND, SoulSand);
            ItemStack Prot = new ItemStack(Material.ENCHANTED_BOOK,Prot5);
            int protchoose = r.nextInt(8);
            Prot.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL,protchoose);
            ItemMeta meta = Prot.getItemMeta();
            meta.setDisplayName("Prot " + protchoose);
            Prot.setItemMeta(meta);
            ItemStack Sharp = new ItemStack(Material.ENCHANTED_BOOK,RSharpness5);
            int Sharpchoose = r.nextInt(10);
            Sharp.addUnsafeEnchantment(Enchantment.DAMAGE_ALL,Sharpchoose);
            ItemMeta meta1 = Sharp.getItemMeta();
            meta1.setDisplayName("Sharpness " + Sharpchoose);
            Sharp.setItemMeta(meta1);
            ItemStack Eff = new ItemStack(Material.ENCHANTED_BOOK,Ef5);
            int Effchoose = r.nextInt(10);
            Eff.addUnsafeEnchantment(Enchantment.DIG_SPEED,Effchoose);
            ItemMeta meta2 = Eff.getItemMeta();
            meta2.setDisplayName("Effeciency " + Effchoose);
            Eff.setItemMeta(meta2);
            ItemStack sands = new ItemStack(Material.SAND,Sand);
            ItemStack gap = new ItemStack(Material.GOLDEN_APPLE,goldenapple);
            ItemStack Egappl = new ItemStack(Material.ENCHANTED_GOLDEN_APPLE,Egap);
            ItemStack protAll = new ItemStack(Material.ENCHANTED_BOOK,allprot);
            ItemMeta meta3 = protAll.getItemMeta();
            meta3.setDisplayName("Prot From All" + 1);
            protAll.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL,1);
            protAll.addUnsafeEnchantment(Enchantment.PROTECTION_EXPLOSIONS,1);
            protAll.addUnsafeEnchantment(Enchantment.PROTECTION_FIRE,1);
            protAll.addUnsafeEnchantment(Enchantment.PROTECTION_PROJECTILE,1);
            protAll.setItemMeta(meta3);

            for(int i = 0; i < 6; i++) {

                int ran = r.nextInt(13);

                if(ran == 1){
                    chest.getBlockInventory().addItem(ghasttears);
                }
                if(ran == 2){
                    chest.getBlockInventory().addItem(EnderPearls);
                }
                if(ran == 3){
                    chest.getBlockInventory().addItem(Netherite);
                }
                if(ran == 4){
                    chest.getBlockInventory().addItem(Diamondss);
                }
                if(ran == 5){
                    chest.getBlockInventory().addItem(Obsidions);
                }
                if(ran == 6){
                    chest.getBlockInventory().addItem(Soulsands);
                }
                if(ran == 7){
                    chest.getBlockInventory().addItem(Prot);
                }
                if(ran == 8){
                    chest.getBlockInventory().addItem(Sharp);
                }
                if(ran == 9){
                    chest.getBlockInventory().addItem(Eff);
                }
                if(ran == 10){
                    chest.getBlockInventory().addItem(sands);
                }
                if(ran == 11){
                    chest.getBlockInventory().addItem(gap);
                }
                if(ran == 12){
                    chest.getBlockInventory().addItem(Egappl);
                }
            }
            chest.update(true);
        }
     
  2. You must use
    Code (Text):
    Chest chest = (Chest)block.getState();
    Inventory inv = chest.getInventory();
    Not sure
     
  3. I have it initiated outside of that code, I probably should have added it sorry lol