mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-19 15:35:52 +00:00
Added PlayerBucketEvent and children, improved Bucket usage and Liquid placing
This commit is contained in:
parent
79e4b3e3a9
commit
da23cf685d
@ -37,8 +37,8 @@ abstract class Liquid extends Transparent{
|
||||
public $isFullBlock = true;
|
||||
|
||||
public $adjacentSources = 0;
|
||||
public $isOptimalFlowDirection = [0, 0, 0];
|
||||
public $flowCost = [0, 0, 0];
|
||||
public $isOptimalFlowDirection = [0, 0, 0, 0];
|
||||
public $flowCost = [0, 0, 0, 0];
|
||||
|
||||
public function getFluidHeightPercent(){
|
||||
$d = $this->meta;
|
||||
@ -316,7 +316,9 @@ abstract class Liquid extends Transparent{
|
||||
}
|
||||
$blockSide = $this->getLevel()->getBlock(new Vector3($x, $y, $z));
|
||||
|
||||
if(!$blockSide->isFlowable or ($blockSide instanceof Liquid and $blockSide->getDamage() === 0)){
|
||||
if(!$blockSide->isFlowable and !($blockSide instanceof Liquid)){
|
||||
continue;
|
||||
}elseif($blockSide instanceof Liquid and $blockSide->getDamage() === 0){
|
||||
continue;
|
||||
}elseif($blockSide->getSide(0)->isFlowable){
|
||||
return $accumulatedCost;
|
||||
@ -356,7 +358,9 @@ abstract class Liquid extends Transparent{
|
||||
}
|
||||
$block = $this->getLevel()->getBlock(new Vector3($x, $y, $z));
|
||||
|
||||
if(!$block->isFlowable or ($block instanceof Liquid and $block->getDamage() === 0)){
|
||||
if(!$block->isFlowable and !($block instanceof Liquid)){
|
||||
continue;
|
||||
}elseif($block instanceof Liquid and $block->getDamage() === 0){
|
||||
continue;
|
||||
}elseif($block->getSide(0)->isFlowable){
|
||||
$this->flowCost[$j] = 0;
|
||||
|
34
src/pocketmine/event/player/PlayerBucketEmptyEvent.php
Normal file
34
src/pocketmine/event/player/PlayerBucketEmptyEvent.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
namespace pocketmine\event\player;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\Player;
|
||||
|
||||
class PlayerBucketEmptyEvent extends PlayerBucketEvent{
|
||||
public static $handlerList = null;
|
||||
|
||||
public function __construct(Player $who, Block $blockClicked, $blockFace, Item $bucket, Item $itemInHand){
|
||||
parent::__construct($who, $blockClicked, $blockFace, $bucket, $itemInHand);
|
||||
}
|
||||
}
|
86
src/pocketmine/event/player/PlayerBucketEvent.php
Normal file
86
src/pocketmine/event/player/PlayerBucketEvent.php
Normal file
@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
namespace pocketmine\event\player;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\event\Cancellable;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\Player;
|
||||
|
||||
abstract class PlayerBucketEvent extends PlayerEvent implements Cancellable{
|
||||
|
||||
/** @var Block */
|
||||
private $blockClicked;
|
||||
/** @var int */
|
||||
private $blockFace;
|
||||
/** @var Item */
|
||||
private $bucket;
|
||||
/** @var Item */
|
||||
private $item;
|
||||
|
||||
/**
|
||||
* @param Player $who
|
||||
* @param Block $blockClicked
|
||||
* @param int $blockFace
|
||||
* @param Item $bucket
|
||||
* @param Item $itemInHand
|
||||
*/
|
||||
public function __construct(Player $who, Block $blockClicked, $blockFace, Item $bucket, Item $itemInHand){
|
||||
$this->player = $who;
|
||||
$this->blockClicked = $blockClicked;
|
||||
$this->blockFace = (int) $blockFace;
|
||||
$this->item = $itemInHand;
|
||||
$this->bucket = $bucket;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the bucket used in this event
|
||||
*
|
||||
* @return Item
|
||||
*/
|
||||
public function getBucket(){
|
||||
return $this->bucket;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the item in hand after the event
|
||||
*
|
||||
* @return Item
|
||||
*/
|
||||
public function getItem(){
|
||||
return $this->item;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Item $item
|
||||
*/
|
||||
public function setItem(Item $item){
|
||||
$this->item = $item;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Block
|
||||
*/
|
||||
public function getBlockClicked(){
|
||||
return $this->blockClicked;
|
||||
}
|
||||
}
|
34
src/pocketmine/event/player/PlayerBucketFillEvent.php
Normal file
34
src/pocketmine/event/player/PlayerBucketFillEvent.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
namespace pocketmine\event\player;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\Player;
|
||||
|
||||
class PlayerBucketFillEvent extends PlayerBucketEvent{
|
||||
public static $handlerList = null;
|
||||
|
||||
public function __construct(Player $who, Block $blockClicked, $blockFace, Item $bucket, Item $itemInHand){
|
||||
parent::__construct($who, $blockClicked, $blockFace, $bucket, $itemInHand);
|
||||
}
|
||||
}
|
@ -25,6 +25,7 @@ use pocketmine\block\Air;
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\block\Liquid;
|
||||
use pocketmine\block\Water;
|
||||
use pocketmine\event\player\PlayerBucketFillEvent;
|
||||
use pocketmine\level\Level;
|
||||
use pocketmine\Player;
|
||||
|
||||
@ -36,35 +37,35 @@ class Bucket extends Item{
|
||||
}
|
||||
|
||||
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
if($this->meta === Item::AIR){
|
||||
if($target instanceof Liquid){
|
||||
$level->setBlock($target, new Air(), true);
|
||||
if(($player->gamemode & 0x01) === 0){
|
||||
$this->meta = ($target instanceof Water) ? Item::WATER : Item::LAVA;
|
||||
}
|
||||
$targetBlock = Block::get($this->meta);
|
||||
|
||||
return true;
|
||||
if($targetBlock instanceof Air){
|
||||
if($target instanceof Liquid and $target->getDamage() === 0){
|
||||
$result = clone $this;
|
||||
$result->setDamage($target->getID());
|
||||
$player->getServer()->getPluginManager()->callEvent($ev = new PlayerBucketFillEvent($player, $block, $face, $this, $result));
|
||||
if(!$ev->isCancelled()){
|
||||
$player->getLevel()->setBlock($target, new Air(), true, true);
|
||||
if($player->isSurvival()){
|
||||
$player->getInventory()->setItemInHand($ev->getItem(), $player);
|
||||
}
|
||||
return true;
|
||||
}else{
|
||||
$player->getInventory()->sendContents($player);
|
||||
}
|
||||
}
|
||||
}elseif($this->meta === Item::WATER){
|
||||
//Support Make Non-Support Water to Support Water
|
||||
if($block->getID() === self::AIR || ($block instanceof Water && ($block->getDamage() & 0x07) != 0x00)){
|
||||
$water = Block::get(Item::WATER, 0, $block);
|
||||
$water->place(clone $this, $block, $target, $face, $fx, $fy, $fz, $player);
|
||||
if(($player->gamemode & 0x01) === 0){
|
||||
$this->meta = 0;
|
||||
}elseif($targetBlock instanceof Liquid){
|
||||
$result = clone $this;
|
||||
$result->setDamage(0);
|
||||
$player->getServer()->getPluginManager()->callEvent($ev = new PlayerBucketFillEvent($player, $block, $face, $this, $result));
|
||||
if(!$ev->isCancelled()){
|
||||
$player->getLevel()->setBlock($block, $targetBlock, true, true);
|
||||
if($player->isSurvival()){
|
||||
$player->getInventory()->setItemInHand($ev->getItem(), $player);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}elseif($this->meta === Item::LAVA){
|
||||
$lava = Block::get(Item::LAVA, 0, $block);
|
||||
$lava->place(clone $this, $block, $target, $face, $fx, $fy, $fz, $player);
|
||||
if($block->getID() === self::AIR){
|
||||
if(($player->gamemode & 0x01) === 0){
|
||||
$this->meta = 0;
|
||||
}
|
||||
|
||||
return true;
|
||||
}else{
|
||||
$player->getInventory()->sendContents($player);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -97,7 +97,7 @@ class Vector3{
|
||||
*/
|
||||
public function add($x, $y = 0, $z = 0){
|
||||
if($x instanceof Vector3){
|
||||
return $this->add($x->x, $x->y, $x->z);
|
||||
return new Vector3($this->x + $x->x, $this->y + $x->y, $this->z + $x->z);
|
||||
}else{
|
||||
return new Vector3($this->x + $x, $this->y + $y, $this->z + $z);
|
||||
}
|
||||
@ -131,7 +131,10 @@ class Vector3{
|
||||
}
|
||||
|
||||
public function floor(){
|
||||
return new Vector3(Math::floorFloat($this->x), Math::floorFloat($this->y), Math::floorFloat($this->z));
|
||||
$x = (int) $this->x;
|
||||
$y = (int) $this->y;
|
||||
$z = (int) $this->z;
|
||||
return new Vector3($this->x >= $x ? $x : $x - 1, $this->y >= $y ? $y : $y - 1, $this->z >= $z ? $z : $z - 1);
|
||||
}
|
||||
|
||||
public function round(){
|
||||
|
Loading…
x
Reference in New Issue
Block a user