diff --git a/src/main/java/me/cortex/voxy/client/core/model/ModelManager.java b/src/main/java/me/cortex/voxy/client/core/model/ModelManager.java index b95f5e93..8372e56f 100644 --- a/src/main/java/me/cortex/voxy/client/core/model/ModelManager.java +++ b/src/main/java/me/cortex/voxy/client/core/model/ModelManager.java @@ -51,6 +51,14 @@ import static org.lwjgl.opengl.GL45C.glTextureSubImage2D; // to all other models already loaded, if it is a duplicate, create a mapping from the id to the already loaded id, this will help with meshing aswell // as leaves and such will be able to be merged public class ModelManager { + //TODO: replace the fluid BlockState with a client model id integer of the fluidState, requires looking up + // the fluid state in the mipper + private record ModelEntry(List textures, BlockState fluidBlockState){ + private ModelEntry(ColourDepthTextureData[] textures, BlockState fluidBlockState) { + this(Stream.of(textures).map(ColourDepthTextureData::clone).toList(), fluidBlockState); + } + } + public static final int MODEL_SIZE = 64; public final ModelTextureBakery bakery; private final GlBuffer modelBuffer; @@ -91,7 +99,7 @@ public class ModelManager { //Provides a map from id -> model id as multiple ids might have the same internal model id private final int[] idMappings; - private final Object2IntOpenHashMap> modelTexture2id = new Object2IntOpenHashMap<>(); + private final Object2IntOpenHashMap modelTexture2id = new Object2IntOpenHashMap<>(); private final List biomes = new ArrayList<>(); @@ -138,7 +146,8 @@ public class ModelManager { var textureData = this.bakery.renderFaces(blockState, 123456, isFluid); {//Deduplicate same entries - int possibleDuplicate = this.modelTexture2id.getInt(List.of(textureData)); + var entry = new ModelEntry(textureData, isFluid||blockState.getFluidState().isEmpty()?null:blockState.getFluidState().getBlockState()); + int possibleDuplicate = this.modelTexture2id.getInt(entry); if (possibleDuplicate != -1) {//Duplicate found this.idMappings[blockId] = possibleDuplicate; modelId = possibleDuplicate; @@ -146,7 +155,7 @@ public class ModelManager { } else {//Not a duplicate so create a new entry modelId = this.modelTexture2id.size(); this.idMappings[blockId] = modelId; - this.modelTexture2id.put(Stream.of(textureData).map(ColourDepthTextureData::clone).toList(), modelId); + this.modelTexture2id.put(entry, modelId); } } diff --git a/src/main/java/me/cortex/voxy/client/core/rendering/building/RenderDataFactory.java b/src/main/java/me/cortex/voxy/client/core/rendering/building/RenderDataFactory.java index f881889b..0a1178b5 100644 --- a/src/main/java/me/cortex/voxy/client/core/rendering/building/RenderDataFactory.java +++ b/src/main/java/me/cortex/voxy/client/core/rendering/building/RenderDataFactory.java @@ -213,16 +213,27 @@ public class RenderDataFactory { // fluid face of type this.world.getMapper().getBlockStateFromId(self).getFluidState() and block type // this.world.getMapper().getBlockStateFromId(self).getFluidState().getBlockState() - //If we are a fluid and the oposing face is also a fluid need to make a closer check - if (ModelManager.containsFluid(metadata) && ModelManager.containsFluid(facingMetadata)) { - //if (this.world.getMapper().getBlockStateFromId(self).getFluidState() != this.world.getMapper().getBlockStateFromId(facingState).getFluidState()) { - // TODO: need to inject a face here of type fluid, how? i have no god damn idea, probably add an auxilery mesher just for this - //} - - //Hackfix + //If we are a fluid + if (ModelManager.containsFluid(metadata)) { var selfBS = this.world.getMapper().getBlockStateFromId(self); - if (selfBS.getBlock() instanceof FluidBlock && selfBS.getFluidState().getBlockState().getBlock() == this.world.getMapper().getBlockStateFromId(facingState).getFluidState().getBlockState().getBlock()) { - return false; + if (ModelManager.containsFluid(facingMetadata)) {//and the oposing face is also a fluid need to make a closer check + var faceBS = this.world.getMapper().getBlockStateFromId(facingState); + + //If we are a fluid block that means our face is a fluid face, waterlogged blocks dont include fluid faces in the model data + if (selfBS.getBlock() instanceof FluidBlock) { + //If the fluid state of both blocks are the same we dont emit extra geometry + if (selfBS.getFluidState().getBlockState().equals(faceBS.getFluidState().getBlockState())) { + return false; + } + } else {//If we are not a fluid block, we might need to emit extra geometry (fluid faces) to the auxliery mesher + boolean shouldEmitFluidFace = !selfBS.getFluidState().getBlockState().equals(faceBS.getFluidState().getBlockState()); + //TODO: THIS + int aa = 0; + } + } else if (!(selfBS.getBlock() instanceof FluidBlock)) {//If we are not a fluid block but we contain a fluid we might need to emit extra geometry + //Basicly need to get the fluid state and run putFaceIfCan using the fluid state as the self state and keep the same facing state + //TODO: THIS + int aa = 0; } }