protected DimensionCache dimensionCache;
protected Set<VillageProcessor> villageProcessors = new HashSet<>();
- private IVillageEventHandler eventHandler = null;
public void worldLoaded(World world) {
IChunkProvider chunkProvider = world.getChunkProvider();
DimensionProcessor boundingBoxCache = new DimensionProcessor(dimensionType);
dimensionCache.put(dimensionType, boundingBoxCache);
if (ConfigManager.drawVillages.getBoolean()) {
- villageProcessors.add(new VillageProcessor(world, dimensionType, eventHandler, boundingBoxCache));
+ villageProcessors.add(new VillageProcessor(world, boundingBoxCache));
}
}
}
dimensionCache = new DimensionCache();
}
- public void setEventHandler(IVillageEventHandler eventHandler) {
- this.eventHandler = eventHandler;
- }
-
public DimensionCache getDimensionCache() {
return dimensionCache;
}
import net.minecraft.village.Village;
import net.minecraft.village.VillageCollection;
import net.minecraft.world.World;
-import net.minecraft.world.dimension.DimensionType;
import java.util.HashMap;
import java.util.List;
public class VillageProcessor {
private World world;
- private DimensionType dimensionType;
- private IVillageEventHandler eventHandler;
private BoundingBoxCache boundingBoxCache;
private Map<Integer, BoundingBoxVillage> villageCache = new HashMap<>();
private boolean closed = false;
- VillageProcessor(World world, DimensionType dimensionType, IVillageEventHandler eventHandler, BoundingBoxCache boundingBoxCache) {
+ VillageProcessor(World world, BoundingBoxCache boundingBoxCache) {
this.world = world;
- this.dimensionType = dimensionType;
- this.eventHandler = eventHandler;
this.boundingBoxCache = boundingBoxCache;
}
VillageCollection villageCollection = world.getVillageCollection();
if (villageCollection != null) {
List<Village> villages = villageCollection.getVillageList();
- for(int i = 0; i < villages.size(); i++) {
- Village village = villages.get(i);
+ for (Village village : villages) {
int villageId = village.hashCode();
BoundingBoxVillage newVillage = oldVillages.get(villageId);
if (newVillage != null && newVillage.matches(village)) {
}
for (BoundingBoxVillage village : oldVillages.values()) {
boundingBoxCache.removeBoundingBox(village);
- if (eventHandler != null) {
- eventHandler.villageRemoved(dimensionType, village);
- }
}
for (BoundingBoxVillage village : newVillages.values()) {
boundingBoxCache.addBoundingBox(village);
public void close() {
closed = true;
world = null;
- eventHandler = null;
boundingBoxCache = null;
villageCache.clear();
}