diff --git a/src/main/java/de/bixilon/minosoft/debug/UIEntity.java b/src/main/java/de/bixilon/minosoft/debug/UIEntity.java
new file mode 100644
index 000000000..31c0b515d
--- /dev/null
+++ b/src/main/java/de/bixilon/minosoft/debug/UIEntity.java
@@ -0,0 +1,55 @@
+/*
+ * Codename Minosoft
+ * Copyright (C) 2020 Moritz Zwerger
+ *
+ * This program is free software: you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program. If not, see .
+ *
+ * This software is not affiliated with Mojang AB, the original developer of Minecraft.
+ */
+
+package de.bixilon.minosoft.debug;
+
+import de.bixilon.minosoft.game.datatypes.entities.Entity;
+import de.bixilon.minosoft.game.datatypes.entities.EntityObject;
+import de.bixilon.minosoft.game.datatypes.entities.Mob;
+
+import java.util.HashMap;
+
+public class UIEntity {
+ static HashMap entityHashMap;
+ final int id;
+ final Entity entity;
+
+ public UIEntity(int id, Entity entity) {
+ if (entityHashMap == null) {
+ entityHashMap = new HashMap<>();
+ }
+ this.id = id;
+ this.entity = entity;
+ entityHashMap.put(id, this);
+ }
+
+ public static UIEntity getByID(int id) {
+ return entityHashMap.get(id);
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public Entity getEntity() {
+ return entity;
+ }
+
+ @Override
+ public String toString() {
+ if (entity instanceof Mob) {
+ return String.format("%d (%s)", id, ((Mob) entity).getEntityType().name());
+ }
+ return String.format("%d (%s)", id, ((EntityObject) entity).getEntityType().name());
+ }
+}
diff --git a/src/main/java/de/bixilon/minosoft/debug/handling/DebugUIHandler.java b/src/main/java/de/bixilon/minosoft/debug/handling/DebugUIHandler.java
index c764bf886..bb0664aed 100644
--- a/src/main/java/de/bixilon/minosoft/debug/handling/DebugUIHandler.java
+++ b/src/main/java/de/bixilon/minosoft/debug/handling/DebugUIHandler.java
@@ -13,9 +13,12 @@
package de.bixilon.minosoft.debug.handling;
+import de.bixilon.minosoft.debug.UIEntity;
import de.bixilon.minosoft.debug.gui.DebugMainWindow;
import de.bixilon.minosoft.game.datatypes.TextComponent;
+import de.bixilon.minosoft.game.datatypes.entities.Entity;
import javafx.application.Platform;
+import javafx.scene.control.ListView;
import javafx.scene.text.Text;
import javafx.scene.text.TextFlow;
@@ -24,13 +27,12 @@ import java.util.List;
public class DebugUIHandler {
List toPrint = new ArrayList<>();
+ List entities = new ArrayList<>();
public void printText(TextComponent component) {
if (DebugMainWindow.isInitialized()) {
TextFlow chat = ((TextFlow) DebugMainWindow.getStage().getScene().lookup("#chat"));
- Platform.runLater(
- () -> chat.getChildren().add(new Text(component.getRawMessage() + "\n"))
- );
+ Platform.runLater(() -> chat.getChildren().add(new Text(component.getRawMessage() + "\n")));
} else {
toPrint.add(component);
}
@@ -50,5 +52,42 @@ public class DebugUIHandler {
public void initializedCallback() {
printTextLeft();
+ printEntitiesLeft();
+ }
+
+ public void addEntity(Entity entity) {
+ UIEntity uiEntity = new UIEntity(entity.getId(), entity);
+ if (DebugMainWindow.isInitialized()) {
+ ListView entityList = (ListView) DebugMainWindow.getStage().getScene().lookup("#entityList");
+ Platform.runLater(() -> entityList.getItems().add(uiEntity));
+ } else {
+ entities.add(uiEntity);
+ }
+ }
+
+ private void removeEntity(int id) {
+ if (DebugMainWindow.isInitialized()) {
+ ListView entityList = (ListView) DebugMainWindow.getStage().getScene().lookup("#entityList");
+ Platform.runLater(() -> entityList.getItems().remove(UIEntity.getByID(id)));
+ } else {
+ entities.remove(UIEntity.getByID(id));
+ }
+ }
+
+ public void printEntitiesLeft() {
+ ListView entityList = (ListView) DebugMainWindow.getStage().getScene().lookup("#entityList");
+ if (entities != null && entities.size() > 0) {
+ // append here
+ for (UIEntity entity : entities) {
+ Platform.runLater(() -> entityList.getItems().add(entity));
+ }
+ entities.clear();
+ }
+ }
+
+ public void removeEntities(int[] entityIds) {
+ for (int id : entityIds) {
+ removeEntity(id);
+ }
}
}
diff --git a/src/main/java/de/bixilon/minosoft/debug/handling/DebugUIPacketHandler.java b/src/main/java/de/bixilon/minosoft/debug/handling/DebugUIPacketHandler.java
index 226f8ff23..0ce48dee3 100644
--- a/src/main/java/de/bixilon/minosoft/debug/handling/DebugUIPacketHandler.java
+++ b/src/main/java/de/bixilon/minosoft/debug/handling/DebugUIPacketHandler.java
@@ -15,6 +15,9 @@ package de.bixilon.minosoft.debug.handling;
import de.bixilon.minosoft.debug.DebugWindow;
import de.bixilon.minosoft.protocol.packets.clientbound.play.PacketChatMessage;
+import de.bixilon.minosoft.protocol.packets.clientbound.play.PacketDestroyEntity;
+import de.bixilon.minosoft.protocol.packets.clientbound.play.PacketSpawnMob;
+import de.bixilon.minosoft.protocol.packets.clientbound.play.PacketSpawnObject;
import de.bixilon.minosoft.protocol.protocol.PacketHandler;
public class DebugUIPacketHandler extends PacketHandler {
@@ -29,4 +32,19 @@ public class DebugUIPacketHandler extends PacketHandler {
window.getUIHandler().printText(pkg.getTextComponent());
}
+ @Override
+ public void handle(PacketSpawnMob pkg) {
+ window.getUIHandler().addEntity(pkg.getMob());
+ }
+
+ @Override
+ public void handle(PacketSpawnObject pkg) {
+ window.getUIHandler().addEntity(pkg.getObject());
+ }
+
+ @Override
+ public void handle(PacketDestroyEntity pkg) {
+ window.getUIHandler().removeEntities(pkg.getEntityIds());
+ }
+
}
diff --git a/src/main/resources/layout/debug/main.fxml b/src/main/resources/layout/debug/main.fxml
index 14a32cbbf..cf2d7e6dc 100644
--- a/src/main/resources/layout/debug/main.fxml
+++ b/src/main/resources/layout/debug/main.fxml
@@ -1,9 +1,6 @@
-
-
-
-
+
@@ -22,6 +19,17 @@
AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0"/>
+
+
+
+
+
+
+
+
+