Work on fluid
This commit is contained in:
@@ -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
|
// 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
|
// as leaves and such will be able to be merged
|
||||||
public class ModelManager {
|
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<ColourDepthTextureData> 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 static final int MODEL_SIZE = 64;
|
||||||
public final ModelTextureBakery bakery;
|
public final ModelTextureBakery bakery;
|
||||||
private final GlBuffer modelBuffer;
|
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
|
//Provides a map from id -> model id as multiple ids might have the same internal model id
|
||||||
private final int[] idMappings;
|
private final int[] idMappings;
|
||||||
private final Object2IntOpenHashMap<List<ColourDepthTextureData>> modelTexture2id = new Object2IntOpenHashMap<>();
|
private final Object2IntOpenHashMap<ModelEntry> modelTexture2id = new Object2IntOpenHashMap<>();
|
||||||
|
|
||||||
|
|
||||||
private final List<Biome> biomes = new ArrayList<>();
|
private final List<Biome> biomes = new ArrayList<>();
|
||||||
@@ -138,7 +146,8 @@ public class ModelManager {
|
|||||||
var textureData = this.bakery.renderFaces(blockState, 123456, isFluid);
|
var textureData = this.bakery.renderFaces(blockState, 123456, isFluid);
|
||||||
|
|
||||||
{//Deduplicate same entries
|
{//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
|
if (possibleDuplicate != -1) {//Duplicate found
|
||||||
this.idMappings[blockId] = possibleDuplicate;
|
this.idMappings[blockId] = possibleDuplicate;
|
||||||
modelId = possibleDuplicate;
|
modelId = possibleDuplicate;
|
||||||
@@ -146,7 +155,7 @@ public class ModelManager {
|
|||||||
} else {//Not a duplicate so create a new entry
|
} else {//Not a duplicate so create a new entry
|
||||||
modelId = this.modelTexture2id.size();
|
modelId = this.modelTexture2id.size();
|
||||||
this.idMappings[blockId] = modelId;
|
this.idMappings[blockId] = modelId;
|
||||||
this.modelTexture2id.put(Stream.of(textureData).map(ColourDepthTextureData::clone).toList(), modelId);
|
this.modelTexture2id.put(entry, modelId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -213,17 +213,28 @@ public class RenderDataFactory {
|
|||||||
// fluid face of type this.world.getMapper().getBlockStateFromId(self).getFluidState() and block type
|
// fluid face of type this.world.getMapper().getBlockStateFromId(self).getFluidState() and block type
|
||||||
// this.world.getMapper().getBlockStateFromId(self).getFluidState().getBlockState()
|
// 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 we are a fluid
|
||||||
if (ModelManager.containsFluid(metadata) && ModelManager.containsFluid(facingMetadata)) {
|
if (ModelManager.containsFluid(metadata)) {
|
||||||
//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
|
|
||||||
var selfBS = this.world.getMapper().getBlockStateFromId(self);
|
var selfBS = this.world.getMapper().getBlockStateFromId(self);
|
||||||
if (selfBS.getBlock() instanceof FluidBlock && selfBS.getFluidState().getBlockState().getBlock() == this.world.getMapper().getBlockStateFromId(facingState).getFluidState().getBlockState().getBlock()) {
|
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;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user