Package org.terasology.math

Examples of org.terasology.math.Vector3i


    }

    @Override
    public void generateChunk(CoreChunk chunk, Region chunkRegion) {
        SurfaceHeightFacet surfaceHeightData = chunkRegion.getFacet(SurfaceHeightFacet.class);
        Vector3i chunkOffset = chunk.getChunkWorldOffset();
        for (int x = 0; x < chunk.getChunkSizeX(); ++x) {
            for (int z = 0; z < chunk.getChunkSizeZ(); ++z) {
                float surfaceHeight = surfaceHeightData.get(x, z);
                int y;
                for (y = 0; y < chunk.getChunkSizeY() && y + chunkOffset.y < surfaceHeight; ++y) {
View Full Code Here


        Path chunksPath =  storagePathProvider.getWorldTempPath();
        Files.createDirectories(chunksPath);
        if (storeChunksInZips) {
            Map<Vector3i, FileSystem> newChunkZips = Maps.newHashMap();
            for (Map.Entry<Vector3i, CompressedChunkBuilder> entry : compressedChunkBuilders.entrySet()) {
                Vector3i chunkPos = entry.getKey();
                Vector3i chunkZipPos = storagePathProvider.getChunkZipPosition(chunkPos);
                FileSystem zip = newChunkZips.get(chunkZipPos);
                if (zip == null) {
                    Path targetPath = storagePathProvider.getChunkZipTempPath(chunkZipPos);
                    Files.deleteIfExists(targetPath);
                    zip = zipProvider.newFileSystem(targetPath, CREATE_ZIP_OPTIONS);
                    newChunkZips.put(chunkZipPos, zip);
                }
                Path chunkPath = zip.getPath(storagePathProvider.getChunkFilename(chunkPos));
                CompressedChunkBuilder compressedChunkBuilder = entry.getValue();
                byte[] compressedChunk = compressedChunkBuilder.buildEncodedChunk();
                try (BufferedOutputStream bos = new BufferedOutputStream(Files.newOutputStream(chunkPath))) {
                    bos.write(compressedChunk);
                }
            }
            // Copy existing, unmodified content into the zips and close them
            for (Map.Entry<Vector3i, FileSystem> chunkZipEntry : newChunkZips.entrySet()) {
                Vector3i chunkZipPos = chunkZipEntry.getKey();
                Path oldChunkZipPath = storagePathProvider.getChunkZipPath(chunkZipPos);
                final FileSystem zip = chunkZipEntry.getValue();
                if (Files.isRegularFile(oldChunkZipPath)) {
                    try (FileSystem oldZip = FileSystems.newFileSystem(oldChunkZipPath, null)) {
                        for (Path root : oldZip.getRootDirectories()) {
                            Files.walkFileTree(root, new SimpleFileVisitor<Path>() {
                                @Override
                                public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
                                        throws IOException {
                                    if (!Files.isRegularFile(zip.getPath(file.toString()))) {
                                        Files.copy(file, zip.getPath(file.toString()));
                                    }
                                    return FileVisitResult.CONTINUE;
                                }
                            });
                        }
                    }
                }
                zip.close();
            }
        } else {
            for (Map.Entry<Vector3i, CompressedChunkBuilder> entry : compressedChunkBuilders.entrySet()) {
                Vector3i chunkPos = entry.getKey();
                CompressedChunkBuilder compressedChunkBuilder = entry.getValue();
                byte[] compressedChunk = compressedChunkBuilder.buildEncodedChunk();
                Path chunkPath = storagePathProvider.getChunkTempPath(chunkPos);
                try (OutputStream out = new BufferedOutputStream(Files.newOutputStream(chunkPath))) {
                    out.write(compressedChunk);
View Full Code Here

        solidBlock = blockManager.getBlock(solidBlock.getURI());
    }

    @Test
    public void simpleWorldView() {
        Chunk chunk = new ChunkImpl(new Vector3i());
        chunk.setBlock(new Vector3i(0, 0, 0), solidBlock);

        ChunkViewCore chunkView = new ChunkViewCoreImpl(new Chunk[]{chunk}, Region3i.createFromCenterExtents(Vector3i.zero(), Vector3i.zero()), new Vector3i());
        assertEquals(solidBlock, chunkView.getBlock(0, 0, 0));
    }
View Full Code Here

        assertEquals(solidBlock, chunkView.getBlock(0, 0, 0));
    }

    @Test
    public void offsetWorldView() {
        Chunk chunk = new ChunkImpl(new Vector3i());
        chunk.setBlock(new Vector3i(0, 0, 0), solidBlock);

        Chunk[] chunks = new Chunk[]{new ChunkImpl(new Vector3i(-1, 0, -1)), new ChunkImpl(new Vector3i(0, 0, -1)), new ChunkImpl(new Vector3i(1, 0, -1)),
                new ChunkImpl(new Vector3i(-1, 0, 0)), chunk, new ChunkImpl(new Vector3i(1, 0, 0)),
                new ChunkImpl(new Vector3i(-1, 0, 1)), new ChunkImpl(new Vector3i(0, 0, 1)), new ChunkImpl(new Vector3i(1, 0, 1))};

        ChunkViewCore chunkView = new ChunkViewCoreImpl(chunks, Region3i.createFromCenterExtents(new Vector3i(0, 0, 0), new Vector3i(1, 0, 1)), new Vector3i(1, 0, 1));
        assertEquals(solidBlock, chunkView.getBlock(0, 0, 0));
    }
View Full Code Here

        assertEquals(solidBlock, chunkView.getBlock(0, 0, 0));
    }

    @Test
    public void offsetWorldViewBeforeMainChunk() {
        Chunk chunk = new ChunkImpl(new Vector3i());
        chunk.setBlock(new Vector3i(15, 0, 15), solidBlock);

        Chunk[] chunks = new Chunk[]{chunk, new ChunkImpl(new Vector3i(0, 0, -1)), new ChunkImpl(new Vector3i(1, 0, -1)),
                new ChunkImpl(new Vector3i(-1, 0, 0)), new ChunkImpl(new Vector3i(0, 0, 0)), new ChunkImpl(new Vector3i(1, 0, 0)),
                new ChunkImpl(new Vector3i(-1, 0, 1)), new ChunkImpl(new Vector3i(0, 0, 1)), new ChunkImpl(new Vector3i(1, 0, 1))};

        ChunkViewCore chunkView = new ChunkViewCoreImpl(chunks, Region3i.createFromCenterExtents(new Vector3i(0, 0, 0), new Vector3i(1, 0, 1)), new Vector3i(1, 0, 1));
        assertEquals(solidBlock, chunkView.getBlock(-1, 0, -1));
    }
View Full Code Here

        assertEquals(solidBlock, chunkView.getBlock(-1, 0, -1));
    }

    @Test
    public void offsetWorldViewAfterMainChunk() {
        Chunk chunk = new ChunkImpl(new Vector3i());
        chunk.setBlock(new Vector3i(0, 0, 0), solidBlock);

        Chunk[] chunks = new Chunk[]{new ChunkImpl(-1, 0, -1), new ChunkImpl(new Vector3i(0, 0, -1)), new ChunkImpl(new Vector3i(1, 0, -1)),
                new ChunkImpl(new Vector3i(-1, 0, 0)), new ChunkImpl(new Vector3i(0, 0, 0)), new ChunkImpl(new Vector3i(1, 0, 0)),
                new ChunkImpl(new Vector3i(-1, 0, 1)), new ChunkImpl(new Vector3i(0, 0, 1)), chunk};

        ChunkViewCore chunkView = new ChunkViewCoreImpl(chunks, Region3i.createFromCenterExtents(new Vector3i(0, 0, 0), new Vector3i(1, 0, 1)), new Vector3i(1, 0, 1));
        assertEquals(solidBlock, chunkView.getBlock(16, 0, 16));
    }
View Full Code Here

        assertEquals(solidBlock, chunkView.getBlock(16, 0, 16));
    }

    @Test
    public void offsetChunksWorldView() {
        Chunk chunk = new ChunkImpl(new Vector3i(1, 0, 1));
        chunk.setBlock(new Vector3i(0, 0, 0), solidBlock);

        Chunk[] chunks = new Chunk[]{new ChunkImpl(new Vector3i(0, 0, 0)), new ChunkImpl(new Vector3i(1, 0, 0)), new ChunkImpl(new Vector3i(2, 0, 0)),
                new ChunkImpl(new Vector3i(0, 0, 1)), chunk, new ChunkImpl(new Vector3i(2, 0, 1)),
                new ChunkImpl(new Vector3i(0, 0, 2)), new ChunkImpl(new Vector3i(1, 0, 2)), new ChunkImpl(new Vector3i(2, 0, 2))};

        ChunkViewCore chunkView = new ChunkViewCoreImpl(chunks, Region3i.createFromCenterExtents(new Vector3i(1, 0, 1), new Vector3i(1, 0, 1)), new Vector3i(1, 0, 1));
        assertEquals(solidBlock, chunkView.getBlock(0, 0, 0));
    }
View Full Code Here

        assertEquals(solidBlock, chunkView.getBlock(0, 0, 0));
    }

    @Test
    public void localToWorld() {
        Chunk chunk = new ChunkImpl(new Vector3i(1, 0, 1));
        chunk.setBlock(new Vector3i(0, 0, 0), solidBlock);

        Chunk[] chunks = new Chunk[]{new ChunkImpl(new Vector3i(0, 0, 0)), new ChunkImpl(new Vector3i(1, 0, 0)), new ChunkImpl(new Vector3i(2, 0, 0)),
                new ChunkImpl(new Vector3i(0, 0, 1)), chunk, new ChunkImpl(new Vector3i(2, 0, 1)),
                new ChunkImpl(new Vector3i(0, 0, 2)), new ChunkImpl(new Vector3i(1, 0, 2)), new ChunkImpl(new Vector3i(2, 0, 2))};

        ChunkViewCoreImpl chunkView = new ChunkViewCoreImpl(chunks, Region3i.createFromCenterExtents(new Vector3i(1, 0, 1), new Vector3i(1, 0, 1)), new Vector3i(1, 1, 1));
        assertEquals(new Vector3i(ChunkConstants.SIZE_X, ChunkConstants.SIZE_Y, ChunkConstants.SIZE_Z), chunkView.toWorldPos(Vector3i.zero()));
    }
View Full Code Here

    @Override
    public void setValueAt(Vector3i pos, byte value) {
        if (!relevantRegion.encompasses(pos)) {
            throw new IllegalArgumentException("Position out of bounds: " + pos);
        }
        lightData.put(new Vector3i(pos), value);
    }
View Full Code Here

    public Vector3i deserialize(PersistedData data, DeserializationContext context) {
        if (data.isArray()) {
            PersistedDataArray dataArray = data.getAsArray();
            if (dataArray.isNumberArray() && dataArray.size() > 2) {
                TIntList ints = dataArray.getAsIntegerArray();
                return new Vector3i(ints.get(0), ints.get(1), ints.get(2));
            }
        }
        return null;
    }
View Full Code Here

TOP

Related Classes of org.terasology.math.Vector3i

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.