下面列出了org.bukkit.Material#MONSTER_EGG 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Converts from an item stack to a spawn egg 1.9
*
* @param item - ItemStack, quantity is disregarded
* @return SpawnEgg 1.9
*/
public static SpawnEgg1_9 fromItemStack(ItemStack item) {
if (item == null) {
throw new IllegalArgumentException("item cannot be null");
}
if (item.getType() != Material.MONSTER_EGG) {
throw new IllegalArgumentException("item is not a monster egg");
}
net.minecraft.server.v1_9_R1.ItemStack stack = CraftItemStack.asNMSCopy(item);
NBTTagCompound tagCompound = stack.getTag();
if (tagCompound != null) {
@SuppressWarnings("deprecation")
EntityType type = EntityType.fromName(tagCompound.getCompound("EntityTag").getString("id"));
if (type != null) {
return new SpawnEgg1_9(type);
} else {
return null;
}
} else {
return null;
}
}
/**
* Converts from an item stack to a spawn egg 1.9
*
* @param item - ItemStack, quantity is disregarded
* @return SpawnEgg 1.9
*/
public static SpawnEgg1_11 fromItemStack(ItemStack item) {
if (item == null) {
throw new IllegalArgumentException("item cannot be null");
}
if (item.getType() != Material.MONSTER_EGG) {
throw new IllegalArgumentException("item is not a monster egg");
}
net.minecraft.server.v1_11_R1.ItemStack stack = CraftItemStack.asNMSCopy(item);
NBTTagCompound tagCompound = stack.getTag();
if (tagCompound != null) {
@SuppressWarnings("deprecation")
EntityType type = EntityType.fromName(tagCompound.getCompound("EntityTag").getString("id"));
if (type != null) {
return new SpawnEgg1_11(type);
} else {
return null;
}
} else {
return null;
}
}
/**
* Converts from an item stack to a spawn egg 1.9
*
* @param item - ItemStack, quantity is disregarded
* @return SpawnEgg 1.9
*/
public static SpawnEgg1_12 fromItemStack(ItemStack item) {
if (item == null) {
throw new IllegalArgumentException("item cannot be null");
}
if (item.getType() != Material.MONSTER_EGG) {
throw new IllegalArgumentException("item is not a monster egg");
}
net.minecraft.server.v1_12_R1.ItemStack stack = CraftItemStack.asNMSCopy(item);
NBTTagCompound tagCompound = stack.getTag();
if (tagCompound != null) {
@SuppressWarnings("deprecation")
EntityType type = EntityType.fromName(tagCompound.getCompound("EntityTag").getString("id"));
if (type != null) {
return new SpawnEgg1_12(type);
} else {
return null;
}
} else {
return null;
}
}
/**
* Converts from an item stack to a spawn egg 1.9
*
* @param item - ItemStack, quantity is disregarded
* @return SpawnEgg 1.9
*/
public static SpawnEgg1_10 fromItemStack(ItemStack item) {
if (item == null) {
throw new IllegalArgumentException("item cannot be null");
}
if (item.getType() != Material.MONSTER_EGG) {
throw new IllegalArgumentException("item is not a monster egg");
}
net.minecraft.server.v1_10_R1.ItemStack stack = CraftItemStack.asNMSCopy(item);
NBTTagCompound tagCompound = stack.getTag();
if (tagCompound != null) {
@SuppressWarnings("deprecation")
EntityType type = EntityType.fromName(tagCompound.getCompound("EntityTag").getString("id"));
if (type != null) {
return new SpawnEgg1_10(type);
} else {
return null;
}
} else {
return null;
}
}
public static boolean isShopCreationItem(ItemStack item) {
if (!Utils.isSimilar(item, Settings.shopCreationItem, (short) Settings.shopCreationItemData, Settings.shopCreationItemName, Settings.shopCreationItemLore)) {
return false;
}
// check spawn egg entity type:
if (shopCreationItem == Material.MONSTER_EGG && !Utils.isEmpty(shopCreationItemSpawnEggEntityType) && NMSManager.getProvider().supportsSpawnEggEntityType()) {
EntityType spawnEggEntityType = NMSManager.getProvider().getSpawnEggEntityType(item); // can be null
EntityType requiredEntityType = null;
try {
requiredEntityType = EntityType.valueOf(shopCreationItemSpawnEggEntityType);
} catch (IllegalArgumentException e) {
// unknown entity type, require 'empty' entity type
}
if (!Objects.equal(spawnEggEntityType, requiredEntityType)) return false;
}
return true;
}
/**
* Get spawn egg
* @param type
* @param amount
* @return
*/
public ItemStack getSpawnEgg(EntityType type, int amount) {
//Bukkit.getLogger().info("DEBUG: setting spawn egg " + type.toString());
ItemStack item = new ItemStack(Material.MONSTER_EGG, amount);
net.minecraft.server.v1_11_R1.ItemStack stack = CraftItemStack.asNMSCopy(item);
NBTTagCompound tagCompound = stack.getTag();
if(tagCompound == null){
tagCompound = new NBTTagCompound();
}
//Bukkit.getLogger().info("DEBUG: tag = " + tagCompound);
NBTTagCompound id = new NBTTagCompound();
if (!bToMConversion.containsKey(type)) {
id.setString("id", "minecraft:" + type.toString().toLowerCase());
} else {
id.setString("id", "minecraft:" + bToMConversion.get(type));
}
tagCompound.set("EntityTag", id);
stack.setTag(tagCompound);
//Bukkit.getLogger().info("DEBUG: after tag = " + tagCompound);
return CraftItemStack.asBukkitCopy(stack);
}
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerInteractMobSpawner(PlayerInteractEvent evt) {
if (plugin.getConfig().getBoolean("features.monsterEggMobSpawner", true)) {
if (evt.getAction() == Action.RIGHT_CLICK_BLOCK) {
if (evt.getPlayer().getItemInHand().getType() == Material.MONSTER_EGG && evt.getClickedBlock().getType() == Material.MOB_SPAWNER) {
ItemStack egg = evt.getPlayer().getItemInHand();
CreatureSpawner cs = (CreatureSpawner) evt.getClickedBlock().getState();
cs.setSpawnedType(EntityType.fromId(egg.getData().getData()));
cs.update(true);
evt.setUseItemInHand(Event.Result.DENY);
evt.setCancelled(true);
}
}
}
}
/**
* Get an itemstack of spawn eggs
*
* @return ItemStack of spawn eggs
*/
@SuppressWarnings("deprecation")
public ItemStack toItemStack(int amount) {
ItemStack item = new ItemStack(Material.MONSTER_EGG, amount);
net.minecraft.server.v1_9_R2.ItemStack stack = CraftItemStack.asNMSCopy(item);
NBTTagCompound tagCompound = stack.getTag();
if (tagCompound == null) {
tagCompound = new NBTTagCompound();
}
NBTTagCompound id = new NBTTagCompound();
id.setString("id", type.getName());
tagCompound.set("EntityTag", id);
stack.setTag(tagCompound);
return CraftItemStack.asBukkitCopy(stack);
}
/**
* Get an itemstack of spawn eggs
*
* @return ItemStack of spawn eggs
*/
@SuppressWarnings("deprecation")
public ItemStack toItemStack(int amount) {
ItemStack item = new ItemStack(Material.MONSTER_EGG, amount);
net.minecraft.server.v1_9_R1.ItemStack stack = CraftItemStack.asNMSCopy(item);
NBTTagCompound tagCompound = stack.getTag();
if (tagCompound == null) {
tagCompound = new NBTTagCompound();
}
NBTTagCompound id = new NBTTagCompound();
id.setString("id", type.getName());
tagCompound.set("EntityTag", id);
stack.setTag(tagCompound);
return CraftItemStack.asBukkitCopy(stack);
}
/**
* Get an itemstack of spawn eggs
*
* @return ItemStack of spawn eggs
*/
@SuppressWarnings("deprecation")
public ItemStack toItemStack(int amount) {
ItemStack item = new ItemStack(Material.MONSTER_EGG, amount);
net.minecraft.server.v1_11_R1.ItemStack stack = CraftItemStack.asNMSCopy(item);
NBTTagCompound tagCompound = stack.getTag();
if (tagCompound == null) {
tagCompound = new NBTTagCompound();
}
NBTTagCompound id = new NBTTagCompound();
id.setString("id", type.getName());
tagCompound.set("EntityTag", id);
stack.setTag(tagCompound);
return CraftItemStack.asBukkitCopy(stack);
}
/**
* Get an itemstack of spawn eggs
*
* @return ItemStack of spawn eggs
*/
@SuppressWarnings("deprecation")
public ItemStack toItemStack(int amount) {
ItemStack item = new ItemStack(Material.MONSTER_EGG, amount);
net.minecraft.server.v1_12_R1.ItemStack stack = CraftItemStack.asNMSCopy(item);
NBTTagCompound tagCompound = stack.getTag();
if (tagCompound == null) {
tagCompound = new NBTTagCompound();
}
NBTTagCompound id = new NBTTagCompound();
id.setString("id", type.getName());
tagCompound.set("EntityTag", id);
stack.setTag(tagCompound);
return CraftItemStack.asBukkitCopy(stack);
}
/**
* Get an itemstack of spawn eggs
*
* @return ItemStack of spawn eggs
*/
@SuppressWarnings("deprecation")
public ItemStack toItemStack(int amount) {
ItemStack item = new ItemStack(Material.MONSTER_EGG, amount);
net.minecraft.server.v1_10_R1.ItemStack stack = CraftItemStack.asNMSCopy(item);
NBTTagCompound tagCompound = stack.getTag();
if (tagCompound == null) {
tagCompound = new NBTTagCompound();
}
NBTTagCompound id = new NBTTagCompound();
id.setString("id", type.getName());
tagCompound.set("EntityTag", id);
stack.setTag(tagCompound);
return CraftItemStack.asBukkitCopy(stack);
}
/**
* Get spawn egg
* @param type
* @param amount
* @return
*/
@SuppressWarnings("deprecation")
public ItemStack getSpawnEgg(EntityType type, int amount) {
ItemStack item = new ItemStack(Material.MONSTER_EGG, amount);
net.minecraft.server.v1_9_R2.ItemStack stack = CraftItemStack.asNMSCopy(item);
NBTTagCompound tagCompound = stack.getTag();
if(tagCompound == null){
tagCompound = new NBTTagCompound();
}
NBTTagCompound id = new NBTTagCompound();
id.setString("id", type.getName());
tagCompound.set("EntityTag", id);
stack.setTag(tagCompound);
return CraftItemStack.asBukkitCopy(stack);
}
/**
* Get spawn egg
* @param type
* @param amount
* @return
*/
@SuppressWarnings("deprecation")
public ItemStack getSpawnEgg(EntityType type, int amount) {
ItemStack item = new ItemStack(Material.MONSTER_EGG, amount);
net.minecraft.server.v1_10_R1.ItemStack stack = CraftItemStack.asNMSCopy(item);
NBTTagCompound tagCompound = stack.getTag();
if(tagCompound == null){
tagCompound = new NBTTagCompound();
}
NBTTagCompound id = new NBTTagCompound();
id.setString("id", type.getName());
tagCompound.set("EntityTag", id);
stack.setTag(tagCompound);
return CraftItemStack.asBukkitCopy(stack);
}
public SpawnEgg() {
super(Material.MONSTER_EGG);
}
/**
* @param data the raw data value
* @deprecated Magic value
*/
@Deprecated
public SpawnEgg(byte data) {
super(Material.MONSTER_EGG, data);
}
protected SpawnEggItemData(byte rawData, ItemMeta meta) {
super(Material.MONSTER_EGG, rawData, meta);
}
@Override
public ItemStack getSubTypeItem() {
return new ItemStack(Material.MONSTER_EGG, 1, (short) 54);
}
@Override
public Material getItemMaterial() {
return Material.MONSTER_EGG;
}
@Override
public ItemStack getSubTypeItem() {
return new ItemStack(Material.MONSTER_EGG, 1, (short) 57);
}