Merge remote-tracking branch 'upstream/master' into breaking

This commit is contained in:
Jesse Boyd
2019-04-03 16:53:34 +11:00
281 changed files with 5963 additions and 5444 deletions

View File

@ -0,0 +1,39 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.function.pattern;
import com.sk89q.worldedit.extent.Extent;
import static com.google.common.base.Preconditions.checkNotNull;
public abstract class AbstractExtentPattern extends AbstractPattern implements ExtentPattern {
private final Extent extent;
public AbstractExtentPattern(Extent extent) {
this.extent = extent;
checkNotNull(extent);
}
@Override
public Extent getExtent() {
return extent;
}
}

View File

@ -1,25 +1,12 @@
package com.sk89q.worldedit.function.pattern;
import com.sk89q.worldedit.world.block.BlockState;
import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BaseBlock;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* A pattern that reads from {@link Clipboard}.
*/
public class ClipboardPattern extends AbstractPattern {
private final Clipboard clipboard;
private final int sx, sy, sz;
private final BlockVector3 min;
// private final BlockVector3 size;
public class ClipboardPattern extends RepeatingExtentPattern {
/**
* Create a new clipboard pattern.
@ -27,25 +14,16 @@ public class ClipboardPattern extends AbstractPattern {
* @param clipboard the clipboard
*/
public ClipboardPattern(Clipboard clipboard) {
checkNotNull(clipboard);
this.clipboard = clipboard;
BlockVector3 size = clipboard.getMaximumPoint().subtract(clipboard.getMinimumPoint()).add(1, 1, 1);
this.sx = size.getBlockX();
this.sy = size.getBlockY();
this.sz = size.getBlockZ();
this.min = clipboard.getMinimumPoint();
this(clipboard, BlockVector3.ZERO);
}
@Override
public BaseBlock apply(BlockVector3 position) {
int xp = position.getBlockX() % sx;
int yp = position.getBlockY() % sy;
int zp = position.getBlockZ() % sz;
if (xp < 0) xp += sx;
if (yp < 0) yp += sy;
if (zp < 0) zp += sz;
return clipboard.getFullBlock(BlockVector3.at(min.getX() + xp, min.getY() + yp, min.getZ() + zp));
/**
* Create a new clipboard pattern.
*
* @param clipboard the clipboard
* @param offset the offset
*/
public ClipboardPattern(Clipboard clipboard, BlockVector3 offset) {
super(clipboard, clipboard.getMinimumPoint(), offset);
}
}
}

View File

@ -0,0 +1,66 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.function.pattern;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.extent.buffer.ExtentBuffer;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BaseBlock;
import static com.google.common.base.Preconditions.checkArgument;
/**
* A pattern that composes multiple patterns consecutively, ensuring that changes from one
* pattern are realized by the subsequent one(s). For best results, use an {@link ExtentBuffer}
* to avoid changing blocks in an underlying extent (e.g. the world).
*/
public class ExtentBufferedCompositePattern extends AbstractExtentPattern {
private final Pattern[] patterns;
/**
* Construct a new instance of this pattern.
*
* <p>Note that all patterns passed which are ExtentPatterns should use the same extent as the one
* passed to this constructor, or block changes may not be realized by those patterns.</p>
*
* @param extent the extent to buffer changes to
* @param patterns the patterns to apply, in order
*/
public ExtentBufferedCompositePattern(Extent extent, Pattern... patterns) {
super(extent);
checkArgument(patterns.length != 0, "patterns cannot be empty");
this.patterns = patterns;
}
@Override
public BaseBlock apply(BlockVector3 position) {
BaseBlock lastBlock = null;
for (Pattern pattern : patterns) {
lastBlock = pattern.apply(position);
try {
getExtent().setBlock(position, lastBlock);
} catch (WorldEditException ignored) { // buffer doesn't throw
}
}
return lastBlock;
}
}

View File

@ -0,0 +1,32 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.function.pattern;
import com.sk89q.worldedit.extent.Extent;
public interface ExtentPattern extends Pattern {
/**
* Get the extent associated with this pattern.
*
* @return the extent for this pattern
*/
public Extent getExtent();
}

View File

@ -19,14 +19,6 @@
package com.sk89q.worldedit.function.pattern;
import com.sk89q.minecraft.util.commands.Link;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.command.UtilityCommands;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.extent.NullExtent;
import com.sk89q.worldedit.internal.expression.runtime.Return;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockStateHolder;

View File

@ -12,12 +12,6 @@ import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BaseBlock;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import static com.google.common.base.Preconditions.checkNotNull;
/**

View File

@ -0,0 +1,45 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.function.pattern;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.FuzzyBlockState;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;
public class RandomStatePattern implements Pattern {
private final Random rand = new Random();
private final List<BaseBlock> blocks;
public RandomStatePattern(FuzzyBlockState state) {
blocks = state.getBlockType().getAllStates().stream().filter(state::equalsFuzzy)
.map(BlockState::toBaseBlock).collect(Collectors.toList());
}
@Override
public BaseBlock apply(BlockVector3 position) {
return blocks.get(rand.nextInt(blocks.size()));
}
}

View File

@ -28,9 +28,10 @@ import com.sk89q.worldedit.world.block.BaseBlock;
/**
* Returns the blocks from {@link Extent}, repeating when out of bounds.
*/
public class RepeatingExtentPattern extends AbstractPattern {
public class RepeatingExtentPattern extends AbstractExtentPattern {
private Extent extent;
private final BlockVector3 size;
private BlockVector3 origin;
private BlockVector3 offset;
/**
@ -39,28 +40,11 @@ public class RepeatingExtentPattern extends AbstractPattern {
* @param extent the extent
* @param offset the offset
*/
public RepeatingExtentPattern(Extent extent, BlockVector3 offset) {
setExtent(extent);
public RepeatingExtentPattern(Extent extent, BlockVector3 origin, BlockVector3 offset) {
super(extent);
setOrigin(origin);
setOffset(offset);
}
/**
* Get the extent.
*
* @return the extent
*/
public Extent getExtent() {
return extent;
}
/**
* Set the extent.
*
* @param extent the extent
*/
public void setExtent(Extent extent) {
checkNotNull(extent);
this.extent = extent;
size = extent.getMaximumPoint().subtract(extent.getMinimumPoint()).add(1, 1, 1);
}
/**
@ -82,13 +66,31 @@ public class RepeatingExtentPattern extends AbstractPattern {
this.offset = offset;
}
/**
* Get the origin.
*
* @return the origin
*/
public BlockVector3 getOrigin() {
return origin;
}
/**
* Set the origin.
*
* @param origin the origin
*/
public void setOrigin(BlockVector3 origin) {
checkNotNull(origin);
this.origin = origin;
}
@Override
public BaseBlock apply(BlockVector3 position) {
BlockVector3 base = position.add(offset);
BlockVector3 size = extent.getMaximumPoint().subtract(extent.getMinimumPoint()).add(1, 1, 1);
int x = base.getBlockX() % size.getBlockX();
int y = base.getBlockY() % size.getBlockY();
int z = base.getBlockZ() % size.getBlockZ();
return extent.getFullBlock(BlockVector3.at(x, y, z));
int x = Math.abs(base.getBlockX()) % size.getBlockX();
int y = Math.abs(base.getBlockY()) % size.getBlockY();
int z = Math.abs(base.getBlockZ()) % size.getBlockZ();
return getExtent().getFullBlock(BlockVector3.at(x, y, z).add(origin));
}
}

View File

@ -0,0 +1,54 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.function.pattern;
import com.google.common.collect.Maps;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockType;
import java.util.Map;
import java.util.Map.Entry;
import static com.sk89q.worldedit.blocks.Blocks.resolveProperties;
public class StateApplyingPattern extends AbstractExtentPattern {
private final Map<String, String> states;
private Map<BlockType, Map<Property<Object>, Object>> cache = Maps.newHashMap();
public StateApplyingPattern(Extent extent, Map<String, String> statesToSet) {
super(extent);
this.states = statesToSet;
}
@Override
public BaseBlock apply(BlockVector3 position) {
BlockState block = getExtent().getBlock(position);
for (Entry<Property<Object>, Object> entry : cache
.computeIfAbsent(block.getBlockType(), (b -> resolveProperties(states, b))).entrySet()) {
block = block.with(entry.getKey(), entry.getValue());
}
return block.toBaseBlock();
}
}

View File

@ -0,0 +1,52 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.function.pattern;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import java.util.Map.Entry;
/**
* Applies a block type while retaining all possible states.
*/
public class TypeApplyingPattern extends AbstractExtentPattern {
private final BlockState blockState;
public TypeApplyingPattern(Extent extent, BlockState blockState) {
super(extent);
this.blockState = blockState;
}
@Override
public BaseBlock apply(BlockVector3 position) {
BlockState oldBlock = getExtent().getBlock(position);
BlockState newBlock = blockState;
for (Entry<Property<?>, Object> entry : oldBlock.getStates().entrySet()) {
@SuppressWarnings("unchecked")
Property<Object> prop = (Property<Object>) entry.getKey();
newBlock = newBlock.with(prop, entry.getValue());
}
return newBlock.toBaseBlock();
}
}

View File

@ -0,0 +1,47 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.function.pattern;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockTypes;
/**
* Removes the waterlogged state from blocks if possible. If not possible, returns air.
*/
public class WaterloggedRemover extends AbstractExtentPattern {
public WaterloggedRemover(Extent extent) {
super(extent);
}
@Override
public BaseBlock apply(BlockVector3 position) {
BaseBlock block = getExtent().getFullBlock(position);
@SuppressWarnings("unchecked")
Property<Object> prop = (Property<Object>) block.getBlockType().getPropertyMap().getOrDefault("waterlogged", null);
if (prop != null) {
return block.with(prop, false);
}
return BlockTypes.AIR.getDefaultState().toBaseBlock();
}
}