Example #1
0
 public static void RemoveGlobalBlock(BlockDefinition def) {
     string name = def.Name.ToLower().Replace(" ", "");         
     Map.BlockNames.Remove(name);
     Map.BlockNames.Remove(def.BlockID.ToString());
     
     GlobalDefinitions[def.BlockID] = null;
     Map.FallbackBlocks[def.BlockID] = Block.Air;
 }
Example #2
0
 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;
     return def;
 }
Example #3
0
 public static void DefineGlobalBlock(BlockDefinition def) {
     // fixup for legacy files
     if (def.MinX == 0 && def.MaxX == 0 ) 
         def.MaxX = 16;
     if (def.MinY == 0 && def.MaxY == 0 ) 
         def.MaxY = 16;
     if (def.MinZ == 0 && def.MaxZ == 0 )
         def.MaxZ = def.Shape == 0 ? (byte)16 : def.Shape;
     
     string name = def.Name.ToLower().Replace(" ", "");         
     Map.BlockNames[name] = (Block)def.BlockID;
     Map.BlockNames[def.BlockID.ToString()] = (Block)def.BlockID;
     
     GlobalDefinitions[def.BlockID] = def;
     Map.FallbackBlocks[def.BlockID] = (Block)def.FallBack;
 }
Example #4
0
  public static void SendGlobalAdd(Player p, BlockDefinition def) {
     if (p.Supports(CpeExtension.BlockDefinitionsExt) && def.Shape != 0)
         p.Send(Packet.MakeDefineBlockExt(def));
     else
         p.Send(Packet.MakeDefineBlock(def));
     p.Send(Packet.MakeSetBlockPermission((Block)def.BlockID, true, true));
 }
Example #5
0
 public static void SendGlobalRemove(Player p, BlockDefinition def) {
     p.Send(Packet.MakeRemoveBlockDefinition(def.BlockID));
     p.Send(Packet.MakeSetBlockPermission((Block)def.BlockID, false, false));
 }
Example #6
0
 static void MakeDefineBlockEnd(BlockDefinition def, int offset, ref Packet packet) {
     packet.Bytes[offset + 0] = def.BlockDraw;
     packet.Bytes[offset + 1] = def.FogDensity;
     packet.Bytes[offset + 2] = def.FogR;
     packet.Bytes[offset + 3] = def.FogG;
     packet.Bytes[offset + 4] = def.FogB;
 }
Example #7
0
 static void MakeDefineBlockStart(BlockDefinition def, ref Packet packet) {
 	// speed = 2^((raw - 128) / 64);
     // therefore raw = 64log2(speed) + 128
     byte rawSpeed = (byte)(64 * Math.Log(def.Speed, 2) + 128);
     
     packet.Bytes[1] = def.BlockID;
     Encoding.ASCII.GetBytes(def.Name.PadRight(64), 0, 64, packet.Bytes, 2);
     packet.Bytes[66] = def.CollideType;
     packet.Bytes[67] = rawSpeed;
     packet.Bytes[68] = def.TopTex;
     packet.Bytes[69] = def.SideTex;
     packet.Bytes[70] = def.BottomTex;
     packet.Bytes[71] = (byte)(def.BlocksLight ? 0 : 1);
     packet.Bytes[72] = def.WalkSound;
     packet.Bytes[73] = (byte)(def.FullBright ? 1 : 0);
 }
Example #8
0
 public static Packet MakeDefineBlockExt(BlockDefinition def) {
     Packet packet = new Packet( OpCode.DefineBlockExt );
     MakeDefineBlockStart(def, ref packet);
     packet.Bytes[74] = def.MinX;
     packet.Bytes[75] = def.MinZ;
     packet.Bytes[76] = def.MinY;
     packet.Bytes[77] = def.MaxX;
     packet.Bytes[78] = def.MaxZ;
     packet.Bytes[79] = def.MaxY;
     MakeDefineBlockEnd(def, 80, ref packet);
     return packet;
 }
Example #9
0
 public static Packet MakeDefineBlock(BlockDefinition def) {
     Packet packet = new Packet( OpCode.DefineBlock );
     MakeDefineBlockStart(def, ref packet);
     packet.Bytes[74] = def.Shape;
     MakeDefineBlockEnd(def, 75, ref packet);
     return packet;
 }