Skip to content

Commit 72b7cfc

Browse files
committed
Revert KubeJS compatibility changes
Fixes enchantment upgrade recipes disappearing upon reload (#460) Tested and working with KubeJS - I guess they stopped doing whatever horrible thing they were doing to break this in the first place
1 parent bd4760d commit 72b7cfc

File tree

5 files changed

+28
-42
lines changed

5 files changed

+28
-42
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ yarn_mappings=1.20.1+build.10
88
loader_version=0.16.14
99

1010
# Mod Properties
11-
mod_version=1.8.6
11+
mod_version=1.8.7
1212
maven_group=de.dafuqs
1313
archives_base_name=spectrum
1414

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package de.dafuqs.spectrum.mixin;
2+
3+
import com.google.common.collect.*;
4+
import com.llamalad7.mixinextras.sugar.*;
5+
import de.dafuqs.spectrum.recipe.enchantment_upgrade.*;
6+
import de.dafuqs.spectrum.registries.*;
7+
import net.minecraft.recipe.*;
8+
import net.minecraft.util.*;
9+
import org.spongepowered.asm.mixin.*;
10+
import org.spongepowered.asm.mixin.injection.*;
11+
import org.spongepowered.asm.mixin.injection.callback.*;
12+
13+
import java.util.*;
14+
15+
@Mixin(RecipeManager.class)
16+
public class RecipeManagerMixin {
17+
@Inject(method = "apply(Ljava/util/Map;Lnet/minecraft/resource/ResourceManager;Lnet/minecraft/util/profiler/Profiler;)V", at = @At(value = "INVOKE_ASSIGN", target = "Lcom/google/common/collect/ImmutableMap;builder()Lcom/google/common/collect/ImmutableMap$Builder;", remap = false))
18+
public void injectEnchantmentUpgradeRecipes(CallbackInfo info, @Local(ordinal = 1) Map<RecipeType<?>, ImmutableMap.Builder<Identifier, Recipe<?>>> recipes, @Local(ordinal = 0) ImmutableMap.Builder<Identifier, Recipe<?>> recipesById) {
19+
ImmutableMap<Identifier, Recipe<?>> collectedRecipes = EnchantmentUpgradeRecipeSerializer.enchantmentUpgradeRecipesToInject.stream().collect(ImmutableMap.toImmutableMap(EnchantmentUpgradeRecipe::getId, enchantmentUpgradeRecipe -> enchantmentUpgradeRecipe));
20+
21+
recipes.computeIfAbsent(SpectrumRecipeTypes.ENCHANTMENT_UPGRADE, (recipeType) -> ImmutableMap.builder()).putAll(collectedRecipes);
22+
recipesById.putAll(collectedRecipes);
23+
}
24+
}

src/main/java/de/dafuqs/spectrum/mixin/accessors/RecipeManagerAccessor.java

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/main/java/de/dafuqs/spectrum/registries/SpectrumEventListeners.java

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import de.dafuqs.spectrum.registries.client.*;
2222
import dev.emi.trinkets.api.*;
2323
import net.fabricmc.fabric.api.entity.event.v1.*;
24+
import net.fabricmc.fabric.api.event.*;
2425
import net.fabricmc.fabric.api.event.lifecycle.v1.*;
2526
import net.fabricmc.fabric.api.event.player.*;
2627
import net.fabricmc.fabric.api.item.v1.*;
@@ -168,7 +169,6 @@ public static void register() {
168169

169170
SpectrumCommon.logInfo("Injecting dynamic recipes into recipe manager...");
170171
FirestarterIdolBlock.addBlockSmeltingRecipes(server);
171-
injectEnchantmentUpgradeRecipes(server);
172172
});
173173

174174
EntitySleepEvents.STOP_SLEEPING.register((entity, sleepingPos) -> {
@@ -380,7 +380,6 @@ public void reload(ResourceManager manager) {
380380
SpectrumCommon.CACHED_ITEM_TAG_MAP.clear();
381381

382382
if (SpectrumCommon.minecraftServer != null) {
383-
injectEnchantmentUpgradeRecipes(SpectrumCommon.minecraftServer);
384383
FirestarterIdolBlock.addBlockSmeltingRecipes(SpectrumCommon.minecraftServer);
385384
}
386385
}
@@ -392,27 +391,6 @@ public Identifier getFabricId() {
392391
});
393392
}
394393

395-
// It could have been so much easier and performant, but KubeJS overrides the ENTIRE recipe manager
396-
// and cancels all sorts of functions at HEAD unconditionally, so Spectrum cannot mixin into it
397-
public static void injectEnchantmentUpgradeRecipes(MinecraftServer minecraftServer) {
398-
if (!EnchantmentUpgradeRecipeSerializer.enchantmentUpgradeRecipesToInject.isEmpty()) {
399-
ImmutableMap<Identifier, Recipe<?>> collectedRecipes = EnchantmentUpgradeRecipeSerializer.enchantmentUpgradeRecipesToInject.stream().collect(ImmutableMap.toImmutableMap(EnchantmentUpgradeRecipe::getId, enchantmentUpgradeRecipe -> enchantmentUpgradeRecipe));
400-
Map<RecipeType<?>, Map<Identifier, Recipe<?>>> recipes = ((RecipeManagerAccessor) minecraftServer.getRecipeManager()).getRecipes();
401-
402-
ArrayList<Recipe<?>> newList = new ArrayList<>();
403-
for (Map<Identifier, Recipe<?>> r : recipes.values()) {
404-
newList.addAll(r.values());
405-
}
406-
for (Recipe<?> recipe : collectedRecipes.values()) {
407-
if (!newList.contains(recipe)) {
408-
newList.add(recipe);
409-
}
410-
}
411-
412-
minecraftServer.getRecipeManager().setRecipes(newList);
413-
}
414-
}
415-
416394
public static int getFluidLuminance(Fluid fluid) {
417395
return fluidLuminance.getOrDefault(fluid, 0);
418396
}

src/main/resources/spectrum.mixins.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
"ProjectileEntityMixin",
7070
"RandomChanceLootConditionMixin",
7171
"RandomChanceWithLootingLootConditionMixin",
72+
"RecipeManagerMixin",
7273
"ServerPlayerEntityMixin",
7374
"ServerPlayerGameModeFabricMixin",
7475
"ServerPlayerInteractionManagerMixin",
@@ -90,13 +91,12 @@
9091
"accessors.FluidBlockAccessor",
9192
"accessors.FoxEntityAccessor",
9293
"accessors.GoatHornItemAccessor",
93-
"accessors.LivingEntityAccessor",
94+
"accessors.LivingEntityAccessor",
9495
"accessors.MapStateAccessor",
9596
"accessors.MobEntityAccessor",
9697
"accessors.MooshroomEntityAccessor",
9798
"accessors.PersistentProjectileEntityAccessor",
9899
"accessors.ProjectileAttackGoalAccessor",
99-
"accessors.RecipeManagerAccessor",
100100
"accessors.ShapedRecipeAccessor",
101101
"accessors.SlimeEntityAccessor",
102102
"accessors.StatusEffectInstanceAccessor",

0 commit comments

Comments
 (0)