It works only with MCDzienny version 10.1+
- Code: Select all
using System;
using System.Collections.Generic;
namespace MCDzienny
{
public class CmdSimpleCuboid : Command
{
public override string name { get { return "scuboid"; } }
public override string shortcut { get { return ""; } }
public override string type { get { return "build"; } }
public override bool museumUsable { get { return false; } }
public override LevelPermission defaultRank { get { return LevelPermission.Builder; } }
// Usually for building commands the console access should be set to false.
public override bool ConsoleAccess { get { return false; } }
public override void Use(Player p, string message)
{
byte block = Block.Zero;
// Parse a block type if specified.
if (message != "")
{
block = Block.Parse(message);
// Check if the block was parsed correctly.
if (block == Block.Zero)
{
Player.SendMessage(p, "Unknown block type.");
return;
}
// Check if the player can place the given block type.
if (!Block.canPlace(p, block))
{
Player.SendMessage(p, "You can't place this block type.");
return;
}
}
// Capture two block changes.
Player.SendMessage(p, "Place two blocks to determine the edges.");
BlockCatch.CaptureMultipleBlocks(p, 2, DrawCuboid, new BasicDrawArgs(block));
}
private void DrawCuboid(Player p, List<ChangeInfo> changes, BasicDrawArgs da)
{
// Set a block type to the block last placed by a player.
byte block = changes[1].Type;
// If the block type was specified earlier set it.
if (da.Type1 != Block.Zero)
block = da.Type1;
// Find the start and the end points of the cube.
// Mind that Y represents a height!
int startX = Math.Min(changes[0].X, changes[1].X);
int endX = Math.Max(changes[0].X, changes[1].X);
int startY = Math.Min(changes[0].Y, changes[1].Y);
int endY = Math.Max(changes[0].Y, changes[1].Y);
int startZ = Math.Min(changes[0].Z, changes[1].Z);
int endZ = Math.Max(changes[0].Z, changes[1].Z);
// Add every block between two points to the block changes list.
for (int x = startX; x <= endX; x++)
for (int y = startY; y <= endY; y++)
for (int z = startZ; z <= endZ; z++)
{
p.BlockChanges.Add(x, y, z, block);
}
// Check if the player can place that many blocks if not abort the changes.
if (p.group.maxBlocks < p.BlockChanges.Count)
{
Player.SendMessage(p, string.Format("You can't place {0} blocks. Your limit is {1}."
, p.BlockChanges.Count, p.group.maxBlocks));
p.BlockChanges.Abort();
return;
}
// Send the block changes.
Player.SendMessage(p, string.Format("You've built a simple cuboid that consists of {0} blocks."
, p.BlockChanges.Count));
p.BlockChanges.Commit();
// If the static mode is on, repeat.
if (p.staticCommands)
BlockCatch.CaptureMultipleBlocks(p, 2, DrawCuboid, da);
}
public override void Help(Player p)
{
Player.SendMessage(p, "/scuboid <block> - draws a simple cuboid.");
Player.SendMessage(p, "block - a block type e.g. water, it's optional.");
}
}
}