2021-09-10 19:02:15 +02:00
|
|
|
package io.gitlab.jfronny.libjf.mixin;
|
|
|
|
|
|
|
|
import com.google.common.collect.ImmutableMap;
|
|
|
|
import com.google.gson.JsonObject;
|
|
|
|
import io.gitlab.jfronny.libjf.Libjf;
|
|
|
|
import io.gitlab.jfronny.libjf.data.RecipeUtil;
|
|
|
|
import net.minecraft.recipe.Recipe;
|
|
|
|
import net.minecraft.recipe.RecipeManager;
|
|
|
|
import net.minecraft.util.Identifier;
|
|
|
|
import org.spongepowered.asm.mixin.Mixin;
|
|
|
|
import org.spongepowered.asm.mixin.injection.At;
|
|
|
|
import org.spongepowered.asm.mixin.injection.ModifyVariable;
|
|
|
|
import org.spongepowered.asm.mixin.injection.Redirect;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
@Mixin(RecipeManager.class)
|
|
|
|
public class RecipeManagerMixin {
|
|
|
|
@ModifyVariable(method = "apply", at = @At(value = "INVOKE_ASSIGN", target = "Ljava/util/Set;iterator()Ljava/util/Iterator;", ordinal = 0, remap = false))
|
|
|
|
private Iterator<Map.Entry<Identifier, JsonObject>> filterIterator(Iterator<Map.Entry<Identifier, JsonObject>> iterator) {
|
|
|
|
ArrayList<Map.Entry<Identifier, JsonObject>> replacement = new ArrayList<>();
|
|
|
|
while(iterator.hasNext()) {
|
|
|
|
Map.Entry<Identifier, JsonObject> cur = iterator.next();
|
|
|
|
Identifier recipeId = cur.getKey();
|
|
|
|
|
2021-09-27 18:25:19 +02:00
|
|
|
if (RecipeUtil.isIdBlocked(recipeId)) {
|
2021-09-10 19:02:15 +02:00
|
|
|
Libjf.LOGGER.info("Blocking recipe by identifier: " + recipeId);
|
|
|
|
} else {
|
|
|
|
replacement.add(cur);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return replacement.iterator();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Redirect(method = "apply", at = @At(value = "INVOKE", target = "Lcom/google/common/collect/ImmutableMap$Builder;put(Ljava/lang/Object;Ljava/lang/Object;)Lcom/google/common/collect/ImmutableMap$Builder;", remap = false))
|
|
|
|
private ImmutableMap.Builder<Identifier, Recipe<?>> onPutRecipe(ImmutableMap.Builder<Identifier, Recipe<?>> builder, Object key, Object value) {
|
|
|
|
Identifier id = (Identifier) key;
|
|
|
|
Recipe<?> recipe = (Recipe<?>) value;
|
2021-09-27 18:25:19 +02:00
|
|
|
|
|
|
|
if (RecipeUtil.isOutputBlocked(recipe.getOutput())) {
|
|
|
|
Libjf.LOGGER.info("Blocked recipe by predicate: " + recipe.getId());
|
|
|
|
return builder;
|
2021-09-10 19:02:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return builder.put(id, recipe);
|
|
|
|
}
|
|
|
|
}
|