GenisysPro  for Minecraft PE/Windows 10 v1.1.x
Feature-rich server software for Minecraft PE and Windows 10 Edition
MobSpawner Class Reference

Public Member Functions

 __construct (Level $level, CompoundTag $nbt)
 
 getEntityId ()
 
 setEntityId (int $id)
 
 getSpawnCount ()
 
 setSpawnCount (int $value)
 
 getSpawnRange ()
 
 setSpawnRange (int $value)
 
 getMinSpawnDelay ()
 
 setMinSpawnDelay (int $value)
 
 getMaxSpawnDelay ()
 
 setMaxSpawnDelay (int $value)
 
 getDelay ()
 
 setDelay (int $value)
 
 getName ()
 
 canUpdate ()
 
 onUpdate ()
 
 getSpawnCompound ()
 
- Public Member Functions inherited from Spawnable
 spawnTo (Player $player)
 
 __construct (Level $level, CompoundTag $nbt)
 
 spawnToAll ()
 
 getSpawnCompound ()
 
 updateCompoundTag (CompoundTag $nbt, Player $player)
 
- Public Member Functions inherited from Tile
 getSaveId ()
 
 __construct (Level $level, CompoundTag $nbt)
 
 getId ()
 
 saveNBT ()
 
 getBlock ()
 
 onUpdate ()
 
 scheduleUpdate ()
 
 __destruct ()
 
 close ()
 
 getName ()
 
- Public Member Functions inherited from Position
 __construct ($x=0, $y=0, $z=0, Level $level=null)
 
 asPosition ()
 
 add ($x, $y=0, $z=0)
 
 getLevel ()
 
 setLevel (Level $level=null)
 
 isValid ()
 
 getSide ($side, $step=1)
 
 __toString ()
 
 setComponents ($x, $y, $z)
 
 fromObjectAdd (Vector3 $pos, $x, $y, $z)
 
- Public Member Functions inherited from Vector3
 __construct ($x=0, $y=0, $z=0)
 
 getX ()
 
 getY ()
 
 getZ ()
 
 getFloorX ()
 
 getFloorY ()
 
 getFloorZ ()
 
 getRight ()
 
 getUp ()
 
 getForward ()
 
 getSouth ()
 
 getWest ()
 
 add ($x, $y=0, $z=0)
 
 subtract ($x=0, $y=0, $z=0)
 
 multiply ($number)
 
 divide ($number)
 
 ceil ()
 
 floor ()
 
 round ()
 
 abs ()
 
 getSide ($side, $step=1)
 
 asVector3 ()
 
 distance (Vector3 $pos)
 
 distanceSquared (Vector3 $pos)
 
 maxPlainDistance ($x=0, $z=0)
 
 length ()
 
 lengthSquared ()
 
 normalize ()
 
 dot (Vector3 $v)
 
 cross (Vector3 $v)
 
 equals (Vector3 $v)
 
 getIntermediateWithXValue (Vector3 $v, $x)
 
 getIntermediateWithYValue (Vector3 $v, $y)
 
 getIntermediateWithZValue (Vector3 $v, $z)
 
 setComponents ($x, $y, $z)
 
 fromObjectAdd (Vector3 $pos, $x, $y, $z)
 
 __toString ()
 

Additional Inherited Members

- Static Public Member Functions inherited from Tile
static init ()
 
static createTile ($type, Level $level, CompoundTag $nbt,... $args)
 
static registerTile ($className)
 
- Static Public Member Functions inherited from Position
static fromObject (Vector3 $pos, Level $level=null)
 
- Static Public Member Functions inherited from Vector3
static getOppositeSide ($side)
 
static createRandomDirection (Random $random)
 
- Data Fields inherited from Tile
const BREWING_STAND = "BrewingStand"
 
const CHEST = "Chest"
 
const DL_DETECTOR = "DayLightDetector"
 
const ENCHANT_TABLE = "EnchantTable"
 
const FLOWER_POT = "FlowerPot"
 
const FURNACE = "Furnace"
 
const MOB_SPAWNER = "MobSpawner"
 
const SIGN = "Sign"
 
const SKULL = "Skull"
 
const ITEM_FRAME = "ItemFrame"
 
const DISPENSER = "Dispenser"
 
const DROPPER = "Dropper"
 
const CAULDRON = "Cauldron"
 
const HOPPER = "Hopper"
 
const BEACON = "Beacon"
 
const ENDER_CHEST = "EnderChest"
 
const BED = "Bed"
 
const DAY_LIGHT_DETECTOR = "DLDetector"
 
 $chunk
 
 $name
 
 $id
 
 $x
 
 $y
 
 $z
 
 $attach
 
 $metadata
 
 $closed = false
 
 $namedtag
 
 $tickTimer
 
- Data Fields inherited from Position
 $level = null
 
- Data Fields inherited from Vector3
const SIDE_DOWN = 0
 
const SIDE_UP = 1
 
const SIDE_NORTH = 2
 
const SIDE_SOUTH = 3
 
const SIDE_WEST = 4
 
const SIDE_EAST = 5
 
 $x
 
 $y
 
 $z
 
- Static Public Attributes inherited from Tile
static $tileCount = 1
 
- Protected Member Functions inherited from Spawnable
 onChanged ()
 
- Protected Attributes inherited from Tile
 $lastUpdate
 
 $server
 
 $timings
 

Constructor & Destructor Documentation

◆ __construct()

__construct ( Level  $level,
CompoundTag  $nbt 
)

MobSpawner constructor.

Parameters
Level$level
CompoundTag$nbt
46  {
47  if(!isset($nbt->EntityId) or !($nbt->EntityId instanceof IntTag)){
48  $nbt->EntityId = new IntTag("EntityId", 0);
49  }
50  if(!isset($nbt->SpawnCount) or !($nbt->SpawnCount instanceof IntTag)){
51  $nbt->SpawnCount = new IntTag("SpawnCount", 4);
52  }
53  if(!isset($nbt->SpawnRange) or !($nbt->SpawnRange instanceof IntTag)){
54  $nbt->SpawnRange = new IntTag("SpawnRange", 4);
55  }
56  if(!isset($nbt->MinSpawnDelay) or !($nbt->MinSpawnDelay instanceof IntTag)){
57  $nbt->MinSpawnDelay = new IntTag("MinSpawnDelay", 200);
58  }
59  if(!isset($nbt->MaxSpawnDelay) or !($nbt->MaxSpawnDelay instanceof IntTag)){
60  $nbt->MaxSpawnDelay = new IntTag("MaxSpawnDelay", 799);
61  }
62  if(!isset($nbt->Delay) or !($nbt->Delay instanceof IntTag)){
63  $nbt->Delay = new IntTag("Delay", mt_rand($nbt->MinSpawnDelay->getValue(), $nbt->MaxSpawnDelay->getValue()));
64  }
65  parent::__construct($level, $nbt);
66  if($this->getEntityId() > 0){
67  $this->scheduleUpdate();
68  }
69  }

Member Function Documentation

◆ canUpdate()

canUpdate ( )
Returns
bool
167  : bool{
168  if($this->getEntityId() === 0) return false;
169  $hasPlayer = false;
170  $count = 0;
171  foreach($this->getLevel()->getEntities() as $e){
172  if($e instanceof Player){
173  if($e->distance($this->getBlock()) <= 15) $hasPlayer = true;
174  }
175  if($e::NETWORK_ID == $this->getEntityId()){
176  $count++;
177  }
178  }
179  if($hasPlayer and $count < 15){ // Spawn limit = 15
180  return true;
181  }
182  return false;
183  }

◆ getDelay()

getDelay ( )
Returns
null
146  {
147  return $this->namedtag["Delay"];
148  }

◆ getEntityId()

getEntityId ( )
Returns
null
74  {
75  return $this->namedtag["EntityId"];
76  }

◆ getMaxSpawnDelay()

getMaxSpawnDelay ( )
Returns
null
132  {
133  return $this->namedtag["MaxSpawnDelay"];
134  }

◆ getMinSpawnDelay()

getMinSpawnDelay ( )
Returns
null
118  {
119  return $this->namedtag["MinSpawnDelay"];
120  }

◆ getName()

getName ( )
Returns
string
160  : string{
161  return "Monster Spawner";
162  }

◆ getSpawnCompound()

getSpawnCompound ( )
Returns
CompoundTag
246  {
247  $c = new CompoundTag("", [
248  new StringTag("id", Tile::MOB_SPAWNER),
249  new IntTag("x", (int) $this->x),
250  new IntTag("y", (int) $this->y),
251  new IntTag("z", (int) $this->z),
252  new IntTag("EntityId", (int) $this->getEntityId())
253  ]);
254 
255  return $c;
256  }

◆ getSpawnCount()

getSpawnCount ( )
Returns
null
90  {
91  return $this->namedtag["SpawnCount"];
92  }

◆ getSpawnRange()

getSpawnRange ( )
Returns
null
104  {
105  return $this->namedtag["SpawnRange"];
106  }

◆ onUpdate()

onUpdate ( )
Returns
bool
188  {
189  if($this->closed === true){
190  return false;
191  }
192 
193  $this->timings->startTiming();
194 
195  if(!($this->chunk instanceof Chunk)){
196  return false;
197  }
198  if($this->canUpdate()){
199  if($this->getDelay() <= 0){
200  $success = 0;
201  for($i = 0; $i < $this->getSpawnCount(); $i++){
202  $pos = $this->add(mt_rand() / mt_getrandmax() * $this->getSpawnRange(), mt_rand(-1, 1), mt_rand() / mt_getrandmax() * $this->getSpawnRange());
203  $target = $this->getLevel()->getBlock($pos);
204  $ground = $target->getSide(Vector3::SIDE_DOWN);
205  if($target->getId() == Item::AIR && $ground->isTopFacingSurfaceSolid()){
206  $success++;
207  $this->getLevel()->getServer()->getPluginManager()->callEvent($ev = new EntityGenerateEvent($pos, $this->getEntityId(), EntityGenerateEvent::CAUSE_MOB_SPAWNER));
208  if(!$ev->isCancelled()){
209  $nbt = new CompoundTag("", [
210  "Pos" => new ListTag("Pos", [
211  new DoubleTag("", $pos->x),
212  new DoubleTag("", $pos->y),
213  new DoubleTag("", $pos->z)
214  ]),
215  "Motion" => new ListTag("Motion", [
216  new DoubleTag("", 0),
217  new DoubleTag("", 0),
218  new DoubleTag("", 0)
219  ]),
220  "Rotation" => new ListTag("Rotation", [
221  new FloatTag("", mt_rand() / mt_getrandmax() * 360),
222  new FloatTag("", 0)
223  ]),
224  ]);
225  $entity = Entity::createEntity($this->getEntityId(), $this->getLevel(), $nbt);
226  $entity->spawnToAll();
227  }
228  }
229  }
230  if($success > 0){
231  $this->setDelay(mt_rand($this->getMinSpawnDelay(), $this->getMaxSpawnDelay()));
232  }
233  }else{
234  $this->setDelay($this->getDelay() - 1);
235  }
236  }
237 
238  $this->timings->stopTiming();
239 
240  return true;
241  }

◆ setDelay()

setDelay ( int  $value)
Parameters
int$value
153  {
154  $this->namedtag->Delay->setValue($value);
155  }

◆ setEntityId()

setEntityId ( int  $id)
Parameters
int$id
81  {
82  $this->namedtag->EntityId->setValue($id);
83  $this->onChanged();
84  $this->scheduleUpdate();
85  }

◆ setMaxSpawnDelay()

setMaxSpawnDelay ( int  $value)
Parameters
int$value
139  {
140  $this->namedtag->MaxSpawnDelay->setValue($value);
141  }

◆ setMinSpawnDelay()

setMinSpawnDelay ( int  $value)
Parameters
int$value
125  {
126  $this->namedtag->MinSpawnDelay->setValue($value);
127  }

◆ setSpawnCount()

setSpawnCount ( int  $value)
Parameters
int$value
97  {
98  $this->namedtag->SpawnCount->setValue($value);
99  }

◆ setSpawnRange()

setSpawnRange ( int  $value)
Parameters
int$value
111  {
112  $this->namedtag->SpawnRange->setValue($value);
113  }

The documentation for this class was generated from the following file: