Skip to content

Commit

Permalink
refactor NetherRoofRenderer
Browse files Browse the repository at this point in the history
  • Loading branch information
granny committed Mar 26, 2024
1 parent 0005ee8 commit 9eb99be
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 98 deletions.
100 changes: 3 additions & 97 deletions core/src/main/java/net/pl3x/map/core/renderer/NetherRoofRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,113 +23,19 @@
*/
package net.pl3x.map.core.renderer;

import net.pl3x.map.core.Pl3xMap;
import net.pl3x.map.core.renderer.heightmap.Heightmap;
import net.pl3x.map.core.renderer.task.RegionScanTask;
import net.pl3x.map.core.util.Colors;
import net.pl3x.map.core.world.BlockState;
import net.pl3x.map.core.world.Chunk;
import net.pl3x.map.core.world.EmptyChunk;
import net.pl3x.map.core.world.Region;
import org.jetbrains.annotations.NotNull;

public class NetherRoofRenderer extends Renderer {
private final Heightmap heightmap;
public class NetherRoofRenderer extends VanillaRenderer {

public NetherRoofRenderer(@NotNull RegionScanTask task, @NotNull Builder builder) {
super(task, builder);
this.heightmap = Pl3xMap.api().getHeightmapRegistry().get("old_school");
}

@Override
public @NotNull Heightmap getHeightmap() {
return this.heightmap;
}

@Override
public void scanData(@NotNull Region region) {
int startX = region.getX() << 9;
int startZ = region.getZ() << 9;

for (int pixelX = 0; pixelX < 512; pixelX++) {
int blockX = startX + pixelX;
double lastBlockY = 0.0D;
for (int pixelZ = -1; pixelZ < 512; pixelZ++) {
int blockZ = startZ + pixelZ;

if (!getWorld().visibleBlock(blockX, blockZ)) {
continue;
}

Pl3xMap.api().getRegionProcessor().checkPaused();

Chunk chunk = region.getWorld().getChunk(region, blockX >> 4, blockZ >> 4);
if (chunk instanceof EmptyChunk) {
continue;
}

int blockY = chunk.noHeightmap() ? getWorld().getMaxBuildHeight() : chunk.getWorldSurfaceY(blockX, blockZ) + 1;
int fluidY = 0;
BlockState blockstate;
BlockState fluidstate = null;

// iterate down until we find a renderable block
do {
blockY -= 1;
blockstate = chunk.getBlockState(blockX, blockY, blockZ);
if (blockstate.getBlock().isFluid()) {
if (fluidstate == null) {
// get fluid information for the top fluid block
fluidY = blockY;
fluidstate = blockstate;
}
continue;
}

// test if block is renderable. we ignore blocks with black color
if (blockstate.getBlock().vanilla() > 0) {
break;
}
} while (blockY > getWorld().getMinBuildHeight());

if (pixelZ >= 0) {
int color;
int brightness;
if (fluidstate != null) {
color = fluidstate.getBlock().vanilla();
double heightDiff = (double) (fluidY - blockY) * 0.1D + (double) (pixelX + pixelZ & 1) * 0.2D;
if (heightDiff < 0.5D) {
brightness = 0x00;
} else if (heightDiff > 0.9D) {
brightness = 0x44;
} else {
brightness = 0x22;
}
} else {
color = blockstate.getBlock().vanilla();
double heightDiff = (blockY - lastBlockY) * 4.0D / (double) (1 + 4) + ((double) (pixelX + pixelZ & 1) - 0.5D) * 0.4D;
if (heightDiff > 0.6D) {
brightness = 0x00;
} else if (heightDiff < -0.6D) {
brightness = 0x44;
} else {
brightness = 0x22;
}
}

getTileImage().setPixel(pixelX, pixelZ, Colors.blend(brightness << 24, Colors.setAlpha(0xFF, color)));
}

if (blockstate.getBlock().isFlat()) {
blockY--;
}

lastBlockY = blockY;
}
}
}

@Override
public void scanBlock(@NotNull Region region, @NotNull Chunk chunk, Chunk.@NotNull BlockData data, int blockX, int blockZ) {
protected int getBlockBelowCeiling(int blockY, Chunk chunk, int blockX, int blockZ) {
return blockY;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ private void setPixel(int pixelZ, BlockState fluidstate, int fluidY, int blockY,
}
}

private int getBlockBelowCeiling(int blockY, Chunk chunk, int blockX, int blockZ) {
protected int getBlockBelowCeiling(int blockY, Chunk chunk, int blockX, int blockZ) {
BlockState blockstate;
if (getWorld().hasCeiling()) {
blockY = getWorld().getLogicalHeight();
Expand Down

0 comments on commit 9eb99be

Please sign in to comment.