public Chunk(World worldIn, int x, int z) { this.storageArrays = new ExtendedBlockStorage[16]; this.blockBiomeArray = new byte[256]; this.precipitationHeightMap = new int[256]; this.updateSkylightColumns = new boolean[256]; this.chunkTileEntityMap = Maps.<BlockPos, TileEntity>newHashMap(); this.queuedLightChecks = 4096; this.tileEntityPosQueue = Queues.<BlockPos>newConcurrentLinkedQueue(); this.entityLists = (ClassInheritanceMultiMap[])(new ClassInheritanceMultiMap[16]); this.worldObj = worldIn; this.xPosition = x; this.zPosition = z; this.heightMap = new int[256]; for (int i = 0; i < this.entityLists.length; ++i) { this.entityLists[i] = new ClassInheritanceMultiMap(Entity.class); } Arrays.fill((int[])this.precipitationHeightMap, (int) - 999); Arrays.fill(this.blockBiomeArray, (byte) - 1); }
public static Chunk fetchDormantChunk(long coords, World world) { if (dormantChunkCacheSize == 0) return null; // Don't bother with maps at all if its never gonna get a response Cache<Long, Chunk> cache = dormantChunkCache.get(world); if (cache == null) { return null; } Chunk chunk = cache.getIfPresent(coords); if (chunk != null) { for (ClassInheritanceMultiMap<Entity> eList : chunk.getEntityLists()) { Iterator<Entity> itr = eList.iterator(); while (itr.hasNext()) { (itr.next()).resetEntityId(); } } } return chunk; }
/** * Called when this Chunk is unloaded by the ChunkProvider */ public void onChunkUnload() { this.isChunkLoaded = false; for (TileEntity tileentity : this.chunkTileEntityMap.values()) { this.worldObj.markTileEntityForRemoval(tileentity); } for (ClassInheritanceMultiMap<Entity> classinheritancemultimap : this.entityLists) { this.worldObj.unloadEntities(classinheritancemultimap); } net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.world.ChunkEvent.Unload(this)); }
/** * Called when this Chunk is loaded by the ChunkProvider */ public void onChunkLoad() { this.isChunkLoaded = true; this.worldObj.addTileEntities(this.chunkTileEntityMap.values()); for (ClassInheritanceMultiMap<Entity> classinheritancemultimap : this.entityLists) { this.worldObj.loadEntities(classinheritancemultimap); } }
/** * Called when this Chunk is unloaded by the ChunkProvider */ public void onChunkUnload() { this.isChunkLoaded = false; for (TileEntity tileentity : this.chunkTileEntityMap.values()) { this.worldObj.markTileEntityForRemoval(tileentity); } for (ClassInheritanceMultiMap<Entity> classinheritancemultimap : this.entityLists) { this.worldObj.unloadEntities(classinheritancemultimap); } }
/** * Called when this Chunk is loaded by the ChunkProvider */ public void onChunkLoad() { this.isChunkLoaded = true; this.worldObj.addTileEntities(this.chunkTileEntityMap.values()); for (ClassInheritanceMultiMap<Entity> classinheritancemultimap : this.entityLists) { this.worldObj.loadEntities(com.google.common.collect.ImmutableList.copyOf(classinheritancemultimap)); } net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.world.ChunkEvent.Load(this)); }
@Override public void handle(Coord here) { for (ClassInheritanceMultiMap<Entity> list : here.getChunk().getEntityLists()) { for (Entity ent : list) { if (!(ent instanceof INpc)) continue; if (hashEnt(ent)) { satisfactory_villagers++; } } } }
private static boolean unloadChunk(net.minecraft.world.chunk.Chunk chunk) { net.minecraft.world.World mcWorld = chunk.getWorld(); ChunkProviderServer chunkProviderServer = (ChunkProviderServer) chunk.getWorld().getChunkProvider(); boolean saveChunk = false; if (chunk.needsSaving(true)) { saveChunk = true; } for (ClassInheritanceMultiMap<Entity> classinheritancemultimap : chunk.getEntityLists()) { chunk.getWorld().unloadEntities(classinheritancemultimap); } if (saveChunk) { saveChunkData(chunkProviderServer, chunk); } chunkProviderServer.id2ChunkMap.remove(ChunkPos.asLong(chunk.x, chunk.z)); ((IMixinChunk) chunk).setScheduledForUnload(-1); org.spongepowered.api.world.Chunk spongeChunk = (org.spongepowered.api.world.Chunk) chunk; for (Direction direction : CARDINAL_DIRECTIONS) { Vector3i neighborPosition = spongeChunk.getPosition().add(direction.asBlockOffset()); IMixinChunkProviderServer spongeChunkProvider = (IMixinChunkProviderServer) mcWorld.getChunkProvider(); net.minecraft.world.chunk.Chunk neighbor = spongeChunkProvider.getLoadedChunkWithoutMarkingActive (neighborPosition.getX(), neighborPosition.getZ()); if (neighbor != null) { int neighborIndex = directionToIndex(direction); int oppositeNeighborIndex = directionToIndex(direction.getOpposite()); ((IMixinChunk) spongeChunk).setNeighborChunk(neighborIndex, null); ((IMixinChunk) neighbor).setNeighborChunk(oppositeNeighborIndex, null); } } return true; }
public boolean hasEntities(Chunk nmsChunk) { ClassInheritanceMultiMap<Entity>[] entities = nmsChunk.getEntityLists(); for (int i = 0; i < entities.length; i++) { ClassInheritanceMultiMap<Entity> slice = entities[i]; if (slice != null && !slice.isEmpty()) { return true; } } return false; }
@Override public Set<Entity> getEntities() { final Set<Entity> entities = Sets.newHashSet(); for (ClassInheritanceMultiMap entityList : this.entityLists) { entities.addAll(entityList); } return entities; }
private List<EntityItem> selectEntitiesWithinAABB(World worldIn, AxisAlignedBB bb) { List<EntityItem> result = new ArrayList<EntityItem>(); final int maxItems = VacuumConfig.vacuumChestMaxItems.get(); final int minChunkX = MathHelper.floor((bb.minX) / 16.0D); final int maxChunkX = MathHelper.floor((bb.maxX) / 16.0D); final int minChunkZ = MathHelper.floor((bb.minZ) / 16.0D); final int maxChunkZ = MathHelper.floor((bb.maxZ) / 16.0D); final int minChunkY = MathHelper.floor((bb.minY) / 16.0D); final int maxChunkY = MathHelper.floor((bb.maxY) / 16.0D); for (int chunkX = minChunkX; chunkX <= maxChunkX; ++chunkX) { for (int chunkZ = minChunkZ; chunkZ <= maxChunkZ; ++chunkZ) { Chunk chunk = worldIn.getChunkFromChunkCoords(chunkX, chunkZ); final ClassInheritanceMultiMap<Entity>[] entityLists = chunk.getEntityLists(); final int minChunkYClamped = MathHelper.clamp(minChunkY, 0, entityLists.length - 1); final int maxChunkYClamped = MathHelper.clamp(maxChunkY, 0, entityLists.length - 1); for (int chunkY = minChunkYClamped; chunkY <= maxChunkYClamped; ++chunkY) { for (Entity entity : entityLists[chunkY]) { if (!entity.isDead && (entity instanceof EntityItem) && entity.getEntityBoundingBox().intersectsWith(bb) && (filter == null || filter.doesItemPassFilter(null, ((EntityItem) entity).getEntityItem())) && MagnetUtil.shouldAttract(getPos(), entity)) { result.add((EntityItem) entity); if (maxItems > 0 && maxItems <= result.size()) { return result; } } } } } } return result; }
public ClassInheritanceMultiMap<Entity>[] getEntityLists() { return this.entityLists; }
private static List<Entity> selectEntitiesWithinAABB(World world, AxisAlignedBB bb) { List<Entity> arraylist = null; int itemsRemaining = Config.magnetMaxItems; if (itemsRemaining <= 0) { itemsRemaining = Integer.MAX_VALUE; } final int minChunkX = MathHelper.floor((bb.minX) / 16.0D); final int maxChunkX = MathHelper.floor((bb.maxX) / 16.0D); final int minChunkZ = MathHelper.floor((bb.minZ) / 16.0D); final int maxChunkZ = MathHelper.floor((bb.maxZ) / 16.0D); final int minChunkY = MathHelper.floor((bb.minY) / 16.0D); final int maxChunkY = MathHelper.floor((bb.maxY) / 16.0D); for (int chunkX = minChunkX; chunkX <= maxChunkX; ++chunkX) { for (int chunkZ = minChunkZ; chunkZ <= maxChunkZ; ++chunkZ) { Chunk chunk = world.getChunkFromChunkCoords(chunkX, chunkZ); final ClassInheritanceMultiMap<Entity>[] entityLists = chunk.getEntityLists(); final int minChunkYClamped = MathHelper.clamp(minChunkY, 0, entityLists.length - 1); final int maxChunkYClamped = MathHelper.clamp(maxChunkY, 0, entityLists.length - 1); for (int chunkY = minChunkYClamped; chunkY <= maxChunkYClamped; ++chunkY) { for (Entity entity : entityLists[chunkY]) { if (!entity.isDead) { boolean isValidTarget = false; if (entity.getEntityBoundingBox().intersectsWith(bb)) { if (entity instanceof EntityItem) { isValidTarget = !hasSolegnoliaAround(entity) && !isBlackListed((EntityItem) entity); } else if (entity instanceof EntityXPOrb) { isValidTarget = true; } } isValidTarget = isValidTarget && !MagnetUtil.isReserved(entity); if (isValidTarget) { if (arraylist == null) { arraylist = new ArrayList<Entity>(Config.magnetMaxItems > 0 ? Config.magnetMaxItems : 20); } arraylist.add(entity); if (itemsRemaining-- <= 0) { return arraylist; } } } } } } } return arraylist; }