mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-21 20:19:44 +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
|
|
@ -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