Skip to content

Commit

Permalink
[1.9.0]锻造台配方新增copy_nbt字段,控制是否保留nbt
Browse files Browse the repository at this point in the history
  • Loading branch information
YufiriaMazenta committed Jan 29, 2024
1 parent ce7343f commit 3306ff3
Show file tree
Hide file tree
Showing 15 changed files with 65 additions and 11 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import java.text.SimpleDateFormat
version = "1.8.13"
version = "1.9.0"

plugins {
`java-library`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public class Languages {
public static final StringLangConfigEntry MENU_RECIPE_CREATOR_ICON_UNLOCK = new StringLangConfigEntry("menu.recipe_creator.icon.unlock");
public static final StringLangConfigEntry MENU_RECIPE_CREATOR_ICON_COOKING_FRAME = new StringLangConfigEntry("menu.recipe_creator.icon.cooking_frame");
public static final StringLangConfigEntry MENU_RECIPE_CREATOR_ICON_SMITHING_FRAME = new StringLangConfigEntry("menu.recipe_creator.icon.smithing_frame");
public static final StringLangConfigEntry MENU_RECIPE_CREATOR_ICON_SMITHING_COPY_NBT_TOGGLE = new StringLangConfigEntry("menu.recipe_creator.icon.smithing_copy_nbt_toggle");
public static final StringLangConfigEntry MENU_RECIPE_CREATOR_ICON_POTION_FRAME = new StringLangConfigEntry("menu.recipe_creator.icon.potion_frame");
public static final StringLangConfigEntry MENU_RECIPE_CREATOR_ICON_ANVIL_FRAME = new StringLangConfigEntry("menu.recipe_creator.icon.anvil_frame");
public static final StringLangConfigEntry MENU_RECIPE_CREATOR_ICON_ANVIL_COPY_NBT_TOGGLE = new StringLangConfigEntry("menu.recipe_creator.icon.anvil_copy_nbt_toggle");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import crypticlib.util.ItemUtil;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;

Expand All @@ -22,6 +23,9 @@
import java.util.Objects;

public class SmithingRecipeCreator extends UnlockableRecipeCreator {

private boolean copyNbt = true;

public SmithingRecipeCreator(@NotNull Player player, @NotNull String recipeName) {
super(player, RecipeType.SMITHING, recipeName);
setDisplay(
Expand All @@ -35,15 +39,15 @@ public SmithingRecipeCreator(@NotNull Player player, @NotNull String recipeName)
"#***#%%%#",
"# * A% %#",
"#***#%%%#",
"#########"
"####B####"
);
} else {
return Arrays.asList(
"####F####",
"#***#%%%#",
"# A% %#",
"#***#%%%#",
"#########"
"####B####"
);
}
},
Expand All @@ -56,6 +60,7 @@ public SmithingRecipeCreator(@NotNull Player player, @NotNull String recipeName)
));
layoutMap.put('%', getResultFrameIcon());
layoutMap.put('F', getUnlockIcon());
layoutMap.put('B', getCopyNbtIcon());
layoutMap.put('A', new Icon(
Material.SMITHING_TABLE,
Languages.MENU_RECIPE_CREATOR_ICON_CONFIRM.value(player),
Expand Down Expand Up @@ -98,6 +103,7 @@ public SmithingRecipeCreator(@NotNull Player player, @NotNull String recipeName)
recipeConfig.set("source.template", templateName);
}
recipeConfig.set("unlock", unlock());
recipeConfig.set("source.copy_nbt", copyNbt);
recipeConfig.saveConfig();
recipeConfig.reloadConfig();
regRecipeGroup(recipeConfig);
Expand All @@ -110,4 +116,30 @@ public SmithingRecipeCreator(@NotNull Player player, @NotNull String recipeName)
))
);
}

protected Icon getCopyNbtIcon() {
Icon icon = new Icon(
Material.NAME_TAG,
Languages.MENU_RECIPE_CREATOR_ICON_SMITHING_COPY_NBT_TOGGLE
.value(player)
.replace("<enable>", String.valueOf(copyNbt)),
event -> toggleCopyNbt(event.getSlot(), event)
);
if (copyNbt)
ItemUtils.toggleItemGlowing(icon.display());
return icon;
}

protected void toggleCopyNbt(int slot, InventoryClickEvent event) {
super.toggleIconGlowing(slot, event);
copyNbt = !copyNbt;
ItemStack display = event.getCurrentItem();
ItemUtil.setDisplayName(
display,
Languages.MENU_RECIPE_CREATOR_ICON_SMITHING_COPY_NBT_TOGGLE
.value(player)
.replace("<enable>", String.valueOf(copyNbt))
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,14 @@ public static List<RecipeRegistry> newSmithingRecipe(YamlConfiguration config, S
ItemStack result = getResultItem(config);
RecipeChoice base = getRecipeChoice(config.getString("source.base", ""));
RecipeChoice addition = getRecipeChoice(config.getString("source.addition", ""));
boolean copyNbt = config.getBoolean("source.copy_nbt", true);
RecipeRegistry recipeRegistry;
if (CrypticLib.minecraftVersion() >= 12000) {
RecipeChoice template = getRecipeChoice(config.getString("source.template", ""));
XSmithingRecipeRegistry.SmithingType type = XSmithingRecipeRegistry.SmithingType.valueOf(config.getString("source.type", "default").toUpperCase());
recipeRegistry = new XSmithingRecipeRegistry(key, namespacedKey, result).setSmithingType(type).setTemplate(template).setBase(base).setAddition(addition);
recipeRegistry = new XSmithingRecipeRegistry(key, namespacedKey, result).setSmithingType(type).setTemplate(template).setBase(base).setAddition(addition).setCopyNbt(copyNbt);
} else {
recipeRegistry = new SmithingRecipeRegistry(key, namespacedKey, result).setBase(base).setAddition(addition);
recipeRegistry = new SmithingRecipeRegistry(key, namespacedKey, result).setBase(base).setAddition(addition).setCopyNbt(copyNbt);
}

return Collections.singletonList(recipeRegistry);
Expand All @@ -229,16 +230,17 @@ public static List<RecipeRegistry> newMultipleSmithingRecipe(YamlConfiguration c
NamespacedKey namespacedKey = new NamespacedKey(Craftorithm.instance(), fullKey);
RecipeChoice base = getRecipeChoice((String) map.get("base"));
RecipeChoice addition = getRecipeChoice((String) map.get("addition"));
boolean copyNbt = map.containsKey("copy_nbt") ? (Boolean) map.get("copy_nbt") : true;
String typeStr = (String) map.get("type");
if (typeStr == null) {
typeStr = "DEFAULT";
}
if (CrypticLib.minecraftVersion() >= 12000) {
RecipeChoice template = getRecipeChoice((String) map.get("template"));
XSmithingRecipeRegistry.SmithingType type = XSmithingRecipeRegistry.SmithingType.valueOf(typeStr.toUpperCase());
recipeRegistries.add(new XSmithingRecipeRegistry(key, namespacedKey, result).setSmithingType(type).setTemplate(template).setBase(base).setAddition(addition));
recipeRegistries.add(new XSmithingRecipeRegistry(key, namespacedKey, result).setSmithingType(type).setTemplate(template).setBase(base).setAddition(addition).setCopyNbt(copyNbt));
} else {
recipeRegistries.add(new SmithingRecipeRegistry(key, namespacedKey, result).setBase(base).setAddition(addition));
recipeRegistries.add(new SmithingRecipeRegistry(key, namespacedKey, result).setBase(base).setAddition(addition).setCopyNbt(copyNbt));
}
}
return recipeRegistries;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
public class SmithingRecipeRegistry extends RecipeRegistry {

private RecipeChoice base, addition;
protected boolean copyNbt = true;

public SmithingRecipeRegistry(@NotNull String recipeGroup, @NotNull NamespacedKey namespacedKey, ItemStack result) {
super(recipeGroup, namespacedKey, result);
Expand All @@ -40,14 +41,23 @@ public SmithingRecipeRegistry setAddition(RecipeChoice addition) {
return this;
}

public boolean copyNbt() {
return copyNbt;
}

public SmithingRecipeRegistry setCopyNbt(boolean copyNbt) {
this.copyNbt = copyNbt;
return this;
}

@Override
public void register() {
Objects.requireNonNull(namespacedKey(), "Recipe key cannot be null");
Objects.requireNonNull(result(), "Recipe result cannot be null");
Objects.requireNonNull(base, "Recipe base cannot be null");
Objects.requireNonNull(addition, "Recipe addition cannot be null");

SmithingRecipe smithingRecipe = new SmithingRecipe(namespacedKey(), result(), base, addition);
SmithingRecipe smithingRecipe = new SmithingRecipe(namespacedKey(), result(), base, addition, copyNbt);
RecipeManager.INSTANCE.regRecipe(group(), smithingRecipe, RecipeType.SMITHING);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ public void register() {
switch (smithingType) {
default:
Objects.requireNonNull(result(), "Recipe result cannot be null");
smithingRecipe = new SmithingRecipe(namespacedKey(), result(), base(), addition());
smithingRecipe = new SmithingRecipe(namespacedKey(), result(), base(), addition(), copyNbt);
break;
case TRIM:
smithingRecipe = new SmithingTrimRecipe(namespacedKey(), template, base(), addition());
smithingRecipe = new SmithingTrimRecipe(namespacedKey(), template, base(), addition(), copyNbt);
break;
case TRANSFORM:
Objects.requireNonNull(result(), "Recipe result cannot be null");
smithingRecipe = new SmithingTransformRecipe(namespacedKey(), result(), template, base(), addition());
smithingRecipe = new SmithingTransformRecipe(namespacedKey(), result(), template, base(), addition(), copyNbt);
break;
}
RecipeManager.INSTANCE.regRecipe(group(), smithingRecipe, RecipeType.SMITHING);
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/lang/de_de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ menu:
- '&aBitte gib die Belohnung Erfahrung ein.'
input_hint: '&3Klicke, um die Belohnung Erfahrung zu ändern. Gib "cancel" ein, um abzubrechen.'
smithing_frame: '&aSchmiede Gegenstand'
smithing_copy_nbt_toggle: '&3Behalte Gegenstand-NBT: &a<enable>'
potion_frame: '&aBrauen von Zutaten'
anvil_frame: '&aSchmiede-Materialien'
anvil_copy_nbt_toggle: '&3Behalte Gegenstand-NBT: &a<enable>'
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/lang/en_us.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ menu:
- '&3Click to modify experience reward.'
input_hint: '&aPlease enter experience reward. Type "cancel" to cancel.'
smithing_frame: '&aSmithing Ingredients'
smithing_copy_nbt_toggle: '&3Preserve item NBT: &a<enable>'
potion_frame: '&aBrewing Ingredients'
anvil_frame: '&aAnvil Ingredients'
anvil_copy_nbt_toggle: '&3Preserve item NBT: &a<enable>'
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/lang/fr_fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ menu:
- '&3Veuillez entrer la récompense d''expérience.'
input_hint: '&3Cliquez pour modifier la récompense d''expérience. Entrez "cancel" pour annuler.'
smithing_frame: '&aObjets de forge'
smithing_copy_nbt_toggle: '&3Conserver les données NBT de l''objet : &a<enable>'
potion_frame: '&aIngrédients de brassage'
anvil_frame: '&aIngrédients d''enclume'
anvil_copy_nbt_toggle: '&3Conserver les données NBT de l''objet : &a<enable>'
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/lang/ja_jp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ menu:
- '&3クリックで経験値ドロップ量を変更する。キャンセルするにはcancelと入力してください。'
input_hint: '&a経験値ドロップ量を入力してください'
smithing_frame: '&a精錬アイテム'
smithing_copy_nbt_toggle: '&3アイテムNBTを保存する:<enable>'
potion_frame: '&a醸造素材'
anvil_frame: '&a鍛冶素材'
anvil_copy_nbt_toggle: '&3アイテムNBTを保存する:<enable>'
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/lang/ru_ru.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ menu:
- '&3Нажмите, чтобы изменить награду опытом, введите "cancel" для отмены.'
input_hint: '&aПожалуйста, введите количество опыта для награды.'
smithing_frame: '&aИзготовление предметов'
smithing_copy_nbt_toggle: '&3Сохранить данные NBT предмета: &a<enable>'
potion_frame: '&aСырье для зельеварения'
anvil_frame: '&aМатериалы для ковки'
anvil_copy_nbt_toggle: '&3Сохранить данные NBT предмета: &a<enable>'
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/lang/tr_tr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ menu:
- '&3Tecrübe Ödülünü Değiştirmek İçin Tıklayın.'
input_hint: '&aLütfen gerekli seviyeyi girin, İptal etmek için "cancel" yazın.'
smithing_frame: '&aDemir işlenmiş eşya'
smithing_copy_nbt_toggle: '&3Özel eşya veri NBT korunsun mu: &a<enable>'
potion_frame: '&aİksir Tarifi'
anvil_frame: '&aÖrs malzemeleri'
anvil_copy_nbt_toggle: '&3Özel eşya veri NBT korunsun mu: &a<enable>'
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/lang/zh_cn.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ menu:
- '&3点击修改奖励经验'
input_hint: '&a请输入奖励经验,输入“cancel”取消'
smithing_frame: '&a锻造物品'
smithing_copy_nbt_toggle: '&3保留物品NBT:&a<enable>'
potion_frame: '&a酿造原料'
anvil_frame: '&a打造原料'
anvil_copy_nbt_toggle: '&3保留物品NBT:&a<enable>'
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/lang/zh_hk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ menu:
- '&3點擊修改獎勵經驗'
input_hint: '&a請輸入獎勵經驗,輸入"cancel"取消。'
smithing_frame: '&a鍛造物品'
smithing_copy_nbt_toggle: '&3保留物品NBT:&a<enable>'
potion_frame: '&a釀造原料'
anvil_frame: '&a製作材料'
anvil_copy_nbt_toggle: '&3保留物品NBT:&a<enable>'
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/lang/zh_tw.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ menu:
- '&3點擊修改獎勵經驗'
input_hint: '&a請輸入獎勵經驗,輸入"cancel"取消。'
smithing_frame: '&a鍛造物品'
smithing_copy_nbt_toggle: '&3保留物品NBT:&a<enable>'
potion_frame: '&a釀造原料'
anvil_frame: '&a製作材料'
anvil_copy_nbt_toggle: '&3保留物品NBT:&a<enable>'
Expand Down

0 comments on commit 3306ff3

Please sign in to comment.