mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 11:39:43 +00:00
farmland weird loop is gone
This commit is contained in:
parent
019e7f26ea
commit
569f81c70c
3 changed files with 32 additions and 70 deletions
|
|
@ -103,7 +103,7 @@ class EntityAPI{
|
|||
if($args[0] === "all"){
|
||||
$cnt = 0;
|
||||
foreach($this->entities as $e){
|
||||
if(!$e->isPlayer()){ //if player, not despawning
|
||||
if(isset($e) && $e != null && !$e->isPlayer()){ //if player, not despawning
|
||||
$this->remove($e->eid);
|
||||
$cnt++;
|
||||
}
|
||||
|
|
@ -292,4 +292,4 @@ class EntityAPI{
|
|||
}
|
||||
return $this->entities;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -400,9 +400,6 @@ class Entity extends Position
|
|||
$endY = $startY + 2;
|
||||
$endZ = $startZ + 2;
|
||||
$waterDone = false;
|
||||
if($this->isPlayer()){
|
||||
|
||||
}
|
||||
if($this->isPlayer()){
|
||||
for($y = $startY; $y <= $endY; ++ $y){
|
||||
for($x = $startX; $x <= $endX; ++ $x){
|
||||
|
|
@ -1318,7 +1315,7 @@ class Entity extends Position
|
|||
|
||||
public function isPlayer()
|
||||
{
|
||||
return $this->player instanceof Player;
|
||||
return isset($this->player) && $this->player instanceof Player;
|
||||
}
|
||||
|
||||
public function sendMoveUpdate()
|
||||
|
|
|
|||
|
|
@ -10,87 +10,52 @@ class FarmlandBlock extends TransparentBlock{
|
|||
array(DIRT, 0, 1),
|
||||
);
|
||||
}
|
||||
|
||||
public function hasCrops(){
|
||||
//TODO vanilla 0.8.1 detection method
|
||||
$b = $this->getSide(1);
|
||||
return $b->isTransparent && $b->id != 0;
|
||||
}
|
||||
public function onUpdate($type){
|
||||
if($type === BLOCK_UPDATE_NORMAL){
|
||||
if($this->getSide(1)->isTransparent === false){
|
||||
if(!$this->getSide(1)->isTransparent){
|
||||
$this->level->setBlock($this, BlockAPI::get(DIRT, 0), true, false, true);
|
||||
return BLOCK_UPDATE_NORMAL;
|
||||
return $type;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if($type === BLOCK_UPDATE_RANDOM){
|
||||
if($this->checkWater()){
|
||||
$this->level->setBlock($this, BlockAPI::get(FARMLAND, 1), true, false, true);
|
||||
return BLOCK_UPDATE_RANDOM;
|
||||
if($this->meta === 0 && mt_rand(0,5) == 0){
|
||||
$water = $this->checkWater();
|
||||
if($water){
|
||||
$this->level->setBlock($this, BlockAPI::get(FARMLAND, 1), true, false, true);
|
||||
}elseif(!$this->hasCrops()){
|
||||
$this->level->setBlock($this, BlockAPI::get(DIRT, 0), true, false, true);
|
||||
}
|
||||
}
|
||||
else{
|
||||
if($this->getSide(1)->isFlowable) return BLOCK_UPDATE_RANDOM;
|
||||
if(!$this->getSide(1)->isFlowable){
|
||||
$this->level->setBlock($this, BlockAPI::get(DIRT, 0), true, false, true);
|
||||
return BLOCK_UPDATE_RANDOM;
|
||||
}
|
||||
return $type;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getBlockID($x, $y, $z){
|
||||
return $this->level->getBlock(new Vector3($x, $y, $z))->getID();
|
||||
}
|
||||
return $this->level->level->getBlockID($x, $y, $z); //PMFLevel method
|
||||
}
|
||||
|
||||
public function checkWater(){
|
||||
$x9 = $this->x+4;
|
||||
$x8 = $this->x+3;
|
||||
$x7 = $this->x+2;
|
||||
$x6 = $this->x+1;
|
||||
$x5 = $this->x;
|
||||
$x4 = $this->x-1;
|
||||
$x3 = $this->x-2;
|
||||
$x2 = $this->x-3;
|
||||
$x1 = $this->x-4;
|
||||
|
||||
$y = $this->y;
|
||||
$z = $this->z;
|
||||
|
||||
for($i = 1; $i < 82; $i++){
|
||||
switch($i){
|
||||
case($i < 10):
|
||||
$z9 = $z + 5 - $i;
|
||||
if($this->getBlockID($x9, $y, $z9) == 8 or $this->getBlockID($x9, $y, $z9) == 9) return true;
|
||||
break;
|
||||
case($i < 19):
|
||||
$z8 = $z + 5 - ($i - 9);
|
||||
if($this->getBlockID($x8, $y, $z8) == 8 or $this->getBlockID($x8, $y, $z8) == 9) return true;
|
||||
break;
|
||||
case($i < 28):
|
||||
$z7 = $z + 5 - ($i - 18);
|
||||
if($this->getBlockID($x7, $y, $z7) == 8 or $this->getBlockID($x7, $y, $z7) == 9) return true;
|
||||
break;
|
||||
case($i < 37):
|
||||
$z6 = $z + 5 - ($i - 27);
|
||||
if($this->getBlockID($x6, $y, $z6) == 8 or $this->getBlockID($x6, $y, $z6) == 9) return true;
|
||||
break;
|
||||
case($i < 46):
|
||||
$z5 = $z + 5 - ($i - 36);
|
||||
if($this->getBlockID($x5, $y, $z5) == 8 or $this->getBlockID($x5, $y, $z5) == 9) return true;
|
||||
break;
|
||||
case($i < 55):
|
||||
$z4 = $z + 5 - ($i - 45);
|
||||
if($this->getBlockID($x4, $y, $z4) == 8 or $this->getBlockID($x4, $y, $z4) == 9) return true;
|
||||
break;
|
||||
case($i < 64):
|
||||
$z3 = $z + 5 - ($i - 54);
|
||||
if($this->getBlockID($x3, $y, $z3) == 8 or $this->getBlockID($x3, $y, $z3) == 9) return true;
|
||||
break;
|
||||
case($i < 73):
|
||||
$z2 = $z + 5 - ($i - 63);
|
||||
if($this->getBlockID($x2, $y, $z2) == 8 or $this->getBlockID($x2, $y, $z2) == 9) return true;
|
||||
break;
|
||||
case($i < 82):
|
||||
$z1 = $z + 5 - ($i - 72);
|
||||
if($this->getBlockID($x1, $y, $z1) == 8 or $this->getBlockID($x1, $y, $z1) == 9) return true;
|
||||
break;
|
||||
|
||||
for($x = $this->x - 4; $x <= $this->x + 4; $x++){
|
||||
for($y = $this->y; $y <= $this->y + 1; $y++){
|
||||
for($z = $this->z - 4; $z <= $this->z + 4; $z++){
|
||||
$id = $this->getBlockID($x, $y, $z);
|
||||
if($id === 8 || $id === 9){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue