mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-07-14 03:14:42 +02:00
Fixing some more things
This commit is contained in:
@ -1,11 +1,9 @@
|
||||
package com.plotsquared.bukkit.generator;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.object.*;
|
||||
import com.intellectualcrafters.plot.util.ChunkManager;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.plotsquared.bukkit.util.bukkit.BukkitChunkManager;
|
||||
import com.plotsquared.bukkit.util.bukkit.BukkitSetBlockManager;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Random;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
@ -13,15 +11,22 @@ import org.bukkit.World;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.generator.BlockPopulator;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Random;
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.object.BlockWrapper;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.PlotCluster;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotLoc;
|
||||
import com.intellectualcrafters.plot.object.PlotManager;
|
||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
import com.intellectualcrafters.plot.object.RegionWrapper;
|
||||
import com.intellectualcrafters.plot.util.ChunkManager;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.plotsquared.bukkit.util.bukkit.BukkitChunkManager;
|
||||
import com.plotsquared.bukkit.util.bukkit.BukkitSetBlockManager;
|
||||
|
||||
public class AugmentedPopulator extends BlockPopulator {
|
||||
public static short[][] x_loc;
|
||||
public static short[][] y_loc;
|
||||
public static short[][] z_loc;
|
||||
public final PlotWorld plotworld;
|
||||
public final PlotManager manager;
|
||||
public final BukkitPlotGenerator generator;
|
||||
@ -36,7 +41,7 @@ public class AugmentedPopulator extends BlockPopulator {
|
||||
private final int tz;
|
||||
|
||||
public AugmentedPopulator(final String world, final BukkitPlotGenerator generator, final PlotCluster cluster, final boolean p, final boolean b) {
|
||||
initCache();
|
||||
MainUtil.initCache();
|
||||
this.cluster = cluster;
|
||||
this.generator = generator;
|
||||
this.plotworld = PS.get().getPlotWorld(world);
|
||||
@ -77,27 +82,7 @@ public class AugmentedPopulator extends BlockPopulator {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void initCache() {
|
||||
if (x_loc == null) {
|
||||
x_loc = new short[16][4096];
|
||||
y_loc = new short[16][4096];
|
||||
z_loc = new short[16][4096];
|
||||
for (int i = 0; i < 16; i++) {
|
||||
int i4 = i << 4;
|
||||
for (int j = 0; j < 4096; j++) {
|
||||
final int y = (i4) + (j >> 8);
|
||||
final int a = (j - ((y & 0xF) << 8));
|
||||
final int z1 = (a >> 4);
|
||||
final int x1 = a - (z1 << 4);
|
||||
x_loc[i][j] = (short) x1;
|
||||
y_loc[i][j] = (short) y;
|
||||
z_loc[i][j] = (short) z1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public BlockWrapper get(final int x, final int z, final int i, final int j, final short[][] r, final boolean c) {
|
||||
final int y = (i << 4) + (j >> 8);
|
||||
final int a = (j - ((y & 0xF) << 8));
|
||||
@ -221,9 +206,9 @@ public class AugmentedPopulator extends BlockPopulator {
|
||||
for (int i = 0; i < result.length; i++) {
|
||||
if (result[i] != null) {
|
||||
for (int j = 0; j < 4096; j++) {
|
||||
int x1 = x_loc[i][j];
|
||||
int y = y_loc[i][j];
|
||||
int z1 = z_loc[i][j];
|
||||
int x1 = MainUtil.x_loc[i][j];
|
||||
int y = MainUtil.y_loc[i][j];
|
||||
int z1 = MainUtil.z_loc[i][j];
|
||||
short id = result[i][j];
|
||||
final int xx = x + x1;
|
||||
final int zz = z + z1;
|
||||
@ -243,7 +228,7 @@ public class AugmentedPopulator extends BlockPopulator {
|
||||
}
|
||||
}
|
||||
else {
|
||||
short y_min = y_loc[i][0];
|
||||
short y_min = MainUtil.y_loc[i][0];
|
||||
if (y_min < 128) {
|
||||
for (int x1 = x; x1 < x + 16; x1++) {
|
||||
for (int z1 = z; z1 < z + 16; z1++) {
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.plotsquared.bukkit.generator;
|
||||
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.generator.PlotGenerator;
|
||||
import com.intellectualcrafters.plot.object.PlotCluster;
|
||||
@ -7,8 +9,6 @@ import com.intellectualcrafters.plot.object.PlotManager;
|
||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
import com.intellectualcrafters.plot.object.SetupObject;
|
||||
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
|
||||
public class BukkitGeneratorWrapper extends PlotGenerator<ChunkGenerator> {
|
||||
|
||||
public final boolean full;
|
||||
|
@ -20,22 +20,28 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.plotsquared.bukkit.generator;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.object.*;
|
||||
import com.intellectualcrafters.plot.util.ChunkManager;
|
||||
import com.plotsquared.bukkit.listeners.WorldEvents;
|
||||
import com.plotsquared.bukkit.object.BukkitPlotPopulator;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.generator.BlockPopulator;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Random;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.generator.BlockPopulator;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.object.PlotLoc;
|
||||
import com.intellectualcrafters.plot.object.PlotManager;
|
||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
import com.intellectualcrafters.plot.object.PseudoRandom;
|
||||
import com.intellectualcrafters.plot.object.RegionWrapper;
|
||||
import com.intellectualcrafters.plot.object.SetupObject;
|
||||
import com.intellectualcrafters.plot.util.ChunkManager;
|
||||
import com.plotsquared.bukkit.listeners.WorldEvents;
|
||||
import com.plotsquared.bukkit.object.BukkitPlotPopulator;
|
||||
|
||||
public abstract class BukkitPlotGenerator extends ChunkGenerator {
|
||||
|
||||
public static short[][][] CACHE_I = null;
|
||||
|
@ -20,20 +20,24 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.plotsquared.bukkit.generator;
|
||||
|
||||
import com.intellectualcrafters.plot.generator.HybridPlotManager;
|
||||
import com.intellectualcrafters.plot.generator.HybridPlotWorld;
|
||||
import com.intellectualcrafters.plot.generator.HybridPop;
|
||||
import com.intellectualcrafters.plot.object.*;
|
||||
import com.plotsquared.bukkit.object.BukkitPlotPopulator;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Biome;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Biome;
|
||||
|
||||
import com.intellectualcrafters.plot.generator.HybridPlotManager;
|
||||
import com.intellectualcrafters.plot.generator.HybridPlotWorld;
|
||||
import com.intellectualcrafters.plot.object.PlotLoc;
|
||||
import com.intellectualcrafters.plot.object.PlotManager;
|
||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
import com.intellectualcrafters.plot.object.PseudoRandom;
|
||||
import com.intellectualcrafters.plot.object.RegionWrapper;
|
||||
import com.plotsquared.bukkit.object.BukkitPlotPopulator;
|
||||
|
||||
/**
|
||||
* The default generator is very messy, as we have decided to try externalize all calculations from within the loop. -
|
||||
* You will see a lot of slower implementations have a single for loop. - This is perfectly fine to do, it will just
|
||||
|
234
src/main/java/com/plotsquared/bukkit/generator/HybridPop.java
Normal file
234
src/main/java/com/plotsquared/bukkit/generator/HybridPop.java
Normal file
@ -0,0 +1,234 @@
|
||||
package com.plotsquared.bukkit.generator;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Biome;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.generator.HybridPlotWorld;
|
||||
import com.intellectualcrafters.plot.object.PlotLoc;
|
||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
import com.intellectualcrafters.plot.object.PseudoRandom;
|
||||
import com.intellectualcrafters.plot.object.RegionWrapper;
|
||||
import com.intellectualcrafters.plot.object.schematic.PlotItem;
|
||||
import com.intellectualcrafters.plot.util.BlockManager;
|
||||
import com.plotsquared.bukkit.object.BukkitPlotPopulator;
|
||||
|
||||
/**
|
||||
* @author Citymonstret
|
||||
*/
|
||||
public class HybridPop extends BukkitPlotPopulator {
|
||||
/*
|
||||
* Sorry, this isn't well documented at the moment.
|
||||
* We advise you to take a look at a world generation tutorial for
|
||||
* information about how a BlockPopulator works.
|
||||
*/
|
||||
final short plotsize;
|
||||
final short pathsize;
|
||||
final byte wall;
|
||||
final byte wallfilling;
|
||||
final byte roadblock;
|
||||
final int size;
|
||||
final int roadheight;
|
||||
final int wallheight;
|
||||
final int plotheight;
|
||||
final byte[] plotfloors;
|
||||
final byte[] filling;
|
||||
final short pathWidthLower;
|
||||
final short pathWidthUpper;
|
||||
private final HybridPlotWorld plotworld;
|
||||
Biome biome;
|
||||
private long state;
|
||||
private boolean doFilling = false;
|
||||
private boolean doFloor = false;
|
||||
private boolean doState = false;
|
||||
|
||||
public HybridPop(final PlotWorld pw) {
|
||||
this.plotworld = (HybridPlotWorld) pw;
|
||||
// save configuration
|
||||
this.plotsize = (short) this.plotworld.PLOT_WIDTH;
|
||||
this.pathsize = (short) this.plotworld.ROAD_WIDTH;
|
||||
this.roadblock = this.plotworld.ROAD_BLOCK.data;
|
||||
this.wallfilling = this.plotworld.WALL_FILLING.data;
|
||||
this.size = this.pathsize + this.plotsize;
|
||||
this.wall = this.plotworld.WALL_BLOCK.data;
|
||||
int count1 = 0;
|
||||
int count2 = 0;
|
||||
this.plotfloors = new byte[this.plotworld.TOP_BLOCK.length];
|
||||
for (int i = 0; i < this.plotworld.TOP_BLOCK.length; i++) {
|
||||
count1++;
|
||||
this.plotfloors[i] = this.plotworld.TOP_BLOCK[i].data;
|
||||
if (this.plotworld.TOP_BLOCK[i].data != 0) {
|
||||
this.doFloor = true;
|
||||
}
|
||||
}
|
||||
this.filling = new byte[this.plotworld.MAIN_BLOCK.length];
|
||||
for (int i = 0; i < this.plotworld.MAIN_BLOCK.length; i++) {
|
||||
count2++;
|
||||
this.filling[i] = this.plotworld.MAIN_BLOCK[i].data;
|
||||
if (this.plotworld.MAIN_BLOCK[i].data != 0) {
|
||||
this.doFilling = true;
|
||||
}
|
||||
}
|
||||
if (((count1 > 0) && this.doFloor) || ((count2 > 0) && this.doFilling)) {
|
||||
this.doState = true;
|
||||
}
|
||||
this.wallheight = this.plotworld.WALL_HEIGHT;
|
||||
this.roadheight = this.plotworld.ROAD_HEIGHT;
|
||||
this.plotheight = this.plotworld.PLOT_HEIGHT;
|
||||
if (this.pathsize == 0) {
|
||||
this.pathWidthLower = (short) -1;
|
||||
this.pathWidthUpper = (short) (this.plotsize + 1);
|
||||
}
|
||||
else {
|
||||
if ((this.pathsize % 2) == 0) {
|
||||
this.pathWidthLower = (short) (Math.floor(this.pathsize / 2) - 1);
|
||||
} else {
|
||||
this.pathWidthLower = (short) (Math.floor(this.pathsize / 2));
|
||||
}
|
||||
this.pathWidthUpper = (short) (this.pathWidthLower + this.plotsize + 1);
|
||||
}
|
||||
}
|
||||
|
||||
public final long nextLong() {
|
||||
final long a = this.state;
|
||||
this.state = xorShift64(a);
|
||||
return a;
|
||||
}
|
||||
|
||||
public final long xorShift64(long a) {
|
||||
a ^= (a << 21);
|
||||
a ^= (a >>> 35);
|
||||
a ^= (a << 4);
|
||||
return a;
|
||||
}
|
||||
|
||||
public final int random(final int n) {
|
||||
final long result = ((nextLong() >>> 32) * n) >> 32;
|
||||
return (int) result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void populate(World world, RegionWrapper requiredRegion, PseudoRandom random, int cx, int cz) {
|
||||
PS.get().getPlotManager(world.getName());
|
||||
|
||||
int sx = (short) ((this.X - this.plotworld.ROAD_OFFSET_X) % this.size);
|
||||
int sz = (short) ((this.Z - this.plotworld.ROAD_OFFSET_Z) % this.size);
|
||||
if (sx < 0) {
|
||||
sx += this.size;
|
||||
}
|
||||
if (sz < 0) {
|
||||
sz += this.size;
|
||||
}
|
||||
|
||||
if (requiredRegion != null) {
|
||||
for (short x = 0; x < 16; x++) {
|
||||
for (short z = 0; z < 16; z++) {
|
||||
if (contains(requiredRegion, x, z)) {
|
||||
if (this.doFilling) {
|
||||
for (short y = 1; y < this.plotheight; y++) {
|
||||
setBlock(x, y, z, this.filling);
|
||||
}
|
||||
}
|
||||
if (this.doFloor) {
|
||||
setBlock(x, (short) this.plotheight, z, this.plotfloors);
|
||||
}
|
||||
if (this.plotworld.PLOT_SCHEMATIC) {
|
||||
final int absX = ((sx + x) % this.size);
|
||||
final int absZ = ((sz + z) % this.size);
|
||||
final PlotLoc loc = new PlotLoc(absX, absZ);
|
||||
final HashMap<Short, Byte> blocks = this.plotworld.G_SCH_DATA.get(loc);
|
||||
if (blocks != null) {
|
||||
for (final short y : blocks.keySet()) {
|
||||
setBlockAbs(x, (short) (this.plotheight + y), z, blocks.get(y));
|
||||
}
|
||||
}
|
||||
if (this.plotworld.G_SCH_STATE != null) {
|
||||
HashSet<PlotItem> states = this.plotworld.G_SCH_STATE.get(loc);
|
||||
if (states != null) {
|
||||
for (PlotItem items : states) {
|
||||
BlockManager.manager.addItems(this.plotworld.worldname, items);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
for (short x = 0; x < 16; x++) {
|
||||
for (short z = 0; z < 16; z++) {
|
||||
final int absX = ((sx + x) % this.size);
|
||||
final int absZ = ((sz + z) % this.size);
|
||||
final boolean gx = absX > this.pathWidthLower;
|
||||
final boolean gz = absZ > this.pathWidthLower;
|
||||
final boolean lx = absX < this.pathWidthUpper;
|
||||
final boolean lz = absZ < this.pathWidthUpper;
|
||||
// inside plot
|
||||
if (gx && gz && lx && lz) {
|
||||
for (short y = 1; y < this.plotheight; y++) {
|
||||
setBlock(x, y, z, this.filling);
|
||||
}
|
||||
setBlock(x, (short) this.plotheight, z, this.plotfloors);
|
||||
if (this.plotworld.PLOT_SCHEMATIC) {
|
||||
final PlotLoc loc = new PlotLoc(absX, absZ);
|
||||
final HashMap<Short, Byte> blocks = this.plotworld.G_SCH_DATA.get(loc);
|
||||
if (blocks != null) {
|
||||
for (final short y : blocks.keySet()) {
|
||||
setBlockAbs(x, (short) (this.plotheight + y), z, blocks.get(y));
|
||||
}
|
||||
}
|
||||
if (this.plotworld.G_SCH_STATE != null) {
|
||||
HashSet<PlotItem> states = this.plotworld.G_SCH_STATE.get(loc);
|
||||
if (states != null) {
|
||||
for (PlotItem items : states) {
|
||||
items.x = this.X + x;
|
||||
items.z = this.Z + z;
|
||||
BlockManager.manager.addItems(this.plotworld.worldname, items);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (pathsize != 0) {
|
||||
// wall
|
||||
if (((absX >= this.pathWidthLower) && (absX <= this.pathWidthUpper) && (absZ >= this.pathWidthLower) && (absZ <= this.pathWidthUpper))) {
|
||||
for (short y = 1; y <= this.wallheight; y++) {
|
||||
setBlock(x, y, z, this.wallfilling);
|
||||
}
|
||||
if (!this.plotworld.ROAD_SCHEMATIC_ENABLED) {
|
||||
setBlock(x, this.wallheight + 1, z, this.wall);
|
||||
}
|
||||
}
|
||||
// road
|
||||
else {
|
||||
for (short y = 1; y <= this.roadheight; y++) {
|
||||
setBlock(x, y, z, this.roadblock);
|
||||
}
|
||||
}
|
||||
if (this.plotworld.ROAD_SCHEMATIC_ENABLED) {
|
||||
final PlotLoc loc = new PlotLoc(absX, absZ);
|
||||
final HashMap<Short, Byte> blocks = this.plotworld.G_SCH_DATA.get(loc);
|
||||
if (blocks != null) {
|
||||
for (final short y : blocks.keySet()) {
|
||||
setBlockAbs(x, (short) (this.roadheight + y), z, blocks.get(y));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setBlock(final short x, final short y, final short z, final byte[] blkids) {
|
||||
if (blkids.length == 1) {
|
||||
setBlock(x, y, z, blkids[0]);
|
||||
} else {
|
||||
final int i = random(blkids.length);
|
||||
setBlock(x, y, z, blkids[i]);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user