Search in sources :

Example 1 with PlayerInventoryBridge

use of io.izzel.arclight.common.bridge.entity.player.PlayerInventoryBridge in project Arclight by IzzelAliz.

the class ItemEntityMixin method onCollideWithPlayer.

/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite
public void onCollideWithPlayer(final PlayerEntity entity) {
    if (!this.world.isRemote) {
        final ItemStack itemstack = this.getItem();
        final net.minecraft.item.Item item = itemstack.getItem();
        final int i = itemstack.getCount();
        int hook = net.minecraftforge.event.ForgeEventFactory.onItemPickup((ItemEntity) (Object) this, entity);
        if (hook < 0)
            return;
        ItemStack copy = itemstack.copy();
        final int canHold = ((PlayerInventoryBridge) entity.inventory).bridge$canHold(itemstack);
        final int remaining = i - canHold;
        if (this.pickupDelay <= 0 && (hook == 1 || canHold > 0)) {
            copy.setCount(canHold);
            net.minecraftforge.fml.hooks.BasicEventHooks.firePlayerItemPickupEvent(entity, (ItemEntity) (Object) this, copy);
            itemstack.setCount(canHold);
            final PlayerPickupItemEvent playerEvent = new PlayerPickupItemEvent(((ServerPlayerEntityBridge) entity).bridge$getBukkitEntity(), (Item) this.getBukkitEntity(), remaining);
            playerEvent.setCancelled(!((PlayerEntityBridge) entity).bridge$canPickUpLoot());
            Bukkit.getPluginManager().callEvent(playerEvent);
            if (playerEvent.isCancelled()) {
                itemstack.setCount(i);
                return;
            }
            final EntityPickupItemEvent entityEvent = new EntityPickupItemEvent(((LivingEntityBridge) entity).bridge$getBukkitEntity(), (Item) this.getBukkitEntity(), remaining);
            entityEvent.setCancelled(!((PlayerEntityBridge) entity).bridge$canPickUpLoot());
            Bukkit.getPluginManager().callEvent(entityEvent);
            if (entityEvent.isCancelled()) {
                itemstack.setCount(i);
                return;
            }
            itemstack.setCount(canHold + remaining);
            this.pickupDelay = 0;
        } else if (this.pickupDelay == 0) {
            this.pickupDelay = -1;
        }
        if (this.pickupDelay == 0 && (this.owner == null || /*|| 6000 - this.age <= 200*/
        this.owner.equals(entity.getUniqueID())) && entity.inventory.addItemStackToInventory(itemstack)) {
            entity.onItemPickup((ItemEntity) (Object) this, i);
            if (itemstack.isEmpty()) {
                this.remove();
                itemstack.setCount(i);
            }
            entity.addStat(Stats.ITEM_PICKED_UP.get(item), i);
        }
    }
}
Also used : EntityPickupItemEvent(org.bukkit.event.entity.EntityPickupItemEvent) PlayerInventoryBridge(io.izzel.arclight.common.bridge.entity.player.PlayerInventoryBridge) ServerPlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge) PlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge) PlayerPickupItemEvent(org.bukkit.event.player.PlayerPickupItemEvent) ItemStack(net.minecraft.item.ItemStack) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 2 with PlayerInventoryBridge

use of io.izzel.arclight.common.bridge.entity.player.PlayerInventoryBridge in project Arclight by IzzelAliz.

the class AbstractArrowEntityMixin method onCollideWithPlayer.

/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite
public void onCollideWithPlayer(final PlayerEntity entityhuman) {
    if (!this.world.isRemote && (this.inGround || this.getNoClip()) && this.arrowShake <= 0) {
        ItemStack itemstack = this.getArrowStack();
        if (this.pickupStatus == AbstractArrowEntity.PickupStatus.ALLOWED && !itemstack.isEmpty() && ((PlayerInventoryBridge) entityhuman.inventory).bridge$canHold(itemstack) > 0) {
            final ItemEntity item = new ItemEntity(this.world, this.posX, this.posY, this.posZ, itemstack);
            final PlayerPickupArrowEvent event = new PlayerPickupArrowEvent(((ServerPlayerEntityBridge) entityhuman).bridge$getBukkitEntity(), new CraftItem(((CraftServer) Bukkit.getServer()), (AbstractArrowEntity) (Object) this, item), (AbstractArrow) this.getBukkitEntity());
            Bukkit.getPluginManager().callEvent(event);
            if (event.isCancelled()) {
                return;
            }
            itemstack = item.getItem();
        }
        boolean flag = this.pickupStatus == AbstractArrowEntity.PickupStatus.ALLOWED || (this.pickupStatus == AbstractArrowEntity.PickupStatus.CREATIVE_ONLY && entityhuman.abilities.isCreativeMode) || (this.getNoClip() && this.getShooter().getUniqueID() == entityhuman.getUniqueID());
        if (this.pickupStatus == AbstractArrowEntity.PickupStatus.ALLOWED && !entityhuman.inventory.addItemStackToInventory(itemstack)) {
            flag = false;
        }
        if (flag) {
            entityhuman.onItemPickup((AbstractArrowEntity) (Object) this, 1);
            this.remove();
        }
    }
}
Also used : ItemEntity(net.minecraft.entity.item.ItemEntity) PlayerInventoryBridge(io.izzel.arclight.common.bridge.entity.player.PlayerInventoryBridge) PlayerPickupArrowEvent(org.bukkit.event.player.PlayerPickupArrowEvent) ItemStack(net.minecraft.item.ItemStack) CraftItem(org.bukkit.craftbukkit.v.entity.CraftItem) AbstractArrowEntity(net.minecraft.entity.projectile.AbstractArrowEntity) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Aggregations

PlayerInventoryBridge (io.izzel.arclight.common.bridge.entity.player.PlayerInventoryBridge)2 ItemStack (net.minecraft.item.ItemStack)2 Overwrite (org.spongepowered.asm.mixin.Overwrite)2 PlayerEntityBridge (io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge)1 ServerPlayerEntityBridge (io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge)1 ItemEntity (net.minecraft.entity.item.ItemEntity)1 AbstractArrowEntity (net.minecraft.entity.projectile.AbstractArrowEntity)1 CraftItem (org.bukkit.craftbukkit.v.entity.CraftItem)1 EntityPickupItemEvent (org.bukkit.event.entity.EntityPickupItemEvent)1 PlayerPickupArrowEvent (org.bukkit.event.player.PlayerPickupArrowEvent)1 PlayerPickupItemEvent (org.bukkit.event.player.PlayerPickupItemEvent)1