14 |
final static int NORTH = 2; |
final static int NORTH = 2; |
15 |
final static int SOUTH = 3; |
final static int SOUTH = 3; |
16 |
|
|
17 |
Location leftUpper; |
private Location leftUpper; |
18 |
|
|
19 |
|
|
20 |
Location blocks[][]; // [width][height] - [0][0] == leftUpper |
private Location blocks[][]; // [width][height] - [0][0] == leftUpper |
21 |
|
private int material[][]; |
22 |
int material; |
private byte data[][]; |
23 |
|
|
24 |
int direction; |
private int direction; |
25 |
|
|
26 |
int width; |
private int width; |
27 |
int height; |
private int height; |
28 |
|
|
29 |
String owner; |
private String owner; |
30 |
|
|
31 |
|
|
32 |
public Door(Block sign, int width, int height, DoorStorage store, String owner) throws ConflictingDoorException{ |
public Door(Block sign, int width, int height, DoorStorage store, String owner) throws ConflictingDoorException{ |
37 |
|
|
38 |
this.owner = owner; |
this.owner = owner; |
39 |
|
|
|
blocks = new Location[width][height]; |
|
40 |
|
|
41 |
direction = sign.getData() - 2; |
direction = sign.getData() - 2; |
42 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
material = leftUpper.getBlock().getTypeId(); |
//material = leftUpper.getBlock().getTypeId(); |
61 |
|
|
62 |
loadBlocks(); |
loadBlocks(); |
63 |
|
|
64 |
|
|
65 |
for (int w=0; w<width; w++) { |
for (int w=0; w<width; w++) { |
66 |
for (int h=0; h<height; h++) { |
for (int h=0; h<height; h++) { |
67 |
Door d = store.findDoor( blocks[w][h] ); |
Door d = store.findDoor( blocks[w][h] ); |
80 |
|
|
81 |
leftUpper = new Location(w, Integer.parseInt(parts[1]), Integer.parseInt(parts[2]), Integer.parseInt(parts[3]) ); |
leftUpper = new Location(w, Integer.parseInt(parts[1]), Integer.parseInt(parts[2]), Integer.parseInt(parts[3]) ); |
82 |
direction = Integer.parseInt( parts[4] ); |
direction = Integer.parseInt( parts[4] ); |
83 |
material = Integer.parseInt( parts[5] ); |
//material = Integer.parseInt( parts[5] ); |
84 |
|
|
85 |
width = Integer.parseInt( parts[6] ); |
width = Integer.parseInt( parts[6] ); |
86 |
height = Integer.parseInt( parts[7] ); |
height = Integer.parseInt( parts[7] ); |
87 |
owner = parts[8]; |
owner = parts[8]; |
88 |
|
|
|
|
|
|
blocks = new Location[width][height]; |
|
89 |
|
|
90 |
loadBlocks(); |
loadBlocks(); |
91 |
} |
} |
92 |
|
|
93 |
|
public void powerChange(World world, int oldCurrent, int newCurrent ) { |
94 |
|
if (isPowered() == true) { |
95 |
|
open(); |
96 |
|
} else { |
97 |
|
close(); |
98 |
|
} |
99 |
|
} |
100 |
|
|
101 |
|
public boolean isPowered() { |
102 |
|
for (int w=0; w<width; w++) { |
103 |
|
for (int h=0; h<height; h++) { |
104 |
|
Block b = blocks[w][h].getBlock(); |
105 |
|
|
106 |
|
if ( b.isBlockPowered() || b.isBlockIndirectlyPowered() ) |
107 |
|
return true; |
108 |
|
} |
109 |
|
} |
110 |
|
|
111 |
|
return false; |
112 |
|
} |
113 |
|
|
114 |
private void loadBlocks() { |
private void loadBlocks() { |
115 |
|
blocks = new Location[width][height]; |
116 |
|
material = new int[width][height]; |
117 |
|
data = new byte[width][height]; |
118 |
|
|
119 |
for (int w=0; w<width; w++) { |
for (int w=0; w<width; w++) { |
120 |
for (int h=0; h<height; h++) { |
for (int h=0; h<height; h++) { |
142 |
//System.out.println("Add block: " + x + ":" + y + ":" + z); |
//System.out.println("Add block: " + x + ":" + y + ":" + z); |
143 |
|
|
144 |
blocks[w][h] = new Location( leftUpper.getWorld(), x, y, z); |
blocks[w][h] = new Location( leftUpper.getWorld(), x, y, z); |
145 |
|
|
146 |
|
material[w][h] = blocks[w][h].getBlock().getTypeId(); |
147 |
|
data[w][h] = blocks[w][h].getBlock().getData(); |
148 |
|
|
149 |
} |
} |
150 |
} |
} |
161 |
|
|
162 |
sb.append( ":" + direction ); |
sb.append( ":" + direction ); |
163 |
|
|
164 |
sb.append( ":" + material ); |
sb.append( ":" + material[0][0] ); |
165 |
|
|
166 |
sb.append( ":" + width ); |
sb.append( ":" + width ); |
167 |
sb.append( ":" + height ); |
sb.append( ":" + height ); |
188 |
|
|
189 |
} |
} |
190 |
|
|
191 |
public void open(World world) { |
public void open() { |
192 |
for (int w=0; w<width; w++) { |
for (int w=0; w<width; w++) { |
193 |
for (int h=0; h<height; h++) { |
for (int h=0; h<height; h++) { |
194 |
blocks[w][h].getBlock().setTypeId(0); |
blocks[w][h].getBlock().setTypeId(0, false); |
195 |
} |
} |
196 |
} |
} |
197 |
|
|
198 |
} |
} |
199 |
|
|
200 |
public void close(World world) { |
public void close() { |
201 |
for (int w=0; w<width; w++) { |
for (int w=0; w<width; w++) { |
202 |
for (int h=0; h<height; h++) { |
for (int h=0; h<height; h++) { |
203 |
blocks[w][h].getBlock().setTypeId( material ); |
blocks[w][h].getBlock().setTypeIdAndData( material[w][h], data[w][h], true ); |
204 |
} |
} |
205 |
} |
} |
206 |
} |
} |
207 |
|
|
208 |
|
|
209 |
|
/////// setters and getters |
210 |
|
public String getOwner() { |
211 |
|
return owner; |
212 |
|
} |
213 |
|
|
214 |
} |
} |