Skip to content

Instantly share code, notes, and snippets.

View PJZ9n's full-sized avatar
🏠
Working from home

PJZ9n PJZ9n

🏠
Working from home
View GitHub Profile
@PJZ9n
PJZ9n / join.php
Created March 15, 2020 13:22
PMMP鯖側
<?php
//とても単純な例で、そのまま使うことを前提としていません
public function onJoin(PlayerJoinEvent $event): void {
//プレイヤーが入ったときに、Web側に所持金データを送信する
$ch = curl_init("http://aaa.com/money.php");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query([
"name" => $event->getPlayer()->getName(),
@PJZ9n
PJZ9n / web.php
Created March 15, 2020 13:24
Webサーバー(使う側)
<?php
//とても単純な例で、そのまま使うことを前提としていません
//同一ディレクトリに所持金記録用のmoney.jsonがあるとする
//処理金を返す
function getMoney(string $name): string {
$moneys = json_decode(file_get_contents("money.json"), true);
return $moneys[$name];
}
@PJZ9n
PJZ9n / irremote-buttons.ino
Created March 16, 2020 15:18
IRRemote用のボタン
const unsigned long BUTTON_ONE = 0xFFA25D;
const unsigned long BUTTON_TWO = 0xFF629D;
const unsigned long BUTTON_THREE = 0xFFE21D;
const unsigned long BUTTON_FOUR = 0xFF22DD;
const unsigned long BUTTON_FIVE = 0xFF02FD;
const unsigned long BUTTON_SIX = 0xFFC23D;
const unsigned long BUTTON_SEVEN = 0xFFE01F;
const unsigned long BUTTON_EIGHT = 0xFFA857;
const unsigned long BUTTON_NINE = 0xFF906F;
const unsigned long BUTTON_ZERO = 0xFF9867;
@PJZ9n
PJZ9n / getChunkPos.php
Last active April 6, 2020 07:20
Vector3からChunkの座標を取得する
/** @var $pos pocketmine\math\Vector3 */
$chunkX = $pos->getFloorX() >> 4;
$chunkZ = $pos->getFloorZ() >> 4;
//参考: https://github.com/pmmp/PocketMine-MP/blob/stable/src/pocketmine/level/Level.php#L2306
/** @var $pos pocketmine\math\Vector3 */
$chunkInX = $pos->getFloorX() & 0x0f;
$chunkInZ = $pos->getFloorZ() & 0x0f;
@PJZ9n
PJZ9n / positions.php
Last active April 10, 2020 20:40
二つの座標からその中の全座標を取得する
<?php
use pocketmine\math\Vector3;
/**
* 二つの座標からその中の全座標を取得する
*
* @param Vector3 $start
* @param Vector3 $end
* @param int $space 取得する間隔(細かさ)
@PJZ9n
PJZ9n / test.php
Last active April 20, 2020 23:23
コルーチンのやつ(動作未確認)
<?php
function test(): \Generator
{
for ($i = 1; $i <= 5; $i++) {
yield;//ここでGeneratorを返す(難しい) 位置が違った,修正済み
echo "Number is" . $i . PHP_EOL;
}
}
$this->getScheduler()->scheduleRepeatingTask(new class(test()) extends Task {
@PJZ9n
PJZ9n / test.php
Last active April 20, 2020 23:39
コルーチンのやつ(無名クラスではない版) 動作未確認、急いで勘で書いたからもしかしたら間違ってるかも
<?php
class TestTask extends Task
{
/** @var \Generator */
private $generator;
public function __construct(\Generator $generator)
{
$this->generator = $generator;
<?php
/**
* Copyright (c) 2020 NewCore.
*
* This file is part of NewCore.
*
* NewCore is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
<?php
/**
* Copyright (c) 2020 NewCore.
*
* This file is part of NewCore.
*
* NewCore is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
@PJZ9n
PJZ9n / math.php
Created April 22, 2020 01:02
二つの座標から中心の座標を求める
<?php
$ax = 0;
$ay = 0;
$bx = 500;
$by = 660;
$x = ($ax + $bx) / 2;
$y = ($ay + $by) / 2;