MiningTask

Discussion in 'Development' started by ZackyVN, Feb 10, 2019 at 5:27 AM.

  1. ZackyVN

    ZackyVN Slime

    Messages:
    89
    I have this code
    PHP:
        public function __construct(Main $pluginEntity $entity){
            
    $this->plugin $plugin;
            
    $this->entity $entity;
        }

        public function 
    onRun(int $tick): void{
            
    $entity $this->entity;
            
    $level $entity->getLevel();
            if(
    $entity instanceof Bot){
                
    $block $level->getBlock(new Vector3($entity->getX()+1$entity->getY()+2$entity->getZ()))->getId();
                
    $tile $level->getTile(new Vector3($entity->getX()-$entity->getY()+2$entity->getZ()));
                if(
    $block === and $tile instanceof Chest){
                    
    $chest $tile->getInventory();
                    
    $level->setBlock(new Vector3($entity->getX()+1$entity->getY()+2$entity->getZ()), Block::get(Block::AIR), falsefalse);
                    
    $chest->addItem(Item::get(401));
                    
    $level->addParticle(new AngryVillagerParticle($entity->getPosition()->add($x$y+2$z)));
                }
            }
        }
    }
    When i put a cobblestone, It didnt do anything.
     
  2. KielKing

    KielKing Baby Zombie

    Messages:
    108
    GitHub:
    kielking
    what is $entity?

    and what is Bot?
     
  3. ZackyVN

    ZackyVN Slime

    Messages:
    89
    a fake human (a fake player)
    same as $entity
     
  4. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    626
    Is it a chest block or a chest inventory?

    if($block === 4 and $tile instanceof Chest){
     
  5. ZackyVN

    ZackyVN Slime

    Messages:
    89
    Nope it is Cobblestone
    The code u said check when a cobblestone in front of the bot (Fake player) and behind it is a chest
     
  6. Kkora

    Kkora Baby Zombie

    Messages:
    162
    GitHub:
    kkora2k3
    is there any problem that happen then logged to the console?
     
  7. KielKing

    KielKing Baby Zombie

    Messages:
    108
    GitHub:
    kielking
    put var_dump($entity->getName()); after if($entity instanceof Bot){ and put var_dump($tile); after if($block === 4 and $tile instanceof Chest){

    tell me the outputs
     
  8. ZackyVN

    ZackyVN Slime

    Messages:
    89
    Nope
     
  9. ZackyVN

    ZackyVN Slime

    Messages:
    89
    It is spamming bunch of this
    Code:
    string(8) "aedsdada"
    NULL
    string(1) "a"
    NULL
    string(3) "dwd"
    NULL
    string(14) "ádafdqawdafsf"
    NULL
    string(3) "dwd"
    NULL
    string(1) "a"
    NULL
    string(8) "aádađa"
    NULL
    string(8) "aedsdada"
    NULL
    string(14) "ádafdqawdafsf"
    NULL
    string(8) "aedsdada"
    NULL
    string(8) "aádađa"
    NULL
    string(3) "dwd"
    NULL
    string(1) "a"
    NULL
    string(14) "ádafdqawdafsf"
    NULL
    string(1) "a"
    NULL
    string(3) "dwd"
    NULL
    string(8) "aedsdada"
    NULL
    string(8) "aádađa"
    
    Updated code
    PHP:
        public function onRun(int $tick): void{
            
    $entity $this->entity;
            
    $level $entity->getLevel();
            
    var_dump($entity->getName());
            if(
    $entity instanceof Bot){
                
    $maxDistance 2;
                
    $block $entity->getTargetBlock($maxDistance);
                
    $tile $level->getTile(new Vector3($entity->getX()-$entity->getY()+1$entity->getZ()));
                
    var_dump($tile);
                if(
    $block === and $tile instanceof Chest){
                    
    $chest $tile->getInventory();
                    
    $level->setBlock(new Vector3($entity->getX()+1$entity->getY()+2$entity->getZ()), Block::get(Block::AIR), falsefalse);
                    
    $chest->addItem(Item::get(401));
                    
    $level->addParticle(new AngryVillagerParticle($entity->getPosition()->add($x$y+2$z)));
     
  10. KielKing

    KielKing Baby Zombie

    Messages:
    108
    GitHub:
    kielking
    the problem says it itself, the tile is not an instance of Chest, and so the if statement won't run :p
     
    Kkora likes this.
  11. ZackyVN

    ZackyVN Slime

    Messages:
    89
    That weird. Behind the entity is a chest. IDK how it didnt work? Is it have something to do with
    PHP:
    $entity->getX()-$entity->getY()+1$entity->getZ()
     
  12. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    626
    Use Level->getBlockIdAt(vector 3)?
     
  13. KielKing

    KielKing Baby Zombie

    Messages:
    108
    GitHub:
    kielking
    tell me what you're trying to do and i'll tell you the best way to do it
     
  14. ZackyVN

    ZackyVN Slime

    Messages:
    89
    I try to check if behind the entity is a chest and in front of the entity is a cobblestone block. I will break the cobblestone block and put it to the chest
     
  15. KielKing

    KielKing Baby Zombie

    Messages:
    108
    GitHub:
    kielking
    X - 1 isn't always behind
     
  16. ZackyVN

    ZackyVN Slime

    Messages:
    89
    So how to check behind it?
     
  17. KielKing

    KielKing Baby Zombie

    Messages:
    108
    GitHub:
    kielking
    PHP:
    //kindy hacky but if you want it here it is
    /** @var Entity $entity */
    $dirVec $entity->getDirectionVector();
    $sub $dirVec->multiply(0.5);
    $pos $entity->subtract($sub);
     
  18. ZackyVN

    ZackyVN Slime

    Messages:
    89
    How about in front of it?
    Does this correct
    PHP:
    $maxDistance 2;
    $block $entity->getTargetBlock($maxDistance);
     
  19. KielKing

    KielKing Baby Zombie

    Messages:
    108
    GitHub:
    kielking
    no, you do the same thing but add $sub
     
  20. ZackyVN

    ZackyVN Slime

    Messages:
    89
    ok
     

Share This Page

  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.