Skip to content

Commit

Permalink
Merge branch '1.19.3' into latest
Browse files Browse the repository at this point in the history
  • Loading branch information
Boxadactle committed Jul 22, 2024
2 parents 7de769a + 6892079 commit 09de895
Show file tree
Hide file tree
Showing 30 changed files with 450 additions and 118 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ name: Publish
on:
push:
branches: [ "latest" ]
pull_request:
branches: [ "latest" ]

permissions:
contents: read
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## Changes
- Rewrote the hud position screen
- Backport to 1.19.3
- Update lang
- Fixed hotbar renderer rendering over messages

## New Features
- Added TOP start corner
- Added LEFT start corner
- Added RIGHT start corner
- Added BOTTOM start corner
9 changes: 7 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,19 @@ githubRelease {
targetCommitish = "latest"
releaseName = "Coordinates Display $project.version"
generateReleaseNotes = true
body = "Coordinates Display $project.version for Minecraft $project.minecraft_version"
body = """"Coordinates Display $project.version for Minecraft $project.minecraft_version"
${new File(rootProject.rootDir, project.changelog_file).text}
"""
authorization = "Token ${System.getenv("GITHUB_TOKEN")}"

var files = [];
var files = []
for (String platform : project.enabled_platforms.split(',')) {
files += fileTree("$platform/build/libs") {
include "*$project.version*"
}
}
releaseAssets = files

// dryRun = true
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class CoordinatesDisplay {

public static final String MOD_ID = "coordinatesdisplay";

public static final String VERSION = "6.1.0";
public static final String VERSION = "7.1.0";

public static final String VERSION_STRING = MOD_NAME + " v" + VERSION;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,9 @@
import dev.boxadactle.boxlib.util.ClientUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.core.Registry;
import net.minecraft.core.Vec3i;
import net.minecraft.data.BuiltinRegistries;
import net.minecraft.network.chat.*;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.world.level.biome.Biome;
Expand All @@ -27,7 +23,6 @@
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.Objects;
import java.util.Optional;

@SuppressWarnings("unchecked")
public class ModUtil {
Expand Down Expand Up @@ -152,25 +147,15 @@ public static String getDirectionFromYaw(double degrees) {
return direction;
}

public static Component getBiomeComponent(Holder<Biome> biome, boolean colored, int defaultColor) {
if (biome == null) {
public static Component getBiomeComponent(ResourceLocation key, Biome biome, boolean colored, int defaultColor) {
if (biome == null && WorldUtils.getWorld() != null) {
return GuiUtils.colorize(Component.translatable("hud.coordinatesdisplay.biome.unknown"), defaultColor);
}

Registry<Biome> registry = WorldUtils.getWorld() != null ? WorldUtils.getWorld().registryAccess().registryOrThrow(Registry.BIOME_REGISTRY) : BuiltinRegistries.BIOME;

Optional<ResourceKey<Biome>> resource = registry.getResourceKey(biome.value());

if (resource.isEmpty()) {
throw new RuntimeException("Biome key is empty for biome: " + biome);
}

ResourceLocation key = resource.get().location();

return GuiUtils.colorize(
Component.translatable("biome." + key.getNamespace() + "." + key.getPath()),
colored ?
WorldColors.getBiomeColor(resource.get(), biome):
WorldColors.getBiomeColor(key, biome):
defaultColor
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
package dev.boxadactle.coordinatesdisplay;

import net.minecraft.core.Holder;
import net.minecraft.resources.ResourceKey;
import dev.boxadactle.boxlib.util.WorldUtils;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.biome.Biome;

import java.awt.*;

public class WorldColors {

public static int getBiomeColor(ResourceKey<Biome> biome, Holder<Biome> biome2) {
String biomeName = biome.location().getPath().toLowerCase();
public static int getBiomeColor(ResourceLocation key, Biome biome) {
if (biome == null) {
return 0x24BC07;
}

String biomeName = key.getPath().toLowerCase();

if (biomeName.contains("end")) return 0xC5BE8B;
if (biomeName.contains("ocean") || biomeName.contains("river") || biomeName.contains("swamp")) return biome2.value().getWaterColor();
if (biomeName.contains("nether")) return new Color(biome2.value().getFogColor()).brighter().brighter().getRGB();
if (biomeName.contains("ocean") || biomeName.contains("river") || biomeName.contains("swamp")) return biome.getWaterColor();
if (biomeName.contains("nether")) return new Color(biome.getFogColor()).brighter().brighter().getRGB();
if (biomeName.contains("icy")) return 0x84ecf0;
if (biomeName.contains("beach")) return 0xfade55;
else return biome2.value().getFoliageColor();
else return biome.getFoliageColor();
}

public static int getDimensionColor(String name, int defaultColor) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public RenderingLayout renderOverlay(int x, int y, Position pos) {
}

if (config().renderBiome || config().renderDimension) {
Component biomeString = ModUtil.getBiomeComponent(pos.world.getBiome(), config().biomeColors, config().dataColor);
Component biomeString = ModUtil.getBiomeComponent(pos.world.getBiomeKey(), pos.world.getBiome(), config().biomeColors, config().dataColor);
Component biome = definition("biome", biomeString);

String dimensionstring = pos.world.getDimension(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import dev.boxadactle.coordinatesdisplay.position.Position;
import net.minecraft.core.Holder;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.biome.Biome;

@HudDisplayMode(
Expand All @@ -39,6 +40,10 @@ public class HotbarRenderer implements HudRenderer {

@Override
public RenderingLayout renderOverlay(int x, int y, Position pos) {
if (((OverlayMessageTimeAccessor) ClientUtils.getClient().gui).getOverlayMessageTime() > 0) {
return new ColumnLayout(0, 0, 0);
}

Triplet<String, String, String> player = this.roundPosition(pos.position.getPlayerPos(), pos.position.getBlockPos(), CoordinatesDisplay.getConfig().decimalPlaces);

Component xyz = definition("xyz",
Expand All @@ -49,8 +54,9 @@ public RenderingLayout renderOverlay(int x, int y, Position pos) {

Component direction = definition("direction", resolveDirection(ModUtil.getDirectionFromYaw(pos.headRot.wrapYaw())));

Holder<Biome> b = pos.world.getBiome();
Component biome = ModUtil.getBiomeComponent(b, config().biomeColors, config().dataColor);
ResourceLocation bKey = pos.world.getBiomeKey();
Biome b = pos.world.getBiome();
Component biome = ModUtil.getBiomeComponent(bKey, b, config().biomeColors, config().dataColor);

Component all = translation("all", xyz, direction, biome);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public RenderingLayout renderOverlay(int x, int y, Position pos) {
if (config().renderBiome) {
Component biome = definition(
"biome",
ModUtil.getBiomeComponent(pos.world.getBiome(), config().biomeColors, config().dataColor)
ModUtil.getBiomeComponent(pos.world.getBiomeKey(), pos.world.getBiome(), config().biomeColors, config().dataColor)
);

row.addComponent(new dev.boxadactle.boxlib.layouts.component.TextComponent(biome));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ protected DeathScreenMixin(Component title) {
@Inject(at = @At("RETURN"), method = "init")
private void init(CallbackInfo ci) {
if (CoordinatesDisplay.CONFIG.get().displayPosOnDeathScreen) {
addRenderableWidget(new Button(this.width / 2 - 100, this.height / 4 + 120, 200, 20, Component.translatable("button.coordinatesdisplay.copy"), (button) -> {
addRenderableWidget(new Button.Builder(Component.translatable("button.coordinatesdisplay.copy"), (button) -> {
button.setMessage(Component.translatable("button.coordinatesdisplay.copied"));
button.active = false;

Expand All @@ -35,7 +35,7 @@ private void init(CallbackInfo ci) {

ClientUtils.getClient().keyboardHandler.setClipboard(x + " " + y + " " + z);
CoordinatesDisplay.LOGGER.info("Copied death position to clipboard");
}));
}).bounds(this.width / 2 - 100, this.height / 4 + 120, 200, 20).build());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
import dev.boxadactle.coordinatesdisplay.CoordinatesDisplay;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.core.Registry;
import net.minecraft.data.BuiltinRegistries;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.biome.Biomes;

public class PlayerWorldData {

Expand All @@ -25,8 +23,6 @@ public PlayerWorldData(BlockPos player) {
CoordinatesDisplay.LOGGER.warn("Client world is null! Resorting to default values.");

dimension = new ResourceLocation("minecraft", "overworld");

biome = BuiltinRegistries.BIOME.getHolderOrThrow(Biomes.PLAINS);
}
}

Expand All @@ -44,12 +40,19 @@ public String getDimension(boolean formatted) {
return formatted ? formatName(dimension.getPath()) : dimension.toString();
}

public Holder<Biome> getBiome() {
return biome;
public Biome getBiome() {
if (biome != null) {
return biome.value();
} else {
return null;
}
}

public ResourceLocation getBiomeKey() {
Registry<Biome> registry = WorldUtils.getWorld() != null ? WorldUtils.getWorld().registryAccess().registryOrThrow(Registry.BIOME_REGISTRY) : BuiltinRegistries.BIOME;
return registry.getKey(biome.value());
ResourceLocation def = new ResourceLocation("minecraft", "plains");
if (biome == null) {
return def;
}
return biome.unwrap().map(ResourceKey::location, (biome) -> def);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,22 @@ public void init() {

int bstart = this.height / 2 - 20;

addRenderableWidget(new Button(this.width / 2 - buttonw / 2, bstart, buttonw, buttonh, Component.translatable("button.coordinatesdisplay.copy"), button -> {
addRenderableWidget(new Button.Builder(Component.translatable("button.coordinatesdisplay.copy"), button -> {
ClientUtils.getClient().keyboardHandler.setClipboard(ModUtil.parseText(CoordinatesDisplay.CONFIG.get().copyPosMessage, this.pos));
CoordinatesDisplay.LOGGER.player.info("Copied coordinates to clipboard");
onClose();
}));
}).bounds(this.width / 2 - buttonw / 2, bstart, buttonw, buttonh).build());

addRenderableWidget(new Button(this.width / 2 - buttonw / 2, bstart + (buttonh + p), buttonw, buttonh, Component.translatable("button.coordinatesdisplay.send"), button -> {
addRenderableWidget(new Button.Builder(Component.translatable("button.coordinatesdisplay.send"), button -> {
CoordinatesDisplay.LOGGER.player.publicChat(ModUtil.parseText(CoordinatesDisplay.CONFIG.get().posChatMessage, this.pos));
onClose();
}));
}).bounds(this.width / 2 - buttonw / 2, bstart + (buttonh + p), buttonw, buttonh).build());

addRenderableWidget(new Button(this.width / 2 - buttonw / 2, bstart + (buttonh + p) * 2, buttonw, buttonh, Component.translatable("button.coordinatesdisplay.copytp"), button -> {
addRenderableWidget(new Button.Builder(Component.translatable("button.coordinatesdisplay.copytp"), button -> {
ClientUtils.getClient().keyboardHandler.setClipboard(CoordinatesDisplay.getConfig().teleportMode.toCommand(Position.of(WorldUtils.getPlayer())));
CoordinatesDisplay.LOGGER.player.info("Copied as TP command");
onClose();
}));
}).bounds(this.width / 2 - buttonw / 2, bstart + (buttonh + p) * 2, buttonw, buttonh).build());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,11 @@ public HudOption(String key, Boolean value, Consumer<Boolean> function, boolean
}

@Override
public void renderToolTip(PoseStack poseStack, int i, int j) {
if (!active) {
RenderScreen.this.renderTooltip(poseStack, Component.translatable("message.coordintatesdisplay.disabled"), i, j);
public void renderButton(PoseStack p_93657_, int mouseX, int mouseY, float delta) {
super.renderButton(p_93657_, mouseX, mouseY, delta);

if (!active && isHovered) {
RenderScreen.this.renderTooltip(p_93657_, Component.translatable("message.coordintatesdisplay.disabled"), mouseX, mouseY);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import dev.boxadactle.coordinatesdisplay.registry.StartCorner;
import dev.boxadactle.coordinatesdisplay.registry.VisibilityFilter;
import dev.boxadactle.coordinatesdisplay.position.Position;
import net.minecraft.client.gui.components.AbstractWidget;
import net.minecraft.client.gui.components.Tooltip;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;

Expand All @@ -23,8 +25,8 @@ public class VisualScreen extends BOptionScreen implements HudHelper {

Position pos;

TooltipEnumButton<?> startCornerButton;
TooltipScreenButton changeHudPosButton;
AbstractWidget startCornerButton;
AbstractWidget changeHudPosButton;

public VisualScreen(Screen parent) {
super(parent);
Expand Down Expand Up @@ -58,7 +60,7 @@ protected void initConfigButtons() {
addConfigLine(new VisibilitySelector(config().visibilityFilter, var2));
}

startCornerButton = addConfigLine(new TooltipEnumButton<>(
startCornerButton = addConfigLine(new BEnumButton<>(
"button.coordinatesdisplay.startcorner",
config().startCorner,
StartCorner.class,
Expand Down Expand Up @@ -114,7 +116,7 @@ protected void initConfigButtons() {
);

// hud position screen
changeHudPosButton = addConfigLine(new TooltipScreenButton(
changeHudPosButton = addConfigLine(new BConfigScreenButton(
Component.translatable("button.coordinatesdisplay.editHudPos"),
this,
PositionScreen::new
Expand Down Expand Up @@ -162,15 +164,15 @@ private void verifyButtons() {
startCornerButton.setTooltip(null);
} else {
startCornerButton.active = false;
startCornerButton.setTooltip(Component.translatable("message.coordintatesdisplay.disabled"));
startCornerButton.setTooltip(Tooltip.create(Component.translatable("message.coordintatesdisplay.disabled")));
}

if (config().renderMode.getMetadata().allowMove()) {
changeHudPosButton.active = true;
changeHudPosButton.setTooltip(null);
} else {
changeHudPosButton.active = false;
changeHudPosButton.setTooltip(Component.translatable("message.coordintatesdisplay.disabled"));
changeHudPosButton.setTooltip(Tooltip.create(Component.translatable("message.coordintatesdisplay.disabled")));
}
}

Expand Down Expand Up @@ -222,42 +224,4 @@ public Component from(DisplayMode input) {
}
}

public class TooltipEnumButton<T extends Enum<T>> extends BEnumButton<T> {
Component tooltip;

public TooltipEnumButton(String key, T value, Class<T> tEnum, Consumer<T> function, int valColor) {
super(key, value, tEnum, function, valColor);
}

public void setTooltip(Component tooltip) {
this.tooltip = tooltip;
}

@Override
public void renderToolTip(PoseStack poseStack, int i, int j) {
if (tooltip != null) {
VisualScreen.this.renderTooltip(poseStack, tooltip, i, j);
}
}
}

public class TooltipScreenButton extends BConfigScreenButton {
Component tooltip;

public TooltipScreenButton(Component message, Screen parent, Provider<?> function) {
super(message, parent, function);
}

public void setTooltip(Component tooltip) {
this.tooltip = tooltip;
}

@Override
public void renderToolTip(PoseStack poseStack, int i, int j) {
if (tooltip != null) {
VisualScreen.this.renderTooltip(poseStack, tooltip, i, j);
}
}
}

}
Loading

0 comments on commit 09de895

Please sign in to comment.