use of net.minecraft.entity.projectile.thrown.SnowballEntity in project MCDungeonsWeapons by chronosacaria.
the class ProjectileEffectHelper method fireSnowballAtNearbyEnemy.
public static void fireSnowballAtNearbyEnemy(LivingEntity attacker, int distance) {
World world = attacker.getEntityWorld();
List<LivingEntity> nearbyEntities = world.getEntitiesByClass(LivingEntity.class, new Box(attacker.getX() - distance, attacker.getY() - distance, attacker.getZ() - distance, attacker.getX() + distance, attacker.getY() + distance, attacker.getZ() + distance), (nearbyEntity) -> AbilityHelper.isAoeTarget(nearbyEntity, attacker, attacker));
if (nearbyEntities.size() < 2)
return;
nearbyEntities.sort(Comparator.comparingDouble(livingEntity -> livingEntity.squaredDistanceTo(attacker)));
LivingEntity target = nearbyEntities.get(0);
if (target != null) {
SnowballEntity snowballEntity = new SnowballEntity(world, attacker);
// borrowed from AbstractSkeletonEntity
double towardsX = target.getX() - attacker.getX();
double towardsZ = target.getZ() - attacker.getZ();
double euclideanDist = (double) MathHelper.sqrt(towardsX * towardsX + towardsZ * towardsZ);
double towardsY = target.getBodyY(0.3333333333333333D) - snowballEntity.getY() + euclideanDist * (double) 0.2F;
snowballEntity.setProperties(attacker, attacker.pitch, attacker.yaw, 0.0F, 1.5F, 1.0F);
setProjectileTowards(snowballEntity, towardsX, towardsY, towardsZ, 0);
//
attacker.world.spawnEntity(snowballEntity);
}
}
use of net.minecraft.entity.projectile.thrown.SnowballEntity in project MCDungeonsArmors by chronosacaria.
the class ProjectileEffectHelper method fireSnowballAtNearbyEnemy.
public static void fireSnowballAtNearbyEnemy(LivingEntity user, int distance) {
World world = user.getEntityWorld();
List<LivingEntity> nearbyEntities = world.getEntitiesByClass(LivingEntity.class, new Box(user.getX() - distance, user.getY() - distance, user.getZ() - distance, user.getX() + distance, user.getY() + distance, user.getZ() + distance), (nearbyEntity) -> nearbyEntity != user && AbilityHelper.canFireAtEnemy(user, nearbyEntity));
if (nearbyEntities.size() < 2)
return;
Optional<LivingEntity> nearest = nearbyEntities.stream().min(Comparator.comparingDouble(e -> e.squaredDistanceTo(user)));
LivingEntity target = nearest.get();
SnowballEntity snowballEntity = new SnowballEntity(world, user);
// borrowed from AbstractSkeletonEntity
double d = target.getX() - snowballEntity.getX();
double e = target.getBodyY(0.3333333333333333D) - snowballEntity.getY();
double f = target.getZ() - snowballEntity.getZ();
double g = Math.sqrt(d * d + f * f);
snowballEntity.setVelocity(user, user.getPitch(), user.getYaw(), 0.0F, 1.5F, 1.0F);
setProjectileTowards(snowballEntity, d, e, g, 0);
//
user.world.spawnEntity(snowballEntity);
}
use of net.minecraft.entity.projectile.thrown.SnowballEntity 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;
}
use of net.minecraft.entity.projectile.thrown.SnowballEntity in project BleachHack by BleachDrinker420.
the class Trajectories method onTick.
@BleachSubscribe
public void onTick(EventTick event) {
poses.clear();
Entity entity = ProjectileSimulator.summonProjectile(mc.player, getSetting(1).asToggle().getState(), getSetting(2).asToggle().getState(), getSetting(3).asToggle().getState());
if (entity != null) {
poses.add(ProjectileSimulator.simulate(entity));
}
if (getSetting(4).asToggle().getState()) {
for (Entity e : mc.world.getEntities()) {
if (e instanceof ThrownEntity || e instanceof PersistentProjectileEntity) {
if (!getSetting(4).asToggle().getChild(0).asToggle().getState() && (e instanceof SnowballEntity || e instanceof EggEntity || e instanceof EnderPearlEntity)) {
continue;
}
if (!getSetting(4).asToggle().getChild(1).asToggle().getState() && e instanceof ExperienceBottleEntity) {
continue;
}
if (!mc.world.getBlockCollisions(e, e.getBoundingBox()).allMatch(VoxelShape::isEmpty))
continue;
Triple<List<Vec3d>, Entity, BlockPos> p = ProjectileSimulator.simulate(e);
if (p.getLeft().size() >= 2)
poses.add(p);
}
}
}
if (getSetting(5).asToggle().getState()) {
for (PlayerEntity e : mc.world.getPlayers()) {
if (e == mc.player)
continue;
Entity proj = ProjectileSimulator.summonProjectile(e, getSetting(1).asToggle().getState(), getSetting(2).asToggle().getState(), getSetting(3).asToggle().getState());
if (proj != null) {
poses.add(ProjectileSimulator.simulate(proj));
}
}
}
}
use of net.minecraft.entity.projectile.thrown.SnowballEntity in project LittleMaidReBirth-Fabric by SistrScarlet.
the class LittleMaidEntity method damage.
@Override
public boolean damage(DamageSource source, float amount) {
if (!world.isClient) {
// 味方のが当たってもちゃんと動くようにフレンド判定より前
if (amount <= 0 && source.getSource() instanceof SnowballEntity) {
play(LMSounds.HURT_SNOW);
return false;
}
}
Entity attacker = source.getAttacker();
// Friendからの攻撃を除外
if (attacker instanceof LivingEntity && isFriend((LivingEntity) attacker)) {
return false;
}
boolean isHurtTime = 0 < this.hurtTime;
boolean result = super.damage(source, amount);
if (!world.isClient && !isHurtTime) {
if (!result || amount <= 0F) {
play(LMSounds.HURT_NO_DAMAGE);
} else if (amount > 0F && ((LivingAccessor) this).blockedByShield_LM(source)) {
play(LMSounds.HURT_GUARD);
} else if (source == DamageSource.FALL) {
play(LMSounds.HURT_FALL);
} else if (source.isFire()) {
play(LMSounds.HURT_FIRE);
} else {
play(LMSounds.HURT);
}
}
return result;
}
Aggregations