mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-23 13:09:44 +00:00
swimming fixed
This commit is contained in:
parent
3d1dba6b86
commit
6eb13e5bd4
16 changed files with 170 additions and 16 deletions
|
|
@ -320,6 +320,18 @@ class Entity extends Position
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function handleWaterMovement(){
|
||||||
|
if($this->level->handleMaterialAcceleration($this->boundingBox->expand(0, -0.4, 0)->contract(0.001, 0.001, 0.001), 0, $this)){
|
||||||
|
$this->fallDistance = 0;
|
||||||
|
$this->inWater = true;
|
||||||
|
$this->fire = 0;
|
||||||
|
}else{
|
||||||
|
$this->inWater = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->inWater;
|
||||||
|
}
|
||||||
|
|
||||||
public function environmentUpdate($time)
|
public function environmentUpdate($time)
|
||||||
{
|
{
|
||||||
$hasUpdate = $this->class === ENTITY_MOB; // force true for mobs
|
$hasUpdate = $this->class === ENTITY_MOB; // force true for mobs
|
||||||
|
|
@ -372,6 +384,9 @@ class Entity extends Position
|
||||||
$this->outOfWorld();
|
$this->outOfWorld();
|
||||||
$hasUpdate = true;
|
$hasUpdate = true;
|
||||||
}
|
}
|
||||||
|
if(!$this->isPlayer()){
|
||||||
|
$this->handleWaterMovement();
|
||||||
|
}
|
||||||
|
|
||||||
if($this->fire > 0){
|
if($this->fire > 0){
|
||||||
if(($this->fire % 20) === 0){
|
if(($this->fire % 20) === 0){
|
||||||
|
|
@ -411,6 +426,8 @@ class Entity extends Position
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//air damage
|
//air damage
|
||||||
if($this->isPlayer() || $this instanceof Living){
|
if($this->isPlayer() || $this instanceof Living){
|
||||||
$d = $this->y + $this->getEyeHeight();
|
$d = $this->y + $this->getEyeHeight();
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ abstract class Living extends Entity implements Pathfindable{
|
||||||
public $aiMoveSpeed;
|
public $aiMoveSpeed;
|
||||||
|
|
||||||
public $renderYawOffset = 0.0; //used by head rotation, TODO better name
|
public $renderYawOffset = 0.0; //used by head rotation, TODO better name
|
||||||
|
public $jumping, $jumpTicks;
|
||||||
public function __construct(Level $level, $eid, $class, $type = 0, $data = array()){
|
public function __construct(Level $level, $eid, $class, $type = 0, $data = array()){
|
||||||
$this->target = false;
|
$this->target = false;
|
||||||
$this->ai = new EntityAI($this);
|
$this->ai = new EntityAI($this);
|
||||||
|
|
@ -115,7 +115,7 @@ abstract class Living extends Entity implements Pathfindable{
|
||||||
|
|
||||||
public function updateEntityMovement(){
|
public function updateEntityMovement(){
|
||||||
if(!$this->dead && Entity::$allowedAI && $this->idleTime <= 0) {
|
if(!$this->dead && Entity::$allowedAI && $this->idleTime <= 0) {
|
||||||
//$this->ai->updateTasks();
|
$this->ai->updateTasks();
|
||||||
}
|
}
|
||||||
//if($this->onGround){
|
//if($this->onGround){
|
||||||
// if(!$this->hasPath() && $this->pathFinder instanceof ITileNavigator){
|
// if(!$this->hasPath() && $this->pathFinder instanceof ITileNavigator){
|
||||||
|
|
@ -123,8 +123,26 @@ abstract class Living extends Entity implements Pathfindable{
|
||||||
// }
|
// }
|
||||||
// $this->pathFollower->followPath();
|
// $this->pathFollower->followPath();
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
|
||||||
|
//not exactly here
|
||||||
|
if($this->jumping){
|
||||||
|
if(!$this->inWater){ //TODO also lava
|
||||||
|
if($this->onGround && $this->jumpTicks <= 0){
|
||||||
|
//TODO jump $this->jump();
|
||||||
|
$this->jumpTicks = 10;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
$this->speedY += 0.04;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
$this->jumpTicks = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
$this->ai->mobController->movementTick();
|
$this->ai->mobController->movementTick();
|
||||||
$this->ai->mobController->rotateTick();
|
$this->ai->mobController->rotateTick();
|
||||||
|
$this->ai->mobController->jumpTick();
|
||||||
|
|
||||||
if(abs($this->speedX) < self::MIN_POSSIBLE_SPEED) $this->speedX = 0;
|
if(abs($this->speedX) < self::MIN_POSSIBLE_SPEED) $this->speedX = 0;
|
||||||
if(abs($this->speedZ) < self::MIN_POSSIBLE_SPEED) $this->speedZ = 0;
|
if(abs($this->speedZ) < self::MIN_POSSIBLE_SPEED) $this->speedZ = 0;
|
||||||
|
|
@ -147,10 +165,28 @@ abstract class Living extends Entity implements Pathfindable{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function counterUpdate(){
|
||||||
|
parent::counterUpdate();
|
||||||
|
if($this->jumpTicks > 0) --$this->jumpTicks;
|
||||||
|
}
|
||||||
|
|
||||||
public function moveEntityWithHeading($strafe, $forward){
|
public function moveEntityWithHeading($strafe, $forward){
|
||||||
//TODO lava, water
|
if($this->inWater){ //also check is player, and can it fly or not
|
||||||
//If not in lava in water ->
|
$this->moveFlying($strafe, $forward, 0.04); //TODO speed: this.isAIEnabled() ? 0.04F : 0.02F
|
||||||
{
|
$this->move($this->speedX, $this->speedY, $this->speedZ);
|
||||||
|
$this->speedX *= 0.8;
|
||||||
|
$this->speedY *= 0.8;
|
||||||
|
$this->speedZ *= 0.8;
|
||||||
|
$this->speedY -= 0.02;
|
||||||
|
|
||||||
|
//TODO: static speedY
|
||||||
|
//if (this.isCollidedHorizontally && this.isOffsetPositionInLiquid(this.motionX, this.motionY + 0.6 - this.posY + var9, this.motionZ))
|
||||||
|
//{
|
||||||
|
// this.motionY = 0.3;
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
//TODO lava
|
||||||
|
else{
|
||||||
$friction = 0.91;
|
$friction = 0.91;
|
||||||
|
|
||||||
if($this->onGround){
|
if($this->onGround){
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,6 @@ class MobController
|
||||||
public $someTicker = 0;
|
public $someTicker = 0;
|
||||||
|
|
||||||
protected $jumping;
|
protected $jumping;
|
||||||
protected $jumpTimeout;
|
|
||||||
|
|
||||||
public $moveToX, $moveToY, $moveToZ;
|
public $moveToX, $moveToY, $moveToZ;
|
||||||
public $speed;
|
public $speed;
|
||||||
|
|
@ -84,6 +83,11 @@ class MobController
|
||||||
return $old + $v4;
|
return $old + $v4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function jumpTick(){
|
||||||
|
$this->entity->jumping = $this->jumping;
|
||||||
|
$this->jumping = false;
|
||||||
|
}
|
||||||
|
|
||||||
public function movementTick(){
|
public function movementTick(){
|
||||||
$this->entity->moveForward = 0;
|
$this->entity->moveForward = 0;
|
||||||
if($this->updateMove){
|
if($this->updateMove){
|
||||||
|
|
|
||||||
|
|
@ -16,15 +16,12 @@ class TaskSwimming extends TaskBase
|
||||||
{
|
{
|
||||||
if(!$ai->entity->inWater){
|
if(!$ai->entity->inWater){
|
||||||
$this->reset();
|
$this->reset();
|
||||||
$ai->mobController->setJumping(false);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(lcg_value() < 0.8){ #1.5.2 method
|
if(lcg_value() < 0.8){ #1.5.2 method
|
||||||
$ai->mobController->setJumping(true);
|
$ai->mobController->setJumping(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function canBeExecuted(EntityAI $ai)
|
public function canBeExecuted(EntityAI $ai)
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ class Chicken extends Animal{
|
||||||
$this->ai->addTask(new TaskLookAtPlayer(6));
|
$this->ai->addTask(new TaskLookAtPlayer(6));
|
||||||
$this->ai->addTask(new TaskPanic(0.375));
|
$this->ai->addTask(new TaskPanic(0.375));
|
||||||
$this->ai->addTask(new TaskLookAround());
|
$this->ai->addTask(new TaskLookAround());
|
||||||
|
$this->ai->addTask(new TaskSwimming());
|
||||||
}
|
}
|
||||||
public function isFood($id){
|
public function isFood($id){
|
||||||
return $id === PUMPKIN_SEEDS || $id === MELON_SEEDS || $id === BEETROOT_SEEDS || $id === WHEAT_SEEDS;
|
return $id === PUMPKIN_SEEDS || $id === MELON_SEEDS || $id === BEETROOT_SEEDS || $id === WHEAT_SEEDS;
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,7 @@ class Cow extends Animal{
|
||||||
$this->ai->addTask(new TaskLookAtPlayer(6));
|
$this->ai->addTask(new TaskLookAtPlayer(6));
|
||||||
$this->ai->addTask(new TaskPanic(0.375));
|
$this->ai->addTask(new TaskPanic(0.375));
|
||||||
$this->ai->addTask(new TaskLookAround());
|
$this->ai->addTask(new TaskLookAround());
|
||||||
|
$this->ai->addTask(new TaskSwimming());
|
||||||
//$this->ai->addTask(new TaskSwimming());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isFood($id){
|
public function isFood($id){
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ class Pig extends Animal implements Rideable{
|
||||||
$this->ai->addTask(new TaskLookAtPlayer(6));
|
$this->ai->addTask(new TaskLookAtPlayer(6));
|
||||||
$this->ai->addTask(new TaskPanic(0.375));
|
$this->ai->addTask(new TaskPanic(0.375));
|
||||||
$this->ai->addTask(new TaskLookAround());
|
$this->ai->addTask(new TaskLookAround());
|
||||||
|
$this->ai->addTask(new TaskSwimming());
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @return boolean
|
* @return boolean
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ class Sheep extends Animal{
|
||||||
$this->ai->addTask(new TaskPanic(0.375));
|
$this->ai->addTask(new TaskPanic(0.375));
|
||||||
$this->ai->addTask(new TaskEatTileGoal());
|
$this->ai->addTask(new TaskEatTileGoal());
|
||||||
$this->ai->addTask(new TaskLookAround());
|
$this->ai->addTask(new TaskLookAround());
|
||||||
|
$this->ai->addTask(new TaskSwimming());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createSaveData(){
|
public function createSaveData(){
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ class Creeper extends Monster{
|
||||||
|
|
||||||
$this->ai->addTask(new TaskRandomWalk(0.25));
|
$this->ai->addTask(new TaskRandomWalk(0.25));
|
||||||
$this->ai->addTask(new TaskLookAround());
|
$this->ai->addTask(new TaskLookAround());
|
||||||
|
$this->ai->addTask(new TaskSwimming());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAttackDamage(){
|
public function getAttackDamage(){
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ class PigZombie extends Monster{
|
||||||
|
|
||||||
$this->ai->addTask(new TaskLookAround());
|
$this->ai->addTask(new TaskLookAround());
|
||||||
$this->ai->addTask(new TaskRandomWalk(0.25));
|
$this->ai->addTask(new TaskRandomWalk(0.25));
|
||||||
|
$this->ai->addTask(new TaskSwimming());
|
||||||
}
|
}
|
||||||
public function getAttackDamage(){
|
public function getAttackDamage(){
|
||||||
return 5;
|
return 5;
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ class Skeleton extends Monster{
|
||||||
|
|
||||||
$this->ai->addTask(new TaskRandomWalk(0.25));
|
$this->ai->addTask(new TaskRandomWalk(0.25));
|
||||||
$this->ai->addTask(new TaskLookAround());
|
$this->ai->addTask(new TaskLookAround());
|
||||||
|
$this->ai->addTask(new TaskSwimming());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAttackDamage(){
|
public function getAttackDamage(){
|
||||||
|
|
@ -18,7 +19,7 @@ class Skeleton extends Monster{
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateBurning(){
|
public function updateBurning(){
|
||||||
if($this->fire > 0 or !$this->level->isDay()){
|
if($this->fire > 0 or !$this->level->isDay() || $this->inWater){ //TODO fix burning in water
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ class Spider extends Monster{
|
||||||
$this->setSpeed(0.3);
|
$this->setSpeed(0.3);
|
||||||
$this->ai->addTask(new TaskRandomWalk(0.25)); //TODO this mob doesnt use newAI -> speed is not correct
|
$this->ai->addTask(new TaskRandomWalk(0.25)); //TODO this mob doesnt use newAI -> speed is not correct
|
||||||
$this->ai->addTask(new TaskLookAround()); //TODO this mob doesnt use newAI
|
$this->ai->addTask(new TaskLookAround()); //TODO this mob doesnt use newAI
|
||||||
|
$this->ai->addTask(new TaskSwimming());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDrops(){
|
public function getDrops(){
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ class Zombie extends Monster{
|
||||||
|
|
||||||
$this->ai->addTask(new TaskRandomWalk(0.25));
|
$this->ai->addTask(new TaskRandomWalk(0.25));
|
||||||
$this->ai->addTask(new TaskLookAround());
|
$this->ai->addTask(new TaskLookAround());
|
||||||
|
$this->ai->addTask(new TaskSwimming());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getArmorValue(){
|
public function getArmorValue(){
|
||||||
|
|
@ -17,7 +18,7 @@ class Zombie extends Monster{
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateBurning(){
|
public function updateBurning(){
|
||||||
if($this->fire > 0 or !$this->level->isDay()){
|
if($this->fire > 0 or !$this->level->isDay() || $this->inWater){ //TODO fix burning in water
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,9 @@
|
||||||
class FallingSand extends Entity{
|
class FallingSand extends Entity{
|
||||||
const TYPE = FALLING_SAND;
|
const TYPE = FALLING_SAND;
|
||||||
const CLASS_TYPE = ENTITY_FALLING;
|
const CLASS_TYPE = ENTITY_FALLING;
|
||||||
|
|
||||||
|
public $fallTime = 0;
|
||||||
|
|
||||||
public function __construct($level, $eid, $class, $type = 0, $data = []){
|
public function __construct($level, $eid, $class, $type = 0, $data = []){
|
||||||
parent::__construct($level, $eid, $class, $type, $data);
|
parent::__construct($level, $eid, $class, $type, $data);
|
||||||
$this->setHealth(PHP_INT_MAX, "generic");
|
$this->setHealth(PHP_INT_MAX, "generic");
|
||||||
|
|
@ -12,4 +15,52 @@ class FallingSand extends Entity{
|
||||||
$this->hasGravity = true;
|
$this->hasGravity = true;
|
||||||
$this->gravity = 0.04;
|
$this->gravity = 0.04;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function update($now){
|
||||||
|
if($this->closed) return;
|
||||||
|
|
||||||
|
if( $this->data["Tile"] == AIR) $this->close();
|
||||||
|
else {
|
||||||
|
$this->lastX = $this->x;
|
||||||
|
$this->lastY = $this->y;
|
||||||
|
$this->lastZ = $this->z;
|
||||||
|
++$this->fallTime;
|
||||||
|
$this->speedY -= 0.04;
|
||||||
|
$this->move($this->speedX, $this->speedY, $this->speedZ);
|
||||||
|
|
||||||
|
$this->speedX *= 0.98;
|
||||||
|
$this->speedY *= 0.98;
|
||||||
|
$this->speedZ *= 0.98;
|
||||||
|
|
||||||
|
$x = floor($this->x);
|
||||||
|
$y = floor($this->y);
|
||||||
|
$z = floot($this->z);
|
||||||
|
|
||||||
|
if($this->fallTime == 1){
|
||||||
|
/* i dont think this is needed here?
|
||||||
|
* if (this.worldObj.getBlockId(var1, var2, var3) != this.blockID)
|
||||||
|
{
|
||||||
|
this.setDead();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.worldObj.setBlockToAir(var1, var2, var3);
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
if($this->onGround){
|
||||||
|
$this->speedX *= 0.7;
|
||||||
|
$this->speedZ *= 0.7;
|
||||||
|
$this->speedY *= -0.5;
|
||||||
|
|
||||||
|
//1.5.2 has piston check, skipping
|
||||||
|
$this->close();
|
||||||
|
//if (!this.isBreakingAnvil && this.worldObj.canPlaceEntityOnSide(this.blockID, var1, var2, var3, true, 1, (Entity)null, (ItemStack)null) && !BlockSand.canFallBelow(this.worldObj, var1, var2 - 1, var3) && this.worldObj.setBlock(var1, var2, var3, this.blockID, this.metadata, 3))
|
||||||
|
//
|
||||||
|
//}
|
||||||
|
//a check if block has tilentity, might be added after tile entities rewrite
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -155,6 +155,7 @@ abstract class Block extends Position{
|
||||||
public $z = 0;
|
public $z = 0;
|
||||||
public $slipperiness;
|
public $slipperiness;
|
||||||
|
|
||||||
|
public static function addVelocityToEntity(Level $level, $x, $y, $z, Entity $entity, Vector3 $velocityVector){}
|
||||||
public static function onRandomTick(Level $level, $x, $y, $z){}
|
public static function onRandomTick(Level $level, $x, $y, $z){}
|
||||||
public static function fallOn(Level $level, $x, $y, $z, Entity $entity, $fallDistance){}
|
public static function fallOn(Level $level, $x, $y, $z, Entity $entity, $fallDistance){}
|
||||||
public static function getCollisionBoundingBoxes(Level $level, $x, $y, $z, Entity $entity){
|
public static function getCollisionBoundingBoxes(Level $level, $x, $y, $z, Entity $entity){
|
||||||
|
|
|
||||||
|
|
@ -76,6 +76,47 @@ class Level{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO public function canPlaceEntityOnSide()
|
||||||
|
|
||||||
|
public function handleMaterialAcceleration(AxisAlignedBB $aabb, $materialType, Entity $entity){
|
||||||
|
$minX = floor($aabb->minX);
|
||||||
|
$maxX = ceil($aabb->maxX);
|
||||||
|
$minY = floor($aabb->minY);
|
||||||
|
$maxY = ceil($aabb->maxY);
|
||||||
|
$minZ = floor($aabb->minZ);
|
||||||
|
$maxZ = ceil($aabb->maxZ);
|
||||||
|
|
||||||
|
//1.5.2 checks that all chunks exist, not needed here i think
|
||||||
|
|
||||||
|
$appliedVelocity = false;
|
||||||
|
$velocityVec = new Vector3(0, 0, 0);
|
||||||
|
|
||||||
|
for($x = $minX; $x < $maxX; ++$x){
|
||||||
|
for($y = $minY; $y < $maxY; ++$y){
|
||||||
|
for($z = $minZ; $z < $maxZ; ++$z){
|
||||||
|
[$block, $meta] = $this->level->getBlock($x, $y, $z);
|
||||||
|
if(($materialType == 0 && ($block == WATER || $block == STILL_WATER)) || ($materialType == 1 && ($block == LAVA || $block == STILL_LAVA))){ //TODO better material system
|
||||||
|
$v16 = ($y + 1) - LiquidBlock::getPercentAir($meta);
|
||||||
|
if($maxY >= $v16){
|
||||||
|
$appliedVelocity = true;
|
||||||
|
Block::$class[$block]::addVelocityToEntity($this, $x, $y, $z, $entity, $velocityVec);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if($velocityVec->length() > 0){ //also checks is player flying
|
||||||
|
$velocityVec = $velocityVec->normalize(); //TODO do not use vec methods
|
||||||
|
$v18 = 0.014;
|
||||||
|
$entity->speedX += $velocityVec->x * $v18;
|
||||||
|
$entity->speedY += $velocityVec->y * $v18;
|
||||||
|
$entity->speedZ += $velocityVec->z * $v18;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $appliedVelocity;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Entity $e
|
* @param Entity $e
|
||||||
* @param AxisAlignedBB $aABB
|
* @param AxisAlignedBB $aABB
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue