Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
import net.minecraft.client.gui.GuiGraphicsExtractor;
import net.minecraft.client.gui.render.TextureSetup;
import net.minecraft.client.renderer.RenderPipelines;
import net.minecraft.client.renderer.SubmitNodeCollector;
import net.minecraft.client.renderer.block.BlockAndTintGetter;
import net.minecraft.client.renderer.state.gui.BlitRenderState;
import net.minecraft.core.BlockPos;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.state.BlockState;
import org.joml.Matrix3x2f;
import org.jspecify.annotations.Nullable;

import java.util.function.BiConsumer;
import java.util.function.Supplier;

public class GuiRenderExtras {
Expand Down Expand Up @@ -296,7 +297,8 @@ public static void submitStructure(
glitched,
poseStack.last().copy(),
guiGraphicsExtractor.pose().get(new Matrix3x2f()),
guiGraphicsExtractor.peekScissorStack()
guiGraphicsExtractor.peekScissorStack(),
(BiConsumer<SubmitNodeCollector, PoseStack>) null
)
);
}
Expand Down Expand Up @@ -329,7 +331,8 @@ public static void submitStructure(
glitched,
pose3D,
guiGraphicsExtractor.pose().get(new Matrix3x2f()),
guiGraphicsExtractor.peekScissorStack()
guiGraphicsExtractor.peekScissorStack(),
(BiConsumer<SubmitNodeCollector, PoseStack>)null
)
);
}
Expand Down Expand Up @@ -360,4 +363,103 @@ public static void submitStructure(
pose3D
);
}

public static void submitStructure(
GuiGraphicsExtractor guiGraphicsExtractor,
BlockAndTintGetter structureAccess,
BlockPos startPos,
BlockPos endPos,
float x0,
float y0,
float x1,
float y1,
float scale,
boolean ambientOcclusion,
boolean glitched,
PoseStack poseStack,
BiConsumer<SubmitNodeCollector, PoseStack> drawAdditionalCallback
) {
guiGraphicsExtractor.submitPictureInPictureRenderState(
new StructurePipRenderingState(
structureAccess,
startPos,
endPos,
(int) x0,
(int) y0,
(int) x1,
(int) y1,
scale,
ambientOcclusion,
glitched,
poseStack.last().copy(),
guiGraphicsExtractor.pose().get(new Matrix3x2f()),
guiGraphicsExtractor.peekScissorStack(),
drawAdditionalCallback
)
);
}

public static void submitStructure(
GuiGraphicsExtractor guiGraphicsExtractor,
BlockAndTintGetter structureAccess,
BlockPos startPos,
BlockPos endPos,
float x0,
float y0,
float x1,
float y1,
float scale,
boolean ambientOcclusion,
boolean glitched,
PoseStack.Pose pose3D,
BiConsumer<SubmitNodeCollector, PoseStack> drawAdditionalCallback
) {
guiGraphicsExtractor.submitPictureInPictureRenderState(
new StructurePipRenderingState(
structureAccess,
startPos,
endPos,
(int) x0,
(int) y0,
(int) x1,
(int) y1,
scale,
ambientOcclusion,
glitched,
pose3D,
guiGraphicsExtractor.pose().get(new Matrix3x2f()),
guiGraphicsExtractor.peekScissorStack(),
drawAdditionalCallback
)
);
}

public static void submitStructure(
GuiGraphicsExtractor guiGraphicsExtractor,
BlockAndTintGetter structureAccess,
BlockPos startPos,
BlockPos endPos,
float x0,
float y0,
float x1,
float y1,
PoseStack.Pose pose3D,
BiConsumer<SubmitNodeCollector, PoseStack> drawAdditionalCallback
) {
submitStructure(
guiGraphicsExtractor,
structureAccess,
startPos,
endPos,
x0,
y0,
x1,
y1,
32.0f,
false,
false,
pose3D,
drawAdditionalCallback
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -147,25 +147,25 @@ protected void renderToTexture(StructurePipRenderingState renderState, PoseStack
}

bufferSource.endBatch();

RenderBuffers renderBuffers = minecraft.renderBuffers();
SubmitNodeStorage submitNodeStorage = new SubmitNodeStorage();
GameRenderer gameRenderer = minecraft.gameRenderer;
FeatureRenderDispatcher frd = new FeatureRenderDispatcher(
submitNodeStorage,
minecraft.getModelManager(),
renderBuffers.bufferSource(),
minecraft.getAtlasManager(),
renderBuffers.outlineBufferSource(),
renderBuffers.crumblingBufferSource(),
minecraft.font,
gameRenderer.getGameRenderState()
);
for (BlockPos blockPos : BlockPos.betweenClosed(renderState.startPos(), renderState.endPos())) {
BlockEntity blockEntity = level.getBlockEntity(blockPos);
if (blockEntity == null) continue;
BlockEntityRenderer blockEntityRenderer = minecraft.getBlockEntityRenderDispatcher().getRenderer(blockEntity);
if (blockEntityRenderer == null) continue;

RenderBuffers renderBuffers = minecraft.renderBuffers();
SubmitNodeStorage submitNodeStorage = new SubmitNodeStorage();
GameRenderer gameRenderer = minecraft.gameRenderer;
FeatureRenderDispatcher frd = new FeatureRenderDispatcher(
submitNodeStorage,
minecraft.getModelManager(),
renderBuffers.bufferSource(),
minecraft.getAtlasManager(),
renderBuffers.outlineBufferSource(),
renderBuffers.crumblingBufferSource(),
minecraft.font,
gameRenderer.getGameRenderState()
);
poseStack.pushPose();
poseStack.translate(blockPos.getX(), blockPos.getY(), blockPos.getZ());
BlockEntityRenderState blockEntityRenderState = blockEntityRenderer.createRenderState();
Expand All @@ -182,12 +182,19 @@ protected void renderToTexture(StructurePipRenderingState renderState, PoseStack
submitNodeStorage,
gameRenderer.getGameRenderState().levelRenderState.cameraRenderState
);
frd.renderAllFeatures();
poseStack.popPose();
}
if (renderState.drawAdditionalCallback() != null) {
renderState.drawAdditionalCallback().accept(submitNodeStorage, poseStack);
}
frd.renderAllFeatures();
bufferSource.endBatch();

poseStack.popPose();
poseStack.popPose();
if (!poseStack.isEmpty()) {
throw new IllegalStateException("Pose stack not empty");
}
if (renderState.glitched()) {
applyGlitchEffect(width, height);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@

import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.gui.navigation.ScreenRectangle;
import net.minecraft.client.renderer.SubmitNodeCollector;
import net.minecraft.client.renderer.block.BlockAndTintGetter;
import net.minecraft.client.renderer.state.gui.pip.PictureInPictureRenderState;
import net.minecraft.core.BlockPos;
import net.minecraft.util.Mth;
import org.jetbrains.annotations.ApiStatus;
import org.joml.Matrix3x2f;
import org.jspecify.annotations.Nullable;

import java.util.function.BiConsumer;

@ApiStatus.Internal
public record StructurePipRenderingState (
BlockAndTintGetter structureAccess,
BlockPos startPos,
Expand All @@ -23,9 +28,45 @@ public record StructurePipRenderingState (
PoseStack.Pose pose3D,
Matrix3x2f pose,
@Nullable ScreenRectangle scissorArea,
@Nullable ScreenRectangle bounds
@Nullable ScreenRectangle bounds,
@Nullable BiConsumer<SubmitNodeCollector, PoseStack> drawAdditionalCallback
) implements PictureInPictureRenderState {

public StructurePipRenderingState(
BlockAndTintGetter structureAccess,
BlockPos startPos,
BlockPos endPos,
int x0,
int y0,
int x1,
int y1,
float scale,
boolean ambientOcclusion,
boolean glitched,
PoseStack.Pose pose3D,
Matrix3x2f pose,
@Nullable ScreenRectangle scissorArea,
@Nullable BiConsumer<SubmitNodeCollector, PoseStack> drawAdditionalCallback
) {
this(
structureAccess,
startPos,
endPos,
x0,
y0,
x1,
y1,
scale,
ambientOcclusion,
glitched,
pose3D,
pose,
scissorArea,
PictureInPictureRenderState.getBounds(Mth.floor(x0), Mth.floor(y0), Mth.floor(x1), Mth.floor(y1), scissorArea),
drawAdditionalCallback
);
}

public StructurePipRenderingState(
BlockAndTintGetter structureAccess,
BlockPos startPos,
Expand All @@ -40,7 +81,42 @@ public StructurePipRenderingState(
PoseStack.Pose pose3D,
Matrix3x2f pose,
@Nullable ScreenRectangle scissorArea
){
) {
this(
structureAccess,
startPos,
endPos,
x0,
y0,
x1,
y1,
scale,
ambientOcclusion,
glitched,
pose3D,
pose,
scissorArea,
PictureInPictureRenderState.getBounds(Mth.floor(x0), Mth.floor(y0), Mth.floor(x1), Mth.floor(y1), scissorArea),
null
);
}

public StructurePipRenderingState(
BlockAndTintGetter structureAccess,
BlockPos startPos,
BlockPos endPos,
int x0,
int y0,
int x1,
int y1,
float scale,
boolean ambientOcclusion,
boolean glitched,
PoseStack.Pose pose3D,
Matrix3x2f pose,
@Nullable ScreenRectangle scissorArea,
@Nullable ScreenRectangle bounds
) {
this(
structureAccess,
startPos,
Expand All @@ -55,7 +131,8 @@ public StructurePipRenderingState(
pose3D,
pose,
scissorArea,
PictureInPictureRenderState.getBounds(Mth.floor(x0), Mth.floor(y0), Mth.floor(x1), Mth.floor(y1), scissorArea)
bounds,
null
);
}
}
Loading