mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-26 07:06:44 +01:00
Optimize schematic paste
This commit is contained in:
parent
e3eccfd476
commit
6af96f43d4
@ -23,6 +23,18 @@ public class HybridGen extends IndependentPlotGenerator {
|
||||
return PS.imp().getPluginName();
|
||||
}
|
||||
|
||||
private void placeSchem(HybridPlotWorld world, ScopedLocalBlockQueue result, short relativeX, short relativeZ, int x, int z) {
|
||||
char[] blocks = world.G_SCH.get(MathMan.pair(relativeX, relativeZ));
|
||||
if (blocks != null) {
|
||||
for (int y = 0; y < blocks.length; y++) {
|
||||
PlotBlock block = PlotBlock.get(blocks[y]);
|
||||
if (block != null) {
|
||||
result.setBlock(x, y, z, block);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateChunk(ScopedLocalBlockQueue result, PlotArea settings, PseudoRandom random) {
|
||||
HybridPlotWorld hpw = (HybridPlotWorld) settings;
|
||||
@ -83,7 +95,7 @@ public class HybridGen extends IndependentPlotGenerator {
|
||||
}
|
||||
}
|
||||
// generation
|
||||
HashMap<Integer, HashMap<Integer, PlotBlock>> sch = hpw.G_SCH;
|
||||
HashMap<Integer, char[]> sch = hpw.G_SCH;
|
||||
for (short x = 0; x < 16; x++) {
|
||||
if (gx[x]) {
|
||||
for (short z = 0; z < 16; z++) {
|
||||
@ -92,12 +104,7 @@ public class HybridGen extends IndependentPlotGenerator {
|
||||
result.setBlock(x, y, z, hpw.ROAD_BLOCK);
|
||||
}
|
||||
if (hpw.ROAD_SCHEMATIC_ENABLED) {
|
||||
HashMap<Integer, PlotBlock> map = sch.get(MathMan.pair(rx[x], rz[z]));
|
||||
if (map != null) {
|
||||
for (Entry<Integer, PlotBlock> entry : map.entrySet()) {
|
||||
result.setBlock(x, entry.getKey(), z, entry.getValue());
|
||||
}
|
||||
}
|
||||
placeSchem(hpw, result, rx[x], rz[z], x, z);
|
||||
}
|
||||
}
|
||||
} else if (wx[x]) {
|
||||
@ -108,12 +115,7 @@ public class HybridGen extends IndependentPlotGenerator {
|
||||
result.setBlock(x, y, z, hpw.ROAD_BLOCK);
|
||||
}
|
||||
if (hpw.ROAD_SCHEMATIC_ENABLED) {
|
||||
HashMap<Integer, PlotBlock> map = sch.get(MathMan.pair(rx[x], rz[z]));
|
||||
if (map != null) {
|
||||
for (Entry<Integer, PlotBlock> entry : map.entrySet()) {
|
||||
result.setBlock(x, entry.getKey(), z, entry.getValue());
|
||||
}
|
||||
}
|
||||
placeSchem(hpw, result, rx[x], rz[z], x, z);
|
||||
}
|
||||
} else {
|
||||
// wall
|
||||
@ -123,12 +125,7 @@ public class HybridGen extends IndependentPlotGenerator {
|
||||
if (!hpw.ROAD_SCHEMATIC_ENABLED) {
|
||||
result.setBlock(x, hpw.WALL_HEIGHT + 1, z, hpw.WALL_BLOCK);
|
||||
} else {
|
||||
HashMap<Integer, PlotBlock> map = sch.get(MathMan.pair(rx[x], rz[z]));
|
||||
if (map != null) {
|
||||
for (Entry<Integer, PlotBlock> entry : map.entrySet()) {
|
||||
result.setBlock(x, entry.getKey(), z, entry.getValue());
|
||||
}
|
||||
}
|
||||
placeSchem(hpw, result, rx[x], rz[z], x, z);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -140,12 +137,7 @@ public class HybridGen extends IndependentPlotGenerator {
|
||||
result.setBlock(x, y, z, hpw.ROAD_BLOCK);
|
||||
}
|
||||
if (hpw.ROAD_SCHEMATIC_ENABLED) {
|
||||
HashMap<Integer, PlotBlock> map = sch.get(MathMan.pair(rx[x], rz[z]));
|
||||
if (map != null) {
|
||||
for (Entry<Integer, PlotBlock> entry : map.entrySet()) {
|
||||
result.setBlock(x, entry.getKey(), z, entry.getValue());
|
||||
}
|
||||
}
|
||||
placeSchem(hpw, result, rx[x], rz[z], x, z);
|
||||
}
|
||||
} else if (wz[z]) {
|
||||
// wall
|
||||
@ -155,12 +147,7 @@ public class HybridGen extends IndependentPlotGenerator {
|
||||
if (!hpw.ROAD_SCHEMATIC_ENABLED) {
|
||||
result.setBlock(x, hpw.WALL_HEIGHT + 1, z, hpw.WALL_BLOCK);
|
||||
} else {
|
||||
HashMap<Integer, PlotBlock> map = sch.get(MathMan.pair(rx[x], rz[z]));
|
||||
if (map != null) {
|
||||
for (Entry<Integer, PlotBlock> entry : map.entrySet()) {
|
||||
result.setBlock(x, entry.getKey(), z, entry.getValue());
|
||||
}
|
||||
}
|
||||
placeSchem(hpw, result, rx[x], rz[z], x, z);
|
||||
}
|
||||
} else {
|
||||
// plot
|
||||
@ -169,13 +156,7 @@ public class HybridGen extends IndependentPlotGenerator {
|
||||
}
|
||||
result.setBlock(x, hpw.PLOT_HEIGHT, z, hpw.TOP_BLOCK[random.random(hpw.TOP_BLOCK.length)]);
|
||||
if (hpw.PLOT_SCHEMATIC) {
|
||||
int pair = MathMan.pair(rx[x], rz[z]);
|
||||
HashMap<Integer, PlotBlock> map = sch.get(pair);
|
||||
if (map != null) {
|
||||
for (Entry<Integer, PlotBlock> entry : map.entrySet()) {
|
||||
result.setBlock(x, entry.getKey(), z, entry.getValue());
|
||||
}
|
||||
}
|
||||
placeSchem(hpw, result, rx[x], rz[z], x, z);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,9 +19,7 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
public class HybridPlotManager extends ClassicPlotManager {
|
||||
|
||||
@ -84,15 +82,13 @@ public class HybridPlotManager extends ClassicPlotManager {
|
||||
if (absZ < 0) {
|
||||
absZ += size;
|
||||
}
|
||||
HashMap<Integer, PlotBlock> blocks = hpw.G_SCH.get(MathMan.pair(absX, absZ));
|
||||
if (clear) {
|
||||
for (short y = (short) 0; y <= hpw.SCHEMATIC_HEIGHT; y++) {
|
||||
queue.setBlock(x, y, z, 0);
|
||||
}
|
||||
}
|
||||
char[] blocks = hpw.G_SCH.get(MathMan.pair(absX, absZ));
|
||||
if (blocks != null) {
|
||||
for (Entry<Integer, PlotBlock> entry : blocks.entrySet()) {
|
||||
queue.setBlock(x, entry.getKey(), z, entry.getValue());
|
||||
for (int y = 0; y < blocks.length; y++) {
|
||||
PlotBlock block = PlotBlock.get(blocks[y]);
|
||||
if (block != null) {
|
||||
queue.setBlock(x, y, z, block);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,11 +21,10 @@ import java.util.Map;
|
||||
public class HybridPlotWorld extends ClassicPlotWorld {
|
||||
|
||||
public boolean ROAD_SCHEMATIC_ENABLED;
|
||||
public short SCHEMATIC_HEIGHT;
|
||||
public boolean PLOT_SCHEMATIC = false;
|
||||
public short PATH_WIDTH_LOWER;
|
||||
public short PATH_WIDTH_UPPER;
|
||||
public HashMap<Integer, HashMap<Integer, PlotBlock>> G_SCH;
|
||||
public HashMap<Integer, char[]> G_SCH;
|
||||
public HashMap<Integer, HashMap<Integer, CompoundTag>> G_SCH_STATE;
|
||||
|
||||
public HybridPlotWorld(String worldName, String id, IndependentPlotGenerator generator, PlotId min, PlotId max) {
|
||||
@ -211,7 +210,7 @@ public class HybridPlotWorld extends ClassicPlotWorld {
|
||||
if (id != 0) {
|
||||
addOverlayBlock((short) (x + shift + oddshift + centerShiftX), (short) (y + this.PLOT_HEIGHT),
|
||||
(short) (z + shift + oddshift + centerShiftZ), id,
|
||||
data, false);
|
||||
data, false, h3);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -256,7 +255,6 @@ public class HybridPlotWorld extends ClassicPlotWorld {
|
||||
short w2 = (short) d2.getX();
|
||||
short l2 = (short) d2.getZ();
|
||||
short h2 = (short) d2.getY();
|
||||
this.SCHEMATIC_HEIGHT = (short) Math.max(h2, h1);
|
||||
for (short x = 0; x < w1; x++) {
|
||||
for (short z = 0; z < l1; z++) {
|
||||
for (short y = 0; y < h1; y++) {
|
||||
@ -264,8 +262,8 @@ public class HybridPlotWorld extends ClassicPlotWorld {
|
||||
short id = ids1[index];
|
||||
byte data = datas1[index];
|
||||
if (id != 0) {
|
||||
addOverlayBlock((short) (x - shift), (short) (y + this.ROAD_HEIGHT), (short) (z + shift + oddshift), id, data, false);
|
||||
addOverlayBlock((short) (z + shift + oddshift), (short) (y + this.ROAD_HEIGHT), (short) (x - shift), id, data, true);
|
||||
addOverlayBlock((short) (x - shift), (short) (y + this.ROAD_HEIGHT), (short) (z + shift + oddshift), id, data, false, h1);
|
||||
addOverlayBlock((short) (z + shift + oddshift), (short) (y + this.ROAD_HEIGHT), (short) (x - shift), id, data, true, h1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -277,14 +275,14 @@ public class HybridPlotWorld extends ClassicPlotWorld {
|
||||
short id = ids2[index];
|
||||
byte data = datas2[index];
|
||||
if (id != 0) {
|
||||
addOverlayBlock((short) (x - shift), (short) (y + this.ROAD_HEIGHT), (short) (z - shift), id, data, false);
|
||||
addOverlayBlock((short) (x - shift), (short) (y + this.ROAD_HEIGHT), (short) (z - shift), id, data, false, h2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addOverlayBlock(short x, short y, short z, short id, byte data, boolean rotate) {
|
||||
public void addOverlayBlock(short x, short y, short z, short id, byte data, boolean rotate, int height) {
|
||||
if (z < 0) {
|
||||
z += this.SIZE;
|
||||
}
|
||||
@ -298,11 +296,14 @@ public class HybridPlotWorld extends ClassicPlotWorld {
|
||||
}
|
||||
}
|
||||
int pair = MathMan.pair(x, z);
|
||||
HashMap<Integer, PlotBlock> existing = this.G_SCH.get(pair);
|
||||
char[] existing = this.G_SCH.get(pair);
|
||||
if (existing == null) {
|
||||
existing = new HashMap<>();
|
||||
existing = new char[height];
|
||||
this.G_SCH.put(pair, existing);
|
||||
}
|
||||
existing.put((int) y, PlotBlock.get(id, data));
|
||||
if (id == 0) {
|
||||
data = 1;
|
||||
}
|
||||
existing[(int) y] = (char) ((id << 4) + data);
|
||||
}
|
||||
}
|
||||
|
@ -21,16 +21,13 @@ import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.intellectualcrafters.plot.util.block.GlobalBlockQueue;
|
||||
import com.intellectualcrafters.plot.util.block.LocalBlockQueue;
|
||||
import com.intellectualcrafters.plot.util.expiry.PlotAnalysis;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
@ -378,7 +375,6 @@ public abstract class HybridUtils {
|
||||
int ex = x + 15;
|
||||
int ez = z + 15;
|
||||
HybridPlotWorld plotWorld = (HybridPlotWorld) area;
|
||||
extend = Math.min(extend, 255 - plotWorld.ROAD_HEIGHT - plotWorld.SCHEMATIC_HEIGHT);
|
||||
if (!plotWorld.ROAD_SCHEMATIC_ENABLED) {
|
||||
return false;
|
||||
}
|
||||
@ -436,13 +432,13 @@ public abstract class HybridUtils {
|
||||
condition = !gx || !gz || !lx || !lz;
|
||||
}
|
||||
if (condition) {
|
||||
HashMap<Integer, PlotBlock> blocks = plotWorld.G_SCH.get(MathMan.pair(absX, absZ));
|
||||
for (short y = (short) plotWorld.ROAD_HEIGHT; y <= plotWorld.ROAD_HEIGHT + plotWorld.SCHEMATIC_HEIGHT + extend; y++) {
|
||||
queue.setBlock(x + X + plotWorld.ROAD_OFFSET_X, y, z + Z + plotWorld.ROAD_OFFSET_Z, 0);
|
||||
}
|
||||
char[] blocks = plotWorld.G_SCH.get(MathMan.pair(absX, absZ));
|
||||
if (blocks != null) {
|
||||
for (Entry<Integer, PlotBlock> entry : blocks.entrySet()) {
|
||||
queue.setBlock(x + X + plotWorld.ROAD_OFFSET_X, entry.getKey(), z + Z + plotWorld.ROAD_OFFSET_Z, entry.getValue());
|
||||
for (int y = 0; y < blocks.length; y++) {
|
||||
PlotBlock block = PlotBlock.get(blocks[y]);
|
||||
if (block != null) {
|
||||
queue.setBlock(x + X + plotWorld.ROAD_OFFSET_X, y, z + Z + plotWorld.ROAD_OFFSET_Z, block);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,17 @@ public class PlotBlock {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public static PlotBlock get(char combinedId) {
|
||||
switch (combinedId) {
|
||||
case 0:
|
||||
return null;
|
||||
case 1:
|
||||
return get(0, 0);
|
||||
default:
|
||||
return get(combinedId >> 4, combinedId & 15);
|
||||
}
|
||||
}
|
||||
|
||||
public static PlotBlock get(int id, int data) {
|
||||
return Settings.Enabled_Components.BLOCK_CACHE && data > 0 ? CACHE[(id << 4) + data] : new PlotBlock((short) id, (byte) data);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user