Search in sources :

Example 1 with PlayerEntityBridge

use of io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge 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 PlayerEntityBridge

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

the class ContainerMixin method getBukkitView.

// todo check this
public InventoryView getBukkitView() {
    if (bukkitView == null) {
        PlayerEntity candidate = null;
        Set<IInventory> set = new HashSet<>();
        for (Slot slot : this.inventorySlots) {
            if (slot.inventory != null) {
                if (slot.inventory instanceof PlayerInventory) {
                    if (candidate != null && ((PlayerInventory) slot.inventory).player != candidate) {
                        ArclightMod.LOGGER.warn("Duplicate PlayerInventory inside {}, previous {}, new {}", this, candidate, slot.inventory);
                    }
                    candidate = ((PlayerInventory) slot.inventory).player;
                } else {
                    set.add(slot.inventory);
                }
            }
        }
        if (candidate == null) {
            if (ArclightCaptures.getContainerOwner() != null) {
                candidate = ArclightCaptures.getContainerOwner();
            } else {
                throw new RuntimeException("candidate cannot be null");
            }
        }
        CraftResultInventory resultCandidate = null;
        IInventory mainCandidate = null;
        for (IInventory inventory : set) {
            if (inventory instanceof CraftResultInventory) {
                resultCandidate = (CraftResultInventory) inventory;
            } else {
                mainCandidate = inventory;
            }
        }
        Inventory inv;
        if (mainCandidate == null && resultCandidate != null) {
            mainCandidate = resultCandidate;
            resultCandidate = null;
        }
        if (mainCandidate != null) {
            if (resultCandidate != null) {
                inv = new org.bukkit.craftbukkit.v.inventory.CraftResultInventory(mainCandidate, resultCandidate);
            } else {
                inv = new CraftInventory(mainCandidate);
            }
        } else {
            // container has no slots
            inv = new CraftInventoryCustom(((PlayerEntityBridge) candidate).bridge$getBukkitEntity(), 0);
        }
        bukkitView = new CraftInventoryView(((PlayerEntityBridge) candidate).bridge$getBukkitEntity(), inv, (Container) (Object) this);
    }
    return bukkitView;
}
Also used : IInventory(net.minecraft.inventory.IInventory) CraftInventoryCustom(org.bukkit.craftbukkit.v.inventory.CraftInventoryCustom) CraftInventory(org.bukkit.craftbukkit.v.inventory.CraftInventory) PlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge) PlayerInventory(net.minecraft.entity.player.PlayerInventory) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) Container(net.minecraft.inventory.container.Container) CraftInventoryView(org.bukkit.craftbukkit.v.inventory.CraftInventoryView) Slot(net.minecraft.inventory.container.Slot) CraftResultInventory(net.minecraft.inventory.CraftResultInventory) Inventory(org.bukkit.inventory.Inventory) CraftInventory(org.bukkit.craftbukkit.v.inventory.CraftInventory) CraftResultInventory(net.minecraft.inventory.CraftResultInventory) PlayerInventory(net.minecraft.entity.player.PlayerInventory) IInventory(net.minecraft.inventory.IInventory) HashSet(java.util.HashSet)

Example 3 with PlayerEntityBridge

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

the class DispenserContainerMixin method getBukkitView.

@Override
public CraftInventoryView getBukkitView() {
    if (bukkitEntity != null) {
        return bukkitEntity;
    }
    CraftInventory inventory = new CraftInventory(this.dispenserInventory);
    bukkitEntity = new CraftInventoryView(((PlayerEntityBridge) this.playerInventory.player).bridge$getBukkitEntity(), inventory, (Container) (Object) this);
    return bukkitEntity;
}
Also used : CraftInventory(org.bukkit.craftbukkit.v.inventory.CraftInventory) Container(net.minecraft.inventory.container.Container) DispenserContainer(net.minecraft.inventory.container.DispenserContainer) CraftInventoryView(org.bukkit.craftbukkit.v.inventory.CraftInventoryView) PlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge)

Example 4 with PlayerEntityBridge

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

the class EnchantmentContainerMixin method getBukkitView.

@Override
public CraftInventoryView getBukkitView() {
    if (bukkitEntity != null) {
        return bukkitEntity;
    }
    CraftInventoryEnchanting inventory = new CraftInventoryEnchanting(this.tableInventory);
    bukkitEntity = new CraftInventoryView(((PlayerEntityBridge) this.playerInventory.player).bridge$getBukkitEntity(), inventory, (Container) (Object) this);
    return bukkitEntity;
}
Also used : CraftInventoryEnchanting(org.bukkit.craftbukkit.v.inventory.CraftInventoryEnchanting) Container(net.minecraft.inventory.container.Container) EnchantmentContainer(net.minecraft.inventory.container.EnchantmentContainer) CraftInventoryView(org.bukkit.craftbukkit.v.inventory.CraftInventoryView) ServerPlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge) PlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge)

Example 5 with PlayerEntityBridge

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

the class AbstractFurnaceContainerMixin method getBukkitView.

@Override
public CraftInventoryView getBukkitView() {
    if (bukkitEntity != null) {
        return bukkitEntity;
    }
    CraftInventoryFurnace inventory = new CraftInventoryFurnace((AbstractFurnaceTileEntity) this.furnaceInventory);
    bukkitEntity = new CraftInventoryView(((PlayerEntityBridge) this.playerInventory.player).bridge$getBukkitEntity(), inventory, (Container) (Object) this);
    return bukkitEntity;
}
Also used : Container(net.minecraft.inventory.container.Container) AbstractFurnaceContainer(net.minecraft.inventory.container.AbstractFurnaceContainer) CraftInventoryFurnace(org.bukkit.craftbukkit.v.inventory.CraftInventoryFurnace) CraftInventoryView(org.bukkit.craftbukkit.v.inventory.CraftInventoryView) PlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge)

Aggregations

PlayerEntityBridge (io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge)20 Container (net.minecraft.inventory.container.Container)15 CraftInventoryView (org.bukkit.craftbukkit.v.inventory.CraftInventoryView)15 CraftInventory (org.bukkit.craftbukkit.v.inventory.CraftInventory)5 Player (org.bukkit.entity.Player)5 Overwrite (org.spongepowered.asm.mixin.Overwrite)5 EntityBridge (io.izzel.arclight.common.bridge.entity.EntityBridge)4 ServerPlayerEntityBridge (io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge)4 MobEntity (net.minecraft.entity.MobEntity)3 PlayerInventory (net.minecraft.entity.player.PlayerInventory)3 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)3 LeashKnotEntity (net.minecraft.entity.item.LeashKnotEntity)2 PlayerEntity (net.minecraft.entity.player.PlayerEntity)2 IInventory (net.minecraft.inventory.IInventory)2 EnchantmentContainer (net.minecraft.inventory.container.EnchantmentContainer)2 ItemStack (net.minecraft.item.ItemStack)2 BlockPos (net.minecraft.util.math.BlockPos)2 HangingPlaceEvent (org.bukkit.event.hanging.HangingPlaceEvent)2 InternalEntityBridge (io.izzel.arclight.common.bridge.entity.InternalEntityBridge)1 PlayerInventoryBridge (io.izzel.arclight.common.bridge.entity.player.PlayerInventoryBridge)1