Search in sources :

Example 21 with Voxel

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

the class VoxelDoor method onRemove.

@Override
public void onRemove(ChunkCell context, WorldModificationCause cause) {
    // Don't interfere with system pokes, else we get stuck in a loop
    if (cause == null || !(cause instanceof Entity))
        return;
    World world = context.getWorld();
    int x = context.getX();
    int y = context.getY();
    int z = context.getZ();
    // Ignore all that crap on a slave world
    if (!(world instanceof WorldMaster))
        return;
    int otherPartOfTheDoorY = y;
    if (top)
        otherPartOfTheDoorY--;
    else
        otherPartOfTheDoorY++;
    Voxel restOfTheDoorVoxel = world.peekSimple(x, otherPartOfTheDoorY, z);
    // Remove the other part as well, if it still exists
    if (restOfTheDoorVoxel instanceof VoxelDoor)
        world.pokeSimple(x, otherPartOfTheDoorY, z, store().air(), -1, -1, 0);
}
Also used : Entity(io.xol.chunkstories.api.entity.Entity) ItemVoxel(io.xol.chunkstories.api.item.ItemVoxel) Voxel(io.xol.chunkstories.api.voxel.Voxel) World(io.xol.chunkstories.api.world.World) WorldMaster(io.xol.chunkstories.api.world.WorldMaster)

Example 22 with Voxel

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

the class VoxelDoor method onPlace.

@Override
public void onPlace(FutureCell cell, WorldModificationCause cause) throws IllegalBlockModificationException {
    // Ignore all that crap on a slave world
    if (!(cell.getWorld() instanceof WorldMaster))
        return;
    // We should only place the lower part, prevent entities from doing so !
    if (top && cause != null && cause instanceof Entity)
        throw new IllegalBlockModificationException(cell, "Entities can't place upper doors parts");
    // If the system adds the upper part, no modifications to be done on it
    if (top)
        return;
    World world = cell.getWorld();
    int x = cell.getX();
    int y = cell.getY();
    int z = cell.getZ();
    // Check top is free
    int topData = world.peekRaw(x, y + 1, z);
    if (VoxelFormat.id(topData) != 0)
        throw new IllegalBlockModificationException(cell, "Top part isn't free");
    // grab our attributes
    boolean isOpen = ((cell.getMetaData() >> 0) & 0x1) == 1;
    boolean hingeSide = ((cell.getMetaData() >> 1) & 0x1) == 1;
    int facingPassed = (cell.getMetaData() >> 2) & 0x3;
    // Default face is given by passed metadata
    VoxelSide doorSideFacing = VoxelSide.values()[facingPassed];
    // Determine side if placed by an entity and not internal code
    if (cause != null && cause instanceof Entity) {
        Location loc = ((Entity) cause).getLocation();
        double dx = loc.x() - (x + 0.5);
        double dz = loc.z() - (z + 0.5);
        if (Math.abs(dx) > Math.abs(dz)) {
            if (dx > 0)
                doorSideFacing = VoxelSide.RIGHT;
            else
                doorSideFacing = VoxelSide.LEFT;
        } else {
            if (dz > 0)
                doorSideFacing = VoxelSide.FRONT;
            else
                doorSideFacing = VoxelSide.BACK;
        }
        // If there is an adjacent one, set the hinge to right
        Voxel adjacent = null;
        switch(doorSideFacing) {
            case LEFT:
                adjacent = world.peekSimple(x, y, z - 1);
                break;
            case RIGHT:
                adjacent = world.peekSimple(x, y, z + 1);
                break;
            case FRONT:
                adjacent = world.peekSimple(x - 1, y, z);
                break;
            case BACK:
                adjacent = world.peekSimple(x + 1, y, z);
                break;
            default:
                break;
        }
        if (adjacent instanceof VoxelDoor) {
            hingeSide = true;
        }
        cell.setMetaData(computeMeta(isOpen, hingeSide, doorSideFacing));
    }
    // Place the upper part and we're good to go
    world.pokeSimple(x, y + 1, z, this.getUpperPart(), -1, -1, cell.getMetaData());
}
Also used : Entity(io.xol.chunkstories.api.entity.Entity) VoxelSide(io.xol.chunkstories.api.voxel.VoxelSide) ItemVoxel(io.xol.chunkstories.api.item.ItemVoxel) Voxel(io.xol.chunkstories.api.voxel.Voxel) IllegalBlockModificationException(io.xol.chunkstories.api.exceptions.world.voxel.IllegalBlockModificationException) World(io.xol.chunkstories.api.world.World) WorldMaster(io.xol.chunkstories.api.world.WorldMaster) Location(io.xol.chunkstories.api.Location)

Example 23 with Voxel

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

the class VoxelFence 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";
    return store.models().getVoxelModel("wood_fence" + "." + type);
}
Also used : Voxel(io.xol.chunkstories.api.voxel.Voxel)

Example 24 with Voxel

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

the class VoxelFence method getCollisionBoxes.

@Override
public CollisionBox[] getCollisionBoxes(CellData info) {
    // System.out.println("kek");
    CollisionBox[] boxes = new CollisionBox[] { new CollisionBox(0.3, 0.0, 0.3, 0.4, 1.0, 0.4) };
    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.3, 0.0, 0.0, 0.4, 1, 1.0), new CollisionBox(0.0, 0.0, 0.3, 1.0, 1, 0.4) };
    } else if (connectLeft && connectFront && connectRight)
        boxes = new CollisionBox[] { new CollisionBox(0.0, 0.0, 0.3, 1.0, 1, 0.4), new CollisionBox(0.3, 0.0, 0.25, 0.4, 1, 0.5).translate(0, 0, 0.25) };
    else if (connectLeft && connectFront && connectBack)
        boxes = new CollisionBox[] { new CollisionBox(0.3, 0.0, 0.0, 0.4, 1, 1.0), new CollisionBox(0.25, 0.0, 0.3, 0.5, 1, 0.4).translate(-0.25, 0, 0) };
    else if (connectLeft && connectBack && connectRight)
        boxes = new CollisionBox[] { new CollisionBox(0.0, 0.0, 0.3, 1.0, 1, 0.4), new CollisionBox(0.3, 0.0, 0.25, 0.4, 1, 0.5).translate(0, 0, -0.25) };
    else if (connectBack && connectFront && connectRight)
        boxes = new CollisionBox[] { new CollisionBox(0.3, 0.0, 0.0, 0.4, 1, 1.0), new CollisionBox(0.25, 0.0, 0.3, 0.5, 1, 0.4).translate(0.25, 0, 0) };
    else if (connectLeft && connectRight)
        boxes = new CollisionBox[] { new CollisionBox(0.0, 0.0, 0.3, 1.0, 1, 0.4) };
    else if (connectFront && connectBack)
        boxes = new CollisionBox[] { new CollisionBox(0.3, 0.0, 0.0, 0.4, 1, 1.0) };
    else if (connectLeft && connectBack)
        boxes = new CollisionBox[] { new CollisionBox(0.15, 0.0, 0.3, 0.7, 1, 0.4).translate(-0.15, 0, 0), new CollisionBox(0.3, 0.0, 0.15, 0.4, 1, 0.7).translate(0, 0, -0.15) };
    else if (connectRight && connectBack)
        boxes = new CollisionBox[] { new CollisionBox(0.15, 0.0, 0.3, 0.7, 1, 0.4).translate(0.15, 0, 0), new CollisionBox(0.3, 0.0, 0.15, 0.4, 1, 0.7).translate(0, 0, -0.15) };
    else if (connectLeft && connectFront)
        boxes = new CollisionBox[] { new CollisionBox(0.15, 0.0, 0.3, 0.7, 1, 0.4).translate(-0.15, 0, 0), new CollisionBox(0.3, 0.0, 0.15, 0.4, 1, 0.7).translate(0, 0, 0.15) };
    else if (connectRight && connectFront)
        boxes = new CollisionBox[] { new CollisionBox(0.15, 0.0, 0.3, 0.7, 1, 0.4).translate(0.15, 0, 0), new CollisionBox(0.3, 0.0, 0.15, 0.4, 1, 0.70).translate(0, 0, 0.15) };
    else if (connectLeft)
        boxes = new CollisionBox[] { new CollisionBox(0.15, 0.0, 0.3, 0.7, 1, 0.4).translate(-0.15, 0, 0) };
    else if (connectRight)
        boxes = new CollisionBox[] { new CollisionBox(0.15, 0.0, 0.3, 0.7, 1, 0.4).translate(0.15, 0, 0) };
    else if (connectFront)
        boxes = new CollisionBox[] { new CollisionBox(0.3, 0.0, 0.15, 0.4, 1, 0.7).translate(0, 0, 0.15) };
    else if (connectBack)
        boxes = new CollisionBox[] { new CollisionBox(0.3, 0.0, 0.15, 0.4, 1, 0.7).translate(0.0, 0.0, -0.15) };
    return boxes;
}
Also used : Voxel(io.xol.chunkstories.api.voxel.Voxel) CollisionBox(io.xol.chunkstories.api.physics.CollisionBox)

Example 25 with Voxel

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

the class DefaultVoxelRenderer method shallBuildWallArround.

protected boolean shallBuildWallArround(CellData renderInfo, int face) {
    Voxel facing = renderInfo.getNeightborVoxel(face);
    Voxel voxel = renderInfo.getVoxel();
    if (voxel.getDefinition().isLiquid() && !facing.getDefinition().isLiquid())
        return true;
    // Facing.isSideOpaque
    if (!facing.isFaceOpaque(VoxelSide.values()[face].getOppositeSide(), renderInfo.getNeightborMetadata(face)) && (!voxel.sameKind(facing) || !voxel.getDefinition().isSelfOpaque()))
        return true;
    return false;
}
Also used : Voxel(io.xol.chunkstories.api.voxel.Voxel)

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