Skip to content

Commit

Permalink
Measure in blocks, instead of tiles
Browse files Browse the repository at this point in the history
  • Loading branch information
TechnicJelle committed May 2, 2023
1 parent 1e397bd commit 281daa1
Show file tree
Hide file tree
Showing 7 changed files with 157 additions and 81 deletions.
52 changes: 27 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,48 +34,50 @@ areas=[
```
`is-whitelist` is a boolean that defines whether the areas list is a whitelist or a blacklist.\
When it's a whitelist, only the areas in the list will be rendered.\
When it's a blacklist, all areas will be rendered except the ones in the list.
When it's a blacklist, all areas will be rendered _except_ the ones in the list.

`debug-mode` is a boolean that defines whether the debug mode is enabled.\
When it's enabled, all areas will be marked on the map with a red border.\
This makes it easier to visualise the areas you're defining, before you (re)render the map.

All areas should be within the `areas` square brackets `[ ]`
All areas should be denoted within the `areas` square brackets `[ ]`

**Please be aware that the numbers in the configs are in *BlueMap tiles, not blocks!***\
There are currently two types of areas: Rectangle and Ellipse, which you configure like this:
The numbers in the configs are in blocks, but please be aware that BlueMap will round them down to the nearest tile.\
You can see the resulting tiles if you enable debug mode.

Rectangle:
There are currently two types of area available that you can use:

- Rectangle:
```hocon
{
type=rect
# X coordinate of the top left corner in tiles
x=-1
# Z coordinate of the top left corner in tiles
z=-1
# Height of the rectangle in tiles
height=2
# Width of the rectangle in tiles
width=2
type = rect
# X coordinate of one corner of the rectangle in blocks
x1 = -30
# Z coordinate of one corner of the rectangle in blocks
z1 = -30
# X coordinate of the opposite corner of the rectangle in blocks
x2 = 33
# Z coordinate of the opposite corner of the rectangle in blocks
z2 = 33
}
```

Ellipse:
- Ellipse:
```hocon
{
type=ellipse
# Center X coordinate in tiles
x=0
# Center Z coordinate in tiles
z=3
# Radius X in tiles
rx=5
# Radius Z in tiles
rz=3
type = ellipse
# Center X coordinate in blocks
x = 18
# Center Z coordinate in blocks
z = 114
# Radius X in blocks
rx = 176
# Radius Z in blocks
rz = 112
}
```

**Full example can be found [here](https://github.com/TechnicJelle/BlueMapAreaControl/blob/main/example.conf)**
**Full config example can be found [here](https://github.com/TechnicJelle/BlueMapAreaControl/blob/main/example.conf)**

## Support

Expand Down
36 changes: 18 additions & 18 deletions example.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,26 @@ debug-mode=false
areas=[
{
# The 2x2 chunks around 0,0
type=rect
# X coordinate of the top left corner in tiles
x=-1
# Z coordinate of the top left corner in tiles
z=-1
# Height of the rectangle in tiles
height=2
# Width of the rectangle in tiles
width=2
type = rect
# X coordinate of one corner of the rectangle in blocks
x1 = -30
# Z coordinate of one corner of the rectangle in blocks
z1 = -30
# X coordinate of the opposite corner of the rectangle in blocks
x2 = 33
# Z coordinate of the opposite corner of the rectangle in blocks
z2 = 33
}
{
# An ellipse below 0,0
type=ellipse
# Center X coordinate in tiles
x=0
# Center Z coordinate in tiles
z=3
# Radius X in tiles
rx=5
# Radius Z in tiles
rz=3
type = ellipse
# Center X coordinate in blocks
x = 18
# Center Z coordinate in blocks
z = 114
# Radius X in blocks
rx = 176
# Radius Z in blocks
rz = 112
}
]
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.technicjelle</groupId>
<artifactId>BlueMapAreaControl</artifactId>
<version>1.0</version>
<version>1.1</version>
<packaging>jar</packaging>

<name>BlueMapAreaControl</name>
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/com/technicjelle/bluemapareacontrol/Area.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@
public interface Area {
boolean isValid();

boolean containsTile(int x, int z);
void calculateTilePositions(BlueMapMap map);

boolean containsTile(int tx, int tz);

String debugString();

ShapeMarker createMarker(BlueMapMap map);
ShapeMarker createBlockMarker(BlueMapMap map);

ShapeMarker createTileMarker(BlueMapMap map);
}
52 changes: 42 additions & 10 deletions src/main/java/com/technicjelle/bluemapareacontrol/AreaEllipse.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,31 @@
import com.flowpowered.math.vector.Vector2i;
import de.bluecolored.bluemap.api.BlueMapMap;
import de.bluecolored.bluemap.api.markers.ShapeMarker;
import de.bluecolored.bluemap.api.math.Color;
import de.bluecolored.bluemap.api.math.Shape;
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
import org.spongepowered.configurate.objectmapping.meta.Comment;

@ConfigSerializable
public class AreaEllipse implements Area {
@Comment("Center X coordinate in tiles")
@Comment("Center X coordinate in blocks")
private final Integer x;
@Comment("Center Z coordinate in tiles")
@Comment("Center Z coordinate in blocks")
private final Integer z;

@Comment("Radius X in tiles")
@Comment("Radius X in blocks")
private final Integer rx;
@Comment("Radius Z in tiles")
@Comment("Radius Z in blocks")
private final Integer rz;

public static final String TYPE = "ellipse";
private final String type = TYPE;

private transient int tx;
private transient int tz;
private transient int trx;
private transient int trz;

public AreaEllipse() {
this.x = null;
this.z = null;
Expand All @@ -42,24 +48,50 @@ public boolean isValid() {
}

@Override
public boolean containsTile(int x, int z) {
return Math.pow(x - this.x, 2) / Math.pow(rx, 2) + Math.pow(z - this.z, 2) / Math.pow(rz, 2) <= 1;
public void calculateTilePositions(BlueMapMap map) {
Vector2i pos = map.posToTile(x, z);
tx = pos.getX();
tz = pos.getY();
Vector2i size = map.posToTile(rx, rz);
trx = size.getX();
trz = size.getY();
}

@Override
public boolean containsTile(int tx, int tz) {
return Math.pow(tx - this.tx, 2) / Math.pow(trx, 2) + Math.pow(tz - this.tz, 2) / Math.pow(trz, 2) <= 1;
}

@Override
public String debugString() {
return "AreaEllipse: x=" + x + ", z=" + z + ", rx=" + rx + ", ry=" + rz;
return "AreaEllipse: tx=" + tx + ", tz=" + tz + ", trx=" + trx + ", trz=" + trz;
}

@Override
public ShapeMarker createBlockMarker(BlueMapMap map) {
Shape shape = Shape.createEllipse(x, z, rx, rz, 24);
return ShapeMarker.builder()
.label(debugString())
.shape(shape, 0)
.depthTestEnabled(false)
.lineColor(new Color(0, 0, 255, 1f))
.fillColor(new Color(0, 0, 200, 0.3f))
.build();
}

@Override
public ShapeMarker createMarker(BlueMapMap map) {
public ShapeMarker createTileMarker(BlueMapMap map) {
Vector2i tileSize = map.getTileSize();
int sx = tileSize.getX();
int sz = tileSize.getY();
Vector2i tileOffset = map.getTileOffset();
int ox = tileOffset.getX() + sx/2;
int oz = tileOffset.getY() + sz/2;
Shape shape = Shape.createEllipse(ox+ x *sx, oz+ z *sz, (rx+0.5)*sx, (rz +0.5)*sz, 24);
return new ShapeMarker(debugString(), shape, 90);
Shape shape = Shape.createEllipse(ox+tx*sx, oz+tz*sz, (trx+0.5)*sx, (trz+0.5)*sz, 24);
return ShapeMarker.builder()
.label(debugString())
.shape(shape, 1)
.depthTestEnabled(false)
.build();
}
}
83 changes: 59 additions & 24 deletions src/main/java/com/technicjelle/bluemapareacontrol/AreaRect.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,63 +3,98 @@
import com.flowpowered.math.vector.Vector2i;
import de.bluecolored.bluemap.api.BlueMapMap;
import de.bluecolored.bluemap.api.markers.ShapeMarker;
import de.bluecolored.bluemap.api.math.Color;
import de.bluecolored.bluemap.api.math.Shape;
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
import org.spongepowered.configurate.objectmapping.meta.Comment;

@ConfigSerializable
public class AreaRect implements Area {
@Comment("X coordinate of the top left corner in tiles")
private final Integer x;
@Comment("Z coordinate of the top left corner in tiles")
private final Integer z;
@Comment("X coordinate of one corner of the rectangle in blocks")
private final Integer x1;
@Comment("Z coordinate of one corner of the rectangle in blocks")
private final Integer z1;

@Comment("Width of the rectangle in tiles")
private final Integer width;
@Comment("Height of the rectangle in tiles")
private final Integer height;
@Comment("X coordinate of the opposite corner of the rectangle in blocks")
private final Integer x2;
@Comment("Z coordinate of the opposite corner of the rectangle in blocks")
private final Integer z2;

public static final String TYPE = "rect";
private final String type = TYPE;

private transient int tx1; //tile top left
private transient int tz1; //tile top left
private transient int tx2; //tile bottom right
private transient int tz2; //tile bottom right

private AreaRect() {
this.x = null;
this.z = null;
this.width = null;
this.height = null;
this.x1 = null;
this.z1 = null;
this.x2 = null;
this.z2 = null;
}

public AreaRect(int x, int z, int width, int height) {
this.x = x;
this.z = z;
this.width = width;
this.height = height;
public AreaRect(int x1, int z1, int x2, int z2) {
//make sure x1/z1 is the top left corner and x2/z2 is the bottom right corner
this.x1 = Math.min(x1, x2);
this.z1 = Math.min(z1, z2);
this.x2 = Math.max(x1, x2);
this.z2 = Math.max(z1, z2);
}

@Override
public boolean isValid() {
return x != null && z != null && width != null && height != null && width > 0 && height > 0;
return x1 != null && z1 != null && x2 != null && z2 != null && x1 < x2 && z1 < z2;
}

@Override
public void calculateTilePositions(BlueMapMap map) {
Vector2i pos = map.posToTile(x1, z1);
tx1 = pos.getX();
tz1 = pos.getY();
Vector2i size = map.posToTile(x2, z2);
tx2 = size.getX();
tz2 = size.getY();
}

@Override
public boolean containsTile(int x, int z) {
return x >= this.x && x < this.x + width && z >= this.z && z < this.z + height;
public boolean containsTile(int tx, int tz) {
return tx >= tx1 && tx <= tx2 && tz >= tz1 && tz <= tz2;
}

@Override
public String debugString() {
return "AreaRect: x=" + x + ", z=" + z + ", width=" + width + ", height=" + height;
return "AreaRect tx1: " + tx1 + " tz1: " + tz1 + " tx2: " + tx2 + " tz2: " + tz2;
}

@Override
public ShapeMarker createBlockMarker(BlueMapMap map) {
Shape shape = Shape.createRect(x1, z1, x2+1, z2+1); //+1 because the shape is exclusive on the right and bottom side
return ShapeMarker.builder()
.label(debugString())
.shape(shape, 0)
.depthTestEnabled(false)
.lineColor(new Color(0, 0, 255, 1f))
.fillColor(new Color(0, 0, 200, 0.3f))
.build();
}

@Override
public ShapeMarker createMarker(BlueMapMap map) {
public ShapeMarker createTileMarker(BlueMapMap map) {
Vector2i tileSize = map.getTileSize();
int sx = tileSize.getX();
int sz = tileSize.getY();
Vector2i tileOffset = map.getTileOffset();
int ox = tileOffset.getX();
int oz = tileOffset.getY();
Shape shape = Shape.createRect(ox+x*sx, oz+z*sz, ox+(x + width)*sx, oz+(z + height)*sz);
return new ShapeMarker(debugString(), shape, 90);
Shape shape = Shape.createRect(ox+tx1*sx, oz+tz1*sz, ox+(tx2+1)*sx, oz+(tz2+1)*sz);
return ShapeMarker.builder()
.label(debugString())
.shape(shape, 1)
.depthTestEnabled(false)
.lineColor(new Color(255, 0, 0, 1f))
.fillColor(new Color(200, 0, 0, 0.3f))
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public void onEnable() {
List<? extends ConfigurationNode> children = areasNode.childrenList();
for (ConfigurationNode child : children) {
Area area = getArea(child);
area.calculateTilePositions(map);
areas.add(area);
}
} catch (Exception e) {
Expand All @@ -122,10 +123,12 @@ public void onEnable() {

for (Area area : areas) {
getLogger().info('\t' + area.debugString());
markerSet.put(area.debugString() + area, area.createMarker(map));
markerSet.put(area.debugString() + "tile" + area, area.createTileMarker(map));
// markerSet.put(area.debugString() + "block" + area, area.createBlockMarker(map));
}
}


map.setTileFilter(tilePos -> {
boolean inArea = false;
for (Area area : areas) {
Expand Down

0 comments on commit 281daa1

Please sign in to comment.