Search in sources :

Example 6 with Voxel

use of io.xol.chunkstories.api.voxel.Voxel in project chunkstories-core by Hugobros3.

the class VoxelPane method getVoxelRenderer.

@Override
public VoxelModel getVoxelRenderer(CellData info) {
    Voxel vox;
    vox = info.getNeightborVoxel(0);
    boolean connectLeft = (vox.getDefinition().isSolid() && vox.getDefinition().isOpaque()) || vox.equals(this);
    vox = info.getNeightborVoxel(1);
    boolean connectFront = (vox.getDefinition().isSolid() && vox.getDefinition().isOpaque()) || vox.equals(this);
    vox = info.getNeightborVoxel(2);
    boolean connectRight = (vox.getDefinition().isSolid() && vox.getDefinition().isOpaque()) || vox.equals(this);
    vox = info.getNeightborVoxel(3);
    boolean connectBack = (vox.getDefinition().isSolid() && vox.getDefinition().isOpaque()) || vox.equals(this);
    String type = "default";
    if (connectLeft && connectFront && connectRight && connectBack)
        type = "allDir";
    else if (connectLeft && connectFront && connectRight)
        type = "allButBack";
    else if (connectLeft && connectFront && connectBack)
        type = "allButRight";
    else if (connectLeft && connectBack && connectRight)
        type = "allButFront";
    else if (connectBack && connectFront && connectRight)
        type = "allButLeft";
    else if (connectLeft && connectRight)
        type = "allX";
    else if (connectFront && connectBack)
        type = "allZ";
    else if (connectLeft && connectBack)
        type = "leftBack";
    else if (connectRight && connectBack)
        type = "rightBack";
    else if (connectLeft && connectFront)
        type = "leftFront";
    else if (connectRight && connectFront)
        type = "rightFront";
    else if (connectLeft)
        type = "left";
    else if (connectRight)
        type = "right";
    else if (connectFront)
        type = "front";
    else if (connectBack)
        type = "back";
    else
        type = "allDir";
    return store.models().getVoxelModel("pane" + "." + type);
}
Also used : Voxel(io.xol.chunkstories.api.voxel.Voxel)

Example 7 with Voxel

use of io.xol.chunkstories.api.voxel.Voxel in project chunkstories-core by Hugobros3.

the class VoxelPane method getCollisionBoxes.

@Override
public CollisionBox[] getCollisionBoxes(CellData info) {
    // System.out.println("kek");
    CollisionBox[] boxes = null;
    Voxel vox;
    vox = info.getNeightborVoxel(0);
    boolean connectLeft = (vox.getDefinition().isSolid() && vox.getDefinition().isOpaque()) || vox.equals(this);
    vox = info.getNeightborVoxel(1);
    boolean connectFront = (vox.getDefinition().isSolid() && vox.getDefinition().isOpaque()) || vox.equals(this);
    vox = info.getNeightborVoxel(2);
    boolean connectRight = (vox.getDefinition().isSolid() && vox.getDefinition().isOpaque()) || vox.equals(this);
    vox = info.getNeightborVoxel(3);
    boolean connectBack = (vox.getDefinition().isSolid() && vox.getDefinition().isOpaque()) || vox.equals(this);
    if (connectLeft && connectFront && connectRight && connectBack) {
        boxes = new CollisionBox[] { new CollisionBox(0.45, 0.0, 0.0, 0.1, 1, 1.0), new CollisionBox(0.0, 0.0, 0.45, 1.0, 1, 0.1) };
    } else if (connectLeft && connectFront && connectRight)
        boxes = new CollisionBox[] { new CollisionBox(0.0, 0.0, 0.45, 1.0, 1, 0.1), new CollisionBox(0.1, 1, 0.5).translate(0.45, 0, 0.5) };
    else if (connectLeft && connectFront && connectBack)
        boxes = new CollisionBox[] { new CollisionBox(0.45, 0.0, 0.0, 0.1, 1, 1.0), new CollisionBox(0.5, 1, 0.1).translate(0.0, 0, 0.45) };
    else if (connectLeft && connectBack && connectRight)
        boxes = new CollisionBox[] { new CollisionBox(0.0, 0.0, 0.45, 1.0, 1, 0.1), new CollisionBox(0.1, 1, 0.5).translate(0.45, 0, 0.0) };
    else if (connectBack && connectFront && connectRight)
        boxes = new CollisionBox[] { new CollisionBox(0.45, 0.0, 0.0, 0.1, 1, 1.0), new CollisionBox(0.5, 1, 0.1).translate(0.5, 0, 0.45) };
    else if (connectLeft && connectRight)
        boxes = new CollisionBox[] { new CollisionBox(0.0, 0.0, 0.45, 1.0, 1, 0.1) };
    else if (connectFront && connectBack)
        boxes = new CollisionBox[] { new CollisionBox(0.45, 0.0, 0.0, 0.1, 1, 1.0) };
    else if (connectLeft && connectBack)
        boxes = new CollisionBox[] { new CollisionBox(0.55, 1, 0.1).translate(0.0, 0, 0.45), new CollisionBox(0.1, 1, 0.55).translate(0.45, 0, 0.0) };
    else if (connectRight && connectBack)
        boxes = new CollisionBox[] { new CollisionBox(0.55, 1, 0.1).translate(0.45, 0, 0.45), new CollisionBox(0.1, 1, 0.55).translate(0.45, 0, 0.0) };
    else if (connectLeft && connectFront)
        boxes = new CollisionBox[] { new CollisionBox(0.55, 1, 0.1).translate(0, 0, 0.45), new CollisionBox(0.1, 1, 0.55).translate(0.45, 0, 0.45) };
    else if (connectRight && connectFront)
        boxes = new CollisionBox[] { new CollisionBox(0.55, 1, 0.1).translate(0.45, 0, 0.45), new CollisionBox(0.1, 1, 0.55).translate(0.45, 0, 0.45) };
    else if (connectLeft)
        boxes = new CollisionBox[] { new CollisionBox(0.0, 0.0, 0.45, 0.5, 1, 0.1).translate(0, 0, 0) };
    else if (connectRight)
        boxes = new CollisionBox[] { new CollisionBox(0.0, 0.0, 0.45, 0.5, 1, 0.1).translate(0.5, 0, 0) };
    else if (connectFront)
        boxes = new CollisionBox[] { new CollisionBox(0.45, 0.0, 0.0, 0.1, 1, 0.5).translate(0, 0, 0.5) };
    else if (connectBack)
        boxes = new CollisionBox[] { new CollisionBox(0.45, 0.0, 0.0, 0.1, 1, 0.5).translate(0, 0, 0.0) };
    else
        boxes = new CollisionBox[] { new CollisionBox(0.45, 0.0, 0.0, 0.1, 1, 1.0), new CollisionBox(0.0, 0.0, 0.45, 1.0, 1, 0.1) };
    return boxes;
}
Also used : Voxel(io.xol.chunkstories.api.voxel.Voxel) CollisionBox(io.xol.chunkstories.api.physics.CollisionBox)

Example 8 with Voxel

use of io.xol.chunkstories.api.voxel.Voxel in project chunkstories-core by Hugobros3.

the class VoxelStoneWall method getCollisionBoxes.

@Override
public CollisionBox[] getCollisionBoxes(CellData info) {
    // System.out.println("kek");
    CollisionBox[] boxes = new CollisionBox[] { new CollisionBox(0.25, 0.0, 0.25, 0.5, 1.0, 0.5) };
    Voxel vox;
    vox = info.getNeightborVoxel(0);
    boolean connectLeft = (vox.getDefinition().isSolid() && vox.getDefinition().isOpaque()) || vox.equals(this);
    vox = info.getNeightborVoxel(1);
    boolean connectFront = (vox.getDefinition().isSolid() && vox.getDefinition().isOpaque()) || vox.equals(this);
    vox = info.getNeightborVoxel(2);
    boolean connectRight = (vox.getDefinition().isSolid() && vox.getDefinition().isOpaque()) || vox.equals(this);
    vox = info.getNeightborVoxel(3);
    boolean connectBack = (vox.getDefinition().isSolid() && vox.getDefinition().isOpaque()) || vox.equals(this);
    if (connectLeft && connectFront && connectRight && connectBack) {
        boxes = new CollisionBox[] { new CollisionBox(0.25, 0.0, 0.0, 0.5, 1, 1.0), new CollisionBox(0.0, 0.0, 0.25, 1.0, 1, 0.5) };
    } else if (connectLeft && connectFront && connectRight)
        boxes = new CollisionBox[] { new CollisionBox(0.0, 0.0, 0.25, 1.0, 1, 0.5), new CollisionBox(0.25, 0.0, 0.25, 0.5, 1, 0.5).translate(0, 0, 0.25) };
    else if (connectLeft && connectFront && connectBack)
        boxes = new CollisionBox[] { new CollisionBox(0.25, 0.0, 0.0, 0.5, 1, 1.0), new CollisionBox(0.25, 0.0, 0.25, 0.5, 1, 0.5).translate(-0.25, 0, 0) };
    else if (connectLeft && connectBack && connectRight)
        boxes = new CollisionBox[] { new CollisionBox(0.0, 0.0, 0.25, 1.0, 1, 0.5), new CollisionBox(0.25, 0.0, 0.25, 0.5, 1, 0.5).translate(0, 0, -0.25) };
    else if (connectBack && connectFront && connectRight)
        boxes = new CollisionBox[] { new CollisionBox(0.25, 0.0, 0.0, 0.5, 1, 1.0), new CollisionBox(0.25, 0.0, 0.25, 0.5, 1, 0.5).translate(0.25, 0, 0) };
    else if (connectLeft && connectRight)
        boxes = new CollisionBox[] { new CollisionBox(0.0, 0.0, 0.25, 1.0, 1, 0.5) };
    else if (connectFront && connectBack)
        boxes = new CollisionBox[] { new CollisionBox(0.25, 0.0, 0.0, 0.5, 1, 1.0) };
    else if (connectLeft && connectBack)
        boxes = new CollisionBox[] { new CollisionBox(0.125, 0.0, 0.25, 0.75, 1, 0.5).translate(-0.125, 0, 0), new CollisionBox(0.25, 0.0, 0.125, 0.5, 1, 0.75).translate(0, 0, -0.125) };
    else if (connectRight && connectBack)
        boxes = new CollisionBox[] { new CollisionBox(0.125, 0.0, 0.25, 0.75, 1, 0.5).translate(0.125, 0, 0), new CollisionBox(0.25, 0.0, 0.125, 0.5, 1, 0.75).translate(0, 0, -0.125) };
    else if (connectLeft && connectFront)
        boxes = new CollisionBox[] { new CollisionBox(0.125, 0.0, 0.25, 0.75, 1, 0.5).translate(-0.125, 0, 0), new CollisionBox(0.25, 0.0, 0.125, 0.5, 1, 0.75).translate(0, 0, 0.125) };
    else if (connectRight && connectFront)
        boxes = new CollisionBox[] { new CollisionBox(0.125, 0.0, 0.25, 0.75, 1, 0.5).translate(0.125, 0, 0), new CollisionBox(0.25, 0.0, 0.125, 0.5, 1, 0.750).translate(0, 0, 0.125) };
    else if (connectLeft)
        boxes = new CollisionBox[] { new CollisionBox(0.125, 0.0, 0.25, 0.75, 1, 0.5).translate(-0.125, 0, 0) };
    else if (connectRight)
        boxes = new CollisionBox[] { new CollisionBox(0.125, 0.0, 0.25, 0.75, 1, 0.5).translate(0.125, 0, 0) };
    else if (connectFront)
        boxes = new CollisionBox[] { new CollisionBox(0.25, 0.0, 0.125, 0.5, 1, 0.75).translate(0, 0, 0.125) };
    else if (connectBack)
        boxes = new CollisionBox[] { new CollisionBox(0.25, 0.0, 0.125, 0.5, 1, 0.75).translate(0.0, 0.0, -0.125) };
    return boxes;
}
Also used : Voxel(io.xol.chunkstories.api.voxel.Voxel) CollisionBox(io.xol.chunkstories.api.physics.CollisionBox)

Example 9 with Voxel

use of io.xol.chunkstories.api.voxel.Voxel in project chunkstories by Hugobros3.

the class TaskBuildHeightmap method task.

@Override
protected boolean task(TaskExecutor taskExecutor) {
    ConverterWorkerThread cwt = (ConverterWorkerThread) taskExecutor;
    // We wait on a bunch of stuff to load everytime
    CompoundFence loadRelevantData = new CompoundFence();
    HeightmapImplementation summary = csWorld.getRegionsSummariesHolder().aquireHeightmap(cwt, regionX, regionZ);
    loadRelevantData.add(summary.waitForLoading());
    // Aquires the chunks we want to make the summaries of.
    for (int innerCX = 0; innerCX < 8; innerCX++) for (int innerCZ = 0; innerCZ < 8; innerCZ++) for (int chunkY = 0; chunkY < OfflineWorldConverter.mcWorldHeight / 32; chunkY++) {
        ChunkHolder holder = csWorld.aquireChunkHolder(cwt, regionX * 8 + innerCX, chunkY, regionZ * 8 + innerCZ);
        if (holder != null) {
            loadRelevantData.add(holder.waitForLoading());
            if (cwt.registeredCS_Holders.add(holder))
                cwt.chunksAquired++;
        }
    }
    // Wait until all of that crap loads
    loadRelevantData.traverse();
    // Descend from top
    for (int i = 0; i < 256; i++) for (int j = 0; j < 256; j++) {
        for (int h = OfflineWorldConverter.mcWorldHeight; h > 0; h--) {
            CellData data = csWorld.peekSafely(regionX * 256 + i, h, regionZ * 256 + j);
            if (!data.getVoxel().isAir()) {
                Voxel vox = data.getVoxel();
                if (vox.getDefinition().isSolid() || vox.getDefinition().isLiquid()) {
                    summary.setTopCell(data);
                    break;
                }
            }
        }
    }
    Fence waitForSummarySave = summary.saveSummary();
    // cwt.converter().verbose("Waiting for summary saving...");
    waitForSummarySave.traverse();
    // cwt.converter().verbose("Done.");
    // We don't need the summary anymore
    summary.unregisterUser(cwt);
    return true;
}
Also used : CompoundFence(io.xol.chunkstories.util.concurrency.CompoundFence) HeightmapImplementation(io.xol.chunkstories.world.summary.HeightmapImplementation) ChunkHolder(io.xol.chunkstories.api.world.chunk.ChunkHolder) Voxel(io.xol.chunkstories.api.voxel.Voxel) ConverterWorkerThread(io.xol.chunkstories.converter.ConverterWorkers.ConverterWorkerThread) Fence(io.xol.chunkstories.api.util.concurrency.Fence) CompoundFence(io.xol.chunkstories.util.concurrency.CompoundFence) CellData(io.xol.chunkstories.api.world.cell.CellData)

Example 10 with Voxel

use of io.xol.chunkstories.api.voxel.Voxel in project chunkstories by Hugobros3.

the class GiveCommand method handleCommand.

@Override
public boolean handleCommand(CommandEmitter emitter, Command command, String[] arguments) {
    if (!emitter.hasPermission("server.give")) {
        emitter.sendMessage("You don't have the permission.");
        return true;
    }
    if (!(emitter instanceof Player)) {
        emitter.sendMessage("You need to be a player to use this command.");
        return true;
    }
    Content gameContent = server.getContent();
    Player player = (Player) emitter;
    if (arguments.length == 0) {
        player.sendMessage("#FF969BSyntax : /give <item> [amount] [to]");
        return true;
    }
    int amount = 1;
    Player to = player;
    String itemName = arguments[0];
    // Look for the item first
    ItemDefinition type = gameContent.items().getItemDefinition(itemName);
    // If the type was found we are simply trying to spawn an item
    Item item = null;
    if (type != null)
        item = type.newItem();
    else {
        String voxelName = itemName;
        int voxelMeta = 0;
        if (voxelName.contains(":")) {
            voxelMeta = Integer.parseInt(voxelName.split(":")[1]);
            voxelName = voxelName.split(":")[0];
        }
        // Try to find a matching voxel
        Voxel voxel = gameContent.voxels().getVoxel(itemName);
        if (voxel != null) {
            // Spawn new itemPile in his inventory
            ItemVoxel itemVoxel = (ItemVoxel) gameContent.items().getItemDefinition("item_voxel").newItem();
            itemVoxel.voxel = voxel;
            itemVoxel.voxelMeta = voxelMeta;
            item = itemVoxel;
        }
    }
    if (item == null) {
        player.sendMessage("#FF969BItem or voxel \"" + arguments[0] + " can't be found.");
        return true;
    }
    if (arguments.length >= 2) {
        amount = Integer.parseInt(arguments[1]);
    }
    if (arguments.length >= 3) {
        if (gameContent instanceof ServerInterface)
            to = ((ServerInterface) gameContent).getPlayerByName(arguments[2]);
        else {
            player.sendMessage("#FF969BThis is a singleplayer world - there are no other players");
            return true;
        }
    }
    if (to == null) {
        player.sendMessage("#FF969BPlayer \"" + arguments[2] + " can't be found.");
        return true;
    }
    ItemPile itemPile = new ItemPile(item);
    itemPile.setAmount(amount);
    ((EntityWithInventory) to.getControlledEntity()).getInventory().addItemPile(itemPile);
    player.sendMessage("#FF969BGave " + (amount > 1 ? amount + "x " : "") + "#4CFF00" + itemPile.getItem().getName() + " #FF969Bto " + to.getDisplayName());
    return true;
}
Also used : Item(io.xol.chunkstories.api.item.Item) Player(io.xol.chunkstories.api.player.Player) ItemVoxel(io.xol.chunkstories.api.item.ItemVoxel) ServerInterface(io.xol.chunkstories.api.server.ServerInterface) Content(io.xol.chunkstories.api.content.Content) ItemVoxel(io.xol.chunkstories.api.item.ItemVoxel) Voxel(io.xol.chunkstories.api.voxel.Voxel) ItemDefinition(io.xol.chunkstories.api.item.ItemDefinition) ItemPile(io.xol.chunkstories.api.item.inventory.ItemPile)

Aggregations

Voxel (io.xol.chunkstories.api.voxel.Voxel)26 ItemVoxel (io.xol.chunkstories.api.item.ItemVoxel)6 WorldMaster (io.xol.chunkstories.api.world.WorldMaster)5 Entity (io.xol.chunkstories.api.entity.Entity)4 CollisionBox (io.xol.chunkstories.api.physics.CollisionBox)4 CellData (io.xol.chunkstories.api.world.cell.CellData)4 Texture2D (io.xol.chunkstories.api.rendering.textures.Texture2D)3 World (io.xol.chunkstories.api.world.World)3 WorldClient (io.xol.chunkstories.api.world.WorldClient)3 Vector3d (org.joml.Vector3d)3 Vector3dc (org.joml.Vector3dc)3 Location (io.xol.chunkstories.api.Location)2 WorldException (io.xol.chunkstories.api.exceptions.world.WorldException)2 Shader (io.xol.chunkstories.api.rendering.shader.Shader)2 VoxelBakerCubic (io.xol.chunkstories.api.rendering.voxel.VoxelBakerCubic)2 VoxelBakerHighPoly (io.xol.chunkstories.api.rendering.voxel.VoxelBakerHighPoly)2 ChunkRenderable (io.xol.chunkstories.api.rendering.world.chunk.ChunkRenderable)2 DummyCell (io.xol.chunkstories.api.world.cell.DummyCell)2 Chunk (io.xol.chunkstories.api.world.chunk.Chunk)2 Vector3f (org.joml.Vector3f)2