Search in sources :

Example 51 with InventoryPlayer

use of net.minecraft.entity.player.InventoryPlayer in project MorePlanets by SteveKunG.

the class BlockInfectedVines method onEntityCollidedWithBlock.

@Override
public void onEntityCollidedWithBlock(World world, BlockPos pos, IBlockState state, Entity entity) {
    if (entity instanceof EntityLivingBase) {
        EntityLivingBase living = (EntityLivingBase) entity;
        if (living instanceof EntityPlayer) {
            EntityPlayer player = (EntityPlayer) entity;
            InventoryPlayer inventory = player.inventory;
            for (int i = 0; i < 4; i++) {
                if (!(inventory.armorInventory.get(i) != null && inventory.armorInventory.get(i).getItem() instanceof ItemArmor)) {
                    if (!player.capabilities.isCreativeMode) {
                        player.attackEntityFrom(DamageSourceMP.INFECTED_GAS, (int) (4.0D * 0.1D + 1.0D));
                        player.addPotionEffect(new PotionEffect(MobEffects.POISON, 50, 1));
                    }
                }
            }
        }
        if (!(living instanceof EntityPlayer) && !(entity instanceof ISpaceMob && ((ISpaceMob) entity).getMobType() == EnumMobType.NIBIRU)) {
            living.attackEntityFrom(DamageSourceMP.INFECTED_GAS, (int) (4.0D * 0.1D + 1.0D));
            living.addPotionEffect(new PotionEffect(MobEffects.POISON, 50, 1));
        }
    }
}
Also used : InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) ISpaceMob(stevekung.mods.moreplanets.util.entity.ISpaceMob) PotionEffect(net.minecraft.potion.PotionEffect) ItemArmor(net.minecraft.item.ItemArmor) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer)

Example 52 with InventoryPlayer

use of net.minecraft.entity.player.InventoryPlayer in project Totemic by TeamTotemic.

the class CeremonyFluteInfusion method effect.

@Override
public void effect(World world, BlockPos pos, CeremonyEffectContext context) {
    if (world.isRemote)
        return;
    for (EntityItem entity : EntityUtil.getEntitiesInRange(EntityItem.class, world, pos, 5, 5)) {
        if (entity.getItem().getItem() == ModItems.flute) {
            EntityUtil.dropItem(world, entity.posX, entity.posY, entity.posZ, new ItemStack(ModItems.flute, 1, 1));
            entity.setDead();
        }
    }
    for (EntityPlayer player : EntityUtil.getEntitiesInRange(EntityPlayer.class, world, pos, 5, 5)) {
        InventoryPlayer inv = player.inventory;
        for (int i = 0; i < inv.getSizeInventory(); i++) {
            if (inv.getStackInSlot(i).getItem() == ModItems.flute)
                inv.setInventorySlotContents(i, new ItemStack(ModItems.flute, 1, 1));
        }
        player.inventoryContainer.detectAndSendChanges();
    }
}
Also used : InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Example 53 with InventoryPlayer

use of net.minecraft.entity.player.InventoryPlayer in project Charset by CharsetMC.

the class TileEntityDayBarrel method addAllItems.

void addAllItems(EntityPlayer entityplayer, EnumHand hand) {
    switch(insertFromItemHandler(entityplayer, true)) {
        case PASS:
            break;
        case SUCCESS:
            return;
        case FAIL:
            info(entityplayer);
            return;
    }
    ItemStack held = entityplayer.getHeldItem(hand);
    InventoryPlayer inv = entityplayer.inventory;
    int total_delta = 0;
    for (int i = 0; i < inv.getSizeInventory(); i++) {
        int free_space = getMaxItemCount() - (getItemCount() + total_delta);
        if (free_space <= 0) {
            break;
        }
        ItemStack is = inv.getStackInSlot(i);
        if (is.isEmpty() || !itemMatch(is)) {
            continue;
        }
        int toAdd = Math.min(is.getCount(), free_space);
        if (is == held && toAdd > 1) {
            toAdd -= 1;
        }
        total_delta += toAdd;
        is.shrink(toAdd);
    }
    if (total_delta > 0) {
        item.grow(total_delta);
        onItemChange(false);
        entityplayer.inventory.markDirty();
    }
}
Also used : InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) ItemStack(net.minecraft.item.ItemStack)

Example 54 with InventoryPlayer

use of net.minecraft.entity.player.InventoryPlayer in project Charset by CharsetMC.

the class CharsetTweakAutoReplace method onPlayerDestroyItem.

@SubscribeEvent
public void onPlayerDestroyItem(PlayerDestroyItemEvent event) {
    if (!(event.getEntity() instanceof EntityPlayerMP) || event.getEntity().world.isRemote || event.getOriginal().isEmpty()) {
        return;
    }
    EntityPlayerMP player = (EntityPlayerMP) event.getEntityPlayer();
    InventoryPlayer inv = player.inventory;
    ItemStack currentItem = inv.getCurrentItem();
    if (currentItem != event.getOriginal()) {
        return;
    }
    int row, lastEmptiedSlot = -1;
    boolean changed = false;
    for (row = 2; row >= 0; row--) {
        int slot = inv.currentItem + row * 9 + 9;
        ItemStack stackAbove = inv.getStackInSlot(slot);
        if (!canReplace(stackAbove, event.getOriginal()))
            break;
        int targetSlot = ((slot < 27) ? (slot + 9) : (slot - 27));
        ItemStack stackTarget = stackAbove.copy();
        inv.setInventorySlotContents(targetSlot, stackTarget);
        inv.setInventorySlotContents(slot, ItemStack.EMPTY);
        player.connection.sendPacket(new SPacketSetSlot(-1, targetSlot, stackTarget));
        changed = true;
        lastEmptiedSlot = slot;
    }
    if (changed) {
        player.connection.sendPacket(new SPacketSetSlot(-1, lastEmptiedSlot, ItemStack.EMPTY));
    }
    inv.markDirty();
}
Also used : InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) SPacketSetSlot(net.minecraft.network.play.server.SPacketSetSlot) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 55 with InventoryPlayer

use of net.minecraft.entity.player.InventoryPlayer in project VoodooCraft by Mod-DevCafeTeam.

the class TileDeathGlyph method savePlayerInventory.

/**
     * Saves the player's inventory to this tile entity
     */
public void savePlayerInventory(EntityPlayer player) {
    playerInventory = new NBTTagCompound();
    InventoryPlayer playerInv = player.inventory;
    writeStacksToNBT(playerInventory, "main", playerInv.mainInventory);
    for (int i = 0; i < playerInv.mainInventory.length; i++) playerInv.mainInventory[i] = null;
    writeStacksToNBT(playerInventory, "armour", playerInv.armorInventory);
    for (int i = 0; i < playerInv.armorInventory.length; i++) playerInv.armorInventory[i] = null;
    writeStacksToNBT(playerInventory, "offhand", playerInv.offHandInventory);
    for (int i = 0; i < playerInv.offHandInventory.length; i++) playerInv.offHandInventory[i] = null;
}
Also used : InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Aggregations

InventoryPlayer (net.minecraft.entity.player.InventoryPlayer)83 ItemStack (net.minecraft.item.ItemStack)57 Slot (net.minecraft.inventory.Slot)15 EntityPlayer (net.minecraft.entity.player.EntityPlayer)14 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)9 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)7 Item (net.minecraft.item.Item)6 ArrayList (java.util.ArrayList)5 Nonnull (javax.annotation.Nonnull)4 IFuzzySlot (logisticspipes.interfaces.IFuzzySlot)4 Button (com.minecolonies.blockout.controls.Button)3 EntityItem (net.minecraft.entity.item.EntityItem)3 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)3 IPhantomSlot (buildcraft.lib.gui.slot.IPhantomSlot)2 TileProjectTable (com.bluepowermod.tile.tier1.TileProjectTable)2 ItemIcon (com.minecolonies.blockout.controls.ItemIcon)2 Label (com.minecolonies.blockout.controls.Label)2 BuildingBuilderResource (com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource)2 GameProfile (com.mojang.authlib.GameProfile)2 LinkedList (java.util.LinkedList)2