mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 11:39:43 +00:00
added step
This commit is contained in:
parent
2c264a023a
commit
92209861ee
5 changed files with 84 additions and 16 deletions
|
|
@ -79,6 +79,9 @@ class Entity extends Position
|
|||
public $onGround, $inWater;
|
||||
public $carryoverDamage;
|
||||
public $gravity;
|
||||
|
||||
public $stepHeight = 0.5;
|
||||
|
||||
function __construct(Level $level, $eid, $class, $type = 0, $data = array())
|
||||
{
|
||||
$this->random = new Random();
|
||||
|
|
@ -150,6 +153,7 @@ class Entity extends Position
|
|||
$this->y = isset($this->data["TileY"]) ? $this->data["TileY"] : $this->y;
|
||||
$this->z = isset($this->data["TileZ"]) ? $this->data["TileZ"] : $this->z;
|
||||
$this->setHealth(1, "generic");
|
||||
$this->stepHeight = false;
|
||||
// $this->setName((isset($objects[$this->type]) ? $objects[$this->type]:$this->type));
|
||||
$this->width = 1;
|
||||
$this->height = 1;
|
||||
|
|
@ -566,6 +570,11 @@ class Entity extends Position
|
|||
}
|
||||
|
||||
$savedSpeedY = $this->speedY;
|
||||
$savedSpeedX = $this->speedX;
|
||||
$savedSpeedZ = $this->speedZ;
|
||||
$ultraMegaOldBB = clone $this->boundingBox;
|
||||
$stepSuccess = false;
|
||||
$beforeStepSpeedY = 0;
|
||||
if($this->class === ENTITY_MOB || $this->class === ENTITY_ITEM || ($this->class === ENTITY_OBJECT && $this->type === OBJECT_PRIMEDTNT) || $this->class === ENTITY_FALLING){
|
||||
$water = false;
|
||||
if($this->hasGravity){
|
||||
|
|
@ -601,6 +610,53 @@ class Entity extends Position
|
|||
}
|
||||
$this->boundingBox->offset($this->speedX, $this->speedY, $this->speedZ);
|
||||
$this->inWater = $water;
|
||||
$fallingFlag = $this->onGround || $savedSpeedY != $this->speedY && $savedSpeedY < 0.0;
|
||||
$beforeStepSpeedY = $this->speedY;
|
||||
if($this->stepHeight > 0 && $fallingFlag && ($this->speedX != $savedSpeedX || $this->speedZ != $savedSpeedZ)){
|
||||
$cx = $this->speedX;
|
||||
$cy = $this->speedY;
|
||||
$cz = $this->speedZ;
|
||||
|
||||
$this->speedX = $savedSpeedX;
|
||||
$this->speedY = $this->stepHeight;
|
||||
$this->speedZ = $savedSpeedZ;
|
||||
|
||||
$aabb = clone $this->boundingBox;
|
||||
$this->boundingBox->setBB($ultraMegaOldBB);
|
||||
$aaBBs = $this->level->getCubes($this, $this->boundingBox->addCoord($this->speedX, $this->speedY, $this->speedZ));
|
||||
|
||||
foreach($aaBBs as $bb){ //TODO optimize
|
||||
$this->speedY = $bb->calculateYOffset($this->boundingBox, $this->speedY);
|
||||
}
|
||||
$this->boundingBox->offset(0, $this->speedY, 0);
|
||||
|
||||
foreach($aaBBs as $bb){
|
||||
$this->speedX = $bb->calculateXOffset($this->boundingBox, $this->speedX);
|
||||
}
|
||||
$this->boundingBox->offset($this->speedX, 0, 0);
|
||||
|
||||
foreach($aaBBs as $bb){
|
||||
$this->speedZ = $bb->calculateZOffset($this->boundingBox, $this->speedZ);
|
||||
}
|
||||
$this->boundingBox->offset(0, 0, $this->speedZ);
|
||||
|
||||
//$this->speedY = -$this->stepHeight;
|
||||
//foreach($aaBBs as $bb){ //TODO optimize
|
||||
// $this->speedY = $bb->calculateYOffset($this->boundingBox, $this->speedY);
|
||||
//}
|
||||
//$this->boundingBox->offset(0, $this->speedY, 0);
|
||||
|
||||
if ($cx*$cx + $cz*$cz >= $this->speedX*$this->speedX + $this->speedZ*$this->speedZ)
|
||||
{
|
||||
$this->speedX = $cx;
|
||||
$this->speedY = $cy;
|
||||
$this->speedZ = $cz;
|
||||
$this->boundingBox->setBB($aabb);
|
||||
}else{
|
||||
$stepSuccess = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
$support = $savedSpeedY != $this->speedY && $savedSpeedY < 0;
|
||||
|
||||
|
|
@ -614,6 +670,7 @@ class Entity extends Position
|
|||
}
|
||||
if($this->speedY != 0){
|
||||
$ny = $this->y + $this->speedY;
|
||||
if($stepSuccess) $this->speedY = $beforeStepSpeedY;
|
||||
if($this->class === ENTITY_FALLING){
|
||||
if($support){
|
||||
$this->level->fastSetBlockUpdate($this->x, $this->y, $this->z, $this->data["Tile"], 0);
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
class MobController
|
||||
{
|
||||
public static $ADVANCED = false;
|
||||
public static $AUTOJUMP = false;
|
||||
public static $landed = false;
|
||||
public static $DANGEROUS_BLOCKS = [
|
||||
LAVA => true,
|
||||
|
|
@ -48,19 +49,21 @@ class MobController
|
|||
$xf = $this->entity->x + ($this->entity->getSpeedModifer() * $ox * $this->entity->getSpeed());
|
||||
$zf = $this->entity->z + ($this->entity->getSpeedModifer() * $oz * $this->entity->getSpeed());
|
||||
$a = $b = $c = $d = 0;
|
||||
$oy = $this->entity->onGround && (
|
||||
StaticBlock::getIsSolid(($a = $this->entity->level->level->getBlockID(ceil($xf), (int)($this->entity->y), ceil($zf)))) &&
|
||||
if(self::$AUTOJUMP){
|
||||
$oy = $this->entity->onGround && (
|
||||
StaticBlock::getIsSolid(($a = $this->entity->level->level->getBlockID(ceil($xf), (int)($this->entity->y), ceil($zf)))) &&
|
||||
!StaticBlock::getIsSolid($this->entity->level->level->getBlockID(ceil($xf), (int)($this->entity->y) + 1, ceil($zf)))
|
||||
||
|
||||
||
|
||||
StaticBlock::getIsSolid(($b = $this->entity->level->level->getBlockID(ceil($xf), (int)($this->entity->y), $zf - ($oz < 0)))) &&
|
||||
!StaticBlock::getIsSolid($this->entity->level->level->getBlockID(ceil($xf), (int)($this->entity->y) + 1, $zf - ($oz < 0)))
|
||||
||
|
||||
||
|
||||
StaticBlock::getIsSolid(($c = $this->entity->level->level->getBlockID($xf - ($ox < 0), (int)($this->entity->y), $zf - ($oz < 0)))) &&
|
||||
!StaticBlock::getIsSolid($this->entity->level->level->getBlockID($xf - ($ox < 0), (int)($this->entity->y) + 1, $zf - ($oz < 0)))
|
||||
||
|
||||
||
|
||||
StaticBlock::getIsSolid(($d = $this->entity->level->level->getBlockID($xf - ($ox < 0), (int)($this->entity->y), ceil($zf)))) &&
|
||||
!StaticBlock::getIsSolid($this->entity->level->level->getBlockID($xf - ($ox < 0), (int)($this->entity->y) + 1, ceil($zf)))
|
||||
);
|
||||
);
|
||||
}
|
||||
|
||||
while(self::$ADVANCED){
|
||||
if($this->isDangerous($a) || $this->isDangerous($b) || $this->isDangerous($c) || $this->isDangerous($d)){
|
||||
|
|
|
|||
|
|
@ -21,5 +21,6 @@ class ItemEntity extends Entity{
|
|||
$this->setHealth(5, "generic");
|
||||
$this->gravity = 0.04;
|
||||
$this->delayBeforePickup = 20;
|
||||
$this->stepHeight = false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
|
||||
//TODO make it extend SlabBlock
|
||||
class WoodSlabBlock extends TransparentBlock{
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(WOOD_SLAB, $meta, "Wooden Slab");
|
||||
|
|
@ -17,7 +17,10 @@ class WoodSlabBlock extends TransparentBlock{
|
|||
}
|
||||
$this->hardness = 15;
|
||||
}
|
||||
|
||||
public static function getCollisionBoundingBoxes(Level $level, $x, $y, $z, Entity $entity){
|
||||
if(($level->level->getBlockDamage($x, $y, $z) & 0x08) == 0x08) return [new AxisAlignedBB($x, $y, $z, $x + 1, $y + 1, $z + 1)];
|
||||
return [new AxisAlignedBB($x, $y, $z, $x + 1, $y + 0.5, $z + 1)];
|
||||
}
|
||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
$this->meta &= 0x07;
|
||||
if($face === 0){
|
||||
|
|
|
|||
|
|
@ -75,15 +75,16 @@ class Level{
|
|||
}
|
||||
|
||||
/**
|
||||
* @param Entity $e
|
||||
* @param AxisAlignedBB $aABB
|
||||
* @return AxisAlignedBB[]
|
||||
*/
|
||||
public function getCubes(AxisAlignedBB $aABB) {
|
||||
public function getCubes(Entity $e, AxisAlignedBB $aABB) {
|
||||
$aABBs = [];
|
||||
$x0 = floor($aABB->minX);
|
||||
$x1 = ceil($aABB->maxX);
|
||||
$y0 = floor($aABB->minY);
|
||||
$y1 = round($aABB->maxY);
|
||||
$y1 = ceil($aABB->maxY);
|
||||
$z0 = floor($aABB->minZ);
|
||||
$z1 = ceil($aABB->maxZ);
|
||||
$x0 = $x0 < 0 ? 0 : $x0;
|
||||
|
|
@ -93,12 +94,15 @@ class Level{
|
|||
$y1 = $y1 > 128 ? 128 : $y1;
|
||||
$z1 = $z1 > 256 ? 256 : $z1;
|
||||
|
||||
for($x = $x0; $x < $x1; ++$x) {
|
||||
for($y = $y0; $y < $y1; ++$y) {
|
||||
for($z = $z0; $z < $z1; ++$z) {
|
||||
$b = $this->getBlockWithoutVector($x, $y, $z);
|
||||
if($b != false && $b->boundingBox->intersectsWith($aABB) && $b->isSolid) {
|
||||
$aABBs[] = $b->boundingBox;
|
||||
for($x = $x0; $x <= $x1; ++$x) {
|
||||
for($y = $y0; $y <= $y1; ++$y) {
|
||||
for($z = $z0; $z <= $z1; ++$z) {
|
||||
$bid = $this->level->getBlockID($x, $y, $z);
|
||||
if($bid > 0){
|
||||
$blockBounds = Block::$class[$bid]::getCollisionBoundingBoxes($this, $x, $y, $z, $e); //StaticBlock::getBoundingBoxForBlockCoords($b, $x, $y, $z);
|
||||
foreach($blockBounds as $blockBound){
|
||||
$aABBs[] = $blockBound;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue