-
Notifications
You must be signed in to change notification settings - Fork 0
/
CommandDrain.java
138 lines (112 loc) · 4.3 KB
/
CommandDrain.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
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
package kdx7214.necessities;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.jcraft.jorbis.Block;
import cpw.mods.fml.common.Loader;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.liquids.LiquidDictionary;
import net.minecraftforge.liquids.LiquidStack;
public class CommandDrain extends CommandBaseNecessities {
public CommandDrain() {
}
public String getCommandName()
{
return "drain";
}
public String getCommandUsage(ICommandSender par1ICommandSender)
{
return "/" + getCommandName() + " <water/lava/oil> <radius>" ;
}
public List getCommandAliases()
{
return null;
}
//
// The /drain command will recognize three possible liquid names: water, lava, Oil
//
public void processCommand(ICommandSender sender, String[] var2)
{
Map<String, LiquidStack> liquids = LiquidDictionary.getLiquids() ;
LiquidStack oil = LiquidDictionary.getLiquid("Oil", 1) ;
double radius = 0.0 ;
EntityPlayer player = getCommandSenderAsPlayer(sender) ;
EntityPlayerMP playerMP = (EntityPlayerMP)sender ;
Set<Integer> blocks = new HashSet<Integer>() ;
NBTTagCompound playerdata = NecessitiesMain.instance.necessities_data.getCompoundTag(player.username) ;
NecessitiesMain.instance.necessities_data.setCompoundTag(player.username, playerdata) ;
NBTTagCompound we = playerdata.getCompoundTag("[Worldedit]") ;
playerdata.setCompoundTag("[Worldedit]", we) ;
int limit ;
if (we.hasKey("Limit")) {
limit = we.getInteger("Limit") ;
} else {
limit = Integer.MAX_VALUE ;
}
// air == block id #0
// water == block id #8-9 (9 = stationary) Block.waterStill Block.waterMoving
// lava == block id #10-11 (11 = stationary) Block.lavaStill Block.lavaMoving
if (var2.length != 2) {
sender.sendChatToPlayer(getCommandUsage(sender)) ;
return ;
}
if (var2[0].equalsIgnoreCase("water")) {
blocks.add(8) ;
blocks.add(9) ;
} else if (var2[0].equalsIgnoreCase("lava")) {
blocks.add(10) ;
blocks.add(11) ;
} else if (var2[0].equalsIgnoreCase("oil")) {
if (oil == null) {
sender.sendChatToPlayer("Oil is not registered in the LiquidDictionary. Please install a mod that adds Oil.") ;
} else {
blocks.add(oil.itemID) ;
blocks.add(oil.itemID - 1) ;
}
} else {
sender.sendChatToPlayer("Invalid liquid name.") ;
return ;
}
radius = Double.parseDouble(var2[1]) ;
if (radius < 1.0 || radius > 100.0) {
sender.sendChatToPlayer("Radius must be between 1 and 100") ;
return ;
}
double minX = player.posX - radius ;
double maxX = player.posX + radius ;
double minY = player.posY - radius ;
double maxY = player.posY + radius ;
double minZ = player.posZ - radius ;
double maxZ = player.posZ + radius ;
int count = 0 ;
double dist ;
for (double i = minX; i < maxX; ++i) {
for (double j = minY; j < maxY; ++j) {
for (double k = minZ; k < maxZ; ++k) {
dist = (player.posX - i) * (player.posX - i) +
(player.posY - j) * (player.posY - j) +
(player.posZ - k) * (player.posZ - k) ;
dist = Math.sqrt(dist) ;
if (dist - 0.5 < radius) { // This means we are within the sphere
if (blocks.contains(playerMP.getServerForPlayer().getBlockId((int)i, (int)j, (int)k))) {
if (count < limit) {
playerMP.getServerForPlayer().setBlockWithNotify((int)i, (int)j, (int)k, 0) ;
}
count++ ;
} // if (block needs to be changed)
} // if (within sphere)
} // for (...)
} // for (...)
} // for (...)
sender.sendChatToPlayer("" + count + " blocks changed.") ;
} // public void processCommand(...)
@Override
public boolean canCommandSenderUseCommand(ICommandSender sender) {
return hasPermission(sender, "necessities.drain", true, false) ;
} // public boolean canCommandSenderUseCommand(...)
} // public class CommandDrain