From a6de44b5ba7434fa40d8853661cf37c410ce9eee Mon Sep 17 00:00:00 2001 From: sekwah Date: Tue, 19 Dec 2023 06:23:01 +0000 Subject: [PATCH] feat: show triggerblocks in debug view --- .../portal/ShowPortalSubCommand.java | 101 +++++++++++++++--- .../core/portal/AdvancedPortal.java | 13 +++ .../core/repository/ConfigRepository.java | 4 + .../repository/impl/ConfigRepositoryImpl.java | 5 + .../core/serializeddata/PlayerTempData.java | 2 +- .../core/serializeddata/config/Config.java | 2 + 6 files changed, 109 insertions(+), 18 deletions(-) diff --git a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/ShowPortalSubCommand.java b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/ShowPortalSubCommand.java index a7fe85b4..f07b0dd8 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/ShowPortalSubCommand.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/ShowPortalSubCommand.java @@ -6,9 +6,9 @@ import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer; import com.sekwah.advancedportals.core.connector.containers.PlayerContainer; import com.sekwah.advancedportals.core.connector.containers.ServerContainer; +import com.sekwah.advancedportals.core.portal.AdvancedPortal; import com.sekwah.advancedportals.core.repository.ConfigRepository; import com.sekwah.advancedportals.core.serializeddata.BlockLocation; -import com.sekwah.advancedportals.core.serializeddata.PlayerTempData; import com.sekwah.advancedportals.core.services.PortalServices; import com.sekwah.advancedportals.core.services.PortalTempDataServices; import com.sekwah.advancedportals.core.tags.activation.NameTag; @@ -18,6 +18,8 @@ import java.awt.*; import java.util.List; +import java.util.function.BiConsumer; +import java.util.function.Consumer; /** * This will be different from the old show command and I believe it is 1.16+ till the latest version as of writing this. @@ -44,6 +46,17 @@ public class ShowPortalSubCommand implements SubCommand, SubCommand.SubCommandOn @Inject ConfigRepository config; + final Color POS1_COLOR = new Color(0, 255, 0); + final Color POS2_COLOR = new Color(255, 0, 0); + + final Color SELECTION_COLOR = new Color(255, 0, 0, 100); + + final Color OUTLINE_COLOR = new Color(0, 255, 0, 100); + + final Color TRIGGER_COLOR = new Color(0, 0, 255, 100); + + final Color TRIGGER_OUTLINE_COLOR = new Color(0, 117, 200, 100); + @Override public void onCommand(CommandSenderContainer sender, String[] args) { if(core.getMcVersion()[1] < 16) { @@ -90,17 +103,18 @@ public void registered() { } + if (tempData.getPos1() != null && tempData.getPos2() != null) { + debugVisuals(player, tempData.getPos1(), tempData.getPos2(), SELECTION_COLOR, SHOW_TICKS); + } + if(tempData.getPos1() != null) { - Debug.addMarker(player, tempData.getPos1(), "Pos1", new Color(0, 255, 0), SHOW_TICKS); + Debug.addMarker(player, tempData.getPos1(), "Pos1", POS1_COLOR, SHOW_TICKS); } if(tempData.getPos2() != null) { - Debug.addMarker(player, tempData.getPos2(), "Pos2", new Color(255, 0, 0), SHOW_TICKS); - } - - if (tempData.getPos1() != null && tempData.getPos2() != null) { - debugPortal(player, tempData.getPos1(), tempData.getPos2(), new Color(255, 0, 0, 100), SHOW_TICKS, true); + Debug.addMarker(player, tempData.getPos2(), "Pos2", POS2_COLOR, SHOW_TICKS); } + var world = player.getWorld(); for (var portal : portalServices.getPortals()) { if(portal.isLocationInPortal(player.getLoc(), config.getVisibleRange())) { BlockLocation minLoc = portal.getMinLoc(); @@ -108,8 +122,16 @@ public void registered() { int midX = (minLoc.posX + maxLoc.posX) / 2; int midZ = (minLoc.posZ + maxLoc.posZ) / 2; BlockLocation midPoint = new BlockLocation(minLoc.worldName, midX, maxLoc.posY, midZ); - var color = new Color(0, 255, 0, 100); - debugPortal(player, portal.getMinLoc(), portal.getMaxLoc(), color, 1000, false); + Color color; + if(portal.isTriggerBlock(world.getBlock(midPoint))) { + color = TRIGGER_OUTLINE_COLOR; + } else { + if(midPoint.posX == minLoc.posX || midPoint.posX == maxLoc.posX || midPoint.posZ == minLoc.posZ || midPoint.posZ == maxLoc.posZ) + color = OUTLINE_COLOR; + else + color = new Color(0, 0, 0, 0); + } + debugVisuals(player, portal, OUTLINE_COLOR, 1000, TRIGGER_COLOR); Debug.addMarker(player, midPoint, portal.getArgValues(NameTag.TAG_NAME)[0], color, SHOW_TICKS); } } @@ -117,7 +139,15 @@ public void registered() { }, 1, 20); } - private static void debugPortal(PlayerContainer player, BlockLocation pos1, BlockLocation pos2, Color color, int time, boolean hideCorners) { + private void debugVisuals(PlayerContainer player, BlockLocation pos1, BlockLocation pos2, Color color, int time) { + debugVisuals(player, pos1, pos2, color, time, null, null); + } + + private void debugVisuals(PlayerContainer player, AdvancedPortal portal, Color color, int time, Color triggerColor) { + debugVisuals(player, portal.getMinLoc(), portal.getMaxLoc(), color, time, triggerColor, portal); + } + + private void debugVisuals(PlayerContainer player, BlockLocation pos1, BlockLocation pos2, Color color, int time, Color triggerColor, AdvancedPortal portal) { int minX = Math.min(pos1.posX, pos2.posX); int minY = Math.min(pos1.posY, pos2.posY); int minZ = Math.min(pos1.posZ, pos2.posZ); @@ -126,17 +156,54 @@ private static void debugPortal(PlayerContainer player, BlockLocation pos1, Bloc int maxY = Math.max(pos1.posY, pos2.posY); int maxZ = Math.max(pos1.posZ, pos2.posZ); - for (int x = minX; x <= maxX; x++) { - for (int y = minY; y <= maxY; y++) { - for (int z = minZ; z <= maxZ; z++) { - if ((y == minY || y == maxY) && (x == minX || x == maxX || z == minZ || z == maxZ) || (z == minZ || z == maxZ) && (x == minX || x == maxX)) { + var world = player.getWorld(); + + + int widthX = maxX - minX + 1; + int widthY = maxY - minY + 1; + int widthZ = maxZ - minZ + 1; + + int totalBlocks = widthX * widthY * widthZ; + + if(totalBlocks <= config.getMaxTriggerVisualisationSize()) { + for (int x = minX; x <= maxX; x++) { + for (int y = minY; y <= maxY; y++) { + for (int z = minZ; z <= maxZ; z++) { var pos = new BlockLocation(pos1.worldName, x, y, z); - if ((pos.equals(pos1) || pos.equals(pos2)) && hideCorners) - continue; - Debug.addMarker(player, pos, "", color, time); + boolean isTrigger = portal != null && portal.isTriggerBlock(world.getBlock(pos)); + boolean isOutline = (y == minY || y == maxY) && (x == minX || x == maxX || z == minZ || z == maxZ) || (z == minZ || z == maxZ) && (x == minX || x == maxX); + if (isTrigger && isOutline) { + Debug.addMarker(player, pos, "", TRIGGER_OUTLINE_COLOR, time); + } + else if(isTrigger) { + Debug.addMarker(player, pos, "", triggerColor, time); + } else if (isOutline) { + Debug.addMarker(player, pos, "", color, time); + } } } } + } else { + + for (int x = minX; x <= maxX; x++) { + Debug.addMarker(player, new BlockLocation(pos1.worldName, x, minY, minZ), "", color, time); + Debug.addMarker(player, new BlockLocation(pos1.worldName, x, minY, maxZ), "", color, time); + Debug.addMarker(player, new BlockLocation(pos1.worldName, x, maxY, minZ), "", color, time); + Debug.addMarker(player, new BlockLocation(pos1.worldName, x, maxY, maxZ), "", color, time); + } + for (int z = minZ + 1; z < maxZ; z++) { + Debug.addMarker(player, new BlockLocation(pos1.worldName, minX, minY, z), "", color, time); + Debug.addMarker(player, new BlockLocation(pos1.worldName, maxX, minY, z), "", color, time); + Debug.addMarker(player, new BlockLocation(pos1.worldName, minX, maxY, z), "", color, time); + Debug.addMarker(player, new BlockLocation(pos1.worldName, maxX, maxY, z), "", color, time); + } + + for (int y = minY + 1; y < maxY; y++) { + Debug.addMarker(player, new BlockLocation(pos1.worldName, minX, y, minZ), "", color, time); + Debug.addMarker(player, new BlockLocation(pos1.worldName, maxX, y, minZ), "", color, time); + Debug.addMarker(player, new BlockLocation(pos1.worldName, minX, y, maxZ), "", color, time); + Debug.addMarker(player, new BlockLocation(pos1.worldName, maxX, y, maxZ), "", color, time); + } } } } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/portal/AdvancedPortal.java b/core/src/main/java/com/sekwah/advancedportals/core/portal/AdvancedPortal.java index c7bd718b..79784ebd 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/portal/AdvancedPortal.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/portal/AdvancedPortal.java @@ -8,6 +8,7 @@ import com.sekwah.advancedportals.core.serializeddata.DataTag; import com.sekwah.advancedportals.core.registry.TagRegistry; import com.sekwah.advancedportals.core.serializeddata.PlayerLocation; +import com.sekwah.advancedportals.core.tags.activation.TriggerBlockTag; import com.sekwah.advancedportals.core.warphandler.ActivationData; import com.sekwah.advancedportals.core.warphandler.Tag; @@ -151,6 +152,18 @@ public ArrayList getArgs() { return tagList; } + public boolean isTriggerBlock(String blockMaterial) { + var triggerBlocks = this.getArgValues(TriggerBlockTag.TAG_NAME); + if(triggerBlocks != null) { + for(String triggerBlock : triggerBlocks) { + if(blockMaterial.equals(triggerBlock)) { + return true; + } + } + } + return false; + } + /*public void setTriggerBlocks(String[] triggerBlocks) { this.triggerBlocks = triggerBlocks; }*/ diff --git a/core/src/main/java/com/sekwah/advancedportals/core/repository/ConfigRepository.java b/core/src/main/java/com/sekwah/advancedportals/core/repository/ConfigRepository.java index 2a5afd19..39b0c0fa 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/repository/ConfigRepository.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/repository/ConfigRepository.java @@ -15,4 +15,8 @@ public interface ConfigRepository { void loadConfig(DataStorage dataStorage); int getVisibleRange(); + + int getMaxTriggerVisualisationSize(); + + } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/repository/impl/ConfigRepositoryImpl.java b/core/src/main/java/com/sekwah/advancedportals/core/repository/impl/ConfigRepositoryImpl.java index f31ea552..dba102df 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/repository/impl/ConfigRepositoryImpl.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/repository/impl/ConfigRepositoryImpl.java @@ -47,6 +47,11 @@ public int getVisibleRange() { return this.config.visibleRange; } + @Override + public int getMaxTriggerVisualisationSize() { + return this.config.maxTriggerVisualisationSize; + } + @Override public void loadConfig(DataStorage dataStorage) { this.config = dataStorage.loadJson(Config.class, "config.json"); diff --git a/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/PlayerTempData.java b/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/PlayerTempData.java index f5b71030..c96efbf7 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/PlayerTempData.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/PlayerTempData.java @@ -22,7 +22,7 @@ public class PlayerTempData { /** * If to show portals near the player */ - private boolean portalVisible; + private boolean portalVisible = true; /** * If to show destination blocks near the player diff --git a/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/config/Config.java b/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/config/Config.java index 9bdf4eb6..0a1db003 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/config/Config.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/config/Config.java @@ -29,4 +29,6 @@ public class Config { public int visibleRange = 50; + public int maxTriggerVisualisationSize = 1000; + }