use of net.silentchaos512.gems.entity.EntityChaosProjectile in project SilentGems by SilentChaos512.
the class EntityChaosProjectileHoming method findHomingTarget.
public void findHomingTarget() {
if (world.isRemote || homingTarget != null || (ticksExisted % 100 != 0 && ticksExisted > 20)) {
return;
}
homingTarget = null;
final EntityChaosProjectile projectile = this;
Predicate<EntityLivingBase> predicate = input -> {
// @formatter:off
return shooter != null && shooter != input && !input.isOnSameTeam(shooter);
// @formatter:on
};
int minDistance = Integer.MAX_VALUE;
Entity entity;
EntityLivingBase entityLiving;
// Go through all entities in the world
for (int i = 0; i < world.loadedEntityList.size(); ++i) {
entity = world.loadedEntityList.get(i);
// Target living entities
if (entity instanceof EntityLivingBase) {
entityLiving = (EntityLivingBase) entity;
// Target entities that are not the shooter and not on the same team.
if (predicate.apply(entityLiving)) {
// Add some randomness so that different shots will select different targets.
int distance = (int) entityLiving.getDistanceSqToEntity(projectile) + SilentGems.instance.random.nextInt(512);
// Within certain range and closer than the closest selected entity so far.
if (distance < 1200 && distance < minDistance) {
minDistance = distance;
homingTarget = entityLiving;
}
}
}
}
}
use of net.silentchaos512.gems.entity.EntityChaosProjectile in project SilentGems by SilentChaos512.
the class ItemGemSword method onItemLeftClickSL.
// ==============
// Item overrides
// ==============
@Override
public ActionResult<ItemStack> onItemLeftClickSL(World world, EntityPlayer player, EnumHand hand) {
ItemStack stack = player.getHeldItem(hand);
if (!player.isSneaking() || ToolHelper.getToolTier(stack).ordinal() < EnumMaterialTier.SUPER.ordinal()) {
return new ActionResult<ItemStack>(EnumActionResult.PASS, stack);
}
if (world.isRemote) {
GuiChaosBar.INSTANCE.show();
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
}
int costToCast = getShotCost(player, stack);
int cooldown = getShotCooldown(player, stack);
PlayerData data = PlayerDataHandler.get(player);
if (data.chaos >= costToCast && data.magicCooldown <= 0) {
if (!player.capabilities.isCreativeMode) {
data.drainChaos(costToCast);
data.magicCooldown = cooldown;
stack.damageItem(1, player);
}
ToolHelper.incrementStatShotsFired(stack, 1);
if (!world.isRemote) {
for (EntityChaosProjectile shot : getShots(player, stack)) {
EntityHelper.safeSpawn(shot);
}
}
}
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
}
use of net.silentchaos512.gems.entity.EntityChaosProjectile in project SilentGems by SilentChaos512.
the class ItemGemSword method getShots.
private List<EntityChaosProjectile> getShots(EntityPlayer player, ItemStack stack) {
List<EntityChaosProjectile> list = Lists.newArrayList();
if (ToolHelper.getToolTier(stack).ordinal() < EnumMaterialTier.SUPER.ordinal()) {
return list;
}
EnumMagicType magicType = EnumMagicType.getMagicType(stack);
int shotCount = magicType.getShotCount(stack);
// Calculate magic damage.
// Includes player "magic strength" (currently just a constant 1, might do something with it later).
float damage = 1f + getMagicDamage(stack);
// Magic damage enchantment
int magicEnchLevel = EnchantmentHelper.getEnchantmentLevel(ModEnchantments.magicDamage, stack);
if (magicEnchLevel > 0)
damage += ModEnchantments.magicDamage.calcDamage(magicEnchLevel);
damage *= magicType.getDamagePerShotMultiplier();
Item item = stack.getItem();
// Dagger
if (item instanceof ItemGemDagger) {
for (int i = 0; i < shotCount; ++i) {
list.add(new EntityChaosProjectileHoming(player, stack, damage, false, 0.0325, 0.25));
}
} else // Scepter
if (item instanceof ItemGemScepter) {
for (int i = 0; i < shotCount; ++i) {
list.add(new EntityChaosProjectileHoming(player, stack, damage, true, 0.075, 0.35));
}
} else // Katana
if (item instanceof ItemGemKatana) {
final float maxAngle = 0.05f;
for (float angle = -maxAngle; angle <= maxAngle; angle += maxAngle / (shotCount / 2)) {
list.add(new EntityChaosProjectileSweep(player, stack, damage, angle));
}
} else // Machete
if (item instanceof ItemGemMachete) {
for (int i = 0; i < shotCount; ++i) {
list.add(new EntityChaosProjectileScatter(player, stack, damage));
}
} else // Classic sword (default)
{
for (int i = 0; i < shotCount; ++i) {
EntityChaosProjectile e = new EntityChaosProjectile(player, stack, damage);
e.motionY += 0.2 * i;
list.add(e);
}
}
return list;
}
use of net.silentchaos512.gems.entity.EntityChaosProjectile in project SilentGems by SilentChaos512.
the class GemsCommonEvents method onLivingDeath.
@SubscribeEvent
public void onLivingDeath(LivingDeathEvent event) {
Entity entitySource = event.getSource().getTrueSource();
EntityPlayer player = null;
if (event.getEntityLiving() instanceof EntityPlayer) {
EntityPlayer deadPlayer = (EntityPlayer) event.getEntityLiving();
PlayerData data = PlayerDataHandler.get(deadPlayer);
data.haloTime = data.HALO_TIME_DEFAULT;
}
if (entitySource instanceof EntityPlayer) {
player = (EntityPlayer) entitySource;
} else if (entitySource instanceof EntityChaosProjectile) {
EntityChaosProjectile projectile = (EntityChaosProjectile) entitySource;
EntityLivingBase shooter = projectile.getShooter();
if (shooter instanceof EntityPlayer)
player = (EntityPlayer) shooter;
}
if (player != null) {
ItemStack weapon = player.getHeldItem(EnumHand.MAIN_HAND);
if (StackHelper.isValid(weapon) && weapon.getItem() instanceof ITool)
ToolHelper.incrementStatKillCount(weapon, 1);
}
}
Aggregations