mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2024-12-22 04:37:42 +01:00
!Fixed crafting recipes (still don't work properly tho)
This commit is contained in:
parent
48aa1dec34
commit
a79c9bbcd0
@ -22,9 +22,8 @@ import net.Indyuce.mmoitems.api.SoulboundInfo;
|
||||
import net.Indyuce.mmoitems.api.Type;
|
||||
import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem;
|
||||
import net.Indyuce.mmoitems.api.player.PlayerData;
|
||||
import net.Indyuce.mmoitems.command.MMOItemsCommand;
|
||||
import net.Indyuce.mmoitems.command.MMOItemsCommandTreeRoot;
|
||||
import net.Indyuce.mmoitems.command.UpdateItemCommand;
|
||||
import net.Indyuce.mmoitems.command.completion.MMOItemsCompletion;
|
||||
import net.Indyuce.mmoitems.command.completion.UpdateItemCompletion;
|
||||
import net.Indyuce.mmoitems.comp.AdvancedEnchantmentsHook;
|
||||
import net.Indyuce.mmoitems.comp.MMOItemsMetrics;
|
||||
@ -96,13 +95,13 @@ public class MMOItems extends JavaPlugin {
|
||||
private final TypeManager typeManager = new TypeManager();
|
||||
private final TemplateManager templateManager = new TemplateManager();
|
||||
private final ItemManager itemManager = new ItemManager();
|
||||
private final RecipeManager recipeManager = new RecipeManager();
|
||||
|
||||
private DropTableManager dropTableManager;
|
||||
private WorldGenManager worldGenManager;
|
||||
private UpgradeManager upgradeManager;
|
||||
private UpdaterManager dynamicUpdater;
|
||||
private ConfigManager configManager;
|
||||
private RecipeManager recipeManager;
|
||||
private BlockManager blockManager;
|
||||
private TierManager tierManager;
|
||||
private StatManager statManager;
|
||||
@ -275,14 +274,15 @@ public class MMOItems extends JavaPlugin {
|
||||
|
||||
// advanced recipes
|
||||
getLogger().log(Level.INFO, "Loading recipes, please wait...");
|
||||
recipeManager = new RecipeManager();
|
||||
recipeManager.loadRecipes();
|
||||
|
||||
// commands
|
||||
getCommand("mmoitems").setExecutor(new MMOItemsCommand());
|
||||
// main command
|
||||
MMOItemsCommandTreeRoot mmoitemsCommand = new MMOItemsCommandTreeRoot();
|
||||
getCommand("mmoitems").setExecutor(mmoitemsCommand);
|
||||
getCommand("mmoitems").setTabCompleter(mmoitemsCommand);
|
||||
|
||||
// update item command
|
||||
getCommand("updateitem").setExecutor(new UpdateItemCommand());
|
||||
|
||||
// tab completion
|
||||
getCommand("mmoitems").setTabCompleter(new MMOItemsCompletion());
|
||||
getCommand("updateitem").setTabCompleter(new UpdateItemCompletion());
|
||||
}
|
||||
|
||||
|
@ -16,8 +16,8 @@ import net.Indyuce.mmoitems.api.recipe.workbench.ingredients.WorkbenchIngredient
|
||||
import net.mmogroup.mmolib.api.item.NBTItem;
|
||||
|
||||
public class CustomRecipe implements Comparable<CustomRecipe> {
|
||||
private final boolean shapeless;
|
||||
private final ItemStack output;
|
||||
private final boolean shapeless;
|
||||
private final Map<Integer, WorkbenchIngredient> ingredients = new HashMap<>(9);
|
||||
|
||||
public CustomRecipe(NBTItem output, List<String> recipe, boolean isShapeless) {
|
||||
@ -28,20 +28,19 @@ public class CustomRecipe implements Comparable<CustomRecipe> {
|
||||
|
||||
if (shapeless) {
|
||||
if (recipe.size() != 9) {
|
||||
MMOItems.plugin.getLogger().warning("Invalid shapeless recipe for '" + output.getType().getId() + "."
|
||||
+ output.getString("MMOITEMS_ITEM_ID") + "'");
|
||||
MMOItems.plugin.getLogger()
|
||||
.warning("Invalid shapeless recipe for '" + output.getType().getId() + "." + output.getString("MMOITEMS_ITEM_ID") + "'");
|
||||
recipe = Arrays.asList("AIR", "AIR", "AIR", "AIR", "AIR", "AIR", "AIR", "AIR", "AIR");
|
||||
}
|
||||
for (int i = 0; i < 9; i++) {
|
||||
ItemStack stack = MMOItems.plugin.getRecipes().parseStack(recipe.get(i));
|
||||
if (stack == null || stack.getType() == Material.AIR)
|
||||
continue;
|
||||
if (stack != null && stack.getType() != Material.AIR)
|
||||
ingredients.put(i, WorkbenchIngredient.getAutomatically(stack));
|
||||
}
|
||||
} else {
|
||||
if (recipe.size() != 3) {
|
||||
MMOItems.plugin.getLogger().warning("Invalid shaped recipe for '" + output.getType().getId() + "."
|
||||
+ output.getString("MMOITEMS_ITEM_ID") + "'");
|
||||
MMOItems.plugin.getLogger()
|
||||
.warning("Invalid shaped recipe for '" + output.getType().getId() + "." + output.getString("MMOITEMS_ITEM_ID") + "'");
|
||||
recipe = Arrays.asList("AIR AIR AIR", "AIR AIR AIR", "AIR AIR AIR");
|
||||
}
|
||||
for (int i = 0; i < 9; i++) {
|
||||
@ -50,10 +49,8 @@ public class CustomRecipe implements Comparable<CustomRecipe> {
|
||||
line.add("AIR");
|
||||
|
||||
ItemStack stack = MMOItems.plugin.getRecipes().parseStack(line.get(i % 3));
|
||||
if (stack == null || stack.getType() == Material.AIR)
|
||||
ingredients.put(i, new AirIngredient());
|
||||
else
|
||||
ingredients.put(i, WorkbenchIngredient.getAutomatically(stack));
|
||||
ingredients.put(i,
|
||||
stack == null || stack.getType() == Material.AIR ? new AirIngredient() : WorkbenchIngredient.getAutomatically(stack));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -63,13 +60,10 @@ public class CustomRecipe implements Comparable<CustomRecipe> {
|
||||
}
|
||||
|
||||
public boolean fitsPlayerCrafting() {
|
||||
boolean check = true;
|
||||
for (int value : ingredients.keySet())
|
||||
if (value > 3) {
|
||||
check = false;
|
||||
break;
|
||||
}
|
||||
return check;
|
||||
if (value > 3)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
|
@ -6,7 +6,6 @@ import java.util.Collection;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.logging.Level;
|
||||
@ -21,6 +20,7 @@ import net.Indyuce.mmoitems.comp.mythicmobs.MythicMobsAbility;
|
||||
|
||||
public class AbilityManager {
|
||||
private final Map<String, Ability> abilities = new HashMap<>();
|
||||
|
||||
private boolean registration = true;
|
||||
|
||||
public Ability getAbility(String id) {
|
||||
@ -35,10 +35,6 @@ public class AbilityManager {
|
||||
return abilities.values();
|
||||
}
|
||||
|
||||
public Set<String> getAbilityKeys() {
|
||||
return abilities.keySet();
|
||||
}
|
||||
|
||||
public void registerAbility(Ability ability) {
|
||||
if (!registration) {
|
||||
MMOItems.plugin.getLogger().log(Level.INFO,
|
||||
|
@ -31,22 +31,27 @@ import net.Indyuce.mmoitems.api.recipe.MMORecipeChoice;
|
||||
import net.Indyuce.mmoitems.api.recipe.workbench.CustomRecipe;
|
||||
|
||||
public class RecipeManager {
|
||||
|
||||
/**
|
||||
* Custom recipes which are handled by MMOItems
|
||||
*/
|
||||
private final Set<CustomRecipe> craftingRecipes = new HashSet<>();
|
||||
private final Set<LoadedRecipe> loadedRecipes = new HashSet<>();
|
||||
|
||||
public RecipeManager() {
|
||||
reload();
|
||||
}
|
||||
/**
|
||||
* Recipes which are handled by the vanilla spigot API. All recipes
|
||||
* registered here are Keyed
|
||||
*/
|
||||
private final Set<Recipe> loadedRecipes = new HashSet<>();
|
||||
|
||||
public void reload() {
|
||||
clearCustomRecipes();
|
||||
public void loadRecipes() {
|
||||
craftingRecipes.clear();
|
||||
|
||||
for (Type type : MMOItems.plugin.getTypes().getAll()) {
|
||||
FileConfiguration config = type.getConfigFile().getConfig();
|
||||
for (MMOItemTemplate template : MMOItems.plugin.getTemplates().getTemplates(type))
|
||||
if (config.contains(template.getId() + ".crafting"))
|
||||
if (config.contains(template.getId() + ".base.crafting"))
|
||||
try {
|
||||
ConfigurationSection section = config.getConfigurationSection(template.getId() + ".crafting");
|
||||
ConfigurationSection section = config.getConfigurationSection(template.getId() + ".base.crafting");
|
||||
|
||||
if (section.contains("shaped"))
|
||||
section.getConfigurationSection("shaped").getKeys(false)
|
||||
@ -77,14 +82,14 @@ public class RecipeManager {
|
||||
}
|
||||
|
||||
sortRecipes();
|
||||
Bukkit.getScheduler().runTask(MMOItems.plugin, () -> getLoadedRecipes().forEach(recipe -> Bukkit.addRecipe(recipe.getRecipe())));
|
||||
Bukkit.getScheduler().runTask(MMOItems.plugin, () -> getLoadedRecipes().forEach(recipe -> Bukkit.addRecipe(recipe)));
|
||||
}
|
||||
|
||||
public void registerBurningRecipe(BurningRecipeType recipeType, Type type, String id, BurningRecipeInformation info, String recipeId) {
|
||||
NamespacedKey key = getRecipeKey(type, id, recipeType.getPath(), recipeId);
|
||||
Recipe recipe = recipeType.provideRecipe(key, MMOItems.plugin.getItem(type, id), toBukkit(info.getChoice()), info.getExp(),
|
||||
info.getBurnTime());
|
||||
registerRecipe(key, recipe);
|
||||
loadedRecipes.add(recipe);
|
||||
}
|
||||
|
||||
public void registerShapedRecipe(Type type, String id, List<String> list) {
|
||||
@ -106,16 +111,12 @@ public class RecipeManager {
|
||||
return choice.isVanilla() ? new RecipeChoice.MaterialChoice(choice.getItem().getType()) : new RecipeChoice.ExactChoice(choice.getItem());
|
||||
}
|
||||
|
||||
public void registerRecipe(NamespacedKey key, Recipe recipe) {
|
||||
loadedRecipes.add(new LoadedRecipe(key, recipe));
|
||||
}
|
||||
|
||||
public void registerRecipe(CustomRecipe recipe) {
|
||||
if (!recipe.isEmpty())
|
||||
craftingRecipes.add(recipe);
|
||||
}
|
||||
|
||||
public Set<LoadedRecipe> getLoadedRecipes() {
|
||||
public Set<Recipe> getLoadedRecipes() {
|
||||
return loadedRecipes;
|
||||
}
|
||||
|
||||
@ -124,7 +125,7 @@ public class RecipeManager {
|
||||
}
|
||||
|
||||
public Set<NamespacedKey> getNamespacedKeys() {
|
||||
return loadedRecipes.stream().map(recipe -> recipe.getKey()).collect(Collectors.toSet());
|
||||
return loadedRecipes.stream().map(recipe -> ((Keyed) recipe).getKey()).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
public void sortRecipes() {
|
||||
@ -134,14 +135,13 @@ public class RecipeManager {
|
||||
craftingRecipes.addAll(temporary.stream().sorted().collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
public void clearCustomRecipes() {
|
||||
craftingRecipes.clear();
|
||||
}
|
||||
|
||||
public NamespacedKey getRecipeKey(Type type, String id, String recipeType, String number) {
|
||||
return new NamespacedKey(MMOItems.plugin, recipeType + "_" + type.getId() + "_" + id + "_" + number);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters bukkit recipes and loads everything again
|
||||
*/
|
||||
public void reloadRecipes() {
|
||||
Bukkit.getScheduler().runTask(MMOItems.plugin, () -> {
|
||||
|
||||
@ -153,7 +153,7 @@ public class RecipeManager {
|
||||
}
|
||||
|
||||
loadedRecipes.clear();
|
||||
reload();
|
||||
loadRecipes();
|
||||
});
|
||||
}
|
||||
|
||||
@ -228,30 +228,11 @@ public class RecipeManager {
|
||||
Recipe provide(NamespacedKey key, ItemStack result, RecipeChoice source, float experience, int cookTime);
|
||||
}
|
||||
|
||||
/*
|
||||
* used because spigot API does not let us access namespaced key of a Recipe
|
||||
* instance.
|
||||
*/
|
||||
public class LoadedRecipe {
|
||||
private final Recipe recipe;
|
||||
private final NamespacedKey key;
|
||||
|
||||
public LoadedRecipe(NamespacedKey key, Recipe recipe) {
|
||||
this.recipe = recipe;
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public NamespacedKey getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public Recipe getRecipe() {
|
||||
return recipe;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* blast furnace, smoker, campfire and furnace recipes have extra parameters
|
||||
/**
|
||||
* Used to handle furnace/smoker/campifire/furnace extra crafting recipe
|
||||
* parameters
|
||||
*
|
||||
* @author ASangarin
|
||||
*/
|
||||
public class BurningRecipeInformation {
|
||||
private final MMORecipeChoice choice;
|
||||
|
Loading…
Reference in New Issue
Block a user