Changelist:

- Added aliases for custom configuration types
- Removed numerical ID based methods in Block Queues
- Fixed sign removal in Plot.java
- (Hopefully) fixed dividing by 0 errors in BlockBucket
- Removed random from some methods, as blockbucket has it's own random
- Temporarily removed chunk analysis
- Changed a lot in GenChunk and BukkitPlotGenerator
This commit is contained in:
sauilitired
2018-12-20 02:23:48 +01:00
parent 11ccfe7ac4
commit e939b8237e
20 changed files with 112 additions and 325 deletions

View File

@ -25,7 +25,6 @@ public class BukkitPlotGenerator extends ChunkGenerator
implements GeneratorWrapper<ChunkGenerator> {
private final GenChunk chunkSetter;
private final PseudoRandom random = new PseudoRandom();
private final IndependentPlotGenerator plotGenerator;
private final ChunkGenerator platformGenerator;
private final boolean full;
@ -48,41 +47,11 @@ public class BukkitPlotGenerator extends ChunkGenerator
if (queue == null) {
queue = GlobalBlockQueue.IMP.getNewQueue(world.getName(), false);
}
byte[][] resultData =
dataMap.isEmpty() ? null : dataMap.remove(new ChunkLoc(c.getX(), c.getZ()));
if (resultData == null) {
GenChunk result = BukkitPlotGenerator.this.chunkSetter;
// Set the chunk location
result.setChunk(c);
// Set the result data
result.result = new short[16][];
result.result_data = new byte[16][];
result.grid = null;
result.cd = null;
// Catch any exceptions (as exceptions usually thrown)
generate(world, c.getX(), c.getZ(), result);
resultData = result.result_data;
}
if (resultData != null) {
for (int i = 0; i < resultData.length; i++) {
byte[] section = resultData[i];
if (section == null) {
continue;
}
for (int j = 0; j < section.length; j++) {
int x = MainUtil.x_loc[i][j];
int y = MainUtil.y_loc[i][j];
int z = MainUtil.z_loc[i][j];
c.getBlock(x, y, z).setData(section[j]);
}
}
}
BukkitPlotGenerator.this.random.state = c.getX() << 16 | c.getZ() & 0xFFFF;
PlotArea area = PlotSquared.get().getPlotArea(world.getName(), null);
ChunkWrapper wrap = new ChunkWrapper(area.worldname, c.getX(), c.getZ());
ScopedLocalBlockQueue chunk = queue.getForChunk(wrap.x, wrap.z);
if (BukkitPlotGenerator.this.plotGenerator
.populateChunk(chunk, area, BukkitPlotGenerator.this.random)) {
.populateChunk(chunk, area)) {
queue.flush();
}
}
@ -122,8 +91,7 @@ public class BukkitPlotGenerator extends ChunkGenerator
}
@Override
public void generateChunk(final ScopedLocalBlockQueue result, PlotArea settings,
PseudoRandom random) {
public void generateChunk(final ScopedLocalBlockQueue result, PlotArea settings) {
World w = BukkitUtil.getWorld(world);
Location min = result.getMin();
int cx = min.getX() >> 4;
@ -146,6 +114,7 @@ public class BukkitPlotGenerator extends ChunkGenerator
}
} catch (Throwable ignored) {
}
/* TODO: Redo this
// Populator spillage
short[][] tmp = cg.generateExtBlockSections(w, r, cx, cz, grid);
if (tmp != null) {
@ -156,7 +125,7 @@ public class BukkitPlotGenerator extends ChunkGenerator
for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) {
for (int y = i << 4; y < (i << 4) + 16; y++) {
result.setBlock(x, y, z, (short) 0, (byte) 0);
result.setBlock(x, y, z, PlotBlock.get("air"));
}
}
}
@ -171,6 +140,7 @@ public class BukkitPlotGenerator extends ChunkGenerator
}
}
}
*/
for (BlockPopulator populator : cg.getDefaultPopulators(w)) {
populator.populate(w, r, w.getChunkAt(cx, cz));
}
@ -256,15 +226,14 @@ public class BukkitPlotGenerator extends ChunkGenerator
// Set the result data
result.cd = createChunkData(world);
result.grid = grid;
result.result = null;
result.result_data = null;
result.result = generateExtBlockSections(world, random, cx, cz, grid);
// Catch any exceptions (as exceptions usually thrown)
try {
// Fill the result data if necessary
if (this.platformGenerator != this) {
return this.platformGenerator.generateChunkData(world, random, cx, cz, grid);
} else {
generate(world, cx, cz, result);
generate(world, result);
}
} catch (Throwable e) {
e.printStackTrace();
@ -273,22 +242,20 @@ public class BukkitPlotGenerator extends ChunkGenerator
return result.cd;
}
public void generate(World world, int cx, int cz, ScopedLocalBlockQueue result) {
public void generate(World world, ScopedLocalBlockQueue result) {
// Load if improperly loaded
if (!this.loaded) {
String name = world.getName();
PlotSquared.get().loadWorld(name, this);
this.loaded = true;
}
// Set random seed
this.random.state = cx << 16 | cz & 0xFFFF;
// Process the chunk
if (ChunkManager.preProcessChunk(result)) {
return;
}
PlotArea area = PlotSquared.get().getPlotArea(world.getName(), null);
try {
this.plotGenerator.generateChunk(this.chunkSetter, area, this.random);
this.plotGenerator.generateChunk(this.chunkSetter, area);
} catch (Throwable e) {
// Recover from generator error
e.printStackTrace();
@ -296,29 +263,34 @@ public class BukkitPlotGenerator extends ChunkGenerator
ChunkManager.postProcessChunk(result);
}
@Override public short[][] generateExtBlockSections(World world, Random r, int cx, int cz,
public PlotBlock[][] generateExtBlockSections(World world, Random r, int cx, int cz,
BiomeGrid grid) {
GenChunk result = this.chunkSetter;
// Set the chunk location
result.setChunk(new ChunkWrapper(world.getName(), cx, cz));
// Set the result data
result.result = new short[16][];
result.result_data = new byte[16][];
result.result = new PlotBlock[16][];
result.grid = grid;
result.cd = null;
// Catch any exceptions (as exceptions usually thrown)
try {
// Fill the result data
if (this.platformGenerator != this) {
return this.platformGenerator.generateExtBlockSections(world, r, cx, cz, grid);
} else {
generate(world, cx, cz, result);
for (int i = 0; i < result.result_data.length; i++) {
if (result.result_data[i] != null) {
this.dataMap.put(new ChunkLoc(cx, cz), result.result_data);
break;
final ChunkData chunkData = this.platformGenerator.generateChunkData(world, r, cx, cz, grid);
final PlotBlock[][] blocks = new PlotBlock[world.getMaxHeight() / 16][];
// section ID = Y >> 4
for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) {
for (int y = 0; y < world.getMaxHeight(); y++) {
if (blocks[y >> 4] == null) {
blocks[y >> 4] = new PlotBlock[4096];
}
blocks[y >> 4][((y & 0xF) << 8) | (z << 4) | x] = PlotBlock.get(chunkData.getType(x, y, z));
}
}
}
} else {
generate(world, result);
}
} catch (Throwable e) {
e.printStackTrace();
@ -327,6 +299,7 @@ public class BukkitPlotGenerator extends ChunkGenerator
return result.result;
}
/**
* Allow spawning everywhere.
*

View File

@ -945,9 +945,9 @@ import java.util.regex.Pattern;
return;
}
if (PlotSquared.get().worldedit != null && pp.getAttribute("worldedit")) {
if (player.getInventory().getItemInMainHand().getType() == LegacyMappings
.fromLegacyId(PlotSquared.get().worldedit.getConfiguration().wandItem)
.getMaterial()) {
if (player.getInventory().getItemInMainHand().getType() == BukkitUtil.getBukkitLegacyMappings()
.fromLegacyToString(PlotSquared.get().worldedit.getConfiguration().wandItem)
.to(Material.class)) {
return;
}
}
@ -1682,10 +1682,12 @@ import java.util.regex.Pattern;
return;
}
if (PlotSquared.get().worldedit != null && pp.getAttribute("worldedit")) {
if (player.getInventory().getItemInMainHand().getType() == LegacyMappings
.fromLegacyId(PlotSquared.get().worldedit.getConfiguration().wandItem)
.getMaterial()) {
return;
if (PlotSquared.get().worldedit != null && pp.getAttribute("worldedit")) {
if (player.getInventory().getItemInMainHand().getType() == BukkitUtil.getBukkitLegacyMappings()
.fromLegacyToString(PlotSquared.get().worldedit.getConfiguration().wandItem)
.to(Material.class)) {
return;
}
}
}
if (!EventUtil.manager.checkPlayerBlockEvent(pp, eventType, location, lb, true)) {

View File

@ -72,20 +72,20 @@ public class BukkitChunkManager extends ChunkManager {
// byte data2 = block2.getData();
if (id1 == Material.AIR) {
if (id2 != Material.AIR) {
queue1.setBlock(x, y, z, id2.name());
queue2.setBlock(xx, y, zz, (short) 0, (byte) 0);
queue1.setBlock(x, y, z, PlotBlock.get(id2));
queue2.setBlock(xx, y, zz, PlotBlock.get("air"));
}
} else if (id2 == Material.AIR) {
queue1.setBlock(x, y, z, (short) 0, (byte) 0);
queue2.setBlock(xx, y, zz, id1.name());
queue1.setBlock(x, y, z, PlotBlock.get("air"));
queue2.setBlock(xx, y, zz, PlotBlock.get(id1));
} else if (id1 == id2) {
if (data1 != data2) {
block1.setBlockData(data2);
block2.setBlockData(data1);
}
} else {
queue1.setBlock(x, y, z, id2.name());
queue2.setBlock(xx, y, zz, id1.name());
queue1.setBlock(x, y, z, PlotBlock.get(id2));
queue2.setBlock(xx, y, zz, PlotBlock.get(id1));
// queue1.setBlock(x, y, z, (short) id2, data2);
// queue2.setBlock(xx, y, zz, (short) id1, data1);
}
@ -297,7 +297,7 @@ public class BukkitChunkManager extends ChunkManager {
if (id != null) {
value.setBlock(x, y, z, id);
} else {
value.setBlock(x, y, z, 0, (byte) 0);
value.setBlock(x, y, z, PlotBlock.get("air"));
}
}
for (int y = Math.min(128, ids.length);
@ -392,13 +392,11 @@ public class BukkitChunkManager extends ChunkManager {
maps.add(swapChunk(world1, world2, chunk1, chunk2, region1, region2));
}
}
GlobalBlockQueue.IMP.addTask(new Runnable() {
@Override public void run() {
for (ContentMap map : maps) {
map.restoreBlocks(world1, 0, 0);
map.restoreEntities(world1, 0, 0);
TaskManager.runTaskLater(whenDone, 1);
}
GlobalBlockQueue.IMP.addTask(() -> {
for (ContentMap map : maps) {
map.restoreBlocks(world1, 0, 0);
map.restoreEntities(world1, 0, 0);
TaskManager.runTaskLater(whenDone, 1);
}
});
}

View File

@ -1,28 +1,9 @@
package com.github.intellectualsites.plotsquared.bukkit.util;
import com.github.intellectualsites.plotsquared.plot.generator.HybridUtils;
import com.github.intellectualsites.plotsquared.plot.object.Location;
import com.github.intellectualsites.plotsquared.plot.object.PlotBlock;
import com.github.intellectualsites.plotsquared.plot.object.RegionWrapper;
import com.github.intellectualsites.plotsquared.plot.object.RunnableVal;
import com.github.intellectualsites.plotsquared.plot.util.ChunkManager;
import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
import com.github.intellectualsites.plotsquared.plot.util.MathMan;
import com.github.intellectualsites.plotsquared.plot.util.TaskManager;
import com.github.intellectualsites.plotsquared.plot.util.block.GlobalBlockQueue;
import com.github.intellectualsites.plotsquared.plot.util.block.LocalBlockQueue;
import com.github.intellectualsites.plotsquared.plot.util.expiry.PlotAnalysis;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Biome;
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.generator.ChunkGenerator.BiomeGrid;
import org.bukkit.material.Directional;
import org.bukkit.material.MaterialData;
import java.util.HashSet;
import java.util.Random;
public class BukkitHybridUtils extends HybridUtils {
@ -40,6 +21,7 @@ public class BukkitHybridUtils extends HybridUtils {
* - recheck each block
*
*/
/* TODO: Redo
TaskManager.runTaskAsync(new Runnable() {
@Override public void run() {
final LocalBlockQueue queue = GlobalBlockQueue.IMP.getNewQueue(world, false);
@ -275,5 +257,6 @@ public class BukkitHybridUtils extends HybridUtils {
}, 5);
}
});
*/
}
}

View File

@ -23,7 +23,7 @@ import java.util.*;
/**
* Schematic Handler.
*/
public abstract class BukkitSchematicHandler extends SchematicHandler {
public class BukkitSchematicHandler extends SchematicHandler {
@Override public void getCompoundTag(final String world, final Set<RegionWrapper> regions,
final RunnableVal<CompoundTag> whenDone) {

View File

@ -6,6 +6,7 @@ import com.github.intellectualsites.plotsquared.plot.config.C;
import com.github.intellectualsites.plotsquared.plot.object.*;
import com.github.intellectualsites.plotsquared.plot.object.schematic.PlotItem;
import com.github.intellectualsites.plotsquared.plot.util.*;
import com.sk89q.worldedit.bukkit.BukkitWorld;
import lombok.NonNull;
import org.bukkit.Bukkit;
import org.bukkit.Material;

View File

@ -12,15 +12,13 @@ import org.bukkit.World;
import org.bukkit.block.Biome;
import org.bukkit.generator.ChunkGenerator.BiomeGrid;
import org.bukkit.generator.ChunkGenerator.ChunkData;
import org.bukkit.material.MaterialData;
import java.util.Arrays;
public class GenChunk extends ScopedLocalBlockQueue {
public final Biome[] biomes;
public short[][] result;
public byte[][] result_data;
public PlotBlock[][] result;
public ChunkData cd;
public BiomeGrid grid;
@ -55,13 +53,6 @@ public class GenChunk extends ScopedLocalBlockQueue {
cz = wrap.z;
}
public ChunkWrapper getChunkWrapper() {
if (chunk == null) {
return new ChunkWrapper(world, cx, cz);
}
return new ChunkWrapper(chunk.getWorld().getName(), chunk.getX(), chunk.getZ());
}
@Override public void fillBiome(String biomeName) {
if (grid == null) {
return;
@ -75,17 +66,17 @@ public class GenChunk extends ScopedLocalBlockQueue {
}
@Override public void setCuboid(Location pos1, Location pos2, PlotBlock block) {
if (block.data == 0 && result != null && pos1.getX() == 0 && pos1.getZ() == 0
if (result != null && pos1.getX() == 0 && pos1.getZ() == 0
&& pos2.getX() == 15 && pos2.getZ() == 15) {
for (int y = pos1.getY(); y <= pos2.getY(); y++) {
int layer = y >> 4;
short[] data = result[layer];
PlotBlock[] data = result[layer];
if (data == null) {
result[layer] = data = new short[4096];
result[layer] = data = new PlotBlock[4096];
}
int start = y << 8;
int end = start + 256;
Arrays.fill(data, start, end, block.id);
Arrays.fill(data, start, end, block);
}
} else {
super.setCuboid(pos1, pos2, block);
@ -96,14 +87,6 @@ public class GenChunk extends ScopedLocalBlockQueue {
return setBiome(x, z, Biome.valueOf(biome.toUpperCase()));
}
public boolean setBiome(int x, int z, int biome) {
if (this.grid != null) {
this.grid.setBiome(x, z, this.biomes[biome]);
return true;
}
return false;
}
public boolean setBiome(int x, int z, Biome biome) {
if (this.grid != null) {
this.grid.setBiome(x, z, biome);
@ -112,48 +95,32 @@ public class GenChunk extends ScopedLocalBlockQueue {
return false;
}
@Override public boolean setBlock(int x, int y, int z, int id, int data) {
@Override public boolean setBlock(int x, int y, int z, PlotBlock id) {
if (this.result == null) {
this.cd.setBlock(x, y, z, new MaterialData(Material.getMaterial(id), (byte) data));
this.cd.setBlock(x, y, z, id.to(Material.class));
return true;
}
int i = MainUtil.CACHE_I[y][x][z];
short[] v = this.result[i];
PlotBlock[] v = this.result[i];
if (v == null) {
this.result[i] = v = new short[4096];
this.result[i] = v = new PlotBlock[4096];
}
int j = MainUtil.CACHE_J[y][x][z];
v[j] = (short) id;
if (data != 0) {
byte[] vd = this.result_data[i];
if (vd == null) {
this.result_data[i] = vd = new byte[4096];
}
vd[j] = (byte) data;
}
v[j] = id;
return true;
}
@Override public PlotBlock getBlock(int x, int y, int z) {
int i = MainUtil.CACHE_I[y][x][z];
if (result == null) {
MaterialData md = cd.getTypeAndData(x, y, z);
return PlotBlock.get(md.getItemTypeId(), md.getData());
return PlotBlock.get(cd.getType(x, y, z));
}
short[] array = result[i];
PlotBlock[] array = result[i];
if (array == null) {
return PlotBlock.get(0, 0);
return PlotBlock.get("");
}
int j = MainUtil.CACHE_J[y][x][z];
short id = array[j];
if (id == 0) {
return PlotBlock.get(id, 0);
}
byte[] dataArray = result_data[i];
if (dataArray == null) {
return PlotBlock.get(id, 0);
}
return PlotBlock.get(id, dataArray[j]);
return array[j];
}
public int getX() {
@ -181,29 +148,14 @@ public class GenChunk extends ScopedLocalBlockQueue {
new GenChunk(chunk, new ChunkWrapper(getWorld(), chunk.getX(), chunk.getZ()));
if (this.result != null) {
for (int i = 0; i < this.result.length; i++) {
short[] matrix = this.result[i];
PlotBlock[] matrix = this.result[i];
if (matrix != null) {
toReturn.result[i] = new short[matrix.length];
toReturn.result[i] = new PlotBlock[matrix.length];
System.arraycopy(matrix, 0, toReturn.result[i], 0, matrix.length);
}
}
for (int i = 0; i < this.result_data.length; i++) {
byte[] matrix = this.result_data[i];
if (matrix != null) {
toReturn.result_data[i] = new byte[matrix.length];
System.arraycopy(matrix, 0, toReturn.result_data[i], 0, matrix.length);
}
}
}
toReturn.cd = this.cd;
return toReturn;
}
public GenChunk shallowClone() {
GenChunk toReturn = new GenChunk(chunk, new ChunkWrapper(getWorld(), getX(), getZ()));
toReturn.result = this.result;
toReturn.result_data = this.result_data;
toReturn.cd = this.cd;
return toReturn;
}
}