Mask and Pattern modifications

This commit is contained in:
MattBDev 2020-03-17 23:05:52 -04:00
parent 1df5853f33
commit 8a70f97445
17 changed files with 15 additions and 334 deletions

View File

@ -108,7 +108,7 @@ public class BukkitImageViewer implements ImageViewer {
Collection<Entity> entities = world.getNearbyEntities(pos, 0.1, 0.1, 0.1);
boolean contains = false;
for (Entity ent : entities) {
if (ent instanceof ItemFrame && ((ItemFrame) ent).getFacing() == facing) {
if (ent instanceof ItemFrame && ent.getFacing() == facing) {
ItemFrame itemFrame = (ItemFrame) ent;
itemFrame.setRotation(Rotation.NONE);
contains = true;
@ -188,4 +188,4 @@ public class BukkitImageViewer implements ImageViewer {
public void close() throws IOException {
last = null;
}
}
}

View File

@ -145,7 +145,7 @@ public class JSON2NBT {
private static JSON2NBT.Any getTagFromNameValue(String str, boolean isArray) throws NBTException {
String s = locateName(str, isArray);
String s1 = locateValue(str, isArray);
return joinStrToNBT(new String[]{s, s1});
return joinStrToNBT(s, s1);
}
private static String nextNameValuePair(String str, boolean isCompound) throws NBTException {

View File

@ -7,6 +7,7 @@ import com.sk89q.worldedit.history.change.Change;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.biome.BiomeType;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
public class NullChangeSet extends AbstractChangeSet {
@ -58,7 +59,7 @@ public class NullChangeSet extends AbstractChangeSet {
@Override
public final Iterator<Change> getIterator(boolean undo) {
return new ArrayList<Change>().iterator();
return Collections.emptyIterator();
}
@Override

View File

@ -2,12 +2,10 @@ package com.boydti.fawe.object.brush;
import com.boydti.fawe.object.collection.LocalBlockVectorSet;
import com.boydti.fawe.object.mask.SurfaceMask;
import com.boydti.fawe.object.pattern.BiomePattern;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.mask.AbstractExtentMask;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.operation.Operations;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.function.visitor.BreadthFirstSearch;
@ -30,13 +28,7 @@ public class SplatterBrush extends ScatterBrush {
public void apply(final EditSession editSession, final LocalBlockVectorSet placed, final BlockVector3 position, Pattern p, double size) throws MaxChangedBlocksException {
final Pattern finalPattern;
if (solid) {
Pattern tmp;
try {
tmp = p.apply(position);
} catch (BiomePattern.BiomePatternException e) {
tmp = e.getPattern();
}
finalPattern = tmp;
finalPattern = p.apply(position);
} else {
finalPattern = p;
}

View File

@ -178,7 +178,7 @@ public abstract class FaweStreamChangeSet extends AbstractChangeSet {
};
} else {
posDel = new FaweStreamPositionDelegate() {
byte[] buffer = new byte[5];
final byte[] buffer = new byte[5];
int lx, ly, lz;
@Override
@ -405,7 +405,7 @@ public abstract class FaweStreamChangeSet extends AbstractChangeSet {
public Iterator<MutableBlockChange> getBlockIterator(final boolean dir) throws IOException {
final FaweInputStream is = getBlockIS();
if (is == null) {
return new ArrayList<MutableBlockChange>().iterator();
return Collections.emptyIterator();
}
final MutableBlockChange change = new MutableBlockChange(0, 0, 0, BlockTypes.AIR.getInternalId());
return new Iterator<MutableBlockChange>() {
@ -456,7 +456,7 @@ public abstract class FaweStreamChangeSet extends AbstractChangeSet {
public Iterator<MutableBiomeChange> getBiomeIterator(final boolean dir) throws IOException {
final FaweInputStream is = getBiomeIS();
if (is == null) {
return new ArrayList<MutableBiomeChange>().iterator();
return Collections.emptyIterator();
}
final MutableBiomeChange change = new MutableBiomeChange();
return new Iterator<MutableBiomeChange>() {
@ -570,7 +570,7 @@ public abstract class FaweStreamChangeSet extends AbstractChangeSet {
public Iterator<MutableEntityChange> getEntityIterator(final NBTInputStream is, final boolean create) {
if (is == null) {
return new ArrayList<MutableEntityChange>().iterator();
return Collections.emptyIterator();
}
final MutableEntityChange change = new MutableEntityChange(null, create);
try {
@ -619,7 +619,7 @@ public abstract class FaweStreamChangeSet extends AbstractChangeSet {
public Iterator<MutableTileChange> getTileIterator(final NBTInputStream is, final boolean create) {
if (is == null) {
return new ArrayList<MutableTileChange>().iterator();
return Collections.emptyIterator();
}
final MutableTileChange change = new MutableTileChange(null, create);
try {

View File

@ -37,7 +37,6 @@ public class AngleMask extends SolidBlockMask implements ResettableMask {
cacheBotX = Integer.MIN_VALUE;
cacheBotZ = Integer.MIN_VALUE;
lastX = Integer.MIN_VALUE;
lastX = Integer.MIN_VALUE;
lastY = Integer.MIN_VALUE;
if (cacheHeights != null) {
Arrays.fill(cacheHeights, (byte) 0);

View File

@ -1,29 +0,0 @@
package com.boydti.fawe.object.mask;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.mask.AbstractExtentMask;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.MutableBlockVector2;
import com.sk89q.worldedit.world.biome.BiomeType;
public class BiomeMask extends AbstractExtentMask implements ResettableMask {
private final BiomeType biome;
private transient MutableBlockVector2 mutable = new MutableBlockVector2();
public BiomeMask(Extent extent, BiomeType biome) {
super(extent);
this.biome = biome;
}
@Override
public void reset() {
mutable = new MutableBlockVector2();
}
@Override
public boolean test(Extent extent, BlockVector3 vector) {
BlockVector2 pos = mutable.setComponents(vector.getBlockX(), vector.getBlockZ());
return extent.getBiome(pos).getId() == biome.getId();
}
}

View File

@ -1,27 +0,0 @@
package com.boydti.fawe.object.mask;
import com.boydti.fawe.object.extent.LightingExtent;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.mask.AbstractExtentMask;
import com.sk89q.worldedit.math.BlockVector3;
public class BlockLightMask extends AbstractExtentMask {
private final int min, max;
public BlockLightMask(Extent extent, int min, int max) {
super(extent);
this.min = min;
this.max = max;
}
@Override
public boolean test(Extent extent, BlockVector3 vector) {
if (extent instanceof LightingExtent) {
int light = ((LightingExtent) extent).getBlockLight(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ());
return light >= min && light <= max;
}
return false;
}
}

View File

@ -1,27 +0,0 @@
package com.boydti.fawe.object.mask;
import com.boydti.fawe.object.extent.LightingExtent;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.mask.AbstractExtentMask;
import com.sk89q.worldedit.math.BlockVector3;
public class BrightnessMask extends AbstractExtentMask {
private final int min, max;
public BrightnessMask(Extent extent, int min, int max) {
super(extent);
this.min = min;
this.max = max;
}
@Override
public boolean test(Extent extent, BlockVector3 vector) {
if (extent instanceof LightingExtent) {
int light = ((LightingExtent) extent).getBrightness(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ());
return light >= min && light <= max;
}
return false;
}
}

View File

@ -1,27 +0,0 @@
package com.boydti.fawe.object.mask;
import com.boydti.fawe.object.extent.LightingExtent;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.mask.AbstractExtentMask;
import com.sk89q.worldedit.math.BlockVector3;
public class LightMask extends AbstractExtentMask {
private final int min, max;
public LightMask(Extent extent, int min, int max) {
super(extent);
this.min = min;
this.max = max;
}
@Override
public boolean test(Extent extent, BlockVector3 vector) {
if (extent instanceof LightingExtent) {
int light = ((LightingExtent) extent).getLight(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ());
return light >= min && light <= max;
}
return false;
}
}

View File

@ -1,27 +0,0 @@
package com.boydti.fawe.object.mask;
import com.boydti.fawe.object.extent.LightingExtent;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.mask.AbstractExtentMask;
import com.sk89q.worldedit.math.BlockVector3;
public class OpacityMask extends AbstractExtentMask {
private final int min, max;
public OpacityMask(Extent extent, int min, int max) {
super(extent);
this.min = min;
this.max = max;
}
@Override
public boolean test(Extent extent, BlockVector3 vector) {
if (extent instanceof LightingExtent) {
int light = ((LightingExtent) extent).getOpacity(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ());
return light >= min && light <= max;
}
return false;
}
}

View File

@ -10,7 +10,6 @@ public class ROCAngleMask extends AngleMask {
@Override
protected boolean testSlope(Extent extent, int x, int y, int z) {
double tmp;
lastY = y;
int base = getHeight(extent, x, y, z);
@ -18,7 +17,8 @@ public class ROCAngleMask extends AngleMask {
(getHeight(extent, x + distance, y, z) - base - (base - getHeight(extent, x - distance, y, z)))
* ADJACENT_MOD;
tmp = (getHeight(extent, x, y, z + distance) - base - (base - getHeight(extent, x, y, z - distance))) * ADJACENT_MOD;
double tmp = (getHeight(extent, x, y, z + distance) - base - (base - getHeight(extent, x, y,
z - distance))) * ADJACENT_MOD;
if (Math.abs(tmp) > Math.abs(slope)) slope = tmp;
tmp = (getHeight(extent, x + distance, y, z + distance) - base - (base - getHeight(extent, x - distance, y,

View File

@ -1,29 +0,0 @@
package com.boydti.fawe.object.mask;
import com.boydti.fawe.object.extent.LightingExtent;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.mask.AbstractExtentMask;
import com.sk89q.worldedit.math.BlockVector3;
public class SkyLightMask extends AbstractExtentMask {
private final int min;
private final int max;
public SkyLightMask(Extent extent, int min, int max) {
super(extent);
this.min = min;
this.max = max;
}
@Override
public boolean test(Extent extent, BlockVector3 vector) {
if (extent instanceof LightingExtent) {
int light = ((LightingExtent) extent)
.getSkyLight(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ());
return light >= min && light <= max;
}
return false;
}
}

View File

@ -1,44 +0,0 @@
package com.boydti.fawe.object.pattern;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock;
public class BiomePattern extends ExistingPattern {
private final BiomeType biome;
public BiomePattern(Extent extent, BiomeType biome) {
super(extent);
this.biome = biome;
}
@Override
public BaseBlock apply(BlockVector3 position) {
throw new BiomePatternException();
}
@Override
public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException {
return set.setBiome(extent, biome);
}
public class BiomePatternException extends RuntimeException {
private BiomePatternException() {
}
public BiomePattern getPattern() {
return BiomePattern.this;
}
public BiomeType getBiome() {
return biome;
}
@Override
public Throwable fillInStackTrace() {
return this;
}
}
}

View File

@ -1,51 +0,0 @@
package com.boydti.fawe.object.pattern;
import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.function.mask.ExistingBlockMask;
import com.sk89q.worldedit.function.operation.ForwardExtentCopy;
import com.sk89q.worldedit.function.operation.Operations;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.MutableBlockVector3;
import com.sk89q.worldedit.world.block.BaseBlock;
import java.io.IOException;
import java.io.NotSerializableException;
/**
* A pattern that reads from {@link Clipboard}.
*/
public class FullClipboardPattern extends AbstractExtentPattern {
private final Clipboard clipboard;
private final MutableBlockVector3 mutable = new MutableBlockVector3();
/**
* Create a new clipboard pattern.
*
* @param clipboard the clipboard
*/
public FullClipboardPattern(Extent extent, Clipboard clipboard) {
super(extent);
checkNotNull(clipboard);
this.clipboard = clipboard;
}
@Override
public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException {
ForwardExtentCopy copy = new ForwardExtentCopy(clipboard, clipboard.getRegion(), clipboard.getOrigin(), extent, set);
copy.setSourceMask(new ExistingBlockMask(clipboard));
Operations.completeBlindly(copy);
return true;
}
@Override
public BaseBlock apply(BlockVector3 position) {
throw new IllegalStateException("Incorrect use. This pattern can only be applied to an extent!");
}
private void writeObject(java.io.ObjectOutputStream stream) throws IOException {
throw new NotSerializableException("Clipboard cannot be serialized!");
}
}

View File

@ -1571,10 +1571,8 @@ public class LocalSession implements TextureHolder {
this.sourceMask = mask;
}
public void setTextureUtil(TextureUtil texture) {
synchronized (this) {
this.texture = texture;
}
public synchronized void setTextureUtil(TextureUtil texture) {
this.texture = texture;
}
/**

View File

@ -74,25 +74,6 @@
//@CommandContainer//(superTypes = CommandPermissionsConditionGenerator.Registration.class)
//public class PatternCommands {
//
// @Command(
// name = "#existing",
// aliases = {"#*", "*", ".*"},
// desc = "Use the block that is already there"
// )
// public Pattern existing(Extent extent, @Arg(desc = "String", def = "") String properties) { // TODO FIXME , @Arg(name = "properties", desc = "String", def = "") String properties
// if (properties == null) return new ExistingPattern(extent);
// return new PropertyPattern(extent).addRegex(".*[" + properties + "]");
// }
//
// @Command(
// name = "#clipboard",
// aliases = {"#copy"},
// desc = "Use the blocks in your clipboard as the pattern")
// public Pattern clipboard(LocalSession session) throws EmptyClipboardException {
// ClipboardHolder holder = session.getClipboard();
// Clipboard clipboard = holder.getClipboard();
// return new ClipboardPattern(clipboard);
// }
//
// @Command(
// name = "#simplex",
@ -175,35 +156,6 @@
// }
//
// @Command(
// name = "#fullcopy",
// desc = "Places your full clipboard at each block"
//)
// public Pattern fullcopy(Player player, Extent extent, LocalSession session, @Arg(desc = "String", def = "#copy") String location, @Arg(desc = "boolean", def = "false") boolean rotate, @Arg(desc = "boolean", def = "false") boolean flip) throws EmptyClipboardException, InputParseException, IOException {
// List<ClipboardHolder> clipboards;
// switch (location.toLowerCase()) {
// case "#copy":
// case "#clipboard":
// ClipboardHolder clipboard = session.getExistingClipboard();
// if (clipboard == null) {
// throw new InputParseException("To use #fullcopy, please first copy something to your clipboard");
// }
// if (!rotate && !flip) {
// return new FullClipboardPattern(extent, clipboard.getClipboard());
// }
// clipboards = Collections.singletonList(clipboard);
// break;
// default:
// MultiClipboardHolder multi = ClipboardFormats.loadAllFromInput(player, location, null, true);
// clipboards = multi != null ? multi.getHolders() : null;
// break;
// }
// if (clipboards == null) {
// throw new InputParseException("#fullcopy:<source>");
// }
// return new RandomFullClipboardPattern(extent, clipboards, rotate, flip);
// }
//
// @Command(
// name = "#buffer",
// desc = "Only place a block once while a pattern is in use",
// descFooter = "Only place a block once while a pattern is in use\n" +