Skip to content

Commit

Permalink
feat: Able to change HUD information detailed level
Browse files Browse the repository at this point in the history
  • Loading branch information
SnightW committed Jun 22, 2021
1 parent 092998c commit 58ec3c3
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 27 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ plugins {
}
apply plugin: 'net.minecraftforge.gradle'

def baseVersion = '1.0.2'
def baseVersion = '1.1.0'
def minecraftVersion = '1.15.2'
version = "${minecraftVersion}-${baseVersion}" as Object
group = 'com.github.samarium150'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,40 @@ public final class StructuresCompassConfig {
public static final ForgeConfigSpec.DoubleValue maxDistance;
public static final ForgeConfigSpec.IntValue radius;
public static final ForgeConfigSpec.BooleanValue easyCrafting;
public static final ForgeConfigSpec.IntValue HUD_Level;

static {
ForgeConfigSpec.Builder builder = new ForgeConfigSpec.Builder();
builder.comment("configs for both server and clients").push("General");
blacklist = builder
.comment("A list of structures that the compass will not search, " +
.comment("\nA list of structures that the compass will not search, " +
"specified by resource location. ",
"Ex: [\"minecraft:stronghold\", \"quark:big_dungeon\"]")
.define("blacklist", new ArrayList<>());

maxDistance = builder
.comment("The pseudo maximum searching radius.",
.comment("\nThe pseudo maximum searching radius.",
"If the distance to the structure exceeds this value, HUD would display 'Not Found'")
.defineInRange("MaxSearchRadius", 5000D, 20 , 20000);

radius = builder
.comment("The real maximum searching radius used by the underlying method (no idea how it works.)",
.comment("\nThe real maximum searching radius used by the underlying method (no idea how it works.)",
"If you still couldn't find a structure with a big enough MaxSearchRadius, increase this one.",
"If you think searching makes the server slow, decrease this one.")
.defineInRange("RealRadius", 64, 1 , 128);

easyCrafting = builder
.comment("Easy Crafting", "Using Iron bars instead of dead corals")
.comment("\nEasy Crafting", "Using Iron bars instead of dead corals")
.define("EasyCrafting", false);


HUD_Level = builder
.comment("\nHUD information detail level.",
"0: Nothing.",
"1+: Structure and Dimension name.",
"2+: Distance to the structure.",
"3: Position of the structure and distance in x/y/z axis.")
.defineInRange("HUD_Level", 3, 0 , 3);

COMMON_CONFIG = builder.build();
builder.pop();
}
Expand All @@ -55,27 +64,27 @@ public final class StructuresCompassConfig {
ForgeConfigSpec.Builder builder = new ForgeConfigSpec.Builder();
builder.comment("configs only for clients").push("Client");
hudPosition = builder
.comment("The side of the information HUD. Ex: LEFT, RIGHT")
.comment("\nThe side of the information HUD. Ex: LEFT, RIGHT")
.defineEnum("HUDPosition", HUDPosition.LEFT);

displayWithChatOpen = builder
.comment("Displays the compass information HUD even while chat is open.(default:true)")
.comment("\nDisplays the compass information HUD even while chat is open.(default:true)")
.define("DisplayWithChatOpen", true);

xOffset = builder
.comment("The X offset for information rendered on the HUD.(default:7)")
.comment("\nThe X offset for information rendered on the HUD.(default:7)")
.defineInRange("xOffset", 7, 0 , 9600);

yOffset = builder
.comment("The Y offset for information rendered on the HUD.(default:16)")
.comment("\nThe Y offset for information rendered on the HUD.(default:16)")
.defineInRange("yOffset", 16, 0 , 5400);

overlayLineOffset = builder
.comment("The line offset for information rendered on the HUD.(default:1)")
.comment("\nThe line offset for information rendered on the HUD.(default:1)")
.defineInRange("OverlayLineOffset", 1, 0 , 50);

closeEnough = builder
.comment("The X/Y/Z-distance won't be shown if it is smaller than the value.(default:0.3)")
.comment("\nThe X/Y/Z-distance won't be shown if it is smaller than the value.(default:0.3)")
.defineInRange("CloseEnough", 0.3, 0 , 50);

CLIENT_CONFIG = builder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public StructuresCompassHUD() { }
*/
public void render() {

if ((minecraft.currentScreen == null || (StructuresCompassConfig.displayWithChatOpen.get()
if (StructuresCompassConfig.HUD_Level.get() != 0 &&
(minecraft.currentScreen == null || (StructuresCompassConfig.displayWithChatOpen.get()
&& minecraft.currentScreen instanceof ChatScreen))) {
final PlayerEntity player = minecraft.player;
final ItemStack stack;
Expand Down Expand Up @@ -79,13 +80,15 @@ else if (!player.getHeldItemOffhand().isEmpty()
5, 5, 0xAAAAAA, ++relLineOffset
);
relLineOffset++;

String temp = pos.getY() == 0 ? ", X, " : ", " + pos.getY() + ", ";
temp = I18n.format("string.structurescompass.hud_pos") + " [" + pos.getX() + temp + pos.getZ() + "]";
RenderUtils.drawConfiguredStringOnHUD(
temp,
5, 5, 0x4AFF4A, ++relLineOffset
);

if (StructuresCompassConfig.HUD_Level.get() == 3) {
String temp = pos.getY() == 0 ? ", X, " : ", " + pos.getY() + ", ";
temp = I18n.format("string.structurescompass.hud_pos") + " [" + pos.getX() + temp + pos.getZ() + "]";
RenderUtils.drawConfiguredStringOnHUD(
temp,
5, 5, 0x4AFF4A, ++relLineOffset
);
}

if (StructureUtils.getDimensionName(player.getEntityWorld().getDimension().getType()).equals(dim)) {

Expand All @@ -95,40 +98,41 @@ else if (!player.getHeldItemOffhand().isEmpty()
double disZ = dis.getZ();
double distance = (double) Math.round(Math.sqrt(disX * disX + disY * disY + disZ * disZ) * 100) / 100;

if (disX > StructuresCompassConfig.closeEnough.get())
if (StructuresCompassConfig.HUD_Level.get() == 3 && disX > StructuresCompassConfig.closeEnough.get())
RenderUtils.drawConfiguredStringOnHUD(
I18n.format("string.structurescompass.hud_east") + disX,
5, 5, 0xFFFFFF, ++relLineOffset
);
else if (disX < -StructuresCompassConfig.closeEnough.get())
else if (StructuresCompassConfig.HUD_Level.get() == 3 && disX < -StructuresCompassConfig.closeEnough.get())
RenderUtils.drawConfiguredStringOnHUD(
I18n.format("string.structurescompass.hud_west") + -disX,
5, 5, 0xFFFFFF, ++relLineOffset
);

if (disZ > StructuresCompassConfig.closeEnough.get())
if (StructuresCompassConfig.HUD_Level.get() == 3 && disZ > StructuresCompassConfig.closeEnough.get())
RenderUtils.drawConfiguredStringOnHUD(
I18n.format("string.structurescompass.hud_south") + disZ,
5, 5, 0xFFFFFF, ++relLineOffset
);
else if (disZ < -StructuresCompassConfig.closeEnough.get())
else if (StructuresCompassConfig.HUD_Level.get() == 3 && disZ < -StructuresCompassConfig.closeEnough.get())
RenderUtils.drawConfiguredStringOnHUD(
I18n.format("string.structurescompass.hud_north") + -disZ,
5, 5, 0xFFFFFF, ++relLineOffset
);

if (disY > StructuresCompassConfig.closeEnough.get())
if (StructuresCompassConfig.HUD_Level.get() == 3 && disY > StructuresCompassConfig.closeEnough.get())
RenderUtils.drawConfiguredStringOnHUD(
I18n.format("string.structurescompass.hud_up") + disY,
5, 5, 0xFFFFFF, ++relLineOffset
);
else if (disY < -StructuresCompassConfig.closeEnough.get())
else if (StructuresCompassConfig.HUD_Level.get() == 3 && disY < -StructuresCompassConfig.closeEnough.get())
RenderUtils.drawConfiguredStringOnHUD(
I18n.format("string.structurescompass.hud_down") + -disY,
5, 5, 0xFFFFFF, ++relLineOffset
);

if (relLineOffset > 6) {
if ((StructuresCompassConfig.HUD_Level.get() == 3 && relLineOffset > 6) ||
(StructuresCompassConfig.HUD_Level.get() >= 2 && distance > StructuresCompassConfig.closeEnough.get())) {
relLineOffset++;
RenderUtils.drawConfiguredStringOnHUD(
I18n.format("string.structurescompass.hud_distance") + distance,
Expand Down

0 comments on commit 58ec3c3

Please sign in to comment.