1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Silk Spawners?

Discussion in 'Development' started by Astro, Mar 28, 2019.

  1. Astro

    Astro Slime

    Messages:
    78
    GitHub:
    RealAstro
    error:
    Code:
    [18:10:09] [Server thread/CRITICAL]: Error: "Call to a member function getInt() on null" (EXCEPTION) in "plugins/HestraCore/src/InfernalCore/MobSpawner/SpawnersListener" at line 48
    code:
    PHP:
            if (!$event->isCancelled() && $event->getBlock()->getId() === Block::MOB_SPAWNER) {
                
    $block $event->getBlock();
                if (
    $event->getItem()->getId() === Item::DIAMOND_PICKAXE && $event->getItem()->hasEnchantment(Enchantment::SILK_TOUCH)) {
                    
    $tile $event->getPlayer()->getLevel()->getTile($block);
                    if (!
    $tile instanceof MobSpawner) return false;
                    
    $spawner Item::get(Item::MOB_SPAWNER01);
                    
    $spawner->setCustomBlockData(new CompoundTag("", [
                        new 
    IntTag("EntityId"$tile->getEntityId())
                    ]));
                    
    $spawner->setCustomName($this->getSpawnerByName());
                    
    $level $event->getBlock()->getLevel();
                    
    $level->dropItem($event->getBlock(), $spawner);
                }
            }
        }

        public function 
    getSpawnerByName() {
            
    $spawner Item::get(Item::MOB_SPAWNER01);
            
    $int $spawner->getCustomBlockData()->getInt("EntityId");
            switch (
    $int) {
                case 
    10:
                    return 
    "§r§6§l*§r§e Chicken Spawner §6§l*§r";
                case 
    11:
                    return 
    "§r§6§l*§r§e Cow Spawner §6§l*§r";
                case 
    12:
                    return 
    "§r§6§l*§r§e Pig Spawner §6§l*§r";
                case 
    13:
                    return 
    "§r§6§l*§r§e Sheep Spawner §6§l*§r";
                case 
    14:
                    return 
    "§r§6§l*§r§e Wolf Spawner §6§l*§r";
                case 
    16:
                    return 
    "§r§6§l*§r§e Mooshroom Spawner §6§l*§r";
                case 
    17:
                    return 
    "§r§6§l*§r§e Squid Spawner §6§l*§r";
                case 
    18:
                    return 
    "§r§6§l*§r§e Rabbit Spawner §6§l*§r";
                case 
    22:
                    return 
    "§r§6§l*§r§e Wolf Spawner §6§l*§r";
                case 
    23:
                    return 
    "§r§6§l*§r§e Horse Spawner §6§l*§r";
                case 
    32:
                    return 
    "§r§6§l*§r§e Zombie Spawner §6§l*§r";
                case 
    33:
                    return 
    "§r§6§l*§r§e Creeper Spawner §6§l*§r";
                case 
    34:
                    return 
    "§r§6§l*§r§e Skeleton Spawner §6§l*§r";
                case 
    35:
                    return 
    "§r§6§l*§r§e Spider Spawner §6§l*§r";
                case 
    36:
                    return 
    "§r§6§l*§r§e Zombie Spawner §6§l*§r";
                case 
    37:
                    return 
    "§r§6§l*§r§e Slime Spawner §6§l*§r";
                case 
    38:
                    return 
    "§r§6§l*§r§e Enderman Spawner §6§l*§r";
                case 
    39:
                    return 
    "§r§6§l*§r§e Silverfish Spawner §6§l*§r";
                case 
    40:
                    return 
    "§r§6§l*§r§e Cave Spider Spawner §6§l*§r";
                case 
    42:
                    return 
    "§r§6§l*§r§e Magma Spawner §6§l*§r";
                case 
    41:
                    return 
    "§r§6§l*§r§e Ghast Spawner §6§l*§r";
                case 
    43:
                    return 
    "§r§6§l*§r§e Blaze Spawner §6§l*§r";
                case 
    45:
                    return 
    "§r§6§l*§r§e Witch Spawner §6§l*§r";
                case 
    48:
                    return 
    "§r§6§l*§r§e Wither Skeleton Spawner §6§l*§r";
                case 
    49:
                    return 
    "§r§6§l*§r§e Guardian Spawner §6§l*§r";
                case 
    51:
                    return 
    "§r§6§l*§r§e Villager Spawner §6§l*§r";
                case 
    55:
                    return 
    "§r§6§l*§r§e Endermite Spawner §6§l*§r";
            }
        }
     
  2. KielKing

    KielKing Zombie

    Messages:
    245
    GitHub:
    kielking
    $spawner->getCustomBlockData() returns null
     
    Astro likes this.
  3. Astro

    Astro Slime

    Messages:
    78
    GitHub:
    RealAstro
    alright
     
  4. Emirhan Akpınar

    Emirhan Akpınar Slime

    Messages:
    90
    Try this for add tag.
    PHP:
    $spawner Item::get(Item::MOB_SPAWNER01);
    $customBlockData = new CompoundTag("");
    $customBlockData->setInt("EntityId"$tile->getEntityId());
    $spawner->setCustomBlockData($customBlockData);
    $spawner->setCustomName($this->getSpawnerName($spawner));
    After use this for get entity ids.
    PHP:
       /**
       * @var Item $spawner
       * @return null|string
       */

    public function getSpawnerName(Item $spawner) ?string {
       
    $nbt $spawner->getCustomBlockData();
       if (
    $nbt->hasTag("EntityId"IntTag::class)) {
         
    $entityId $nbt->getInt("EntityId");
         switch (
    $entityId) {
           
    // Code

         
    }

       }

     }
     
    Last edited: Mar 28, 2019
  5. Astro

    Astro Slime

    Messages:
    78
    GitHub:
    RealAstro
    it's working but the issue is the name is not setting and once u place the spawner again and mine it, nothing drops
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.