Skip to content

Commit ce80d75

Browse files
quantum googles? (kinda broken)
1 parent 8aa5e53 commit ce80d75

9 files changed

Lines changed: 282 additions & 4 deletions

File tree

src/main/java/net/tcmfatbird/tutorialmod/TutorialMod.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import net.tcmfatbird.tutorialmod.feature.ChatMentions;
1717
import net.tcmfatbird.tutorialmod.feature.UraniumRadiationHandler;
1818
import net.tcmfatbird.tutorialmod.feature.TemporalRewindManager;
19+
import net.tcmfatbird.tutorialmod.feature.QuantumWavefunctionHandler;
1920
import net.tcmfatbird.tutorialmod.network.*;
2021
import net.tcmfatbird.tutorialmod.item.ModItemGroups;
2122
import net.tcmfatbird.tutorialmod.item.ModItems;
@@ -65,6 +66,7 @@ public void onInitialize() {
6566
ModOreGeneration.register();
6667
UraniumRadiationHandler.register();
6768
TemporalRewindManager.register();
69+
QuantumWavefunctionHandler.register();
6870
CustomCommands.register();
6971

7072
FuelRegistry.INSTANCE.add(ModItems.STARLIGHT_ASHES, 600);

src/main/java/net/tcmfatbird/tutorialmod/TutorialModClient.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import net.tcmfatbird.tutorialmod.feature.GeigerCounterClient;
1212
import net.tcmfatbird.tutorialmod.feature.GeigerHud;
1313
import net.tcmfatbird.tutorialmod.feature.TemporalRewindClientEffects;
14+
import net.tcmfatbird.tutorialmod.feature.QuantumVisionClient;
1415
import net.tcmfatbird.tutorialmod.gui.ClockScreen;
1516
import net.tcmfatbird.tutorialmod.item.ModItems;
1617
import net.tcmfatbird.tutorialmod.network.BlockHighlightPacket;
@@ -33,6 +34,7 @@ public class TutorialModClient implements ClientModInitializer {
3334
public void onInitializeClient() {
3435
GeigerHud.register();
3536
TemporalRewindClientEffects.register();
37+
QuantumVisionClient.register();
3638

3739
ClientPlayNetworking.registerGlobalReceiver(NearestUraniumPacket.ID, (payload, context) -> {
3840
context.client().execute(() -> {
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
package net.tcmfatbird.tutorialmod.feature;
2+
3+
import com.mojang.blaze3d.systems.RenderSystem;
4+
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
5+
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext;
6+
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents;
7+
import net.minecraft.block.BlockState;
8+
import net.minecraft.client.MinecraftClient;
9+
import net.minecraft.client.gui.DrawContext;
10+
import net.minecraft.client.render.*;
11+
import net.minecraft.client.render.RenderTickCounter;
12+
import net.minecraft.entity.EquipmentSlot;
13+
import net.minecraft.util.math.BlockPos;
14+
import net.minecraft.util.math.Vec3d;
15+
import net.tcmfatbird.tutorialmod.item.ModItems;
16+
import org.joml.Matrix4f;
17+
18+
public final class QuantumVisionClient {
19+
private static final int RADIUS = 16;
20+
private static final int XZ_STEP = 4;
21+
private static final int Y_STEP = 3;
22+
23+
private QuantumVisionClient() {}
24+
25+
public static void register() {
26+
HudRenderCallback.EVENT.register(QuantumVisionClient::renderOverlay);
27+
WorldRenderEvents.AFTER_ENTITIES.register(QuantumVisionClient::renderOreClouds);
28+
}
29+
30+
private static boolean active(MinecraftClient client) {
31+
return client.player != null
32+
&& client.world != null
33+
&& client.player.getEquippedStack(EquipmentSlot.HEAD).isOf(ModItems.WAVEFUNCTION_GOGGLES);
34+
}
35+
36+
private static void renderOverlay(DrawContext context, RenderTickCounter tickCounter) {
37+
MinecraftClient client = MinecraftClient.getInstance();
38+
if (!active(client)) return;
39+
40+
int width = context.getScaledWindowWidth();
41+
int height = context.getScaledWindowHeight();
42+
context.fill(0, 0, width, height, 0x3311FF44);
43+
context.drawText(client.textRenderer, "~ WAVEFUNCTION VISION ~", width / 2 - 58, 8, 0xCCFFCC, true);
44+
}
45+
46+
private static void renderOreClouds(WorldRenderContext context) {
47+
MinecraftClient client = MinecraftClient.getInstance();
48+
if (!active(client)) return;
49+
50+
Vec3d cam = context.camera().getPos();
51+
Matrix4f matrix = context.matrixStack().peek().getPositionMatrix();
52+
53+
RenderSystem.disableDepthTest();
54+
RenderSystem.enableBlend();
55+
RenderSystem.defaultBlendFunc();
56+
RenderSystem.setShader(GameRenderer::getPositionColorProgram);
57+
58+
Tessellator tessellator = Tessellator.getInstance();
59+
BufferBuilder buffer = tessellator.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR);
60+
61+
BlockPos center = client.player.getBlockPos();
62+
boolean wroteGeometry = false;
63+
64+
for (int x = center.getX() - RADIUS; x <= center.getX() + RADIUS; x += XZ_STEP) {
65+
for (int z = center.getZ() - RADIUS; z <= center.getZ() + RADIUS; z += XZ_STEP) {
66+
for (int y = center.getY() - 10; y <= center.getY() + 6; y += Y_STEP) {
67+
BlockPos anchor = new BlockPos(x, y, z);
68+
BlockState state = client.world.getBlockState(anchor);
69+
float chance = QuantumWavefunctionHandler.getCollapseChance(state, y);
70+
if (chance <= 0f) continue;
71+
72+
float patchRoll = QuantumWavefunctionHandler.positionRoll(anchor);
73+
if (patchRoll > chance * 2.2f) continue;
74+
75+
wroteGeometry = drawFluffyPatch(buffer, matrix, cam, anchor) || wroteGeometry;
76+
}
77+
}
78+
}
79+
80+
if (wroteGeometry) {
81+
BufferRenderer.drawWithGlobalProgram(buffer.end());
82+
}
83+
84+
RenderSystem.enableDepthTest();
85+
RenderSystem.disableBlend();
86+
}
87+
88+
private static boolean drawFluffyPatch(BufferBuilder buffer, Matrix4f matrix, Vec3d cam, BlockPos anchor) {
89+
boolean wrote = false;
90+
int blobs = 7 + Math.floorMod(anchor.getX() + anchor.getY() + anchor.getZ(), 5);
91+
92+
for (int i = 0; i < blobs; i++) {
93+
int sx = spread(anchor, i * 13 + 3);
94+
int sy = spread(anchor, i * 17 + 7) / 2;
95+
int sz = spread(anchor, i * 19 + 11);
96+
97+
float ox = sx * 0.22f;
98+
float oy = sy * 0.18f;
99+
float oz = sz * 0.22f;
100+
101+
float cx = anchor.getX() + 0.5f + ox;
102+
float cy = anchor.getY() + 0.45f + oy;
103+
float cz = anchor.getZ() + 0.5f + oz;
104+
105+
float size = 0.22f + (Math.abs(spread(anchor, i * 23 + 5)) * 0.015f);
106+
float alpha = 0.10f + (0.03f * i);
107+
108+
addCube(buffer, matrix,
109+
cx - (float) cam.x,
110+
cy - (float) cam.y,
111+
cz - (float) cam.z,
112+
size,
113+
1.0f, 1.0f, 1.0f, Math.min(alpha, 0.28f));
114+
wrote = true;
115+
}
116+
117+
return wrote;
118+
}
119+
120+
private static int spread(BlockPos pos, int salt) {
121+
int hash = pos.getX() * 73428767 ^ pos.getY() * 9127837 ^ pos.getZ() * 43828921 ^ salt;
122+
hash ^= (hash >>> 13);
123+
return Math.floorMod(hash, 9) - 4;
124+
}
125+
126+
private static void addCube(BufferBuilder buffer, Matrix4f matrix,
127+
float cx, float cy, float cz,
128+
float half,
129+
float r, float g, float b, float a) {
130+
float minX = cx - half;
131+
float maxX = cx + half;
132+
float minY = cy - half;
133+
float maxY = cy + half;
134+
float minZ = cz - half;
135+
float maxZ = cz + half;
136+
137+
quad(buffer, matrix, minX, minY, minZ, maxX, minY, minZ, maxX, maxY, minZ, minX, maxY, minZ, r, g, b, a);
138+
quad(buffer, matrix, minX, minY, maxZ, minX, maxY, maxZ, maxX, maxY, maxZ, maxX, minY, maxZ, r, g, b, a);
139+
140+
quad(buffer, matrix, minX, minY, minZ, minX, maxY, minZ, minX, maxY, maxZ, minX, minY, maxZ, r, g, b, a);
141+
quad(buffer, matrix, maxX, minY, minZ, maxX, minY, maxZ, maxX, maxY, maxZ, maxX, maxY, minZ, r, g, b, a);
142+
143+
quad(buffer, matrix, minX, maxY, minZ, maxX, maxY, minZ, maxX, maxY, maxZ, minX, maxY, maxZ, r, g, b, a);
144+
quad(buffer, matrix, minX, minY, minZ, minX, minY, maxZ, maxX, minY, maxZ, maxX, minY, minZ, r, g, b, a);
145+
}
146+
147+
private static void quad(BufferBuilder buffer, Matrix4f matrix,
148+
float x1, float y1, float z1,
149+
float x2, float y2, float z2,
150+
float x3, float y3, float z3,
151+
float x4, float y4, float z4,
152+
float r, float g, float b, float a) {
153+
buffer.vertex(matrix, x1, y1, z1).color(r, g, b, a);
154+
buffer.vertex(matrix, x2, y2, z2).color(r, g, b, a);
155+
buffer.vertex(matrix, x3, y3, z3).color(r, g, b, a);
156+
buffer.vertex(matrix, x4, y4, z4).color(r, g, b, a);
157+
}
158+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package net.tcmfatbird.tutorialmod.feature;
2+
3+
import net.fabricmc.fabric.api.event.player.PlayerBlockBreakEvents;
4+
import net.minecraft.block.Block;
5+
import net.minecraft.block.BlockState;
6+
import net.minecraft.block.Blocks;
7+
import net.minecraft.entity.EquipmentSlot;
8+
import net.minecraft.server.network.ServerPlayerEntity;
9+
import net.minecraft.sound.SoundCategory;
10+
import net.minecraft.sound.SoundEvents;
11+
import net.minecraft.util.math.BlockPos;
12+
import net.tcmfatbird.tutorialmod.block.ModBlocks;
13+
import net.tcmfatbird.tutorialmod.item.ModItems;
14+
15+
public final class QuantumWavefunctionHandler {
16+
private QuantumWavefunctionHandler() {}
17+
18+
public static void register() {
19+
PlayerBlockBreakEvents.BEFORE.register((world, player, pos, state, blockEntity) -> {
20+
if (!(player instanceof ServerPlayerEntity serverPlayer)) {
21+
return true;
22+
}
23+
24+
if (!isWearingGoggles(serverPlayer)) {
25+
return true;
26+
}
27+
28+
float chance = getCollapseChance(state, pos.getY());
29+
if (chance <= 0f) {
30+
return true;
31+
}
32+
33+
world.playSound(null, pos, SoundEvents.BLOCK_AMETHYST_BLOCK_RESONATE, SoundCategory.BLOCKS, 0.35f, 1.5f);
34+
35+
if (positionRoll(pos) < chance) {
36+
world.setBlockState(pos, getCollapsedOre(state, pos), Block.NOTIFY_ALL);
37+
}
38+
39+
return true;
40+
});
41+
}
42+
43+
public static float getCollapseChance(BlockState state, int y) {
44+
if (state.isOf(Blocks.STONE)) {
45+
return y < 24 ? 0.18f : 0.12f;
46+
}
47+
48+
if (state.isOf(Blocks.DEEPSLATE)) {
49+
return y < -24 ? 0.3f : 0.2f;
50+
}
51+
52+
return 0f;
53+
}
54+
55+
public static float positionRoll(BlockPos pos) {
56+
int hash = pos.getX() * 73428767 ^ pos.getY() * 9127837 ^ pos.getZ() * 43828921;
57+
hash ^= (hash >>> 13);
58+
return (hash & 0x7fffffff) / (float) Integer.MAX_VALUE;
59+
}
60+
61+
private static boolean isWearingGoggles(ServerPlayerEntity player) {
62+
return player.getEquippedStack(EquipmentSlot.HEAD).isOf(ModItems.WAVEFUNCTION_GOGGLES);
63+
}
64+
65+
private static Block getCollapsedOre(BlockState state, BlockPos pos) {
66+
int chooser = Math.floorMod(pos.getX() * 31 + pos.getY() * 17 + pos.getZ() * 13, 2);
67+
68+
if (state.isOf(Blocks.STONE)) {
69+
return (pos.getY() < 0 && chooser == 1) ? ModBlocks.URANIUM_ORE : ModBlocks.PINK_GARNET_ORE;
70+
}
71+
72+
if (state.isOf(Blocks.DEEPSLATE)) {
73+
return (pos.getY() < -16 && chooser == 1) ? ModBlocks.URANIUM_DEEPSLATE_ORE : ModBlocks.PINK_GARNET_DEEPSLATE_ORE;
74+
}
75+
76+
return Blocks.AIR;
77+
}
78+
}

src/main/java/net/tcmfatbird/tutorialmod/item/ModItemGroups.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public class ModItemGroups {
3030

3131
entries.add(ModItems.GEIGER_COUNTER);
3232
entries.add(ModItems.TEMPORAL_REWINDER);
33+
entries.add(ModItems.WAVEFUNCTION_GOGGLES);
3334
}).build());
3435

3536
public static final ItemGroup PINK_GARNET_BLOCKS_GROUP = Registry.register(Registries.ITEM_GROUP,

src/main/java/net/tcmfatbird/tutorialmod/item/ModItems.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package net.tcmfatbird.tutorialmod.item;
22

33
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
4-
import net.minecraft.item.Item;
5-
import net.minecraft.item.ItemGroups;
6-
import net.minecraft.item.ItemStack;
4+
import net.minecraft.item.*;
75
import net.minecraft.item.tooltip.TooltipType;
86
import net.minecraft.registry.Registries;
97
import net.minecraft.registry.Registry;
@@ -40,6 +38,15 @@ public void appendTooltip(ItemStack stack, TooltipContext context, List<Text> to
4038

4139
public static final Item TEMPORAL_REWINDER = registerItem("temporal_rewinder", new Item(new Item.Settings().maxCount(1)));
4240

41+
public static final Item WAVEFUNCTION_GOGGLES = registerItem("wavefunction_goggles", new ArmorItem(ArmorMaterials.CHAIN, ArmorItem.Type.HELMET, new Item.Settings()) {
42+
@Override
43+
public void appendTooltip(ItemStack stack, TooltipContext context, List<Text> tooltip, TooltipType type) {
44+
tooltip.add(Text.translatable("tooltip.tutorialmod.wavefunction_goggles"));
45+
super.appendTooltip(stack, context, tooltip, type);
46+
}
47+
});
48+
49+
4350
private static Item registerItem(String name, Item item) {
4451
return Registry.register(Registries.ITEM, Identifier.of(TutorialMod.MOD_ID, name), item);
4552
}
@@ -52,6 +59,7 @@ public static void registerModItems() {
5259
fabricItemGroupEntries.add(RAW_PINK_GARNET);
5360
fabricItemGroupEntries.add(GEIGER_COUNTER);
5461
fabricItemGroupEntries.add(TEMPORAL_REWINDER);
62+
fabricItemGroupEntries.add(WAVEFUNCTION_GOGGLES);
5563
});
5664
}
5765
}

src/main/resources/assets/tutorialmod/lang/en_us.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,8 @@
3535
"item.tutorialmod.temporal_rewinder": "Temporal Rewinder",
3636
"key.category.tutorialmod": "Tutorial Mod",
3737
"key.tutorialmod.clockgui": "Open Clock GUI",
38-
"key.tutorialmod.temporal_rewind": "Hold to Rewind Time"
38+
"key.tutorialmod.temporal_rewind": "Hold to Rewind Time",
39+
40+
"item.tutorialmod.wavefunction_goggles": "Wavefunction Vision Goggles",
41+
"tooltip.tutorialmod.wavefunction_goggles": "Potential ore clouds shimmer until observed. Mining collapses possibility into ore... or nothing."
3942
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"parent": "minecraft:item/generated",
3+
"textures": {
4+
"layer0": "tutorialmod:item/wavefunction_goggles"
5+
}
6+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"type": "minecraft:crafting_shaped",
3+
"show_notification": true,
4+
"category": "equipment",
5+
"key": {
6+
"G": {"item": "minecraft:glass_pane"},
7+
"R": {"item": "minecraft:redstone"},
8+
"U": {"item": "tutorialmod:uranium_ore"},
9+
"P": {"item": "tutorialmod:pink_garnet"}
10+
},
11+
"pattern": [
12+
"GPG",
13+
"R R",
14+
" U "
15+
],
16+
"result": {
17+
"count": 1,
18+
"id": "tutorialmod:wavefunction_goggles"
19+
}
20+
}

0 commit comments

Comments
 (0)