mirror of
https://github.com/GTNewHorizons/Angelica.git
synced 2026-11-28 07:55:53 +00:00
Initial FluidLogged compat (#985)
* Initial FluidLogged compat * FluidLogged works(probably mostly) * Make FluidLogged optional * Remove a leftover print * Fix fluidlogged fluids rendering incorrectly with shaders on * Rmemove unused code * Cleanup unused imports --------- Co-authored-by: embeddedt <[email protected]> Co-authored-by: Jason Mitchell <[email protected]>
This commit is contained in:
7 files changed
+176
-6
No files matched your search
@@ -32,6 +32,7 @@ public class ModStatus {
|
||||
public static boolean isThaumcraftLoaded;
|
||||
public static boolean isThaumicHorizonsLoaded;
|
||||
public static boolean isBaublesLoaded;
|
||||
public static boolean isFluidLoggedLoaded;
|
||||
|
||||
public static void preInit(){
|
||||
isBackhandLoaded = Loader.isModLoaded("backhand");
|
||||
@@ -51,6 +52,7 @@ public class ModStatus {
|
||||
isThaumcraftLoaded = Loader.isModLoaded("Thaumcraft");
|
||||
isThaumicHorizonsLoaded = Loader.isModLoaded("ThaumicHorizons");
|
||||
isBaublesLoaded = Loader.isModLoaded("Baubles");
|
||||
isFluidLoggedLoaded = Loader.isModLoaded("fluidlogged");
|
||||
|
||||
isHoloInventoryLoaded = Loader.isModLoaded("holoinventory");
|
||||
|
||||
|
||||
+18
-2
@@ -2,6 +2,7 @@ package me.jellysquid.mods.sodium.client.render.chunk.tasks;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.blockpos.BlockPos;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.util.WorldUtil;
|
||||
import com.gtnewhorizons.angelica.compat.ModStatus;
|
||||
import com.gtnewhorizons.angelica.compat.mojang.ChunkOcclusionDataBuilder;
|
||||
import com.gtnewhorizons.angelica.compat.toremove.RenderLayer;
|
||||
import com.gtnewhorizons.angelica.config.AngelicaConfig;
|
||||
@@ -36,6 +37,7 @@ import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import org.joml.Vector3d;
|
||||
|
||||
import java.util.Map;
|
||||
@@ -155,6 +157,11 @@ public class ChunkRenderRebuildTask<T extends ChunkGraphicsState> extends ChunkR
|
||||
|
||||
for (int relZ = 0; relZ < 16; relZ++) {
|
||||
for (int relX = 0; relX < 16; relX++) {
|
||||
Fluid fluid = null;
|
||||
if (ModStatus.isFluidLoggedLoaded) {
|
||||
fluid = slice.getFluidRelative(relX + 16, relY + 16, relZ + 16);
|
||||
}
|
||||
|
||||
final Block block = slice.getBlockRelative(relX + 16, relY + 16, relZ + 16);
|
||||
|
||||
// If the block is vanilla air, assume it renders nothing. Don't use isAir because mods
|
||||
@@ -172,10 +179,18 @@ public class ChunkRenderRebuildTask<T extends ChunkGraphicsState> extends ChunkR
|
||||
|
||||
if (rendersOffThread(block)) {
|
||||
// Do regular block rendering
|
||||
final long seed = MathUtil.hashPos(pos.x, pos.y, pos.z);
|
||||
for (BlockRenderPass pass : BlockRenderPass.VALUES) {
|
||||
if (ModStatus.isFluidLoggedLoaded) {
|
||||
if (fluid != null && canRenderInPass(fluid.getBlock(), pass)) {
|
||||
ChunkRenderManager.setWorldRenderPass(pass);
|
||||
if(AngelicaConfig.enableIris) buffers.iris$setMaterialId(fluid.getBlock(), ExtendedDataHelper.FLUID_RENDER_TYPE);
|
||||
|
||||
cache.getBlockRenderer().renderFluidLogged(fluid, renderBlocks, pos, buffers.get(pass), seed);
|
||||
}
|
||||
}
|
||||
if (canRenderInPass(block, pass) && !shouldUseSodiumFluidRendering(block)) {
|
||||
ChunkRenderManager.setWorldRenderPass(pass);
|
||||
final long seed = MathUtil.hashPos(pos.x, pos.y, pos.z);
|
||||
if(AngelicaConfig.enableIris) buffers.iris$setMaterialId(block, ExtendedDataHelper.BLOCK_RENDER_TYPE);
|
||||
|
||||
if (cache.getBlockRenderer().renderModel(cache.getWorldSlice(), renderBlocks, block, meta, pos, buffers.get(pass), true, seed)) {
|
||||
@@ -183,6 +198,7 @@ public class ChunkRenderRebuildTask<T extends ChunkGraphicsState> extends ChunkR
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
mainThreadBlocks.enqueue(pos.asLong());
|
||||
hasMainThreadBlocks = true;
|
||||
@@ -339,6 +355,6 @@ public class ChunkRenderRebuildTask<T extends ChunkGraphicsState> extends ChunkR
|
||||
}
|
||||
|
||||
private static boolean shouldUseSodiumFluidRendering(Block block) {
|
||||
return AngelicaConfig.enableSodiumFluidRendering && WorldUtil.isFluidBlock(block);
|
||||
return AngelicaConfig.enableSodiumFluidRendering && WorldUtil.isFluidBlock(block) && !ModStatus.isFluidLoggedLoaded;
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,7 @@ import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
@@ -62,13 +63,54 @@ public class BlockRenderer {
|
||||
this.occlusionCache = new BlockOcclusionCache();
|
||||
}
|
||||
|
||||
public boolean renderFluidLogged(Fluid fluid, RenderBlocks renderBlocks, BlockPos pos, ChunkModelBuffers buffers, long seed) {
|
||||
if (fluid == null) {
|
||||
return false;
|
||||
}
|
||||
Block block = fluid.getBlock();
|
||||
if (block == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean rendered = false;
|
||||
|
||||
try {
|
||||
final LightMode mode = LightMode.SMOOTH; // TODO: this.getLightingMode(block); is what was previously used. The flat pipeline is busted and was only an optimization for very few blocks.
|
||||
final LightPipeline lighter = this.lighters.getLighter(mode);
|
||||
|
||||
TessellatorManager.startCapturing();
|
||||
final CapturingTessellator tess = (CapturingTessellator) TessellatorManager.get();
|
||||
tess.startDrawingQuads();
|
||||
// Use setTranslation rather than setOffset so that the float data written to the internal buffer
|
||||
// is done in subchunk-relative coordinates
|
||||
tess.setOffset(POS_ZERO);
|
||||
tess.setTranslation(-pos.x, -pos.y, -pos.z);
|
||||
renderBlocks.renderBlockByRenderType(block, pos.x, pos.y, pos.z);
|
||||
final List<QuadView> quads = TessellatorManager.stopCapturingToPooledQuads();
|
||||
tess.resetOffset();
|
||||
|
||||
for (ModelQuadFacing facing : ModelQuadFacing.VALUES) {
|
||||
this.random.setSeed(seed);
|
||||
this.renderQuadList(pos, lighter, buffers, quads, facing, (this.useAmbientOcclusion && this.useSodiumAO));
|
||||
}
|
||||
|
||||
if (!quads.isEmpty()) rendered = true;
|
||||
} finally {
|
||||
TessellatorManager.cleanup();
|
||||
}
|
||||
|
||||
return rendered;
|
||||
|
||||
}
|
||||
|
||||
public boolean renderModel(IBlockAccess world, RenderBlocks renderBlocks, Block block, int meta, BlockPos pos, ChunkModelBuffers buffers, boolean cull, long seed) {
|
||||
final LightMode mode = LightMode.SMOOTH; // TODO: this.getLightingMode(block); is what was previously used. The flat pipeline is busted and was only an optimization for very few blocks.
|
||||
final LightPipeline lighter = this.lighters.getLighter(mode);
|
||||
|
||||
boolean rendered = false;
|
||||
|
||||
this.useSeparateAo = AngelicaConfig.enableIris && BlockRenderingSettings.INSTANCE.shouldUseSeparateAo();
|
||||
|
||||
boolean rendered = false;
|
||||
final QuadProvider model = ((ModeledBlock) block).getModel();
|
||||
|
||||
if (model != null) {
|
||||
|
||||
@@ -3,13 +3,16 @@ package me.jellysquid.mods.sodium.client.world;
|
||||
import java.util.Arrays;
|
||||
|
||||
import com.gtnewhorizons.angelica.api.IBlockAccessExtended;
|
||||
import com.gtnewhorizons.angelica.compat.ModStatus;
|
||||
import com.gtnewhorizons.angelica.compat.mojang.ChunkSectionPos;
|
||||
import com.gtnewhorizons.angelica.compat.mojang.CompatMathHelper;
|
||||
import com.gtnewhorizons.angelica.dynamiclights.DynamicLights;
|
||||
import cpw.mods.fml.common.Optional;
|
||||
import lombok.Getter;
|
||||
import me.jellysquid.mods.sodium.client.world.cloned.ChunkRenderContext;
|
||||
import me.jellysquid.mods.sodium.client.world.cloned.ClonedChunkSection;
|
||||
import me.jellysquid.mods.sodium.client.world.cloned.ClonedChunkSectionCache;
|
||||
import mega.fluidlogged.api.FLBlockAccess;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.multiplayer.WorldClient;
|
||||
import net.minecraft.init.Blocks;
|
||||
@@ -24,6 +27,8 @@ import net.minecraft.world.chunk.NibbleArray;
|
||||
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
|
||||
import net.minecraft.world.gen.structure.StructureBoundingBox;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Takes a slice of world state (block states, biome and light data arrays) and copies the data for use in off-thread
|
||||
@@ -35,7 +40,8 @@ import net.minecraftforge.common.util.ForgeDirection;
|
||||
*
|
||||
* Object pooling should be used to avoid huge allocations as this class contains many large arrays.
|
||||
*/
|
||||
public class WorldSlice implements IBlockAccessExtended {
|
||||
@Optional.Interface(iface = "mega.fluidlogged.api.FLBlockAccess", modid = "fluidlogged")
|
||||
public class WorldSlice implements IBlockAccessExtended, FLBlockAccess {
|
||||
private static final EnumSkyBlock[] LIGHT_TYPES = EnumSkyBlock.values();
|
||||
|
||||
// The number of blocks on each axis in a section.
|
||||
@@ -68,6 +74,7 @@ public class WorldSlice implements IBlockAccessExtended {
|
||||
|
||||
// Local Section->BlockState table.
|
||||
private final Block[][] blockArrays;
|
||||
private final Fluid[][] fluidArrays;
|
||||
private final int[][] metadataArrays;
|
||||
|
||||
// Local Section->Light table
|
||||
@@ -145,6 +152,12 @@ public class WorldSlice implements IBlockAccessExtended {
|
||||
this.biomeData = new BiomeGenBase[SECTION_TABLE_ARRAY_SIZE][];
|
||||
this.lightArrays = new NibbleArray[SECTION_TABLE_ARRAY_SIZE][LIGHT_TYPES.length];
|
||||
|
||||
if (ModStatus.isFluidLoggedLoaded) {
|
||||
this.fluidArrays = new Fluid[SECTION_TABLE_ARRAY_SIZE][];
|
||||
} else {
|
||||
this.fluidArrays = null;
|
||||
}
|
||||
|
||||
for (int x = 0; x < SECTION_LENGTH; x++) {
|
||||
for (int y = 0; y < SECTION_LENGTH; y++) {
|
||||
for (int z = 0; z < SECTION_LENGTH; z++) {
|
||||
@@ -152,6 +165,10 @@ public class WorldSlice implements IBlockAccessExtended {
|
||||
this.blockArrays[i] = new Block[SECTION_BLOCK_COUNT];
|
||||
Arrays.fill(this.blockArrays[i], Blocks.air);
|
||||
this.metadataArrays[i] = new int[SECTION_BLOCK_COUNT];
|
||||
|
||||
if (ModStatus.isFluidLoggedLoaded && this.fluidArrays != null) {
|
||||
this.fluidArrays[i] = new Fluid[SECTION_BLOCK_COUNT];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -175,6 +192,11 @@ public class WorldSlice implements IBlockAccessExtended {
|
||||
final ClonedChunkSection section = this.sections[idx];
|
||||
|
||||
this.unpackBlockData(this.blockArrays[idx], this.metadataArrays[idx], section, context.getVolume());
|
||||
|
||||
if (ModStatus.isFluidLoggedLoaded) {
|
||||
this.unpackFluidLoggedData(this.fluidArrays[idx], section, context.getVolume());
|
||||
}
|
||||
|
||||
this.biomeData[idx] = section.getBiomeData();
|
||||
|
||||
this.lightArrays[idx][EnumSkyBlock.Block.ordinal()] = section.getLightArray(EnumSkyBlock.Block);
|
||||
@@ -191,8 +213,8 @@ public class WorldSlice implements IBlockAccessExtended {
|
||||
return (15 << 20) | (min << 4);
|
||||
}
|
||||
|
||||
final int skyBrightness = this.getSkyBlockTypeBrightness(net.minecraft.world.EnumSkyBlock.Sky, x, y, z);
|
||||
int blockBrightness = this.getSkyBlockTypeBrightness(net.minecraft.world.EnumSkyBlock.Block, x, y, z);
|
||||
final int skyBrightness = this.getSkyBlockTypeBrightness(EnumSkyBlock.Sky, x, y, z);
|
||||
int blockBrightness = this.getSkyBlockTypeBrightness(EnumSkyBlock.Block, x, y, z);
|
||||
|
||||
if (blockBrightness < min) {
|
||||
blockBrightness = min;
|
||||
@@ -265,6 +287,14 @@ public class WorldSlice implements IBlockAccessExtended {
|
||||
return getBlock(x, y, z).isSideSolid(this, x, y, z, side);
|
||||
}
|
||||
|
||||
private void unpackFluidLoggedData(Fluid[] fluids, ClonedChunkSection section, StructureBoundingBox box) {
|
||||
if (this.origin.equals(section.getPosition())) {
|
||||
this.unpackFluidLoggedDataZ(fluids, section);
|
||||
} else {
|
||||
this.unpackFluidLoggedDataR(fluids, section, box);
|
||||
}
|
||||
}
|
||||
|
||||
private void unpackBlockData(Block[] blocks, int[] metas, ClonedChunkSection section, StructureBoundingBox box) {
|
||||
if (this.origin.equals(section.getPosition())) {
|
||||
this.unpackBlockDataZ(blocks, metas, section);
|
||||
@@ -273,6 +303,48 @@ public class WorldSlice implements IBlockAccessExtended {
|
||||
}
|
||||
}
|
||||
|
||||
private void unpackFluidLoggedDataR(Fluid[] fluids, ClonedChunkSection section, StructureBoundingBox box) {
|
||||
final ChunkSectionPos pos = section.getPosition();
|
||||
|
||||
final int minBlockX = Math.max(box.minX, pos.getMinX());
|
||||
final int maxBlockX = Math.min(box.maxX, pos.getMaxX());
|
||||
|
||||
final int minBlockY = Math.max(box.minY, pos.getMinY());
|
||||
final int maxBlockY = Math.min(box.maxY, pos.getMaxY());
|
||||
|
||||
final int minBlockZ = Math.max(box.minZ, pos.getMinZ());
|
||||
final int maxBlockZ = Math.min(box.maxZ, pos.getMaxZ());
|
||||
|
||||
copyFluids(fluids, section, minBlockY, maxBlockY, minBlockZ, maxBlockZ, minBlockX, maxBlockX);
|
||||
}
|
||||
|
||||
private void unpackFluidLoggedDataZ(Fluid[] fluids, ClonedChunkSection section) {
|
||||
// TODO: Look into a faster copy for this?
|
||||
final ChunkSectionPos pos = section.getPosition();
|
||||
|
||||
final int minBlockX = pos.getMinX();
|
||||
final int maxBlockX = pos.getMaxX();
|
||||
|
||||
final int minBlockY = pos.getMinY();
|
||||
final int maxBlockY = pos.getMaxY();
|
||||
|
||||
final int minBlockZ = pos.getMinZ();
|
||||
final int maxBlockZ = pos.getMaxZ();
|
||||
|
||||
// TODO: Can this be optimized?
|
||||
copyFluids(fluids, section, minBlockY, maxBlockY, minBlockZ, maxBlockZ, minBlockX, maxBlockX);
|
||||
}
|
||||
|
||||
private static void copyFluids(Fluid[] fluids, ClonedChunkSection section, int minBlockY, int maxBlockY, int minBlockZ, int maxBlockZ, int minBlockX, int maxBlockX) {
|
||||
for (int y = minBlockY; y <= maxBlockY; y++) {
|
||||
for (int z = minBlockZ; z <= maxBlockZ; z++) {
|
||||
for (int x = minBlockX; x <= maxBlockX; x++) {
|
||||
final int blockIdx = getLocalBlockIndex(x & 15, y & 15, z & 15);
|
||||
fluids[blockIdx] = section.getFluid(x & 15, y & 15, z & 15);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void copyBlocks(Block[] blocks, int[] metas, ClonedChunkSection section, int minBlockY, int maxBlockY, int minBlockZ, int maxBlockZ, int minBlockX, int maxBlockX) {
|
||||
for (int y = minBlockY; y <= maxBlockY; y++) {
|
||||
@@ -419,4 +491,23 @@ public class WorldSlice implements IBlockAccessExtended {
|
||||
z >= box.minZ &&
|
||||
z <= box.maxZ;
|
||||
}
|
||||
|
||||
public @Nullable Fluid fl$getFluid(int x, int y, int z) {
|
||||
if (!blockBoxContains(this.volume, x, y, z)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final int relX = x - this.baseX;
|
||||
final int relY = y - this.baseY;
|
||||
final int relZ = z - this.baseZ;
|
||||
return this.fluidArrays[getLocalSectionIndex(relX >> 4, relY >> 4, relZ >> 4)][getLocalBlockIndex(relX & 15, relY & 15, relZ & 15)];
|
||||
}
|
||||
|
||||
public Fluid getFluidRelative(int x, int y, int z) {
|
||||
return this.fluidArrays[getLocalSectionIndex(x >> 4, y >> 4, z >> 4)][getLocalBlockIndex(x & 15, y & 15, z & 15)];
|
||||
}
|
||||
|
||||
public void fl$setFluid(int x, int y, int z, @Nullable Fluid fluid) {
|
||||
throw new UnsupportedOperationException("Cannot set fluids in a world slice. WorldSlice is read-only");
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import com.gtnewhorizons.angelica.compat.mojang.ChunkSectionPos;
|
||||
import it.unimi.dsi.fastutil.shorts.Short2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.shorts.Short2ObjectOpenHashMap;
|
||||
import lombok.Getter;
|
||||
import mega.fluidlogged.internal.mixin.hook.FLSubChunk;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.EnumSkyBlock;
|
||||
@@ -15,6 +16,7 @@ import net.minecraft.world.biome.BiomeGenBase;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraft.world.chunk.NibbleArray;
|
||||
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
@@ -102,6 +104,14 @@ public class ClonedChunkSection {
|
||||
return data.getBlockByExtId(x, y, z);
|
||||
}
|
||||
|
||||
public Fluid getFluid(int x, int y, int z) {
|
||||
if (ModStatus.isFluidLoggedLoaded) {
|
||||
return ((FLSubChunk) data).fl$getFluid(x, y, z);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getBlockMetadata(int x, int y, int z) {
|
||||
return data.getExtBlockMetadata(x, y, z);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user