Abstracted cycler tool methods to BlockData and optimized them slightly, as well as adding support for many new blocks.

This commit is contained in:
Wizjany
2011-09-17 01:34:55 -04:00
parent b10498b9c7
commit ece3934994
2 changed files with 171 additions and 98 deletions

View File

@ -20,7 +20,7 @@
package com.sk89q.worldedit.tools;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.blocks.BlockID;
import com.sk89q.worldedit.data.BlockData;
/**
* A mode that cycles the data values of supported blocks.
@ -49,59 +49,11 @@ public class BlockDataCyler implements DoubleActionBlockTool {
}
int increment = forward ? 1 : -1;
if (type == BlockID.LOG) {
data = (data + increment) % 3;
} else if (type == BlockID.LEAVES) {
data = (data + increment) % 3;
} else if (type == BlockID.SAPLING) {
int saplingType = data & 0x03;
int age = data & 0x0c;
data = (saplingType + increment) % 4 | age;
} else if (type == BlockID.CACTUS) {
data = (data + increment) % 16;
} else if (type == BlockID.SOIL) {
data = (data + increment) % 9;
} else if (type == BlockID.CROPS) {
data = (data + increment) % 6;
} else if (type == BlockID.MINECART_TRACKS) {
if (data >= 6 && data <= 9) {
data = (data + increment) % 4 + 6;
} else {
player.printError("This minecart track orientation is not supported.");
return true;
}
} else if (type == BlockID.WOODEN_STAIRS
|| type == BlockID.COBBLESTONE_STAIRS
|| type == BlockID.BRICK_STAIRS
|| type == BlockID.STONE_BRICK_STAIRS) {
data = (data + increment) % 4;
} else if (type == BlockID.SIGN_POST) {
data = (data + increment) % 16;
} else if (type == BlockID.WALL_SIGN) {
data = ((data + increment) - 2) % 4 + 2;
} else if (type == BlockID.STEP) {
data = (data + increment) % 6;
} else if (type == BlockID.DOUBLE_STEP) {
data = (data + increment) % 6;
} else if (type == BlockID.FURNACE || type == BlockID.BURNING_FURNACE
|| type == BlockID.DISPENSER) {
data = (data + increment) % 4 + 2;
} else if (type == BlockID.PUMPKIN || type == BlockID.JACKOLANTERN) {
data = (data + increment) % 4;
} else if (type == BlockID.CLOTH) {
if (forward) {
data = nextClothColor(data);
} else {
data = prevClothColor(data);
}
} else if (type == BlockID.RED_MUSHROOM_CAP || type == BlockID.BROWN_MUSHROOM_CAP) {
data = (data + increment) % 2;
} else {
player.printError("That block's data cannot be cycled.");
data = BlockData.cycle(type, data, increment);
if (data < 0) {
player.printError("That block's data cannot be cycled!");
return true;
}
world.setBlockData(clicked, data);
return true;
@ -117,50 +69,5 @@ public class BlockDataCyler implements DoubleActionBlockTool {
LocalSession session, WorldVector clicked) {
return handleCycle(server, config, player, session, clicked, false);
}
private 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;
}
private 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;
}
}