package com.irtimaled.bbor.client.providers;
import com.irtimaled.bbor.client.Player;
-import com.irtimaled.bbor.common.Dimensions;
import com.irtimaled.bbor.common.models.BoundingBoxBeacon;
import com.irtimaled.bbor.common.models.Coords;
import java.util.concurrent.ConcurrentHashMap;
public class BeaconProvider implements IBoundingBoxProvider<BoundingBoxBeacon> {
- private static final Map<Integer, Map<Coords, BoundingBoxBeacon>> dimensionsCache = buildBeaconsCache();
-
- private static Map<Integer, Map<Coords, BoundingBoxBeacon>> buildBeaconsCache() {
- Map<Integer, Map<Coords, BoundingBoxBeacon>> map = new HashMap<>();
- map.put(Dimensions.OVERWORLD, new ConcurrentHashMap<>());
- map.put(Dimensions.NETHER, new ConcurrentHashMap<>());
- map.put(Dimensions.THE_END, new ConcurrentHashMap<>());
- return map;
- }
+ private static final Map<Integer, Map<Coords, BoundingBoxBeacon>> dimensionsCache = new HashMap<>();
private static Map<Coords, BoundingBoxBeacon> getCache(int dimensionId) {
return dimensionsCache.computeIfAbsent(dimensionId, i -> new ConcurrentHashMap<>());
import com.irtimaled.bbor.client.Player;
import com.irtimaled.bbor.common.BoundingBoxType;
-import com.irtimaled.bbor.common.Dimensions;
import com.irtimaled.bbor.common.models.BoundingBoxCuboid;
import com.irtimaled.bbor.common.models.Coords;
import java.util.concurrent.ConcurrentHashMap;
public class CustomBoxProvider implements IBoundingBoxProvider<BoundingBoxCuboid> {
- private static final Map<Integer, Map<Integer, BoundingBoxCuboid>> dimensionCache = buildDimensionCache();
-
- private static Map<Integer, Map<Integer, BoundingBoxCuboid>> buildDimensionCache() {
- Map<Integer, Map<Integer, BoundingBoxCuboid>> map = new HashMap<>();
- map.put(Dimensions.OVERWORLD, new ConcurrentHashMap<>());
- map.put(Dimensions.NETHER, new ConcurrentHashMap<>());
- map.put(Dimensions.THE_END, new ConcurrentHashMap<>());
- return map;
- }
+ private final static Map<Integer, Map<Integer, BoundingBoxCuboid>> dimensionCache = new HashMap<>();
private static int getHashKey(Coords minCoords, Coords maxCoords) {
return (31 + minCoords.hashCode()) * 31 + maxCoords.hashCode();
public static final BoundingBoxType Custom = register(Color.WHITE, "Custom", ConfigManager.drawCustomBoxes);
private static BoundingBoxType register(Color color, String name, Setting<Boolean> shouldRenderSetting) {
- return structureTypeMap.computeIfAbsent(name.hashCode(), k -> new BoundingBoxType(color, name, shouldRenderSetting));
+ BoundingBoxType type = structureTypeMap.computeIfAbsent(name.hashCode(), k -> new BoundingBoxType(color, name, shouldRenderSetting));
+ ChunkProcessor.registerSupportedStructure(type);
+ return type;
}
public static BoundingBoxType getByNameHash(Integer nameHash) {
--- /dev/null
+package com.irtimaled.bbor.common;
+
+import com.irtimaled.bbor.common.models.AbstractBoundingBox;
+import com.irtimaled.bbor.common.models.BoundingBoxCuboid;
+import com.irtimaled.bbor.common.models.BoundingBoxMobSpawner;
+import com.irtimaled.bbor.common.models.Coords;
+import net.minecraft.tileentity.TileEntity;
+import net.minecraft.tileentity.TileEntityMobSpawner;
+import net.minecraft.util.math.MutableBoundingBox;
+import net.minecraft.world.chunk.Chunk;
+import net.minecraft.world.gen.feature.structure.StructurePiece;
+import net.minecraft.world.gen.feature.structure.StructureStart;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+class ChunkProcessor {
+ private static final Set<BoundingBoxType> supportedStructures = new HashSet<>();
+
+ static void registerSupportedStructure(BoundingBoxType type) {
+ supportedStructures.add(type);
+ }
+
+ ChunkProcessor(BoundingBoxCache boundingBoxCache) {
+ this.boundingBoxCache = boundingBoxCache;
+ }
+
+ private final BoundingBoxCache boundingBoxCache;
+
+ private void addStructures(BoundingBoxType type, Map<String, StructureStart> structureMap) {
+ StructureStart structureStart = structureMap.get(type.getName());
+ if (structureStart == null) return;
+
+ MutableBoundingBox bb = structureStart.getBoundingBox();
+ if (bb == null) return;
+
+ AbstractBoundingBox boundingBox = buildStructure(bb, type);
+ if (boundingBoxCache.isCached(boundingBox)) return;
+
+ Set<AbstractBoundingBox> structureBoundingBoxes = new HashSet<>();
+ for (StructurePiece structureComponent : structureStart.getComponents()) {
+ structureBoundingBoxes.add(buildStructure(structureComponent.getBoundingBox(), type));
+ }
+ boundingBoxCache.addBoundingBoxes(boundingBox, structureBoundingBoxes);
+ }
+
+ private AbstractBoundingBox buildStructure(MutableBoundingBox bb, BoundingBoxType type) {
+ Coords min = new Coords(bb.minX, bb.minY, bb.minZ);
+ Coords max = new Coords(bb.maxX, bb.maxY, bb.maxZ);
+ return BoundingBoxCuboid.from(min, max, type);
+ }
+
+ private void addMobSpawners(Chunk chunk) {
+ Collection<TileEntity> tileEntities = chunk.getTileEntityMap().values();
+ for (TileEntity tileEntity : tileEntities) {
+ TileEntityMobSpawner spawner = TypeHelper.as(tileEntity, TileEntityMobSpawner.class);
+ if (spawner != null) {
+ Coords coords = new Coords(spawner.getPos());
+ boundingBoxCache.addBoundingBox(BoundingBoxMobSpawner.from(coords));
+ }
+ }
+ }
+
+ void process(Chunk chunk) {
+ Map<String, StructureStart> structureMap = chunk.getStructureStarts();
+ if (structureMap.size() > 0) {
+ supportedStructures.forEach(type -> addStructures(type, structureMap));
+ }
+ addMobSpawners(chunk);
+ }
+}
package com.irtimaled.bbor.common;
import com.irtimaled.bbor.Logger;
-import com.irtimaled.bbor.common.chunkProcessors.AbstractChunkProcessor;
-import com.irtimaled.bbor.common.chunkProcessors.EndChunkProcessor;
-import com.irtimaled.bbor.common.chunkProcessors.NetherChunkProcessor;
-import com.irtimaled.bbor.common.chunkProcessors.OverworldChunkProcessor;
import com.irtimaled.bbor.common.events.*;
import com.irtimaled.bbor.common.messages.AddBoundingBox;
import com.irtimaled.bbor.common.messages.InitializeClient;
private final Map<Integer, ServerPlayer> players = new ConcurrentHashMap<>();
private final Map<Integer, Set<AbstractBoundingBox>> playerBoundingBoxesCache = new HashMap<>();
private final Map<Integer, VillageProcessor> villageProcessors = new HashMap<>();
- private final Map<Integer, AbstractChunkProcessor> chunkProcessors = new HashMap<>();
+ private final Map<Integer, ChunkProcessor> chunkProcessors = new HashMap<>();
private final Map<Integer, BoundingBoxCache> dimensionCache = new ConcurrentHashMap<>();
private Long seed = null;
private Integer spawnX = null;
private void worldLoaded(WorldLoaded event) {
int dimensionId = event.getDimensionId();
long seed = event.getSeed();
- BoundingBoxCache boundingBoxCache = getOrCreateCache(dimensionId);
- AbstractChunkProcessor chunkProcessor = null;
- switch (dimensionId) {
- case Dimensions.OVERWORLD:
- setSeed(seed);
- setWorldSpawn(event.getSpawnX(), event.getSpawnZ());
- chunkProcessor = new OverworldChunkProcessor(boundingBoxCache);
- break;
- case Dimensions.NETHER:
- chunkProcessor = new NetherChunkProcessor(boundingBoxCache);
- break;
- case Dimensions.THE_END:
- chunkProcessor = new EndChunkProcessor(boundingBoxCache);
- break;
+ if (dimensionId == Dimensions.OVERWORLD) {
+ setSeed(seed);
+ setWorldSpawn(event.getSpawnX(), event.getSpawnZ());
}
Logger.info("create world dimension: %s (seed: %d)", dimensionId, seed);
- chunkProcessors.put(dimensionId, chunkProcessor);
+ BoundingBoxCache boundingBoxCache = getOrCreateCache(dimensionId);
+ chunkProcessors.put(dimensionId, new ChunkProcessor(boundingBoxCache));
villageProcessors.put(dimensionId, new VillageProcessor(dimensionId, boundingBoxCache));
}
private void chunkLoaded(ChunkLoaded event) {
- AbstractChunkProcessor chunkProcessor = chunkProcessors.get(event.getDimensionId());
+ ChunkProcessor chunkProcessor = chunkProcessors.get(event.getDimensionId());
if (chunkProcessor == null) return;
chunkProcessor.process(event.getChunk());
public class Dimensions {
public static final int OVERWORLD = 0;
- public static final int NETHER = -1;
- public static final int THE_END = 1;
}
+++ /dev/null
-package com.irtimaled.bbor.common.chunkProcessors;
-
-import com.irtimaled.bbor.common.BoundingBoxCache;
-import com.irtimaled.bbor.common.BoundingBoxType;
-import com.irtimaled.bbor.common.TypeHelper;
-import com.irtimaled.bbor.common.models.AbstractBoundingBox;
-import com.irtimaled.bbor.common.models.BoundingBoxCuboid;
-import com.irtimaled.bbor.common.models.BoundingBoxMobSpawner;
-import com.irtimaled.bbor.common.models.Coords;
-import net.minecraft.tileentity.TileEntity;
-import net.minecraft.tileentity.TileEntityMobSpawner;
-import net.minecraft.util.math.MutableBoundingBox;
-import net.minecraft.world.chunk.Chunk;
-import net.minecraft.world.gen.feature.structure.StructurePiece;
-import net.minecraft.world.gen.feature.structure.StructureStart;
-
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-public abstract class AbstractChunkProcessor {
- Set<BoundingBoxType> supportedStructures = new HashSet<>();
-
- AbstractChunkProcessor(BoundingBoxCache boundingBoxCache) {
- this.boundingBoxCache = boundingBoxCache;
- }
-
- private final BoundingBoxCache boundingBoxCache;
-
- private void addStructures(BoundingBoxType type, Map<String, StructureStart> structureMap) {
- StructureStart structureStart = structureMap.get(type.getName());
- if (structureStart == null) return;
-
- MutableBoundingBox bb = structureStart.getBoundingBox();
- if (bb == null) return;
-
- AbstractBoundingBox boundingBox = buildStructure(bb, type);
- if (boundingBoxCache.isCached(boundingBox)) return;
-
- Set<AbstractBoundingBox> structureBoundingBoxes = new HashSet<>();
- for (StructurePiece structureComponent : structureStart.getComponents()) {
- structureBoundingBoxes.add(buildStructure(structureComponent.getBoundingBox(), type));
- }
- boundingBoxCache.addBoundingBoxes(boundingBox, structureBoundingBoxes);
- }
-
- private AbstractBoundingBox buildStructure(MutableBoundingBox bb, BoundingBoxType type) {
- Coords min = new Coords(bb.minX, bb.minY, bb.minZ);
- Coords max = new Coords(bb.maxX, bb.maxY, bb.maxZ);
- return BoundingBoxCuboid.from(min, max, type);
- }
-
- private void addMobSpawners(Chunk chunk) {
- Collection<TileEntity> tileEntities = chunk.getTileEntityMap().values();
- for (TileEntity tileEntity : tileEntities) {
- TileEntityMobSpawner spawner = TypeHelper.as(tileEntity, TileEntityMobSpawner.class);
- if (spawner != null) {
- Coords coords = new Coords(spawner.getPos());
- boundingBoxCache.addBoundingBox(BoundingBoxMobSpawner.from(coords));
- }
- }
- }
-
- public void process(Chunk chunk) {
- Map<String, StructureStart> structureMap = chunk.getStructureStarts();
- if (structureMap.size() > 0) {
- supportedStructures.forEach(type -> addStructures(type, structureMap));
- }
- addMobSpawners(chunk);
- }
-}
+++ /dev/null
-package com.irtimaled.bbor.common.chunkProcessors;
-
-import com.irtimaled.bbor.common.BoundingBoxCache;
-import com.irtimaled.bbor.common.BoundingBoxType;
-
-public class EndChunkProcessor extends AbstractChunkProcessor {
- public EndChunkProcessor(BoundingBoxCache boundingBoxCache) {
- super(boundingBoxCache);
- supportedStructures.add(BoundingBoxType.EndCity);
- }
-}
+++ /dev/null
-package com.irtimaled.bbor.common.chunkProcessors;
-
-import com.irtimaled.bbor.common.BoundingBoxCache;
-import com.irtimaled.bbor.common.BoundingBoxType;
-
-public class NetherChunkProcessor extends AbstractChunkProcessor {
- public NetherChunkProcessor(BoundingBoxCache boundingBoxCache) {
- super(boundingBoxCache);
- supportedStructures.add(BoundingBoxType.NetherFortress);
- }
-}
+++ /dev/null
-package com.irtimaled.bbor.common.chunkProcessors;
-
-import com.irtimaled.bbor.common.BoundingBoxCache;
-import com.irtimaled.bbor.common.BoundingBoxType;
-
-public class OverworldChunkProcessor extends AbstractChunkProcessor {
- public OverworldChunkProcessor(BoundingBoxCache boundingBoxCache) {
- super(boundingBoxCache);
- supportedStructures.add(BoundingBoxType.Village);
- supportedStructures.add(BoundingBoxType.DesertTemple);
- supportedStructures.add(BoundingBoxType.JungleTemple);
- supportedStructures.add(BoundingBoxType.WitchHut);
- supportedStructures.add(BoundingBoxType.OceanMonument);
- supportedStructures.add(BoundingBoxType.Stronghold);
- supportedStructures.add(BoundingBoxType.Mansion);
- supportedStructures.add(BoundingBoxType.MineShaft);
- supportedStructures.add(BoundingBoxType.Shipwreck);
- supportedStructures.add(BoundingBoxType.OceanRuin);
- supportedStructures.add(BoundingBoxType.BuriedTreasure);
- supportedStructures.add(BoundingBoxType.Igloo);
- supportedStructures.add(BoundingBoxType.PillagerOutpost);
- }
-}