use of net.minecraft.server.v1_13_R2.ItemStack in project SilkSpawners by timbru31.
the class NMSHandler method getVanillaNBTEntityID.
@Override
@Nullable
public String getVanillaNBTEntityID(final ItemStack item) {
net.minecraft.server.v1_13_R2.ItemStack itemStack = null;
final CraftItemStack craftStack = CraftItemStack.asCraftCopy(item);
itemStack = CraftItemStack.asNMSCopy(craftStack);
NBTTagCompound tag = itemStack.getTag();
if (tag == null || !tag.hasKey("BlockEntityTag")) {
return null;
}
tag = tag.getCompound("BlockEntityTag");
tag.setString("id", TileEntityTypes.a(TileEntityTypes.MOB_SPAWNER).getKey());
if (tag.hasKey("EntityId")) {
return tag.getString("EntityId");
} else if (tag.hasKey("SpawnData") && tag.getCompound("SpawnData").hasKey("id")) {
return tag.getCompound("SpawnData").getString("id");
} else if (tag.hasKey("SpawnPotentials") && !tag.getList("SpawnPotentials", 8).isEmpty()) {
return tag.getList("SpawnPotentials", 8).getCompound(0).getCompound("Entity").getString("id");
} else {
return null;
}
}
use of net.minecraft.server.v1_13_R2.ItemStack in project SilkSpawners by timbru31.
the class NMSHandler method getVanillaEggNBTEntityID.
@Override
public String getVanillaEggNBTEntityID(final ItemStack item) {
net.minecraft.server.v1_13_R2.ItemStack itemStack = null;
final CraftItemStack craftStack = CraftItemStack.asCraftCopy(item);
itemStack = CraftItemStack.asNMSCopy(craftStack);
NBTTagCompound tag = itemStack.getTag();
if (tag == null || !tag.hasKey("EntityTag")) {
final MinecraftKey vanillaKey = IRegistry.ITEM.getKey(itemStack.getItem());
if (vanillaKey != null) {
return vanillaKey.getKey().replace("minecraft:", "").replace("_spawn_egg", "");
}
} else {
tag = tag.getCompound("EntityTag");
if (tag.hasKey("id")) {
return tag.getString("id").replace("minecraft:", "");
}
}
return null;
}
use of net.minecraft.server.v1_13_R2.ItemStack in project SilkSpawners by timbru31.
the class NMSHandler method setNBTEntityID.
@Override
public ItemStack setNBTEntityID(final ItemStack item, final String entity) {
if (item == null || StringUtils.isBlank(entity)) {
Bukkit.getLogger().warning("[SilkSpawners] Skipping invalid spawner to set NBT data on.");
return null;
}
String prefixedEntity;
if (!entity.startsWith("minecraft:")) {
prefixedEntity = "minecraft:" + entity;
} else {
prefixedEntity = entity;
}
net.minecraft.server.v1_13_R2.ItemStack itemStack = null;
final CraftItemStack craftStack = CraftItemStack.asCraftCopy(item);
itemStack = CraftItemStack.asNMSCopy(craftStack);
NBTTagCompound tag = itemStack.getOrCreateTag();
// Check for SilkSpawners key
if (!tag.hasKey("SilkSpawners")) {
tag.set("SilkSpawners", new NBTTagCompound());
}
tag.getCompound("SilkSpawners").setString("entity", entity);
// Check for Vanilla keys
if (!tag.hasKey("BlockEntityTag")) {
tag.set("BlockEntityTag", new NBTTagCompound());
}
tag = tag.getCompound("BlockEntityTag");
// EntityId - Deprecated in 1.9
tag.setString("EntityId", entity);
tag.setString("id", TileEntityTypes.a(TileEntityTypes.MOB_SPAWNER).getKey());
// SpawnData
if (!tag.hasKey("SpawnData")) {
tag.set("SpawnData", new NBTTagCompound());
}
tag.getCompound("SpawnData").setString("id", prefixedEntity);
if (!tag.hasKey("SpawnPotentials")) {
tag.set("SpawnPotentials", new NBTTagCompound());
}
// SpawnEgg data
if (!tag.hasKey("EntityTag")) {
tag.set("EntityTag", new NBTTagCompound());
}
tag.getCompound("EntityTag").setString("id", prefixedEntity);
return CraftItemStack.asCraftMirror(itemStack);
}
use of net.minecraft.server.v1_13_R2.ItemStack in project MyPet by xXKeyleXx.
the class EntityMyBlaze method handlePlayerInteraction.
public boolean handlePlayerInteraction(EntityHuman entityhuman) {
if (super.handlePlayerInteraction(entityhuman)) {
return true;
}
ItemStack itemStack = entityhuman.inventory.getItemInHand();
if (getOwner().equals(entityhuman) && itemStack != null && canUseItem()) {
if (getMyPet().isOnFire() && itemStack.getItem() == Items.GLASS_BOTTLE && itemStack.getData() == 0 && getOwner().getPlayer().isSneaking()) {
getMyPet().setOnFire(false);
makeSound("random.fizz", 1.0F, 1.0F);
if (!entityhuman.abilities.canInstantlyBuild) {
if (--itemStack.count <= 0) {
entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, new ItemStack(Items.GLASS_BOTTLE));
} else {
if (!entityhuman.inventory.pickup(new ItemStack(Items.GLASS_BOTTLE))) {
entityhuman.drop(new ItemStack(Items.GLASS_BOTTLE), true);
}
}
}
return true;
} else if (!getMyPet().isOnFire() && itemStack.getItem() == Items.FLINT_AND_STEEL && getOwner().getPlayer().isSneaking()) {
getMyPet().setOnFire(true);
makeSound("fire.ignite", 1.0F, 1.0F);
if (!entityhuman.abilities.canInstantlyBuild) {
itemStack.damage(1, entityhuman);
}
return true;
}
}
return false;
}
use of net.minecraft.server.v1_13_R2.ItemStack in project MyPet by xXKeyleXx.
the class IconMenuInventory method createItemStack.
protected ItemStack createItemStack(IconMenuItem icon) {
ItemStack is = CraftItemStack.asNMSCopy(CraftItemStack.asCraftCopy(new org.bukkit.inventory.ItemStack(icon.getMaterial(), icon.getAmount(), (short) icon.getData())));
if (is == null) {
is = CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(Material.SAPLING));
}
NBTTagList emptyList = new NBTTagList();
if (is.getTag() == null) {
is.setTag(new NBTTagCompound());
}
if (icon.getBukkitMeta() != null) {
try {
applyToItemMethhod.invoke(icon.getBukkitMeta(), is.getTag());
} catch (InvocationTargetException | IllegalAccessException e) {
e.printStackTrace();
}
}
// remove item attributes like attack damage
is.getTag().set("AttributeModifiers", emptyList);
// add enchantment glowing
if (icon.isGlowing()) {
is.getTag().set("ench", emptyList);
} else {
is.getTag().remove("ench");
}
// Prepare display tag
NBTTagCompound display;
if (is.getTag().hasKey("display")) {
display = is.getTag().getCompound("display");
} else {
display = new NBTTagCompound();
is.getTag().set("display", display);
}
// set Title
if (!icon.getTitle().equals("")) {
display.setString("Name", icon.getTitle());
}
if (icon.getLore().size() > 0) {
// set Lore
NBTTagList loreTag = new NBTTagList();
display.set("Lore", loreTag);
for (String loreLine : icon.getLore()) {
loreTag.add(new NBTTagString(loreLine));
}
}
if (icon.hasMeta()) {
TagCompound tag = new TagCompound();
icon.getMeta().applyTo(tag);
NBTTagCompound vanillaTag = (NBTTagCompound) ItemStackNBTConverter.compoundToVanillaCompound(tag);
for (String key : vanillaTag.c()) {
is.getTag().set(key, vanillaTag.get(key));
}
}
return is;
}
Aggregations