Damián Huba

replace classic 1x1 oak with 2x2 oak that would look structurally be like 2x2 dark oak but it would be a classic normal oak.

Kodari AI
KodariOct 12 at 4:52 pm 1
OakExpansion
Replaces classic 1x1 oak logs with 2x2 oak logs that structurally resemble 2x2 dark oak but use classic normal oak texture. When players place a single oak log, the plugin automatically converts it to a 2x2 formation if space allows, creating a thicker, more robust oak pillar appearance. The plugin handles block placement events, checks surrounding air blocks, and places the four oak logs simultaneously. It also manages breaking mechanics so when one log in the 2x2 formation is broken, the entire structure collapses naturally. Compatible with all oak log variants including stripped and bark types.

I’ll create a plugin that replaces natural oak growth with a 2×2 oak-log trunk and a canopy of persistent oak leaves.

Created OakGrove. Natural oak growth now produces a 2×2 oak-log trunk with a classic oak-leaf canopy; other tree types are unchanged. If there isn’t enough clear space, the normal oak growth proceeds instead.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
4 170
src/main/java/com/kodari/oakgrove/OakGrovePlugin.java
package com.kodari.oakgrove;

import com.cryptomorin.xseries.XMaterial;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.type.Leaves;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.world.StructureGrowEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.TreeType;

import java.util.concurrent.ThreadLocalRandom;

public final class OakGrovePlugin extends JavaPlugin implements Listener {
    private Material oakSapling;
    private Material oakLog;
    private Material oakLeaves;

    @Override
    public void onEnable() {
        oakSapling = resolveMaterial("OAK_SAPLING");
        oakLog = resolveMaterial("OAK_LOG");
        oakLeaves = resolveMaterial("OAK_LEAVES");
        getServer().getPluginManager().registerEvents(this, this);
    }

    @EventHandler(ignoreCancelled = true)
    public void onOakGrow(StructureGrowEvent event) {
        if (event.getSpecies() != TreeType.TREE && event.getSpecies() != TreeType.BIG_TREE) {
            return;
        }

        Block base = findSaplingOrigin(event.getLocation().getBlock());
        int height = ThreadLocalRandom.current().nextInt(5, 8);
        if (!canPlaceTree(base, height)) {
            return;
        }

        event.setCancelled(true);
        placeTree(base, height);
    }

    private Block findSaplingOrigin(Block trigger) {
        for (int xOffset = -1; xOffset <= 0; xOffset++) {
            for (int zOffset = -1; zOffset <= 0; zOffset++) {
                Block candidate = trigger.getRelative(xOffset, 0, zOffset);
                if (isSapling(candidate)
                        && isSapling(candidate.getRelative(1, 0, 0))
                        && isSapling(candidate.getRelative(0, 0, 1))
                        && isSapling(candidate.getRelative(1, 0, 1))) {
                    return candidate;
                }
            }
        }
        return trigger;
    }

    private boolean canPlaceTree(Block base, int height) {
        for (int y = 0; y < height; y++) {
            for (int x = 0; x < 2; x++) {
                for (int z = 0; z < 2; z++) {
                    if (!canReplace(base.getRelative(x, y, z))) {
                        return false;
                    }
                }
            }
        }

        for (int layer = 0; layer < 4; layer++) {
            int radius = layer < 2 ? 2 : 1;
            int y = height - 2 + layer;
            for (int x = -radius; x <= 1 + radius; x++) {
                for (int z = -radius; z <= 1 + radius; z++) {
                    if (isCanopyCorner(x, z, radius) || isTrunkPosition(x, z)) {
                        continue;
                    }
                    if (!canReplace(base.getRelative(x, y, z))) {
                        return false;
                    }
                }
            }
        }
        return true;
    }

    private void placeTree(Block base, int height) {
        for (int y = 0; y < height; y++) {
            for (int x = 0; x < 2; x++) {
                for (int z = 0; z < 2; z++) {
                    base.getRelative(x, y, z).setType(oakLog, false);
                }
            }
        }

        for (int layer = 0; layer < 4; layer++) {
            int radius = layer < 2 ? 2 : 1;
            int y = height - 2 + layer;
            for (int x = -radius; x <= 1 + radius; x++) {
                for (int z = -radius; z <= 1 + radius; z++) {
                    if (isCanopyCorner(x, z, radius) || isTrunkPosition(x, z)) {
                        continue;
                    }
                    Block leafBlock = base.getRelative(x, y, z);
                    leafBlock.setType(oakLeaves, false);
                    BlockData data = leafBlock.getBlockData();
                    if (data instanceof Leaves leaves) {
                        leaves.setPersistent(true);
                        leafBlock.setBlockData(leaves, false);
                    }
                }
            }
        }
    }

    private boolean isSapling(Block block) {
        return block.getType().equals(oakSapling);
    }

    private boolean canReplace(Block block) {
        Material type = block.getType();
        return type.isAir() || type.equals(oakSapling) || type.equals(oakLeaves);
    }

    private boolean isTrunkPosition(int x, int z) {
        return x >= 0 && x <= 1 && z >= 0 && z <= 1;
    }

    private boolean isCanopyCorner(int x, int z, int radius) {
        int min = -radius;
        int max = 1 + radius;
        return (x == min || x == max) && (z == min || z == max);
    }

    private Material resolveMaterial(String name) {
        return XMaterial.matchXMaterial(name)
                .map(XMaterial::parseMaterial)
                .orElseThrow(() -> new IllegalStateException("Unsupported material: " + name));
    }
}