added terrain slice to preview gui

This commit is contained in:
dags- 2020-03-21 13:19:42 +00:00
parent a6f896be93
commit bc4a6db5fc
3 changed files with 47 additions and 13 deletions

View File

@ -54,14 +54,16 @@ import java.util.concurrent.Future;
public class Preview extends Button {
private static final int FACTOR = 4;
private static final int BLOCK_SIZE = 256;//Size.chunkToBlock(1 << FACTOR);
public static final int WIDTH = 256;//Size.chunkToBlock(1 << FACTOR);
private static final int SLICE_HEIGHT = 64;
public static final int HEIGHT = WIDTH + SLICE_HEIGHT;//Size.chunkToBlock(1 << FACTOR);
private static final float[] LEGEND_SCALES = {1, 0.9F, 0.75F, 0.6F};
private final int offsetX;
private final int offsetZ;
private final Random random = new Random(System.currentTimeMillis());
private final PreviewSettings previewSettings = new PreviewSettings();
private final DynamicTexture texture = new DynamicTexture(new NativeImage(BLOCK_SIZE, BLOCK_SIZE, true));
private final DynamicTexture texture = new DynamicTexture(new NativeImage(WIDTH, HEIGHT, true));
private int seed;
private long lastUpdate = 0L;
@ -93,6 +95,9 @@ public class Preview extends Button {
@Override
public void render(int mx, int my, float partialTicks) {
float scale = width / (float) WIDTH;
height = width + NoiseUtil.round(SLICE_HEIGHT * scale);
preRender();
texture.bindTexture();
@ -105,7 +110,7 @@ public class Preview extends Button {
RenderSystem.disableRescaleNormal();
updateLegend(mx, my);
renderLegend(labels, values, x + 1, y + height + 2, 15, 0xFFFFFF);
renderLegend(labels, values, x, y + width, 10, 0xFFFFFF);
}
public void update(Settings settings, CompoundNBT prevSettings) {
@ -148,13 +153,43 @@ public class Preview extends Button {
int stroke = 2;
int width = region.getBlockSize().size;
int zoom = (101 - previewSettings.zoom);
int half = width / 2;
int sliceStartY = image.getHeight() - 1 - SLICE_HEIGHT;
float zoomUnit = 1F - (zoom / 100F);
float zoomStrength = 0.5F;
float unit = (1 - zoomStrength) + (zoomStrength * zoomUnit);
float heightModifier = settings.generator.world.worldHeight / 256F;
float waterLevelModifier = settings.generator.world.seaLevel / (float) settings.generator.world.worldHeight;
float imageWaterLevelY = image.getHeight() - 1 - (waterLevelModifier * SLICE_HEIGHT * unit);
region.iterate((cell, x, z) -> {
if (x < stroke || z < stroke || x >= width - stroke || z >= width - stroke) {
image.setPixelRGBA(x, z, Color.black.getRGB());
image.setPixelRGBA(x, z, Color.BLACK.getRGB());
} else {
Color color = renderer.color(cell, context);
image.setPixelRGBA(x, z, RenderMode.rgba(color));
}
if (z == half) {
int height = (int) (cell.value * SLICE_HEIGHT * unit * heightModifier);
float imageSurfaceLevelY = image.getHeight() - 1 - height;
for (int dy = sliceStartY; dy < image.getHeight(); dy++) {
if (x < stroke || x >= width - stroke || dy > image.getHeight() - 1 - stroke) {
image.setPixelRGBA(x, dy, Color.BLACK.getRGB());
continue;
}
if (dy > imageSurfaceLevelY) {
image.setPixelRGBA(x, dy, Color.BLACK.getRGB());
} else if (dy > imageWaterLevelY) {
image.setPixelRGBA(x, dy, Color.GRAY.getRGB());
} else {
image.setPixelRGBA(x, dy, Color.WHITE.getRGB());
}
}
}
});
texture.updateDynamicTexture();
@ -173,7 +208,7 @@ public class Preview extends Button {
.size(FACTOR, 0)
.build();
return renderer.generate(offsetX, offsetZ, 101 - previewSettings.zoom, false);
return renderer.generate(offsetX, offsetZ, 101 - previewSettings.zoom, true);
}
private void updateLegend(int mx ,int my) {
@ -208,10 +243,9 @@ public class Preview extends Button {
private void renderLegend(String[] labels, String[] values, int left, int top, int lineHeight, int color) {
float scale = getLegendScale();
lineHeight = Math.round(lineHeight * scale);
RenderSystem.pushMatrix();
RenderSystem.translatef(left, top, 0);
RenderSystem.translatef(left + 3.75F * scale, top - lineHeight * (3.2F * scale), 0);
RenderSystem.scalef(scale, scale, 1);
FontRenderer renderer = Minecraft.getInstance().fontRenderer;
@ -220,12 +254,12 @@ public class Preview extends Button {
spacing = Math.max(spacing, renderer.getStringWidth(s));
}
int maxX = this.x + this.width;
float maxWidth = (width - 4) / scale;
for (int i = 0; i < labels.length && i < values.length; i++) {
String label = labels[i];
String value = values[i];
while (left + spacing + Minecraft.getInstance().fontRenderer.getStringWidth(value) > maxX) {
while (value.length() > 0 && spacing + Minecraft.getInstance().fontRenderer.getStringWidth(value) > maxWidth) {
value = value.substring(0, value.length() - 1);
}

View File

@ -68,8 +68,8 @@ public class PreviewPage extends BasePage {
Column right = getColumn(1);
preview.x = 0;
preview.y = 0;
preview.setWidth(256);
preview.setHeight(256);
preview.setWidth(Preview.WIDTH);
preview.setHeight(Preview.HEIGHT);
addElements(right.left, right.top, right, previewerSettings, right.scrollPane::addButton, this::update);
right.scrollPane.addButton(new TerraButton("New Seed") {
@ -84,7 +84,7 @@ public class PreviewPage extends BasePage {
// used to pad the scroll-pane out so that the preview legend scrolls on larger gui scales
TerraButton spacer = createSpacer();
for (int i = 0; i < 6; i++) {
for (int i = 0; i < 7; i++) {
right.scrollPane.addButton(spacer);
}

View File

@ -47,7 +47,7 @@ public enum RenderMode {
}
float bands = 10F;
float alpha = 0.15F;
float alpha = 0.2F;
float elevation = (cell.value - baseHeight) / (1F - baseHeight);
int band = NoiseUtil.round(elevation * bands);