Skip to content

Commit

Permalink
Initial pass at supporting Forge and Fabric in parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
ChloeDawn committed Jan 18, 2021
1 parent 6c7e1d1 commit a6d4b67
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 53 deletions.
13 changes: 9 additions & 4 deletions build.gradle.kts
Expand Up @@ -2,7 +2,7 @@ import org.gradle.util.GradleVersion
import java.time.Instant

plugins {
id("fabric-loom") version "0.5.43"
id("fabric-loom") version "0.6.22"
id("net.nemerosa.versioning") version "2.6.1"
id("signing")
}
Expand All @@ -14,13 +14,18 @@ java {
withSourcesJar()
}

repositories {
maven("https://files.minecraftforge.net/maven/")
}

dependencies {
minecraft("com.mojang:minecraft:1.16.5")
mappings(minecraft.officialMojangMappings())
modImplementation("net.fabricmc:fabric-loader:0.11.1")
implementation("com.google.code.findbugs:jsr305:3.0.2")
implementation("org.jetbrains:annotations:20.1.0")
implementation("org.checkerframework:checker-qual:3.9.0")
compileOnly("net.minecraftforge:forge:1.16.5-36.0.1:universal")
}

tasks {
Expand Down Expand Up @@ -59,11 +64,11 @@ tasks {
"Implementation-Version" to project.version,
"Implementation-Vendor" to project.group,

"Specification-Title" to "MinecraftMod",
"Specification-Version" to "1.1.0",
"Specification-Title" to "ForgeMod",
"Specification-Version" to "1.0.0",
"Specification-Vendor" to project.group,

"Sealed" to "true"
"MixinConfigs" to "dev/sapphic/controlshift/mixins.json"
)

exclude(minecraft.getRefmapName())
Expand Down
57 changes: 11 additions & 46 deletions src/main/java/dev/sapphic/controlshift/ControlShift.java
@@ -1,51 +1,16 @@
/*
* Copyright 2021 Chloe Dawn
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package dev.sapphic.controlshift;

import net.minecraft.client.Options;
import org.lwjgl.glfw.GLFW;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.Group;
import org.spongepowered.asm.mixin.injection.ModifyConstant;

@Mixin(value = Options.class)
abstract class ControlShift {
@Group(name = "shiftToControl", min = 1, max = 1)
@ModifyConstant(method = "<init>", constant = @Constant(intValue = GLFW.GLFW_KEY_LEFT_SHIFT), allow = 1)
private static int shiftToControlGlfw(final int shift) {
return GLFW.GLFW_KEY_LEFT_CONTROL;
}

@Group(name = "controlToShift", max = 1)
@ModifyConstant(method = "<init>", constant = @Constant(intValue = GLFW.GLFW_KEY_LEFT_CONTROL), allow = 1)
private static int controlToShiftGlfw(final int control) {
return GLFW.GLFW_KEY_LEFT_SHIFT;
}

@Group(name = "shiftToControl", min = 1, max = 1)
@ModifyConstant(method = "<init>", constant = @Constant(intValue = JInput.KEY_LEFTSHIFT), allow = 1)
private static int shiftToControlJinput(final int shift) {
return JInput.KEY_LEFTCTRL;
}
import net.minecraftforge.fml.ExtensionPoint;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.network.FMLNetworkConstants;
import org.apache.commons.lang3.tuple.Pair;

@Group(name = "controlToShift", max = 1)
@ModifyConstant(method = "<init>", constant = @Constant(intValue = JInput.KEY_LEFTCTRL), allow = 1)
private static int controlToShiftJinput(final int control) {
return JInput.KEY_LEFTSHIFT;
@Mod("controlshift")
public final class ControlShift {
public ControlShift() {
ModLoadingContext.get().registerExtensionPoint(ExtensionPoint.DISPLAYTEST, () -> {
return Pair.of(() -> FMLNetworkConstants.IGNORESERVERONLY, (s, v) -> true);
});
}
}
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package dev.sapphic.controlshift;
package dev.sapphic.controlshift.mixin;

interface JInput {
/**
Expand Down
53 changes: 53 additions & 0 deletions src/main/java/dev/sapphic/controlshift/mixin/OptionsMixin.java
@@ -0,0 +1,53 @@
/*
* Copyright 2021 Chloe Dawn
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package dev.sapphic.controlshift.mixin;

import net.minecraft.client.Options;
import org.lwjgl.glfw.GLFW;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Pseudo;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.Group;
import org.spongepowered.asm.mixin.injection.ModifyConstant;

@Pseudo
@Mixin(value = Options.class, targets = { "net.minecraft.client.GameSettings" })
abstract class OptionsMixin {
@Group(name = "shiftToControl", min = 1, max = 1)
@ModifyConstant(method = "<init>", constant = @Constant(intValue = GLFW.GLFW_KEY_LEFT_SHIFT), allow = 1)
private static int shiftToControlGlfw(final int shift) {
return GLFW.GLFW_KEY_LEFT_CONTROL;
}

@Group(name = "controlToShift", max = 1)
@ModifyConstant(method = "<init>", constant = @Constant(intValue = GLFW.GLFW_KEY_LEFT_CONTROL), allow = 1)
private static int controlToShiftGlfw(final int control) {
return GLFW.GLFW_KEY_LEFT_SHIFT;
}

@Group(name = "shiftToControl", min = 1, max = 1)
@ModifyConstant(method = "<init>", constant = @Constant(intValue = JInput.KEY_LEFTSHIFT), allow = 1)
private static int shiftToControlJinput(final int shift) {
return JInput.KEY_LEFTCTRL;
}

@Group(name = "controlToShift", max = 1)
@ModifyConstant(method = "<init>", constant = @Constant(intValue = JInput.KEY_LEFTCTRL), allow = 1)
private static int controlToShiftJinput(final int control) {
return JInput.KEY_LEFTSHIFT;
}
}
24 changes: 24 additions & 0 deletions src/main/resources/META-INF/mods.toml
@@ -0,0 +1,24 @@
modLoader="javafml"
loaderVersion="[28,)"
license="Apache-2.0"
issueTrackerURL="https://git.io/JfhAe"

[[mods]]
modId="controlshift"
version="${file.jarVersion}"
displayName="Control Shift"
displayURL="https://git.io/JfhNj"
authors="Chloe Dawn"
description='''Swaps the default sneaking and sprinting key bindings'''

[[dependencies.controlshift]]
modId="minecraft"
mandatory=true
versionRange="[1.14,1.17)"
side="CLIENT"

[[dependencies.controlshift]]
modId="forge"
mandatory=true
versionRange="[28,)"
side="CLIENT"
4 changes: 2 additions & 2 deletions src/main/resources/dev/sapphic/controlshift/mixins.json
Expand Up @@ -2,8 +2,8 @@
"minVersion": "0.8",
"compatibilityLevel": "JAVA_8",
"required": true,
"package": "dev.sapphic.controlshift",
"package": "dev.sapphic.controlshift.mixin",
"client": [
"ControlShift"
"OptionsMixin"
]
}
6 changes: 6 additions & 0 deletions src/main/resources/pack.mcmeta
@@ -0,0 +1,6 @@
{
"pack": {
"description": "",
"pack_format": -1
}
}

0 comments on commit a6d4b67

Please sign in to comment.