Improve PistonCalculator last time

This commit is contained in:
2025-07-29 12:32:25 +02:00
parent 1355b57a93
commit 7edd72ac27
2 changed files with 138 additions and 12 deletions
@@ -21,10 +21,7 @@ package de.steamwar.bausystem.features.util;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission;
import de.steamwar.entity.CWireframe;
import de.steamwar.entity.REntity;
import de.steamwar.entity.REntityServer;
import de.steamwar.entity.RTextDisplay;
import de.steamwar.entity.*;
import de.steamwar.linkage.Linked;
import de.steamwar.linkage.MinVersion;
import org.bukkit.Bukkit;
@@ -46,6 +43,7 @@ import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import java.util.*;
import java.util.stream.Collectors;
@Linked
@MinVersion(20)
@@ -255,14 +253,15 @@ public class PistonCalculator implements Listener {
Location location = movedBlocks.get(i);
int order = i + 1;
RTextDisplay textDisplay = new RTextDisplay(server, location.clone().add(0.5, 0.4, 0.5));
textDisplay.setText("§e" + order);
textDisplay.setBillboard(Display.Billboard.CENTER);
textDisplay.setAlignment(TextDisplay.TextAlignment.CENTER);
textDisplay.setSeeThrough(true);
textDisplay.setBackgroundColor(0);
textDisplay.setShadowed(false);
textDisplay.setBrightness(new Display.Brightness(15, 15));
CCubedTextDisplay display = new CCubedTextDisplay(server, location);
display.setText("§e" + order);
display.setBackgroundColor(0);
display.setShadowed(false);
Set<BlockFace> toHide = Arrays.stream(FACES).filter(blockFace -> {
return movedBlocks.contains(location.clone().add(blockFace.getModX(), blockFace.getModY(), blockFace.getModZ()));
}).collect(Collectors.toSet());
display.hide(toHide);
}
for (int i = 0; i < brokenBlocks.size(); i++) {
@@ -0,0 +1,127 @@
/*
* 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.entity;
import org.bukkit.Location;
import org.bukkit.block.BlockFace;
import org.bukkit.util.Transformation;
import org.joml.Quaternionf;
import org.joml.Vector3f;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
public class CCubedTextDisplay extends CEntity {
private Map<BlockFace, RTextDisplay> displays = new HashMap<>();
public CCubedTextDisplay(REntityServer server, Location loc) {
super(server);
{
Location location = loc.clone().add(0.5, 0.4, 1.01);
RTextDisplay display = new RTextDisplay(server, location);
entities.add(display);
displays.put(BlockFace.SOUTH, display);
}
{
Location location = loc.clone().add(0.5, 0.4, -0.01);
RTextDisplay display = new RTextDisplay(server, location);
display.setTransform(new Transformation(new Vector3f(0, 0, 0), new Quaternionf().rotateY((float) Math.toRadians(180)), new Vector3f(1, 1, 1), new Quaternionf()));
entities.add(display);
displays.put(BlockFace.NORTH, display);
}
{
Location location = loc.clone().add(1.01, 0.4, 0.5);
RTextDisplay display = new RTextDisplay(server, location);
display.setTransform(new Transformation(new Vector3f(0, 0, 0), new Quaternionf().rotateY((float) Math.toRadians(90)), new Vector3f(1, 1, 1), new Quaternionf()));
entities.add(display);
displays.put(BlockFace.EAST, display);
}
{
Location location = loc.clone().add(-0.01, 0.4, 0.5);
RTextDisplay display = new RTextDisplay(server, location);
display.setTransform(new Transformation(new Vector3f(0, 0, 0), new Quaternionf().rotateY((float) Math.toRadians(270)), new Vector3f(1, 1, 1), new Quaternionf()));
entities.add(display);
displays.put(BlockFace.WEST, display);
}
{
Location location = loc.clone().add(0.5, 1.01, 0.6);
RTextDisplay display = new RTextDisplay(server, location);
display.setTransform(new Transformation(new Vector3f(0, 0, 0), new Quaternionf().rotationX((float) Math.toRadians(270)), new Vector3f(1, 1, 1), new Quaternionf()));
entities.add(display);
displays.put(BlockFace.UP, display);
}
{
Location location = loc.clone().add(0.5, -0.01, 0.4);
RTextDisplay display = new RTextDisplay(server, location);
display.setTransform(new Transformation(new Vector3f(0, 0, 0), new Quaternionf().rotationX((float) Math.toRadians(90)), new Vector3f(1, 1, 1), new Quaternionf()));
entities.add(display);
displays.put(BlockFace.DOWN, display);
}
}
public void hide(Set<BlockFace> blockFaceSet) {
for (BlockFace blockFace : BlockFace.values()) {
RTextDisplay display = displays.get(blockFace);
if (display == null) continue;
display.hide(blockFaceSet.contains(blockFace));
}
if (displays.values().stream().allMatch(RTextDisplay::isHidden)) {
displays.values().forEach(rTextDisplay -> rTextDisplay.hide(false));
}
}
@Override
public void move(Location location) {
}
@Override
public void move(double locX, double locY, double locZ, float pitch, float yaw, byte headYaw) {
}
public void setText(String text) {
displays.values().forEach(rTextDisplay -> rTextDisplay.setText(text));
}
public void setLineWidth(int lineWidth) {
displays.values().forEach(rTextDisplay -> rTextDisplay.setLineWidth(lineWidth));
}
public void setTextOpacity(byte textOpacity) {
displays.values().forEach(rTextDisplay -> rTextDisplay.setTextOpacity(textOpacity));
}
public void setShadowed(boolean shadowed) {
displays.values().forEach(rTextDisplay -> rTextDisplay.setShadowed(shadowed));
}
public void setSeeThrough(boolean seeThrough) {
displays.values().forEach(rTextDisplay -> rTextDisplay.setSeeThrough(seeThrough));
}
public void setBackgroundColor(int color) {
displays.values().forEach(rTextDisplay -> rTextDisplay.setBackgroundColor(color));
}
public void setDefaultBackground(boolean defaultBackground) {
displays.values().forEach(rTextDisplay -> rTextDisplay.setDefaultBackground(defaultBackground));
}
}