Close #966
Close #953
(duplicates)
Changes to chunk copying etc to interfere less with world generation
This commit is contained in:
Jesse Boyd 2016-03-18 01:22:51 +11:00
parent 16dac99fed
commit f9db269813
7 changed files with 55 additions and 130 deletions

View file

@ -234,6 +234,8 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap
// Set the result data
result.cd = createChunkData(world);
result.grid = grid;
result.result = null;
result.result_data = null;
// Catch any exceptions (as exceptions usually thrown
try {
// Fill the result data if necessary
@ -259,9 +261,7 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap
// Set random seed
this.random.state = (cx << 16) | (cz & 0xFFFF);
// Process the chunk
result.modified = false;
ChunkManager.preProcessChunk(result);
if (result.modified) {
if (ChunkManager.preProcessChunk(result)) {
return;
}
PlotArea area = PS.get().getPlotArea(world.getName(), null);
@ -279,6 +279,7 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap
result.result = new short[16][];
result.result_data = new byte[16][];
result.grid = grid;
result.cd = null;
// Catch any exceptions (as exceptions usually thrown
try {
// Fill the result data

View file

@ -534,7 +534,7 @@ public class BukkitChunkManager extends ChunkManager {
}
}
}
final PlotLoc loc = new PlotLoc(x, z);
final PlotLoc loc = new PlotLoc(x + offset_x, z + offset_z);
allblocks.put(loc, ids);
}
@ -633,133 +633,48 @@ public class BukkitChunkManager extends ChunkManager {
public boolean copyRegion(final Location pos1, final Location pos2, final Location newPos, final Runnable whenDone) {
final int relX = newPos.getX() - pos1.getX();
final int relZ = newPos.getZ() - pos1.getZ();
final int relCX = relX >> 4;
final int relCZ = relZ >> 4;
final Location pos4 = new Location(newPos.getWorld(), newPos.getX() + relX, 256, newPos.getZ() + relZ);
final RegionWrapper region = new RegionWrapper(pos1.getX(), pos2.getX(), pos1.getZ(), pos2.getZ());
final World oldWorld = Bukkit.getWorld(pos1.getWorld());
final World newWorld = Bukkit.getWorld(newPos.getWorld());
final String newWorldname = newWorld.getName();
final List<ChunkLoc> chunks = new ArrayList<>();
initMaps();
ChunkManager.chunkTask(pos1, pos2, new RunnableVal<int[]>() {
@Override
public void run(int[] value) {
initMaps();
final int bx = value[2];
final int bz = value[3];
final int tx = value[4];
final int tz = value[5];
// Load chunks
final ChunkLoc loc1 = new ChunkLoc(value[0], value[1]);
final ChunkLoc loc2 = new ChunkLoc(loc1.x + relCX, loc1.z + relCZ);
final Chunk c1 = oldWorld.getChunkAt(loc1.x, loc1.z);
final Chunk c2 = newWorld.getChunkAt(loc2.x, loc2.z);
c1.load(true);
c2.load(true);
chunks.add(loc2);
// entities
saveEntitiesIn(c1, region);
// copy chunk
setChunkInPlotArea(null, new RunnableVal<PlotChunk<?>>() {
@Override
public void run(PlotChunk<?> value) {
for (int x = bx & 15; x <= (tx & 15); x++) {
for (int z = bz & 15; z <= (tz & 15); z++) {
for (int y = 1; y < 256; y++) {
Block block = c1.getBlock(x, y, z);
Material id = block.getType();
switch (id) {
case AIR:
case GRASS:
case COBBLESTONE:
case GRAVEL:
case GOLD_ORE:
case IRON_ORE:
case GLASS:
case LAPIS_ORE:
case LAPIS_BLOCK:
case WEB:
case DEAD_BUSH:
case YELLOW_FLOWER:
case BROWN_MUSHROOM:
case RED_MUSHROOM:
case GOLD_BLOCK:
case IRON_BLOCK:
case BRICK:
case TNT:
case BOOKSHELF:
case MOSSY_COBBLESTONE:
case OBSIDIAN:
case FIRE:
case REDSTONE_WIRE:
case DIAMOND_ORE:
case DIAMOND_BLOCK:
case WORKBENCH:
case SOIL:
case BEDROCK:
case WATER:
case STATIONARY_WATER:
case LAVA:
case STATIONARY_LAVA:
case REDSTONE_ORE:
case GLOWING_REDSTONE_ORE:
case SNOW:
case ICE:
case SNOW_BLOCK:
case CACTUS:
case CLAY:
case SUGAR_CANE_BLOCK:
case FENCE:
case NETHERRACK:
case SOUL_SAND:
case IRON_FENCE:
case THIN_GLASS:
case MELON_BLOCK:
case MYCEL:
case NETHER_BRICK:
case NETHER_FENCE:
case ENDER_STONE:
case DRAGON_EGG:
case EMERALD_ORE:
case EMERALD_BLOCK:
case SLIME_BLOCK:
case BARRIER:
case SEA_LANTERN:
case HAY_BLOCK:
case HARD_CLAY:
case COAL_BLOCK:
case PACKED_ICE:
case DOUBLE_STONE_SLAB2:
case STONE_SLAB2:
case SPRUCE_FENCE:
case BIRCH_FENCE:
case JUNGLE_FENCE:
case DARK_OAK_FENCE:
case ACACIA_FENCE:
value.setBlock(x, y, z, id.getId(), (byte) 0);
break;
default:
value.setBlock(x, y, z, id.getId(), block.getData());
break;
}
}
}
}
final ChunkLoc loc = new ChunkLoc(value[0], value[1]);
final int cxx = loc.x << 4;
final int czz = loc.z << 4;
final Chunk chunk = oldWorld.getChunkAt(loc.x, loc.z);
saveEntitiesIn(chunk, region);
for (int x = bx & 15; x <= (tx & 15); x++) {
for (int z = bz & 15; z <= (tz & 15); z++) {
saveBlocks(oldWorld, 256, cxx + x, czz + z, relX, relZ, true);
}
}, newWorldname, loc2);
// restore chunk
restoreBlocks(newWorld, relX, relZ);
restoreEntities(newWorld, relX, relZ);
}
}
}, new Runnable() {
@Override
public void run() {
SetQueue.IMP.queue.sendChunk(newWorldname, chunks);
for (Entry<PlotLoc, PlotBlock[]> entry : allblocks.entrySet()) {
PlotLoc loc = entry.getKey();
PlotBlock[] blocks = entry.getValue();
for (int y = 0; y < blocks.length; y++) {
PlotBlock block = blocks[y];
if (block != null) {
SetQueue.IMP.setBlock(newWorldname, loc.x, y, loc.z, block);
}
}
}
while (SetQueue.IMP.forceChunkSet());
restoreBlocks(newWorld, 0, 0);
restoreEntities(newWorld, relX, relZ);
TaskManager.runTask(whenDone);
}
}, 5);

View file

@ -17,7 +17,6 @@ public class GenChunk extends PlotChunk<Chunk> {
public short[][] result;
public byte[][] result_data;
public ChunkData cd;
public boolean modified = false;
public BiomeGrid grid;
public GenChunk(Chunk chunk, ChunkWrapper wrap) {
@ -42,7 +41,6 @@ public class GenChunk extends PlotChunk<Chunk> {
@Override
public void setBiome(int x, int z, int biome) {
modified = true;
grid.setBiome(x, z, biomes[biome]);
}
@ -55,14 +53,12 @@ public class GenChunk extends PlotChunk<Chunk> {
@Override
public void setBlock(int x, int y, int z, int id, byte data) {
if (result == null) {
modified = true;
cd.setBlock(x, y, z, id, data);
return;
}
int i = MainUtil.CACHE_I[y][x][z];
short[] v = result[i];
if (v == null) {
modified = true;
result[i] = v = new short[4096];
}
int j = MainUtil.CACHE_J[y][x][z];

View file

@ -2789,7 +2789,7 @@ public class Plot {
// copy data
for (final Plot plot : plots) {
final Plot other = plot.getRelative(offset.x, offset.y);
other.create(other.owner, false);
other.create(plot.owner, false);
if (!plot.getFlags().isEmpty()) {
other.getSettings().flags = plot.getFlags();
DBFunc.setFlags(other, plot.getFlags().values());
@ -2799,19 +2799,19 @@ public class Plot {
}
if ((plot.members != null) && !plot.members.isEmpty()) {
other.members = plot.members;
for (final UUID member : other.members) {
for (final UUID member : plot.members) {
DBFunc.setMember(other, member);
}
}
if ((plot.trusted != null) && !plot.trusted.isEmpty()) {
other.trusted = plot.trusted;
for (final UUID trusted : other.trusted) {
for (final UUID trusted : plot.trusted) {
DBFunc.setTrusted(other, trusted);
}
}
if ((plot.denied != null) && !plot.denied.isEmpty()) {
other.denied = plot.denied;
for (final UUID denied : other.denied) {
for (final UUID denied : plot.denied) {
DBFunc.setDenied(other, denied);
}
}

View file

@ -17,7 +17,12 @@ public class PlotLoc {
result = (prime * result) + z;
return result;
}
@Override
public String toString() {
return x + "," + z;
}
@Override
public boolean equals(final Object obj) {
if (this == obj) {

View file

@ -49,18 +49,22 @@ public abstract class ChunkManager {
}
}
public static void preProcessChunk(PlotChunk<?> chunk) {
public static boolean preProcessChunk(PlotChunk<?> chunk) {
if (CURRENT_FORCE_CHUNK != null) {
CURRENT_FORCE_CHUNK.run(chunk);
CURRENT_FORCE_CHUNK = null;
return true;
}
return false;
}
public static void postProcessChunk(PlotChunk<?> chunk) {
public static boolean postProcessChunk(PlotChunk<?> chunk) {
if (CURRENT_ADD_CHUNK != null) {
CURRENT_ADD_CHUNK.run(chunk);
CURRENT_ADD_CHUNK = null;
return true;
}
return false;
}
public static void largeRegionTask(final String world, final RegionWrapper region, final RunnableVal<ChunkLoc> task, final Runnable whenDone) {

View file

@ -1,12 +1,11 @@
package com.plotsquared.sponge.util.block;
import org.spongepowered.api.world.Chunk;
import org.spongepowered.api.world.extent.MutableBiomeArea;
import org.spongepowered.api.world.extent.MutableBlockVolume;
import com.intellectualcrafters.plot.util.PlotChunk;
import com.intellectualcrafters.plot.util.SetQueue.ChunkWrapper;
import com.plotsquared.sponge.util.SpongeUtil;
import org.spongepowered.api.world.Chunk;
import org.spongepowered.api.world.extent.MutableBiomeArea;
import org.spongepowered.api.world.extent.MutableBlockVolume;
public class GenChunk extends PlotChunk<Chunk> {
@ -41,12 +40,17 @@ public class GenChunk extends PlotChunk<Chunk> {
public void setBlock(int x, int y, int z, int id, byte data) {
terain.setBlock(bx + x, y, bz + z, SpongeUtil.getBlockState(id, data));
}
@Override
public void setChunkWrapper(ChunkWrapper loc) {
super.setChunkWrapper(loc);
}
@Override
public PlotChunk clone() {
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
}
@Override
public PlotChunk shallowClone() {
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");