Skip to content

Commit

Permalink
Use gt5u localized ore mix names (#60)
Browse files Browse the repository at this point in the history
* use gt5u localized ore mix names

* the Math.max/min's are inside VeinType now

* highlight vein when vein name is searched in nei (again)

* update

---------

Co-authored-by: Martin Robertz <dream-master@gmx.net>
  • Loading branch information
Lyfts and Dream-Master authored Sep 28, 2024
1 parent 3c1ba04 commit 5b56eb3
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 36 deletions.
2 changes: 1 addition & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
dependencies {
api('com.github.GTNewHorizons:Navigator:1.0.15:dev')
api('com.github.GTNewHorizons:GTNHLib:0.5.11:dev')
api('com.github.GTNewHorizons:GT5-Unofficial:5.09.50.20:dev')
api('com.github.GTNewHorizons:GT5-Unofficial:5.09.50.21:dev')

runtimeOnlyNonPublishable(rfg.deobf('maven.modrinth:journeymap:5.2.6'))
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private void notifyNewOreVein(OreVeinPosition oreVeinPosition) {
final String location = "(" + (oreVeinPosition.getBlockX() + 8) + "," + (oreVeinPosition.getBlockZ() + 8) + ")";
final IChatComponent veinNotification = new ChatComponentTranslation(
"visualprospecting.vein.prospected",
oreVeinPosition.veinType.getPrimaryOreName(),
oreVeinPosition.veinType.getVeinName(),
location);
veinNotification.getChatStyle().setItalic(true);
veinNotification.getChatStyle().setColor(EnumChatFormatting.GRAY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,6 @@ public GregTechOreMaterialProvider(Materials material) {
this.primaryOreName = material.mLocalizedName;
}

GregTechOreMaterialProvider() {
material = Materials._NULL;
primaryOreColor = 0;
primaryOreName = "";
containedOres = ImmutableList.of();
}

@Override
@SideOnly(Side.CLIENT)
public IIcon getIcon() {
Expand All @@ -59,6 +52,7 @@ public ImmutableList<String> getContainedOres(ShortCollection ores) {
if (containedOres == null) {
List<String> temp = new ArrayList<>();
for (short meta : ores) {
if (meta < 0) break;
Materials material = GregTechAPI.sGeneratedMaterials[meta];
if (material == null) continue;
temp.add(material.mLocalizedName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.google.common.collect.ImmutableList;
import com.sinthoras.visualprospecting.Tags;

import gregtech.api.enums.Materials;
import gregtech.common.OreMixBuilder;
import it.unimi.dsi.fastutil.shorts.ShortArraySet;
import it.unimi.dsi.fastutil.shorts.ShortCollection;
Expand All @@ -32,11 +33,12 @@ public class VeinType {
private final ShortSet oresAsSet = new ShortArraySet();
private final List<String> allowedDims = new ArrayList<>();
private boolean isHighlighted = true;
private final String localizedName;

// Available after VisualProspecting post GT initialization
public static final VeinType NO_VEIN = new VeinType(
Tags.ORE_MIX_NONE_NAME,
new GregTechOreMaterialProvider(),
new GregTechOreMaterialProvider(Materials._NULL),
0,
(short) -1,
(short) -1,
Expand All @@ -52,18 +54,20 @@ public VeinType(String name, IOreMaterialProvider oreMaterialProvider, int block
this.name = name;
this.oreMaterialProvider = oreMaterialProvider;
this.blockSize = blockSize;
this.minBlockY = minBlockY;
this.maxBlockY = maxBlockY;
this.minBlockY = Math.max(0, minBlockY);
this.maxBlockY = Math.min(255, maxBlockY);
oresAsSet.add(this.primaryOreMeta = primaryOreMeta);
oresAsSet.add(this.secondaryOreMeta = secondaryOreMeta);
oresAsSet.add(this.inBetweenOreMeta = inBetweenOreMeta);
oresAsSet.add(this.sporadicOreMeta = sporadicOreMeta);
localizedName = oreMaterialProvider.getLocalizedName();
allowedDims.add(dimName);
}

public VeinType(OreMixBuilder oreMix) {
name = oreMix.oreMixName;
oreMaterialProvider = new GregTechOreMaterialProvider(oreMix.primary);
oreMaterialProvider = new GregTechOreMaterialProvider(oreMix.representative);
localizedName = oreMix.localizedName;
blockSize = oreMix.size;
oresAsSet.add(primaryOreMeta = (short) oreMix.primary.mMetaItemSubID);
oresAsSet.add(secondaryOreMeta = (short) oreMix.secondary.mMetaItemSubID);
Expand Down Expand Up @@ -106,8 +110,8 @@ public ImmutableList<String> getOreMaterialNames() {
return oreMaterialProvider.getContainedOres(oresAsSet);
}

public String getPrimaryOreName() {
return oreMaterialProvider.getLocalizedName();
public String getVeinName() {
return localizedName;
}

public ShortSet getOresAtLayer(int layerBlockY) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@
import static com.sinthoras.visualprospecting.Utils.*;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.OptionalInt;
import java.util.regex.Pattern;

import net.minecraft.util.EnumChatFormatting;

import org.apache.commons.lang3.StringUtils;

import com.sinthoras.visualprospecting.Tags;
import com.sinthoras.visualprospecting.Utils;

Expand Down Expand Up @@ -49,9 +54,15 @@ public void run() {
}

for (BWOreLayer vein : BWOreLayer.sList) {
final IOreMaterialProvider oreMaterialProvider = (vein.bwOres & 0b1000) == 0
? new GregTechOreMaterialProvider(getGregTechMaterial((short) vein.mPrimaryMeta))
: new BartworksOreMaterialProvider(Werkstoff.werkstoffHashMap.get((short) vein.mPrimaryMeta));
final IOreMaterialProvider oreMaterialProvider;
if (containsBartworksOres(vein.bwOres)) {
oreMaterialProvider = getRepresentativeProvider(
vein.mWorldGenName,
new int[] { vein.mPrimaryMeta, vein.mSecondaryMeta, vein.mBetweenMeta, vein.mSporadicMeta });
} else {
oreMaterialProvider = new GregTechOreMaterialProvider(
GregTechAPI.sGeneratedMaterials[(short) vein.mPrimaryMeta]);
}
veinTypes.add(
new VeinType(
vein.mWorldGenName,
Expand All @@ -61,8 +72,8 @@ public void run() {
(short) vein.mSecondaryMeta,
(short) vein.mBetweenMeta,
(short) vein.mSporadicMeta,
Math.max(0, vein.mMinY),
Math.min(255, vein.mMaxY),
vein.mMinY,
vein.mMaxY,
vein.getDimName()));
}

Expand All @@ -81,16 +92,6 @@ public void run() {
saveVeinTypeStorageInfo();
}

private Materials getGregTechMaterial(short metaId) {
final Materials material = GregTechAPI.sGeneratedMaterials[metaId];
if (material == null) {
// Some materials are not registered in dev when their usage mod is not available.
return Materials.getAll().stream().filter(m -> m.mMetaItemSubID == metaId).findAny()
.orElse(Materials._NULL);
}
return material;
}

public static VeinType getVeinType(short veinTypeId) {
return veinTypeLookupTableForIds.getOrDefault(veinTypeId, VeinType.NO_VEIN);
}
Expand Down Expand Up @@ -123,7 +124,8 @@ public static void recalculateNEISearch() {
for (VeinType veinType : veinTypes) {
if (veinType == VeinType.NO_VEIN) continue;
if (isSearchActive && !searchString.isEmpty()) {
List<String> searchableStrings = veinType.getOreMaterialNames();
List<String> searchableStrings = new ArrayList<>(veinType.getOreMaterialNames());
searchableStrings.add(veinType.getVeinName());
final boolean match = searchableStrings.stream()
.map(EnumChatFormatting::getTextWithoutFormattingCodes).map(String::toLowerCase)
.anyMatch(searchableString -> filterPattern.matcher(searchableString).find());
Expand All @@ -135,4 +137,27 @@ public static void recalculateNEISearch() {
}
}
}

private static boolean containsBartworksOres(byte bwOres) {
return (bwOres & 0b1111) != 0;
}

private static IOreMaterialProvider getRepresentativeProvider(String veinName, int[] ores) {
for (int meta : ores) {
Werkstoff werkstoff = Werkstoff.werkstoffHashMap.get((short) meta);
if (werkstoff == null) continue;
String defaultName = werkstoff.getDefaultName();
// also try lobbing a few characters off the end of the vein name because bart
if (StringUtils.endsWithIgnoreCase(veinName, defaultName)
|| StringUtils.containsIgnoreCase(veinName, defaultName.substring(0, defaultName.length() - 2))) {
return new BartworksOreMaterialProvider(werkstoff);
}
}

Werkstoff primaryMaterial = Arrays.stream(ores).mapToObj(meta -> Werkstoff.werkstoffHashMap.get((short) meta))
.filter(Objects::nonNull).findFirst().orElse(null);

return primaryMaterial == null ? new GregTechOreMaterialProvider(Materials._NULL)
: new BartworksOreMaterialProvider(primaryMaterial);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public Optional<String> getVeinName(int dimensionId, ChunkCoordIntPair coordinat
// capture which language the original cover attaching player is using, maybe. (I think this requires
// reflection, of course. Why should things be easy?) Even then, it wouldn't help in a multiplayer scenario
// with users having different locales.
return Optional.of(oreVein.veinType.getPrimaryOreName());
return Optional.of(oreVein.veinType.getVeinName());
} else {
return Optional.empty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class OreVeinLocation implements IWaypointAndLocationProvider {

public OreVeinLocation(OreVeinPosition oreVeinPosition) {
this.oreVeinPosition = oreVeinPosition;
name = EnumChatFormatting.WHITE + oreVeinPosition.veinType.getPrimaryOreName();
name = EnumChatFormatting.WHITE + oreVeinPosition.veinType.getVeinName();
materialNames = oreVeinPosition.veinType.getOreMaterialNames().stream()
.map(materialName -> EnumChatFormatting.GRAY + materialName).collect(Collectors.toList());
}
Expand All @@ -43,7 +43,7 @@ public Waypoint toWaypoint() {
65,
oreVeinPosition.getBlockZ(),
oreVeinPosition.dimensionId,
I18n.format("visualprospecting.tracked", oreVeinPosition.veinType.getPrimaryOreName()),
I18n.format("visualprospecting.tracked", oreVeinPosition.veinType.getVeinName()),
getColor());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void onVeinProspected(ProspectingNotificationEvent.OreVein event) {
TreeSet<Integer> dim = new TreeSet<>();
dim.add(pos.dimensionId);
VoxelMapWaypointManager.addVoxelMapWaypoint(
pos.veinType.getPrimaryOreName(), // name
pos.veinType.getVeinName(), // name
pos.getBlockX(), // X
pos.getBlockZ(), // Z
getY(), // Y
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public GT_MetaTileEntity_ScannerMixin() {
if (veinId < foundOreVeins.size()) {
final OreVeinPosition oreVein = foundOreVeins.get(veinId);
pageString.append(oreVein.getBlockX()).append(",").append(oreVein.getBlockZ()).append(" - ")
.append(oreVein.veinType.getPrimaryOreName()).append("\n");
.append(oreVein.veinType.getVeinName()).append("\n");
}
}
String pageCounter = numberOfPages > 1 ? String.format(" %d/%d", pageNumber + 1, numberOfPages)
Expand Down

0 comments on commit 5b56eb3

Please sign in to comment.