Search in sources :

Example 51 with EntityItem

use of net.minecraft.entity.item.EntityItem in project LogisticsPipes by RS485.

the class SimpleStackInventory method dropItems.

private void dropItems(World world, ItemStack stack, int i, int j, int k) {
    if (stack.stackSize <= 0) {
        return;
    }
    float f1 = 0.7F;
    double d = (world.rand.nextFloat() * f1) + (1.0F - f1) * 0.5D;
    double d1 = (world.rand.nextFloat() * f1) + (1.0F - f1) * 0.5D;
    double d2 = (world.rand.nextFloat() * f1) + (1.0F - f1) * 0.5D;
    EntityItem entityitem = new EntityItem(world, i + d, j + d1, k + d2, stack);
    entityitem.delayBeforeCanPickup = 10;
    world.spawnEntityInWorld(entityitem);
}
Also used : EntityItem(net.minecraft.entity.item.EntityItem)

Example 52 with EntityItem

use of net.minecraft.entity.item.EntityItem in project Witchworks by Um-Mitternacht.

the class TileKettle method processingLogic.

//------------------------------------Crafting Logic------------------------------------//
@SuppressWarnings("ConstantConditions")
public boolean processingLogic(ItemStack stack) {
    if (!isBoiling() || hasIngredients() || stack.getCount() > 64)
        return false;
    Map<Item, ItemValidator<ItemStack>> processing = KettleRegistry.getKettleProcessing(inv.getInnerFluid());
    if (processing != null && processing.containsKey(stack.getItem())) {
        ItemValidator<ItemStack> validator = processing.get(stack.getItem());
        Optional<ItemStack> optional = validator.getMatchFor(stack);
        if (optional.isPresent()) {
            ItemStack out = optional.get().copy();
            if (stack.isItemDamaged() && out.isItemStackDamageable())
                out.setItemDamage(stack.getItemDamage());
            int fluidAmount = inv.getFluidAmount();
            int fluidTaken = 250;
            out.setCount(0);
            if (stack.getCount() <= 16) {
                out.setCount(stack.getCount());
                stack.setCount(0);
            } else {
                while (stack.getCount() > 0 && fluidTaken <= fluidAmount) {
                    stack.shrink(1);
                    out.grow(1);
                    if (out.getCount() % 16 == 0) {
                        if (fluidTaken >= fluidAmount) {
                            fluidTaken = fluidAmount;
                            break;
                        }
                        fluidTaken += 250;
                    }
                }
            }
            if (out.getCount() > 0) {
                final double x = getPos().getX();
                final double y = getPos().getY() + 1D;
                final double z = getPos().getZ();
                final EntityItem item = new EntityItem(world, x + 0.5D, y, z + 0.5D, out);
                item.motionX = world.rand.nextDouble() * 2 - 1;
                item.motionZ = world.rand.nextDouble() * 2 - 1;
                item.motionY = 0.1D;
                item.setPickupDelay(0);
                world.spawnEntity(item);
                play(SoundEvents.BLOCK_FIRE_EXTINGUISH, 1F, 1F);
                for (int i = 0; i < 4; i++) {
                    PacketHandler.spawnParticle(ParticleF.STEAM, world, x + world.rand.nextFloat(), getParticleLevel(), z + world.rand.nextFloat(), 5, 0, 0, 0);
                }
                inv.drain(fluidTaken, true);
                return true;
            }
        }
    }
    return false;
}
Also used : Item(net.minecraft.item.Item) EntityItem(net.minecraft.entity.item.EntityItem) IFluidHandlerItem(net.minecraftforge.fluids.capability.IFluidHandlerItem) ItemValidator(com.witchworks.api.recipe.ItemValidator) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Example 53 with EntityItem

use of net.minecraft.entity.item.EntityItem in project Witchworks by Um-Mitternacht.

the class TileKettle method update.

@Override
public void update() {
    if (!world.isRemote && ticks % 2 == 0) {
        double x = getPos().getX();
        double y = getPos().getY();
        double z = getPos().getZ();
        AxisAlignedBB box = new AxisAlignedBB(x, y, z, x + 1, y + 0.65D, z + 1);
        final List<EntityItem> entityItemList = world.getEntitiesWithinAABB(EntityItem.class, box);
        entityItemList.forEach(this::collideItem);
    }
    if (inv.hasFluid()) {
        if (!inv.hasFluid(FluidRegistry.LAVA)) {
            if (isBoiling()) {
                handleParticles();
                if (ticks % 5 == 0 && world.rand.nextInt(15) == 0) {
                    play(SoundEvents.BLOCK_LAVA_AMBIENT, 0.1F, 1F);
                }
            }
        } else if (ticks % 5 == 0 && world.rand.nextInt(20) == 0) {
            play(SoundEvents.BLOCK_LAVA_AMBIENT, 1F, 1F);
        }
    }
    if (ticks % 20 == 0) {
        handleHeat();
        tryTurnLiquid();
    }
    if (!world.isRemote && mode == Mode.RITUAL && ritual != null) {
        handleRitual();
    }
    ++ticks;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) EntityItem(net.minecraft.entity.item.EntityItem)

Example 54 with EntityItem

use of net.minecraft.entity.item.EntityItem in project Witchworks by Um-Mitternacht.

the class TileApiary method dropItems.

public void dropItems() {
    for (int i = 0; i < 16; ++i) {
        final ItemStack stack = itemStacks.get(i);
        if (!world.isRemote && !stack.isEmpty()) {
            final EntityItem item = new EntityItem(world, pos.getX() + 0.5D, pos.getY() + 0.5D, pos.getZ() + 0.5D, stack);
            world.spawnEntity(item);
        }
        itemStacks.set(i, ItemStack.EMPTY);
    }
}
Also used : ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Example 55 with EntityItem

use of net.minecraft.entity.item.EntityItem in project Witchworks by Um-Mitternacht.

the class ItemRitual method spawnItem.

@SuppressWarnings("ConstantConditions")
private void spawnItem(World world, double x, double y, double z) {
    final EntityItem item = new EntityItem(world, x + 0.5D, y, z + 0.5D, stack);
    item.motionX = world.rand.nextDouble() * 2 - 1;
    item.motionZ = world.rand.nextDouble() * 2 - 1;
    item.motionY = 0.1D;
    world.spawnEntity(item);
}
Also used : EntityItem(net.minecraft.entity.item.EntityItem)

Aggregations

EntityItem (net.minecraft.entity.item.EntityItem)284 ItemStack (net.minecraft.item.ItemStack)178 TileEntity (net.minecraft.tileentity.TileEntity)45 EntityPlayer (net.minecraft.entity.player.EntityPlayer)36 Entity (net.minecraft.entity.Entity)26 ArrayList (java.util.ArrayList)19 BlockPos (net.minecraft.util.math.BlockPos)19 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)18 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)16 World (net.minecraft.world.World)16 Random (java.util.Random)15 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)14 Item (net.minecraft.item.Item)13 IInventory (net.minecraft.inventory.IInventory)12 AxisAlignedBB (net.minecraft.util.AxisAlignedBB)12 List (java.util.List)11 Block (net.minecraft.block.Block)11 EntityLivingBase (net.minecraft.entity.EntityLivingBase)11 IBlockState (net.minecraft.block.state.IBlockState)10 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)6