9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-30 12:29:15 +00:00

支持低版本的酿造

This commit is contained in:
XiaoMoMi
2025-07-14 16:26:35 +08:00
parent 215c94f9ff
commit d736e466b3
4 changed files with 39 additions and 6 deletions

View File

@@ -274,7 +274,6 @@ public class BukkitRecipeManager extends AbstractRecipeManager<ItemStack> {
private Object stolenFeatureFlagSet;
// Some delayed tasks on main thread
private final List<Runnable> delayedTasksOnMainThread = new ArrayList<>();
private final Map<Key, PotionMix> brewingRecipes = new HashMap<>();
public BukkitRecipeManager(BukkitCraftEngine plugin) {
instance = this;
@@ -374,11 +373,11 @@ public class BukkitRecipeManager extends AbstractRecipeManager<ItemStack> {
if (recipe instanceof CustomBrewingRecipe<ItemStack> brewingRecipe) {
PotionMix potionMix = new PotionMix(new NamespacedKey(id.namespace(), id.value()),
brewingRecipe.result(ItemBuildContext.EMPTY),
PotionMix.createPredicateChoice(container -> {
new PredicateChoice(container -> {
Item<ItemStack> wrapped = this.plugin.itemManager().wrap(container);
return brewingRecipe.container().test(new UniqueIdItem<>(wrapped.recipeIngredientId(), wrapped));
}),
PotionMix.createPredicateChoice(ingredient -> {
new PredicateChoice(ingredient -> {
Item<ItemStack> wrapped = this.plugin.itemManager().wrap(ingredient);
return brewingRecipe.ingredient().test(new UniqueIdItem<>(wrapped.recipeIngredientId(), wrapped));
})

View File

@@ -0,0 +1,29 @@
package net.momirealms.craftengine.bukkit.item.recipe;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.RecipeChoice;
import org.jetbrains.annotations.NotNull;
import java.util.function.Predicate;
public record PredicateChoice(Predicate<ItemStack> predicate) implements RecipeChoice {
@Override
public @NotNull RecipeChoice clone() {
try {
return (PredicateChoice) super.clone();
} catch (final CloneNotSupportedException ex) {
throw new AssertionError(ex);
}
}
@Override
public @NotNull ItemStack getItemStack() {
throw new UnsupportedOperationException("PredicateChoice doesn't support getItemStack()");
}
@Override
public boolean test(@NotNull ItemStack itemStack) {
return this.predicate.test(itemStack);
}
}

View File

@@ -2219,8 +2219,13 @@ public class PacketConsumers {
FriendlyByteBuf buf = event.getBuffer();
Object friendlyBuf = FastNMS.INSTANCE.constructor$FriendlyByteBuf(buf);
short slotNum = buf.readShort();
ItemStack itemStack = VersionHelper.isOrAbove1_20_5() ?
FastNMS.INSTANCE.method$FriendlyByteBuf$readUntrustedItem(friendlyBuf) : FastNMS.INSTANCE.method$FriendlyByteBuf$readItem(friendlyBuf);
ItemStack itemStack;
try {
itemStack = VersionHelper.isOrAbove1_20_5() ?
FastNMS.INSTANCE.method$FriendlyByteBuf$readUntrustedItem(friendlyBuf) : FastNMS.INSTANCE.method$FriendlyByteBuf$readItem(friendlyBuf);
} catch (Exception e) {
return;
}
BukkitItemManager.instance().c2s(itemStack).ifPresent((newItemStack) -> {
event.setChanged(true);
buf.clear();