2011-01-30 07:10:12 +00:00
|
|
|
// $Id$
|
|
|
|
/*
|
|
|
|
* WorldEdit
|
|
|
|
* Copyright (C) 2010, 2011 sk89q <http://www.sk89q.com>
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package com.sk89q.worldedit.data;
|
|
|
|
|
2011-08-26 10:41:31 +00:00
|
|
|
import com.sk89q.worldedit.CuboidClipboard.FlipDirection;
|
2011-01-30 07:10:12 +00:00
|
|
|
import com.sk89q.worldedit.blocks.BlockID;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Block data related classes.
|
|
|
|
*
|
|
|
|
* @author sk89q
|
|
|
|
*/
|
|
|
|
public final class BlockData {
|
|
|
|
/**
|
|
|
|
* Rotate a block's data value 90 degrees (north->east->south->west->north);
|
|
|
|
*
|
|
|
|
* @param type
|
|
|
|
* @param data
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public static int rotate90(int type, int data) {
|
2011-08-26 10:41:31 +00:00
|
|
|
switch (type) {
|
|
|
|
case BlockID.TORCH:
|
|
|
|
case BlockID.REDSTONE_TORCH_OFF:
|
|
|
|
case BlockID.REDSTONE_TORCH_ON:
|
2011-01-30 07:10:12 +00:00
|
|
|
switch (data) {
|
2011-08-26 10:41:31 +00:00
|
|
|
case 1: return 3;
|
|
|
|
case 2: return 4;
|
|
|
|
case 3: return 2;
|
|
|
|
case 4: return 1;
|
2011-01-30 07:10:12 +00:00
|
|
|
}
|
2011-08-26 10:41:31 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BlockID.MINECART_TRACKS:
|
2011-01-30 07:10:12 +00:00
|
|
|
switch (data) {
|
2011-08-26 10:41:31 +00:00
|
|
|
case 6: return 7;
|
|
|
|
case 7: return 8;
|
|
|
|
case 8: return 9;
|
|
|
|
case 9: return 6;
|
|
|
|
}
|
|
|
|
/* FALL-THROUGH */
|
|
|
|
|
|
|
|
case BlockID.POWERED_RAIL:
|
|
|
|
case BlockID.DETECTOR_RAIL:
|
|
|
|
switch (data & 0x7) {
|
2011-09-25 04:01:01 +00:00
|
|
|
case 0: return 1 | (data & ~0x7);
|
|
|
|
case 1: return 0 | (data & ~0x7);
|
|
|
|
case 2: return 5 | (data & ~0x7);
|
|
|
|
case 3: return 4 | (data & ~0x7);
|
|
|
|
case 4: return 2 | (data & ~0x7);
|
|
|
|
case 5: return 3 | (data & ~0x7);
|
2011-01-30 07:10:12 +00:00
|
|
|
}
|
2011-08-26 10:41:31 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BlockID.WOODEN_STAIRS:
|
|
|
|
case BlockID.COBBLESTONE_STAIRS:
|
2011-09-25 04:01:01 +00:00
|
|
|
case BlockID.BRICK_STAIRS:
|
|
|
|
case BlockID.STONE_BRICK_STAIRS:
|
2011-01-30 07:10:12 +00:00
|
|
|
switch (data) {
|
2011-08-26 10:41:31 +00:00
|
|
|
case 0: return 2;
|
|
|
|
case 1: return 3;
|
|
|
|
case 2: return 1;
|
|
|
|
case 3: return 0;
|
2011-01-30 07:10:12 +00:00
|
|
|
}
|
2011-08-26 10:41:31 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BlockID.LEVER:
|
|
|
|
case BlockID.STONE_BUTTON:
|
2011-01-30 07:10:12 +00:00
|
|
|
int thrown = data & 0x8;
|
2011-08-26 10:41:31 +00:00
|
|
|
int withoutThrown = data & ~0x8;
|
2011-01-30 07:10:12 +00:00
|
|
|
switch (withoutThrown) {
|
2011-08-26 10:41:31 +00:00
|
|
|
case 1: return 3 | thrown;
|
|
|
|
case 2: return 4 | thrown;
|
|
|
|
case 3: return 2 | thrown;
|
|
|
|
case 4: return 1 | thrown;
|
2011-01-30 07:10:12 +00:00
|
|
|
}
|
2011-08-26 10:41:31 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BlockID.WOODEN_DOOR:
|
|
|
|
case BlockID.IRON_DOOR:
|
2011-01-30 07:10:12 +00:00
|
|
|
int topHalf = data & 0x8;
|
|
|
|
int swung = data & 0x4;
|
2011-08-26 10:41:31 +00:00
|
|
|
int withoutFlags = data & ~(0x8 | 0x4);
|
2011-01-30 07:10:12 +00:00
|
|
|
switch (withoutFlags) {
|
2011-08-26 10:41:31 +00:00
|
|
|
case 0: return 1 | topHalf | swung;
|
|
|
|
case 1: return 2 | topHalf | swung;
|
|
|
|
case 2: return 3 | topHalf | swung;
|
|
|
|
case 3: return 0 | topHalf | swung;
|
2011-01-30 07:10:12 +00:00
|
|
|
}
|
2011-08-26 10:41:31 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BlockID.SIGN_POST:
|
2011-01-30 07:10:12 +00:00
|
|
|
return (data + 4) % 16;
|
2011-08-26 10:41:31 +00:00
|
|
|
|
|
|
|
case BlockID.LADDER:
|
|
|
|
case BlockID.WALL_SIGN:
|
|
|
|
case BlockID.FURNACE:
|
|
|
|
case BlockID.BURNING_FURNACE:
|
|
|
|
case BlockID.DISPENSER:
|
2011-01-30 07:10:12 +00:00
|
|
|
switch (data) {
|
2011-08-26 10:41:31 +00:00
|
|
|
case 2: return 5;
|
|
|
|
case 3: return 4;
|
|
|
|
case 4: return 2;
|
|
|
|
case 5: return 3;
|
2011-01-30 07:10:12 +00:00
|
|
|
}
|
2011-08-26 10:41:31 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BlockID.PUMPKIN:
|
|
|
|
case BlockID.JACKOLANTERN:
|
2011-01-30 07:10:12 +00:00
|
|
|
switch (data) {
|
2011-08-26 10:41:31 +00:00
|
|
|
case 0: return 1;
|
|
|
|
case 1: return 2;
|
|
|
|
case 2: return 3;
|
|
|
|
case 3: return 0;
|
2011-01-30 07:10:12 +00:00
|
|
|
}
|
2011-08-26 10:41:31 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BlockID.REDSTONE_REPEATER_OFF:
|
|
|
|
case BlockID.REDSTONE_REPEATER_ON:
|
2011-06-04 05:51:42 +00:00
|
|
|
int dir = data & 0x03;
|
|
|
|
int delay = data - dir;
|
|
|
|
switch (dir) {
|
2011-08-26 10:41:31 +00:00
|
|
|
case 0: return 1 | delay;
|
|
|
|
case 1: return 2 | delay;
|
|
|
|
case 2: return 3 | delay;
|
|
|
|
case 3: return 0 | delay;
|
2011-06-04 05:51:42 +00:00
|
|
|
}
|
2011-08-26 10:41:31 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BlockID.TRAP_DOOR:
|
2011-06-01 02:43:48 +00:00
|
|
|
int open = data & 0x4;
|
2011-08-26 10:41:31 +00:00
|
|
|
int withoutOpen = data & ~0x4;
|
2011-06-01 02:43:48 +00:00
|
|
|
switch (withoutOpen) {
|
2011-08-26 10:41:31 +00:00
|
|
|
case 0: return 3 | open;
|
|
|
|
case 1: return 2 | open;
|
|
|
|
case 2: return 0 | open;
|
|
|
|
case 3: return 1 | open;
|
2011-06-01 02:43:48 +00:00
|
|
|
}
|
2011-09-24 19:24:10 +00:00
|
|
|
break;
|
2011-09-23 13:15:43 +00:00
|
|
|
|
2011-08-26 10:41:31 +00:00
|
|
|
case BlockID.PISTON_BASE:
|
|
|
|
case BlockID.PISTON_STICKY_BASE:
|
|
|
|
case BlockID.PISTON_EXTENSION:
|
2011-09-24 01:00:10 +00:00
|
|
|
final int rest = data & ~0x7;
|
|
|
|
switch (data & 0x7) {
|
|
|
|
case 2: return 5 | rest;
|
|
|
|
case 3: return 4 | rest;
|
|
|
|
case 4: return 2 | rest;
|
|
|
|
case 5: return 3 | rest;
|
2011-09-23 13:15:43 +00:00
|
|
|
}
|
2011-09-24 19:24:10 +00:00
|
|
|
break;
|
2011-09-23 13:15:43 +00:00
|
|
|
|
|
|
|
case BlockID.BROWN_MUSHROOM_CAP:
|
|
|
|
case BlockID.RED_MUSHROOM_CAP:
|
2011-09-24 19:24:10 +00:00
|
|
|
if (data >= 10) return data;
|
2011-09-23 13:15:43 +00:00
|
|
|
return (data * 3) % 10;
|
|
|
|
|
|
|
|
case BlockID.VINE:
|
|
|
|
return ((data << 1) | (data >> 3)) & 0xf;
|
|
|
|
|
|
|
|
case BlockID.FENCE_GATE:
|
2011-09-24 19:24:10 +00:00
|
|
|
return ((data + 1) & 0x3) | (data & ~0x3);
|
2011-09-23 13:15:43 +00:00
|
|
|
|
2011-01-30 07:10:12 +00:00
|
|
|
}
|
2011-08-26 10:41:31 +00:00
|
|
|
|
2011-01-30 07:10:12 +00:00
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Rotate a block's data value -90 degrees (north<-east<-south<-west<-north);
|
|
|
|
*
|
|
|
|
* @param type
|
|
|
|
* @param data
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public static int rotate90Reverse(int type, int data) {
|
|
|
|
// case ([0-9]+): return ([0-9]+) -> case \2: return \1
|
2011-08-26 10:41:31 +00:00
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case BlockID.TORCH:
|
|
|
|
case BlockID.REDSTONE_TORCH_OFF:
|
|
|
|
case BlockID.REDSTONE_TORCH_ON:
|
2011-01-30 07:10:12 +00:00
|
|
|
switch (data) {
|
2011-08-26 10:41:31 +00:00
|
|
|
case 3: return 1;
|
|
|
|
case 4: return 2;
|
|
|
|
case 2: return 3;
|
|
|
|
case 1: return 4;
|
2011-01-30 07:10:12 +00:00
|
|
|
}
|
2011-08-26 10:41:31 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BlockID.MINECART_TRACKS:
|
2011-01-30 07:10:12 +00:00
|
|
|
switch (data) {
|
2011-08-26 10:41:31 +00:00
|
|
|
case 7: return 6;
|
|
|
|
case 8: return 7;
|
|
|
|
case 9: return 8;
|
|
|
|
case 6: return 9;
|
2011-01-30 07:10:12 +00:00
|
|
|
}
|
2011-08-26 10:41:31 +00:00
|
|
|
/* FALL-THROUGH */
|
|
|
|
|
|
|
|
case BlockID.POWERED_RAIL:
|
|
|
|
case BlockID.DETECTOR_RAIL:
|
|
|
|
switch (data & 0x7) {
|
2011-09-25 04:01:01 +00:00
|
|
|
case 1: return 0 | (data & ~0x7);
|
|
|
|
case 0: return 1 | (data & ~0x7);
|
|
|
|
case 5: return 2 | (data & ~0x7);
|
|
|
|
case 4: return 3 | (data & ~0x7);
|
|
|
|
case 2: return 4 | (data & ~0x7);
|
|
|
|
case 3: return 5 | (data & ~0x7);
|
2011-08-26 10:41:31 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BlockID.WOODEN_STAIRS:
|
|
|
|
case BlockID.COBBLESTONE_STAIRS:
|
2011-09-25 04:01:01 +00:00
|
|
|
case BlockID.BRICK_STAIRS:
|
|
|
|
case BlockID.STONE_BRICK_STAIRS:
|
2011-01-30 07:10:12 +00:00
|
|
|
switch (data) {
|
2011-08-26 10:41:31 +00:00
|
|
|
case 2: return 0;
|
|
|
|
case 3: return 1;
|
|
|
|
case 1: return 2;
|
|
|
|
case 0: return 3;
|
2011-01-30 07:10:12 +00:00
|
|
|
}
|
2011-08-26 10:41:31 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BlockID.LEVER:
|
|
|
|
case BlockID.STONE_BUTTON:
|
2011-01-30 07:10:12 +00:00
|
|
|
int thrown = data & 0x8;
|
2011-08-26 10:41:31 +00:00
|
|
|
int withoutThrown = data & ~0x8;
|
2011-01-30 07:10:12 +00:00
|
|
|
switch (withoutThrown) {
|
2011-08-26 10:41:31 +00:00
|
|
|
case 3: return 1 | thrown;
|
|
|
|
case 4: return 2 | thrown;
|
|
|
|
case 2: return 3 | thrown;
|
|
|
|
case 1: return 4 | thrown;
|
2011-01-30 07:10:12 +00:00
|
|
|
}
|
2011-08-26 10:41:31 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BlockID.WOODEN_DOOR:
|
|
|
|
case BlockID.IRON_DOOR:
|
2011-01-30 07:10:12 +00:00
|
|
|
int topHalf = data & 0x8;
|
|
|
|
int swung = data & 0x4;
|
2011-08-26 10:41:31 +00:00
|
|
|
int withoutFlags = data & ~(0x8 | 0x4);
|
2011-01-30 07:10:12 +00:00
|
|
|
switch (withoutFlags) {
|
2011-08-26 10:41:31 +00:00
|
|
|
case 1: return 0 | topHalf | swung;
|
|
|
|
case 2: return 1 | topHalf | swung;
|
|
|
|
case 3: return 2 | topHalf | swung;
|
|
|
|
case 0: return 3 | topHalf | swung;
|
2011-01-30 07:10:12 +00:00
|
|
|
}
|
2011-08-26 10:41:31 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BlockID.SIGN_POST:
|
|
|
|
return (data + 12) % 16;
|
|
|
|
|
|
|
|
case BlockID.LADDER:
|
|
|
|
case BlockID.WALL_SIGN:
|
|
|
|
case BlockID.FURNACE:
|
|
|
|
case BlockID.BURNING_FURNACE:
|
|
|
|
case BlockID.DISPENSER:
|
2011-01-30 07:10:12 +00:00
|
|
|
switch (data) {
|
2011-08-26 10:41:31 +00:00
|
|
|
case 5: return 2;
|
|
|
|
case 4: return 3;
|
|
|
|
case 2: return 4;
|
|
|
|
case 3: return 5;
|
2011-01-30 07:10:12 +00:00
|
|
|
}
|
2011-08-26 10:41:31 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BlockID.PUMPKIN:
|
|
|
|
case BlockID.JACKOLANTERN:
|
2011-01-30 07:10:12 +00:00
|
|
|
switch (data) {
|
2011-08-26 10:41:31 +00:00
|
|
|
case 1: return 0;
|
|
|
|
case 2: return 1;
|
|
|
|
case 3: return 2;
|
|
|
|
case 0: return 3;
|
2011-01-30 07:10:12 +00:00
|
|
|
}
|
2011-08-26 10:41:31 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BlockID.REDSTONE_REPEATER_OFF:
|
|
|
|
case BlockID.REDSTONE_REPEATER_ON:
|
2011-06-04 05:51:42 +00:00
|
|
|
int dir = data & 0x03;
|
2011-08-26 10:41:31 +00:00
|
|
|
int delay = data - dir;
|
2011-06-04 05:51:42 +00:00
|
|
|
switch (dir) {
|
2011-08-26 10:41:31 +00:00
|
|
|
case 1: return 0 | delay;
|
|
|
|
case 2: return 1 | delay;
|
|
|
|
case 3: return 2 | delay;
|
|
|
|
case 0: return 3 | delay;
|
2011-06-04 05:51:42 +00:00
|
|
|
}
|
2011-08-26 10:41:31 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BlockID.TRAP_DOOR:
|
2011-06-01 02:43:48 +00:00
|
|
|
int open = data & 0x4;
|
2011-08-26 10:41:31 +00:00
|
|
|
int withoutOpen = data & ~0x4;
|
2011-06-01 02:43:48 +00:00
|
|
|
switch (withoutOpen) {
|
2011-08-26 10:41:31 +00:00
|
|
|
case 3: return 0 | open;
|
|
|
|
case 2: return 1 | open;
|
|
|
|
case 0: return 2 | open;
|
|
|
|
case 1: return 3 | open;
|
|
|
|
}
|
2011-09-23 13:15:43 +00:00
|
|
|
|
2011-08-26 10:41:31 +00:00
|
|
|
case BlockID.PISTON_BASE:
|
|
|
|
case BlockID.PISTON_STICKY_BASE:
|
|
|
|
case BlockID.PISTON_EXTENSION:
|
2011-09-24 01:00:10 +00:00
|
|
|
final int rest = data & ~0x7;
|
|
|
|
switch (data & 0x7) {
|
|
|
|
case 5: return 2 | rest;
|
|
|
|
case 4: return 3 | rest;
|
|
|
|
case 2: return 4 | rest;
|
|
|
|
case 3: return 5 | rest;
|
2011-06-01 02:43:48 +00:00
|
|
|
}
|
2011-09-24 19:24:10 +00:00
|
|
|
break;
|
2011-09-23 13:15:43 +00:00
|
|
|
|
|
|
|
case BlockID.BROWN_MUSHROOM_CAP:
|
|
|
|
case BlockID.RED_MUSHROOM_CAP:
|
2011-09-24 19:24:10 +00:00
|
|
|
if (data >= 10) return data;
|
2011-09-23 13:15:43 +00:00
|
|
|
return (data * 7) % 10;
|
|
|
|
|
|
|
|
case BlockID.VINE:
|
|
|
|
return ((data >> 1) | (data << 3)) & 0xf;
|
|
|
|
|
|
|
|
case BlockID.FENCE_GATE:
|
2011-09-24 19:24:10 +00:00
|
|
|
return ((data + 3) & 0x3) | (data & ~0x3);
|
2011-01-30 07:10:12 +00:00
|
|
|
}
|
2011-08-26 10:41:31 +00:00
|
|
|
|
2011-01-30 07:10:12 +00:00
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Flip a block's data value.
|
2011-09-03 16:54:20 +00:00
|
|
|
*
|
|
|
|
* @param type
|
|
|
|
* @param data
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public static int flip(int type, int data) {
|
|
|
|
return rotate90(type, rotate90(type, data));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Flip a block's data value.
|
2011-01-30 07:10:12 +00:00
|
|
|
*
|
|
|
|
* @param type
|
|
|
|
* @param data
|
2011-08-26 10:41:31 +00:00
|
|
|
* @param direction
|
2011-01-30 07:10:12 +00:00
|
|
|
* @return
|
|
|
|
*/
|
2011-08-26 10:41:31 +00:00
|
|
|
public static int flip(int type, int data, FlipDirection direction) {
|
|
|
|
int flipX = 0;
|
|
|
|
int flipY = 0;
|
|
|
|
int flipZ = 0;
|
|
|
|
|
|
|
|
switch (direction) {
|
|
|
|
case NORTH_SOUTH:
|
|
|
|
flipX = 1;
|
|
|
|
break;
|
2011-09-25 03:15:20 +00:00
|
|
|
|
2011-08-26 10:41:31 +00:00
|
|
|
case WEST_EAST:
|
2011-09-23 04:44:31 +00:00
|
|
|
flipZ = 1;
|
2011-08-26 10:41:31 +00:00
|
|
|
break;
|
2011-09-25 03:15:20 +00:00
|
|
|
|
2011-08-26 10:41:31 +00:00
|
|
|
case UP_DOWN:
|
2011-09-23 04:44:31 +00:00
|
|
|
flipY = 1;
|
2011-08-26 10:41:31 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case BlockID.TORCH:
|
|
|
|
case BlockID.REDSTONE_TORCH_OFF:
|
|
|
|
case BlockID.REDSTONE_TORCH_ON:
|
|
|
|
case BlockID.LEVER:
|
|
|
|
case BlockID.STONE_BUTTON:
|
|
|
|
switch (data & ~0x8) {
|
|
|
|
case 1: return data + flipX;
|
|
|
|
case 2: return data - flipX;
|
2011-09-23 04:44:31 +00:00
|
|
|
case 3: return data + flipZ;
|
|
|
|
case 4: return data - flipZ;
|
2011-08-26 10:41:31 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BlockID.MINECART_TRACKS:
|
|
|
|
switch (data) {
|
2011-09-24 19:24:10 +00:00
|
|
|
case 6: return data + flipX + flipZ * 3;
|
|
|
|
case 7: return data - flipX + flipZ;
|
|
|
|
case 8: return data + flipX - flipZ;
|
|
|
|
case 9: return data - flipX - flipZ * 3;
|
2011-08-26 10:41:31 +00:00
|
|
|
}
|
|
|
|
/* FALL-THROUGH */
|
|
|
|
|
|
|
|
case BlockID.POWERED_RAIL:
|
|
|
|
case BlockID.DETECTOR_RAIL:
|
|
|
|
switch (data & 0x7) {
|
|
|
|
case 0:
|
|
|
|
case 1:
|
|
|
|
return data;
|
2011-09-25 03:15:20 +00:00
|
|
|
|
2011-08-26 10:41:31 +00:00
|
|
|
case 2:
|
|
|
|
case 3:
|
|
|
|
return data ^ flipX;
|
2011-09-25 03:15:20 +00:00
|
|
|
|
2011-08-26 10:41:31 +00:00
|
|
|
case 4:
|
|
|
|
case 5:
|
2011-09-23 04:44:31 +00:00
|
|
|
return data ^ flipZ;
|
2011-08-26 10:41:31 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BlockID.WOODEN_STAIRS:
|
|
|
|
case BlockID.COBBLESTONE_STAIRS:
|
2011-09-23 04:44:31 +00:00
|
|
|
case BlockID.BRICK_STAIRS:
|
|
|
|
case BlockID.STONE_BRICK_STAIRS:
|
2011-08-26 10:41:31 +00:00
|
|
|
switch (data) {
|
|
|
|
case 0:
|
|
|
|
case 1:
|
|
|
|
return data ^ flipX;
|
2011-09-25 03:15:20 +00:00
|
|
|
|
2011-08-26 10:41:31 +00:00
|
|
|
case 2:
|
|
|
|
case 3:
|
2011-09-23 04:44:31 +00:00
|
|
|
return data ^ flipZ;
|
2011-08-26 10:41:31 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BlockID.WOODEN_DOOR:
|
|
|
|
case BlockID.IRON_DOOR:
|
2011-09-23 04:44:31 +00:00
|
|
|
data ^= flipY << 3;
|
2011-08-26 10:41:31 +00:00
|
|
|
switch (data & 0x3) {
|
2011-09-24 19:24:10 +00:00
|
|
|
case 0: return data + flipX + flipZ * 3;
|
|
|
|
case 1: return data - flipX + flipZ;
|
|
|
|
case 2: return data + flipX - flipZ;
|
|
|
|
case 3: return data - flipX - flipZ * 3;
|
2011-08-26 10:41:31 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BlockID.SIGN_POST:
|
2011-08-26 14:48:31 +00:00
|
|
|
switch (direction) {
|
|
|
|
case NORTH_SOUTH:
|
2011-09-24 19:24:10 +00:00
|
|
|
return (16 - data) & 0xf;
|
2011-09-25 03:15:20 +00:00
|
|
|
|
2011-08-26 14:48:31 +00:00
|
|
|
case WEST_EAST:
|
2011-09-24 19:24:10 +00:00
|
|
|
return (8 - data) & 0xf;
|
2011-08-26 14:48:31 +00:00
|
|
|
}
|
|
|
|
break;
|
2011-08-26 10:41:31 +00:00
|
|
|
|
|
|
|
case BlockID.LADDER:
|
|
|
|
case BlockID.WALL_SIGN:
|
|
|
|
case BlockID.FURNACE:
|
|
|
|
case BlockID.BURNING_FURNACE:
|
|
|
|
case BlockID.DISPENSER:
|
|
|
|
switch (data) {
|
|
|
|
case 2:
|
|
|
|
case 3:
|
2011-09-23 04:44:31 +00:00
|
|
|
return data ^ flipZ;
|
2011-09-25 03:15:20 +00:00
|
|
|
|
2011-08-26 10:41:31 +00:00
|
|
|
case 4:
|
|
|
|
case 5:
|
|
|
|
return data ^ flipX;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BlockID.PUMPKIN:
|
|
|
|
case BlockID.JACKOLANTERN:
|
|
|
|
case BlockID.REDSTONE_REPEATER_OFF:
|
|
|
|
case BlockID.REDSTONE_REPEATER_ON:
|
|
|
|
switch (data & 0x3) {
|
|
|
|
case 0:
|
|
|
|
case 2:
|
2011-09-24 19:24:10 +00:00
|
|
|
return data ^ (flipZ << 1);
|
2011-09-25 03:15:20 +00:00
|
|
|
|
2011-08-26 10:41:31 +00:00
|
|
|
case 1:
|
|
|
|
case 3:
|
2011-09-24 19:24:10 +00:00
|
|
|
return data ^ (flipX << 1);
|
2011-08-26 10:41:31 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BlockID.TRAP_DOOR:
|
|
|
|
switch (data & 0x3) {
|
|
|
|
case 0:
|
|
|
|
case 1:
|
2011-09-23 04:44:31 +00:00
|
|
|
return data ^ flipZ;
|
2011-09-25 03:15:20 +00:00
|
|
|
|
2011-08-26 10:41:31 +00:00
|
|
|
case 2:
|
|
|
|
case 3:
|
|
|
|
return data ^ flipX;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BlockID.PISTON_BASE:
|
|
|
|
case BlockID.PISTON_STICKY_BASE:
|
|
|
|
case BlockID.PISTON_EXTENSION:
|
2011-09-23 04:44:31 +00:00
|
|
|
switch (data & ~0x8) {
|
2011-08-26 10:41:31 +00:00
|
|
|
case 0:
|
|
|
|
case 1:
|
2011-09-23 04:44:31 +00:00
|
|
|
return data ^ flipY;
|
2011-09-25 03:15:20 +00:00
|
|
|
|
2011-08-26 10:41:31 +00:00
|
|
|
case 2:
|
|
|
|
case 3:
|
2011-09-23 04:44:31 +00:00
|
|
|
return data ^ flipZ;
|
2011-09-25 03:15:20 +00:00
|
|
|
|
2011-08-26 10:41:31 +00:00
|
|
|
case 4:
|
|
|
|
case 5:
|
|
|
|
return data ^ flipX;
|
|
|
|
}
|
2011-09-23 04:44:31 +00:00
|
|
|
break;
|
2011-09-23 11:43:05 +00:00
|
|
|
|
|
|
|
case BlockID.RED_MUSHROOM_CAP:
|
|
|
|
case BlockID.BROWN_MUSHROOM_CAP:
|
|
|
|
switch (data) {
|
|
|
|
case 1:
|
|
|
|
case 4:
|
|
|
|
case 7:
|
2011-09-25 03:15:20 +00:00
|
|
|
data += flipX * 2;
|
2011-09-23 11:43:05 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
case 6:
|
|
|
|
case 9:
|
2011-09-25 03:15:20 +00:00
|
|
|
data -= flipX * 2;
|
2011-09-23 11:43:05 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
switch (data) {
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
case 3:
|
2011-09-25 03:15:20 +00:00
|
|
|
return data + flipZ * 6;
|
2011-09-23 11:43:05 +00:00
|
|
|
case 7:
|
|
|
|
case 8:
|
|
|
|
case 9:
|
2011-09-25 03:15:20 +00:00
|
|
|
return data - flipZ * 6;
|
2011-09-23 11:43:05 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BlockID.VINE:
|
|
|
|
final int bit1, bit2;
|
|
|
|
switch (direction) {
|
|
|
|
case NORTH_SOUTH:
|
|
|
|
bit1 = 0x2;
|
|
|
|
bit2 = 0x8;
|
|
|
|
break;
|
2011-09-25 03:15:20 +00:00
|
|
|
|
2011-09-23 11:43:05 +00:00
|
|
|
case WEST_EAST:
|
|
|
|
bit1 = 0x1;
|
|
|
|
bit2 = 0x4;
|
|
|
|
break;
|
2011-09-25 03:15:20 +00:00
|
|
|
|
2011-09-23 11:43:05 +00:00
|
|
|
default:
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
int newData = data & ~(bit1 | bit2);
|
|
|
|
if ((data & bit1) != 0) newData |= bit2;
|
|
|
|
if ((data & bit2) != 0) newData |= bit1;
|
|
|
|
|
|
|
|
return newData;
|
|
|
|
|
|
|
|
case BlockID.FENCE_GATE:
|
|
|
|
switch (data & 0x3) {
|
|
|
|
case 0:
|
|
|
|
case 2:
|
2011-09-25 03:15:20 +00:00
|
|
|
return data ^ flipZ * 2;
|
|
|
|
|
2011-09-23 11:43:05 +00:00
|
|
|
case 1:
|
|
|
|
case 3:
|
2011-09-25 03:15:20 +00:00
|
|
|
return data ^ flipX * 2;
|
2011-09-23 11:43:05 +00:00
|
|
|
}
|
|
|
|
break;
|
2011-08-26 10:41:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return data;
|
2011-01-30 07:10:12 +00:00
|
|
|
}
|
2011-09-17 05:34:55 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Cycle a block's data value. This usually goes through some rotational pattern
|
|
|
|
* depending on the block. If it returns -1, it means the id and data specified
|
|
|
|
* do not have anything to cycle to.
|
|
|
|
*
|
|
|
|
* @param type block id to be cycled
|
|
|
|
* @param data block data value that it starts at
|
|
|
|
* @param increment whether to go forward (1) or backward (-1) in the cycle
|
|
|
|
* @return the new data value for the block
|
|
|
|
*/
|
|
|
|
public static int cycle(int type, int data, int increment) {
|
|
|
|
switch (type) {
|
|
|
|
case BlockID.LOG:
|
|
|
|
case BlockID.LONG_GRASS:
|
|
|
|
case BlockID.STONE_BRICK:
|
2011-09-17 18:11:59 +00:00
|
|
|
case BlockID.SILVERFISH_BLOCK:
|
2011-09-17 05:34:55 +00:00
|
|
|
return (data + increment) % 3;
|
|
|
|
|
|
|
|
case BlockID.TORCH:
|
|
|
|
case BlockID.REDSTONE_TORCH_ON:
|
|
|
|
case BlockID.REDSTONE_TORCH_OFF:
|
|
|
|
if (data == 5) return -1;
|
|
|
|
/* FALL-THROUGH */
|
|
|
|
case BlockID.WOODEN_STAIRS:
|
|
|
|
case BlockID.COBBLESTONE_STAIRS:
|
|
|
|
case BlockID.BRICK_STAIRS:
|
|
|
|
case BlockID.STONE_BRICK_STAIRS:
|
|
|
|
case BlockID.PUMPKIN:
|
|
|
|
case BlockID.JACKOLANTERN:
|
|
|
|
case BlockID.TRAP_DOOR:
|
|
|
|
return (data + increment) % 4;
|
|
|
|
|
|
|
|
case BlockID.STEP:
|
|
|
|
case BlockID.DOUBLE_STEP:
|
|
|
|
case BlockID.CAKE_BLOCK:
|
|
|
|
return (data + increment) % 6;
|
|
|
|
|
|
|
|
case BlockID.CROPS:
|
|
|
|
case BlockID.PUMPKIN_STEM:
|
|
|
|
case BlockID.MELON_STEM:
|
|
|
|
return (data + increment) % 7;
|
|
|
|
|
|
|
|
case BlockID.SOIL:
|
|
|
|
case BlockID.SNOW:
|
|
|
|
return (data + increment) % 9;
|
|
|
|
|
|
|
|
case BlockID.RED_MUSHROOM_CAP:
|
|
|
|
case BlockID.BROWN_MUSHROOM_CAP:
|
|
|
|
return (data + increment) % 10;
|
|
|
|
|
|
|
|
case BlockID.CACTUS:
|
|
|
|
case BlockID.REED:
|
|
|
|
case BlockID.SIGN_POST:
|
|
|
|
return (data + increment) % 16;
|
|
|
|
|
|
|
|
case BlockID.VINE:
|
|
|
|
return (data - 1 + increment) % 15 + 1;
|
|
|
|
|
|
|
|
case BlockID.FURNACE:
|
|
|
|
case BlockID.BURNING_FURNACE:
|
|
|
|
case BlockID.DISPENSER:
|
|
|
|
return (data + increment) % 4 + 2;
|
|
|
|
|
|
|
|
case BlockID.WALL_SIGN:
|
|
|
|
return ((data + increment) - 2) % 4 + 2;
|
|
|
|
|
|
|
|
case BlockID.REDSTONE_REPEATER_OFF:
|
|
|
|
case BlockID.REDSTONE_REPEATER_ON:
|
|
|
|
int dir = data & 0x3;
|
|
|
|
int delay = data & 0x0c;
|
|
|
|
return (dir + increment) % 4 | delay;
|
|
|
|
|
|
|
|
case BlockID.MINECART_TRACKS:
|
|
|
|
if (data >= 6 && data <= 9) {
|
|
|
|
return (data + increment) % 4 + 6;
|
|
|
|
} else {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
case BlockID.SAPLING:
|
|
|
|
int saplingType = data & 0x02;
|
|
|
|
int age = data & 0x0c;
|
|
|
|
return (saplingType + increment) % 3 | age;
|
|
|
|
|
|
|
|
case BlockID.LEAVES:
|
|
|
|
int tree = data & 0x03;
|
|
|
|
int leafMeta = data & 0x0c;
|
|
|
|
return (tree + increment) % 4 | leafMeta;
|
|
|
|
|
|
|
|
case BlockID.CLOTH:
|
|
|
|
if (increment > 0) {
|
|
|
|
data = nextClothColor(data);
|
|
|
|
} else if (increment < 0) {
|
|
|
|
data = prevClothColor(data);
|
|
|
|
} else {
|
|
|
|
return -1; // shouldn't have a 0 increment anyway
|
|
|
|
}
|
|
|
|
return data;
|
|
|
|
|
|
|
|
case BlockID.FENCE_GATE:
|
|
|
|
int direction = data & 0x03;
|
|
|
|
int open = data & 0x04;
|
|
|
|
return (direction + increment) % 4 | open;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the data value for the next color of cloth in the rainbow. This
|
|
|
|
* should not be used if you want to just increment the data value.
|
|
|
|
* @param data
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public static int nextClothColor(int data) {
|
|
|
|
switch (data) {
|
|
|
|
case 0: return 8;
|
|
|
|
case 8: return 7;
|
|
|
|
case 7: return 15;
|
|
|
|
case 15: return 12;
|
|
|
|
case 12: return 14;
|
|
|
|
case 14: return 1;
|
|
|
|
case 1: return 4;
|
|
|
|
case 4: return 5;
|
|
|
|
case 5: return 13;
|
|
|
|
case 13: return 9;
|
|
|
|
case 9: return 3;
|
|
|
|
case 3: return 11;
|
|
|
|
case 11: return 10;
|
|
|
|
case 10: return 2;
|
|
|
|
case 2: return 6;
|
|
|
|
case 6: return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the data value for the previous ext color of cloth in the rainbow.
|
|
|
|
* This should not be used if you want to just increment the data value.
|
|
|
|
* @param data
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public static int prevClothColor(int data) {
|
|
|
|
switch (data) {
|
|
|
|
case 8: return 0;
|
|
|
|
case 7: return 8;
|
|
|
|
case 15: return 7;
|
|
|
|
case 12: return 15;
|
|
|
|
case 14: return 12;
|
|
|
|
case 1: return 14;
|
|
|
|
case 4: return 1;
|
|
|
|
case 5: return 4;
|
|
|
|
case 13: return 5;
|
|
|
|
case 9: return 13;
|
|
|
|
case 3: return 9;
|
|
|
|
case 11: return 3;
|
|
|
|
case 10: return 11;
|
|
|
|
case 2: return 10;
|
|
|
|
case 6: return 2;
|
|
|
|
case 0: return 6;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2011-01-30 07:10:12 +00:00
|
|
|
}
|