swimming fixed

This commit is contained in:
GameHerobrine 2024-01-13 05:13:06 +03:00
parent 3d1dba6b86
commit 6eb13e5bd4
16 changed files with 170 additions and 16 deletions

View file

@ -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();

View file

@ -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){

View file

@ -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){

View file

@ -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)

View file

@ -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;

View file

@ -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){

View file

@ -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

View file

@ -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(){

View file

@ -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(){

View file

@ -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;

View file

@ -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;
}

View file

@ -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(){

View file

@ -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;
}

View file

@ -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
}
}
}
}