Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion paper/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ civGradle {
dependencies {
paperDevBundle("1.18.2-R0.1-SNAPSHOT")

compileOnly("net.civmc.civmodcore:paper:2.0.0-SNAPSHOT:dev-all")
compileOnly("net.civmc.civmodcore:civmodcore-paper:2.3.3:dev-all")
compileOnly("net.civmc.namelayer:paper:3.0.0-SNAPSHOT:dev")
compileOnly("net.civmc.citadel:paper:5.0.0-SNAPSHOT:dev")
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.github.igotyou.FactoryMod.recipes.IRecipe;
import com.github.igotyou.FactoryMod.recipes.InputRecipe;
import com.github.igotyou.FactoryMod.recipes.LoreEnchantRecipe;
import com.github.igotyou.FactoryMod.recipes.LoreRemoveRecipe;
import com.github.igotyou.FactoryMod.recipes.PlayerHeadRecipe;
import com.github.igotyou.FactoryMod.recipes.PrintBookRecipe;
import com.github.igotyou.FactoryMod.recipes.PrintNoteRecipe;
Expand Down Expand Up @@ -791,6 +792,25 @@ private IRecipe parseRecipe(ConfigurationSection config) {
result = new LoreEnchantRecipe(identifier, name, productionTime, input, toolMap, appliedLore,
overwrittenLore);
break;
case "REMOVELORE":
ConfigurationSection loreItem = config.getConfigurationSection("removeLore");
ItemMap materials;
if (loreItem == null) {
if (!(parentRecipe instanceof LoreRemoveRecipe)) {
materials = new ItemMap();
} else {
materials = ((LoreRemoveRecipe) parentRecipe).getItemToCleanse().clone();
}
} else {
materials = ConfigHelper.parseItemMap(loreItem);
}
if (materials.getTotalItemAmount() == 0) {
plugin.warning("Lore removing recipe " + name + " had no item specified, it was skipped");
result = null;
break;
}
result = new LoreRemoveRecipe(identifier, name, productionTime, input, materials);
break;
case "RECIPEMODIFIERUPGRADE":
int rank = config.getInt("rank");
String toUpgrade = config.getString("recipeUpgraded");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
package com.github.igotyou.FactoryMod.recipes;

import com.github.igotyou.FactoryMod.factories.FurnCraftChestFactory;
import com.github.igotyou.FactoryMod.utility.MultiInventoryWrapper;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextDecoration;
import org.apache.commons.collections4.CollectionUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import vg.civcraft.mc.civmodcore.chat.ChatUtils;
import vg.civcraft.mc.civmodcore.inventory.items.ItemMap;
import vg.civcraft.mc.civmodcore.inventory.items.ItemUtils;
import vg.civcraft.mc.civmodcore.inventory.items.MetaUtils;

public class LoreRemoveRecipe extends InputRecipe{

private Component infoComponent = Component.text("This item has lore that will be removed!", NamedTextColor.GOLD).decoration(
TextDecoration.ITALIC, false);
private ItemMap itemToCleanse;
private ItemStack exampleInput;
private ItemStack exampleOutput;

public LoreRemoveRecipe(String identifier, String name, int productionTime, ItemMap input, ItemMap itemToCleanse) {
super(identifier, name, productionTime, input);
this.itemToCleanse = itemToCleanse;
this.exampleInput = itemToCleanse.getItemStackRepresentation().get(0);
this.exampleOutput = itemToCleanse.getItemStackRepresentation().get(0);
ItemUtils.addComponentLore(exampleInput, infoComponent);
}

@Override
public boolean applyEffect(Inventory inputInv, Inventory outputInv, FurnCraftChestFactory fccf) {
MultiInventoryWrapper combo = new MultiInventoryWrapper(inputInv, outputInv);
logBeforeRecipeRun(combo, fccf);
ItemStack toolio = itemToCleanse.getItemStackRepresentation().get(0);
for (ItemStack is : inputInv.getContents()) {
if (is != null && toolio.getType() == is.getType() && checkIfHasLore(is)) {
if (input.removeSafelyFrom(inputInv)) {
ItemMeta im = is.getItemMeta();
if (im == null) {
im = Bukkit.getItemFactory().getItemMeta(is.getType());
}
is.setItemMeta(Bukkit.getItemFactory().getItemMeta(is.getType()));
logAfterRecipeRun(combo, fccf);
return true;
}
}
}
logAfterRecipeRun(combo, fccf);
return false;
}

@Override
public String getTypeIdentifier() {
return "REMOVELORE";
}

public ItemMap getItemToCleanse() {
return itemToCleanse;
}

@Override
public List<ItemStack> getInputRepresentation(Inventory i, FurnCraftChestFactory fccf) {
if (i == null) {
List<ItemStack> itemStackRepresentation = input.getItemStackRepresentation();
List<ItemStack> inputs = new ArrayList<>(itemStackRepresentation.size() + 1);
inputs.addAll(itemStackRepresentation);
inputs.add(exampleInput.clone());
return inputs;
}
List<ItemStack> returns = createLoredStacksForInfo(i);
ItemStack toSt = itemToCleanse.getItemStackRepresentation().get(0);
toSt.editMeta(meta -> {
MetaUtils.addComponentLore(meta, infoComponent);
MetaUtils.addLore(meta, ChatColor.GREEN + "Enough materials for " + new ItemMap(toSt).getMultiplesContainedIn(i)
+ " runs");
});
returns.add(toSt);
return returns;
}

@Override
public List<ItemStack> getOutputRepresentation(Inventory i, FurnCraftChestFactory fccf) {
ItemStack is = exampleOutput.clone();
if (i != null) {
ItemUtils.addLore(
is,
ChatColor.GREEN
+ "Enough materials for "
+ Math.min(itemToCleanse.getMultiplesContainedIn(i), input.getMultiplesContainedIn(i))
+ " runs");
}
List<ItemStack> stacks = new LinkedList<>();
stacks.add(is);
return stacks;
}

private boolean checkIfHasLore(ItemStack itemStack) {
ItemMeta meta = itemStack.getItemMeta();
if (meta == null) {
return false;
}
return CollectionUtils.isEmpty(meta.lore());
}

@Override
public List<String> getTextualInputRepresentation(Inventory i, FurnCraftChestFactory fccf) {
List<String> inputNames = new ArrayList<>();
inputNames.add(exampleInput.getAmount() + " " + ChatUtils.stringify(ItemUtils.asTranslatable(exampleInput)));
for (ItemStack is : input.getItemStackRepresentation()) {
inputNames.add(is.getAmount() + " " + ChatUtils.stringify(ItemUtils.asTranslatable(is)));
}
return inputNames;
}

@Override
public List<String> getTextualOutputRepresentation(Inventory i, FurnCraftChestFactory fccf) {
return Arrays.asList("1 " + ItemUtils.getItemName(exampleOutput));
}

@Override
public Material getRecipeRepresentationMaterial() {
return exampleOutput.getType();
}
}
17 changes: 17 additions & 0 deletions paper/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,23 @@ factories:

#appliedLore is the lore which is applied as replacement for the removed lore. This list may not be empty, but it may contain multiple entries


#10. Remove Lore Recipe

#This recipe is quite specific, We use it to get rid of the lore and PDC tag on an ItemStack that was placed by SimpleAdminHacks.

#removeLore:
# type: REMOVELORE
# input:
# emeralds:
# material: EMERALD
# amount: 9
# removeLore:
# chestplate:
# material: DIAMOND_CHESTPLATE

# This will completely overwrite an items ItemMeta with a fresh copy

#GENERAL NOTE:

# Every recipe type can include at the same level as "name: " the following, although only FCC's will respect it currently:
Expand Down