public Chunk(World par1World, byte[] par2ArrayOfByte, int par3, int par4) : this(par1World, par3, par4) { int i = par2ArrayOfByte.Length / 256; for (int j = 0; j < 16; j++) { for (int k = 0; k < 16; k++) { for (int l = 0; l < i; l++) { byte byte0 = par2ArrayOfByte[j << 11 | k << 7 | l]; if (byte0 == 0) { continue; } int i1 = l >> 4; if (storageArrays[i1] == null) { storageArrays[i1] = new ExtendedBlockStorage(i1 << 4); } storageArrays[i1].SetExtBlockID(j, l & 0xf, k, byte0); } } } }
/// <summary> /// Sets the light value at the coordinate. If enumskyblock is set to sky it sets it in the skylightmap and if its a /// block then into the blocklightmap. Args enumSkyBlock, x, y, z, lightValue /// </summary> public virtual void SetLightValue(SkyBlock par1EnumSkyBlock, int par2, int par3, int par4, int par5) { ExtendedBlockStorage extendedblockstorage = storageArrays[par3 >> 4]; if (extendedblockstorage == null) { extendedblockstorage = storageArrays[par3 >> 4] = new ExtendedBlockStorage((par3 >> 4) << 4); GenerateSkylightMap(); } IsModified = true; if (par1EnumSkyBlock == SkyBlock.Sky) { if (!WorldObj.WorldProvider.HasNoSky) { extendedblockstorage.SetExtSkylightValue(par2, par3 & 0xf, par4, par5); } } else if (par1EnumSkyBlock == SkyBlock.Block) { extendedblockstorage.SetExtBlocklightValue(par2, par3 & 0xf, par4, par5); } else { return; } }
/// <summary> /// Gets the amount of light on a block taking into account sunlight /// </summary> public virtual int GetBlockLightValue(int par1, int par2, int par3, int par4) { ExtendedBlockStorage extendedblockstorage = storageArrays[par2 >> 4]; if (extendedblockstorage == null) { if (!WorldObj.WorldProvider.HasNoSky && par4 < SkyBlock.Sky.DefaultLightValue) { return(SkyBlock.Sky.DefaultLightValue - par4); } else { return(0); } } int i = WorldObj.WorldProvider.HasNoSky ? 0 : extendedblockstorage.GetExtSkylightValue(par1, par2 & 0xf, par3); if (i > 0) { IsLit = true; } i -= par4; int j = extendedblockstorage.GetExtBlocklightValue(par1, par2 & 0xf, par3); if (j > i) { i = j; } return(i); }
/// <summary> /// Set the metadata of a block in the chunk /// </summary> public virtual bool SetBlockMetadata(int par1, int par2, int par3, int par4) { ExtendedBlockStorage extendedblockstorage = storageArrays[par2 >> 4]; if (extendedblockstorage == null) { return(false); } int i = extendedblockstorage.GetExtBlockMetadata(par1, par2 & 0xf, par3); if (i == par4) { return(false); } IsModified = true; extendedblockstorage.SetExtBlockMetadata(par1, par2 & 0xf, par3, par4); int j = extendedblockstorage.GetExtBlockID(par1, par2 & 0xf, par3); if (j > 0 && (Block.BlocksList[j] is BlockContainer)) { TileEntity tileentity = GetChunkBlockTileEntity(par1, par2, par3); if (tileentity != null) { tileentity.UpdateContainingBlockInfo(); tileentity.BlockMetadata = par4; } } return(true); }
/// <summary> /// Turns unknown blocks into air blocks to avoid crashing Minecraft. /// </summary> public virtual void RemoveUnknownBlocks() { ExtendedBlockStorage[] aextendedblockstorage = storageArrays; int i = aextendedblockstorage.Length; for (int j = 0; j < i; j++) { ExtendedBlockStorage extendedblockstorage = aextendedblockstorage[j]; if (extendedblockstorage != null) { extendedblockstorage.Func_48711_e(); } } }
/// <summary> /// Return the metadata corresponding to the given coordinates inside a chunk. /// </summary> public virtual int GetBlockMetadata(int par1, int par2, int par3) { if (par2 >> 4 >= storageArrays.Length) { return(0); } ExtendedBlockStorage extendedblockstorage = storageArrays[par2 >> 4]; if (extendedblockstorage != null) { return(extendedblockstorage.GetExtBlockMetadata(par1, par2 & 0xf, par3)); } else { return(0); } }
/// <summary> /// Gets the amount of light saved in this block (doesn't adjust for daylight) /// </summary> public virtual int GetSavedLightValue(SkyBlock par1EnumSkyBlock, int par2, int par3, int par4) { ExtendedBlockStorage extendedblockstorage = storageArrays[par3 >> 4]; if (extendedblockstorage == null) { return(par1EnumSkyBlock.DefaultLightValue); } if (par1EnumSkyBlock == SkyBlock.Sky) { return(extendedblockstorage.GetExtSkylightValue(par2, par3 & 0xf, par4)); } if (par1EnumSkyBlock == SkyBlock.Block) { return(extendedblockstorage.GetExtBlocklightValue(par2, par3 & 0xf, par4)); } else { return(par1EnumSkyBlock.DefaultLightValue); } }
/// <summary> /// Returns whether the ExtendedBlockStorages containing levels (in blocks) from arg 1 to arg 2 are fully empty /// (true) or not (false). /// </summary> public virtual bool GetAreLevelsEmpty(int par1, int par2) { if (par1 < 0) { par1 = 0; } if (par2 >= 256) { par2 = 255; } for (int i = par1; i <= par2; i += 16) { ExtendedBlockStorage extendedblockstorage = storageArrays[i >> 4]; if (extendedblockstorage != null && !extendedblockstorage.GetIsEmpty()) { return(false); } } return(true); }
private Chunk Func_48444_a(World par1World, NBTTagCompound par2NBTTagCompound) { int i = par2NBTTagCompound.GetInteger("xPos"); int j = par2NBTTagCompound.GetInteger("zPos"); Chunk chunk = new Chunk(par1World, i, j); chunk.HeightMap = par2NBTTagCompound.Func_48182_l("HeightMap"); chunk.IsTerrainPopulated = par2NBTTagCompound.Getbool("TerrainPopulated"); NBTTagList nbttaglist = par2NBTTagCompound.GetTagList("Sections"); sbyte byte0 = 16; ExtendedBlockStorage[] aextendedblockstorage = new ExtendedBlockStorage[byte0]; for (int k = 0; k < nbttaglist.TagCount(); k++) { NBTTagCompound nbttagcompound = (NBTTagCompound)nbttaglist.TagAt(k); byte byte1 = nbttagcompound.GetByte("Y"); ExtendedBlockStorage extendedblockstorage = new ExtendedBlockStorage(byte1 << 4); extendedblockstorage.SetBlockLSBArray(nbttagcompound.GetByteArray("Blocks")); if (nbttagcompound.HasKey("Add")) { extendedblockstorage.SetBlockMSBArray(new NibbleArray(nbttagcompound.GetByteArray("Add"), 4)); } extendedblockstorage.SetBlockMetadataArray(new NibbleArray(nbttagcompound.GetByteArray("Data"), 4)); extendedblockstorage.SetSkylightArray(new NibbleArray(nbttagcompound.GetByteArray("SkyLight"), 4)); extendedblockstorage.SetBlocklightArray(new NibbleArray(nbttagcompound.GetByteArray("BlockLight"), 4)); extendedblockstorage.Func_48708_d(); aextendedblockstorage[byte1] = extendedblockstorage; } chunk.SetStorageArrays(aextendedblockstorage); if (par2NBTTagCompound.HasKey("Biomes")) { chunk.SetBiomeArray(par2NBTTagCompound.GetByteArray("Biomes")); } NBTTagList nbttaglist1 = par2NBTTagCompound.GetTagList("Entities"); if (nbttaglist1 != null) { for (int l = 0; l < nbttaglist1.TagCount(); l++) { NBTTagCompound nbttagcompound1 = (NBTTagCompound)nbttaglist1.TagAt(l); Entity entity = EntityList.CreateEntityFromNBT(nbttagcompound1, par1World); chunk.HasEntities = true; if (entity != null) { chunk.AddEntity(entity); } } } NBTTagList nbttaglist2 = par2NBTTagCompound.GetTagList("TileEntities"); if (nbttaglist2 != null) { for (int i1 = 0; i1 < nbttaglist2.TagCount(); i1++) { NBTTagCompound nbttagcompound2 = (NBTTagCompound)nbttaglist2.TagAt(i1); TileEntity tileentity = TileEntity.CreateAndLoadEntity(nbttagcompound2); if (tileentity != null) { chunk.AddTileEntity(tileentity); } } } if (par2NBTTagCompound.HasKey("TileTicks")) { NBTTagList nbttaglist3 = par2NBTTagCompound.GetTagList("TileTicks"); if (nbttaglist3 != null) { for (int j1 = 0; j1 < nbttaglist3.TagCount(); j1++) { NBTTagCompound nbttagcompound3 = (NBTTagCompound)nbttaglist3.TagAt(j1); par1World.ScheduleBlockUpdateFromLoad(nbttagcompound3.GetInteger("x"), nbttagcompound3.GetInteger("y"), nbttagcompound3.GetInteger("z"), nbttagcompound3.GetInteger("i"), nbttagcompound3.GetInteger("t")); } } } return(chunk); }
private void Func_48445_a(Chunk par1Chunk, World par2World, NBTTagCompound par3NBTTagCompound) { par2World.CheckSessionLock(); par3NBTTagCompound.SetInteger("xPos", par1Chunk.XPosition); par3NBTTagCompound.SetInteger("zPos", par1Chunk.ZPosition); par3NBTTagCompound.SetLong("LastUpdate", par2World.GetWorldTime()); par3NBTTagCompound.Func_48183_a("HeightMap", par1Chunk.HeightMap); par3NBTTagCompound.Setbool("TerrainPopulated", par1Chunk.IsTerrainPopulated); ExtendedBlockStorage[] aextendedblockstorage = par1Chunk.GetBlockStorageArray(); NBTTagList nbttaglist = new NBTTagList("Sections"); ExtendedBlockStorage[] aextendedblockstorage1 = aextendedblockstorage; int i = aextendedblockstorage1.Length; for (int k = 0; k < i; k++) { ExtendedBlockStorage extendedblockstorage = aextendedblockstorage1[k]; if (extendedblockstorage == null || extendedblockstorage.Func_48700_f() == 0) { continue; } NBTTagCompound nbttagcompound = new NBTTagCompound(); nbttagcompound.SetByte("Y", (byte)(extendedblockstorage.GetYLocation() >> 4 & 0xff)); nbttagcompound.SetByteArray("Blocks", extendedblockstorage.Func_48692_g()); if (extendedblockstorage.GetBlockMSBArray() != null) { nbttagcompound.SetByteArray("Add", extendedblockstorage.GetBlockMSBArray().Data); } nbttagcompound.SetByteArray("Data", extendedblockstorage.Func_48697_j().Data); nbttagcompound.SetByteArray("SkyLight", extendedblockstorage.GetSkylightArray().Data); nbttagcompound.SetByteArray("BlockLight", extendedblockstorage.GetBlocklightArray().Data); nbttaglist.AppendTag(nbttagcompound); } par3NBTTagCompound.SetTag("Sections", nbttaglist); par3NBTTagCompound.SetByteArray("Biomes", par1Chunk.GetBiomeArray()); par1Chunk.HasEntities = false; NBTTagList nbttaglist1 = new NBTTagList(); label0: for (int j = 0; j < par1Chunk.EntityLists.Length; j++) { IEnumerator <Entity> iterator = par1Chunk.EntityLists[j].GetEnumerator(); do { if (!iterator.MoveNext()) { goto label0; } Entity entity = iterator.Current; par1Chunk.HasEntities = true; NBTTagCompound nbttagcompound1 = new NBTTagCompound(); if (entity.AddEntityID(nbttagcompound1)) { nbttaglist1.AppendTag(nbttagcompound1); } }while (true); } par3NBTTagCompound.SetTag("Entities", nbttaglist1); NBTTagList nbttaglist2 = new NBTTagList(); NBTTagCompound nbttagcompound2; for (IEnumerator <TileEntity> iterator1 = par1Chunk.ChunkTileEntityMap.Values.GetEnumerator(); iterator1.MoveNext(); nbttaglist2.AppendTag(nbttagcompound2)) { TileEntity tileentity = iterator1.Current; nbttagcompound2 = new NBTTagCompound(); tileentity.WriteToNBT(nbttagcompound2); } par3NBTTagCompound.SetTag("TileEntities", nbttaglist2); List <NextTickListEntry> list = par2World.GetPendingBlockUpdates(par1Chunk, false); if (list != null) { long l = par2World.GetWorldTime(); NBTTagList nbttaglist3 = new NBTTagList(); NBTTagCompound nbttagcompound3; for (IEnumerator <NextTickListEntry> iterator2 = list.GetEnumerator(); iterator2.MoveNext(); nbttaglist3.AppendTag(nbttagcompound3)) { NextTickListEntry nextticklistentry = iterator2.Current; nbttagcompound3 = new NBTTagCompound(); nbttagcompound3.SetInteger("i", nextticklistentry.BlockID); nbttagcompound3.SetInteger("x", nextticklistentry.XCoord); nbttagcompound3.SetInteger("y", nextticklistentry.YCoord); nbttagcompound3.SetInteger("z", nextticklistentry.ZCoord); nbttagcompound3.SetInteger("t", (int)(nextticklistentry.ScheduledTime - l)); } par3NBTTagCompound.SetTag("TileTicks", nbttaglist3); } }
/// <summary> /// Sets a BlockID of a position within a chunk with metadata. Args: x, y, z, BlockID, metadata /// </summary> public virtual bool SetBlockIDWithMetadata(int par1, int par2, int par3, int par4, int par5) { int i = par3 << 4 | par1; if (par2 >= PrecipitationHeightMap[i] - 1) { PrecipitationHeightMap[i] = -999; } int j = HeightMap[i]; int k = GetBlockID(par1, par2, par3); if (k == par4 && GetBlockMetadata(par1, par2, par3) == par5) { return(false); } ExtendedBlockStorage extendedblockstorage = storageArrays[par2 >> 4]; bool flag = false; if (extendedblockstorage == null) { if (par4 == 0) { return(false); } extendedblockstorage = storageArrays[par2 >> 4] = new ExtendedBlockStorage((par2 >> 4) << 4); flag = par2 >= j; } extendedblockstorage.SetExtBlockID(par1, par2 & 0xf, par3, par4); int l = XPosition * 16 + par1; int i1 = ZPosition * 16 + par3; if (k != 0) { if (!WorldObj.IsRemote) { Block.BlocksList[k].OnBlockRemoval(WorldObj, l, par2, i1); } else if ((Block.BlocksList[k] is BlockContainer) && k != par4) { WorldObj.RemoveBlockTileEntity(l, par2, i1); } } if (extendedblockstorage.GetExtBlockID(par1, par2 & 0xf, par3) != par4) { return(false); } extendedblockstorage.SetExtBlockMetadata(par1, par2 & 0xf, par3, par5); if (flag) { GenerateSkylightMap(); } else { if (Block.LightOpacity[par4 & 0xfff] > 0) { if (par2 >= j) { RelightBlock(par1, par2 + 1, par3); } } else if (par2 == j - 1) { RelightBlock(par1, par2, par3); } PropagateSkylightOcclusion(par1, par3); } if (par4 != 0) { if (!WorldObj.IsRemote) { Block.BlocksList[par4].OnBlockAdded(WorldObj, l, par2, i1); } if (Block.BlocksList[par4] is BlockContainer) { TileEntity tileentity = GetChunkBlockTileEntity(par1, par2, par3); if (tileentity == null) { tileentity = ((BlockContainer)Block.BlocksList[par4]).GetBlockEntity(); WorldObj.SetBlockTileEntity(l, par2, i1, tileentity); } if (tileentity != null) { tileentity.UpdateContainingBlockInfo(); } } } else if (k > 0 && (Block.BlocksList[k] is BlockContainer)) { TileEntity tileentity1 = GetChunkBlockTileEntity(par1, par2, par3); if (tileentity1 != null) { tileentity1.UpdateContainingBlockInfo(); } } IsModified = true; return(true); }
/// <summary> /// Initiates the recalculation of both the block-light and sky-light for a given block inside a chunk. /// </summary> private void RelightBlock(int par1, int par2, int par3) { int i = HeightMap[par3 << 4 | par1] & 0xff; int j = i; if (par2 > i) { j = par2; } for (; j > 0 && GetBlockLightOpacity(par1, j - 1, par3) == 0; j--) { } if (j == i) { return; } WorldObj.MarkBlocksDirtyVertical(par1, par3, j, i); HeightMap[par3 << 4 | par1] = j; int k = XPosition * 16 + par1; int l = ZPosition * 16 + par3; if (!WorldObj.WorldProvider.HasNoSky) { if (j < i) { for (int i1 = j; i1 < i; i1++) { ExtendedBlockStorage extendedblockstorage = storageArrays[i1 >> 4]; if (extendedblockstorage != null) { extendedblockstorage.SetExtSkylightValue(par1, i1 & 0xf, par3, 15); WorldObj.Func_48464_p((XPosition << 4) + par1, i1, (ZPosition << 4) + par3); } } } else { for (int j1 = i; j1 < j; j1++) { ExtendedBlockStorage extendedblockstorage1 = storageArrays[j1 >> 4]; if (extendedblockstorage1 != null) { extendedblockstorage1.SetExtSkylightValue(par1, j1 & 0xf, par3, 0); WorldObj.Func_48464_p((XPosition << 4) + par1, j1, (ZPosition << 4) + par3); } } } int k1 = 15; do { if (j <= 0 || k1 <= 0) { break; } j--; int i2 = GetBlockLightOpacity(par1, j, par3); if (i2 == 0) { i2 = 1; } k1 -= i2; if (k1 < 0) { k1 = 0; } ExtendedBlockStorage extendedblockstorage2 = storageArrays[j >> 4]; if (extendedblockstorage2 != null) { extendedblockstorage2.SetExtSkylightValue(par1, j & 0xf, par3, k1); } }while (true); } int l1 = HeightMap[par3 << 4 | par1]; int j2 = i; int k2 = l1; if (k2 < j2) { int l2 = j2; j2 = k2; k2 = l2; } if (!WorldObj.WorldProvider.HasNoSky) { UpdateSkylightNeighborHeight(k - 1, l, j2, k2); UpdateSkylightNeighborHeight(k + 1, l, j2, k2); UpdateSkylightNeighborHeight(k, l - 1, j2, k2); UpdateSkylightNeighborHeight(k, l + 1, j2, k2); UpdateSkylightNeighborHeight(k, l, j2, k2); } IsModified = true; }
/// <summary> /// Generates the initial skylight map for the chunk upon generation or load. /// </summary> public virtual void GenerateSkylightMap() { int i = GetTopFilledSegment(); for (int j = 0; j < 16; j++) { for (int l = 0; l < 16; l++) { PrecipitationHeightMap[j + (l << 4)] = -999; int j1 = (i + 16) - 1; do { if (j1 <= 0) { break; } if (GetBlockLightOpacity(j, j1 - 1, l) != 0) { HeightMap[l << 4 | j] = j1; break; } j1--; }while (true); if (WorldObj.WorldProvider.HasNoSky) { continue; } j1 = 15; int k1 = (i + 16) - 1; do { j1 -= GetBlockLightOpacity(j, k1, l); if (j1 > 0) { ExtendedBlockStorage extendedblockstorage = storageArrays[k1 >> 4]; if (extendedblockstorage != null) { extendedblockstorage.SetExtSkylightValue(j, k1 & 0xf, l, j1); WorldObj.Func_48464_p((XPosition << 4) + j, k1, (ZPosition << 4) + l); } } }while (--k1 > 0 && j1 > 0); } } IsModified = true; for (int k = 0; k < 16; k++) { for (int i1 = 0; i1 < 16; i1++) { PropagateSkylightOcclusion(k, i1); } } }
public virtual void Func_48494_a(byte[] par1ArrayOfByte, int par2, int par3, bool par4) { int i = 0; for (int j = 0; j < storageArrays.Length; j++) { if ((par2 & 1 << j) != 0) { if (storageArrays[j] == null) { storageArrays[j] = new ExtendedBlockStorage(j << 4); } byte[] abyte0 = storageArrays[j].Func_48692_g(); Array.Copy(par1ArrayOfByte, i, abyte0, 0, abyte0.Length); i += abyte0.Length; continue; } if (par4 && storageArrays[j] != null) { storageArrays[j] = null; } } for (int k = 0; k < storageArrays.Length; k++) { if ((par2 & 1 << k) != 0 && storageArrays[k] != null) { NibbleArray nibblearray = storageArrays[k].Func_48697_j(); Array.Copy(par1ArrayOfByte, i, nibblearray.Data, 0, nibblearray.Data.Length); i += nibblearray.Data.Length; } } for (int l = 0; l < storageArrays.Length; l++) { if ((par2 & 1 << l) != 0 && storageArrays[l] != null) { NibbleArray nibblearray1 = storageArrays[l].GetBlocklightArray(); Array.Copy(par1ArrayOfByte, i, nibblearray1.Data, 0, nibblearray1.Data.Length); i += nibblearray1.Data.Length; } } for (int i1 = 0; i1 < storageArrays.Length; i1++) { if ((par2 & 1 << i1) != 0 && storageArrays[i1] != null) { NibbleArray nibblearray2 = storageArrays[i1].GetSkylightArray(); Array.Copy(par1ArrayOfByte, i, nibblearray2.Data, 0, nibblearray2.Data.Length); i += nibblearray2.Data.Length; } } for (int j1 = 0; j1 < storageArrays.Length; j1++) { if ((par3 & 1 << j1) != 0) { if (storageArrays[j1] == null) { i += 2048; continue; } NibbleArray nibblearray3 = storageArrays[j1].GetBlockMSBArray(); if (nibblearray3 == null) { nibblearray3 = storageArrays[j1].CreateBlockMSBArray(); } Array.Copy(par1ArrayOfByte, i, nibblearray3.Data, 0, nibblearray3.Data.Length); i += nibblearray3.Data.Length; continue; } if (par4 && storageArrays[j1] != null && storageArrays[j1].GetBlockMSBArray() != null) { storageArrays[j1].Func_48715_h(); } } if (par4) { Array.Copy(par1ArrayOfByte, i, blockBiomeArray, 0, blockBiomeArray.Length); i += blockBiomeArray.Length; } for (int k1 = 0; k1 < storageArrays.Length; k1++) { if (storageArrays[k1] != null && (par2 & 1 << k1) != 0) { storageArrays[k1].Func_48708_d(); } } GenerateHeightMap(); TileEntity tileentity; for (IEnumerator <TileEntity> iterator = ChunkTileEntityMap.Values.GetEnumerator(); iterator.MoveNext(); tileentity.UpdateContainingBlockInfo()) { tileentity = iterator.Current; } }