Search in sources :

Example 21 with EntityItem

use of net.minecraft.server.v1_16_R3.EntityItem in project MyPet by xXKeyleXx.

the class EntityMySkeleton 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(EntityInsentient.j(itemStack).getSlotFlag());
            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;
}
Also used : MyPet(de.Keyle.MyPet.api.entity.MyPet) Util(de.Keyle.MyPet.api.Util) Arrays(java.util.Arrays) PetState(de.Keyle.MyPet.api.entity.MyPet.PetState) EntitySize(de.Keyle.MyPet.api.entity.EntitySize) MySkeleton(de.Keyle.MyPet.api.entity.types.MySkeleton) MyPetApi(de.Keyle.MyPet.MyPetApi) EquipmentSlot(de.Keyle.MyPet.api.entity.EquipmentSlot) net.minecraft.server.v1_16_R3(net.minecraft.server.v1_16_R3) Pair(com.mojang.datafixers.util.Pair) InvocationTargetException(java.lang.reflect.InvocationTargetException) ENTITY_LIVING_broadcastItemBreak(de.Keyle.MyPet.compat.v1_16_R3.CompatManager.ENTITY_LIVING_broadcastItemBreak) EntityMyPet(de.Keyle.MyPet.compat.v1_16_R3.entity.EntityMyPet) Bukkit(org.bukkit.Bukkit) CraftItemStack(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack) EquipmentSlot(de.Keyle.MyPet.api.entity.EquipmentSlot) CraftItemStack(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack)

Example 22 with EntityItem

use of net.minecraft.server.v1_16_R3.EntityItem in project MyPet by xXKeyleXx.

the class EntityMyPig method handlePlayerInteraction.

public boolean handlePlayerInteraction(final EntityHuman entityhuman, EnumHand enumhand, final ItemStack itemStack) {
    if (enumhand == EnumHand.OFF_HAND) {
        if (itemStack != null) {
            if (itemStack.getItem() == Items.LEAD) {
                ((WorldServer) this.world).getTracker().a(this, new PacketPlayOutAttachEntity(this, null));
                entityhuman.a(EnumHand.OFF_HAND, null);
                new BukkitRunnable() {

                    public void run() {
                        if (entityhuman instanceof EntityPlayer) {
                            entityhuman.a(EnumHand.OFF_HAND, itemStack);
                            Player p = (Player) entityhuman.getBukkitEntity();
                            if (!p.isOnline()) {
                                p.saveData();
                            }
                        }
                    }
                }.runTaskLater(MyPetApi.getPlugin(), 5);
            }
        }
        return true;
    }
    if (isMyPet() && myPet.getOwner().equals(entityhuman)) {
        if (Configuration.Skilltree.Skill.Ride.RIDE_ITEM == null || Configuration.Skilltree.Skill.Ride.RIDE_ITEM.compare(itemStack)) {
            if (myPet.getSkills().isActive(RideImpl.class) && canMove()) {
                if (itemStack != null && itemStack.getItem() == Items.LEAD) {
                    ((WorldServer) this.world).getTracker().a(this, new PacketPlayOutAttachEntity(this, null));
                    entityhuman.a(EnumHand.MAIN_HAND, null);
                    new BukkitRunnable() {

                        public void run() {
                            if (entityhuman instanceof EntityPlayer) {
                                entityhuman.a(EnumHand.MAIN_HAND, itemStack);
                                Player p = (Player) entityhuman.getBukkitEntity();
                                if (!p.isOnline()) {
                                    p.saveData();
                                }
                            }
                        }
                    }.runTaskLater(MyPetApi.getPlugin(), 5);
                }
                getOwner().sendMessage("Unfortunately, pigs can not be ridden (Minecraft limitation)", 5000);
                return true;
            }
        }
    }
    if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack)) {
        return true;
    }
    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 = new EntityItem(this.world, this.locX, this.locY + 1, this.locZ, CraftItemStack.asNMSCopy(getMyPet().getSaddle()));
            entityitem.pickupDelay = 10;
            entityitem.motY += (double) (this.random.nextFloat() * 0.05F);
            this.world.addEntity(entityitem);
            makeSound("entity.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;
}
Also used : PacketPlayOutAttachEntity(net.minecraft.server.v1_9_R2.PacketPlayOutAttachEntity) Player(org.bukkit.entity.Player) EntityPlayer(net.minecraft.server.v1_9_R2.EntityPlayer) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) EntityPlayer(net.minecraft.server.v1_9_R2.EntityPlayer) RideImpl(de.Keyle.MyPet.skill.skills.RideImpl) EntityItem(net.minecraft.server.v1_9_R2.EntityItem)

Example 23 with EntityItem

use of net.minecraft.server.v1_16_R3.EntityItem in project WildChests by BG-Software-LLC.

the class NMSAdapter_v1_12_R1 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())));
}
Also used : AxisAlignedBB(net.minecraft.server.v1_12_R1.AxisAlignedBB) InventoryHolder(com.bgsoftware.wildchests.objects.inventory.InventoryHolder) DataInputStream(java.io.DataInputStream) TileEntityChest(net.minecraft.server.v1_12_R1.TileEntityChest) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Item(org.bukkit.entity.Item) NBTTagCompound(net.minecraft.server.v1_12_R1.NBTTagCompound) AxisAlignedBB(net.minecraft.server.v1_12_R1.AxisAlignedBB) Inventory(org.bukkit.inventory.Inventory) ArrayList(java.util.ArrayList) Entity(net.minecraft.server.v1_12_R1.Entity) EntityHuman(net.minecraft.server.v1_12_R1.EntityHuman) Chunk(net.minecraft.server.v1_12_R1.Chunk) World(net.minecraft.server.v1_12_R1.World) Location(org.bukkit.Location) ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) BigInteger(java.math.BigInteger) ChestType(com.bgsoftware.wildchests.api.objects.ChestType) KeySet(com.bgsoftware.wildchests.key.KeySet) Material(org.bukkit.Material) HumanEntity(org.bukkit.entity.HumanEntity) CraftItemStack(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack) DataOutput(java.io.DataOutput) CraftChunk(org.bukkit.craftbukkit.v1_12_R1.CraftChunk) NBTCompressedStreamTools(net.minecraft.server.v1_12_R1.NBTCompressedStreamTools) BlockPosition(net.minecraft.server.v1_12_R1.BlockPosition) CraftHumanEntity(org.bukkit.craftbukkit.v1_12_R1.entity.CraftHumanEntity) Collectors(java.util.stream.Collectors) Particle(org.bukkit.Particle) NBTTagList(net.minecraft.server.v1_12_R1.NBTTagList) Base64(java.util.Base64) List(java.util.List) Stream(java.util.stream.Stream) CraftWorld(org.bukkit.craftbukkit.v1_12_R1.CraftWorld) EntityItem(net.minecraft.server.v1_12_R1.EntityItem) ItemStack(net.minecraft.server.v1_12_R1.ItemStack) Entity(net.minecraft.server.v1_12_R1.Entity) HumanEntity(org.bukkit.entity.HumanEntity) CraftHumanEntity(org.bukkit.craftbukkit.v1_12_R1.entity.CraftHumanEntity) Item(org.bukkit.entity.Item) EntityItem(net.minecraft.server.v1_12_R1.EntityItem) ArrayList(java.util.ArrayList) World(net.minecraft.server.v1_12_R1.World) CraftWorld(org.bukkit.craftbukkit.v1_12_R1.CraftWorld) Chunk(net.minecraft.server.v1_12_R1.Chunk) CraftChunk(org.bukkit.craftbukkit.v1_12_R1.CraftChunk) CraftWorld(org.bukkit.craftbukkit.v1_12_R1.CraftWorld) CraftChunk(org.bukkit.craftbukkit.v1_12_R1.CraftChunk) EntityItem(net.minecraft.server.v1_12_R1.EntityItem)

Example 24 with EntityItem

use of net.minecraft.server.v1_16_R3.EntityItem in project WildChests by BG-Software-LLC.

the class NMSAdapter_v1_8_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.a((Entity) 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())));
}
Also used : AxisAlignedBB(net.minecraft.server.v1_8_R3.AxisAlignedBB) InventoryHolder(com.bgsoftware.wildchests.objects.inventory.InventoryHolder) DataInputStream(java.io.DataInputStream) NBTTagList(net.minecraft.server.v1_8_R3.NBTTagList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Item(org.bukkit.entity.Item) EntityHuman(net.minecraft.server.v1_8_R3.EntityHuman) EntityItem(net.minecraft.server.v1_8_R3.EntityItem) NBTTagCompound(net.minecraft.server.v1_8_R3.NBTTagCompound) Inventory(org.bukkit.inventory.Inventory) ArrayList(java.util.ArrayList) Effect(org.bukkit.Effect) Location(org.bukkit.Location) ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) NBTCompressedStreamTools(net.minecraft.server.v1_8_R3.NBTCompressedStreamTools) CraftWorld(org.bukkit.craftbukkit.v1_8_R3.CraftWorld) BigInteger(java.math.BigInteger) ChestType(com.bgsoftware.wildchests.api.objects.ChestType) KeySet(com.bgsoftware.wildchests.key.KeySet) ItemStack(net.minecraft.server.v1_8_R3.ItemStack) CraftHumanEntity(org.bukkit.craftbukkit.v1_8_R3.entity.CraftHumanEntity) Material(org.bukkit.Material) CraftItemStack(org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack) HumanEntity(org.bukkit.entity.HumanEntity) DataOutput(java.io.DataOutput) TileEntityChest(net.minecraft.server.v1_8_R3.TileEntityChest) CraftChunk(org.bukkit.craftbukkit.v1_8_R3.CraftChunk) Collectors(java.util.stream.Collectors) World(net.minecraft.server.v1_8_R3.World) Base64(java.util.Base64) List(java.util.List) Stream(java.util.stream.Stream) Chunk(net.minecraft.server.v1_8_R3.Chunk) BlockPosition(net.minecraft.server.v1_8_R3.BlockPosition) AxisAlignedBB(net.minecraft.server.v1_8_R3.AxisAlignedBB) Entity(net.minecraft.server.v1_8_R3.Entity) CraftHumanEntity(org.bukkit.craftbukkit.v1_8_R3.entity.CraftHumanEntity) HumanEntity(org.bukkit.entity.HumanEntity) Entity(net.minecraft.server.v1_8_R3.Entity) Item(org.bukkit.entity.Item) EntityItem(net.minecraft.server.v1_8_R3.EntityItem) ArrayList(java.util.ArrayList) CraftWorld(org.bukkit.craftbukkit.v1_8_R3.CraftWorld) World(net.minecraft.server.v1_8_R3.World) CraftChunk(org.bukkit.craftbukkit.v1_8_R3.CraftChunk) Chunk(net.minecraft.server.v1_8_R3.Chunk) CraftWorld(org.bukkit.craftbukkit.v1_8_R3.CraftWorld) CraftChunk(org.bukkit.craftbukkit.v1_8_R3.CraftChunk) EntityItem(net.minecraft.server.v1_8_R3.EntityItem)

Aggregations

CraftItemStack (org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack)19 MyPetApi (de.Keyle.MyPet.MyPetApi)18 EntitySize (de.Keyle.MyPet.api.entity.EntitySize)18 MyPet (de.Keyle.MyPet.api.entity.MyPet)18 EntityMyPet (de.Keyle.MyPet.compat.v1_16_R3.entity.EntityMyPet)18 InvocationTargetException (java.lang.reflect.InvocationTargetException)18 net.minecraft.server.v1_16_R3 (net.minecraft.server.v1_16_R3)18 Pair (com.mojang.datafixers.util.Pair)17 Util (de.Keyle.MyPet.api.Util)17 EquipmentSlot (de.Keyle.MyPet.api.entity.EquipmentSlot)17 Arrays (java.util.Arrays)17 Bukkit (org.bukkit.Bukkit)17 ENTITY_LIVING_broadcastItemBreak (de.Keyle.MyPet.compat.v1_16_R3.CompatManager.ENTITY_LIVING_broadcastItemBreak)15 Configuration (de.Keyle.MyPet.api.Configuration)10 PetState (de.Keyle.MyPet.api.entity.MyPet.PetState)6 Location (org.bukkit.Location)4 ChestType (com.bgsoftware.wildchests.api.objects.ChestType)3 KeySet (com.bgsoftware.wildchests.key.KeySet)3 InventoryHolder (com.bgsoftware.wildchests.objects.inventory.InventoryHolder)3 CompatManager (de.Keyle.MyPet.compat.v1_16_R3.CompatManager)3