From c5db89975bc2f6293e363343dd239189f677be6b Mon Sep 17 00:00:00 2001 From: Lyfts <127234178+Lyfts@users.noreply.github.com> Date: Fri, 27 Sep 2024 18:37:11 +0200 Subject: [PATCH 1/4] use gt5u localized ore mix names --- .../database/ClientCache.java | 2 +- .../GregTechOreMaterialProvider.java | 8 +-- .../database/veintypes/VeinType.java | 16 +++--- .../database/veintypes/VeinTypeCaching.java | 49 ++++++++++++++----- .../integration/gregtech/VeinDatabase.java | 2 +- .../model/locations/OreVeinLocation.java | 4 +- .../voxelmap/VoxelMapEventHandler.java | 2 +- .../GT_MetaTileEntity_ScannerMixin.java | 2 +- 8 files changed, 53 insertions(+), 32 deletions(-) diff --git a/src/main/java/com/sinthoras/visualprospecting/database/ClientCache.java b/src/main/java/com/sinthoras/visualprospecting/database/ClientCache.java index e225354..1d728e0 100644 --- a/src/main/java/com/sinthoras/visualprospecting/database/ClientCache.java +++ b/src/main/java/com/sinthoras/visualprospecting/database/ClientCache.java @@ -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); diff --git a/src/main/java/com/sinthoras/visualprospecting/database/veintypes/GregTechOreMaterialProvider.java b/src/main/java/com/sinthoras/visualprospecting/database/veintypes/GregTechOreMaterialProvider.java index 8956c20..d6d6020 100644 --- a/src/main/java/com/sinthoras/visualprospecting/database/veintypes/GregTechOreMaterialProvider.java +++ b/src/main/java/com/sinthoras/visualprospecting/database/veintypes/GregTechOreMaterialProvider.java @@ -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() { @@ -59,6 +52,7 @@ public ImmutableList getContainedOres(ShortCollection ores) { if (containedOres == null) { List temp = new ArrayList<>(); for (short meta : ores) { + if (meta < 0) break; Materials material = GregTechAPI.sGeneratedMaterials[meta]; if (material == null) continue; temp.add(material.mLocalizedName); diff --git a/src/main/java/com/sinthoras/visualprospecting/database/veintypes/VeinType.java b/src/main/java/com/sinthoras/visualprospecting/database/veintypes/VeinType.java index 4b3244f..7737e97 100644 --- a/src/main/java/com/sinthoras/visualprospecting/database/veintypes/VeinType.java +++ b/src/main/java/com/sinthoras/visualprospecting/database/veintypes/VeinType.java @@ -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; @@ -32,11 +33,12 @@ public class VeinType { private final ShortSet oresAsSet = new ShortArraySet(); private final List 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, @@ -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); @@ -106,8 +110,8 @@ public ImmutableList getOreMaterialNames() { return oreMaterialProvider.getContainedOres(oresAsSet); } - public String getPrimaryOreName() { - return oreMaterialProvider.getLocalizedName(); + public String getVeinName() { + return localizedName; } public ShortSet getOresAtLayer(int layerBlockY) { diff --git a/src/main/java/com/sinthoras/visualprospecting/database/veintypes/VeinTypeCaching.java b/src/main/java/com/sinthoras/visualprospecting/database/veintypes/VeinTypeCaching.java index f90a831..d7f27f8 100644 --- a/src/main/java/com/sinthoras/visualprospecting/database/veintypes/VeinTypeCaching.java +++ b/src/main/java/com/sinthoras/visualprospecting/database/veintypes/VeinTypeCaching.java @@ -3,14 +3,18 @@ import static com.sinthoras.visualprospecting.Utils.*; import java.io.File; +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; @@ -49,9 +53,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, @@ -81,16 +91,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); } @@ -135,4 +135,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); + } } diff --git a/src/main/java/com/sinthoras/visualprospecting/integration/gregtech/VeinDatabase.java b/src/main/java/com/sinthoras/visualprospecting/integration/gregtech/VeinDatabase.java index 3124c91..a437250 100644 --- a/src/main/java/com/sinthoras/visualprospecting/integration/gregtech/VeinDatabase.java +++ b/src/main/java/com/sinthoras/visualprospecting/integration/gregtech/VeinDatabase.java @@ -22,7 +22,7 @@ public Optional 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(); } diff --git a/src/main/java/com/sinthoras/visualprospecting/integration/model/locations/OreVeinLocation.java b/src/main/java/com/sinthoras/visualprospecting/integration/model/locations/OreVeinLocation.java index 3ce125b..893d064 100644 --- a/src/main/java/com/sinthoras/visualprospecting/integration/model/locations/OreVeinLocation.java +++ b/src/main/java/com/sinthoras/visualprospecting/integration/model/locations/OreVeinLocation.java @@ -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()); } @@ -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()); } diff --git a/src/main/java/com/sinthoras/visualprospecting/integration/voxelmap/VoxelMapEventHandler.java b/src/main/java/com/sinthoras/visualprospecting/integration/voxelmap/VoxelMapEventHandler.java index 80b4399..9718021 100644 --- a/src/main/java/com/sinthoras/visualprospecting/integration/voxelmap/VoxelMapEventHandler.java +++ b/src/main/java/com/sinthoras/visualprospecting/integration/voxelmap/VoxelMapEventHandler.java @@ -29,7 +29,7 @@ public void onVeinProspected(ProspectingNotificationEvent.OreVein event) { TreeSet 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 diff --git a/src/main/java/com/sinthoras/visualprospecting/mixins/late/gregtech/GT_MetaTileEntity_ScannerMixin.java b/src/main/java/com/sinthoras/visualprospecting/mixins/late/gregtech/GT_MetaTileEntity_ScannerMixin.java index a7c589f..bb10f0a 100644 --- a/src/main/java/com/sinthoras/visualprospecting/mixins/late/gregtech/GT_MetaTileEntity_ScannerMixin.java +++ b/src/main/java/com/sinthoras/visualprospecting/mixins/late/gregtech/GT_MetaTileEntity_ScannerMixin.java @@ -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) From 642fdc380da1dd824ab5f017e2d18154a74302d7 Mon Sep 17 00:00:00 2001 From: Lyfts <127234178+Lyfts@users.noreply.github.com> Date: Fri, 27 Sep 2024 18:46:09 +0200 Subject: [PATCH 2/4] the Math.max/min's are inside VeinType now --- .../visualprospecting/database/veintypes/VeinTypeCaching.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/sinthoras/visualprospecting/database/veintypes/VeinTypeCaching.java b/src/main/java/com/sinthoras/visualprospecting/database/veintypes/VeinTypeCaching.java index d7f27f8..402fca4 100644 --- a/src/main/java/com/sinthoras/visualprospecting/database/veintypes/VeinTypeCaching.java +++ b/src/main/java/com/sinthoras/visualprospecting/database/veintypes/VeinTypeCaching.java @@ -71,8 +71,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())); } From 46fc47e604b199371e6e8bf09d3880e5c9a5f038 Mon Sep 17 00:00:00 2001 From: Lyfts <127234178+Lyfts@users.noreply.github.com> Date: Fri, 27 Sep 2024 23:15:23 +0200 Subject: [PATCH 3/4] highlight vein when vein name is searched in nei (again) --- .../visualprospecting/database/veintypes/VeinTypeCaching.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/sinthoras/visualprospecting/database/veintypes/VeinTypeCaching.java b/src/main/java/com/sinthoras/visualprospecting/database/veintypes/VeinTypeCaching.java index 402fca4..d2f92b3 100644 --- a/src/main/java/com/sinthoras/visualprospecting/database/veintypes/VeinTypeCaching.java +++ b/src/main/java/com/sinthoras/visualprospecting/database/veintypes/VeinTypeCaching.java @@ -3,6 +3,7 @@ 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; @@ -123,7 +124,8 @@ public static void recalculateNEISearch() { for (VeinType veinType : veinTypes) { if (veinType == VeinType.NO_VEIN) continue; if (isSearchActive && !searchString.isEmpty()) { - List searchableStrings = veinType.getOreMaterialNames(); + List 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()); From e34f38f2853d02ecdf23f47cc3ae1dacf166fbc0 Mon Sep 17 00:00:00 2001 From: Martin Robertz Date: Sat, 28 Sep 2024 16:55:53 +0200 Subject: [PATCH 4/4] update --- dependencies.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dependencies.gradle b/dependencies.gradle index b5d8d48..22f3792 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -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')) }