Skip to content

Commit 5e2f4b0

Browse files
committed
Added Aether Density information getter to Aspect Lens
1 parent d9a2d85 commit 5e2f4b0

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

src/main/java/dev/overgrown/thaumaturge/item/AspectLensItem.java

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
11
package dev.overgrown.thaumaturge.item;
22

3+
import dev.overgrown.aspectslib.aether.AetherDensity;
4+
import dev.overgrown.aspectslib.aether.AetherDensityManager;
5+
import dev.overgrown.aspectslib.aether.DynamicAetherDensityManager;
36
import net.minecraft.client.item.TooltipContext;
47
import net.minecraft.entity.player.PlayerEntity;
58
import net.minecraft.item.Item;
69
import net.minecraft.item.ItemStack;
710
import net.minecraft.text.Text;
811
import net.minecraft.util.Formatting;
12+
import net.minecraft.util.Hand;
13+
import net.minecraft.util.Identifier;
14+
import net.minecraft.util.TypedActionResult;
15+
import net.minecraft.util.math.BlockPos;
916
import net.minecraft.world.World;
1017
import org.jetbrains.annotations.Nullable;
1118

1219
import java.util.List;
20+
import java.util.Map;
1321

1422
public class AspectLensItem extends Item {
23+
private static final Identifier VITIUM_ASPECT = new Identifier("aspectslib", "vitium");
24+
1525
public AspectLensItem(Settings settings) {
1626
super(settings);
1727
}
@@ -22,6 +32,74 @@ public void appendTooltip(ItemStack stack, @Nullable World world, List<Text> too
2232
tooltip.add(Text.translatable("item.thaumaturge.aspect_lens.tooltip").formatted(Formatting.GRAY));
2333
}
2434

35+
@Override
36+
public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand) {
37+
ItemStack stack = user.getStackInHand(hand);
38+
39+
if (!world.isClient()) {
40+
// Get player position and biome information
41+
BlockPos pos = user.getBlockPos();
42+
43+
// Get current aether density
44+
AetherDensity density = AetherDensityManager.getDensity(world, pos);
45+
46+
// Get biome ID for dynamic modifications
47+
Identifier biomeId = world.getBiome(pos).getKey().orElseThrow().getValue();
48+
49+
// Get dynamic modifications
50+
Map<Identifier, Double> modifications = DynamicAetherDensityManager.getModifications(biomeId);
51+
52+
// Calculate vitium and total aspects
53+
double vitium = density.getDensity(VITIUM_ASPECT);
54+
double totalOtherAspects = 0.0;
55+
56+
for (Map.Entry<Identifier, Double> entry : density.getDensities().entrySet()) {
57+
if (!entry.getKey().equals(VITIUM_ASPECT)) {
58+
totalOtherAspects += entry.getValue();
59+
}
60+
}
61+
62+
// Send information to player
63+
user.sendMessage(Text.literal("=== Aether Density Report ===").formatted(Formatting.GOLD));
64+
user.sendMessage(Text.literal("Biome: " + biomeId.toString()));
65+
66+
// Display all aspects
67+
for (Map.Entry<Identifier, Double> entry : density.getDensities().entrySet()) {
68+
Formatting color = entry.getKey().equals(VITIUM_ASPECT) ? Formatting.RED : Formatting.GREEN;
69+
user.sendMessage(Text.literal(
70+
String.format("%s: %.2f", entry.getKey().getPath(), entry.getValue())
71+
).formatted(color));
72+
}
73+
74+
// Display corruption status
75+
user.sendMessage(Text.literal("---").formatted(Formatting.GRAY));
76+
user.sendMessage(Text.literal(String.format("Vitium (Corruption): %.2f", vitium)).formatted(Formatting.RED));
77+
user.sendMessage(Text.literal(String.format("Total Other Aspects: %.2f", totalOtherAspects)).formatted(Formatting.GREEN));
78+
79+
// Display corruption dominance
80+
if (vitium > totalOtherAspects) {
81+
user.sendMessage(Text.literal("Status: CORRUPTED").formatted(Formatting.DARK_RED));
82+
} else {
83+
user.sendMessage(Text.literal("Status: PURE").formatted(Formatting.DARK_GREEN));
84+
}
85+
86+
// Display dynamic modifications if any
87+
if (modifications != null && !modifications.isEmpty()) {
88+
user.sendMessage(Text.literal("---").formatted(Formatting.GRAY));
89+
user.sendMessage(Text.literal("Dynamic Modifications:").formatted(Formatting.BLUE));
90+
91+
for (Map.Entry<Identifier, Double> entry : modifications.entrySet()) {
92+
String change = entry.getValue() >= 0 ? "+" : "";
93+
user.sendMessage(Text.literal(
94+
String.format("%s: %s%.2f", entry.getKey().getPath(), change, entry.getValue())
95+
));
96+
}
97+
}
98+
}
99+
100+
return TypedActionResult.success(stack, world.isClient());
101+
}
102+
25103
public static boolean hasLens(PlayerEntity player) {
26104
if (player == null) return false;
27105

0 commit comments

Comments
 (0)