Skip to content

Commit

Permalink
fix origin weirdness (#799)
Browse files Browse the repository at this point in the history
  • Loading branch information
embeddedt authored Dec 17, 2024
1 parent e2ee822 commit 99a8136
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 117 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.gtnewhorizon.gtnhlib.blockpos.BlockPos;
import com.gtnewhorizon.gtnhlib.client.renderer.util.WorldUtil;
import com.gtnewhorizons.angelica.compat.mojang.ChunkOcclusionDataBuilder;
import com.gtnewhorizons.angelica.compat.mojang.ChunkSectionPos;
import com.gtnewhorizons.angelica.compat.toremove.RenderLayer;
import com.gtnewhorizons.angelica.config.AngelicaConfig;
import com.gtnewhorizons.angelica.mixins.interfaces.ITexturesCache;
Expand Down Expand Up @@ -132,7 +131,7 @@ public ChunkBuildResult<T> performBuild(ChunkRenderCacheLocal cache, ChunkBuildB
cache.init(this.context);

final WorldSlice slice = cache.getWorldSlice();
final RenderBlocks renderBlocks = new RenderBlocks(slice.getSubChunkRelativeAccess());
final RenderBlocks renderBlocks = new RenderBlocks(slice);
if(renderBlocks instanceof ITexturesCache) ((ITexturesCache)renderBlocks).enableTextureTracking();

final int baseX = this.render.getOriginX();
Expand Down Expand Up @@ -263,7 +262,7 @@ private void performMainBuild(ChunkRenderCacheLocal cache, ChunkBuildBuffers buf
final int baseY = this.render.getOriginY();
final int baseZ = this.render.getOriginZ();
final BlockPos renderOffset = this.offset;
final RenderBlocks rb = new RenderBlocks(new WorldSlice.SubchunkRelative(slice.getWorld(), this.render.getChunkPos()));
final RenderBlocks rb = new RenderBlocks(slice.getWorld());
if(rb instanceof ITexturesCache) ((ITexturesCache)rb).enableTextureTracking();
while(!mainThreadBlocks.isEmpty()) {
final long longPos = mainThreadBlocks.dequeueLong();
Expand Down Expand Up @@ -295,7 +294,7 @@ private void performMainBuild(ChunkRenderCacheLocal cache, ChunkBuildBuffers buf
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(slice, rb, block, meta, pos, buffers.get(pass), true, seed)) {
if (cache.getBlockRenderer().renderModel(slice.getWorld(), rb, block, meta, pos, buffers.get(pass), true, seed)) {
bounds.addBlock(relX, relY, relZ);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import me.jellysquid.mods.sodium.client.util.ModelQuadUtil;
import me.jellysquid.mods.sodium.client.util.color.ColorABGR;
import me.jellysquid.mods.sodium.client.util.rand.XoRoShiRoRandom;
import me.jellysquid.mods.sodium.client.world.WorldSlice;
import net.coderbot.iris.block_rendering.BlockRenderingSettings;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
Expand All @@ -38,6 +37,7 @@
import java.util.Random;

public class BlockRenderer {
private static final BlockPos POS_ZERO = new BlockPos(0, 0, 0);

private final Random random = new XoRoShiRoRandom();

Expand All @@ -52,7 +52,6 @@ public class BlockRenderer {

private Object Quad;
private final ObjectPooler<QuadView> quadPool = new ObjectPooler<>(Quad::new);
private final BlockPos subChunkRelativePos = new BlockPos();
// TODO: Use modern model API, and store them here


Expand All @@ -64,7 +63,7 @@ public BlockRenderer(LightPipelineProvider lighters) {
this.occlusionCache = new BlockOcclusionCache();
}

public boolean renderModel(WorldSlice world, RenderBlocks renderBlocks, Block block, int meta, BlockPos pos, ChunkModelBuffers buffers, boolean cull, long seed) {
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);

Expand Down Expand Up @@ -99,13 +98,11 @@ public boolean renderModel(WorldSlice world, RenderBlocks renderBlocks, Block bl
TessellatorManager.startCapturing();
final CapturingTessellator tess = (CapturingTessellator) TessellatorManager.get();
tess.startDrawingQuads();

var worldOrigin = world.getOrigin();
var subChunkRelativePos = this.subChunkRelativePos;
subChunkRelativePos.set(pos.x - worldOrigin.getMinX(), pos.y - worldOrigin.getMinY(), pos.z - worldOrigin.getMinZ());
tess.setOffset(subChunkRelativePos);
// RenderBlocks is expecting to get subchunk-relative coordinates, cancel the offset out here
renderBlocks.renderBlockByRenderType(block, subChunkRelativePos.x, subChunkRelativePos.y, subChunkRelativePos.z);
// 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();

Expand Down
103 changes: 0 additions & 103 deletions src/main/java/me/jellysquid/mods/sodium/client/world/WorldSlice.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,6 @@ public class WorldSlice implements IBlockAccess {

StructureBoundingBox volume;

@Getter
private SubchunkRelative subChunkRelativeAccess;

public static ChunkRenderContext prepare(World world, ChunkSectionPos origin, ClonedChunkSectionCache sectionCache) {
final Chunk chunk = world.getChunkFromChunkCoords(origin.x, origin.z);
final ExtendedBlockStorage section = chunk.getBlockStorageArray()[origin.y];
Expand Down Expand Up @@ -184,8 +181,6 @@ public void copyData(ChunkRenderContext context) {
}
}
}

this.subChunkRelativeAccess = new SubchunkRelative(this, this.origin);
}

@Override
Expand Down Expand Up @@ -422,102 +417,4 @@ private static boolean blockBoxContains(StructureBoundingBox box, int x, int y,
z >= box.minZ &&
z <= box.maxZ;
}

/**
* Wraps an {@link IBlockAccess} so that it can be given to RenderBlocks with subchunk-relative coordinates.
*/
public static final class SubchunkRelative implements IBlockAccess {
private final IBlockAccess delegate;
private final ChunkSectionPos origin;

public SubchunkRelative(IBlockAccess delegate, ChunkSectionPos origin) {
this.delegate = delegate;
this.origin = origin;
}

@Override
public Block getBlock(int x, int y, int z) {
return delegate.getBlock(
x + this.origin.getMinX(),
y + this.origin.getMinY(),
z + this.origin.getMinZ()
);
}

@Override
public TileEntity getTileEntity(int x, int y, int z) {
return delegate.getTileEntity(
x + this.origin.getMinX(),
y + this.origin.getMinY(),
z + this.origin.getMinZ()
);
}

@Override
public int getLightBrightnessForSkyBlocks(int x, int y, int z, int p_72802_4_) {
return delegate.getLightBrightnessForSkyBlocks(
x + this.origin.getMinX(),
y + this.origin.getMinY(),
z + this.origin.getMinZ(),
p_72802_4_
);
}

@Override
public int getBlockMetadata(int x, int y, int z) {
return delegate.getBlockMetadata(
x + this.origin.getMinX(),
y + this.origin.getMinY(),
z + this.origin.getMinZ()
);
}

@Override
public int isBlockProvidingPowerTo(int x, int y, int z, int directionIn) {
return delegate.isBlockProvidingPowerTo(
x + this.origin.getMinX(),
y + this.origin.getMinY(),
z + this.origin.getMinZ(),
directionIn
);
}

@Override
public boolean isAirBlock(int x, int y, int z) {
return delegate.isAirBlock(
x + this.origin.getMinX(),
y + this.origin.getMinY(),
z + this.origin.getMinZ()
);
}

@Override
public BiomeGenBase getBiomeGenForCoords(int x, int z) {
return delegate.getBiomeGenForCoords(
x + this.origin.getMinX(),
z + this.origin.getMinZ()
);
}

@Override
public int getHeight() {
return delegate.getHeight();
}

@Override
public boolean extendedLevelsInChunkCache() {
return delegate.extendedLevelsInChunkCache();
}

@Override
public boolean isSideSolid(int x, int y, int z, ForgeDirection side, boolean _default) {
return delegate.isSideSolid(
x + this.origin.getMinX(),
y + this.origin.getMinY(),
z + this.origin.getMinZ(),
side,
_default
);
}
}
}

0 comments on commit 99a8136

Please sign in to comment.