forked from SteamWar/SteamWar
Update WorldEditRenderer
This commit is contained in:
@@ -1,125 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2020 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.core;
|
||||
|
||||
import com.sk89q.worldedit.EmptyClipboardException;
|
||||
import com.sk89q.worldedit.IncompleteRegionException;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import com.sk89q.worldedit.math.transform.Transform;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.regions.RegionSelector;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public class WorldEditRenderer9 implements WorldEditRenderer {
|
||||
|
||||
private static final int VIEW_DISTANCE = 64;
|
||||
private static final int SQ_VIEW_DISTANCE = VIEW_DISTANCE * VIEW_DISTANCE;
|
||||
|
||||
private static final double STEP_SIZE = 0.5;
|
||||
|
||||
private static final Vector ONES = new Vector(1, 1, 1);
|
||||
|
||||
private static final Material WAND = FlatteningWrapper.impl.getMaterial("WOOD_AXE");
|
||||
|
||||
private final WorldEditPlugin we;
|
||||
|
||||
public WorldEditRenderer9() {
|
||||
we = WorldEditWrapper.getWorldEditPlugin();
|
||||
|
||||
Bukkit.getScheduler().runTaskTimer(Core.getInstance(), this::render, 20, 20);
|
||||
}
|
||||
|
||||
private void render() {
|
||||
for(Player player : Bukkit.getOnlinePlayers()) {
|
||||
if(player.getInventory().getItemInMainHand().getType() != WAND)
|
||||
continue;
|
||||
|
||||
LocalSession session = we.getSession(player);
|
||||
try {
|
||||
Clipboard clipboard = session.getClipboard().getClipboard();
|
||||
Vector pos = player.getLocation().toVector();
|
||||
Region region = clipboard.getRegion();
|
||||
Transform transform = session.getClipboard().getTransform();
|
||||
Vector a = WorldEditWrapper.impl.applyTransform(WorldEditWrapper.impl.getMinimum(region).subtract(WorldEditWrapper.impl.getOrigin(clipboard)), transform).add(pos);
|
||||
Vector b = WorldEditWrapper.impl.applyTransform(WorldEditWrapper.impl.getMaximum(region).subtract(WorldEditWrapper.impl.getOrigin(clipboard)), transform).add(pos);
|
||||
drawCuboid(Vector.getMinimum(a, b), Vector.getMaximum(a, b), TrickyParticleWrapper.impl.getVillagerHappy(), player);
|
||||
} catch (EmptyClipboardException e) {
|
||||
//ignore
|
||||
}
|
||||
|
||||
World world = session.getSelectionWorld();
|
||||
if(world != null) {
|
||||
RegionSelector regionSelector = session.getRegionSelector(world);
|
||||
try {
|
||||
Region region = regionSelector.getRegion();
|
||||
drawCuboid(WorldEditWrapper.impl.getMinimum(region), WorldEditWrapper.impl.getMaximum(region), Particle.DRAGON_BREATH, player);
|
||||
} catch (IncompleteRegionException e) {
|
||||
//ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void drawCuboid(Vector min, Vector max, Particle particle, Player owner) {
|
||||
max.add(ONES);
|
||||
|
||||
for(double x = min.getBlockX(); x <= max.getBlockX(); x += STEP_SIZE) {
|
||||
draw(x, min.getBlockY(), min.getBlockZ(), particle, owner);
|
||||
draw(x, min.getBlockY(), max.getBlockZ(), particle, owner);
|
||||
draw(x, max.getBlockY(), min.getBlockZ(), particle, owner);
|
||||
draw(x, max.getBlockY(), max.getBlockZ(), particle, owner);
|
||||
}
|
||||
|
||||
for(double y = min.getBlockY() + STEP_SIZE; y <= max.getBlockY() - STEP_SIZE; y += STEP_SIZE) {
|
||||
draw(min.getBlockX(), y, min.getBlockZ(), particle, owner);
|
||||
draw(min.getBlockX(), y, max.getBlockZ(), particle, owner);
|
||||
draw(max.getBlockX(), y, min.getBlockZ(), particle, owner);
|
||||
draw(max.getBlockX(), y, max.getBlockZ(), particle, owner);
|
||||
}
|
||||
|
||||
for(double z = min.getBlockZ() + STEP_SIZE; z <= max.getBlockZ() - STEP_SIZE; z += STEP_SIZE) {
|
||||
draw(min.getBlockX(), min.getBlockY(), z, particle, owner);
|
||||
draw(min.getBlockX(), max.getBlockY(), z, particle, owner);
|
||||
draw(max.getBlockX(), min.getBlockY(), z, particle, owner);
|
||||
draw(max.getBlockX(), max.getBlockY(), z, particle, owner);
|
||||
}
|
||||
}
|
||||
|
||||
private void draw(double x, double y, double z, Particle particle, Player owner) {
|
||||
for(Player player : Bukkit.getOnlinePlayers()) {
|
||||
Location location = player.getLocation();
|
||||
double dx = x - location.getX();
|
||||
double dy = y - location.getY();
|
||||
double dz = z - location.getZ();
|
||||
if(dx*dx + dy*dy + dz*dz > SQ_VIEW_DISTANCE)
|
||||
continue;
|
||||
|
||||
player.spawnParticle(player == owner ? particle : org.bukkit.Particle.TOWN_AURA, x, y, z, 1, 0.0, 0.0, 0.0, 0.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2020 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.core;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public class WorldEditRendererWrapper9 implements WorldEditRendererWrapper {
|
||||
|
||||
private static final int VIEW_DISTANCE = 64;
|
||||
private static final int SQ_VIEW_DISTANCE = VIEW_DISTANCE * VIEW_DISTANCE;
|
||||
|
||||
private static final double STEP_SIZE = 0.5;
|
||||
private static final Vector ONES = new Vector(1, 1, 1);
|
||||
private static final Vector STEPS = new Vector(STEP_SIZE, STEP_SIZE, STEP_SIZE);
|
||||
|
||||
@Override
|
||||
public void draw(Player player, Player owner, boolean clipboard, Vector min, Vector max) {
|
||||
max = max.clone().add(ONES);
|
||||
drawLine(player, owner, clipboard, new Vector(min.getX(), min.getY(), min.getZ()), new Vector(max.getX(), min.getY(), min.getZ()));
|
||||
drawLine(player, owner, clipboard, new Vector(min.getX(), max.getY(), min.getZ()), new Vector(max.getX(), max.getY(), min.getZ()));
|
||||
drawLine(player, owner, clipboard, new Vector(min.getX(), min.getY(), max.getZ()), new Vector(max.getX(), min.getY(), max.getZ()));
|
||||
drawLine(player, owner, clipboard, new Vector(min.getX(), max.getY(), max.getZ()), new Vector(max.getX(), max.getY(), max.getZ()));
|
||||
|
||||
drawLine(player, owner, clipboard, new Vector(min.getX(), min.getY(), min.getZ()), new Vector(min.getX(), max.getY(), min.getZ()));
|
||||
drawLine(player, owner, clipboard, new Vector(max.getX(), min.getY(), min.getZ()), new Vector(max.getX(), max.getY(), min.getZ()));
|
||||
drawLine(player, owner, clipboard, new Vector(min.getX(), min.getY(), max.getZ()), new Vector(min.getX(), max.getY(), max.getZ()));
|
||||
drawLine(player, owner, clipboard, new Vector(max.getX(), min.getY(), max.getZ()), new Vector(max.getX(), max.getY(), max.getZ()));
|
||||
|
||||
drawLine(player, owner, clipboard, new Vector(min.getX(), min.getY(), min.getZ()), new Vector(min.getX(), min.getY(), max.getZ()));
|
||||
drawLine(player, owner, clipboard, new Vector(max.getX(), min.getY(), min.getZ()), new Vector(max.getX(), min.getY(), max.getZ()));
|
||||
drawLine(player, owner, clipboard, new Vector(min.getX(), max.getY(), min.getZ()), new Vector(min.getX(), max.getY(), max.getZ()));
|
||||
drawLine(player, owner, clipboard, new Vector(max.getX(), max.getY(), min.getZ()), new Vector(max.getX(), max.getY(), max.getZ()));
|
||||
}
|
||||
|
||||
public void drawLine(Player player, Player owner, boolean clipboard, Vector min, Vector max) {
|
||||
Particle particle;
|
||||
if (player == owner) {
|
||||
if (clipboard) {
|
||||
particle = TrickyParticleWrapper.impl.getVillagerHappy();
|
||||
} else {
|
||||
particle = Particle.DRAGON_BREATH;
|
||||
}
|
||||
} else {
|
||||
particle = Particle.TOWN_AURA;
|
||||
}
|
||||
|
||||
Vector stepSize = max.clone().subtract(min).normalize().multiply(STEPS);
|
||||
while (min.getX() <= max.getX() && min.getY() <= max.getY() && min.getZ() <= max.getZ()) {
|
||||
Location location = player.getLocation();
|
||||
double dx = min.getX() - location.getX();
|
||||
double dy = min.getY() - location.getY();
|
||||
double dz = min.getZ() - location.getZ();
|
||||
if (dx * dx + dy * dy + dz * dz > SQ_VIEW_DISTANCE)
|
||||
continue;
|
||||
|
||||
player.spawnParticle(particle, min.getX(), min.getY(), min.getZ(), 1, 0.0, 0.0, 0.0, 0.0);
|
||||
min.add(stepSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user