From e2b9d1982c4315442f579860f88568e847c2060e Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Fri, 5 May 2017 04:08:24 +1000 Subject: [PATCH] CFI tweaks --- .../jnbt/anvil/HeightMapMCAGenerator.java | 67 +++++++++++++++++-- .../collection/LocalBlockVector2DSet.java | 2 +- .../regions/general/plot/CreateFromImage.java | 26 +++++-- 3 files changed, 83 insertions(+), 12 deletions(-) diff --git a/core/src/main/java/com/boydti/fawe/jnbt/anvil/HeightMapMCAGenerator.java b/core/src/main/java/com/boydti/fawe/jnbt/anvil/HeightMapMCAGenerator.java index c1f1dd85..ac19775f 100644 --- a/core/src/main/java/com/boydti/fawe/jnbt/anvil/HeightMapMCAGenerator.java +++ b/core/src/main/java/com/boydti/fawe/jnbt/anvil/HeightMapMCAGenerator.java @@ -161,9 +161,61 @@ public class HeightMapMCAGenerator extends MCAWriter implements Extent { } else { schematic.paste(this, worldData, mutable, false, transform); } - x += distance; - index += distance; - continue; + if (x + distance < getWidth()) { + x += distance; + index += distance; + } else { + break; + } + } + } + } + + public void addSchems(Mask mask, WorldData worldData, ClipboardHolder[] clipboards, int rarity, int distance, boolean randomRotate) throws WorldEditException{ + int scaledRarity = (256 * rarity) / 100; + int index = 0; + AffineTransform identity = new AffineTransform(); + LocalBlockVector2DSet placed = new LocalBlockVector2DSet(); + for (int z = 0; z < getLength(); z++) { + mutable.mutZ(z); + for (int x = 0; x < getWidth(); x++, index++){ + int y = heights[index]; + if (PseudoRandom.random.nextInt(256) > scaledRarity) { + continue; + } + mutable.mutX(x); + mutable.mutY(y); + if (!mask.test(mutable)) { + continue; + } + if (placed.containsRadius(x, z, distance)) { + continue; + } + mutable.mutY(y + 1); + placed.add(x, z); + ClipboardHolder holder = clipboards[PseudoRandom.random.random(clipboards.length)]; + if (randomRotate) { + int rotate = PseudoRandom.random.random(4) * 90; + if (rotate != 0) { + holder.setTransform(new AffineTransform().rotateY(PseudoRandom.random.random(4) * 90)); + } else { + holder.setTransform(identity); + } + } + Clipboard clipboard = holder.getClipboard(); + Schematic schematic = new Schematic(clipboard); + Transform transform = holder.getTransform(); + if (transform.isIdentity()) { + schematic.paste(this, mutable, false); + } else { + schematic.paste(this, worldData, mutable, false, transform); + } + if (x + distance < getWidth()) { + x += distance; + index += distance; + } else { + break; + } } } } @@ -695,13 +747,14 @@ public class HeightMapMCAGenerator extends MCAWriter implements Extent { Arrays.fill(chunk.data[i], (byte) 0); } } - int index = 0; + int index; int maxY = 0; int minY = Integer.MAX_VALUE; int[] heightMap = chunk.getHeightMapArray(); int globalIndex; for (int z = csz; z <= cez; z++) { globalIndex = z * getWidth() + csx; + index = (z & 15) << 4; for (int x = csx; x <= cex; x++, index++, globalIndex++) { indexes[index] = globalIndex; chunk.biomes[index] = biomes[globalIndex]; @@ -727,10 +780,10 @@ public class HeightMapMCAGenerator extends MCAWriter implements Extent { } if (modifiedMain) { // If the main block is modified, we can't short circuit this for (int layer = 0; layer < fillLayers; layer++) { - index = 0; byte[] layerIds = chunk.ids[layer]; byte[] layerDatas = chunk.data[layer]; for (int z = csz; z <= cez; z++) { + index = (z & 15) << 4; for (int x = csx; x <= cex; x++, index++) { globalIndex = indexes[index]; char mainCombined = main[globalIndex]; @@ -778,10 +831,10 @@ public class HeightMapMCAGenerator extends MCAWriter implements Extent { Arrays.fill(chunk.skyLight[layer], (byte) 255); byte[] layerIds = chunk.ids[layer]; byte[] layerDatas = chunk.data[layer]; - index = 0; int startY = layer << 4; int endY = startY + 15; for (int z = csz; z <= cez; z++) { + index = (z & 15) << 4; for (int x = csx; x <= cex; x++, index++) { globalIndex = indexes[index]; int height = heightMap[index]; @@ -841,10 +894,10 @@ public class HeightMapMCAGenerator extends MCAWriter implements Extent { chunk.ids[layer] = null; chunk.data[layer] = null; } - index = 0; { // Bedrock byte[] layerIds = chunk.ids[0]; for (int z = csz; z <= cez; z++) { + index = (z & 15) << 4; for (int x = csx; x <= cex; x++) { layerIds[index++] = (byte) 7; } diff --git a/core/src/main/java/com/boydti/fawe/object/collection/LocalBlockVector2DSet.java b/core/src/main/java/com/boydti/fawe/object/collection/LocalBlockVector2DSet.java index 6bd44109..f6677717 100644 --- a/core/src/main/java/com/boydti/fawe/object/collection/LocalBlockVector2DSet.java +++ b/core/src/main/java/com/boydti/fawe/object/collection/LocalBlockVector2DSet.java @@ -78,7 +78,7 @@ public class LocalBlockVector2DSet implements Set { for (int cx = bcx; cx <= tcx; cx++) { int index = MathMan.pairSearchCoords(cx << 4, cy << 4) - 1; int endIndex = index + 256; - while ((index = set.nextSetBit(index + 1)) <= endIndex && index != -1) { + while ((index = set.nextSetBit(index + 1)) != -1 && index <= endIndex) { // if (index == centerIndex) continue; int curx = MathMan.unpairSearchCoordsX(index); int cury = MathMan.unpairSearchCoordsY(index); diff --git a/core/src/main/java/com/boydti/fawe/regions/general/plot/CreateFromImage.java b/core/src/main/java/com/boydti/fawe/regions/general/plot/CreateFromImage.java index ca4aa55d..ff85e749 100644 --- a/core/src/main/java/com/boydti/fawe/regions/general/plot/CreateFromImage.java +++ b/core/src/main/java/com/boydti/fawe/regions/general/plot/CreateFromImage.java @@ -1,6 +1,7 @@ package com.boydti.fawe.regions.general.plot; import com.boydti.fawe.Fawe; +import com.boydti.fawe.FaweCache; import com.boydti.fawe.config.BBC; import com.boydti.fawe.jnbt.anvil.HeightMapMCAGenerator; import com.boydti.fawe.object.FawePlayer; @@ -27,11 +28,13 @@ import com.intellectualcrafters.plot.object.worlds.SinglePlotAreaManager; import com.intellectualcrafters.plot.util.MainUtil; import com.plotsquared.general.commands.Command; import com.plotsquared.general.commands.CommandDeclaration; +import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector2D; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.extension.input.InputParseException; import com.sk89q.worldedit.extension.input.ParserContext; +import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat; import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.pattern.Pattern; @@ -46,6 +49,7 @@ import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.net.URL; +import java.util.HashSet; import java.util.List; import java.util.Set; import javax.imageio.ImageIO; @@ -153,7 +157,7 @@ public class CreateFromImage extends Command { fp.sendMessage(BBC.getPrefix() + "/2 cfi blockBiomeColor "); fp.sendMessage(BBC.getPrefix() + "/2 cfi paletteComplexity "); fp.sendMessage(BBC.getPrefix() + "/2 cfi paletteRandomization "); - fp.sendMessage(BBC.getPrefix() + "/2 cfi paletteBlocks "); + fp.sendMessage(BBC.getPrefix() + "/2 cfi paletteBlocks "); fp.sendMessage(BBC.getPrefix() + "/2 cfi paletteBiomePriority "); fp.sendMessage(BBC.getPrefix() + "/2 cfi done"); fp.sendMessage(BBC.getPrefix() + "/2 cfi cancel"); @@ -210,7 +214,7 @@ public class CreateFromImage extends Command { int distance = Integer.parseInt(argList.get(4 + argOffset)); boolean rotate = Boolean.parseBoolean(argList.get(5 + argOffset)); if (img == null) { - generator.addSchems(mask, wd, clipboards, rarity, rotate); + generator.addSchems(mask, wd, clipboards, rarity, distance, rotate); } else { generator.addSchems(img, mask, wd, clipboards, rarity, distance, rotate); } @@ -251,11 +255,25 @@ public class CreateFromImage extends Command { // roughness // blocks if (argList.size() != 2) { - C.COMMAND_SYNTAX.send(player, "/2 cfi " + argList.get(0) + " "); + C.COMMAND_SYNTAX.send(player, "/2 cfi " + argList.get(0) + " "); return; } context.setPreferringWildcard(true); - Set blocks = we.getBlockFactory().parseFromListInput(argList.get(1), context); + Set blocks; + if (argList.get(1).equalsIgnoreCase("#clipboard")) { + ClipboardHolder holder = fp.getSession().getClipboard(); + Clipboard clipboard = holder.getClipboard(); + boolean[] ids = new boolean[Character.MAX_VALUE + 1]; + for (Vector pt : clipboard.getRegion()) { + ids[clipboard.getBlock(pt).getCombined()] = true; + } + blocks = new HashSet<>(); + for (int combined = 0; combined < ids.length; combined++) { + if (ids[combined]) blocks.add(FaweCache.CACHE_BLOCK[combined]); + } + } else { + blocks = we.getBlockFactory().parseFromListInput(argList.get(1), context); + } generator.setTextureUtil(new FilteredTextureUtil(Fawe.get().getTextureUtil(), blocks)); player.sendMessage("Set color palette blocks, what's next?"); return;