Rewrite testmod debug renderer to be cooler
This commit is contained in:
parent
365eb80a28
commit
6c85449b63
|
|
@ -4,16 +4,23 @@ import com.google.common.base.Stopwatch;
|
|||
import net.fabricmc.api.ModInitializer;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TestMod implements ModInitializer {
|
||||
public static final String ID = "mfix_testmod";
|
||||
public static final Logger LOGGER = LogManager.getLogger("ModernFix TestMod");
|
||||
|
||||
public static final int NUM_COLORS = 32;
|
||||
public static final int NUM_COLORS = 100;
|
||||
public static final int MAX_COLOR = NUM_COLORS - 1;
|
||||
|
||||
public static final List<BlockState> WOOL_STATES = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
// Register 1 million blocks & items
|
||||
|
|
@ -26,6 +33,7 @@ public class TestMod implements ModInitializer {
|
|||
for(int b = 0; b < NUM_COLORS; b++) {
|
||||
ResourceLocation name = new ResourceLocation(ID, "wool_" + r + "_" + g + "_" + b);
|
||||
TestBlock block = Registry.register(Registry.BLOCK, name, new TestBlock());
|
||||
WOOL_STATES.add(block.defaultBlockState());
|
||||
Registry.register(Registry.ITEM, name, new TestBlockItem(block));
|
||||
numRegistered++;
|
||||
if((numRegistered % progressReport) == 0) {
|
||||
|
|
@ -37,4 +45,20 @@ public class TestMod implements ModInitializer {
|
|||
watch.stop();
|
||||
LOGGER.info("Registered {} registry entries in {}", totalToRegister, watch);
|
||||
}
|
||||
|
||||
private static final BlockState AIR = Blocks.AIR.defaultBlockState();
|
||||
|
||||
public static BlockState getColorCubeStateFor(int chunkX, int chunkY, int chunkZ) {
|
||||
BlockState blockState = AIR;
|
||||
if (chunkX >= 0 && chunkY >= 0 && chunkZ >= 0 && chunkX % 2 == 0 && chunkY % 2 == 0 && chunkZ % 2 == 0) {
|
||||
chunkX /= 2;
|
||||
chunkY /= 2;
|
||||
chunkZ /= 2;
|
||||
if(chunkX <= TestMod.MAX_COLOR && chunkY <= TestMod.MAX_COLOR && chunkZ <= TestMod.MAX_COLOR) {
|
||||
blockState = TestMod.WOOL_STATES.get((chunkX * TestMod.NUM_COLORS * TestMod.NUM_COLORS) + (chunkY * TestMod.NUM_COLORS) + chunkZ);
|
||||
}
|
||||
}
|
||||
|
||||
return blockState;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,25 @@
|
|||
package org.embeddedt.modernfix.testmod.mixin;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.chunk.LevelChunk;
|
||||
import org.embeddedt.modernfix.testmod.TestMod;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(LevelChunk.class)
|
||||
public class ChunkMixin {
|
||||
@Shadow @Final private Level level;
|
||||
|
||||
@Inject(method = "getBlockState", at = @At("HEAD"), cancellable = true)
|
||||
private void redirectDebugWorld(BlockPos pos, CallbackInfoReturnable<BlockState> cir) {
|
||||
if(this.level.isDebug()) {
|
||||
cir.setReturnValue(TestMod.getColorCubeStateFor(pos.getX(), pos.getY(), pos.getZ()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
package org.embeddedt.modernfix.testmod.mixin;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.level.WorldGenRegion;
|
||||
import net.minecraft.world.level.StructureFeatureManager;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.levelgen.DebugLevelSource;
|
||||
import org.embeddedt.modernfix.testmod.TestMod;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(DebugLevelSource.class)
|
||||
public class DebugLevelSourceMixin {
|
||||
@Inject(method = "applyBiomeDecoration", at = @At("HEAD"), cancellable = true)
|
||||
private void showColorCube(WorldGenRegion region, StructureFeatureManager structureManager, CallbackInfo ci) {
|
||||
ci.cancel();
|
||||
BlockPos.MutableBlockPos mutableBlockPos = new BlockPos.MutableBlockPos();
|
||||
int i = region.getCenterX();
|
||||
int j = region.getCenterZ();
|
||||
|
||||
for(int k = 0; k < 16; ++k) {
|
||||
for(int l = 0; l < 16; ++l) {
|
||||
int m = (i << 4) + k;
|
||||
int n = (j << 4) + l;
|
||||
for(int y = 0; y < 255; y++) {
|
||||
BlockState blockState = TestMod.getColorCubeStateFor(m, y, n);
|
||||
if (blockState != null) {
|
||||
region.setBlock(mutableBlockPos.set(m, y, n), blockState, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -14,6 +14,7 @@
|
|||
},
|
||||
"license": "LGPL-3.0",
|
||||
"environment": "*",
|
||||
"mixins": [ "testmod.mixins.json" ],
|
||||
"entrypoints": {
|
||||
"main": [
|
||||
"org.embeddedt.modernfix.testmod.TestMod"
|
||||
|
|
|
|||
13
fabric/testmod/src/main/resources/testmod.mixins.json
Normal file
13
fabric/testmod/src/main/resources/testmod.mixins.json
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"required": true,
|
||||
"package": "org.embeddedt.modernfix.testmod.mixin",
|
||||
"compatibilityLevel": "JAVA_8",
|
||||
"minVersion": "0.8",
|
||||
"mixins": [
|
||||
"ChunkMixin",
|
||||
"DebugLevelSourceMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user