3D rendering of fluids in transparent crucibles

This commit is contained in:
thedarkcolour 2024-03-21 22:07:31 -07:00
parent c8e423129d
commit 07ae72d9ec
8 changed files with 43 additions and 22 deletions

View File

@ -54,6 +54,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import thedarkcolour.exdeorum.blockentity.helper.FluidHelper;
import thedarkcolour.exdeorum.config.EConfig;
import thedarkcolour.exdeorum.material.AbstractCrucibleMaterial;
import thedarkcolour.exdeorum.recipe.crucible.CrucibleRecipe;
import thedarkcolour.exdeorum.registry.EBlockEntities;
import thedarkcolour.exdeorum.registry.EItems;
@ -83,9 +84,12 @@ public abstract class AbstractCrucibleBlockEntity extends EBlockEntity {
private Fluid fluid = null;
private short solids;
private boolean needsLightUpdate;
public final boolean transparent;
public AbstractCrucibleBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
super(type, pos, state);
this.transparent = AbstractCrucibleMaterial.TRANSPARENT_CRUCIBLES.contains(state.getBlock());
}
@NotNull

View File

@ -49,7 +49,6 @@ import net.minecraftforge.client.extensions.common.IClientFluidTypeExtensions;
import net.minecraftforge.client.model.CompositeModel;
import net.minecraftforge.client.model.data.ModelData;
import net.minecraftforge.registries.ForgeRegistries;
import org.joml.Matrix4f;
import org.joml.Vector3f;
import thedarkcolour.exdeorum.ExDeorum;
import thedarkcolour.exdeorum.client.ter.SieveRenderer;
@ -173,7 +172,7 @@ public class RenderUtil {
}
@SuppressWarnings("DuplicatedCode")
public static void renderFluidCube(MultiBufferSource buffers, PoseStack stack, Level level, BlockPos pos, float minY, float maxY, float edge, int light, int r, int g, int b, Fluid fluid) {
public static void renderFluidCuboid(MultiBufferSource buffers, PoseStack stack, Level level, BlockPos pos, float minY, float maxY, float edge, int light, int r, int g, int b, Fluid fluid) {
var extensions = IClientFluidTypeExtensions.of(fluid);
var state = fluid.defaultFluidState();
var builder = buffers.getBuffer(Sheets.translucentCullBlockSheet());

View File

@ -33,7 +33,6 @@ import net.minecraft.util.Mth;
import net.minecraft.world.inventory.InventoryMenu;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.ItemDisplayContext;
import net.minecraft.world.level.material.Fluid;
import net.minecraftforge.client.model.data.ModelData;
import net.minecraftforge.common.capabilities.ForgeCapabilities;
import thedarkcolour.exdeorum.ExDeorum;
@ -99,7 +98,7 @@ public class BarrelRenderer implements BlockEntityRenderer<BarrelBlockEntity> {
}
if (barrel.transparent) {
RenderUtil.renderFluidCube(buffers, stack, level, pos, 1 / 16f, y, 2.0f, light, r, g, b, fluid);
RenderUtil.renderFluidCuboid(buffers, stack, level, pos, 1 / 16f, y, 2.0f, light, r, g, b, fluid);
} else {
RenderUtil.renderFlatFluidSprite(buffers, stack, level, pos, y, 2.0f, light, r, g, b, fluid);
}

View File

@ -23,7 +23,6 @@ import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
import net.minecraft.util.Mth;
import net.minecraft.world.level.block.Block;
import net.minecraftforge.common.capabilities.ForgeCapabilities;
import thedarkcolour.exdeorum.blockentity.AbstractCrucibleBlockEntity;
import thedarkcolour.exdeorum.client.RenderUtil;
@ -49,7 +48,15 @@ public class CrucibleRenderer implements BlockEntityRenderer<AbstractCrucibleBlo
var color = RenderUtil.getFluidColor(fluid, level, pos);
float y = Mth.lerp(liquid, 4.0f, 14.0f) / 16f;
RenderUtil.renderFlatFluidSprite(buffers, stack, level, pos, y, 2.0f, light, (color >> 16) & 0xff, (color >> 8) & 0xff, color & 0xff, fluid);
int r = (color >> 16) & 0xff;
int g = (color >> 8) & 0xff;
int b = color & 0xff;
if (crucible.transparent) {
RenderUtil.renderFluidCuboid(buffers, stack, level, pos, 4 / 16f, y, 2.0f, light, r, g, b, fluid);
} else {
RenderUtil.renderFlatFluidSprite(buffers, stack, level, pos, y, 2.0f, light, r, g, b, fluid);
}
}
if (solids != 0) {
// eating my words rn :(
@ -64,8 +71,8 @@ public class CrucibleRenderer implements BlockEntityRenderer<AbstractCrucibleBlo
if (color == -1) color = 0xffffff;
// todo 3D solids for transparent crucibles
face.renderFlatSpriteLerp(buffers, stack, solids, (color >> 16) & 0xff, (color >> 8) & 0xff, color & 0xff, light, 2.0f, 4.0f, 14.0f);
}
}
});

View File

@ -18,12 +18,23 @@
package thedarkcolour.exdeorum.material;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.SoundType;
import org.jetbrains.annotations.Nullable;
import java.util.HashSet;
import java.util.Set;
public abstract class AbstractCrucibleMaterial extends AbstractMaterial {
public AbstractCrucibleMaterial(SoundType soundType, float strength, boolean needsCorrectTool, int mapColor, String requiredModId) {
public static final Set<Block> TRANSPARENT_CRUCIBLES = new HashSet<>();
// Whether fluids and solids should be rendered with sides instead of just the top
public final boolean transparent;
public AbstractCrucibleMaterial(SoundType soundType, float strength, boolean needsCorrectTool, int mapColor, String requiredModId, boolean transparent) {
super(soundType, strength, needsCorrectTool, mapColor, requiredModId);
this.transparent = transparent;
}
@Nullable
@ -33,15 +44,16 @@ public abstract class AbstractCrucibleMaterial extends AbstractMaterial {
boolean needsCorrectTool = parser.getOptionalBoolean("needs_correct_tool");
int mapColor = parser.getMapColor();
String requiredModId = parser.getRequiredModId();
boolean transparent = parser.getOptionalBoolean("transparent");
if (parser.error) {
return null;
} else {
return factory.create(soundType, strength, needsCorrectTool, mapColor, requiredModId);
return factory.create(soundType, strength, needsCorrectTool, mapColor, requiredModId, transparent);
}
}
public interface Factory<T> {
T create(SoundType soundType, float strength, boolean needsCorrectTool, int mapColor, String requiredModId);
T create(SoundType soundType, float strength, boolean needsCorrectTool, int mapColor, String requiredModId, boolean transparent);
}
}

View File

@ -106,13 +106,13 @@ public class DefaultMaterials {
public static final SieveMaterial CRYSTALLIZED_SIEVE = addDefaultSieve("crystallized", SoundType.GLASS, true, ModIds.BLUE_SKIES);
// Ex Deorum
public static final LavaCrucibleMaterial PORCELAIN_CRUCIBLE = addDefaultLavaCrucible("porcelain", SoundType.STONE, 2.0f, false, MapColor.TERRACOTTA_WHITE, ExDeorum.ID);
public static final LavaCrucibleMaterial WARPED_CRUCIBLE = addDefaultLavaCrucible("warped", SoundType.STEM, 1.5f, false, MapColor.CRIMSON_STEM, ExDeorum.ID);
public static final LavaCrucibleMaterial CRIMSON_CRUCIBLE = addDefaultLavaCrucible("crimson", SoundType.STEM, 1.5f, false, MapColor.WARPED_STEM, ExDeorum.ID);
public static final LavaCrucibleMaterial PORCELAIN_CRUCIBLE = addDefaultLavaCrucible("porcelain", SoundType.STONE, 2.0f, false, MapColor.TERRACOTTA_WHITE, ExDeorum.ID, false);
public static final LavaCrucibleMaterial WARPED_CRUCIBLE = addDefaultLavaCrucible("warped", SoundType.STEM, 1.5f, false, MapColor.CRIMSON_STEM, ExDeorum.ID, false);
public static final LavaCrucibleMaterial CRIMSON_CRUCIBLE = addDefaultLavaCrucible("crimson", SoundType.STEM, 1.5f, false, MapColor.WARPED_STEM, ExDeorum.ID, false);
// Biomes O' Plenty
public static final LavaCrucibleMaterial HELLBARK_CRUCIBLE = addDefaultLavaCrucible("hellbark", SoundType.WOOD, 1.5f, false, MapColor.COLOR_LIGHT_GRAY, ModIds.BIOMES_O_PLENTY);
public static final LavaCrucibleMaterial HELLBARK_CRUCIBLE = addDefaultLavaCrucible("hellbark", SoundType.WOOD, 1.5f, false, MapColor.COLOR_LIGHT_GRAY, ModIds.BIOMES_O_PLENTY, false);
// Blue Skies
public static final LavaCrucibleMaterial CRYSTALLIZED_CRUCIBLE = addDefaultLavaCrucible("crystallized", SoundType.GLASS, 2.0f, true, MapColor.TERRACOTTA_WHITE, ModIds.BLUE_SKIES);
public static final LavaCrucibleMaterial CRYSTALLIZED_CRUCIBLE = addDefaultLavaCrucible("crystallized", SoundType.GLASS, 2.0f, true, MapColor.TERRACOTTA_WHITE, ModIds.BLUE_SKIES, true);
// Ex Deorum
public static final WaterCrucibleMaterial OAK_CRUCIBLE = addDefaultWaterCrucible("oak", SoundType.WOOD, MapColor.WOOD, ExDeorum.ID);
@ -171,14 +171,14 @@ public class DefaultMaterials {
return material;
}
private static LavaCrucibleMaterial addDefaultLavaCrucible(String name, SoundType soundType, float strength, boolean needsCorrectTool, MapColor color, String requiredModId) {
var material = new LavaCrucibleMaterial(soundType, strength, needsCorrectTool, color.id, requiredModId);
private static LavaCrucibleMaterial addDefaultLavaCrucible(String name, SoundType soundType, float strength, boolean needsCorrectTool, MapColor color, String requiredModId, boolean transparent) {
var material = new LavaCrucibleMaterial(soundType, strength, needsCorrectTool, color.id, requiredModId, transparent);
LAVA_CRUCIBLES.register(name, material);
return material;
}
private static WaterCrucibleMaterial addDefaultWaterCrucible(String name, SoundType soundType, MapColor color, String requiredModId) {
var material = new WaterCrucibleMaterial(soundType, 1.5f, false, color.id, requiredModId);
var material = new WaterCrucibleMaterial(soundType, 1.5f, false, color.id, requiredModId, false);
WATER_CRUCIBLES.register(name, material);
return material;
}

View File

@ -23,8 +23,8 @@ import net.minecraft.world.level.block.SoundType;
import thedarkcolour.exdeorum.block.LavaCrucibleBlock;
public class LavaCrucibleMaterial extends AbstractCrucibleMaterial {
protected LavaCrucibleMaterial(SoundType soundType, float strength, boolean needsCorrectTool, int mapColor, String requiredModId) {
super(soundType, strength, needsCorrectTool, mapColor, requiredModId);
protected LavaCrucibleMaterial(SoundType soundType, float strength, boolean needsCorrectTool, int mapColor, String requiredModId, boolean transparent) {
super(soundType, strength, needsCorrectTool, mapColor, requiredModId, transparent);
}
@Override

View File

@ -23,8 +23,8 @@ import net.minecraft.world.level.block.SoundType;
import thedarkcolour.exdeorum.block.WaterCrucibleBlock;
public class WaterCrucibleMaterial extends AbstractCrucibleMaterial {
protected WaterCrucibleMaterial(SoundType soundType, float strength, boolean needsCorrectTool, int mapColor, String requiredModId) {
super(soundType, strength, needsCorrectTool, mapColor, requiredModId);
protected WaterCrucibleMaterial(SoundType soundType, float strength, boolean needsCorrectTool, int mapColor, String requiredModId, boolean transparent) {
super(soundType, strength, needsCorrectTool, mapColor, requiredModId, transparent);
}
@Override