mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-22 12:05:51 -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) {
|
||||
case Block.dirt: return PlaceBehaviour.Dirt;
|
||||
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.c4det: return PlaceBehaviour.C4Det;
|
||||
}
|
||||
|
||||
if (props[block.Index].StackId != Block.air) return PlaceBehaviour.Stack(block);
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -129,8 +129,6 @@ namespace MCGalaxy.Blocks {
|
||||
case Block.lava_fire: return FirePhysics.Do;
|
||||
case Block.sand: 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.sponge: return (Level lvl, ref Check C) =>
|
||||
|
@ -44,27 +44,18 @@ namespace MCGalaxy.Blocks {
|
||||
p.ChangeBlock(x, y, z, block);
|
||||
}
|
||||
|
||||
|
||||
internal static void Stairs(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.staircasestep) {
|
||||
p.ChangeBlock(x, y, z, (ExtBlock)Block.staircasestep); return;
|
||||
internal static HandlePlace Stack(ExtBlock block) {
|
||||
return (p, b, x, y, z) => Stack(p, block, x, y, z);
|
||||
}
|
||||
static void Stack(Player p, ExtBlock block, ushort x, ushort y, ushort z) {
|
||||
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.ChangeBlock(x, (ushort)(y - 1), z, (ExtBlock)Block.staircasefull);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
byte stack = p.level.BlockProps[block.Index].StackId;
|
||||
p.ChangeBlock(x, (ushort)(y - 1), z, ExtBlock.FromRaw(stack));
|
||||
}
|
||||
|
||||
internal static void C4(Player p, ExtBlock block, ushort x, ushort y, ushort z) {
|
||||
if (p.level.physics == 0 || p.level.physics == 5) {
|
||||
|
@ -83,6 +83,8 @@ namespace MCGalaxy {
|
||||
Props[sponge].LavaKills = true; Props[bookcase].LavaKills = true;
|
||||
Props[leaf].LavaKills = true; Props[crate].LavaKills = true;
|
||||
Props[red].IsRails = true; Props[op_air].IsRails = true;
|
||||
Props[staircasestep].StackId = staircasefull;
|
||||
Props[cobblestoneslab].StackId = stone;
|
||||
|
||||
// Block specific physics properties
|
||||
Props[Block.birdblack].AnimalAI = AnimalAI.Fly;
|
||||
|
@ -63,6 +63,10 @@ namespace MCGalaxy.Blocks {
|
||||
/// <summary> Animal AI behaviour of this block. </summary>
|
||||
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>
|
||||
public bool Changed;
|
||||
|
||||
@ -92,7 +96,7 @@ namespace MCGalaxy.Blocks {
|
||||
w.WriteLine(id + ":" + props.IsRails + ":" + props.IsTDoor + ":" + props.IsDoor + ":"
|
||||
+ props.IsMessageBlock + ":" + props.IsPortal + ":" + props.WaterKills + ":"
|
||||
+ 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);
|
||||
scope[idx].AnimalAI = (AnimalAI)ai;
|
||||
}
|
||||
if (parts.Length > 11) {
|
||||
byte stackId; byte.TryParse(parts[11], out stackId);
|
||||
scope[idx].StackId = stackId;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -66,22 +66,6 @@ namespace MCGalaxy.Blocks.Physics {
|
||||
}
|
||||
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) {
|
||||
int index = lvl.IntOffset(C.b, 0, -1, 0);
|
||||
|
@ -126,6 +126,9 @@ namespace MCGalaxy.Commands.World {
|
||||
} else if (prop == "animalai" || prop == "animal") {
|
||||
string msg = args.Length > 3 ? args[3] : null;
|
||||
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 {
|
||||
Help(p);
|
||||
}
|
||||
@ -173,6 +176,20 @@ namespace MCGalaxy.Commands.World {
|
||||
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) {
|
||||
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, "%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");
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user