Skip to content

Commit

Permalink
auto edit values in chat
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeRNG committed Apr 28, 2024
1 parent 36fe69f commit 307d90d
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 8 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ yarn_mappings=1.20.4+build.3
loader_version=0.15.3

# Mod Properties
mod_version=1.6.2
mod_version=1.6.3
maven_group=dev.dfonline
archives_base_name=CodeClient

Expand Down
11 changes: 11 additions & 0 deletions src/main/java/dev/dfonline/codeclient/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public class Config {
public CustomChestMenuType CustomCodeChest = CustomChestMenuType.OFF;
public boolean PickAction = true;
public boolean DevForBuild = false;
public boolean ChatEditsVars = true;

public Config() {
}
Expand Down Expand Up @@ -205,6 +206,16 @@ public YetAnotherConfigLib getLibConfig() {
)
.controller(TickBoxControllerBuilder::create)
.build())
.option(Option.createBuilder(boolean.class)
.name(Text.translatable("codeclient.config.chat_edits_vars"))
.description(OptionDescription.of(Text.translatable("codeclient.config.chat_edits_vars.description")))
.binding(
true,
() -> ChatEditsVars,
opt -> ChatEditsVars = opt
)
.controller(TickBoxControllerBuilder::create)
.build())
.option(Option.createBuilder(boolean.class)
.name(Text.literal("CCDBUG"))
.description(OptionDescription.createBuilder()
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/dev/dfonline/codeclient/hypercube/item/Scope.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@
import net.minecraft.util.Formatting;

public enum Scope {
unsaved(TextColor.fromFormatting(Formatting.GRAY), "GAME", "G"),
local(TextColor.fromFormatting(Formatting.GREEN), "LOCAL", "L"),
saved(TextColor.fromFormatting(Formatting.YELLOW), "SAVE", "S"),
line(TextColor.fromRgb(0x55aaff), "LINE", "L");
unsaved(TextColor.fromFormatting(Formatting.GRAY), "GAME", "G", "g"),
local(TextColor.fromFormatting(Formatting.GREEN), "LOCAL", "L", "l"),
saved(TextColor.fromFormatting(Formatting.YELLOW), "SAVE", "S", "s"),
line(TextColor.fromRgb(0x55aaff), "LINE", "L", "i");

public final TextColor color;
public final String longName;
public final String shortName;
public final String tag;

Scope(TextColor color, String longName, String shortName) {
Scope(TextColor color, String longName, String shortName, String tag) {
this.color = color;
this.longName = longName;
this.shortName = shortName;
this.tag = tag;
}

public String getShortName() {
Expand Down
43 changes: 43 additions & 0 deletions src/main/java/dev/dfonline/codeclient/mixin/MChatScreen.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package dev.dfonline.codeclient.mixin;

import dev.dfonline.codeclient.CodeClient;
import dev.dfonline.codeclient.config.Config;
import dev.dfonline.codeclient.hypercube.item.*;
import dev.dfonline.codeclient.location.Dev;
import net.minecraft.client.gui.screen.ChatScreen;
import net.minecraft.client.gui.widget.TextFieldWidget;
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;

import java.text.DecimalFormat;

@Mixin(ChatScreen.class)
public abstract class MChatScreen {

@Shadow protected TextFieldWidget chatField;

@Inject(method = "init", at = @At("TAIL"))
private void onOpen(CallbackInfo ci) {
if (CodeClient.MC.player == null || !(CodeClient.location instanceof Dev) || !Config.getConfig().ChatEditsVars) return;
var item = VarItems.parse(CodeClient.MC.player.getMainHandStack());
DecimalFormat format = new DecimalFormat("0.#");
if(item instanceof Variable var) {
this.chatField.setText(var.getName().replaceAll("§","&") + " -" + var.getScope().tag);
}
else if(item instanceof NamedItem named) {
this.chatField.setText(named.getName().replaceAll("§","&"));
}
else if(item instanceof Vector vec) {
this.chatField.setText("%s %s %s".formatted(format.format(vec.getX()), format.format(vec.getY()), format.format(vec.getZ())));
}
else if(item instanceof Sound sound) {
this.chatField.setText("%s %s".formatted(format.format(sound.getPitch()), format.format(sound.getVolume())));
}
else return;
this.chatField.setCursorToStart(false);
this.chatField.setCursorToEnd(true);
}
}
5 changes: 3 additions & 2 deletions src/main/resources/CodeClient.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"package": "dev.dfonline.codeclient.mixin",
"compatibilityLevel": "JAVA_17",
"client": [
"MChatScreen",
"MHandledScreens",
"MKeyboard",
"entity.MEntity",
Expand All @@ -23,11 +24,11 @@
"world.MWorldRenderer",
"world.block.MAbstractBlockState",
"world.block.MBarrierBlock",
"world.block.MBlock",
"world.block.MBlockItem",
"world.block.MLightBlock",
"world.block.MSignBlockEntity",
"world.block.MStructureVoidBlock",
"world.block.MBlock"
"world.block.MStructureVoidBlock"
],
"injectors": {
"defaultRequire": 1
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/assets/codeclient/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

"codeclient.config.dev_for_build": "Dev mode for build",
"codeclient.config.dev_for_build.description": "Uses dev mode instead of build mode, clearing your inventory and teleporting you.",
"codeclient.config.chat_edits_vars": "Auto edit values",
"codeclient.config.chat_edits_vars.description": "Opening chat whilst holding a value will automatically put the contents in chat.",

"codeclient.parse_db": "Could not parse ActionDump. Go to %s to find out how to fix this.",

Expand Down

0 comments on commit 307d90d

Please sign in to comment.