mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 19:49:44 +00:00
swimming fixed
This commit is contained in:
parent
3d1dba6b86
commit
6eb13e5bd4
16 changed files with 170 additions and 16 deletions
|
|
@ -319,7 +319,19 @@ class Entity extends Position
|
|||
$this->server->api->entity->drop($this, BlockAPI::getItem($drop[0] & 0xFFFF, $drop[1] & 0xFFFF, $drop[2] & 0xFF), true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
$hasUpdate = $this->class === ENTITY_MOB; // force true for mobs
|
||||
|
|
@ -372,7 +384,10 @@ class Entity extends Position
|
|||
$this->outOfWorld();
|
||||
$hasUpdate = true;
|
||||
}
|
||||
|
||||
if(!$this->isPlayer()){
|
||||
$this->handleWaterMovement();
|
||||
}
|
||||
|
||||
if($this->fire > 0){
|
||||
if(($this->fire % 20) === 0){
|
||||
$this->harm(1, "burning");
|
||||
|
|
@ -411,6 +426,8 @@ class Entity extends Position
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//air damage
|
||||
if($this->isPlayer() || $this instanceof Living){
|
||||
$d = $this->y + $this->getEyeHeight();
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ abstract class Living extends Entity implements Pathfindable{
|
|||
public $aiMoveSpeed;
|
||||
|
||||
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()){
|
||||
$this->target = false;
|
||||
$this->ai = new EntityAI($this);
|
||||
|
|
@ -115,7 +115,7 @@ abstract class Living extends Entity implements Pathfindable{
|
|||
|
||||
public function updateEntityMovement(){
|
||||
if(!$this->dead && Entity::$allowedAI && $this->idleTime <= 0) {
|
||||
//$this->ai->updateTasks();
|
||||
$this->ai->updateTasks();
|
||||
}
|
||||
//if($this->onGround){
|
||||
// if(!$this->hasPath() && $this->pathFinder instanceof ITileNavigator){
|
||||
|
|
@ -123,9 +123,27 @@ abstract class Living extends Entity implements Pathfindable{
|
|||
// }
|
||||
// $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->rotateTick();
|
||||
|
||||
$this->ai->mobController->jumpTick();
|
||||
|
||||
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->speedY) < self::MIN_POSSIBLE_SPEED) $this->speedY = 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){
|
||||
//TODO lava, water
|
||||
//If not in lava in water ->
|
||||
{
|
||||
if($this->inWater){ //also check is player, and can it fly or not
|
||||
$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;
|
||||
|
||||
if($this->onGround){
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ class MobController
|
|||
public $someTicker = 0;
|
||||
|
||||
protected $jumping;
|
||||
protected $jumpTimeout;
|
||||
|
||||
public $moveToX, $moveToY, $moveToZ;
|
||||
public $speed;
|
||||
|
|
@ -84,6 +83,11 @@ class MobController
|
|||
return $old + $v4;
|
||||
}
|
||||
|
||||
public function jumpTick(){
|
||||
$this->entity->jumping = $this->jumping;
|
||||
$this->jumping = false;
|
||||
}
|
||||
|
||||
public function movementTick(){
|
||||
$this->entity->moveForward = 0;
|
||||
if($this->updateMove){
|
||||
|
|
|
|||
|
|
@ -16,15 +16,12 @@ class TaskSwimming extends TaskBase
|
|||
{
|
||||
if(!$ai->entity->inWater){
|
||||
$this->reset();
|
||||
$ai->mobController->setJumping(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if(lcg_value() < 0.8){ #1.5.2 method
|
||||
$ai->mobController->setJumping(true);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function canBeExecuted(EntityAI $ai)
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ class Chicken extends Animal{
|
|||
$this->ai->addTask(new TaskLookAtPlayer(6));
|
||||
$this->ai->addTask(new TaskPanic(0.375));
|
||||
$this->ai->addTask(new TaskLookAround());
|
||||
$this->ai->addTask(new TaskSwimming());
|
||||
}
|
||||
public function isFood($id){
|
||||
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 TaskPanic(0.375));
|
||||
$this->ai->addTask(new TaskLookAround());
|
||||
|
||||
//$this->ai->addTask(new TaskSwimming());
|
||||
$this->ai->addTask(new TaskSwimming());
|
||||
}
|
||||
|
||||
public function isFood($id){
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ class Pig extends Animal implements Rideable{
|
|||
$this->ai->addTask(new TaskLookAtPlayer(6));
|
||||
$this->ai->addTask(new TaskPanic(0.375));
|
||||
$this->ai->addTask(new TaskLookAround());
|
||||
$this->ai->addTask(new TaskSwimming());
|
||||
}
|
||||
/**
|
||||
* @return boolean
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ class Sheep extends Animal{
|
|||
$this->ai->addTask(new TaskPanic(0.375));
|
||||
$this->ai->addTask(new TaskEatTileGoal());
|
||||
$this->ai->addTask(new TaskLookAround());
|
||||
$this->ai->addTask(new TaskSwimming());
|
||||
}
|
||||
|
||||
public function createSaveData(){
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ class Creeper extends Monster{
|
|||
|
||||
$this->ai->addTask(new TaskRandomWalk(0.25));
|
||||
$this->ai->addTask(new TaskLookAround());
|
||||
$this->ai->addTask(new TaskSwimming());
|
||||
}
|
||||
|
||||
public function getAttackDamage(){
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ class PigZombie extends Monster{
|
|||
|
||||
$this->ai->addTask(new TaskLookAround());
|
||||
$this->ai->addTask(new TaskRandomWalk(0.25));
|
||||
$this->ai->addTask(new TaskSwimming());
|
||||
}
|
||||
public function getAttackDamage(){
|
||||
return 5;
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ class Skeleton extends Monster{
|
|||
|
||||
$this->ai->addTask(new TaskRandomWalk(0.25));
|
||||
$this->ai->addTask(new TaskLookAround());
|
||||
$this->ai->addTask(new TaskSwimming());
|
||||
}
|
||||
|
||||
public function getAttackDamage(){
|
||||
|
|
@ -18,7 +19,7 @@ class Skeleton extends Monster{
|
|||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ class Spider extends Monster{
|
|||
$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 TaskLookAround()); //TODO this mob doesnt use newAI
|
||||
$this->ai->addTask(new TaskSwimming());
|
||||
}
|
||||
|
||||
public function getDrops(){
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ class Zombie extends Monster{
|
|||
|
||||
$this->ai->addTask(new TaskRandomWalk(0.25));
|
||||
$this->ai->addTask(new TaskLookAround());
|
||||
$this->ai->addTask(new TaskSwimming());
|
||||
}
|
||||
|
||||
public function getArmorValue(){
|
||||
|
|
@ -17,7 +18,7 @@ class Zombie extends Monster{
|
|||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@
|
|||
class FallingSand extends Entity{
|
||||
const TYPE = FALLING_SAND;
|
||||
const CLASS_TYPE = ENTITY_FALLING;
|
||||
|
||||
public $fallTime = 0;
|
||||
|
||||
public function __construct($level, $eid, $class, $type = 0, $data = []){
|
||||
parent::__construct($level, $eid, $class, $type, $data);
|
||||
$this->setHealth(PHP_INT_MAX, "generic");
|
||||
|
|
@ -12,4 +15,52 @@ class FallingSand extends Entity{
|
|||
$this->hasGravity = true;
|
||||
$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 $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 fallOn(Level $level, $x, $y, $z, Entity $entity, $fallDistance){}
|
||||
public static function getCollisionBoundingBoxes(Level $level, $x, $y, $z, Entity $entity){
|
||||
|
|
|
|||
|
|
@ -76,6 +76,47 @@ class Level{
|
|||
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 AxisAlignedBB $aABB
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue