From cac291df476e0ab1932c2078610e988500f27e31 Mon Sep 17 00:00:00 2001 From: embeddedt <42941056+embeddedt@users.noreply.github.com> Date: Wed, 9 Aug 2023 19:51:59 -0400 Subject: [PATCH 1/4] Add minor Brigadier patch to limit suggestion count to 10000 Fixes lag when there are many items registered --- .../SuggestionsBuilderMixin.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 fabric/src/main/java/org/embeddedt/modernfix/fabric/mixin/perf/faster_command_suggestions/SuggestionsBuilderMixin.java diff --git a/fabric/src/main/java/org/embeddedt/modernfix/fabric/mixin/perf/faster_command_suggestions/SuggestionsBuilderMixin.java b/fabric/src/main/java/org/embeddedt/modernfix/fabric/mixin/perf/faster_command_suggestions/SuggestionsBuilderMixin.java new file mode 100644 index 000000000..e27b04802 --- /dev/null +++ b/fabric/src/main/java/org/embeddedt/modernfix/fabric/mixin/perf/faster_command_suggestions/SuggestionsBuilderMixin.java @@ -0,0 +1,30 @@ +package org.embeddedt.modernfix.fabric.mixin.perf.faster_command_suggestions; + +import com.mojang.brigadier.suggestion.Suggestion; +import com.mojang.brigadier.suggestion.SuggestionsBuilder; +import org.spongepowered.asm.mixin.*; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +import java.util.List; + +/** + * Simple hack-fix to limit the number of suggestions being processed. Not a perfect fix but mitigates lag decently + * on an i3-4150. + */ +@Mixin(SuggestionsBuilder.class) +public class SuggestionsBuilderMixin { + @Unique + private static final int MAX_SUGGESTIONS = 10000; + + @Shadow @Final @Mutable + private List result; + + @Redirect(method = "*", at = @At(value = "INVOKE", target = "Ljava/util/List;add(Ljava/lang/Object;)Z"), require = 0) + private boolean addIfFits(List list, T entry) { + if(list != result || list.size() < MAX_SUGGESTIONS) { + return list.add(entry); + } + return false; + } +} From fed0392ddcf53d15e5d6ef7be1156a96b7681f44 Mon Sep 17 00:00:00 2001 From: embeddedt <42941056+embeddedt@users.noreply.github.com> Date: Wed, 9 Aug 2023 20:07:59 -0400 Subject: [PATCH 2/4] Introduce test mod --- common/build.gradle | 2 +- fabric/testmod/build.gradle | 26 +++++++++++++++++++ .../embeddedt/modernfix/testmod/TestMod.java | 10 +++++++ .../src/main/resources/fabric.mod.json | 22 ++++++++++++++++ settings.gradle | 10 +++++-- 5 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 fabric/testmod/build.gradle create mode 100644 fabric/testmod/src/main/java/org/embeddedt/modernfix/testmod/TestMod.java create mode 100644 fabric/testmod/src/main/resources/fabric.mod.json diff --git a/common/build.gradle b/common/build.gradle index ab51f2360..c067d1573 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -11,7 +11,7 @@ dependencies { // Do NOT use other classes from fabric loader modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}" - modApi("dev.latvian.mods:kubejs:${kubejs_version}") { + modCompileOnly("dev.latvian.mods:kubejs:${kubejs_version}") { transitive = false } // Remove the next line if you don't want to depend on the API diff --git a/fabric/testmod/build.gradle b/fabric/testmod/build.gradle new file mode 100644 index 000000000..580342537 --- /dev/null +++ b/fabric/testmod/build.gradle @@ -0,0 +1,26 @@ +apply plugin: "dev.architectury.loom" + +dependencies { + minecraft "com.mojang:minecraft:${rootProject.minecraft_version}" + mappings loom.layered() { + officialMojangMappings() + if(rootProject.hasProperty("parchment_version")) { + parchment("org.parchmentmc.data:parchment-${minecraft_version}:${parchment_version}@zip") + } + } + + modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}" + modImplementation(fabricApi.module("fabric-resource-loader-v0", rootProject.fabric_api_version)) { exclude group: 'net.fabricmc', module: 'fabric-loader' } + + implementation project(path: ":common", configuration: "namedElements") + implementation project(path: ":fabric", configuration: "namedElements") +} + +processResources { + inputs.property "version", project.version + + filesMatching("fabric.mod.json") { + expand "version": project.version + } +} + diff --git a/fabric/testmod/src/main/java/org/embeddedt/modernfix/testmod/TestMod.java b/fabric/testmod/src/main/java/org/embeddedt/modernfix/testmod/TestMod.java new file mode 100644 index 000000000..fb06e5a75 --- /dev/null +++ b/fabric/testmod/src/main/java/org/embeddedt/modernfix/testmod/TestMod.java @@ -0,0 +1,10 @@ +package org.embeddedt.modernfix.testmod; + +import net.fabricmc.api.ModInitializer; + +public class TestMod implements ModInitializer { + @Override + public void onInitialize() { + System.out.println("Hello ModernFix world!"); + } +} diff --git a/fabric/testmod/src/main/resources/fabric.mod.json b/fabric/testmod/src/main/resources/fabric.mod.json new file mode 100644 index 000000000..4677a1c6c --- /dev/null +++ b/fabric/testmod/src/main/resources/fabric.mod.json @@ -0,0 +1,22 @@ +{ + "schemaVersion": 1, + "id": "mfix_testmod", + "version": "${version}", + "name": "ModernFix test mod", + "description": "Test mod used to validate features and behaviors of ModernFix, the essential Minecraft performance mod", + "authors": [ + "embeddedt" + ], + "contact": { + "sources": "https://github.com/embeddedt/ModernFix", + "homepage": "https://modrinth.com/mod/modernfix", + "issues": "https://github.com/embeddedt/ModernFix/issues" + }, + "license": "LGPL-3.0", + "environment": "*", + "entrypoints": { + "main": [ + "org.embeddedt.modernfix.testmod.TestMod" + ] + } +} \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 739e778f5..c5b39d7cf 100644 --- a/settings.gradle +++ b/settings.gradle @@ -10,8 +10,14 @@ pluginManagement { include("test_agent") include("common") -getProperty("enabled_platforms").tokenize(',').each { it -> - include(it.trim()) +def current_platforms = getProperty("enabled_platforms").tokenize(',') +current_platforms.each { it -> + def platform_name = it.trim() + include(platform_name) + def testmodFolder = new File(platform_name + "/" + "testmod") + if(testmodFolder.isDirectory()) { + include(platform_name + ":testmod") + } } rootProject.name = 'modernfix' From 365eb80a285a207aeb7d2f17e4f5c487855b67aa Mon Sep 17 00:00:00 2001 From: embeddedt <42941056+embeddedt@users.noreply.github.com> Date: Wed, 9 Aug 2023 21:45:21 -0400 Subject: [PATCH 3/4] Testmod for many blocks/items test --- fabric/testmod/build.gradle | 7 + .../modernfix/testmod/TestBlock.java | 13 ++ .../modernfix/testmod/TestBlockItem.java | 13 ++ .../embeddedt/modernfix/testmod/TestMod.java | 32 +++- .../testmod/client/TestModBlockModel.java | 142 ++++++++++++++++++ .../testmod/client/TestModClient.java | 27 ++++ .../mfix_testmod/textures/block/base_wool.png | Bin 0 -> 560 bytes .../src/main/resources/fabric.mod.json | 3 + fabric/testmod/src/main/resources/pack.mcmeta | 7 + 9 files changed, 243 insertions(+), 1 deletion(-) create mode 100644 fabric/testmod/src/main/java/org/embeddedt/modernfix/testmod/TestBlock.java create mode 100644 fabric/testmod/src/main/java/org/embeddedt/modernfix/testmod/TestBlockItem.java create mode 100644 fabric/testmod/src/main/java/org/embeddedt/modernfix/testmod/client/TestModBlockModel.java create mode 100644 fabric/testmod/src/main/java/org/embeddedt/modernfix/testmod/client/TestModClient.java create mode 100644 fabric/testmod/src/main/resources/assets/mfix_testmod/textures/block/base_wool.png create mode 100644 fabric/testmod/src/main/resources/pack.mcmeta diff --git a/fabric/testmod/build.gradle b/fabric/testmod/build.gradle index 580342537..8e27f9b9f 100644 --- a/fabric/testmod/build.gradle +++ b/fabric/testmod/build.gradle @@ -1,5 +1,9 @@ apply plugin: "dev.architectury.loom" +loom { + accessWidenerPath = project(":common").loom.accessWidenerPath +} + dependencies { minecraft "com.mojang:minecraft:${rootProject.minecraft_version}" mappings loom.layered() { @@ -11,6 +15,9 @@ dependencies { modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}" modImplementation(fabricApi.module("fabric-resource-loader-v0", rootProject.fabric_api_version)) { exclude group: 'net.fabricmc', module: 'fabric-loader' } + modImplementation(fabricApi.module("fabric-models-v0", rootProject.fabric_api_version)) { exclude group: 'net.fabricmc', module: 'fabric-loader' } + modImplementation(fabricApi.module("fabric-renderer-api-v1", rootProject.fabric_api_version)) { exclude group: 'net.fabricmc', module: 'fabric-loader' } + modRuntimeOnly(fabricApi.module("fabric-renderer-indigo", rootProject.fabric_api_version)) { exclude group: 'net.fabricmc', module: 'fabric-loader' } implementation project(path: ":common", configuration: "namedElements") implementation project(path: ":fabric", configuration: "namedElements") diff --git a/fabric/testmod/src/main/java/org/embeddedt/modernfix/testmod/TestBlock.java b/fabric/testmod/src/main/java/org/embeddedt/modernfix/testmod/TestBlock.java new file mode 100644 index 000000000..c10b8c09f --- /dev/null +++ b/fabric/testmod/src/main/java/org/embeddedt/modernfix/testmod/TestBlock.java @@ -0,0 +1,13 @@ +package org.embeddedt.modernfix.testmod; + +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockBehaviour; + +public class TestBlock extends Block { + private static final BlockBehaviour.Properties PROPERTIES = BlockBehaviour.Properties.copy(Blocks.STONE); + + public TestBlock() { + super(PROPERTIES); + } +} diff --git a/fabric/testmod/src/main/java/org/embeddedt/modernfix/testmod/TestBlockItem.java b/fabric/testmod/src/main/java/org/embeddedt/modernfix/testmod/TestBlockItem.java new file mode 100644 index 000000000..cfc09cfaa --- /dev/null +++ b/fabric/testmod/src/main/java/org/embeddedt/modernfix/testmod/TestBlockItem.java @@ -0,0 +1,13 @@ +package org.embeddedt.modernfix.testmod; + +import net.minecraft.world.item.BlockItem; +import net.minecraft.world.item.CreativeModeTab; +import net.minecraft.world.item.Item; + +public class TestBlockItem extends BlockItem { + private static final Item.Properties PROPERTIES = new Item.Properties().tab(CreativeModeTab.TAB_BUILDING_BLOCKS); + + public TestBlockItem(TestBlock block) { + super(block, PROPERTIES); + } +} diff --git a/fabric/testmod/src/main/java/org/embeddedt/modernfix/testmod/TestMod.java b/fabric/testmod/src/main/java/org/embeddedt/modernfix/testmod/TestMod.java index fb06e5a75..f519edc53 100644 --- a/fabric/testmod/src/main/java/org/embeddedt/modernfix/testmod/TestMod.java +++ b/fabric/testmod/src/main/java/org/embeddedt/modernfix/testmod/TestMod.java @@ -1,10 +1,40 @@ package org.embeddedt.modernfix.testmod; +import com.google.common.base.Stopwatch; import net.fabricmc.api.ModInitializer; +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; 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 MAX_COLOR = NUM_COLORS - 1; + @Override public void onInitialize() { - System.out.println("Hello ModernFix world!"); + // Register 1 million blocks & items + Stopwatch watch = Stopwatch.createStarted(); + int totalToRegister = NUM_COLORS * NUM_COLORS * NUM_COLORS; + int progressReport = totalToRegister / 20; + int numRegistered = 0; + for(int r = 0; r < NUM_COLORS; r++) { + for(int g = 0; g < NUM_COLORS; g++) { + 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()); + Registry.register(Registry.ITEM, name, new TestBlockItem(block)); + numRegistered++; + if((numRegistered % progressReport) == 0) { + LOGGER.info(String.format("Registering... %.02f%%", ((float)numRegistered)/totalToRegister * 100)); + } + } + } + } + watch.stop(); + LOGGER.info("Registered {} registry entries in {}", totalToRegister, watch); } } diff --git a/fabric/testmod/src/main/java/org/embeddedt/modernfix/testmod/client/TestModBlockModel.java b/fabric/testmod/src/main/java/org/embeddedt/modernfix/testmod/client/TestModBlockModel.java new file mode 100644 index 000000000..a890f540f --- /dev/null +++ b/fabric/testmod/src/main/java/org/embeddedt/modernfix/testmod/client/TestModBlockModel.java @@ -0,0 +1,142 @@ +package org.embeddedt.modernfix.testmod.client; + +import com.google.common.collect.ImmutableList; +import com.mojang.datafixers.util.Pair; +import net.fabricmc.fabric.api.renderer.v1.Renderer; +import net.fabricmc.fabric.api.renderer.v1.RendererAccess; +import net.fabricmc.fabric.api.renderer.v1.mesh.Mesh; +import net.fabricmc.fabric.api.renderer.v1.mesh.MeshBuilder; +import net.fabricmc.fabric.api.renderer.v1.mesh.MutableQuadView; +import net.fabricmc.fabric.api.renderer.v1.mesh.QuadEmitter; +import net.fabricmc.fabric.api.renderer.v1.model.FabricBakedModel; +import net.fabricmc.fabric.api.renderer.v1.model.ModelHelper; +import net.fabricmc.fabric.api.renderer.v1.render.RenderContext; +import net.minecraft.client.renderer.block.model.BakedQuad; +import net.minecraft.client.renderer.block.model.ItemOverrides; +import net.minecraft.client.renderer.block.model.ItemTransforms; +import net.minecraft.client.renderer.texture.TextureAtlas; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.client.resources.model.*; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.BlockAndTintGetter; +import net.minecraft.world.level.block.state.BlockState; +import org.embeddedt.modernfix.testmod.TestMod; +import org.jetbrains.annotations.Nullable; + +import java.util.*; +import java.util.function.Function; +import java.util.function.Supplier; + +public class TestModBlockModel implements UnbakedModel, BakedModel, FabricBakedModel { + private static final Material BASE_WOOL = new Material(TextureAtlas.LOCATION_BLOCKS, new ResourceLocation(TestMod.ID, "block/base_wool")); + + private Mesh mesh; + private TextureAtlasSprite texture; + + private final int r, g, b; + + public TestModBlockModel(int r, int g, int b) { + this.r = r; + this.g = g; + this.b = b; + } + + @Override + public boolean isVanillaAdapter() { + return false; + } + + @Override + public void emitBlockQuads(BlockAndTintGetter blockView, BlockState state, BlockPos pos, Supplier randomSupplier, RenderContext context) { + context.meshConsumer().accept(mesh); + } + + @Override + public void emitItemQuads(ItemStack stack, Supplier randomSupplier, RenderContext context) { + context.meshConsumer().accept(mesh); + } + + @Override + public List getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand) { + return Collections.emptyList(); + } + + @Override + public boolean useAmbientOcclusion() { + return true; + } + + @Override + public boolean isGui3d() { + return true; + } + + @Override + public boolean usesBlockLight() { + return true; + } + + @Override + public boolean isCustomRenderer() { + return false; + } + + @Override + public TextureAtlasSprite getParticleIcon() { + return texture; + } + + @Override + public ItemTransforms getTransforms() { + return ModelHelper.MODEL_TRANSFORM_BLOCK; + } + + @Override + public ItemOverrides getOverrides() { + return ItemOverrides.EMPTY; + } + + @Override + public Collection getDependencies() { + return Collections.emptyList(); + } + + @Override + public Collection getMaterials(Function modelGetter, Set> missingTextureErrors) { + return ImmutableList.of(BASE_WOOL); + } + + private static int scaleColor(int c) { + return c * 255 / TestMod.MAX_COLOR; + } + + @Nullable + @Override + public BakedModel bake(ModelBakery modelBakery, Function spriteGetter, ModelState transform, ResourceLocation location) { + // Build the mesh using the Renderer API + Renderer renderer = RendererAccess.INSTANCE.getRenderer(); + MeshBuilder builder = renderer.meshBuilder(); + QuadEmitter emitter = builder.getEmitter(); + + texture = spriteGetter.apply(BASE_WOOL); + + for(Direction direction : Direction.values()) { + // Add a new face to the mesh + emitter.square(direction, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f); + // Set the sprite of the face, must be called after .square() + // We haven't specified any UV coordinates, so we want to use the whole texture. BAKE_LOCK_UV does exactly that. + emitter.spriteBake(0, texture, MutableQuadView.BAKE_LOCK_UV); + int color = (255 << 24) | (scaleColor(r) << 16) | (scaleColor(g) << 8) | scaleColor(b); + // Enable texture usage + emitter.spriteColor(0, color, color, color, color); + // Add the quad to the mesh + emitter.emit(); + } + mesh = builder.build(); + + return this; + } +} diff --git a/fabric/testmod/src/main/java/org/embeddedt/modernfix/testmod/client/TestModClient.java b/fabric/testmod/src/main/java/org/embeddedt/modernfix/testmod/client/TestModClient.java new file mode 100644 index 000000000..3bf0c36a7 --- /dev/null +++ b/fabric/testmod/src/main/java/org/embeddedt/modernfix/testmod/client/TestModClient.java @@ -0,0 +1,27 @@ +package org.embeddedt.modernfix.testmod.client; + +import net.fabricmc.api.ClientModInitializer; +import net.fabricmc.fabric.api.client.model.ModelLoadingRegistry; +import org.embeddedt.modernfix.testmod.TestMod; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class TestModClient implements ClientModInitializer { + private static final Pattern RGB_PATTERN = Pattern.compile("^wool_([0-9]+)_([0-9]+)_([0-9]+)$"); + @Override + public void onInitializeClient() { + ModelLoadingRegistry.INSTANCE.registerVariantProvider(resourceManager -> (modelId, context) -> { + if(modelId.getNamespace().equals(TestMod.ID)) { + Matcher matcher = RGB_PATTERN.matcher(modelId.getPath()); + if(matcher.matches()) { + int r = Integer.parseInt(matcher.group(1)); + int g = Integer.parseInt(matcher.group(2)); + int b = Integer.parseInt(matcher.group(3)); + return new TestModBlockModel(r, g, b); + } + } + return null; + }); + } +} diff --git a/fabric/testmod/src/main/resources/assets/mfix_testmod/textures/block/base_wool.png b/fabric/testmod/src/main/resources/assets/mfix_testmod/textures/block/base_wool.png new file mode 100644 index 0000000000000000000000000000000000000000..39d6ec76404abdab87916313c39fd0c779574fd1 GIT binary patch literal 560 zcmV-00?+-4P)EX>4Tx04R}tkv&MmP!xqvQ>CR;9PA+CkfAzR5EXIMDionYs1;guFnQ@8G-*gu zTpR`0f`dPcRRQHpmtPe_uLvW80Dz#(EMrcR((qkh_iiQb57W9>6uG1by3X52R1Q81AsGtfP2|9IBEM(|D>Ej=A{Svtpa#g^{ zv49#h$gUrJ2ETi26(=XWq-YZ8eQ}(R5g@b+v>J}{ee5``6B^euaHV(rwI(q0NqVEB z#gBmgZQ$a%qbYm9VN}D=(EtEdZ37*jE)}8x0000 Date: Wed, 9 Aug 2023 22:48:10 -0400 Subject: [PATCH 4/4] Rewrite testmod debug renderer to be cooler --- .../embeddedt/modernfix/testmod/TestMod.java | 26 +++++++++++++- .../modernfix/testmod/mixin/ChunkMixin.java | 25 +++++++++++++ .../testmod/mixin/DebugLevelSourceMixin.java | 36 +++++++++++++++++++ .../src/main/resources/fabric.mod.json | 1 + .../src/main/resources/testmod.mixins.json | 13 +++++++ 5 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 fabric/testmod/src/main/java/org/embeddedt/modernfix/testmod/mixin/ChunkMixin.java create mode 100644 fabric/testmod/src/main/java/org/embeddedt/modernfix/testmod/mixin/DebugLevelSourceMixin.java create mode 100644 fabric/testmod/src/main/resources/testmod.mixins.json diff --git a/fabric/testmod/src/main/java/org/embeddedt/modernfix/testmod/TestMod.java b/fabric/testmod/src/main/java/org/embeddedt/modernfix/testmod/TestMod.java index f519edc53..5ad72e50a 100644 --- a/fabric/testmod/src/main/java/org/embeddedt/modernfix/testmod/TestMod.java +++ b/fabric/testmod/src/main/java/org/embeddedt/modernfix/testmod/TestMod.java @@ -4,16 +4,23 @@ 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 WOOL_STATES = new ArrayList<>(); + @Override public void onInitialize() { // Register 1 million blocks & items @@ -26,6 +33,7 @@ public void onInitialize() { 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 void onInitialize() { 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; + } } diff --git a/fabric/testmod/src/main/java/org/embeddedt/modernfix/testmod/mixin/ChunkMixin.java b/fabric/testmod/src/main/java/org/embeddedt/modernfix/testmod/mixin/ChunkMixin.java new file mode 100644 index 000000000..1356aece6 --- /dev/null +++ b/fabric/testmod/src/main/java/org/embeddedt/modernfix/testmod/mixin/ChunkMixin.java @@ -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 cir) { + if(this.level.isDebug()) { + cir.setReturnValue(TestMod.getColorCubeStateFor(pos.getX(), pos.getY(), pos.getZ())); + } + } +} diff --git a/fabric/testmod/src/main/java/org/embeddedt/modernfix/testmod/mixin/DebugLevelSourceMixin.java b/fabric/testmod/src/main/java/org/embeddedt/modernfix/testmod/mixin/DebugLevelSourceMixin.java new file mode 100644 index 000000000..40d3eba96 --- /dev/null +++ b/fabric/testmod/src/main/java/org/embeddedt/modernfix/testmod/mixin/DebugLevelSourceMixin.java @@ -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); + } + } + } + } + } +} diff --git a/fabric/testmod/src/main/resources/fabric.mod.json b/fabric/testmod/src/main/resources/fabric.mod.json index 3188e5034..6ebb4d54e 100644 --- a/fabric/testmod/src/main/resources/fabric.mod.json +++ b/fabric/testmod/src/main/resources/fabric.mod.json @@ -14,6 +14,7 @@ }, "license": "LGPL-3.0", "environment": "*", + "mixins": [ "testmod.mixins.json" ], "entrypoints": { "main": [ "org.embeddedt.modernfix.testmod.TestMod" diff --git a/fabric/testmod/src/main/resources/testmod.mixins.json b/fabric/testmod/src/main/resources/testmod.mixins.json new file mode 100644 index 000000000..9eeb91ea8 --- /dev/null +++ b/fabric/testmod/src/main/resources/testmod.mixins.json @@ -0,0 +1,13 @@ +{ + "required": true, + "package": "org.embeddedt.modernfix.testmod.mixin", + "compatibilityLevel": "JAVA_8", + "minVersion": "0.8", + "mixins": [ + "ChunkMixin", + "DebugLevelSourceMixin" + ], + "injectors": { + "defaultRequire": 1 + } +} \ No newline at end of file