Skip to content

Commit 6c85449

Browse files
committed
Rewrite testmod debug renderer to be cooler
1 parent 365eb80 commit 6c85449

File tree

5 files changed

+100
-1
lines changed

5 files changed

+100
-1
lines changed

fabric/testmod/src/main/java/org/embeddedt/modernfix/testmod/TestMod.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,23 @@
44
import net.fabricmc.api.ModInitializer;
55
import net.minecraft.core.Registry;
66
import net.minecraft.resources.ResourceLocation;
7+
import net.minecraft.world.level.block.Blocks;
8+
import net.minecraft.world.level.block.state.BlockState;
79
import org.apache.logging.log4j.LogManager;
810
import org.apache.logging.log4j.Logger;
911

12+
import java.util.ArrayList;
13+
import java.util.List;
14+
1015
public class TestMod implements ModInitializer {
1116
public static final String ID = "mfix_testmod";
1217
public static final Logger LOGGER = LogManager.getLogger("ModernFix TestMod");
1318

14-
public static final int NUM_COLORS = 32;
19+
public static final int NUM_COLORS = 100;
1520
public static final int MAX_COLOR = NUM_COLORS - 1;
1621

22+
public static final List<BlockState> WOOL_STATES = new ArrayList<>();
23+
1724
@Override
1825
public void onInitialize() {
1926
// Register 1 million blocks & items
@@ -26,6 +33,7 @@ public void onInitialize() {
2633
for(int b = 0; b < NUM_COLORS; b++) {
2734
ResourceLocation name = new ResourceLocation(ID, "wool_" + r + "_" + g + "_" + b);
2835
TestBlock block = Registry.register(Registry.BLOCK, name, new TestBlock());
36+
WOOL_STATES.add(block.defaultBlockState());
2937
Registry.register(Registry.ITEM, name, new TestBlockItem(block));
3038
numRegistered++;
3139
if((numRegistered % progressReport) == 0) {
@@ -37,4 +45,20 @@ public void onInitialize() {
3745
watch.stop();
3846
LOGGER.info("Registered {} registry entries in {}", totalToRegister, watch);
3947
}
48+
49+
private static final BlockState AIR = Blocks.AIR.defaultBlockState();
50+
51+
public static BlockState getColorCubeStateFor(int chunkX, int chunkY, int chunkZ) {
52+
BlockState blockState = AIR;
53+
if (chunkX >= 0 && chunkY >= 0 && chunkZ >= 0 && chunkX % 2 == 0 && chunkY % 2 == 0 && chunkZ % 2 == 0) {
54+
chunkX /= 2;
55+
chunkY /= 2;
56+
chunkZ /= 2;
57+
if(chunkX <= TestMod.MAX_COLOR && chunkY <= TestMod.MAX_COLOR && chunkZ <= TestMod.MAX_COLOR) {
58+
blockState = TestMod.WOOL_STATES.get((chunkX * TestMod.NUM_COLORS * TestMod.NUM_COLORS) + (chunkY * TestMod.NUM_COLORS) + chunkZ);
59+
}
60+
}
61+
62+
return blockState;
63+
}
4064
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package org.embeddedt.modernfix.testmod.mixin;
2+
3+
import net.minecraft.core.BlockPos;
4+
import net.minecraft.world.level.Level;
5+
import net.minecraft.world.level.block.state.BlockState;
6+
import net.minecraft.world.level.chunk.LevelChunk;
7+
import org.embeddedt.modernfix.testmod.TestMod;
8+
import org.spongepowered.asm.mixin.Final;
9+
import org.spongepowered.asm.mixin.Mixin;
10+
import org.spongepowered.asm.mixin.Shadow;
11+
import org.spongepowered.asm.mixin.injection.At;
12+
import org.spongepowered.asm.mixin.injection.Inject;
13+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
14+
15+
@Mixin(LevelChunk.class)
16+
public class ChunkMixin {
17+
@Shadow @Final private Level level;
18+
19+
@Inject(method = "getBlockState", at = @At("HEAD"), cancellable = true)
20+
private void redirectDebugWorld(BlockPos pos, CallbackInfoReturnable<BlockState> cir) {
21+
if(this.level.isDebug()) {
22+
cir.setReturnValue(TestMod.getColorCubeStateFor(pos.getX(), pos.getY(), pos.getZ()));
23+
}
24+
}
25+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package org.embeddedt.modernfix.testmod.mixin;
2+
3+
import net.minecraft.core.BlockPos;
4+
import net.minecraft.server.level.WorldGenRegion;
5+
import net.minecraft.world.level.StructureFeatureManager;
6+
import net.minecraft.world.level.block.state.BlockState;
7+
import net.minecraft.world.level.levelgen.DebugLevelSource;
8+
import org.embeddedt.modernfix.testmod.TestMod;
9+
import org.spongepowered.asm.mixin.Mixin;
10+
import org.spongepowered.asm.mixin.injection.At;
11+
import org.spongepowered.asm.mixin.injection.Inject;
12+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
13+
14+
@Mixin(DebugLevelSource.class)
15+
public class DebugLevelSourceMixin {
16+
@Inject(method = "applyBiomeDecoration", at = @At("HEAD"), cancellable = true)
17+
private void showColorCube(WorldGenRegion region, StructureFeatureManager structureManager, CallbackInfo ci) {
18+
ci.cancel();
19+
BlockPos.MutableBlockPos mutableBlockPos = new BlockPos.MutableBlockPos();
20+
int i = region.getCenterX();
21+
int j = region.getCenterZ();
22+
23+
for(int k = 0; k < 16; ++k) {
24+
for(int l = 0; l < 16; ++l) {
25+
int m = (i << 4) + k;
26+
int n = (j << 4) + l;
27+
for(int y = 0; y < 255; y++) {
28+
BlockState blockState = TestMod.getColorCubeStateFor(m, y, n);
29+
if (blockState != null) {
30+
region.setBlock(mutableBlockPos.set(m, y, n), blockState, 2);
31+
}
32+
}
33+
}
34+
}
35+
}
36+
}

fabric/testmod/src/main/resources/fabric.mod.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
},
1515
"license": "LGPL-3.0",
1616
"environment": "*",
17+
"mixins": [ "testmod.mixins.json" ],
1718
"entrypoints": {
1819
"main": [
1920
"org.embeddedt.modernfix.testmod.TestMod"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"required": true,
3+
"package": "org.embeddedt.modernfix.testmod.mixin",
4+
"compatibilityLevel": "JAVA_8",
5+
"minVersion": "0.8",
6+
"mixins": [
7+
"ChunkMixin",
8+
"DebugLevelSourceMixin"
9+
],
10+
"injectors": {
11+
"defaultRequire": 1
12+
}
13+
}

0 commit comments

Comments
 (0)