Search in sources :

Example 1 with PartEntity

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

the class ItemSoulBottle method onLeftClickEntity.

@Override
public boolean onLeftClickEntity(ItemStack stack, PlayerEntity player, Entity entity) {
    if (player.isCreative()) {
        if (!player.world.isRemote && !(entity instanceof PartEntity)) {
            CompoundNBT bottle = stack.getTagCompound();
            if (bottle == null) {
                bottle = new CompoundNBT();
                stack.setTagCompound(bottle);
            }
            if (!bottle.hasKey(ENTITY_IN_TAG)) {
                CompoundNBT entityTag = new CompoundNBT();
                entity.writeToNBTOptional(entityTag);
                entityTag.removeTag("UUIDLeast");
                entityTag.removeTag("UUIDMost");
                entityTag.removeTag("Pos");
                ListNBT passengers = entityTag.getTagList("Passengers", 10);
                for (INBT passenger : passengers) {
                    ((CompoundNBT) passenger).removeTag("UUIDLeast");
                    ((CompoundNBT) passenger).removeTag("UUIDMost");
                    ((CompoundNBT) passenger).removeTag("Pos");
                }
                entity.setDead();
                for (Entity passenger : entity.getPassengers()) {
                    passenger.setDead();
                }
                bottle.setTag(ENTITY_IN_TAG, entityTag);
                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) PartEntity(net.minecraftforge.entity.PartEntity) ListNBT(net.minecraft.nbt.ListNBT) CompoundNBT(net.minecraft.nbt.CompoundNBT) INBT(net.minecraft.nbt.INBT) PartEntity(net.minecraftforge.entity.PartEntity)

Example 2 with PartEntity

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

the class ProjectileThrownBlock method onHit.

@Override
protected void onHit(RayTraceResult result) {
    if (this.world.isRemote) {
        return;
    }
    if (result.typeOfHit == Type.ENTITY) {
        if (result.entityHit == this.thrower) {
            return;
        }
        if (result.entityHit instanceof PartEntity && ((PartEntity) result.entityHit).parent == this.thrower) {
            return;
        }
        result.entityHit.attackEntityFrom(DamageSource.causeIndirectDamage(this, this.thrower), 10);
        this.setDead();
        return;
    }
    if (CQRConfig.bosses.thrownBlocksGetPlaced && this.placeOnImpact) {
        // TODO: Add placed block to whitelist of protected region
        this.world.setBlockState(new BlockPos(result.hitVec.x, result.hitVec.y, result.hitVec.z), this.state);
        // this.world.createExplosion(this.thrower, this.posX, this.posY, this.posZ, 1.5F, false);
        if (this.world instanceof ServerWorld) {
            ServerWorld ws = (ServerWorld) this.world;
            Vector3d pos = result.hitVec;
            double particleSpeed = 0.2D;
            for (int i = 0; i < 50; i++) {
                double dx = -0.5 + this.rand.nextDouble();
                dx *= particleSpeed;
                double dy = -0.5 + this.rand.nextDouble();
                dy *= particleSpeed;
                double dz = -0.5 + this.rand.nextDouble();
                dz *= particleSpeed;
                ws.spawnParticle(ParticleTypes.BLOCK_CRACK, pos.x, pos.y, pos.z, dx, dy, dz, Block.getStateId(this.state));
                this.playSound(this.state.getBlock().getSoundType(this.state, this.world, this.getPosition(), this).getPlaceSound(), 1.5F, 1.25F);
            }
        }
    }
    this.setDead();
}
Also used : ServerWorld(net.minecraft.world.server.ServerWorld) Vector3d(net.minecraft.util.math.vector.Vector3d) BlockPos(net.minecraft.util.math.BlockPos) PartEntity(net.minecraftforge.entity.PartEntity)

Example 3 with PartEntity

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

the class ItemUtil method attackTarget.

/**
 * Copied from {@link PlayerEntity#attackTargetEntityWithCurrentItem(Entity)}
 *
 * @param stack
 * @param player
 * @param targetEntity
 * @param fakeCrit                     If set to true and no real crit occurred it will spawn spell crit particles
 *                                     (vanilla: false)
 * @param damageBonus                  A flat damage bonus which affects the main attack and enchantments like sweeping
 *                                     edge (vanilla: 0.0F)
 * @param damageMultiplier             A damage multiplier which affects the main attack and enchantments like sweeping
 *                                     edge (vanilla: 1.0F)
 * @param sweepingEnabled              If set to false the player won't be able to make a sweeping attack with this item
 *                                     (vanilla: true)
 * @param sweepingDamage               The base amount of damage which the sweeping attack deals (vanilla: 1.0F)
 * @param sweepingDamageMultiplicative A damage bonus for sweeping attacks based on the main attack damage (vanilla:
 *                                     0.0F)
 * @param sweepingRangeHorizontal      (vanilla: 1.0D)
 * @param sweepingRangeVertical        (vanilla: 0.25D)
 * @param sweepingKnockback            (vanilla: 0.4F)
 */
public static void attackTarget(ItemStack stack, PlayerEntity player, Entity targetEntity, boolean fakeCrit, float damageBonus, float damageMultiplier, boolean sweepingEnabled, float sweepingDamage, float sweepingDamageMultiplicative, double sweepingRangeHorizontal, double sweepingRangeVertical, float sweepingKnockback) {
    // CQR: Replacement for ForgeHooks.onPlayerAttackTarget to prevent infinity loop
    if (MinecraftForge.EVENT_BUS.post(new AttackEntityEvent(player, targetEntity))) {
        return;
    }
    if (targetEntity.isAttackable()) {
        if (!targetEntity.skipAttackInteraction(player)) {
            float f = (float) player.getAttribute(Attributes.ATTACK_DAMAGE).getValue();
            // CQR: Add flat damage bonus
            f = f + damageBonus;
            float f1;
            if (targetEntity instanceof LivingEntity) {
                f1 = EnchantmentHelper.getDamageBonus(player.getMainHandItem(), ((LivingEntity) targetEntity).getMobType());
            } else {
                f1 = EnchantmentHelper.getDamageBonus(player.getMainHandItem(), CreatureAttribute.UNDEFINED);
            }
            float f2 = player.getAttackStrengthScale(0.5F);
            f = f * (0.2F + f2 * f2 * 0.8F);
            f1 = f1 * f2;
            player.resetAttackStrengthTicker();
            if (f > 0.0F || f1 > 0.0F) {
                boolean flag = f2 > 0.9F;
                boolean flag1 = false;
                int i = 0;
                i = i + EnchantmentHelper.getKnockbackBonus(player);
                if (player.isSprinting() && flag) {
                    player.level.playSound((PlayerEntity) null, player.getX(), player.getY(), player.getZ(), SoundEvents.PLAYER_ATTACK_KNOCKBACK, player.getSoundSource(), 1.0F, 1.0F);
                    ++i;
                    flag1 = true;
                }
                boolean flag2 = flag && player.fallDistance > 0.0F && !player.isOnGround() && !player.onClimbable() && !player.isInWater() && !player.hasEffect(Effects.BLINDNESS) && !player.isPassenger() && targetEntity instanceof LivingEntity;
                flag2 = flag2 && !player.isSprinting();
                CriticalHitEvent hitResult = ForgeHooks.getCriticalHit(player, targetEntity, flag2, flag2 ? 1.5F : 1.0F);
                flag2 = hitResult != null;
                if (flag2) {
                    f *= hitResult.getDamageModifier();
                }
                f = f + f1;
                // CQR: Add damage bonus multiplier
                f = f * damageMultiplier;
                boolean flag3 = false;
                double d0 = player.walkDist - player.walkDistO;
                // CQR: Disable sweep attack when sweepingEnabled is false
                if (sweepingEnabled && flag && !flag2 && !flag1 && player.isOnGround() && d0 < player.getSpeed()) {
                    ItemStack itemstack = player.getItemInHand(Hand.MAIN_HAND);
                    if (itemstack.getItem() instanceof SwordItem) {
                        flag3 = true;
                    }
                }
                float f4 = 0.0F;
                boolean flag4 = false;
                int j = EnchantmentHelper.getFireAspect(player);
                if (targetEntity instanceof LivingEntity) {
                    f4 = ((LivingEntity) targetEntity).getHealth();
                    if (j > 0 && !targetEntity.isOnFire()) {
                        flag4 = true;
                        targetEntity.setSecondsOnFire(1);
                    }
                }
                Vector3d motion = player.getDeltaMovement();
                boolean flag5 = targetEntity.hurt(DamageSource.playerAttack(player), f);
                if (flag5) {
                    if (i > 0) {
                        if (targetEntity instanceof LivingEntity) {
                            ((LivingEntity) targetEntity).knockback(i * 0.5F, MathHelper.sin(player.yRot * 0.017453292F), (-MathHelper.cos(player.yRot * 0.017453292F)));
                        } else {
                            targetEntity.push(-MathHelper.sin(player.yRot * 0.017453292F) * i * 0.5F, 0.1D, MathHelper.cos(player.yRot * 0.017453292F) * i * 0.5F);
                        }
                        player.setDeltaMovement(player.getDeltaMovement().multiply(0.6, 1.0, 0.6));
                        player.setSprinting(false);
                    }
                    if (flag3) {
                        // CQR: Allow modification of sweeping damage
                        float f3 = sweepingDamage + sweepingDamageMultiplicative * f;
                        f3 = f3 + EnchantmentHelper.getSweepingDamageRatio(player) * f;
                        double entityReachDistanceSqr = getEntityReachDistanceSqr(player);
                        // CQR: Allow modification of sweeping hitbox
                        AxisAlignedBB aabb = targetEntity.getBoundingBox().expandTowards(sweepingRangeHorizontal, sweepingRangeVertical, sweepingRangeHorizontal);
                        for (LivingEntity entitylivingbase : player.level.getEntitiesOfClass(LivingEntity.class, aabb)) {
                            // CQR: Increase sweeping range when players reach distance is higher
                            if (entitylivingbase != player && entitylivingbase != targetEntity && !player.isAlliedTo(entitylivingbase) && player.distanceToSqr(entitylivingbase) < entityReachDistanceSqr) {
                                // CQR: Allow modification of sweeping knockback strength
                                entitylivingbase.knockback(sweepingKnockback, MathHelper.sin(player.yRot * 0.017453292F), (-MathHelper.cos(player.yRot * 0.017453292F)));
                                entitylivingbase.hurt(DamageSource.playerAttack(player), f3);
                            }
                        }
                        player.level.playSound((PlayerEntity) null, player.getX(), player.getY(), player.getZ(), SoundEvents.PLAYER_ATTACK_SWEEP, player.getSoundSource(), 1.0F, 1.0F);
                        player.sweepAttack();
                    }
                    if (targetEntity instanceof ServerPlayerEntity && targetEntity.hurtMarked) {
                        ((ServerPlayerEntity) targetEntity).connection.send(new SEntityVelocityPacket(targetEntity));
                        targetEntity.hurtMarked = false;
                        targetEntity.setDeltaMovement(motion);
                    }
                    if (flag2) {
                        player.level.playSound((PlayerEntity) null, player.getX(), player.getY(), player.getZ(), SoundEvents.PLAYER_ATTACK_CRIT, player.getSoundSource(), 1.0F, 1.0F);
                        player.crit(targetEntity);
                    } else if (fakeCrit) {
                        // CQR: Allow fake crits to happen
                        player.level.playSound((PlayerEntity) null, player.getX(), player.getY(), player.getZ(), SoundEvents.PLAYER_ATTACK_CRIT, player.getSoundSource(), 1.0F, 1.2F);
                        player.crit(targetEntity);
                    }
                    if (!flag2 && !fakeCrit && !flag3) {
                        if (flag) {
                            player.level.playSound((PlayerEntity) null, player.getX(), player.getY(), player.getZ(), SoundEvents.PLAYER_ATTACK_STRONG, player.getSoundSource(), 1.0F, 1.0F);
                        } else {
                            player.level.playSound((PlayerEntity) null, player.getX(), player.getY(), player.getZ(), SoundEvents.PLAYER_ATTACK_WEAK, player.getSoundSource(), 1.0F, 1.0F);
                        }
                    }
                    if (f1 > 0.0F) {
                        player.magicCrit(targetEntity);
                    }
                    player.setLastHurtMob(targetEntity);
                    if (targetEntity instanceof LivingEntity) {
                        EnchantmentHelper.doPostHurtEffects((LivingEntity) targetEntity, player);
                    }
                    EnchantmentHelper.doPostDamageEffects(player, targetEntity);
                    ItemStack itemstack1 = player.getMainHandItem();
                    Entity entity = targetEntity;
                    if (targetEntity instanceof PartEntity) {
                        Entity ientitymultipart = ((PartEntity) targetEntity).getParent();
                        if (ientitymultipart instanceof LivingEntity) {
                            entity = (LivingEntity) ientitymultipart;
                        }
                    }
                    if (!itemstack1.isEmpty() && entity instanceof LivingEntity) {
                        ItemStack beforeHitCopy = itemstack1.copy();
                        itemstack1.hurtEnemy((LivingEntity) entity, player);
                        if (itemstack1.isEmpty()) {
                            ForgeEventFactory.onPlayerDestroyItem(player, beforeHitCopy, Hand.MAIN_HAND);
                            player.setItemInHand(Hand.MAIN_HAND, ItemStack.EMPTY);
                        }
                    }
                    if (targetEntity instanceof LivingEntity) {
                        float f5 = f4 - ((LivingEntity) targetEntity).getHealth();
                        player.awardStat(Stats.DAMAGE_DEALT, Math.round(f5 * 10.0F));
                        if (j > 0) {
                            targetEntity.setSecondsOnFire(j * 4);
                        }
                        if (player.level instanceof ServerWorld && f5 > 2.0F) {
                            int k = (int) (f5 * 0.5D);
                            ((ServerWorld) targetEntity.level).sendParticles(ParticleTypes.DAMAGE_INDICATOR, targetEntity.getX(), targetEntity.getY(0.5D), targetEntity.getZ(), k, 0.1D, 0.0D, 0.1D, 0.2D);
                        }
                    }
                    player.causeFoodExhaustion(0.1F);
                } else {
                    player.level.playSound((PlayerEntity) null, player.getX(), player.getY(), player.getZ(), SoundEvents.PLAYER_ATTACK_NODAMAGE, player.getSoundSource(), 1.0F, 1.0F);
                    if (flag4) {
                        targetEntity.clearFire();
                    }
                }
            }
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) LivingEntity(net.minecraft.entity.LivingEntity) PartEntity(net.minecraftforge.entity.PartEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) PartEntity(net.minecraftforge.entity.PartEntity) SwordItem(net.minecraft.item.SwordItem) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) LivingEntity(net.minecraft.entity.LivingEntity) SEntityVelocityPacket(net.minecraft.network.play.server.SEntityVelocityPacket) ServerWorld(net.minecraft.world.server.ServerWorld) AttackEntityEvent(net.minecraftforge.event.entity.player.AttackEntityEvent) CriticalHitEvent(net.minecraftforge.event.entity.player.CriticalHitEvent) Vector3d(net.minecraft.util.math.vector.Vector3d) ItemStack(net.minecraft.item.ItemStack)

Example 4 with PartEntity

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

the class ProjectileHookShotHook method onHit.

@Override
protected void onHit(RayTraceResult result) {
    if (!this.world.isRemote && this.getHookState() == EnumHookState.SHOOT) {
        if (result.typeOfHit == RayTraceResult.Type.BLOCK) {
            BlockState state = this.world.getBlockState(result.getBlockPos());
            if (this.item.canLatchToBlock(state.getBlock())) {
                // Hit a valid latch block, start pulling next tick
                Vector3d v = result.hitVec;
                this.setPosition(v.x, v.y, v.z);
                this.motionX = 0.0D;
                this.motionY = 0.0D;
                this.motionZ = 0.0D;
                this.setLatchedPos(v);
                this.setHookState(EnumHookState.PULL_SHOOTER_TO_HOOK_LATCHED_TO_BLOCK);
            } else {
                // Hit something but this hookshot cannot latch to it, send the hook back
                this.motionX = 0.0D;
                this.motionY = 0.0D;
                this.motionZ = 0.0D;
                this.setHookState(EnumHookState.RETRACT);
            }
        } else if (result.typeOfHit == RayTraceResult.Type.ENTITY) {
            if (result.entityHit != this.thrower && result.entityHit instanceof LivingEntity) {
                Entity entityHit = result.entityHit;
                // Recalculate the hitVec because result.hitVec is just the pos of result.entityHit
                Vector3d start = new Vector3d(this.posX, this.posY, this.posZ);
                Vector3d end = start.add(this.motionX, this.motionY, this.motionZ);
                AxisAlignedBB aabb = entityHit.getEntityBoundingBox().grow(0.3D);
                RayTraceResult result1 = aabb.calculateIntercept(start, end);
                Vector3d v = result1.hitVec;
                this.setPosition(v.x, v.y, v.z);
                this.motionX = 0.0D;
                this.motionY = 0.0D;
                this.motionZ = 0.0D;
                this.setLatchedEntity(entityHit);
                this.setLatchedPos(v.subtract(entityHit.posX, entityHit.posY, entityHit.posZ));
                if (CQRConfig.general.hookOnlyPullsSmallerEntities) {
                    double sizeOwner = this.thrower.width * this.thrower.height * 1.25D;
                    double sizeHit = entityHit.width * entityHit.height;
                    if (sizeOwner >= sizeHit || entityHit instanceof PartEntity) {
                        this.setHookState(EnumHookState.PULL_ENTITY_TO_SHOOTER);
                    } else {
                        this.setHookState(EnumHookState.PULL_SHOOTER_TO_HOOK_LATCHED_TO_ENTITY);
                    }
                } else {
                    this.setHookState(EnumHookState.PULL_ENTITY_TO_SHOOTER);
                }
            }
        }
    }
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) LivingEntity(net.minecraft.entity.LivingEntity) PartEntity(net.minecraftforge.entity.PartEntity) BlockState(net.minecraft.block.BlockState) Vector3d(net.minecraft.util.math.vector.Vector3d) RayTraceResult(net.minecraft.util.math.RayTraceResult) PartEntity(net.minecraftforge.entity.PartEntity)

Example 5 with PartEntity

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

the class ProjectileHomingEnderEye method onHit.

@Override
protected void onHit(RayTraceResult result) {
    // TODO: Remove a few end blocks around the location
    if (!this.world.isRemote) {
        AreaEffectCloudEntity entityareaeffectcloud = new AreaEffectCloudEntity(this.world, this.posX, this.posY, this.posZ);
        entityareaeffectcloud.setOwner(this.shooter);
        entityareaeffectcloud.setParticle(ParticleTypes.DRAGON_BREATH);
        entityareaeffectcloud.setRadius(2F);
        entityareaeffectcloud.setDuration(200);
        entityareaeffectcloud.setRadiusOnUse(-0.25F);
        entityareaeffectcloud.setWaitTime(10);
        entityareaeffectcloud.setRadiusPerTick(-entityareaeffectcloud.getRadius() / entityareaeffectcloud.getDuration());
        entityareaeffectcloud.addEffect(new EffectInstance(Effects.INSTANT_DAMAGE, 20, 1));
        this.world.spawnEntity(entityareaeffectcloud);
        if (result.typeOfHit == RayTraceResult.Type.BLOCK) {
            this.world.createExplosion(this.shooter, this.posX, this.posY, this.posZ, 2, false);
            this.setDead();
        } else if (result.typeOfHit == RayTraceResult.Type.ENTITY && result.entityHit != null && result.entityHit != this.shooter && !(result.entityHit instanceof PartEntity)) {
            this.applyEntityCollisionEye(result.entityHit);
        }
    }
    super.onHit(result);
}
Also used : AreaEffectCloudEntity(net.minecraft.entity.AreaEffectCloudEntity) PartEntity(net.minecraftforge.entity.PartEntity) EffectInstance(net.minecraft.potion.EffectInstance)

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