Skip to content

Commit

Permalink
No More Z-Fighting with EQUAL depth, but I wanna try with blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
Direwolf20-MC committed Feb 25, 2024
1 parent 713f656 commit eb422b9
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.direwolf20.justdirethings.client.blockentityrenders;

import com.direwolf20.justdirethings.JustDireThings;
import com.direwolf20.justdirethings.client.renderers.DireVertexConsumer;
import com.direwolf20.justdirethings.client.renderers.OurRenderTypes;
import com.direwolf20.justdirethings.common.blockentities.gooblocks.GooBlockBE_Base;
import com.direwolf20.justdirethings.setup.Registration;
Expand All @@ -12,24 +11,18 @@
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.block.BlockRenderDispatcher;
import net.minecraft.client.renderer.block.ModelBlockRenderer;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
import net.neoforged.neoforge.client.model.data.ModelData;
import org.joml.Matrix3f;
import org.joml.Matrix4f;

import java.util.BitSet;
import java.util.List;

public class GooBlockRender_Base<T extends GooBlockBE_Base> implements BlockEntityRenderer<T> {
public static final ResourceLocation[] patterns = {
new ResourceLocation(JustDireThings.MODID, "textures/misc/goorender1.png"),
Expand Down Expand Up @@ -62,7 +55,7 @@ public void render(T blockentity, float partialTicks, PoseStack matrixStackIn, M
int maxTicks = blockentity.getCraftingDuration();
renderTextures(Direction.UP, level, pos, matrixStackIn, bufferIn, combinedOverlayIn, renderState, ibakedmodel, modelBlockRenderer, remainingTicks, maxTicks);
}

renderTextures(Direction.UP, level, pos, matrixStackIn, bufferIn, combinedOverlayIn, renderState, ibakedmodel, modelBlockRenderer, 535, 1000);
//ResourceLocation patternLocation = new ResourceLocation(JustDireThings.MODID, "textures/misc/goorender4.png");
//renderTexturePattern(level, pos, matrixStackIn, bufferIn, combinedOverlayIn, 1, patternLocation, renderState, ibakedmodel, modelBlockRenderer);
//ResourceLocation patternLocation2 = new ResourceLocation(JustDireThings.MODID, "textures/misc/goorender6.png");
Expand All @@ -83,6 +76,8 @@ public void renderTextures(Direction direction, Level level, BlockPos pos, PoseS
}

public void renderTexturePattern(Direction direction, Level level, BlockPos pos, PoseStack matrixStackIn, MultiBufferSource bufferIn, int combinedOverlayIn, float transparency, ResourceLocation pattern, BlockState renderState, BakedModel ibakedmodel, ModelBlockRenderer modelBlockRenderer) {
OurRenderTypes.updateRenders();

matrixStackIn.pushPose();
matrixStackIn.translate(0, 1, 0); //Todo proper sidedness

Expand All @@ -98,10 +93,16 @@ public void renderTexturePattern(Direction direction, Level level, BlockPos pos,
renderQuad(matrix4f, matrix3f, vertexconsumer, 1f, 1f, 1f, 1f, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1);
matrixStackIn.popPose();

vertexconsumer = bufferIn.getBuffer(OurRenderTypes.gooPatternColor(patterns[8]));
matrixStackIn.pushPose();
matrixStackIn.translate(0, 0, -0.0002f);
matrixStackIn.translate(0, 0, -0.0003f);
PoseStack.Pose posestack$pose2 = matrixStackIn.last();
Matrix4f matrix4f2 = posestack$pose2.pose();
Matrix3f matrix3f2 = posestack$pose2.normal();

VertexConsumer builder = bufferIn.getBuffer(OurRenderTypes.RenderBlockBackface);
renderQuad(matrix4f2, matrix3f2, vertexconsumer, 1f, 1f, 1f, 1f, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1);

/*VertexConsumer builder = bufferIn.getBuffer(OurRenderTypes.RenderBlockBackface);
DireVertexConsumer chunksConsumer = new DireVertexConsumer(builder, transparency);
float[] afloat = new float[Direction.values().length * 2];
Expand All @@ -119,7 +120,7 @@ public void renderTexturePattern(Direction direction, Level level, BlockPos pos,
if (!list.isEmpty()) {
blockpos$mutableblockpos.setWithOffset(pos, renderSide);
modelBlockRenderer.renderModelFaceAO(level, renderState, pos, matrixStackIn, chunksConsumer, list, afloat, bitset, modelblockrenderer$ambientocclusionface, combinedOverlayIn);
}
}*/
matrixStackIn.popPose();

matrixStackIn.popPose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import java.util.function.Function;

public class OurRenderTypes extends RenderType {
public static final RenderType RenderBlockBackface = create("GadgetRenderBlockBackface",
public static RenderType RenderBlockBackface = create("GadgetRenderBlockBackface",
DefaultVertexFormat.BLOCK, VertexFormat.Mode.QUADS, 256, false, false,
RenderType.CompositeState.builder()
.setShaderState(RenderStateShard.RENDERTYPE_TRANSLUCENT_SHADER)
Expand All @@ -22,7 +22,7 @@ public class OurRenderTypes extends RenderType {
.setOverlayState(RenderStateShard.OVERLAY)
.createCompositeState(false));

private static final Function<ResourceLocation, RenderType> GooPattern = Util.memoize(
private static Function<ResourceLocation, RenderType> GooPattern = Util.memoize(
p_286150_ -> {
RenderType.CompositeState overlay = RenderType.CompositeState.builder()
.setShaderState(RenderStateShard.RENDERTYPE_ENTITY_ALPHA_SHADER)
Expand All @@ -38,12 +38,28 @@ public static RenderType gooPatternAlpha(ResourceLocation pId) {
return GooPattern.apply(pId);
}

private static Function<ResourceLocation, RenderType> GooTexture = Util.memoize(
p_286150_ -> {
RenderType.CompositeState overlay = RenderType.CompositeState.builder()
.setShaderState(RenderStateShard.RENDERTYPE_ENTITY_ALPHA_SHADER)
.setLightmapState(LIGHTMAP)
.setTextureState(new RenderStateShard.TextureStateShard(p_286150_, false, false))
.setCullState(NO_CULL)
.setWriteMaskState(RenderStateShard.DEPTH_WRITE)
.createCompositeState(true);
return create("GooTexture", DefaultVertexFormat.BLOCK, VertexFormat.Mode.QUADS, 1536, false, false, overlay);
});

public static RenderType gooPatternColor(ResourceLocation pId) {
return GooTexture.apply(pId);
}


public OurRenderTypes(String p_173178_, VertexFormat p_173179_, VertexFormat.Mode p_173180_, int p_173181_, boolean p_173182_, boolean p_173183_, Runnable p_173184_, Runnable p_173185_) {
super(p_173178_, p_173179_, p_173180_, p_173181_, p_173182_, p_173183_, p_173184_, p_173185_);
}

/* public static void updateRenders() { //Only used when testing
public static void updateRenders() { //Only used when testing
GooPattern = Util.memoize(
p_286150_ -> {
RenderType.CompositeState overlay = RenderType.CompositeState.builder()
Expand All @@ -63,9 +79,24 @@ public OurRenderTypes(String p_173178_, VertexFormat p_173179_, VertexFormat.Mod
.setLightmapState(LIGHTMAP)
.setTextureState(BLOCK_SHEET)
.setTransparencyState(TRANSLUCENT_TRANSPARENCY)
.setDepthTestState(GREATER_DEPTH_TEST)
.setDepthTestState(EQUAL_DEPTH_TEST)
.setCullState(CULL)
.setOverlayState(RenderStateShard.OVERLAY)
.createCompositeState(false));
}*/

GooTexture = Util.memoize(
p_286150_ -> {
RenderType.CompositeState overlay = RenderType.CompositeState.builder()
.setShaderState(RenderStateShard.RENDERTYPE_TRANSLUCENT_SHADER)
.setLightmapState(LIGHTMAP)
.setTransparencyState(NO_TRANSPARENCY)
.setDepthTestState(RenderStateShard.EQUAL_DEPTH_TEST)
.setTextureState(new RenderStateShard.TextureStateShard(p_286150_, false, false))
.setCullState(NO_CULL)
.setWriteMaskState(RenderStateShard.COLOR_DEPTH_WRITE)
.setOverlayState(RenderStateShard.OVERLAY)
.createCompositeState(false);
return create("GooTexture", DefaultVertexFormat.BLOCK, VertexFormat.Mode.QUADS, 1536, false, false, overlay);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public int getTier() {
}

public int getCraftingDuration() {
return 100; //Todo Config or Crafting Recipe setting
return 500; //Todo Config or Crafting Recipe setting
}

public int getRemainingTimeFor(Direction direction) {
Expand Down

0 comments on commit eb422b9

Please sign in to comment.