Skip to content

Commit ff0e8ee

Browse files
authored
Merge pull request #397 from BentoBoxWorld/390_oraxen_furniture
Add Oraxen furniture mechanic support for island levelling
2 parents b83349a + 6a319f3 commit ff0e8ee

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

src/main/java/world/bentobox/level/calculators/IslandLevelCalculator.java

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,13 @@
3131
import org.bukkit.block.ShulkerBox;
3232
import org.bukkit.block.data.BlockData;
3333
import org.bukkit.block.data.type.Slab;
34+
import org.bukkit.entity.Entity;
3435
import org.bukkit.entity.EntityType;
3536
import org.bukkit.inventory.ItemStack;
3637
import org.bukkit.inventory.meta.BlockStateMeta;
3738

39+
import io.th0rgal.oraxen.mechanics.provided.gameplay.furniture.FurnitureMechanic;
40+
3841
import com.bgsoftware.wildstacker.api.WildStackerAPI;
3942
import com.bgsoftware.wildstacker.api.objects.StackedBarrel;
4043
import com.google.common.collect.Multiset;
@@ -73,6 +76,7 @@ public class IslandLevelCalculator {
7376
private final int seaHeight;
7477
private final List<Location> stackedBlocks = new ArrayList<>();
7578
private final Set<Chunk> chestBlocks = new HashSet<>();
79+
private final Set<Chunk> furnitureChunks = new HashSet<>();
7680
private final Map<Location, Boolean> spawners = new HashMap<>();
7781

7882
/**
@@ -473,6 +477,10 @@ record ChunkPair(World world, Chunk chunk, ChunkSnapshot chunkSnapshot) {
473477
}
474478

475479
private void scanAsync(ChunkPair cp) {
480+
// Track chunks for Oraxen furniture entity scanning (done on main thread later)
481+
if (BentoBox.getInstance().getHooks().getHook("Oraxen").isPresent()) {
482+
furnitureChunks.add(cp.chunk);
483+
}
476484
// Get the chunk coordinates and island boundaries once per chunk scan
477485
int chunkX = cp.chunk.getX() << 4;
478486
int chunkZ = cp.chunk.getZ() << 4;
@@ -741,6 +749,7 @@ public void scanIsland(Pipeliner pipeliner) {
741749
// Chunk finished
742750
// This was the last chunk. Handle stacked blocks, spawners, chests and exit
743751
handleStackedBlocks().thenCompose(v -> handleSpawners()).thenCompose(v -> handleChests())
752+
.thenCompose(v -> handleOraxenFurniture())
744753
.thenRun(() -> {
745754
this.tidyUp();
746755
this.getR().complete(getResults());
@@ -782,6 +791,50 @@ private CompletableFuture<Void> handleChests() {
782791
return CompletableFuture.allOf(futures.toArray(new CompletableFuture[0]));
783792
}
784793

794+
/**
795+
* Scans entities in each island chunk for Oraxen furniture and counts them toward the island level.
796+
* Furniture is entity-based in Oraxen (item displays / armor stands), so it is invisible to the
797+
* normal block scanner. Only the base entity of each furniture piece is counted to avoid
798+
* double-counting multi-entity furniture.
799+
*
800+
* @return a CompletableFuture that completes when all chunks have been checked
801+
*/
802+
private CompletableFuture<Void> handleOraxenFurniture() {
803+
if (!BentoBox.getInstance().getHooks().getHook("Oraxen").isPresent() || furnitureChunks.isEmpty()) {
804+
return CompletableFuture.completedFuture(null);
805+
}
806+
int minX = island.getMinProtectedX();
807+
int maxX = island.getMaxProtectedX();
808+
int minZ = island.getMinProtectedZ();
809+
int maxZ = island.getMaxProtectedZ();
810+
List<CompletableFuture<Void>> futures = new ArrayList<>();
811+
for (Chunk chunk : furnitureChunks) {
812+
CompletableFuture<Void> future = Util.getChunkAtAsync(chunk.getWorld(), chunk.getX(), chunk.getZ())
813+
.thenAccept(c -> {
814+
for (Entity entity : c.getEntities()) {
815+
// Only count the root/base entity of each furniture piece
816+
if (!OraxenHook.isBaseEntity(entity)) {
817+
continue;
818+
}
819+
Location loc = entity.getLocation();
820+
// Confirm entity is within the island's protected bounds
821+
if (loc.getBlockX() < minX || loc.getBlockX() >= maxX
822+
|| loc.getBlockZ() < minZ || loc.getBlockZ() >= maxZ) {
823+
continue;
824+
}
825+
FurnitureMechanic mechanic = OraxenHook.getFurnitureMechanic(entity);
826+
if (mechanic == null) {
827+
continue;
828+
}
829+
boolean belowSeaLevel = seaHeight > 0 && loc.getBlockY() <= seaHeight;
830+
checkBlock("oraxen:" + mechanic.getItemID(), belowSeaLevel);
831+
}
832+
});
833+
futures.add(future);
834+
}
835+
return CompletableFuture.allOf(futures.toArray(new CompletableFuture[0]));
836+
}
837+
785838
private CompletableFuture<Void> handleStackedBlocks() {
786839
// Deal with any stacked blocks
787840
List<CompletableFuture<Void>> futures = new ArrayList<>();

0 commit comments

Comments
 (0)