forked from SteamWar/SteamWar
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.
75 lines
3.0 KiB
Java
75 lines
3.0 KiB
Java
/*
|
|
* 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))));
|
|
}
|
|
}
|
|
}
|
|
}
|