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

Feeding baby animals accelerate their growth #907

Merged
merged 9 commits into from Apr 29, 2018

Conversation

Projects
None yet
3 participants
@FlorentClarret
Member

FlorentClarret commented Apr 28, 2018

Hi,

Currently, animals can be fed, but it does nothing except removing the item in the player's main hand. With this PR, feeding babies will slowly accelerate their growth. Most of the time, feeding a baby takes 10% off the remaining time to grow up. However, it's a bit different for horses and llamas because it depends on the item.

I'm not really sure that my english is always correct here, so if you see something strange, tell me.

@FlorentClarret FlorentClarret changed the title from Feeding babies accelerate their growth to Feeding baby animals accelerate their growth Apr 28, 2018

player.getInventory()
.setItem(message.getHandSlot(), InventoryUtil.createEmptyStack());
}
player.getInventory().consumeItemInMainHand();

This comment has been minimized.

@momothereal

momothereal Apr 28, 2018

Member

You can get the hand slot that was used from the message data

protected int computeGrowthAmount(Material material) {
if (!isAdult() && getBreedingFoods().contains(material)) {
return Math.abs(getAge() / 10);
} else {

This comment has been minimized.

@momothereal

momothereal Apr 28, 2018

Member

The else statement is redundant because of the return statement.

@@ -67,7 +78,7 @@ private int getHorseFlags() {
}
if (this instanceof GlowHorse) {
GlowHorse horse = (GlowHorse) this;
if (getInventory() != null && ((HorseInventory) getInventory()).getSaddle() != null) {
if (getInventory() != null && getInventory().getSaddle() != null) {

This comment has been minimized.

@momothereal

momothereal Apr 28, 2018

Member

Replace the null check for the saddle with InventoryUtil.isEmpty

Integer mapResult = GROWING_FOODS.get(material);
if (mapResult != null) {
amount = Math.min(mapResult, Math.abs(getAge()));

This comment has been minimized.

@momothereal

momothereal Apr 28, 2018

Member

No need for that local variable. Just return at this line, and return 0 and the end of the method.

@@ -11,10 +14,20 @@
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Llama;
/**
* Represents a llama.
* The data come from https://minecraft.gamepedia.com/Llama

This comment has been minimized.

@momothereal

momothereal Apr 28, 2018

Member

Typo: the data comes from

Although this is debatable because data is the plural form of datum. However, data is used as a singular mass noun in everyday usage.

Integer mapResult = GROWING_FOODS.get(material);
if (mapResult != null) {
amount = Math.min(mapResult, Math.abs(getAge()));

This comment has been minimized.

@momothereal

momothereal Apr 28, 2018

Member

See previous review comment about the local variable.

@FlorentClarret

This comment has been minimized.

Member

FlorentClarret commented Apr 29, 2018

Done ;)

@@ -67,7 +79,7 @@ private int getHorseFlags() {
}
if (this instanceof GlowHorse) {
GlowHorse horse = (GlowHorse) this;
if (getInventory() != null && ((HorseInventory) getInventory()).getSaddle() != null) {
if (getInventory() != null && InventoryUtil.isEmpty(getInventory().getSaddle())) {

This comment has been minimized.

@momothereal

momothereal Apr 29, 2018

Member

This should be the opposite (!InventoryUtil.isEmpty)

This comment has been minimized.

@FlorentClarret

FlorentClarret Apr 29, 2018

Member

oops, my bad

@momothereal momothereal merged commit 7d8d85f into GlowstoneMC:dev Apr 29, 2018

2 checks passed

ci/circleci: build Your tests passed on CircleCI!
Details
license/cla Contributor License Agreement is signed.
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment