mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-28 05:35:40 +00:00
Improved effects, threading changes
This commit is contained in:
parent
76767294bf
commit
71657a2a4e
@ -26,10 +26,38 @@ namespace pocketmine;
|
|||||||
*/
|
*/
|
||||||
abstract class Thread extends \Thread{
|
abstract class Thread extends \Thread{
|
||||||
|
|
||||||
|
/** @var \ClassLoader */
|
||||||
|
protected $classLoader;
|
||||||
|
|
||||||
|
public function getClassLoader(){
|
||||||
|
return $this->classLoader;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setClassLoader(\ClassLoader $loader = null){
|
||||||
|
if($loader === null){
|
||||||
|
$loader = Server::getInstance()->getLoader();
|
||||||
|
}
|
||||||
|
$this->classLoader = $loader;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function registerClassLoader(){
|
||||||
|
if(!interface_exists("ClassLoader", false)){
|
||||||
|
require(\pocketmine\PATH . "src/spl/ClassLoader.php");
|
||||||
|
require(\pocketmine\PATH . "src/spl/BaseClassLoader.php");
|
||||||
|
require(\pocketmine\PATH . "src/pocketmine/CompatibleClassLoader.php");
|
||||||
|
}
|
||||||
|
if($this->classLoader !== null){
|
||||||
|
$this->classLoader->register(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function start($options = PTHREADS_INHERIT_ALL){
|
public function start($options = PTHREADS_INHERIT_ALL){
|
||||||
ThreadManager::getInstance()->add($this);
|
ThreadManager::getInstance()->add($this);
|
||||||
|
|
||||||
if(!$this->isRunning() and !$this->isJoined() and !$this->isTerminated()){
|
if(!$this->isRunning() and !$this->isJoined() and !$this->isTerminated()){
|
||||||
|
if($this->getClassLoader() === null){
|
||||||
|
$this->setClassLoader();
|
||||||
|
}
|
||||||
return parent::start($options);
|
return parent::start($options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,10 +26,38 @@ namespace pocketmine;
|
|||||||
*/
|
*/
|
||||||
abstract class Worker extends \Worker{
|
abstract class Worker extends \Worker{
|
||||||
|
|
||||||
|
/** @var \ClassLoader */
|
||||||
|
protected $classLoader;
|
||||||
|
|
||||||
|
public function getClassLoader(){
|
||||||
|
return $this->classLoader;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setClassLoader(\ClassLoader $loader = null){
|
||||||
|
if($loader === null){
|
||||||
|
$loader = Server::getInstance()->getLoader();
|
||||||
|
}
|
||||||
|
$this->classLoader = $loader;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function registerClassLoader(){
|
||||||
|
if(!interface_exists("ClassLoader", false)){
|
||||||
|
require(\pocketmine\PATH . "src/spl/ClassLoader.php");
|
||||||
|
require(\pocketmine\PATH . "src/spl/BaseClassLoader.php");
|
||||||
|
require(\pocketmine\PATH . "src/pocketmine/CompatibleClassLoader.php");
|
||||||
|
}
|
||||||
|
if($this->classLoader !== null){
|
||||||
|
$this->classLoader->register(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function start($options = PTHREADS_INHERIT_ALL){
|
public function start($options = PTHREADS_INHERIT_ALL){
|
||||||
ThreadManager::getInstance()->add($this);
|
ThreadManager::getInstance()->add($this);
|
||||||
|
|
||||||
if(!$this->isRunning() and !$this->isJoined() and !$this->isTerminated() and !$this->isShutdown()){
|
if(!$this->isRunning() and !$this->isJoined() and !$this->isTerminated()){
|
||||||
|
if($this->getClassLoader() === null){
|
||||||
|
$this->setClassLoader();
|
||||||
|
}
|
||||||
return parent::start($options);
|
return parent::start($options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,6 @@ namespace pocketmine\command\defaults;
|
|||||||
|
|
||||||
use pocketmine\command\CommandSender;
|
use pocketmine\command\CommandSender;
|
||||||
use pocketmine\utils\TextFormat;
|
use pocketmine\utils\TextFormat;
|
||||||
use pocketmine\ThreadManager;
|
|
||||||
|
|
||||||
class StatusCommand extends VanillaCommand{
|
class StatusCommand extends VanillaCommand{
|
||||||
|
|
||||||
|
@ -180,17 +180,17 @@ class Effect{
|
|||||||
public function canTick(){
|
public function canTick(){
|
||||||
switch($this->id){
|
switch($this->id){
|
||||||
case Effect::POISON:
|
case Effect::POISON:
|
||||||
if(($interval = 25 >> $this->amplifier) > 0){
|
if(($interval = (25 >> $this->amplifier)) > 0){
|
||||||
return ($this->duration % $interval) === 0;
|
return ($this->duration % $interval) === 0;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
case Effect::WITHER:
|
case Effect::WITHER:
|
||||||
if(($interval = 50 >> $this->amplifier) > 0){
|
if(($interval = (50 >> $this->amplifier)) > 0){
|
||||||
return ($this->duration % $interval) === 0;
|
return ($this->duration % $interval) === 0;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
case Effect::REGENERATION:
|
case Effect::REGENERATION:
|
||||||
if(($interval = 40 >> $this->amplifier) > 0){
|
if(($interval = (40 >> $this->amplifier)) > 0){
|
||||||
return ($this->duration % $interval) === 0;
|
return ($this->duration % $interval) === 0;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -73,6 +73,15 @@ abstract class Living extends Entity implements Damageable{
|
|||||||
//return $this->getLevel()->rayTraceBlocks(Vector3::createVector($this->x, $this->y + $this->height, $this->z), Vector3::createVector($entity->x, $entity->y + $entity->height, $entity->z)) === null;
|
//return $this->getLevel()->rayTraceBlocks(Vector3::createVector($this->x, $this->y + $this->height, $this->z), Vector3::createVector($entity->x, $entity->y + $entity->height, $entity->z)) === null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function heal($amount, EntityRegainHealthEvent $source){
|
||||||
|
parent::heal($amount, $source);
|
||||||
|
if($source->isCancelled()){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->attackTime = 0;
|
||||||
|
}
|
||||||
|
|
||||||
public function attack($damage, EntityDamageEvent $source){
|
public function attack($damage, EntityDamageEvent $source){
|
||||||
if($this->attackTime > 0 or $this->noDamageTicks > 0){
|
if($this->attackTime > 0 or $this->noDamageTicks > 0){
|
||||||
$lastCause = $this->getLastDamageCause();
|
$lastCause = $this->getLastDamageCause();
|
||||||
|
@ -273,7 +273,7 @@ class CraftingManager{
|
|||||||
Item::IRON_BLOCK => Item::IRON_INGOT,
|
Item::IRON_BLOCK => Item::IRON_INGOT,
|
||||||
Item::DIAMOND_BLOCK => Item::DIAMOND,
|
Item::DIAMOND_BLOCK => Item::DIAMOND,
|
||||||
Item::EMERALD_BLOCK => Item::EMERALD,
|
Item::EMERALD_BLOCK => Item::EMERALD,
|
||||||
//Item::REDSTONE_BLOCK => Item::REDSTONE_DUST,
|
Item::REDSTONE_BLOCK => Item::REDSTONE_DUST,
|
||||||
Item::COAL_BLOCK => Item::COAL,
|
Item::COAL_BLOCK => Item::COAL,
|
||||||
Item::HAY_BALE => Item::WHEAT,
|
Item::HAY_BALE => Item::WHEAT,
|
||||||
];
|
];
|
||||||
|
@ -46,7 +46,8 @@ class AsyncPool{
|
|||||||
|
|
||||||
for($i = 0; $i < $this->size; ++$i){
|
for($i = 0; $i < $this->size; ++$i){
|
||||||
$this->workerUsage[$i] = 0;
|
$this->workerUsage[$i] = 0;
|
||||||
$this->workers[$i] = new AsyncWorker($server->getLoader());
|
$this->workers[$i] = new AsyncWorker;
|
||||||
|
$this->workers[$i]->setClassLoader($server->getLoader());
|
||||||
$this->workers[$i]->start();
|
$this->workers[$i]->start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,19 +25,8 @@ use pocketmine\Worker;
|
|||||||
|
|
||||||
class AsyncWorker extends Worker{
|
class AsyncWorker extends Worker{
|
||||||
|
|
||||||
public $loader;
|
|
||||||
|
|
||||||
public function __construct(\ClassLoader $loader){
|
|
||||||
$this->loader = $loader;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function run(){
|
public function run(){
|
||||||
if(!interface_exists("ClassLoader", false)){
|
$this->registerClassLoader();
|
||||||
require(\pocketmine\PATH . "src/spl/ClassLoader.php");
|
|
||||||
require(\pocketmine\PATH . "src/spl/BaseClassLoader.php");
|
|
||||||
require(\pocketmine\PATH . "src/pocketmine/CompatibleClassLoader.php");
|
|
||||||
}
|
|
||||||
$this->loader->register(true);
|
|
||||||
|
|
||||||
global $store;
|
global $store;
|
||||||
$store = [];
|
$store = [];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user