Skip to content

Commit

Permalink
Look for NeoForge glowing block entities
Browse files Browse the repository at this point in the history
  • Loading branch information
IMS212 committed Sep 14, 2024
1 parent 31d08b0 commit b758900
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 12 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ val FABRIC_API_VERSION by extra { "0.103.0+1.21.1" }
val PARCHMENT_VERSION by extra { null }

// https://semver.org/
val MOD_VERSION by extra { "0.6.0-beta.1" }
val MOD_VERSION by extra { "0.6.0-beta.2" }

allprojects {
apply(plugin = "java")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.caffeinemc.mods.sodium.client.render;

import com.llamalad7.mixinextras.sugar.ref.LocalBooleanRef;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.SheetedDecalTextureGenerator;
Expand All @@ -18,6 +19,7 @@
import net.caffeinemc.mods.sodium.client.render.chunk.terrain.DefaultTerrainRenderPasses;
import net.caffeinemc.mods.sodium.client.render.chunk.translucent_sorting.trigger.CameraMovement;
import net.caffeinemc.mods.sodium.client.render.viewport.Viewport;
import net.caffeinemc.mods.sodium.client.services.PlatformBlockAccess;
import net.caffeinemc.mods.sodium.client.util.NativeBuffer;
import net.caffeinemc.mods.sodium.client.world.LevelRendererExtension;
import net.minecraft.client.Camera;
Expand Down Expand Up @@ -293,18 +295,24 @@ public void renderBlockEntities(PoseStack matrices,
RenderBuffers bufferBuilders,
Long2ObjectMap<SortedSet<BlockDestructionProgress>> blockBreakingProgressions,
Camera camera,
float tickDelta) {
float tickDelta, LocalBooleanRef isGlowing) {
MultiBufferSource.BufferSource immediate = bufferBuilders.bufferSource();

Vec3 cameraPos = camera.getPosition();
double x = cameraPos.x();
double y = cameraPos.y();
double z = cameraPos.z();

LocalPlayer player = this.client.player;

if (player == null) {
throw new IllegalStateException("Client instance has no active player entity");
}

BlockEntityRenderDispatcher blockEntityRenderer = Minecraft.getInstance().getBlockEntityRenderDispatcher();

this.renderBlockEntities(matrices, bufferBuilders, blockBreakingProgressions, tickDelta, immediate, x, y, z, blockEntityRenderer);
this.renderGlobalBlockEntities(matrices, bufferBuilders, blockBreakingProgressions, tickDelta, immediate, x, y, z, blockEntityRenderer);
this.renderBlockEntities(matrices, bufferBuilders, blockBreakingProgressions, tickDelta, immediate, x, y, z, blockEntityRenderer, player, isGlowing);
this.renderGlobalBlockEntities(matrices, bufferBuilders, blockBreakingProgressions, tickDelta, immediate, x, y, z, blockEntityRenderer, player, isGlowing);
}

private void renderBlockEntities(PoseStack matrices,
Expand All @@ -315,7 +323,9 @@ private void renderBlockEntities(PoseStack matrices,
double x,
double y,
double z,
BlockEntityRenderDispatcher blockEntityRenderer) {
BlockEntityRenderDispatcher blockEntityRenderer,
LocalPlayer player,
LocalBooleanRef isGlowing) {
SortedRenderLists renderLists = this.renderSectionManager.getRenderLists();
Iterator<ChunkRenderList> renderListIterator = renderLists.iterator();

Expand All @@ -340,7 +350,7 @@ private void renderBlockEntities(PoseStack matrices,
}

for (BlockEntity blockEntity : blockEntities) {
renderBlockEntity(matrices, bufferBuilders, blockBreakingProgressions, tickDelta, immediate, x, y, z, blockEntityRenderer, blockEntity);
renderBlockEntity(matrices, bufferBuilders, blockBreakingProgressions, tickDelta, immediate, x, y, z, blockEntityRenderer, blockEntity, player, isGlowing);
}
}
}
Expand All @@ -354,7 +364,9 @@ private void renderGlobalBlockEntities(PoseStack matrices,
double x,
double y,
double z,
BlockEntityRenderDispatcher blockEntityRenderer) {
BlockEntityRenderDispatcher blockEntityRenderer,
LocalPlayer player,
LocalBooleanRef isGlowing) {
for (var renderSection : this.renderSectionManager.getSectionsWithGlobalEntities()) {
var blockEntities = renderSection.getGlobalBlockEntities();

Expand All @@ -363,7 +375,7 @@ private void renderGlobalBlockEntities(PoseStack matrices,
}

for (var blockEntity : blockEntities) {
renderBlockEntity(matrices, bufferBuilders, blockBreakingProgressions, tickDelta, immediate, x, y, z, blockEntityRenderer, blockEntity);
renderBlockEntity(matrices, bufferBuilders, blockBreakingProgressions, tickDelta, immediate, x, y, z, blockEntityRenderer, blockEntity, player, isGlowing);
}
}
}
Expand All @@ -377,7 +389,9 @@ private static void renderBlockEntity(PoseStack matrices,
double y,
double z,
BlockEntityRenderDispatcher dispatcher,
BlockEntity entity) {
BlockEntity entity,
LocalPlayer player,
LocalBooleanRef isGlowing) {
BlockPos pos = entity.getBlockPos();

matrices.pushPose();
Expand All @@ -403,6 +417,12 @@ private static void renderBlockEntity(PoseStack matrices,

dispatcher.render(entity, tickDelta, matrices, consumer);

if (isGlowing != null) {
if (PlatformBlockAccess.getInstance().shouldBlockEntityGlow(entity, player)) {
isGlowing.set(true);
}
}

matrices.popPose();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import net.caffeinemc.mods.sodium.client.model.quad.ModelQuadView;
import net.caffeinemc.mods.sodium.client.render.frapi.render.AmbientOcclusionMode;
import net.fabricmc.fabric.api.util.TriState;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.core.BlockPos;
Expand Down Expand Up @@ -77,4 +78,11 @@ static PlatformBlockAccess getInstance() {
* @return If ambient occlusion is forced, or {@code DEFAULT}
*/
AmbientOcclusionMode usesAmbientOcclusion(BakedModel model, BlockState state, SodiumModelData data, RenderType renderType, BlockAndTintGetter level, BlockPos pos);

/**
* @param blockEntity The block entity to check.
* @param player The current player rendering.
* @return Whether this block entity should activate the outline shader.
*/
boolean shouldBlockEntityGlow(BlockEntity blockEntity, LocalPlayer player);
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package net.caffeinemc.mods.sodium.mixin.core.render.world;

import com.llamalad7.mixinextras.sugar.Local;
import com.llamalad7.mixinextras.sugar.ref.LocalBooleanRef;
import com.mojang.blaze3d.vertex.PoseStack;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import net.caffeinemc.mods.sodium.client.gl.device.RenderDevice;
import net.caffeinemc.mods.sodium.client.render.SodiumWorldRenderer;
import net.caffeinemc.mods.sodium.client.render.chunk.ChunkRenderMatrices;
import net.caffeinemc.mods.sodium.client.render.viewport.ViewportProvider;
import net.caffeinemc.mods.sodium.client.services.PlatformLevelAccess;
import net.caffeinemc.mods.sodium.client.services.PlatformLevelRenderHooks;
import net.caffeinemc.mods.sodium.client.util.FlawlessFrames;
import net.caffeinemc.mods.sodium.client.world.LevelRendererExtension;
Expand Down Expand Up @@ -207,8 +208,8 @@ private void onReload(CallbackInfo ci) {
}

@Inject(method = "renderLevel", at = @At(value = "FIELD", target = "Lnet/minecraft/client/renderer/LevelRenderer;globalBlockEntities:Ljava/util/Set;", shift = At.Shift.BEFORE, ordinal = 0))
private void onRenderBlockEntities(DeltaTracker deltaTracker, boolean bl, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f matrix4f, Matrix4f matrix4f2, CallbackInfo ci) {
this.renderer.renderBlockEntities(new PoseStack(), this.renderBuffers, this.destructionProgress, camera, deltaTracker.getGameTimeDeltaPartialTick(false));
private void onRenderBlockEntities(DeltaTracker deltaTracker, boolean bl, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f matrix4f, Matrix4f matrix4f2, CallbackInfo ci, @Local(ordinal = 3) LocalBooleanRef isGlowing) {
this.renderer.renderBlockEntities(new PoseStack(), this.renderBuffers, this.destructionProgress, camera, deltaTracker.getGameTimeDeltaPartialTick(false), isGlowing);
}

// Exclusive to NeoForge, allow to fail.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
import net.caffeinemc.mods.sodium.client.services.SodiumModelData;
import net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandlerRegistry;
import net.fabricmc.fabric.api.util.TriState;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.level.BlockAndTintGetter;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.FluidState;

Expand Down Expand Up @@ -83,4 +85,9 @@ public float getNormalVectorShade(ModelQuadView quad, BlockAndTintGetter level,
public AmbientOcclusionMode usesAmbientOcclusion(BakedModel model, BlockState state, SodiumModelData data, RenderType renderType, BlockAndTintGetter level, BlockPos pos) {
return model.useAmbientOcclusion() ? AmbientOcclusionMode.DEFAULT : AmbientOcclusionMode.DISABLED;
}

@Override
public boolean shouldBlockEntityGlow(BlockEntity blockEntity, LocalPlayer player) {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
import net.caffeinemc.mods.sodium.client.services.SodiumModelData;
import net.caffeinemc.mods.sodium.client.util.DirectionUtil;
import net.fabricmc.fabric.api.util.TriState;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.level.BlockAndTintGetter;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.FluidState;
import net.neoforged.neoforge.client.model.data.ModelData;
Expand Down Expand Up @@ -51,4 +53,9 @@ public AmbientOcclusionMode usesAmbientOcclusion(BakedModel model, BlockState st
case DEFAULT -> AmbientOcclusionMode.DEFAULT;
};
}

@Override
public boolean shouldBlockEntityGlow(BlockEntity blockEntity, LocalPlayer player) {
return blockEntity.hasCustomOutlineRendering(player);
}
}

0 comments on commit b758900

Please sign in to comment.