PHP8: use match function

This commit is contained in:
Sunch 2024-08-17 20:12:37 +08:00
parent 1275a4558c
commit f74e6e0638
41 changed files with 300 additions and 574 deletions

View file

@ -145,17 +145,11 @@ class LevelAPI{
if($generator !== false and class_exists($generator)){
$generator = new $generator($options);
}else{
switch(strtoupper($this->server->api->getProperty("level-type"))){
case "FLAT":
$generator = new SuperflatGenerator($options);
break;
case "VANILLA":
$generator = new VanillaGenerator($options);
break;
default:
$generator = new TemporalGenerator($options);
break;
}
$generator = match (strtoupper($this->server->api->getProperty("level-type"))) {
"FLAT" => new SuperflatGenerator($options),
"VANILLA" => new VanillaGenerator($options),
default => new TemporalGenerator($options),
};
}
$gen = new WorldGenerator($generator, $name, $seed === false ? Utils::readInt(Utils::getRandomBytes(4, false)) : (int) $seed);
$gen->generate();

View file

@ -57,38 +57,18 @@ class PlayerAPI{
}
}
}else{
switch($data["cause"]){
case "cactus":
$message = " was pricked to death";
break;
case "lava":
$message = " tried to swim in lava";
break;
case "fire":
$message = " went up in flames";
break;
case "burning":
$message = " burned to death";
break;
case "suffocation":
$message = " suffocated in a wall";
break;
case "water":
$message = " drowned";
break;
case "void":
$message = " fell out of the world";
break;
case "fall":
$message = " hit the ground too hard";
break;
case "explosion":
$message = " blew up";
break;
default:
$message = " died";
break;
}
$message = match ($data["cause"]) {
"cactus" => " was pricked to death",
"lava" => " tried to swim in lava",
"fire" => " went up in flames",
"burning" => " burned to death",
"suffocation" => " suffocated in a wall",
"water" => " drowned",
"void" => " fell out of the world",
"fall" => " hit the ground too hard",
"explosion" => " blew up",
default => " died",
};
}
$this->server->api->chat->broadcast($data["player"]->username . $message);
return true;

View file

@ -175,25 +175,13 @@ function console($message, $EOL = true, $log = true, $level = 1){
if(ENABLE_ANSI === true){
$add = "";
if(preg_match("/\[([a-zA-Z0-9]*)\]/", $message, $matches) > 0){
switch($matches[1]){
case "ERROR":
case "SEVERE":
$add .= FORMAT_RED;
break;
case "INTERNAL":
case "DEBUG":
$add .= FORMAT_WHITE;
break;
case "WARNING":
$add .= FORMAT_YELLOW;
break;
case "NOTICE":
$add .= FORMAT_AQUA;
break;
default:
$add .= FORMAT_GRAY;
break;
}
$add .= match ($matches[1]) {
"ERROR", "SEVERE" => FORMAT_RED,
"INTERNAL", "DEBUG" => FORMAT_WHITE,
"WARNING" => FORMAT_YELLOW,
"NOTICE" => FORMAT_AQUA,
default => FORMAT_GRAY,
};
}
$message = TextFormat::toANSI($time . $add . $message . FORMAT_RESET);
}else{

View file

@ -259,20 +259,14 @@ class Item{
//TODO remove?
public function getPickaxeLevel(){ //Returns false or level of the pickaxe
switch($this->id){
case WOODEN_PICKAXE:
return 1;
case GOLDEN_PICKAXE:
return 2;
case STONE_PICKAXE:
return 3;
case IRON_PICKAXE:
return 4;
case DIAMOND_PICKAXE:
return 5;
default:
return false;
}
return match ($this->id) {
WOODEN_PICKAXE => 1,
GOLDEN_PICKAXE => 2,
STONE_PICKAXE => 3,
IRON_PICKAXE => 4,
DIAMOND_PICKAXE => 5,
default => false,
};
}
public function isAxe(){

View file

@ -11,21 +11,15 @@ class IronDoorBlock extends DoorBlock{
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.95;
case 4:
return 1.25;
case 3:
return 1.9;
case 2:
return 0.65;
case 1:
return 3.75;
default:
return 25;
}
return match ($item->getPickaxeLevel()) {
5 => 0.95,
4 => 1.25,
3 => 1.9,
2 => 0.65,
1 => 3.75,
default => 25,
};
}
public function getDrops(Item $item, Player $player){

View file

@ -93,21 +93,15 @@ class SlabBlock extends TransparentBlock{
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.4;
case 4:
return 0.5;
case 3:
return 0.75;
case 2:
return 0.25;
case 1:
return 1.5;
default:
return 10;
}
return match ($item->getPickaxeLevel()) {
5 => 0.4,
4 => 0.5,
3 => 0.75,
2 => 0.25,
1 => 1.5,
default => 10,
};
}
public function getDrops(Item $item, Player $player){

View file

@ -89,21 +89,15 @@ class WoodSlabBlock extends TransparentBlock{
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->isAxe()){
case 5:
return 0.4;
case 4:
return 0.5;
case 3:
return 0.75;
case 2:
return 0.25;
case 1:
return 1.5;
default:
return 3;
}
return match ($item->isAxe()) {
5 => 0.4,
4 => 0.5,
3 => 0.75,
2 => 0.25,
1 => 1.5,
default => 3,
};
}
public function getDrops(Item $item, Player $player){

View file

@ -9,21 +9,15 @@ class WoodStairsBlock extends StairBlock{
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->isAxe()){
case 5:
return 0.4;
case 4:
return 0.5;
case 3:
return 0.75;
case 2:
return 0.25;
case 1:
return 1.5;
default:
return 3;
}
return match ($item->isAxe()) {
5 => 0.4,
4 => 0.5,
3 => 0.75,
2 => 0.25,
1 => 1.5,
default => 3,
};
}
public function getDrops(Item $item, Player $player){

View file

@ -10,21 +10,15 @@ class CoalOreBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.6;
case 4:
return 0.75;
case 3:
return 1.15;
case 2:
return 0.4;
case 1:
return 2.25;
default:
return 15;
}
return match ($item->getPickaxeLevel()) {
5 => 0.6,
4 => 0.75,
3 => 1.15,
2 => 0.4,
1 => 2.25,
default => 15,
};
}
public function getDrops(Item $item, Player $player){

View file

@ -10,15 +10,12 @@ class DiamondOreBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.6;
case 4:
return 0.75;
default:
return 15;
}
return match ($item->getPickaxeLevel()) {
5 => 0.6,
4 => 0.75,
default => 15,
};
}
public function getDrops(Item $item, Player $player){

View file

@ -18,15 +18,12 @@ class GlowingRedstoneOreBlock extends SolidBlock implements LightingBlock{
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.6;
case 4:
return 0.75;
default:
return 15;
}
return match ($item->getPickaxeLevel()) {
5 => 0.6,
4 => 0.75,
default => 15,
};
}
public function getDrops(Item $item, Player $player){

View file

@ -10,15 +10,12 @@ class GoldOreBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.6;
case 4:
return 0.75;
default:
return 15;
}
return match ($item->getPickaxeLevel()) {
5 => 0.6,
4 => 0.75,
default => 15,
};
}
public function getDrops(Item $item, Player $player){

View file

@ -10,17 +10,13 @@ class IronOreBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.6;
case 4:
return 0.75;
case 3:
return 1.15;
default:
return 15;
}
return match ($item->getPickaxeLevel()) {
5 => 0.6,
4 => 0.75,
3 => 1.15,
default => 15,
};
}
public function getDrops(Item $item, Player $player){

View file

@ -10,17 +10,13 @@ class LapisOreBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.6;
case 4:
return 0.75;
case 3:
return 1.15;
default:
return 15;
}
return match ($item->getPickaxeLevel()) {
5 => 0.6,
4 => 0.75,
3 => 1.15,
default => 15,
};
}
public function getDrops(Item $item, Player $player){

View file

@ -10,21 +10,15 @@ class BricksBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.4;
case 4:
return 0.5;
case 3:
return 0.75;
case 2:
return 0.25;
case 1:
return 1.5;
default:
return 10;
}
return match ($item->getPickaxeLevel()) {
5 => 0.4,
4 => 0.5,
3 => 0.75,
2 => 0.25,
1 => 1.5,
default => 10,
};
}
public function getDrops(Item $item, Player $player){

View file

@ -55,21 +55,15 @@ class BurningFurnaceBlock extends SolidBlock implements LightingBlock{
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.7;
case 4:
return 0.9;
case 3:
return 1.35;
case 2:
return 0.45;
case 1:
return 2.65;
default:
return 17.5;
}
return match ($item->getPickaxeLevel()) {
5 => 0.7,
4 => 0.9,
3 => 1.35,
2 => 0.45,
1 => 2.65,
default => 17.5,
};
}
public function getDrops(Item $item, Player $player){

View file

@ -10,21 +10,15 @@ class CoalBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.95;
case 4:
return 1.25;
case 3:
return 1.9;
case 2:
return 0.65;
case 1:
return 3.75;
default:
return 25;
}
return match ($item->getPickaxeLevel()) {
5 => 0.95,
4 => 1.25,
3 => 1.9,
2 => 0.65,
1 => 3.75,
default => 25,
};
}
public function getDrops(Item $item, Player $player){

View file

@ -10,21 +10,15 @@ class CobblestoneBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.4;
case 4:
return 0.5;
case 3:
return 0.75;
case 2:
return 0.25;
case 1:
return 1.5;
default:
return 10;
}
return match ($item->getPickaxeLevel()) {
5 => 0.4,
4 => 0.5,
3 => 0.75,
2 => 0.25,
1 => 1.5,
default => 10,
};
}
public function getDrops(Item $item, Player $player){

View file

@ -10,15 +10,12 @@ class DiamondBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.95;
case 4:
return 1.25;
default:
return 25;
}
return match ($item->getPickaxeLevel()) {
5 => 0.95,
4 => 1.25,
default => 25,
};
}
public function getDrops(Item $item, Player $player){

View file

@ -21,21 +21,15 @@ class DoubleSlabBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.4;
case 4:
return 0.5;
case 3:
return 0.75;
case 2:
return 0.25;
case 1:
return 1.5;
default:
return 10;
}
return match ($item->getPickaxeLevel()) {
5 => 0.4,
4 => 0.5,
3 => 0.75,
2 => 0.25,
1 => 1.5,
default => 10,
};
}
public function getDrops(Item $item, Player $player){

View file

@ -17,21 +17,15 @@ class DoubleWoodSlabBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->isAxe()){
case 5:
return 0.4;
case 4:
return 0.5;
case 3:
return 0.75;
case 2:
return 0.25;
case 1:
return 1.5;
default:
return 3;
}
return match ($item->isAxe()) {
5 => 0.4,
4 => 0.5,
3 => 0.75,
2 => 0.25,
1 => 1.5,
default => 3,
};
}
public function getDrops(Item $item, Player $player){

View file

@ -10,15 +10,12 @@ class GoldBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.6;
case 4:
return 0.75;
default:
return 15;
}
return match ($item->getPickaxeLevel()) {
5 => 0.6,
4 => 0.75,
default => 15,
};
}
public function getDrops(Item $item, Player $player){

View file

@ -57,21 +57,15 @@ class IceBlock extends TransparentBlock{
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.1;
case 4:
return 0.15;
case 3:
return 0.2;
case 2:
return 0.1;
case 1:
return 0.4;
default:
return 0.75;
}
return match ($item->getPickaxeLevel()) {
5 => 0.1,
4 => 0.15,
3 => 0.2,
2 => 0.1,
1 => 0.4,
default => 0.75,
};
}
public function getDrops(Item $item, Player $player){

View file

@ -10,17 +10,13 @@ class IronBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.95;
case 4:
return 1.25;
case 3:
return 1.9;
default:
return 25;
}
return match ($item->getPickaxeLevel()) {
5 => 0.95,
4 => 1.25,
3 => 1.9,
default => 25,
};
}
public function getDrops(Item $item, Player $player){

View file

@ -10,17 +10,13 @@ class LapisBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.6;
case 4:
return 0.75;
case 3:
return 1.15;
default:
return 15;
}
return match ($item->getPickaxeLevel()) {
5 => 0.6,
4 => 0.75,
3 => 1.15,
default => 15,
};
}
public function getDrops(Item $item, Player $player){

View file

@ -10,21 +10,15 @@ class MossStoneBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.4;
case 4:
return 0.5;
case 3:
return 0.75;
case 2:
return 0.25;
case 1:
return 1.5;
default:
return 10;
}
return match ($item->getPickaxeLevel()) {
5 => 0.4,
4 => 0.5,
3 => 0.75,
2 => 0.25,
1 => 1.5,
default => 10,
};
}
public function getDrops(Item $item, Player $player){

View file

@ -10,21 +10,15 @@ class NetherBricksBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.4;
case 4:
return 0.5;
case 3:
return 0.75;
case 2:
return 0.25;
case 1:
return 1.5;
default:
return 10;
}
return match ($item->getPickaxeLevel()) {
5 => 0.4,
4 => 0.5,
3 => 0.75,
2 => 0.25,
1 => 1.5,
default => 10,
};
}
public function getDrops(Item $item, Player $player){

View file

@ -10,21 +10,15 @@ class NetherrackBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.1;
case 4:
return 0.1;
case 3:
return 0.15;
case 2:
return 0.05;
case 1:
return 0.3;
default:
return 2;
}
return match ($item->getPickaxeLevel()) {
5 => 0.1,
4 => 0.1,
3 => 0.15,
2 => 0.05,
1 => 0.3,
default => 2,
};
}
public function getDrops(Item $item, Player $player){

View file

@ -16,21 +16,15 @@ class QuartzBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.15;
case 4:
return 0.2;
case 3:
return 0.3;
case 2:
return 0.1;
case 1:
return 0.6;
default:
return 4;
}
return match ($item->getPickaxeLevel()) {
5 => 0.15,
4 => 0.2,
3 => 0.3,
2 => 0.1,
1 => 0.6,
default => 4,
};
}
public function getDrops(Item $item, Player $player){

View file

@ -16,21 +16,15 @@ class SandstoneBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.15;
case 4:
return 0.2;
case 3:
return 0.3;
case 2:
return 0.1;
case 1:
return 0.6;
default:
return 4;
}
return match ($item->getPickaxeLevel()) {
5 => 0.15,
4 => 0.2,
3 => 0.3,
2 => 0.1,
1 => 0.6,
default => 4,
};
}
public function getDrops(Item $item, Player $player){

View file

@ -10,21 +10,15 @@ class StoneBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.4;
case 4:
return 0.5;
case 3:
return 0.75;
case 2:
return 0.25;
case 1:
return 1.5;
default:
return 7.5;
}
return match ($item->getPickaxeLevel()) {
5 => 0.4,
4 => 0.5,
3 => 0.75,
2 => 0.25,
1 => 1.5,
default => 7.5,
};
}
public function getDrops(Item $item, Player $player){

View file

@ -17,21 +17,15 @@ class StoneBricksBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.4;
case 4:
return 0.5;
case 3:
return 0.75;
case 2:
return 0.25;
case 1:
return 1.5;
default:
return 7.5;
}
return match ($item->getPickaxeLevel()) {
5 => 0.4,
4 => 0.5,
3 => 0.75,
2 => 0.25,
1 => 1.5,
default => 7.5,
};
}
public function getDrops(Item $item, Player $player){

View file

@ -7,20 +7,14 @@ abstract class ItemAxe extends ItemTool
}
public function getLevel(){
switch($this->id){
case WOODEN_AXE:
return 1;
case GOLDEN_AXE:
return 2;
case STONE_AXE:
return 3;
case IRON_AXE:
return 4;
case DIAMOND_AXE:
return 5;
default:
return false;
}
return match ($this->id) {
WOODEN_AXE => 1,
GOLDEN_AXE => 2,
STONE_AXE => 3,
IRON_AXE => 4,
DIAMOND_AXE => 5,
default => false,
};
}
}

View file

@ -16,20 +16,14 @@ abstract class ItemHoe extends ItemTool
}
public function getLevel(){
switch($this->id){
case WOODEN_HOE:
return 1;
case GOLDEN_HOE:
return 2;
case STONE_HOE:
return 3;
case IRON_HOE:
return 4;
case DIAMOND_HOE:
return 5;
default:
return false;
}
return match ($this->id) {
WOODEN_HOE => 1,
GOLDEN_HOE => 2,
STONE_HOE => 3,
IRON_HOE => 4,
DIAMOND_HOE => 5,
default => false,
};
}
}

View file

@ -12,20 +12,14 @@ abstract class ItemPickaxe extends ItemTool
}
public function getLevel(){
switch($this->id){
case WOODEN_PICKAXE:
return 1;
case GOLDEN_PICKAXE:
return 2;
case STONE_PICKAXE:
return 3;
case IRON_PICKAXE:
return 4;
case DIAMOND_PICKAXE:
return 5;
default:
return false;
}
return match ($this->id) {
WOODEN_PICKAXE => 1,
GOLDEN_PICKAXE => 2,
STONE_PICKAXE => 3,
IRON_PICKAXE => 4,
DIAMOND_PICKAXE => 5,
default => false,
};
}
}

View file

@ -7,20 +7,14 @@ class ItemShovel extends ItemTool
}
public function getLevel(){
switch($this->id){
case WOODEN_SHOVEL:
return 1;
case GOLDEN_SHOVEL:
return 2;
case STONE_SHOVEL:
return 3;
case IRON_SHOVEL:
return 4;
case DIAMOND_SHOVEL:
return 5;
default:
return false;
}
return match ($this->id) {
WOODEN_SHOVEL => 1,
GOLDEN_SHOVEL => 2,
STONE_SHOVEL => 3,
IRON_SHOVEL => 4,
DIAMOND_SHOVEL => 5,
default => false,
};
}
}

View file

@ -8,20 +8,14 @@ abstract class ItemSword extends ItemTool
}
public function getLevel(){
switch($this->id){
case WOODEN_SWORD:
return 1;
case GOLDEN_SWORD:
return 2;
case STONE_SWORD:
return 3;
case IRON_SWORD:
return 4;
case DIAMOND_SWORD:
return 5;
default:
return false;
}
return match ($this->id) {
WOODEN_SWORD => 1,
GOLDEN_SWORD => 2,
STONE_SWORD => 3,
IRON_SWORD => 4,
DIAMOND_SWORD => 5,
default => false,
};
}
}

View file

@ -140,16 +140,13 @@ class Matrix implements ArrayAccess{
if($this->isSquare() !== true){
return false;
}
switch($this->rows){
case 1:
return 0;
case 2:
return $this->matrix[0][0] * $this->matrix[1][1] - $this->matrix[0][1] * $this->matrix[1][0];
case 3:
return $this->matrix[0][0] * $this->matrix[1][1] * $this->matrix[2][2] + $this->matrix[0][1] * $this->matrix[1][2] * $this->matrix[2][0] + $this->matrix[0][2] * $this->matrix[1][0] * $this->matrix[2][1] - $this->matrix[2][0] * $this->matrix[1][1] * $this->matrix[0][2] - $this->matrix[2][1] * $this->matrix[1][2] * $this->matrix[0][0] - $this->matrix[2][2] * $this->matrix[1][0] * $this->matrix[0][1];
}
return false;
}
return match ($this->rows) {
1 => 0,
2 => $this->matrix[0][0] * $this->matrix[1][1] - $this->matrix[0][1] * $this->matrix[1][0],
3 => $this->matrix[0][0] * $this->matrix[1][1] * $this->matrix[2][2] + $this->matrix[0][1] * $this->matrix[1][2] * $this->matrix[2][0] + $this->matrix[0][2] * $this->matrix[1][0] * $this->matrix[2][1] - $this->matrix[2][0] * $this->matrix[1][1] * $this->matrix[0][2] - $this->matrix[2][1] * $this->matrix[1][2] * $this->matrix[0][0] - $this->matrix[2][2] * $this->matrix[1][0] * $this->matrix[0][1],
default => false,
};
}
//Computation of the determinant of 2x2 and 3x3 matrices

View file

@ -104,22 +104,15 @@ class Vector3{
}
public function getSide($side, $step = 1){
switch((int) $side){
case 0:
return new Vector3($this->x, $this->y - $step, $this->z);
case 1:
return new Vector3($this->x, $this->y + $step, $this->z);
case 2:
return new Vector3($this->x, $this->y, $this->z - $step);
case 3:
return new Vector3($this->x, $this->y, $this->z + $step);
case 4:
return new Vector3($this->x - $step, $this->y, $this->z);
case 5:
return new Vector3($this->x + $step, $this->y, $this->z);
default:
return $this;
}
return match ((int)$side) {
0 => new Vector3($this->x, $this->y - $step, $this->z),
1 => new Vector3($this->x, $this->y + $step, $this->z),
2 => new Vector3($this->x, $this->y, $this->z - $step),
3 => new Vector3($this->x, $this->y, $this->z + $step),
4 => new Vector3($this->x - $step, $this->y, $this->z),
5 => new Vector3($this->x + $step, $this->y, $this->z),
default => $this,
};
}
public function distance($x = 0, $y = 0, $z = 0){

View file

@ -38,37 +38,9 @@ abstract class RakNetInfo{
const ACK = 0xc0;
public static function isValid($pid){
switch((int) $pid){
case RakNetInfo::UNCONNECTED_PING:
case RakNetInfo::UNCONNECTED_PING_OPEN_CONNECTIONS:
case RakNetInfo::OPEN_CONNECTION_REQUEST_1:
case RakNetInfo::OPEN_CONNECTION_REPLY_1:
case RakNetInfo::OPEN_CONNECTION_REQUEST_2:
case RakNetInfo::OPEN_CONNECTION_REPLY_2:
case RakNetInfo::INCOMPATIBLE_PROTOCOL_VERSION:
case RakNetInfo::UNCONNECTED_PONG:
case RakNetInfo::ADVERTISE_SYSTEM:
case RakNetInfo::DATA_PACKET_0:
case RakNetInfo::DATA_PACKET_1:
case RakNetInfo::DATA_PACKET_2:
case RakNetInfo::DATA_PACKET_3:
case RakNetInfo::DATA_PACKET_4:
case RakNetInfo::DATA_PACKET_5:
case RakNetInfo::DATA_PACKET_6:
case RakNetInfo::DATA_PACKET_7:
case RakNetInfo::DATA_PACKET_8:
case RakNetInfo::DATA_PACKET_9:
case RakNetInfo::DATA_PACKET_A:
case RakNetInfo::DATA_PACKET_B:
case RakNetInfo::DATA_PACKET_C:
case RakNetInfo::DATA_PACKET_D:
case RakNetInfo::DATA_PACKET_E:
case RakNetInfo::DATA_PACKET_F:
case RakNetInfo::NACK:
case RakNetInfo::ACK:
return true;
default:
return false;
}
return match ((int)$pid) {
RakNetInfo::UNCONNECTED_PING, RakNetInfo::UNCONNECTED_PING_OPEN_CONNECTIONS, RakNetInfo::OPEN_CONNECTION_REQUEST_1, RakNetInfo::OPEN_CONNECTION_REPLY_1, RakNetInfo::OPEN_CONNECTION_REQUEST_2, RakNetInfo::OPEN_CONNECTION_REPLY_2, RakNetInfo::INCOMPATIBLE_PROTOCOL_VERSION, RakNetInfo::UNCONNECTED_PONG, RakNetInfo::ADVERTISE_SYSTEM, RakNetInfo::DATA_PACKET_0, RakNetInfo::DATA_PACKET_1, RakNetInfo::DATA_PACKET_2, RakNetInfo::DATA_PACKET_3, RakNetInfo::DATA_PACKET_4, RakNetInfo::DATA_PACKET_5, RakNetInfo::DATA_PACKET_6, RakNetInfo::DATA_PACKET_7, RakNetInfo::DATA_PACKET_8, RakNetInfo::DATA_PACKET_9, RakNetInfo::DATA_PACKET_A, RakNetInfo::DATA_PACKET_B, RakNetInfo::DATA_PACKET_C, RakNetInfo::DATA_PACKET_D, RakNetInfo::DATA_PACKET_E, RakNetInfo::DATA_PACKET_F, RakNetInfo::NACK, RakNetInfo::ACK => true,
default => false,
};
}
}

View file

@ -14,30 +14,13 @@ class Utils{
}*/
const emojiRegex = "([*#0-9](?>\\xEF\\xB8\\x8F)?\\xE2\\x83\\xA3|\\xC2[\\xA9\\xAE]|\\xE2..(\\xF0\\x9F\\x8F[\\xBB-\\xBF])?(?>\\xEF\\xB8\\x8F)?|\\xE3(?>\\x80[\\xB0\\xBD]|\\x8A[\\x97\\x99])(?>\\xEF\\xB8\\x8F)?|\\xF0\\x9F(?>[\\x80-\\x86].(?>\\xEF\\xB8\\x8F)?|\\x87.\\xF0\\x9F\\x87.|..(\\xF0\\x9F\\x8F[\\xBB-\\xBF])?|(((?<zwj>\\xE2\\x80\\x8D)\\xE2\\x9D\\xA4\\xEF\\xB8\\x8F\k<zwj>\\xF0\\x9F..(\k<zwj>\\xF0\\x9F\\x91.)?|(\\xE2\\x80\\x8D\\xF0\\x9F\\x91.){2,3}))?))";
public static function getEntityTypeByID($id){
switch($id){
case 10:
case 11:
case 12:
case 13:
case 32:
case 33:
case 34:
case 35:
case 36:
return ENTITY_MOB;
case 62:
case 65:
case 80:
case 81:
case 82:
case 83:
case 84:
return ENTITY_OBJECT;
case 66:
return FALLING_SAND;
}
return $id;
}
return match ($id) {
10, 11, 12, 13, 32, 33, 34, 35, 36 => ENTITY_MOB,
62, 65, 80, 81, 82, 83, 84 => ENTITY_OBJECT,
66 => FALLING_SAND,
default => $id,
};
}
public static function wrapAngleTo360($angle)
{