mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-23 13:09:44 +00:00
better code
This commit is contained in:
parent
7347838876
commit
0e11e4c10e
2 changed files with 20 additions and 18 deletions
|
|
@ -27,7 +27,9 @@ class RailBlock extends FlowableBlock{
|
||||||
$this->isSolid = true;
|
$this->isSolid = true;
|
||||||
$this->meta = $meta;
|
$this->meta = $meta;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static $shouldconnectrails = false;
|
public static $shouldconnectrails = false;
|
||||||
|
|
||||||
private function isRailBlock($id){
|
private function isRailBlock($id){
|
||||||
switch($id){
|
switch($id){
|
||||||
case RAIL:
|
case RAIL:
|
||||||
|
|
@ -37,20 +39,21 @@ class RailBlock extends FlowableBlock{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function isValidRailMeta($meta){
|
private function isValidRailMeta($meta){
|
||||||
return !($meta < 0 || $meta > 10);
|
return !($meta < 0 || $meta > 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function canConnectRail($block) {
|
private function canConnectRail($block) {
|
||||||
if(!($block instanceof RailBlock)) return null;
|
if(!($block instanceof RailBlock)) return null;
|
||||||
if($this->distanceSquared($block) > 2) return null;
|
if($this->distanceSquared($block) > 2) return null;
|
||||||
$result = $this->checkRail($this);
|
$result = $this->checkRail($this);
|
||||||
if (count($result) === 2) return null;
|
if(count($result) === 2) return null;
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function checkRail($rail){//fixed
|
||||||
private function checkRail($rail) { //fixed
|
if(!($rail instanceof Rail)) return null;
|
||||||
if (!($rail instanceof Rail)) return null;
|
|
||||||
$damage = $rail->meta;
|
$damage = $rail->meta;
|
||||||
if ($damage < 0 || $damage > 10) return null;
|
if ($damage < 0 || $damage > 10) return null;
|
||||||
$delta = array(
|
$delta = array(
|
||||||
|
|
@ -66,16 +69,16 @@ class RailBlock extends FlowableBlock{
|
||||||
|
|
||||||
array(array(-1, 0), array(0, -1)),
|
array(array(-1, 0), array(0, -1)),
|
||||||
array(array(0, -1), array(1, 0))
|
array(array(0, -1), array(1, 0))
|
||||||
|
|
||||||
);
|
);
|
||||||
$deltaY = array(0, 1, -1);
|
$deltaY = array(0, 1, -1);
|
||||||
$blocks = $delta[$damage];
|
$blocks = $delta[$damage];
|
||||||
$connected = array();
|
$connected = array();
|
||||||
|
|
||||||
foreach($deltaY as $y){
|
foreach($deltaY as $y){
|
||||||
$v3 = new Vector3(
|
$v3 = new Vector3(
|
||||||
$rail->getFloorX() + $blocks[0][0],
|
$rail->getFloorX() + $blocks[0][0],
|
||||||
$rail->getFloorY() + $y,
|
$rail->getFloorY() + $y,
|
||||||
$rail->getFloorZ() + $blocks[0][1]
|
$rail->getFloorZ() + $blocks[0][1]
|
||||||
);
|
);
|
||||||
$idToConnect = $rail->level->getBlock(v3.getFloorX(), v3.getFloorY(), v3.getFloorZ())->getID();
|
$idToConnect = $rail->level->getBlock(v3.getFloorX(), v3.getFloorY(), v3.getFloorZ())->getID();
|
||||||
$metaToConnect = $rail->level->getBlock(v3.getFloorX(), v3.getFloorY(), v3.getFloorZ())->getMetadata();
|
$metaToConnect = $rail->level->getBlock(v3.getFloorX(), v3.getFloorY(), v3.getFloorZ())->getMetadata();
|
||||||
|
|
@ -89,9 +92,9 @@ class RailBlock extends FlowableBlock{
|
||||||
}
|
}
|
||||||
foreach($deltaY as $y){
|
foreach($deltaY as $y){
|
||||||
$v3 = new Vector3(
|
$v3 = new Vector3(
|
||||||
$rail.getFloorX() + $blocks[1][0],
|
$rail.getFloorX() + $blocks[1][0],
|
||||||
$rail.getFloorY() + $y,
|
$rail.getFloorY() + $y,
|
||||||
$rail.getFloorZ() + $blocks[1][1]
|
$rail.getFloorZ() + $blocks[1][1]
|
||||||
);
|
);
|
||||||
$idToConnect = $rail->level->getBlock(v3.getFloorX(), v3.getFloorY(), v3.getFloorZ())->getID();
|
$idToConnect = $rail->level->getBlock(v3.getFloorX(), v3.getFloorY(), v3.getFloorZ())->getID();
|
||||||
$metaToConnect = $rail->level->getBlock(v3.getFloorX(), v3.getFloorY(), v3.getFloorZ())->getMetadata();
|
$metaToConnect = $rail->level->getBlock(v3.getFloorX(), v3.getFloorY(), v3.getFloorZ())->getMetadata();
|
||||||
|
|
@ -105,6 +108,7 @@ class RailBlock extends FlowableBlock{
|
||||||
}
|
}
|
||||||
return $connected;
|
return $connected;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function connectRail($rail){
|
private function connectRail($rail){
|
||||||
$connected = $this->canConnectRail($rail);
|
$connected = $this->canConnectRail($rail);
|
||||||
if ($connected === null || count($connected) === 0) return;
|
if ($connected === null || count($connected) === 0) return;
|
||||||
|
|
@ -129,11 +133,10 @@ class RailBlock extends FlowableBlock{
|
||||||
$this->level->setBlock($rail, new RailBlock($this.getDamage()), true, true);
|
$this->level->setBlock($rail, new RailBlock($this.getDamage()), true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||||
$down = $this->getSide(0);
|
$down = $this->getSide(0);
|
||||||
if($down->getID() !== AIR and $down instanceof SolidBlock){
|
if($down->getID() !== AIR and $down instanceof SolidBlock){
|
||||||
/*Rail connection(ported from nukkit)*/
|
//Rail connection(ported from nukkit)
|
||||||
if(RailBlock::$shouldconnectrails){
|
if(RailBlock::$shouldconnectrails){
|
||||||
$arrayXZ = array(array(1, 0),array(0, 1),array(-1, 0),array(0, -1));
|
$arrayXZ = array(array(1, 0),array(0, 1),array(-1, 0),array(0, -1));
|
||||||
$arrayY = array(0, 1, -1);
|
$arrayY = array(0, 1, -1);
|
||||||
|
|
@ -173,7 +176,7 @@ class RailBlock extends FlowableBlock{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*End of Logic*/
|
//End of Logic
|
||||||
$this->level->setBlock($block, $this, true, false, true);
|
$this->level->setBlock($block, $this, true, false, true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -182,12 +185,11 @@ class RailBlock extends FlowableBlock{
|
||||||
|
|
||||||
public function onUpdate($type){
|
public function onUpdate($type){
|
||||||
if($type === BLOCK_UPDATE_NORMAL){
|
if($type === BLOCK_UPDATE_NORMAL){
|
||||||
if($this->getSide(0)->getID() === AIR){ //Replace with common break method
|
if($this->getSide(0)->getID() === AIR){//Replace with common break method
|
||||||
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id, $this->meta, 1));
|
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id, $this->meta, 1));
|
||||||
$this->level->setBlock($this, new AirBlock(), true, false, true);
|
$this->level->setBlock($this, new AirBlock(), true, false, true);
|
||||||
return BLOCK_UPDATE_NORMAL;
|
return BLOCK_UPDATE_NORMAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -670,7 +670,7 @@ class Entity extends Position{
|
||||||
elseif($rand == 2) $color = 7;
|
elseif($rand == 2) $color = 7;
|
||||||
else $color = 8;
|
else $color = 8;
|
||||||
break;
|
break;
|
||||||
case $chance <= 100:
|
default:
|
||||||
$color = 0;
|
$color = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue