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

Unable to place spawner.

Discussion in 'Development' started by DiamondGamer30, Aug 6, 2018.

  1. DiamondGamer30

    DiamondGamer30 Baby Zombie

    Messages:
    175
    GitHub:
    diamondgamermcpe
    What could be a possible reason my spawner can't place?

    My place() function.
    PHP:
    public function place(Item $itemBlock $blockReplaceBlock $blockClickedint $faceVector3 $clickVectorPlayer $player null): bool {
        
    parent::place($item$blockReplace$blockClicked$face$clickVector$player);
        if(
    $item->getDamage() > and $item instanceof CustomItem) {
            
    /** @var CompoundTag $tag */
            
    $tag $item->getNamedTagEntry(CustomItem::SPECIAL);
            
    $tier $tag->getInt("tier");
            
    $this->setTier($tier);
            
    $tile $this->getLevel()->getTile($this);
            
    $this->entityId $item->getDamage();
            if(!
    $tile instanceof MobSpawner) {
                
    /** @var CompoundTag $nbt */
                
    $nbt = new CompoundTag("", [
                    new 
    StringTag(Tile::TAG_IDTile::MOB_SPAWNER),
                    new 
    IntTag(Tile::TAG_X, (int)$this->x),
                    new 
    IntTag(Tile::TAG_Y, (int)$this->y),
                    new 
    IntTag(Tile::TAG_Z, (int)$this->z),
                    new 
    IntTag(MobSpawner::TAG_ENTITY_ID$this->entityId),
                    new 
    IntTag(MobSpawner::TAG_SPAWN_COUNT4),
                    new 
    IntTag(MobSpawner::TAG_MIN_SPAWN_DELAYfloor(200 $tier)),
                    new 
    IntTag(MobSpawner::TAG_MAX_SPAWN_DELAYfloor(800 $tier))
                ]);
                
    /** @var MobSpawner $tile */
                
    $tile Tile::createTile(Tile::MOB_SPAWNER$this->getLevel(), $nbt);
                
    $tile->setEntityId($this->entityId);
                return 
    true;
            }
        }
        return 
    true;
    }
     
  2. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    Does it ever leave your hand? Does it appear for a split second, then go back to your hand?
     
    Muqsit likes this.
  3. DiamondGamer30

    DiamondGamer30 Baby Zombie

    Messages:
    175
    GitHub:
    diamondgamermcpe
    2nd one
     
  4. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    Can I see where you registered the block? I assume it's a class that overrides the existing MonsterSpawner class, right?
     
  5. DiamondGamer30

    DiamondGamer30 Baby Zombie

    Messages:
    175
    GitHub:
    diamondgamermcpe
    Its registered already.
     
  6. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Send your MobSpawner::addAdditionalSpawnData()
    method.
     
  7. DiamondGamer30

    DiamondGamer30 Baby Zombie

    Messages:
    175
    GitHub:
    diamondgamermcpe
    PHP:
    protected function addAdditionalSpawnData(CompoundTag $nbt): void {
        
    $nbt->setInt(self::TAG_ENTITY_ID$this->getSpawnCompound()->getInt(self::TAG_ENTITY_ID));
        
    $nbt->setInt(self::TAG_DELAY$this->getSpawnCompound()->getInt(self::TAG_DELAY));
        
    $nbt->setInt(self::TAG_SPAWN_COUNT$this->getSpawnCompound()->getInt(self::TAG_SPAWN_COUNT));
        
    $nbt->setInt(self::TAG_SPAWN_RANGE$this->getSpawnCompound()->getInt(self::TAG_SPAWN_RANGE));
        
    $nbt->setInt(self::TAG_MIN_SPAWN_DELAY$this->getSpawnCompound()->getInt(self::TAG_MIN_SPAWN_DELAY));
        
    $nbt->setInt(self::TAG_MAX_SPAWN_DELAY$this->getSpawnCompound()->getInt(self::TAG_MAX_SPAWN_DELAY));
    }
     
  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.