diff --git a/src/main/java/net/moonleay/mods/gimble/client/ClientMain.kt b/src/main/java/net/moonleay/mods/gimble/client/ClientMain.kt index dd78ddc..1507934 100644 --- a/src/main/java/net/moonleay/mods/gimble/client/ClientMain.kt +++ b/src/main/java/net/moonleay/mods/gimble/client/ClientMain.kt @@ -3,6 +3,7 @@ package net.moonleay.mods.gimble.client import net.moonleay.mods.gimble.build.BuildConstants import net.fabricmc.api.ClientModInitializer 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.KeybindingRegistrar import org.apache.logging.log4j.LogManager diff --git a/src/main/java/net/moonleay/mods/gimble/client/editor/Editor.kt b/src/main/java/net/moonleay/mods/gimble/client/editor/ClientEditor.kt similarity index 94% rename from src/main/java/net/moonleay/mods/gimble/client/editor/Editor.kt rename to src/main/java/net/moonleay/mods/gimble/client/editor/ClientEditor.kt index 386337f..31f2ddb 100644 --- a/src/main/java/net/moonleay/mods/gimble/client/editor/Editor.kt +++ b/src/main/java/net/moonleay/mods/gimble/client/editor/ClientEditor.kt @@ -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.ModeModifier -object Editor { +object ClientEditor { var CURRENT_MODE = Mode.NORMAL val CURRENT_MODE_MODIFIER = mutableListOf() private val TEMP_DISABLED_MODIFIERS = mutableListOf() @@ -75,4 +75,8 @@ object Editor { fun getCurrentModifier(): List { return CURRENT_MODE_MODIFIER } + + fun containsModifier(mod: ModeModifier): Boolean { + return CURRENT_MODE_MODIFIER.contains(mod) + } } diff --git a/src/main/java/net/moonleay/mods/gimble/client/keybindings/impl/editormode/EnableInsertModeShortcut.kt b/src/main/java/net/moonleay/mods/gimble/client/keybindings/impl/editormode/EnableInsertModeShortcut.kt index b2baebb..06609cb 100644 --- a/src/main/java/net/moonleay/mods/gimble/client/keybindings/impl/editormode/EnableInsertModeShortcut.kt +++ b/src/main/java/net/moonleay/mods/gimble/client/keybindings/impl/editormode/EnableInsertModeShortcut.kt @@ -2,15 +2,15 @@ package net.moonleay.mods.gimble.client.keybindings.impl.editormode import net.minecraft.client.MinecraftClient 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.editor.modes.Mode class EnableInsertModeShortcut(key: KeyBinding): GimbleShortcut(key) { override fun onPressed(client: MinecraftClient) { - Editor.CURRENT_MODE = Mode.INSERT + ClientEditor.CURRENT_MODE = Mode.INSERT - Editor.checkForIncompatibleModeModifiers() + ClientEditor.checkForIncompatibleModeModifiers() } } diff --git a/src/main/java/net/moonleay/mods/gimble/client/keybindings/impl/editormode/EnableReplaceModeShortcut.kt b/src/main/java/net/moonleay/mods/gimble/client/keybindings/impl/editormode/EnableReplaceModeShortcut.kt index 9d53d5a..2f142ba 100644 --- a/src/main/java/net/moonleay/mods/gimble/client/keybindings/impl/editormode/EnableReplaceModeShortcut.kt +++ b/src/main/java/net/moonleay/mods/gimble/client/keybindings/impl/editormode/EnableReplaceModeShortcut.kt @@ -2,15 +2,15 @@ package net.moonleay.mods.gimble.client.keybindings.impl.editormode import net.minecraft.client.MinecraftClient 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.editor.modes.Mode class EnableReplaceModeShortcut(key: KeyBinding): GimbleShortcut(key) { override fun onPressed(client: MinecraftClient) { - Editor.CURRENT_MODE = Mode.REPLACE + ClientEditor.CURRENT_MODE = Mode.REPLACE - Editor.checkForIncompatibleModeModifiers() + ClientEditor.checkForIncompatibleModeModifiers() } } diff --git a/src/main/java/net/moonleay/mods/gimble/client/keybindings/impl/editormode/EnableVisualModeShortcut.kt b/src/main/java/net/moonleay/mods/gimble/client/keybindings/impl/editormode/EnableVisualModeShortcut.kt index a866f83..92975be 100644 --- a/src/main/java/net/moonleay/mods/gimble/client/keybindings/impl/editormode/EnableVisualModeShortcut.kt +++ b/src/main/java/net/moonleay/mods/gimble/client/keybindings/impl/editormode/EnableVisualModeShortcut.kt @@ -2,15 +2,15 @@ package net.moonleay.mods.gimble.client.keybindings.impl.editormode import net.minecraft.client.MinecraftClient 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.editor.modes.Mode class EnableVisualModeShortcut(key: KeyBinding): GimbleShortcut(key) { override fun onPressed(client: MinecraftClient) { - Editor.CURRENT_MODE = Mode.VISUAL + ClientEditor.CURRENT_MODE = Mode.VISUAL - Editor.checkForIncompatibleModeModifiers() + ClientEditor.checkForIncompatibleModeModifiers() } } diff --git a/src/main/java/net/moonleay/mods/gimble/client/keybindings/impl/editormodemodifier/ToggleBulldozerModifierShortcut.kt b/src/main/java/net/moonleay/mods/gimble/client/keybindings/impl/editormodemodifier/ToggleBulldozerModifierShortcut.kt index 3cccc6a..c8c75cf 100644 --- a/src/main/java/net/moonleay/mods/gimble/client/keybindings/impl/editormodemodifier/ToggleBulldozerModifierShortcut.kt +++ b/src/main/java/net/moonleay/mods/gimble/client/keybindings/impl/editormodemodifier/ToggleBulldozerModifierShortcut.kt @@ -2,14 +2,14 @@ package net.moonleay.mods.gimble.client.keybindings.impl.editormodemodifier import net.minecraft.client.MinecraftClient 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.editor.modes.ModeModifier class ToggleBulldozerModifierShortcut(key: KeyBinding): GimbleShortcut(key) { override fun onPressed(client: MinecraftClient) { - Editor.toggleModifier(ModeModifier.BULLDOZER) + ClientEditor.toggleModifier(ModeModifier.BULLDOZER) - Editor.onModifiersUpdated() + ClientEditor.onModifiersUpdated() } } diff --git a/src/main/java/net/moonleay/mods/gimble/client/keybindings/impl/editormodemodifier/ToggleForcePlaceModifierShortcut.kt b/src/main/java/net/moonleay/mods/gimble/client/keybindings/impl/editormodemodifier/ToggleForcePlaceModifierShortcut.kt index 9b62517..bfc5a1b 100644 --- a/src/main/java/net/moonleay/mods/gimble/client/keybindings/impl/editormodemodifier/ToggleForcePlaceModifierShortcut.kt +++ b/src/main/java/net/moonleay/mods/gimble/client/keybindings/impl/editormodemodifier/ToggleForcePlaceModifierShortcut.kt @@ -2,14 +2,14 @@ package net.moonleay.mods.gimble.client.keybindings.impl.editormodemodifier import net.minecraft.client.MinecraftClient 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.editor.modes.ModeModifier class ToggleForcePlaceModifierShortcut(key: KeyBinding): GimbleShortcut(key) { override fun onPressed(client: MinecraftClient) { - Editor.toggleModifier(ModeModifier.FORCE_PLACE) + ClientEditor.toggleModifier(ModeModifier.FORCE_PLACE) - Editor.onModifiersUpdated() + ClientEditor.onModifiersUpdated() } } diff --git a/src/main/java/net/moonleay/mods/gimble/client/keybindings/impl/editormodemodifier/ToggleNoClipModifierShortcut.kt b/src/main/java/net/moonleay/mods/gimble/client/keybindings/impl/editormodemodifier/ToggleNoClipModifierShortcut.kt index 134a37e..af84acf 100644 --- a/src/main/java/net/moonleay/mods/gimble/client/keybindings/impl/editormodemodifier/ToggleNoClipModifierShortcut.kt +++ b/src/main/java/net/moonleay/mods/gimble/client/keybindings/impl/editormodemodifier/ToggleNoClipModifierShortcut.kt @@ -2,14 +2,14 @@ package net.moonleay.mods.gimble.client.keybindings.impl.editormodemodifier import net.minecraft.client.MinecraftClient 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.editor.modes.ModeModifier class ToggleNoClipModifierShortcut(key: KeyBinding): GimbleShortcut(key) { override fun onPressed(client: MinecraftClient) { - Editor.toggleModifier(ModeModifier.NO_CLIP) + ClientEditor.toggleModifier(ModeModifier.NO_CLIP) - Editor.onModifiersUpdated() + ClientEditor.onModifiersUpdated() } } diff --git a/src/main/java/net/moonleay/mods/gimble/client/keybindings/impl/editormodemodifier/ToggleNoUpdatesModifierShortcut.kt b/src/main/java/net/moonleay/mods/gimble/client/keybindings/impl/editormodemodifier/ToggleNoUpdatesModifierShortcut.kt index f51366e..d3571b7 100644 --- a/src/main/java/net/moonleay/mods/gimble/client/keybindings/impl/editormodemodifier/ToggleNoUpdatesModifierShortcut.kt +++ b/src/main/java/net/moonleay/mods/gimble/client/keybindings/impl/editormodemodifier/ToggleNoUpdatesModifierShortcut.kt @@ -2,14 +2,14 @@ package net.moonleay.mods.gimble.client.keybindings.impl.editormodemodifier import net.minecraft.client.MinecraftClient 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.editor.modes.ModeModifier class ToggleNoUpdatesModifierShortcut(key: KeyBinding): GimbleShortcut(key) { override fun onPressed(client: MinecraftClient) { - Editor.toggleModifier(ModeModifier.NO_UPDATES) + ClientEditor.toggleModifier(ModeModifier.NO_UPDATES) - Editor.onModifiersUpdated() + ClientEditor.onModifiersUpdated() } } diff --git a/src/main/java/net/moonleay/mods/gimble/mixin/HudMixin.java b/src/main/java/net/moonleay/mods/gimble/mixin/HudMixin.java index 724d542..56cb635 100644 --- a/src/main/java/net/moonleay/mods/gimble/mixin/HudMixin.java +++ b/src/main/java/net/moonleay/mods/gimble/mixin/HudMixin.java @@ -5,7 +5,7 @@ import net.minecraft.client.font.TextRenderer; import net.minecraft.client.gui.hud.InGameHud; import net.minecraft.client.util.math.MatrixStack; 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.ModeModifier; import org.jetbrains.annotations.NotNull; @@ -26,7 +26,7 @@ public class HudMixin { @Inject(method = "renderStatusEffectOverlay", at = @At("HEAD")) private void render(MatrixStack matrices, CallbackInfo ci) { - Mode currentMode = Editor.INSTANCE.getCurrentMode(); + Mode currentMode = ClientEditor.INSTANCE.getCurrentMode(); StringBuilder displayText = getStringBuilder(currentMode); MinecraftClient mc = MinecraftClient.getInstance(); @@ -44,7 +44,7 @@ public class HudMixin { @Unique private static @NotNull StringBuilder getStringBuilder(Mode currentMode) { - List currentModifier = Editor.INSTANCE.getCurrentModifier(); + List currentModifier = ClientEditor.INSTANCE.getCurrentModifier(); StringBuilder displayText = new StringBuilder(currentMode.getDisplayName()); if (!currentModifier.isEmpty()) { displayText.append(" ["); diff --git a/src/main/java/net/moonleay/mods/gimble/mixin/KeyMixin.java b/src/main/java/net/moonleay/mods/gimble/mixin/KeyMixin.java index 634808f..8253ff8 100644 --- a/src/main/java/net/moonleay/mods/gimble/mixin/KeyMixin.java +++ b/src/main/java/net/moonleay/mods/gimble/mixin/KeyMixin.java @@ -1,7 +1,6 @@ package net.moonleay.mods.gimble.mixin; import net.minecraft.client.Keyboard; -import org.lwjgl.glfw.GLFW; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; diff --git a/src/main/java/net/moonleay/mods/gimble/mixin/NoClipMixin.java b/src/main/java/net/moonleay/mods/gimble/mixin/NoClipMixin.java new file mode 100644 index 0000000..1d65009 --- /dev/null +++ b/src/main/java/net/moonleay/mods/gimble/mixin/NoClipMixin.java @@ -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; + } +} diff --git a/src/main/java/net/moonleay/mods/gimble/mixin/NormalModeMixin.java b/src/main/java/net/moonleay/mods/gimble/mixin/NormalModeMixin.java index 2d1c19e..1f4c572 100644 --- a/src/main/java/net/moonleay/mods/gimble/mixin/NormalModeMixin.java +++ b/src/main/java/net/moonleay/mods/gimble/mixin/NormalModeMixin.java @@ -1,9 +1,8 @@ package net.moonleay.mods.gimble.mixin; import net.minecraft.client.MinecraftClient; -import net.minecraft.client.network.ClientPlayerEntity; 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 org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Mixin; @@ -21,17 +20,17 @@ public class NormalModeMixin { @Inject(method = "openPauseMenu", at = @At("HEAD"), cancellable = true) 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 - Editor.INSTANCE.setCURRENT_MODE(Mode.NORMAL); - Editor.INSTANCE.checkForIncompatibleModeModifiers(); + ClientEditor.INSTANCE.setCURRENT_MODE(Mode.NORMAL); + ClientEditor.INSTANCE.checkForIncompatibleModeModifiers(); ci.cancel(); } } @Inject(method = "handleInputEvents", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;isUsingItem()Z"), cancellable = true) - private void blockWorldManipulation(CallbackInfo ci) { - if (Editor.INSTANCE.getCURRENT_MODE() == Mode.NORMAL || Editor.INSTANCE.getCURRENT_MODE() == Mode.VISUAL) { + private void blockWorldManipulation(CallbackInfo ci) { // This could be replaced by net.minecraft.world.GameMode#isBlockBreakingRestricted + if (ClientEditor.INSTANCE.getCURRENT_MODE() == Mode.NORMAL || ClientEditor.INSTANCE.getCURRENT_MODE() == Mode.VISUAL) { while(this.options.attackKey.wasPressed()) { } diff --git a/src/main/java/net/moonleay/mods/gimble/mixin/ReplaceModeMixin.java b/src/main/java/net/moonleay/mods/gimble/mixin/ReplaceModeMixin.java index 83e0140..846f8e2 100644 --- a/src/main/java/net/moonleay/mods/gimble/mixin/ReplaceModeMixin.java +++ b/src/main/java/net/moonleay/mods/gimble/mixin/ReplaceModeMixin.java @@ -11,9 +11,8 @@ import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.HitResult; import net.minecraft.util.math.BlockPos; 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.util.ChatUtil; import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -39,7 +38,7 @@ public abstract class ReplaceModeMixin { @Inject(method = "doItemUse", at = @At("HEAD")) private void replaceBlock(CallbackInfo ci) { // 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 MinecraftClient client = MinecraftClient.getInstance(); assert this.interactionManager != null; diff --git a/src/main/resources/gimble.mixins.json b/src/main/resources/gimble.mixins.json index 2a209c8..48557e1 100644 --- a/src/main/resources/gimble.mixins.json +++ b/src/main/resources/gimble.mixins.json @@ -1,16 +1,17 @@ { - "required": true, - "minVersion": "0.8", - "package": "net.moonleay.mods.gimble.mixin", - "compatibilityLevel": "JAVA_17", - "mixins": [ - ], - "client": [ - "HudMixin", - "NormalModeMixin", - "ReplaceModeMixin" - ], - "injectors": { - "defaultRequire": 1 - } + "required": true, + "minVersion": "0.8", + "package": "net.moonleay.mods.gimble.mixin", + "compatibilityLevel": "JAVA_17", + "mixins": [ + "NoClipMixin" + ], + "client": [ + "HudMixin", + "NormalModeMixin", + "ReplaceModeMixin" + ], + "injectors": { + "defaultRequire": 1 + } }