commanding-pipeline diff

This commit is contained in:
Jesse Boyd
2019-10-23 05:23:52 +01:00
parent fb91456bdd
commit 2080e9786b
193 changed files with 5449 additions and 3491 deletions

View File

@ -80,6 +80,8 @@ public class Naturalizer implements LayerFunction {
}
private boolean naturalize(BlockVector3 position, int depth) throws WorldEditException {
return editSession.setBlock(position, getTargetBlock(depth));
/*
BlockState block = editSession.getBlock(position);
BlockState targetBlock = getTargetBlock(depth);
@ -88,6 +90,7 @@ public class Naturalizer implements LayerFunction {
}
return editSession.setBlock(position, targetBlock);
*/
}
@Override

View File

@ -24,6 +24,7 @@ import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.function.RegionFunction;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.util.TreeGenerator;
import com.sk89q.worldedit.world.block.BlockID;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes;
@ -53,22 +54,28 @@ public class ForestGenerator implements RegionFunction {
BlockState block = editSession.getBlock(position);
BlockType t = block.getBlockType();
if (t == BlockTypes.GRASS_BLOCK || t == BlockTypes.DIRT || t == BlockTypes.PODZOL || t == BlockTypes.COARSE_DIRT) {
return treeType.generate(editSession, position.add(0, 1, 0));
} else if (t.getMaterial().isReplacedDuringPlacement()) {
// since the implementation's tree generators generally don't generate in non-air spots,
// we trick editsession history here in the first call
editSession.setBlock(position, BlockTypes.AIR.getDefaultState());
// and then trick the generator here by directly setting into the world
editSession.getWorld().setBlock(position, BlockTypes.AIR.getDefaultState());
// so that now the generator can generate the tree
boolean success = treeType.generate(editSession, position);
if (!success) {
editSession.setBlock(position, block); // restore on failure
}
return success;
} else { // Trees won't grow on this!
return false;
switch (t.getInternalId()) {
case BlockID.GRASS_BLOCK:
case BlockID.DIRT:
case BlockID.PODZOL:
case BlockID.COARSE_DIRT:
return treeType.generate(editSession, position.add(0, 1, 0));
default:
if (t.getMaterial().isReplacedDuringPlacement()) {
// since the implementation's tree generators generally don't generate in non-air spots,
// we trick editsession history here in the first call
editSession.setBlock(position, BlockTypes.AIR.getDefaultState());
// and then trick the generator here by directly setting into the world
editSession.getWorld().setBlock(position, BlockTypes.AIR.getDefaultState());
// so that now the generator can generate the tree
boolean success = treeType.generate(editSession, position);
if (!success) {
editSession.setBlock(position, block); // restore on failure
}
return success;
} else { // Trees won't grow on this!
return false;
}
}
}
}

View File

@ -151,7 +151,9 @@ public class BlockMask extends ABlockMask {
@Deprecated
public void add(Collection<BaseBlock> blocks) {
checkNotNull(blocks);
blocks.forEach(baseBlock -> add(baseBlock.toBlockState()));
for (BaseBlock block : blocks) {
add(block.toBlockState());
}
}
/**

View File

@ -149,14 +149,13 @@ public class BlockMaskBuilder {
Collection<BlockType> types = type != null ? Collections.singleton(type) : blockTypeList;
throw new SuggestInputParseException("No value for " + input, input, () -> {
HashSet<String> values = new HashSet<>();
types.forEach(t -> {
if (t.hasProperty(fKey)) {
Property p = t.getProperty(fKey);
for (int j = 0; j < p.getValues().size(); j++) {
if (has(t, p, j)) {
String o = p.getValues().get(j).toString();
if (o.startsWith(value)) values.add(o);
}
types.stream().filter(t -> t.hasProperty(fKey)).forEach(t -> {
Property p = t.getProperty(fKey);
for (int j = 0; j < p.getValues().size(); j++) {
if (has(t, p, j)) {
String o = p.getValues().get(j).toString();
if (o.startsWith(value))
values.add(o);
}
}
});
@ -224,7 +223,6 @@ public class BlockMaskBuilder {
AbstractProperty prop = (AbstractProperty) property;
long[] states = bitSets[type.getInternalId()];
if (states == null) return false;
List values = prop.getValues();
int localI = index << prop.getBitOffset() >> BlockTypes.BIT_OFFSET;
return (states == ALL || FastBitSet.get(states, localI));
}

View File

@ -40,7 +40,7 @@ public class ExistingBlockMask extends AbstractExtentMask {
@Override
public boolean test(BlockVector3 vector) {
return !getExtent().getBlock(vector).getBlockType().getMaterial().isAir();
return !vector.getBlock(getExtent()).getMaterial().isAir();
}
@Nullable

View File

@ -75,8 +75,7 @@ public class ExpressionMask extends AbstractMask {
if (timeout == null) {
return expression.evaluate(vector.getX(), vector.getY(), vector.getZ()) > 0;
} else {
return expression.evaluate(new double[]{vector.getX(), vector.getY(), vector.getZ()},
timeout.getAsInt()) > 0;
return expression.evaluateTimeout(timeout.getAsInt(), vector.getX(), vector.getY(), vector.getZ()) > 0;
}
} catch (EvaluationException e) {
return false;

View File

@ -61,10 +61,10 @@ public class ExpressionMask2D extends AbstractMask2D {
@Override
public boolean test(BlockVector2 vector) {
try {
if (timeout != null) {
if (timeout == null) {
return expression.evaluate(vector.getX(), 0, vector.getZ()) > 0;
} else {
return expression.evaluate(new double[]{vector.getX(), 0, vector.getZ()}, timeout.getAsInt()) > 0;
return expression.evaluate(timeout.getAsInt(), vector.getX(), 0, vector.getZ()) > 0;
}
} catch (EvaluationException e) {
return false;

View File

@ -19,7 +19,6 @@
package com.sk89q.worldedit.function.mask;
import com.boydti.fawe.beta.DelegateFilter;
import com.boydti.fawe.beta.Filter;
import com.boydti.fawe.beta.FilterBlock;
import com.sk89q.worldedit.math.BlockVector3;
@ -38,15 +37,8 @@ public interface Mask {
*/
boolean test(BlockVector3 vector);
default <T extends Filter> DelegateFilter<T> toFilter(T filter) {
return new DelegateFilter<T>(filter) {
@Override
public void applyBlock(FilterBlock block) {
if (test(block)) {
filter.applyBlock(block);
}
}
};
default <T extends Filter> MaskFilter<T> toFilter(T filter) {
return new MaskFilter<>(filter, this);
}
/**
@ -81,15 +73,15 @@ public interface Mask {
return value == null ? this : value;
}
// default Mask and(Mask other) {
// Mask value = and(other);
// return value == null ? new MaskIntersection(this, other) : value;
// }
default Mask and(Mask other) {
Mask value = and(other);
return value == null ? MaskIntersection.of(this, other) : value;
}
// default Mask or(Mask other) {
// Mask value = or(other);
// return value == null ? new MaskUnion(this, other) : value;
// }
default Mask or(Mask other) {
Mask value = or(other);
return value == null ? MaskUnion.of(this, other) : value;
}
default Mask inverse() {
if (this instanceof Masks.AlwaysTrue) {
@ -99,4 +91,15 @@ public interface Mask {
}
return new InverseMask(this);
}
default Filter toFilter(Runnable run) {
return new Filter() {
@Override
public void applyBlock(FilterBlock block) {
if (test(block)) {
run.run();
}
}
};
}
}

View File

@ -0,0 +1,38 @@
package com.sk89q.worldedit.function.mask;
import com.boydti.fawe.beta.DelegateFilter;
import com.boydti.fawe.beta.Filter;
import com.boydti.fawe.beta.FilterBlock;
import java.util.function.Supplier;
public class MaskFilter<T extends Filter> extends DelegateFilter<T> {
private final Supplier<Mask> supplier;
private final Mask mask;
public MaskFilter(T other, Mask mask) {
this(other, () -> mask);
}
public MaskFilter(T other, Supplier<Mask> supplier) {
this(other, supplier, supplier.get());
}
public MaskFilter(T other, Supplier<Mask> supplier, Mask root) {
super(other);
this.supplier = supplier;
this.mask = root;
}
@Override
public void applyBlock(FilterBlock block) {
if (mask.test(block)) {
getParent().applyBlock(block);
}
}
@Override
public MaskFilter newInstance(Filter other) {
return new MaskFilter<>(other, supplier);
}
}

View File

@ -44,8 +44,9 @@ import javax.annotation.Nullable;
*/
public class MaskIntersection extends AbstractMask {
private final Set<Mask> masks = new LinkedHashSet<>();
private final Set<Mask> masks;
private Mask[] masksArray;
private boolean defaultReturn;
/**
* Create a new intersection.
@ -54,7 +55,7 @@ public class MaskIntersection extends AbstractMask {
*/
public MaskIntersection(Collection<Mask> masks) {
checkNotNull(masks);
this.masks.addAll(masks);
this.masks = new LinkedHashSet<>(masks);
formArray();
}
@ -97,6 +98,7 @@ public class MaskIntersection extends AbstractMask {
} else {
masksArray = masks.toArray(new Mask[0]);
}
this.defaultReturn = masksArray.length != 0;
}
public Function<Entry<Mask, Mask>, Mask> pairingFunction() {
@ -155,7 +157,7 @@ public class MaskIntersection extends AbstractMask {
}
// Return result
formArray();
if (masks.size() == 0) return Masks.alwaysTrue();
if (masks.isEmpty()) return Masks.alwaysTrue();
if (masks.size() == 1) return masks.iterator().next();
return changed ? this : null;
}
@ -222,17 +224,13 @@ public class MaskIntersection extends AbstractMask {
@Override
public boolean test(BlockVector3 vector) {
if (masksArray.length == 0) {
return false;
}
for (Mask mask : masksArray) {
if (!mask.test(vector)) {
return false;
}
}
return true;
return defaultReturn;
}
@Nullable

View File

@ -35,7 +35,23 @@ import java.util.List;
*/
public class ChangeSetExecutor implements Operation {
public enum Type {UNDO, REDO}
public enum Type {
UNDO {
@Override
public void perform(Change change, UndoContext context) {
change.undo(context);
}
},
REDO {
@Override
public void perform(Change change, UndoContext context) {
change.redo(context);
}
}
;
public void perform(Change change, UndoContext context) {}
}
private final Iterator<Change> iterator;
private final Type type;
@ -68,13 +84,8 @@ public class ChangeSetExecutor implements Operation {
public Operation resume(RunContext run) throws WorldEditException {
while (iterator.hasNext()) {
Change change = iterator.next();
if (type == Type.UNDO) {
change.undo(context);
} else {
change.redo(context);
}
type.perform(change, context);
}
return null;
}

View File

@ -65,10 +65,9 @@ public class WaterloggedRemover extends AbstractExtentPattern {
@Override
public BaseBlock apply(BlockVector3 position) {
BaseBlock block = getExtent().getFullBlock(position);
@SuppressWarnings("unchecked")
Property<Object> prop = (Property<Object>) remap[block.getOrdinal()].getBlockType().getPropertyMap().getOrDefault("waterlogged", null);
if (prop != null) {
return block.with(prop, false);
BlockState newState = remap[block.getOrdinal()];
if (newState != null) {
return newState.toBaseBlock(block.getNbtData());
}
return BlockTypes.AIR.getDefaultState().toBaseBlock();
}

View File

@ -41,11 +41,24 @@ public class RegionVisitor implements Operation {
public final Iterable<? extends BlockVector3> iterable;
/**
* Deprecated in favor of the other constructors which will preload chunks during iteration
*
* @param region
* @param function
*/
@Deprecated
public RegionVisitor(Region region, RegionFunction function) {
this((Iterable<BlockVector3>) region, function);
}
/**
* Deprecated in favor of the other constructors which will preload chunks during iteration
*
* @param region
* @param function
*/
@Deprecated
public RegionVisitor(Iterable<BlockVector3> iterable, RegionFunction function) {
this.region = iterable instanceof Region ? (Region) iterable : null;
this.function = function;