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

[New API] Creating a subclass of a Block

Comments in 'Plugin Development' started by Aussi, Jan 16, 2015.

  1. Aussi
    Offline

    Aussi New Member

    Joined:
    Jan 16, 2015
    Posts:
    2
    I'm trying to create a block that looks like a Gold block (i.e. it stands out from a long distance and is easy to see) but that players can walk through.

    I did some digging around all the existing Blocks and thought I was on the right track taking properties from Blocks like 'Carrot' (a Crop) that you can walk on top of, combined with a subclass of block\Gold to give the look and feel of gold. Also tried setting some other properties that seemed relevant, so my code looks like this:

    PHP:
    use pocketmine\block\Gold;

    class 
    RegionMarker extends Gold {

        protected 
    $id 1000000;

        public function 
    __construct() {
            
    parent::__construct();
            
    $this->boundingBox null;
        }

        public function 
    isTransparent(){
            return 
    true;
        }

        public function 
    isSolid(){
            return 
    false;
        }

        public function 
    getBoundingBox(){
            return 
    null;
        }
    }
    I've discovered that fiddling with the value of $id causes the block to look and behave completely differently - I've tried various values. However, I can't make a Gold block that can be walked through. Can anyone shine some light on the secrets of how to extend a Block to alter it?
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Yes PocketMine thinks it's transparent, but clients won't because the transparency won't be sent to the client.
    iksaku likes this.
  3. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,130
    Plugins:
    4
    Minecraft User:
    iksaku
    Yes, those flags are for the server to correctly handle player movements, and prevent illegal moves (hacks xD) but anyways, you can spawn a "FallingSand" entity with the Gold Block behaviour ;) check out how sand works and I believe that it will only need a change of ID xD
    PEMapModder likes this.
  4. Aussi
    Offline

    Aussi New Member

    Joined:
    Jan 16, 2015
    Posts:
    2
    Ah, thanks both, that's great, I'll give falling sand a try. Yes, thinking about it, I should have realised there are client-side implications to making your own blocks, doh!

Share This Page

Advertisement