use of net.minecraft.world.item.ItemStack in project MyPet by xXKeyleXx.
the class EntityMyLlama method handlePlayerInteraction.
@Override
public InteractionResult handlePlayerInteraction(Player entityhuman, InteractionHand enumhand, ItemStack itemStack) {
if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).consumesAction()) {
return InteractionResult.CONSUME;
}
if (itemStack != null && canUseItem()) {
if (ItemTags.CARPETS.contains(itemStack.getItem()) && !getMyPet().hasDecor() && getOwner().getPlayer().isSneaking() && canEquip()) {
getMyPet().setDecor(CraftItemStack.asBukkitCopy(itemStack));
if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) {
itemStack.shrink(1);
if (itemStack.getCount() <= 0) {
entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY);
}
}
return InteractionResult.CONSUME;
} else if (itemStack.getItem() == Blocks.CHEST.asItem() && getOwner().getPlayer().isSneaking() && !getMyPet().hasChest() && !getMyPet().isBaby() && canEquip()) {
getMyPet().setChest(CraftItemStack.asBukkitCopy(itemStack));
if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) {
itemStack.shrink(1);
if (itemStack.getCount() <= 0) {
entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY);
}
}
return InteractionResult.CONSUME;
} else if (itemStack.getItem() == Items.SHEARS && getOwner().getPlayer().isSneaking() && canEquip()) {
if (getMyPet().hasChest()) {
ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), CraftItemStack.asNMSCopy(getMyPet().getChest()));
entityitem.pickupDelay = 10;
entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0));
this.level.addFreshEntity(entityitem);
}
if (getMyPet().hasDecor()) {
ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), CraftItemStack.asNMSCopy(getMyPet().getDecor()));
entityitem.pickupDelay = 10;
entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0));
this.level.addFreshEntity(entityitem);
}
makeSound("entity.sheep.shear", 1.0F, 1.0F);
getMyPet().setChest(null);
getMyPet().setDecor(null);
if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) {
try {
itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastBreakEvent(enumhand));
} catch (Error e) {
// TODO REMOVE
itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> {
try {
CompatManager.ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand);
} catch (IllegalAccessException | InvocationTargetException ex) {
ex.printStackTrace();
}
});
}
}
return InteractionResult.CONSUME;
} else if (Configuration.MyPet.Llama.GROW_UP_ITEM.compare(itemStack) && getMyPet().isBaby() && getOwner().getPlayer().isSneaking()) {
if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) {
itemStack.shrink(1);
if (itemStack.getCount() <= 0) {
entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY);
}
}
getMyPet().setBaby(false);
return InteractionResult.CONSUME;
}
}
return InteractionResult.PASS;
}
use of net.minecraft.world.item.ItemStack in project MyPet by xXKeyleXx.
the class EntityMyPiglin method handlePlayerInteraction.
@Override
public InteractionResult handlePlayerInteraction(Player entityhuman, InteractionHand enumhand, ItemStack itemStack) {
if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack) == InteractionResult.CONSUME) {
return InteractionResult.CONSUME;
}
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 && itemInSlot.getItem() != Items.AIR) {
ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), itemInSlot);
entityitem.pickupDelay = 10;
entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0));
this.level.addFreshEntity(entityitem);
getMyPet().setEquipment(slot, null);
hadEquipment = true;
}
}
if (hadEquipment) {
if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) {
try {
itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastBreakEvent(enumhand));
} catch (Error e) {
// TODO REMOVE
itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> {
try {
CompatManager.ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand);
} catch (IllegalAccessException | InvocationTargetException ex) {
ex.printStackTrace();
}
});
}
}
}
return InteractionResult.CONSUME;
} else if (MyPetApi.getPlatformHelper().isEquipment(CraftItemStack.asBukkitCopy(itemStack)) && getOwner().getPlayer().isSneaking() && canEquip()) {
EquipmentSlot slot = EquipmentSlot.getSlotById(Mob.getEquipmentSlotForItem(itemStack).getFilterFlag());
ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot));
if (itemInSlot != null && itemInSlot.getItem() != Items.AIR && itemInSlot != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) {
ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), itemInSlot);
entityitem.pickupDelay = 10;
entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0));
this.level.addFreshEntity(entityitem);
}
getMyPet().setEquipment(slot, CraftItemStack.asBukkitCopy(itemStack));
if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) {
itemStack.shrink(1);
if (itemStack.getCount() <= 0) {
entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY);
}
}
return InteractionResult.CONSUME;
} else if (Configuration.MyPet.Piglin.GROW_UP_ITEM.compare(itemStack) && getMyPet().isBaby() && getOwner().getPlayer().isSneaking()) {
if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) {
itemStack.shrink(1);
if (itemStack.getCount() <= 0) {
entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY);
}
}
getMyPet().setBaby(false);
return InteractionResult.CONSUME;
}
}
return InteractionResult.PASS;
}
use of net.minecraft.world.item.ItemStack in project MyPet by xXKeyleXx.
the class EntityMyPillager method handlePlayerInteraction.
/**
* Is called when player rightclicks this MyPet
* return:
* true: there was a reaction on rightclick
* false: no reaction on rightclick
*/
@Override
public InteractionResult handlePlayerInteraction(Player entityhuman, InteractionHand enumhand, ItemStack itemStack) {
if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).consumesAction()) {
return InteractionResult.CONSUME;
}
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 && itemInSlot.getItem() != Items.AIR) {
ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), itemInSlot);
entityitem.pickupDelay = 10;
entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0));
this.level.addFreshEntity(entityitem);
getMyPet().setEquipment(slot, null);
hadEquipment = true;
}
}
if (hadEquipment) {
if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) {
try {
itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastBreakEvent(enumhand));
} catch (Error e) {
// TODO REMOVE
itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> {
try {
CompatManager.ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand);
} catch (IllegalAccessException | InvocationTargetException ex) {
ex.printStackTrace();
}
});
}
}
}
return InteractionResult.CONSUME;
} else if (MyPetApi.getPlatformHelper().isEquipment(CraftItemStack.asBukkitCopy(itemStack)) && getOwner().getPlayer().isSneaking() && canEquip()) {
EquipmentSlot slot = EquipmentSlot.getSlotById(Mob.getEquipmentSlotForItem(itemStack).getFilterFlag());
if (slot == EquipmentSlot.MainHand) {
ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot));
if (itemInSlot != null && itemInSlot.getItem() != Items.AIR && itemInSlot != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) {
ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), itemInSlot);
entityitem.pickupDelay = 10;
entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0));
this.level.addFreshEntity(entityitem);
}
getMyPet().setEquipment(slot, CraftItemStack.asBukkitCopy(itemStack));
if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) {
itemStack.shrink(1);
if (itemStack.getCount() <= 0) {
entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY);
}
}
return InteractionResult.CONSUME;
}
} else if (itemStack.getItem() instanceof BannerItem && getOwner().getPlayer().isSneaking() && canEquip()) {
ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(EquipmentSlot.Helmet));
if (itemInSlot != null && itemInSlot.getItem() != Items.AIR && itemInSlot != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) {
ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), itemInSlot);
entityitem.pickupDelay = 10;
entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0));
this.level.addFreshEntity(entityitem);
}
getMyPet().setEquipment(EquipmentSlot.Helmet, CraftItemStack.asBukkitCopy(itemStack));
if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) {
itemStack.shrink(1);
if (itemStack.getCount() <= 0) {
entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY);
}
}
return InteractionResult.CONSUME;
}
}
return InteractionResult.PASS;
}
use of net.minecraft.world.item.ItemStack in project MyPet by xXKeyleXx.
the class EntityMyStray method handlePlayerInteraction.
@Override
public InteractionResult handlePlayerInteraction(Player entityhuman, InteractionHand enumhand, ItemStack itemStack) {
if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).consumesAction()) {
return InteractionResult.CONSUME;
}
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 && itemInSlot.getItem() != Items.AIR) {
ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), itemInSlot);
entityitem.pickupDelay = 10;
entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0));
this.level.addFreshEntity(entityitem);
getMyPet().setEquipment(slot, null);
hadEquipment = true;
}
}
if (hadEquipment) {
if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) {
try {
itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastBreakEvent(enumhand));
} catch (Error e) {
// TODO REMOVE
itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> {
try {
CompatManager.ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand);
} catch (IllegalAccessException | InvocationTargetException ex) {
ex.printStackTrace();
}
});
}
}
}
return InteractionResult.CONSUME;
} else if (MyPetApi.getPlatformHelper().isEquipment(CraftItemStack.asBukkitCopy(itemStack)) && getOwner().getPlayer().isSneaking() && canEquip()) {
EquipmentSlot slot = EquipmentSlot.getSlotById(Mob.getEquipmentSlotForItem(itemStack).getFilterFlag());
ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot));
if (itemInSlot != null && itemInSlot.getItem() != Items.AIR && itemInSlot != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) {
ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), itemInSlot);
entityitem.pickupDelay = 10;
entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0));
this.level.addFreshEntity(entityitem);
}
getMyPet().setEquipment(slot, CraftItemStack.asBukkitCopy(itemStack));
if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) {
itemStack.shrink(1);
if (itemStack.getCount() <= 0) {
entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY);
}
}
return InteractionResult.CONSUME;
}
}
return InteractionResult.PASS;
}
use of net.minecraft.world.item.ItemStack in project MyPet by xXKeyleXx.
the class EntityMyTraderLlama method handlePlayerInteraction.
@Override
public InteractionResult handlePlayerInteraction(Player entityhuman, InteractionHand enumhand, ItemStack itemStack) {
if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).consumesAction()) {
return InteractionResult.CONSUME;
}
if (itemStack != null && canUseItem()) {
if (ItemTags.CARPETS.contains(itemStack.getItem()) && !getMyPet().hasDecor() && getOwner().getPlayer().isSneaking() && canEquip()) {
getMyPet().setDecor(CraftItemStack.asBukkitCopy(itemStack));
if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) {
itemStack.shrink(1);
if (itemStack.getCount() <= 0) {
entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY);
}
}
return InteractionResult.CONSUME;
} else if (itemStack.getItem() == Blocks.CHEST.asItem() && getOwner().getPlayer().isSneaking() && !getMyPet().hasChest() && !getMyPet().isBaby() && canEquip()) {
getMyPet().setChest(CraftItemStack.asBukkitCopy(itemStack));
if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) {
itemStack.shrink(1);
if (itemStack.getCount() <= 0) {
entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY);
}
}
return InteractionResult.CONSUME;
} else if (itemStack.getItem() == Items.SHEARS && getOwner().getPlayer().isSneaking() && canEquip()) {
if (getMyPet().hasChest()) {
ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), CraftItemStack.asNMSCopy(getMyPet().getChest()));
entityitem.pickupDelay = 10;
entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0));
this.level.addFreshEntity(entityitem);
}
if (getMyPet().hasDecor()) {
ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), CraftItemStack.asNMSCopy(getMyPet().getDecor()));
entityitem.pickupDelay = 10;
entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0));
this.level.addFreshEntity(entityitem);
}
makeSound("entity.sheep.shear", 1.0F, 1.0F);
getMyPet().setChest(null);
getMyPet().setDecor(null);
if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) {
try {
itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastBreakEvent(enumhand));
} catch (Error e) {
// TODO REMOVE
itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> {
try {
CompatManager.ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand);
} catch (IllegalAccessException | InvocationTargetException ex) {
ex.printStackTrace();
}
});
}
}
return InteractionResult.CONSUME;
} else if (Configuration.MyPet.Llama.GROW_UP_ITEM.compare(itemStack) && getMyPet().isBaby() && getOwner().getPlayer().isSneaking()) {
if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) {
itemStack.shrink(1);
if (itemStack.getCount() <= 0) {
entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY);
}
}
getMyPet().setBaby(false);
return InteractionResult.CONSUME;
}
}
return InteractionResult.PASS;
}
Aggregations