-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement beacon #4687
base: minor-next
Are you sure you want to change the base?
Implement beacon #4687
Conversation
a |
I'm not sure that dktapps will merged it. |
I am in the process of making changes to improve performance |
I haven't had time to review it yet. |
I've meant that it's useless for most users of PocketMine-MP. This functionality can be move to plugin. I thought pmmp was following the way of minimalism. No? |
If that were the case, we could strip almost all the code in the name of "minimalism"... |
* Make use of `World->getNearbyEntities()` * Added checks for primary and secondary effect
* Make use of `World->getNearbyEntities()` * Added checks for primary and secondary effect
If the beacon level reduces the secondary effect should be removed. This is an unlikely case so it doesn't bear much thinking about. |
good |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works nice, tested
idk. who need a event/PHPDoc seems a little bit old
} | ||
|
||
public function onScheduledUpdate() : void{ | ||
$this->position->getWorld()->scheduleDelayedBlockUpdate($this->position, 20 * 3); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the wiki, updates are every 4 seconds
public const MIN_LEVEL_BEACON = 1; | ||
public const MAX_LEVEL_BEACON = 4; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inclunding BEACON
in the constant name seems redundant since it is on the Beacon
class
ItemTypeIds::NETHERITE_INGOT => true | ||
]; | ||
|
||
private const ALLOWED_BLOCK_IDS = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to allow plugins to be able to modify this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Type tags would be the best thing
if(!$this->viewSky()){ | ||
return; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need some validation here, it is possible that players might destroy blocks on any level and some effects will be no longer avaible
} | ||
} | ||
|
||
public function isBeaconLevelValid(int $level) : bool{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please document this function, i feel that the name isn't clear enough
return true; | ||
} | ||
|
||
public function viewSky() : bool{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function name is not the most appropriate.
} | ||
|
||
/** @return Effect[] */ | ||
public function getAllowedEffect(int $beaconLevel) : array { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public function getAllowedEffect(int $beaconLevel) : array { | |
public function getAllowedEffects(int $beaconLevel) : array { |
if(!in_array($this->primaryEffect, $allowedEffects, true)){ | ||
throw new TransactionValidationException("Primary effect provided is not allowed"); | ||
} | ||
if($this->secondaryEffect !== null && !in_array($this->secondaryEffect, $allowedEffects, true)){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This validation is incomplete. Secondary effect can only be Regeneration or the same as primary effect. Current code allows that a hacked-cleint to send a primary effect as secondary.
} | ||
|
||
$allowedEffects = $block->getAllowedEffect($block->getBeaconLevel()); | ||
if(!in_array($this->primaryEffect, $allowedEffects, true)){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid using in_array when possible
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I stalled to review this because the performance will suck, but there currently isn't a great alternative way to detect changes in the pyramid.
for($z = -$level; $z <= $level; $z++){ | ||
$block = $world->getBlock($pos->add($x, 0, $z)); | ||
if(!isset(self::ALLOWED_BLOCK_IDS[$block->getTypeId()])){ | ||
return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really don't like this. I know that's the most obvious way to do it, but it's going to lag like shit.
ItemTypeIds::NETHERITE_INGOT => true | ||
]; | ||
|
||
private const ALLOWED_BLOCK_IDS = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Type tags would be the best thing
As discussed internally, it would be best to move forward with a ChunkListener-based system for triggering pyramid rechecks as per @Muqsit's beacons plugin. |
This PR has been marked as "Waiting on Author", but we haven't seen any activity in 7 days. If there is no further activity, it will be closed in 28 days. Note for maintainers: Adding an assignee to the PR will prevent it from being marked as stale. |
Introduction
Beacons are currently available but completely useless as the functionality has not been added.
Changes
API changes
Tests