Search in sources :

Example 1 with Chunk

use of io.xol.chunkstories.api.world.chunk.Chunk in project chunkstories-core by Hugobros3.

the class Chest method output.

@Override
public void output(World csWorld, int csX, int csY, int csZ, int minecraftBlockId, int minecraftMetaData, MinecraftRegion region, int minecraftCuurrentChunkXinsideRegion, int minecraftCuurrentChunkZinsideRegion, int x, int y, int z) {
    Chunk chunk = csWorld.getChunkWorldCoordinates(csX, csY, csZ);
    assert chunk != null;
    /*int baked = voxelID;
		
		if (voxel instanceof VoxelChest)
			try {
				baked = ((VoxelChest) voxel).onPlace(chunk.peek(csX, csY, csZ), baked, null);
			} catch (WorldException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		else
			System.out.println("fuck you 666");
		
		csWorld.pokeRawSilently(csX, csY, csZ, baked);*/
    csWorld.pokeSimpleSilently(new FutureCell(csWorld, csX, csY, csZ, voxel));
}
Also used : FutureCell(io.xol.chunkstories.api.world.cell.FutureCell) Chunk(io.xol.chunkstories.api.world.chunk.Chunk)

Example 2 with Chunk

use of io.xol.chunkstories.api.world.chunk.Chunk in project chunkstories-core by Hugobros3.

the class Door method output.

@Override
public void output(World csWorld, int csX, int csY, int csZ, int minecraftBlockId, int minecraftMetaData, MinecraftRegion region, int minecraftCuurrentChunkXinsideRegion, int minecraftCuurrentChunkZinsideRegion, int x, int y, int z) {
    Chunk chunk = csWorld.getChunkWorldCoordinates(csX, csY, csZ);
    assert chunk != null;
    int upper = (minecraftMetaData & 0x8) >> 3;
    int open = (minecraftMetaData & 0x4) >> 2;
    // We only place the lower half of the door and the other half is created by the placing logic of chunk stories
    if (upper != 1) {
        int upperMeta = region.getChunk(minecraftCuurrentChunkXinsideRegion, minecraftCuurrentChunkZinsideRegion).getBlockMeta(x, y + 1, z);
        int hingeSide = upperMeta & 0x01;
        int direction = minecraftMetaData & 0x3;
        csWorld.pokeSimple(csX, csY, csZ, voxel, -1, -1, VoxelDoor.computeMeta(open == 1, hingeSide == 1, VoxelSide.getSideMcDoor(direction)));
    } else
        return;
}
Also used : Chunk(io.xol.chunkstories.api.world.chunk.Chunk)

Example 3 with Chunk

use of io.xol.chunkstories.api.world.chunk.Chunk in project chunkstories-core by Hugobros3.

the class Sign method output.

@Override
public void output(World csWorld, int csX, int csY, int csZ, int minecraftBlockId, int minecraftMetaData, MinecraftRegion region, int minecraftCuurrentChunkXinsideRegion, int minecraftCuurrentChunkZinsideRegion, int x, int y, int z) {
    Chunk chunk = csWorld.getChunkWorldCoordinates(csX, csY, csZ);
    assert chunk != null;
    if (voxel instanceof VoxelSign) {
        if (!voxel.getName().endsWith("_post")) {
            if (minecraftMetaData == 2)
                minecraftMetaData = 8;
            else if (minecraftMetaData == 3)
                minecraftMetaData = 0;
            else if (minecraftMetaData == 4)
                minecraftMetaData = 4;
            else if (minecraftMetaData == 5)
                minecraftMetaData = 12;
        }
        /*baked = VoxelFormat.changeMeta(baked, minecraftMetaData);
			
			try {
				baked = ((VoxelSign) voxel).onPlace(chunk.peek(csX, csY, csZ), baked, null);
			} catch (WorldException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			csWorld.pokeRawSilently(csX, csY, csZ, baked);*/
        FutureCell future = new FutureCell(csWorld, csX, csY, csZ, voxel);
        future.setMetaData(minecraftMetaData);
        csWorld.pokeSimple(future);
        try {
            translateSignText(csWorld.peek(csX, csY, csZ).components().get("signData"), region.getChunk(minecraftCuurrentChunkXinsideRegion, minecraftCuurrentChunkZinsideRegion), x, y, z);
        } catch (WorldException e) {
            e.printStackTrace();
        }
    // TODO Move Sign text getting here ?
    } else
        System.out.println("fuck you 666");
}
Also used : FutureCell(io.xol.chunkstories.api.world.cell.FutureCell) WorldException(io.xol.chunkstories.api.exceptions.world.WorldException) MinecraftChunk(io.xol.enklume.MinecraftChunk) Chunk(io.xol.chunkstories.api.world.chunk.Chunk) VoxelSign(io.xol.chunkstories.core.voxel.VoxelSign)

Example 4 with Chunk

use of io.xol.chunkstories.api.world.chunk.Chunk in project chunkstories-core by Hugobros3.

the class NearbyVoxelsVolumeTexture method update.

public void update(RenderingInterface renderingContext) {
    if (test == null) {
        test = renderingContext.newTexture3D(TextureFormat.RGBA_8BPP, 32, 32, 32);
    }
    final int SIZE = size;
    final int mod = SIZE / 32;
    int offCenter = SIZE / 2;
    int chunkX = (int) ((renderingContext.getCamera().getCameraPosition().x() - offCenter) / 32);
    int chunkY = (int) ((renderingContext.getCamera().getCameraPosition().y() - offCenter) / 32);
    int chunkZ = (int) ((renderingContext.getCamera().getCameraPosition().z() - offCenter) / 32);
    offsetX = chunkX % mod;
    offsetY = chunkY % mod;
    offsetZ = chunkZ % mod;
    if (bx != chunkX || by != chunkY || bz != chunkZ) {
        bx = chunkX;
        by = chunkY;
        bz = chunkZ;
        ByteBuffer bb = ByteBuffer.allocateDirect(4 * SIZE * SIZE * SIZE);
        byte[] empty = { 0, 0, 0, 0 };
        Chunk zChunk = null;
        Vector4f col = new Vector4f();
        for (int a = 0; a * 32 < SIZE; a++) for (int b = 0; b * 32 < SIZE; b++) for (int c = 0; c * 32 < SIZE; c++) {
            zChunk = worldRenderer.getWorld().getChunk(chunkX + a, chunkY + b, chunkZ + c);
            if (zChunk != null) {
                for (int z = 0; z < 32; z++) for (int y = 0; y < 32; y++) {
                    int dx = (0 + a) % mod;
                    int dy = (0 + b) % mod;
                    int dz = (0 + c) % mod;
                    bb.position(4 * ((dz * 32 + z) * SIZE * SIZE + (dy * 32 + y) * SIZE + 0 + dx * 32));
                    for (int x = 0; x < 32; x++) {
                        CellData cell = zChunk.peek(x, y, z);
                        // zChunk.peekSimple(x, y, z);
                        Voxel voxel = cell.getVoxel();
                        if (voxel.isAir() || voxel.getName().startsWith("glass") || voxel instanceof VoxelPane || (!voxel.getDefinition().isSolid() && !voxel.getDefinition().isLiquid() && voxel.getDefinition().getEmittedLightLevel() == 0)) {
                            bb.put(empty);
                        } else {
                            col.set(voxel.getVoxelTexture(VoxelSide.TOP, cell).getColor());
                            if (col.w() < 1.0) {
                                col.mul(new Vector4f(0.1f, 0.5f, 0.1f, 1.0f));
                            }
                            if (voxel.getDefinition().getEmittedLightLevel() > 0) {
                                Vector4f emits = new Vector4f(1.0f, 1.0f, 1.0f, 1.0f);
                                float alpha = col.w;
                                // if(alpha <= 0.0f)
                                alpha = 1.0f;
                                if (voxel.getName().contains("torch"))
                                    alpha = 2f;
                                bb.put((byte) (int) Math.max(0.0, col.x() * 255.0 * alpha));
                                bb.put((byte) (int) Math.max(0.0, col.y() * 255.0 * alpha));
                                bb.put((byte) (int) Math.max(0.0, col.z() * 255.0 * alpha));
                                bb.put((byte) 20);
                            } else {
                                bb.put((byte) (int) (col.x() * 255));
                                bb.put((byte) (int) (col.y() * 255));
                                bb.put((byte) (int) (col.z() * 255));
                                bb.put((byte) 1);
                            }
                        }
                    }
                }
            }
        }
        bb.position(0);
        bb.limit(bb.capacity());
        test.uploadTextureData(SIZE, SIZE, SIZE, bb);
        test.setTextureWrapping(true);
        System.out.println("do an upload");
    // MemoryUtil.memFree(bb);
    }
}
Also used : VoxelPane(io.xol.chunkstories.core.voxel.VoxelPane) Vector4f(org.joml.Vector4f) Voxel(io.xol.chunkstories.api.voxel.Voxel) Chunk(io.xol.chunkstories.api.world.chunk.Chunk) ByteBuffer(java.nio.ByteBuffer) CellData(io.xol.chunkstories.api.world.cell.CellData)

Example 5 with Chunk

use of io.xol.chunkstories.api.world.chunk.Chunk in project chunkstories-core by Hugobros3.

the class BigVoxel method onPlace.

@Override
public void onPlace(FutureCell context, WorldModificationCause cause) throws IllegalBlockModificationException {
    // Be cool with the system doing it's thing
    if (cause == null)
        return;
    int x = context.getX();
    int y = context.getY();
    int z = context.getZ();
    // Check if there is space for it ...
    for (int a = x; a < x + xWidth; a++) {
        for (int b = y; b < y + yWidth; b++) {
            for (int c = z; c < z + zWidth; c++) {
                Chunk chunk = context.getWorld().getChunkWorldCoordinates(a, b, c);
                if (chunk == null)
                    throw new IllegalBlockModificationException(context, "All chunks upon wich this block places itself must be fully loaded !");
                CellData stuff = context.getWorld().peekSafely(a, b, c);
                if (stuff.getVoxel() == null || stuff.getVoxel().isAir() || !stuff.getVoxel().getDefinition().isSolid()) {
                    // These blocks are replaceable
                    continue;
                } else
                    throw new IllegalBlockModificationException(context, "Can't overwrite block at " + a + ": " + b + ": " + c);
            }
        }
    }
    // Actually build the thing then
    for (int a = 0; a < 0 + xWidth; a++) {
        for (int b = 0; b < 0 + yWidth; b++) {
            for (int c = 0; c < 0 + zWidth; c++) {
                int metadata = (byte) (((a & xMask) << xShift) | ((b & yMask) << yShift) | ((c & zMask) << zShift));
                context.getWorld().pokeSimple(a + x, b + y, c + z, this, -1, -1, metadata);
            }
        }
    }
}
Also used : IllegalBlockModificationException(io.xol.chunkstories.api.exceptions.world.voxel.IllegalBlockModificationException) Chunk(io.xol.chunkstories.api.world.chunk.Chunk) CellData(io.xol.chunkstories.api.world.cell.CellData)

Aggregations

Chunk (io.xol.chunkstories.api.world.chunk.Chunk)22 CubicChunk (io.xol.chunkstories.world.chunk.CubicChunk)12 ChunkRenderable (io.xol.chunkstories.api.rendering.world.chunk.ChunkRenderable)5 Entity (io.xol.chunkstories.api.entity.Entity)3 CellData (io.xol.chunkstories.api.world.cell.CellData)3 Region (io.xol.chunkstories.api.world.region.Region)3 ChunkNotLoadedException (io.xol.chunkstories.api.exceptions.world.ChunkNotLoadedException)2 RegionNotLoadedException (io.xol.chunkstories.api.exceptions.world.RegionNotLoadedException)2 WorldException (io.xol.chunkstories.api.exceptions.world.WorldException)2 Voxel (io.xol.chunkstories.api.voxel.Voxel)2 WorldMaster (io.xol.chunkstories.api.world.WorldMaster)2 FutureCell (io.xol.chunkstories.api.world.cell.FutureCell)2 ChunksIterator (io.xol.chunkstories.api.world.chunk.ChunksIterator)2 ChunkRenderDataHolder (io.xol.chunkstories.renderer.chunks.ChunkRenderDataHolder)2 ClientChunk (io.xol.chunkstories.world.chunk.ClientChunk)2 Vector4f (org.joml.Vector4f)2 Location (io.xol.chunkstories.api.Location)1 EntityBase (io.xol.chunkstories.api.entity.EntityBase)1 EntityLiving (io.xol.chunkstories.api.entity.EntityLiving)1 EntityControllable (io.xol.chunkstories.api.entity.interfaces.EntityControllable)1