LoginSignup
1
0

マインクラフトで球体構築物の実装

Posted at

マインクラフトで、RCONのコマンドを発行し、球体の構築物を作ります。

1.NugetでCoreRCONを導入してください。

2.実装

以下、半球の構築物を作るコマンドを吐き出します。
縦に、半分に切れた半球で仲が中空になっていますので、中に入ることができます。

for文の終了条件180を360に変えると、球体になると思います。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MinecraftBall
{
    internal class CadPoint
    {
        public int x;
        public int y;
        public int z;

        public CadPoint(int x, int y, int z)
        {
            this.x = x;
            this.y = y;
            this.z = z;
        }
    }

    internal class Ball
    {
        public List<CadPoint> points = new List<CadPoint>();
        public Ball(int r)
        {
            for (int i = 0; i < 180; i++)
            {
                double rad1 = (2 * Math.PI * i) / 360;
                double zz = r * Math.Cos(rad1);

                for (int th = 0; th < 180; th++)
                {
                    double rad2 = (2 * Math.PI * th) / 360;

                    double xx = r * Math.Sin(rad2) * Math.Sin(rad1);

                    double yy = r * Math.Cos(rad2) * Math.Sin(rad1);
                                        
                    points.Add(new CadPoint((int)xx, (int)zz, (int)yy));
                }
            }
        }
    }
}

ドライバは以下のようになります。

using MinecraftBall;
using System.Net;
using System.Runtime.CompilerServices;


int r = 50;

var ball = new Ball(r);

var point = ball.points;

int x = 600;
int y = 40;
int z = 600;

var ipAddress = IPAddress.Parse(<ip-address>);
ushort port = <port>;
var password = <username>;
var connection = new CoreRCON.RCON(ipAddress, port, password);

await connection.ConnectAsync();

string bl = "stone";

foreach (var s in point)
{
    string str = string.Format("setblock {0} {1} {2} minecraft:{3}", s.x + x, s.z + y, (s.y) + z, bl);
    string respnose = await connection.SendCommandAsync(str);

    Console.WriteLine(str);
    Console.WriteLine(respnose);
}

Console.WriteLine("end");

await connection.SendCommandAsync("/time set day");

さいごに

球の表面積の座標を求めるアルゴリズム自体は、もしかしたら、球の表面積の大きさそのものを求めたり、証明をしたりする用途に使えるかもしれません。お時間があれば、ぜひ、こちらもご覧ください。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0