mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-29 00:26:15 -04:00
Add /gb copy and /lb copy. (Thanks william341)
This commit is contained in:
parent
bfb535c88d
commit
7dc6fd4cfc
@ -41,6 +41,10 @@ namespace MCGalaxy.Commands {
|
|||||||
case "add":
|
case "add":
|
||||||
case "create":
|
case "create":
|
||||||
AddHandler(p, parts, global); break;
|
AddHandler(p, parts, global); break;
|
||||||
|
case "copy":
|
||||||
|
case "clone":
|
||||||
|
case "duplicate":
|
||||||
|
CopyHandler(p, parts, global); break;
|
||||||
case "delete":
|
case "delete":
|
||||||
case "remove":
|
case "remove":
|
||||||
RemoveHandler(p, parts, global); break;
|
RemoveHandler(p, parts, global); break;
|
||||||
@ -69,9 +73,8 @@ namespace MCGalaxy.Commands {
|
|||||||
if (!CheckBlockId(p, id, global, out targetId)) return;
|
if (!CheckBlockId(p, id, global, out targetId)) return;
|
||||||
BlockDefinition[] defs = global ? BlockDefinition.GlobalDefs : p.level.CustomBlockDefs;
|
BlockDefinition[] defs = global ? BlockDefinition.GlobalDefs : p.level.CustomBlockDefs;
|
||||||
BlockDefinition def = defs[targetId];
|
BlockDefinition def = defs[targetId];
|
||||||
if (!global && def == BlockDefinition.GlobalDefs[targetId]) def = null;
|
|
||||||
|
|
||||||
if (def != null) {
|
if (ExistsInScope(def, targetId, global)) {
|
||||||
Player.SendMessage(p, "There is already a custom block with the id " + id +
|
Player.SendMessage(p, "There is already a custom block with the id " + id +
|
||||||
", you must either use a different id or use \"" + cmd + " remove " + id + "\"");
|
", you must either use a different id or use \"" + cmd + " remove " + id + "\"");
|
||||||
return;
|
return;
|
||||||
@ -97,6 +100,29 @@ namespace MCGalaxy.Commands {
|
|||||||
SendStepHelp(p, GetStep(p, global));
|
SendStepHelp(p, GetStep(p, global));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CopyHandler(Player p, string[] parts, bool global) {
|
||||||
|
int srcId, dstId;
|
||||||
|
if (!CheckBlockId(p, parts[1], global, out srcId)) return;
|
||||||
|
if (!CheckBlockId(p, parts[2], global, out dstId)) return;
|
||||||
|
BlockDefinition[] defs = global ? BlockDefinition.GlobalDefs : p.level.CustomBlockDefs;
|
||||||
|
string cmd = global ? "/gb" : "/lb";
|
||||||
|
|
||||||
|
BlockDefinition src = defs[srcId], dst = defs[dstId];
|
||||||
|
if (!ExistsInScope(src, srcId, global)) { MessageNoBlock(p, srcId, global); return; }
|
||||||
|
if (ExistsInScope(dst, dstId, global)) { MessageAlreadyBlock(p, dstId, global); return; }
|
||||||
|
|
||||||
|
dst = src.Copy();
|
||||||
|
dst.BlockID = (byte)dstId;
|
||||||
|
BlockDefinition.Add(dst, defs, p == null ? null : p.level);
|
||||||
|
string scope = global ? "global" : "level";
|
||||||
|
Player.SendMessage(p, "Duplicated the " + scope + " custom block " +
|
||||||
|
"with id \"" + srcId + "\" to \"" + dstId + "\".");
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ExistsInScope(BlockDefinition def, int i, bool global) {
|
||||||
|
return def != null && (global ? true : def != BlockDefinition.GlobalDefs[i]);
|
||||||
|
}
|
||||||
|
|
||||||
void ListHandler(Player p, string[] parts, bool global) {
|
void ListHandler(Player p, string[] parts, bool global) {
|
||||||
int offset = 0, index = 0, count = 0;
|
int offset = 0, index = 0, count = 0;
|
||||||
if (parts.Length > 1) int.TryParse(parts[1], out offset);
|
if (parts.Length > 1) int.TryParse(parts[1], out offset);
|
||||||
@ -104,8 +130,7 @@ namespace MCGalaxy.Commands {
|
|||||||
string cmd = global ? "/gb" : "/lb";
|
string cmd = global ? "/gb" : "/lb";
|
||||||
for( int i = 1; i < 256; i++ ) {
|
for( int i = 1; i < 256; i++ ) {
|
||||||
BlockDefinition def = defs[i];
|
BlockDefinition def = defs[i];
|
||||||
if (def == null) continue;
|
if (!ExistsInScope(def, i, global)) continue;
|
||||||
if (!global && def == BlockDefinition.GlobalDefs[i]) continue;
|
|
||||||
|
|
||||||
if (index >= offset) {
|
if (index >= offset) {
|
||||||
count++;
|
count++;
|
||||||
@ -129,8 +154,7 @@ namespace MCGalaxy.Commands {
|
|||||||
|
|
||||||
BlockDefinition[] defs = global ? BlockDefinition.GlobalDefs : p.level.CustomBlockDefs;
|
BlockDefinition[] defs = global ? BlockDefinition.GlobalDefs : p.level.CustomBlockDefs;
|
||||||
BlockDefinition def = defs[blockId];
|
BlockDefinition def = defs[blockId];
|
||||||
if (!global && def == BlockDefinition.GlobalDefs[blockId]) def = null;
|
if (!ExistsInScope(def, blockId, global)) { MessageNoBlock(p, blockId, global); return; }
|
||||||
if (def == null) { MessageNoBlock(p, global); return; }
|
|
||||||
|
|
||||||
BlockDefinition.Remove(def, defs, p == null ? null : p.level);
|
BlockDefinition.Remove(def, defs, p == null ? null : p.level);
|
||||||
BlockDefinition globalDef = BlockDefinition.GlobalDefs[blockId];
|
BlockDefinition globalDef = BlockDefinition.GlobalDefs[blockId];
|
||||||
@ -164,7 +188,7 @@ namespace MCGalaxy.Commands {
|
|||||||
if (byte.TryParse(value, out bd.TopTex))
|
if (byte.TryParse(value, out bd.TopTex))
|
||||||
step++;
|
step++;
|
||||||
} else if (step == 6) {
|
} else if (step == 6) {
|
||||||
if (byte.TryParse(value, out bd.SideTex)) {
|
if (byte.TryParse(value, out bd.SideTex)) {
|
||||||
bd.LeftTex = bd.SideTex; bd.RightTex = bd.SideTex;
|
bd.LeftTex = bd.SideTex; bd.RightTex = bd.SideTex;
|
||||||
bd.FrontTex = bd.SideTex; bd.BackTex = bd.SideTex;
|
bd.FrontTex = bd.SideTex; bd.BackTex = bd.SideTex;
|
||||||
step++;
|
step++;
|
||||||
@ -236,7 +260,8 @@ namespace MCGalaxy.Commands {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Player.SendMessage(p, "Created a new custom block " + bd.Name + "(" + bd.BlockID + ")");
|
string scope = global ? "global" : "level";
|
||||||
|
Player.SendMessage(p, "Created a new " + scope + " custom block " + bd.Name + "(" + bd.BlockID + ")");
|
||||||
BlockDefinition.Add(bd, defs, p == null ? null : p.level);
|
BlockDefinition.Add(bd, defs, p == null ? null : p.level);
|
||||||
SetBD(p, global, null);
|
SetBD(p, global, null);
|
||||||
SetStep(p, global, 0);
|
SetStep(p, global, 0);
|
||||||
@ -257,11 +282,10 @@ namespace MCGalaxy.Commands {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int blockId;
|
int blockId;
|
||||||
if (!CheckBlockId(p, parts[1], global, out blockId)) return;
|
if (!CheckBlockId(p, parts[1], global, out blockId)) return;
|
||||||
BlockDefinition[] defs = global ? BlockDefinition.GlobalDefs : p.level.CustomBlockDefs;
|
BlockDefinition[] defs = global ? BlockDefinition.GlobalDefs : p.level.CustomBlockDefs;
|
||||||
BlockDefinition def = defs[blockId];
|
BlockDefinition def = defs[blockId];
|
||||||
if (!global && def == BlockDefinition.GlobalDefs[blockId]) def = null;
|
if (!ExistsInScope(def, blockId, global)) { MessageNoBlock(p, blockId, global); return; }
|
||||||
if (def == null) { MessageNoBlock(p, global); return; }
|
|
||||||
|
|
||||||
string value = parts[3];
|
string value = parts[3];
|
||||||
float fTemp;
|
float fTemp;
|
||||||
@ -305,7 +329,7 @@ namespace MCGalaxy.Commands {
|
|||||||
case "back":
|
case "back":
|
||||||
case "backtex":
|
case "backtex":
|
||||||
if (!EditByte(p, value, "Back texture", ref def.BackTex)) return;
|
if (!EditByte(p, value, "Back texture", ref def.BackTex)) return;
|
||||||
break;
|
break;
|
||||||
case "bottom":
|
case "bottom":
|
||||||
case "bottomtex":
|
case "bottomtex":
|
||||||
if (!EditByte(p, value, "Bottom texture", ref def.BottomTex)) return;
|
if (!EditByte(p, value, "Bottom texture", ref def.BottomTex)) return;
|
||||||
@ -375,9 +399,12 @@ namespace MCGalaxy.Commands {
|
|||||||
def.FallBack = tempX; break;
|
def.FallBack = tempX; break;
|
||||||
default:
|
default:
|
||||||
Player.SendMessage(p, "Unrecognised property: " + parts[2]); return;
|
Player.SendMessage(p, "Unrecognised property: " + parts[2]); return;
|
||||||
}
|
}
|
||||||
|
BlockDefinition.Add(def, defs, p == null ? null : p.level);
|
||||||
BlockDefinition.Add(def, defs, p == null ? null : p.level);
|
ReloadMap(p, global);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ReloadMap(Player p, bool global) {
|
||||||
foreach (Player pl in PlayerInfo.players) {
|
foreach (Player pl in PlayerInfo.players) {
|
||||||
if (!pl.HasCpeExt(CpeExt.BlockDefinitions)) continue;
|
if (!pl.HasCpeExt(CpeExt.BlockDefinitions)) continue;
|
||||||
if (!global && p.level != pl.level) continue;
|
if (!global && p.level != pl.level) continue;
|
||||||
@ -395,10 +422,17 @@ namespace MCGalaxy.Commands {
|
|||||||
return Block.Zero;
|
return Block.Zero;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void MessageNoBlock(Player p, bool global) {
|
static void MessageNoBlock(Player p, int id, bool global) {
|
||||||
string scope = global ? "global" : "level";
|
string scope = global ? "global" : "level";
|
||||||
string cmd = global ? "/gb" : "/lb";
|
string cmd = global ? "/gb" : "/lb";
|
||||||
Player.SendMessage(p, "There is no " + scope + " custom block with that block id.");
|
Player.SendMessage(p, "There is no " + scope + " custom block with the id \"" + id + "\".");
|
||||||
|
Player.SendMessage(p, "Type \"%T" + cmd +" list\" %Sto see a list of " + scope + " custom blocks.");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void MessageAlreadyBlock(Player p, int id, bool global) {
|
||||||
|
string scope = global ? "global" : "level";
|
||||||
|
string cmd = global ? "/gb" : "/lb";
|
||||||
|
Player.SendMessage(p, "There is already a " + scope + " custom block with the id \"" + id + "\".");
|
||||||
Player.SendMessage(p, "Type \"%T" + cmd +" list\" %Sto see a list of " + scope + " custom blocks.");
|
Player.SendMessage(p, "Type \"%T" + cmd +" list\" %Sto see a list of " + scope + " custom blocks.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -500,11 +534,11 @@ namespace MCGalaxy.Commands {
|
|||||||
static BlockDefinition consoleBD;
|
static BlockDefinition consoleBD;
|
||||||
static int consoleStep, consoleTargetId;
|
static int consoleStep, consoleTargetId;
|
||||||
|
|
||||||
static BlockDefinition GetBD(Player p, bool global) {
|
static BlockDefinition GetBD(Player p, bool global) {
|
||||||
return p == null ? consoleBD : (global ? p.gbBlock : p.lbBlock);
|
return p == null ? consoleBD : (global ? p.gbBlock : p.lbBlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int GetStep(Player p, bool global) {
|
static int GetStep(Player p, bool global) {
|
||||||
return p == null ? consoleStep : (global ? p.gbStep : p.lbStep);
|
return p == null ? consoleStep : (global ? p.gbStep : p.lbStep);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -530,11 +564,12 @@ namespace MCGalaxy.Commands {
|
|||||||
string fullCmd = global ? "/globalblock" : "/levelblock";
|
string fullCmd = global ? "/globalblock" : "/levelblock";
|
||||||
string cmd = global ? "/gb" : "/lb";
|
string cmd = global ? "/gb" : "/lb";
|
||||||
|
|
||||||
Player.SendMessage(p, "%T" + fullCmd + " <add/remove/list/edit>");
|
Player.SendMessage(p, "%T" + fullCmd + " <add/copy/edit/list/remove>");
|
||||||
Player.SendMessage(p, "%H " + cmd + " add [id] - begins the creation a new custom block.");
|
Player.SendMessage(p, "%H " + cmd + " add [id] - begins the creation a new custom block.");
|
||||||
Player.SendMessage(p, "%H " + cmd + " remove id - removes the custom block with the given id.");
|
Player.SendMessage(p, "%H " + cmd + " copy [source id] [new id] - clones a new custom block from the existing source block.");
|
||||||
|
Player.SendMessage(p, "%H " + cmd + " edit [id] [property] [value] - edits the given property of the custom block with that id.");
|
||||||
Player.SendMessage(p, "%H " + cmd + " list [offset] - lists all custom blocks.");
|
Player.SendMessage(p, "%H " + cmd + " list [offset] - lists all custom blocks.");
|
||||||
Player.SendMessage(p, "%H " + cmd + " edit id property value - edits the given property of the custom block with the given id.");
|
Player.SendMessage(p, "%H " + cmd + " remove [id] - removes the custom block with that id.");
|
||||||
Player.SendMessage(p, "%HTo see the list of editable properties, type " + cmd + " edit.");
|
Player.SendMessage(p, "%HTo see the list of editable properties, type " + cmd + " edit.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,6 +49,25 @@ namespace MCGalaxy {
|
|||||||
|
|
||||||
public static BlockDefinition[] GlobalDefs;
|
public static BlockDefinition[] GlobalDefs;
|
||||||
|
|
||||||
|
public BlockDefinition Copy() {
|
||||||
|
BlockDefinition def = new BlockDefinition();
|
||||||
|
def.BlockID = BlockID; def.Name = Name;
|
||||||
|
def.CollideType = CollideType; def.Speed = Speed;
|
||||||
|
def.TopTex = TopTex; def.SideTex = SideTex;
|
||||||
|
def.BottomTex = BottomTex; def.BlocksLight = BlocksLight;
|
||||||
|
def.WalkSound = WalkSound; def.FullBright = FullBright;
|
||||||
|
def.Shape = Shape; def.BlockDraw = BlockDraw;
|
||||||
|
def.FogDensity = FogDensity; def.FogR = FogR;
|
||||||
|
def.FogG = FogG; def.FogB = FogB;
|
||||||
|
def.FallBack = FallBack;
|
||||||
|
def.MinX = MinX; def.MinY = MinY; def.MinZ = MinZ;
|
||||||
|
def.MaxX = MaxX; def.MaxY = MaxY; def.MaxZ = MaxZ;
|
||||||
|
def.Version2 = Version2;
|
||||||
|
def.LeftTex = LeftTex; def.RightTex = RightTex;
|
||||||
|
def.FrontTex = FrontTex; def.BackTex = BackTex;
|
||||||
|
return def;
|
||||||
|
}
|
||||||
|
|
||||||
public static void LoadGlobal() {
|
public static void LoadGlobal() {
|
||||||
GlobalDefs = Load(true, null);
|
GlobalDefs = Load(true, null);
|
||||||
GlobalDefs[0] = new BlockDefinition();
|
GlobalDefs[0] = new BlockDefinition();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user