/* * This file is part of MyPet * * Copyright © 2011-2016 Keyle * MyPet is licensed under the GNU Lesser General Public License. * * MyPet is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * MyPet is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package de.Keyle.MyPet.compat.v1_8_R1.entity.types; import de.Keyle.MyPet.api.Configuration; import de.Keyle.MyPet.api.entity.EntitySize; import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.api.entity.types.MyPig; import de.Keyle.MyPet.compat.v1_8_R1.entity.EntityMyPet; import net.minecraft.server.v1_8_R1.*; import org.bukkit.craftbukkit.v1_8_R1.inventory.CraftItemStack; @EntitySize(width = 0.7F, height = 0.9F) public class EntityMyPig extends EntityMyPet { public EntityMyPig(World world, MyPet myPet) { super(world, myPet); } @Override protected String getDeathSound() { return "mob.pig.death"; } @Override protected String getHurtSound() { return "mob.pig.say"; } protected String getLivingSound() { return "mob.pig.say"; } 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.SADDLE && !getMyPet().hasSaddle() && getOwner().getPlayer().isSneaking()) { getMyPet().setSaddle(CraftItemStack.asBukkitCopy(itemStack)); if (!entityhuman.abilities.canInstantlyBuild) { if (--itemStack.count <= 0) { entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, null); } } return true; } else if (itemStack.getItem() == Items.SHEARS && getMyPet().hasSaddle() && getOwner().getPlayer().isSneaking()) { EntityItem entityitem = this.a(CraftItemStack.asNMSCopy(getMyPet().getSaddle()), 1.0F); entityitem.motY += (double) (this.random.nextFloat() * 0.05F); entityitem.motX += (double) ((this.random.nextFloat() - this.random.nextFloat()) * 0.1F); entityitem.motZ += (double) ((this.random.nextFloat() - this.random.nextFloat()) * 0.1F); makeSound("mob.sheep.shear", 1.0F, 1.0F); getMyPet().setSaddle(null); if (!entityhuman.abilities.canInstantlyBuild) { itemStack.damage(1, entityhuman); } return true; } else if (Configuration.MyPet.Pig.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; } protected void initDatawatcher() { super.initDatawatcher(); this.datawatcher.a(12, new Byte((byte) 0)); // age this.datawatcher.a(16, new Byte((byte) 0)); // saddle } @Override public void updateVisuals() { if (getMyPet().isBaby()) { this.datawatcher.watch(12, Byte.valueOf(Byte.MIN_VALUE)); } else { this.datawatcher.watch(12, new Byte((byte) 0)); } if (getMyPet().hasSaddle()) { this.datawatcher.watch(16, (byte) 1); } else { this.datawatcher.watch(16, (byte) 0); } } public void playStepSound() { makeSound("mob.pig.step", 0.15F, 1.0F); } public MyPig getMyPet() { return (MyPig) myPet; } }