Brandon Summerlin

Im wanting to make a custom endless sand dimension. The big things i want from it are. 1. a portal that i can build in game to go into it 2. custom structures 3. make sure the sand is not floating make sure its on stable ground with no air blocks beneath use sandstone to support if needed, like how current desert biomes are generated. 4. a portal i can build to go back to the overworld

Kodari AI
KodariWed at 5:13 am 2
EndlessSandRealm
A custom endless sand dimension plugin. Players construct a buildable portal in-game to enter a vast desert realm. The dimension generates stable terrain with sandstone support beneath sand layers, preventing floating blocks, similar to vanilla desert biomes. Custom structures spawn throughout the realm. A return portal built inside the dimension teleports players back to the overworld. The plugin handles dimension registration, portal detection, terrain generation with proper block support, structure placement, and bidirectional travel mechanics.

I’ll use a buildable obsidian portal activated with flint and steel, and generate a sand-and-sandstone world with desert structures. Players can return through a portal there to where they entered.

Created the endless sand world with solid sandstone beneath the sand, scattered pyramids, and a return portal.

To travel there, build a 4-wide × 5-high obsidian frame and right-click it with flint and steel. The portal in the desert returns you to where you entered.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
Code
4 235
src/main/java/com/kodari/endlesssand/EndlessSandPlugin.java
package com.kodari.endlesssand;

import com.cryptomorin.xseries.XMaterial;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import org.bukkit.Axis;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.WorldCreator;
import org.bukkit.block.Block;
import org.bukkit.block.data.Orientable;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerPortalEvent;
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.plugin.java.JavaPlugin;

public final class EndlessSandPlugin extends JavaPlugin implements Listener {
    private final Material obsidian = material("OBSIDIAN");
    private final Material portal = material("NETHER_PORTAL");
    private final Material flintAndSteel = material("FLINT_AND_STEEL");
    private final Set<String> portalBlocks = new HashSet<>();
    private final Map<UUID, Long> cooldowns = new HashMap<>();
    private World desert;
    private Location desertArrival;

    private static Material material(String name) {
        return XMaterial.matchXMaterial(name).map(XMaterial::parseMaterial).orElseThrow();
    }

    @Override
    public void onEnable() {
        portalBlocks.addAll(getConfig().getStringList("portal-blocks"));
        desert = Bukkit.createWorld(new WorldCreator("endless_sand").generator(new DesertGenerator()));
        if (desert == null) {
            getLogger().severe("Could not create the endless sand world.");
            Bukkit.getPluginManager().disablePlugin(this);
            return;
        }
        int y = desert.getHighestBlockYAt(0, 0) + 1;
        buildPortal(desert, 0, y, 0);
        desertArrival = new Location(desert, 1.5, y, -1.5, 0, 0);
        Bukkit.getPluginManager().registerEvents(this, this);
    }

    @Override
    public ChunkGenerator getDefaultWorldGenerator(String worldName, String id) {
        return new DesertGenerator();
    }

    private void buildPortal(World world, int x, int y, int z) {
        for (int dx = 0; dx < 4; dx++) {
            for (int dy = 0; dy < 5; dy++) {
                Block block = world.getBlockAt(x + dx, y + dy, z);
                if (dx == 0 || dx == 3 || dy == 0 || dy == 4) {
                    block.setType(obsidian, false);
                } else {
                    setPortal(block, Axis.X);
                }
            }
        }
        savePortals();
    }

    private void setPortal(Block block, Axis axis) {
        block.setType(portal, false);
        Orientable data = (Orientable) block.getBlockData();
        data.setAxis(axis);
        block.setBlockData(data, false);
        portalBlocks.add(key(block));
    }

    private String key(Block block) {
        return block.getWorld().getUID() + ":" + block.getX() + ":" + block.getY() + ":" + block.getZ();
    }

    private void savePortals() {
        getConfig().set("portal-blocks", new ArrayList<>(portalBlocks));
        saveConfig();
    }

    @EventHandler(ignoreCancelled = true)
    public void onInteract(PlayerInteractEvent event) {
        if (event.getAction() != Action.RIGHT_CLICK_BLOCK || event.getHand() != EquipmentSlot.HAND
                || event.getItem() == null || event.getItem().getType() != flintAndSteel
                || event.getClickedBlock() == null || event.getClickedBlock().getType() != obsidian) return;
        Block clicked = event.getClickedBlock();
        for (Axis axis : new Axis[] {Axis.X, Axis.Z}) {
            for (int horizontal = 0; horizontal < 4; horizontal++) {
                for (int vertical = 0; vertical < 5; vertical++) {
                    int x = clicked.getX() - (axis == Axis.X ? horizontal : 0);
                    int z = clicked.getZ() - (axis == Axis.Z ? horizontal : 0);
                    int y = clicked.getY() - vertical;
                    if (activate(clicked.getWorld(), x, y, z, axis)) {
                        event.setCancelled(true);
                        event.getPlayer().sendMessage("\u00a76Sand portal activated!");
                        return;
                    }
                }
            }
        }
    }

    private boolean activate(World world, int x, int y, int z, Axis axis) {
        if (y < world.getMinHeight() || y + 4 >= world.getMaxHeight()) return false;
        List<Block> interior = new ArrayList<>();
        for (int h = 0; h < 4; h++) {
            for (int v = 0; v < 5; v++) {
                Block block = world.getBlockAt(x + (axis == Axis.X ? h : 0), y + v,
                        z + (axis == Axis.Z ? h : 0));
                if (h == 0 || h == 3 || v == 0 || v == 4) {
                    if (block.getType() != obsidian) return false;
                } else {
                    if (!block.getType().isAir() && block.getType() != portal) return false;
                    interior.add(block);
                }
            }
        }
        for (Block block : interior) setPortal(block, axis);
        savePortals();
        return true;
    }

    @EventHandler(ignoreCancelled = true)
    public void onMove(PlayerMoveEvent event) {
        Location to = event.getTo();
        if (to == null || to.getBlock().getType() != portal || !portalBlocks.contains(key(to.getBlock()))) return;
        Player player = event.getPlayer();
        long now = System.currentTimeMillis();
        if (cooldowns.getOrDefault(player.getUniqueId(), 0L) > now) return;
        Location destination;
        String path = "returns." + player.getUniqueId();
        if (player.getWorld().equals(desert)) {
            destination = getConfig().getLocation(path);
            if (destination == null || destination.getWorld() == null || destination.getWorld().equals(desert)) {
                destination = Bukkit.getWorlds().get(0).getSpawnLocation();
            }
        } else {
            getConfig().set(path, event.getFrom());
            saveConfig();
            destination = desertArrival.clone();
        }
        cooldowns.put(player.getUniqueId(), now + 5000L);
        event.setTo(destination);
    }

    @EventHandler(ignoreCancelled = true)
    public void onPortal(PlayerPortalEvent event) {
        if (event.getFrom().getWorld().equals(desert)
                || portalBlocks.contains(key(event.getFrom().getBlock()))) event.setCancelled(true);
    }
}