clicking on spawner with egg will change a mob there

This commit is contained in:
GameHerobrine 2023-12-02 14:05:37 +03:00
parent 60fd866de6
commit ea3babff02
7 changed files with 23 additions and 3 deletions

View file

@ -5,7 +5,16 @@ class MonsterSpawnerBlock extends SolidBlock{
parent::__construct(MONSTER_SPAWNER, $meta, "Monster Spawner");
$this->hardness = 5;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
parent::place($item, $player, $block, $target, $face, $fx, $fy, $fz);
ServerAPI::request()->api->tile->add($this->level, TILE_MOB_SPAWNER, $this->x, $this->y, $this->z, [
"EntityId" => 0,
"id" => TILE_MOB_SPAWNER,
"x" => $this->x,
"y" => $this->y,
"z" => $this->z,
]);
}
public function getDrops(Item $item, Player $player){
return [];
}

View file

@ -8,6 +8,18 @@ class SpawnEggItem extends Item{
}
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
if($target instanceof MonsterSpawnerBlock){
$tile = ServerAPI::request()->api->tile->get($target);
if($tile instanceof Tile){
$tile->data["EntityId"] = $this->meta;
//TODO update tile somehow
}else{
ConsoleAPI::warn("No tile was found at $target!");
}
return false;
}
$ageable = $this->meta === MOB_CHICKEN || $this->meta === MOB_COW || $this->meta === MOB_SHEEP || $this->meta === MOB_PIG;
$data = array(
"x" => $block->x + 0.5,

View file

@ -226,7 +226,6 @@ class Level{
$tileEntities .= $nbt->write();
break;
case TILE_MOB_SPAWNER:
console("mobspawner spawn {$tile->data["EntityId"]}");
$nbt->setData(new Compound("", array(
new StringTag("id", TILE_MOB_SPAWNER),
new IntTag("x", (int) $tile->x),

View file

@ -185,7 +185,7 @@ class NormalGenerator implements NewLevelGenerator{
}
}
foreach($this->populators as $populator){
$this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->getSeed()); //ty shoghicp for 250k bytes of randomness
$this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->getSeed()); //ty shoghicp for 250k bytes of randomness (where ~65536 are usable)
$populator->populate($this->level, $chunkX, $chunkZ, $this->random);
}
}