mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 00:04:42 +00:00
Keep a clipped sea-surface stack ending on its top palette block
A stack cut short by the height limit stopped on a body block because the top threshold was computed from the unclipped length. Clamp the stack to the room under the ceiling before placing, and treat a single-block stack as the top block. Upstream:75353d43c5baea8dd5
This commit is contained in:
1 parent
e004ae1775
commit
0d9ea26cc9
2 files changed
+80
-19
No files matched your search
+70
@@ -0,0 +1,70 @@
|
||||
package art.arcane.iris.engine.decorator;
|
||||
|
||||
import art.arcane.iris.builtin.decorant.DecorationPart;
|
||||
import art.arcane.iris.engine.modifier.ApiChunk;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.host.ArrayHunk;
|
||||
import com.volmit.host.ModuleLogs;
|
||||
import com.volmit.hunk.Hunk;
|
||||
import com.volmit.world.BiomeKind;
|
||||
import com.volmit.world.TerrainSampler;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.mockito.ArgumentMatchers.anyDouble;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class IrisSeaSurfaceDecoratorBoundsTest {
|
||||
private static final int WORLD_HEIGHT = 8;
|
||||
private static final int TALL_STACK = 30;
|
||||
private static final double TOP_THRESHOLD = 0.9;
|
||||
private static final BlockState AIR = ApiChunk.AIR;
|
||||
private static final BlockState BODY = new BlockState("minecraft:kelp_plant");
|
||||
private static final BlockState TOP = new BlockState("minecraft:kelp");
|
||||
private static final DecoratedBiome BIOME = new DecoratedBiome("ocean", null, BiomeKind.SEA);
|
||||
|
||||
@Test
|
||||
public void stackClippedByTheCeilingEndsOnTheTopBlock() {
|
||||
Hunk<BlockState> blocks = decorate(4, TALL_STACK);
|
||||
|
||||
assertSame(BODY, blocks.get(0, 5, 0));
|
||||
assertSame(BODY, blocks.get(0, 6, 0));
|
||||
assertSame(TOP, blocks.get(0, 7, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stackOfOneBelowTheCeilingIsTheTopBlock() {
|
||||
Hunk<BlockState> blocks = decorate(6, 1);
|
||||
|
||||
assertSame(TOP, blocks.get(0, 7, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void baseAtTheCeilingPlacesNothing() {
|
||||
Hunk<BlockState> blocks = decorate(WORLD_HEIGHT - 1, TALL_STACK);
|
||||
|
||||
for (int y = 0; y < WORLD_HEIGHT; y++) {
|
||||
assertSame(AIR, blocks.get(0, y, 0));
|
||||
}
|
||||
}
|
||||
|
||||
private Hunk<BlockState> decorate(int height, int stackHeight) {
|
||||
TerrainSampler terrain = mock(TerrainSampler.class);
|
||||
ResolvedDecorator decorator = mock(ResolvedDecorator.class);
|
||||
BiomeDecorators decorators = mock(BiomeDecorators.class);
|
||||
when(decorators.decorators(BIOME, DecorationPart.SEA_SURFACE)).thenReturn(new ResolvedDecorator[]{decorator});
|
||||
when(decorator.passesChanceGate(anyDouble(), anyDouble())).thenReturn(true);
|
||||
when(decorator.isStacking()).thenReturn(true);
|
||||
when(decorator.stackHeight(anyDouble(), anyDouble())).thenReturn(stackHeight);
|
||||
when(decorator.topThreshold()).thenReturn(TOP_THRESHOLD);
|
||||
when(decorator.blockAt(anyDouble(), anyDouble(), anyDouble())).thenReturn(BODY);
|
||||
when(decorator.topBlockAt(anyDouble(), anyDouble(), anyDouble())).thenReturn(TOP);
|
||||
Hunk<BlockState> blocks = new ArrayHunk<>(BlockState.class, 1, WORLD_HEIGHT, 1, AIR);
|
||||
DecorationScene scene = new DecorationScene(blocks, ApiChunk.blockRegistry(), terrain, null, decorators, 17L,
|
||||
ModuleLogs.discarding());
|
||||
|
||||
new IrisSeaSurfaceDecorator(scene).decorate(0, 0, 0, 1, -1, 0, 1, -1, BIOME, height, WORLD_HEIGHT);
|
||||
return blocks;
|
||||
}
|
||||
}
|
||||
+10
-19
@@ -29,6 +29,12 @@ public class IrisSeaSurfaceDecorator extends IrisEngineDecorator {
|
||||
@Override
|
||||
public void decorate(int x, int z, int realX, int realX1, int realX_1, int realZ, int realZ1, int realZ_1,
|
||||
DecoratedBiome biome, int height, int max) {
|
||||
var data = scene.blocks();
|
||||
int maxBaseY = Math.min(max, Math.min(scene.worldHeight(), data.height()) - 1);
|
||||
if (height < 0 || height >= maxBaseY) {
|
||||
return;
|
||||
}
|
||||
|
||||
RNG rng = getRNG(realX, realZ);
|
||||
ResolvedDecorator decorator = DecoratorCore.pickDecorator(decorators.decorators(biome, getPart()), rng, realX, realZ, decorators.log());
|
||||
|
||||
@@ -36,11 +42,9 @@ public class IrisSeaSurfaceDecorator extends IrisEngineDecorator {
|
||||
return;
|
||||
}
|
||||
|
||||
var data = scene.blocks();
|
||||
if (!decorator.isStacking()) {
|
||||
int targetY = height + 1;
|
||||
if (height >= 0 && targetY < scene.worldHeight()
|
||||
&& DecoratorCore.canReplaceStackTarget(scene, data.get(x, targetY, z), false)) {
|
||||
if (DecoratorCore.canReplaceStackTarget(scene, data.get(x, targetY, z), false)) {
|
||||
BlockState block = decorator.blockAt(realX, height, realZ);
|
||||
if (block != null) {
|
||||
data.set(x, targetY, z, block);
|
||||
@@ -54,28 +58,15 @@ public class IrisSeaSurfaceDecorator extends IrisEngineDecorator {
|
||||
stack = (int) Math.ceil((double) (max - height) * ((double) stack / 100));
|
||||
}
|
||||
|
||||
if (stack == 1) {
|
||||
int targetY = height + 1;
|
||||
if (targetY >= data.height() || !DecoratorCore.canReplaceStackTarget(scene, data.get(x, targetY, z), false)) {
|
||||
return;
|
||||
}
|
||||
stack = Math.min(stack, maxBaseY - height);
|
||||
|
||||
BlockState block = decorator.topBlockAt(realX, height, realZ);
|
||||
if (block != null) {
|
||||
data.set(x, targetY, z, block);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
int engineHeight = scene.worldHeight();
|
||||
for (int i = 0; i < stack; i++) {
|
||||
int h = height + i;
|
||||
int targetY = h + 1;
|
||||
if (h >= max || targetY >= engineHeight
|
||||
|| !DecoratorCore.canReplaceStackTarget(scene, data.get(x, targetY, z), false)) {
|
||||
if (!DecoratorCore.canReplaceStackTarget(scene, data.get(x, targetY, z), false)) {
|
||||
break;
|
||||
}
|
||||
double threshold = ((double) i) / (stack - 1);
|
||||
double threshold = stack == 1 ? 1.0 : ((double) i) / (stack - 1);
|
||||
BlockState block = threshold >= decorator.topThreshold()
|
||||
? decorator.topBlockAt(realX, h, realZ)
|
||||
: decorator.blockAt(realX, h, realZ);
|
||||
|
||||
Reference in new issue
Block a user