mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-06 20:56:41 +00:00
wip upstream merge
This commit is contained in:
@ -1409,23 +1409,23 @@ public class LocalSession implements TextureHolder {
|
||||
this.fastMode = fastMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the reorder mode of the session.
|
||||
*
|
||||
* @return The reorder mode
|
||||
*/
|
||||
public EditSession.ReorderMode getReorderMode() {
|
||||
return reorderMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the reorder mode of the session.
|
||||
*
|
||||
* @param reorderMode The reorder mode
|
||||
*/
|
||||
public void setReorderMode(EditSession.ReorderMode reorderMode) {
|
||||
this.reorderMode = reorderMode;
|
||||
}
|
||||
// /**
|
||||
// * Gets the reorder mode of the session.
|
||||
// *
|
||||
// * @return The reorder mode
|
||||
// */
|
||||
// public EditSession.ReorderMode getReorderMode() {
|
||||
// return reorderMode;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Sets the reorder mode of the session.
|
||||
// *
|
||||
// * @param reorderMode The reorder mode
|
||||
// */
|
||||
// public void setReorderMode(EditSession.ReorderMode reorderMode) {
|
||||
// this.reorderMode = reorderMode;
|
||||
// }
|
||||
|
||||
/**
|
||||
* Get the mask.
|
||||
|
@ -37,6 +37,9 @@ import com.sk89q.worldedit.extension.platform.PlatformManager;
|
||||
import com.sk89q.worldedit.extent.inventory.BlockBag;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.internal.expression.Expression;
|
||||
import com.sk89q.worldedit.internal.expression.runtime.Constant;
|
||||
import com.sk89q.worldedit.internal.expression.runtime.RValue;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.scripting.CraftScriptContext;
|
||||
import com.sk89q.worldedit.scripting.CraftScriptEngine;
|
||||
@ -73,8 +76,6 @@ import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static com.sk89q.worldedit.event.platform.Interaction.HIT;
|
||||
import static com.sk89q.worldedit.event.platform.Interaction.OPEN;
|
||||
|
@ -56,6 +56,7 @@ import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.biome.BiomeData;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.biome.BiomeTypes;
|
||||
import com.sk89q.worldedit.world.registry.BiomeRegistry;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -65,6 +66,8 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.sk89q.minecraft.util.commands.Logging.LogMode.REGION;
|
||||
|
||||
/**
|
||||
* Implements biome-related commands such as "/biomelist".
|
||||
*/
|
||||
@ -104,7 +107,7 @@ public class BiomeCommands extends MethodCommands {
|
||||
}
|
||||
|
||||
BiomeRegistry biomeRegistry = getBiomeRegistry();
|
||||
List<BiomeType> biomes = biomeRegistry.getBiomes();
|
||||
List<BiomeType> biomes = BiomeTypes.values();
|
||||
int totalPages = biomes.size() / 19 + 1;
|
||||
Message msg = BBC.BIOME_LIST_HEADER.m(page, totalPages);
|
||||
String setBiome = Commands.getAlias(BiomeCommands.class, "/setbiome");
|
||||
@ -141,7 +144,8 @@ public class BiomeCommands extends MethodCommands {
|
||||
@CommandPermissions("worldedit.biome.info")
|
||||
public void biomeInfo(Player player, LocalSession session, final EditSession editSession, CommandContext args) throws WorldEditException {
|
||||
BiomeRegistry biomeRegistry = getBiomeRegistry();
|
||||
final int[] biomes = new int[256];
|
||||
List<BiomeType> values = BiomeTypes.values();
|
||||
final int[] biomes = new int[values.size()];
|
||||
final String qualifier;
|
||||
|
||||
int size = 0;
|
||||
@ -165,14 +169,14 @@ public class BiomeCommands extends MethodCommands {
|
||||
|
||||
if (region instanceof FlatRegion) {
|
||||
for (BlockVector2 pt : new Fast2DIterator(((FlatRegion) region).asFlatRegion(), editSession)) {
|
||||
biomes[editSession.getBiome(pt).getId()]++;
|
||||
biomes[editSession.getBiome(pt).getInternalId()]++;
|
||||
size++;
|
||||
}
|
||||
} else {
|
||||
RegionVisitor visitor = new RegionVisitor(region, new RegionFunction() {
|
||||
@Override
|
||||
public boolean apply(BlockVector3 position) throws WorldEditException {
|
||||
biomes[editSession.getBiome(position.toBlockVector2()).getId()]++;
|
||||
biomes[editSession.getBiome(position.toBlockVector2()).getInternalId()]++;
|
||||
return true;
|
||||
}
|
||||
}, editSession);
|
||||
@ -187,7 +191,7 @@ public class BiomeCommands extends MethodCommands {
|
||||
for (int i = 0; i < biomes.length; i++) {
|
||||
int count = biomes[i];
|
||||
if (count != 0) {
|
||||
distribution.add(new Countable<>(new BiomeType(i), count));
|
||||
distribution.add(new Countable<>(BiomeTypes.get(i), count));
|
||||
}
|
||||
}
|
||||
Collections.sort(distribution);
|
||||
|
@ -25,6 +25,7 @@ import com.sk89q.minecraft.util.commands.Command;
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
||||
import com.sk89q.worldedit.*;
|
||||
import com.sk89q.worldedit.extension.input.DisallowedUsageException;
|
||||
import com.sk89q.worldedit.world.item.ItemType;
|
||||
import com.sk89q.worldedit.world.item.ItemTypes;
|
||||
import com.sk89q.worldedit.entity.Player;
|
||||
|
@ -54,7 +54,17 @@ import com.sk89q.worldedit.util.command.binding.Range;
|
||||
import com.sk89q.worldedit.util.command.binding.Switch;
|
||||
import com.sk89q.worldedit.util.command.binding.Text;
|
||||
import com.sk89q.worldedit.util.command.parametric.Optional;
|
||||
import com.sk89q.worldedit.util.command.parametric.ParameterException;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
|
||||
import static com.sk89q.minecraft.util.commands.Logging.LogMode.*;
|
||||
|
||||
|
||||
/**
|
||||
* Commands for the generation of shapes and other objects.
|
||||
@ -427,7 +437,8 @@ public class GenerationCommands extends MethodCommands {
|
||||
@Switch('h') boolean hollow,
|
||||
@Switch('r') boolean useRawCoords,
|
||||
@Switch('o') boolean offset,
|
||||
@Switch('c') boolean offsetCenter) throws WorldEditException {
|
||||
@Switch('c') boolean offsetCenter,
|
||||
CommandContext context) throws WorldEditException {
|
||||
final Vector3 zero;
|
||||
Vector3 unit;
|
||||
|
||||
|
@ -53,6 +53,7 @@ import com.sk89q.worldedit.function.visitor.LayerVisitor;
|
||||
import com.sk89q.worldedit.internal.annotation.Direction;
|
||||
import com.sk89q.worldedit.internal.annotation.Selection;
|
||||
import com.sk89q.worldedit.internal.expression.ExpressionException;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
import com.sk89q.worldedit.math.convolution.GaussianKernel;
|
||||
@ -66,6 +67,11 @@ import com.sk89q.worldedit.util.command.binding.Range;
|
||||
import com.sk89q.worldedit.util.command.binding.Switch;
|
||||
import com.sk89q.worldedit.util.command.binding.Text;
|
||||
import com.sk89q.worldedit.util.command.parametric.Optional;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.biome.BiomeTypes;
|
||||
import com.sk89q.worldedit.world.biome.Biomes;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.registry.BiomeRegistry;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
@ -704,7 +710,7 @@ public class RegionCommands extends MethodCommands {
|
||||
BiomeType biome = null;
|
||||
if (context.argsLength() >= 1) {
|
||||
BiomeRegistry biomeRegistry = worldEdit.getPlatformManager().queryCapability(Capability.GAME_HOOKS).getRegistries().getBiomeRegistry();
|
||||
List<BiomeType> knownBiomes = biomeRegistry.getBiomes();
|
||||
List<BiomeType> knownBiomes = BiomeTypes.values();
|
||||
biome = Biomes.findBiomeByName(knownBiomes, context.getString(0), biomeRegistry);
|
||||
}
|
||||
Long seed = context.argsLength() != 2 || !MathMan.isInteger(context.getString(1)) ? null : Long.parseLong(context.getString(1));
|
||||
|
@ -65,8 +65,10 @@ import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.nio.channels.Channels;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
import java.nio.file.Files;
|
||||
@ -79,6 +81,7 @@ import java.util.UUID;
|
||||
import java.util.concurrent.atomic.LongAdder;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static com.boydti.fawe.util.ReflectionUtils.as;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
@ -92,7 +95,6 @@ public class SchematicCommands extends MethodCommands {
|
||||
*/
|
||||
private static final int SCHEMATICS_PER_PAGE = 9;
|
||||
private static final Logger log = LoggerFactory.getLogger(SchematicCommands.class);
|
||||
private final WorldEdit worldEdit;
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
@ -279,7 +281,7 @@ public class SchematicCommands extends MethodCommands {
|
||||
player.printError("Unknown filename: " + filename);
|
||||
} catch (URISyntaxException | IOException e) {
|
||||
player.printError("File could not be read or it does not exist: " + e.getMessage());
|
||||
log.log(Level.WARNING, "Failed to load a saved clipboard", e);
|
||||
log.warn("Failed to load a saved clipboard", e);
|
||||
} finally {
|
||||
if (in != null) {
|
||||
try {
|
||||
|
@ -60,6 +60,7 @@ import com.sk89q.worldedit.regions.selector.RegionSelectorType;
|
||||
import com.sk89q.worldedit.regions.selector.SphereRegionSelector;
|
||||
import com.sk89q.worldedit.session.ClipboardHolder;
|
||||
import com.sk89q.worldedit.util.Countable;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import com.sk89q.worldedit.util.command.binding.Switch;
|
||||
import com.sk89q.worldedit.util.formatting.ColorCodeBuilder;
|
||||
import com.sk89q.worldedit.util.formatting.Style;
|
||||
@ -103,7 +104,7 @@ public class SelectionCommands {
|
||||
@CommandPermissions("worldedit.selection.pos")
|
||||
public void pos1(Player player, LocalSession session, CommandContext args) throws WorldEditException {
|
||||
|
||||
Location pos;
|
||||
BlockVector3 pos;
|
||||
|
||||
if (args.argsLength() == 1) {
|
||||
if (args.getString(0).matches("-?\\d+,-?\\d+,-?\\d+")) {
|
||||
@ -136,7 +137,7 @@ public class SelectionCommands {
|
||||
@CommandPermissions("worldedit.selection.pos")
|
||||
public void pos2(Player player, LocalSession session, CommandContext args) throws WorldEditException {
|
||||
|
||||
Location pos;
|
||||
BlockVector3 pos;
|
||||
if (args.argsLength() == 1) {
|
||||
if (args.getString(0).matches("-?\\d+,-?\\d+,-?\\d+")) {
|
||||
String[] coords = args.getString(0).split(",");
|
||||
@ -735,7 +736,7 @@ public class SelectionCommands {
|
||||
min = 0,
|
||||
max = 1
|
||||
)
|
||||
public void select(Player player, LocalSession session, CommandContext args) throws WorldEditException {
|
||||
public void select(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
|
||||
final World world = player.getWorld();
|
||||
if (args.argsLength() == 0) {
|
||||
session.getRegionSelector(world).clear();
|
||||
|
@ -27,6 +27,10 @@ import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||
import com.sk89q.worldedit.entity.Player;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.extension.platform.Platform;
|
||||
import com.sk89q.worldedit.function.mask.BlockMask;
|
||||
import com.sk89q.worldedit.function.operation.Operations;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.function.visitor.RecursiveVisitor;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.util.Direction;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
@ -70,7 +74,8 @@ public class FloatingTreeRemover implements BlockTool {
|
||||
Player player, LocalSession session, Location clicked) {
|
||||
|
||||
final World world = (World) clicked.getExtent();
|
||||
final BlockState state = world.getBlock(clicked.toBlockPoint());
|
||||
BlockVector3 pos = clicked.toBlockPoint();
|
||||
final BlockState state = world.getBlock(pos);
|
||||
|
||||
if (!isTreeBlock(state.getBlockType())) {
|
||||
player.printError("That's not a tree.");
|
||||
|
@ -21,14 +21,11 @@ package com.sk89q.worldedit.command.tool.brush;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.function.mask.Masks;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
|
||||
public class GravityBrush implements Brush {
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
package com.sk89q.worldedit.event.extent;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.event.Cancellable;
|
||||
import com.sk89q.worldedit.event.Event;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
|
@ -22,6 +22,7 @@ package com.sk89q.worldedit.extension.factory;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.factory.parser.pattern.BlockCategoryPatternParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.pattern.ClipboardPatternParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.pattern.DefaultPatternParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.pattern.RandomPatternParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.pattern.RandomStatePatternParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.pattern.SingleBlockPatternParser;
|
||||
|
@ -44,6 +44,7 @@ import com.sk89q.worldedit.command.composition.DeformCommand;
|
||||
import com.sk89q.worldedit.command.composition.PaintCommand;
|
||||
import com.sk89q.worldedit.command.composition.ShapedBrushCommand;
|
||||
import com.sk89q.worldedit.entity.Entity;
|
||||
import com.sk89q.worldedit.entity.Player;
|
||||
import com.sk89q.worldedit.event.platform.CommandEvent;
|
||||
import com.sk89q.worldedit.event.platform.CommandSuggestionEvent;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
@ -486,7 +487,7 @@ public final class CommandManager {
|
||||
actor.printError(BBC.getPrefix() + e.getMessage());
|
||||
} else {
|
||||
actor.printError(BBC.getPrefix() + "An unknown FAWE error has occurred! Please see console.");
|
||||
log.log(Level.SEVERE, "An unknown FAWE error occurred", e);
|
||||
log.error("An unknown FAWE error occurred", e);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
Exception faweException = FaweException.get(e);
|
||||
@ -496,7 +497,7 @@ public final class CommandManager {
|
||||
} else {
|
||||
actor.printError(BBC.getPrefix() + "There was an error handling a FAWE command: [See console]");
|
||||
actor.printRaw(e.getClass().getName() + ": " + e.getMessage());
|
||||
log.log(Level.SEVERE, "An unexpected error occurred while handling a FAWE command", e);
|
||||
log.error("An unexpected error occurred while handling a FAWE command", e);
|
||||
}
|
||||
} finally {
|
||||
final EditSession editSession = locals.get(EditSession.class);
|
||||
|
@ -36,6 +36,8 @@ import com.google.common.io.Files;
|
||||
import com.sk89q.worldedit.LocalConfiguration;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
@ -61,7 +61,7 @@ import javax.annotation.Nullable;
|
||||
*/
|
||||
public class BlockTransformExtent extends ResettableExtent {
|
||||
|
||||
private final Transform transform;
|
||||
private Transform transform;
|
||||
|
||||
|
||||
public BlockTransformExtent(Extent parent) {
|
||||
@ -138,9 +138,6 @@ public class BlockTransformExtent extends ResettableExtent {
|
||||
return super.setBlock(location, transformBlock(block, true));
|
||||
}
|
||||
|
||||
private static final Set<String> directionNames = Sets.newHashSet("north", "south", "east", "west");
|
||||
|
||||
|
||||
private static final Set<String> directionNames = Sets.newHashSet("north", "south", "east", "west");
|
||||
|
||||
/**
|
||||
|
@ -150,8 +150,7 @@ public class Deform implements Contextual<Operation> {
|
||||
}
|
||||
|
||||
LocalSession session = context.getSession();
|
||||
return new DeformOperation(context.getDestination(), region, zero, unit, expression,
|
||||
session == null ? WorldEdit.getInstance().getConfiguration().calculationTimeout : session.getTimeout());
|
||||
return new DeformOperation(context.getDestination(), region, zero, unit, expression);
|
||||
}
|
||||
|
||||
private static final class DeformOperation implements Operation {
|
||||
@ -160,7 +159,6 @@ public class Deform implements Contextual<Operation> {
|
||||
private final Vector3 zero;
|
||||
private final Vector3 unit;
|
||||
private final String expression;
|
||||
private final int timeout;
|
||||
|
||||
private DeformOperation(Extent destination, Region region, Vector3 zero, Vector3 unit, String expression) {
|
||||
this.destination = destination;
|
||||
@ -168,7 +166,6 @@ public class Deform implements Contextual<Operation> {
|
||||
this.zero = zero;
|
||||
this.unit = unit;
|
||||
this.expression = expression;
|
||||
this.timeout = timeout;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -12,6 +12,11 @@ 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;
|
||||
|
||||
/**
|
||||
|
@ -20,6 +20,8 @@
|
||||
package com.sk89q.worldedit.world.biome;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Stores a list of common Biome String IDs.
|
||||
@ -121,4 +123,8 @@ public class BiomeTypes {
|
||||
public static BiomeType get(int parseInt) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
public static List<BiomeType> values() {
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.platform.Capability;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.function.pattern.FawePattern;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
@ -52,31 +53,17 @@ import java.util.Set;
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public class BlockState implements BlockStateHolder<BlockState>, FawePattern {
|
||||
private final BlockType blockType;
|
||||
private BlockMaterial material;
|
||||
private BlockType blockType;
|
||||
private int internalId, ordinal;
|
||||
private BaseBlock emptyBaseBlock;
|
||||
|
||||
BlockState(BlockType blockType) {
|
||||
BlockState(BlockType blockType, int internalId, int ordinal) {
|
||||
this.blockType = blockType;
|
||||
this.emptyBaseBlock = new BaseBlock(this);
|
||||
this.internalId = internalId;
|
||||
this.ordinal = ordinal;
|
||||
}
|
||||
|
||||
BlockState(BlockType blockType, BaseBlock baseBlock){
|
||||
this.blockType = blockType;
|
||||
this.emptyBaseBlock = baseBlock;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a fuzzy BlockState. This can be used for partial matching.
|
||||
*
|
||||
* @param blockType The block type
|
||||
* @param values The block state values
|
||||
*/
|
||||
private BlockState(BlockType blockType, Map<Property<?>, Object> values) {
|
||||
this.blockType = blockType;
|
||||
// this.values = values;
|
||||
// this.fuzzy = true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a temporary BlockState for a given internal id
|
||||
* @param combinedId
|
||||
@ -364,13 +351,22 @@ public class BlockState implements BlockStateHolder<BlockState>, FawePattern {
|
||||
|
||||
@Override
|
||||
public BlockMaterial getMaterial() {
|
||||
return blockType.getMaterial();
|
||||
if (this.material == null) {
|
||||
if (blockType == BlockTypes.__RESERVED__) {
|
||||
return this.material = blockType.getMaterial();
|
||||
}
|
||||
if (this.material == null) {
|
||||
this.material = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS).getRegistries().getBlockRegistry().getMaterial(this);
|
||||
}
|
||||
}
|
||||
return material;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrdinal() {
|
||||
get ordinal
|
||||
return this.ordinal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal method used for creating the initial BlockState.
|
||||
*
|
||||
@ -399,8 +395,6 @@ public class BlockState implements BlockStateHolder<BlockState>, FawePattern {
|
||||
return equalsFuzzy((BlockState) obj);
|
||||
}
|
||||
|
||||
private Integer hashCodeCache = null;
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return getOrdinal();
|
||||
|
@ -21,14 +21,13 @@ package com.sk89q.worldedit.world.block;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.boydti.fawe.util.ReflectionUtils;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.function.mask.SingleBlockTypeMask;
|
||||
import com.sk89q.worldedit.function.pattern.FawePattern;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.world.registry.BlockMaterial;
|
||||
import com.sk89q.worldedit.extension.platform.Capability;
|
||||
@ -37,16 +36,11 @@ import com.sk89q.worldedit.registry.state.AbstractProperty;
|
||||
import com.sk89q.worldedit.registry.state.Property;
|
||||
import com.sk89q.worldedit.registry.state.PropertyKey;
|
||||
import com.sk89q.worldedit.world.item.ItemType;
|
||||
import com.sk89q.worldedit.world.item.ItemTypes;
|
||||
import com.sk89q.worldedit.world.registry.BundledBlockData;
|
||||
import com.sk89q.worldedit.world.registry.BlockMaterial;
|
||||
import com.sk89q.worldedit.world.registry.LegacyMapper;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
@ -55,33 +49,50 @@ public class BlockType implements FawePattern {
|
||||
public static final NamespacedRegistry<BlockType> REGISTRY = new NamespacedRegistry<>("block type");
|
||||
|
||||
private final @Nonnull String id;
|
||||
private ArrayList<BlockState> states;
|
||||
public final Function<BlockState, BlockState> defaultValue;
|
||||
private BlockTypes.Settings settings;
|
||||
private BlockMaterial material;
|
||||
private final BlockTypeEnum typeEnum;
|
||||
private BlockTypes.Settings settings;
|
||||
|
||||
public BlockType(@Nonnull String id) {
|
||||
this(id, null);
|
||||
// private ArrayList<BlockState> states;
|
||||
// public final Function<BlockState, BlockState> defaultValue;
|
||||
//
|
||||
// private BlockMaterial material;
|
||||
|
||||
public BlockType(@Nonnull BlockTypeEnum typeEnum) {
|
||||
this.typeEnum = typeEnum;
|
||||
}
|
||||
|
||||
public BlockType(@Nonnull String id, Function<BlockState, BlockState> defaultValue) {
|
||||
this.id = id;
|
||||
this.defaultValue = defaultValue;
|
||||
}
|
||||
|
||||
public void setStates(ArrayList<BlockState> states) {
|
||||
|
||||
public BlockTypeEnum getTypeEnum() {
|
||||
return typeEnum;
|
||||
}
|
||||
|
||||
private void init(String id, int internalId, List<BlockState> states) {
|
||||
try {
|
||||
if (getId() == null) {
|
||||
String name = (name().indexOf(':') == -1 ? "minecraft:" : "") + name().toLowerCase();
|
||||
ReflectionUtils.setFailsafeFieldValue(BlockTypes.class.getDeclaredField("id"), this, name);
|
||||
}
|
||||
Settings settings = new Settings(this, id, internalId, states);
|
||||
ReflectionUtils.setFailsafeFieldValue(BlockTypes.class.getDeclaredField("settings"), this, settings);
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void setStates(ArrayList<BlockState> states) { //
|
||||
this.states = states;
|
||||
}
|
||||
|
||||
public void setSettings(BlockTypes.Settings settings) {
|
||||
public void setSettings(BlockTypes.Settings settings) { //
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
public BlockTypes.Settings getSettings(){
|
||||
public BlockTypes.Settings getSettings(){ //
|
||||
return settings;
|
||||
}
|
||||
|
||||
public ArrayList<BlockState> updateStates(){
|
||||
public ArrayList<BlockState> updateStates(){ //
|
||||
if(settings != null) {
|
||||
return settings.localStates = new ArrayList<>(settings.localStates.stream()
|
||||
.map(state -> new BlockStateImpl(this, state.getInternalId(), state.getOrdinal())).collect(Collectors.toList()));
|
||||
@ -130,13 +141,13 @@ public class BlockType implements FawePattern {
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public BlockState withPropertyId(int propertyId) {
|
||||
if (settings.stateOrdinals == null) return settings.defaultState;
|
||||
return states.get(settings.stateOrdinals[propertyId]);
|
||||
public BlockState withPropertyId(int internalPropertiesId) {
|
||||
if (internalPropertiesId == 0) return getDefaultState();
|
||||
return BlockState.getFromInternalId(getInternalId() + (internalPropertiesId << BlockTypes.BIT_OFFSET));
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public BlockState withStateId(int internalStateId) {
|
||||
public BlockState withStateId(int internalStateId) { //
|
||||
return this.withPropertyId(internalStateId >> BlockTypes.BIT_OFFSET);
|
||||
}
|
||||
|
||||
@ -145,7 +156,7 @@ public class BlockType implements FawePattern {
|
||||
* @param properties
|
||||
* @return
|
||||
*/
|
||||
public BlockState withProperties(String properties) {
|
||||
public BlockState withProperties(String properties) { //
|
||||
int id = getInternalId();
|
||||
for (String keyPair : properties.split(",")) {
|
||||
String[] split = keyPair.split("=");
|
||||
@ -190,7 +201,6 @@ public class BlockType implements FawePattern {
|
||||
*/
|
||||
@Deprecated
|
||||
public <V> Property<V> getProperty(String name) {
|
||||
checkArgument(this.settings.propertiesMap.get(name) != null, "%s has no property named %s", this, name);
|
||||
return (Property<V>) this.settings.propertiesMap.get(name);
|
||||
}
|
||||
|
||||
@ -213,18 +223,14 @@ public class BlockType implements FawePattern {
|
||||
* @return The default state
|
||||
*/
|
||||
public BlockState getDefaultState() {
|
||||
BlockState defaultState = this.settings.defaultState;
|
||||
if (defaultValue != null) {
|
||||
defaultState = defaultValue.apply(defaultState);
|
||||
}
|
||||
return defaultState;
|
||||
return this.settings.defaultState;
|
||||
}
|
||||
|
||||
public FuzzyBlockState getFuzzyMatcher() {
|
||||
public FuzzyBlockState getFuzzyMatcher() { //
|
||||
return new FuzzyBlockState(this);
|
||||
}
|
||||
|
||||
public FuzzyBlockState getFuzzyMatcher() {
|
||||
public FuzzyBlockState getFuzzyMatcher() { //
|
||||
return updateField(emptyFuzzy, () -> new FuzzyBlockState(this));
|
||||
}
|
||||
|
||||
@ -235,7 +241,7 @@ public class BlockType implements FawePattern {
|
||||
@Deprecated
|
||||
public List<BlockState> getAllStates() {
|
||||
if (settings.stateOrdinals == null) return Collections.singletonList(getDefaultState());
|
||||
return IntStream.of(settings.stateOrdinals).filter(i -> i != -1).mapToObj(i -> states.get(i)).collect(Collectors.toList());
|
||||
return IntStream.of(settings.stateOrdinals).filter(i -> i != -1).mapToObj(i -> BlockTypes.states[i]).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -243,7 +249,7 @@ public class BlockType implements FawePattern {
|
||||
*
|
||||
* @return The state, if it exists
|
||||
*/
|
||||
public BlockState getState(Map<Property<?>, Object> key) {
|
||||
public BlockState getState(Map<Property<?>, Object> key) { //
|
||||
int id = getInternalId();
|
||||
for (Map.Entry<Property<?>, Object> iter : key.entrySet()) {
|
||||
Property<?> prop = iter.getKey();
|
||||
@ -278,7 +284,7 @@ public class BlockType implements FawePattern {
|
||||
*/
|
||||
@Nullable
|
||||
public ItemType getItemType() {
|
||||
return ItemTypes.get(this);
|
||||
return settings.itemType;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -287,9 +293,7 @@ public class BlockType implements FawePattern {
|
||||
* @return The material
|
||||
*/
|
||||
public BlockMaterial getMaterial() {
|
||||
return this.material == null ?
|
||||
WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS).getRegistries().getBlockRegistry().getMaterial(this)
|
||||
: this.material;
|
||||
return this.settings.blockMaterial;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -317,12 +321,12 @@ public class BlockType implements FawePattern {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.getSettings().defaultState.ordinal();
|
||||
return settings.internalId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return obj instanceof BlockType && this.id.equals(((BlockType) obj).id);
|
||||
return obj == this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -347,7 +351,7 @@ public class BlockType implements FawePattern {
|
||||
|
||||
|
||||
@Deprecated
|
||||
public int getLegacyId() {
|
||||
public int getLegacyId() { //
|
||||
Integer id = LegacyMapper.getInstance().getLegacyCombined(this.getDefaultState());
|
||||
if (id != null) {
|
||||
return id >> 4;
|
||||
|
@ -0,0 +1,5 @@
|
||||
package com.sk89q.worldedit.world.block;
|
||||
|
||||
public enum BlockTypeEnum {
|
||||
|
||||
}
|
@ -20,6 +20,7 @@
|
||||
package com.sk89q.worldedit.world.item;
|
||||
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.blocks.BaseItem;
|
||||
import com.sk89q.worldedit.extension.platform.Capability;
|
||||
import com.sk89q.worldedit.registry.NamespacedRegistry;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
|
@ -872,6 +872,10 @@ public final class ItemTypes {
|
||||
return ItemType.REGISTRY.register(type.getId(), type);
|
||||
}
|
||||
|
||||
public static final @Nullable ItemType get(String id) {
|
||||
|
||||
}
|
||||
|
||||
public static final @Nullable ItemType get(BlockType type) {
|
||||
ItemType item = get(type.getId());
|
||||
if (item != null && item.getBlockType() == null) {
|
||||
|
@ -51,11 +51,4 @@ public class BundledItemRegistry implements ItemRegistry {
|
||||
public Collection<String> registerItems() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getName(ItemType itemType) {
|
||||
BundledItemData.ItemEntry itemEntry = BundledItemData.getInstance().findById(itemType.getId());
|
||||
return itemEntry != null ? itemEntry.localizedName : null;
|
||||
}
|
||||
}
|
||||
|
@ -233,7 +233,7 @@ public class LegacyMapper {
|
||||
try {
|
||||
return BlockTypes.get(plotBlock.toString()).getDefaultState().toBaseBlock();
|
||||
}catch(Throwable failed) {
|
||||
log.severe("Unable to convert StringPlotBlock " + plotBlock + " to BaseBlock!");
|
||||
log.error("Unable to convert StringPlotBlock " + plotBlock + " to BaseBlock!");
|
||||
failed.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
@ -241,12 +241,12 @@ public class LegacyMapper {
|
||||
try {
|
||||
return new BaseBlock(((LegacyPlotBlock)plotBlock).getId(), ((LegacyPlotBlock)plotBlock).getData());
|
||||
}catch(Throwable failed) {
|
||||
log.severe("Unable to convert LegacyPlotBlock " + plotBlock + " to BaseBlock!");
|
||||
log.error("Unable to convert LegacyPlotBlock " + plotBlock + " to BaseBlock!");
|
||||
failed.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}else {
|
||||
log.severe("Unable to convert LegacyPlotBlock " + plotBlock + " to BaseBlock!");
|
||||
log.error("Unable to convert LegacyPlotBlock " + plotBlock + " to BaseBlock!");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user