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);
}
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;
}
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();
}
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));
}
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();
}
Aggregations