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

配方后处理器的准备

This commit is contained in:
XiaoMoMi
2025-07-17 16:02:50 +08:00
parent fd2c9e637b
commit 5e3115c08c
18 changed files with 118 additions and 46 deletions

View File

@@ -42,13 +42,13 @@ public class BukkitCustomItem extends AbstractCustomItem<ItemStack> {
}
@Override
public Item<ItemStack> buildItem(ItemBuildContext context) {
ItemStack item = FastNMS.INSTANCE.method$CraftItemStack$asCraftMirror(FastNMS.INSTANCE.constructor$ItemStack(this.item, 1));
public Item<ItemStack> buildItem(ItemBuildContext context, int count) {
ItemStack item = FastNMS.INSTANCE.method$CraftItemStack$asCraftMirror(FastNMS.INSTANCE.constructor$ItemStack(this.item, count));
Item<ItemStack> wrapped = BukkitCraftEngine.instance().itemManager().wrap(item);
for (ItemDataModifier<ItemStack> modifier : dataModifiers()) {
modifier.apply(wrapped, context);
}
return BukkitCraftEngine.instance().itemManager().wrap(wrapped.getItem());
return wrapped;
}
public Object clientItem() {

View File

@@ -29,8 +29,6 @@ import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigExce
import net.momirealms.craftengine.core.plugin.logger.Debugger;
import net.momirealms.craftengine.core.util.*;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.Registry;
import org.bukkit.event.HandlerList;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
@@ -165,11 +163,11 @@ public class BukkitItemManager extends AbstractItemManager<ItemStack> {
@Override
public Optional<BuildableItem<ItemStack>> getVanillaItem(Key key) {
Material material = Registry.MATERIAL.get(KeyUtils.toNamespacedKey(key));
if (material == null) {
ItemStack vanilla = createVanillaItemStack(key);
if (vanilla == null) {
return Optional.empty();
}
return Optional.of(new CloneableConstantItem(key, new ItemStack(material)));
return Optional.of(new CloneableConstantItem(key, this.wrap(vanilla)));
}
@Override

View File

@@ -1,15 +1,16 @@
package net.momirealms.craftengine.bukkit.item;
import net.momirealms.craftengine.core.item.BuildableItem;
import net.momirealms.craftengine.core.item.Item;
import net.momirealms.craftengine.core.item.ItemBuildContext;
import net.momirealms.craftengine.core.util.Key;
import org.bukkit.inventory.ItemStack;
public class CloneableConstantItem implements BuildableItem<ItemStack> {
private final ItemStack item;
private final Item<ItemStack> item;
private final Key id;
public CloneableConstantItem(Key id, ItemStack item) {
public CloneableConstantItem(Key id, Item<ItemStack> item) {
this.item = item;
this.id = id;
}
@@ -19,10 +20,13 @@ public class CloneableConstantItem implements BuildableItem<ItemStack> {
return this.id;
}
@Override
public Item<ItemStack> buildItem(ItemBuildContext context, int count) {
return this.item.copyWithCount(count);
}
@Override
public ItemStack buildItemStack(ItemBuildContext context, int count) {
ItemStack itemStack = this.item.clone();
itemStack.setAmount(count);
return itemStack;
return this.item.copyWithCount(count).getItem();
}
}

View File

@@ -561,7 +561,7 @@ public class BukkitRecipeManager extends AbstractRecipeManager<ItemStack> {
}
CustomStoneCuttingRecipe<ItemStack> ceRecipe = new CustomStoneCuttingRecipe<>(
id, recipe.group(), Ingredient.of(holders),
new CustomRecipeResult<>(new CloneableConstantItem(recipe.result().isCustom() ? Key.of("!internal:custom") : Key.of(recipe.result().id()), result), recipe.result().count())
new CustomRecipeResult<>(new CloneableConstantItem(recipe.result().isCustom() ? Key.of("!internal:custom") : Key.of(recipe.result().id()), BukkitItemManager.instance().wrap(result)), recipe.result().count(), null)
);
this.registerInternalRecipe(id, ceRecipe);
}
@@ -590,7 +590,7 @@ public class BukkitRecipeManager extends AbstractRecipeManager<ItemStack> {
}
CustomShapelessRecipe<ItemStack> ceRecipe = new CustomShapelessRecipe<>(
id, recipe.category(), recipe.group(), ingredientList,
new CustomRecipeResult<>(new CloneableConstantItem(recipe.result().isCustom() ? Key.of("!internal:custom") : Key.of(recipe.result().id()), result), recipe.result().count())
new CustomRecipeResult<>(new CloneableConstantItem(recipe.result().isCustom() ? Key.of("!internal:custom") : Key.of(recipe.result().id()), BukkitItemManager.instance().wrap(result)), recipe.result().count(), null)
);
if (hasCustomItemInTag) {
Runnable converted = findNMSRecipeConvertor(ceRecipe).convert(id, ceRecipe);
@@ -627,7 +627,7 @@ public class BukkitRecipeManager extends AbstractRecipeManager<ItemStack> {
CustomShapedRecipe<ItemStack> ceRecipe = new CustomShapedRecipe<>(
id, recipe.category(), recipe.group(),
new CustomShapedRecipe.Pattern<>(recipe.pattern(), ingredients),
new CustomRecipeResult<>(new CloneableConstantItem(recipe.result().isCustom() ? Key.of("!internal:custom") : Key.of(recipe.result().id()), result), recipe.result().count())
new CustomRecipeResult<>(new CloneableConstantItem(recipe.result().isCustom() ? Key.of("!internal:custom") : Key.of(recipe.result().id()), BukkitItemManager.instance().wrap(result)), recipe.result().count(), null)
);
if (hasCustomItemInTag) {
Runnable converted = findNMSRecipeConvertor(ceRecipe).convert(id, ceRecipe);
@@ -651,7 +651,7 @@ public class BukkitRecipeManager extends AbstractRecipeManager<ItemStack> {
id, recipe.category(), recipe.group(),
Ingredient.of(holders),
recipe.cookingTime(), recipe.experience(),
new CustomRecipeResult<>(new CloneableConstantItem(recipe.result().isCustom() ? Key.of("!internal:custom") : Key.of(recipe.result().id()), result), recipe.result().count())
new CustomRecipeResult<>(new CloneableConstantItem(recipe.result().isCustom() ? Key.of("!internal:custom") : Key.of(recipe.result().id()), BukkitItemManager.instance().wrap(result)), recipe.result().count(), null)
);
if (hasCustomItemInTag) {
Runnable converted = findNMSRecipeConvertor(ceRecipe).convert(id, ceRecipe);
@@ -680,7 +680,7 @@ public class BukkitRecipeManager extends AbstractRecipeManager<ItemStack> {
baseHolders.isEmpty() ? null : Ingredient.of(baseHolders),
templateHolders.isEmpty() ? null : Ingredient.of(templateHolders),
additionHolders.isEmpty() ? null : Ingredient.of(additionHolders),
new CustomRecipeResult<>(new CloneableConstantItem(recipe.result().isCustom() ? Key.of("!internal:custom") : Key.of(recipe.result().id()), result), recipe.result().count()),
new CustomRecipeResult<>(new CloneableConstantItem(recipe.result().isCustom() ? Key.of("!internal:custom") : Key.of(recipe.result().id()), BukkitItemManager.instance().wrap(result)), recipe.result().count(), null),
true,
List.of()
);