2010-10-13 23:49:35 +00:00
|
|
|
// $Id$
|
|
|
|
/*
|
|
|
|
* WorldEdit
|
2012-01-05 21:38:23 +00:00
|
|
|
* Copyright (C) 2010 sk89q <http://www.sk89q.com> and contributors
|
2010-10-13 23:49:35 +00:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2010-10-14 08:31:05 +00:00
|
|
|
package com.sk89q.worldedit.blocks;
|
2010-10-13 23:49:35 +00:00
|
|
|
|
2011-08-26 10:41:31 +00:00
|
|
|
import com.sk89q.worldedit.CuboidClipboard.FlipDirection;
|
2012-08-23 23:52:37 +00:00
|
|
|
import com.sk89q.worldedit.foundation.Block;
|
2011-01-30 07:10:12 +00:00
|
|
|
|
2013-12-03 22:36:37 +00:00
|
|
|
import java.util.Collection;
|
|
|
|
|
2010-10-13 23:49:35 +00:00
|
|
|
/**
|
|
|
|
* Represents a block.
|
|
|
|
*
|
2012-08-23 23:52:37 +00:00
|
|
|
* @see Block new class to replace this one
|
2010-10-13 23:49:35 +00:00
|
|
|
* @author sk89q
|
|
|
|
*/
|
2012-08-23 23:52:37 +00:00
|
|
|
public class BaseBlock extends Block {
|
|
|
|
|
2010-10-13 23:49:35 +00:00
|
|
|
/**
|
2012-08-23 23:52:37 +00:00
|
|
|
* Construct the block with its type, with default data value 0.
|
2010-10-13 23:49:35 +00:00
|
|
|
*
|
2012-08-23 23:52:37 +00:00
|
|
|
* @param type type ID of block
|
2010-10-13 23:49:35 +00:00
|
|
|
*/
|
|
|
|
public BaseBlock(int type) {
|
2012-03-30 04:11:49 +00:00
|
|
|
this(type, 0);
|
2010-10-13 23:49:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Construct the block with its type and data.
|
|
|
|
*
|
2012-08-23 23:52:37 +00:00
|
|
|
* @param type type ID of block
|
|
|
|
* @param data data value
|
2010-10-13 23:49:35 +00:00
|
|
|
*/
|
|
|
|
public BaseBlock(int type, int data) {
|
2012-08-23 23:52:37 +00:00
|
|
|
super(type, data);
|
2010-10-13 23:49:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-08-23 23:52:37 +00:00
|
|
|
* Get the type of block.
|
|
|
|
*
|
2010-10-13 23:49:35 +00:00
|
|
|
* @return the type
|
|
|
|
*/
|
2011-01-16 17:39:11 +00:00
|
|
|
public int getType() {
|
2012-08-23 23:52:37 +00:00
|
|
|
return getId();
|
2010-10-13 23:49:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-08-23 23:52:37 +00:00
|
|
|
* Set the type of block.
|
|
|
|
*
|
2010-10-13 23:49:35 +00:00
|
|
|
* @param type the type to set
|
|
|
|
*/
|
|
|
|
public void setType(int type) {
|
2012-08-23 23:52:37 +00:00
|
|
|
setId(type);
|
2010-10-13 23:49:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if it's air.
|
|
|
|
*
|
|
|
|
* @return if air
|
|
|
|
*/
|
|
|
|
public boolean isAir() {
|
2012-08-23 23:52:37 +00:00
|
|
|
return getType() == BlockID.AIR;
|
2010-10-13 23:49:35 +00:00
|
|
|
}
|
2011-09-24 19:32:03 +00:00
|
|
|
|
2011-01-30 07:10:12 +00:00
|
|
|
/**
|
|
|
|
* Rotate this block 90 degrees.
|
2012-08-23 23:52:37 +00:00
|
|
|
*
|
|
|
|
* @return new data value
|
2011-01-30 07:10:12 +00:00
|
|
|
*/
|
2011-10-04 21:13:41 +00:00
|
|
|
public int rotate90() {
|
2012-08-23 23:52:37 +00:00
|
|
|
int newData = BlockData.rotate90(getType(), getData());
|
|
|
|
setData(newData);
|
|
|
|
return newData;
|
2011-01-30 07:10:12 +00:00
|
|
|
}
|
2011-09-24 19:32:03 +00:00
|
|
|
|
2011-01-30 07:10:12 +00:00
|
|
|
/**
|
|
|
|
* Rotate this block -90 degrees.
|
2012-08-23 23:52:37 +00:00
|
|
|
*
|
|
|
|
* @return new data value
|
2011-01-30 07:10:12 +00:00
|
|
|
*/
|
2011-10-04 21:13:41 +00:00
|
|
|
public int rotate90Reverse() {
|
2012-08-23 23:52:37 +00:00
|
|
|
int newData = BlockData.rotate90Reverse(getType(), getData());
|
|
|
|
setData((short) newData);
|
2011-10-04 21:13:41 +00:00
|
|
|
return newData;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cycle the damage value of the block forward or backward
|
|
|
|
*
|
|
|
|
* @param increment 1 for forward, -1 for backward
|
|
|
|
* @return new data value
|
|
|
|
*/
|
|
|
|
public int cycleData(int increment) {
|
2012-08-23 23:52:37 +00:00
|
|
|
int newData = BlockData.cycle(getType(), getData(), increment);
|
|
|
|
setData((short) newData);
|
2011-10-04 21:13:41 +00:00
|
|
|
return newData;
|
2011-01-30 07:10:12 +00:00
|
|
|
}
|
2011-09-24 19:32:03 +00:00
|
|
|
|
2011-09-03 16:54:20 +00:00
|
|
|
/**
|
|
|
|
* Flip this block.
|
2012-08-23 23:52:37 +00:00
|
|
|
*
|
|
|
|
* @return this block
|
2011-09-03 16:54:20 +00:00
|
|
|
*/
|
|
|
|
public BaseBlock flip() {
|
2012-08-23 23:52:37 +00:00
|
|
|
setData((short) BlockData.flip(getType(), getData()));
|
2011-09-03 16:54:20 +00:00
|
|
|
return this;
|
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-01-30 07:10:12 +00:00
|
|
|
/**
|
|
|
|
* Flip this block.
|
2012-08-23 23:52:37 +00:00
|
|
|
*
|
|
|
|
* @param direction direction to flip in
|
|
|
|
* @return this block
|
2011-01-30 07:10:12 +00:00
|
|
|
*/
|
2011-09-03 16:54:20 +00:00
|
|
|
public BaseBlock flip(FlipDirection direction) {
|
2012-08-23 23:52:37 +00:00
|
|
|
setData((short) BlockData.flip(getType(), getData(), direction));
|
2011-09-03 16:54:20 +00:00
|
|
|
return this;
|
2011-01-30 07:10:12 +00:00
|
|
|
}
|
2011-08-29 06:57:07 +00:00
|
|
|
|
2012-08-23 23:52:37 +00:00
|
|
|
/**
|
|
|
|
* Checks whether the type ID and data value are equal.
|
|
|
|
*/
|
2011-08-29 06:57:07 +00:00
|
|
|
@Override
|
|
|
|
public boolean equals(Object o) {
|
|
|
|
if (!(o instanceof BaseBlock)) {
|
|
|
|
return false;
|
|
|
|
}
|
2012-01-31 15:57:40 +00:00
|
|
|
|
2013-12-02 08:46:45 +00:00
|
|
|
final BaseBlock otherBlock = (BaseBlock) o;
|
|
|
|
if (getType() != otherBlock.getType()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return getData() == otherBlock.getData();
|
2012-01-31 15:57:40 +00:00
|
|
|
}
|
|
|
|
|
2012-08-23 23:52:37 +00:00
|
|
|
/**
|
|
|
|
* Checks if the type is the same, and if data is the same if only data != -1.
|
|
|
|
*
|
|
|
|
* @param o other block
|
|
|
|
* @return true if equal
|
|
|
|
*/
|
2012-01-31 15:57:40 +00:00
|
|
|
public boolean equalsFuzzy(BaseBlock o) {
|
2013-03-16 02:25:57 +00:00
|
|
|
return (getType() == o.getType()) && (getData() == o.getData() || getData() == -1 || o.getData() == -1);
|
2011-08-29 06:57:07 +00:00
|
|
|
}
|
|
|
|
|
2012-01-31 15:57:40 +00:00
|
|
|
/**
|
|
|
|
* @param iter
|
|
|
|
* @return
|
2013-12-03 22:36:37 +00:00
|
|
|
* @deprecated This method is silly, use {@link #containsFuzzy(java.util.Collection, BaseBlock)} instead.
|
2012-01-31 15:57:40 +00:00
|
|
|
*/
|
|
|
|
@Deprecated
|
2011-08-29 06:57:07 +00:00
|
|
|
public boolean inIterable(Iterable<BaseBlock> iter) {
|
|
|
|
for (BaseBlock block : iter) {
|
2012-01-31 15:57:40 +00:00
|
|
|
if (block.equalsFuzzy(this)) {
|
2011-08-29 06:57:07 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2013-12-03 22:36:37 +00:00
|
|
|
|
|
|
|
public static boolean containsFuzzy(Collection<BaseBlock> collection, BaseBlock o) {
|
|
|
|
// allow masked data in the searchBlocks to match various types
|
|
|
|
for (BaseBlock b : collection) {
|
|
|
|
if (b.equalsFuzzy(o)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2010-10-13 23:49:35 +00:00
|
|
|
}
|