Skip to content

Commit

Permalink
Improve fire+lava check
Browse files Browse the repository at this point in the history
  • Loading branch information
emortaldev committed Sep 1, 2023
1 parent c9e36e9 commit 518b89a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

public class ChestListener {

private static TaskSchedule CHEST_REFILL_INTERVAL = TaskSchedule.seconds(80);
private static final TaskSchedule CHEST_REFILL_INTERVAL = TaskSchedule.seconds(80);

public static void registerListener(EventNode<InstanceEvent> eventNode, BattleGame game) {
Set<Point> chests = new HashSet<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import net.kyori.adventure.text.format.TextDecoration;
import net.kyori.adventure.title.Title;
import net.minestom.server.coordinate.Point;
import net.minestom.server.coordinate.Vec;
import net.minestom.server.entity.GameMode;
import net.minestom.server.entity.Player;
import net.minestom.server.entity.damage.DamageType;
Expand All @@ -28,8 +27,7 @@
import org.jetbrains.annotations.Nullable;

import java.time.Duration;
import java.util.HashSet;
import java.util.Set;
import java.util.Iterator;

import static net.kyori.adventure.title.Title.DEFAULT_TIMES;

Expand Down Expand Up @@ -92,13 +90,11 @@ public static void registerListener(EventNode<InstanceEvent> eventNode, BattleGa
// }
// }

Set<Point> blocksInHitbox = getPointsBetween(
e.getPlayer().getBoundingBox().relativeStart().add(e.getPlayer().getPosition()),
e.getPlayer().getBoundingBox().relativeEnd().add(e.getPlayer().getPosition())
);

for (Point pos : blocksInHitbox) {
Block block = e.getInstance().getBlock(pos, Block.Getter.Condition.TYPE);
Iterator<Point> blocksInHitbox = e.getPlayer().getBoundingBox().getBlocks(e.getPlayer().getPosition());

while (blocksInHitbox.hasNext()) {
Block block = e.getInstance().getBlock(blocksInHitbox.next(), Block.Getter.Condition.TYPE);

// TODO: Could probably be cleaner
if (block.compare(Block.WATER)) {
Expand Down Expand Up @@ -184,26 +180,4 @@ public static void playerDied(BattleGame game, Player player, @Nullable Player k

}


private static Set<Point> getPointsBetween(Point a, Point b) {
Set<Point> points = new HashSet<>();

int minX = Math.min(a.blockX(), b.blockX());
int maxX = Math.max(a.blockX(), b.blockX());
int minY = Math.min(a.blockY(), b.blockY());
int maxY = Math.max(a.blockY(), b.blockY());
int minZ = Math.min(a.blockZ(), b.blockZ());
int maxZ = Math.max(a.blockZ(), b.blockZ());

for (int x = minX; x <= maxX; x++) {
for (int y = minY; y <= maxY; y++) {
for (int z = minZ; z <= maxZ; z++) {
points.add(new Vec(x, y, z));
}
}
}

return points;
}

}

0 comments on commit 518b89a

Please sign in to comment.