Search in sources :

Example 1 with EntityChaosProjectile

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;
                }
            }
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) ItemStack(net.minecraft.item.ItemStack) ByteBufUtil(io.netty.buffer.ByteBufUtil) ByteBuf(io.netty.buffer.ByteBuf) Vec3d(net.minecraft.util.math.Vec3d) Predicate(com.google.common.base.Predicate) EntityLivingBase(net.minecraft.entity.EntityLivingBase) World(net.minecraft.world.World) SilentGems(net.silentchaos512.gems.SilentGems) Color(net.silentchaos512.lib.util.Color) Entity(net.minecraft.entity.Entity) EntityLivingBase(net.minecraft.entity.EntityLivingBase)

Example 2 with EntityChaosProjectile

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);
}
Also used : ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) EntityChaosProjectile(net.silentchaos512.gems.entity.EntityChaosProjectile) ItemStack(net.minecraft.item.ItemStack) PlayerData(net.silentchaos512.gems.handler.PlayerDataHandler.PlayerData)

Example 3 with EntityChaosProjectile

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;
}
Also used : EntityChaosProjectileScatter(net.silentchaos512.gems.entity.EntityChaosProjectileScatter) EntityChaosProjectileSweep(net.silentchaos512.gems.entity.EntityChaosProjectileSweep) EnumMagicType(net.silentchaos512.gems.util.EnumMagicType) EntityChaosProjectile(net.silentchaos512.gems.entity.EntityChaosProjectile) EntityChaosProjectileHoming(net.silentchaos512.gems.entity.EntityChaosProjectileHoming) Item(net.minecraft.item.Item) EntityItem(net.minecraft.entity.item.EntityItem)

Example 4 with EntityChaosProjectile

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);
    }
}
Also used : Entity(net.minecraft.entity.Entity) EntityChaosProjectile(net.silentchaos512.gems.entity.EntityChaosProjectile) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) PlayerData(net.silentchaos512.gems.handler.PlayerDataHandler.PlayerData) ITool(net.silentchaos512.gems.api.ITool) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

ItemStack (net.minecraft.item.ItemStack)3 EntityChaosProjectile (net.silentchaos512.gems.entity.EntityChaosProjectile)3 Entity (net.minecraft.entity.Entity)2 EntityLivingBase (net.minecraft.entity.EntityLivingBase)2 PlayerData (net.silentchaos512.gems.handler.PlayerDataHandler.PlayerData)2 Predicate (com.google.common.base.Predicate)1 ByteBuf (io.netty.buffer.ByteBuf)1 ByteBufUtil (io.netty.buffer.ByteBufUtil)1 EntityItem (net.minecraft.entity.item.EntityItem)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 Item (net.minecraft.item.Item)1 ActionResult (net.minecraft.util.ActionResult)1 EnumActionResult (net.minecraft.util.EnumActionResult)1 Vec3d (net.minecraft.util.math.Vec3d)1 World (net.minecraft.world.World)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1 SilentGems (net.silentchaos512.gems.SilentGems)1 ITool (net.silentchaos512.gems.api.ITool)1 EntityChaosProjectileHoming (net.silentchaos512.gems.entity.EntityChaosProjectileHoming)1 EntityChaosProjectileScatter (net.silentchaos512.gems.entity.EntityChaosProjectileScatter)1