Private
Public Access
1
0

Changed ore Set to a HashMap and now keeping track of how many ore blocks there are. Removed Unique getMessage and instead just Shadowing the original.

This commit is contained in:
2025-05-27 00:59:58 +01:00
parent f752edf813
commit b90ff37dda

View File

@ -24,6 +24,7 @@ import net.minecraft.world.level.chunk.LevelChunkSection;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import java.util.*;
@ -42,7 +43,7 @@ public abstract class IGMineralTestingItemMixin extends IGGenericItem implements
* @reason Tweaking geologist pick usage logic.
*/
@Overwrite
public InteractionResult useOn(UseOnContext context) {
public @NotNull InteractionResult useOn(UseOnContext context) {
Player player = context.getPlayer();
ItemStack stack = context.getItemInHand();
if (player == null || !stack.getItem().equals(this)) {
@ -73,9 +74,9 @@ public abstract class IGMineralTestingItemMixin extends IGGenericItem implements
int sectionMin = level.getSectionIndex(minBuildHeight);
int sectionMax = level.getSectionIndex(maxBuildHeight);
Set<MaterialInterface<?>> oreSet = new HashSet<>();
HashMap<MaterialInterface<?>, Integer> oreMap = new HashMap<>();
TagKey<Block> allOresTag = BlockCategoryFlags.ORE_BLOCK.getCategoryTag();
chunkScan: for (int dx = -1; dx <= 1; dx++) {
for (int dx = -1; dx <= 1; dx++) {
for (int dz = -1; dz <= 1; dz++) {
ChunkAccess chunk = level.getChunk(centerChunkX + dx, centerChunkZ + dz);
@ -96,10 +97,7 @@ public abstract class IGMineralTestingItemMixin extends IGGenericItem implements
BlockState blockState = section.getBlockState(x, y, z);
if (blockState.is(allOresTag)) {
IOreBlock ore = (IOreBlock) blockState.getBlock();
oreSet.add(ore.getOreMaterial());
if (oreSet.size() >= 3) {
break chunkScan;
}
oreMap.put(ore.getOreMaterial(), oreMap.getOrDefault(ore.getOreMaterial(), 0) + 1);
}
}
}
@ -108,7 +106,7 @@ public abstract class IGMineralTestingItemMixin extends IGGenericItem implements
}
}
Component message = geologist_pick_tweaks_1_20_1$getMessage(oreSet);
Component message = getMessage(oreMap.keySet());
player.displayClientMessage(message, true);
geologist_pick_tweaks_1_20_1$mineralCache.put(centerChunkPos, cachedEntry);
@ -116,30 +114,9 @@ public abstract class IGMineralTestingItemMixin extends IGGenericItem implements
return InteractionResult.SUCCESS;
}
@Unique
private static @NotNull Component geologist_pick_tweaks_1_20_1$getMessage(Set<MaterialInterface<?>> oreSet) {
Component message;
if (oreSet.isEmpty()) {
message = Component.translatable("immersivegeology.prospecting_pick.nothing");
} else {
List<MaterialInterface<?>> found = new ArrayList<>(oreSet);
String messageKey = "immersivegeology.prospecting_pick.found";
String materialsText;
switch (found.size()) {
case 1:
materialsText = "Found Traces of " + found.get(0);
break;
case 2:
materialsText = "Found Traces of " + found.get(0) + " and " + found.get(1);
break;
default: // 3 or more
materialsText = "Found Cluster of " + found.get(0) + ", " + found.get(1) + " and " + found.get(2);
break;
}
message = Component.translatable(messageKey, materialsText);
}
return message;
@Shadow
@NotNull
private static Component getMessage(Set<MaterialInterface<?>> oreSet) {
return Component.empty();
}
}