Skip to content

Add some improvements to cwaypoint #723

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: fabric
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/main/java/net/earthcomputer/clientcommands/Configs.java
Original file line number Diff line number Diff line change
@@ -182,4 +182,7 @@ public enum PacketDumpMethod {
public static void setMinimumReplyDelaySeconds(float minimumReplyDelaySeconds) {
Configs.minimumReplyDelaySeconds = Math.clamp(minimumReplyDelaySeconds, 0.0f, ReplyCommand.MAXIMUM_REPLY_DELAY_SECONDS);
}

@Config(comment = "Distance after which to stop rendering waypoint labels; put a negative value to disable")
public static int waypointLabelRenderLimit = -1;
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package net.earthcomputer.clientcommands.datafix;

import com.mojang.datafixers.DataFix;
import com.mojang.datafixers.TypeRewriteRule;
import com.mojang.datafixers.schemas.Schema;

public class WaypointAddVisibilityAndColorIfNotPresentFix extends DataFix {

private static final String VISIBILITY_KEY = "Visible";
private static final String COLOR_KEY = "Color";

private final boolean visible;
private final int color;
private final String name;

public WaypointAddVisibilityAndColorIfNotPresentFix(Schema outputSchema, boolean visible, int color) {
super(outputSchema, true);
this.visible = visible;
this.color = color;
this.name = "WaypointAddVisibilityIfNotPresentFix_" + VISIBILITY_KEY + "=" + this.visible + "_" + COLOR_KEY + "=" + this.color + " for " + outputSchema.getVersionKey();
}

@Override
protected TypeRewriteRule makeRule() {
// TODO
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package net.earthcomputer.clientcommands.mixin.datafix;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.llamalad7.mixinextras.sugar.Local;
import com.mojang.datafixers.DataFixerBuilder;
import com.mojang.datafixers.schemas.Schema;
import net.minecraft.util.datafix.DataFixers;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Slice;

@Mixin(DataFixers.class)
public class DataFixersMixin {
@ModifyExpressionValue(
method = "addFixers",
slice = @Slice(from = @At(value = "CONSTANT", args = "intValue=4187")),
at = @At(value = "INVOKE", target = "Lcom/mojang/datafixers/DataFixerBuilder;addSchema(ILjava/util/function/BiFunction;)Lcom/mojang/datafixers/schemas/Schema;", ordinal = 0, remap = false))
private static Schema addFixers(Schema original, @Local(argsOnly = true) DataFixerBuilder builder) {
// TODO
// builder.addFixer(new WaypointAddVisibilityIfNotPresentFix(original, true, ChatFormatting.WHITE.getColor()));
return original;
}
}
13 changes: 10 additions & 3 deletions src/main/resources/assets/clientcommands/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -286,14 +286,21 @@
"commands.cvar.remove.success": "Successfully removed variable \"%s\"",
"commands.cvar.saveFile.failed": "Could not save variables file",

"commands.cwaypoint.add.success": "Waypoint \"%s\" at %s in %s successfully added",
"commands.cwaypoint.add.success": "Waypoint \"%s\" at %s in %s with color %s successfully added",
"commands.cwaypoint.alreadyExists": "A waypoint with the name \"%s\" already exists",
"commands.cwaypoint.edit.success": "Waypoint \"%s\" has successfully been changed to %s in %s",
"commands.cwaypoint.list": "- \"%s\" at %s in %s",
"commands.cwaypoint.alreadyHidden": "This waypoint is already hidden",
"commands.cwaypoint.alreadyVisible": "This waypoint is already visible",
"commands.cwaypoint.edit.success": "Waypoint \"%s\" has successfully been changed to %s in %s with color %s",
"commands.cwaypoint.hidden": "hidden",
"commands.cwaypoint.hide.success": "Now hiding %s",
"commands.cwaypoint.invalidColor": "The color %s is invalid",
"commands.cwaypoint.list": "- \"%s\" at %s in %s (%s)",
"commands.cwaypoint.list.empty": "No available waypoints",
"commands.cwaypoint.notFound": "No waypoint with the name \"%s\" could be found",
"commands.cwaypoint.remove.success": "Waypoint \"%s\" successfully removed",
"commands.cwaypoint.saveFailed": "Could not save waypoints file",
"commands.cwaypoint.show.success": "Now showing %s",
"commands.cwaypoint.shown": "shown",

"commands.cwe.playerNotFound": "Player not found",

1 change: 1 addition & 0 deletions src/main/resources/mixins.clientcommands.json
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@
"commands.render.EntityRendererDispatcherMixin",
"commands.time.ClientLevelDataMixin",
"commands.weather.LevelMixin",
"datafix.DataFixersMixin",
"debug.EntityMixin",
"debug.ServerLevelMixin",
"events.MinecraftMixin",
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.earthcomputer.clientcommands.command.WaypointCommand;
import net.minecraft.ChatFormatting;
import net.minecraft.SharedConstants;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
@@ -30,7 +31,7 @@ private static CompoundTag parseSnbt(String snbt) {
}

@Test
public void testWaypointLoading() {
public void testWaypointLoadingWithoutVisibleAndColorKey() {
CompoundTag waypointTag = parseSnbt("""
{
DataVersion: 4189,
@@ -54,5 +55,38 @@ public void testWaypointLoading() {
var waypoint = worldWaypoints.get("testWaypoint");
assertEquals(new BlockPos(1, 2, 3), waypoint.location());
assertEquals(Level.OVERWORLD, waypoint.dimension());
assertTrue(waypoint.visible());
assertEquals(ChatFormatting.WHITE.getColor(), waypoint.color());
}

@Test
public void testWaypointLoading() {
CompoundTag waypointTag = parseSnbt("""
{
DataVersion: 4189,
Waypoints: {
foo: {
testWaypoint: {
pos: [I; 1, 2, 3],
Dimension: "minecraft:overworld",
Visible: true,
Color: 16733525
}
}
}
}
""");

var waypoints = WaypointCommand.deserializeWaypoints(waypointTag);
assertEquals(1, waypoints.size());
assertTrue(waypoints.containsKey("foo"));
var worldWaypoints = waypoints.get("foo");
assertEquals(1, worldWaypoints.size());
assertTrue(worldWaypoints.containsKey("testWaypoint"));
var waypoint = worldWaypoints.get("testWaypoint");
assertEquals(new BlockPos(1, 2, 3), waypoint.location());
assertEquals(Level.OVERWORLD, waypoint.dimension());
assertTrue(waypoint.visible());
assertEquals(ChatFormatting.RED.getColor(), waypoint.color());
}
}
Loading