Improved Nether Door calculation

This commit is contained in:
PeratX 2016-04-27 17:00:43 +08:00
commit ba09ea7bc9
4 changed files with 81 additions and 70 deletions

View file

@ -24,6 +24,7 @@ namespace pocketmine\block;
use pocketmine\entity\Arrow;
use pocketmine\entity\Effect;
use pocketmine\entity\Entity;
use pocketmine\event\block\BlockBurnEvent;
use pocketmine\event\entity\EntityCombustByBlockEvent;
use pocketmine\event\entity\EntityDamageByBlockEvent;
use pocketmine\event\entity\EntityDamageEvent;
@ -36,8 +37,14 @@ class Fire extends Flowable{
protected $id = self::FIRE;
/** @var Vector3 */
private $temporalVector = null;
public function __construct($meta = 0){
$this->meta = $meta;
if($this->temporalVector === null){
$this->temporalVector = new Vector3(0, 0, 0);
}
}
public function hasEntityCollision(){
@ -131,7 +138,6 @@ class Fire extends Flowable{
$this->tryToCatchBlockOnFire($this->getSide(Vector3::SIDE_SOUTH), 300 + $o, $meta);
$this->tryToCatchBlockOnFire($this->getSide(Vector3::SIDE_NORTH), 300 + $o, $meta);
$tempVector = new Vector3(0, 0, 0);
for($x = ($this->x - 1); $x <= ($this->x + 1); ++$x){
for($z = ($this->z - 1); $z <= ($this->z + 1); ++$z){
for($y = ($this->y -1); $y <= ($this->y + 4); ++$y){
@ -141,18 +147,18 @@ class Fire extends Flowable{
$k += ($y - ($this->y + 1)) * 100;
}
$chance = $this->getChanceOfNeighborsEncouragingFire($this->getLevel()->getBlock($tempVector->setComponents($x, $y, $z)));
$chance = $this->getChanceOfNeighborsEncouragingFire($this->getLevel()->getBlock($this->temporalVector->setComponents($x, $y, $z)));
if($chance > 0){
$t = ($chance + 40 + $this->getLevel()->getServer()->getDifficulty() * 7);
//TODO: decrease the t if the rainfall values are high
//TODO: decrease t if the rainfall values are high
if($t > 0 and mt_rand(0, $k) <= $t){
$damage = min(15, $meta + mt_rand(0, 5) / 4);
$this->getLevel()->setBlock($tempVector->setComponents($x, $y, $z), new Fire($damage), true);
$this->getLevel()->scheduleUpdate($tempVector, $this->getTickRate());
$this->getLevel()->setBlock($this->temporalVector->setComponents($x, $y, $z), new Fire($damage), true);
$this->getLevel()->scheduleUpdate($this->temporalVector, $this->getTickRate());
}
}
}

View file

@ -67,44 +67,42 @@ class Obsidian extends Solid{
for($i = 0;$i <= 6;$i++){
if($i == 6){
return;
}elseif($this->getLevel()->getBlock($this->getSide($i))->getId() == 90){
$side = $i;
break;
}
}
$block = $this->getLevel()->getBlock($this->getSide($i));
if($this->getLevel()->getBlock($block->add(-1, 0, 0))->getId() == 90 or $this->getLevel()->getBlock($block->add(1, 0, 0))->getId() == 90){//x方向
for($x = $block->getX();$this->getLevel()->getBlock($this->temporalVector->setComponents($x, $block->getY(), $block->getZ()))->getId() == 90;$x++){
for($y = $block->getY();$this->getLevel()->getBlock($this->temporalVector->setComponents($x, $y, $block->getZ()))->getId() == 90;$y++){
$this->getLevel()->setBlock($this->temporalVector->setComponents($x, $y, $block->getZ()), new Block(0, 0));
if($this->getLevel()->getBlock($this->temporalVector->setComponents($block->x - 1, $block->y, $block->z))->getId() == Block::PORTAL or
$this->getLevel()->getBlock($this->temporalVector->setComponents($block->x + 1, $block->y, $block->z))->getId() == Block::PORTAL){//x方向
for($x = $block->x;$this->getLevel()->getBlock($this->temporalVector->setComponents($x, $block->y, $block->z))->getId() == Block::PORTAL;$x++){
for($y = $block->y;$this->getLevel()->getBlock($this->temporalVector->setComponents($x, $y, $block->z))->getId() == Block::PORTAL;$y++){
$this->getLevel()->setBlock($this->temporalVector->setComponents($x, $y, $block->z), new Air());
}
for($y = $block->getY() - 1;$this->getLevel()->getBlock($this->temporalVector->setComponents($x, $y, $block->getZ()))->getId() == 90;$y--){
$this->getLevel()->setBlock($this->temporalVector->setComponents($x, $y, $block->getZ()), new Block(0, 0));
for($y = $block->y - 1;$this->getLevel()->getBlock($this->temporalVector->setComponents($x, $y, $block->z))->getId() == Block::PORTAL;$y--){
$this->getLevel()->setBlock($this->temporalVector->setComponents($x, $y, $block->z), new Air());
}
}
for($x = $block->getX() - 1;$this->getLevel()->getBlock($this->temporalVector->setComponents($x, $block->getY(), $block->getZ()))->getId() == 90;$x--){
for($y = $block->getY();$this->getLevel()->getBlock($this->temporalVector->setComponents($x, $y, $block->getZ()))->getId() == 90;$y++){
$this->getLevel()->setBlock($this->temporalVector->setComponents($x, $y, $block->getZ()), new Block(0, 0));
for($x = $block->x - 1;$this->getLevel()->getBlock($this->temporalVector->setComponents($x, $block->y, $block->z))->getId() == Block::PORTAL;$x--){
for($y = $block->y;$this->getLevel()->getBlock($this->temporalVector->setComponents($x, $y, $block->z))->getId() == Block::PORTAL;$y++){
$this->getLevel()->setBlock($this->temporalVector->setComponents($x, $y, $block->z), new Air());
}
for($y = $block->getY() - 1;$this->getLevel()->getBlock($this->temporalVector->setComponents($x, $y, $block->getZ()))->getId() == 90;$y--){
$this->getLevel()->setBlock($this->temporalVector->setComponents($x, $y, $block->getZ()), new Block(0, 0));
for($y = $block->y - 1;$this->getLevel()->getBlock($this->temporalVector->setComponents($x, $y, $block->z))->getId() == Block::PORTAL;$y--){
$this->getLevel()->setBlock($this->temporalVector->setComponents($x, $y, $block->z), new Air());
}
}
}else{//z方向
for($z = $block->getZ();$this->getLevel()->getBlock($this->temporalVector->setComponents($block->getX(), $block->getY(), $z))->getId() == 90;$z++){
for($y = $block->getY();$this->getLevel()->getBlock($this->temporalVector->setComponents($block->getX(), $y, $z))->getId() == 90;$y++){
$this->getLevel()->setBlock($this->temporalVector->setComponents($block->getX(), $y, $z), new Block(0, 0));
for($z = $block->z;$this->getLevel()->getBlock($this->temporalVector->setComponents($block->x, $block->y, $z))->getId() == Block::PORTAL;$z++){
for($y = $block->y;$this->getLevel()->getBlock($this->temporalVector->setComponents($block->x, $y, $z))->getId() == Block::PORTAL;$y++){
$this->getLevel()->setBlock($this->temporalVector->setComponents($block->x, $y, $z), new Air());
}
for($y = $block->getY() - 1;$this->getLevel()->getBlock($this->temporalVector->setComponents($block->getX(), $y, $z))->getId() == 90;$y--){
$this->getLevel()->setBlock($this->temporalVector->setComponents($block->getX(), $y, $z), new Block(0, 0));
for($y = $block->y - 1;$this->getLevel()->getBlock($this->temporalVector->setComponents($block->x, $y, $z))->getId() == Block::PORTAL;$y--){
$this->getLevel()->setBlock($this->temporalVector->setComponents($block->x, $y, $z), new Air());
}
}
for($z = $block->getZ() - 1;$this->getLevel()->getBlock($this->temporalVector->setComponents($block->getX(), $block->getY(), $z))->getId() == 90;$z--){
for($y = $block->getY();$this->getLevel()->getBlock($this->temporalVector->setComponents($block->getX(), $y, $z))->getId() == 90;$y++){
$this->getLevel()->setBlock($this->temporalVector->setComponents($block->getX(), $y, $z), new Block(0, 0));
for($z = $block->z - 1;$this->getLevel()->getBlock($this->temporalVector->setComponents($block->x, $block->y, $z))->getId() == Block::PORTAL;$z--){
for($y = $block->y;$this->getLevel()->getBlock($this->temporalVector->setComponents($block->x, $y, $z))->getId() == Block::PORTAL;$y++){
$this->getLevel()->setBlock($this->temporalVector->setComponents($block->x, $y, $z), new Air());
}
for($y = $block->getY() - 1;$this->getLevel()->getBlock($this->temporalVector->setComponents($block->getX(), $y, $z))->getId() == 90;$y--){
$this->getLevel()->setBlock($this->temporalVector->setComponents($block->getX(), $y, $z), new Block(0, 0));
for($y = $block->y - 1;$this->getLevel()->getBlock($this->temporalVector->setComponents($block->x, $y, $z))->getId() == Block::PORTAL;$y--){
$this->getLevel()->setBlock($this->temporalVector->setComponents($block->x, $y, $z), new Air());
}
}
}

View file

@ -87,39 +87,40 @@ class Portal extends Transparent{
$particle = new PortalParticle($this);
$this->getLevel()->addParticle($particle);
$block = $this;
//$this->getLevel()->setBlock($block, new Block(90, 0));//在破坏处放置一个方块防止计算出错
if($this->getLevel()->getBlock($block->add(-1, 0, 0))->getId() == 90 or $this->getLevel()->getBlock($block->add(1, 0, 0))->getId() == 90){//x方向
for($x = $block->getX();$this->getLevel()->getBlock($this->temporalVector->setComponents($x, $block->getY(), $block->getZ()))->getId() == 90;$x++){
for($y = $block->getY();$this->getLevel()->getBlock($this->temporalVector->setComponents($x, $y, $block->getZ()))->getId() == 90;$y++){
$this->getLevel()->setBlock($this->temporalVector->setComponents($x, $y, $block->getZ()), new Block(0, 0));
//$this->getLevel()->setBlock($block, new Block(Block::PORTAL, 0));//在破坏处放置一个方块防止计算出错
if($this->getLevel()->getBlock($this->temporalVector->setComponents($block->x - 1, $block->y, $block->z))->getId() == Block::PORTAL or
$this->getLevel()->getBlock($this->temporalVector->setComponents($block->x + 1, $block->y, $block->z))->getId() == Block::PORTAL){//x方向
for($x = $block->x;$this->getLevel()->getBlock($this->temporalVector->setComponents($x, $block->y, $block->z))->getId() == Block::PORTAL;$x++){
for($y = $block->y;$this->getLevel()->getBlock($this->temporalVector->setComponents($x, $y, $block->z))->getId() == Block::PORTAL;$y++){
$this->getLevel()->setBlock($this->temporalVector->setComponents($x, $y, $block->z), new Air());
}
for($y = $block->getY() - 1;$this->getLevel()->getBlock($this->temporalVector->setComponents($x, $y, $block->getZ()))->getId() == 90;$y--){
$this->getLevel()->setBlock($this->temporalVector->setComponents($x, $y, $block->getZ()), new Block(0, 0));
for($y = $block->y - 1;$this->getLevel()->getBlock($this->temporalVector->setComponents($x, $y, $block->z))->getId() == Block::PORTAL;$y--){
$this->getLevel()->setBlock($this->temporalVector->setComponents($x, $y, $block->z), new Air());
}
}
for($x = $block->getX() - 1;$this->getLevel()->getBlock($this->temporalVector->setComponents($x, $block->getY(), $block->getZ()))->getId() == 90;$x--){
for($y = $block->getY();$this->getLevel()->getBlock($this->temporalVector->setComponents($x, $y, $block->getZ()))->getId() == 90;$y++){
$this->getLevel()->setBlock($this->temporalVector->setComponents($x, $y, $block->getZ()), new Block(0, 0));
for($x = $block->x - 1;$this->getLevel()->getBlock($this->temporalVector->setComponents($x, $block->y, $block->z))->getId() == Block::PORTAL;$x--){
for($y = $block->y;$this->getLevel()->getBlock($this->temporalVector->setComponents($x, $y, $block->z))->getId() == Block::PORTAL;$y++){
$this->getLevel()->setBlock($this->temporalVector->setComponents($x, $y, $block->z), new Air());
}
for($y = $block->getY() - 1;$this->getLevel()->getBlock($this->temporalVector->setComponents($x, $y, $block->getZ()))->getId() == 90;$y--){
$this->getLevel()->setBlock($this->temporalVector->setComponents($x, $y, $block->getZ()), new Block(0, 0));
for($y = $block->y - 1;$this->getLevel()->getBlock($this->temporalVector->setComponents($x, $y, $block->z))->getId() == Block::PORTAL;$y--){
$this->getLevel()->setBlock($this->temporalVector->setComponents($x, $y, $block->z), new Air());
}
}
}else{//z方向
for($z = $block->getZ();$this->getLevel()->getBlock($this->temporalVector->setComponents($block->getX(), $block->getY(), $z))->getId() == 90;$z++){
for($y = $block->getY();$this->getLevel()->getBlock($this->temporalVector->setComponents($block->getX(), $y, $z))->getId() == 90;$y++){
$this->getLevel()->setBlock($this->temporalVector->setComponents($block->getX(), $y, $z), new Block(0, 0));
for($z = $block->z;$this->getLevel()->getBlock($this->temporalVector->setComponents($block->x, $block->y, $z))->getId() == Block::PORTAL;$z++){
for($y = $block->y;$this->getLevel()->getBlock($this->temporalVector->setComponents($block->x, $y, $z))->getId() == Block::PORTAL;$y++){
$this->getLevel()->setBlock($this->temporalVector->setComponents($block->x, $y, $z), new Air());
}
for($y = $block->getY() - 1;$this->getLevel()->getBlock($this->temporalVector->setComponents($block->getX(), $y, $z))->getId() == 90;$y--){
$this->getLevel()->setBlock($this->temporalVector->setComponents($block->getX(), $y, $z), new Block(0, 0));
for($y = $block->y - 1;$this->getLevel()->getBlock($this->temporalVector->setComponents($block->x, $y, $z))->getId() == Block::PORTAL;$y--){
$this->getLevel()->setBlock($this->temporalVector->setComponents($block->x, $y, $z), new Air());
}
}
for($z = $block->getZ() - 1;$this->getLevel()->getBlock($this->temporalVector->setComponents($block->getX(), $block->getY(), $z))->getId() == 90;$z--){
for($y = $block->getY();$this->getLevel()->getBlock($this->temporalVector->setComponents($block->getX(), $y, $z))->getId() == 90;$y++){
$this->getLevel()->setBlock($this->temporalVector->setComponents($block->getX(), $y, $z), new Block(0, 0));
for($z = $block->z - 1;$this->getLevel()->getBlock($this->temporalVector->setComponents($block->x, $block->y, $z))->getId() == Block::PORTAL;$z--){
for($y = $block->y;$this->getLevel()->getBlock($this->temporalVector->setComponents($block->x, $y, $z))->getId() == Block::PORTAL;$y++){
$this->getLevel()->setBlock($this->temporalVector->setComponents($block->x, $y, $z), new Air());
}
for($y = $block->getY() - 1;$this->getLevel()->getBlock($this->temporalVector->setComponents($block->getX(), $y, $z))->getId() == 90;$y--){
$this->getLevel()->setBlock($this->temporalVector->setComponents($block->getX(), $y, $z), new Block(0, 0));
for($y = $block->y - 1;$this->getLevel()->getBlock($this->temporalVector->setComponents($block->x, $y, $z))->getId() == Block::PORTAL;$y--){
$this->getLevel()->setBlock($this->temporalVector->setComponents($block->x, $y, $z), new Air());
}
}
}

View file

@ -23,14 +23,21 @@ namespace pocketmine\item;
use pocketmine\block\Block;
use pocketmine\block\Fire;
use pocketmine\block\Portal;
use pocketmine\block\Solid;
use pocketmine\level\Level;
use pocketmine\Player;
use pocketmine\math\Vector3;
class FlintSteel extends Tool{
/** @var Vector3 */
private $temporalVector = null;
public function __construct($meta = 0, $count = 1){
parent::__construct(self::FLINT_STEEL, $meta, $count, "Flint and Steel");
if($this->temporalVector === null){
$this->temporalVector = new Vector3(0, 0, 0);
}
}
public function canBeActivated() : bool{
@ -38,7 +45,7 @@ class FlintSteel extends Tool{
}
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
if($target->getId() === 49 and $player->getServer()->netherEnabled){//黑曜石 4*5最小 23*23最大
if($target->getId() === Block::OBSIDIAN and $player->getServer()->netherEnabled){//黑曜石 4*5最小 23*23最大
//$level->setBlock($block, new Fire(), true);
$tx = $target->getX();
$ty = $target->getY();
@ -46,21 +53,20 @@ class FlintSteel extends Tool{
//x方向
$x_max = $tx;//x最大值
$x_min = $tx;//x最小值
$count_x = 0;//x方向方块
for($x = $tx + 1; $level->getBlock(new Vector3($x, $ty, $tz))->getId() == 49; $x++){
for($x = $tx + 1; $level->getBlock($this->temporalVector->setComponents($x, $ty, $tz))->getId() == Block::OBSIDIAN; $x++){
$x_max++;
}
for($x = $tx - 1; $level->getBlock(new Vector3($x, $ty, $tz))->getId() == 49; $x--){
for($x = $tx - 1; $level->getBlock($this->temporalVector->setComponents($x, $ty, $tz))->getId() == Block::OBSIDIAN; $x--){
$x_min--;
}
$count_x = $x_max - $x_min + 1;
$count_x = $x_max - $x_min + 1;//x方向方块
if($count_x >= 4 and $count_x <= 23){//4 23
$x_max_y = $ty;//x最大值时的y最大值
$x_min_y = $ty;//x最小值时的y最大值
for($y = $ty; $level->getBlock(new Vector3($x_max, $y, $tz))->getId() == 49; $y++){
for($y = $ty; $level->getBlock($this->temporalVector->setComponents($x_max, $y, $tz))->getId() == Block::OBSIDIAN; $y++){
$x_max_y++;
}
for($y = $ty; $level->getBlock(new Vector3($x_min, $y, $tz))->getId() == 49; $y++){
for($y = $ty; $level->getBlock($this->temporalVector->setComponents($x_min, $y, $tz))->getId() == Block::OBSIDIAN; $y++){
$x_min_y++;
}
$y_max = min($x_max_y, $x_min_y) - 1;//y最大值
@ -68,17 +74,17 @@ class FlintSteel extends Tool{
//Server::getInstance()->broadcastMessage("$y_max $x_max_y $x_min_y $x_max $x_min");
if($count_y >= 5 and $count_y <= 23){//5 23
$count_up = 0;//上面
for($ux = $x_min; ($level->getBlock(new Vector3($ux, $y_max, $tz))->getId() == 49 and $ux <= $x_max); $ux++){
for($ux = $x_min; ($level->getBlock($this->temporalVector->setComponents($ux, $y_max, $tz))->getId() == Block::OBSIDIAN and $ux <= $x_max); $ux++){
$count_up++;
}
//Server::getInstance()->broadcastMessage("$count_up $count_x");
if($count_up == $count_x){
for($px = $x_min + 1; $px < $x_max; $px++){
for($py = $ty + 1; $py < $y_max; $py++){
$level->setBlock(new Vector3($px, $py, $tz), new Block(90, 0));
$level->setBlock($this->temporalVector->setComponents($px, $py, $tz), new Portal());
}
}
if (($player->gamemode & 0x01) === 0) {
if($player->isSurvival()){
$this->useOn($block, 2);
$player->getInventory()->setItemInHand($this);
}
@ -91,37 +97,37 @@ class FlintSteel extends Tool{
$z_max = $tz;//z最大值
$z_min = $tz;//z最小值
$count_z = 0;//z方向方块
for($z = $tz + 1; $level->getBlock(new Vector3($tx, $ty, $z))->getId() == 49; $z++){
for($z = $tz + 1; $level->getBlock($this->temporalVector->setComponents($tx, $ty, $z))->getId() == Block::OBSIDIAN; $z++){
$z_max++;
}
for($z = $tz - 1; $level->getBlock(new Vector3($tx, $ty, $z))->getId() == 49; $z--){
for($z = $tz - 1; $level->getBlock($this->temporalVector->setComponents($tx, $ty, $z))->getId() == Block::OBSIDIAN; $z--){
$z_min--;
}
$count_z = $z_max - $z_min + 1;
if($count_z >= 4 and $count_z <= 23){//4 23
$z_max_y = $ty;//z最大值时的y最大值
$z_min_y = $ty;//z最小值时的y最大值
for($y = $ty; $level->getBlock(new Vector3($tx, $y, $z_max))->getId() == 49; $y++){
for($y = $ty; $level->getBlock($this->temporalVector->setComponents($tx, $y, $z_max))->getId() == Block::OBSIDIAN; $y++){
$z_max_y++;
}
for($y = $ty; $level->getBlock(new Vector3($tx, $y, $z_min))->getId() == 49; $y++){
for($y = $ty; $level->getBlock($this->temporalVector->setComponents($tx, $y, $z_min))->getId() == Block::OBSIDIAN; $y++){
$z_min_y++;
}
$y_max = min($z_max_y, $z_min_y) - 1;//y最大值
$count_y = $y_max - $ty + 2;//方向方块
if($count_y >= 5 and $count_y <= 23){//5 23
$count_up = 0;//上面
for($uz = $z_min; ($level->getBlock(new Vector3($tx, $y_max, $uz))->getId() == 49 and $uz <= $z_max); $uz++){
for($uz = $z_min; ($level->getBlock($this->temporalVector->setComponents($tx, $y_max, $uz))->getId() == Block::OBSIDIAN and $uz <= $z_max); $uz++){
$count_up++;
}
//Server::getInstance()->broadcastMessage("$count_up $count_z");
if($count_up == $count_z){
for($pz = $z_min + 1; $pz < $z_max; $pz++){
for($py = $ty + 1; $py < $y_max; $py++){
$level->setBlock(new Vector3($tx, $py, $pz), new Block(90, 0));
$level->setBlock($this->temporalVector->setComponents($tx, $py, $pz), new Portal());
}
}
if (($player->gamemode & 0x01) === 0) {
if($player->isSurvival()){
$this->useOn($block, 2);
$player->getInventory()->setItemInHand($this);
}
@ -139,10 +145,10 @@ class FlintSteel extends Tool{
$block = $level->getBlock($block);
if($block->getSide(Vector3::SIDE_DOWN)->isTopFacingSurfaceSolid() or $block->canNeighborBurn()){
$level->scheduleUpdate($block, $block->getTickRate() + mt_rand(0, 10));
// return true;
// return true;
}
if (($player->gamemode & 0x01) === 0) {
if($player->isSurvival()){
$this->useOn($block, 2);//耐久跟报废分别写在 tool 跟 level 了
$player->getInventory()->setItemInHand($this);
}