Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allowed players to eat in creative mode and difficulty peaceful #5923

Open
wants to merge 12 commits into
base: minor-next
Choose a base branch
from
9 changes: 7 additions & 2 deletions src/entity/Human.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,13 @@ public function getHungerManager() : HungerManager{
}

public function consumeObject(Consumable $consumable) : bool{
NTT1906 marked this conversation as resolved.
Show resolved Hide resolved
if($consumable instanceof FoodSource && $consumable->requiresHunger() && !$this->hungerManager->isHungry()){
return false;
if ($consumable instanceof FoodSource) {
NTT1906 marked this conversation as resolved.
Show resolved Hide resolved
if ($this instanceof Player && $this->allowForceEating()) {
NTT1906 marked this conversation as resolved.
Show resolved Hide resolved
return parent::consumeObject($consumable);
}
if ($consumable->requiresHunger() && !$this->getHungerManager()->isHungry()){
return false;
}
}

ShockedPlot7560 marked this conversation as resolved.
Show resolved Hide resolved
return parent::consumeObject($consumable);
Expand Down
2 changes: 1 addition & 1 deletion src/item/Food.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ public function onConsume(Living $consumer) : void{
}

public function canStartUsingItem(Player $player) : bool{
return !$this->requiresHunger() || $player->getHungerManager()->isHungry();
return $player->allowForceEating() || !$this->requiresHunger() || $player->getHungerManager()->isHungry();
}
}
7 changes: 7 additions & 0 deletions src/player/Player.php
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,13 @@ public function setUsingItem(bool $value) : void{
$this->networkPropertiesDirty = true;
}

/**
* Allow eating
*/
public function allowForceEating () : bool{
NTT1906 marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a fan of this name. It feels way too specific.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a fan of this name. It feels way too specific.

what is your idea?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

canPlayerConsume

canPlayerSnack
canPlayerChew
canPlayerDevour
isPlayerFamished

allowForceFeast
canFreelyEating

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could canEatAnytime better ? It can't include player because it's linked to Human and not only Player.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None of these address my original comment.
I'm thinking more along the lines of canEat(), which covers the creative case and hunger together.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

canEat() seems too general, but I too go with that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ShockedPlot7560 Can I go with "canEatWithoutHunger"?

return $this->isCreative() || $this->getWorld()->getDifficulty() === World::DIFFICULTY_PEACEFUL;
}

/**
* Returns how long the player has been using their currently-held item for. Used for determining arrow shoot force
* for bows.
Expand Down