Skip to content

Commit

Permalink
(Temp?) fix for transparent/translucent rendering of mixed slabs
Browse files Browse the repository at this point in the history
  • Loading branch information
Micalobia committed Oct 3, 2021
1 parent bd8016b commit 56d7594
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/main/java/dev/micalobia/full_slabs/FullSlabsMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static Identifier id(String path) {

@Override
public void onInitialize() {
FULL_SLAB_BLOCK = Registry.register(Registry.BLOCK, id("full_slab_block"), new FullSlabBlock(Settings.copy(Blocks.BEDROCK)));
FULL_SLAB_BLOCK = Registry.register(Registry.BLOCK, id("full_slab_block"), new FullSlabBlock(Settings.copy(Blocks.BEDROCK).nonOpaque()));
FULL_SLAB_BLOCK_ENTITY = Registry.register(Registry.BLOCK_ENTITY_TYPE, id("full_slab"), FabricBlockEntityTypeBuilder.create(FullSlabBlockEntity::new, FULL_SLAB_BLOCK).build());

AutoConfig.register(ModConfig.class, GsonConfigSerializer::new);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
package dev.micalobia.full_slabs.client.render.model;

import com.mojang.datafixers.util.Pair;
import dev.micalobia.full_slabs.FullSlabsMod;
import dev.micalobia.full_slabs.block.FullSlabBlock;
import dev.micalobia.full_slabs.util.Utility;
import net.fabricmc.fabric.api.renderer.v1.RendererAccess;
import net.fabricmc.fabric.api.renderer.v1.material.BlendMode;
import net.fabricmc.fabric.api.renderer.v1.material.MaterialFinder;
import net.fabricmc.fabric.api.renderer.v1.material.RenderMaterial;
import net.fabricmc.fabric.api.renderer.v1.mesh.MeshBuilder;
import net.fabricmc.fabric.api.renderer.v1.mesh.QuadEmitter;
import net.fabricmc.fabric.api.renderer.v1.model.FabricBakedModel;
import net.fabricmc.fabric.api.renderer.v1.render.RenderContext;
import net.fabricmc.fabric.api.renderer.v1.render.RenderContext.QuadTransform;
import net.fabricmc.fabric.api.rendering.data.v1.RenderAttachedBlockView;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.RenderLayers;
import net.minecraft.client.render.block.BlockRenderManager;
import net.minecraft.client.render.model.*;
import net.minecraft.client.render.model.json.ModelOverrideList;
Expand All @@ -35,6 +45,14 @@ public class FullSlabModel implements UnbakedModel, BakedModel, FabricBakedModel
public FullSlabModel() {
}

private static QuadTransform applyMaterial(RenderMaterial material) {
return (quad -> {
quad.material(material);
FullSlabsMod.LOGGER.info(quad.getClass());
return true;
});
}

@Override
public Collection<Identifier> getModelDependencies() {
return Collections.emptySet();
Expand Down Expand Up @@ -106,8 +124,53 @@ public void emitBlockQuads(BlockRenderView blockView, BlockState state, BlockPos
BlockState positiveState = Utility.getSlabState(pair, axis, true);
BlockState negativeState = Utility.getSlabState(pair, axis, false);
BlockRenderManager manager = MinecraftClient.getInstance().getBlockRenderManager();
context.fallbackConsumer().accept(manager.getModel(positiveState));
context.fallbackConsumer().accept(manager.getModel(negativeState));
var renderer = RendererAccess.INSTANCE.getRenderer();
assert renderer != null;
MaterialFinder finder = renderer.materialFinder();
RenderLayer positiveLayer = RenderLayers.getBlockLayer(positiveState);
RenderLayer negativeLayer = RenderLayers.getBlockLayer(negativeState);
BlendMode positiveBlend = BlendMode.fromRenderLayer(positiveLayer);
BlendMode negativeBlend = BlendMode.fromRenderLayer(negativeLayer);
RenderMaterial positiveMaterial = finder.clear().blendMode(0, positiveBlend).find();
RenderMaterial negativeMaterial = finder.clear().blendMode(0, negativeBlend).find();
BakedModel positiveModel = manager.getModel(positiveState);
BakedModel negativeModel = manager.getModel(negativeState);
MeshBuilder builder = renderer.meshBuilder();
QuadEmitter quadEmitter = builder.getEmitter();
// context.pushTransform(applyMaterial(finder.clear().find()));
// context.fallbackConsumer().accept(positiveModel);
// context.popTransform();
// context.pushTransform(applyMaterial(finder.clear().find()));
// context.fallbackConsumer().accept(negativeModel);
// context.popTransform();
//((FabricBakedModel) positiveModel).emitBlockQuads(blockView, state, pos, randomSupplier, context);
//((FabricBakedModel) negativeModel).emitBlockQuads(blockView, state, pos, randomSupplier, context);
boolean positiveCull = positiveBlend != BlendMode.SOLID && blockView.getBlockState(pos.offset(axis, 1)).isOf(FullSlabsMod.FULL_SLAB_BLOCK);
boolean negativeCull = negativeBlend != BlendMode.SOLID && blockView.getBlockState(pos.offset(axis, -1)).isOf(FullSlabsMod.FULL_SLAB_BLOCK);
for(Direction direction : Direction.values()) {
for(BakedQuad quad : positiveModel.getQuads(positiveState, direction, randomSupplier.get())) {
quadEmitter.fromVanilla(quad, positiveMaterial, positiveCull ? direction : null);
quadEmitter.emit();
}
for(BakedQuad quad : negativeModel.getQuads(negativeState, direction, randomSupplier.get())) {
quadEmitter.fromVanilla(quad, negativeMaterial, negativeCull ? direction : null);
quadEmitter.emit();
}
}
for(BakedQuad quad : positiveModel.getQuads(positiveState, null, randomSupplier.get())) {
quadEmitter.fromVanilla(quad, positiveMaterial, null);
quadEmitter.emit();
}
for(BakedQuad quad : negativeModel.getQuads(negativeState, null, randomSupplier.get())) {
quadEmitter.fromVanilla(quad, negativeMaterial, null);
quadEmitter.emit();
}
context.meshConsumer().accept(builder.build());
// context.fallbackConsumer().accept((BakedModel) positiveModel);
// context.fallbackConsumer().accept((BakedModel) negativeModel);
//positiveModel.emitBlockQuads(blockView, state, pos, randomSupplier, context);
//negativeModel.emitBlockQuads(blockView, state, pos, randomSupplier, context);
//context.popTransform();
}

@Override
Expand Down

0 comments on commit 56d7594

Please sign in to comment.