Skip to content

Commit

Permalink
Fix custom ingredients not being supported on Fabric, cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxNeedsSnacks committed Jul 14, 2023
1 parent 43a9841 commit b37b50b
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public abstract class MinecraftServerMixin {

@ModifyVariable(method = {"*"}, at = @At("STORE"), remap = false)
public CloseableResourceManager wrapResourceManager(CloseableResourceManager original) {
ServerScriptManager.instance = new ServerScriptManager();
return ServerScriptManager.instance.wrapResourceManager(original);
return (ServerScriptManager.instance = new ServerScriptManager()).wrapResourceManager(original);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ public final RecipeJS keepIngredient(IngredientActionFilter filter) {

public final RecipeJS modifyResult(ModifyRecipeResultCallback callback) {
UUID id = UUID.randomUUID();
RecipesEventJS.modifyResultCallbackMap.put(id, callback);
RecipesEventJS.MODIFY_RESULT_CALLBACKS.put(id, callback);
json.addProperty("kubejs:modify_result", UUIDTypeAdapter.fromUUID(id));
save();
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,19 @@

public class RecipesEventJS extends EventJS {
private static final Pattern SKIP_ERROR = Pattern.compile("at\\s+dev\\.latvian\\.mods\\.kubejs\\.recipe\\.RecipesEventJS\\.post");

public static final Map<UUID, ModifyRecipeResultCallback> MODIFY_RESULT_CALLBACKS = new HashMap<>();

public static Map<UUID, IngredientWithCustomPredicate> customIngredientMap = null;
public static Map<UUID, ModifyRecipeResultCallback> modifyResultCallbackMap = null;

public static RecipesEventJS instance;

public final Map<ResourceLocation, RecipeJS> originalRecipes;
public final Collection<RecipeJS> addedRecipes;
public final Collection<RecipeJS> removedRecipes;
final Map<String, Object> recipeFunctions;
public final AtomicInteger failedCount;

private final Map<String, Object> recipeFunctions;
public final RecipeTypeFunction shaped;
public final RecipeTypeFunction shapeless;
public final RecipeTypeFunction smelting;
Expand All @@ -79,7 +81,7 @@ public class RecipesEventJS extends EventJS {
public final RecipeTypeFunction stonecutting;
public final RecipeTypeFunction smithing;

RecipeSerializer<?> stageSerializer;
final RecipeSerializer<?> stageSerializer;

public RecipesEventJS() {
ConsoleJS.SERVER.info("Scanning recipes...");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public ShapedKubeJSRecipe fromJson(ResourceLocation id, JsonObject json) {

ModifyRecipeResultCallback modifyResult = null;
if (json.has("kubejs:modify_result")) {
modifyResult = RecipesEventJS.modifyResultCallbackMap.get(UUIDTypeAdapter.fromString(json.get("kubejs:modify_result").getAsString()));
modifyResult = RecipesEventJS.MODIFY_RESULT_CALLBACKS.get(UUIDTypeAdapter.fromString(json.get("kubejs:modify_result").getAsString()));
}

var stage = GsonHelper.getAsString(json, "kubejs:stage", "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public ShapelessKubeJSRecipe fromJson(ResourceLocation id, JsonObject json) {
var ingredientActions = IngredientAction.parseList(json.get("kubejs:actions"));
ModifyRecipeResultCallback modifyResult = null;
if (json.has("kubejs:modify_result")) {
modifyResult = RecipesEventJS.modifyResultCallbackMap.get(UUIDTypeAdapter.fromString(json.get("kubejs:modify_result").getAsString()));
modifyResult = RecipesEventJS.MODIFY_RESULT_CALLBACKS.get(UUIDTypeAdapter.fromString(json.get("kubejs:modify_result").getAsString()));
}

var stage = GsonHelper.getAsString(json, "kubejs:stage", "");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package dev.latvian.mods.kubejs.server;

import dev.architectury.platform.Platform;
import dev.latvian.mods.kubejs.KubeJSPaths;
import dev.latvian.mods.kubejs.KubeJSPlugin;
import dev.latvian.mods.kubejs.bindings.event.ServerEvents;
import dev.latvian.mods.kubejs.platform.RecipePlatformHelper;
import dev.latvian.mods.kubejs.recipe.RecipesEventJS;
Expand All @@ -13,6 +13,7 @@
import dev.latvian.mods.kubejs.script.data.KubeJSFolderPackResources;
import dev.latvian.mods.kubejs.script.data.VirtualKubeJSDataPack;
import dev.latvian.mods.kubejs.util.ConsoleJS;
import dev.latvian.mods.kubejs.util.KubeJSPlugins;
import net.minecraft.server.ReloadableServerResources;
import net.minecraft.server.packs.FilePackResources;
import net.minecraft.server.packs.PackType;
Expand Down Expand Up @@ -81,13 +82,10 @@ public MultiPackResourceManager wrapResourceManager(CloseableResourceManager ori

ConsoleJS.SERVER.info("Scripts loaded");

// Currently custom ingredients are only supported on Forge
if (Platform.isForge()) {
RecipesEventJS.customIngredientMap = new HashMap<>();
}

RecipesEventJS.modifyResultCallbackMap = new HashMap<>();
// note we only set this map on the logical server, it'll be null on the client!
RecipesEventJS.customIngredientMap = new HashMap<>();

RecipesEventJS.MODIFY_RESULT_CALLBACKS.clear();
CustomIngredientAction.MAP.clear();

SpecialRecipeSerializerManager.INSTANCE.reset();
Expand Down

0 comments on commit b37b50b

Please sign in to comment.