mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-21 12:09:43 +00:00
rewritten how item durability/count is handled on serverside
This commit is contained in:
parent
4880be5452
commit
841e12b9ea
30 changed files with 128 additions and 152 deletions
|
|
@ -415,9 +415,8 @@ class BlockAPI{
|
|||
if($target->onBreak($item, $player) === false){
|
||||
return $this->cancelAction($target, $player, false);
|
||||
}
|
||||
if(($player->gamemode & 0x01) === 0 and $item->useOn($target) and $item->getMetadata() >= $item->getMaxDurability()){
|
||||
$player->setSlot($player->slot, new Item(AIR, 0, 0), false);
|
||||
}
|
||||
|
||||
$item->mineBlock($target, $player);
|
||||
}else{
|
||||
return $this->cancelAction($target, $player, false);
|
||||
}
|
||||
|
|
@ -446,7 +445,7 @@ class BlockAPI{
|
|||
|
||||
$target = $player->level->getBlock($vector);
|
||||
$block = $target->getSide($face);
|
||||
$item = $player->getSlot($player->slot);
|
||||
$item = $player->getHeldItem();
|
||||
|
||||
if($target->getID() === AIR and $this->server->api->dhandle("player.block.place.invalid", ["player" => $player, "block" => $block, "target" => $target, "item" => $item]) !== true){ //If no block exists or not allowed in CREATIVE
|
||||
if($this->server->api->dhandle("player.block.place.bypass", ["player" => $player, "block" => $block, "target" => $target, "item" => $item]) !== true){
|
||||
|
|
@ -479,10 +478,7 @@ class BlockAPI{
|
|||
return false;
|
||||
}
|
||||
|
||||
if($item->isActivable === true and $item->onActivate($player->level, $player, $block, $target, $face, $fx, $fy, $fz) === true){
|
||||
if($item->count <= 0){
|
||||
$player->setSlot($player->slot, BlockAPI::getItem(AIR, 0, 0), false);
|
||||
}
|
||||
if($item->isActivable === true && $item->onActivate($player->level, $player, $block, $target, $face, $fx, $fy, $fz) === true){
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -528,12 +524,7 @@ class BlockAPI{
|
|||
$t->data["creator"] = $player->username;
|
||||
}
|
||||
|
||||
if(($player->gamemode & 0x01) === 0x00){
|
||||
--$item->count;
|
||||
if($item->count <= 0){
|
||||
$player->setSlot($player->slot, BlockAPI::getItem(AIR, 0, 0), false);
|
||||
}
|
||||
}
|
||||
$player->consumeSingleItem();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,9 @@ class Player{
|
|||
public $slot;
|
||||
public $hotbar;
|
||||
public $curHotbarIndex = 0;
|
||||
/**
|
||||
* @var Item[]
|
||||
*/
|
||||
public $armor = [];
|
||||
public $loggedIn = false;
|
||||
public $gamemode;
|
||||
|
|
@ -193,7 +196,7 @@ class Player{
|
|||
public function getSpawn(){
|
||||
return $this->spawnPosition;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Vector3 $pos
|
||||
*
|
||||
|
|
@ -2302,10 +2305,7 @@ class Player{
|
|||
$e->shoot($e->speedX, $e->speedY, $e->speedZ, ($power+$power) * 1.5, 1.0);
|
||||
$this->server->api->entity->spawnToAll($e);
|
||||
if(($this->gamemode & 0x01) == 0x0) {
|
||||
$bow = $this->getSlot($this->slot);
|
||||
if(++$bow->meta >= $bow->getMaxDurability()){
|
||||
$this->inventory[$this->slot] = BlockAPI::getItem(AIR, 0, 0);
|
||||
}
|
||||
$this->getHeldItem()->hurtAndBreak(1, $this);
|
||||
$this->removeItem(ARROW, 0, 1, send: true);
|
||||
}
|
||||
}
|
||||
|
|
@ -2652,7 +2652,6 @@ class Player{
|
|||
$this->addCraftingIngridient($packet->slot, $slot->getID(), $slot->getMetadata(), $slot->count);
|
||||
$this->addCraftingResult($packet->slot, $citem->getID(), $citem->getMetadata(), $citem->count);
|
||||
}
|
||||
|
||||
}else{
|
||||
$this->toCraft = [];
|
||||
$this->craftingItems = [];
|
||||
|
|
@ -2998,7 +2997,22 @@ class Player{
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Removes a single item from whatever player is holding.
|
||||
* @param boolean $send Force send inventory to player.
|
||||
*/
|
||||
public function consumeSingleItem($send = false){
|
||||
$it = $this->getHeldItem();
|
||||
if(($this->gamemode & 0x01) === 0x00) --$it->count;
|
||||
|
||||
if($it->count <= 0){
|
||||
$this->setSlot($this->slot, BlockAPI::getItem(0, 0, 0), false);
|
||||
}
|
||||
|
||||
if($send) $this->sendInventory();
|
||||
}
|
||||
|
||||
public function removeItem($type, $damage, $count, $send = true){
|
||||
while($count > 0){
|
||||
$remove = 0;
|
||||
|
|
@ -3089,15 +3103,6 @@ class Player{
|
|||
}
|
||||
}
|
||||
|
||||
public function damageArmorPart($slot, $part){
|
||||
$part->useOn($this->entity, true);
|
||||
if($part->getMetadata() >= $part->getMaxDurability()){
|
||||
$this->setArmor($slot, BlockAPI::getItem(AIR, 0, 0), false);
|
||||
return;
|
||||
}
|
||||
$this->setArmor($slot, $part, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
|
|
@ -3121,6 +3126,11 @@ class Player{
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated armor is damaged by Entity::hurtArmor and cant be damaged by singular pieces
|
||||
*/
|
||||
public function damageArmorPart($slot, $part){}
|
||||
|
||||
/**
|
||||
* @deprecated 16x16x16 chunk sending was removed
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -140,9 +140,7 @@ abstract class Animal extends Creature implements Ageable, Breedable{
|
|||
if($e->isPlayer() && $action === InteractPacket::ACTION_HOLD){
|
||||
$slot = $e->player->getHeldItem();
|
||||
if($this->isFood($slot->getID()) && $this->inLove <= 0 && !$this->isBaby() && $this->loveTimeout <= 0){
|
||||
if(($e->player->gamemode & 0x01) === SURVIVAL){
|
||||
$e->player->removeItem($slot->getID(), $slot->getMetadata(), 1);
|
||||
}
|
||||
$e->player->consumeSingleItem();
|
||||
$this->inLove = 600;
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1047,11 +1047,7 @@ class Entity extends Position
|
|||
$slot = $e->player->getHeldItem();
|
||||
$damage = $slot->getDamageAgainstOf($this);
|
||||
$this->harm($damage, $e->eid);
|
||||
if($slot->isTool() && (!$this->isPlayer() || ($this->player->gamemode & 0x01) === 0)){
|
||||
if($slot->useOn($this) and $slot->getMetadata() >= $slot->getMaxDurability()){
|
||||
$e->player->removeItem($slot->getID(), $slot->getMetadata(), 1, true);
|
||||
}
|
||||
}
|
||||
$slot->hurtEnemy($this, $e->player); //TODO dont try destroying if harm was cancelled?
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
@ -1558,16 +1554,28 @@ class Entity extends Position
|
|||
foreach($this->player->armor as $slot => $part){
|
||||
if($part instanceof ArmorItem){
|
||||
$pnts += $part->getDamageReduceAmount();
|
||||
$this->player->damageArmorPart($slot, $part);
|
||||
}
|
||||
}
|
||||
$this->player->sendArmor($this->player);
|
||||
}
|
||||
return $pnts;
|
||||
}
|
||||
|
||||
public function hurtArmor($dmg){
|
||||
if($this->isPlayer()){
|
||||
$v2 = (int)($dmg / 4);
|
||||
if($v2 < 1) $v2 = 1;
|
||||
|
||||
foreach($this->player->armor as $slot => $part){
|
||||
$part->hurtAndBreak($v2, $this->player);
|
||||
}
|
||||
$this->player->sendArmor();
|
||||
}
|
||||
}
|
||||
|
||||
public function applyArmor($damage, $cause){
|
||||
if(is_numeric($cause) || $cause === "explosion"){
|
||||
$var3 = 25 - $this->getArmorValue();
|
||||
$this->hurtArmor($damage); //uses damage without armor affection
|
||||
$var4 = $damage * $var3 + $this->carryoverDamage;
|
||||
$damage = $var4 / 25;
|
||||
$this->carryoverDamage = $var4 % 25;
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ class Cow extends Animal{
|
|||
if($e->isPlayer() && $action === InteractPacket::ACTION_HOLD){
|
||||
$slot = $e->player->getHeldItem();
|
||||
if($slot->getID() === BUCKET && $slot->getMetadata() === 0){
|
||||
$e->player->removeItem($slot->getID(), $slot->getMetadata(), 1, true); //remove only 1 bucket
|
||||
$e->player->consumeSingleItem();
|
||||
$e->player->addItem(BUCKET, 1, 1, true);
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ class Pig extends Animal implements Rideable{
|
|||
|
||||
if($slot->getID() === SADDLE){
|
||||
if(!$this->isSaddled()){
|
||||
$e->player->removeItem($slot->getID(), 0, 1, send: true);
|
||||
$e->player->consumeSingleItem(send: true);
|
||||
$this->setSaddled(1);
|
||||
}
|
||||
return true; //avoid further interactions
|
||||
|
|
|
|||
|
|
@ -75,25 +75,18 @@ class Sheep extends Animal{
|
|||
$slot = $e->player->getHeldItem();
|
||||
if($slot->getID() === SHEARS){
|
||||
if(!$this->isSheared() && !$this->isBaby()){
|
||||
if($e->player->gamemode != 1) $slot->useOn($this);
|
||||
$this->setSheared(1);
|
||||
$speedX = (lcg_value() * 0.2 - 0.1) + (lcg_value() - lcg_value()) * 0.1;
|
||||
$speedZ = (lcg_value() * 0.2 - 0.1) + (lcg_value() - lcg_value()) * 0.1;
|
||||
$speedY = 0.2 + (lcg_value()) * 0.05;
|
||||
$this->server->api->entity->dropRawPos($this->level, $this->x, $this->y + 1, $this->z, BlockAPI::getItem(WOOL, $this->getColor(), mt_rand(1, 3)), $speedX, $speedY, $speedZ);
|
||||
if($slot->getMetadata() >= $slot->getMaxDurability()){
|
||||
$e->player->removeItem($slot->getID(), $slot->getMetadata(), $slot->count, true);
|
||||
}else{
|
||||
$e->player->setSlot($e->player->slot, $slot);
|
||||
}
|
||||
$slot->hurtAndBreak(1, $e->player);
|
||||
}
|
||||
return true;
|
||||
}elseif($slot->getID() === DYE){
|
||||
$this->setColor($this->switchColorMeta($slot->getMetadata()));
|
||||
|
||||
if(($e->player->gamemode & 0x01) === SURVIVAL){
|
||||
$e->player->removeItem($slot->getID(), $slot->getMetadata(), 1, true);
|
||||
}
|
||||
$e->player->consumeSingleItem();
|
||||
}
|
||||
}
|
||||
return parent::interactWith($e, $action);
|
||||
|
|
|
|||
|
|
@ -27,8 +27,6 @@ class Creeper extends Monster{
|
|||
$this->setState($v === null ? !$this->getState() : $v);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
|
|
@ -40,11 +38,7 @@ class Creeper extends Monster{
|
|||
if($e->isPlayer() && $action === InteractPacket::ACTION_HOLD){
|
||||
$slot = $e->player->getHeldItem();
|
||||
if($slot->getID() === FLINT_AND_STEEL && !$this->isIgnited()){
|
||||
if($slot->useOn($this) && $slot->getMetadata() >= $slot->getMaxDurability()){
|
||||
$e->player->removeItem($slot->getID(), $slot->getMetadata(), $slot->count, true);
|
||||
}else{
|
||||
$e->player->setSlot($e->player->slot, $slot);
|
||||
}
|
||||
$slot->hurtAndBreak(1, $e->player);
|
||||
$this->ignite();
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -220,18 +220,30 @@ class Item{
|
|||
|
||||
}
|
||||
|
||||
public function useOn($object, $force = false){
|
||||
if($force){
|
||||
if(($object instanceof Entity) and !$this->isSword()){
|
||||
$this->meta += 2;
|
||||
}else{
|
||||
$this->meta++;
|
||||
/**
|
||||
* @param int $dmg - damage dealt to item
|
||||
* @param Player $player - player who used the item
|
||||
*/
|
||||
public function hurtAndBreak($dmg, Player $player){
|
||||
if(($player->gamemode & 1) !== 0) return; //dont break items in creative
|
||||
|
||||
if($this->getMaxDurability() !== false){
|
||||
$this->meta += $dmg;
|
||||
if($this->meta > $this->getMaxDurability()){
|
||||
$player->consumeSingleItem();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public function hurtEnemy(Entity $target, Player $attacker){
|
||||
|
||||
}
|
||||
|
||||
public function mineBlock(Block $block, Player $player){
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public function isTool(){
|
||||
return false;
|
||||
}
|
||||
|
|
@ -334,4 +346,11 @@ class Item{
|
|||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Item damaging changed. Use hurtAndBreak to damage the item and update it in the client's inventory correctly.
|
||||
*/
|
||||
public function useOn($object, $force = false){
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,9 +10,7 @@ class TNTBlock extends SolidBlock{
|
|||
|
||||
public function onActivate(Item $item, Player $player){
|
||||
if($item->getID() === FLINT_STEEL){
|
||||
if(($player->gamemode & 0x01) === 0){
|
||||
$item->useOn($this);
|
||||
}
|
||||
$item->hurtAndBreak(1, $player);
|
||||
$data = array(
|
||||
"x" => $this->x + 0.5,
|
||||
"y" => $this->y,
|
||||
|
|
|
|||
|
|
@ -32,9 +32,7 @@ class BeetrootBlock extends FlowableBlock{
|
|||
$this->meta = 7;
|
||||
}
|
||||
$this->level->setBlock($this, $this, true, false, true);
|
||||
if(($player->gamemode & 0x01) === 0){
|
||||
$player->removeItem(DYE,0x0F,1);
|
||||
}
|
||||
$player->consumeSingleItem();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -25,9 +25,7 @@ class CarrotBlock extends FlowableBlock{
|
|||
$this->meta = 7;
|
||||
}
|
||||
$this->level->setBlock($this, $this, true, false, true);
|
||||
if(($player->gamemode & 0x01) === 0){
|
||||
$player->removeItem(DYE,0x0F,1);
|
||||
}
|
||||
$player->consumeSingleItem();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -34,11 +34,9 @@ class CyanFlowerBlock extends FlowableBlock{
|
|||
|
||||
public function onActivate(Item $item, Player $player){
|
||||
if($item->getID() === DYE and $item->getMetadata() === 0x0F){
|
||||
if(($player->gamemode & 0x01) === 0){
|
||||
$player->removeItem(DYE,0x0F,1);
|
||||
}
|
||||
$random = new Random();
|
||||
self::placeFlowers($this->level, new Vector3($this->x, $this->y, $this->z), $random, $random->nextRange(2, 5), 2);
|
||||
$player->consumeSingleItem();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -29,11 +29,9 @@ class DandelionBlock extends FlowableBlock{
|
|||
|
||||
public function onActivate(Item $item, Player $player){
|
||||
if($item->getID() === DYE and $item->getMetadata() === 0x0F){
|
||||
if(($player->gamemode & 0x01) === 0){
|
||||
$player->removeItem(DYE,0x0F,1);
|
||||
}
|
||||
$random = new Random();
|
||||
self::placeFlowers($this->level, new Vector3($this->x, $this->y, $this->z), $random, $random->nextRange(2, 5), 2);
|
||||
$player->consumeSingleItem();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -58,9 +58,7 @@ class MelonStemBlock extends FlowableBlock{
|
|||
$this->meta = 7;
|
||||
}
|
||||
$this->level->setBlock($this, $this, true, false, true);
|
||||
if(($player->gamemode & 0x01) === 0){
|
||||
$player->removeItem(DYE,0x0F,1);
|
||||
}
|
||||
$player->consumeSingleItem();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -34,9 +34,7 @@ class PotatoBlock extends FlowableBlock{
|
|||
$this->meta = 7;
|
||||
}
|
||||
$this->level->setBlock($this, $this, true, false, true);
|
||||
if(($player->gamemode & 0x01) === 0){
|
||||
$player->removeItem(DYE,0x0F,1);
|
||||
}
|
||||
$player->consumeSingleItem();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -58,9 +58,7 @@ class PumpkinStemBlock extends FlowableBlock{
|
|||
$this->meta = 7;
|
||||
}
|
||||
$this->level->setBlock($this, $this, true, false, true);
|
||||
if(($player->gamemode & 0x01) === 0){
|
||||
$player->removeItem(DYE,0x0F,1);
|
||||
}
|
||||
$player->consumeSingleItem();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -36,9 +36,7 @@ class SaplingBlock extends FlowableBlock{
|
|||
public function onActivate(Item $item, Player $player){
|
||||
if($item->getID() === DYE and $item->getMetadata() === 0x0F){ //Bonemeal
|
||||
TreeObject::growTree($this->level, $this, new Random(), $this->meta & 0x03);
|
||||
if(($player->gamemode & 0x01) === 0){
|
||||
$player->removeItem(DYE,0x0F,1);
|
||||
}
|
||||
$player->consumeSingleItem();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -29,9 +29,7 @@ class SugarcaneBlock extends FlowableBlock{
|
|||
$this->level->fastSetBlockUpdateMeta($this->x, $this->y, $this->z, $this->meta, true);
|
||||
}
|
||||
|
||||
if(($player->gamemode & 0x01) === 0){
|
||||
$player->removeItem(DYE,0x0F,1);
|
||||
}
|
||||
$player->consumeSingleItem();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -25,9 +25,7 @@ class WheatBlock extends FlowableBlock{
|
|||
$this->meta = 7;
|
||||
}
|
||||
$this->level->setBlock($this, $this, true, false, true);
|
||||
if(($player->gamemode & 0x01) === 0){
|
||||
$player->removeItem(DYE,0x0F,1);
|
||||
}
|
||||
$player->consumeSingleItem();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -11,11 +11,7 @@ class DirtBlock extends SolidBlock{
|
|||
public function onActivate(Item $item, Player $player){
|
||||
if($item->isHoe()){
|
||||
if($this->getSide(1)->isTransparent === false) return false;
|
||||
if(($player->gamemode & 0x01) === 0){
|
||||
$item->useOn($this);
|
||||
if($item->getMetadata() >= $item->getMaxDurability()) $player->setSlot($player->slot, new Item(AIR, 0, 0), false);
|
||||
else $player->setSlot($player->slot, $item, true);
|
||||
}
|
||||
$item->hurtAndBreak(1, $player); //TODO move to ItemHoe
|
||||
$this->level->fastSetBlockUpdate($this->x, $this->y, $this->z, FARMLAND, 0, true);
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,18 +16,12 @@ class GrassBlock extends SolidBlock{
|
|||
|
||||
public function onActivate(Item $item, Player $player){
|
||||
if($item->getID() === DYE and $item->getMetadata() === 0x0F){
|
||||
if(($player->gamemode & 0x01) === 0){
|
||||
$player->removeItem(DYE,0x0F,1);
|
||||
}
|
||||
$player->consumeSingleItem();
|
||||
TallGrassObject::growGrass($this->level, $this, new Random(), 8, 2);
|
||||
return true;
|
||||
}elseif($item->isHoe()){
|
||||
if($this->getSide(1)->isTransparent === false) return false;
|
||||
if(($player->gamemode & 0x01) === 0){
|
||||
$item->useOn($this);
|
||||
if($item->getMetadata() >= $item->getMaxDurability()) $player->setSlot($player->slot, new Item(AIR, 0, 0), false);
|
||||
else $player->setSlot($player->slot, $item, true);
|
||||
}
|
||||
$item->hurtAndBreak(1, $player); //TODO move to ItemHoe
|
||||
$this->level->fastSetBlockUpdate($this->x, $this->y, $this->z, FARMLAND, 0, true);
|
||||
$this->seedsDrop();
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -5,15 +5,6 @@ abstract class ItemHoe extends ItemTool
|
|||
public function isHoe(){
|
||||
return true;
|
||||
}
|
||||
|
||||
public function useOn($object, $force = false){
|
||||
if(($object instanceof Block) and ($object->getID() === GRASS or $object->getID() === DIRT)){
|
||||
$this->meta++;
|
||||
return true;
|
||||
}else{
|
||||
return parent::useOn($object, $force);
|
||||
}
|
||||
}
|
||||
|
||||
public function getLevel(){
|
||||
return match ($this->id) {
|
||||
|
|
|
|||
|
|
@ -17,5 +17,15 @@ abstract class ItemSword extends ItemTool
|
|||
default => false,
|
||||
};
|
||||
}
|
||||
|
||||
public function hurtEnemy(Entity $target, Player $attacker){
|
||||
$this->hurtAndBreak(1, $attacker);
|
||||
}
|
||||
|
||||
|
||||
public function mineBlock(Block $block, Player $player){
|
||||
$this->hurtAndBreak(2, $player);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,16 +11,23 @@ abstract class ItemTool extends Item
|
|||
public function isTool(){
|
||||
return true;
|
||||
}
|
||||
public function useOn($object, $force = false){
|
||||
|
||||
if($this->isSword() && !($object instanceof Entity)){
|
||||
$this->meta += 2;
|
||||
}else if(($object instanceof Entity) && !$this->isSword()){
|
||||
$this->meta += 2;
|
||||
}else{
|
||||
$this->meta++;
|
||||
|
||||
public function hurtEnemy(Entity $target, Player $attacker){
|
||||
if($this->isPickaxe() || $this->isAxe() || $this->isShovel()){
|
||||
$this->hurtAndBreak(2, $attacker);
|
||||
return;
|
||||
}
|
||||
return true;
|
||||
|
||||
parent::hurtEnemy($target, $attacker);
|
||||
}
|
||||
|
||||
public function mineBlock(Block $block, Player $player){
|
||||
if($this->isPickaxe() || $this->isAxe() || $this->isShovel()){
|
||||
$this->hurtAndBreak(1, $player);
|
||||
return true;
|
||||
}
|
||||
|
||||
return parent::mineBlock($block, $player);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,8 +18,6 @@ class MinecartItem extends Item{
|
|||
];
|
||||
$e = $server->api->entity->add($level, ENTITY_OBJECT, OBJECT_MINECART, $data);
|
||||
$server->api->entity->spawnToAll($e);
|
||||
if(($player->gamemode & 0x01) === 0x00){
|
||||
$player->removeItem($this->getID(), $this->getMetadata(), 1, false);
|
||||
}
|
||||
$player->consumeSingleItem();
|
||||
}
|
||||
}
|
||||
|
|
@ -38,7 +38,7 @@ class PaintingItem extends Item{
|
|||
private static $right = array(4, 5, 3, 2);
|
||||
|
||||
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
if($target->isTransparent === false and $face > 1 and $block->isSolid === false){
|
||||
if($target->isTransparent === false && $face > 1 and $block->isSolid === false){
|
||||
$server = ServerAPI::request();
|
||||
|
||||
if($face < 2 || $face > 5) return;
|
||||
|
|
@ -65,9 +65,8 @@ class PaintingItem extends Item{
|
|||
$painting->eid = $server->api->entity->getNextEID();
|
||||
$server->api->entity->addRaw($painting);
|
||||
$server->api->entity->spawnToAll($painting);
|
||||
if(($player->gamemode & 0x01) === 0x00){
|
||||
$player->removeItem($this->getID(), $this->getMetadata(), 1, false);
|
||||
}
|
||||
|
||||
$player->consumeSingleItem();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -17,9 +17,7 @@ class SpawnEggItem extends Item{
|
|||
);
|
||||
$e = ServerAPI::request()->api->entity->add($block->level, ENTITY_MOB, $this->meta, $data);
|
||||
ServerAPI::request()->api->entity->spawnToAll($e);
|
||||
if(($player->gamemode & 0x01) === 0){
|
||||
-- $this->count;
|
||||
}
|
||||
$player->consumeSingleItem();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -8,19 +8,11 @@ class FlintSteelItem extends ItemTool{
|
|||
}
|
||||
|
||||
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
if(($player->gamemode & 0x01) === 0 and $this->useOn($block) and $this->getMetadata() >= $this->getMaxDurability()){
|
||||
$player->setSlot($player->slot, new Item(AIR, 0, 0), false);
|
||||
}
|
||||
|
||||
$this->hurtAndBreak(1, $player);
|
||||
if($block->getID() === AIR && $target->isSolid){
|
||||
$level->fastSetBlockUpdate($block->x, $block->y, $block->z, FIRE, 0, true);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function useOn($object, $force = false){
|
||||
++$this->meta;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -5,11 +5,11 @@ class ShearsItem extends ItemTool{
|
|||
parent::__construct(SHEARS, $meta, $count, "Shears");
|
||||
}
|
||||
|
||||
public function useOn($object, $force = false){
|
||||
if(($object instanceof Sheep) and $this->id === SHEARS){
|
||||
$this->meta++;
|
||||
public function mineBlock(Block $block, Player $player){
|
||||
if($block->getID() === LEAVES || $block->getID() === COBWEB){
|
||||
$this->hurtAndBreak(1, $player);
|
||||
return true;
|
||||
}
|
||||
parent::useOn($object, $force);
|
||||
return parent::mineBlock($block, $player);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue