mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-13 09:19:42 +00:00
Fixed items doing crazy things
This commit is contained in:
parent
d5ba2a72a5
commit
c9adc336ee
@ -776,13 +776,11 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
|||||||
public function sleepOn(Vector3 $pos){
|
public function sleepOn(Vector3 $pos){
|
||||||
foreach($this->level->getNearbyEntities($this->boundingBox->grow(2, 1, 2), $this) as $p){
|
foreach($this->level->getNearbyEntities($this->boundingBox->grow(2, 1, 2), $this) as $p){
|
||||||
if($p instanceof Player){
|
if($p instanceof Player){
|
||||||
if($p->sleeping !== null){
|
if($p->sleeping !== null and $pos->distance($p->sleeping) <= 0.1){
|
||||||
if($pos->distance($p->sleeping) <= 0.1){
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
$this->server->getPluginManager()->callEvent($ev = new PlayerBedEnterEvent($this, $this->level->getBlock($pos)));
|
$this->server->getPluginManager()->callEvent($ev = new PlayerBedEnterEvent($this, $this->level->getBlock($pos)));
|
||||||
if($ev->isCancelled()){
|
if($ev->isCancelled()){
|
||||||
@ -790,7 +788,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->sleeping = clone $pos;
|
$this->sleeping = clone $pos;
|
||||||
$this->teleport(new Position($pos->x + 0.5, $pos->y + 1, $pos->z + 0.5, $this->level));
|
//$this->teleport(new Position($pos->x + 0.5, $pos->y + 1, $pos->z + 0.5, $this->level));
|
||||||
|
|
||||||
$this->setDataProperty(self::DATA_PLAYER_BED_POSITION, self::DATA_TYPE_POS, [$pos->x, $pos->y, $pos->z]);
|
$this->setDataProperty(self::DATA_PLAYER_BED_POSITION, self::DATA_TYPE_POS, [$pos->x, $pos->y, $pos->z]);
|
||||||
$this->setDataFlag(self::DATA_PLAYER_FLAGS, self::DATA_PLAYER_FLAG_SLEEP, true);
|
$this->setDataFlag(self::DATA_PLAYER_FLAGS, self::DATA_PLAYER_FLAG_SLEEP, true);
|
||||||
@ -856,8 +854,6 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1024,7 +1020,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
|||||||
|
|
||||||
protected function getCreativeBlock(Item $item){
|
protected function getCreativeBlock(Item $item){
|
||||||
foreach(Block::$creative as $i => $d){
|
foreach(Block::$creative as $i => $d){
|
||||||
if($d[0] === $item->getId() and $d[1] === $item->getDamage()){
|
if($d[0] === $item->getId() and ($item->isTool() or $d[1] === $item->getDamage())){
|
||||||
return $i;
|
return $i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1772,12 +1768,10 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
|||||||
case 5: //Shot arrow
|
case 5: //Shot arrow
|
||||||
if($this->startAction > -1 and $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ACTION) and $this->inventory->getItemInHand()->getId() === Item::BOW){
|
if($this->startAction > -1 and $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ACTION) and $this->inventory->getItemInHand()->getId() === Item::BOW){
|
||||||
$bow = $this->inventory->getItemInHand();
|
$bow = $this->inventory->getItemInHand();
|
||||||
if($this->isSurvival()){
|
if($this->isSurvival() and !$this->inventory->contains(Item::get(Item::ARROW, 0, 1))){
|
||||||
if(!$this->inventory->contains(Item::get(Item::ARROW, 0, 1))){
|
|
||||||
$this->inventory->sendContents($this);
|
$this->inventory->sendContents($this);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
$nbt = new Compound("", [
|
$nbt = new Compound("", [
|
||||||
@ -1798,22 +1792,19 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
$diff = ($this->server->getTick() - $this->startAction);
|
$diff = ($this->server->getTick() - $this->startAction);
|
||||||
if($diff < 5){
|
|
||||||
$this->inventory->sendContents($this);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
$p = $diff / 20;
|
$p = $diff / 20;
|
||||||
$f = min((($p ** 2) + $p * 2) / 3, 1) * 2;
|
$f = min((($p ** 2) + $p * 2) / 3, 1) * 2;
|
||||||
if($f < 0.1){
|
|
||||||
$this->inventory->sendContents($this);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
$ev = new EntityShootBowEvent($this, $bow, Entity::createEntity("Arrow", $this->chunk, $nbt, $this, $f == 2 ? true : false), $f);
|
$ev = new EntityShootBowEvent($this, $bow, Entity::createEntity("Arrow", $this->chunk, $nbt, $this, $f == 2 ? true : false), $f);
|
||||||
|
|
||||||
|
if($f < 0.1 or $diff < 5){
|
||||||
|
$ev->setCancelled();
|
||||||
|
}
|
||||||
|
|
||||||
$this->server->getPluginManager()->callEvent($ev);
|
$this->server->getPluginManager()->callEvent($ev);
|
||||||
|
|
||||||
if($ev->isCancelled()){
|
if($ev->isCancelled()){
|
||||||
$ev->getProjectile()->kill();
|
$ev->getProjectile()->kill();
|
||||||
|
$this->inventory->sendContents($this);
|
||||||
}else{
|
}else{
|
||||||
$ev->getProjectile()->setMotion($ev->getProjectile()->getMotion()->multiply($ev->getForce()));
|
$ev->getProjectile()->setMotion($ev->getProjectile()->getMotion()->multiply($ev->getForce()));
|
||||||
if($this->isSurvival()){
|
if($this->isSurvival()){
|
||||||
|
@ -534,7 +534,6 @@ abstract class Entity extends Location implements Metadatable{
|
|||||||
|
|
||||||
$this->setLastDamageCause($source);
|
$this->setLastDamageCause($source);
|
||||||
|
|
||||||
|
|
||||||
$this->setHealth($this->getHealth() - $source->getFinalDamage());
|
$this->setHealth($this->getHealth() - $source->getFinalDamage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -615,29 +614,25 @@ abstract class Entity extends Location implements Metadatable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected function checkObstruction($x, $y, $z){
|
protected function checkObstruction($x, $y, $z){
|
||||||
$i = (int) $x;
|
$i = Math::floorFloat($x);
|
||||||
$j = (int) $y;
|
$j = Math::floorFloat($y);
|
||||||
$k = (int) $z;
|
$k = Math::floorFloat($z);
|
||||||
|
|
||||||
$diffX = $x - $i;
|
$diffX = $x - $i;
|
||||||
$diffY = $y - $j;
|
$diffY = $y - $j;
|
||||||
$diffZ = $z - $k;
|
$diffZ = $z - $k;
|
||||||
|
|
||||||
$list = $this->level->getCollisionBlocks($this->boundingBox);
|
|
||||||
|
|
||||||
$v = new Vector3($i, $j, $k);
|
$v = new Vector3($i, $j, $k);
|
||||||
|
|
||||||
if(count($list) === 0 and !$this->level->isFullBlock($v->setComponents($i, $j, $k))){
|
if($this->level->isFullBlock($v)){
|
||||||
return false;
|
|
||||||
}else{
|
|
||||||
$flag = !$this->level->isFullBlock($v->setComponents($i - 1, $j, $k));
|
$flag = !$this->level->isFullBlock($v->setComponents($i - 1, $j, $k));
|
||||||
$flag1 = !$this->level->isFullBlock($v->setComponents($i + 1, $j, $k));
|
$flag1 = !$this->level->isFullBlock($v->setComponents($i + 1, $j, $k));
|
||||||
//$flag2 = !$this->level->isFullBlock($v->setComponents($i, $j - 1, $k));
|
$flag2 = !$this->level->isFullBlock($v->setComponents($i, $j - 1, $k));
|
||||||
$flag3 = !$this->level->isFullBlock($v->setComponents($i, $j + 1, $k));
|
$flag3 = !$this->level->isFullBlock($v->setComponents($i, $j + 1, $k));
|
||||||
$flag4 = !$this->level->isFullBlock($v->setComponents($i, $j, $k - 1));
|
$flag4 = !$this->level->isFullBlock($v->setComponents($i, $j, $k - 1));
|
||||||
$flag5 = !$this->level->isFullBlock($v->setComponents($i, $j, $k + 1));
|
$flag5 = !$this->level->isFullBlock($v->setComponents($i, $j, $k + 1));
|
||||||
|
|
||||||
$direction = 3; //UP!
|
$direction = -1;
|
||||||
$limit = 9999;
|
$limit = 9999;
|
||||||
|
|
||||||
if($flag){
|
if($flag){
|
||||||
@ -650,6 +645,11 @@ abstract class Entity extends Location implements Metadatable{
|
|||||||
$direction = 1;
|
$direction = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($flag2 and $diffY < $limit){
|
||||||
|
$limit = $diffY;
|
||||||
|
$direction = 2;
|
||||||
|
}
|
||||||
|
|
||||||
if($flag3 and 1 - $diffY < $limit){
|
if($flag3 and 1 - $diffY < $limit){
|
||||||
$limit = 1 - $diffY;
|
$limit = 1 - $diffY;
|
||||||
$direction = 3;
|
$direction = 3;
|
||||||
@ -678,7 +678,11 @@ abstract class Entity extends Location implements Metadatable{
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//No direction 2
|
if($direction === 2){
|
||||||
|
$this->motionY = -$force;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if($direction === 3){
|
if($direction === 3){
|
||||||
$this->motionY = $force;
|
$this->motionY = $force;
|
||||||
@ -699,6 +703,8 @@ abstract class Entity extends Location implements Metadatable{
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function entityBaseTick($tickDiff = 1){
|
public function entityBaseTick($tickDiff = 1){
|
||||||
@ -728,10 +734,6 @@ abstract class Entity extends Location implements Metadatable{
|
|||||||
$effect->setDuration($effect->getDuration() - $tickDiff);
|
$effect->setDuration($effect->getDuration() - $tickDiff);
|
||||||
if($effect->getDuration() <= 0){
|
if($effect->getDuration() <= 0){
|
||||||
$this->removeEffect($effect->getId());
|
$this->removeEffect($effect->getId());
|
||||||
$this->sendMetadata($this->hasSpawned);
|
|
||||||
if($this instanceof Player){
|
|
||||||
$this->sendMetadata($this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1106,8 +1108,7 @@ abstract class Entity extends Location implements Metadatable{
|
|||||||
//TODO: big messy loop
|
//TODO: big messy loop
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
$list = $this->level->getCollisionCubes($this, $this->boundingBox->getOffsetBoundingBox($dx, $dy, $dz), false);
|
$list = $this->level->getCollisionCubes($this, $this->boundingBox->addCoord($dx, $dy, $dz), false);
|
||||||
|
|
||||||
|
|
||||||
foreach($list as $bb){
|
foreach($list as $bb){
|
||||||
$dy = $bb->calculateYOffset($this->boundingBox, $dy);
|
$dy = $bb->calculateYOffset($this->boundingBox, $dy);
|
||||||
@ -1160,7 +1161,7 @@ abstract class Entity extends Location implements Metadatable{
|
|||||||
|
|
||||||
$this->boundingBox->setBB($axisalignedbb);
|
$this->boundingBox->setBB($axisalignedbb);
|
||||||
|
|
||||||
$list = $this->level->getCollisionCubes($this, $this->boundingBox->getOffsetBoundingBox($dx, $dy, $dz), false);
|
$list = $this->level->getCollisionCubes($this, $this->boundingBox->addCoord($dx, $dy, $dz), false);
|
||||||
|
|
||||||
foreach($list as $bb){
|
foreach($list as $bb){
|
||||||
$dy = $bb->calculateYOffset($this->boundingBox, $dy);
|
$dy = $bb->calculateYOffset($this->boundingBox, $dy);
|
||||||
|
@ -71,6 +71,10 @@ class FallingSand extends Entity{
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function attack($damage, EntityDamageEvent $source){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public function onUpdate($currentTick){
|
public function onUpdate($currentTick){
|
||||||
|
|
||||||
if($this->closed){
|
if($this->closed){
|
||||||
|
@ -74,6 +74,13 @@ class Item extends Entity{
|
|||||||
$this->server->getPluginManager()->callEvent(new ItemSpawnEvent($this));
|
$this->server->getPluginManager()->callEvent(new ItemSpawnEvent($this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function attack($damage, EntityDamageEvent $source){
|
||||||
|
if($source->getCause() === EntityDamageEvent::CAUSE_FIRE_TICK){
|
||||||
|
parent::attack($damage, $source);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function onUpdate($currentTick){
|
public function onUpdate($currentTick){
|
||||||
if($this->closed !== false){
|
if($this->closed !== false){
|
||||||
return false;
|
return false;
|
||||||
@ -94,7 +101,7 @@ class Item extends Entity{
|
|||||||
|
|
||||||
$this->motionY -= $this->gravity;
|
$this->motionY -= $this->gravity;
|
||||||
|
|
||||||
$this->keepMovement = $this->checkObstruction($this->x, ($this->boundingBox->minY + $this->boundingBox->maxY) / 2, $this->z);
|
$this->checkObstruction($this->x, ($this->boundingBox->minY + $this->boundingBox->maxY) / 2, $this->z);
|
||||||
$this->move($this->motionX, $this->motionY, $this->motionZ);
|
$this->move($this->motionX, $this->motionY, $this->motionZ);
|
||||||
|
|
||||||
$friction = 1 - $this->drag;
|
$friction = 1 - $this->drag;
|
||||||
|
@ -44,6 +44,11 @@ class PrimedTNT extends Entity implements Explosive{
|
|||||||
|
|
||||||
public $canCollide = false;
|
public $canCollide = false;
|
||||||
|
|
||||||
|
|
||||||
|
public function attack($damage, EntityDamageEvent $source){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
protected function initEntity(){
|
protected function initEntity(){
|
||||||
parent::initEntity();
|
parent::initEntity();
|
||||||
|
|
||||||
@ -102,8 +107,6 @@ class PrimedTNT extends Entity implements Explosive{
|
|||||||
if($this->fuse <= 0){
|
if($this->fuse <= 0){
|
||||||
$this->kill();
|
$this->kill();
|
||||||
$this->explode();
|
$this->explode();
|
||||||
}else{
|
|
||||||
$this->sendMetadata($this->getViewers());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,11 @@ abstract class Projectile extends Entity{
|
|||||||
|
|
||||||
public $hadCollision = false;
|
public $hadCollision = false;
|
||||||
|
|
||||||
|
|
||||||
|
public function attack($damage, EntityDamageEvent $source){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
protected function initEntity(){
|
protected function initEntity(){
|
||||||
parent::initEntity();
|
parent::initEntity();
|
||||||
|
|
||||||
|
@ -824,17 +824,17 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
$minX = Math::floorFloat($bb->minX);
|
$minX = Math::floorFloat($bb->minX);
|
||||||
$minY = Math::floorFloat($bb->minY);
|
$minY = Math::floorFloat($bb->minY);
|
||||||
$minZ = Math::floorFloat($bb->minZ);
|
$minZ = Math::floorFloat($bb->minZ);
|
||||||
$maxX = Math::floorFloat($bb->maxX + 1);
|
$maxX = Math::ceilFloat($bb->maxX);
|
||||||
$maxY = Math::floorFloat($bb->maxY + 1);
|
$maxY = Math::ceilFloat($bb->maxY);
|
||||||
$maxZ = Math::floorFloat($bb->maxZ + 1);
|
$maxZ = Math::ceilFloat($bb->maxZ);
|
||||||
|
|
||||||
$collides = [];
|
$collides = [];
|
||||||
|
|
||||||
$v = $this->temporalVector;
|
$v = $this->temporalVector;
|
||||||
|
|
||||||
for($v->z = $minZ; $v->z < $maxZ; ++$v->z){
|
for($v->z = $minZ; $v->z <= $maxZ; ++$v->z){
|
||||||
for($v->x = $minX; $v->x < $maxX; ++$v->x){
|
for($v->x = $minX; $v->x <= $maxX; ++$v->x){
|
||||||
for($v->y = $minY - 1; $v->y < $maxY; ++$v->y){
|
for($v->y = $minY - 1; $v->y <= $maxY; ++$v->y){
|
||||||
$block = $this->getBlock($v);
|
$block = $this->getBlock($v);
|
||||||
if($block->getId() !== 0){
|
if($block->getId() !== 0){
|
||||||
$block->collidesWithBB($bb, $collides);
|
$block->collidesWithBB($bb, $collides);
|
||||||
@ -872,15 +872,15 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
$minX = Math::floorFloat($bb->minX);
|
$minX = Math::floorFloat($bb->minX);
|
||||||
$minY = Math::floorFloat($bb->minY);
|
$minY = Math::floorFloat($bb->minY);
|
||||||
$minZ = Math::floorFloat($bb->minZ);
|
$minZ = Math::floorFloat($bb->minZ);
|
||||||
$maxX = Math::floorFloat($bb->maxX + 1);
|
$maxX = Math::ceilFloat($bb->maxX);
|
||||||
$maxY = Math::floorFloat($bb->maxY + 1);
|
$maxY = Math::ceilFloat($bb->maxY);
|
||||||
$maxZ = Math::floorFloat($bb->maxZ + 1);
|
$maxZ = Math::ceilFloat($bb->maxZ);
|
||||||
|
|
||||||
$collides = [];
|
$collides = [];
|
||||||
$v = $this->temporalVector;
|
$v = $this->temporalVector;
|
||||||
|
|
||||||
for($v->z = $minZ; $v->z < $maxZ; ++$v->z){
|
for($v->z = $minZ; $v->z <= $maxZ; ++$v->z){
|
||||||
for($v->x = $minX; $v->x < $maxX; ++$v->x){
|
for($v->x = $minX; $v->x <= $maxX; ++$v->x){
|
||||||
for($v->y = $minY - 1; $v->y < $maxY; ++$v->y){
|
for($v->y = $minY - 1; $v->y < $maxY; ++$v->y){
|
||||||
$block = $this->getBlock($v);
|
$block = $this->getBlock($v);
|
||||||
if($block->getId() !== 0){
|
if($block->getId() !== 0){
|
||||||
@ -1492,9 +1492,9 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
$nearby = [];
|
$nearby = [];
|
||||||
|
|
||||||
if($entity === null or $entity->canCollide){
|
if($entity === null or $entity->canCollide){
|
||||||
$minX = Math::ceilFloat(($bb->minX - 2) / 16);
|
$minX = Math::floorFloat(($bb->minX - 2) / 16);
|
||||||
$maxX = Math::ceilFloat(($bb->maxX + 2) / 16);
|
$maxX = Math::ceilFloat(($bb->maxX + 2) / 16);
|
||||||
$minZ = Math::ceilFloat(($bb->minZ - 2) / 16);
|
$minZ = Math::floorFloat(($bb->minZ - 2) / 16);
|
||||||
$maxZ = Math::ceilFloat(($bb->maxZ + 2) / 16);
|
$maxZ = Math::ceilFloat(($bb->maxZ + 2) / 16);
|
||||||
|
|
||||||
for($x = $minX; $x <= $maxX; ++$x){
|
for($x = $minX; $x <= $maxX; ++$x){
|
||||||
@ -1522,9 +1522,9 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
public function getNearbyEntities(AxisAlignedBB $bb, Entity $entity = null){
|
public function getNearbyEntities(AxisAlignedBB $bb, Entity $entity = null){
|
||||||
$nearby = [];
|
$nearby = [];
|
||||||
|
|
||||||
$minX = Math::ceilFloat(($bb->minX - 2) / 16);
|
$minX = Math::floorFloat(($bb->minX - 2) / 16);
|
||||||
$maxX = Math::ceilFloat(($bb->maxX + 2) / 16);
|
$maxX = Math::ceilFloat(($bb->maxX + 2) / 16);
|
||||||
$minZ = Math::ceilFloat(($bb->minZ - 2) / 16);
|
$minZ = Math::floorFloat(($bb->minZ - 2) / 16);
|
||||||
$maxZ = Math::ceilFloat(($bb->maxZ + 2) / 16);
|
$maxZ = Math::ceilFloat(($bb->maxZ + 2) / 16);
|
||||||
|
|
||||||
for($x = $minX; $x <= $maxX; ++$x){
|
for($x = $minX; $x <= $maxX; ++$x){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user