use of de.Keyle.MyPet.api.entity.EquipmentSlot in project MyPet by xXKeyleXx.
the class EntityMySkeleton 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.SHEARS && getOwner().getPlayer().isSneaking() && canEquip()) {
boolean hadEquipment = false;
for (EquipmentSlot slot : EquipmentSlot.values()) {
ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot));
if (itemInSlot != null) {
EntityItem entityitem = this.a(itemInSlot.cloneItemStack(), 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);
getMyPet().setEquipment(slot, null);
hadEquipment = true;
}
}
if (hadEquipment) {
if (!entityhuman.abilities.canInstantlyBuild) {
itemStack.damage(1, entityhuman);
}
}
return true;
} else if (MyPetApi.getPlatformHelper().isEquipment(CraftItemStack.asBukkitCopy(itemStack)) && getOwner().getPlayer().isSneaking() && canEquip()) {
EquipmentSlot slot = EquipmentSlot.getSlotById(b(itemStack));
ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot));
if (itemInSlot != null && !entityhuman.abilities.canInstantlyBuild) {
EntityItem entityitem = this.a(itemInSlot.cloneItemStack(), 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);
}
getMyPet().setEquipment(slot, CraftItemStack.asBukkitCopy(itemStack));
if (!entityhuman.abilities.canInstantlyBuild) {
--itemStack.count;
}
if (itemStack.count <= 0) {
entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, null);
}
return true;
}
}
return false;
}
use of de.Keyle.MyPet.api.entity.EquipmentSlot in project MyPet by xXKeyleXx.
the class EntityMyZombie method updateVisuals.
@Override
public void updateVisuals() {
this.datawatcher.watch(12, (byte) (getMyPet().isBaby() ? 1 : 0));
this.datawatcher.watch(13, (byte) (getMyPet().isVillager() ? 1 : 0));
Bukkit.getScheduler().runTaskLater(MyPetApi.getPlugin(), () -> {
if (getMyPet().getStatus() == MyPet.PetState.Here) {
for (EquipmentSlot slot : EquipmentSlot.values()) {
if (slot == EquipmentSlot.OffHand) {
continue;
}
setPetEquipment(slot.getSlotId(), CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot)));
}
}
}, 5L);
}
use of de.Keyle.MyPet.api.entity.EquipmentSlot in project MyPet by xXKeyleXx.
the class EntityMyPigZombie 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.SHEARS && getOwner().getPlayer().isSneaking() && canEquip()) {
boolean hadEquipment = false;
for (EquipmentSlot slot : EquipmentSlot.values()) {
ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot));
if (itemInSlot != null) {
EntityItem entityitem = this.a(itemInSlot.cloneItemStack(), 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);
getMyPet().setEquipment(slot, null);
hadEquipment = true;
}
}
if (hadEquipment) {
if (!entityhuman.abilities.canInstantlyBuild) {
itemStack.damage(1, entityhuman);
}
}
return true;
} else if (MyPetApi.getPlatformHelper().isEquipment(CraftItemStack.asBukkitCopy(itemStack)) && getOwner().getPlayer().isSneaking() && canEquip()) {
EquipmentSlot slot = EquipmentSlot.getSlotById(c(itemStack));
ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot));
if (itemInSlot != null && !entityhuman.abilities.canInstantlyBuild) {
EntityItem entityitem = this.a(itemInSlot.cloneItemStack(), 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);
}
getMyPet().setEquipment(slot, CraftItemStack.asBukkitCopy(itemStack));
if (!entityhuman.abilities.canInstantlyBuild) {
if (--itemStack.count <= 0) {
entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, null);
}
}
return true;
} else if (Configuration.MyPet.PigZombie.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 de.Keyle.MyPet.api.entity.EquipmentSlot in project MyPet by xXKeyleXx.
the class EntityMyZombie method handlePlayerInteraction.
/**
* Is called when player rightclicks this MyPet
* return:
* true: there was a reaction on rightclick
* false: no reaction on rightclick
*/
public boolean handlePlayerInteraction(EntityHuman entityhuman) {
if (super.handlePlayerInteraction(entityhuman)) {
return true;
}
ItemStack itemStack = entityhuman.inventory.getItemInHand();
if (getOwner().equals(entityhuman) && itemStack != null) {
if (itemStack.getItem() == Items.SHEARS && getOwner().getPlayer().isSneaking() && canEquip()) {
boolean hadEquipment = false;
for (EquipmentSlot slot : EquipmentSlot.values()) {
ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot));
if (itemInSlot != null) {
EntityItem entityitem = this.a(itemInSlot.cloneItemStack(), 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);
getMyPet().setEquipment(slot, null);
hadEquipment = true;
}
}
if (hadEquipment) {
if (!entityhuman.abilities.canInstantlyBuild) {
itemStack.damage(1, entityhuman);
}
}
return true;
} else if (MyPetApi.getPlatformHelper().isEquipment(CraftItemStack.asBukkitCopy(itemStack)) && getOwner().getPlayer().isSneaking() && canEquip()) {
EquipmentSlot slot = EquipmentSlot.getSlotById(c(itemStack));
ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot));
if (itemInSlot != null && !entityhuman.abilities.canInstantlyBuild) {
EntityItem entityitem = this.a(itemInSlot.cloneItemStack(), 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);
}
getMyPet().setEquipment(slot, CraftItemStack.asBukkitCopy(itemStack));
if (!entityhuman.abilities.canInstantlyBuild) {
if (--itemStack.count <= 0) {
entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, null);
}
}
return true;
} else if (Configuration.MyPet.Zombie.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 de.Keyle.MyPet.api.entity.EquipmentSlot in project MyPet by xXKeyleXx.
the class EntityMyPigZombie method handlePlayerInteraction.
public boolean handlePlayerInteraction(EntityHuman entityhuman, EnumHand enumhand, ItemStack itemStack) {
if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack)) {
return true;
}
if (getOwner().equals(entityhuman) && itemStack != null && canUseItem()) {
if (itemStack.getItem() == Items.SHEARS && getOwner().getPlayer().isSneaking() && canEquip()) {
boolean hadEquipment = false;
for (EquipmentSlot slot : EquipmentSlot.values()) {
ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot));
if (itemInSlot != null) {
EntityItem entityitem = new EntityItem(this.world, this.locX, this.locY + 1, this.locZ, itemInSlot);
entityitem.pickupDelay = 10;
entityitem.motY += (double) (this.random.nextFloat() * 0.05F);
this.world.addEntity(entityitem);
getMyPet().setEquipment(slot, null);
hadEquipment = true;
}
}
if (hadEquipment) {
if (!entityhuman.abilities.canInstantlyBuild) {
itemStack.damage(1, entityhuman);
}
}
return true;
} else if (MyPetApi.getPlatformHelper().isEquipment(CraftItemStack.asBukkitCopy(itemStack)) && getOwner().getPlayer().isSneaking() && canEquip()) {
EquipmentSlot slot = EquipmentSlot.getSlotById(d(itemStack).c());
ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot));
if (itemInSlot != null && !entityhuman.abilities.canInstantlyBuild) {
EntityItem entityitem = new EntityItem(this.world, this.locX, this.locY + 1, this.locZ, itemInSlot);
entityitem.pickupDelay = 10;
entityitem.motY += (double) (this.random.nextFloat() * 0.05F);
this.world.addEntity(entityitem);
}
getMyPet().setEquipment(slot, CraftItemStack.asBukkitCopy(itemStack));
if (!entityhuman.abilities.canInstantlyBuild) {
itemStack.subtract(1);
if (itemStack.getCount() <= 0) {
entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, ItemStack.a);
}
}
return true;
} else if (Configuration.MyPet.PigZombie.GROW_UP_ITEM.compare(itemStack) && getMyPet().isBaby() && getOwner().getPlayer().isSneaking()) {
if (!entityhuman.abilities.canInstantlyBuild) {
itemStack.subtract(1);
if (itemStack.getCount() <= 0) {
entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, ItemStack.a);
}
}
getMyPet().setBaby(false);
return true;
}
}
return false;
}
Aggregations