Skip to content

Commit

Permalink
feat: show triggerblocks in debug view
Browse files Browse the repository at this point in the history
  • Loading branch information
sekwah41 committed Dec 19, 2023
1 parent 02d58e5 commit a6de44b
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand All @@ -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) {
Expand Down Expand Up @@ -90,34 +103,51 @@ 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();
BlockLocation maxLoc = portal.getMaxLoc();
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);
}
}
}
}, 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);
Expand All @@ -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);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -151,6 +152,18 @@ public ArrayList<DataTag> 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;
}*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ public interface ConfigRepository {
void loadConfig(DataStorage dataStorage);

int getVisibleRange();

int getMaxTriggerVisualisationSize();


}
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ public class Config {

public int visibleRange = 50;

public int maxTriggerVisualisationSize = 1000;

}

0 comments on commit a6de44b

Please sign in to comment.