Search in sources :

Example 36 with InventoryPlayer

use of net.minecraft.entity.player.InventoryPlayer in project malmo by Microsoft.

the class PlaceCommandsImplementation method onExecute.

@Override
protected boolean onExecute(String verb, String parameter, MissionInit missionInit) {
    EntityPlayerSP player = Minecraft.getMinecraft().player;
    if (player == null)
        return false;
    if (!verb.equalsIgnoreCase("place"))
        return false;
    Item item = Item.getByNameOrId(parameter);
    Block block = Block.getBlockFromItem(item);
    if (item == null || item.getRegistryName() == null || block.getRegistryName() == null)
        return false;
    InventoryPlayer inv = player.inventory;
    boolean blockInInventory = false;
    ItemStack stackInInventory = null;
    int stackIndex = -1;
    for (int i = 0; !blockInInventory && i < inv.getSizeInventory(); i++) {
        Item stack = inv.getStackInSlot(i).getItem();
        if (stack.getRegistryName() != null && stack.getRegistryName().equals(item.getRegistryName())) {
            stackInInventory = inv.getStackInSlot(i);
            stackIndex = i;
            blockInInventory = true;
        }
    }
    // We don't have that item in our inventories
    if (!blockInInventory)
        return false;
    RayTraceResult mop = Minecraft.getMinecraft().objectMouseOver;
    if (mop.typeOfHit == RayTraceResult.Type.BLOCK) {
        BlockPos pos = mop.getBlockPos().add(mop.sideHit.getDirectionVec());
        // Can we place this block here?
        AxisAlignedBB axisalignedbb = block.getDefaultState().getCollisionBoundingBox(player.world, pos);
        if (axisalignedbb == null || player.world.checkNoEntityCollision(axisalignedbb.offset(pos), null)) {
            MalmoMod.network.sendToServer(new DiscreteMovementCommandsImplementation.UseActionMessage(mop.getBlockPos(), new ItemStack(block), mop.sideHit, false, mop.hitVec));
            if (stackInInventory.getCount() == 1)
                inv.setInventorySlotContents(stackIndex, new ItemStack(Block.getBlockById(0)));
            else
                stackInInventory.setCount(stackInInventory.getCount() - 1);
        }
    }
    return true;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Item(net.minecraft.item.Item) InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) RayTraceResult(net.minecraft.util.math.RayTraceResult) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP) ItemStack(net.minecraft.item.ItemStack)

Example 37 with InventoryPlayer

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

the class BlockInfectedVines method onEntityCollision.

@Override
public void onEntityCollision(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).isEmpty() || !(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.utils.entity.ISpaceMob) PotionEffect(net.minecraft.potion.PotionEffect) ItemArmor(net.minecraft.item.ItemArmor) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer)

Example 38 with InventoryPlayer

use of net.minecraft.entity.player.InventoryPlayer in project GregTech by GregTechCE.

the class ElectricStats method onUpdate.

@Override
public void onUpdate(ItemStack itemStack, Entity entity) {
    IElectricItem electricItem = itemStack.getCapability(GregtechCapabilities.CAPABILITY_ELECTRIC_ITEM, null);
    if (!entity.world.isRemote && entity instanceof EntityPlayer && electricItem != null && electricItem.canProvideChargeExternally() && isInDishargeMode(itemStack) && electricItem.getCharge() > 0L) {
        EntityPlayer entityPlayer = (EntityPlayer) entity;
        InventoryPlayer inventoryPlayer = entityPlayer.inventory;
        long transferLimit = electricItem.getTransferLimit();
        for (int i = 0; i < inventoryPlayer.getSizeInventory(); i++) {
            ItemStack itemInSlot = inventoryPlayer.getStackInSlot(i);
            IElectricItem slotElectricItem = itemInSlot.getCapability(GregtechCapabilities.CAPABILITY_ELECTRIC_ITEM, null);
            if (slotElectricItem != null && !slotElectricItem.canProvideChargeExternally()) {
                long chargedAmount = chargeElectricItem(transferLimit, electricItem, slotElectricItem);
                if (chargedAmount > 0L) {
                    transferLimit -= chargedAmount;
                    if (transferLimit == 0L)
                        break;
                }
            }
        }
    }
}
Also used : InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) IElectricItem(gregtech.api.capability.IElectricItem) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack)

Example 39 with InventoryPlayer

use of net.minecraft.entity.player.InventoryPlayer in project GregTech by GregTechCE.

the class ItemListSlotWidget method setCreativeHeldItem.

private void setCreativeHeldItem(ItemStack itemStack) {
    InventoryPlayer inventory = gui.entityPlayer.inventory;
    if (!itemStack.isEmpty() && inventory.getItemStack().isEmpty()) {
        itemStack.setCount(itemStack.getMaxStackSize());
        inventory.setItemStack(itemStack);
    }
}
Also used : InventoryPlayer(net.minecraft.entity.player.InventoryPlayer)

Example 40 with InventoryPlayer

use of net.minecraft.entity.player.InventoryPlayer in project GregTech by GregTechCE.

the class ItemListSlotWidget method extractItemStack.

private void extractItemStack(ItemStackKey itemStackKey, int amount, boolean isClient) {
    InventoryPlayer inventory = gui.entityPlayer.inventory;
    if (inventory.getItemStack().isEmpty()) {
        if (!isClient) {
            // on server, we try to extract from the network
            IItemList itemList = gridWidget.getItemList();
            int amountExtracted = itemList.extractItem(itemStackKey, amount, false);
            if (amountExtracted > 0) {
                ItemStack resultStack = itemStackKey.getItemStack();
                resultStack.setCount(amountExtracted);
                inventory.setItemStack(resultStack);
            }
            uiAccess.sendHeldItemUpdate();
        } else {
            // on client we assume we can extract as much items as user wishes
            ItemStack itemStack = itemStackKey.getItemStack();
            itemStack.setCount(amount);
            inventory.setItemStack(itemStack);
        }
    }
}
Also used : InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) IItemList(gregtech.common.inventory.IItemList) ItemStack(net.minecraft.item.ItemStack)

Aggregations

InventoryPlayer (net.minecraft.entity.player.InventoryPlayer)81 ItemStack (net.minecraft.item.ItemStack)56 Slot (net.minecraft.inventory.Slot)15 EntityPlayer (net.minecraft.entity.player.EntityPlayer)14 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)8 Item (net.minecraft.item.Item)6 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)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