Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ plugins {
//alias(libs.plugins.shadow)
}

loom {
accessWidenerPath = file("src/main/resources/civmodern.accesswidener")
}

dependencies {
minecraft(libs.minecraft)
mappings(loom.layered() {
Expand Down
27 changes: 5 additions & 22 deletions src/main/java/sh/okx/civmodern/common/CivMapConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.Properties;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import sh.okx.civmodern.common.features.CompactedItem;
import sh.okx.civmodern.common.gui.Alignment;

public class CivMapConfig {
Expand All @@ -16,7 +17,6 @@ public class CivMapConfig {
public static final int DEFAULT_CHEVRON_COLOUR = 0xFF0000;
public static final int DEFAULT_BORDER_COLOUR = 0x7a7a7a;
private final File file;
private int compactedColour;
private int radarCircles;
private int radarSize;
private float iconSize;
Expand Down Expand Up @@ -47,15 +47,14 @@ public class CivMapConfig {
private int minimapSize;
private boolean playerWaypointsEnabled;
private float minimapZoom;
private boolean cratesAreCompacted;
private boolean showRepairCost;
private boolean radarLogarithm;
private boolean showMinimapCoords;
private int borderColour;

public CivMapConfig(File file, Properties properties) {
this.file = file;
this.compactedColour = Integer.parseInt(properties.getProperty("compacted_colour", "16777048"));
CompactedItem.COMPACTED.setRBG(Integer.parseInt(properties.getProperty("compacted_colour", Integer.toString(CompactedItem.COMPACTED.defaultColour))));
this.radarCircles = Integer.parseInt(properties.getProperty("radar_circles", "4"));
this.radarSize = Integer.parseInt(properties.getProperty("radar_size", "80"));
this.alignment = Alignment.valueOf(properties.getProperty("alignment", "top_left").toUpperCase());
Expand Down Expand Up @@ -86,17 +85,17 @@ public CivMapConfig(File file, Properties properties) {
this.minimapSize = Integer.parseInt(properties.getProperty("minimap_size", "100"));
this.playerWaypointsEnabled = Boolean.parseBoolean(properties.getProperty("player_waypoints_enabled", "true"));
this.minimapZoom = Float.parseFloat(properties.getProperty("minimap_zoom", "4"));
this.cratesAreCompacted = Boolean.parseBoolean(properties.getProperty("crates_are_compacted", "true"));
this.showRepairCost = Boolean.parseBoolean(properties.getProperty("show_repair_cost", "true"));
this.radarLogarithm = Boolean.parseBoolean(properties.getProperty("radar_logarithm", "false"));
this.showMinimapCoords = Boolean.parseBoolean(properties.getProperty("show_minimap_coords", "true"));
this.borderColour = Integer.parseInt(properties.getProperty("border_colour", Integer.toString(DEFAULT_BORDER_COLOUR)));
CompactedItem.CRATE.setRBG(Integer.parseInt(properties.getProperty("crate_colour", Integer.toString(CompactedItem.CRATE.defaultColour))));
}

public void save() {
try {
Properties properties = new Properties();
properties.setProperty("compacted_colour", Integer.toString(compactedColour));
properties.setProperty("compacted_colour", Integer.toString(CompactedItem.COMPACTED.getRBG()));
properties.setProperty("radar_circles", Integer.toString(radarCircles));
properties.setProperty("radar_size", Integer.toString(radarSize));
properties.setProperty("alignment", alignment.name().toLowerCase());
Expand Down Expand Up @@ -126,11 +125,11 @@ public void save() {
properties.setProperty("minimap_size", Integer.toString(minimapSize));
properties.setProperty("player_waypoints_enabled", Boolean.toString(playerWaypointsEnabled));
properties.setProperty("minimap_zoom", Float.toString(minimapZoom));
properties.setProperty("crates_are_compacted", Boolean.toString(cratesAreCompacted));
properties.setProperty("show_repair_cost", Boolean.toString(showRepairCost));
properties.setProperty("radar_logarithm", Boolean.toString(radarLogarithm));
properties.setProperty("show_minimap_coords", Boolean.toString(showMinimapCoords));
properties.setProperty("border_colour", Integer.toString(borderColour));
properties.setProperty("crate_colour", Integer.toString(CompactedItem.CRATE.getRBG()));

try (FileOutputStream output = new FileOutputStream(file)) {
properties.store(output, null);
Expand All @@ -149,14 +148,6 @@ public void setShowItems(boolean showItems) {
this.showItems = showItems;
}

public int getColour() {
return compactedColour;
}

public void setColour(int compactedColour) {
this.compactedColour = compactedColour;
}

public void setRadarCircles(int radarCircles) {
this.radarCircles = radarCircles;
}
Expand Down Expand Up @@ -389,14 +380,6 @@ public void setMinimapZoom(float minimapZoom) {
this.minimapZoom = minimapZoom;
}

public boolean isCratesAreCompacted() {
return cratesAreCompacted;
}

public void setCratesAreCompacted(boolean cratesAreCompacted) {
this.cratesAreCompacted = cratesAreCompacted;
}

public boolean isShowRepairCost() {
return showRepairCost;
}
Expand Down
9 changes: 0 additions & 9 deletions src/main/java/sh/okx/civmodern/common/ColourProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,13 @@ public class ColourProvider {
private final CivMapConfig config;
private Integer radarFg;
private Integer radarBg;
private Integer compacted;
private Integer chevron;
private Integer border;

public ColourProvider(CivMapConfig config) {
this.config = config;
}

public int getCompactedColour() {
return Objects.requireNonNullElseGet(compacted, config::getColour);
}

public int getForegroundColour() {
return Objects.requireNonNullElseGet(radarFg, config::getRadarColour);
}
Expand All @@ -43,10 +38,6 @@ public void setTemporaryRadarBackgroundColour(Integer colour) {
radarBg = colour;
}

public void setTemporaryCompactedColour(Integer colour) {
compacted = colour;
}

public void setTemporaryChevronColour(Integer colour) {
chevron = colour;
}
Expand Down
124 changes: 124 additions & 0 deletions src/main/java/sh/okx/civmodern/common/features/CompactedItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
package sh.okx.civmodern.common.features;

import java.awt.Color;
import java.util.List;
import java.util.NoSuchElementException;
import net.minecraft.core.component.DataComponentPatch;
import net.minecraft.core.component.DataComponents;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.Style;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.component.ItemLore;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public enum CompactedItem {
CRATE(0xFF_41_41),
COMPACTED(0xFF_FF_58),
;

public final int defaultColour;
public final Color defaultAwtColor;
private volatile int colour;

CompactedItem(
final int defaultColour
) {
this.defaultColour = defaultColour;
this.defaultAwtColor = new Color(defaultColour);
this.colour = defaultColour;
}

public int getRBG() {
return 0xFF_00_00_00 | this.colour;
}

public void setRBG(
final int colour
) {
this.colour = colour;
}

private static final String CRATE_LORE = "Crate";
private static final String COMPACTED_LORE = "Compacted Item";

public static @Nullable CompactedItem determineCompactedItemType(
final @NotNull ItemStack item
) {
if (CompactedItem.isCrate(item)) {
return CompactedItem.CRATE;
}
else if (CompactedItem.isCompacted(item)) {
return CompactedItem.COMPACTED;
}
else {
return null;
}
}

private static boolean isCrate(
final @NotNull ItemStack item
) {
return item.getItem() == Items.CHEST
&& hasLastPlainLoreLine(item, CRATE_LORE, true);
}

private static boolean isCompacted(
final @NotNull ItemStack item
) {
return hasLastPlainLoreLine(item, COMPACTED_LORE, true);
}

private static boolean hasLastPlainLoreLine(
final @NotNull ItemStack item,
final @NotNull String expected,
final boolean caseSensitive
) {
final ItemLore lore = item.getComponents().get(DataComponents.LORE);
if (lore == null) {
return false;
}
final Component line;
try {
line = lore.lines().getLast();
}
catch (final NoSuchElementException ignored) {
return false;
}
final var content = new StringBuilder();
for (final Component child : line.toFlatList()) {
if (!Style.EMPTY.equals(child.getStyle())) {
return false;
}
content.append(child.getString());
}
return caseSensitive
? expected.contentEquals(content)
: expected.equalsIgnoreCase(content.toString());
}

public static @NotNull ItemStack createExampleCrate() {
return new ItemStack(
Items.CHEST.builtInRegistryHolder(),
64,
DataComponentPatch.builder()
.set(DataComponents.LORE, new ItemLore(List.of(
Component.literal(CompactedItem.CRATE_LORE)
)))
.build()
);
}

public static @NotNull ItemStack createExampleCompacted() {
return new ItemStack(
Items.STONE.builtInRegistryHolder(),
64,
DataComponentPatch.builder()
.set(DataComponents.LORE, new ItemLore(List.of(
Component.literal(CompactedItem.COMPACTED_LORE)
)))
.build()
);
}
}

This file was deleted.

Loading