Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Tiles ticking

Comments in 'Plugin Development' started by Creeperface, Mar 9, 2016.

  1. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    Server ticks tiles every tick but i think it is needless, isn't it? What about ticking every 10 ticks?
    Maybe im wrong.
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    1. Server doesn't tick tiles every tick. It just checks tiles from the to-be-updated queue and updates them. If nothing is scheduled, they don't need to be ticked at all.
    2. They are used for furnaces.
  3. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    Yes i know but why one update per 10 ticks isn't enough?
    If i do burnTime += 10 (and other furnace/brewing times)
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Because furnace is not the only tile that ticks.
  5. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    And what tiles tick too? I only know about brewing and furnace
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Daylight sensor. And probably others, we never know.
    What exists is not the problem. The tile ticking system was designed to support any kind of tiles that exist right now or in the future, without knowing what the tiles are. It is like PocketMine calling PluginManager::callEvent() without knowing whether there is a plugin that handles it.
    After all, if there are no tiles that need ticking, there will be almost no lag.
  7. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    but i don't have to set this in level class but in furnace/brewing class, so it doesn't affect another tiles
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Now what is your question? We are talking about tick tile updates.
  9. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    i've just tested it and it works fine and it is almost same like 20 ticks per seconds (im using 2 ticks per second)
  10. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    But it isn't that every single tile will tick even when nothing happens. Can you show your test?
  11. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    this is onUpdate function in my enderFurnace

    PHP:
    private $lastUpdate2 0;

        public function 
    onUpdate(){
            if(
    $this->closed === true){
                return 
    false;
            }

            if(
    $this->lastUpdate2 10){
                
    $this->lastUpdate2++;
                return 
    true;
            }

            
    $this->lastUpdate2 0;

            
    $this->timings->startTiming();

            
    //$ret = false;

            
    foreach($this->inventories as $inventory) {

                
    $fuel $inventory->getFuel();
                
    $raw $inventory->getSmelting();
                
    $product $inventory->getResult();
                
    $smelt $this->server->getCraftingManager()->matchFurnaceRecipe($raw);
                
    $canSmelt = ($smelt instanceof FurnaceRecipe and $raw->getCount() > and (($smelt->getResult()->equals($product) and $product->getCount() < $product->getMaxStackSize()) or $product->getId() === Item::AIR));

                if (
    $inventory->burnTime <= and $canSmelt and $fuel->getFuelTime() !== null and $fuel->getCount() > 0) {
                    
    $this->checkFuel($fuel$inventory);
                }

                if (
    $inventory->burnTime 0) {
                    
    $inventory->burnTime--;
                    
    $inventory->burnTicks ceil(($inventory->burnTime $inventory->maxTime 20));

                    if (
    $smelt instanceof FurnaceRecipe and $canSmelt) {
                        
    $inventory->cookTime++;
                        if (
    $inventory->cookTime >= 20) { //10 seconds
                            
    $product Item::get($smelt->getResult()->getId(), $smelt->getResult()->getDamage(), $product->getCount() + 1);
                                
    $inventory->setResult($product);
                                
    $raw->setCount($raw->getCount() - 1);
                                if (
    $raw->getCount() === 0) {
                                    
    $raw Item::get(Item::AIR00);
                                }
                                
    $inventory->setSmelting($raw);

                            
    $inventory->cookTime $inventory->cookTime 20;
                        }
                    } elseif (
    $inventory->burnTime <= 0) {
                        
    $inventory->burnTime 0;
                        
    $inventory->cookTime 0;
                        
    $inventory->burnTicks 0;
                    } else {
                        
    $inventory->cookTime 0;
                    }
                    
    //$ret = true;

                    
    foreach ($inventory->getViewers() as $player) {
                        
    $windowId $player->getWindowId($inventory);
                        if (
    $windowId 0) {
                            
    $pk = new ContainerSetDataPacket();
                            
    $pk->windowid $windowId;
                            
    $pk->property 0//Smelting
                            
    $pk->value floor($inventory->cookTime 10);
                            
    $player->dataPacket($pk);

                            
    $pk = new ContainerSetDataPacket();
                            
    $pk->windowid $windowId;
                            
    $pk->property 1//Fire icon
                            
    $pk->value $inventory->burnTicks 10;
                            
    $player->dataPacket($pk);
                        }

                    }

                } else {
                    
    $inventory->burnTime 0;
                    
    $inventory->cookTime 0;
                    
    $inventory->burnTicks 0;
                    unset(
    $this->inventories[$inventory->owner]);
                }
            }

            
    $this->lastUpdate microtime(true);

            
    $this->timings->stopTiming();

            return 
    true;
        }
  12. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    i think it is faster
  13. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
  14. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    if tile was not updated it wouldn't be called. but im using this in my minigame and i need it, that's why it returns true always, but i think normal furnace in pocketmine can run only 2 times per second too
  15. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    decreased tile ticking rate?
  16. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    yes, it doesn't cause any problem. but not for all tiles. only for furnace and brewing
    Last edited: Mar 9, 2016
  17. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    And if you don't schedule an update, the onUpdate() won't be called.
  18. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    I dont understand now, but it works well for me
    Legoboy0215 likes this.

Share This Page

Advertisement