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;
|
2011-01-30 07:10:12 +00:00
|
|
|
|
2010-10-13 23:49:35 +00:00
|
|
|
/**
|
|
|
|
* Represents a block.
|
|
|
|
*
|
|
|
|
* @author sk89q
|
|
|
|
*/
|
|
|
|
public class BaseBlock {
|
|
|
|
/**
|
|
|
|
* BaseBlock type.
|
|
|
|
*/
|
|
|
|
private short type = 0;
|
|
|
|
/**
|
|
|
|
* BaseBlock data.
|
|
|
|
*/
|
2011-08-29 12:43:56 +00:00
|
|
|
private byte data = 0;
|
2010-10-13 23:49:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Construct the block with its type.
|
|
|
|
*
|
|
|
|
* @param type
|
|
|
|
*/
|
|
|
|
public BaseBlock(int type) {
|
2011-09-24 19:24:10 +00:00
|
|
|
this.type = (short) type;
|
2010-10-13 23:49:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Construct the block with its type and data.
|
|
|
|
*
|
|
|
|
* @param type
|
2011-09-24 19:32:03 +00:00
|
|
|
* @param data
|
2010-10-13 23:49:35 +00:00
|
|
|
*/
|
|
|
|
public BaseBlock(int type, int data) {
|
2011-09-24 19:24:10 +00:00
|
|
|
this.type = (short) type;
|
|
|
|
this.data = (byte) data;
|
2010-10-13 23:49:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the type
|
|
|
|
*/
|
2011-01-16 17:39:11 +00:00
|
|
|
public int getType() {
|
2011-09-24 19:24:10 +00:00
|
|
|
return (int) type;
|
2010-10-13 23:49:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param type the type to set
|
|
|
|
*/
|
|
|
|
public void setType(int type) {
|
2011-09-24 19:24:10 +00:00
|
|
|
this.type = (short) type;
|
2010-10-13 23:49:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the data
|
|
|
|
*/
|
|
|
|
public int getData() {
|
2011-11-23 01:29:48 +00:00
|
|
|
return (int) data;
|
2010-10-13 23:49:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param data the data to set
|
|
|
|
*/
|
|
|
|
public void setData(int data) {
|
2011-09-24 19:24:10 +00:00
|
|
|
this.data = (byte) data;
|
2010-10-13 23:49:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if it's air.
|
|
|
|
*
|
|
|
|
* @return if air
|
|
|
|
*/
|
|
|
|
public boolean isAir() {
|
2011-10-04 21:13:41 +00:00
|
|
|
return type == 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.
|
|
|
|
*/
|
2011-10-04 21:13:41 +00:00
|
|
|
public int rotate90() {
|
|
|
|
int newData = BlockData.rotate90(type, data);
|
|
|
|
this.data = (byte) newData;
|
|
|
|
return data;
|
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.
|
|
|
|
*/
|
2011-10-04 21:13:41 +00:00
|
|
|
public int rotate90Reverse() {
|
|
|
|
int newData = BlockData.rotate90Reverse(type, data);
|
|
|
|
this.data = (byte) newData;
|
|
|
|
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) {
|
|
|
|
int newData = BlockData.cycle(this.type, this.data, increment);
|
|
|
|
this.data = (byte) newData;
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
public BaseBlock flip() {
|
|
|
|
data = (byte) BlockData.flip(type, data);
|
|
|
|
return this;
|
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-01-30 07:10:12 +00:00
|
|
|
/**
|
|
|
|
* Flip this block.
|
2011-08-26 10:41:31 +00:00
|
|
|
* @param direction
|
2011-01-30 07:10:12 +00:00
|
|
|
*/
|
2011-09-03 16:54:20 +00:00
|
|
|
public BaseBlock flip(FlipDirection direction) {
|
|
|
|
data = (byte) BlockData.flip(type, data, direction);
|
|
|
|
return this;
|
2011-01-30 07:10:12 +00:00
|
|
|
}
|
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
|
|
|
|
|
|
|
return type == ((BaseBlock) o).type && data == ((BaseBlock) o).data;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean equalsFuzzy(BaseBlock o) {
|
|
|
|
return (type == o.type && data == o.data) || data == -1 || o.data == -1;
|
2011-08-29 06:57:07 +00:00
|
|
|
}
|
2011-09-24 19:32:03 +00:00
|
|
|
|
2011-09-29 02:05:22 +00:00
|
|
|
@Override
|
|
|
|
public int hashCode() {
|
|
|
|
int ret = type << 3;
|
2011-10-04 21:13:41 +00:00
|
|
|
if (data != (byte) -1) ret |= data;
|
2011-09-29 02:05:22 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-08-29 06:57:07 +00:00
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return "BaseBlock id: " + getType() + " with damage: " + getData();
|
|
|
|
}
|
|
|
|
|
2012-01-31 15:57:40 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param iter
|
|
|
|
* @return
|
|
|
|
* @deprecated This method is silly
|
|
|
|
*/
|
|
|
|
@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;
|
|
|
|
}
|
2010-10-13 23:49:35 +00:00
|
|
|
}
|