Loading visualization

- Fix up/comment out some touchy mixins.
- Get chests to render.
- There's something wrong with the projection matrix.
- Add comment to DebugMemoryBlockImpl's stack walker usage.
This commit is contained in:
Jozufozu 2023-11-23 22:48:29 -08:00
parent 90cfd967dc
commit 9f019fc72f
5 changed files with 45 additions and 13 deletions

View file

@ -49,6 +49,7 @@ import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.IExtensionPoint;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
@ -116,6 +117,10 @@ public class Flywheel {
ShadersModHandler.init();
modEventBus.addListener(Flywheel::lateInit);
}
private static void lateInit(final FMLClientSetupEvent event) {
VertexTypes.init();
InstanceTypes.init();
Materials.init();
@ -124,12 +129,12 @@ public class Flywheel {
MaterialIndices.init();
VanillaVisuals.init();
RegistryImpl.freezeAll();
IdRegistryImpl.freezeAll();
}
private static void setup(final FMLCommonSetupEvent event) {
RegistryImpl.freezeAll();
IdRegistryImpl.freezeAll();
ArgumentTypeInfos.registerByClass(BackendArgument.class, SingletonArgumentInfo.contextFree(() -> BackendArgument.INSTANCE));
}

View file

@ -23,6 +23,12 @@ class DebugMemoryBlockImpl extends MemoryBlockImpl {
}
static StackWalker.StackFrame[] getStackTrace() {
// skip 4 frames to get to the caller:
// - this method
// - DebugMemoryBlockImpl::new
// - DebugMemoryBlockImpl::malloc/calloc
// - MemoryBlock::malloc/calloc
// - {caller is here}
return StackWalker.getInstance().walk(s -> s.skip(4).toArray(StackWalker.StackFrame[]::new));
}

View file

@ -128,7 +128,7 @@ public class LevelRendererMixin {
flywheel$dispatch(RenderStage.AFTER_FINAL_END_BATCH);
}
@Inject(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/LevelRenderer;renderChunkLayer(Lnet/minecraft/client/renderer/RenderType;Lcom/mojang/blaze3d/vertex/PoseStack;DDDLcom/mojang/math/Matrix4f;)V", ordinal = 6, shift = Shift.AFTER))
@Inject(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/LevelRenderer;renderChunkLayer(Lnet/minecraft/client/renderer/RenderType;Lcom/mojang/blaze3d/vertex/PoseStack;DDDLorg/joml/Matrix4f;)V", ordinal = 6, shift = Shift.AFTER))
private void flywheel$onStage$afterTranslucentTerrain(CallbackInfo ci) {
flywheel$dispatch(RenderStage.AFTER_TRANSLUCENT_TERRAIN);
}

View file

@ -17,10 +17,10 @@ public class FixNormalScalingMixin {
* applied, which negates the matrix again, resulting in the matrix being the
* same as in the beginning.
*/
@Inject(method = "scale(FFF)V", at = @At(value = "INVOKE", target = "Lcom/mojang/math/Matrix3f;mul(F)V", shift = Shift.AFTER), cancellable = true)
private void flywheel$returnAfterNegate(float x, float y, float z, CallbackInfo ci) {
ci.cancel();
}
// @Inject(method = "scale(FFF)V", at = @At(value = "INVOKE", target = "Lcom/mojang/math/Matrix3f;mul(F)V", shift = Shift.AFTER), cancellable = true)
// private void flywheel$returnAfterNegate(float x, float y, float z, CallbackInfo ci) {
// ci.cancel();
// }
/**
* Minecraft takes the inverse cube root of the product of all scales to provide a

View file

@ -5,18 +5,39 @@ import java.util.Set;
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.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import com.jozufozu.flywheel.impl.visualization.VisualizationHelper;
import net.minecraft.client.renderer.chunk.ChunkRenderDispatcher;
import net.minecraft.client.renderer.chunk.RenderChunkRegion;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.entity.BlockEntity;
@Mixin(targets = "net.minecraft.client.renderer.chunk.SectionRenderDispatcher$RenderSection$RebuildTask")
@Mixin(targets = "net.minecraft.client.renderer.chunk.ChunkRenderDispatcher$RenderChunk$RebuildTask")
public class ChunkRebuildHooksMixin {
@Inject(method = "handleBlockEntity(Lnet/minecraft/client/renderer/chunk/SectionRenderDispatcher$RenderSection$RebuildTask$CompileResults;Lnet/minecraft/world/level/block/entity/BlockEntity;)V", at = @At("HEAD"), cancellable = true)
private <E extends BlockEntity> void flywheel$tryAddBlockEntity(Object pCompileResults, E pBlockEntity, CallbackInfo ci) {
if (VisualizationHelper.tryAddBlockEntity(pBlockEntity)) {
ci.cancel();
// FIXME: use this instead of the redirect if there's a clean way to reference the CompileResults
// @Inject(method = "handleBlockEntity(Lnet/minecraft/client/renderer/chunk/ChunkRenderDispatcher$RenderChunk$RebuildTask$CompileResults;Lnet/minecraft/world/level/block/entity/BlockEntity;)V", at = @At("HEAD"), cancellable = true)
// private <E extends BlockEntity> void flywheel$tryAddBlockEntity(Object pCompileResults, E pBlockEntity, CallbackInfo ci) {
// if (VisualizationHelper.tryAddBlockEntity(pBlockEntity)) {
// ci.cancel();
// }
// }
@Redirect(method = "compile", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/chunk/RenderChunkRegion;getBlockEntity(Lnet/minecraft/core/BlockPos;)Lnet/minecraft/world/level/block/entity/BlockEntity;"))
private BlockEntity flywheel$interceptGetBlockEntity(RenderChunkRegion region, BlockPos pos) {
BlockEntity blockEntity = region.getBlockEntity(pos);
if (blockEntity == null) {
return null;
}
if (VisualizationHelper.tryAddBlockEntity(blockEntity)) {
return null;
}
return blockEntity;
}
}