refactor: refactored entity DebugLine
This commit is contained in:
parent
5f3cab0634
commit
bbcba20499
@ -2,26 +2,20 @@ package ru.dragonestia.msb3.api.boot;
|
|||||||
|
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
|
||||||
import net.minestom.server.coordinate.Point;
|
import net.minestom.server.coordinate.Point;
|
||||||
import net.minestom.server.coordinate.Vec;
|
import net.minestom.server.coordinate.Vec;
|
||||||
import net.minestom.server.entity.EntityType;
|
|
||||||
import net.minestom.server.entity.GameMode;
|
import net.minestom.server.entity.GameMode;
|
||||||
import net.minestom.server.entity.metadata.display.BlockDisplayMeta;
|
|
||||||
import net.minestom.server.instance.Instance;
|
import net.minestom.server.instance.Instance;
|
||||||
import net.minestom.server.instance.block.Block;
|
import net.minestom.server.instance.block.Block;
|
||||||
import ru.dragonestia.msb3.api.entity.debug.DebugLine;
|
import ru.dragonestia.msb3.api.entity.debug.DebugLine;
|
||||||
import ru.dragonestia.msb3.api.entity.debug.DebugMarker;
|
import ru.dragonestia.msb3.api.entity.debug.DebugMarker;
|
||||||
import ru.dragonestia.msb3.api.entity.debug.DebugRendererEntity;
|
|
||||||
import ru.dragonestia.msb3.api.module.FlatWorldModule;
|
import ru.dragonestia.msb3.api.module.FlatWorldModule;
|
||||||
import ru.dragonestia.msb3.api.module.MotdModule;
|
import ru.dragonestia.msb3.api.module.MotdModule;
|
||||||
import ru.dragonestia.msb3.api.module.PrometheusMetricsModule;
|
import ru.dragonestia.msb3.api.module.PrometheusMetricsModule;
|
||||||
import ru.dragonestia.msb3.api.module.ResourcePackRepositoryModule;
|
import ru.dragonestia.msb3.api.module.ResourcePackRepositoryModule;
|
||||||
import ru.dragonestia.msb3.api.math.Quaternion;
|
|
||||||
import team.unnamed.creative.ResourcePack;
|
import team.unnamed.creative.ResourcePack;
|
||||||
|
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
@Log4j2
|
@Log4j2
|
||||||
@ -63,8 +57,8 @@ public class DefaultBootstrap extends ServerInitializer {
|
|||||||
drawLine(instance, startPos, endPos);
|
drawLine(instance, startPos, endPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
drawLine(instance, new Vec(3, 20, 0), new Vec(3, 60, 0));
|
drawLine(instance, new Vec(3, 50, 0), new Vec(3, 60, 0));
|
||||||
drawLine(instance, new Vec(-3, 60, 0), new Vec(-3, 20, 0));
|
drawLine(instance, new Vec(-3, 60, 0), new Vec(-3, 50, 0));
|
||||||
drawLine(instance, new Vec(10, 60, 3), new Vec(-10, 60, 3));
|
drawLine(instance, new Vec(10, 60, 3), new Vec(-10, 60, 3));
|
||||||
drawLine(instance, new Vec(-10, 60, -3), new Vec(10, 60, -3));
|
drawLine(instance, new Vec(-10, 60, -3), new Vec(10, 60, -3));
|
||||||
drawLine(instance, new Vec(0, 57, 10), new Vec(0, 57, -10));
|
drawLine(instance, new Vec(0, 57, 10), new Vec(0, 57, -10));
|
||||||
@ -85,24 +79,6 @@ public class DefaultBootstrap extends ServerInitializer {
|
|||||||
marker.setInstance(instance, endPos);
|
marker.setInstance(instance, endPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
var dist = startPos.distance(endPos);
|
DebugLine.spawn(instance, startPos, endPos, Block.LIME_CONCRETE, "test");
|
||||||
record LineColor(Block block, Vec rot) {}
|
|
||||||
for (var rot: List.of(
|
|
||||||
new LineColor(Block.RED_CONCRETE, new Vec(3, 0.1, 0.1)),
|
|
||||||
new LineColor(Block.LIME_CONCRETE, new Vec(0.1, dist, 0.1)),
|
|
||||||
new LineColor(Block.LIGHT_BLUE_CONCRETE, new Vec(0.1, 0.1, 3))
|
|
||||||
)) {
|
|
||||||
var entity = new DebugRendererEntity(EntityType.BLOCK_DISPLAY, "test");
|
|
||||||
var meta = (BlockDisplayMeta) entity.getEntityMeta();
|
|
||||||
var normal = Vec.fromPoint(endPos.sub(startPos)).normalize();
|
|
||||||
meta.setBlockState(rot.block());
|
|
||||||
meta.setScale(rot.rot());
|
|
||||||
|
|
||||||
meta.setLeftRotation(Quaternion.DEFAULT.rotate(normal).toFloatArray());
|
|
||||||
|
|
||||||
entity.setInstance(instance, startPos);
|
|
||||||
}
|
|
||||||
var line = new DebugLine("test", startPos, endPos, NamedTextColor.GOLD);
|
|
||||||
line.setInstance(instance, startPos);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,63 +2,52 @@ package ru.dragonestia.msb3.api.entity.debug;
|
|||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
import net.kyori.adventure.text.format.TextColor;
|
|
||||||
import net.minestom.server.coordinate.Point;
|
import net.minestom.server.coordinate.Point;
|
||||||
import net.minestom.server.coordinate.Vec;
|
import net.minestom.server.coordinate.Vec;
|
||||||
import net.minestom.server.entity.EntityType;
|
import net.minestom.server.entity.EntityType;
|
||||||
import net.minestom.server.network.packet.server.play.ParticlePacket;
|
import net.minestom.server.entity.metadata.display.BlockDisplayMeta;
|
||||||
import net.minestom.server.particle.Particle;
|
import net.minestom.server.instance.Instance;
|
||||||
|
import net.minestom.server.instance.block.Block;
|
||||||
|
import ru.dragonestia.msb3.api.math.Quaternion;
|
||||||
|
|
||||||
|
@Getter
|
||||||
@Log4j2
|
@Log4j2
|
||||||
public class DebugLine extends DebugRendererEntity {
|
public class DebugLine extends DebugRendererEntity {
|
||||||
|
|
||||||
@Getter private Point startPos;
|
private Vec normalWithLength;
|
||||||
@Getter private Point endPos;
|
private Block block;
|
||||||
private double dist;
|
|
||||||
private long lastTick = 0;
|
|
||||||
private final Particle particle;
|
|
||||||
|
|
||||||
public DebugLine(String layerName, Point start, Point end, TextColor color) {
|
protected DebugLine(String layerName, Vec normalWithLength, Block block) {
|
||||||
super(EntityType.TEXT_DISPLAY, layerName);
|
super(EntityType.BLOCK_DISPLAY, layerName);
|
||||||
this.startPos = start;
|
|
||||||
this.endPos = end;
|
|
||||||
updateDist();
|
|
||||||
|
|
||||||
particle = Particle.DUST.withColor(color).withScale(1);
|
var meta = getMeta();
|
||||||
|
meta.setBrightnessOverride(15);
|
||||||
|
meta.setBrightness(15, 15);
|
||||||
|
|
||||||
|
updateNormalWithLength(normalWithLength);
|
||||||
|
updateBlock(block);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public void updateNormalWithLength(Vec newValue) {
|
||||||
public void tick(long time) {
|
normalWithLength = newValue;
|
||||||
super.tick(time);
|
var meta = getMeta();
|
||||||
|
meta.setScale(new Vec(0.1, normalWithLength.length(), 0.1));
|
||||||
if (time - lastTick < 500) return;
|
meta.setLeftRotation(Quaternion.DEFAULT
|
||||||
lastTick = time;
|
.rotate(newValue.normalize())
|
||||||
|
.toFloatArray());
|
||||||
if (getViewers().isEmpty()) return;
|
|
||||||
|
|
||||||
double currentDist = 0;
|
|
||||||
while ((currentDist += 0.7) < dist) {
|
|
||||||
var pos = Vec.fromPoint(endPos.sub(startPos))
|
|
||||||
.normalize()
|
|
||||||
.mul(currentDist)
|
|
||||||
.add(startPos);
|
|
||||||
|
|
||||||
var pk = new ParticlePacket(particle, pos.x(), pos.y(), pos.z(), 0, 0, 0, 0, 1);
|
|
||||||
getViewers().forEach(player -> player.sendPacket(pk));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateDist() {
|
public void updateBlock(Block block) {
|
||||||
dist = endPos.distance(startPos);
|
getMeta().setBlockState(this.block = block);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setStartPos(Point startPos) {
|
private BlockDisplayMeta getMeta() {
|
||||||
this.startPos = startPos;
|
return (BlockDisplayMeta) getEntityMeta();
|
||||||
updateDist();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setEndPos(Point endPos) {
|
public static DebugLine spawn(Instance instance, Point start, Point end, Block block, String layerName) {
|
||||||
this.endPos = endPos;
|
var entity = new DebugLine(layerName, Vec.fromPoint(end.sub(start)), block);
|
||||||
updateDist();
|
entity.setInstance(instance, start);
|
||||||
|
return entity;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user