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
[B+C] Add a way to induce mob breeding, adds BUKKIT-5687 #1085
Open
mcmonkey4eva
wants to merge
20
commits into
Bukkit:master
Choose a base branch
from
mcmonkey4eva:breeding
base: master
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 12 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
2911773
Add a way to induce mob breeding, adds BUKKIT-5687
mcmonkey4eva b16f6e7
Add details to the javadocs
mcmonkey4eva 3079406
Correct formatting
mcmonkey4eva b740fbe
Wrap docs
mcmonkey4eva 7ab259f
Add a timeout option
mcmonkey4eva d0da868
Add a note on null players
mcmonkey4eva cb2543e
Add alternate functions
mcmonkey4eva a297fc0
Add an entitybreedevent
mcmonkey4eva 491e4cc
Add breedWith function
mcmonkey4eva 90724c5
Add a note on required entity type
mcmonkey4eva 38fe520
Return the baby entity
mcmonkey4eva a76d521
Add get/set experience functions
mcmonkey4eva 771e744
Lowercase XP to xp
mcmonkey4eva de3aba9
Add getParents()
mcmonkey4eva a65483a
Clean docs
mcmonkey4eva 42eb5b4
Note enforced breedability
mcmonkey4eva b639f49
Remove breedWith
mcmonkey4eva 9e1b19f
Remove breeder from event
mcmonkey4eva dfbe7f1
Add getBreeder function to Animals
mcmonkey4eva 664bd88
Make the baby the main entity of the breed event
mcmonkey4eva File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,121 @@ | ||
package org.bukkit.entity; | ||
|
||
import org.bukkit.entity.Player; | ||
import org.bukkit.entity.Ageable; | ||
|
||
/** | ||
* Represents an Animal. | ||
*/ | ||
public interface Animals extends Ageable {} | ||
public interface Animals extends Ageable { | ||
|
||
/** | ||
* Determines if this animal is currently breeding. | ||
* An animal is considered to be breeding when it has been given food | ||
* (EG: wheat) and is looking for another animal of its species to mate | ||
* with and produce a baby animal. | ||
* Will return false again if the breeding attempt timed out or after the | ||
* mating was successful and a baby is spawned. | ||
* Will return true if the entity is actively breeding but hasn't yet had | ||
* a child. | ||
* | ||
* @return true if it is breeding. | ||
*/ | ||
public boolean isBreeding(); | ||
|
||
/** | ||
* Set whether this animal is currently trying to breed. | ||
* An animal is considered to be breeding when it has been given food | ||
* (EG: wheat) and is looking for another animal of its species to mate | ||
* with and produce a baby animal. | ||
* If 'breeding' is true, this function has the same result as given the | ||
* entity its breeding food (EG: wheat). | ||
* If 'breeding' is false, this function will take away any desire to | ||
* breed from the entity, and even stop an in-progress mating session. | ||
* Specify a non-null player to indicate that the given player was the | ||
* one who induced breeding, which will give any built in or plugin | ||
* created rewards (EG: an achievement) to that player when the breeding | ||
* is successful. | ||
* Specify a null player to simply not reward a player for successful | ||
* breeding. | ||
* | ||
* @param breeding whether the animal should try to breed. | ||
* @param player the player that induced the breeding. | ||
* @param timeout how many ticks until the breeding state automatically | ||
* cancels. The default is 600. | ||
*/ | ||
public void setBreeding(boolean breeding, Player player, int timeout); | ||
|
||
/** | ||
* Set whether this animal is currently trying to breed. | ||
* An animal is considered to be breeding when it has been given food | ||
* (EG: wheat) and is looking for another animal of its species to mate | ||
* with and produce a baby animal. | ||
* If 'breeding' is true, this function has the same result as given the | ||
* entity its breeding food (EG: wheat). | ||
* If 'breeding' is false, this function will take away any desire to | ||
* breed from the entity, and even stop an in-progress mating session. | ||
* This will assume a null player, meaning that no player will be given | ||
* any rewards (EG: an achievement) for a successful breeding. | ||
* Specify a null player to simply not reward a player for successful | ||
* breeding. | ||
* | ||
* @param breeding whether the animal should try to breed. | ||
* @param player the player that induced the breeding. | ||
* @param timeout how many ticks until the breeding state automatically | ||
* cancels. The default is 600. | ||
*/ | ||
public void setBreeding(boolean breeding, int timeout); | ||
|
||
/** | ||
* Set whether this animal is currently trying to breed. | ||
* An animal is considered to be breeding when it has been given food | ||
* (EG: wheat) and is looking for another animal of its species to mate | ||
* with and produce a baby animal. | ||
* If 'breeding' is true, this function has the same result as given the | ||
* entity its breeding food (EG: wheat). | ||
* If 'breeding' is false, this function will take away any desire to | ||
* breed from the entity, and even stop an in-progress mating session. | ||
* Specify a non-null player to indicate that the given player was the | ||
* one who induced breeding, which will give any built in or plugin | ||
* created rewards (EG: an achievement) to that player when the breeding | ||
* is successful. | ||
* Specify a null player to simply not reward a player for successful | ||
* breeding. | ||
* This will also assume a default breed timeout of 600 ticks. | ||
* | ||
* @param breeding whether the animal should try to breed. | ||
* @param player the player that induced the breeding. | ||
* @param timeout how many ticks until the breeding state automatically | ||
* cancels. The default is 600. | ||
*/ | ||
public void setBreeding(boolean breeding, Player player); | ||
|
||
/** | ||
* Set whether this animal is currently trying to breed. | ||
* An animal is considered to be breeding when it has been given food | ||
* (EG: wheat) and is looking for another animal of its species to mate | ||
* with and produce a baby animal. | ||
* If 'breeding' is true, this function has the same result as given the | ||
* entity its breeding food (EG: wheat). | ||
* If 'breeding' is false, this function will take away any desire to | ||
* breed from the entity, and even stop an in-progress mating session. | ||
* This will assume a null player, meaning that no player will be given | ||
* any rewards (EG: an achievement) for a successful breeding. | ||
* This will also assume a default breed timeout of 600 ticks. | ||
* | ||
* @param breeding whether the animal should try to breed. | ||
*/ | ||
public void setBreeding(boolean breeding); | ||
|
||
/** | ||
* Instantly breeds this animal with another. | ||
* Will spawn a baby animal at this animal's location. | ||
* The input animal must be of the same entity type as this animal. | ||
* Both this animal and the input animal will be unable to breed natural | ||
* for a short period of time. | ||
* Returns the baby entity created, or null if the event was cancelled. | ||
* | ||
* @param animal the animal to breed with. | ||
*/ | ||
public Ageable breedWith(Animals animal); | ||
} |
108 changes: 108 additions & 0 deletions
108
src/main/java/org/bukkit/event/entity/EntityBreedEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package org.bukkit.event.entity; | ||
|
||
import org.bukkit.entity.Animals; | ||
import org.bukkit.entity.Ageable; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.Cancellable; | ||
import org.bukkit.event.HandlerList; | ||
|
||
/** | ||
* Called when an {@link Animals} breeds with another animal. | ||
*/ | ||
public class EntityBreedEvent extends EntityEvent implements Cancellable { | ||
private static final HandlerList handlers = new HandlerList(); | ||
private final Animals entityTwo; | ||
private final Ageable baby; | ||
private Player breeder; | ||
private boolean cancelled; | ||
private int XP; | ||
|
||
public EntityBreedEvent(final Animals entity, final Animals entityTwo, final Player breeder, final Ageable baby, final int XP) { | ||
super(entity); | ||
this.entityTwo = entityTwo; | ||
this.breeder = breeder; | ||
this.baby = baby; | ||
this.XP = XP; | ||
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. As per java conventions. This should be 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. Will fix. |
||
} | ||
|
||
@Override | ||
public Animals getEntity() { | ||
return (Animals) entity; | ||
} | ||
|
||
/** | ||
* Returns the living entity that the main entity has bred with. | ||
* | ||
* @return the living entity that was bred with. | ||
*/ | ||
public Animals getBredWith() { | ||
return entityTwo; | ||
} | ||
|
||
/** | ||
* Returns the (currently unspawned) baby entity. | ||
* | ||
* @return the baby entity. | ||
*/ | ||
public Ageable getBaby() { | ||
return baby; | ||
} | ||
|
||
/** | ||
* Gets the player that started the breeding, if any. | ||
* If breeding was induced by plugin, may return null. | ||
* | ||
* @returns the breeder player, or null if none. | ||
*/ | ||
public Player getBreeder() { | ||
return breeder; | ||
} | ||
|
||
/** | ||
* Sets the player that is considered to have started the breeding, | ||
* if any. | ||
* The player set will receive potential rewards for breeding, | ||
* (EG: an achievement). | ||
* Set the player null to give nobody the reward. | ||
* | ||
* @param player the new breeder player, or null for none. | ||
*/ | ||
public void setBreeder(Player player) { | ||
breeder = player; | ||
} | ||
|
||
public boolean isCancelled() { | ||
return cancelled; | ||
} | ||
|
||
public void setCancelled(boolean cancel) { | ||
cancelled = cancel; | ||
} | ||
|
||
@Override | ||
public HandlerList getHandlers() { | ||
return handlers; | ||
} | ||
|
||
public static HandlerList getHandlerList() { | ||
return handlers; | ||
} | ||
|
||
/** | ||
* Gets the amount of experience that will be dropped by this event. | ||
* | ||
* @return the total amount of experience. | ||
*/ | ||
public int getExperience() { | ||
return XP; | ||
} | ||
|
||
/** | ||
* Changes the amount of XP this event will drop. | ||
* | ||
* @param newXP the amount of XP to drop. | ||
*/ | ||
public void setExperience(int newXP) { | ||
XP = newXP; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why is this an Ageable?
Can an Animal spawn a non-animal?
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.
Ask Mojang. The internals use Ageables for the child entities. It might be something set up for modding/future edits where animals can spawn non-animals.