mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-23 04:59:46 +00:00
arrows block collision fix, uncommented commented code
This commit is contained in:
parent
60be9fb2da
commit
2ce333af5e
3 changed files with 64 additions and 57 deletions
|
|
@ -1226,8 +1226,8 @@ class Player{
|
||||||
$motionSent = false;
|
$motionSent = false;
|
||||||
$moveSent = false;
|
$moveSent = false;
|
||||||
$headSent = false;
|
$headSent = false;
|
||||||
//if($e->speedX != 0 || $e->speedY != 0 || $e->speedZ != 0 || $e->speedY != $e->lastSpeedY || $e->speedX != $e->lastSpeedX || $e->speedZ != $e->lastSpeedZ){
|
if($e->speedX != 0 || $e->speedY != 0 || $e->speedZ != 0 || $e->speedY != $e->lastSpeedY || $e->speedX != $e->lastSpeedX || $e->speedZ != $e->lastSpeedZ){
|
||||||
// if(!($e->speedY < 0 && $e->onGround) || $e->speedX != 0 || $e->speedZ != 0 || $e->speedY != $e->lastSpeedY || $e->speedX != $e->lastSpeedX || $e->speedZ != $e->lastSpeedZ){
|
if(!($e->speedY < 0 && $e->onGround) || $e->speedX != 0 || $e->speedZ != 0 || $e->speedY != $e->lastSpeedY || $e->speedX != $e->lastSpeedX || $e->speedZ != $e->lastSpeedZ){
|
||||||
$motion = new SetEntityMotionPacket();
|
$motion = new SetEntityMotionPacket();
|
||||||
$motion->eid = $e->eid;
|
$motion->eid = $e->eid;
|
||||||
$motion->speedX = $e->speedX;
|
$motion->speedX = $e->speedX;
|
||||||
|
|
@ -1237,9 +1237,9 @@ class Player{
|
||||||
$len += 1 + strlen($motion->buffer);
|
$len += 1 + strlen($motion->buffer);
|
||||||
++$packets;
|
++$packets;
|
||||||
$motionSent = true;
|
$motionSent = true;
|
||||||
// }
|
}
|
||||||
//}
|
}
|
||||||
//if($e->x != $e->lastX || $e->y != $e->lastY || $e->z != $e->lastZ || $e->yaw != $e->lastYaw || $e->pitch != $e->lastPitch){
|
if($e->x != $e->lastX || $e->y != $e->lastY || $e->z != $e->lastZ || $e->yaw != $e->lastYaw || $e->pitch != $e->lastPitch){
|
||||||
$move = new MoveEntityPacket_PosRot();
|
$move = new MoveEntityPacket_PosRot();
|
||||||
$move->eid = $e->eid;
|
$move->eid = $e->eid;
|
||||||
$move->x = $e->x;
|
$move->x = $e->x;
|
||||||
|
|
@ -1251,8 +1251,8 @@ class Player{
|
||||||
$len += strlen($move->buffer) + 1;
|
$len += strlen($move->buffer) + 1;
|
||||||
++$packets;
|
++$packets;
|
||||||
$moveSent = true;
|
$moveSent = true;
|
||||||
//}
|
}
|
||||||
//if($e->headYaw != $e->lastHeadYaw){
|
if($e->headYaw != $e->lastHeadYaw){
|
||||||
$headyaw = new RotateHeadPacket();
|
$headyaw = new RotateHeadPacket();
|
||||||
$headyaw->eid = $e->eid;
|
$headyaw->eid = $e->eid;
|
||||||
$headyaw->yaw = $e->headYaw;
|
$headyaw->yaw = $e->headYaw;
|
||||||
|
|
@ -1260,7 +1260,7 @@ class Player{
|
||||||
$len += strlen($headyaw->buffer) + 1;
|
$len += strlen($headyaw->buffer) + 1;
|
||||||
++$packets;
|
++$packets;
|
||||||
$headSent = true;
|
$headSent = true;
|
||||||
//}
|
}
|
||||||
if($packets <= 0) return;
|
if($packets <= 0) return;
|
||||||
//console("Update {$e}: $packets, mot: $motionSent, mov: $moveSent, hed: $headSent");
|
//console("Update {$e}: $packets, mot: $motionSent, mov: $moveSent, hed: $headSent");
|
||||||
$MTU = $this->MTU - 24;
|
$MTU = $this->MTU - 24;
|
||||||
|
|
@ -1845,46 +1845,44 @@ class Player{
|
||||||
|
|
||||||
switch($packet->action){
|
switch($packet->action){
|
||||||
case 5: //Shot arrow
|
case 5: //Shot arrow
|
||||||
if($this->entity->inAction === true){
|
if($this->entity->inAction){
|
||||||
if($this->getSlot($this->slot)->getID() === BOW){
|
if($this->getSlot($this->slot)->getID() === BOW){ //TODO check arrow count
|
||||||
if($this->startAction !== false){
|
if($this->startAction !== false){
|
||||||
$time = microtime(true) - $this->startAction;
|
|
||||||
$d = [
|
|
||||||
"x" => $this->entity->x,
|
|
||||||
"y" => $this->entity->y + 1.6,
|
|
||||||
"z" => $this->entity->z,
|
|
||||||
"yaw" => $this->entity->yaw,
|
|
||||||
"pitch" => $this->entity->pitch
|
|
||||||
];
|
|
||||||
$e = $this->server->api->entity->add($this->level, ENTITY_OBJECT, OBJECT_ARROW, $d);
|
|
||||||
$e->speedX = -sin(($e->yaw / 180) * M_PI) * cos(($e->pitch / 180) * M_PI);
|
|
||||||
$e->speedZ = cos(($e->yaw / 180) * M_PI) * cos(($e->pitch / 180) * M_PI);
|
|
||||||
$e->speedY = -sin(($e->pitch / 180) * M_PI);
|
|
||||||
$e->shooterEID = $this->entity->eid;
|
|
||||||
$e->shotByEntity = true;
|
|
||||||
/**
|
|
||||||
* Max usage: 72000ticks
|
|
||||||
* initalPower = 72000 - (72000 - usedCtr)
|
|
||||||
* power = initialPower / 20'
|
|
||||||
* power = (power*power+power*2)/3
|
|
||||||
* powerMax is 1, powerMin is 0.1
|
|
||||||
* args: xvel, yvel, zvel, (power+power)*1.5, 1.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
$initalPower = $this->entity->inActionCounter;
|
$initalPower = $this->entity->inActionCounter;
|
||||||
$power = $initalPower / 20;
|
$power = $initalPower / 20;
|
||||||
$power = ($power * $power + $power * 2) / 3;
|
$power = ($power * $power + $power * 2) / 3;
|
||||||
if($power > 1.0) $power = 1;
|
if($power >= 0.1){
|
||||||
elseif($power < 0.1){
|
if($power > 1) $power = 1;
|
||||||
//CANCEL but i am too lazy
|
$this->server->dhandle("player.shoot", [
|
||||||
$power = 0.1;
|
"player" => $this,
|
||||||
}
|
"power" => &$power,
|
||||||
if(DEBUG){
|
]);
|
||||||
|
|
||||||
|
$d = [
|
||||||
|
"x" => $this->entity->x,
|
||||||
|
"y" => $this->entity->y + 1.6,
|
||||||
|
"z" => $this->entity->z,
|
||||||
|
"yaw" => $this->entity->yaw,
|
||||||
|
"pitch" => $this->entity->pitch
|
||||||
|
];
|
||||||
|
$e = $this->server->api->entity->add($this->level, ENTITY_OBJECT, OBJECT_ARROW, $d);
|
||||||
|
$e->speedX = -sin(($e->yaw / 180) * M_PI) * cos(($e->pitch / 180) * M_PI);
|
||||||
|
$e->speedZ = cos(($e->yaw / 180) * M_PI) * cos(($e->pitch / 180) * M_PI);
|
||||||
|
$e->speedY = -sin(($e->pitch / 180) * M_PI);
|
||||||
|
$e->shooterEID = $this->entity->eid;
|
||||||
|
$e->shotByEntity = true;
|
||||||
|
/**
|
||||||
|
* Max usage: 72000ticks
|
||||||
|
* initalPower = 72000 - (72000 - usedCtr)
|
||||||
|
* power = initialPower / 20'
|
||||||
|
* power = (power*power+power*2)/3
|
||||||
|
* powerMax is 1, powerMin is 0.1
|
||||||
|
* args: xvel, yvel, zvel, (power+power)*1.5, 1.0
|
||||||
|
*/
|
||||||
$e->critical = ($power === 1);
|
$e->critical = ($power === 1);
|
||||||
$e->shoot($e->speedX, $e->speedY, $e->speedZ, ($power+$power) * 1.5, 1.0);
|
$e->shoot($e->speedX, $e->speedY, $e->speedZ, ($power+$power) * 1.5, 1.0);
|
||||||
$this->server->api->entity->spawnToAll($e);
|
$this->server->api->entity->spawnToAll($e);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,15 +7,13 @@ class Arrow extends Projectile{
|
||||||
public $shooterEID = 0;
|
public $shooterEID = 0;
|
||||||
public $shotByEntity;
|
public $shotByEntity;
|
||||||
|
|
||||||
public $inWall = false;
|
|
||||||
public $groundTicks = 0;
|
|
||||||
|
|
||||||
public $xTile, $yTile, $zTile;
|
public $xTile, $yTile, $zTile;
|
||||||
public $inTile, $inData;
|
public $inTile, $inData;
|
||||||
public $shake;
|
public $shake;
|
||||||
public $inGround;
|
public $inGround;
|
||||||
public $airTicks = 0;
|
public $airTicks = 0;
|
||||||
public $criticial = false;
|
public $criticial = false;
|
||||||
|
public $groundTicks = 0;
|
||||||
|
|
||||||
function __construct(Level $level, $eid, $class, $type = 0, $data = [], $shooter = false){
|
function __construct(Level $level, $eid, $class, $type = 0, $data = [], $shooter = false){
|
||||||
parent::__construct($level, $eid, $class, $type, $data);
|
parent::__construct($level, $eid, $class, $type, $data);
|
||||||
|
|
@ -127,7 +125,25 @@ class Arrow extends Projectile{
|
||||||
}
|
}
|
||||||
|
|
||||||
if($this->inGround){
|
if($this->inGround){
|
||||||
//TODO despawn after 1200 if if & meta == this->inTIle, this->inData
|
|
||||||
|
$this->speedZ = $this->speedX = $this->speedY = 0;
|
||||||
|
|
||||||
|
[$blockID, $blockMeta] = $this->level->level->getBlock($this->xTile, $this->yTile, $this->zTile);
|
||||||
|
|
||||||
|
if($blockID == $this->inTile && $blockMeta == $this->inData){
|
||||||
|
++$this->groundTicks;
|
||||||
|
if($this->groundTicks >= 1200){ //TODO customizeable?
|
||||||
|
$this->close();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
$this->inGround = false;
|
||||||
|
$this->speedX *= lcg_value() * 0.2;
|
||||||
|
$this->speedY *= lcg_value() * 0.2;
|
||||||
|
$this->speedZ *= lcg_value() * 0.2;
|
||||||
|
$this->groundTicks = $this->airTicks = 0;
|
||||||
|
}
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
++$this->airTicks;
|
++$this->airTicks;
|
||||||
$start = new Vector3($this->x, $this->y, $this->z);
|
$start = new Vector3($this->x, $this->y, $this->z);
|
||||||
|
|
@ -144,7 +160,6 @@ class Arrow extends Projectile{
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO entity collisions
|
//TODO entity collisions
|
||||||
console($v4);
|
|
||||||
if($v4 != null){
|
if($v4 != null){
|
||||||
if($v4->entityHit != null){
|
if($v4->entityHit != null){
|
||||||
//TODO entity hit
|
//TODO entity hit
|
||||||
|
|
@ -191,8 +206,6 @@ class Arrow extends Projectile{
|
||||||
$this->boundingBox->setBounds($this->x - $v7, $this->y - $this->yOffset /*+ $this->ySize*/, $this->z - $v7, $this->x + $v7, $this->y - $this->yOffset + $v8 /*+ $this->ySize*/, $this->z + $v7);
|
$this->boundingBox->setBounds($this->x - $v7, $this->y - $this->yOffset /*+ $this->ySize*/, $this->z - $v7, $this->x + $v7, $this->y - $this->yOffset + $v8 /*+ $this->ySize*/, $this->z + $v7);
|
||||||
|
|
||||||
$this->doBlocksCollision();
|
$this->doBlocksCollision();
|
||||||
console($this);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -97,8 +97,7 @@ class Level{
|
||||||
|
|
||||||
[$startID, $startMeta] = $this->level->getBlock($xStart, $yStart, $zStart);
|
[$startID, $startMeta] = $this->level->getBlock($xStart, $yStart, $zStart);
|
||||||
$block = StaticBlock::getBlock($startID);
|
$block = StaticBlock::getBlock($startID);
|
||||||
console("($xStart, $yStart, $zStart): $startID");
|
|
||||||
console("start end: $start $end BEFORE");
|
|
||||||
//$block::updateShape($this, $xStart, $yStart, $zStart); //TODO better way to do it
|
//$block::updateShape($this, $xStart, $yStart, $zStart); //TODO better way to do it
|
||||||
$aabb = $block::getAABB($this, $xStart, $yStart, $zStart);
|
$aabb = $block::getAABB($this, $xStart, $yStart, $zStart);
|
||||||
if($startID > 0 && $aabb != null){ //TODO also block::canColideCheck
|
if($startID > 0 && $aabb != null){ //TODO also block::canColideCheck
|
||||||
|
|
@ -108,7 +107,7 @@ class Level{
|
||||||
|
|
||||||
for($i = 0; $i <= 200; ++$i){
|
for($i = 0; $i <= 200; ++$i){
|
||||||
|
|
||||||
if($xStart == $xEnd && $yStart == $yEnd && $zStart == $zEnd){ //also add checks for nan?
|
if(is_nan($start->x) || is_nan($start->y) || is_nan($start->z) || ($xStart == $xEnd && $yStart == $yEnd && $zStart == $zEnd)){ //also add checks for nan?
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -132,9 +131,9 @@ class Level{
|
||||||
$v29 = $end->y - $start->y;
|
$v29 = $end->y - $start->y;
|
||||||
$v31 = $end->z - $start->z;
|
$v31 = $end->z - $start->z;
|
||||||
|
|
||||||
if($v39) $v21 = ($v15 - $start->x) / $v27;
|
if($v39) $v21 = $v27 == 0 ? ($v15 - $start->x)*INF : ($v15 - $start->x) / $v27;
|
||||||
if($v40) $v23 = ($v17 - $start->y) / $v29;
|
if($v40) $v23 = $v29 == 0 ? ($v17 - $start->y)*INF : ($v17 - $start->y) / $v29;
|
||||||
if($v41) $v25 = ($v19 - $start->z) / $v31;
|
if($v41) $v25 = $v31 == 0 ? ($v19 - $start->z)*INF : ($v19 - $start->z) / $v31;
|
||||||
|
|
||||||
if($v21 < $v23 && $v21 < $v25){
|
if($v21 < $v23 && $v21 < $v25){
|
||||||
$v42 = $xEnd > $xStart ? 4 : 5;
|
$v42 = $xEnd > $xStart ? 4 : 5;
|
||||||
|
|
@ -167,15 +166,12 @@ class Level{
|
||||||
|
|
||||||
[$blockID, $blockMeta] = $this->level->getBlock($xStart, $yStart, $zStart);
|
[$blockID, $blockMeta] = $this->level->getBlock($xStart, $yStart, $zStart);
|
||||||
$block = StaticBlock::getBlock($blockID);
|
$block = StaticBlock::getBlock($blockID);
|
||||||
console("$i($xStart, $yStart, $zStart): $blockID");
|
|
||||||
console("start end: $start $end BEFORE");
|
|
||||||
|
|
||||||
$aabb = $block::getAABB($this, $xStart, $yStart, $zStart);
|
$aabb = $block::getAABB($this, $xStart, $yStart, $zStart);
|
||||||
if($startID > 0 && $aabb != null){ //TODO also block::canColideCheck
|
if($blockID > 0 && $aabb != null){ //TODO also block::canColideCheck
|
||||||
$v38 = $block::clip($this, $xStart, $yStart, $zStart, $start, $end);
|
$v38 = $block::clip($this, $xStart, $yStart, $zStart, $start, $end);
|
||||||
if($v38 != null) return $v38;
|
if($v38 != null) return $v38;
|
||||||
}
|
}
|
||||||
console("start end: $start $end AFTER");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue