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
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue