mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 10:30:42 +00:00
implement SpongeStructure
This commit is contained in:
@@ -1,42 +1,91 @@
|
||||
package com.dfsek.terra.addons.sponge;
|
||||
|
||||
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.BufferedItem;
|
||||
import com.dfsek.terra.api.structure.buffer.items.BufferedBlock;
|
||||
import com.dfsek.terra.api.structure.rotation.Rotation;
|
||||
import com.dfsek.terra.api.util.RotationUtil;
|
||||
import com.dfsek.terra.api.util.vector.Vector2;
|
||||
import com.dfsek.terra.api.util.vector.Vector3;
|
||||
import com.dfsek.terra.api.world.Chunk;
|
||||
import com.dfsek.terra.api.world.World;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
|
||||
public class SpongeStructure implements Structure {
|
||||
|
||||
private final BufferedItem[][][] blocks;
|
||||
private final BlockState[][][] blocks;
|
||||
private final Platform platform;
|
||||
|
||||
public SpongeStructure() {
|
||||
blocks = new BufferedItem[0][][];
|
||||
private final String id;
|
||||
|
||||
public SpongeStructure(BlockState[][][] blocks, Platform platform, String id) {
|
||||
this.blocks = blocks;
|
||||
this.platform = platform;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean generate(Vector3 location, World 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++) {
|
||||
Vector2 r = RotationUtil.rotateVector(new Vector2(x, z), rotation);
|
||||
int rX = r.getBlockX();
|
||||
int rZ = r.getBlockZ();
|
||||
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++) {
|
||||
world.setBlockData(bX+rX, bY+y, bZ+rZ, blocks[x][z][y]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean generate(Buffer buffer, World world, Random random, Rotation rotation, int recursions) {
|
||||
for(int x = 0; x < blocks.length; x++) {
|
||||
for(int z = 0; z < blocks[x].length; z++) {
|
||||
Vector2 r = RotationUtil.rotateVector(new Vector2(x, z), rotation);
|
||||
int rX = r.getBlockX();
|
||||
int rZ = r.getBlockZ();
|
||||
for(int y = 0; y < blocks[z].length; y++) {
|
||||
buffer.addItem(new BufferedBlock(blocks[x][z][y], true, platform, false), new Vector3(rX, y, rZ));
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean generate(Vector3 location, World world, 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++) {
|
||||
Vector2 r = RotationUtil.rotateVector(new Vector2(x, z), rotation);
|
||||
int rX = r.getBlockX();
|
||||
int rZ = r.getBlockZ();
|
||||
for(int y = 0; y < blocks[z].length; y++) {
|
||||
world.setBlockData(bX+rX, bY+y, bZ+rZ, blocks[x][z][y]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getID() {
|
||||
return null;
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user