use of org.bukkit.craftbukkit.v1_9_R2.inventory.CraftItemStack in project SilkSpawners by timbru31.
the class NMSHandler method getVanillaEggNBTEntityID.
@Override
public String getVanillaEggNBTEntityID(final ItemStack item) {
net.minecraft.world.item.ItemStack itemStack = null;
final CraftItemStack craftStack = CraftItemStack.asCraftCopy(item);
itemStack = CraftItemStack.asNMSCopy(craftStack);
CompoundTag tag = itemStack.getTag();
if (tag == null || !tag.contains("EntityTag")) {
final Registry<Item> itemRegistry = Registry.ITEM;
final ResourceLocation vanillaKey = itemRegistry.getKey(itemStack.getItem());
if (vanillaKey != null) {
return vanillaKey.getPath().replace("minecraft:", "").replace("_spawn_egg", "");
}
} else {
tag = tag.getCompound("EntityTag");
if (tag.contains("id")) {
return tag.getString("id").replace("minecraft:", "");
}
}
return null;
}
use of org.bukkit.craftbukkit.v1_9_R2.inventory.CraftItemStack in project SilkSpawners by timbru31.
the class NMSHandler method newEggItem.
@Override
public ItemStack newEggItem(final String entityID, final int amount, final String displayName) {
final ItemStack item = new ItemStack(Material.MONSTER_EGG, amount, this.entitiesMaps.get(entityID).shortValue());
net.minecraft.server.v1_8_R1.ItemStack itemStack = null;
final CraftItemStack craftStack = CraftItemStack.asCraftCopy(item);
itemStack = CraftItemStack.asNMSCopy(craftStack);
NBTTagCompound tag = itemStack.getTag();
// Create tag if necessary
if (tag == null) {
tag = new NBTTagCompound();
itemStack.setTag(tag);
}
if (!tag.hasKey("SilkSpawners")) {
tag.set("SilkSpawners", new NBTTagCompound());
}
tag.getCompound("SilkSpawners").setString("entity", entityID);
if (!tag.hasKey("EntityTag")) {
tag.set("EntityTag", new NBTTagCompound());
}
tag.getCompound("EntityTag").setString("id", entityID);
return CraftItemStack.asCraftMirror(itemStack);
}
use of org.bukkit.craftbukkit.v1_9_R2.inventory.CraftItemStack in project SilkSpawners by timbru31.
the class NMSHandler method getSilkSpawnersNBTEntityID.
@Override
@Nullable
public String getSilkSpawnersNBTEntityID(final ItemStack item) {
net.minecraft.server.v1_8_R3.ItemStack itemStack = null;
final CraftItemStack craftStack = CraftItemStack.asCraftCopy(item);
itemStack = CraftItemStack.asNMSCopy(craftStack);
final NBTTagCompound tag = itemStack.getTag();
if (tag == null || !tag.hasKey("SilkSpawners")) {
return null;
}
final NBTTagCompound silkSpawnersTag = tag.getCompound("SilkSpawners");
if (silkSpawnersTag.hasKey("entity")) {
return silkSpawnersTag.getString("entity");
}
if (silkSpawnersTag.hasKey("entityID")) {
return getEntityFromNumericalID(silkSpawnersTag.getShort("entityID"));
}
return null;
}
use of org.bukkit.craftbukkit.v1_9_R2.inventory.CraftItemStack in project SilkSpawners by timbru31.
the class NMSHandler method newEggItem.
@SuppressWarnings("deprecation")
@Override
public ItemStack newEggItem(final String entityID, final int amount, final String displayName) {
Material spawnEgg = Material.matchMaterial(entityID.toUpperCase() + "_SPAWN_EGG");
if (spawnEgg == null) {
spawnEgg = Material.LEGACY_MONSTER_EGG;
}
final ItemStack item = new ItemStack(spawnEgg, amount);
if (displayName != null) {
final ItemMeta itemMeta = item.getItemMeta();
itemMeta.setDisplayName(displayName);
item.setItemMeta(itemMeta);
}
net.minecraft.world.item.ItemStack itemStack = null;
final CraftItemStack craftStack = CraftItemStack.asCraftCopy(item);
itemStack = CraftItemStack.asNMSCopy(craftStack);
final CompoundTag tag = itemStack.getOrCreateTag();
if (!tag.contains("SilkSpawners")) {
tag.put("SilkSpawners", new CompoundTag());
}
tag.getCompound("SilkSpawners").putString("entity", entityID);
if (!tag.contains("EntityTag")) {
tag.put("EntityTag", new CompoundTag());
}
String prefixedEntity;
if (!entityID.startsWith("minecraft:")) {
prefixedEntity = "minecraft:" + entityID;
} else {
prefixedEntity = entityID;
}
tag.getCompound("EntityTag").putString("id", prefixedEntity);
return CraftItemStack.asCraftMirror(itemStack);
}
use of org.bukkit.craftbukkit.v1_9_R2.inventory.CraftItemStack in project SilkSpawners by timbru31.
the class NMSHandler method getVanillaNBTEntityID.
@Override
@Nullable
public String getVanillaNBTEntityID(final ItemStack item) {
net.minecraft.world.item.ItemStack itemStack = null;
final CraftItemStack craftStack = CraftItemStack.asCraftCopy(item);
itemStack = CraftItemStack.asNMSCopy(craftStack);
CompoundTag tag = itemStack.getTag();
if (tag == null || !tag.contains("BlockEntityTag")) {
return null;
}
tag = tag.getCompound("BlockEntityTag");
if (tag.contains("EntityId")) {
return tag.getString("EntityId");
} else if (tag.contains("SpawnData") && tag.getCompound("SpawnData").contains("id")) {
return tag.getCompound("SpawnData").getString("id");
} else if (tag.contains("SpawnPotentials") && !tag.getList("SpawnPotentials", 8).isEmpty()) {
return tag.getList("SpawnPotentials", 8).getCompound(0).getCompound("Entity").getString("id");
} else {
return null;
}
}
Aggregations