-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathWorldUtils.java
More file actions
154 lines (133 loc) · 3.45 KB
/
Copy pathWorldUtils.java
File metadata and controls
154 lines (133 loc) · 3.45 KB
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package net.virtuallyabstract.minecraft;
import org.bukkit.plugin.java.*;
import org.bukkit.plugin.*;
import org.bukkit.event.*;
import org.bukkit.event.player.*;
import org.bukkit.entity.*;
import org.bukkit.inventory.*;
import org.bukkit.*;
import org.bukkit.block.*;
import org.bukkit.command.*;
import org.bukkit.material.*;
import java.util.logging.*;
import java.util.concurrent.*;
import java.util.*;
public class WorldUtils
{
public static void createRoomNoWalls(Location loc, int width, int depth, int height, int floorType)
{
Location newLoc = loc.clone();
int halfdepth = depth / 2;
int halfwidth = width / 2;
double xbase = loc.getX();
double zbase = loc.getZ();
double ybase = loc.getY() - 1;
//Construct the walls and interior
for(double y = 0.0; y <= height; y += 1.0)
{
newLoc.setY(ybase + y);
for(double x = -halfdepth; x <= halfdepth; x += 1.0)
{
newLoc.setX(xbase + x);
for(double z = -halfwidth; z <= halfwidth; z += 1.0)
{
newLoc.setZ(zbase + z);
if(y == 0.0)
{
if(x >= -halfdepth && x <= halfdepth)
{
if(z >= -halfwidth && z <= halfwidth)
{
newLoc.getBlock().setTypeId(floorType);
continue;
}
}
}
newLoc.getBlock().setType(Material.AIR);
}
}
}
}
public static ArrayList<BlockInfo> createRoom(Location loc, int width, int depth, int height, int type, boolean hollow)
{
ArrayList<BlockInfo> retVal = new ArrayList<BlockInfo>();
Location newLoc = loc.clone();
int halfdepth = depth / 2;
int halfwidth = width / 2;
double xbase = loc.getX();
double zbase = loc.getZ();
double ybase = loc.getY() - 1;
//Construct the walls and interior
for(double y = 0.0; y <= height; y += 1.0)
{
newLoc.setY(ybase + y);
for(double x = -halfdepth; x <= halfdepth; x += 1.0)
{
newLoc.setX(xbase + x);
for(double z = -halfwidth; z <= halfwidth; z += 1.0)
{
newLoc.setZ(zbase + z);
if(y > 0.0 && y < height)
{
if(x > -halfdepth && x < halfdepth)
{
if(z > -halfwidth && z < halfwidth)
{
if(hollow)
{
BlockInfo bi = new BlockInfo(newLoc.getBlock());
retVal.add(bi);
newLoc.getBlock().setType(Material.AIR);
}
continue;
}
}
}
BlockInfo bi = new BlockInfo(newLoc.getBlock());
retVal.add(bi);
if(type != -1)
newLoc.getBlock().setTypeId(type);
}
}
}
if(!hollow || type == 20)
return retVal;
//Lets add some torches
for(double y = 1.0; y <= height-1; y += 1.0)
{
newLoc.setY(ybase + y);
for(double x = -halfdepth+1; x <= halfdepth-1; x += 1.0)
{
newLoc.setX(xbase + x);
for(double z = -halfwidth+1; z <= halfwidth-1; z += 1.0)
{
newLoc.setZ(zbase + z);
if(y > 0.0 && y < height && y % 3 == 0)
{
if((x == -halfdepth+1 || x == halfdepth-1) && z % 3 == 0)
{
newLoc.getBlock().setType(Material.TORCH);
continue;
}
if((z == -halfwidth+1 || z == halfwidth-1) && x % 3 == 0)
{
newLoc.getBlock().setType(Material.TORCH);
continue;
}
}
if(y == 1.0 && z % 3 == 0 && x % 3 == 0)
{
newLoc.getBlock().setType(Material.TORCH);
continue;
}
}
}
}
return retVal;
}
public static String createLocationKey(Location loc)
{
String key = loc.getWorld().getName() + ":" + loc.getBlockX() + ":" + loc.getBlockZ() + ":" + loc.getBlockY();
return key;
}
}