mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-02 19:36:41 +00:00
Copy paste/merge FAWE classes to this WorldEdit fork
- so certain people can look at the diff and complain about my sloppy code :( Signed-off-by: Jesse Boyd <jessepaleg@gmail.com>
This commit is contained in:
@ -1,26 +1,12 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* An abstract implementation for {@link Pattern}s.
|
||||
*/
|
||||
public abstract class AbstractPattern implements Pattern {
|
||||
import java.io.Serializable;
|
||||
|
||||
public abstract class AbstractPattern implements Pattern, Serializable {
|
||||
public AbstractPattern() {
|
||||
}
|
||||
|
||||
public static Class<?> inject() {
|
||||
return AbstractPattern.class;
|
||||
}
|
||||
}
|
||||
|
@ -1,44 +1,30 @@
|
||||
/*
|
||||
* 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.boydti.fawe.FaweCache;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
|
||||
/**
|
||||
* A pattern that returns the same {@link BaseBlock} each time.
|
||||
* @deprecated Just use BaseBlock directly
|
||||
*/
|
||||
public class BlockPattern extends AbstractPattern {
|
||||
@Deprecated
|
||||
public class BlockPattern implements Pattern {
|
||||
|
||||
private BlockStateHolder block;
|
||||
|
||||
/**
|
||||
* Create a new pattern with the given block.
|
||||
*
|
||||
* @param block the block
|
||||
*/
|
||||
public BlockPattern(BlockStateHolder block) {
|
||||
setBlock(block);
|
||||
this.block = block;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockStateHolder apply(Vector position) {
|
||||
return block;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -60,9 +46,7 @@ public class BlockPattern extends AbstractPattern {
|
||||
this.block = block;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockStateHolder apply(Vector position) {
|
||||
return block;
|
||||
public static Class<BlockPattern> inject() {
|
||||
return BlockPattern.class;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,37 +1,24 @@
|
||||
/*
|
||||
* 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 static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldedit.MutableBlockVector;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
|
||||
|
||||
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 Vector size;
|
||||
private final int sx, sy, sz;
|
||||
private final Vector min;
|
||||
private MutableBlockVector mutable = new MutableBlockVector();
|
||||
|
||||
/**
|
||||
* Create a new clipboard pattern.
|
||||
@ -41,16 +28,28 @@ public class ClipboardPattern extends AbstractPattern {
|
||||
public ClipboardPattern(Clipboard clipboard) {
|
||||
checkNotNull(clipboard);
|
||||
this.clipboard = clipboard;
|
||||
this.size = clipboard.getMaximumPoint().subtract(clipboard.getMinimumPoint()).add(1, 1, 1);
|
||||
Vector 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();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockStateHolder apply(Vector position) {
|
||||
int xp = Math.abs(position.getBlockX()) % size.getBlockX();
|
||||
int yp = Math.abs(position.getBlockY()) % size.getBlockY();
|
||||
int zp = Math.abs(position.getBlockZ()) % size.getBlockZ();
|
||||
|
||||
return clipboard.getFullBlock(clipboard.getMinimumPoint().add(new Vector(xp, yp, zp)));
|
||||
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;
|
||||
mutable.mutX((min.getX() + xp));
|
||||
mutable.mutY((min.getY() + yp));
|
||||
mutable.mutZ((min.getZ() + zp));
|
||||
return clipboard.getBlock(mutable);
|
||||
}
|
||||
|
||||
}
|
||||
public static Class<?> inject() {
|
||||
return ClipboardPattern.class;
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package com.sk89q.worldedit.function.pattern;
|
||||
|
||||
import com.sk89q.minecraft.util.commands.Link;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.command.UtilityCommands;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.extent.NullExtent;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
|
||||
/**
|
||||
* Returns a {@link BlockStateHolder} for a given position.
|
||||
* - Adapts the vector apply to integer
|
||||
*/
|
||||
@Link(clazz = UtilityCommands.class, value = "patterns")
|
||||
public interface FawePattern extends Pattern {
|
||||
|
||||
@Deprecated
|
||||
default BlockStateHolder apply(Vector position) {
|
||||
throw new UnsupportedOperationException("Please use apply(extent, get, set)");
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a {@link BlockStateHolder} for the given position.
|
||||
*
|
||||
* @return a block
|
||||
*/
|
||||
@Override
|
||||
boolean apply(Extent extent, Vector get, Vector set) throws WorldEditException;
|
||||
}
|
||||
|
@ -19,13 +19,36 @@
|
||||
|
||||
package com.sk89q.worldedit.function.pattern;
|
||||
|
||||
import com.sk89q.minecraft.util.commands.Link;
|
||||
import com.sk89q.worldedit.MutableBlockVector;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.blocks.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.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
|
||||
/**
|
||||
* Returns a {@link BlockStateHolder} for a given position.
|
||||
* @deprecated Use FawePattern
|
||||
*/
|
||||
public interface Pattern {
|
||||
@Link(clazz = UtilityCommands.class, value = "patterns")
|
||||
@Deprecated
|
||||
public interface Pattern extends com.sk89q.worldedit.patterns.Pattern{
|
||||
|
||||
@Override
|
||||
default BaseBlock next(Vector position) {
|
||||
return new BaseBlock(apply(position));
|
||||
}
|
||||
|
||||
@Override
|
||||
default BaseBlock next(int x, int y, int z) {
|
||||
return new BaseBlock(apply(new Vector(x, y, z)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a {@link BlockStateHolder} for the given position.
|
||||
@ -33,6 +56,10 @@ public interface Pattern {
|
||||
* @param position the position
|
||||
* @return a block
|
||||
*/
|
||||
@Deprecated
|
||||
BlockStateHolder apply(Vector position);
|
||||
|
||||
}
|
||||
default boolean apply(Extent extent, Vector get, Vector set) throws WorldEditException {
|
||||
return extent.setBlock(set, apply(get));
|
||||
}
|
||||
}
|
@ -1,88 +1,79 @@
|
||||
/*
|
||||
* 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 static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.boydti.fawe.object.collection.RandomCollection;
|
||||
import com.boydti.fawe.object.random.SimpleRandom;
|
||||
import com.boydti.fawe.object.random.TrueRandom;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Uses a random pattern of a weighted list of patterns.
|
||||
*/
|
||||
public class RandomPattern extends AbstractPattern {
|
||||
|
||||
private final Random random = new Random();
|
||||
private List<Chance> patterns = new ArrayList<>();
|
||||
private double max = 0;
|
||||
private final SimpleRandom random;
|
||||
private Map<Pattern, Double> weights = new HashMap<>();
|
||||
private RandomCollection<Pattern> collection;
|
||||
private LinkedHashSet<Pattern> patterns = new LinkedHashSet<>();
|
||||
|
||||
public RandomPattern() {
|
||||
this(new TrueRandom());
|
||||
}
|
||||
|
||||
public RandomPattern(SimpleRandom random) {
|
||||
this.random = random;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a pattern to the weight list of patterns.
|
||||
*
|
||||
* <p>
|
||||
* <p>The probability for the pattern added is chance / max where max is
|
||||
* the sum of the probabilities of all added patterns.</p>
|
||||
*
|
||||
* @param pattern the pattern
|
||||
* @param chance the chance, which can be any positive number
|
||||
* @param chance the chance, which can be any positive number
|
||||
*/
|
||||
public void add(Pattern pattern, double chance) {
|
||||
checkNotNull(pattern);
|
||||
patterns.add(new Chance(pattern, chance));
|
||||
max += chance;
|
||||
Double existingWeight = weights.get(pattern);
|
||||
if (existingWeight != null) chance += existingWeight;
|
||||
weights.put(pattern, chance);
|
||||
collection = RandomCollection.of(weights, random);
|
||||
this.patterns.add(pattern);
|
||||
}
|
||||
|
||||
public Set<Pattern> getPatterns() {
|
||||
return patterns;
|
||||
}
|
||||
|
||||
public RandomCollection<Pattern> getCollection() {
|
||||
return collection;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockStateHolder apply(Vector position) {
|
||||
double r = random.nextDouble();
|
||||
double offset = 0;
|
||||
|
||||
for (Chance chance : patterns) {
|
||||
if (r <= (offset + chance.getChance()) / max) {
|
||||
return chance.getPattern().apply(position);
|
||||
}
|
||||
offset += chance.getChance();
|
||||
}
|
||||
|
||||
throw new RuntimeException("ProportionalFillPattern");
|
||||
public BlockStateHolder apply(Vector get) {
|
||||
return collection.next(get.getBlockX(), get.getBlockY(), get.getBlockZ()).apply(get);
|
||||
}
|
||||
|
||||
private static class Chance {
|
||||
private Pattern pattern;
|
||||
private double chance;
|
||||
|
||||
private Chance(Pattern pattern, double chance) {
|
||||
this.pattern = pattern;
|
||||
this.chance = chance;
|
||||
}
|
||||
|
||||
public Pattern getPattern() {
|
||||
return pattern;
|
||||
}
|
||||
|
||||
public double getChance() {
|
||||
return chance;
|
||||
}
|
||||
@Override
|
||||
public boolean apply(Extent extent, Vector set, Vector get) throws WorldEditException {
|
||||
return collection.next(get.getBlockX(), get.getBlockY(), get.getBlockZ()).apply(extent, set, get);
|
||||
}
|
||||
|
||||
}
|
||||
public static Class<?> inject() {
|
||||
return RandomPattern.class;
|
||||
}
|
||||
|
||||
}
|
@ -19,11 +19,12 @@
|
||||
|
||||
package com.sk89q.worldedit.function.pattern;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Returns the blocks from {@link Extent}, repeating when out of bounds.
|
||||
@ -89,7 +90,6 @@ public class RepeatingExtentPattern extends AbstractPattern {
|
||||
int x = base.getBlockX() % size.getBlockX();
|
||||
int y = base.getBlockY() % size.getBlockY();
|
||||
int z = base.getBlockZ() % size.getBlockZ();
|
||||
return extent.getFullBlock(new Vector(x, y, z));
|
||||
return extent.getBlock(new Vector(x, y, z));
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user