use of net.minecraft.server.v1_16_R1.EntityItem in project MyPet by xXKeyleXx.
the class EntityMyWitherSkeleton method handlePlayerInteraction.
@Override
public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, EnumHand enumhand, ItemStack itemStack) {
if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).a()) {
return EnumInteractionResult.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) {
EntityItem entityitem = new EntityItem(this.world, this.locX(), this.locY() + 1, this.locZ(), itemInSlot);
entityitem.pickupDelay = 10;
entityitem.setMot(entityitem.getMot().add(0, this.random.nextFloat() * 0.05F, 0));
this.world.addEntity(entityitem);
getMyPet().setEquipment(slot, null);
hadEquipment = true;
}
}
if (hadEquipment) {
if (itemStack != ItemStack.b && !entityhuman.abilities.canInstantlyBuild) {
try {
itemStack.damage(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastItemBreak(enumhand));
} catch (Error e) {
// TODO REMOVE
itemStack.damage(1, entityhuman, (entityhuman1) -> {
try {
ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand);
} catch (IllegalAccessException | InvocationTargetException ex) {
ex.printStackTrace();
}
});
}
}
}
return EnumInteractionResult.CONSUME;
} else if (MyPetApi.getPlatformHelper().isEquipment(CraftItemStack.asBukkitCopy(itemStack)) && getOwner().getPlayer().isSneaking() && canEquip()) {
EquipmentSlot slot = EquipmentSlot.getSlotById(j(itemStack).c());
ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot));
if (itemInSlot != null && itemInSlot.getItem() != Items.AIR && itemInSlot != ItemStack.b && !entityhuman.abilities.canInstantlyBuild) {
EntityItem entityitem = new EntityItem(this.world, this.locX(), this.locY() + 1, this.locZ(), itemInSlot);
entityitem.pickupDelay = 10;
entityitem.setMot(entityitem.getMot().add(0, this.random.nextFloat() * 0.05F, 0));
this.world.addEntity(entityitem);
}
getMyPet().setEquipment(slot, CraftItemStack.asBukkitCopy(itemStack));
if (itemStack != ItemStack.b && !entityhuman.abilities.canInstantlyBuild) {
itemStack.subtract(1);
if (itemStack.getCount() <= 0) {
entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, ItemStack.b);
}
}
return EnumInteractionResult.CONSUME;
}
}
return EnumInteractionResult.PASS;
}
use of net.minecraft.server.v1_16_R1.EntityItem 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
*/
@Override
public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, EnumHand enumhand, ItemStack itemStack) {
if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).a()) {
return EnumInteractionResult.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) {
EntityItem entityitem = new EntityItem(this.world, this.locX(), this.locY() + 1, this.locZ(), itemInSlot);
entityitem.pickupDelay = 10;
entityitem.setMot(entityitem.getMot().add(0, this.random.nextFloat() * 0.05F, 0));
this.world.addEntity(entityitem);
getMyPet().setEquipment(slot, null);
hadEquipment = true;
}
}
if (hadEquipment) {
if (itemStack != ItemStack.b && !entityhuman.abilities.canInstantlyBuild) {
try {
itemStack.damage(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastItemBreak(enumhand));
} catch (Error e) {
// TODO REMOVE
itemStack.damage(1, entityhuman, (entityhuman1) -> {
try {
ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand);
} catch (IllegalAccessException | InvocationTargetException ex) {
ex.printStackTrace();
}
});
}
}
}
return EnumInteractionResult.CONSUME;
} else if (MyPetApi.getPlatformHelper().isEquipment(CraftItemStack.asBukkitCopy(itemStack)) && getOwner().getPlayer().isSneaking() && canEquip()) {
EquipmentSlot slot = EquipmentSlot.getSlotById(j(itemStack).c());
ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot));
if (itemInSlot != null && itemInSlot.getItem() != Items.AIR && itemInSlot != ItemStack.b && !entityhuman.abilities.canInstantlyBuild) {
EntityItem entityitem = new EntityItem(this.world, this.locX(), this.locY() + 1, this.locZ(), itemInSlot);
entityitem.pickupDelay = 10;
entityitem.setMot(entityitem.getMot().add(0, this.random.nextFloat() * 0.05F, 0));
this.world.addEntity(entityitem);
}
getMyPet().setEquipment(slot, CraftItemStack.asBukkitCopy(itemStack));
if (itemStack != ItemStack.b && !entityhuman.abilities.canInstantlyBuild) {
itemStack.subtract(1);
if (itemStack.getCount() <= 0) {
entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, ItemStack.b);
}
}
return EnumInteractionResult.CONSUME;
} else if (Configuration.MyPet.Zombie.GROW_UP_ITEM.compare(itemStack) && getMyPet().isBaby() && getOwner().getPlayer().isSneaking()) {
if (itemStack != ItemStack.b && !entityhuman.abilities.canInstantlyBuild) {
itemStack.subtract(1);
if (itemStack.getCount() <= 0) {
entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, ItemStack.b);
}
}
getMyPet().setBaby(false);
return EnumInteractionResult.CONSUME;
}
}
return EnumInteractionResult.PASS;
}
use of net.minecraft.server.v1_16_R1.EntityItem in project MyPet by xXKeyleXx.
the class EntityMyHusk method handlePlayerInteraction.
/**
* Is called when player rightclicks this MyPet
* return:
* true: there was a reaction on rightclick
* false: no reaction on rightclick
*/
@Override
public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, EnumHand enumhand, ItemStack itemStack) {
if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).a()) {
return EnumInteractionResult.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) {
EntityItem entityitem = new EntityItem(this.world, this.locX(), this.locY() + 1, this.locZ(), itemInSlot);
entityitem.pickupDelay = 10;
entityitem.setMot(entityitem.getMot().add(0, this.random.nextFloat() * 0.05F, 0));
this.world.addEntity(entityitem);
getMyPet().setEquipment(slot, null);
hadEquipment = true;
}
}
if (hadEquipment) {
if (itemStack != ItemStack.b && !entityhuman.abilities.canInstantlyBuild) {
try {
itemStack.damage(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastItemBreak(enumhand));
} catch (Error e) {
// TODO REMOVE
itemStack.damage(1, entityhuman, (entityhuman1) -> {
try {
ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand);
} catch (IllegalAccessException | InvocationTargetException ex) {
ex.printStackTrace();
}
});
}
}
}
return EnumInteractionResult.CONSUME;
} else if (MyPetApi.getPlatformHelper().isEquipment(CraftItemStack.asBukkitCopy(itemStack)) && getOwner().getPlayer().isSneaking() && canEquip()) {
EquipmentSlot slot = EquipmentSlot.getSlotById(j(itemStack).c());
ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot));
if (itemInSlot != null && itemInSlot.getItem() != Items.AIR && itemInSlot != ItemStack.b && !entityhuman.abilities.canInstantlyBuild) {
EntityItem entityitem = new EntityItem(this.world, this.locX(), this.locY() + 1, this.locZ(), itemInSlot);
entityitem.pickupDelay = 10;
entityitem.setMot(entityitem.getMot().add(0, this.random.nextFloat() * 0.05F, 0));
this.world.addEntity(entityitem);
}
getMyPet().setEquipment(slot, CraftItemStack.asBukkitCopy(itemStack));
if (itemStack != ItemStack.b && !entityhuman.abilities.canInstantlyBuild) {
itemStack.subtract(1);
if (itemStack.getCount() <= 0) {
entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, ItemStack.b);
}
}
return EnumInteractionResult.CONSUME;
} else if (Configuration.MyPet.Zombie.GROW_UP_ITEM.compare(itemStack) && getMyPet().isBaby() && getOwner().getPlayer().isSneaking()) {
if (itemStack != ItemStack.b && !entityhuman.abilities.canInstantlyBuild) {
itemStack.subtract(1);
if (itemStack.getCount() <= 0) {
entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, ItemStack.b);
}
}
getMyPet().setBaby(false);
return EnumInteractionResult.CONSUME;
}
}
return EnumInteractionResult.PASS;
}
use of net.minecraft.server.v1_16_R1.EntityItem in project MyPet by xXKeyleXx.
the class EntityMyStray method handlePlayerInteraction.
@Override
public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, EnumHand enumhand, ItemStack itemStack) {
if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).a()) {
return EnumInteractionResult.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) {
EntityItem entityitem = new EntityItem(this.world, this.locX(), this.locY() + 1, this.locZ(), itemInSlot);
entityitem.pickupDelay = 10;
entityitem.setMot(entityitem.getMot().add(0, this.random.nextFloat() * 0.05F, 0));
this.world.addEntity(entityitem);
getMyPet().setEquipment(slot, null);
hadEquipment = true;
}
}
if (hadEquipment) {
if (itemStack != ItemStack.b && !entityhuman.abilities.canInstantlyBuild) {
try {
itemStack.damage(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastItemBreak(enumhand));
} catch (Error e) {
// TODO REMOVE
itemStack.damage(1, entityhuman, (entityhuman1) -> {
try {
ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand);
} catch (IllegalAccessException | InvocationTargetException ex) {
ex.printStackTrace();
}
});
}
}
}
return EnumInteractionResult.CONSUME;
} else if (MyPetApi.getPlatformHelper().isEquipment(CraftItemStack.asBukkitCopy(itemStack)) && getOwner().getPlayer().isSneaking() && canEquip()) {
EquipmentSlot slot = EquipmentSlot.getSlotById(j(itemStack).c());
ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot));
if (itemInSlot != null && itemInSlot.getItem() != Items.AIR && itemInSlot != ItemStack.b && !entityhuman.abilities.canInstantlyBuild) {
EntityItem entityitem = new EntityItem(this.world, this.locX(), this.locY() + 1, this.locZ(), itemInSlot);
entityitem.pickupDelay = 10;
entityitem.setMot(entityitem.getMot().add(0, this.random.nextFloat() * 0.05F, 0));
this.world.addEntity(entityitem);
}
getMyPet().setEquipment(slot, CraftItemStack.asBukkitCopy(itemStack));
if (itemStack != ItemStack.b && !entityhuman.abilities.canInstantlyBuild) {
itemStack.subtract(1);
if (itemStack.getCount() <= 0) {
entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, ItemStack.b);
}
}
return EnumInteractionResult.CONSUME;
}
}
return EnumInteractionResult.PASS;
}
use of net.minecraft.server.v1_16_R1.EntityItem in project WildChests by BG-Software-LLC.
the class NMSAdapter_v1_16_R3 method getNearbyItems.
@Override
public Stream<Item> getNearbyItems(Location location, int range, boolean onlyChunk, KeySet blacklisted, KeySet whitelisted) {
World world = ((CraftWorld) location.getWorld()).getHandle();
List<Entity> entityList = new ArrayList<>();
if (onlyChunk) {
Chunk chunk = ((CraftChunk) location.getChunk()).getHandle();
for (int i = 0; i < chunk.entitySlices.length; i++) entityList.addAll(chunk.entitySlices[i]);
entityList = entityList.stream().filter(entity -> entity instanceof EntityItem).collect(Collectors.toList());
} else {
AxisAlignedBB boundingBox = new AxisAlignedBB(location.getX() + range, location.getY() + range, location.getZ() + range, location.getX() - range, location.getY() - range, location.getZ() - range);
entityList = world.getEntities(null, boundingBox, entity -> entity instanceof EntityItem);
}
return entityList.stream().map(entity -> (Item) entity.getBukkitEntity()).filter(item -> !blacklisted.contains(item.getItemStack()) && (whitelisted.isEmpty() || whitelisted.contains(item.getItemStack())));
}
Aggregations