Skip to content

Commit

Permalink
map scripts: handle out-of-view objects properly
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Aug 19, 2021
1 parent 3bb2f52 commit 8e478c6
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
Expand Up @@ -145,8 +145,7 @@ public void execute(ScriptEntry scriptEntry) {
for (PlayerTag player : players) {
Player ent = player.getPlayerEntity();
if (sound.asBoolean()) {
NMSHandler.getSoundHelper().playSound(ent, location,
Sound.BLOCK_CHEST_OPEN, 1, 1, "BLOCKS");
NMSHandler.getSoundHelper().playSound(ent, location, Sound.BLOCK_CHEST_OPEN, 1, 1, "BLOCKS");
}
packetHelper.showBlockAction(ent, location, 1, 1);
}
Expand All @@ -155,8 +154,7 @@ public void execute(ScriptEntry scriptEntry) {
for (PlayerTag player : players) {
Player ent = player.getPlayerEntity();
if (sound.asBoolean()) {
NMSHandler.getSoundHelper().playSound(ent, location,
Sound.BLOCK_CHEST_CLOSE, 1, 1, "BLOCKS");
NMSHandler.getSoundHelper().playSound(ent, location, Sound.BLOCK_CHEST_CLOSE, 1, 1, "BLOCKS");
}
packetHelper.showBlockAction(ent, location, 1, 0);
}
Expand Down
Expand Up @@ -58,7 +58,12 @@ public Map<String, Object> getSaveData() {
@Override
public void render(MapView mapView, MapCanvas mapCanvas, PlayerTag player, UUID uuid) {
try {
org.bukkit.map.MapCursor cursor = new org.bukkit.map.MapCursor((byte) (getX(player) * 2), (byte) (getY(player) * 2), getDirection(player), getType(player).getValue(), isVisibleTo(player));
int x = getX(player);
int z = getY(player);
if (x < 0 || z < 0 || x > 127 || z > 127) {
return;
}
org.bukkit.map.MapCursor cursor = new org.bukkit.map.MapCursor((byte) ((x * 2) - 128), (byte) ((z * 2) - 128), getDirection(player), getType(player).getValue(), isVisibleTo(player));
mapCanvas.getCursors().addCursor(cursor);
cursors.put(uuid, cursor);
}
Expand Down
Expand Up @@ -40,12 +40,12 @@ public void render(MapView mapView, MapCanvas mapCanvas, PlayerTag player, UUID
Color color = ColorTag.valueOf(tag(colorTag, player), getTagContext(player)).getColor();
for (int x = -radius; x < radius; x++) {
int finalX = baseX + x;
if (finalX >= 128) {
if (finalX < 0 || finalX > 127) {
continue;
}
for (int y = -radius; y < radius; y++) {
int finalY = baseY + y;
if (finalY >= 128) {
if (finalY < 0 || finalY > 127) {
continue;
}
if (((x + 0.5) * (x + 0.5)) + ((y + 0.5) * (y + 0.5)) <= (radius * radius)) {
Expand Down
Expand Up @@ -38,8 +38,7 @@ public int getX(PlayerTag player) {
int x = (int) Double.parseDouble(tag(xTag, player));
if (worldCoordinates && lastMap != null) {
float f = (float) (x - lastMap.getCenterX()) / (2 << (lastMap.getScale().getValue()));
int bx = ((int) ((f * 2.0F) + 0.5D));
return (bx < -127 ? -127 : (bx > 127 ? 127 : bx));
return ((int) ((f * 2.0F) + 0.5D));
}
return x;
}
Expand All @@ -48,8 +47,7 @@ public int getY(PlayerTag player) {
int y = (int) Double.parseDouble(tag(yTag, player));
if (worldCoordinates && lastMap != null) {
float f1 = (float) (y - lastMap.getCenterZ()) / (2 << (lastMap.getScale().getValue()));
int by = ((int) ((f1 * 2.0F) + 0.5D));
return (by < -127 ? -127 : (by > 127 ? 127 : by));
return ((int) ((f1 * 2.0F) + 0.5D));
}
return y;
}
Expand Down

0 comments on commit 8e478c6

Please sign in to comment.