Package com.sk89q.worldedit

Examples of com.sk89q.worldedit.Vector


    }

    @Override
    public boolean setBlock(Vector position, BaseBlock block) throws WorldEditException {
        if (region.contains(position)) {
            Vector v = position.subtract(region.getMinimumPoint());
            blocks[v.getBlockX()][v.getBlockY()][v.getBlockZ()] = new BaseBlock(block);
            return true;
        } else {
            return false;
        }
    }
View Full Code Here


     * @param f3 coefficient for baseIndex+1
     * @param f4 coefficient for baseIndex+2
     * @return linear combination of nodes[n-1..n+2] with f1..4
     */
    private Vector linearCombination(int baseIndex, double f1, double f2, double f3, double f4) {
        final Vector r1 = retrieve(baseIndex - 1).multiply(f1);
        final Vector r2 = retrieve(baseIndex    ).multiply(f2);
        final Vector r3 = retrieve(baseIndex + 1).multiply(f3);
        final Vector r4 = retrieve(baseIndex + 2).multiply(f4);

        return r1.add(r2).add(r3).add(r4);
    }
View Full Code Here

    @Override
    public boolean regenerate(Region region, EditSession editSession) {
        BaseBlock[] history = new BaseBlock[256 * (getMaxY() + 1)];

        for (Vector2D chunk : region.getChunks()) {
            Vector min = new Vector(chunk.getBlockX() * 16, 0, chunk.getBlockZ() * 16);

            for (int x = 0; x < 16; x++) {
                for (int y = 0; y < getMaxY() + 1; y++) {
                    for (int z = 0; z < 16; z++) {
                        Vector pt = min.add(x, y, z);
                        int index = y * 16 * 16 + z * 16 + x;
                        history[index] = editSession.getBlock(pt);
                    }
                }
            }
            try {
                Set<Vector2D> chunks = region.getChunks();
                IChunkProvider provider = getWorld().getChunkProvider();
                if (!(provider instanceof ChunkProviderServer)) {
                    return false;
                }
                ChunkProviderServer chunkServer = (ChunkProviderServer) provider;
                Field u;
                try {
                    u = ChunkProviderServer.class.getDeclaredField("field_73248_b"); // chunksToUnload
                } catch(NoSuchFieldException e) {
                    u = ChunkProviderServer.class.getDeclaredField("chunksToUnload");
                }
                u.setAccessible(true);
                Set<?> unloadQueue = (Set<?>) u.get(chunkServer);
                Field m;
                try {
                    m = ChunkProviderServer.class.getDeclaredField("field_73244_f"); // loadedChunkHashMap
                } catch(NoSuchFieldException e) {
                    m = ChunkProviderServer.class.getDeclaredField("loadedChunkHashMap");
                }
                m.setAccessible(true);
                LongHashMap loadedMap = (LongHashMap) m.get(chunkServer);
                Field lc;
                try {
                    lc = ChunkProviderServer.class.getDeclaredField("field_73245_g"); // loadedChunkHashMap
                } catch(NoSuchFieldException e) {
                    lc = ChunkProviderServer.class.getDeclaredField("loadedChunks");
                }
                lc.setAccessible(true);
                @SuppressWarnings("unchecked") List<Chunk> loaded = (List<Chunk>) lc.get(chunkServer);
                Field p;
                try {
                    p = ChunkProviderServer.class.getDeclaredField("field_73246_d"); // currentChunkProvider
                } catch(NoSuchFieldException e) {
                    p = ChunkProviderServer.class.getDeclaredField("currentChunkProvider");
                }
                p.setAccessible(true);
                IChunkProvider chunkProvider = (IChunkProvider) p.get(chunkServer);

                for (Vector2D coord : chunks) {
                    long pos = ChunkCoordIntPair.chunkXZ2Int(coord.getBlockX(), coord.getBlockZ());
                    Chunk mcChunk;
                    if (chunkServer.chunkExists(coord.getBlockX(), coord.getBlockZ())) {
                        mcChunk = chunkServer.loadChunk(coord.getBlockX(), coord.getBlockZ());
                        mcChunk.onChunkUnload();
                    }
                    unloadQueue.remove(pos);
                    loadedMap.remove(pos);
                    mcChunk = chunkProvider.provideChunk(coord.getBlockX(), coord.getBlockZ());
                    loadedMap.add(pos, mcChunk);
                    loaded.add(mcChunk);
                    if (mcChunk != null) {
                        mcChunk.onChunkLoad();
                        mcChunk.populateChunk(chunkProvider, chunkProvider, coord.getBlockX(), coord.getBlockZ());
                    }
                }
            } catch (Throwable t) {
                logger.log(Level.WARNING, "Failed to generate chunk", t);
                return false;
            }

            for (int x = 0; x < 16; x++) {
                for (int y = 0; y < getMaxY() + 1; y++) {
                    for (int z = 0; z < 16; z++) {
                        Vector pt = min.add(x, y, z);
                        int index = y * 16 * 16 + z * 16 + x;

                        if (!region.contains(pt))
                            editSession.smartSetBlock(pt, history[index]);
                        else {
View Full Code Here

            }

            Chunk chunk = world.getChunkProvider().provideChunk(pt.getBlockX(), pt.getBlockZ());
            for (List<net.minecraft.entity.Entity> entitySubList : chunk.entityLists) {
                for (net.minecraft.entity.Entity entity : entitySubList) {
                    if (region.contains(new Vector(entity.posX, entity.posY, entity.posZ))) {
                        entities.add(new ForgeEntity(entity));
                    }
                }
            }
        }
View Full Code Here

    }

    @Test
    public void testToVector() throws Exception {
        World world = mock(World.class);
        Vector position = new Vector(1, 1, 1);
        Location location = new Location(world, position);
        assertEquals(position, location.toVector());
    }
View Full Code Here

    }

    @Test
    public void testGetX() throws Exception {
        World world = mock(World.class);
        Location location = new Location(world, new Vector(TEST_VALUE, 0, 0));
        assertEquals(TEST_VALUE, location.getX(), EPSILON);
    }
View Full Code Here

    }

    @Test
    public void testGetBlockX() throws Exception {
        World world = mock(World.class);
        Location location = new Location(world, new Vector(TEST_VALUE, 0, 0));
        assertEquals(TEST_VALUE, location.getBlockX());
    }
View Full Code Here

    }

    @Test
    public void testSetX() throws Exception {
        World world = mock(World.class);
        Location location1 = new Location(world, new Vector());
        Location location2 = location1.setX(TEST_VALUE);
        assertEquals(0, location1.getX(), EPSILON);
        assertEquals(TEST_VALUE, location2.getX(), EPSILON);
        assertEquals(0, location2.getY(), EPSILON);
        assertEquals(0, location2.getZ(), EPSILON);
View Full Code Here

    }

    @Test
    public void testGetY() throws Exception {
        World world = mock(World.class);
        Location location = new Location(world, new Vector(0, TEST_VALUE, 0));
        assertEquals(TEST_VALUE, location.getY(), EPSILON);
    }
View Full Code Here

    }

    @Test
    public void testGetBlockY() throws Exception {
        World world = mock(World.class);
        Location location = new Location(world, new Vector(0, TEST_VALUE, 0));
        assertEquals(TEST_VALUE, location.getBlockY());
    }
View Full Code Here

TOP

Related Classes of com.sk89q.worldedit.Vector

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.