Skip to content
This repository was archived by the owner on Feb 3, 2023. It is now read-only.

Commit 4156897

Browse files
author
dearminder
committed
Merge remote-tracking branch 'upstream/stable' into stable
2 parents b28c71a + cb53da1 commit 4156897

File tree

12 files changed

+274
-55
lines changed

12 files changed

+274
-55
lines changed

src/pocketmine/command/utils/CommandSelector.php

+12
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,16 @@ public static function findTargets(CommandSender $sender, string $selector, stri
9898

9999
return $targets;
100100
}
101+
102+
/**
103+
* @param CommandSender $sender
104+
* @param string $selector
105+
* @param string $entityType
106+
* @param Vector3|null $pos
107+
*
108+
* @return Entity|null
109+
*/
110+
public static function findTarget(CommandSender $sender, string $selector, string $entityType = Entity::class, ?Vector3 $pos = null) : ?Entity{
111+
return !empty($targets = self::findTargets($sender, $selector, $entityType, $pos)) ? reset($targets) : null;
112+
}
101113
}

src/pocketmine/entity/Entity.php

+12-15
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
use pocketmine\entity\hostile\ZombieVillager;
4848
use pocketmine\entity\hostile\Dolphin;
4949
use pocketmine\entity\object\ArmorStand;
50+
use pocketmine\entity\object\EnderCrystal;
5051
use pocketmine\entity\object\ExperienceOrb;
5152
use pocketmine\entity\object\FallingBlock;
5253
use pocketmine\entity\object\FireworksRocket;
@@ -435,6 +436,7 @@ public static function init() : void{
435436
Entity::registerEntity(FireworksRocket::class, false, ['FireworksRocket', 'minecraft:fireworks_rocket']);
436437
Entity::registerEntity(Slime::class, false, ['Slime', 'minecraft:slime']);
437438
Entity::registerEntity(MagmaCube::class, false, ['MagmaCube', 'minecraft:magma_cube']);
439+
Entity::registerEntity(EnderCrystal::class, false, ['EnderCrystal', 'minecraft:ender_crystal']);
438440

439441
Entity::registerEntity(Human::class, true);
440442

@@ -868,11 +870,7 @@ public function setRiding(bool $value) : void{
868870
}
869871

870872
public function getRidingEntity() : ?Entity{
871-
if($this->ridingEid !== null){
872-
return $this->server->findEntity($this->ridingEid);
873-
}else{
874-
return null;
875-
}
873+
return $this->ridingEid !== null ? $this->server->findEntity($this->ridingEid) : null;
876874
}
877875

878876
public function setRidingEntity(?Entity $ridingEntity = null) : void{
@@ -884,11 +882,7 @@ public function setRidingEntity(?Entity $ridingEntity = null) : void{
884882
}
885883

886884
public function getRiddenByEntity() : ?Entity{
887-
if($this->riddenByEid !== null){
888-
return $this->server->findEntity($this->riddenByEid);
889-
}else{
890-
return null;
891-
}
885+
return $this->riddenByEid !== null ? $this->server->findEntity($this->riddenByEid) : null;
892886
}
893887

894888
public function setRiddenByEntity(?Entity $riddenByEntity = null) : void{
@@ -1648,8 +1642,12 @@ protected function applyGravity() : void{
16481642
$this->motion->y -= $this->gravity;
16491643
}
16501644

1645+
protected function getDefaultDrag() : float{
1646+
return 0.09;
1647+
}
1648+
16511649
protected function tryChangeMovement() : void{
1652-
$friction = 0.91;
1650+
$friction = 1 - $this->getDefaultDrag();
16531651

16541652
if($this->applyDragBeforeGravity()){
16551653
$this->motion->y *= $friction;
@@ -1941,9 +1939,8 @@ protected function updateFallState(float $distanceThisTick, bool $onGround) : vo
19411939
}
19421940

19431941
public function mountEntity(Entity $entity, int $seatNumber = 0) : bool{
1944-
if($this->getRidingEntity() == null and $entity !== $this and count($entity->passengers) < $entity->getSeatCount()){
1942+
if($this->getRidingEntity() === null and $entity !== $this and count($entity->passengers) < $entity->getSeatCount()){
19451943
if(!isset($entity->passengers[$seatNumber])){
1946-
19471944
if($seatNumber === 0){
19481945
$entity->setRiddenByEntity($this);
19491946

@@ -2004,9 +2001,9 @@ public function dismountEntity(bool $immediate = false) : bool{
20042001
if($this->getRidingEntity() !== null){
20052002
$entity = $this->getRidingEntity();
20062003

2007-
unset($entity->passengers[array_search($this->getId(), $entity->passengers, true)]);
2004+
unset($entity->passengers[$this->propertyManager->getByte(self::DATA_CONTROLLING_RIDER_SEAT_NUMBER)]);
20082005

2009-
if($this->isRiding()){
2006+
if($entity->getRiddenByEntity() === $this){
20102007
$entity->setRiddenByEntity(null);
20112008

20122009
$this->entityRiderYawDelta = 0;

src/pocketmine/entity/Human.php

-11
Original file line numberDiff line numberDiff line change
@@ -620,17 +620,6 @@ protected function initHumanData() : void{
620620
$this->setNameTag($this->namedtag->getString("NameTag"));
621621
}
622622

623-
$skin = $this->namedtag->getCompoundTag("Skin");
624-
if($skin !== null){
625-
$this->setSkin(new Skin(
626-
$skin->getString("Name"),
627-
$skin->hasTag("Data", StringTag::class) ? $skin->getString("Data") : $skin->getByteArray("Data"), //old data (this used to be saved as a StringTag in older versions of PM)
628-
$skin->hasTag("CapeData", ByteArrayTag::class) ? $skin->getByteArray("CapeData", "") : $skin->getString("CapeData", ""),
629-
$skin->getString("GeometryName", ""),
630-
$skin->hasTag("GeometryData", ByteArrayTag::class) ? $skin->getByteArray("GeometryData", "") : $skin->getString("GeometryData", "")
631-
));
632-
}
633-
634623
$this->uuid = UUID::fromData((string) $this->getId(), $this->skin->getSkinData(), $this->getNameTag());
635624
}
636625

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
3+
/*
4+
* _ _
5+
* /\ | | |
6+
* / \ | | |_ __ _ _ _
7+
* / /\ \ | | __/ _` | | | |
8+
* / ____ \| | || (_| | |_| |
9+
* /_/ \_|_|\__\__,_|\__, |
10+
* __/ |
11+
* |___/
12+
*
13+
* This program is free software: you can redistribute it and/or modify
14+
* it under the terms of the GNU Lesser General Public License as published by
15+
* the Free Software Foundation, either version 3 of the License, or
16+
* (at your option) any later version.
17+
*
18+
* @author TuranicTeam
19+
* @link https://github.com/TuranicTeam/Altay
20+
*
21+
*/
22+
23+
declare(strict_types=1);
24+
25+
namespace pocketmine\entity\object;
26+
27+
use pocketmine\block\Block;
28+
use pocketmine\block\Fire;
29+
use pocketmine\entity\Entity;
30+
use pocketmine\event\entity\EntityDamageEvent;
31+
use pocketmine\level\Explosion;
32+
use pocketmine\level\GameRules;
33+
use pocketmine\level\generator\end\End;
34+
35+
class EnderCrystal extends Entity{
36+
public const NETWORK_ID = self::ENDER_CRYSTAL;
37+
38+
public $height = 0.98;
39+
public $width = 0.98;
40+
41+
public $gravity = 0;
42+
public $drag = 0;
43+
44+
public function onMovementUpdate() : void{
45+
// NOOP
46+
}
47+
48+
public function onUpdate(int $currentTick) : bool{
49+
if($this->level->getProvider()->getPath() === End::class){
50+
if($this->level->getBlock($this)->getId() !== Block::FIRE){
51+
$this->level->setBlock($this, new Fire());
52+
}
53+
}
54+
55+
return parent::onUpdate($currentTick);
56+
}
57+
58+
public function attack(EntityDamageEvent $source) : void{
59+
parent::attack($source);
60+
61+
if(!$source->isCancelled() and $source->getCause() !== EntityDamageEvent::CAUSE_FIRE and $source->getCause() !== EntityDamageEvent::CAUSE_FIRE_TICK){
62+
$this->flagForDespawn();
63+
64+
if($this->level->getGameRules()->getBool(GameRules::RULE_TNT_EXPLODES)){
65+
$exp = new Explosion($this, 6, $this);
66+
67+
$exp->explodeA();
68+
$exp->explodeB();
69+
}
70+
}
71+
}
72+
73+
public function canBeCollidedWith() : bool{
74+
return false;
75+
}
76+
77+
public function setShowBase(bool $value) : void{
78+
$this->setGenericFlag(self::DATA_FLAG_SHOWBASE, $value);
79+
}
80+
81+
public function showBase() : bool{
82+
return $this->getGenericFlag(self::DATA_FLAG_SHOWBASE);
83+
}
84+
}

src/pocketmine/entity/object/ItemEntity.php

+58-7
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,14 @@
2323

2424
namespace pocketmine\entity\object;
2525

26+
use pocketmine\block\Water;
2627
use pocketmine\entity\Entity;
2728
use pocketmine\event\entity\ItemDespawnEvent;
2829
use pocketmine\event\entity\ItemSpawnEvent;
2930
use pocketmine\event\inventory\InventoryPickupItemEvent;
3031
use pocketmine\item\Item;
32+
use pocketmine\math\AxisAlignedBB;
33+
use pocketmine\network\mcpe\protocol\ActorEventPacket;
3134
use pocketmine\network\mcpe\protocol\AddItemActorPacket;
3235
use pocketmine\network\mcpe\protocol\TakeItemActorPacket;
3336
use pocketmine\Player;
@@ -52,7 +55,7 @@ class ItemEntity extends Entity{
5255
protected $gravity = 0.04;
5356
protected $drag = 0.02;
5457

55-
public $canCollide = false;
58+
public $canCollide = true;
5659

5760
/** @var int */
5861
protected $age = 0;
@@ -61,13 +64,13 @@ protected function initEntity() : void{
6164
parent::initEntity();
6265

6366
$this->setMaxHealth(5);
67+
$this->setImmobile(true);
6468
$this->setHealth($this->namedtag->getShort("Health", (int) $this->getHealth()));
6569
$this->age = $this->namedtag->getShort("Age", $this->age);
6670
$this->pickupDelay = $this->namedtag->getShort("PickupDelay", $this->pickupDelay);
6771
$this->owner = $this->namedtag->getString("Owner", $this->owner);
6872
$this->thrower = $this->namedtag->getString("Thrower", $this->thrower);
6973

70-
7174
$itemTag = $this->namedtag->getCompoundTag("Item");
7275
if($itemTag === null){
7376
throw new \UnexpectedValueException("Invalid " . get_class($this) . " entity: expected \"Item\" NBT tag not found");
@@ -95,6 +98,32 @@ public function entityBaseTick(int $tickDiff = 1) : bool{
9598
$this->pickupDelay = 0;
9699
}
97100

101+
if($this->ticksLived % 60 === 0){
102+
foreach($this->level->getCollidingEntities($this->getBoundingBox()->expandedCopy(1, 1, 1), $this) as $entity){
103+
if($entity instanceof ItemEntity){
104+
$item = $this->getItem();
105+
if($item->getCount() < $item->getMaxStackSize()){
106+
if($entity->getItem()->equals($item, true, true)){
107+
$nextAmount = $item->getCount() + $entity->getItem()->getCount();
108+
if($nextAmount <= $item->getMaxStackSize()){
109+
if($this->ticksLived > $entity->ticksLived){
110+
$entity->flagForDespawn();
111+
112+
$item->setCount($nextAmount);
113+
$this->broadcastEntityEvent(ActorEventPacket::ITEM_ENTITY_MERGE, $nextAmount);
114+
}else{
115+
$this->flagForDespawn();
116+
117+
$entity->getItem()->setCount($nextAmount);
118+
$entity->broadcastEntityEvent(ActorEventPacket::ITEM_ENTITY_MERGE, $nextAmount);
119+
}
120+
}
121+
}
122+
}
123+
}
124+
}
125+
}
126+
98127
$this->age += $tickDiff;
99128
if($this->age > 6000){
100129
$ev = new ItemDespawnEvent($this);
@@ -111,6 +140,10 @@ public function entityBaseTick(int $tickDiff = 1) : bool{
111140
return $hasUpdate;
112141
}
113142

143+
protected function getDefaultDrag() : float{
144+
return 0.02;
145+
}
146+
114147
protected function tryChangeMovement() : void{
115148
$this->checkObstruction($this->x, $this->y, $this->z);
116149
parent::tryChangeMovement();
@@ -120,6 +153,28 @@ protected function applyDragBeforeGravity() : bool{
120153
return true;
121154
}
122155

156+
protected function applyGravity() : void{
157+
$bb = $this->getBoundingBox();
158+
$waterCount = 0;
159+
160+
for($j = 0; $j < 5; ++$j){
161+
$d1 = $bb->minY + ($bb->maxY - $bb->minY) * $j / 5 + 0.4;
162+
$d3 = $bb->minY + ($bb->maxY - $bb->minY) * ($j + 1) / 5 + 1;
163+
164+
$bb2 = new AxisAlignedBB($bb->minX, $d1, $bb->minZ, $bb->maxX, $d3, $bb->maxZ);
165+
166+
if($this->level->isLiquidInBoundingBox($bb2, new Water())){
167+
$waterCount += 0.2;
168+
}
169+
}
170+
171+
if($waterCount > 0){
172+
$this->motion->y += 0.002 * ($waterCount * 2 - 1);
173+
}else{
174+
$this->motion->y -= $this->gravity;
175+
}
176+
}
177+
123178
public function saveNBT() : void{
124179
parent::saveNBT();
125180
$this->namedtag->setTag($this->item->nbtSerialize(-1, "Item"));
@@ -142,11 +197,7 @@ public function getItem() : Item{
142197
}
143198

144199
public function canCollideWith(Entity $entity) : bool{
145-
return false;
146-
}
147-
148-
public function canBeCollidedWith() : bool{
149-
return false;
200+
return parent::canCollideWith($entity) and $entity instanceof ItemEntity;
150201
}
151202

152203
/**

src/pocketmine/entity/projectile/FishingHook.php

+2
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ public function __construct(Level $level, CompoundTag $nbt, ?Entity $owner = nul
9696
* @param RayTraceResult $hitResult
9797
*/
9898
public function onHitEntity(Entity $entityHit, RayTraceResult $hitResult) : void{
99+
$entityHit->attack(new EntityDamageByEntityEvent($this, $entityHit, EntityDamageEvent::CAUSE_ENTITY_ATTACK, 0));
100+
99101
$this->mountEntity($entityHit);
100102
}
101103

src/pocketmine/entity/projectile/Projectile.php

+4
Original file line numberDiff line numberDiff line change
@@ -340,4 +340,8 @@ protected function onHitBlock(Block $blockHit, RayTraceResult $hitResult) : void
340340
$this->blockHitId = $blockHit->getId();
341341
$this->blockHitData = $blockHit->getDamage();
342342
}
343+
344+
public function getDefaultDrag() : float{
345+
return 0;
346+
}
343347
}

0 commit comments

Comments
 (0)