mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-19 19:25:48 +00:00
[CI skip] Slight refactoring
This commit is contained in:
parent
acd8278889
commit
4f2bb90f15
@ -37,6 +37,7 @@
|
|||||||
* (1.16+) Added Nether Gold Ore recipe to the Ore Crusher
|
* (1.16+) Added Nether Gold Ore recipe to the Ore Crusher
|
||||||
* (1.16+) Added Shroomlights to the fuel list for the Bio Generator
|
* (1.16+) Added Shroomlights to the fuel list for the Bio Generator
|
||||||
* (1.16+) Added Warped and Crimson Fungus to the fuel list for the Bio Generator
|
* (1.16+) Added Warped and Crimson Fungus to the fuel list for the Bio Generator
|
||||||
|
* Added an AoE damage effect to the Explosive Bow
|
||||||
|
|
||||||
#### Changes
|
#### Changes
|
||||||
* Coolant Cells now last twice as long
|
* Coolant Cells now last twice as long
|
||||||
|
@ -17,17 +17,31 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
|||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The {@link ExplosiveBow} is a {@link SlimefunBow} which creates a fake explosion when it hits
|
||||||
|
* a {@link LivingEntity}. Any nearby {@link LivingEntity LivingEntities} get pushed away and
|
||||||
|
* take a little bit of damage, similar to an "Area of Effect" damage.
|
||||||
|
*
|
||||||
|
* @author TheBusyBiscuit
|
||||||
|
* @author Linox
|
||||||
|
*
|
||||||
|
* @see SlimefunBow
|
||||||
|
*
|
||||||
|
*/
|
||||||
public class ExplosiveBow extends SlimefunBow {
|
public class ExplosiveBow extends SlimefunBow {
|
||||||
|
|
||||||
private final ItemSetting<Integer> range = new ItemSetting<Integer>("explosion-range", 3) {
|
private final ItemSetting<Integer> range = new ItemSetting<Integer>("explosion-range", 3) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean validateInput(Integer input) {
|
public boolean validateInput(Integer input) {
|
||||||
return input != null && input > 0;
|
return super.validateInput(input) && input > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
public ExplosiveBow(Category category, SlimefunItemStack item, ItemStack[] recipe) {
|
public ExplosiveBow(Category category, SlimefunItemStack item, ItemStack[] recipe) {
|
||||||
super(category, item, recipe);
|
super(category, item, recipe);
|
||||||
|
|
||||||
addItemSetting(range);
|
addItemSetting(range);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,27 +49,29 @@ public class ExplosiveBow extends SlimefunBow {
|
|||||||
public BowShootHandler onShoot() {
|
public BowShootHandler onShoot() {
|
||||||
return (e, target) -> {
|
return (e, target) -> {
|
||||||
target.getWorld().spawnParticle(Particle.EXPLOSION_LARGE, target.getLocation(), 1);
|
target.getWorld().spawnParticle(Particle.EXPLOSION_LARGE, target.getLocation(), 1);
|
||||||
target.getWorld().playSound(target.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 1F, 1F);
|
target.getWorld().playSound(target.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 1, 1);
|
||||||
|
|
||||||
Collection<Entity> entites = target.getWorld().getNearbyEntities(target.getLocation(), range.getValue(), range.getValue(), range.getValue(), entity -> entity instanceof LivingEntity && entity.isValid());
|
Collection<Entity> entites = target.getWorld().getNearbyEntities(target.getLocation(), range.getValue(), range.getValue(), range.getValue(), entity -> entity instanceof LivingEntity && entity.isValid());
|
||||||
for (Entity entity : entites) {
|
for (Entity nearby : entites) {
|
||||||
LivingEntity entityL = (LivingEntity) entity;
|
LivingEntity entity = (LivingEntity) nearby;
|
||||||
|
|
||||||
Vector distanceVector = entityL.getLocation().toVector().subtract(target.getLocation().toVector());
|
Vector distanceVector = entity.getLocation().toVector().subtract(target.getLocation().toVector());
|
||||||
distanceVector.setY(distanceVector.getY() + 0.6D);
|
distanceVector.setY(distanceVector.getY() + 0.6);
|
||||||
Vector entityVelocity = entityL.getVelocity();
|
|
||||||
|
Vector velocity = entity.getVelocity();
|
||||||
|
|
||||||
double distanceSquared = distanceVector.lengthSquared();
|
double distanceSquared = distanceVector.lengthSquared();
|
||||||
double damage = calculateDamage(distanceSquared, e.getDamage());
|
double damage = calculateDamage(distanceSquared, e.getDamage());
|
||||||
|
|
||||||
Vector knockback = entityVelocity.add(distanceVector.normalize().multiply((int) (e.getDamage() / damage)));
|
Vector knockback = velocity.add(distanceVector.normalize().multiply((int) (e.getDamage() / damage)));
|
||||||
entityL.setVelocity(knockback);
|
entity.setVelocity(knockback);
|
||||||
|
|
||||||
if (!entityL.getUniqueId().equals(target.getUniqueId())) {
|
if (!entity.getUniqueId().equals(target.getUniqueId())) {
|
||||||
EntityDamageByEntityEvent damageEvent = new EntityDamageByEntityEvent(e.getDamager(), entityL, EntityDamageEvent.DamageCause.ENTITY_EXPLOSION, damage);
|
EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(e.getDamager(), entity, EntityDamageEvent.DamageCause.ENTITY_EXPLOSION, damage);
|
||||||
Bukkit.getPluginManager().callEvent(damageEvent);
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
if (!damageEvent.isCancelled()) {
|
|
||||||
entityL.damage(damageEvent.getDamage());
|
if (!event.isCancelled()) {
|
||||||
|
entity.damage(event.getDamage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -63,7 +79,10 @@ public class ExplosiveBow extends SlimefunBow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private double calculateDamage(double distanceSquared, double originalDamage) {
|
private double calculateDamage(double distanceSquared, double originalDamage) {
|
||||||
if (distanceSquared <= 0.05D) return originalDamage;
|
if (distanceSquared <= 0.05) {
|
||||||
|
return originalDamage;
|
||||||
|
}
|
||||||
|
|
||||||
double damage = originalDamage * (1 - (distanceSquared / (range.getValue() * range.getValue())));
|
double damage = originalDamage * (1 - (distanceSquared / (range.getValue() * range.getValue())));
|
||||||
return Math.min(Math.max(1, damage), originalDamage);
|
return Math.min(Math.max(1, damage), originalDamage);
|
||||||
}
|
}
|
||||||
|
@ -180,6 +180,7 @@ public final class PostSetup {
|
|||||||
if (input[0] != null && recipe[0] != null) {
|
if (input[0] != null && recipe[0] != null) {
|
||||||
grinderRecipes.add(new ItemStack[] { input[0], recipe[0] });
|
grinderRecipes.add(new ItemStack[] { input[0], recipe[0] });
|
||||||
}
|
}
|
||||||
|
|
||||||
input = null;
|
input = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user