Mahyar Khan
๐Ÿ“Ž 1 file 1,672 chars
๐Ÿ“„
pasted-code-1791057293770.txt
txt 58 lines
โ–ถ
Act as an expert Minecraft Java/Fabric developer.

Create a production-quality client-side FPS optimization mod for Minecraft 1.21.11 using Fabric, Fabric Loom, Yarn mappings, and Java 21.

Goal

Optimize distant Block Entity rendering (chests, furnaces, barrels, signs, etc.) using a Mixin targeting the 1.21.11 Block Entity rendering pipeline.

Rendering rules
0โ€“24 blocks: 100% visible
24โ€“32 blocks: smoothly fade out
32+ blocks: completely culled
Use squared distance only:
dx*dx + dy*dy + dz*dz
Never use Math.sqrt() in the render loop.
Fade with smoothstep:
t*t*(3-2*t)
Clamp t to 0โ€“1.
Performance

Keep the hot path extremely lightweight:

No allocations
No streams/lambdas
No unnecessary calculations
Early return when possible
Cache configurable values
Avoid unnecessary matrix/render-state operations
Rendering API

Use the actual Minecraft 1.21.11 rendering API. Do NOT blindly use old RenderSystem.setShaderColor() techniques.

Minecraft 1.21.11 uses the newer Block Entity render-state/command-queue system, so adapt the implementation accordingly. Do not use outdated pre-1.21 rendering methods.

Prevent render-state leaks and restore any state you modify.

Compatibility

Explain compatibility with:

Vanilla
Sodium
Other client rendering mods

Avoid conflicts where possible.

Output

Provide:

Complete Java source/Mixins
mymod.mixins.json
fabric.mod.json
Minimal build.gradle, gradle.properties, and settings.gradle
Project structure
Build/install instructions

Critical: Do not invent Minecraft 1.21.11 method names, fields, or mappings. Use verified 1.21.11 Yarn signatures. If a signature must be checked locally, clearly mark it instead of guessing.
Kodari AI
KodariOct 3 at 8:18 pm 2
BlockEntityFadeCuller
Client-side Fabric mod for Minecraft 1.21.11 that optimizes distant block entity rendering. Uses a Mixin targeting the block entity render pipeline to fade out entities between 24-32 blocks using smoothstep interpolation and cull them beyond 32 blocks. Uses squared distance calculations without Math.sqrt() for performance. Integrates with the modern render-state/command-queue API, prevents render-state leaks, and maintains compatibility with vanilla, Sodium, and other rendering mods. Includes configurable caching and lightweight hot-path optimizations with no allocations or streams.
  1. Verify the 1.21.11 block-entity render pipeline and the least-conflicting mixin hook.

  2. Create the client mod, mixin, metadata, and minimal Gradle project files.

Created the Fabric 1.21.11 project with a client-side mixin that uses squared distance and culls block-entity renders at 32 blocks or farther.

Important limitation: this implementation does not provide the requested 24โ€“32 block smooth fade. The shared deferred render queue has no universal opacity control, and alpha tint alone does not fade models using opaque render pipelines. The 24โ€“32 block band therefore remains fully visible until the 32-block cull boundary; claiming otherwise would be misleading.

Compatibility: Vanilla block entities rendered through BlockEntityRenderManager are covered. Sodium or another rendering mod may alter or bypass that path, so compatibility isnโ€™t guaranteed. The mixin cancels rendering before the renderer runs and does not modify shared render state.

Project files: build.gradle, gradle.properties, settings.gradle, fabric.mod.json, dbeoptimizer.mixins.json, and the mixin under src/client/java/.

Compile and install: In Kodari, click Compile (or on phone, โ‹ฎ โ†’ Compile Project), click Compile in the window, then click Download when it succeeds. Install the downloaded JAR in a Minecraft 1.21.11 Fabric client with Fabric API installed.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
settings.gradle
Code
6 130
src/client/java/dev/kodari/dbeoptimizer/mixin/BlockEntityRenderManagerMixin.java
package dev.kodari.dbeoptimizer.mixin;

import net.minecraft.client.render.block.entity.BlockEntityRenderManager;
import net.minecraft.client.render.block.entity.state.BlockEntityRenderState;
import net.minecraft.util.math.Vec3d;
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.CallbackInfo;

@Mixin(BlockEntityRenderManager.class)
public abstract class BlockEntityRenderManagerMixin {
    private static final double MAX_RENDER_DISTANCE_SQUARED = 32.0 * 32.0;

    @Shadow
    private Vec3d cameraPos;

    @Inject(
            method = "render(Lnet/minecraft/client/render/block/entity/state/BlockEntityRenderState;Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/command/OrderedRenderCommandQueue;Lnet/minecraft/client/render/state/CameraRenderState;)V",
            at = @At("HEAD"),
            cancellable = true
    )
    private void dbeoptimizer$cullBeyondRange(BlockEntityRenderState renderState, CallbackInfo ci) {
        double dx = renderState.pos.getX() + 0.5 - this.cameraPos.x;
        double dy = renderState.pos.getY() + 0.5 - this.cameraPos.y;
        double dz = renderState.pos.getZ() + 0.5 - this.cameraPos.z;

        if (dx * dx + dy * dy + dz * dz >= MAX_RENDER_DISTANCE_SQUARED) {
            ci.cancel();
        }
    }
}