/** * Returns the block corresponding to the given coordinates inside a chunk. */ private Block getBlock0(int x, int y, int z) { Block block = Blocks.air; if (y >= 0 && y >> 4 < this.storageArrays.length) { ExtendedBlockStorage extendedblockstorage = this.storageArrays[y >> 4]; if (extendedblockstorage != null) { try { block = extendedblockstorage.getBlockByExtId(x, y & 15, z); } catch (Throwable throwable) { CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Getting block"); throw new ReportedException(crashreport); } } } return block; }
public int getLightSubtracted(BlockPos pos, int amount) { int i = pos.getX() & 15; int j = pos.getY(); int k = pos.getZ() & 15; ExtendedBlockStorage extendedblockstorage = this.storageArrays[j >> 4]; if (extendedblockstorage == null) { return !this.worldObj.provider.getHasNoSky() && amount < EnumSkyBlock.SKY.defaultLightValue ? EnumSkyBlock.SKY.defaultLightValue - amount : 0; } else { int l = this.worldObj.provider.getHasNoSky() ? 0 : extendedblockstorage.getExtSkylightValue(i, j & 15, k); l = l - amount; int i1 = extendedblockstorage.getExtBlocklightValue(i, j & 15, k); if (i1 > l) { l = i1; } return l; } }
/** * Returns whether the ExtendedBlockStorages containing levels (in blocks) from arg 1 to arg 2 are fully empty * (true) or not (false). */ public boolean getAreLevelsEmpty(int startY, int endY) { if (startY < 0) { startY = 0; } if (endY >= 256) { endY = 255; } for (int i = startY; i <= endY; i += 16) { ExtendedBlockStorage extendedblockstorage = this.storageArrays[i >> 4]; if (extendedblockstorage != null && !extendedblockstorage.isEmpty()) { return false; } } return true; }
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 int getLightSubtracted(BlockPos pos, int amount) { int i = pos.getX() & 15; int j = pos.getY(); int k = pos.getZ() & 15; ExtendedBlockStorage extendedblockstorage = this.storageArrays[j >> 4]; if (extendedblockstorage == NULL_BLOCK_STORAGE) { return this.worldObj.provider.func_191066_m() && amount < EnumSkyBlock.SKY.defaultLightValue ? EnumSkyBlock.SKY.defaultLightValue - amount : 0; } else { int l = !this.worldObj.provider.func_191066_m() ? 0 : extendedblockstorage.getExtSkylightValue(i, j & 15, k); l = l - amount; int i1 = extendedblockstorage.getExtBlocklightValue(i, j & 15, k); if (i1 > l) { l = i1; } return l; } }
/** * Returns whether the ExtendedBlockStorages containing levels (in blocks) from arg 1 to arg 2 are fully empty * (true) or not (false). */ public boolean getAreLevelsEmpty(int startY, int endY) { if (startY < 0) { startY = 0; } if (endY >= 256) { endY = 255; } for (int i = startY; i <= endY; i += 16) { ExtendedBlockStorage extendedblockstorage = this.storageArrays[i >> 4]; if (extendedblockstorage != NULL_BLOCK_STORAGE && !extendedblockstorage.isEmpty()) { return false; } } return true; }
public int getLightSubtracted(BlockPos pos, int amount) { int i = pos.getX() & 15; int j = pos.getY(); int k = pos.getZ() & 15; ExtendedBlockStorage extendedblockstorage = this.storageArrays[j >> 4]; if (extendedblockstorage == NULL_BLOCK_STORAGE) { return !this.worldObj.provider.getHasNoSky() && amount < EnumSkyBlock.SKY.defaultLightValue ? EnumSkyBlock.SKY.defaultLightValue - amount : 0; } else { int l = this.worldObj.provider.getHasNoSky() ? 0 : extendedblockstorage.getExtSkylightValue(i, j & 15, k); l = l - amount; int i1 = extendedblockstorage.getExtBlocklightValue(i, j & 15, k); if (i1 > l) { l = i1; } return l; } }
/** * Gets a chunk from the chunk coordinates, then adds it * to the queue if it exists and is not already in the queue. * @param x chunk coordinate * @param z chunk coordinate * @return if the chunk exists */ public boolean updateChunk(int x, int z) { Chunk chunk = mc.world.getChunkFromChunkCoords(x, z); ExtendedBlockStorage[] storage = chunk.getBlockStorageArray(); for (int y = 0; y < 16; y++) { if (storage[y] != null) { updateChunk(chunk); return true; } } return false; }
/** * Gets a chunk from the chunk coordinates, then adds it * to the beginning of the queue if it exists. * @param x chunk coordinate * @param z chunk coordinate * @return if the chunk exists */ public boolean updateChunkFirst(int x, int z) { Chunk chunk = mc.world.getChunkFromChunkCoords(x, z); ExtendedBlockStorage[] storage = chunk.getBlockStorageArray(); for (int y = 0; y < 16; y++) { if (storage[y] != null) { updateChunkFirst(chunk); return true; } } return false; }
/** * Get block storage array for y-coordinate * Returns null in case block is outside * @param chunk Target chunk * @param y Block height inside chunk * @return Block storage or null */ private static ExtendedBlockStorage getStorage(Chunk chunk, int y) { ExtendedBlockStorage[] storage = chunk.getBlockStorageArray(); if (y < 0 || y >= 256) { return null; } int i = y >> 4; if (storage[i] == Chunk.NULL_BLOCK_STORAGE) { storage[i] = new ExtendedBlockStorage(i << 4, chunk.getWorld().provider.hasSkyLight()); chunk.generateSkylightMap(); } return storage[i]; }
private void loadChunk(int id, Shader shader, ExtendedBlockStorage storage) { ObjectIntIdentityMap<IBlockState> map = GameData.getBlockStateIDMap(); int[] data = new int[chunkSize*2]; for (int y = 0; y < 16; y++) { for (int z = 0; z < 16; z++) { for (int x = 0; x < 16; x++) { IBlockState state = storage.get(x, y, z); boolean fullBlock = state.isFullBlock(); boolean cube = state.isFullCube(); if (fullBlock != cube) { Log.info(state.getBlock().getUnlocalizedName() + ": " + fullBlock); } if (fullBlock) { stateSet.add(state); } int stateId = map.get(state); //TODO data[(y<<9) + (z<<5) + (x<<1)] = Block.getIdFromBlock(storage.get(x, y, z).getBlock()); } } } for (int y = 0; y < 16; y++) { for (int z = 0; z < 16; z++) { for (int x = 0; x < 16; x++) { data[(y<<9) + (z<<5) + (x<<1) + 1] = storage.getBlocklightArray().get(x, y, z); } } } IntBuffer buffer = BufferUtils.createIntBuffer(chunkSize*2); buffer.put(data); buffer.flip(); GL15.glBindBuffer(GL43.GL_SHADER_STORAGE_BUFFER, shader.getChunkSsbo()); GL15.glBufferSubData(GL43.GL_SHADER_STORAGE_BUFFER, (id-1)*chunkSize*2*4, buffer); GL15.glBindBuffer(GL43.GL_SHADER_STORAGE_BUFFER, 0); }
/** * * @param id * @param shader * @param storage * @return true if the id was used, false if there was nothing to upload */ private boolean loadMetadata(int id, Shader shader, ExtendedBlockStorage storage) { int[] data = new int[chunkSize]; boolean containsValues = false; for (int y = 0; y < 16; y++) { for (int z = 0; z < 16; z++) { for (int x = 0; x < 16; x++) { int metadata = storage.get(x, y, z).getBlock().getMetaFromState(storage.get(x, y, z)); data[(y<<8) + (z<<4) + x] = metadata; if (metadata != 0) { containsValues = true; } } } } if (containsValues) { IntBuffer buffer = BufferUtils.createIntBuffer(chunkSize); buffer.put(data); buffer.flip(); GL15.glBindBuffer(GL43.GL_SHADER_STORAGE_BUFFER, shader.getMetadataSsbo()); GL15.glBufferSubData(GL43.GL_SHADER_STORAGE_BUFFER, (id-1)*chunkSize*4, buffer); GL15.glBindBuffer(GL43.GL_SHADER_STORAGE_BUFFER, 0); } return containsValues; }
/** * Get block state from the world * @param pos Block position * @return Block state */ public UBlockState getBlockState(UBlockPos pos) { ExtendedBlockStorage storage = getStorage(world.getChunkFromBlockCoords(pos.getBlockPos()), pos.getY()); if (storage != null) { return new UBlockState(storage.get(pos.getX() & 15, pos.getY() & 15, pos.getZ() & 15)); } return UBlocks.AIR.getState(); }
public Chunk(World worldIn, ChunkPrimer primer, int x, int z) { this(worldIn, x, z); int i = 256; boolean flag = !worldIn.provider.getHasNoSky(); for (int j = 0; j < 16; ++j) { for (int k = 0; k < 16; ++k) { for (int l = 0; l < i; ++l) { int i1 = j * i * 16 | k * i | l; IBlockState iblockstate = primer.getBlockState(i1); if (iblockstate.getBlock().getMaterial() != Material.air) { int j1 = l >> 4; if (this.storageArrays[j1] == null) { this.storageArrays[j1] = new ExtendedBlockStorage(j1 << 4, flag); } this.storageArrays[j1].set(j, l & 15, k, iblockstate); } } } } }
/** * Updates queued data * @param pos Block position to update */ public void updateBlock(UBlockPos pos) { ExtendedBlockStorage storage = getStorage(world.getChunkFromBlockCoords(pos.getBlockPos()), pos.getY()); if (storage != null) { UBlockState state = getBlockState(pos); UBlock block = state.getBlock(); try { world.notifyNeighborsOfStateChange(pos.getBlockPos(), block.getBlock(), true); world.immediateBlockTick(pos.getBlockPos(), state.getState(), new Random()); world.notifyLightSet(pos.getBlockPos()); } catch (Throwable ignored) {} } }
/** * Set light for block * @param pos Block position * @param light Block light value * @param sky Set for sky */ @SuppressWarnings({"ConstantConditions"}) public void setLight(UBlockPos pos, int light, boolean sky) { ExtendedBlockStorage storage = getStorage(world.getChunkFromBlockCoords(pos.getX(), pos.getZ()), pos.getY()); if (storage != null) { if (sky) { if (storage.getSkylightArray() != null) { storage.setExtSkylightValue(pos.getX() & 15, pos.getY() & 15, pos.getZ() & 15, light); } } else { storage.setExtBlocklightValue(pos.getX() & 15, pos.getY() & 15, pos.getZ() & 15, light); } } }
public void setLightFor(EnumSkyBlock p_177431_1_, BlockPos pos, int value) { int i = pos.getX() & 15; int j = pos.getY(); int k = pos.getZ() & 15; ExtendedBlockStorage extendedblockstorage = this.storageArrays[j >> 4]; if (extendedblockstorage == null) { extendedblockstorage = this.storageArrays[j >> 4] = new ExtendedBlockStorage(j >> 4 << 4, !this.worldObj.provider.getHasNoSky()); this.generateSkylightMap(); } this.isModified = true; if (p_177431_1_ == EnumSkyBlock.SKY) { if (!this.worldObj.provider.getHasNoSky()) { extendedblockstorage.setExtSkylightValue(i, j & 15, k, value); } } else if (p_177431_1_ == EnumSkyBlock.BLOCK) { extendedblockstorage.setExtBlocklightValue(i, j & 15, k, value); } }
public void setStorageArrays(ExtendedBlockStorage[] newStorageArrays) { if (this.storageArrays.length != newStorageArrays.length) { logger.warn("Could not set level chunk sections, array length is " + newStorageArrays.length + " instead of " + this.storageArrays.length); } else { for (int i = 0; i < this.storageArrays.length; ++i) { this.storageArrays[i] = newStorageArrays[i]; } } }
/** * Return the metadata corresponding to the given coordinates inside a chunk. */ private int getBlockMetadata(int x, int y, int z) { if (y >> 4 >= this.storageArrays.length) { return 0; } else { ExtendedBlockStorage extendedblockstorage = this.storageArrays[y >> 4]; return extendedblockstorage != null ? extendedblockstorage.getExtBlockMetadata(x, y & 15, z) : 0; } }
public int getLightFor(EnumSkyBlock p_177413_1_, BlockPos pos) { int i = pos.getX() & 15; int j = pos.getY(); int k = pos.getZ() & 15; ExtendedBlockStorage extendedblockstorage = this.storageArrays[j >> 4]; return extendedblockstorage == null ? (this.canSeeSky(pos) ? p_177413_1_.defaultLightValue : 0) : (p_177413_1_ == EnumSkyBlock.SKY ? (this.worldObj.provider.getHasNoSky() ? 0 : extendedblockstorage.getExtSkylightValue(i, j & 15, k)) : (p_177413_1_ == EnumSkyBlock.BLOCK ? extendedblockstorage.getExtBlocklightValue(i, j & 15, k) : p_177413_1_.defaultLightValue)); }