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

This commit is contained in:
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

View file

@ -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

View file

@ -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<ModeModifier>()
private val TEMP_DISABLED_MODIFIERS = mutableListOf<ModeModifier>()
@ -75,4 +75,8 @@ object Editor {
fun getCurrentModifier(): List<ModeModifier> {
return CURRENT_MODE_MODIFIER
}
fun containsModifier(mod: ModeModifier): Boolean {
return CURRENT_MODE_MODIFIER.contains(mod)
}
}

View file

@ -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()
}
}

View file

@ -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()
}
}

View file

@ -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()
}
}

View file

@ -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()
}
}

View file

@ -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()
}
}

View file

@ -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()
}
}

View file

@ -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()
}
}

View file

@ -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<ModeModifier> currentModifier = Editor.INSTANCE.getCurrentModifier();
List<ModeModifier> currentModifier = ClientEditor.INSTANCE.getCurrentModifier();
StringBuilder displayText = new StringBuilder(currentMode.getDisplayName());
if (!currentModifier.isEmpty()) {
displayText.append(" [");

View file

@ -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;

View file

@ -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;
}
}

View file

@ -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()) {
}

View file

@ -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;

View file

@ -4,6 +4,7 @@
"package": "net.moonleay.mods.gimble.mixin",
"compatibilityLevel": "JAVA_17",
"mixins": [
"NoClipMixin"
],
"client": [
"HudMixin",