Search in sources :

Example 1 with IntPair

use of com.fastasyncworldedit.core.math.IntPair in project FastAsyncWorldEdit by IntellectualSites.

the class DiskStorageHistory method readHeader.

public IntPair readHeader() {
    int ox = getOriginX();
    int oz = getOriginZ();
    if (ox == 0 && oz == 0 && bdFile.exists()) {
        try (FileInputStream fis = new FileInputStream(bdFile)) {
            final FaweInputStream gis = MainUtil.getCompressedIS(fis);
            // skip mode
            gis.skipFully(1);
            // skip version
            gis.skipFully(1);
            // origin
            ox = ((gis.read() << 24) + (gis.read() << 16) + (gis.read() << 8) + gis.read());
            oz = ((gis.read() << 24) + (gis.read() << 16) + (gis.read() << 8) + gis.read());
            setOrigin(ox, oz);
            fis.close();
            gis.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return new IntPair(ox, oz);
}
Also used : FaweInputStream(com.fastasyncworldedit.core.internal.io.FaweInputStream) IOException(java.io.IOException) IntPair(com.fastasyncworldedit.core.math.IntPair) FileInputStream(java.io.FileInputStream)

Example 2 with IntPair

use of com.fastasyncworldedit.core.math.IntPair in project FastAsyncWorldEdit by IntellectualSites.

the class PaperweightFaweWorldNativeAccess method setBlockState.

@Nullable
@Override
public synchronized net.minecraft.world.level.block.state.BlockState setBlockState(LevelChunk levelChunk, BlockPos blockPos, net.minecraft.world.level.block.state.BlockState blockState) {
    int currentTick = MinecraftServer.currentTick;
    if (Fawe.isMainThread()) {
        return levelChunk.setBlockState(blockPos, blockState, this.sideEffectSet != null && this.sideEffectSet.shouldApply(SideEffect.UPDATE));
    }
    // Since FAWE is.. Async we need to do it on the main thread (wooooo.. :( )
    cachedChanges.add(new CachedChange(levelChunk, blockPos, blockState));
    cachedChunksToSend.add(new IntPair(levelChunk.bukkitChunk.getX(), levelChunk.bukkitChunk.getZ()));
    boolean nextTick = lastTick.get() > currentTick;
    if (nextTick || cachedChanges.size() >= 1024) {
        if (nextTick) {
            lastTick.set(currentTick);
        }
        flushAsync(nextTick);
    }
    return blockState;
}
Also used : IntPair(com.fastasyncworldedit.core.math.IntPair) Nullable(javax.annotation.Nullable)

Example 3 with IntPair

use of com.fastasyncworldedit.core.math.IntPair in project FastAsyncWorldEdit by IntellectualSites.

the class PaperweightFaweWorldNativeAccess method flush.

@Override
public synchronized void flush() {
    RunnableVal<Object> runnableVal = new RunnableVal<>() {

        @Override
        public void run(Object value) {
            cachedChanges.forEach(cc -> cc.levelChunk.setBlockState(cc.blockPos, cc.blockState, sideEffectSet != null && sideEffectSet.shouldApply(SideEffect.UPDATE)));
            for (IntPair chunk : cachedChunksToSend) {
                PaperweightPlatformAdapter.sendChunk(getLevel().getWorld().getHandle(), chunk.x(), chunk.z(), false);
            }
        }
    };
    if (Fawe.isMainThread()) {
        runnableVal.run();
    } else {
        TaskManager.taskManager().sync(runnableVal);
    }
    cachedChanges.clear();
    cachedChunksToSend.clear();
}
Also used : RunnableVal(com.fastasyncworldedit.core.util.task.RunnableVal) IntPair(com.fastasyncworldedit.core.math.IntPair)

Example 4 with IntPair

use of com.fastasyncworldedit.core.math.IntPair in project FastAsyncWorldEdit by IntellectualSites.

the class PaperweightFaweWorldNativeAccess method flushAsync.

private synchronized void flushAsync(final boolean sendChunks) {
    final Set<CachedChange> changes = Set.copyOf(cachedChanges);
    cachedChanges.clear();
    final Set<IntPair> toSend;
    if (sendChunks) {
        toSend = Set.copyOf(cachedChunksToSend);
        cachedChunksToSend.clear();
    } else {
        toSend = Collections.emptySet();
    }
    RunnableVal<Object> runnableVal = new RunnableVal<>() {

        @Override
        public void run(Object value) {
            changes.forEach(cc -> cc.levelChunk.setBlockState(cc.blockPos, cc.blockState, sideEffectSet != null && sideEffectSet.shouldApply(SideEffect.UPDATE)));
            if (!sendChunks) {
                return;
            }
            for (IntPair chunk : toSend) {
                PaperweightPlatformAdapter.sendChunk(getLevel().getWorld().getHandle(), chunk.x(), chunk.z(), false);
            }
        }
    };
    TaskManager.taskManager().async(() -> TaskManager.taskManager().sync(runnableVal));
}
Also used : RunnableVal(com.fastasyncworldedit.core.util.task.RunnableVal) IntPair(com.fastasyncworldedit.core.math.IntPair)

Example 5 with IntPair

use of com.fastasyncworldedit.core.math.IntPair in project FastAsyncWorldEdit by IntellectualSites.

the class PaperweightFaweWorldNativeAccess method flush.

@Override
public synchronized void flush() {
    RunnableVal<Object> runnableVal = new RunnableVal<>() {

        @Override
        public void run(Object value) {
            cachedChanges.forEach(cc -> cc.levelChunk.setBlockState(cc.blockPos, cc.blockState, sideEffectSet != null && sideEffectSet.shouldApply(SideEffect.UPDATE)));
            for (IntPair chunk : cachedChunksToSend) {
                PaperweightPlatformAdapter.sendChunk(getLevel().getWorld().getHandle(), chunk.x(), chunk.z(), false);
            }
        }
    };
    if (Fawe.isMainThread()) {
        runnableVal.run();
    } else {
        TaskManager.taskManager().sync(runnableVal);
    }
    cachedChanges.clear();
    cachedChunksToSend.clear();
}
Also used : RunnableVal(com.fastasyncworldedit.core.util.task.RunnableVal) IntPair(com.fastasyncworldedit.core.math.IntPair)

Aggregations

IntPair (com.fastasyncworldedit.core.math.IntPair)10 RunnableVal (com.fastasyncworldedit.core.util.task.RunnableVal)6 Nullable (javax.annotation.Nullable)3 FaweInputStream (com.fastasyncworldedit.core.internal.io.FaweInputStream)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1