Skip to content

Commit

Permalink
Begin to work on rendering, kinda
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaming32 committed May 28, 2023
1 parent f700b36 commit 4421f31
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package com.fusionflux.portalcubed.accessor;

import net.minecraft.entity.Entity;
import net.minecraft.fluid.FluidState;
import net.minecraft.world.BlockView;

public interface CameraExt {
FluidState portalcubed$getSubmergedFluidState();

void updateSimple(BlockView area, Entity focusedEntity);
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.fusionflux.portalcubed.client.render.entity;

import com.fusionflux.portalcubed.accessor.CameraExt;
import com.fusionflux.portalcubed.client.render.entity.model.ExperimentalPortalModel;
import com.fusionflux.portalcubed.config.PortalCubedConfig;
import com.fusionflux.portalcubed.entity.ExperimentalPortal;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.VertexConsumer;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.Camera;
import net.minecraft.client.render.OverlayTexture;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.VertexConsumerProvider;
Expand All @@ -16,8 +19,11 @@
import net.minecraft.util.math.Vec3f;

import static com.fusionflux.portalcubed.PortalCubed.id;
import static org.lwjgl.opengl.GL11.*;

public class ExperimentalPortalRenderer extends EntityRenderer<ExperimentalPortal> {
private static final int MAX_PORTAL_LAYER = 0; // 1; // No recursive rendering yet
private static int portalLayer = 0;

private static final Identifier SQUARE_TEXTURE = id("textures/entity/portal_square_outline_closed.png");
private static final Identifier ROUND_TEXTURE = id("textures/entity/portal_oval_outline_closed.png");
Expand Down Expand Up @@ -54,18 +60,66 @@ public void render(ExperimentalPortal entity, float yaw, float tickDelta, Matrix
if (progress <= 1) {
matrices.scale(progress, progress, progress);
}
this.model.render(matrices, vertexConsumers.getBuffer(RenderLayer.getEntityTranslucentEmissive(this.getTexture(entity))), light, OverlayTexture.DEFAULT_UV, r, g, b, 1F);

renderPortal(matrices, vertexConsumers, entity, light, r, g, b, tickDelta);

matrices.pop();

if (MinecraftClient.getInstance().getEntityRenderDispatcher().shouldRenderHitboxes() && !entity.isInvisible() && !MinecraftClient.getInstance().hasReducedDebugInfo()) {
renderAxes(entity, matrices, vertexConsumers.getBuffer(RenderLayer.getLines()));
}
}

private void renderPortal(
MatrixStack matrices,
VertexConsumerProvider vertexConsumers,
ExperimentalPortal entity,
int light,
int r,
int g,
int b,
float tickDelta
) {
final boolean renderPortal = portalLayer < MAX_PORTAL_LAYER && entity.getActive();
if (renderPortal) {
RenderSystem.colorMask(false, false, false, false);
RenderSystem.depthMask(false);
RenderSystem.stencilFunc(GL_NEVER, 0, 0xff);
RenderSystem.stencilOp(GL_INCR, GL_KEEP, GL_KEEP);
RenderSystem.clear(GL_STENCIL_BUFFER_BIT, false);
}
model.render(matrices, vertexConsumers.getBuffer(RenderLayer.getEntityTranslucentEmissive(getTexture(entity))), light, OverlayTexture.DEFAULT_UV, r, g, b, 1F);
if (renderPortal) {
RenderSystem.colorMask(true, true, true, true);
RenderSystem.depthMask(true);
RenderSystem.stencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
RenderSystem.stencilFunc(GL_LEQUAL, 1, 0xff);

portalLayer++;
final MinecraftClient minecraft = MinecraftClient.getInstance();
final Camera camera = new Camera();
((CameraExt)camera).updateSimple(entity.world, entity);
minecraft.worldRenderer.render(
new MatrixStack(),
tickDelta,
0,
false,
camera,
minecraft.gameRenderer,
minecraft.gameRenderer.getLightmapTextureManager(),
matrices.peek().getModel()
);
portalLayer--;

RenderSystem.stencilFunc(GL_ALWAYS, 1, 0xff);
}
}

private void renderAxes(ExperimentalPortal entity, MatrixStack matrices, VertexConsumer vertices) {
final MatrixStack.Entry entry = matrices.peek();
renderAxis(entry, vertices, entity.getNormal());
entity.getAxisW().ifPresent(axisW -> renderAxis(entry, vertices, axisW));
entity.getAxisH().ifPresent(axisH -> renderAxis(entry, vertices, axisH));
// entity.getAxisW().ifPresent(axisW -> renderAxis(entry, vertices, axisW));
// entity.getAxisH().ifPresent(axisH -> renderAxis(entry, vertices, axisH));
}

private void renderAxis(MatrixStack.Entry entry, VertexConsumer vertices, Vec3d axis) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fusionflux.portalcubed.accessor.CameraExt;
import net.minecraft.client.render.Camera;
import net.minecraft.entity.Entity;
import net.minecraft.fluid.FluidState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockView;
Expand All @@ -17,8 +18,19 @@ public abstract class CameraMixin implements CameraExt {
@Final
private BlockPos.Mutable blockPos;

@Shadow private Entity focusedEntity;

@Shadow private boolean ready;

@Override
public FluidState portalcubed$getSubmergedFluidState() {
return this.area.getFluidState(blockPos);
}

@Override
public void updateSimple(BlockView area, Entity focusedEntity) {
this.area = area;
this.focusedEntity = focusedEntity;
ready = true;
}
}

0 comments on commit 4421f31

Please sign in to comment.