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

Entity damage problems

Discussion in 'Development' started by SavionLegendZzz, Mar 8, 2017.

  1. SavionLegendZzz

    SavionLegendZzz Slime

    Messages:
    75
    GitHub:
    savionlegends
    So i spawned a entity(FallingSand) and i tried hitting it and it wont do any damage here is my code(i also tried to output to console and nothing worked at all) the entity spawns perfectly

    Code:
    PHP:
    public function spawnEgg($id 122$damage 0Player $player){
            
    $pos1 $player->getPosition();
            
    $block1 Entity::createEntity("FallingSand"$player->getLevel(), new CompoundTag("", [
                
    "Pos" => new ListTag("Pos", [
                    new 
    DoubleTag(""$pos1->x),
                    new 
    DoubleTag(""$pos1->y),
                    new 
    DoubleTag(""$pos1->z)
                ]),
                
    "Motion" => new ListTag("Motion", [
                    new 
    DoubleTag(""0),
                    new 
    DoubleTag(""0),
                    new 
    DoubleTag(""0)
                ]),
                
    "Rotation" => new ListTag("Rotation", [
                    new 
    FloatTag(""0),
                    new 
    FloatTag(""0)
                ]),
                
    "TileID" => new IntTag("TileID"$id),
                
    "Data" => new ByteTag("Data"$damage),
            ]));

            
    $block1->spawnToAll();
            if(
    $block1 instanceof FallingSand){
                
    $this->block[$block1->getBlock()] = 100;
            }
        }

        public function 
    onHit(EntityDamageEvent $ev){
            
    $entity $ev->getEntity();
            if(
    $entity instanceof FallingSand){
               if(isset(
    $this->block[$entity->getBlock()])){
                   
    $damage $ev->getOriginalDamage();
                   
    $this->block[$entity->getBlock()] = ($this->block[$entity->getBlock()] - $damage);
                   if(
    $damage >= $this->block[$entity->getBlock()]){
                       
    $entity->close();
                   }
                   
    $blockEvent = new EntityDamageEvent($entityEntityDamageEvent::CAUSE_VOID$damage);
                   
    $entity->attack($damage$blockEvent);
                   echo 
    $this->block[$entity->getBlock()];
               }
            }
     
  2. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    Last edited: Mar 8, 2017
    Marabou likes this.
  3. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    extending falling sand and overwrite attack function should do the trick
     
  4. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    But if you do parent::attack() from your class that extends it will call FallingSand::attack() and it would stop there as it would not be void damage :/
    If you want to do it that way you need to copy FallingSand class into the plugin, modify then Entity::registerEntity()
     
    Marabou likes this.
  5. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    if you overwrite the attack function to not call parent::attack but your own attack handler, shouldnt that fix it
    as i consider copying a whole file then editing it is bad, especially when you can get away with extending and such
     
    Jack Noordhuis likes this.
  6. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    Hmm then it should work if you extend FallingSand and then copy method attack() from Entity
     
  7. Jack Noordhuis

    Jack Noordhuis Zombie Pigman Poggit Reviewer

    Messages:
    618
    GitHub:
    JackNoordhuis
    Just call Entity::attack() from your custom falling sand's attack function to call pocketmine/entity/Entity.php's attack method.
     
  8. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    How do you do that? I've only know parent::attack() and copying attack() from Entity works
     
  9. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    Ohhh I didn't know that will work! I've learned something new today! :D I've always thought it will call it statically :p
     
  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.