mirror of
https://github.com/architectury/architectury-api.git
synced 2026-03-30 13:05:25 -05:00
Add AbstractRecipeSerializer
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
package me.shedaniel.architectury.core;
|
||||
|
||||
import net.minecraft.world.item.crafting.Recipe;
|
||||
import net.minecraft.world.item.crafting.RecipeSerializer;
|
||||
|
||||
/**
|
||||
* The equivalent of {@link RecipeSerializer} to use in common that has forge registry entries extended.
|
||||
*/
|
||||
public abstract class AbstractRecipeSerializer<T extends Recipe<?>> implements RecipeSerializer<T> {
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package me.shedaniel.architectury.mixin.forge;
|
||||
|
||||
import me.shedaniel.architectury.core.AbstractRecipeSerializer;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
|
||||
@Mixin(AbstractRecipeSerializer.class)
|
||||
public class MixinAbstractRecipeSerializer {
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package me.shedaniel.architectury.plugin.forge;
|
||||
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.tree.AbstractInsnNode;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.objectweb.asm.tree.MethodInsnNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
|
||||
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
public class ArchitecturyMixinPlugin implements IMixinConfigPlugin {
|
||||
@Override
|
||||
public void onLoad(String mixinPackage) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRefMapperConfig() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getMixins() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
|
||||
// Inject our own sugar
|
||||
switch (mixinClassName) {
|
||||
case "me.shedaniel.architectury.mixin.forge.MixinAbstractRecipeSerializer":
|
||||
targetClass.superName = "net/minecraftforge/registries/ForgeRegistryEntry";
|
||||
for (MethodNode method : targetClass.methods) {
|
||||
if (Objects.equals(method.name, "<init>")) {
|
||||
for (AbstractInsnNode insnNode : method.instructions) {
|
||||
if (insnNode.getOpcode() == Opcodes.INVOKESPECIAL && insnNode instanceof MethodInsnNode) {
|
||||
MethodInsnNode node = (MethodInsnNode) insnNode;
|
||||
if (Objects.equals(node.name, "<init>") && Objects.equals(node.owner, "java/lang/Object")) {
|
||||
node.owner = "net/minecraftforge/registries/ForgeRegistryEntry";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
String recipeSerializer = targetClass.interfaces.get(0);
|
||||
if (targetClass.signature != null) {
|
||||
targetClass.signature = targetClass.signature.replace("Ljava/lang/Object;", "Lnet/minecraftforge/registries/ForgeRegistryEntry<L" + recipeSerializer + "<*>;>");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,15 @@
|
||||
{
|
||||
"required": true,
|
||||
"package": "me.shedaniel.architectury.mixin.forge",
|
||||
"plugin": "me.shedaniel.architectury.plugin.forge.ArchitecturyMixinPlugin",
|
||||
"compatibilityLevel": "JAVA_8",
|
||||
"minVersion": "0.8",
|
||||
"client": [
|
||||
],
|
||||
"mixins": ["BiomeGenerationSettingsBuilderAccessor", "MixinBlockEntity", "MixinBlockEntityExtension", "MobSpawnSettingsBuilderAccessor"],
|
||||
"mixins": [
|
||||
"BiomeGenerationSettingsBuilderAccessor", "MixinAbstractRecipeSerializer", "MixinBlockEntity", "MixinBlockEntityExtension",
|
||||
"MobSpawnSettingsBuilderAccessor"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user