From e971223e4f6d5d69c4d9c21d9782528ea5b6d00a Mon Sep 17 00:00:00 2001 From: dfsek Date: Fri, 15 Oct 2021 22:15:35 -0700 Subject: [PATCH] implement SpongeStructure --- .../terra/addons/sponge/SpongeStructure.java | 59 +++++++++++++++++-- 1 file changed, 54 insertions(+), 5 deletions(-) diff --git a/common/addons/structure-sponge-loader/src/main/java/com/dfsek/terra/addons/sponge/SpongeStructure.java b/common/addons/structure-sponge-loader/src/main/java/com/dfsek/terra/addons/sponge/SpongeStructure.java index 9d3496098..8e7a7852d 100644 --- a/common/addons/structure-sponge-loader/src/main/java/com/dfsek/terra/addons/sponge/SpongeStructure.java +++ b/common/addons/structure-sponge-loader/src/main/java/com/dfsek/terra/addons/sponge/SpongeStructure.java @@ -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; } }