package eu.mhsl.minenet.minigames.world.generator.structures.generatable;

import eu.mhsl.minenet.minigames.world.generator.structures.Structure;
import net.minestom.server.coordinate.Point;
import net.minestom.server.instance.block.Block;

public class Tree extends Structure {
    private final Point position;

    public Tree(Point position) {
        this.position = position;
    }

    @Override
    public void generateStructure(Block.Setter setter) {
        int trunkX = position.blockX();
        int trunkBottomY = position.blockY();
        int trunkZ = position.blockZ();

        for (int i = 0; i < 2; i++) {
            setter.setBlock(trunkX + 1, trunkBottomY + 3 + i, trunkZ, Block.OAK_LEAVES);
            setter.setBlock(trunkX - 1, trunkBottomY + 3 + i, trunkZ, Block.OAK_LEAVES);
            setter.setBlock(trunkX, trunkBottomY + 3 + i, trunkZ + 1, Block.OAK_LEAVES);
            setter.setBlock(trunkX, trunkBottomY + 3 + i, trunkZ - 1, Block.OAK_LEAVES);

            for (int x = -1; x <= 1; x++) {
                for (int z = -1; z <= 1; z++) {
                    setter.setBlock(trunkX + x, trunkBottomY + 2 + i, trunkZ - z, Block.OAK_LEAVES);
                }
            }
        }

        setter.setBlock(trunkX, trunkBottomY, trunkZ, Block.OAK_LOG);
        setter.setBlock(trunkX, trunkBottomY + 1, trunkZ, Block.OAK_LOG);
        setter.setBlock(trunkX, trunkBottomY + 2, trunkZ, Block.OAK_LOG);
        setter.setBlock(trunkX, trunkBottomY + 3, trunkZ, Block.OAK_LOG);
        setter.setBlock(trunkX, trunkBottomY + 4, trunkZ, Block.OAK_LEAVES);
    }
}
