mirror of
https://github.com/sekwah41/Advanced-Portals.git
synced 2024-09-27 14:52:59 +02:00
feat: show triggerblocks in debug view
This commit is contained in:
parent
02d58e5dfd
commit
a6de44b5ba
@ -6,9 +6,9 @@ import com.sekwah.advancedportals.core.commands.SubCommand;
|
|||||||
import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer;
|
import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer;
|
||||||
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
|
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
|
||||||
import com.sekwah.advancedportals.core.connector.containers.ServerContainer;
|
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.repository.ConfigRepository;
|
||||||
import com.sekwah.advancedportals.core.serializeddata.BlockLocation;
|
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.PortalServices;
|
||||||
import com.sekwah.advancedportals.core.services.PortalTempDataServices;
|
import com.sekwah.advancedportals.core.services.PortalTempDataServices;
|
||||||
import com.sekwah.advancedportals.core.tags.activation.NameTag;
|
import com.sekwah.advancedportals.core.tags.activation.NameTag;
|
||||||
@ -18,6 +18,8 @@ import com.sekwah.advancedportals.core.util.Lang;
|
|||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.util.List;
|
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.
|
* 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
|
@Inject
|
||||||
ConfigRepository config;
|
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
|
@Override
|
||||||
public void onCommand(CommandSenderContainer sender, String[] args) {
|
public void onCommand(CommandSenderContainer sender, String[] args) {
|
||||||
if(core.getMcVersion()[1] < 16) {
|
if(core.getMcVersion()[1] < 16) {
|
||||||
@ -90,17 +103,18 @@ public class ShowPortalSubCommand implements SubCommand, SubCommand.SubCommandOn
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (tempData.getPos1() != null && tempData.getPos2() != null) {
|
||||||
|
debugVisuals(player, tempData.getPos1(), tempData.getPos2(), SELECTION_COLOR, SHOW_TICKS);
|
||||||
|
}
|
||||||
|
|
||||||
if(tempData.getPos1() != null) {
|
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) {
|
if(tempData.getPos2() != null) {
|
||||||
Debug.addMarker(player, tempData.getPos2(), "Pos2", new Color(255, 0, 0), SHOW_TICKS);
|
Debug.addMarker(player, tempData.getPos2(), "Pos2", POS2_COLOR, SHOW_TICKS);
|
||||||
}
|
|
||||||
|
|
||||||
if (tempData.getPos1() != null && tempData.getPos2() != null) {
|
|
||||||
debugPortal(player, tempData.getPos1(), tempData.getPos2(), new Color(255, 0, 0, 100), SHOW_TICKS, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var world = player.getWorld();
|
||||||
for (var portal : portalServices.getPortals()) {
|
for (var portal : portalServices.getPortals()) {
|
||||||
if(portal.isLocationInPortal(player.getLoc(), config.getVisibleRange())) {
|
if(portal.isLocationInPortal(player.getLoc(), config.getVisibleRange())) {
|
||||||
BlockLocation minLoc = portal.getMinLoc();
|
BlockLocation minLoc = portal.getMinLoc();
|
||||||
@ -108,8 +122,16 @@ public class ShowPortalSubCommand implements SubCommand, SubCommand.SubCommandOn
|
|||||||
int midX = (minLoc.posX + maxLoc.posX) / 2;
|
int midX = (minLoc.posX + maxLoc.posX) / 2;
|
||||||
int midZ = (minLoc.posZ + maxLoc.posZ) / 2;
|
int midZ = (minLoc.posZ + maxLoc.posZ) / 2;
|
||||||
BlockLocation midPoint = new BlockLocation(minLoc.worldName, midX, maxLoc.posY, midZ);
|
BlockLocation midPoint = new BlockLocation(minLoc.worldName, midX, maxLoc.posY, midZ);
|
||||||
var color = new Color(0, 255, 0, 100);
|
Color color;
|
||||||
debugPortal(player, portal.getMinLoc(), portal.getMaxLoc(), color, 1000, false);
|
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);
|
Debug.addMarker(player, midPoint, portal.getArgValues(NameTag.TAG_NAME)[0], color, SHOW_TICKS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -117,7 +139,15 @@ public class ShowPortalSubCommand implements SubCommand, SubCommand.SubCommandOn
|
|||||||
}, 1, 20);
|
}, 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 minX = Math.min(pos1.posX, pos2.posX);
|
||||||
int minY = Math.min(pos1.posY, pos2.posY);
|
int minY = Math.min(pos1.posY, pos2.posY);
|
||||||
int minZ = Math.min(pos1.posZ, pos2.posZ);
|
int minZ = Math.min(pos1.posZ, pos2.posZ);
|
||||||
@ -126,17 +156,54 @@ public class ShowPortalSubCommand implements SubCommand, SubCommand.SubCommandOn
|
|||||||
int maxY = Math.max(pos1.posY, pos2.posY);
|
int maxY = Math.max(pos1.posY, pos2.posY);
|
||||||
int maxZ = Math.max(pos1.posZ, pos2.posZ);
|
int maxZ = Math.max(pos1.posZ, pos2.posZ);
|
||||||
|
|
||||||
|
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 x = minX; x <= maxX; x++) {
|
||||||
for (int y = minY; y <= maxY; y++) {
|
for (int y = minY; y <= maxY; y++) {
|
||||||
for (int z = minZ; z <= maxZ; z++) {
|
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 pos = new BlockLocation(pos1.worldName, x, y, z);
|
var pos = new BlockLocation(pos1.worldName, x, y, z);
|
||||||
if ((pos.equals(pos1) || pos.equals(pos2)) && hideCorners)
|
boolean isTrigger = portal != null && portal.isTriggerBlock(world.getBlock(pos));
|
||||||
continue;
|
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);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ import com.sekwah.advancedportals.core.serializeddata.BlockLocation;
|
|||||||
import com.sekwah.advancedportals.core.serializeddata.DataTag;
|
import com.sekwah.advancedportals.core.serializeddata.DataTag;
|
||||||
import com.sekwah.advancedportals.core.registry.TagRegistry;
|
import com.sekwah.advancedportals.core.registry.TagRegistry;
|
||||||
import com.sekwah.advancedportals.core.serializeddata.PlayerLocation;
|
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.ActivationData;
|
||||||
import com.sekwah.advancedportals.core.warphandler.Tag;
|
import com.sekwah.advancedportals.core.warphandler.Tag;
|
||||||
|
|
||||||
@ -151,6 +152,18 @@ public class AdvancedPortal implements TagTarget {
|
|||||||
return tagList;
|
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) {
|
/*public void setTriggerBlocks(String[] triggerBlocks) {
|
||||||
this.triggerBlocks = triggerBlocks;
|
this.triggerBlocks = triggerBlocks;
|
||||||
}*/
|
}*/
|
||||||
|
@ -15,4 +15,8 @@ public interface ConfigRepository {
|
|||||||
void loadConfig(DataStorage dataStorage);
|
void loadConfig(DataStorage dataStorage);
|
||||||
|
|
||||||
int getVisibleRange();
|
int getVisibleRange();
|
||||||
|
|
||||||
|
int getMaxTriggerVisualisationSize();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -47,6 +47,11 @@ public class ConfigRepositoryImpl implements ConfigRepository {
|
|||||||
return this.config.visibleRange;
|
return this.config.visibleRange;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMaxTriggerVisualisationSize() {
|
||||||
|
return this.config.maxTriggerVisualisationSize;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void loadConfig(DataStorage dataStorage) {
|
public void loadConfig(DataStorage dataStorage) {
|
||||||
this.config = dataStorage.loadJson(Config.class, "config.json");
|
this.config = dataStorage.loadJson(Config.class, "config.json");
|
||||||
|
@ -22,7 +22,7 @@ public class PlayerTempData {
|
|||||||
/**
|
/**
|
||||||
* If to show portals near the player
|
* If to show portals near the player
|
||||||
*/
|
*/
|
||||||
private boolean portalVisible;
|
private boolean portalVisible = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If to show destination blocks near the player
|
* If to show destination blocks near the player
|
||||||
|
@ -29,4 +29,6 @@ public class Config {
|
|||||||
|
|
||||||
public int visibleRange = 50;
|
public int visibleRange = 50;
|
||||||
|
|
||||||
|
public int maxTriggerVisualisationSize = 1000;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user