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
Changes from 2 commits
4f3ce8e
7fc93ce
e43ac73
97cac89
f46e7ba
33eb94a
2f3c562
ef44ea5
c71d92f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,9 +45,8 @@ protected int getAmbientDelay() { | |
|
||
@Override | ||
public boolean entityInteract(GlowPlayer player, InteractEntityMessage message) { | ||
super.entityInteract(player, message); | ||
|
||
if (message.getAction() == InteractEntityMessage.Action.INTERACT.ordinal()) { | ||
if (!super.entityInteract(player, message) | ||
&& message.getAction() == InteractEntityMessage.Action.INTERACT.ordinal()) { | ||
ItemStack item = InventoryUtil | ||
.itemOrEmpty(player.getInventory().getItem(message.getHandSlot())); | ||
|
||
|
@@ -60,7 +59,9 @@ public boolean entityInteract(GlowPlayer player, InteractEntityMessage message) | |
&& getBreedingFoods().contains(item.getType())) { | ||
// TODO set love mode if possible and spawn particles | ||
// TODO heal | ||
// TODO only consume the item if the animal is healed or something else | ||
player.getInventory().consumeItemInMainHand(); | ||
return true; | ||
} | ||
} | ||
|
||
|
@@ -74,4 +75,13 @@ && getBreedingFoods().contains(item.getType())) { | |
public Set<Material> getBreedingFoods() { | ||
return DEFAULT_BREEDING_FOODS; | ||
} | ||
|
||
@Override | ||
protected int computeGrowthAmount(Material material) { | ||
if (!isAdult() && getBreedingFoods().contains(material)) { | ||
return Math.abs(getAge() / 10); | ||
} else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The else statement is redundant because of the return statement. |
||
return 0; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
package net.glowstone.entity.passive; | ||
|
||
import com.flowpowered.network.Message; | ||
import com.google.common.collect.ImmutableMap; | ||
import com.google.common.collect.Sets; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
@@ -15,13 +17,22 @@ | |
import org.bukkit.entity.ChestedHorse; | ||
import org.bukkit.entity.EntityType; | ||
import org.bukkit.entity.Horse; | ||
import org.bukkit.inventory.HorseInventory; | ||
|
||
public abstract class GlowAbstractHorse extends GlowTameable implements AbstractHorse { | ||
|
||
private static final Set<Material> BREEDING_FOODS = Sets.immutableEnumSet(Material.GOLDEN_APPLE, | ||
Material.GOLDEN_CARROT); | ||
|
||
private static final Map<Material, Integer> GROWING_FOODS = ImmutableMap | ||
.<Material, Integer>builder() | ||
.put(Material.SUGAR, 600) | ||
.put(Material.WHEAT, 400) | ||
.put(Material.APPLE, 1200) | ||
.put(Material.GOLDEN_CARROT, 1200) | ||
.put(Material.GOLDEN_APPLE, 4800) | ||
.put(Material.HAY_BLOCK, 3600) | ||
.build(); | ||
|
||
@Getter | ||
@Setter | ||
private int domestication; | ||
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replace the null check for the saddle with |
||
value |= 0x04; | ||
} | ||
if (horse.hasReproduced()) { | ||
|
@@ -90,4 +101,20 @@ private int getHorseFlags() { | |
public Set<Material> getBreedingFoods() { | ||
return BREEDING_FOODS; | ||
} | ||
|
||
@Override | ||
protected int computeGrowthAmount(Material material) { | ||
int amount = 0; | ||
|
||
// We need to be a baby and only tamed horses can be fed with hay block | ||
if (!isAdult() && !(Material.HAY_BLOCK == material && !isTamed())) { | ||
Integer mapResult = GROWING_FOODS.get(material); | ||
|
||
if (mapResult != null) { | ||
amount = Math.min(mapResult, Math.abs(getAge())); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need for that local variable. Just return at this line, and return |
||
} | ||
} | ||
|
||
return amount; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
package net.glowstone.entity.passive; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import com.google.common.collect.Sets; | ||
|
||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.concurrent.ThreadLocalRandom; | ||
import net.glowstone.entity.meta.MetadataIndex; | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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. |
||
*/ | ||
public class GlowLlama extends GlowChestedHorse<GlowLlamaInventory> implements Llama { | ||
|
||
private static final Set<Material> BREEDING_FOODS = Sets.immutableEnumSet(Material.HAY_BLOCK); | ||
|
||
private static final Map<Material, Integer> GROWING_FOODS = ImmutableMap | ||
.<Material, Integer>builder() | ||
.put(Material.WHEAT, 200) | ||
.put(Material.HAY_BLOCK, 1800) | ||
.build(); | ||
|
||
/** | ||
* Creates a llama entity. | ||
* | ||
|
@@ -81,4 +94,20 @@ protected GlowLlamaInventory createNewInventory() { | |
public Set<Material> getBreedingFoods() { | ||
return BREEDING_FOODS; | ||
} | ||
|
||
@Override | ||
protected int computeGrowthAmount(Material material) { | ||
int amount = 0; | ||
|
||
if (!isAdult()) { | ||
Integer mapResult = GROWING_FOODS.get(material); | ||
|
||
if (mapResult != null) { | ||
amount = Math.min(mapResult, Math.abs(getAge())); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See previous review comment about the local variable. |
||
} | ||
} | ||
|
||
return amount; | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can get the hand slot that was used from the message data