Search in sources :

Example 56 with EntityItem

use of net.minecraft.entity.item.EntityItem in project MineFactoryReloaded by powercrystals.

the class BlockConveyor method onEntityCollidedWithBlock.

@Override
public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity entity) {
    if (entity instanceof EntityPlayer && MFRConfig.conveyorNeverCapturesPlayers.getBoolean(false)) {
        return;
    }
    // TODO: add conveyer entity blacklist: these two cases will be covered conditionally elsewhere
    if (entity.getClass().getName().contains("thaumcraft.common.entities.golems") && MFRConfig.conveyorNeverCapturesTCGolems.getBoolean(false)) {
        return;
    }
    if (!(entity instanceof EntityItem || entity instanceof EntityXPOrb || (entity instanceof EntityLiving && MFRConfig.conveyorCaptureNonItems.getBoolean(true)))) {
        return;
    }
    TileEntity conveyor = world.getBlockTileEntity(x, y, z);
    if (!(conveyor instanceof TileEntityConveyor && ((TileEntityConveyor) conveyor).getConveyorActive())) {
        return;
    }
    if (!world.isRemote && entity instanceof EntityItem) {
        specialRoute(world, x, y, z, (EntityItem) entity);
    }
    double xVelocity = 0;
    double yVelocity = 0;
    double zVelocity = 0;
    int md = world.getBlockMetadata(x, y, z);
    int horizDirection = md & 0x03;
    boolean isUphill = (md & 0x04) != 0;
    boolean isDownhill = (md & 0x08) != 0;
    if (isUphill) {
        yVelocity = 0.25D;
    }
    if (isUphill || isDownhill) {
        entity.onGround = false;
    }
    if (horizDirection == 0) {
        xVelocity = 0.1D;
    } else if (horizDirection == 1) {
        zVelocity = 0.1D;
    } else if (horizDirection == 2) {
        xVelocity = -0.1D;
    } else if (horizDirection == 3) {
        zVelocity = -0.1D;
    }
    if (horizDirection == 0 || horizDirection == 2) {
        if (entity.posZ > z + 0.55D) {
            zVelocity = -0.1D;
        } else if (entity.posZ < z + 0.45D) {
            zVelocity = 0.1D;
        }
    } else if (horizDirection == 1 || horizDirection == 3) {
        if (entity.posX > x + 0.55D) {
            xVelocity = -0.1D;
        } else if (entity.posX < x + 0.45D) {
            xVelocity = 0.1D;
        }
    }
    setEntityVelocity(entity, xVelocity, yVelocity, zVelocity);
    if (entity instanceof EntityLiving) {
        ((EntityLiving) entity).fallDistance = 0;
    } else if (entity instanceof EntityItem) {
        ((EntityItem) entity).delayBeforeCanPickup = 40;
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) EntityLiving(net.minecraft.entity.EntityLiving) TileEntityConveyor(powercrystals.minefactoryreloaded.tile.conveyor.TileEntityConveyor) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityItem(net.minecraft.entity.item.EntityItem) EntityXPOrb(net.minecraft.entity.item.EntityXPOrb)

Example 57 with EntityItem

use of net.minecraft.entity.item.EntityItem in project MineFactoryReloaded by powercrystals.

the class TileEntityConveyor method setInventorySlotContents.

@Override
public void setInventorySlotContents(int slot, ItemStack stack) {
    int horizDirection = worldObj.getBlockMetadata(xCoord, yCoord, zCoord) & 0x03;
    float dropOffsetX = 0.5F;
    float dropOffsetY = 0.4F;
    float dropOffsetZ = 0.5F;
    double motionX = 0.0D;
    double motionY = 0.0D;
    double motionZ = 0.0D;
    //because of the setup, slot is also the ForgeDirection ordinal from which the item is being inserted
    switch(slot) {
        case //DOWN
        0:
            dropOffsetY = 0.3F;
            motionY = 0.15D;
            break;
        case //UP
        1:
            dropOffsetY = 0.8F;
            motionY = -0.15D;
            break;
        case //NORTH
        2:
            dropOffsetZ = 0.2F;
            motionZ = 0.15D;
            break;
        case //SOUTH
        3:
            dropOffsetZ = 0.8F;
            motionZ = -0.15D;
            break;
        case //WEST
        4:
            dropOffsetX = 0.2F;
            motionX = 0.15D;
            break;
        case //EAST
        5:
            dropOffsetX = 0.8F;
            motionX = -0.15D;
            break;
        //UNKNOWN
        case 6:
    }
    if (horizDirection == 0) {
        motionX = 0.05D;
    } else if (horizDirection == 1) {
        motionZ = 0.05D;
    } else if (horizDirection == 3) {
        motionX = -0.05D;
    } else if (horizDirection == 3) {
        motionX = -0.05D;
    }
    EntityItem entityitem = new EntityItem(worldObj, xCoord + dropOffsetX, yCoord + dropOffsetY, zCoord + dropOffsetZ, stack.copy());
    entityitem.motionX = motionX;
    entityitem.motionY = motionY;
    entityitem.motionZ = motionZ;
    entityitem.delayBeforeCanPickup = 20;
    worldObj.spawnEntityInWorld(entityitem);
}
Also used : EntityItem(net.minecraft.entity.item.EntityItem)

Example 58 with EntityItem

use of net.minecraft.entity.item.EntityItem in project PlusTiC by Landmaster.

the class NaturesBlessing method dropBread.

protected void dropBread(World world, double x, double y, double z, float chance) {
    if (!world.isRemote && random.nextFloat() < chance) {
        EntityItem entity = new EntityItem(world, x, y, z, new ItemStack(Items.BREAD));
        world.spawnEntity(entity);
    }
}
Also used : EntityItem(net.minecraft.entity.item.EntityItem)

Example 59 with EntityItem

use of net.minecraft.entity.item.EntityItem in project ImmersiveEngineering by BluSunrize.

the class EventHandler method onLivingDrops.

@SubscribeEvent
public void onLivingDrops(LivingDropsEvent event) {
    if (!event.isCanceled() && !event.getEntityLiving().isNonBoss()) {
        EnumRarity r = EnumRarity.EPIC;
        for (Class<? extends EntityLiving> boring : listOfBoringBosses) if (boring.isAssignableFrom(event.getEntityLiving().getClass()))
            return;
        ItemStack bag = new ItemStack(IEContent.itemShaderBag);
        ItemNBTHelper.setString(bag, "rarity", r.toString());
        event.getDrops().add(new EntityItem(event.getEntityLiving().worldObj, event.getEntityLiving().posX, event.getEntityLiving().posY, event.getEntityLiving().posZ, bag));
    }
}
Also used : EnumRarity(net.minecraft.item.EnumRarity) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 60 with EntityItem

use of net.minecraft.entity.item.EntityItem in project ImmersiveEngineering by BluSunrize.

the class ConveyorVertical method onEntityCollision.

@Override
public void onEntityCollision(TileEntity tile, Entity entity, EnumFacing facing) {
    if (!isActive(tile))
        return;
    BlockPos posWall = tile.getPos().offset(facing);
    double d = .625 + entity.width;
    double distToWall = Math.abs((facing.getAxis() == Axis.Z ? posWall.getZ() : posWall.getX()) + .5 - (facing.getAxis() == Axis.Z ? entity.posZ : entity.posX));
    if (distToWall > d) {
        super.onEntityCollision(tile, entity, facing);
        return;
    }
    if (entity != null && !entity.isDead && !(entity instanceof EntityPlayer && entity.isSneaking())) {
        double distY = Math.abs(tile.getPos().add(0, 1, 0).getY() + .5 - entity.posY);
        double treshold = .9;
        boolean contact = distY < treshold;
        entity.onGround = false;
        if (entity.fallDistance < 3)
            entity.fallDistance = 0;
        else
            entity.fallDistance *= .9;
        Vec3d vec = getDirection(tile, entity, facing);
        entity.motionX = vec.xCoord;
        entity.motionY = vec.yCoord;
        entity.motionZ = vec.zCoord;
        if (!contact)
            ConveyorHandler.applyMagnetSupression(entity, (IConveyorTile) tile);
        else {
            BlockPos posTop = tile.getPos().add(0, 1, 0);
            if (!((tile.getWorld().getTileEntity(posTop) instanceof IConveyorTile) || (tile.getWorld().isAirBlock(posTop) && (tile.getWorld().getTileEntity(posTop.offset(facing)) instanceof IConveyorTile))))
                ConveyorHandler.revertMagnetSupression(entity, (IConveyorTile) tile);
        }
        if (entity instanceof EntityItem) {
            ((EntityItem) entity).setNoDespawn();
            TileEntity inventoryTile;
            inventoryTile = tile.getWorld().getTileEntity(tile.getPos().add(0, 1, 0));
            if (!tile.getWorld().isRemote) {
                if (contact && inventoryTile != null && !(inventoryTile instanceof IConveyorTile)) {
                    ItemStack stack = ((EntityItem) entity).getEntityItem();
                    if (stack != null) {
                        ItemStack ret = Utils.insertStackIntoInventory(inventoryTile, stack, EnumFacing.DOWN);
                        if (ret == null)
                            entity.setDead();
                        else if (ret.stackSize < stack.stackSize)
                            ((EntityItem) entity).setEntityItemStack(ret);
                    }
                }
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) IConveyorTile(blusunrize.immersiveengineering.api.tool.ConveyorHandler.IConveyorTile) Vec3d(net.minecraft.util.math.Vec3d) EntityItem(net.minecraft.entity.item.EntityItem)

Aggregations

EntityItem (net.minecraft.entity.item.EntityItem)253 ItemStack (net.minecraft.item.ItemStack)157 TileEntity (net.minecraft.tileentity.TileEntity)42 EntityPlayer (net.minecraft.entity.player.EntityPlayer)31 Entity (net.minecraft.entity.Entity)23 ArrayList (java.util.ArrayList)16 BlockPos (net.minecraft.util.math.BlockPos)16 Random (java.util.Random)15 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)14 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)14 IInventory (net.minecraft.inventory.IInventory)12 AxisAlignedBB (net.minecraft.util.AxisAlignedBB)11 World (net.minecraft.world.World)11 List (java.util.List)10 Block (net.minecraft.block.Block)10 Item (net.minecraft.item.Item)10 EntityLivingBase (net.minecraft.entity.EntityLivingBase)8 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)8 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)7 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)6