protected virtual void ProbeBlockDensityMode(IWorldAccessor world, Entity byEntity, ItemSlot itemslot, BlockSelection blockSel)
        {
            IPlayer byPlayer = null;

            if (byEntity is EntityPlayer)
            {
                byPlayer = world.PlayerByUid(((EntityPlayer)byEntity).PlayerUID);
            }

            Block block   = world.BlockAccessor.GetBlock(blockSel.Position);
            float dropMul = 1f;

            if (block.BlockMaterial == EnumBlockMaterial.Ore || block.BlockMaterial == EnumBlockMaterial.Stone)
            {
                dropMul = 0;
            }

            block.OnBlockBroken(world, blockSel.Position, byPlayer, dropMul);

            if (!block.Code.Path.StartsWith("rock") && !block.Code.Path.StartsWith("ore"))
            {
                return;
            }

            IServerPlayer splr = byPlayer as IServerPlayer;

            if (splr == null)
            {
                return;
            }

            if (splr.WorldData.CurrentGameMode == EnumGameMode.Creative)
            {
                PrintProbeResults(world, splr, itemslot, blockSel.Position);
                return;
            }

            IntArrayAttribute attr = itemslot.Itemstack.Attributes["probePositions"] as IntArrayAttribute;

            if ((attr == null || attr.value == null || attr.value.Length == 0))
            {
                itemslot.Itemstack.Attributes["probePositions"] = attr = new IntArrayAttribute();
                attr.AddInt(blockSel.Position.X, blockSel.Position.Y, blockSel.Position.Z);

                splr.SendMessage(GlobalConstants.InfoLogChatGroup, Lang.Get("Ok, need 2 more samples"), EnumChatType.Notification);
            }
            else
            {
                float requiredSamples = 2;

                attr.AddInt(blockSel.Position.X, blockSel.Position.Y, blockSel.Position.Z);

                int[] vals = attr.value;
                for (int i = 0; i < vals.Length; i += 3)
                {
                    int x = vals[i];
                    int y = vals[i + 1];
                    int z = vals[i + 2];

                    float mindist = 99;


                    for (int j = i + 3; j < vals.Length; j += 3)
                    {
                        int dx = x - vals[j];
                        int dy = y - vals[j + 1];
                        int dz = z - vals[j + 2];

                        mindist = Math.Min(mindist, GameMath.Sqrt(dx * dx + dy * dy + dz * dz));
                    }

                    if (i + 3 < vals.Length)
                    {
                        requiredSamples -= GameMath.Clamp(mindist * mindist, 3, 16) / 16;

                        if (mindist > 20)
                        {
                            splr.SendMessage(GlobalConstants.InfoLogChatGroup, Lang.Get("Sample too far away from initial reading. Sampling around this point now, need 2 more samples."), EnumChatType.Notification);
                            attr.value = new int[] { blockSel.Position.X, blockSel.Position.Y, blockSel.Position.Z };
                            return;
                        }
                    }
                }

                if (requiredSamples > 0)
                {
                    int q = (int)Math.Ceiling(requiredSamples);
                    splr.SendMessage(GlobalConstants.InfoLogChatGroup, q > 1 ? Lang.Get("propick-xsamples", q) : Lang.Get("propick-1sample"), EnumChatType.Notification);
                }
                else
                {
                    int startX = vals[0];
                    int startY = vals[1];
                    int startZ = vals[2];
                    PrintProbeResults(world, splr, itemslot, new BlockPos(startX, startY, startZ));
                    attr.value = new int[0];
                }
            }
        }
Пример #2
0
        void ProbeGround(IWorldAccessor world, IEntity byEntity, IItemSlot itemslot, BlockSelection blockSel)
        {
            IPlayer byPlayer = null;

            if (byEntity is IEntityPlayer)
            {
                byPlayer = world.PlayerByUid(((IEntityPlayer)byEntity).PlayerUID);
            }

            Block block = world.BlockAccessor.GetBlock(blockSel.Position);

            block.OnBlockBroken(world, blockSel.Position, byPlayer, 0);

            if (!block.Code.Path.StartsWith("rock") && !block.Code.Path.StartsWith("ore"))
            {
                return;
            }

            IServerPlayer splr = byPlayer as IServerPlayer;

            if (splr != null)
            {
                IntArrayAttribute attr = itemslot.Itemstack.Attributes["probePositions"] as IntArrayAttribute;

                if (attr == null || attr.value == null || attr.value.Length == 0)
                {
                    itemslot.Itemstack.Attributes["probePositions"] = attr = new IntArrayAttribute();
                    attr.AddInt(blockSel.Position.X, blockSel.Position.Y, blockSel.Position.Z);

                    splr.SendMessage(GlobalConstants.CurrentChatGroup, "Ok, need 2 more samples", EnumChatType.Notification);
                }
                else
                {
                    float requiredSamples = 2;

                    attr.AddInt(blockSel.Position.X, blockSel.Position.Y, blockSel.Position.Z);

                    int[] vals = attr.value;
                    for (int i = 0; i < vals.Length; i += 3)
                    {
                        int x = vals[i];
                        int z = vals[i + 2];

                        float mindist = 99;


                        for (int j = i + 3; j < vals.Length; j += 3)
                        {
                            int dx = x - vals[j];
                            int dz = z - vals[j + 2];

                            mindist = Math.Min(mindist, GameMath.Sqrt(dx * dx + dz * dz));
                        }

                        if (i + 3 < vals.Length)
                        {
                            requiredSamples -= GameMath.Clamp(mindist * mindist, 0, 16) / 16;

                            if (mindist > 16)
                            {
                                splr.SendMessage(GlobalConstants.CurrentChatGroup, "Sample too far away from initial reading. Sampling around this point now, need 2 more samples.", EnumChatType.Notification);
                                attr.value = new int[] { blockSel.Position.X, blockSel.Position.Y, blockSel.Position.Z };
                                return;
                            }
                        }
                    }

                    if (requiredSamples > 0)
                    {
                        int q = (int)Math.Ceiling(requiredSamples);
                        splr.SendMessage(GlobalConstants.CurrentChatGroup, "Ok, need " + q + " more " + (q == 1 ? "sample" : "samples"), EnumChatType.Notification);
                    }
                    else
                    {
                        int startX = vals[0];
                        int startY = vals[1];
                        int startZ = vals[2];
                        PrintProbeResults(world, splr, itemslot, new BlockPos(startX, startY, startZ));
                        attr.value = new int[0];
                    }
                }
            }
        }