diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 000000000..fef4346f8 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,59 @@ +name: CI + +on: + push: + pull_request: + workflow_dispatch: + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + build: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v2 + with: + submodules: true + + - name: Restore PHP build cache + id: php-build-cache + uses: actions/cache@v2 + with: + path: "./bin" + key: "php-build-generic-${{ hashFiles('./build/php/compile.sh') }}" + + - name: Compile PHP + if: steps.php-build-cache.outputs.cache-hit != 'true' + run: | + sudo apt update && sudo apt install -y re2c libtool libtool-bin + march=x86-64 ./build/php/compile.sh -j8 + + - name: Prefix PHP to PATH + run: echo "$(pwd)/bin/php7/bin" >> $GITHUB_PATH + + - name: Install Composer + run: curl -sS https://getcomposer.org/installer | php + + - name: Restore Composer package cache + uses: actions/cache@v2 + with: + path: | + ~/.composer/cache/files + ~/.composer/cache/vcs + key: composer-cache + + - name: Install Composer dependencies + run: php composer.phar install --prefer-dist --no-interaction + + - name: Run PHPStan + run: ./vendor/bin/phpstan analyze --no-progress --memory-limit=2G + + - name: Run PHPUnit tests + run: ./vendor/bin/phpunit --bootstrap vendor/autoload.php --fail-on-warning tests/phpunit + + - name: Run integration tests + run: ./tests/travis.sh -t4 diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 89bc5120e..000000000 --- a/.travis.yml +++ /dev/null @@ -1,20 +0,0 @@ -import: - source: ./tests/travis/setup-php.yml - -script: - - composer install --prefer-dist - - ./vendor/bin/phpstan analyze --no-progress --memory-limit=2G - - ./vendor/bin/phpunit --bootstrap vendor/autoload.php --fail-on-warning tests/phpunit - - composer install --no-dev --prefer-dist - - ./tests/travis.sh -t4 - -cache: - - $HOME/.composer/cache/files - - $HOME/.composer/cache/vcs - -notifications: - email: - recipients: - - team@pmmp.io - on_success: change - on_failure: always diff --git a/src/block/BlockToolType.php b/src/block/BlockToolType.php index e7046bd87..8e6c36cd7 100644 --- a/src/block/BlockToolType.php +++ b/src/block/BlockToolType.php @@ -39,5 +39,6 @@ final class BlockToolType{ public const PICKAXE = 1 << 2; public const AXE = 1 << 3; public const SHEARS = 1 << 4; + public const HOE = 1 << 5; } diff --git a/src/block/Sponge.php b/src/block/Sponge.php index dd6491e7a..9d0325b9a 100644 --- a/src/block/Sponge.php +++ b/src/block/Sponge.php @@ -29,7 +29,7 @@ class Sponge extends Opaque{ protected $wet = false; public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){ - parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(0.6)); + parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(0.6, BlockToolType::HOE)); } protected function writeStateToMeta() : int{ diff --git a/src/item/Hoe.php b/src/item/Hoe.php index 2d3191954..87dd77c35 100644 --- a/src/item/Hoe.php +++ b/src/item/Hoe.php @@ -23,11 +23,24 @@ declare(strict_types=1); namespace pocketmine\item; +use pocketmine\block\Block; +use pocketmine\block\BlockToolType; use pocketmine\entity\Entity; class Hoe extends TieredTool{ + public function getBlockToolType() : int{ + return BlockToolType::HOE; + } + public function onAttackEntity(Entity $victim) : bool{ return $this->applyDamage(1); } + + public function onDestroyBlock(Block $block) : bool{ + if(!$block->getBreakInfo()->breaksInstantly()){ + return $this->applyDamage(1); + } + return false; + } } diff --git a/tests/travis/setup-php.yml b/tests/travis/setup-php.yml deleted file mode 100644 index cac532476..000000000 --- a/tests/travis/setup-php.yml +++ /dev/null @@ -1,79 +0,0 @@ -dist: xenial -language: php -php: - - 7.3 - - 7.4 - -before_script: - - phpenv config-rm xdebug.ini - - | - set -e - - LEVELDB_VERSION="f520e1d607759b00e335e332469c9c1b13e05f41" - if [ ! -f "./leveldb-mcpe/built_version" ] || [ $(cat "./leveldb-mcpe/built_version") != "$LEVELDB_VERSION" ]; then - echo "Building new LevelDB" - rm -rf "./leveldb-mcpe" || true - mkdir "./leveldb-mcpe" - - curl -fsSL "https://github.com/pmmp/leveldb/archive/$LEVELDB_VERSION.tar.gz" | tar -zx - mv "./leveldb-$LEVELDB_VERSION" leveldb-mcpe-build - DIR=$(pwd)/leveldb-mcpe - cd leveldb-mcpe-build - CFLAGS="-fPIC" CXXFLAGS="-fPIC" cmake . \ - -DCMAKE_INSTALL_PREFIX="$DIR" \ - -DCMAKE_PREFIX_PATH="$DIR" \ - -DCMAKE_INSTALL_LIBDIR=lib \ - -DLEVELDB_BUILD_TESTS=OFF \ - -DLEVELDB_BUILD_BENCHMARKS=OFF \ - -DLEVELDB_SNAPPY=OFF \ - -DLEVELDB_ZSTD=OFF \ - -DLEVELDB_TCMALLOC=OFF \ - -DCMAKE_BUILD_TYPE=Release - make -j4 install - - echo "$LEVELDB_VERSION" > "./built_version" - cd .. - else - echo "Using cached build for LevelDB version $LEVELDB_VERSION" - fi - - - git clone https://github.com/pmmp/php-leveldb.git leveldb - - cd leveldb - - git checkout bed651cf74e83139d97ebbcacc749fa7752b7782 - - phpize - - ./configure --with-leveldb=../leveldb-mcpe && make && make install - - cd .. - - git clone https://github.com/pmmp/ext-chunkutils2.git chunkutils - - cd chunkutils - - git checkout -f d8d762a597ac0da6f333f862096d6af0e6286b75 - - phpize - - ./configure && make && make install - - cd .. - # - pecl install channel://pecl.php.net/pthreads-3.1.6 - - echo | pecl install channel://pecl.php.net/yaml-2.1.0 - - pecl install channel://pecl.php.net/crypto-0.3.1 - - pecl install channel://pecl.php.net/ds-1.2.9 - - pecl install channel://pecl.php.net/igbinary-3.1.2 - - git clone https://github.com/pmmp/pthreads.git - - cd pthreads - - git checkout b81ab29df58fa0fb239a9d5ca1c2380a0d087feb - - phpize - - ./configure - - make - - make install - - cd .. - - | - git clone https://github.com/pmmp/ext-morton.git -b 0.1.0 --depth=1 - cd ext-morton - phpize - ./configure - make - make install - cd .. - - echo "extension=pthreads.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini - - echo "extension=chunkutils2.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini - - echo "extension=leveldb.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini - - echo "extension=morton.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini - - composer self-update --2 -cache: - - leveldb-mcpe