Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial pass at supporting Forge and Fabric in parallel
- Loading branch information
Showing
7 changed files
with
106 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/main/java/dev/sapphic/controlshift/mixin/OptionsMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"pack": { | ||
"description": "", | ||
"pack_format": -1 | ||
} | ||
} |