mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-19 06:09:05 +00:00
Create First Push of Recipe Events
This commit is contained in:
1 parent
2860cc5cf3
commit
bacfb5eba0
15 files changed
+671
-57
No files matched your search
@@ -11,9 +11,7 @@ import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.api.handler.IRecipeHandler;
|
||||
import noppes.npcs.api.handler.data.IAnvilRecipe;
|
||||
import noppes.npcs.api.handler.data.IRecipe;
|
||||
import noppes.npcs.controllers.data.RecipeAnvil;
|
||||
import noppes.npcs.controllers.data.RecipeCarpentry;
|
||||
import noppes.npcs.controllers.data.RecipesDefault;
|
||||
import noppes.npcs.controllers.data.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
@@ -28,6 +26,9 @@ public class RecipeController implements IRecipeHandler {
|
||||
public HashMap<Integer, RecipeCarpentry> carpentryRecipes = new HashMap<Integer, RecipeCarpentry>();
|
||||
public HashMap<Integer, RecipeAnvil> anvilRecipes = new HashMap<Integer, RecipeAnvil>();
|
||||
|
||||
public HashMap<Integer, RecipeScript> carpentryScripts = new HashMap<>();
|
||||
public HashMap<Integer, RecipeScript> anvilScripts = new HashMap<>();
|
||||
|
||||
public static RecipeController Instance;
|
||||
|
||||
public static final int version = 1;
|
||||
@@ -104,12 +105,14 @@ public class RecipeController implements IRecipeHandler {
|
||||
for (int i = 0; i < list.tagCount(); i++) {
|
||||
NBTTagCompound compound = list.getCompoundTagAt(i);
|
||||
if (compound.hasKey("IsAnvil")) {
|
||||
RecipeAnvil anvil = RecipeAnvil.read(compound);
|
||||
RecipeAnvil anvil = new RecipeAnvil();
|
||||
anvil.readNBT(compound);
|
||||
anvilRecipes.put(anvil.id, anvil);
|
||||
if (anvil.id > nextAnvilId)
|
||||
nextAnvilId = anvil.id;
|
||||
} else {
|
||||
RecipeCarpentry recipe = RecipeCarpentry.read(compound);
|
||||
RecipeCarpentry recipe = RecipeCarpentry.create(compound);
|
||||
recipe.readNBT(compound);
|
||||
if (recipe.isGlobal)
|
||||
globalRecipes.put(recipe.id, recipe);
|
||||
else
|
||||
@@ -130,13 +133,13 @@ public class RecipeController implements IRecipeHandler {
|
||||
File saveDir = CustomNpcs.getWorldSaveDirectory();
|
||||
NBTTagList list = new NBTTagList();
|
||||
for (RecipeCarpentry recipe : globalRecipes.values()) {
|
||||
list.appendTag(recipe.writeNBT());
|
||||
list.appendTag(recipe.writeNBT(true));
|
||||
}
|
||||
for (RecipeCarpentry recipe : carpentryRecipes.values()) {
|
||||
list.appendTag(recipe.writeNBT());
|
||||
list.appendTag(recipe.writeNBT(true));
|
||||
}
|
||||
for (RecipeAnvil recipe : anvilRecipes.values()) {
|
||||
list.appendTag(recipe.writeNBT());
|
||||
list.appendTag(recipe.writeNBT(true));
|
||||
}
|
||||
NBTTagCompound nbttagcompound = new NBTTagCompound();
|
||||
nbttagcompound.setTag("Data", list);
|
||||
@@ -186,7 +189,8 @@ public class RecipeController implements IRecipeHandler {
|
||||
}
|
||||
|
||||
public RecipeCarpentry saveRecipe(NBTTagCompound compound) throws IOException {
|
||||
RecipeCarpentry recipe = RecipeCarpentry.read(compound);
|
||||
RecipeCarpentry recipe = RecipeCarpentry.create(compound);
|
||||
recipe.readNBT(compound);
|
||||
|
||||
RecipeCarpentry current = getRecipe(recipe.id);
|
||||
if (current != null && !current.name.equals(recipe.name)) {
|
||||
@@ -212,7 +216,8 @@ public class RecipeController implements IRecipeHandler {
|
||||
}
|
||||
|
||||
public RecipeAnvil saveAnvilRecipe(NBTTagCompound compound) throws IOException {
|
||||
RecipeAnvil recipe = RecipeAnvil.read(compound);
|
||||
RecipeAnvil recipe = new RecipeAnvil();
|
||||
recipe.readNBT(compound);
|
||||
|
||||
RecipeAnvil current = getAnvilRecipe(recipe.id);
|
||||
if (current != null && !current.name.equals(recipe.name)) {
|
||||
@@ -270,8 +275,10 @@ public class RecipeController implements IRecipeHandler {
|
||||
SyncController.syncAllWorkbenchRecipes();
|
||||
|
||||
RecipeCarpentry carpentry = carpentryRecipes.remove(recipe.id);
|
||||
if (carpentry != null)
|
||||
if (carpentry != null){
|
||||
carpentryScripts.remove(recipe.id);
|
||||
SyncController.syncAllCarpentryRecipes();
|
||||
}
|
||||
|
||||
saveCategories();
|
||||
reloadGlobalRecipes(globalRecipes);
|
||||
@@ -329,7 +336,7 @@ public class RecipeController implements IRecipeHandler {
|
||||
recipe = RecipeCarpentry.saveRecipe(recipe, result, objects);
|
||||
|
||||
try {
|
||||
this.saveRecipe(recipe.writeNBT());
|
||||
this.saveRecipe(recipe.writeNBT(true));
|
||||
} catch (Exception var7) {
|
||||
var7.printStackTrace();
|
||||
}
|
||||
@@ -352,7 +359,7 @@ public class RecipeController implements IRecipeHandler {
|
||||
recipe.name = name;
|
||||
|
||||
try {
|
||||
this.saveRecipe(recipe.writeNBT());
|
||||
this.saveRecipe(recipe.writeNBT(true));
|
||||
} catch (IOException var12) {
|
||||
var12.printStackTrace();
|
||||
}
|
||||
@@ -362,7 +369,7 @@ public class RecipeController implements IRecipeHandler {
|
||||
public void addAnvilRecipe(String name, boolean global, ItemStack itemToRepair, ItemStack repairMaterial, int xpCost, float repairPercentage) {
|
||||
RecipeAnvil recipe = new RecipeAnvil(name, itemToRepair, repairMaterial, xpCost, repairPercentage);
|
||||
try {
|
||||
this.saveAnvilRecipe(recipe.writeNBT());
|
||||
this.saveAnvilRecipe(recipe.writeNBT(true));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user