mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 11:39:43 +00:00
item physics test
This commit is contained in:
parent
828599184c
commit
3892d697f8
5 changed files with 51 additions and 29 deletions
|
|
@ -239,31 +239,43 @@ class EntityAPI{
|
|||
$e->setHealth($e->getHealth() - $attack, $cause, $force);
|
||||
}
|
||||
|
||||
public function dropRawPos(Position $pos, $item, $speedX, $speedY, $speedZ){
|
||||
if($item->getID() === AIR or $item->count <= 0){
|
||||
return;
|
||||
}
|
||||
$data = [
|
||||
"x" => $pos->x,
|
||||
"y" => $pos->y,
|
||||
"z" => $pos->z,
|
||||
"level" => $pos->level,
|
||||
"speedX" => $speedX,
|
||||
"speedY" => $speedY,
|
||||
"speedZ" => $speedZ,
|
||||
"item" => $item,
|
||||
];
|
||||
if($this->server->api->handle("item.drop", $data) !== false){
|
||||
for($count = $item->count; $count > 0;){
|
||||
$item->count = min($item->getMaxStackSize(), $count);
|
||||
$count -= $item->count;
|
||||
$e = $this->add($pos->level, ENTITY_ITEM, $item->getID(), $data);
|
||||
$this->spawnToAll($e);
|
||||
$this->server->api->handle("entity.motion", $e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function drop(Position $pos, Item $item){
|
||||
if($item->getID() === AIR or $item->count <= 0){
|
||||
return;
|
||||
}
|
||||
$i = 0;
|
||||
do{ // drop the block to the first supporting block
|
||||
$i++;
|
||||
$v = new Vector3($pos->x, $pos->y - $i, $pos->z);
|
||||
$b = $pos->level->getBlock($v);
|
||||
if($b->isSolid === true)
|
||||
break;
|
||||
if(($b instanceof LiquidBlock) or $b->getID() === COBWEB or $b->getID() === LADDER or $b->getID() === FENCE or $b->getID() === STONE_WALL)
|
||||
break;
|
||||
|
||||
}while($i < 200);
|
||||
$i %= 200; //if i >= 200, set to 0..1..2..199
|
||||
|
||||
$data = [
|
||||
"x" => $pos->x + mt_rand(-10, 10) / 50,
|
||||
"y" => $pos->y + 0.19 + 1 - $i,
|
||||
"y" => $pos->y + 0.19,
|
||||
"z" => $pos->z + mt_rand(-10, 10) / 50,
|
||||
"level" => $pos->level,
|
||||
//"speedX" => mt_rand(-3, 3) / 8,
|
||||
//"speedY" => mt_rand(5, 8) / 2, speed is handled differently now
|
||||
//"speedZ" => mt_rand(-3, 3) / 8,
|
||||
"speedX" => Utils::randomFloat() * 0.2 - 0.1,
|
||||
"speedY" => 0.2,
|
||||
"speedZ" => Utils::randomFloat() * 0.2 - 0.1,
|
||||
"item" => $item,
|
||||
];
|
||||
if($this->server->api->handle("item.drop", $data) !== false){
|
||||
|
|
|
|||
|
|
@ -1897,7 +1897,18 @@ class Player{
|
|||
$data["item"] = $packet->item;
|
||||
$data["player"] = $this;
|
||||
if($this->blocked === false and $this->server->handle("player.drop", $data) !== false){
|
||||
$this->server->api->entity->drop(new Position($this->entity->x - 0.5, $this->entity->y, $this->entity->z - 0.5, $this->level), $packet->item);
|
||||
$f1 = 0.3;
|
||||
$sX = -sin(($this->entity->yaw / 180) * M_PI) * cos(($this->entity->pitch / 180) * M_PI) * $f1;
|
||||
$sZ = cos(($this->entity->yaw / 180) * M_PI) * cos(($this->entity->pitch / 180) * M_PI) * $f1;
|
||||
$sY = -sin(($this->entity->pitch / 180) * M_PI) * $f1 + 0.1;
|
||||
$f1 = 0.02;
|
||||
$f3 = $this->entity->random->nextFloat() * M_PI * 2.0;
|
||||
$f1 *= $this->entity->random->nextFloat();
|
||||
$sX += cos($f3) * $f1;
|
||||
$sY += ($this->entity->random->nextFloat() - $this->entity->random->nextFloat()) * 0.1;
|
||||
$sZ += sin($f3) * $f1;
|
||||
|
||||
$this->server->api->entity->dropRawPos(new Position($this->entity->x, $this->entity->y - 0.3 + $this->entity->height - 0.12, $this->entity->z, $this->level), $packet->item, $sX, $sY, $sZ);
|
||||
$this->setSlot($this->slot, BlockAPI::getItem(AIR, 0, 0), false);
|
||||
}
|
||||
if($this->entity->inAction === true){
|
||||
|
|
|
|||
|
|
@ -139,12 +139,7 @@ class Entity extends Position
|
|||
}
|
||||
$this->hasGravity = true;
|
||||
$this->setHealth(5, "generic");
|
||||
$this->server->schedule(6010, array(
|
||||
$this,
|
||||
"update"
|
||||
)); // Despawn
|
||||
$this->height = 0.75;
|
||||
$this->width = 0.75;
|
||||
$this->setSize(0.25, 0.25);
|
||||
break;
|
||||
case ENTITY_FALLING:
|
||||
$this->setHealth(PHP_INT_MAX, "generic");
|
||||
|
|
@ -170,6 +165,7 @@ class Entity extends Position
|
|||
break;
|
||||
}
|
||||
$this->boundingBox = new AxisAlignedBB($this->x - $this->radius, $this->y, $this->z - $this->radius, $this->x + $this->radius, $this->y + $this->height, $this->z + $this->radius);
|
||||
$this->update();
|
||||
$this->updateLast();
|
||||
$this->updatePosition();
|
||||
if($this->isInVoid()){
|
||||
|
|
@ -331,7 +327,7 @@ class Entity extends Position
|
|||
$hasUpdate = Entity::$updateOnTick ? $this->class === ENTITY_MOB : false; // force true for mobs
|
||||
$time = microtime(true);
|
||||
if($this->class === ENTITY_PLAYER and ($this->player instanceof Player) and $this->player->spawned === true and $this->player->blocked !== true && ! $this->dead){
|
||||
foreach($this->server->api->entity->getRadius($this, 1.5, ENTITY_ITEM) as $item){
|
||||
foreach($this->server->api->entity->getRadius($this, 1, ENTITY_ITEM) as $item){
|
||||
if(! $item->closed && $item->spawntime > 0 && ($time - $item->spawntime) >= 0.6){
|
||||
if((($this->player->gamemode & 0x01) === 1 || $this->player->hasSpace($item->type, $item->meta, $item->stack) === true) && $this->server->api->dhandle("player.pickup", array(
|
||||
"eid" => $this->player->eid,
|
||||
|
|
@ -535,6 +531,7 @@ class Entity extends Position
|
|||
if(Utils::in_range($this->speedY, - 0.001, 0.001)){
|
||||
$this->speedY = 0;
|
||||
}
|
||||
|
||||
if(($this->class === ENTITY_MOB || $this->class === ENTITY_ITEM || ($this->class === ENTITY_OBJECT && $this->type === OBJECT_PRIMEDTNT)) && ($this->speedX != 0 || $this->speedY != 0 || $this->speedZ != 0)){
|
||||
$blocks = $this->level->getCubes($this->boundingBox->getOffsetBoundingBox($this->speedX, $this->speedY, $this->speedZ));
|
||||
foreach($blocks as $b){
|
||||
|
|
@ -585,7 +582,7 @@ class Entity extends Position
|
|||
}
|
||||
|
||||
if($this->hasGravity && $support === false){
|
||||
$this->speedY -= $this->class === ENTITY_FALLING ? 0.04 : 0.08; // TODO: replace with $gravity
|
||||
$this->speedY -= ($this->class === ENTITY_FALLING) ? 0.04 : ($this->class === ENTITY_ITEM ? 0.06 : 0.08); // TODO: replace with $gravity
|
||||
$update = true;
|
||||
} else{
|
||||
// $this->speedX = 0;
|
||||
|
|
|
|||
|
|
@ -4,12 +4,12 @@ class Chicken extends Animal{
|
|||
const TYPE = MOB_CHICKEN;
|
||||
public $timeUntilEgg;
|
||||
function __construct(Level $level, $eid, $class, $type = 0, $data = []){
|
||||
$this->timeUntilEgg = mt_rand(0,6000) + 6000;
|
||||
parent::__construct($level, $eid, $class, $type, $data);
|
||||
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 4, "generic");
|
||||
$this->setName('Chicken');
|
||||
$this->setSize($this->isBaby() ? 0.2 : 0.4, $this->isBaby() ? 0.35 : 0.7);
|
||||
$this->setSpeed(0.25);
|
||||
$this->timeUntilEgg = mt_rand(0,6000) + 6000;
|
||||
$this->update();
|
||||
}
|
||||
public function isFood($id){
|
||||
|
|
|
|||
|
|
@ -36,6 +36,8 @@ class Level{
|
|||
public function close(){
|
||||
$this->__destruct();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param AxisAlignedBB $aABB
|
||||
* @return AxisAlignedBB[]
|
||||
|
|
@ -55,9 +57,9 @@ class Level{
|
|||
$y1 = $y1 > 128 ? 128 : $y1;
|
||||
$z1 = $z1 > 256 ? 256 : $z1;
|
||||
|
||||
for($x = $x0; $x <= $x1; ++$x) {
|
||||
for($x = $x0; $x < $x1; ++$x) {
|
||||
for($y = $y0; $y < $y1; ++$y) {
|
||||
for($z = $z0; $z <= $z1; ++$z) {
|
||||
for($z = $z0; $z < $z1; ++$z) {
|
||||
$b = $this->getBlockWithoutVector($x, $y, $z);
|
||||
if($b != false && $b->boundingBox->intersectsWith($aABB) && $b->isSolid) {
|
||||
$aABBs[] = $b->boundingBox;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue