Improve WorldEditRendererWrapper20

This commit is contained in:
2025-09-29 11:00:50 +02:00
parent bfe9c7559e
commit f4c9ce512e
3 changed files with 43 additions and 22 deletions
@@ -87,9 +87,7 @@ public class WorldEditRendererWrapper20 implements WorldEditRendererWrapper {
box = new CWireframe(server);
boxPair.set(clipboard, box);
}
box.setPos1(null).setPos2(null);
box.setPos1(pos1.toLocation(player.getWorld()));
box.setPos2(pos2.toLocation(player.getWorld()));
box.setPos1And2(pos1.toLocation(player.getWorld()), pos2.toLocation(player.getWorld()));
box.setWidth(width);
box.setBlock(block);
}
@@ -59,6 +59,14 @@ public class CLine extends CEntity {
return this;
}
public CLine setFromAndTo(Location from, Location to) {
if (Objects.equals(from, this.from) && Objects.equals(to, this.to)) return this;
this.from = from;
this.to = to;
tick();
return this;
}
public CLine setFrom(Location from) {
return checkAndSet(this.from, from, location -> this.from = location);
}
@@ -99,7 +107,16 @@ public class CLine extends CEntity {
@Override
void tick() {
if (from == null || to == null) return;
if (from == null || to == null) {
if (startLine != null) startLine.hide(true);
if (middleLine != null) middleLine.hide(true);
if (endLine != null) endLine.hide(true);
return;
} else {
if (startLine != null) startLine.hide(false);
if (middleLine != null) middleLine.hide(false);
if (endLine != null) endLine.hide(false);
}
if (hide) return;
updateStart();
updateMiddle();
@@ -22,11 +22,9 @@ package de.steamwar.entity;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.data.BlockData;
import org.bukkit.util.Consumer;
import org.bukkit.util.Vector;
import java.util.List;
import java.util.Objects;
/**
* Compound Box (12 CLine)
@@ -46,6 +44,13 @@ public class CWireframe extends CEntity {
}
}
public CWireframe setPos1And2(Location pos1, Location pos2) {
this.pos1 = pos1;
this.pos2 = pos2;
updateAndSpawnLines();
return this;
}
public CWireframe setPos1(Location pos1) {
this.pos1 = pos1;
updateAndSpawnLines();
@@ -75,29 +80,30 @@ public class CWireframe extends CEntity {
}
private void updateAndSpawnLines() {
if (pos1 == null || pos2 == null) return;
List<CLine> lines = getEntitiesByType(CLine.class);
if (pos1 == null || pos2 == null) {
lines.forEach(line -> line.setFrom(null).setTo(null));
return;
}
World world = pos1.getWorld();
Vector min = Vector.getMinimum(pos1.toVector(), pos2.toVector());
Vector max = Vector.getMaximum(pos1.toVector(), pos2.toVector())
.add(new Vector(1 - width, 1 - width, 1 - width));
List<CLine> lines = getEntitiesByType(CLine.class);
lines.forEach(line -> line.setFrom(null).setTo(null));
lines.get(0).setFromAndTo(new Vector(min.getX(), min.getY(), min.getZ()).toLocation(world), new Vector(max.getX() + width, min.getY(), min.getZ()).toLocation(world));
lines.get(1).setFromAndTo(new Vector(min.getX(), max.getY(), min.getZ()).toLocation(world), new Vector(max.getX() + width, max.getY(), min.getZ()).toLocation(world));
lines.get(2).setFromAndTo(new Vector(min.getX(), min.getY(), max.getZ()).toLocation(world), new Vector(max.getX() + width, min.getY(), max.getZ()).toLocation(world));
lines.get(3).setFromAndTo(new Vector(min.getX(), max.getY(), max.getZ()).toLocation(world), new Vector(max.getX() + width, max.getY(), max.getZ()).toLocation(world));
lines.get(0).setFrom(new Vector(min.getX(), min.getY(), min.getZ()).toLocation(world)).setTo(new Vector(max.getX() + width, min.getY(), min.getZ()).toLocation(world));
lines.get(1).setFrom(new Vector(min.getX(), max.getY(), min.getZ()).toLocation(world)).setTo(new Vector(max.getX() + width, max.getY(), min.getZ()).toLocation(world));
lines.get(2).setFrom(new Vector(min.getX(), min.getY(), max.getZ()).toLocation(world)).setTo(new Vector(max.getX() + width, min.getY(), max.getZ()).toLocation(world));
lines.get(3).setFrom(new Vector(min.getX(), max.getY(), max.getZ()).toLocation(world)).setTo(new Vector(max.getX() + width, max.getY(), max.getZ()).toLocation(world));
lines.get(4).setFromAndTo(new Vector(min.getX(), min.getY(), min.getZ()).toLocation(world), new Vector(min.getX(), max.getY() + width, min.getZ()).toLocation(world));
lines.get(5).setFromAndTo(new Vector(max.getX(), min.getY(), min.getZ()).toLocation(world), new Vector(max.getX(), max.getY() + width, min.getZ()).toLocation(world));
lines.get(6).setFromAndTo(new Vector(min.getX(), min.getY(), max.getZ()).toLocation(world), new Vector(min.getX(), max.getY() + width, max.getZ()).toLocation(world));
lines.get(7).setFromAndTo(new Vector(max.getX(), min.getY(), max.getZ()).toLocation(world), new Vector(max.getX(), max.getY() + width, max.getZ()).toLocation(world));
lines.get(4).setFrom(new Vector(min.getX(), min.getY(), min.getZ()).toLocation(world)).setTo(new Vector(min.getX(), max.getY() + width, min.getZ()).toLocation(world));
lines.get(5).setFrom(new Vector(max.getX(), min.getY(), min.getZ()).toLocation(world)).setTo(new Vector(max.getX(), max.getY() + width, min.getZ()).toLocation(world));
lines.get(6).setFrom(new Vector(min.getX(), min.getY(), max.getZ()).toLocation(world)).setTo(new Vector(min.getX(), max.getY() + width, max.getZ()).toLocation(world));
lines.get(7).setFrom(new Vector(max.getX(), min.getY(), max.getZ()).toLocation(world)).setTo(new Vector(max.getX(), max.getY() + width, max.getZ()).toLocation(world));
lines.get(8).setFrom(new Vector(min.getX(), min.getY(), min.getZ()).toLocation(world)).setTo(new Vector(min.getX(), min.getY(), max.getZ() + width).toLocation(world));
lines.get(9).setFrom(new Vector(max.getX(), min.getY(), min.getZ()).toLocation(world)).setTo(new Vector(max.getX(), min.getY(), max.getZ() + width).toLocation(world));
lines.get(10).setFrom(new Vector(min.getX(), max.getY(), min.getZ()).toLocation(world)).setTo(new Vector(min.getX(), max.getY(), max.getZ() + width).toLocation(world));
lines.get(11).setFrom(new Vector(max.getX(), max.getY(), min.getZ()).toLocation(world)).setTo(new Vector(max.getX(), max.getY(), max.getZ() + width).toLocation(world));
lines.get(8).setFromAndTo(new Vector(min.getX(), min.getY(), min.getZ()).toLocation(world), new Vector(min.getX(), min.getY(), max.getZ() + width).toLocation(world));
lines.get(9).setFromAndTo(new Vector(max.getX(), min.getY(), min.getZ()).toLocation(world), new Vector(max.getX(), min.getY(), max.getZ() + width).toLocation(world));
lines.get(10).setFromAndTo(new Vector(min.getX(), max.getY(), min.getZ()).toLocation(world), new Vector(min.getX(), max.getY(), max.getZ() + width).toLocation(world));
lines.get(11).setFromAndTo(new Vector(max.getX(), max.getY(), min.getZ()).toLocation(world), new Vector(max.getX(), max.getY(), max.getZ() + width).toLocation(world));
}
}