Beispiel #1
0
        /// <summary>
        /// Gets the TileEntity for a given block in this chunk
        /// </summary>
        public virtual TileEntity GetChunkBlockTileEntity(int par1, int par2, int par3)
        {
            ChunkPosition chunkposition = new ChunkPosition(par1, par2, par3);
            TileEntity    tileentity    = ChunkTileEntityMap[chunkposition];

            if (tileentity == null)
            {
                int i = GetBlockID(par1, par2, par3);

                if (i <= 0 || !Block.BlocksList[i].HasTileEntity())
                {
                    return(null);
                }

                if (tileentity == null)
                {
                    tileentity = ((BlockContainer)Block.BlocksList[i]).GetBlockEntity();
                    WorldObj.SetBlockTileEntity(XPosition * 16 + par1, par2, ZPosition * 16 + par3, tileentity);
                }

                tileentity = ChunkTileEntityMap[chunkposition];
            }

            if (tileentity != null && tileentity.IsInvalid())
            {
                ChunkTileEntityMap.Remove(chunkposition);
                return(null);
            }
            else
            {
                return(tileentity);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Finds a valid position within a range, that is once of the listed biomes.
        /// </summary>
        public virtual ChunkPosition FindBiomePosition(int par1, int par2, int par3, List <BiomeGenBase> par4List, Random par5Random)
        {
            int i  = par1 - par3 >> 2;
            int j  = par2 - par3 >> 2;
            int k  = par1 + par3 >> 2;
            int l  = par2 + par3 >> 2;
            int i1 = (k - i) + 1;
            int j1 = (l - j) + 1;

            int[]         ai            = GenBiomes.GetInts(i, j, i1, j1);
            ChunkPosition chunkposition = null;
            int           k1            = 0;

            for (int l1 = 0; l1 < ai.Length; l1++)
            {
                int          i2           = i + l1 % i1 << 2;
                int          j2           = j + l1 / i1 << 2;
                BiomeGenBase biomegenbase = BiomeGenBase.BiomeList[ai[l1]];

                if (par4List.Contains(biomegenbase) && (chunkposition == null || par5Random.Next(k1 + 1) == 0))
                {
                    chunkposition = new ChunkPosition(i2, 0, j2);
                    k1++;
                }
            }

            return(chunkposition);
        }
Beispiel #3
0
        protected override bool CanSpawnStructureAtCoords(int par1, int par2)
        {
            if (!RanBiomeCheck)
            {
                Random random = new Random();
                random.SetSeed((int)WorldObj.GetSeed());
                double d = random.NextDouble() * Math.PI * 2D;

                for (int k = 0; k < StructureCoords.Length; k++)
                {
                    double d1 = (1.25D + random.NextDouble()) * 32D;
                    int    l  = (int)Math.Round(Math.Cos(d) * d1);
                    int    i1 = (int)Math.Round(Math.Sin(d) * d1);
                    List <BiomeGenBase> arraylist     = new List <BiomeGenBase>();
                    BiomeGenBase[]      abiomegenbase = AllowedBiomeGenBases;
                    int j1 = abiomegenbase.Length;

                    for (int k1 = 0; k1 < j1; k1++)
                    {
                        BiomeGenBase biomegenbase = abiomegenbase[k1];
                        arraylist.Add(biomegenbase);
                    }

                    ChunkPosition chunkposition = WorldObj.GetWorldChunkManager().FindBiomePosition((l << 4) + 8, (i1 << 4) + 8, 112, arraylist, random);

                    if (chunkposition != null)
                    {
                        l  = chunkposition.x >> 4;
                        i1 = chunkposition.z >> 4;
                    }
                    else
                    {
                        Console.WriteLine((new StringBuilder()).Append("Placed stronghold in INVALID biome at (").Append(l).Append(", ").Append(i1).Append(")").ToString());
                    }

                    StructureCoords[k] = new ChunkCoordIntPair(l, i1);
                    d += (Math.PI * 2D) / (double)StructureCoords.Length;
                }

                RanBiomeCheck = true;
            }

            ChunkCoordIntPair[] achunkcoordintpair = StructureCoords;
            int i = achunkcoordintpair.Length;

            for (int j = 0; j < i; j++)
            {
                ChunkCoordIntPair chunkcoordintpair = achunkcoordintpair[j];

                if (par1 == chunkcoordintpair.ChunkXPos && par2 == chunkcoordintpair.ChunkZPos)
                {
                    Console.WriteLine((new StringBuilder()).Append(par1).Append(", ").Append(par2).ToString());
                    return(true);
                }
            }

            return(false);
        }
Beispiel #4
0
        /// <summary>
        /// Sets the strength of the wire current (0-15) for this block based on neighboring blocks and propagates to
        /// neighboring redstone wires
        /// </summary>
        private void UpdateAndPropagateCurrentStrength(World par1World, int par2, int par3, int par4)
        {
            CalculateCurrentChanges(par1World, par2, par3, par4, par2, par3, par4);
            List <ChunkPosition> arraylist = new List <ChunkPosition>(BlocksNeedingUpdate);

            BlocksNeedingUpdate.Clear();

            for (int i = 0; i < arraylist.Count; i++)
            {
                ChunkPosition chunkposition = (ChunkPosition)arraylist[i];
                par1World.NotifyBlocksOfNeighborChange(chunkposition.x, chunkposition.y, chunkposition.z, BlockID);
            }
        }
        /// <summary>
        /// Returns true if the specified block is in the same railway.
        /// </summary>
        private bool IsInTrack(int par1, int par2, int par3)
        {
            for (int i = 0; i < ConnectedTracks.Count; i++)
            {
                ChunkPosition chunkposition = (ChunkPosition)ConnectedTracks[i];

                if (chunkposition.x == par1 && chunkposition.z == par3)
                {
                    return(true);
                }
            }

            return(false);
        }
        private bool IsConnectedTo(RailLogic par1RailLogic)
        {
            for (int i = 0; i < ConnectedTracks.Count; i++)
            {
                ChunkPosition chunkposition = (ChunkPosition)ConnectedTracks[i];

                if (chunkposition.x == par1RailLogic.TrackX && chunkposition.z == par1RailLogic.TrackZ)
                {
                    return(true);
                }
            }

            return(false);
        }
Beispiel #7
0
        /// <summary>
        /// Removes the TileEntity for a given block in this chunk
        /// </summary>
        public virtual void RemoveChunkBlockTileEntity(int par1, int par2, int par3)
        {
            ChunkPosition chunkposition = new ChunkPosition(par1, par2, par3);

            if (IsChunkLoaded)
            {
                TileEntity tileentity = ChunkTileEntityMap[chunkposition];
                ChunkTileEntityMap.Remove(chunkposition);

                if (tileentity != null)
                {
                    tileentity.Invalidate();
                }
            }
        }
        /// <summary>
        /// Neighboring tracks have potentially been broken, so prune the connected track list
        /// </summary>
        private void RefreshConnectedTracks()
        {
            for (int i = 0; i < ConnectedTracks.Count; i++)
            {
                RailLogic raillogic = GetMinecartTrackLogic((ChunkPosition)ConnectedTracks[i]);

                if (raillogic == null || !raillogic.IsConnectedTo(this))
                {
                    ConnectedTracks.RemoveAt(i--);
                }
                else
                {
                    ConnectedTracks[i] = new ChunkPosition(raillogic.TrackX, raillogic.TrackY, raillogic.TrackZ);
                }
            }
        }
Beispiel #9
0
        /// <summary>
        /// Returns the block ID at the current camera location (either air or fluid), taking into account the height of
        /// fluid blocks
        /// </summary>
        public static int GetBlockIdAtEntityViewpoint(World par0World, EntityLiving par1EntityLiving, float par2)
        {
            Vec3D         vec3d         = ProjectViewFromEntity(par1EntityLiving, par2);
            ChunkPosition chunkposition = new ChunkPosition(vec3d);
            int           i             = par0World.GetBlockId(chunkposition.x, chunkposition.y, chunkposition.z);

            if (i != 0 && Block.BlocksList[i].BlockMaterial.IsLiquid())
            {
                float f  = BlockFluid.GetFluidHeightPercent(par0World.GetBlockMetadata(chunkposition.x, chunkposition.y, chunkposition.z)) - 0.1111111F;
                float f1 = (float)(chunkposition.y + 1) - f;

                if (vec3d.YCoord >= (double)f1)
                {
                    i = par0World.GetBlockId(chunkposition.x, chunkposition.y + 1, chunkposition.z);
                }
            }

            return(i);
        }
Beispiel #10
0
        /// <summary>
        /// Sets the TileEntity for a given block in this chunk
        /// </summary>
        public virtual void SetChunkBlockTileEntity(int par1, int par2, int par3, TileEntity par4TileEntity)
        {
            ChunkPosition chunkposition = new ChunkPosition(par1, par2, par3);

            par4TileEntity.WorldObj = WorldObj;
            par4TileEntity.XCoord   = XPosition * 16 + par1;
            par4TileEntity.YCoord   = par2;
            par4TileEntity.ZCoord   = ZPosition * 16 + par3;

            if (GetBlockID(par1, par2, par3) == 0 || !(Block.BlocksList[GetBlockID(par1, par2, par3)] is BlockContainer))
            {
                return;
            }
            else
            {
                par4TileEntity.Validate();
                ChunkTileEntityMap[chunkposition] = par4TileEntity;
                return;
            }
        }
        /// <summary>
        /// Determines whether or not the track can bend to meet the specified rail
        /// </summary>
        private bool CanConnectTo(RailLogic par1RailLogic)
        {
            if (IsConnectedTo(par1RailLogic))
            {
                return(true);
            }

            if (ConnectedTracks.Count == 2)
            {
                return(false);
            }

            if (ConnectedTracks.Count == 0)
            {
                return(true);
            }

            ChunkPosition chunkposition = ConnectedTracks[0];

            return(par1RailLogic.TrackY != TrackY || chunkposition.y != TrackY ? true : true);
        }
        private RailLogic GetMinecartTrackLogic(ChunkPosition par1ChunkPosition)
        {
            if (BlockRail.IsRailBlockAt(WorldObj, par1ChunkPosition.x, par1ChunkPosition.y, par1ChunkPosition.z))
            {
                return(new RailLogic(Rail, WorldObj, par1ChunkPosition.x, par1ChunkPosition.y, par1ChunkPosition.z));
            }

            if (BlockRail.IsRailBlockAt(WorldObj, par1ChunkPosition.x, par1ChunkPosition.y + 1, par1ChunkPosition.z))
            {
                return(new RailLogic(Rail, WorldObj, par1ChunkPosition.x, par1ChunkPosition.y + 1, par1ChunkPosition.z));
            }

            if (BlockRail.IsRailBlockAt(WorldObj, par1ChunkPosition.x, par1ChunkPosition.y - 1, par1ChunkPosition.z))
            {
                return(new RailLogic(Rail, WorldObj, par1ChunkPosition.x, par1ChunkPosition.y - 1, par1ChunkPosition.z));
            }
            else
            {
                return(null);
            }
        }
Beispiel #13
0
        /// <summary>
        /// Abstract. Writes the raw packet data to the data stream.
        /// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void writePacketData(DataOutputStream par1DataOutputStream) throws IOException
        public override void WritePacketData(BinaryWriter par1DataOutputStream)
        {
            par1DataOutputStream.Write(ExplosionX);
            par1DataOutputStream.Write(ExplosionY);
            par1DataOutputStream.Write(ExplosionZ);
            par1DataOutputStream.Write(ExplosionSize);
            par1DataOutputStream.Write(DestroyedBlockPositions.Count);
            int i = (int)ExplosionX;
            int j = (int)ExplosionY;
            int k = (int)ExplosionZ;
            int j1;

            for (IEnumerator <ChunkPosition> iterator = DestroyedBlockPositions.GetEnumerator(); iterator.MoveNext(); par1DataOutputStream.Write(j1))
            {
                ChunkPosition chunkposition = iterator.Current;
                int           l             = chunkposition.x - i;
                int           i1            = chunkposition.y - j;
                j1 = chunkposition.z - k;
                par1DataOutputStream.Write(l);
                par1DataOutputStream.Write(i1);
            }
        }
Beispiel #14
0
        /// <summary>
        /// The main spawning algorithm, spawns three random creatures of types in the subclass array
        /// </summary>
        public static int PerformSpawning(World par0World, bool par1, bool par2)
        {
            if (!par1 && !par2)
            {
                return(0);
            }
            else
            {
                EligibleChunksForSpawning.Clear();
                int var3;
                int var6;

                for (var3 = 0; var3 < par0World.PlayerEntities.Count; ++var3)
                {
                    EntityPlayer var4 = (EntityPlayer)par0World.PlayerEntities[var3];
                    int          var5 = MathHelper2.Floor_double(var4.PosX / 16.0D);
                    var6 = MathHelper2.Floor_double(var4.PosZ / 16.0D);
                    sbyte var7 = 8;

                    for (int var8 = -var7; var8 <= var7; ++var8)
                    {
                        for (int var9 = -var7; var9 <= var7; ++var9)
                        {
                            bool var10 = var8 == -var7 || var8 == var7 || var9 == -var7 || var9 == var7;
                            ChunkCoordIntPair var11 = new ChunkCoordIntPair(var8 + var5, var9 + var6);

                            if (!var10)
                            {
                                EligibleChunksForSpawning[var11] = false;
                            }
                            else if (!EligibleChunksForSpawning.ContainsKey(var11))
                            {
                                EligibleChunksForSpawning[var11] = true;
                            }
                        }
                    }
                }

                var3 = 0;
                ChunkCoordinates var31 = par0World.GetSpawnPoint();
                CreatureType[]   var32 = CreatureType.GetValues();
                var6 = var32.Length;

                for (int var33 = 0; var33 < var6; ++var33)
                {
                    CreatureType var34 = var32[var33];

                    if ((!var34.IsPeacefulCreature || par2) && (var34.IsPeacefulCreature || par1) && par0World.CountEntities(var34.CreatureClass) <= var34.MaxNumberOfCreature * EligibleChunksForSpawning.Count / 256)
                    {
                        IEnumerator <ChunkCoordIntPair> var35 = EligibleChunksForSpawning.Keys.GetEnumerator();
label108:

                        while (var35.MoveNext())
                        {
                            ChunkCoordIntPair var37 = var35.Current;

                            if (!EligibleChunksForSpawning[var37])
                            {
                                ChunkPosition var36 = GetRandomSpawningPointInChunk(par0World, var37.ChunkXPos, var37.ChunkZPos);
                                int           var12 = var36.x;
                                int           var13 = var36.y;
                                int           var14 = var36.z;

                                if (!par0World.IsBlockNormalCube(var12, var13, var14) && par0World.GetBlockMaterial(var12, var13, var14) == var34.CreatureMaterial)
                                {
                                    int var15 = 0;
                                    int var16 = 0;

                                    while (var16 < 3)
                                    {
                                        int            var17 = var12;
                                        int            var18 = var13;
                                        int            var19 = var14;
                                        sbyte          var20 = 6;
                                        SpawnListEntry var21 = null;
                                        int            var22 = 0;

                                        while (true)
                                        {
                                            if (var22 < 4)
                                            {
label101:
                                                {
                                                    var17 += par0World.Rand.Next(var20) - par0World.Rand.Next(var20);
                                                    var18 += par0World.Rand.Next(1) - par0World.Rand.Next(1);
                                                    var19 += par0World.Rand.Next(var20) - par0World.Rand.Next(var20);

                                                    if (CanCreatureTypeSpawnAtLocation(var34, par0World, var17, var18, var19))
                                                    {
                                                        float var23 = (float)var17 + 0.5F;
                                                        float var24 = (float)var18;
                                                        float var25 = (float)var19 + 0.5F;

                                                        if (par0World.GetClosestPlayer(var23, var24, var25, 24) == null)
                                                        {
                                                            float var26 = var23 - (float)var31.PosX;
                                                            float var27 = var24 - (float)var31.PosY;
                                                            float var28 = var25 - (float)var31.PosZ;
                                                            float var29 = var26 * var26 + var27 * var27 + var28 * var28;

                                                            if (var29 >= 576.0F)
                                                            {
                                                                if (var21 == null)
                                                                {
                                                                    var21 = par0World.GetRandomMob(var34, var17, var18, var19);

                                                                    if (var21 == null)
                                                                    {
                                                                        goto label101;
                                                                    }
                                                                }

                                                                EntityLiving var38;

                                                                try
                                                                {
                                                                    var38 = (EntityLiving)Activator.CreateInstance(var21.EntityClass, new object[] { par0World });
                                                                }
                                                                catch (Exception var30)
                                                                {
                                                                    Console.WriteLine(var30.ToString());
                                                                    Console.Write(var30.StackTrace);
                                                                    return(var3);
                                                                }

                                                                var38.SetLocationAndAngles(var23, var24, var25, (float)par0World.Rand.NextDouble() * 360.0F, 0.0F);

                                                                if (var38.GetCanSpawnHere())
                                                                {
                                                                    ++var15;
                                                                    par0World.SpawnEntityInWorld(var38);
                                                                    CreatureSpecificInit(var38, par0World, var23, var24, var25);

                                                                    if (var15 >= var38.GetMaxSpawnedInChunk())
                                                                    {
                                                                        goto label108;
                                                                    }
                                                                }

                                                                var3 += var15;
                                                            }
                                                        }
                                                    }

                                                    ++var22;
                                                    continue;
                                                }
                                            }

                                            ++var16;
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                return(var3);
            }
        }
        /// <summary>
        /// Does the second part of explosion (sound, particles, drop spawn)
        /// </summary>
        public virtual void DoExplosionB(bool par1)
        {
            WorldObj.PlaySoundEffect(ExplosionX, ExplosionY, ExplosionZ, "random.explode", 4F, (1.0F + (WorldObj.Rand.NextFloat() - WorldObj.Rand.NextFloat()) * 0.2F) * 0.7F);
            WorldObj.SpawnParticle("hugeexplosion", ExplosionX, ExplosionY, ExplosionZ, 0.0F, 0.0F, 0.0F);
            List <ChunkPosition> arraylist = new List <ChunkPosition>();

            arraylist.AddRange(DestroyedBlockPositions);

            for (int i = arraylist.Count - 1; i >= 0; i--)
            {
                ChunkPosition chunkposition = arraylist[i];
                int           k             = chunkposition.x;
                int           i1            = chunkposition.y;
                int           k1            = chunkposition.z;
                int           i2            = WorldObj.GetBlockId(k, i1, k1);

                if (par1)
                {
                    double d  = (float)k + WorldObj.Rand.NextFloat();
                    double d1 = (float)i1 + WorldObj.Rand.NextFloat();
                    double d2 = (float)k1 + WorldObj.Rand.NextFloat();
                    double d3 = d - ExplosionX;
                    double d4 = d1 - ExplosionY;
                    double d5 = d2 - ExplosionZ;
                    double d6 = MathHelper2.Sqrt_double(d3 * d3 + d4 * d4 + d5 * d5);
                    d3 /= d6;
                    d4 /= d6;
                    d5 /= d6;
                    double d7 = 0.5D / (d6 / (double)ExplosionSize + 0.10000000000000001D);
                    d7 *= WorldObj.Rand.NextFloat() * WorldObj.Rand.NextFloat() + 0.3F;
                    d3 *= d7;
                    d4 *= d7;
                    d5 *= d7;
                    WorldObj.SpawnParticle("explode", (d + ExplosionX * 1.0D) / 2D, (d1 + ExplosionY * 1.0D) / 2D, (d2 + ExplosionZ * 1.0D) / 2D, d3, d4, d5);
                    WorldObj.SpawnParticle("smoke", d, d1, d2, d3, d4, d5);
                }

                if (i2 > 0)
                {
                    Block.BlocksList[i2].DropBlockAsItemWithChance(WorldObj, k, i1, k1, WorldObj.GetBlockMetadata(k, i1, k1), 0.3F, 0);
                    WorldObj.SetBlockWithNotify(k, i1, k1, 0);
                    Block.BlocksList[i2].OnBlockDestroyedByExplosion(WorldObj, k, i1, k1);
                }
            }

            if (IsFlaming)
            {
                for (int j = arraylist.Count - 1; j >= 0; j--)
                {
                    ChunkPosition chunkposition1 = arraylist[j];
                    int           l  = chunkposition1.x;
                    int           j1 = chunkposition1.y;
                    int           l1 = chunkposition1.z;
                    int           j2 = WorldObj.GetBlockId(l, j1, l1);
                    int           k2 = WorldObj.GetBlockId(l, j1 - 1, l1);

                    if (j2 == 0 && Block.OpaqueCubeLookup[k2] && ExplosionRNG.Next(3) == 0)
                    {
                        WorldObj.SetBlockWithNotify(l, j1, l1, Block.Fire.BlockID);
                    }
                }
            }
        }
        public virtual ChunkPosition GetNearestInstance(World par1World, int par2, int par3, int par4)
        {
            WorldObj = par1World;
            Rand.SetSeed((int)par1World.GetSeed());
            long l  = Rand.Next();
            long l1 = Rand.Next();
            long l2 = (long)(par2 >> 4) * l;
            long l3 = (long)(par4 >> 4) * l1;

            Rand.SetSeed((int)(l2 ^ l3 ^ par1World.GetSeed()));
            RecursiveGenerate(par1World, par2 >> 4, par4 >> 4, 0, 0, null);
            double        d             = double.MaxValue;
            ChunkPosition chunkposition = null;

            IEnumerator <StructureStart> iterator = CoordMap.Values.GetEnumerator();

            do
            {
                if (!iterator.MoveNext())
                {
                    break;
                }

                StructureStart structurestart = iterator.Current;

                if (structurestart.IsSizeableStructure())
                {
                    StructureComponent structurecomponent = structurestart.GetComponents()[0];
                    ChunkPosition      chunkposition2     = structurecomponent.GetCenter();
                    int    i  = chunkposition2.x - par2;
                    int    k  = chunkposition2.y - par3;
                    int    j1 = chunkposition2.z - par4;
                    double d1 = i + i * k * k + j1 * j1;

                    if (d1 < d)
                    {
                        d             = d1;
                        chunkposition = chunkposition2;
                    }
                }
            }while (true);

            if (chunkposition != null)
            {
                return(chunkposition);
            }

            List <ChunkPosition> list = Func_40482_a();

            if (iterator != null)
            {
                ChunkPosition chunkposition1          = null;
                IEnumerator <ChunkPosition> iterator2 = list.GetEnumerator();

                do
                {
                    if (!iterator2.MoveNext())
                    {
                        break;
                    }

                    ChunkPosition chunkposition3 = iterator2.Current;
                    int           j  = chunkposition3.x - par2;
                    int           i1 = chunkposition3.y - par3;
                    int           k1 = chunkposition3.z - par4;
                    double        d2 = j + j * i1 * i1 + k1 * k1;

                    if (d2 < d)
                    {
                        d = d2;
                        chunkposition1 = chunkposition3;
                    }
                }while (true);

                return(chunkposition1);
            }
            else
            {
                return(null);
            }
        }