Java Code Examples for net.minecraft.entity.item.EntityItem#onCollideWithPlayer()

The following examples show how to use net.minecraft.entity.item.EntityItem#onCollideWithPlayer() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: Ex-Aliquo   File: AliquoEvents.java    License: MIT License 6 votes vote down vote up
@ForgeSubscribe
public void onLivingDrops(LivingDropsEvent event)
{
	if (event.entityLiving == null)
	{
		return;
	}
	
	if (event.entityLiving instanceof EntityDragon)
	{
		if (event.source.getEntity() != null && event.source.getEntity() instanceof EntityPlayer)
		{
			EntityPlayer player = (EntityPlayer) event.source.getEntity();
			if (!player.worldObj.isRemote)
			{
				EntityItem item = new EntityItem(player.worldObj, player.posX + 0.5D, player.posY + 0.5D, player.posZ + 0.5D, new ItemStack(Registries.dragonEgg, 1, 0));
	            player.worldObj.spawnEntityInWorld(item);
	            if (!(player instanceof FakePlayer))
	            {
	                item.onCollideWithPlayer(player);
	            }
			}
		}
	}
}
 
Example 2
/**
 * Makes it so when a player right clicks a rail block with a different rail item, it will be replaced, without having to remove and place a rail.
 * TODO: Replace signal types
 * @param e
 */
@SubscribeEvent
public void onBlockInteraction(RightClickBlock e){
    if(!e.getWorld().isRemote && e.getFace() == EnumFacing.UP) {
        ItemStack stack = e.getEntityPlayer().getHeldItemMainhand();
        BlockRailBase railBlock = getRailBlock(stack);
        if(railBlock != null) {
            IBlockState state = e.getWorld().getBlockState(e.getPos());
            IRail rail = RailManager.getInstance().getRail(e.getWorld(), e.getPos(), state);
            if(rail != null && state.getBlock() != railBlock) {
                EnumRailDirection dir = rail.getDirection(e.getWorld(), e.getPos(), state);
                e.getWorld().destroyBlock(e.getPos(), !e.getEntityPlayer().isCreative());
                List<EntityItem> drops = e.getWorld().getEntitiesWithinAABB(EntityItem.class, new AxisAlignedBB(e.getPos()));
                for(EntityItem drop : drops) {
                    drop.setPickupDelay(0);
                    drop.onCollideWithPlayer(e.getEntityPlayer());
                }

                e.getWorld().setBlockState(e.getPos(), railBlock.getDefaultState());
                if(!e.getEntityPlayer().isCreative()) stack.shrink(1);

                //Set the rail orientation equal to the old rail, if possible.
                if(railBlock.getShapeProperty().getAllowedValues().contains(dir)) {
                    IBlockState curState = e.getWorld().getBlockState(e.getPos());
                    e.getWorld().setBlockState(e.getPos(), curState.withProperty(railBlock.getShapeProperty(), dir));
                }
            }
        }
    }
}
 
Example 3
public void breakSemiBlock(World world, int x, int y, int z, EntityPlayer player){
    ISemiBlock semiBlock = getSemiBlock(world, x, y, z);
    if(semiBlock != null) {
        List<ItemStack> drops = new ArrayList<ItemStack>();
        semiBlock.addDrops(drops);
        for(ItemStack stack : drops) {
            EntityItem item = new EntityItem(world, x + 0.5, y + 0.5, z + 0.5, stack);
            world.spawnEntityInWorld(item);
            if(player != null) item.onCollideWithPlayer(player);
        }
        setSemiBlock(world, x, y, z, null);
    }
}
 
Example 4
Source Project: NotEnoughItems   File: ServerHandler.java    License: MIT License 4 votes vote down vote up
private void updateMagneticPlayer(EntityPlayerMP player, PlayerSave save) {
    if (!save.isActionEnabled("magnet") || player.isDead)
        return;

    float distancexz = 16;
    float distancey = 8;
    double maxspeedxz = 0.5;
    double maxspeedy = 0.5;
    double speedxz = 0.05;
    double speedy = 0.07;
    List<EntityItem> items = player.worldObj.getEntitiesWithinAABB(EntityItem.class, player.getEntityBoundingBox().expand(distancexz, distancey, distancexz));
    for (EntityItem item : items) {
        if (item.cannotPickup()) continue;
        if (!NEIServerUtils.canItemFitInInventory(player, item.getEntityItem())) continue;
        if (save.magneticItems.add(item))
            NEISPH.sendAddMagneticItemTo(player, item);

        double dx = player.posX - item.posX;
        double dy = player.posY + player.getEyeHeight() - item.posY;
        double dz = player.posZ - item.posZ;
        double absxz = Math.sqrt(dx * dx + dz * dz);
        double absy = Math.abs(dy);
        if (absxz > distancexz)
            continue;

        if (absxz < 1)
            item.onCollideWithPlayer(player);

        if (absxz > 1) {
            dx /= absxz;
            dz /= absxz;
        }

        if (absy > 1)
            dy /= absy;

        double vx = item.motionX + speedxz * dx;
        double vy = item.motionY + speedy * dy;
        double vz = item.motionZ + speedxz * dz;

        double absvxz = Math.sqrt(vx * vx + vz * vz);
        double absvy = Math.abs(vy);

        double rationspeedxz = absvxz / maxspeedxz;
        if (rationspeedxz > 1) {
            vx /= rationspeedxz;
            vz /= rationspeedxz;
        }

        double rationspeedy = absvy / maxspeedy;
        if (absvy > 1)
            vy /= rationspeedy;

        item.motionX = vx;
        item.motionY = vy;
        item.motionZ = vz;
    }
}