-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d4a9578
commit 350514c
Showing
7 changed files
with
145 additions
and
34 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
paper-api/src/main/java/org/bukkit/inventory/ItemTypeRecipeChoiceImpl.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,37 @@ | ||
package org.bukkit.inventory; | ||
|
||
import com.google.common.base.Preconditions; | ||
import io.papermc.paper.registry.RegistryKey; | ||
import io.papermc.paper.registry.keys.ItemTypeKeys; | ||
import io.papermc.paper.registry.set.RegistryKeySet; | ||
import org.jspecify.annotations.NullMarked; | ||
|
||
@NullMarked | ||
record ItemTypeRecipeChoiceImpl(RegistryKeySet<ItemType> itemTypes) implements RecipeChoice.ItemTypeChoice { | ||
|
||
ItemTypeRecipeChoiceImpl { | ||
Preconditions.checkArgument(!itemTypes.isEmpty(), "RecipeChoice.ItemTypeChoice cannot be empty"); | ||
Preconditions.checkArgument(!(itemTypes.contains(ItemTypeKeys.AIR)), "RecipeChoice.ItemTypeChoice cannot contain minecraft:air"); | ||
} | ||
|
||
@Override | ||
public ItemStack getItemStack() { | ||
throw new UnsupportedOperationException("ItemTypeRecipeChoice does not support this"); | ||
} | ||
|
||
@Override | ||
public RecipeChoice clone() { | ||
return new ItemTypeRecipeChoiceImpl(this.itemTypes); | ||
} | ||
|
||
@Override | ||
public boolean test(final ItemStack itemStack) { | ||
return this.itemTypes.contains(RegistryKey.ITEM.typedKey(itemStack.getType().key())); | ||
} | ||
|
||
@Override | ||
public RecipeChoice validate(final boolean allowEmptyRecipes) { | ||
Preconditions.checkArgument(!(this.itemTypes.contains(ItemTypeKeys.AIR)), "RecipeChoice.ItemTypeChoice cannot contain minecraft:air"); | ||
return this; | ||
} | ||
} |
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
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
35 changes: 35 additions & 0 deletions
35
paper-server/patches/sources/net/minecraft/core/HolderSet.java.patch
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,35 @@ | ||
--- a/net/minecraft/core/HolderSet.java | ||
+++ b/net/minecraft/core/HolderSet.java | ||
@@ -166,6 +_,8 @@ | ||
private final TagKey<T> key; | ||
@Nullable | ||
private List<Holder<T>> contents; | ||
+ @Nullable | ||
+ private Set<io.papermc.paper.registry.TypedKey<?>> typedKeys; // Paper - cache typed key set for constant contains calls | ||
|
||
Named(HolderOwner<T> owner, TagKey<T> key) { | ||
this.owner = owner; | ||
@@ -174,6 +_,7 @@ | ||
|
||
void bind(List<Holder<T>> contents) { | ||
this.contents = List.copyOf(contents); | ||
+ this.typedKeys = null; // Paper - reset if tag is re-bound | ||
} | ||
|
||
public TagKey<T> key() { | ||
@@ -218,5 +_,15 @@ | ||
public boolean canSerializeIn(HolderOwner<T> owner) { | ||
return this.owner.canSerializeIn(owner); | ||
} | ||
+ | ||
+ // Paper start - cache typed key set for constant contains calls | ||
+ public boolean contains(io.papermc.paper.registry.TypedKey<?> key) { | ||
+ if (this.typedKeys == null) { | ||
+ this.typedKeys = this.contents().stream().map(h -> io.papermc.paper.registry.PaperRegistries.fromNms(h.unwrapKey().orElseThrow())).collect(java.util.stream.Collectors.toUnmodifiableSet()); | ||
+ } | ||
+ | ||
+ return this.typedKeys.contains(key); | ||
+ } | ||
+ // Paper end | ||
} | ||
} |
6 changes: 4 additions & 2 deletions
6
paper-server/patches/sources/net/minecraft/world/item/crafting/Ingredient.java.patch
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
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
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