first look at separating Entity and Location

This commit is contained in:
Dylan K. Taylor
2019-08-19 17:20:34 +01:00
parent 591d35889e
commit 2d4a32fc77
36 changed files with 302 additions and 257 deletions

View File

@@ -50,11 +50,12 @@ class Bow extends Tool{
return ItemUseResult::FAIL();
}
$location = $player->getLocation();
$nbt = EntityFactory::createBaseNBT(
$player->getEyePos(),
$player->getDirectionVector(),
($player->yaw > 180 ? 360 : 0) - $player->yaw,
-$player->pitch
($location->yaw > 180 ? 360 : 0) - $location->yaw,
-$location->pitch
);
$nbt->setShort("Fire", $player->isOnFire() ? 45 * 60 : 0);
@@ -63,7 +64,7 @@ class Bow extends Tool{
$baseForce = min((($p ** 2) + $p * 2) / 3, 1);
/** @var ArrowEntity $entity */
$entity = EntityFactory::create(ArrowEntity::class, $player->getWorld(), $nbt, $player, $baseForce >= 1);
$entity = EntityFactory::create(ArrowEntity::class, $location->getWorld(), $nbt, $player, $baseForce >= 1);
$infinity = $this->hasEnchantment(Enchantment::INFINITY());
if($infinity){
@@ -104,7 +105,7 @@ class Bow extends Tool{
}
$ev->getProjectile()->spawnToAll();
$player->getWorld()->addSound($player, new BowShootSound());
$location->getWorld()->addSound($location, new BowShootSound());
}else{
$entity->spawnToAll();
}

View File

@@ -49,9 +49,10 @@ class ChorusFruit extends Food{
$world = $consumer->getWorld();
assert($world !== null);
$minX = $consumer->getFloorX() - 8;
$minY = min($consumer->getFloorY(), $consumer->getWorld()->getWorldHeight()) - 8;
$minZ = $consumer->getFloorZ() - 8;
$origin = $consumer->getPosition();
$minX = $origin->getFloorX() - 8;
$minY = min($origin->getFloorY(), $consumer->getWorld()->getWorldHeight()) - 8;
$minZ = $origin->getFloorZ() - 8;
$maxX = $minX + 16;
$maxY = $minY + 16;
@@ -76,7 +77,7 @@ class ChorusFruit extends Food{
}
//Sounds are broadcasted at both source and destination
$world->addSound($consumer->asVector3(), new EndermanTeleportSound());
$world->addSound($origin, new EndermanTeleportSound());
$consumer->teleport($target = new Vector3($x + 0.5, $y + 1, $z + 0.5));
$world->addSound($target, new EndermanTeleportSound());

View File

@@ -53,14 +53,15 @@ abstract class ProjectileItem extends Item{
}
public function onClickAir(Player $player, Vector3 $directionVector) : ItemUseResult{
$nbt = EntityFactory::createBaseNBT($player->getEyePos(), $directionVector, $player->yaw, $player->pitch);
$location = $player->getLocation();
$nbt = EntityFactory::createBaseNBT($player->getEyePos(), $directionVector, $location->yaw, $location->pitch);
$this->addExtraTags($nbt);
$class = $this->getProjectileEntityClass();
Utils::testValidInstance($class, Throwable::class);
/** @var Throwable $projectile */
$projectile = EntityFactory::create($class, $player->getWorld(), $nbt, $player);
$projectile = EntityFactory::create($class, $location->getWorld(), $nbt, $player);
$projectile->setMotion($projectile->getMotion()->multiply($this->getThrowForce()));
$projectileEv = new ProjectileLaunchEvent($projectile);
@@ -72,7 +73,7 @@ abstract class ProjectileItem extends Item{
$projectile->spawnToAll();
$player->getWorld()->addSound($player, new ThrowSound());
$location->getWorld()->addSound($location, new ThrowSound());
$this->pop();

View File

@@ -38,7 +38,8 @@ class KnockbackEnchantment extends MeleeWeaponEnchantment{
public function onPostAttack(Entity $attacker, Entity $victim, int $enchantmentLevel) : void{
if($victim instanceof Living){
$victim->knockBack($victim->x - $attacker->x, $victim->z - $attacker->z, $enchantmentLevel * 0.5);
$diff = $victim->getPosition()->subtract($attacker->getPosition());
$victim->knockBack($diff->x, $diff->z, $enchantmentLevel * 0.5);
}
}
}