/
BlockDataCyler.java
113 lines (102 loc) · 3.99 KB
/
BlockDataCyler.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 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.tools;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.blocks.BlockID;
/**
* A mode that cycles the data values of supported blocks.
*
* @author sk89q
*/
public class BlockDataCyler implements BlockTool {
@Override
public boolean act(ServerInterface server, LocalConfiguration config,
LocalPlayer player, LocalSession session, WorldVector clicked) {
LocalWorld world = clicked.getWorld();
int type = world.getBlockType(clicked);
int data = world.getBlockData(clicked);
if (config.allowedDataCycleBlocks.size() > 0
&& !player.hasPermission("worldedit.override.data-cycler")
&& !config.allowedDataCycleBlocks.contains(type)) {
player.printError("You are not permitted to cycle the data value of that block.");
return true;
}
if (type == BlockID.LOG) {
data = (data + 1) % 3;
} else if (type == BlockID.LEAVES) {
data = (data + 1) % 3;
} else if (type == BlockID.CACTUS) {
data = (data + 1) % 16;
} else if (type == BlockID.SOIL) {
data = (data + 1) % 9;
} else if (type == BlockID.CROPS) {
data = (data + 1) % 6;
} else if (type == BlockID.MINECART_TRACKS) {
if (data >= 6 && data <= 9) {
data = (data + 1) % 4 + 6;
} else {
player.printError("This minecart track orientation is not supported.");
return true;
}
} else if (type == BlockID.WOODEN_STAIRS || type == BlockID.COBBLESTONE_STAIRS) {
data = (data + 1) % 4;
} else if (type == BlockID.SIGN_POST) {
data = (data + 1) % 16;
} else if (type == BlockID.WALL_SIGN) {
if(data == 2) data = 5; else data--;
} else if (type == BlockID.STEP) {
data = (data + 1) % 3;
} else if (type == BlockID.DOUBLE_STEP) {
data = (data + 1) % 3;
} else if (type == BlockID.FURNACE || type == BlockID.BURNING_FURNACE
|| type == BlockID.DISPENSER) {
data = (data + 1) % 4 + 2;
} else if (type == BlockID.PUMPKIN || type == BlockID.JACKOLANTERN) {
data = (data + 1) % 4;
} else if (type == BlockID.CLOTH) {
data = nextClothColor(data);
} else {
player.printError("That block's data cannot be cycled.");
return true;
}
world.setBlockData(clicked, data);
return true;
}
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;
}
}