-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Add event for Copper Golem deciding whether an item belongs in a chest #13811
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
Open
jsbrn
wants to merge
7
commits into
PaperMC:main
Choose a base branch
from
jsbrn:feat/copper-golem-sorting-event
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
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 all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d0da070
Add Copper Golem pre-sort event
jsbrn fa58ac0
Add patch to use new pre-sort event
jsbrn 9e1f2b1
Add comment to pre-sort patch
jsbrn bc04ab0
Use tristate instead of two booleans
jsbrn 524f3d2
Merge branch 'main' into feat/copper-golem-sorting-event
jsbrn b24e693
Use consistent name for default golem sort behaviour
jsbrn 2739fa4
Apply behaviour enum rename patch
jsbrn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
90 changes: 90 additions & 0 deletions
90
paper-api/src/main/java/io/papermc/paper/event/entity/ItemTransportingEntitySortEvent.java
This file contains hidden or 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,90 @@ | ||
| package io.papermc.paper.event.entity; | ||
|
|
||
| import org.bukkit.block.Container; | ||
| import org.bukkit.entity.CopperGolem; | ||
| import org.bukkit.entity.Entity; | ||
| import org.bukkit.event.HandlerList; | ||
| import org.bukkit.event.entity.EntityEvent; | ||
| import org.bukkit.inventory.Inventory; | ||
| import org.bukkit.inventory.ItemStack; | ||
| import org.jetbrains.annotations.ApiStatus; | ||
| import org.jspecify.annotations.NullMarked; | ||
|
|
||
| /** | ||
| * Called when an item-transporting entity (typically a {@link CopperGolem}, | ||
| * although other entities may be possible through non-API means) | ||
| * is inspecting a destination {@link Container} to decide if the item it is holding | ||
| * belongs in said container. This gives plugin developers an opportunity to | ||
| * override the {@link CopperGolem}'s sorting behavior. | ||
| */ | ||
| @NullMarked | ||
| public class ItemTransportingEntitySortEvent extends EntityEvent { | ||
| protected static final HandlerList HANDLER_LIST = new HandlerList(); | ||
|
|
||
| public enum ItemTransportingEntityDecision { | ||
| ALLOW_DESTINATION, | ||
| REJECT_DESTINATION, | ||
| DEFAULT | ||
| } | ||
|
|
||
| private final ItemStack itemStack; | ||
| private final Inventory containerInventory; | ||
| private ItemTransportingEntityDecision decision; | ||
|
|
||
| @ApiStatus.Internal | ||
| public ItemTransportingEntitySortEvent( | ||
| final Entity entity, | ||
| final ItemStack itemStack, | ||
| final Inventory containerInventory | ||
| ) { | ||
| super(entity); | ||
| this.containerInventory = containerInventory; | ||
| this.itemStack = itemStack; | ||
| this.decision = ItemTransportingEntityDecision.DEFAULT; | ||
| } | ||
|
|
||
| /** | ||
| * Sets if the item belongs in the container. | ||
| * | ||
| * @param d Whether the item belongs in the chest. | ||
| */ | ||
| public void setDecision(boolean d) { | ||
| this.decision = d ? ItemTransportingEntityDecision.ALLOW_DESTINATION : ItemTransportingEntityDecision.REJECT_DESTINATION; | ||
| } | ||
|
|
||
| /** | ||
| * Gets if the held item stack belongs in the container. | ||
| * | ||
| * @return Whether the item stack belongs in the chest. | ||
| */ | ||
| public ItemTransportingEntityDecision getDecision() { | ||
| return this.decision; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the container the entity is comparing to the held item. | ||
| * | ||
| * @return The potential destination container | ||
| */ | ||
| public Inventory getContainerInventory() { | ||
| return this.containerInventory; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the held item stack being compared against the container. | ||
| * | ||
| * @return The held item stack | ||
| */ | ||
| public ItemStack getHeldItemStack() { | ||
| return this.itemStack; | ||
| } | ||
|
|
||
| public static HandlerList getHandlerList() { | ||
| return HANDLER_LIST; | ||
| } | ||
|
|
||
| @Override | ||
| public HandlerList getHandlers() { | ||
| return HANDLER_LIST; | ||
| } | ||
| } | ||
This file contains hidden or 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
This file contains hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.