Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-12-27 03:12:37 +01:00
Removed foundation.* package.
Dieser Commit ist enthalten in:
Ursprung
a08ee7bce9
Commit
08900cbfc2
@ -1313,7 +1313,7 @@ public class BukkitWorld extends LocalWorld {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean setBlock(Vector pt, com.sk89q.worldedit.foundation.Block block, boolean notifyAdjacent) {
|
public boolean setBlock(Vector pt, BaseBlock block, boolean notifyAdjacent) {
|
||||||
if (!skipNmsSafeSet) {
|
if (!skipNmsSafeSet) {
|
||||||
try {
|
try {
|
||||||
return (Boolean) nmsSetSafeMethod.invoke(null, this, pt, block, notifyAdjacent);
|
return (Boolean) nmsSetSafeMethod.invoke(null, this, pt, block, notifyAdjacent);
|
||||||
|
41
src/legacy/java/com/sk89q/worldedit/foundation/Block.java
Normale Datei
41
src/legacy/java/com/sk89q/worldedit/foundation/Block.java
Normale Datei
@ -0,0 +1,41 @@
|
|||||||
|
// $Id$
|
||||||
|
/*
|
||||||
|
* This file is a part of WorldEdit.
|
||||||
|
* Copyright (c) sk89q <http://www.sk89q.com>
|
||||||
|
* Copyright (c) the 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
|
||||||
|
* (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
|
||||||
|
* GNU 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.foundation;
|
||||||
|
|
||||||
|
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Use {@link BaseBlock}
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public abstract class Block {
|
||||||
|
|
||||||
|
public abstract int getId();
|
||||||
|
|
||||||
|
public abstract void setId(int id);
|
||||||
|
|
||||||
|
public abstract int getData();
|
||||||
|
|
||||||
|
public abstract void setData(int data);
|
||||||
|
|
||||||
|
public abstract void setIdAndData(int id, int data);
|
||||||
|
|
||||||
|
public abstract boolean hasWildcardData();
|
||||||
|
|
||||||
|
}
|
@ -21,8 +21,7 @@ package com.sk89q.worldedit;
|
|||||||
|
|
||||||
import com.sk89q.worldedit.blocks.*;
|
import com.sk89q.worldedit.blocks.*;
|
||||||
import com.sk89q.worldedit.extent.Extent;
|
import com.sk89q.worldedit.extent.Extent;
|
||||||
import com.sk89q.worldedit.foundation.Block;
|
import com.sk89q.worldedit.world.World;
|
||||||
import com.sk89q.worldedit.foundation.World;
|
|
||||||
import com.sk89q.worldedit.function.mask.BlockMask;
|
import com.sk89q.worldedit.function.mask.BlockMask;
|
||||||
import com.sk89q.worldedit.function.mask.Mask;
|
import com.sk89q.worldedit.function.mask.Mask;
|
||||||
import com.sk89q.worldedit.function.operation.Operation;
|
import com.sk89q.worldedit.function.operation.Operation;
|
||||||
@ -533,7 +532,7 @@ public abstract class LocalWorld implements World, Extent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean setBlock(Vector pt, Block block, boolean notifyAdjacent) {
|
public boolean setBlock(Vector pt, BaseBlock block, boolean notifyAdjacent) {
|
||||||
boolean successful;
|
boolean successful;
|
||||||
|
|
||||||
// Default implementation will call the old deprecated methods
|
// Default implementation will call the old deprecated methods
|
||||||
|
@ -19,36 +19,216 @@
|
|||||||
|
|
||||||
package com.sk89q.worldedit.blocks;
|
package com.sk89q.worldedit.blocks;
|
||||||
|
|
||||||
|
import com.sk89q.jnbt.CompoundTag;
|
||||||
|
import com.sk89q.jnbt.StringTag;
|
||||||
|
import com.sk89q.jnbt.Tag;
|
||||||
import com.sk89q.worldedit.CuboidClipboard.FlipDirection;
|
import com.sk89q.worldedit.CuboidClipboard.FlipDirection;
|
||||||
import com.sk89q.worldedit.foundation.Block;
|
import com.sk89q.worldedit.foundation.Block;
|
||||||
|
import com.sk89q.worldedit.world.DataException;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a block.
|
* Represents a mutable copy of a block that is not tied to any 'real' block in a world.
|
||||||
*
|
* A single instance of this can be set to multiple locations and each location would
|
||||||
* @see Block new class to replace this one
|
* have a copy of this instance's data.
|
||||||
* @author sk89q
|
* </p>
|
||||||
|
* Implementations can and should extend this class to allow native implementations
|
||||||
|
* of NBT data handling, primarily for performance reasons. Subclasses can only convert
|
||||||
|
* from and to WorldEdit-native NBT structures when absolutely necessary (a.k.a. when
|
||||||
|
* {@link #getNbtData()} and {@link #setNbtData(CompoundTag)} are called). When
|
||||||
|
* overriding the NBT methods, {@link #getNbtId()} should be overridden too, otherwise
|
||||||
|
* the default implementation will invoke {@link #getNbtData()}, a potentially costly
|
||||||
|
* operation when it is not needed. Implementations may want to cache converted NBT data
|
||||||
|
* structures if possible.
|
||||||
*/
|
*/
|
||||||
public class BaseBlock extends Block {
|
public class BaseBlock extends Block implements TileEntityBlock {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct the block with its type, with default data value 0.
|
* Indicates the highest possible block ID (inclusive) that can be used. This value
|
||||||
*
|
* is subject to change depending on the implementation, but internally this class
|
||||||
* @param type type ID of block
|
* only supports a range of 4096 IDs (for space reasons), which coincides with the
|
||||||
|
* number of possible IDs that official Minecraft supports as of version 1.3.
|
||||||
*/
|
*/
|
||||||
public BaseBlock(int type) {
|
public static final int MAX_ID = 4095;
|
||||||
this(type, 0);
|
|
||||||
|
/**
|
||||||
|
* Indicates the maximum data value (inclusive) that can be used. Minecraft 1.4 may
|
||||||
|
* abolish usage of data values and this value may be removed in the future.
|
||||||
|
*/
|
||||||
|
public static final int MAX_DATA = 15;
|
||||||
|
|
||||||
|
// Instances of this class should be _as small as possible_ because there will
|
||||||
|
// be millions of instances of this object.
|
||||||
|
|
||||||
|
private short id;
|
||||||
|
private short data;
|
||||||
|
private CompoundTag nbtData;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct a block with the given ID and a data value of 0.
|
||||||
|
*
|
||||||
|
* @param id ID value
|
||||||
|
* @see #setId(int)
|
||||||
|
*/
|
||||||
|
public BaseBlock(int id) {
|
||||||
|
internalSetId(id);
|
||||||
|
internalSetData(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct the block with its type and data.
|
* Construct a block with the given ID and data value.
|
||||||
*
|
*
|
||||||
* @param type type ID of block
|
* @param id ID value
|
||||||
* @param data data value
|
* @param data data value
|
||||||
|
* @see #setId(int)
|
||||||
|
* @see #setData(int)
|
||||||
*/
|
*/
|
||||||
public BaseBlock(int type, int data) {
|
public BaseBlock(int id, int data) {
|
||||||
super(type, data);
|
internalSetId(id);
|
||||||
|
internalSetData(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct a block with the given ID, data value, and NBT data structure.
|
||||||
|
*
|
||||||
|
* @param id ID value
|
||||||
|
* @param data data value
|
||||||
|
* @param nbtData NBT data
|
||||||
|
* @throws DataException if possibly the data is invalid
|
||||||
|
* @see #setId(int)
|
||||||
|
* @see #setData(int)
|
||||||
|
* @see #setNbtData(CompoundTag)
|
||||||
|
*/
|
||||||
|
public BaseBlock(int id, int data, CompoundTag nbtData) throws DataException {
|
||||||
|
setId(id);
|
||||||
|
setData(data);
|
||||||
|
setNbtData(nbtData);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the ID of the block.
|
||||||
|
*
|
||||||
|
* @return ID (between 0 and {@link #MAX_ID})
|
||||||
|
*/
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the block ID.
|
||||||
|
*
|
||||||
|
* @param id block id (between 0 and {@link #MAX_ID}).
|
||||||
|
*/
|
||||||
|
protected final void internalSetId(int id) {
|
||||||
|
if (id > MAX_ID) {
|
||||||
|
throw new IllegalArgumentException("Can't have a block ID above "
|
||||||
|
+ MAX_ID + " (" + id + " given)");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (id < 0) {
|
||||||
|
throw new IllegalArgumentException("Can't have a block ID below 0");
|
||||||
|
}
|
||||||
|
|
||||||
|
this.id = (short) id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the block ID.
|
||||||
|
*
|
||||||
|
* @param id block id (between 0 and {@link #MAX_ID}).
|
||||||
|
*/
|
||||||
|
public void setId(int id) {
|
||||||
|
internalSetId(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the block's data value.
|
||||||
|
*
|
||||||
|
* @return data value (0-15)
|
||||||
|
*/
|
||||||
|
public int getData() {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the block's data value.
|
||||||
|
*
|
||||||
|
* @param data block data value (between 0 and {@link #MAX_DATA}).
|
||||||
|
*/
|
||||||
|
protected final void internalSetData(int data) {
|
||||||
|
if (data > MAX_DATA) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"Can't have a block data value above " + MAX_DATA + " ("
|
||||||
|
+ data + " given)");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data < -1) {
|
||||||
|
throw new IllegalArgumentException("Can't have a block data value below -1");
|
||||||
|
}
|
||||||
|
|
||||||
|
this.data = (short) data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the block's data value.
|
||||||
|
*
|
||||||
|
* @param data block data value (between 0 and {@link #MAX_DATA}).
|
||||||
|
*/
|
||||||
|
public void setData(int data) {
|
||||||
|
internalSetData(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set both the block's ID and data value.
|
||||||
|
*
|
||||||
|
* @param id ID value
|
||||||
|
* @param data data value
|
||||||
|
* @see #setId(int)
|
||||||
|
* @see #setData(int)
|
||||||
|
*/
|
||||||
|
public void setIdAndData(int id, int data) {
|
||||||
|
setId(id);
|
||||||
|
setData(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether the data value is -1, indicating that this block is to be
|
||||||
|
* used as a wildcard matching block.
|
||||||
|
*
|
||||||
|
* @return true if the data value is -1
|
||||||
|
*/
|
||||||
|
public boolean hasWildcardData() {
|
||||||
|
return getData() == -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasNbtData() {
|
||||||
|
return getNbtData() != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getNbtId() {
|
||||||
|
CompoundTag nbtData = getNbtData();
|
||||||
|
if (nbtData == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
Tag idTag = nbtData.getValue().get("id");
|
||||||
|
if (idTag != null && idTag instanceof StringTag) {
|
||||||
|
return ((StringTag) idTag).getValue();
|
||||||
|
} else {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompoundTag getNbtData() {
|
||||||
|
return nbtData;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setNbtData(CompoundTag nbtData) throws DataException {
|
||||||
|
this.nbtData = nbtData;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -184,4 +364,17 @@ public class BaseBlock extends Block {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int ret = getId() << 3;
|
||||||
|
if (getData() != (byte) -1) ret |= getData();
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Block{ID:" + getId() + ", Data: " + getData() + "}";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -19,16 +19,10 @@
|
|||||||
|
|
||||||
package com.sk89q.worldedit.blocks;
|
package com.sk89q.worldedit.blocks;
|
||||||
|
|
||||||
import java.util.EnumSet;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Random;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import com.sk89q.util.StringUtil;
|
import com.sk89q.util.StringUtil;
|
||||||
import com.sk89q.worldedit.PlayerDirection;
|
import com.sk89q.worldedit.PlayerDirection;
|
||||||
import com.sk89q.worldedit.foundation.Block;
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Block types.
|
* Block types.
|
||||||
@ -552,7 +546,7 @@ public enum BlockType {
|
|||||||
* @param block
|
* @param block
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static boolean canPassThrough(Block block) {
|
public static boolean canPassThrough(BaseBlock block) {
|
||||||
return canPassThrough(block.getId(), block.getData());
|
return canPassThrough(block.getId(), block.getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -649,7 +643,7 @@ public enum BlockType {
|
|||||||
* @param block
|
* @param block
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static double centralTopLimit(Block block) {
|
public static double centralTopLimit(BaseBlock block) {
|
||||||
return centralTopLimit(block.getId(), block.getData());
|
return centralTopLimit(block.getId(), block.getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1053,7 +1047,7 @@ public enum BlockType {
|
|||||||
* @param block The block
|
* @param block The block
|
||||||
* @return true if the block type is naturally occuring
|
* @return true if the block type is naturally occuring
|
||||||
*/
|
*/
|
||||||
public static boolean isNaturalTerrainBlock(Block block) {
|
public static boolean isNaturalTerrainBlock(BaseBlock block) {
|
||||||
return isNaturalTerrainBlock(block.getId(), block.getData());
|
return isNaturalTerrainBlock(block.getId(), block.getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
package com.sk89q.worldedit.blocks;
|
package com.sk89q.worldedit.blocks;
|
||||||
|
|
||||||
import com.sk89q.worldedit.foundation.NbtValued;
|
import com.sk89q.worldedit.world.NbtValued;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates a block that contains extra data identified as an NBT structure. Compared
|
* Indicates a block that contains extra data identified as an NBT structure. Compared
|
||||||
|
@ -1,248 +0,0 @@
|
|||||||
// $Id$
|
|
||||||
/*
|
|
||||||
* This file is a part of WorldEdit.
|
|
||||||
* Copyright (c) sk89q <http://www.sk89q.com>
|
|
||||||
* Copyright (c) the 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
|
|
||||||
* (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
|
|
||||||
* GNU 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.foundation;
|
|
||||||
|
|
||||||
import com.sk89q.jnbt.CompoundTag;
|
|
||||||
import com.sk89q.jnbt.StringTag;
|
|
||||||
import com.sk89q.jnbt.Tag;
|
|
||||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
|
||||||
import com.sk89q.worldedit.blocks.TileEntityBlock;
|
|
||||||
import com.sk89q.worldedit.world.DataException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents a mutable copy of a block that is not tied to any 'real' block in a world.
|
|
||||||
* A single instance of this can be set to multiple locations and each location would
|
|
||||||
* have a copy of this instance's data.
|
|
||||||
* </p>
|
|
||||||
* Implementations can and should extend this class to allow native implementations
|
|
||||||
* of NBT data handling, primarily for performance reasons. Subclasses can only convert
|
|
||||||
* from and to WorldEdit-native NBT structures when absolutely necessary (a.k.a. when
|
|
||||||
* {@link #getNbtData()} and {@link #setNbtData(CompoundTag)} are called). When
|
|
||||||
* overriding the NBT methods, {@link #getNbtId()} should be overridden too, otherwise
|
|
||||||
* the default implementation will invoke {@link #getNbtData()}, a potentially costly
|
|
||||||
* operation when it is not needed. Implementations may want to cache converted NBT data
|
|
||||||
* structures if possible.
|
|
||||||
* </p>
|
|
||||||
* Currently, {@link BaseBlock} is used throughout WorldEdit and implementations, but
|
|
||||||
* eventually an API-breaking transition will occur to switch to this object instead.
|
|
||||||
* As-is, the definition of this class is complete, but may need changes in MC 1.4
|
|
||||||
* because data values may be eradicated.
|
|
||||||
*/
|
|
||||||
public class Block implements TileEntityBlock {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Indicates the highest possible block ID (inclusive) that can be used. This value
|
|
||||||
* is subject to change depending on the implementation, but internally this class
|
|
||||||
* only supports a range of 4096 IDs (for space reasons), which coincides with the
|
|
||||||
* number of possible IDs that official Minecraft supports as of version 1.3.
|
|
||||||
*/
|
|
||||||
public static final int MAX_ID = 4095;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Indicates the maximum data value (inclusive) that can be used. Minecraft 1.4 may
|
|
||||||
* abolish usage of data values and this value may be removed in the future.
|
|
||||||
*/
|
|
||||||
public static final int MAX_DATA = 15;
|
|
||||||
|
|
||||||
// Instances of this class should be _as small as possible_ because there will
|
|
||||||
// be millions of instances of this object.
|
|
||||||
|
|
||||||
private short id;
|
|
||||||
private short data;
|
|
||||||
private CompoundTag nbtData;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Construct a block with the given ID and a data value of 0.
|
|
||||||
*
|
|
||||||
* @param id ID value
|
|
||||||
* @see #setId(int)
|
|
||||||
*/
|
|
||||||
public Block(int id) {
|
|
||||||
internalSetId(id);
|
|
||||||
internalSetData(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Construct a block with the given ID and data value.
|
|
||||||
*
|
|
||||||
* @param id ID value
|
|
||||||
* @param data data value
|
|
||||||
* @see #setId(int)
|
|
||||||
* @see #setData(int)
|
|
||||||
*/
|
|
||||||
public Block(int id, int data) {
|
|
||||||
internalSetId(id);
|
|
||||||
internalSetData(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Construct a block with the given ID, data value, and NBT data structure.
|
|
||||||
*
|
|
||||||
* @param id ID value
|
|
||||||
* @param data data value
|
|
||||||
* @param nbtData NBT data
|
|
||||||
* @throws DataException if possibly the data is invalid
|
|
||||||
* @see #setId(int)
|
|
||||||
* @see #setData(int)
|
|
||||||
* @see #setNbtData(CompoundTag)
|
|
||||||
*/
|
|
||||||
public Block(int id, int data, CompoundTag nbtData) throws DataException {
|
|
||||||
setId(id);
|
|
||||||
setData(data);
|
|
||||||
setNbtData(nbtData);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the ID of the block.
|
|
||||||
*
|
|
||||||
* @return ID (between 0 and {@link #MAX_ID})
|
|
||||||
*/
|
|
||||||
public int getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the block ID.
|
|
||||||
*
|
|
||||||
* @param id block id (between 0 and {@link #MAX_ID}).
|
|
||||||
*/
|
|
||||||
protected final void internalSetId(int id) {
|
|
||||||
if (id > MAX_ID) {
|
|
||||||
throw new IllegalArgumentException("Can't have a block ID above "
|
|
||||||
+ MAX_ID + " (" + id + " given)");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (id < 0) {
|
|
||||||
throw new IllegalArgumentException("Can't have a block ID below 0");
|
|
||||||
}
|
|
||||||
|
|
||||||
this.id = (short) id;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the block ID.
|
|
||||||
*
|
|
||||||
* @param id block id (between 0 and {@link #MAX_ID}).
|
|
||||||
*/
|
|
||||||
public void setId(int id) {
|
|
||||||
internalSetId(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the block's data value.
|
|
||||||
*
|
|
||||||
* @return data value (0-15)
|
|
||||||
*/
|
|
||||||
public int getData() {
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the block's data value.
|
|
||||||
*
|
|
||||||
* @param data block data value (between 0 and {@link #MAX_DATA}).
|
|
||||||
*/
|
|
||||||
protected final void internalSetData(int data) {
|
|
||||||
if (data > MAX_DATA) {
|
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"Can't have a block data value above " + MAX_DATA + " ("
|
|
||||||
+ data + " given)");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data < -1) {
|
|
||||||
throw new IllegalArgumentException("Can't have a block data value below -1");
|
|
||||||
}
|
|
||||||
|
|
||||||
this.data = (short) data;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the block's data value.
|
|
||||||
*
|
|
||||||
* @param data block data value (between 0 and {@link #MAX_DATA}).
|
|
||||||
*/
|
|
||||||
public void setData(int data) {
|
|
||||||
internalSetData(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set both the block's ID and data value.
|
|
||||||
*
|
|
||||||
* @param id ID value
|
|
||||||
* @param data data value
|
|
||||||
* @see #setId(int)
|
|
||||||
* @see #setData(int)
|
|
||||||
*/
|
|
||||||
public void setIdAndData(int id, int data) {
|
|
||||||
setId(id);
|
|
||||||
setData(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns whether the data value is -1, indicating that this block is to be
|
|
||||||
* used as a wildcard matching block.
|
|
||||||
*
|
|
||||||
* @return true if the data value is -1
|
|
||||||
*/
|
|
||||||
public boolean hasWildcardData() {
|
|
||||||
return getData() == -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasNbtData() {
|
|
||||||
return getNbtData() != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getNbtId() {
|
|
||||||
CompoundTag nbtData = getNbtData();
|
|
||||||
if (nbtData == null) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
Tag idTag = nbtData.getValue().get("id");
|
|
||||||
if (idTag != null && idTag instanceof StringTag) {
|
|
||||||
return ((StringTag) idTag).getValue();
|
|
||||||
} else {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CompoundTag getNbtData() {
|
|
||||||
return nbtData;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setNbtData(CompoundTag nbtData) throws DataException {
|
|
||||||
this.nbtData = nbtData;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
int ret = getId() << 3;
|
|
||||||
if (getData() != (byte) -1) ret |= getData();
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "Block{ID:" + getId() + ", Data: " + getData() + "}";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -16,7 +16,7 @@
|
|||||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.sk89q.worldedit.foundation;
|
package com.sk89q.worldedit.world;
|
||||||
|
|
||||||
import com.sk89q.jnbt.CompoundTag;
|
import com.sk89q.jnbt.CompoundTag;
|
||||||
import com.sk89q.worldedit.world.DataException;
|
import com.sk89q.worldedit.world.DataException;
|
@ -16,10 +16,12 @@
|
|||||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.sk89q.worldedit.foundation;
|
package com.sk89q.worldedit.world;
|
||||||
|
|
||||||
import com.sk89q.worldedit.LocalWorld;
|
import com.sk89q.worldedit.LocalWorld;
|
||||||
import com.sk89q.worldedit.Vector;
|
import com.sk89q.worldedit.Vector;
|
||||||
|
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||||
|
import com.sk89q.worldedit.foundation.Block;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a world instance that can be modified. The world instance could be
|
* Represents a world instance that can be modified. The world instance could be
|
||||||
@ -33,8 +35,8 @@ public interface World {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Change the block at the given location to the given block. The operation may
|
* Change the block at the given location to the given block. The operation may
|
||||||
* not tie the given {@link Block} to the world, so future changes to the
|
* not tie the given {@link BaseBlock} to the world, so future changes to the
|
||||||
* {@link Block} do not affect the world until this method is called again.
|
* {@link BaseBlock} do not affect the world until this method is called again.
|
||||||
* </p>
|
* </p>
|
||||||
* Implementations may or may not consider the value of the notifyAdjacent
|
* Implementations may or may not consider the value of the notifyAdjacent
|
||||||
* parameter, and implementations may to choose to either apply physics anyway or
|
* parameter, and implementations may to choose to either apply physics anyway or
|
||||||
@ -53,17 +55,17 @@ public interface World {
|
|||||||
* @param notifyAdjacent true to to notify adjacent (perform physics)
|
* @param notifyAdjacent true to to notify adjacent (perform physics)
|
||||||
* @return true if the block was successfully set (return value may not be accurate)
|
* @return true if the block was successfully set (return value may not be accurate)
|
||||||
*/
|
*/
|
||||||
boolean setBlock(Vector location, Block block, boolean notifyAdjacent);
|
boolean setBlock(Vector location, BaseBlock block, boolean notifyAdjacent);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a copy of the block at the given location. May return null if the location
|
* Get a copy of the block at the given location. May return null if the location
|
||||||
* given is out of bounds. The returned block must not be tied to any real block
|
* given is out of bounds. The returned block must not be tied to any real block
|
||||||
* in the world, so changes to the returned {@link Block} have no effect until
|
* in the world, so changes to the returned {@link Block} have no effect until
|
||||||
* {@link #setBlock(Vector, Block, boolean)} is called.
|
* {@link #setBlock(Vector, BaseBlock, boolean)} is called.
|
||||||
*
|
*
|
||||||
* @param location location of the block
|
* @param location location of the block
|
||||||
* @return the block, or null if the block does not exist
|
* @return the block, or null if the block does not exist
|
||||||
*/
|
*/
|
||||||
Block getBlock(Vector location);
|
BaseBlock getBlock(Vector location);
|
||||||
|
|
||||||
}
|
}
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren