use of net.minecraft.server.v1_7_R4.ItemStack in project MyPet by xXKeyleXx.
the class EntityMyCow 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 (itemStack.getItem() == Items.BUCKET && Configuration.MyPet.Cow.CAN_GIVE_MILK) {
ItemStack milkBucket = new ItemStack(Items.BUCKET, 1, 0);
entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, milkBucket);
return true;
} else if (Configuration.MyPet.Cow.GROW_UP_ITEM.compare(itemStack) && getMyPet().isBaby() && getOwner().getPlayer().isSneaking()) {
if (!entityhuman.abilities.canInstantlyBuild) {
if (--itemStack.count <= 0) {
entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, null);
}
}
getMyPet().setBaby(false);
return true;
}
}
return false;
}
use of net.minecraft.server.v1_7_R4.ItemStack in project MyPet by xXKeyleXx.
the class EntityMyMooshroom method handlePlayerInteraction.
public boolean handlePlayerInteraction(final EntityHuman entityhuman) {
if (super.handlePlayerInteraction(entityhuman)) {
return true;
}
ItemStack itemStack = entityhuman.inventory.getItemInHand();
if (itemStack != null) {
if (itemStack.getItem().equals(Items.BOWL)) {
if (!getOwner().equals(entityhuman) || !canUseItem() || !Configuration.MyPet.Mooshroom.CAN_GIVE_SOUP) {
final int itemInHandIndex = entityhuman.inventory.itemInHandIndex;
ItemStack is = new ItemStack(Items.MUSHROOM_STEW);
final ItemStack oldIs = entityhuman.inventory.getItem(itemInHandIndex);
entityhuman.inventory.setItem(itemInHandIndex, is);
Bukkit.getScheduler().scheduleSyncDelayedTask(MyPetApi.getPlugin(), new Runnable() {
@Override
public void run() {
entityhuman.inventory.setItem(itemInHandIndex, oldIs);
}
}, 2L);
} else {
if (--itemStack.count <= 0) {
entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, new ItemStack(Items.MUSHROOM_STEW));
} else {
if (!entityhuman.inventory.pickup(new ItemStack(Items.MUSHROOM_STEW))) {
entityhuman.drop(new ItemStack(Items.GLASS_BOTTLE), true);
}
}
return true;
}
}
if (getOwner().equals(entityhuman) && canUseItem()) {
if (Configuration.MyPet.Mooshroom.GROW_UP_ITEM.compare(itemStack) && getMyPet().isBaby() && getOwner().getPlayer().isSneaking()) {
if (!entityhuman.abilities.canInstantlyBuild) {
if (--itemStack.count <= 0) {
entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, null);
}
}
getMyPet().setBaby(false);
return true;
}
}
}
return false;
}
use of net.minecraft.server.v1_7_R4.ItemStack in project MyPet by xXKeyleXx.
the class IconMenuInventory method open.
@Override
public void open(IconMenu menu, HumanEntity player) {
size = menu.getSize();
minecraftInventory = new CustomInventory(size, menu.getTitle());
for (int slot = 0; slot < size; slot++) {
IconMenuItem menuItem = menu.getOption(slot);
if (menuItem != null) {
ItemStack item = createItemStack(menuItem);
minecraftInventory.setItem(slot, item);
}
}
player.openInventory(minecraftInventory.getBukkitInventory());
}
use of net.minecraft.server.v1_7_R4.ItemStack in project MyPet by xXKeyleXx.
the class IconMenuInventory method createItemStack.
protected ItemStack createItemStack(IconMenuItem icon) {
ItemStack is = CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(icon.getMaterial(), icon.getAmount(), (short) icon.getData()));
// TODO allow items like FIRE (51)
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()) {
TagCompound enchTag = new TagCompound();
enchTag.put("id", new TagShort(2));
enchTag.put("lvl", new TagShort(1));
TagList enchList = new TagList();
enchList.addTag(enchTag);
is.getTag().set("ench", ItemStackNBTConverter.compoundToVanillaCompound(enchList));
is.getTag().setInt("HideFlags", 1);
} 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));
}
}
if (icon.getTags() != null) {
NBTTagCompound vanillaTag = (NBTTagCompound) ItemStackNBTConverter.compoundToVanillaCompound(icon.getTags());
for (String key : vanillaTag.c()) {
is.getTag().set(key, vanillaTag.get(key));
}
}
return is;
}
use of net.minecraft.server.v1_7_R4.ItemStack in project MyPet by xXKeyleXx.
the class EntityMyMooshroom method handlePlayerInteraction.
public boolean handlePlayerInteraction(final EntityHuman entityhuman) {
if (super.handlePlayerInteraction(entityhuman)) {
return true;
}
ItemStack itemStack = entityhuman.inventory.getItemInHand();
if (itemStack != null) {
if (itemStack.getItem().equals(Items.BOWL)) {
if (!getOwner().equals(entityhuman) || !canUseItem() || !Configuration.MyPet.Mooshroom.CAN_GIVE_SOUP) {
final int itemInHandIndex = entityhuman.inventory.itemInHandIndex;
ItemStack is = new ItemStack(Items.MUSHROOM_SOUP);
final ItemStack oldIs = entityhuman.inventory.getItem(itemInHandIndex);
entityhuman.inventory.setItem(itemInHandIndex, is);
Bukkit.getScheduler().scheduleSyncDelayedTask(MyPetApi.getPlugin(), new Runnable() {
@Override
public void run() {
entityhuman.inventory.setItem(itemInHandIndex, oldIs);
}
}, 2L);
} else {
if (--itemStack.count <= 0) {
entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, new ItemStack(Items.MUSHROOM_SOUP));
} else {
if (!entityhuman.inventory.pickup(new ItemStack(Items.MUSHROOM_SOUP))) {
entityhuman.drop(new ItemStack(Items.GLASS_BOTTLE), true);
}
}
return true;
}
}
if (getOwner().equals(entityhuman) && canUseItem()) {
if (Configuration.MyPet.Mooshroom.GROW_UP_ITEM.compare(itemStack) && getMyPet().isBaby() && getOwner().getPlayer().isSneaking()) {
if (!entityhuman.abilities.canInstantlyBuild) {
if (--itemStack.count <= 0) {
entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, null);
}
}
getMyPet().setBaby(false);
return true;
}
}
}
return false;
}
Aggregations