mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-23 04:32:50 -04:00
Allow custom blocks to stack with /blockprops. Fixes #330
This commit is contained in:
parent
d127436ec4
commit
23c37f00dd
@ -42,11 +42,11 @@ namespace MCGalaxy.Blocks {
|
|||||||
switch (block.BlockID) {
|
switch (block.BlockID) {
|
||||||
case Block.dirt: return PlaceBehaviour.Dirt;
|
case Block.dirt: return PlaceBehaviour.Dirt;
|
||||||
case Block.grass: return PlaceBehaviour.Grass;
|
case Block.grass: return PlaceBehaviour.Grass;
|
||||||
case Block.staircasestep: return PlaceBehaviour.Stairs;
|
|
||||||
case Block.cobblestoneslab: return PlaceBehaviour.CobbleStairs;
|
|
||||||
case Block.c4: return PlaceBehaviour.C4;
|
case Block.c4: return PlaceBehaviour.C4;
|
||||||
case Block.c4det: return PlaceBehaviour.C4Det;
|
case Block.c4det: return PlaceBehaviour.C4Det;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (props[block.Index].StackId != Block.air) return PlaceBehaviour.Stack(block);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,8 +129,6 @@ namespace MCGalaxy.Blocks {
|
|||||||
case Block.lava_fire: return FirePhysics.Do;
|
case Block.lava_fire: return FirePhysics.Do;
|
||||||
case Block.sand: return OtherPhysics.DoFalling;
|
case Block.sand: return OtherPhysics.DoFalling;
|
||||||
case Block.gravel: return OtherPhysics.DoFalling;
|
case Block.gravel: return OtherPhysics.DoFalling;
|
||||||
case Block.cobblestoneslab: return OtherPhysics.DoStairs;
|
|
||||||
case Block.staircasestep: return OtherPhysics.DoStairs;
|
|
||||||
case Block.wood_float: return OtherPhysics.DoFloatwood;
|
case Block.wood_float: return OtherPhysics.DoFloatwood;
|
||||||
|
|
||||||
case Block.sponge: return (Level lvl, ref Check C) =>
|
case Block.sponge: return (Level lvl, ref Check C) =>
|
||||||
|
@ -44,28 +44,19 @@ namespace MCGalaxy.Blocks {
|
|||||||
p.ChangeBlock(x, y, z, block);
|
p.ChangeBlock(x, y, z, block);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static HandlePlace Stack(ExtBlock block) {
|
||||||
internal static void Stairs(Player p, ExtBlock block, ushort x, ushort y, ushort z) {
|
return (p, b, x, y, z) => Stack(p, block, x, y, z);
|
||||||
if (!(p.level.physics == 0 || p.level.physics == 5)
|
}
|
||||||
|| p.level.GetBlock(x, (ushort)(y - 1), z) != (ExtBlock)Block.staircasestep) {
|
static void Stack(Player p, ExtBlock block, ushort x, ushort y, ushort z) {
|
||||||
p.ChangeBlock(x, y, z, (ExtBlock)Block.staircasestep); return;
|
if (p.level.GetBlock(x, (ushort)(y - 1), z) != block) {
|
||||||
|
p.ChangeBlock(x, y, z, block); return;
|
||||||
}
|
}
|
||||||
|
|
||||||
p.SendBlockchange(x, y, z, ExtBlock.Air); // send the air block back only to the user
|
p.SendBlockchange(x, y, z, ExtBlock.Air); // send the air block back only to the user
|
||||||
p.ChangeBlock(x, (ushort)(y - 1), z, (ExtBlock)Block.staircasefull);
|
byte stack = p.level.BlockProps[block.Index].StackId;
|
||||||
|
p.ChangeBlock(x, (ushort)(y - 1), z, ExtBlock.FromRaw(stack));
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void CobbleStairs(Player p, ExtBlock block, ushort x, ushort y, ushort z) {
|
|
||||||
if (!(p.level.physics == 0 || p.level.physics == 5)
|
|
||||||
|| p.level.GetBlock(x, (ushort)(y - 1), z) != (ExtBlock)Block.cobblestoneslab) {
|
|
||||||
p.ChangeBlock(x, y, z, (ExtBlock)Block.cobblestoneslab); return;
|
|
||||||
}
|
|
||||||
|
|
||||||
p.SendBlockchange(x, y, z, ExtBlock.Air); // send the air block back only to the user
|
|
||||||
p.ChangeBlock(x, (ushort)(y - 1), z, (ExtBlock)Block.stone);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
internal static void C4(Player p, ExtBlock block, ushort x, ushort y, ushort z) {
|
internal static void C4(Player p, ExtBlock block, ushort x, ushort y, ushort z) {
|
||||||
if (p.level.physics == 0 || p.level.physics == 5) {
|
if (p.level.physics == 0 || p.level.physics == 5) {
|
||||||
p.RevertBlock(x, y, z); return;
|
p.RevertBlock(x, y, z); return;
|
||||||
|
@ -83,6 +83,8 @@ namespace MCGalaxy {
|
|||||||
Props[sponge].LavaKills = true; Props[bookcase].LavaKills = true;
|
Props[sponge].LavaKills = true; Props[bookcase].LavaKills = true;
|
||||||
Props[leaf].LavaKills = true; Props[crate].LavaKills = true;
|
Props[leaf].LavaKills = true; Props[crate].LavaKills = true;
|
||||||
Props[red].IsRails = true; Props[op_air].IsRails = true;
|
Props[red].IsRails = true; Props[op_air].IsRails = true;
|
||||||
|
Props[staircasestep].StackId = staircasefull;
|
||||||
|
Props[cobblestoneslab].StackId = stone;
|
||||||
|
|
||||||
// Block specific physics properties
|
// Block specific physics properties
|
||||||
Props[Block.birdblack].AnimalAI = AnimalAI.Fly;
|
Props[Block.birdblack].AnimalAI = AnimalAI.Fly;
|
||||||
|
@ -63,6 +63,10 @@ namespace MCGalaxy.Blocks {
|
|||||||
/// <summary> Animal AI behaviour of this block. </summary>
|
/// <summary> Animal AI behaviour of this block. </summary>
|
||||||
public AnimalAI AnimalAI;
|
public AnimalAI AnimalAI;
|
||||||
|
|
||||||
|
/// <summary> ID of the block that is placed when two of this block are placed on top of each other. </summary>
|
||||||
|
/// <remarks> e.g. slabs and cobblestone slabs. </remarks>
|
||||||
|
public byte StackId;
|
||||||
|
|
||||||
/// <summary> Whether the properties for this block have been modified and hence require saving. </summary>
|
/// <summary> Whether the properties for this block have been modified and hence require saving. </summary>
|
||||||
public bool Changed;
|
public bool Changed;
|
||||||
|
|
||||||
@ -92,7 +96,7 @@ namespace MCGalaxy.Blocks {
|
|||||||
w.WriteLine(id + ":" + props.IsRails + ":" + props.IsTDoor + ":" + props.IsDoor + ":"
|
w.WriteLine(id + ":" + props.IsRails + ":" + props.IsTDoor + ":" + props.IsDoor + ":"
|
||||||
+ props.IsMessageBlock + ":" + props.IsPortal + ":" + props.WaterKills + ":"
|
+ props.IsMessageBlock + ":" + props.IsPortal + ":" + props.WaterKills + ":"
|
||||||
+ props.LavaKills + ":" + props.KillerBlock + ":" + deathMsg + ":"
|
+ props.LavaKills + ":" + props.KillerBlock + ":" + deathMsg + ":"
|
||||||
+ (byte)props.AnimalAI);
|
+ (byte)props.AnimalAI + ":" + props.StackId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -138,6 +142,10 @@ namespace MCGalaxy.Blocks {
|
|||||||
byte ai; byte.TryParse(parts[10], out ai);
|
byte ai; byte.TryParse(parts[10], out ai);
|
||||||
scope[idx].AnimalAI = (AnimalAI)ai;
|
scope[idx].AnimalAI = (AnimalAI)ai;
|
||||||
}
|
}
|
||||||
|
if (parts.Length > 11) {
|
||||||
|
byte stackId; byte.TryParse(parts[11], out stackId);
|
||||||
|
scope[idx].StackId = stackId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -67,22 +67,6 @@ namespace MCGalaxy.Blocks.Physics {
|
|||||||
C.data.Data = PhysicsArgs.RemoveFromChecks;
|
C.data.Data = PhysicsArgs.RemoveFromChecks;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void DoStairs(Level lvl, ref Check C) {
|
|
||||||
int indexBelow = lvl.IntOffset(C.b, 0, -1, 0);
|
|
||||||
byte block = lvl.blocks[C.b];
|
|
||||||
byte below = Block.Invalid;
|
|
||||||
if (indexBelow >= 0) below = lvl.blocks[indexBelow];
|
|
||||||
|
|
||||||
if (below == Block.staircasestep && block == Block.staircasestep) {
|
|
||||||
lvl.AddUpdate(C.b, Block.air);
|
|
||||||
lvl.AddUpdate(indexBelow, Block.staircasefull);
|
|
||||||
} else if (below == Block.cobblestoneslab && block == Block.cobblestoneslab) {
|
|
||||||
lvl.AddUpdate(C.b, Block.air);
|
|
||||||
lvl.AddUpdate(indexBelow, Block.stone);
|
|
||||||
}
|
|
||||||
C.data.Data = PhysicsArgs.RemoveFromChecks;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void DoFloatwood(Level lvl, ref Check C) {
|
public static void DoFloatwood(Level lvl, ref Check C) {
|
||||||
int index = lvl.IntOffset(C.b, 0, -1, 0);
|
int index = lvl.IntOffset(C.b, 0, -1, 0);
|
||||||
if (lvl.GetTile(index) == Block.air) {
|
if (lvl.GetTile(index) == Block.air) {
|
||||||
|
@ -126,6 +126,9 @@ namespace MCGalaxy.Commands.World {
|
|||||||
} else if (prop == "animalai" || prop == "animal") {
|
} else if (prop == "animalai" || prop == "animal") {
|
||||||
string msg = args.Length > 3 ? args[3] : null;
|
string msg = args.Length > 3 ? args[3] : null;
|
||||||
SetEnum(p, scope, block, msg);
|
SetEnum(p, scope, block, msg);
|
||||||
|
} else if (prop == "stackid" || prop == "stackblock") {
|
||||||
|
string msg = args.Length > 3 ? args[3] : null;
|
||||||
|
SetStackId(p, scope, block, msg);
|
||||||
} else {
|
} else {
|
||||||
Help(p);
|
Help(p);
|
||||||
}
|
}
|
||||||
@ -173,6 +176,20 @@ namespace MCGalaxy.Commands.World {
|
|||||||
OnPropsChanged(scope, lvl, block);
|
OnPropsChanged(scope, lvl, block);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void SetStackId(Player p, BlockProps[] scope, ExtBlock block, string msg) {
|
||||||
|
Level lvl = Player.IsSuper(p) ? null : p.level;
|
||||||
|
ExtBlock stackBlock;
|
||||||
|
if (!CommandParser.GetBlock(p, msg, out stackBlock)) return;
|
||||||
|
|
||||||
|
scope[block.Index].StackId = stackBlock.RawID;
|
||||||
|
string stackBlockName = Player.IsSuper(p) ?
|
||||||
|
BlockName(scope, lvl, stackBlock) : p.level.BlockName(stackBlock);
|
||||||
|
|
||||||
|
Player.Message(p, "Stack block for {0} set to: {1}",
|
||||||
|
BlockName(scope, lvl, block), stackBlockName);
|
||||||
|
OnPropsChanged(scope, lvl, block);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void OnPropsChanged(BlockProps[] scope, Level level, ExtBlock block) {
|
static void OnPropsChanged(BlockProps[] scope, Level level, ExtBlock block) {
|
||||||
scope[block.Index].Changed = true;
|
scope[block.Index].Changed = true;
|
||||||
@ -231,7 +248,7 @@ namespace MCGalaxy.Commands.World {
|
|||||||
Player.Message(p, "%H[scope] can be: %Score, global, level");
|
Player.Message(p, "%H[scope] can be: %Score, global, level");
|
||||||
|
|
||||||
Player.Message(p, "%Hproperties: %Sportal, messageblock, rails, waterkills, " +
|
Player.Message(p, "%Hproperties: %Sportal, messageblock, rails, waterkills, " +
|
||||||
"lavakills, door, tdoor, killer, deathmessage, animalai");
|
"lavakills, door, tdoor, killer, deathmessage, animalai, stackblock");
|
||||||
Player.Message(p, "%HType %T/help blockprops [property] %Hfor more details");
|
Player.Message(p, "%HType %T/help blockprops [property] %Hfor more details");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user