From e356f4205e7c7c10c0ccaa33c26431c9fc2c4d48 Mon Sep 17 00:00:00 2001 From: Roman Kozin Date: Tue, 22 Oct 2024 15:32:09 +0300 Subject: [PATCH 1/5] implemented drawBlock and drawCuboid --- .../MissionHandlers/DrawImplementation.java | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 src/main/java/io/singularitynet/MissionHandlers/DrawImplementation.java diff --git a/src/main/java/io/singularitynet/MissionHandlers/DrawImplementation.java b/src/main/java/io/singularitynet/MissionHandlers/DrawImplementation.java new file mode 100644 index 0000000..0fa3493 --- /dev/null +++ b/src/main/java/io/singularitynet/MissionHandlers/DrawImplementation.java @@ -0,0 +1,78 @@ +package io.singularitynet.MissionHandlers; + +import io.singularitynet.projectmalmo.*; +import jakarta.xml.bind.JAXBElement; +import net.minecraft.client.MinecraftClient; +import net.minecraft.command.CommandSource; +import net.minecraft.server.command.CommandManager; +import net.minecraft.server.command.ServerCommandSource; +import org.apache.logging.log4j.LogManager; + +import java.lang.reflect.Type; +import java.util.List; +import java.util.Map; +import java.util.function.Function; + +public class DrawImplementation extends DrawingDecorator { + public static void draw(List worldDecorator) { + //get command manager and command source + CommandManager commandManager = null; + ServerCommandSource commandSource= null; + try { + MinecraftClient client = MinecraftClient.getInstance(); + commandManager = client.getServer().getCommandManager(); + commandSource = client.getServer().getCommandSource(); + } catch (Exception e) { + LogManager.getLogger().error("Failed to get command manager and command source"); + LogManager.getLogger().error(e); + } + try { + for (Object obj : worldDecorator){ + List> drawObjects = null; + if (obj instanceof DrawingDecorator){ + drawObjects = ((DrawingDecorator)obj).getDrawObjectType(); + } + for (JAXBElement drawObject : drawObjects){ + switch (drawObject.getValue()) { + case DrawBlock db -> drawBlock(db, commandManager, commandSource); + case DrawCuboid dc -> drawCuboid(dc, commandManager, commandSource); + default -> {} + } + } + } + } catch (Exception e) { + LogManager.getLogger().error("Failed to draw objects"); + LogManager.getLogger().error(e); + } + } + + public static void drawBlock(DrawBlock val, CommandManager commandManager, ServerCommandSource commandSource){ + try { + String command = "/setblock " + val.getX() + " " + + val.getY() + " " + + val.getZ() + " " + + val.getType().value(); + commandManager.executeWithPrefix(commandSource, command); + } catch (Exception e) { + LogManager.getLogger().error("Failed to draw the block"); + LogManager.getLogger().error(e); + } + } + + public static void drawCuboid(DrawCuboid val, CommandManager commandManager, ServerCommandSource commandSource){ + try { + String command = "/fill " + val.getX1() + " " + + val.getY1() + " " + + val.getZ1() + " " + + val.getX2() + " " + + val.getY2() + " " + + val.getZ2() + " " + + val.getType().value(); + commandManager.executeWithPrefix(commandSource, command); + } catch (Exception e) { + LogManager.getLogger().error("Failed to draw the cuboid"); + LogManager.getLogger().error(e); + } + } + +} \ No newline at end of file From 4b89f5191c0bcb05d359d6d61bfca3b055d90dee Mon Sep 17 00:00:00 2001 From: Roman Kozin Date: Tue, 22 Oct 2024 15:32:26 +0300 Subject: [PATCH 2/5] added draw after world generation --- .../java/io/singularitynet/Client/ClientStateMachine.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/io/singularitynet/Client/ClientStateMachine.java b/src/main/java/io/singularitynet/Client/ClientStateMachine.java index eaaa2f7..5d7f95a 100755 --- a/src/main/java/io/singularitynet/Client/ClientStateMachine.java +++ b/src/main/java/io/singularitynet/Client/ClientStateMachine.java @@ -25,6 +25,7 @@ import io.singularitynet.MissionHandlerInterfaces.IVideoProducer; import io.singularitynet.MissionHandlerInterfaces.IWantToQuit; import io.singularitynet.MissionHandlerInterfaces.IWorldGenerator; +import io.singularitynet.MissionHandlers.DrawImplementation; import io.singularitynet.MissionHandlers.MissionBehaviour; import io.singularitynet.MissionHandlers.MultidimensionalReward; import io.singularitynet.Server.VereyaModServer; @@ -1084,6 +1085,11 @@ protected void execute() if (MinecraftClient.getInstance().getServer() != null) { MinecraftClient.getInstance().getServer().setOnlineMode(false); } + // draw blocks and entities from DrawingDecorator section + List worldDecorator = ClientStateMachine.this.currentMissionInit.getMission().getServerSection().getServerHandlers().getWorldDecorators(); + if (!worldDecorator.isEmpty()){ + DrawImplementation.draw(worldDecorator); + } } else { From e5536fd3919b7ecdbb651323d040be0fd6f44b5c Mon Sep 17 00:00:00 2001 From: Roman Kozin Date: Tue, 22 Oct 2024 16:32:27 +0300 Subject: [PATCH 3/5] implemented drawItem --- .../MissionHandlers/DrawImplementation.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/main/java/io/singularitynet/MissionHandlers/DrawImplementation.java b/src/main/java/io/singularitynet/MissionHandlers/DrawImplementation.java index 0fa3493..3645055 100644 --- a/src/main/java/io/singularitynet/MissionHandlers/DrawImplementation.java +++ b/src/main/java/io/singularitynet/MissionHandlers/DrawImplementation.java @@ -3,15 +3,11 @@ import io.singularitynet.projectmalmo.*; import jakarta.xml.bind.JAXBElement; import net.minecraft.client.MinecraftClient; -import net.minecraft.command.CommandSource; import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.ServerCommandSource; import org.apache.logging.log4j.LogManager; -import java.lang.reflect.Type; import java.util.List; -import java.util.Map; -import java.util.function.Function; public class DrawImplementation extends DrawingDecorator { public static void draw(List worldDecorator) { @@ -36,6 +32,7 @@ public static void draw(List worldDecorator) { switch (drawObject.getValue()) { case DrawBlock db -> drawBlock(db, commandManager, commandSource); case DrawCuboid dc -> drawCuboid(dc, commandManager, commandSource); + case DrawItem di -> drawItem(di, commandManager, commandSource); default -> {} } } @@ -75,4 +72,17 @@ public static void drawCuboid(DrawCuboid val, CommandManager commandManager, Ser } } + public static void drawItem(DrawItem val, CommandManager commandManager, ServerCommandSource commandSource){ + try { + String command = "/summon item " + val.getX() + " " + + val.getY() + " " + + val.getZ() + " " + + "{Item:{id:" + val.getType() + ",Count:1}}"; + commandManager.executeWithPrefix(commandSource, command); + } catch (Exception e) { + LogManager.getLogger().error("Failed to draw the item"); + LogManager.getLogger().error(e); + } + } + } \ No newline at end of file From 192e8335100c5828e9e487d00ff1a15c52db86e7 Mon Sep 17 00:00:00 2001 From: Roman Kozin Date: Wed, 23 Oct 2024 11:58:12 +0300 Subject: [PATCH 4/5] implemented drawLine --- .../MissionHandlers/DrawImplementation.java | 40 ++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/singularitynet/MissionHandlers/DrawImplementation.java b/src/main/java/io/singularitynet/MissionHandlers/DrawImplementation.java index 3645055..32df820 100644 --- a/src/main/java/io/singularitynet/MissionHandlers/DrawImplementation.java +++ b/src/main/java/io/singularitynet/MissionHandlers/DrawImplementation.java @@ -33,7 +33,8 @@ public static void draw(List worldDecorator) { case DrawBlock db -> drawBlock(db, commandManager, commandSource); case DrawCuboid dc -> drawCuboid(dc, commandManager, commandSource); case DrawItem di -> drawItem(di, commandManager, commandSource); - default -> {} + case DrawLine dl -> drawLine(dl, commandManager, commandSource); + default -> LogManager.getLogger().warn("The type " + drawObject.getClass().getSimpleName() + " is not supported"); } } } @@ -85,4 +86,41 @@ public static void drawItem(DrawItem val, CommandManager commandManager, ServerC } } + public static void drawLine(DrawLine val, CommandManager commandManager, ServerCommandSource commandSource){ + try { + int dx = val.getX2() - val.getX1(); + int dy = val.getY2() - val.getY1(); + int dz = val.getZ2() - val.getZ1(); + + int steps = Math.max(Math.abs(dx), Math.max(Math.abs(dy), Math.abs(dz))); + + double xInc = (double)dx / steps; + double yInc = (double)dy / steps; + double zInc = (double)dz / steps; + + for (int i = 0; i <= steps; i++){ + int x = (int)Math.round(val.getX1() + i * xInc); + int y = (int)Math.round(val.getY1() + i * yInc); + int z = (int)Math.round(val.getZ1() + i * zInc); + setBlock(x, y, z, val.getType().value(), commandManager, commandSource); + } + + } catch (Exception e) { + LogManager.getLogger().error("Failed to draw the line"); + LogManager.getLogger().error(e); + } + } + + public static void setBlock(int x, int y, int z, String type, CommandManager commandManager, ServerCommandSource commandSource){ + try { + String command = "/setblock " + x + " " + + y + " " + + z + " " + + type; + commandManager.executeWithPrefix(commandSource, command); + } catch (Exception e) { + LogManager.getLogger().error("Failed to set the block"); + LogManager.getLogger().error(e); + } + } } \ No newline at end of file From 0c6bb57a49fe058617fa2f5341bd1eff4a7be1ae Mon Sep 17 00:00:00 2001 From: Roman Kozin Date: Wed, 23 Oct 2024 14:17:09 +0300 Subject: [PATCH 5/5] changed setBlock access modifier --- .../io/singularitynet/MissionHandlers/DrawImplementation.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/singularitynet/MissionHandlers/DrawImplementation.java b/src/main/java/io/singularitynet/MissionHandlers/DrawImplementation.java index 32df820..b879698 100644 --- a/src/main/java/io/singularitynet/MissionHandlers/DrawImplementation.java +++ b/src/main/java/io/singularitynet/MissionHandlers/DrawImplementation.java @@ -34,6 +34,7 @@ public static void draw(List worldDecorator) { case DrawCuboid dc -> drawCuboid(dc, commandManager, commandSource); case DrawItem di -> drawItem(di, commandManager, commandSource); case DrawLine dl -> drawLine(dl, commandManager, commandSource); +// case DrawSphere ds -> drawSphere(ds, commandManager, commandSource); default -> LogManager.getLogger().warn("The type " + drawObject.getClass().getSimpleName() + " is not supported"); } } @@ -111,7 +112,7 @@ public static void drawLine(DrawLine val, CommandManager commandManager, ServerC } } - public static void setBlock(int x, int y, int z, String type, CommandManager commandManager, ServerCommandSource commandSource){ + protected static void setBlock(int x, int y, int z, String type, CommandManager commandManager, ServerCommandSource commandSource){ try { String command = "/setblock " + x + " " + y + " " +