From 5f1774b8ce1eebd8f68a41248b9236877294d648 Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Wed, 31 Jan 2024 04:26:54 +0300 Subject: [PATCH] inWeb, fire damage" --- src/Player.php | 1 + src/entity/Entity.php | 71 +++++++++++++++++++--- src/entity/object/ItemEntity.php | 9 ++- src/material/Block.php | 3 + src/material/block/nonfull/CobwebBlock.php | 6 +- src/world/Level.php | 6 +- 6 files changed, 80 insertions(+), 16 deletions(-) diff --git a/src/Player.php b/src/Player.php index fa4eb5f4..5caa83f5 100755 --- a/src/Player.php +++ b/src/Player.php @@ -2332,6 +2332,7 @@ class Player{ $this->entity->linkedEntity->setPosition($this->entity); $this->entity->linkedEntity->sendMoveUpdate(); + //$this->entity->linkedEntity->moveFlying($packet->moveStrafe, $packet->moveForward, 1); } break; diff --git a/src/entity/Entity.php b/src/entity/Entity.php index 088283be..99fec561 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -91,6 +91,12 @@ class Entity extends Position public $chunkZ = 0; public $isCollidedHorizontally, $isCollidedVertically, $isCollided; + /** + * Amount of ticks you can be in fire until you start receiving damage + * @var integer + */ + public $fireResistance = 1; + public $inWeb; function __construct(Level $level, $eid, $class, $type = 0, $data = array()) { @@ -156,6 +162,7 @@ class Entity extends Position $this->hasKnockback = true; $this->hasGravity = true; $this->canBeAttacked = true; + $this->fireResistance = 20; //TODO fire resiatance for player break; case ENTITY_OBJECT: $this->x = isset($this->data["TileX"]) ? $this->data["TileX"] : $this->x; @@ -191,6 +198,11 @@ class Entity extends Position } + public function setInWeb(){ + $this->inWeb = true; + $this->fallDistance = 0; + } + public function addVelocity($vX, $vY = 0, $vZ = 0) { if($vX instanceof Vector3){ @@ -394,7 +406,7 @@ class Entity extends Position $this->handleWaterMovement(); } - if($this->fire > 0){ + if($this->fire > 0){ //TODO move somewhere if(($this->fire % 20) === 0){ $this->harm(1, "burning"); } @@ -446,7 +458,7 @@ class Entity extends Position $f = LiquidBlock::getPercentAir($this->level->level->getBlockDamage($x, $y, $z)) - 0.1111111; $f1 = ($y + 1) - $f; if($d < $f1){ - $this->air -= 1*$tickDiff; + $this->air -= $tickDiff; if($this->air <= -20){ $this->harm(2, "water"); $this->air = 0; //harm every 1 second @@ -515,7 +527,7 @@ class Entity extends Position public function moveFlying($strafe, $forward, $speed){ //TODO rename? $v4 = $strafe*$strafe + $forward*$forward; - if($v4 >= 1.0e-4){ //TODO dont use ugly scienfitic notation + if($v4 >= 0.0001){ $v4 = sqrt($v4); if($v4 < 1) $v4 = 1; @@ -532,14 +544,44 @@ class Entity extends Position } public function updateEntityMovement(){} - + + public function doBlocksCollision(){ + $minX = floor($this->boundingBox->minX + 0.001); + $minY = floor($this->boundingBox->minY + 0.001); + $minZ = floor($this->boundingBox->minZ + 0.001); + $maxX = floor($this->boundingBox->maxX - 0.001); + $maxY = floor($this->boundingBox->maxY - 0.001); + $maxZ = floor($this->boundingBox->maxZ - 0.001); + + for($x = $minX; $x <= $maxX; ++$x){ + for($y = $minY; $y <= $maxY; ++$y){ + for($z = $minZ; $z <= $maxZ; ++$z){ + $id = $this->level->level->getBlockID($x, $y, $z); + + if($id > 0){ + Block::$class[$id]::onEntityCollidedWithBlock($this->level, $x, $y, $z, $this); + } + } + } + } + + } + public function move($dx, $dy, $dz){ - //TODO ySize? $movX = $this->x; $movY = $this->y; $movZ = $this->z; - //TODO isInWeb + if($this->inWeb){ + $this->inWeb = false; + $dx *= 0.25; + $dy *= 0.05; + $dz *= 0.25; + + $this->speedX = $this->speedY = $this->speedZ = 0; + } + + $savedDX = $dx; $savedDY = $dy; $savedDZ = $dz; @@ -636,12 +678,21 @@ class Entity extends Position //TODO more stuff -> onEntityWalking - //TODO block collisions? + $this->doBlocksCollision(); - //TODO deal fire damage here if($this->level->isBoundingBoxOnFire($this->boundingBox->contract(0.001, 0.001, 0.001))){ - + $this->harm(1, "fire"); + if($this->inWater){ + ++$this->fire; + if($this->fire == 0) $this->fire = 8; + } + }else if($this->fire <= 0){ + $this->fire = -$this->fireResistance; + } + + if($this->inWater && $this->fire > 0){ + $this->fire = -$this->fireResistance; } } @@ -1285,7 +1336,7 @@ class Entity extends Position if (! $this->canBeAttacked) { return false; } - $dmg = $this->applyArmor($dmg, $cause); //TODO HURTCAM + $dmg = $this->applyArmor($dmg, $cause); $ret = $this->setHealth(max(- 128, $this->getHealth() - ((int) $dmg)), $cause, $force); if ($ret != false && $this->hasKnockback && is_numeric($cause) && ($entity = $this->server->api->entity->get($cause)) != false) { diff --git a/src/entity/object/ItemEntity.php b/src/entity/object/ItemEntity.php index 4d036849..7e8d711d 100644 --- a/src/entity/object/ItemEntity.php +++ b/src/entity/object/ItemEntity.php @@ -86,8 +86,13 @@ class ItemEntity extends Entity{ $var1 = (int)$this->x != (int)$this->lastX || (int)$this->y != (int)$this->lastY || (int)$this->z != (int)$this->lastZ; - if($var1 || $this->counter % 25 == 0/* || $this->ticksExisted % 25 == 0*/){ //TODO ticksExisted(should be alternative in nc already) - //TODO check material + if($var1 || $this->counter % 25 == 0){ + $blockIDAt = $this->level->level->getBlockID(floor($this->x), floor($this->y), floor($this->z)); + if($blockIDAt == LAVA || $blockIDAt == STILL_LAVA){ + $this->speedY = 0.2; + $this->speedX = (lcg_value() - lcg_value()) * 0.2; + $this->speedZ = (lcg_value() - lcg_value()) * 0.2; + } $this->searchForOtherItemsNearby(); //not in vanilla 0.8.1 } diff --git a/src/material/Block.php b/src/material/Block.php index 17c89272..4884c85e 100755 --- a/src/material/Block.php +++ b/src/material/Block.php @@ -175,6 +175,9 @@ abstract class Block extends Position{ public static function getCollisionBoundingBoxes(Level $level, $x, $y, $z, Entity $entity){ return [new AxisAlignedBB($x, $y, $z, $x, $y, $z)]; } + public static function onEntityCollidedWithBlock(Level $level, $x, $y, $z, Entity $entity){} + + public function __construct($id, $meta = 0, $name = "Unknown"){ $this->id = (int) $id; $this->meta = (int) $meta; diff --git a/src/material/block/nonfull/CobwebBlock.php b/src/material/block/nonfull/CobwebBlock.php index b969f4a4..0982b960 100644 --- a/src/material/block/nonfull/CobwebBlock.php +++ b/src/material/block/nonfull/CobwebBlock.php @@ -18,5 +18,9 @@ class CobwebBlock extends FlowableBlock{ array(COBWEB, 0, 1), ]; } - } + } + + public static function onEntityCollidedWithBlock(Level $level, $x, $y, $z, Entity $entity){ + $entity->setInWeb(); + } } \ No newline at end of file diff --git a/src/world/Level.php b/src/world/Level.php index 12e80a1b..0c1a8eb7 100644 --- a/src/world/Level.php +++ b/src/world/Level.php @@ -454,11 +454,11 @@ class Level{ public function isBoundingBoxOnFire(AxisAlignedBB $bb){ $minX = floor($bb->minX); - $maxX = ceil($bb->maxX); + $maxX = floor($bb->maxX + 1); $minY = floor($bb->minY); - $maxY = ceil($bb->maxY); + $maxY = floor($bb->maxY + 1); $minZ = floor($bb->minZ); - $maxZ = ceil($bb->maxZ); + $maxZ = floor($bb->maxZ + 1); for($x = $minX; $x < $maxX; ++$x){ for($y = $minY; $y < $maxY; ++$y){