Skip to content

Instantly share code, notes, and snippets.

View Muqsit's full-sized avatar
👑
A beacon of hope.

Muqsit Muqsit

👑
A beacon of hope.
View GitHub Profile
@Muqsit
Muqsit / WeightedRandom.php
Last active May 16, 2024 22:39
Weighted random in PHP with O(1) runtime complexity (Alias Method)
<?php
declare(strict_types=1);
use pocketmine\utils\Binary; // https://github.com/pmmp/BinaryUtils
use pocketmine\utils\Random; // https://github.com/pmmp/PocketMine-MP/blob/60938c8c9df4bf21d096f142c6579dfad92eb8c2/src/utils/Random.php
/**
* @phpstan-template T
*/
<?php
use pocketmine\block\Block;
use pocketmine\event\player\PlayerInteractEvent;
use pocketmine\item\Item;
use pocketmine\math\Facing;
use pocketmine\utils\Random;
public function onPlayerInteract(PlayerInteractEvent $event) : void{
if($action === PlayerInteractEvent::RIGHT_CLICK_BLOCK && $item->getId() === Item::STICK){
<?php
const ITERATIONS = 100000;
benchmark(SORT_REGULAR, "SORT_REGULAR");
benchmark(SORT_NUMERIC, "SORT_NUMERIC");
function benchmark(int $sort_type, string $sort_type_string){
$array = [];
for($i = 0; $i < ITERATIONS; ++$i){
<?php
use pocketmine\block\Block;
use pocketmine\scheduler\Task;
use pocketmine\tile\Chest;
use pocketmine\tile\Tile;
public function onCommand(CommandSender $issuer, Command $cmd, string $label, array $args) : bool{
if($args[0] === 'xdt3'){
$forceId = isset($args[1]) ? 66 : null;
@Muqsit
Muqsit / DoubleChestDebug.php
Created June 23, 2018 18:00
Sends viewer count of a double chest and it's pairs.
<?php
/**
* @name DoubleChestDebug
* @main muqsit\dcdcd\Main
* @version 1.0
* @api 3.0.0
*/
namespace muqsit\dcdcd {
use pocketmine\plugin\PluginBase;
<?php
class A {
/** @var \SplFixedArray */
public $array;
public function __construct(){
$this->array = new \SplFixedArray(1);
<?php
namespace imt;
use muqsit\invmenu\{InvMenu, InvMenuHandler};
use pocketmine\block\Block;
use pocketmine\event\block\BlockPlaceEvent;
use pocketmine\event\Listener;
use pocketmine\item\Item;
use pocketmine\Player;
<?php
namespace villagertrade;
use pocketmine\entity\Villager;
use pocketmine\inventory\BaseInventory;
use pocketmine\item\Item;
use pocketmine\nbt\NetworkLittleEndianNBTStream;
use pocketmine\nbt\tag\{ByteTag, CompoundTag, IntTag, ListTag};
use pocketmine\network\mcpe\protocol\UpdateTradePacket;
use pocketmine\Player;
@Muqsit
Muqsit / StringUtils.php
Created January 16, 2018 15:59
minet str center
<?php
/**
* Source from:
* https://github.com/NiclasOlofsson/MiNET/blob/master/src/MiNET/MiNET/Utils/TextUtils.cs
*/
namespace cosmiccore\miscs;
use pocketmine\utils\TextFormat as TF;
class StringUtils {
@Muqsit
Muqsit / redistests.php
Last active December 20, 2017 15:23
Redis PHP get,set
<?php
//This is the redis database being selected
//Databases in redis are integers (0-15) unlike
//mysql where the database can be a string
const REDIS_DATABASE = 0;
$redis = new \Redis();// https://github.com/phpredis/phpredis
$redis->connect("127.0.0.1");