/
CommandUtil.java
38 lines (32 loc) · 1.25 KB
/
CommandUtil.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
package mezz.jei.util;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
/**
* Server-side-safe utilities for commands.
*/
public class CommandUtil {
public static String[] getGiveCommandParameters(EntityPlayer sender, ItemStack itemStack, int amount) {
String senderName = sender.getName();
Item item = itemStack.getItem();
ResourceLocation itemResourceLocation = item.getRegistryName();
if (itemResourceLocation == null) {
String stackInfo = ErrorUtil.getItemStackInfo(itemStack);
throw new IllegalArgumentException("item.getRegistryName() returned null for: " + stackInfo);
}
List<String> commandStrings = new ArrayList<String>();
commandStrings.add(senderName);
commandStrings.add(itemResourceLocation.toString());
commandStrings.add(String.valueOf(amount));
commandStrings.add(String.valueOf(itemStack.getMetadata()));
NBTTagCompound tagCompound = itemStack.getTagCompound();
if (tagCompound != null) {
commandStrings.add(tagCompound.toString());
}
return commandStrings.toArray(new String[commandStrings.size()]);
}
}