mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-23 17:57:38 +00:00
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
This commit is contained in:
parent
93f36955ca
commit
c6c55c3b2a
@ -601,13 +601,15 @@ public final class BlockData {
|
|||||||
case BlockID.LONG_GRASS:
|
case BlockID.LONG_GRASS:
|
||||||
case BlockID.STONE_BRICK:
|
case BlockID.STONE_BRICK:
|
||||||
case BlockID.SILVERFISH_BLOCK:
|
case BlockID.SILVERFISH_BLOCK:
|
||||||
|
if (data > 2) return -1;
|
||||||
return (data + increment) % 3;
|
return (data + increment) % 3;
|
||||||
|
|
||||||
case BlockID.TORCH:
|
case BlockID.TORCH:
|
||||||
case BlockID.REDSTONE_TORCH_ON:
|
case BlockID.REDSTONE_TORCH_ON:
|
||||||
case BlockID.REDSTONE_TORCH_OFF:
|
case BlockID.REDSTONE_TORCH_OFF:
|
||||||
if (data == 5) return -1;
|
if (data < 1 || data > 4) return -1;
|
||||||
/* FALL-THROUGH */
|
return (data - 1 + increment) % 4 + 1;
|
||||||
|
|
||||||
case BlockID.WOODEN_STAIRS:
|
case BlockID.WOODEN_STAIRS:
|
||||||
case BlockID.COBBLESTONE_STAIRS:
|
case BlockID.COBBLESTONE_STAIRS:
|
||||||
case BlockID.BRICK_STAIRS:
|
case BlockID.BRICK_STAIRS:
|
||||||
@ -615,64 +617,66 @@ public final class BlockData {
|
|||||||
case BlockID.PUMPKIN:
|
case BlockID.PUMPKIN:
|
||||||
case BlockID.JACKOLANTERN:
|
case BlockID.JACKOLANTERN:
|
||||||
case BlockID.TRAP_DOOR:
|
case BlockID.TRAP_DOOR:
|
||||||
|
if (data > 3) return -1;
|
||||||
return (data + increment) % 4;
|
return (data + increment) % 4;
|
||||||
|
|
||||||
case BlockID.STEP:
|
case BlockID.STEP:
|
||||||
case BlockID.DOUBLE_STEP:
|
case BlockID.DOUBLE_STEP:
|
||||||
case BlockID.CAKE_BLOCK:
|
case BlockID.CAKE_BLOCK:
|
||||||
|
if (data > 5) return -1;
|
||||||
return (data + increment) % 6;
|
return (data + increment) % 6;
|
||||||
|
|
||||||
case BlockID.CROPS:
|
case BlockID.CROPS:
|
||||||
case BlockID.PUMPKIN_STEM:
|
case BlockID.PUMPKIN_STEM:
|
||||||
case BlockID.MELON_STEM:
|
case BlockID.MELON_STEM:
|
||||||
|
if (data > 6) return -1;
|
||||||
return (data + increment) % 7;
|
return (data + increment) % 7;
|
||||||
|
|
||||||
case BlockID.SOIL:
|
case BlockID.SOIL:
|
||||||
case BlockID.SNOW:
|
case BlockID.SNOW:
|
||||||
|
if (data > 8) return -1;
|
||||||
return (data + increment) % 9;
|
return (data + increment) % 9;
|
||||||
|
|
||||||
case BlockID.RED_MUSHROOM_CAP:
|
case BlockID.RED_MUSHROOM_CAP:
|
||||||
case BlockID.BROWN_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.CACTUS:
|
||||||
case BlockID.REED:
|
case BlockID.REED:
|
||||||
case BlockID.SIGN_POST:
|
case BlockID.SIGN_POST:
|
||||||
return (data + increment) % 16;
|
|
||||||
|
|
||||||
case BlockID.VINE:
|
case BlockID.VINE:
|
||||||
return (data - 1 + increment) % 15 + 1;
|
return (data + increment) % 16;
|
||||||
|
|
||||||
case BlockID.FURNACE:
|
case BlockID.FURNACE:
|
||||||
case BlockID.BURNING_FURNACE:
|
case BlockID.BURNING_FURNACE:
|
||||||
case BlockID.DISPENSER:
|
case BlockID.DISPENSER:
|
||||||
return (data + increment) % 4 + 2;
|
|
||||||
|
|
||||||
case BlockID.WALL_SIGN:
|
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_OFF:
|
||||||
case BlockID.REDSTONE_REPEATER_ON:
|
case BlockID.REDSTONE_REPEATER_ON: {
|
||||||
int dir = data & 0x3;
|
int orientation = data & 0x3;
|
||||||
int delay = data & 0x0c;
|
int withoutOrientation = data & ~0x3;
|
||||||
return (dir + increment) % 4 | delay;
|
return (orientation + increment) % 4 | withoutOrientation;
|
||||||
|
|
||||||
case BlockID.MINECART_TRACKS:
|
|
||||||
if (data >= 6 && data <= 9) {
|
|
||||||
return (data + increment) % 4 + 6;
|
|
||||||
} else {
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case BlockID.MINECART_TRACKS:
|
||||||
|
if (data < 6 || data > 9) return -1;
|
||||||
|
return (data - 6 + increment) % 4 + 6;
|
||||||
|
|
||||||
case BlockID.SAPLING:
|
case BlockID.SAPLING:
|
||||||
int saplingType = data & 0x02;
|
int saplingType = data & 0x3;
|
||||||
int age = data & 0x0c;
|
int withoutType = data & ~0x3;
|
||||||
return (saplingType + increment) % 3 | age;
|
return (saplingType + increment) % 3 | withoutType;
|
||||||
|
|
||||||
case BlockID.LEAVES:
|
case BlockID.LEAVES:
|
||||||
int tree = data & 0x03;
|
int tree = data & 0x3;
|
||||||
int leafMeta = data & 0x0c;
|
int withoutTree = data & ~0x3;
|
||||||
return (tree + increment) % 4 | leafMeta;
|
return (tree + increment) % 4 | withoutTree;
|
||||||
|
|
||||||
case BlockID.CLOTH:
|
case BlockID.CLOTH:
|
||||||
if (increment > 0) {
|
if (increment > 0) {
|
||||||
@ -684,10 +688,11 @@ public final class BlockData {
|
|||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
|
|
||||||
case BlockID.FENCE_GATE:
|
case BlockID.FENCE_GATE: {
|
||||||
int direction = data & 0x03;
|
int orientation = data & 0x3;
|
||||||
int open = data & 0x04;
|
int withoutOrientation = data & ~0x3;
|
||||||
return (direction + increment) % 4 | open;
|
return (orientation + increment) % 4 | withoutOrientation;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -22,12 +22,13 @@ package com.sk89q.worldedit.data;
|
|||||||
import org.junit.*;
|
import org.junit.*;
|
||||||
|
|
||||||
import com.sk89q.worldedit.CuboidClipboard.FlipDirection;
|
import com.sk89q.worldedit.CuboidClipboard.FlipDirection;
|
||||||
|
import com.sk89q.worldedit.blocks.BlockID;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
public class BlockDataTest {
|
public class BlockDataTest {
|
||||||
@Test
|
@Test
|
||||||
public void testSlice() {
|
public void testRotateFlip() {
|
||||||
for (int type = 0; type < 256; ++type) {
|
for (int type = 0; type < 256; ++type) {
|
||||||
for (int data = 0; data < 16; ++data) {
|
for (int data = 0; data < 16; ++data) {
|
||||||
final String message = type+"/"+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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user