Migrate away from deprecated fabric-api modules

This commit is contained in:
Jonas Herzig
2022-05-24 10:44:30 +02:00
parent f595d9ca23
commit 9f8957f468
6 changed files with 147 additions and 7 deletions

View File

@@ -279,9 +279,11 @@ dependencies {
"resource-loader-v0", "resource-loader-v0",
] ]
if (mcVersion >= 11600) { if (mcVersion >= 11600) {
fabricApiModules.remove("keybindings-v0")
fabricApiModules.add("key-binding-api-v1") fabricApiModules.add("key-binding-api-v1")
} }
if (mcVersion >= 11700) { if (mcVersion >= 11700) {
fabricApiModules.remove("networking-v0")
fabricApiModules.add("networking-api-v1") fabricApiModules.add("networking-api-v1")
} }
fabricApiModules.each { module -> fabricApiModules.each { module ->

View File

@@ -14,7 +14,11 @@ import net.minecraft.util.crash.CrashException;
//#if FABRIC>=1 //#if FABRIC>=1
import com.replaymod.core.versions.LangResourcePack; import com.replaymod.core.versions.LangResourcePack;
import net.fabricmc.fabric.api.client.keybinding.FabricKeyBinding; //#if MC>=11600
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
//#else
//$$ import net.fabricmc.fabric.api.client.keybinding.FabricKeyBinding;
//#endif
import net.minecraft.client.util.InputUtil; import net.minecraft.client.util.InputUtil;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import static com.replaymod.core.ReplayMod.MOD_ID; import static com.replaymod.core.ReplayMod.MOD_ID;
@@ -35,8 +39,8 @@ import java.util.function.Supplier;
public class KeyBindingRegistry extends EventRegistrations { public class KeyBindingRegistry extends EventRegistrations {
private static final String CATEGORY = "replaymod.title"; private static final String CATEGORY = "replaymod.title";
//#if FABRIC>=1 //#if FABRIC>=1 && MC<11600
static { net.fabricmc.fabric.api.client.keybinding.KeyBindingRegistry.INSTANCE.addCategory(CATEGORY); } //$$ static { net.fabricmc.fabric.api.client.keybinding.KeyBindingRegistry.INSTANCE.addCategory(CATEGORY); }
//#endif //#endif
private final Map<String, Binding> bindings = new HashMap<>(); private final Map<String, Binding> bindings = new HashMap<>();
@@ -63,9 +67,15 @@ public class KeyBindingRegistry extends EventRegistrations {
keyCode = -1; keyCode = -1;
} }
Identifier id = new Identifier(MOD_ID, name.substring(LangResourcePack.LEGACY_KEY_PREFIX.length())); Identifier id = new Identifier(MOD_ID, name.substring(LangResourcePack.LEGACY_KEY_PREFIX.length()));
FabricKeyBinding fabricKeyBinding = FabricKeyBinding.Builder.create(id, InputUtil.Type.KEYSYM, keyCode, CATEGORY).build(); //#if MC>=11600
net.fabricmc.fabric.api.client.keybinding.KeyBindingRegistry.INSTANCE.register(fabricKeyBinding); String key = String.format("key.%s.%s", id.getNamespace(), id.getPath());
KeyBinding keyBinding = fabricKeyBinding; KeyBinding keyBinding = new KeyBinding(key, InputUtil.Type.KEYSYM, keyCode, CATEGORY);
KeyBindingHelper.registerKeyBinding(keyBinding);
//#else
//$$ FabricKeyBinding fabricKeyBinding = FabricKeyBinding.Builder.create(id, InputUtil.Type.KEYSYM, keyCode, CATEGORY).build();
//$$ net.fabricmc.fabric.api.client.keybinding.KeyBindingRegistry.INSTANCE.register(fabricKeyBinding);
//$$ KeyBinding keyBinding = fabricKeyBinding;
//#endif
//#else //#else
//$$ KeyBinding keyBinding = new KeyBinding(name, keyCode, CATEGORY); //$$ KeyBinding keyBinding = new KeyBinding(name, keyCode, CATEGORY);
//$$ ClientRegistry.registerKeyBinding(keyBinding); //$$ ClientRegistry.registerKeyBinding(keyBinding);

View File

@@ -16,7 +16,11 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
//#if FABRIC>=1 //#if FABRIC>=1
//#if MC>=11700
//$$ import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
//#else
import net.fabricmc.fabric.api.network.ClientSidePacketRegistry; import net.fabricmc.fabric.api.network.ClientSidePacketRegistry;
//#endif
//#else //#else
//$$ import net.minecraftforge.fml.network.NetworkRegistry; //$$ import net.minecraftforge.fml.network.NetworkRegistry;
//#endif //#endif
@@ -68,7 +72,11 @@ public class ReplayModRecording implements Module {
new GuiHandler(core).register(); new GuiHandler(core).register();
//#if FABRIC>=1 //#if FABRIC>=1
//#if MC>=11700
//$$ ClientPlayNetworking.registerGlobalReceiver(Restrictions.PLUGIN_CHANNEL, (client, handler, buf, resp) -> {});
//#else
ClientSidePacketRegistry.INSTANCE.register(Restrictions.PLUGIN_CHANNEL, (packetContext, packetByteBuf) -> {}); ClientSidePacketRegistry.INSTANCE.register(Restrictions.PLUGIN_CHANNEL, (packetContext, packetByteBuf) -> {});
//#endif
//#else //#else
//#if MC>=11400 //#if MC>=11400
//$$ NetworkRegistry.newEventChannel(Restrictions.PLUGIN_CHANNEL, () -> "0", any -> true, any -> true); //$$ NetworkRegistry.newEventChannel(Restrictions.PLUGIN_CHANNEL, () -> "0", any -> true, any -> true);

View File

@@ -43,7 +43,7 @@
"depends": { "depends": {
"fabricloader": ">=0.7.0", "fabricloader": ">=0.7.0",
"fabric-networking-v0": "*", "fabric-networking-v0": "*",
"fabric-keybindings-v0": "*", "fabric-key-binding-api-v1": "*",
"fabric-resource-loader-v0": "*" "fabric-resource-loader-v0": "*"
}, },

View File

@@ -0,0 +1,60 @@
{
"schemaVersion": 1,
"id": "replaymod",
"version": "${version}",
"name": "Replay Mod",
"description": "A Mod which allows you to record, replay and share your Minecraft experience.",
"authors": [
"CrushedPixel",
"johni0702"
],
"contact": {
"homepage": "https://replaymod.com/",
"sources": "https://github.com/ReplayMod/ReplayMod"
},
"license": "GPL-3.0-or-later",
"icon": "assets/replaymod/favicon_logo.png",
"environment": "client",
"entrypoints": {
"client": [
"com.replaymod.core.ReplayModBackend"
],
"modmenu": [
"com.replaymod.core.gui.ModMenuApiImpl"
],
"frex_flawless_frames": [
"com.replaymod.render.utils.FlawlessFrames::registerConsumer"
],
"preLaunch": [
"com.replaymod.core.DummyChainLoadEntryPoint"
],
"mm:early_risers": [
"com.replaymod.core.ReplayModMMLauncher"
]
},
"mixins": [
"mixins.jgui.json",
"mixins.nonmmlauncher.replaymod.json"
],
"depends": {
"fabricloader": ">=0.7.0",
"fabric-networking-v0": "*",
"fabric-keybindings-v0": "*",
"fabric-resource-loader-v0": "*"
},
"conflicts": {
"iris": "<1.1.3"
},
"custom": {
"mm:early_risers": [
"com.replaymod.core.ReplayModMMLauncher"
],
"modmenu:clientsideOnly": true
}
}

View File

@@ -0,0 +1,60 @@
{
"schemaVersion": 1,
"id": "replaymod",
"version": "${version}",
"name": "Replay Mod",
"description": "A Mod which allows you to record, replay and share your Minecraft experience.",
"authors": [
"CrushedPixel",
"johni0702"
],
"contact": {
"homepage": "https://replaymod.com/",
"sources": "https://github.com/ReplayMod/ReplayMod"
},
"license": "GPL-3.0-or-later",
"icon": "assets/replaymod/favicon_logo.png",
"environment": "client",
"entrypoints": {
"client": [
"com.replaymod.core.ReplayModBackend"
],
"modmenu": [
"com.replaymod.core.gui.ModMenuApiImpl"
],
"frex_flawless_frames": [
"com.replaymod.render.utils.FlawlessFrames::registerConsumer"
],
"preLaunch": [
"com.replaymod.core.DummyChainLoadEntryPoint"
],
"mm:early_risers": [
"com.replaymod.core.ReplayModMMLauncher"
]
},
"mixins": [
"mixins.jgui.json",
"mixins.nonmmlauncher.replaymod.json"
],
"depends": {
"fabricloader": ">=0.7.0",
"fabric-networking-api-v1": "*",
"fabric-key-binding-api-v1": "*",
"fabric-resource-loader-v0": "*"
},
"conflicts": {
"iris": "<1.1.3"
},
"custom": {
"mm:early_risers": [
"com.replaymod.core.ReplayModMMLauncher"
],
"modmenu:clientsideOnly": true
}
}