Skip to content

Commit

Permalink
switch to translations apart on config (& debug cuz rewrite it soon)
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeRNG committed Apr 8, 2024
1 parent db2936f commit 1e4415e
Show file tree
Hide file tree
Showing 13 changed files with 191 additions and 106 deletions.
133 changes: 62 additions & 71 deletions src/main/java/dev/dfonline/codeclient/Commands.java

Large diffs are not rendered by default.

20 changes: 17 additions & 3 deletions src/main/java/dev/dfonline/codeclient/Utility.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ public static void makeHolding(ItemStack item) {
inv.setStack(0, item);
}

public static void debug(Object object) {
debug(Objects.toString(object));
}
public static void debug(String message) {
CodeClient.LOGGER.info("%%% DEBUG: " + message);
}

/**
* Gets the base64 template data from an item. Null if there is none.
*/
Expand Down Expand Up @@ -241,17 +248,24 @@ public static String compileTemplate(String data) throws IOException {
return new String(Base64.getEncoder().encode(obj.toByteArray()));
}

/**
* @deprecated This uses literals, use translations when you can.
*/
public static void sendMessage(String message, ChatType type) {
sendMessage(Text.literal(message), type);
}

/**
* @deprecated This uses literals, use translations when you can.
*/
public static void sendMessage(String message) {
sendMessage(Text.literal(message), ChatType.INFO);
}
public static void sendMessage(MutableText message) {
public static void sendMessage(Text message) {
sendMessage(message, ChatType.INFO);
}

public static void sendMessage(MutableText message, @Nullable ChatType type) {
public static void sendMessage(Text message, @Nullable ChatType type) {
ClientPlayerEntity player = CodeClient.MC.player;
if (player == null) return;
if (type == null) {
Expand All @@ -260,7 +274,7 @@ public static void sendMessage(MutableText message, @Nullable ChatType type) {
player.sendMessage(Text.empty()
.append(type.getText())
.append(Text.literal(" "))
.append(message.formatted(Formatting.RESET, type.getTrailing())), false);
.append(Text.empty().formatted(Formatting.RESET, type.getTrailing()).append(message)), false);
if (type == ChatType.FAIL) {
player.playSound(SoundEvent.of(new Identifier("minecraft:block.note_block.didgeridoo")), SoundCategory.PLAYERS, 2, 0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import dev.dfonline.codeclient.action.Action;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.s2c.play.GameMessageS2CPacket;
import net.minecraft.text.Style;
import net.minecraft.text.Text;
import net.minecraft.text.TextColor;
import net.minecraft.util.Formatting;
Expand Down Expand Up @@ -44,9 +45,9 @@ public boolean onReceivePacket(Packet<?> packet) {
if(packet instanceof GameMessageS2CPacket message) {
if(message.content().getString().startsWith("Error:")) {
isDone = true;
OverlayManager.setOverlayText(Text.literal("Couldn't start. Check you are on beta.").formatted(Formatting.RED));
OverlayManager.addOverlayText(Text.literal("Or, beta isn't working right now.").formatted(Formatting.RED));
OverlayManager.addOverlayText(Text.literal("Type").append(Text.literal(" /abort ").formatted(Formatting.GREEN)).append(Text.literal("to hide this.")).formatted(Formatting.LIGHT_PURPLE));
OverlayManager.setOverlayText(Text.translatable("codeclient.action.get_action_dump.error.could_not_start").formatted(Formatting.RED));
OverlayManager.addOverlayText(Text.translatable("codeclient.action.get_action_dump.error.beta_broke").formatted(Formatting.RED));
OverlayManager.addOverlayText(Text.translatable("codeclient.action.get_action_dump.abort",Text.literal(" /abort ").formatted(Formatting.GREEN)).formatted(Formatting.LIGHT_PURPLE));

return true;
}
Expand All @@ -68,23 +69,23 @@ public boolean onReceivePacket(Packet<?> packet) {
lines += 1;
length += content.length();
OverlayManager.setOverlayText();
OverlayManager.addOverlayText(Text.literal("GetActionDump:").formatted(Formatting.GOLD));
OverlayManager.addOverlayText(Text.literal("Size: ").formatted(Formatting.LIGHT_PURPLE).append(Text.literal(String.valueOf(length)).formatted(Formatting.GREEN)));
OverlayManager.addOverlayText(Text.literal("Lines: ").formatted(Formatting.LIGHT_PURPLE).append(Text.literal(String.valueOf(lines)).formatted(Formatting.GREEN)));
OverlayManager.addOverlayText(Text.literal("Time: ").formatted(Formatting.LIGHT_PURPLE).append(Text.literal(String.valueOf((float) (new Date().getTime() - startTime.getTime()) / 1000)).formatted(Formatting.GREEN)));
OverlayManager.addOverlayText(Text.translatable("codeclient.action.get_action_dump.scanning.title").formatted(Formatting.GOLD));
OverlayManager.addOverlayText(Text.translatable("codeclient.action.get_action_dump.scanning.size",Text.literal(String.valueOf(length)).formatted(Formatting.GREEN)).formatted(Formatting.LIGHT_PURPLE));
OverlayManager.addOverlayText(Text.translatable("codeclient.action.get_action_dump.scanning.lines",Text.literal(String.valueOf(lines)).formatted(Formatting.GREEN)).formatted(Formatting.LIGHT_PURPLE));
OverlayManager.addOverlayText(Text.translatable("codeclient.action.get_action_dump.scanning.time",Text.literal(String.valueOf((float) (new Date().getTime() - startTime.getTime()) / 1000)).formatted(Formatting.GREEN)).formatted(Formatting.LIGHT_PURPLE));
if(Objects.equals(content, "}")) {
isDone = true;
OverlayManager.addOverlayText(Text.literal(""));
OverlayManager.addOverlayText(Text.literal("Complete!").formatted(Formatting.LIGHT_PURPLE));
OverlayManager.addOverlayText(Text.literal("Type").append(Text.literal(" /abort ").formatted(Formatting.GREEN)).append(Text.literal("to hide this.")).formatted(Formatting.LIGHT_PURPLE));
OverlayManager.addOverlayText(Text.translatable("codeclient.action.get_action_dump.scanning.complete").formatted(Formatting.LIGHT_PURPLE));
OverlayManager.addOverlayText(Text.translatable("codeclient.action.get_action_dump.abort",Text.literal(" /abort ").formatted(Formatting.GREEN)).formatted(Formatting.LIGHT_PURPLE));
OverlayManager.addOverlayText(Text.literal(""));
try {
Path path = FileManager.writeFile("actiondump.json",capturedData.toString());
OverlayManager.addOverlayText(Text.literal("There will now be a file in your Minecraft directory.").formatted(Formatting.LIGHT_PURPLE));
OverlayManager.addOverlayText(Text.translatable("codeclient.action.get_action_dump.scanning.complete.file").formatted(Formatting.LIGHT_PURPLE));
OverlayManager.addOverlayText(Text.literal(path.toString()).formatted(Formatting.GREEN));
} catch (IOException e) {
OverlayManager.addOverlayText(Text.literal("An error occurred whilst writing to a file,").formatted(Formatting.RED));
OverlayManager.addOverlayText(Text.literal("so instead it has been written to your console.").formatted(Formatting.RED));
OverlayManager.addOverlayText(Text.translatable("codeclient.files.error.cant_save").formatted(Formatting.RED));
OverlayManager.addOverlayText(Text.translatable("codeclient.action.get_action_dump.scanning.complete.save_error").formatted(Formatting.RED));
}
callback();
}
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/dev/dfonline/codeclient/dev/BuildPhaser.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import net.minecraft.network.packet.s2c.play.PlaySoundFromEntityS2CPacket;
import net.minecraft.network.packet.s2c.play.PlayerPositionLookS2CPacket;
import net.minecraft.text.ClickEvent;
import net.minecraft.text.HoverEvent;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.minecraft.util.Hand;
Expand All @@ -44,7 +45,7 @@ public static void tick() {

if(CodeClient.location instanceof Dev plot) {
if(plot.getX() == null) {
if(CodeClient.clipBind.wasPressed()) Utility.sendMessage(CodeClient.MOD_NAME + " doesn't know the plot origin location.");
if(CodeClient.clipBind.wasPressed()) Utility.sendMessage(Text.translatable("codeclient.phaser.plot_origin"));
}
// CodeClient.LOGGER.info("dev and X");
if(!clipping && CodeClient.clipBind.isPressed() && plot.getX() != null) startClipping();
Expand All @@ -68,7 +69,13 @@ else if(clipping || waitForTP) {
if(CodeClient.location instanceof Build) {
if(CodeClient.clipBind.isPressed() && !dontSpamBuildWarn) {
dontSpamBuildWarn = true;
Utility.sendMessage(Text.literal("Cannot use phaser in build mode, since ").append(Text.literal("it uses locations items").setStyle(Text.empty().getStyle().withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL,"https://github.com/DFOnline/CodeClient/wiki/phaser#internal"))).formatted(Formatting.AQUA,Formatting.UNDERLINE)).append(" to teleport."), ChatType.FAIL);
Utility.sendMessage(Text.translatable("codeclient.phaser.dev_mode1",
Text.translatable("codeclient.phaser.dev_mode2")
.setStyle(Text.empty().getStyle()
.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL,"https://github.com/DFOnline/CodeClient/wiki/phaser#internal"))
.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.translatable("chat.link.open")))
).formatted(Formatting.AQUA,Formatting.UNDERLINE)),
ChatType.FAIL);
}
if(dontSpamBuildWarn && !CodeClient.clipBind.isPressed()) dontSpamBuildWarn = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ public static boolean onBreakBlock(BlockPos pos) {
BlockPos breakPos = isBlockBreakable(pos);
if(breakPos != null) {
if(Config.getConfig().ReportBrokenBlock && validBlocks.contains(CodeClient.MC.world.getBlockState(breakPos).getBlock()) && CodeClient.MC.world.getBlockEntity(breakPos.west()) instanceof SignBlockEntity sign) {
if(!sign.getFrontText().getMessage(1,false).equals(Text.empty())) Utility.sendMessage(Text.empty().formatted(Formatting.AQUA).append(Text.literal("You just broke ")).append(Text.empty().formatted(Formatting.WHITE).append(sign.getFrontText().getMessage(1,false))).append(Text.literal(".")), ChatType.INFO);
if(!sign.getFrontText().getMessage(1,false).equals(Text.empty()))
Utility.sendMessage(Text.translatable("codeclient.interaction.broke",Text.empty().formatted(Formatting.WHITE).append(sign.getFrontText().getMessage(1,false))).formatted(Formatting.AQUA), ChatType.INFO);
}
BlockBreakDeltaCalculator.breakBlock(pos);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,10 @@ protected void init() {
}
catch (IOException | JsonParseException e) {
CodeClient.LOGGER.error(e.getMessage());
Utility.sendMessage(Text.literal("Could not parse the ActionDump. Go to ").append(Text.literal("https://github.com/DFOnline/CodeClient/wiki/actiondump").formatted(Formatting.AQUA)).append(Text.literal(" to find out how to fix this."))
.setStyle(Style.EMPTY.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://github.com/DFOnline/CodeClient/wiki/actiondump"))), ChatType.FAIL);
Utility.sendMessage(
Text.translatable("codeclient.parse_db",Text.literal("https://github.com/DFOnline/CodeClient/wiki/actiondump").formatted(Formatting.AQUA,Formatting.UNDERLINE))
.setStyle(Style.EMPTY.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://github.com/DFOnline/CodeClient/wiki/actiondump"))),
ChatType.FAIL);
}

TextRenderer textRenderer = this.textRenderer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ public static List<Text> getOverlayText() {
if (CodeClient.location instanceof Dev && currentBlock != null && items != null) {
ArrayList<Text> texts = new ArrayList<>();
if(items.isEmpty()) {
texts.add(Text.literal("Empty").formatted(Formatting.GOLD));
texts.add(Text.translatable("codeclient.peeker.empty").formatted(Formatting.GOLD));
}
else {
texts.add(Text.literal("Contents").formatted(Formatting.GOLD));
texts.add(Text.translatable("codeclient.peeker.contents").formatted(Formatting.GOLD));
for (NbtElement itemData : items) {
if (itemData instanceof NbtCompound compound) {
ItemStack item = Registries.ITEM.get(Identifier.tryParse(compound.getString("id"))).getDefaultStack();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public abstract class GenericSwitcher extends Screen {
private Integer lastMouseX;
private Integer lastMouseY;
protected Integer selected;
protected Text footer = Text.literal("No Footer");
protected Text footer = Text.translatable("codeclient.switcher.footer");

/**
* Key to hold down, generally F3.
Expand Down Expand Up @@ -85,7 +85,7 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) {
}

Option selected = getSelected();
Text selectedText = selected != null ? selected.text : Text.literal("Select");
Text selectedText = selected != null ? selected.text : Text.translatable("codeclient.switcher.select");

context.drawCenteredTextWithShadow(this.textRenderer, selectedText, this.width / 2, this.height / 2 - 51, 0xFFFFFF);
context.drawCenteredTextWithShadow(this.textRenderer, footer, this.width / 2, this.height / 2 + 5, 0xFFFFFF);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import dev.dfonline.codeclient.CodeClient;
import dev.dfonline.codeclient.Utility;
import dev.dfonline.codeclient.hypercube.item.Scope;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.nbt.NbtCompound;
Expand All @@ -19,20 +18,19 @@
import org.lwjgl.glfw.GLFW;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class ScopeSwitcher extends GenericSwitcher {
private String option;

public ScopeSwitcher(String option) {
super(Text.literal("Scope"), -1, GLFW.GLFW_KEY_SPACE);
super(Text.translatable("codeclient.switcher.scope"), -1, GLFW.GLFW_KEY_SPACE);
this.option = option;
}

@Override
protected void init() {
footer = Text.literal("[ Click ]").formatted(Formatting.AQUA).append(Text.literal(" Select").formatted(Formatting.WHITE));
footer = Text.translatable("codeclient.switcher.scope.select",Text.translatable("codeclient.switcher.footer.brackets","Click").formatted(Formatting.AQUA)).formatted(Formatting.WHITE);

selected = switch (option) {
case "saved" -> 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ public class SpeedSwitcher extends GenericSwitcher {
private static int lastSpeed = 3;

public SpeedSwitcher() {
super(Text.literal("Speed Switcher"), GLFW.GLFW_KEY_F3, GLFW.GLFW_KEY_F5);
super(Text.translatable("codeclient.switcher.speed"), GLFW.GLFW_KEY_F3, GLFW.GLFW_KEY_F5);
}

@Override
protected void init() {
footer = Text.literal("[ F5 ]").formatted(Formatting.AQUA).append(Text.literal(" Next").formatted(Formatting.WHITE));
footer = Text.translatable("codeclient.switcher.footer.next",Text.translatable("codeclient.switcher.footer.brackets","F5").formatted(Formatting.AQUA));
selected = 0;
// 0.05 is 100% on df. 1000% is 0.5.
if(CodeClient.MC.player.getAbilities().getFlySpeed() == 0.05f) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@

public class StateSwitcher extends GenericSwitcher {
public StateSwitcher() {
super(Text.literal("Mode Switcher"), GLFW.GLFW_KEY_F3, GLFW.GLFW_KEY_F4);
super(Text.translatable("codeclient.switcher.state"), GLFW.GLFW_KEY_F3, GLFW.GLFW_KEY_F4);
}

@Override
protected void init() {
footer = Text.literal("[ F4 ]").formatted(Formatting.AQUA).append(Text.literal(" Next").formatted(Formatting.WHITE));
footer = Text.translatable("codeclient.switcher.footer.next",Text.translatable("codeclient.switcher.footer.brackets","F4").formatted(Formatting.AQUA));
selected = 0;
if(CodeClient.lastLocation instanceof Plot) {
if(CodeClient.lastLocation instanceof Play) selected = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ public void onOpen(WebSocket conn, ClientHandshake handshake) {
CodeClient.LOGGER.info("connection");
SocketHandler.setConnection(conn);
CodeClient.LOGGER.info(conn.getRemoteSocketAddress().toString() + " has just connected to the CodeClient API.");
Utility.sendMessage("An application has connected to CodeClient", ChatType.INFO);
Utility.sendMessage("Run §e/auth§b to allow it to§l freely modify your plot", ChatType.INFO);
Utility.sendMessage(Text.translatable("codeclient.api.connect"), ChatType.INFO);
Utility.sendMessage(Text.translatable("codeclient.api.run_auth"), ChatType.INFO);
Utility.sendMessage(Text.translatable("codeclient.api.warning"), ChatType.INFO);
}

@Override
Expand Down
Loading

0 comments on commit 1e4415e

Please sign in to comment.