Search in sources :

Example 6 with PartEntity

use of net.minecraftforge.entity.PartEntity in project ChocolateQuestRepoured by TeamChocoQuest.

the class EntityAIAttackSpecialSpinAttack method continueAttack.

@Override
public void continueAttack(AbstractEntityCQR attacker, LivingEntity target, int tick) {
    final boolean oldTargetWasNull = this.targetWasNullInLastCycle;
    this.targetWasNullInLastCycle = target == null || target.isDeadOrDying();
    if (attacker.horizontalCollision) {
        this.ticksCollided++;
    } else {
        this.ticksCollided = 0;
    }
    if (!this.targetWasNullInLastCycle && oldTargetWasNull != this.targetWasNullInLastCycle) {
        this.calcAttackDirection(attacker, target);
    }
    Vector3d deltaMovement = new Vector3d(this.attackDirection.x, attacker.getDeltaMovement().y(), this.attackDirection.z);
    /*attacker.motionX = this.attackDirection.x;
		attacker.motionZ = this.attackDirection.z;
		atacker.velocityChanged = true;*/
    attacker.setDeltaMovement(deltaMovement);
    attacker.hasImpulse = true;
    // First: Damage all entities around us
    final double radius = 1.5 * attacker.getSizeVariation();
    List<Entity> affectedEntities = attacker.getWorld().getEntities(attacker, attacker.getBoundingBox().inflate(radius), TargetUtil.createPredicateNonAlly(attacker.getFaction()));
    affectedEntities.forEach((Entity entity) -> {
        if (entity == null) {
            return;
        }
        if (entity instanceof PartEntity) {
            return;
        }
        if (attacker.distanceTo(entity) > radius) {
            return;
        }
        if (entity instanceof LivingEntity) {
            LivingEntity living = (LivingEntity) entity;
            float dmg = (float) attacker.getAttribute(Attributes.ATTACK_DAMAGE).getValue();
            dmg += 0.75 * EnchantmentHelper.getDamageBonus(attacker.getOffhandItem(), living.getMobType());
            dmg += 0.75 * EnchantmentHelper.getDamageBonus(attacker.getMainHandItem(), living.getMobType());
            /*
				 * living.attackEntityFrom(DamageSource.causeThornsDamage(attacker), dmg);
				 * final Vec3d v = living.getPositionVector().subtract(attacker.getPositionVector()).normalize().scale(1.25).add(0,
				 * 0.25, 0).scale(attacker.getSizeVariation()).add(attackDirection);
				 * living.motionX += v.x;
				 * living.motionY += v.y;
				 * living.motionZ += v.z;
				 * living.velocityChanged = true;
				 */
            final float knockbackStrength = 0.6125F * attacker.getSizeVariation();
            living.hurt(DamageSource.mobAttack(attacker), dmg);
            // Correct replacement?
            living.knockback(/*entity,*/
            knockbackStrength, 1, 1);
        }
    });
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) Entity(net.minecraft.entity.Entity) LivingEntity(net.minecraft.entity.LivingEntity) PartEntity(net.minecraftforge.entity.PartEntity) Vector3d(net.minecraft.util.math.vector.Vector3d) PartEntity(net.minecraftforge.entity.PartEntity)

Example 7 with PartEntity

use of net.minecraftforge.entity.PartEntity in project ChocolateQuestRepoured by TeamChocoQuest.

the class ISizable method setSizeVariation.

// Always use this to change the size, never call resize directly!!
default void setSizeVariation(float size) {
    this.applySizeVariation(size);
    if (this instanceof Entity) {
        Entity myself = (Entity) this;
        // Copy from SlimeEntity code
        this.reapplyPositionClone(myself);
        double d0 = myself.getX();
        double d1 = myself.getY();
        double d2 = myself.getZ();
        myself.refreshDimensions();
        myself.setPos(d0, d1, d2);
        if (myself.getParts() != null) {
            for (PartEntity part : myself.getParts()) {
                if (part instanceof ISizable) {
                    ((ISizable) part).setSizeVariation(size);
                }
            }
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) PartEntity(net.minecraftforge.entity.PartEntity) PartEntity(net.minecraftforge.entity.PartEntity)

Example 8 with PartEntity

use of net.minecraftforge.entity.PartEntity in project ChocolateQuestRepoured by TeamChocoQuest.

the class ItemMobToSpawner method onLeftClickEntity.

/*
	 * @Override public boolean canDestroyBlockInCreative(World world, BlockPos pos, ItemStack stack, EntityPlayer player) {
	 * Block block =
	 * world.getBlockState(pos).getBlock(); return block != ModBlocks.SPAWNER && block != Blocks.MOB_SPAWNER; }
	 */
@Override
public boolean onLeftClickEntity(ItemStack stack, PlayerEntity player, Entity entity) {
    if (player.isCreative()) {
        if (!player.world.isRemote && !(entity instanceof PartEntity)) {
            SpawnerFactory.placeSpawner(new Entity[] { entity }, false, null, player.world, new BlockPos(entity));
            entity.setDead();
            for (Entity passenger : entity.getPassengers()) {
                passenger.setDead();
            }
            this.spawnAdditions(entity.world, entity.posX, entity.posY + entity.height * 0.5D, entity.posZ);
        }
        return true;
    }
    return false;
}
Also used : Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) LivingEntity(net.minecraft.entity.LivingEntity) PartEntity(net.minecraftforge.entity.PartEntity) BlockPos(net.minecraft.util.math.BlockPos) PartEntity(net.minecraftforge.entity.PartEntity)

Aggregations

PartEntity (net.minecraftforge.entity.PartEntity)8 Entity (net.minecraft.entity.Entity)6 LivingEntity (net.minecraft.entity.LivingEntity)4 PlayerEntity (net.minecraft.entity.player.PlayerEntity)4 Vector3d (net.minecraft.util.math.vector.Vector3d)4 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)2 BlockPos (net.minecraft.util.math.BlockPos)2 ServerWorld (net.minecraft.world.server.ServerWorld)2 BlockState (net.minecraft.block.BlockState)1 AreaEffectCloudEntity (net.minecraft.entity.AreaEffectCloudEntity)1 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)1 ItemStack (net.minecraft.item.ItemStack)1 SwordItem (net.minecraft.item.SwordItem)1 CompoundNBT (net.minecraft.nbt.CompoundNBT)1 INBT (net.minecraft.nbt.INBT)1 ListNBT (net.minecraft.nbt.ListNBT)1 SEntityVelocityPacket (net.minecraft.network.play.server.SEntityVelocityPacket)1 EffectInstance (net.minecraft.potion.EffectInstance)1 RayTraceResult (net.minecraft.util.math.RayTraceResult)1 AttackEntityEvent (net.minecraftforge.event.entity.player.AttackEntityEvent)1