Java Code Examples for net.minecraft.entity.EntityLivingBase#playSound()

The following examples show how to use net.minecraft.entity.EntityLivingBase#playSound() . 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 File: BounceManager.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
public static void onFall(LivingFallEvent event) {
	EntityLivingBase entity = event.getEntityLiving();
	if (entity == null) return;

	if (!shouldBounce(entity)) return;

	INSTANCE.blocks.removeIf(bouncyBlock -> entity.world.getTotalWorldTime() - bouncyBlock.tickSpawned > bouncyBlock.expiry);

	boolean isClient = entity.getEntityWorld().isRemote;
	if (event.getDistance() > 0.5) {
		event.setDamageMultiplier(0);
		entity.fallDistance = 0;

		if (isClient) {
			entity.motionY *= -0.9;
			entity.isAirBorne = true;
			entity.onGround = false;
			double f = 0.95;
			entity.motionX /= f;
			entity.motionZ /= f;
			PacketHandler.NETWORK.sendToServer(new PacketBounce());
		} else {
			event.setCanceled(true);
		}
		entity.playSound(SoundEvents.ENTITY_SLIME_SQUISH, 1f, 1f);
		BounceHandler.addBounceHandler(entity, entity.motionY);

	}
}
 
Example 2
Source File: BounceManager.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
public static void onFlyableFall(PlayerFlyableFallEvent event) {
	EntityLivingBase entity = event.getEntityLiving();
	if (entity == null) return;

	if (!shouldBounce(entity)) return;

	INSTANCE.blocks.removeIf(bouncyBlock -> entity.world.getTotalWorldTime() - bouncyBlock.tickSpawned > bouncyBlock.expiry);

	boolean isClient = entity.getEntityWorld().isRemote;
	if (event.getDistance() > 0.5) {
		entity.fallDistance = 0;

		if (isClient) {
			entity.motionY *= -0.9;
			entity.isAirBorne = true;
			entity.onGround = false;
			double f = 0.95;
			entity.motionX /= f;
			entity.motionZ /= f;
			PacketHandler.NETWORK.sendToServer(new PacketBounce());
		}
		entity.playSound(SoundEvents.ENTITY_SLIME_SQUISH, 1f, 1f);
		BounceHandler.addBounceHandler(entity, entity.motionY);

	}
}
 
Example 3
Source File: ItemPotteryJug.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ItemStack onItemUseFinish(ItemStack stack, World worldIn, EntityLivingBase entityLiving)
{
	if(!worldIn.isRemote)
	{
		EntityPlayer player = (EntityPlayer) entityLiving;

		if(IsWaterJug(stack))
		{
			IFoodStatsTFC food = (IFoodStatsTFC)player.getFoodStats();
			food.setWaterLevel(20);
			TFC.network.sendTo(new CFoodPacket(food), (EntityPlayerMP) player);
		}

		if(IsWaterJug(stack) && !((EntityPlayer)entityLiving).capabilities.isCreativeMode)
		{
			if(worldIn.rand.nextInt(50) == 0)
			{
				stack.shrink(1);
				entityLiving.playSound(TFC_Sounds.CERAMICBREAK, 0.7f, worldIn.rand.nextFloat() * 0.2f + 0.8f);
			}
			else
				stack.setItemDamage(1);
		}
	}
	return stack;
}
 
Example 4
Source File: ChorusFruit.java    From Et-Futurum with The Unlicense 4 votes vote down vote up
private static boolean teleportTo(EntityLivingBase entity, double xx, double yy, double zz) {
	EnderTeleportEvent event = new EnderTeleportEvent(entity, xx, yy, zz, 0);
	if (MinecraftForge.EVENT_BUS.post(event))
		return false;

	double d3 = entity.posX;
	double d4 = entity.posY;
	double d5 = entity.posZ;
	entity.posX = event.targetX;
	entity.posY = event.targetY;
	entity.posZ = event.targetZ;
	boolean flag = false;
	int i = MathHelper.floor_double(entity.posX);
	int j = MathHelper.floor_double(entity.posY);
	int k = MathHelper.floor_double(entity.posZ);

	if (entity.worldObj.blockExists(i, j, k)) {
		boolean flag1 = false;
		while (!flag1 && j > 0) {
			Block block = entity.worldObj.getBlock(i, j - 1, k);
			if (block.getMaterial().blocksMovement())
				flag1 = true;
			else {
				entity.posY--;
				j--;
			}
		}

		if (flag1) {
			entity.setPositionAndUpdate(entity.posX, entity.posY, entity.posZ);
			if (entity.worldObj.getCollidingBoundingBoxes(entity, entity.boundingBox).isEmpty() && !entity.worldObj.isAnyLiquid(entity.boundingBox))
				flag = true;
		}
	}

	if (!flag) {
		entity.setPosition(d3, d4, d5);
		return false;
	} else {
		short short1 = 128;

		for (int l = 0; l < short1; l++) {
			double d6 = l / (short1 - 1.0D);
			float f = (entity.getRNG().nextFloat() - 0.5F) * 0.2F;
			float f1 = (entity.getRNG().nextFloat() - 0.5F) * 0.2F;
			float f2 = (entity.getRNG().nextFloat() - 0.5F) * 0.2F;
			double d7 = d3 + (entity.posX - d3) * d6 + (entity.getRNG().nextDouble() - 0.5D) * entity.width * 2.0D;
			double d8 = d4 + (entity.posY - d4) * d6 + entity.getRNG().nextDouble() * entity.height;
			double d9 = d5 + (entity.posZ - d5) * d6 + (entity.getRNG().nextDouble() - 0.5D) * entity.width * 2.0D;
			entity.worldObj.spawnParticle("portal", d7, d8, d9, f, f1, f2);
		}

		entity.worldObj.playSoundEffect(d3, d4, d5, "mob.endermen.portal", 1.0F, 1.0F);
		entity.playSound("mob.endermen.portal", 1.0F, 1.0F);
		return true;
	}
}
 
Example 5
Source File: TeleportHelper.java    From EnderZoo with Creative Commons Zero v1.0 Universal 4 votes vote down vote up
public static boolean teleportTo(EntityLivingBase entity, double x, double y, double z, boolean fireEndermanEvent) {

    EnderTeleportEvent event = new EnderTeleportEvent(entity, x, y, z, 0);
    if (fireEndermanEvent) {
      if (MinecraftForge.EVENT_BUS.post(event)) {
        return false;
      }
    }

    double origX = entity.posX;
    double origY = entity.posY;
    double origZ = entity.posZ;
    entity.posX = event.getTargetX();
    entity.posY = event.getTargetY();
    entity.posZ = event.getTargetZ();

    int xInt = MathHelper.floor(entity.posX);
    int yInt = Math.max(2, MathHelper.floor(entity.posY));
    int zInt = MathHelper.floor(entity.posZ);

    boolean doTeleport = false;
    World worldObj = entity.getEntityWorld();
    if (worldObj.isBlockLoaded(new BlockPos(xInt, yInt, zInt), true)) {
      boolean foundGround = false;
      while (!foundGround && yInt > 2) {
        IBlockState bs = worldObj.getBlockState(new BlockPos(xInt, yInt - 1, zInt));
        if (bs != null && bs.getBlock() != null && bs.getMaterial().blocksMovement()) {
          foundGround = true;
        } else {
          --entity.posY;
          --yInt;
        }
      }

      if (foundGround) {
        entity.setPosition(entity.posX, entity.posY, entity.posZ);
        if (worldObj.getCollisionBoxes(entity, entity.getEntityBoundingBox()).isEmpty()
            && !worldObj.containsAnyLiquid(entity.getEntityBoundingBox())) {
          doTeleport = true;
        } else if (yInt <= 0) {
          doTeleport = false;
        }
      }
    }

    if (!doTeleport) {
      entity.setPosition(origX, origY, origZ);
      return false;
    }

    entity.setPositionAndUpdate(entity.posX, entity.posY, entity.posZ);

    short short1 = 128;
    for (int l = 0; l < short1; ++l) {
      double d6 = l / (short1 - 1.0D);
      float f = (rand.nextFloat() - 0.5F) * 0.2F;
      float f1 = (rand.nextFloat() - 0.5F) * 0.2F;
      float f2 = (rand.nextFloat() - 0.5F) * 0.2F;
      double d7 = origX + (entity.posX - origX) * d6 + (rand.nextDouble() - 0.5D) * entity.width * 2.0D;
      double d8 = origY + (entity.posY - origY) * d6 + rand.nextDouble() * entity.height;
      double d9 = origZ + (entity.posZ - origZ) * d6 + (rand.nextDouble() - 0.5D) * entity.width * 2.0D;
      worldObj.spawnParticle(EnumParticleTypes.PORTAL, d7, d8, d9, f, f1, f2);
    }

    worldObj.playSound(origX, origY, origZ, SoundEvents.ENTITY_ENDERMEN_TELEPORT, SoundCategory.NEUTRAL, 1.0F, 1.0F, false);
    entity.playSound(SoundEvents.ENTITY_ENDERMEN_TELEPORT, 1.0F, 1.0F);
    return true;

  }