Ejemplo n.º 1
0
        public override Cuboidf[] GetSelectionBoxes(IBlockAccessor world, BlockPos pos, IPlayer forPlayer = null)
        {
            if (Api.Side == EnumAppSide.Client && DetailingMode)
            {
                if (forPlayer == null)
                {
                    forPlayer = (Api.World as IClientWorldAccessor).Player;
                }

                int nowSize = GetChiselSize(forPlayer);

                if (prevSize > 0 && prevSize != nowSize)
                {
                    selectionBoxesVoxels = null;
                }

                prevSize = nowSize;

                return(GetOrCreateVoxelSelectionBoxes(forPlayer));
            }

            if (selectionBoxes.Length == 0)
            {
                return new Cuboidf[] { Cuboidf.Default() }
            }
            ;

            return(selectionBoxes);
        }
Ejemplo n.º 2
0
 public virtual Cuboidf[] GetSelectionBoxes(IBlockAccessor world, BlockPos pos, IPlayer forPlayer = null)
 {
     if (selectionBoxes.Length == 0)
     {
         return new Cuboidf[] { Cuboidf.Default() }
     }
     ;
     return(selectionBoxes);
 }
Ejemplo n.º 3
0
        public override Cuboidf[] GetSelectionBoxes(IBlockAccessor blockAccessor, BlockPos pos)
        {
            var block  = blockAccessor.GetBlock(pos.X + OffsetInv.X, pos.Y + OffsetInv.Y, pos.Z + OffsetInv.Z);
            var blockm = block as IMultiBlockMonolithicSmall;

            if (blockm != null)
            {
                return(blockm.MBGetSelectionBoxes(blockAccessor, pos, OffsetInv));
            }

            // Prevent Stack overflow
            if (block is BlockMultiblock || block.Id == 0)
            {
                return(new Cuboidf[] { Cuboidf.Default() });
            }

            return(block.GetSelectionBoxes(blockAccessor, pos));
        }
Ejemplo n.º 4
0
        protected virtual void OnGameTick(float dt)
        {
            if (Data.EntityCodes == null || Data.EntityCodes.Length == 0)
            {
                lastSpawnTotalHours = Api.World.Calendar.TotalHours;
                return;
            }


            ICoreServerAPI sapi = Api as ICoreServerAPI;

            int rnd = sapi.World.Rand.Next(Data.EntityCodes.Length);
            EntityProperties type = Api.World.GetEntityType(new AssetLocation(Data.EntityCodes[rnd]));

            if (lastSpawnTotalHours + Data.InGameHourInterval > Api.World.Calendar.TotalHours && Data.InitialSpawnQuantity <= 0)
            {
                return;
            }
            if (!IsAreaLoaded())
            {
                return;
            }
            if (Data.SpawnOnlyAfterImport && !Data.WasImported)
            {
                return;
            }
            if (Data.MinPlayerRange > 0)
            {
                IPlayer player = Api.World.NearestPlayer(Pos.X, Pos.Y, Pos.Z);
                if (player?.Entity?.ServerPos == null)
                {
                    return;
                }
                if (player.Entity.ServerPos.SquareDistanceTo(Pos.ToVec3d()) > Data.MinPlayerRange * Data.MinPlayerRange)
                {
                    return;
                }
            }

            if (type == null)
            {
                return;
            }

            for (int i = 0; i < spawnedEntities.Count; i++)
            {
                if (!sapi.World.LoadedEntities.ContainsKey(spawnedEntities[i]))
                {
                    spawnedEntities.RemoveAt(i);
                    i--;
                }
            }

            if (spawnedEntities.Count >= Data.MaxCount)
            {
                lastSpawnTotalHours = Api.World.Calendar.TotalHours;
                return;
            }

            Cuboidf collisionBox = new Cuboidf()
            {
                X1 = -type.CollisionBoxSize.X / 2,
                Z1 = -type.CollisionBoxSize.X / 2,
                X2 = type.CollisionBoxSize.X / 2,
                Z2 = type.CollisionBoxSize.X / 2,
                Y2 = type.CollisionBoxSize.Y
            }.OmniNotDownGrowBy(0.1f);

            Cuboidf collisionBox2 = new Cuboidf()
            {
                X1 = -type.CollisionBoxSize.X / 2,
                Z1 = -type.CollisionBoxSize.X / 2,
                X2 = type.CollisionBoxSize.X / 2,
                Z2 = type.CollisionBoxSize.X / 2,
                Y2 = type.CollisionBoxSize.Y
            };

            int      q             = Data.GroupSize;
            long     herdId        = 0;
            Vec3d    spawnPos      = new Vec3d();
            BlockPos spawnBlockPos = new BlockPos();

            while (q-- > 0)
            {
                for (int tries = 0; tries < 15; tries++)
                {
                    spawnPos.Set(Pos).Add(
                        0.5 + Data.SpawnArea.MinX + Api.World.Rand.NextDouble() * Data.SpawnArea.SizeX,
                        Data.SpawnArea.MinY + Api.World.Rand.NextDouble() * Data.SpawnArea.SizeY,
                        0.5 + Data.SpawnArea.MinZ + Api.World.Rand.NextDouble() * Data.SpawnArea.SizeZ
                        );

                    if (!collisionTester.IsColliding(Api.World.BlockAccessor, collisionBox, spawnPos, false))
                    {
                        if (requireSpawnOnWallSide)
                        {
                            bool haveWall = false;
                            for (int i = 0; !haveWall && i < BlockFacing.NumberOfFaces; i++)
                            {
                                BlockFacing face = BlockFacing.ALLFACES[i];

                                spawnBlockPos.Set(spawnPos).Add(face.Normali);
                                haveWall = Api.World.BlockAccessor.GetBlock(spawnBlockPos).SideSolid[face.Opposite.Index];
                                if (haveWall)
                                {
                                    Cuboidd entityPos = collisionBox2.ToDouble().Translate(spawnPos);
                                    Cuboidd blockPos  = Cuboidf.Default().ToDouble().Translate(spawnBlockPos);
                                    /// North: Negative Z
                                    /// East: Positive X
                                    /// South: Positive Z
                                    /// West: Negative X
                                    /// Up: Positive Y
                                    /// Down: Negative Y

                                    switch (face.Index)
                                    {
                                    case 0:    // BlockFacing.NORTH.Index:
                                        spawnPos.Z -= blockPos.Z2 - entityPos.Z1 + 0.01f;
                                        break;

                                    case 1:     // BlockFacing.EAST.Index:
                                        spawnPos.X += blockPos.X1 - entityPos.X2 - 0.01f;
                                        break;

                                    case 2:     // BlockFacing.SOUTH.Index:
                                        spawnPos.Z += blockPos.Z1 - entityPos.Z2 - 0.01f;
                                        break;

                                    case 3:     // BlockFacing.WEST.Index:
                                        spawnPos.X -= blockPos.X2 - entityPos.X1 + 0.01f;
                                        break;

                                    case 4:     // BlockFacing.UP.Index:
                                        spawnPos.Y += blockPos.Y1 - entityPos.Y2 - 0.01f;
                                        break;

                                    case 5:     // BlockFacing.DOWN.Index:
                                        spawnPos.Y -= blockPos.Y2 - entityPos.Y1 + 0.01f;
                                        break;
                                    }
                                }
                            }
                            if (!haveWall)
                            {
                                continue;
                            }
                        }

                        if (herdId == 0)
                        {
                            herdId = GetNextHerdId();
                        }

                        DoSpawn(type, spawnPos, herdId);
                        lastSpawnTotalHours = Api.World.Calendar.TotalHours;

                        if (Data.InitialQuantitySpawned > 0)
                        {
                            Data.InitialQuantitySpawned--;
                        }

                        // Self destruct, if configured so
                        if (Data.RemoveAfterSpawnCount > 0)
                        {
                            Data.RemoveAfterSpawnCount--;
                            if (Data.RemoveAfterSpawnCount == 0)
                            {
                                Api.World.BlockAccessor.SetBlock(0, Pos);
                            }
                        }

                        return;
                    }
                }
            }
        }