3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-11-03 01:50:07 +01:00

Use default state a bit more.

Dieser Commit ist enthalten in:
Matthew Miller 2018-06-19 11:55:35 +10:00
Ursprung 282eca7663
Commit 70aceb3837
16 geänderte Dateien mit 59 neuen und 54 gelöschten Zeilen

Datei anzeigen

@ -688,7 +688,7 @@ public class EditSession implements Extent {
getWorld(), // Causes clamping of Y range
position.add(-apothem + 1, 0, -apothem + 1),
position.add(apothem - 1, height - 1, apothem - 1));
Pattern pattern = new BlockPattern(new BaseBlock(BlockTypes.AIR));
Pattern pattern = new BlockPattern(BlockTypes.AIR.getDefaultState());
return setBlocks(region, pattern);
}
@ -710,7 +710,7 @@ public class EditSession implements Extent {
getWorld(), // Causes clamping of Y range
position.add(-apothem + 1, 0, -apothem + 1),
position.add(apothem - 1, -height + 1, apothem - 1));
Pattern pattern = new BlockPattern(new BaseBlock(BlockTypes.AIR));
Pattern pattern = new BlockPattern(BlockTypes.AIR.getDefaultState());
return setBlocks(region, pattern);
}
@ -723,17 +723,17 @@ public class EditSession implements Extent {
* @return number of blocks affected
* @throws MaxChangedBlocksException thrown if too many blocks are changed
*/
public int removeNear(Vector position, int blockType, int apothem) throws MaxChangedBlocksException {
public int removeNear(Vector position, com.sk89q.worldedit.blocks.type.BlockType blockType, int apothem) throws MaxChangedBlocksException {
checkNotNull(position);
checkArgument(apothem >= 1, "apothem >= 1");
Mask mask = new FuzzyBlockMask(this, new BaseBlock(blockType, -1));
Mask mask = new FuzzyBlockMask(this, blockType.getDefaultState().toFuzzy());
Vector adjustment = new Vector(1, 1, 1).multiply(apothem - 1);
Region region = new CuboidRegion(
getWorld(), // Causes clamping of Y range
position.add(adjustment.multiply(-1)),
position.add(adjustment));
Pattern pattern = new BlockPattern(new BaseBlock(BlockTypes.AIR));
Pattern pattern = new BlockPattern(BlockTypes.AIR.getDefaultState());
return replaceBlocks(region, mask, pattern);
}
@ -1059,7 +1059,7 @@ public class EditSession implements Extent {
// Remove the original blocks
com.sk89q.worldedit.function.pattern.Pattern pattern = replacement != null ?
new BlockPattern(replacement) :
new BlockPattern(new BaseBlock(BlockTypes.AIR));
new BlockPattern(BlockTypes.AIR.getDefaultState());
BlockReplace remove = new BlockReplace(this, pattern);
// Copy to a buffer so we don't destroy our original before we can copy all the blocks from it
@ -1146,15 +1146,15 @@ public class EditSession implements Extent {
// Our origins can only be liquids
BlockMask liquidMask = new BlockMask(
this,
new BaseBlock(moving),
new BaseBlock(stationary));
moving.getDefaultState(),
stationary.getDefaultState());
// But we will also visit air blocks
MaskIntersection blockMask =
new MaskUnion(liquidMask,
new BlockMask(
this,
new BaseBlock(BlockTypes.AIR)));
BlockTypes.AIR.getDefaultState()));
// There are boundaries that the routine needs to stay in
MaskIntersection mask = new MaskIntersection(
@ -1162,7 +1162,7 @@ public class EditSession implements Extent {
new RegionMask(new EllipsoidRegion(null, origin, new Vector(radius, radius, radius))),
blockMask);
BlockReplace replace = new BlockReplace(this, new BlockPattern(new BaseBlock(stationary)));
BlockReplace replace = new BlockReplace(this, new BlockPattern(stationary.getDefaultState()));
NonRisingVisitor visitor = new NonRisingVisitor(mask, replace);
// Around the origin in a 3x3 block
@ -1433,8 +1433,8 @@ public class EditSession implements Extent {
int oy = position.getBlockY();
int oz = position.getBlockZ();
BaseBlock air = new BaseBlock(BlockTypes.AIR);
BaseBlock water = new BaseBlock(BlockTypes.WATER);
BlockState air = BlockTypes.AIR.getDefaultState();
BlockState water = BlockTypes.WATER.getDefaultState();
int ceilRadius = (int) Math.ceil(radius);
for (int x = ox - ceilRadius; x <= ox + ceilRadius; ++x) {
@ -1483,8 +1483,8 @@ public class EditSession implements Extent {
int oy = position.getBlockY();
int oz = position.getBlockZ();
BaseBlock ice = new BaseBlock(BlockTypes.ICE);
BaseBlock snow = new BaseBlock(BlockTypes.SNOW);
BlockState ice = BlockTypes.ICE.getDefaultState();
BlockState snow = BlockTypes.SNOW.getDefaultState();
int ceilRadius = (int) Math.ceil(radius);
for (int x = ox - ceilRadius; x <= ox + ceilRadius; ++x) {
@ -1659,7 +1659,7 @@ public class EditSession implements Extent {
++affected;
break;
} else if (t == BlockTypes.SNOW) {
setBlock(new Vector(x, y, z), new BaseBlock(BlockTypes.AIR));
setBlock(new Vector(x, y, z), BlockTypes.AIR.getDefaultState());
} else if (t != BlockTypes.AIR) { // Trees won't grow on this!
break;
}

Datei anzeigen

@ -110,6 +110,10 @@ public class BlockState implements BlockStateHolder<BlockState> {
return Collections.unmodifiableMap(this.values);
}
public BlockState toFuzzy() {
return new BlockState(this.getBlockType(), new HashMap<>());
}
@Override
public boolean equalsFuzzy(BlockStateHolder o) {
if (!getBlockType().equals(o.getBlockType())) {

Datei anzeigen

@ -19,6 +19,8 @@
package com.sk89q.worldedit.command;
import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.minecraft.util.commands.Command;
import com.sk89q.minecraft.util.commands.CommandContext;
import com.sk89q.minecraft.util.commands.CommandPermissions;
@ -28,7 +30,6 @@ import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.type.BlockTypes;
import com.sk89q.worldedit.command.tool.BrushTool;
import com.sk89q.worldedit.command.tool.brush.ButcherBrush;
@ -50,8 +51,6 @@ import com.sk89q.worldedit.util.HandSide;
import com.sk89q.worldedit.util.command.binding.Switch;
import com.sk89q.worldedit.util.command.parametric.Optional;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Commands to set brush shape.
*/
@ -194,10 +193,10 @@ public class BrushCommands {
worldEdit.checkMaxBrushRadius(radius);
BrushTool tool = session.getBrushTool(player.getItemInHand(HandSide.MAIN_HAND).getType());
Pattern fill = new BlockPattern(new BaseBlock(BlockTypes.AIR));
Pattern fill = new BlockPattern(BlockTypes.AIR.getDefaultState());
tool.setFill(fill);
tool.setSize(radius);
tool.setMask(new BlockMask(editSession, new BaseBlock(BlockTypes.FIRE)));
tool.setMask(new BlockMask(editSession, BlockTypes.FIRE.getDefaultState().toFuzzy()));
tool.setBrush(new SphereBrush(), "worldedit.brush.ex");
player.print(String.format("Extinguisher equipped (%.0f).", radius));

Datei anzeigen

@ -261,7 +261,7 @@ public class UtilityCommands {
int size = Math.max(1, args.getInteger(1, 50));
we.checkMaxRadius(size);
int affected = editSession.removeNear(session.getPlacementPosition(player), block.getBlockType().getLegacyId(), size);
int affected = editSession.removeNear(session.getPlacementPosition(player), block.getBlockType(), size);
player.print(affected + " block(s) have been removed.");
}
@ -381,7 +381,7 @@ public class UtilityCommands {
: defaultRadius;
we.checkMaxRadius(size);
int affected = editSession.removeNear(session.getPlacementPosition(player), 51, size);
int affected = editSession.removeNear(session.getPlacementPosition(player), BlockTypes.FIRE, size);
player.print(affected + " block(s) have been removed.");
}

Datei anzeigen

@ -21,6 +21,7 @@ package com.sk89q.worldedit.command.tool;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.type.BlockState;
import com.sk89q.worldedit.blocks.type.BlockType;
import com.sk89q.worldedit.blocks.type.BlockTypes;
import com.sk89q.worldedit.entity.Player;
@ -37,7 +38,7 @@ import java.util.Set;
*/
public class RecursivePickaxe implements BlockTool {
private static final BaseBlock air = new BaseBlock(BlockTypes.AIR);
private static final BlockState air = BlockTypes.AIR.getDefaultState();
private double range;
public RecursivePickaxe(double range) {

Datei anzeigen

@ -54,7 +54,7 @@ public class SinglePickaxe implements BlockTool {
editSession.getSurvivalExtent().setToolUse(config.superPickaxeDrop);
try {
editSession.setBlock(clicked.toVector(), new BaseBlock(BlockTypes.AIR));
editSession.setBlock(clicked.toVector(), BlockTypes.AIR.getDefaultState());
} catch (MaxChangedBlocksException e) {
player.printError("Max blocks change limit reached.");
} finally {

Datei anzeigen

@ -38,7 +38,7 @@ public class CylinderBrush implements Brush {
@Override
public void build(EditSession editSession, Vector position, Pattern pattern, double size) throws MaxChangedBlocksException {
if (pattern == null) {
pattern = new BlockPattern(new BaseBlock(BlockTypes.COBBLESTONE));
pattern = new BlockPattern(BlockTypes.COBBLESTONE.getDefaultState());
}
editSession.makeCylinder(position, pattern, size, size, height, true);
}

Datei anzeigen

@ -299,7 +299,7 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
@Override
public void floatAt(int x, int y, int z, boolean alwaysGlass) {
try {
getLocation().getExtent().setBlock(new Vector(x, y - 1, z), new BaseBlock(BlockTypes.GLASS));
getLocation().getExtent().setBlock(new Vector(x, y - 1, z), BlockTypes.GLASS.getDefaultState());
} catch (WorldEditException e) {
e.printStackTrace();
}

Datei anzeigen

@ -55,12 +55,12 @@ public class BlockQuirkExtent extends AbstractDelegateExtent {
@Override
public boolean setBlock(Vector position, BlockStateHolder block) throws WorldEditException {
BaseBlock lazyBlock = getExtent().getLazyBlock(position);
int existing = lazyBlock.getBlockType().getLegacyId();
com.sk89q.worldedit.blocks.type.BlockType existing = lazyBlock.getBlockType();
if (BlockType.isContainerBlock(existing)) {
if (BlockType.isContainerBlock(existing.getLegacyId())) {
world.clearContainerBlockContents(position); // Clear the container block so that it doesn't drop items
} else if (existing == BlockID.ICE) {
world.setBlock(position, new BaseBlock(BlockTypes.AIR)); // Ice turns until water so this has to be done first
} else if (existing == BlockTypes.ICE) {
world.setBlock(position, BlockTypes.AIR.getDefaultState()); // Ice turns until water so this has to be done first
}
return super.setBlock(position, block);

Datei anzeigen

@ -24,6 +24,7 @@ import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.type.BlockState;
import com.sk89q.worldedit.blocks.type.BlockTypes;
import com.sk89q.worldedit.function.LayerFunction;
import com.sk89q.worldedit.function.mask.BlockMask;
@ -38,9 +39,9 @@ import static com.google.common.base.Preconditions.checkNotNull;
*/
public class Naturalizer implements LayerFunction {
private static final BaseBlock grass = new BaseBlock(BlockTypes.GRASS_BLOCK);
private static final BaseBlock dirt = new BaseBlock(BlockTypes.DIRT);
private static final BaseBlock stone = new BaseBlock(BlockTypes.STONE);
private static final BlockState grass = BlockTypes.GRASS_BLOCK.getDefaultState();
private static final BlockState dirt = BlockTypes.DIRT.getDefaultState();
private static final BlockState stone = BlockTypes.STONE.getDefaultState();
private final EditSession editSession;
private final Mask mask;

Datei anzeigen

@ -22,7 +22,6 @@ package com.sk89q.worldedit.function.generator;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.type.BlockStateHolder;
import com.sk89q.worldedit.blocks.type.BlockTypes;
import com.sk89q.worldedit.function.RegionFunction;
@ -84,9 +83,9 @@ public class FloraGenerator implements RegionFunction {
*/
public static Pattern getDesertPattern() {
RandomPattern pattern = new RandomPattern();
pattern.add(new BlockPattern(new BaseBlock(BlockTypes.DEAD_BUSH)), 30);
pattern.add(new BlockPattern(new BaseBlock(BlockTypes.CACTUS)), 20);
pattern.add(new BlockPattern(new BaseBlock(BlockTypes.AIR)), 300);
pattern.add(new BlockPattern(BlockTypes.DEAD_BUSH.getDefaultState()), 30);
pattern.add(new BlockPattern(BlockTypes.CACTUS.getDefaultState()), 20);
pattern.add(new BlockPattern(BlockTypes.AIR.getDefaultState()), 300);
return pattern;
}
@ -97,9 +96,9 @@ public class FloraGenerator implements RegionFunction {
*/
public static Pattern getTemperatePattern() {
RandomPattern pattern = new RandomPattern();
pattern.add(new BlockPattern(new BaseBlock(BlockTypes.GRASS)), 300);
pattern.add(new BlockPattern(new BaseBlock(BlockTypes.POPPY)), 5);
pattern.add(new BlockPattern(new BaseBlock(BlockTypes.DANDELION)), 5);
pattern.add(new BlockPattern(BlockTypes.GRASS.getDefaultState()), 300);
pattern.add(new BlockPattern(BlockTypes.POPPY.getDefaultState()), 5);
pattern.add(new BlockPattern(BlockTypes.DANDELION.getDefaultState()), 5);
return pattern;
}

Datei anzeigen

@ -58,11 +58,11 @@ public class ForestGenerator implements RegionFunction {
treeGenerator.generate(editSession, position.add(0, 1, 0));
return true;
} else if (t == BlockTypes.TALL_GRASS || t == BlockTypes.DEAD_BUSH || t == BlockTypes.POPPY || t == BlockTypes.DANDELION) { // TODO: This list needs to be moved
editSession.setBlock(position, new BaseBlock(BlockTypes.AIR));
editSession.setBlock(position, BlockTypes.AIR.getDefaultState());
treeGenerator.generate(editSession, position);
return true;
} else if (t == BlockTypes.SNOW) {
editSession.setBlock(position, new BaseBlock(BlockTypes.AIR));
editSession.setBlock(position, BlockTypes.AIR.getDefaultState());
return false;
} else { // Trees won't grow on this!
return false;

Datei anzeigen

@ -214,6 +214,6 @@ public class GardenPatchGenerator implements RegionFunction {
* @return a melon pattern
*/
public static Pattern getMelonPattern() {
return new BlockPattern(new BaseBlock(BlockTypes.MELON_BLOCK));
return new BlockPattern(BlockTypes.MELON_BLOCK.getDefaultState());
}
}

Datei anzeigen

@ -19,16 +19,15 @@
package com.sk89q.worldedit.math.convolution;
import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.type.BlockState;
import com.sk89q.worldedit.blocks.type.BlockTypes;
import com.sk89q.worldedit.regions.Region;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Allows applications of Kernels onto the region's height map.
*
@ -123,7 +122,7 @@ public class HeightMap {
int originZ = minY.getBlockZ();
int maxY = region.getMaximumPoint().getBlockY();
BaseBlock fillerAir = new BaseBlock(BlockTypes.AIR);
BlockState fillerAir = BlockTypes.AIR.getDefaultState();
int blocksChanged = 0;

Datei anzeigen

@ -23,10 +23,10 @@ import com.google.common.collect.Sets;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.type.BlockState;
import com.sk89q.worldedit.blocks.type.BlockStateHolder;
import com.sk89q.worldedit.blocks.type.BlockTypes;
import javax.annotation.Nullable;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap;
@ -34,6 +34,8 @@ import java.util.Map;
import java.util.Random;
import java.util.Set;
import javax.annotation.Nullable;
/**
* Tree generator.
*/
@ -198,8 +200,8 @@ public class TreeGenerator {
int trunkHeight = (int) Math.floor(Math.random() * 2) + 3;
int height = (int) Math.floor(Math.random() * 5) + 8;
BaseBlock logBlock = new BaseBlock(BlockTypes.OAK_LOG);
BaseBlock leavesBlock = new BaseBlock(BlockTypes.OAK_LEAVES);
BlockState logBlock = BlockTypes.OAK_LOG.getDefaultState();
BlockState leavesBlock = BlockTypes.OAK_LEAVES.getDefaultState();
// Create trunk
for (int i = 0; i < trunkHeight; ++i) {
@ -269,7 +271,7 @@ public class TreeGenerator {
* @return whether a block was changed
* @throws MaxChangedBlocksException thrown if too many blocks are changed
*/
private static boolean setChanceBlockIfAir(EditSession session, Vector position, BaseBlock block, double probability)
private static boolean setChanceBlockIfAir(EditSession session, Vector position, BlockStateHolder block, double probability)
throws MaxChangedBlocksException {
return Math.random() <= probability && setBlockIfAir(session, position, block);
}
@ -282,7 +284,7 @@ public class TreeGenerator {
* @return if block was changed
* @throws MaxChangedBlocksException thrown if too many blocks are changed
*/
private static boolean setBlockIfAir(EditSession session, Vector position, BaseBlock block) throws MaxChangedBlocksException {
private static boolean setBlockIfAir(EditSession session, Vector position, BlockStateHolder block) throws MaxChangedBlocksException {
return session.getBlock(position).getBlockType() == BlockTypes.AIR && session.setBlock(position, block);
}
}

Datei anzeigen

@ -94,7 +94,7 @@ public abstract class AbstractWorld implements World {
}
try {
setBlock(pt, new BaseBlock(BlockTypes.AIR));
setBlock(pt, BlockTypes.AIR.getDefaultState());
} catch (WorldEditException e) {
throw new RuntimeException(e);
}