netsky blade gadget
This commit is contained in:
@@ -3,10 +3,7 @@ package fun.ogre.ogredupealias.events;
|
||||
import fun.ogre.ogredupealias.data.PlacedStructures;
|
||||
import fun.ogre.ogredupealias.plugin.InventoryPresets;
|
||||
import fun.ogre.ogredupealias.plugin.ItemPresets;
|
||||
import fun.ogre.ogredupealias.utils.Cooldown;
|
||||
import fun.ogre.ogredupealias.utils.ItemUtils;
|
||||
import fun.ogre.ogredupealias.utils.RaycastUtils;
|
||||
import fun.ogre.ogredupealias.utils.SoundPlayer;
|
||||
import fun.ogre.ogredupealias.utils.*;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.Sound;
|
||||
@@ -56,7 +53,7 @@ public class InteractionListener implements Listener {
|
||||
Action a = e.getAction();
|
||||
|
||||
if (ItemUtils.matchDisplay(stack, ItemPresets.NETSKY_BLADE) && !netskySwordCooldown.isOnCooldown(p.getUniqueId())) {
|
||||
netskySwordCooldown.setCooldown(p.getUniqueId(), 1000);
|
||||
netskySwordCooldown.setCooldown(p.getUniqueId(), 333);
|
||||
switch (a) {
|
||||
case LEFT_CLICK_BLOCK, LEFT_CLICK_AIR -> {
|
||||
Location start = p.getEyeLocation();
|
||||
@@ -65,15 +62,20 @@ public class InteractionListener implements Listener {
|
||||
|
||||
shootSound.playWithin(20);
|
||||
|
||||
RaycastUtils.raycast(start, rotation, 20, 0.5, 1, point -> {
|
||||
RaycastUtils.raycast(start, rotation, 30, 0.5, 1, (point, distance) -> {
|
||||
if (point == null || point.getWorld() == null) return false;
|
||||
|
||||
World w = point.getWorld();
|
||||
SoundPlayer popSound = new SoundPlayer(start, Sound.BLOCK_LAVA_POP, 1, 1);
|
||||
SoundPlayer hissSound = new SoundPlayer(start, Sound.BLOCK_LAVA_EXTINGUISH, 1, 1);
|
||||
double radius = 1;
|
||||
double x = radius * Math.sin(distance);
|
||||
double y = radius * Math.sin(point.getY());
|
||||
double z = radius * Math.cos(distance);
|
||||
|
||||
w.spawnParticle(Particle.SOUL_FIRE_FLAME, point.clone().add(x, y, z), 10, 0, 0, 0, 0);
|
||||
w.spawnParticle(Particle.FLAME, point, 1, 0, 0, 0, 0);
|
||||
w.spawnParticle(Particle.LAVA, point, 1, 0, 0, 0, 0);
|
||||
w.spawnParticle(Particle.LAVA, point, 5, 0, 0, 0, 0);
|
||||
popSound.playWithin(3);
|
||||
|
||||
List<Entity> targets = new ArrayList<>(w.getNearbyEntities(point, 2, 2, 2, entity -> {
|
||||
@@ -88,15 +90,19 @@ public class InteractionListener implements Listener {
|
||||
}
|
||||
});
|
||||
|
||||
return !targets.isEmpty();
|
||||
return !targets.isEmpty() || !point.getBlock().isPassable();
|
||||
}, result -> {
|
||||
if (result == null || result.getWorld() == null) return;
|
||||
|
||||
World w = result.getWorld();
|
||||
SoundPlayer explodeSound = new SoundPlayer(result, Sound.ENTITY_GENERIC_EXPLODE, 1, 1.5F);
|
||||
SoundPlayer explodeSound = new SoundPlayer(result, Sound.ENTITY_GENERIC_EXPLODE, 3, 1.5F);
|
||||
|
||||
explodeSound.playWithin(500);
|
||||
w.spawnParticle(Particle.CAMPFIRE_COSY_SMOKE, result, 20, 0, 0, 0, 0.1);
|
||||
explodeSound.playWithin(128);
|
||||
w.spawnParticle(Particle.LAVA, result, 120, 0, 0, 0, 1);
|
||||
DisplayUtils.wave(result, 3, 1, 3, point -> {
|
||||
point.getWorld().spawnParticle(Particle.SOUL_FIRE_FLAME, point, 1, 0, 0, 0, 0);
|
||||
});
|
||||
});
|
||||
}
|
||||
case RIGHT_CLICK_AIR, RIGHT_CLICK_BLOCK -> {
|
||||
|
||||
30
src/main/java/fun/ogre/ogredupealias/utils/DisplayUtils.java
Normal file
30
src/main/java/fun/ogre/ogredupealias/utils/DisplayUtils.java
Normal file
@@ -0,0 +1,30 @@
|
||||
package fun.ogre.ogredupealias.utils;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static fun.ogre.ogredupealias.OgreDupeAlias.instance;
|
||||
|
||||
public final class DisplayUtils {
|
||||
|
||||
public static void ring(Location center, double radius, Consumer<Location> onPoint) {
|
||||
for (int i = 0; i <= 360; i ++) {
|
||||
Location point = center.clone().add(radius * Math.sin(i), 0, radius * Math.cos(i));
|
||||
onPoint.accept(point);
|
||||
}
|
||||
}
|
||||
|
||||
public static void wave(Location center, double radius, double frequency, long interval, Consumer<Location> onPoint) {
|
||||
AtomicReference<Double> currentRadius = new AtomicReference<>(0.0);
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(instance, () -> {
|
||||
if (currentRadius.get() <= radius) {
|
||||
ring(center, currentRadius.get(), onPoint);
|
||||
currentRadius.set(currentRadius.get() + frequency);
|
||||
}
|
||||
}, 0, interval);
|
||||
}
|
||||
}
|
||||
@@ -5,12 +5,13 @@ import org.bukkit.Location;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.BiPredicate;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import static fun.ogre.ogredupealias.OgreDupeAlias.instance;
|
||||
|
||||
public class RaycastUtils {
|
||||
public final class RaycastUtils {
|
||||
|
||||
public static Location raycast(Location start, Location end, Predicate<Location> hitCondition) {
|
||||
return raycast(start, end, 0.5, hitCondition);
|
||||
@@ -34,7 +35,7 @@ public class RaycastUtils {
|
||||
return start.clone().add(rotation.clone().multiply(distance));
|
||||
}
|
||||
|
||||
public static void raycast(Location start, Vector rotation, double distance, double frequency, long tickInterval, Predicate<Location> hitCondition, Consumer<Location> onhit) {
|
||||
public static void raycast(Location start, Vector rotation, double distance, double frequency, long tickInterval, BiPredicate<Location, Double> hitCondition, Consumer<Location> onhit) {
|
||||
AtomicReference<Location> result = new AtomicReference<>();
|
||||
AtomicReference<Double> val = new AtomicReference<>(0.0);
|
||||
AtomicReference<Boolean> active = new AtomicReference<>(true);
|
||||
@@ -42,7 +43,7 @@ public class RaycastUtils {
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(instance, () -> {
|
||||
if (val.get() <= distance && result.get() == null && active.get()) {
|
||||
Location point = start.clone().add(rotation.clone().multiply(val.get()));
|
||||
if (hitCondition.test(point)) {
|
||||
if (hitCondition.test(point, val.get())) {
|
||||
result.set(point);
|
||||
}
|
||||
val.set(val.get() + frequency);
|
||||
|
||||
Reference in New Issue
Block a user