Add online_mode and velocity_secret config options
Some checks failed
Build JStom / build (push) Failing after 53s
Some checks failed
Build JStom / build (push) Failing after 53s
This commit is contained in:
52
scripts/elytra_boost.js
Normal file
52
scripts/elytra_boost.js
Normal file
@@ -0,0 +1,52 @@
|
||||
const Material = Java.type('net.minestom.server.item.Material');
|
||||
const Sound = Java.type('net.kyori.adventure.sound.Sound');
|
||||
const SoundEvent = Java.type('net.minestom.server.sound.SoundEvent');
|
||||
const Entity = Java.type('net.minestom.server.entity.Entity');
|
||||
const EntityType = Java.type('net.minestom.server.entity.EntityType');
|
||||
const Duration = Java.type('java.time.Duration');
|
||||
|
||||
server.log("Vanilla Elytra Boost loaded.");
|
||||
|
||||
server.on('net.minestom.server.event.player.PlayerUseItemEvent', (event) => {
|
||||
const player = event.getPlayer();
|
||||
const item = event.getItemStack();
|
||||
|
||||
// 1. Validate Condition
|
||||
if (item.material().name() !== "minecraft:firework_rocket") return;
|
||||
if (!player.isFlyingWithElytra()) return;
|
||||
|
||||
// 2. Consume Item (if not creative)
|
||||
if (player.getGameMode().name() !== "CREATIVE") {
|
||||
player.setItemInHand(event.getHand(), item.withAmount(item.amount() - 1));
|
||||
}
|
||||
|
||||
// 3. Spawn Firework Rocket
|
||||
// The entity itself handles the boosting physics in Minestom/Client
|
||||
const rocket = new Entity(EntityType.fromKey("minecraft:firework_rocket"));
|
||||
const meta = rocket.getEntityMeta();
|
||||
|
||||
meta.setFireworkInfo(item);
|
||||
meta.setShooter(player);
|
||||
|
||||
// Spawn at player position
|
||||
rocket.setInstance(player.getInstance(), player.getPosition());
|
||||
|
||||
// Set rocket velocity to fly in look direction
|
||||
const direction = player.getPosition().direction();
|
||||
rocket.setVelocity(direction.mul(1.5)); // Adjust rocket speed if needed
|
||||
|
||||
// Cleanup: Remove rocket after lifetime (e.g., 1.5s for duration 3)
|
||||
// Vanilla duration calculation is roughly (FlightDuration + 1) * 10 + random ticks
|
||||
// 1.5s is a safe average for Duration 3
|
||||
rocket.scheduleRemove(Duration.ofMillis(1500));
|
||||
|
||||
// 4. Play Sound
|
||||
const launchSound = Sound.sound(
|
||||
SoundEvent.fromKey("minecraft:entity.firework_rocket.launch"),
|
||||
Sound.Source.PLAYER,
|
||||
3.0,
|
||||
1.0
|
||||
);
|
||||
player.getViewers().forEach(v => v.playSound(launchSound, player.getPosition()));
|
||||
player.playSound(launchSound);
|
||||
});
|
||||
Reference in New Issue
Block a user