feat: added NoClip, renamed Editor to ClientEditor to make space for Server support

moonleay 2024-04-23 03:04:58 +02:00
parent 82311fa617
commit 0cd271f139
Signed by: moonleay
GPG key ID: 82667543CCD715FB
15 changed files with 88 additions and 50 deletions

@ -3,6 +3,7 @@ package net.moonleay.mods.gimble.client
import net.moonleay.mods.gimble.build.BuildConstants import net.moonleay.mods.gimble.build.BuildConstants
import net.fabricmc.api.ClientModInitializer import net.fabricmc.api.ClientModInitializer
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents
import net.moonleay.mods.gimble.client.editor.ClientEditor
import net.moonleay.mods.gimble.client.keybindings.KeybindingManager import net.moonleay.mods.gimble.client.keybindings.KeybindingManager
import net.moonleay.mods.gimble.client.keybindings.KeybindingRegistrar import net.moonleay.mods.gimble.client.keybindings.KeybindingRegistrar
import org.apache.logging.log4j.LogManager import org.apache.logging.log4j.LogManager

@ -5,7 +5,7 @@ import net.moonleay.mods.gimble.client.util.ChatUtil
import net.moonleay.mods.gimble.client.editor.modes.Mode import net.moonleay.mods.gimble.client.editor.modes.Mode
import net.moonleay.mods.gimble.client.editor.modes.ModeModifier import net.moonleay.mods.gimble.client.editor.modes.ModeModifier
object Editor { object ClientEditor {
var CURRENT_MODE = Mode.NORMAL var CURRENT_MODE = Mode.NORMAL
val CURRENT_MODE_MODIFIER = mutableListOf<ModeModifier>() val CURRENT_MODE_MODIFIER = mutableListOf<ModeModifier>()
private val TEMP_DISABLED_MODIFIERS = mutableListOf<ModeModifier>() private val TEMP_DISABLED_MODIFIERS = mutableListOf<ModeModifier>()
@ -75,4 +75,8 @@ object Editor {
fun getCurrentModifier(): List<ModeModifier> { fun getCurrentModifier(): List<ModeModifier> {
return CURRENT_MODE_MODIFIER return CURRENT_MODE_MODIFIER
} }
fun containsModifier(mod: ModeModifier): Boolean {
return CURRENT_MODE_MODIFIER.contains(mod)
}
} }

@ -2,15 +2,15 @@ package net.moonleay.mods.gimble.client.keybindings.impl.editormode
import net.minecraft.client.MinecraftClient import net.minecraft.client.MinecraftClient
import net.minecraft.client.option.KeyBinding import net.minecraft.client.option.KeyBinding
import net.moonleay.mods.gimble.client.editor.Editor import net.moonleay.mods.gimble.client.editor.ClientEditor
import net.moonleay.mods.gimble.client.keybindings.impl.GimbleShortcut import net.moonleay.mods.gimble.client.keybindings.impl.GimbleShortcut
import net.moonleay.mods.gimble.client.editor.modes.Mode import net.moonleay.mods.gimble.client.editor.modes.Mode
class EnableInsertModeShortcut(key: KeyBinding): GimbleShortcut(key) { class EnableInsertModeShortcut(key: KeyBinding): GimbleShortcut(key) {
override fun onPressed(client: MinecraftClient) { override fun onPressed(client: MinecraftClient) {
Editor.CURRENT_MODE = Mode.INSERT ClientEditor.CURRENT_MODE = Mode.INSERT
Editor.checkForIncompatibleModeModifiers() ClientEditor.checkForIncompatibleModeModifiers()
} }
} }

@ -2,15 +2,15 @@ package net.moonleay.mods.gimble.client.keybindings.impl.editormode
import net.minecraft.client.MinecraftClient import net.minecraft.client.MinecraftClient
import net.minecraft.client.option.KeyBinding import net.minecraft.client.option.KeyBinding
import net.moonleay.mods.gimble.client.editor.Editor import net.moonleay.mods.gimble.client.editor.ClientEditor
import net.moonleay.mods.gimble.client.keybindings.impl.GimbleShortcut import net.moonleay.mods.gimble.client.keybindings.impl.GimbleShortcut
import net.moonleay.mods.gimble.client.editor.modes.Mode import net.moonleay.mods.gimble.client.editor.modes.Mode
class EnableReplaceModeShortcut(key: KeyBinding): GimbleShortcut(key) { class EnableReplaceModeShortcut(key: KeyBinding): GimbleShortcut(key) {
override fun onPressed(client: MinecraftClient) { override fun onPressed(client: MinecraftClient) {
Editor.CURRENT_MODE = Mode.REPLACE ClientEditor.CURRENT_MODE = Mode.REPLACE
Editor.checkForIncompatibleModeModifiers() ClientEditor.checkForIncompatibleModeModifiers()
} }
} }

@ -2,15 +2,15 @@ package net.moonleay.mods.gimble.client.keybindings.impl.editormode
import net.minecraft.client.MinecraftClient import net.minecraft.client.MinecraftClient
import net.minecraft.client.option.KeyBinding import net.minecraft.client.option.KeyBinding
import net.moonleay.mods.gimble.client.editor.Editor import net.moonleay.mods.gimble.client.editor.ClientEditor
import net.moonleay.mods.gimble.client.keybindings.impl.GimbleShortcut import net.moonleay.mods.gimble.client.keybindings.impl.GimbleShortcut
import net.moonleay.mods.gimble.client.editor.modes.Mode import net.moonleay.mods.gimble.client.editor.modes.Mode
class EnableVisualModeShortcut(key: KeyBinding): GimbleShortcut(key) { class EnableVisualModeShortcut(key: KeyBinding): GimbleShortcut(key) {
override fun onPressed(client: MinecraftClient) { override fun onPressed(client: MinecraftClient) {
Editor.CURRENT_MODE = Mode.VISUAL ClientEditor.CURRENT_MODE = Mode.VISUAL
Editor.checkForIncompatibleModeModifiers() ClientEditor.checkForIncompatibleModeModifiers()
} }
} }

@ -2,14 +2,14 @@ package net.moonleay.mods.gimble.client.keybindings.impl.editormodemodifier
import net.minecraft.client.MinecraftClient import net.minecraft.client.MinecraftClient
import net.minecraft.client.option.KeyBinding import net.minecraft.client.option.KeyBinding
import net.moonleay.mods.gimble.client.editor.Editor import net.moonleay.mods.gimble.client.editor.ClientEditor
import net.moonleay.mods.gimble.client.keybindings.impl.GimbleShortcut import net.moonleay.mods.gimble.client.keybindings.impl.GimbleShortcut
import net.moonleay.mods.gimble.client.editor.modes.ModeModifier import net.moonleay.mods.gimble.client.editor.modes.ModeModifier
class ToggleBulldozerModifierShortcut(key: KeyBinding): GimbleShortcut(key) { class ToggleBulldozerModifierShortcut(key: KeyBinding): GimbleShortcut(key) {
override fun onPressed(client: MinecraftClient) { override fun onPressed(client: MinecraftClient) {
Editor.toggleModifier(ModeModifier.BULLDOZER) ClientEditor.toggleModifier(ModeModifier.BULLDOZER)
Editor.onModifiersUpdated() ClientEditor.onModifiersUpdated()
} }
} }

@ -2,14 +2,14 @@ package net.moonleay.mods.gimble.client.keybindings.impl.editormodemodifier
import net.minecraft.client.MinecraftClient import net.minecraft.client.MinecraftClient
import net.minecraft.client.option.KeyBinding import net.minecraft.client.option.KeyBinding
import net.moonleay.mods.gimble.client.editor.Editor import net.moonleay.mods.gimble.client.editor.ClientEditor
import net.moonleay.mods.gimble.client.keybindings.impl.GimbleShortcut import net.moonleay.mods.gimble.client.keybindings.impl.GimbleShortcut
import net.moonleay.mods.gimble.client.editor.modes.ModeModifier import net.moonleay.mods.gimble.client.editor.modes.ModeModifier
class ToggleForcePlaceModifierShortcut(key: KeyBinding): GimbleShortcut(key) { class ToggleForcePlaceModifierShortcut(key: KeyBinding): GimbleShortcut(key) {
override fun onPressed(client: MinecraftClient) { override fun onPressed(client: MinecraftClient) {
Editor.toggleModifier(ModeModifier.FORCE_PLACE) ClientEditor.toggleModifier(ModeModifier.FORCE_PLACE)
Editor.onModifiersUpdated() ClientEditor.onModifiersUpdated()
} }
} }

@ -2,14 +2,14 @@ package net.moonleay.mods.gimble.client.keybindings.impl.editormodemodifier
import net.minecraft.client.MinecraftClient import net.minecraft.client.MinecraftClient
import net.minecraft.client.option.KeyBinding import net.minecraft.client.option.KeyBinding
import net.moonleay.mods.gimble.client.editor.Editor import net.moonleay.mods.gimble.client.editor.ClientEditor
import net.moonleay.mods.gimble.client.keybindings.impl.GimbleShortcut import net.moonleay.mods.gimble.client.keybindings.impl.GimbleShortcut
import net.moonleay.mods.gimble.client.editor.modes.ModeModifier import net.moonleay.mods.gimble.client.editor.modes.ModeModifier
class ToggleNoClipModifierShortcut(key: KeyBinding): GimbleShortcut(key) { class ToggleNoClipModifierShortcut(key: KeyBinding): GimbleShortcut(key) {
override fun onPressed(client: MinecraftClient) { override fun onPressed(client: MinecraftClient) {
Editor.toggleModifier(ModeModifier.NO_CLIP) ClientEditor.toggleModifier(ModeModifier.NO_CLIP)
Editor.onModifiersUpdated() ClientEditor.onModifiersUpdated()
} }
} }

@ -2,14 +2,14 @@ package net.moonleay.mods.gimble.client.keybindings.impl.editormodemodifier
import net.minecraft.client.MinecraftClient import net.minecraft.client.MinecraftClient
import net.minecraft.client.option.KeyBinding import net.minecraft.client.option.KeyBinding
import net.moonleay.mods.gimble.client.editor.Editor import net.moonleay.mods.gimble.client.editor.ClientEditor
import net.moonleay.mods.gimble.client.keybindings.impl.GimbleShortcut import net.moonleay.mods.gimble.client.keybindings.impl.GimbleShortcut
import net.moonleay.mods.gimble.client.editor.modes.ModeModifier import net.moonleay.mods.gimble.client.editor.modes.ModeModifier
class ToggleNoUpdatesModifierShortcut(key: KeyBinding): GimbleShortcut(key) { class ToggleNoUpdatesModifierShortcut(key: KeyBinding): GimbleShortcut(key) {
override fun onPressed(client: MinecraftClient) { override fun onPressed(client: MinecraftClient) {
Editor.toggleModifier(ModeModifier.NO_UPDATES) ClientEditor.toggleModifier(ModeModifier.NO_UPDATES)
Editor.onModifiersUpdated() ClientEditor.onModifiersUpdated()
} }
} }

@ -5,7 +5,7 @@ import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.hud.InGameHud; import net.minecraft.client.gui.hud.InGameHud;
import net.minecraft.client.util.math.MatrixStack; import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.moonleay.mods.gimble.client.editor.Editor; import net.moonleay.mods.gimble.client.editor.ClientEditor;
import net.moonleay.mods.gimble.client.editor.modes.Mode; import net.moonleay.mods.gimble.client.editor.modes.Mode;
import net.moonleay.mods.gimble.client.editor.modes.ModeModifier; import net.moonleay.mods.gimble.client.editor.modes.ModeModifier;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -26,7 +26,7 @@ public class HudMixin {
@Inject(method = "renderStatusEffectOverlay", at = @At("HEAD")) @Inject(method = "renderStatusEffectOverlay", at = @At("HEAD"))
private void render(MatrixStack matrices, CallbackInfo ci) { private void render(MatrixStack matrices, CallbackInfo ci) {
Mode currentMode = Editor.INSTANCE.getCurrentMode(); Mode currentMode = ClientEditor.INSTANCE.getCurrentMode();
StringBuilder displayText = getStringBuilder(currentMode); StringBuilder displayText = getStringBuilder(currentMode);
MinecraftClient mc = MinecraftClient.getInstance(); MinecraftClient mc = MinecraftClient.getInstance();
@ -44,7 +44,7 @@ public class HudMixin {
@Unique @Unique
private static @NotNull StringBuilder getStringBuilder(Mode currentMode) { private static @NotNull StringBuilder getStringBuilder(Mode currentMode) {
List<ModeModifier> currentModifier = Editor.INSTANCE.getCurrentModifier(); List<ModeModifier> currentModifier = ClientEditor.INSTANCE.getCurrentModifier();
StringBuilder displayText = new StringBuilder(currentMode.getDisplayName()); StringBuilder displayText = new StringBuilder(currentMode.getDisplayName());
if (!currentModifier.isEmpty()) { if (!currentModifier.isEmpty()) {
displayText.append(" ["); displayText.append(" [");

@ -1,7 +1,6 @@
package net.moonleay.mods.gimble.mixin; package net.moonleay.mods.gimble.mixin;
import net.minecraft.client.Keyboard; import net.minecraft.client.Keyboard;
import org.lwjgl.glfw.GLFW;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;

@ -0,0 +1,35 @@
package net.moonleay.mods.gimble.mixin;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.network.Packet;
import net.minecraft.world.World;
import net.minecraft.world.entity.EntityLike;
import net.moonleay.mods.gimble.client.editor.ClientEditor;
import net.moonleay.mods.gimble.client.editor.modes.ModeModifier;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(Entity.class)
public class NoClipMixin {
@Shadow public boolean noClip;
@Inject(method = "tick", at = @At(value = "HEAD"))
private void enoClip(CallbackInfo ci) {
if (!ClientEditor.INSTANCE.containsModifier(ModeModifier.NO_CLIP))
return;
// TODO: Add player check, add multiplayer compat
if(!((Entity)(Object)this instanceof PlayerEntity))
return;
this.noClip = true;
}
}

@ -1,9 +1,8 @@
package net.moonleay.mods.gimble.mixin; package net.moonleay.mods.gimble.mixin;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.option.GameOptions; import net.minecraft.client.option.GameOptions;
import net.moonleay.mods.gimble.client.editor.Editor; import net.moonleay.mods.gimble.client.editor.ClientEditor;
import net.moonleay.mods.gimble.client.editor.modes.Mode; import net.moonleay.mods.gimble.client.editor.modes.Mode;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
@ -21,17 +20,17 @@ public class NormalModeMixin {
@Inject(method = "openPauseMenu", at = @At("HEAD"), cancellable = true) @Inject(method = "openPauseMenu", at = @At("HEAD"), cancellable = true)
private void setNormalMode(boolean pause, CallbackInfo ci) { private void setNormalMode(boolean pause, CallbackInfo ci) {
if (Editor.INSTANCE.getCURRENT_MODE() != Mode.NORMAL){ if (ClientEditor.INSTANCE.getCURRENT_MODE() != Mode.NORMAL){
// Set the editor mode to normal // Set the editor mode to normal
Editor.INSTANCE.setCURRENT_MODE(Mode.NORMAL); ClientEditor.INSTANCE.setCURRENT_MODE(Mode.NORMAL);
Editor.INSTANCE.checkForIncompatibleModeModifiers(); ClientEditor.INSTANCE.checkForIncompatibleModeModifiers();
ci.cancel(); ci.cancel();
} }
} }
@Inject(method = "handleInputEvents", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;isUsingItem()Z"), cancellable = true) @Inject(method = "handleInputEvents", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;isUsingItem()Z"), cancellable = true)
private void blockWorldManipulation(CallbackInfo ci) { private void blockWorldManipulation(CallbackInfo ci) { // This could be replaced by net.minecraft.world.GameMode#isBlockBreakingRestricted
if (Editor.INSTANCE.getCURRENT_MODE() == Mode.NORMAL || Editor.INSTANCE.getCURRENT_MODE() == Mode.VISUAL) { if (ClientEditor.INSTANCE.getCURRENT_MODE() == Mode.NORMAL || ClientEditor.INSTANCE.getCURRENT_MODE() == Mode.VISUAL) {
while(this.options.attackKey.wasPressed()) { while(this.options.attackKey.wasPressed()) {
} }

@ -11,9 +11,8 @@ import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.hit.HitResult; import net.minecraft.util.hit.HitResult;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction; import net.minecraft.util.math.Direction;
import net.moonleay.mods.gimble.client.editor.Editor; import net.moonleay.mods.gimble.client.editor.ClientEditor;
import net.moonleay.mods.gimble.client.editor.modes.Mode; import net.moonleay.mods.gimble.client.editor.modes.Mode;
import net.moonleay.mods.gimble.client.util.ChatUtil;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
@ -39,7 +38,7 @@ public abstract class ReplaceModeMixin {
@Inject(method = "doItemUse", at = @At("HEAD")) @Inject(method = "doItemUse", at = @At("HEAD"))
private void replaceBlock(CallbackInfo ci) { private void replaceBlock(CallbackInfo ci) {
// Check if should run // Check if should run
if (!Editor.INSTANCE.getCURRENT_MODE().equals(Mode.REPLACE)) if (!ClientEditor.INSTANCE.getCURRENT_MODE().equals(Mode.REPLACE))
return; // Mode is not REPLACE, ignore return; // Mode is not REPLACE, ignore
MinecraftClient client = MinecraftClient.getInstance(); MinecraftClient client = MinecraftClient.getInstance();
assert this.interactionManager != null; assert this.interactionManager != null;

@ -1,16 +1,17 @@
{ {
"required": true, "required": true,
"minVersion": "0.8", "minVersion": "0.8",
"package": "net.moonleay.mods.gimble.mixin", "package": "net.moonleay.mods.gimble.mixin",
"compatibilityLevel": "JAVA_17", "compatibilityLevel": "JAVA_17",
"mixins": [ "mixins": [
], "NoClipMixin"
"client": [ ],
"HudMixin", "client": [
"NormalModeMixin", "HudMixin",
"ReplaceModeMixin" "NormalModeMixin",
], "ReplaceModeMixin"
"injectors": { ],
"defaultRequire": 1 "injectors": {
} "defaultRequire": 1
}
} }