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

The following examples show how to use net.minecraft.entity.EntityLivingBase#getEntityWorld() . 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
@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
@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 Project: TinkersToolLeveling   File: ModToolLeveling.java    License: MIT License 5 votes vote down vote up
@Override
public void afterHit(ItemStack tool, EntityLivingBase player, EntityLivingBase target, float damageDealt, boolean wasCritical, boolean wasHit) {
  if(!target.getEntityWorld().isRemote && wasHit && player instanceof EntityPlayer) {
    // if we killed it the event for distributing xp was already fired and we just do it manually here
    EntityPlayer entityPlayer = (EntityPlayer) player;
    if(!target.isEntityAlive()) {
      addXp(tool, Math.round(damageDealt), entityPlayer);
    }
    else if(target.hasCapability(CapabilityDamageXp.CAPABILITY, null)) {
      target.getCapability(CapabilityDamageXp.CAPABILITY, null).addDamageFromTool(damageDealt, tool, entityPlayer);
    }
  }
}
 
Example 4
@Override
public boolean hitEntity(ItemStack stack, EntityLivingBase targetEntity, EntityLivingBase attacker)
{
    // Summon fighters mode
    if (targetEntity != null && targetEntity.getEntityWorld().isRemote == false && SwordMode.fromStack(stack) == SwordMode.SUMMON)
    {
        EntityEndermanFighter.summonFighters(targetEntity.getEntityWorld(), targetEntity, 3);
    }

    return this.addToolDamage(stack, 1, targetEntity, attacker);
}
 
Example 5
Source Project: AdvancedRocketry   File: ItemBasicLaserGun.java    License: MIT License 4 votes vote down vote up
@Override
public void onUsingTick(ItemStack stack, EntityLivingBase player, int count) {

	World world = player.getEntityWorld();

	RayTraceResult rayTrace = rayTraceEntity(world,player);

	if(rayTrace != null) {
		rayTrace.entityHit.attackEntityFrom(DamageSource.GENERIC, 1f);
		if(world.isRemote)
			LibVulpes.proxy.playSound(world, player.getPosition(), AudioRegistry.basicLaser, SoundCategory.PLAYERS, 1, 1f);
		AdvancedRocketry.proxy.spawnLaser(player, rayTrace.hitVec);
		player.resetActiveHand();
		return;
	}

	rayTrace = rayTrace(world, (EntityPlayer) player, false);

	if(rayTrace == null)
		return;

	if(posMap.get(player) != null && !posMap.get(player).equals(rayTrace.getBlockPos())) {
		player.resetActiveHand();
		return;
	}
	else if(posMap.get(player) == null && rayTrace.getBlockPos() != null) {
		posMap.put(player, rayTrace.getBlockPos());
	}

	if(rayTrace.typeOfHit == Type.BLOCK) {
		IBlockState state = world.getBlockState(rayTrace.getBlockPos());

		if(count % 5 == 0 && world.isRemote)
			LibVulpes.proxy.playSound(world, player.getPosition(), AudioRegistry.basicLaser, SoundCategory.PLAYERS, 1, 1f);
		//
		AdvancedRocketry.proxy.spawnLaser(player, rayTrace.hitVec);



		super.onUsingTick(stack, player, count);
	}
}
 
Example 6
private boolean addToolDamage(ItemStack stack, int amount, EntityLivingBase living1, EntityLivingBase living2)
{
    //System.out.println("addToolDamage(): living1: " + living1 + " living2: " + living2 + " remote: " + living2.worldObj.isRemote);
    if (this.isToolBroken(stack))
    {
        return false;
    }

    if (amount > 0)
    {
        int unbreakingLevel = EnchantmentHelper.getEnchantmentLevel(Enchantment.getEnchantmentByLocation("unbreaking"), stack);
        int amountNegated = 0;

        for (int i = 0; unbreakingLevel > 0 && i < amount; i++)
        {
            if (itemRand.nextInt(amount + 1) > 0)
            {
                amountNegated++;
            }
        }

        amount -= amountNegated;

        if (amount <= 0)
        {
            return false;
        }
    }

    int damage = this.getDamage(stack);
    damage = Math.min(damage + amount, this.material.getMaxUses());

    if (living1.getEntityWorld().isRemote == false)
    {
        this.setDamage(stack, damage);
    }

    // Tool just broke
    if (damage == this.material.getMaxUses())
    {
        //System.out.printf("tool broke @ %s\n", living1.getEntityWorld().isRemote ? "client" : "server");
        living1.renderBrokenItemStack(stack);
    }

    return true;
}
 
Example 7
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;

  }