clean up Structure API

This commit is contained in:
dfsek
2021-12-19 23:13:57 -07:00
parent 30b02a03c4
commit f088928483
10 changed files with 112 additions and 128 deletions

View File

@@ -96,7 +96,7 @@ public class SpongeSchematicAddon implements AddonInitializer {
}
}
return new SpongeStructure(states, platform, id);
return new SpongeStructure(states, id);
} catch(IOException e) {
throw new IllegalArgumentException("Failed to parse Sponge schematic: ", e);
}

View File

@@ -7,75 +7,28 @@
package com.dfsek.terra.addons.sponge;
import net.jafama.FastMath;
import java.util.Random;
import com.dfsek.terra.api.Platform;
import com.dfsek.terra.api.block.state.BlockState;
import com.dfsek.terra.api.structure.Structure;
import com.dfsek.terra.api.structure.buffer.Buffer;
import com.dfsek.terra.api.structure.buffer.items.BufferedBlock;
import com.dfsek.terra.api.util.Rotation;
import com.dfsek.terra.api.util.vector.Vector3;
import com.dfsek.terra.api.util.vector.integer.Vector2Int;
import com.dfsek.terra.api.world.WritableWorld;
import com.dfsek.terra.api.world.chunk.Chunk;
public class SpongeStructure implements Structure {
private final BlockState[][][] blocks;
private final Platform platform;
private final String id;
public SpongeStructure(BlockState[][][] blocks, Platform platform, String id) {
public SpongeStructure(BlockState[][][] blocks, String id) {
this.blocks = blocks;
this.platform = platform;
this.id = id;
}
@Override
public boolean generate(Vector3 location, WritableWorld world, Chunk chunk, Random random, Rotation rotation) {
int bX = location.getBlockX();
int bY = location.getBlockY();
int bZ = location.getBlockZ();
for(int x = 0; x < blocks.length; x++) {
for(int z = 0; z < blocks[x].length; z++) {
Vector2Int r = Vector2Int.of(x, z).rotate(rotation);
int rX = r.getX();
int rZ = r.getZ();
if(FastMath.floorDiv(bX + rX, 16) != chunk.getX() || FastMath.floorDiv(bZ + rZ, 16) != chunk.getZ()) {
continue;
}
for(int y = 0; y < blocks[z].length; y++) {
BlockState state = blocks[x][z][y];
if(state == null) continue;
world.setBlockState(bX + rX, bY + y, bZ + rZ, state);
}
}
}
return true;
}
@Override
public boolean generate(Buffer buffer, WritableWorld world, Random random, Rotation rotation, int recursions) {
for(int x = 0; x < blocks.length; x++) {
for(int z = 0; z < blocks[x].length; z++) {
Vector2Int r = Vector2Int.of(x, z).rotate(rotation);
int rX = r.getX();
int rZ = r.getZ();
for(int y = 0; y < blocks[z].length; y++) {
BlockState state = blocks[x][z][y];
if(state == null) continue;
buffer.addItem(new BufferedBlock(state, true, platform, false), new Vector3(rX, y, rZ));
}
}
}
return true;
}
@Override
public boolean generate(Vector3 location, WritableWorld world, Random random, Rotation rotation) {
int bX = location.getBlockX();