-
Notifications
You must be signed in to change notification settings - Fork 0
/
CommandButcher.java
100 lines (81 loc) · 2.89 KB
/
CommandButcher.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
package kdx7214.necessities;
import java.io.File;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import net.minecraft.command.CommandBase;
import net.minecraft.command.ICommand;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.monster.IMob;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.server.MinecraftServer;
import net.minecraft.src.ModLoader;
import net.minecraftforge.liquids.LiquidDictionary;
import net.minecraftforge.liquids.LiquidStack;
import java.io.*;
import java.net.*;
import com.google.common.collect.ImmutableMap;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.ModContainer;
public class CommandButcher extends CommandBaseNecessities {
public CommandButcher() {
}
public String getCommandName()
{
return "butcher";
}
public String getCommandUsage(ICommandSender par1ICommandSender)
{
return "/" + getCommandName() + " <radius> [mobtype]" ;
}
public void processCommand(ICommandSender sender, String[] var2)
{
assert(sender instanceof EntityPlayer || sender instanceof EntityPlayerMP) ;
if (var2.length < 1 || var2.length > 2) {
sender.sendChatToPlayer(getCommandUsage(sender)) ;
return ;
}
double r = Double.parseDouble(var2[0]) ;
r *= r ;
EntityPlayer player = getCommandSenderAsPlayer(sender) ;
List mobs = player.worldObj.loadedEntityList ;
Iterator it = mobs.iterator() ;
int count = 0 ;
while (it.hasNext()) {
Object t = it.next() ;
Entity u = (Entity)t ;
double x = player.posX - u.posX ;
double y = player.posY - u.posY ;
double z = player.posZ - u.posZ ;
double dist = x*x + y*y + z*z ;
if (dist < r) {
if (var2.length == 1 && t instanceof IMob) {
u.setDead() ;
count++ ;
} else if (var2.length == 2) {
if (t instanceof EntityPlayer || t instanceof EntityPlayerMP || t instanceof EntityItem)
continue ;
if (u.getEntityName().contains(var2[1])) {
u.setDead() ;
count++ ;
} // if (t.getEntityName().contains(var2[1]))
} // if (...)
} // if (dist < r)
} // while (it.hasNext())
sender.sendChatToPlayer("" + count + " mobs destroyed.") ;
} // public void processCommand(...)
@Override
public boolean canCommandSenderUseCommand(ICommandSender sender)
{
return hasPermission(sender, "necessities.butcher", true, false) ;
} // public boolean canCommandSenderUseCommand(...)
} // public class CommandButcher