-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This ties the f3+f4 and f3+n keybinds to the gamemode command instead of the permission level
- Loading branch information
1 parent
6f18c03
commit f7fd585
Showing
4 changed files
with
76 additions
and
1 deletion.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
src/main/java/net/modfest/fireblanket/mixin/gamemode_selection/MixinKeyboard.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,32 @@ | ||
package net.modfest.fireblanket.mixin.gamemode_selection; | ||
|
||
import net.minecraft.client.Keyboard; | ||
import net.minecraft.client.network.ClientPlayerEntity; | ||
import net.modfest.fireblanket.util.CanSwitchGameMode; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Redirect; | ||
|
||
/** | ||
* @see CanSwitchGameMode#canSwitchGameMode(ClientPlayerEntity) | ||
*/ | ||
@Mixin(Keyboard.class) | ||
public class MixinKeyboard { | ||
/** | ||
* Replaces the {@link net.minecraft.entity.Entity#hasPermissionLevel(int)} check for | ||
* using {@code f3+n} with the one in {@link CanSwitchGameMode}. | ||
*/ | ||
@Redirect(method = "processF3", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;hasPermissionLevel(I)Z", ordinal = 1)) | ||
private boolean redirectPermissionCheck(ClientPlayerEntity instance, int i) { | ||
return CanSwitchGameMode.canSwitchGameMode(instance); | ||
} | ||
|
||
/** | ||
* Replaces the {@link net.minecraft.entity.Entity#hasPermissionLevel(int)} check for | ||
* using {@code f3+f4} with the one in {@link CanSwitchGameMode}. | ||
*/ | ||
@Redirect(method = "processF3", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;hasPermissionLevel(I)Z", ordinal = 2)) | ||
private boolean redirectPermissionCheck2(ClientPlayerEntity instance, int i) { | ||
return CanSwitchGameMode.canSwitchGameMode(instance); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/net/modfest/fireblanket/mixin/gamemode_selection/MixinSelectionScreen.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,22 @@ | ||
package net.modfest.fireblanket.mixin.gamemode_selection; | ||
|
||
import net.minecraft.client.gui.screen.GameModeSelectionScreen; | ||
import net.minecraft.client.network.ClientPlayerEntity; | ||
import net.modfest.fireblanket.util.CanSwitchGameMode; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Redirect; | ||
|
||
/** | ||
* @see CanSwitchGameMode#canSwitchGameMode(ClientPlayerEntity) | ||
*/ | ||
@Mixin(GameModeSelectionScreen.class) | ||
public class MixinSelectionScreen { | ||
/** | ||
* Replaces a {@link net.minecraft.entity.Entity#hasPermissionLevel(int)} check with the one in {@link CanSwitchGameMode}. | ||
*/ | ||
@Redirect(method = "apply(Lnet/minecraft/client/MinecraftClient;Lnet/minecraft/client/gui/screen/GameModeSelectionScreen$GameModeSelection;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;hasPermissionLevel(I)Z")) | ||
private static boolean redirectPermissionCheck(ClientPlayerEntity instance, int i) { | ||
return CanSwitchGameMode.canSwitchGameMode(instance); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/net/modfest/fireblanket/util/CanSwitchGameMode.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,19 @@ | ||
package net.modfest.fireblanket.util; | ||
|
||
import net.minecraft.client.network.ClientPlayerEntity; | ||
|
||
public class CanSwitchGameMode { | ||
/** | ||
* By default, minecraft checks the permission level to see if a player can | ||
* switch game modes using the quick-switcher. This is a more advanced check | ||
* that looks at if the client can use the gamemode command. | ||
* <p> | ||
* This is useful when using player-roles as that can be used to | ||
* give /gamemode without giving the whole permission level | ||
* @see net.modfest.fireblanket.mixin.gamemode_selection.MixinSelectionScreen | ||
*/ | ||
public static boolean canSwitchGameMode(ClientPlayerEntity player) { | ||
var dispatcher = player.networkHandler.getCommandDispatcher(); | ||
return dispatcher.getRoot().getChild("gamemode") != null; | ||
} | ||
} |
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