Adjusted some of the cycler code and added a test case for it.

- Added range checks for most blocks
- torches: Fixed cycle from 0->1->2->3->0 to 1->2->3->4->1
- mushroom caps: Included data value 10 (stem) in cycle
- vines: Included data value 0 (top attachment only) in the cycle
- furnaces/dispensers: Linearised the cycle. It's now 2->3->4->5->2
- chests/ladders: Added cycle code.
- rails: Linearised the cycle. It's now 6->7->8->9->6
Dieser Commit ist enthalten in:
TomyLobo 2011-09-25 10:14:06 +02:00
Ursprung 93f36955ca
Commit c6c55c3b2a
2 geänderte Dateien mit 55 neuen und 29 gelöschten Zeilen

Datei anzeigen

@ -601,13 +601,15 @@ public final class BlockData {
case BlockID.LONG_GRASS:
case BlockID.STONE_BRICK:
case BlockID.SILVERFISH_BLOCK:
if (data > 2) return -1;
return (data + increment) % 3;
case BlockID.TORCH:
case BlockID.REDSTONE_TORCH_ON:
case BlockID.REDSTONE_TORCH_OFF:
if (data == 5) return -1;
/* FALL-THROUGH */
if (data < 1 || data > 4) return -1;
return (data - 1 + increment) % 4 + 1;
case BlockID.WOODEN_STAIRS:
case BlockID.COBBLESTONE_STAIRS:
case BlockID.BRICK_STAIRS:
@ -615,64 +617,66 @@ public final class BlockData {
case BlockID.PUMPKIN:
case BlockID.JACKOLANTERN:
case BlockID.TRAP_DOOR:
if (data > 3) return -1;
return (data + increment) % 4;
case BlockID.STEP:
case BlockID.DOUBLE_STEP:
case BlockID.CAKE_BLOCK:
if (data > 5) return -1;
return (data + increment) % 6;
case BlockID.CROPS:
case BlockID.PUMPKIN_STEM:
case BlockID.MELON_STEM:
if (data > 6) return -1;
return (data + increment) % 7;
case BlockID.SOIL:
case BlockID.SNOW:
if (data > 8) return -1;
return (data + increment) % 9;
case BlockID.RED_MUSHROOM_CAP:
case BlockID.BROWN_MUSHROOM_CAP:
return (data + increment) % 10;
if (data > 10) return -1;
return (data + increment) % 11;
case BlockID.CACTUS:
case BlockID.REED:
case BlockID.SIGN_POST:
return (data + increment) % 16;
case BlockID.VINE:
return (data - 1 + increment) % 15 + 1;
return (data + increment) % 16;
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.LADDER:
case BlockID.CHEST:
if (data < 2 || data > 5) return -1;
return (data - 2 + increment) % 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.REDSTONE_REPEATER_ON: {
int orientation = data & 0x3;
int withoutOrientation = data & ~0x3;
return (orientation + increment) % 4 | withoutOrientation;
}
case BlockID.MINECART_TRACKS:
if (data >= 6 && data <= 9) {
return (data + increment) % 4 + 6;
} else {
return -1;
}
if (data < 6 || data > 9) return -1;
return (data - 6 + increment) % 4 + 6;
case BlockID.SAPLING:
int saplingType = data & 0x02;
int age = data & 0x0c;
return (saplingType + increment) % 3 | age;
int saplingType = data & 0x3;
int withoutType = data & ~0x3;
return (saplingType + increment) % 3 | withoutType;
case BlockID.LEAVES:
int tree = data & 0x03;
int leafMeta = data & 0x0c;
return (tree + increment) % 4 | leafMeta;
int tree = data & 0x3;
int withoutTree = data & ~0x3;
return (tree + increment) % 4 | withoutTree;
case BlockID.CLOTH:
if (increment > 0) {
@ -684,10 +688,11 @@ public final class BlockData {
}
return data;
case BlockID.FENCE_GATE:
int direction = data & 0x03;
int open = data & 0x04;
return (direction + increment) % 4 | open;
case BlockID.FENCE_GATE: {
int orientation = data & 0x3;
int withoutOrientation = data & ~0x3;
return (orientation + increment) % 4 | withoutOrientation;
}
default:
return -1;

Datei anzeigen

@ -22,12 +22,13 @@ package com.sk89q.worldedit.data;
import org.junit.*;
import com.sk89q.worldedit.CuboidClipboard.FlipDirection;
import com.sk89q.worldedit.blocks.BlockID;
import static org.junit.Assert.*;
public class BlockDataTest {
@Test
public void testSlice() {
public void testRotateFlip() {
for (int type = 0; type < 256; ++type) {
for (int data = 0; data < 16; ++data) {
final String message = type+"/"+data;
@ -46,4 +47,24 @@ public class BlockDataTest {
}
}
}
@Test
public void testCycle() {
for (int type = 0; type < 256; ++type) {
if (type == BlockID.CLOTH)
continue;
for (int data = 0; data < 16; ++data) {
final String message = type+"/"+data;
int cycled = BlockData.cycle(type, data, 1);
if (cycled <= data) {
continue;
}
assertEquals(message, data+1, cycled);
}
}
}
}