mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-21 20:19:44 +00:00
added StaticBlock
This commit is contained in:
parent
0b28ed8042
commit
c6c088a7d5
7 changed files with 211 additions and 23 deletions
96
src/material/StaticBlock.php
Normal file
96
src/material/StaticBlock.php
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
<?php
|
||||
/**
|
||||
* Small class to hopefully optimize entities a bit
|
||||
*/
|
||||
class StaticBlock
|
||||
{
|
||||
const DEFAULT_SLIPPERINESS = 0.6;
|
||||
const DEFAULT_HARDNESS = 0;
|
||||
private static $NULL_BOUNDS;
|
||||
public static $isSolid = [];
|
||||
public static $isTransparent = [];
|
||||
public static $isFlowable = [];
|
||||
public static $isReplaceable = [];
|
||||
public static $isPlaceable = [];
|
||||
public static $hasPhysics = [];
|
||||
public static $isLiquid = [];
|
||||
public static $isFullBlock = [];
|
||||
|
||||
public static $hardness = [];
|
||||
public static $slipperiness = [];
|
||||
public static $boundingBoxes = [];
|
||||
public static function init(){
|
||||
self::$NULL_BOUNDS = new AxisAlignedBB(0, 0, 0, 0, 0, 0);
|
||||
foreach(Block::$class as $nonstaticname){
|
||||
/**@var Block $b*/
|
||||
$b = new $nonstaticname();
|
||||
|
||||
self::$isSolid[$b->getID()] = $b->isSolid;
|
||||
self::$isTransparent[$b->getID()] = $b->isTransparent;
|
||||
self::$isFlowable[$b->getID()] = $b->isFlowable;
|
||||
self::$isReplaceable[$b->getID()] = $b->isReplaceable;
|
||||
self::$isPlaceable[$b->getID()] = $b->isPlaceable;
|
||||
self::$hasPhysics[$b->getID()] = $b->hasPhysics;
|
||||
self::$isLiquid[$b->getID()] = $b->isLiquid;
|
||||
self::$isFullBlock[$b->getID()] = $b->isFullBlock;
|
||||
self::$slipperiness[$b->getID()] = $b->slipperiness;
|
||||
self::$boundingBoxes[$b->getID()] = $b->boundingBox;
|
||||
self::$hardness[$b->getID()] = $b->getHardness();
|
||||
}
|
||||
}
|
||||
|
||||
public static function getBlock($id){
|
||||
return Block::$class[$id] ?? Block::$class[0];
|
||||
}
|
||||
|
||||
public static function getHardness($id){
|
||||
return self::$hardness[$id] ?? StaticBlock::DEFAULT_HARDNESS;
|
||||
}
|
||||
|
||||
public static function getBoundingBoxForBlockCoords($id, $x, $y, $z){
|
||||
/**@var AxisAlignedBB $bb*/
|
||||
$bb = self::$boundingBoxes[$id] ?? false;
|
||||
if($bb === false){
|
||||
return clone self::$NULL_BOUNDS;
|
||||
}
|
||||
$bb = clone $bb;
|
||||
return $bb->setBounds($x + $bb->minX, $y + $bb->minY, $z + $bb->minZ, $x + $bb->maxX, $y + $bb->maxY, $z + $bb->maxZ);
|
||||
}
|
||||
|
||||
|
||||
public static function getSlipperiness($id){
|
||||
return self::$slipperiness[$id] ?? StaticBlock::DEFAULT_SLIPPERINESS;
|
||||
}
|
||||
|
||||
public static function getIsSolid($id){
|
||||
return self::$isSolid[$id] ?? false;
|
||||
}
|
||||
|
||||
public static function getIsTransparent($id){
|
||||
return self::$isTransparent[$id] ?? false;
|
||||
}
|
||||
|
||||
public static function getIsFlowable($id){
|
||||
return self::$isFlowable[$id] ?? false;
|
||||
}
|
||||
|
||||
public static function getIsReplaceable($id){
|
||||
return self::$isReplaceable[$id] ?? false;
|
||||
}
|
||||
|
||||
public static function getIsPlaceable($id){
|
||||
return self::$isPlaceable[$id] ?? false;
|
||||
}
|
||||
|
||||
public static function getHasPhysics($id){
|
||||
return self::$hasPhysics[$id] ?? false;
|
||||
}
|
||||
|
||||
public static function getIsLiquid($id){
|
||||
return self::$isLiquid[$id] ?? false;
|
||||
}
|
||||
|
||||
public static function getIsFullBlock($id){
|
||||
return self::$isFullBlock[$id] ?? false;
|
||||
}
|
||||
}
|
||||
30
src/material/block/misc/MobSpawnerBlock.php
Normal file
30
src/material/block/misc/MobSpawnerBlock.php
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
class MobSpawnerBlock extends SolidBlock
|
||||
{
|
||||
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(MONSTER_SPAWNER, $meta, "Mob Spawner");
|
||||
$this->isActivable = true;
|
||||
}
|
||||
|
||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
$api = ServerAPI::request();
|
||||
$tile = $api->api->tile->add($this->level, TILE_MOB_SPAWNER, $this->x, $this->y, $this->z, [
|
||||
"id" => TILE_MOB_SPAWNER,
|
||||
"x" => $this->x,
|
||||
"y" => $this->y,
|
||||
"z" => $this->z,
|
||||
"EntityId" => MOB_SPIDER, //TODO vanilla values
|
||||
"Delay" => 5,
|
||||
"MinSpawnDelay" => 20,
|
||||
"MaxSpawnDelay" => 80,
|
||||
"SpawnCount" => 4,
|
||||
"MaxNearbyEntities" => 0,
|
||||
"RequiredPlayerRange" => 0,
|
||||
"SpawnRange" => 4
|
||||
]);
|
||||
parent::place($item, $player, $block, $target, $face, $fx, $fy, $fz);
|
||||
}
|
||||
}
|
||||
|
||||
62
src/material/block/solid/PodzolBlock.php
Normal file
62
src/material/block/solid/PodzolBlock.php
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
|
||||
class PodzolBlock extends SolidBlock{
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(PODZOL, $meta, "Podzol");
|
||||
$this->hardness = 2.5;
|
||||
}
|
||||
|
||||
public function onUpdate($type){
|
||||
if($type === BLOCK_UPDATE_RANDOM){
|
||||
if(mt_rand(0, 3) == 0){
|
||||
$up = $this->getSide(1);
|
||||
if(($up->isTransparent === false) or ($up->isLiquid) or ($up->getID() == 60)) return false;
|
||||
if($this->getGrassInRadius()){
|
||||
$this->level->setBlock($this, BlockAPI::get(GRASS, 0), true, false, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
return BLOCK_UPDATE_RANDOM;
|
||||
}
|
||||
|
||||
public function getBlockID($x, $y, $z){
|
||||
return $this->level->getBlock(new Vector3($x, $y, $z))->getID();
|
||||
}
|
||||
|
||||
public function getGrassInRadius(){
|
||||
$x = $this->x;
|
||||
$y = $this->y;
|
||||
$z = $this->z;
|
||||
|
||||
if($this->getBlockID($x+1, $y, $z+1) == 2) return true;
|
||||
if($this->getBlockID($x+1, $y, $z) == 2) return true;
|
||||
if($this->getBlockID($x+1, $y, $z-1) == 2) return true;
|
||||
if($this->getBlockID($x, $y, $z+1) == 2) return true;
|
||||
if($this->getBlockID($x, $y, $z-1) == 2) return true;
|
||||
if($this->getBlockID($x-1, $y, $z+1) == 2) return true;
|
||||
if($this->getBlockID($x-1, $y, $z) == 2) return true;
|
||||
if($this->getBlockID($x-1, $y, $z-1) == 2) return true;
|
||||
|
||||
if($this->getBlockID($x+1, $y-1, $z+1) == 2) return true;
|
||||
if($this->getBlockID($x+1, $y-1, $z) == 2) return true;
|
||||
if($this->getBlockID($x+1, $y-1, $z-1) == 2) return true;
|
||||
if($this->getBlockID($x, $y-1, $z+1) == 2) return true;
|
||||
if($this->getBlockID($x, $y-1, $z) == 2) return true;
|
||||
if($this->getBlockID($x, $y-1, $z-1) == 2) return true;
|
||||
if($this->getBlockID($x-1, $y-1, $z+1) == 2) return true;
|
||||
if($this->getBlockID($x-1, $y-1, $z) == 2) return true;
|
||||
if($this->getBlockID($x-1, $y-1, $z-1) == 2) return true;
|
||||
|
||||
if($this->getBlockID($x+1, $y+1, $z+1) == 2) return true;
|
||||
if($this->getBlockID($x+1, $y+1, $z) == 2) return true;
|
||||
if($this->getBlockID($x+1, $y+1, $z-1) == 2) return true;
|
||||
if($this->getBlockID($x, $y+1, $z+1) == 2) return true;
|
||||
if($this->getBlockID($x, $y+1, $z-1) == 2) return true;
|
||||
if($this->getBlockID($x-1, $y+1, $z+1) == 2) return true;
|
||||
if($this->getBlockID($x-1, $y+1, $z) == 2) return true;
|
||||
if($this->getBlockID($x-1, $y+1, $z-1) == 2) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue