Give the rebuildable reward designs unique touches

Rewards whose look the basic designs can build now carry a touch the builder
cannot make: bursts on jumping, landing or sneaking, footprints, a line to
nearby players with the same reward, a December extra, aimed enchanting
glyphs, a heartbeat, a jump-beat wing or an orbiting shape. BodyMotion tracks
the jump, land and sneak events the touches react to.
This commit is contained in:
2026-10-26 14:34:50 +01:00
parent ad9087c038
commit 7d0f5aceae
15 changed files with 521 additions and 22 deletions
@@ -0,0 +1,63 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2026 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.lobby.particle.elements.touch;
import de.steamwar.lobby.particle.BodyMotion;
import de.steamwar.lobby.particle.ParticleElement;
import de.steamwar.lobby.particle.ParticleTickData;
import de.steamwar.lobby.particle.elements.DelegatingParticleElement;
import org.bukkit.entity.Player;
// Shows the burst once at the player's feet in the tick the event happens
public class EventBurst extends DelegatingParticleElement {
public enum Trigger {
JUMP,
LAND,
SNEAK,
}
private final Trigger trigger;
// Landings from lower than this many blocks are ignored
private final double minimumFall;
public EventBurst(Trigger trigger, ParticleElement burst) {
this(trigger, 0, burst);
}
public EventBurst(Trigger trigger, double minimumFall, ParticleElement burst) {
super(burst);
this.trigger = trigger;
this.minimumFall = minimumFall;
}
@Override
public void tick(ParticleTickData particleTickData) {
Player player = particleTickData.getPlayer();
boolean happened = switch (trigger) {
case JUMP -> BodyMotion.jumped(player);
case LAND -> BodyMotion.landed(player) >= minimumFall;
case SNEAK -> BodyMotion.startedSneaking(player);
};
if (happened) {
particleElement.tick(particleTickData.withLocation(player.getLocation()));
}
}
}
@@ -0,0 +1,69 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2026 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.lobby.particle.elements.touch;
import de.steamwar.lobby.particle.ParticleElement;
import de.steamwar.lobby.particle.ParticleTickData;
import de.steamwar.lobby.particle.elements.DelegatingParticleElement;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Map;
import java.util.WeakHashMap;
// Leaves a print every half step on the ground and keeps showing it for a while after the player walked on
public class Footprints extends DelegatingParticleElement {
private static final double STEP = 0.6;
private record Print(Location location, int age) {
}
private final int lifetime;
// Weak keys drop players once they quit
private final Map<Player, Deque<Print>> prints = new WeakHashMap<>();
public Footprints(ParticleElement particleElement, int lifetime) {
super(particleElement);
this.lifetime = lifetime;
}
@Override
@SuppressWarnings("deprecation")
public void tick(ParticleTickData particleTickData) {
Player player = particleTickData.getPlayer();
Deque<Print> playerPrints = prints.computeIfAbsent(player, key -> new ArrayDeque<>());
Location feet = player.getLocation();
Print last = playerPrints.peekLast();
if (player.isOnGround() && (last == null || last.location().getWorld() != feet.getWorld() || last.location().distanceSquared(feet) > STEP * STEP)) {
playerPrints.addLast(new Print(feet, 0));
}
int size = playerPrints.size();
for (int i = 0; i < size; i++) {
Print print = playerPrints.pollFirst();
if (print.age() >= lifetime) continue;
particleElement.tick(particleTickData.withLocation(print.location().clone()));
playerPrints.addLast(new Print(print.location(), print.age() + 1));
}
}
}
@@ -0,0 +1,72 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2026 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.lobby.particle.elements.touch;
import de.steamwar.lobby.particle.ParticleElement;
import de.steamwar.lobby.particle.ParticleTickData;
import org.bukkit.Location;
import org.bukkit.Particle;
import org.bukkit.util.Vector;
// Enchanting glyphs that fly along a path. Spawned with an amount of 0, the offset becomes the glyph's motion: it
// appears at location + offset and flies back to the location, like glyphs flying into an enchanting table.
public class Glyphs implements ParticleElement {
public enum Path {
// From random points on the ground around the player into the chest
INTO_PLAYER,
// From the chest outwards to a ring around the player
OUT_OF_PLAYER,
}
private static final double CHEST = 1.2;
private final Path path;
private final int amount;
private final double radius;
public Glyphs(Path path, int amount, double radius) {
this.path = path;
this.amount = amount;
this.radius = radius;
}
@Override
public void tick(ParticleTickData particleTickData) {
Location chest = particleTickData.getPlayer().getLocation().add(0, CHEST, 0);
for (int i = 0; i < amount; i++) {
Location target;
Vector from;
if (path == Path.INTO_PLAYER) {
double angle = RANDOM.nextDouble() * 2 * Math.PI;
double distance = radius * (0.5 + RANDOM.nextDouble() / 2);
target = chest;
from = new Vector(Math.cos(angle) * distance, -CHEST, Math.sin(angle) * distance);
} else {
double angle = 2 * Math.PI * i / amount;
Vector out = new Vector(Math.cos(angle) * radius, 0, Math.sin(angle) * radius);
target = chest.clone().add(out);
from = out.multiply(-1);
}
Location spawn = target;
display(particleTickData, player -> player.spawnParticle(Particle.ENCHANT, spawn, 0, from.getX(), from.getY(), from.getZ(), 1));
}
}
}
@@ -0,0 +1,47 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2026 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.lobby.particle.elements.touch;
import de.steamwar.lobby.particle.ParticleElement;
import de.steamwar.lobby.particle.ParticleTickData;
import de.steamwar.lobby.particle.elements.DelegatingParticleElement;
import org.bukkit.Location;
// A flat ring of points around the location, all at once, for bursts
public class Ring extends DelegatingParticleElement {
private final double radius;
private final int points;
public Ring(ParticleElement particleElement, double radius, int points) {
super(particleElement);
this.radius = radius;
this.points = points;
}
@Override
public void tick(ParticleTickData particleTickData) {
Location center = particleTickData.getLocation();
for (int i = 0; i < points; i++) {
double angle = 2 * Math.PI * i / points;
particleElement.tick(particleTickData.withLocation(center.clone().add(Math.cos(angle) * radius, 0, Math.sin(angle) * radius)));
}
}
}
@@ -0,0 +1,45 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2026 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.lobby.particle.elements.touch;
import de.steamwar.lobby.particle.ParticleElement;
import de.steamwar.lobby.particle.ParticleTickData;
import de.steamwar.lobby.particle.elements.DelegatingParticleElement;
import java.time.LocalDate;
import java.time.Month;
// Only shows during the given month
public class Seasonal extends DelegatingParticleElement {
private final Month month;
public Seasonal(Month month, ParticleElement particleElement) {
super(particleElement);
this.month = month;
}
@Override
public void tick(ParticleTickData particleTickData) {
if (LocalDate.now().getMonth() == month) {
particleElement.tick(particleTickData);
}
}
}
@@ -0,0 +1,74 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2026 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.lobby.particle.elements.touch;
import de.steamwar.lobby.particle.BodyMotion;
import de.steamwar.lobby.particle.ParticleElement;
import de.steamwar.lobby.particle.ParticleTickData;
import de.steamwar.lobby.particle.elements.DelegatingParticleElement;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import java.util.HashMap;
import java.util.Map;
import java.util.WeakHashMap;
// A line of particles between nearby players who show the same reward. Each pair is drawn by only one of them.
public class TeamLink extends DelegatingParticleElement {
private static final double RANGE = 8;
private static final double SPACING = 0.5;
private static final double CHEST = 1.2;
// Per reward, who showed it in which tick
private static final Map<String, Map<Player, Long>> SHOWING = new HashMap<>();
private final String reward;
public TeamLink(String reward, ParticleElement particleElement) {
super(particleElement);
this.reward = reward;
}
@Override
public void tick(ParticleTickData particleTickData) {
Player player = particleTickData.getPlayer();
long now = BodyMotion.currentTick();
Map<Player, Long> showing = SHOWING.computeIfAbsent(reward, key -> new WeakHashMap<>());
showing.put(player, now);
Location from = player.getLocation().add(0, CHEST, 0);
for (Map.Entry<Player, Long> other : showing.entrySet()) {
Player partner = other.getKey();
// Still showing it, and drawn by the player with the smaller id only
if (partner == player || other.getValue() < now - 1 || player.getUniqueId().compareTo(partner.getUniqueId()) > 0) continue;
Location to = partner.getLocation().add(0, CHEST, 0);
if (to.getWorld() != from.getWorld() || to.distanceSquared(from) > RANGE * RANGE) continue;
Vector step = to.toVector().subtract(from.toVector());
int points = (int) Math.ceil(step.length() / SPACING);
step.multiply(1.0 / points);
for (int i = 1; i < points; i++) {
particleElement.tick(particleTickData.withLocation(from.clone().add(step.clone().multiply(i))));
}
}
}
}