KubeJS compatibility
This commit is contained in:
parent
faa2c10d0e
commit
d38a034b1b
3 changed files with 61 additions and 0 deletions
|
@ -0,0 +1,39 @@
|
|||
package ru.betterend.mixin.common;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.resource.ServerResourceManager;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import ru.betterend.recipe.EndRecipeManager;
|
||||
|
||||
@Mixin(MinecraftServer.class)
|
||||
public class MinecraftServerMixin {
|
||||
@Shadow
|
||||
private ServerResourceManager serverResourceManager;
|
||||
|
||||
@Inject(method = "reloadResources", at = @At(value = "RETURN"), cancellable = true)
|
||||
private void onReload(Collection<String> collection, CallbackInfoReturnable<CompletableFuture<Void>> info) {
|
||||
injectRecipes();
|
||||
}
|
||||
|
||||
@Inject(method = "loadWorld", at = @At(value = "RETURN"), cancellable = true)
|
||||
private void onLoadWorld(CallbackInfo info) {
|
||||
injectRecipes();
|
||||
}
|
||||
|
||||
private void injectRecipes() {
|
||||
if (FabricLoader.getInstance().isModLoaded("kubejs")) {
|
||||
RecipeManagerAccessor accessor = (RecipeManagerAccessor) serverResourceManager.getRecipeManager();
|
||||
accessor.setRecipes(EndRecipeManager.getMap(accessor.getRecipes()));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package ru.betterend.mixin.common;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
import net.minecraft.recipe.Recipe;
|
||||
import net.minecraft.recipe.RecipeManager;
|
||||
import net.minecraft.recipe.RecipeType;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
@Mixin(RecipeManager.class)
|
||||
public interface RecipeManagerAccessor {
|
||||
@Accessor("recipes")
|
||||
Map<RecipeType<?>, Map<Identifier, Recipe<?>>> getRecipes();
|
||||
|
||||
@Accessor("recipes")
|
||||
void setRecipes(Map<RecipeType<?>, Map<Identifier, Recipe<?>>> recipes);
|
||||
}
|
|
@ -12,6 +12,8 @@
|
|||
"ChorusPlantFeatureMixin",
|
||||
"ChorusFlowerBlockMixin",
|
||||
"ChorusPlantBlockMixin",
|
||||
"RecipeManagerAccessor",
|
||||
"MinecraftServerMixin",
|
||||
"TagGroupLoaderMixin",
|
||||
"EndermanEntityMixin",
|
||||
"LocateCommandMixin",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue