Search in sources :

Example 6 with ArrowEntity

use of net.minecraft.entity.projectile.ArrowEntity in project Fragile-Glass by fredtargaryen.

the class EntityDataManager method addCapabilityIfPossible.

public void addCapabilityIfPossible(Entity e, AttachCapabilitiesEvent<Entity> evt) {
    // A player would reasonably expect many existing entities to be able to break fragile blocks, but it is
    // very unlikely that anyone would go to the trouble of writing out all the config lines for every entity.
    // The following code does some type checks and creates BreakerDatas if the entity probably would break a block.
    BreakerData breakerData = this.data.get(e.getType());
    if (breakerData == null) {
        // A breakerdata for this entitytype has not been created yet
        if (e instanceof LivingEntity || e instanceof ArrowEntity || e instanceof FireballEntity || e instanceof MinecartEntity || e instanceof FireworkRocketEntity || e instanceof BoatEntity || e instanceof TNTEntity || e instanceof FallingBlockEntity) {
            breakerData = new BreakerData(DataReference.MINIMUM_ENTITY_SPEED_SQUARED, DataReference.MAXIMUM_ENTITY_SPEED_SQUARED, new String[] {});
            this.data.put(e.getType(), breakerData);
        }
    }
    if (breakerData != null) {
        // The entity was predefined (via configs or commands) as being able to break a block,
        // or a BreakerData was automatically created above.
        ICapabilityProvider iCapProv = new ICapabilityProvider() {

            IBreakCapability inst = new IBreakCapability() {

                @Override
                public void init(Entity e) {
                }

                @Override
                public void update(Entity e) {
                }

                @Override
                public double getSpeedSquared(Entity e) {
                    Vector3d motion = e.getMotion();
                    return motion.x * motion.x + motion.y * motion.y + motion.z * motion.z;
                }

                @Override
                public boolean isAbleToBreak(Entity e, double speedSq) {
                    BreakerData breakerData = EntityDataManager.this.data.get(e.getType());
                    if (breakerData == null)
                        return false;
                    return speedSq >= breakerData.getMinSpeedSquared() && speedSq <= breakerData.getMaxSpeedSquared();
                }

                @Override
                public double getMotionX(Entity e) {
                    return e.getMotion().x;
                }

                @Override
                public double getMotionY(Entity e) {
                    return e.getMotion().y;
                }

                @Override
                public double getMotionZ(Entity e) {
                    return e.getMotion().z;
                }

                @Override
                public byte getNoOfBreaks(Entity e) {
                    return 1;
                }
            };

            @Nullable
            @Override
            public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> capability, @Nullable Direction facing) {
                return capability == FragileGlassBase.BREAKCAP ? LazyOptional.of(() -> (T) inst) : LazyOptional.empty();
            }
        };
        evt.addCapability(DataReference.BREAK_LOCATION, iCapProv);
    }
}
Also used : FallingBlockEntity(net.minecraft.entity.item.FallingBlockEntity) BreakerData(com.fredtargaryen.fragileglass.config.behaviour.data.BreakerData) BoatEntity(net.minecraft.entity.item.BoatEntity) FallingBlockEntity(net.minecraft.entity.item.FallingBlockEntity) ArrowEntity(net.minecraft.entity.projectile.ArrowEntity) BoatEntity(net.minecraft.entity.item.BoatEntity) TNTEntity(net.minecraft.entity.item.TNTEntity) Entity(net.minecraft.entity.Entity) LivingEntity(net.minecraft.entity.LivingEntity) MinecartEntity(net.minecraft.entity.item.minecart.MinecartEntity) FireballEntity(net.minecraft.entity.projectile.FireballEntity) FireworkRocketEntity(net.minecraft.entity.projectile.FireworkRocketEntity) TNTEntity(net.minecraft.entity.item.TNTEntity) IBreakCapability(com.fredtargaryen.fragileglass.entity.capability.IBreakCapability) Capability(net.minecraftforge.common.capabilities.Capability) MinecartEntity(net.minecraft.entity.item.minecart.MinecartEntity) ICapabilityProvider(net.minecraftforge.common.capabilities.ICapabilityProvider) Nonnull(javax.annotation.Nonnull) ArrowEntity(net.minecraft.entity.projectile.ArrowEntity) FireworkRocketEntity(net.minecraft.entity.projectile.FireworkRocketEntity) Direction(net.minecraft.util.Direction) IBreakCapability(com.fredtargaryen.fragileglass.entity.capability.IBreakCapability) LivingEntity(net.minecraft.entity.LivingEntity) Vector3d(net.minecraft.util.math.vector.Vector3d) Nullable(javax.annotation.Nullable) FireballEntity(net.minecraft.entity.projectile.FireballEntity)

Example 7 with ArrowEntity

use of net.minecraft.entity.projectile.ArrowEntity in project BleachHack by BleachDrinker420.

the class ProjectileSimulator method summonProjectile.

public static Entity summonProjectile(PlayerEntity thrower, boolean allowThrowables, boolean allowXp, boolean allowPotions) {
    ItemStack hand = (isThrowable(thrower.getInventory().getMainHandStack().getItem(), allowThrowables, allowXp, allowPotions) ? thrower.getInventory().getMainHandStack() : isThrowable(thrower.getInventory().offHand.get(0).getItem(), allowThrowables, allowXp, allowPotions) ? thrower.getInventory().offHand.get(0) : null);
    if (hand == null) {
        return null;
    }
    if (hand.getItem() instanceof RangedWeaponItem) {
        float charged = hand.getItem() == Items.CROSSBOW && CrossbowItem.isCharged(hand) ? 1f : hand.getItem() == Items.CROSSBOW ? 0f : BowItem.getPullProgress(thrower.getItemUseTime());
        if (charged > 0f) {
            Entity e = new ArrowEntity(mc.world, mc.player);
            initProjectile(e, thrower, 0f, charged * 3);
            return e;
        }
    } else if (hand.getItem() instanceof SnowballItem || hand.getItem() instanceof EggItem || hand.getItem() instanceof EnderPearlItem) {
        Entity e = new SnowballEntity(mc.world, mc.player);
        initProjectile(e, thrower, 0f, 1.5f);
        return e;
    } else if (hand.getItem() instanceof ExperienceBottleItem) {
        Entity e = new ExperienceBottleEntity(mc.world, mc.player);
        initProjectile(e, thrower, -20f, 0.7f);
        return e;
    } else if (hand.getItem() instanceof ThrowablePotionItem) {
        Entity e = new PotionEntity(mc.world, mc.player);
        initProjectile(e, thrower, -20f, 0.5f);
        return e;
    } else if (hand.getItem() instanceof TridentItem) {
        Entity e = new TridentEntity(mc.world, mc.player, hand);
        initProjectile(e, thrower, 0f, 2.5f);
        return e;
    }
    return null;
}
Also used : Entity(net.minecraft.entity.Entity) PotionEntity(net.minecraft.entity.projectile.thrown.PotionEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) LivingEntity(net.minecraft.entity.LivingEntity) SnowballEntity(net.minecraft.entity.projectile.thrown.SnowballEntity) TridentEntity(net.minecraft.entity.projectile.TridentEntity) ThrownEntity(net.minecraft.entity.projectile.thrown.ThrownEntity) ArrowEntity(net.minecraft.entity.projectile.ArrowEntity) ExperienceBottleEntity(net.minecraft.entity.projectile.thrown.ExperienceBottleEntity) ArrowEntity(net.minecraft.entity.projectile.ArrowEntity) PotionEntity(net.minecraft.entity.projectile.thrown.PotionEntity) ExperienceBottleEntity(net.minecraft.entity.projectile.thrown.ExperienceBottleEntity) TridentEntity(net.minecraft.entity.projectile.TridentEntity) SnowballEntity(net.minecraft.entity.projectile.thrown.SnowballEntity)

Example 8 with ArrowEntity

use of net.minecraft.entity.projectile.ArrowEntity in project minecolonies by ldtteam.

the class EntityAIArcherTraining method shoot.

/**
 * The ranged attack modus
 *
 * @return the next state to go to.
 */
protected IAIState shoot() {
    if (currentShootingTarget == null || !isSetup()) {
        worker.getCitizenData().setVisibleStatus(VisibleCitizenStatus.WORKING);
        return START_WORKING;
    }
    if (worker.isUsingItem()) {
        WorkerUtil.faceBlock(currentShootingTarget, worker);
        worker.swing(Hand.MAIN_HAND);
        final ArrowEntity arrow = ModEntities.MC_NORMAL_ARROW.create(world);
        arrow.setBaseDamage(0);
        arrow.setOwner(worker);
        arrow.setPos(worker.getX(), worker.getY() + 1, worker.getZ());
        final double xVector = currentShootingTarget.getX() - worker.getX();
        final double yVector = currentShootingTarget.getY() - arrow.getY();
        final double zVector = currentShootingTarget.getZ() - worker.getZ();
        final double distance = (double) MathHelper.sqrt(xVector * xVector + zVector * zVector);
        final double chance = HIT_CHANCE_DIVIDER / (getPrimarySkillLevel() / 2.0 + 1);
        arrow.shoot(xVector, yVector + distance * RANGED_AIM_SLIGHTLY_HIGHER_MULTIPLIER, zVector, RANGED_VELOCITY, (float) chance);
        worker.playSound(SoundEvents.SKELETON_SHOOT, (float) BASIC_VOLUME, (float) SoundUtils.getRandomPitch(worker.getRandom()));
        worker.level.addFreshEntity(arrow);
        final double xDiff = currentShootingTarget.getX() - worker.getX();
        final double zDiff = currentShootingTarget.getZ() - worker.getZ();
        final double goToX = xDiff > 0 ? MOVE_MINIMAL : -MOVE_MINIMAL;
        final double goToZ = zDiff > 0 ? MOVE_MINIMAL : -MOVE_MINIMAL;
        worker.move(MoverType.SELF, new Vector3d(goToX, 0, goToZ));
        if (worker.getRandom().nextBoolean()) {
            worker.getCitizenItemHandler().damageItemInHand(Hand.MAIN_HAND, 1);
        }
        worker.stopUsingItem();
        this.incrementActionsDoneAndDecSaturation();
        arrowInProgress = arrow;
        currentAttackDelay = RANGED_ATTACK_DELAY_BASE;
    } else {
        reduceAttackDelay();
        if (currentAttackDelay <= 0) {
            worker.startUsingItem(Hand.MAIN_HAND);
        }
        return ARCHER_SHOOT;
    }
    return ARCHER_CHECK_SHOT;
}
Also used : Vector3d(net.minecraft.util.math.vector.Vector3d) ArrowEntity(net.minecraft.entity.projectile.ArrowEntity)

Aggregations

ArrowEntity (net.minecraft.entity.projectile.ArrowEntity)8 LivingEntity (net.minecraft.entity.LivingEntity)4 Entity (net.minecraft.entity.Entity)3 PlayerEntity (net.minecraft.entity.player.PlayerEntity)3 Vector3d (net.minecraft.util.math.vector.Vector3d)3 ItemStack (net.minecraft.item.ItemStack)2 Inject (org.spongepowered.asm.mixin.injection.Inject)2 BreakerData (com.fredtargaryen.fragileglass.config.behaviour.data.BreakerData)1 IBreakCapability (com.fredtargaryen.fragileglass.entity.capability.IBreakCapability)1 PoiseClusterEntity (com.minecraftabnormals.endergetic.common.entities.PoiseClusterEntity)1 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1 Nonnull (javax.annotation.Nonnull)1 Nullable (javax.annotation.Nullable)1 BoatEntity (net.minecraft.entity.item.BoatEntity)1 FallingBlockEntity (net.minecraft.entity.item.FallingBlockEntity)1 TNTEntity (net.minecraft.entity.item.TNTEntity)1 MinecartEntity (net.minecraft.entity.item.minecart.MinecartEntity)1 FireballEntity (net.minecraft.entity.projectile.FireballEntity)1 FireworkRocketEntity (net.minecraft.entity.projectile.FireworkRocketEntity)1