Пример #1
0
    // Schedules a BUD request in the system
    public void ScheduleBUD(BUDSignal b, int tickOffset)
    {
        if (tickOffset == 0)
        {
            if (this.data.ContainsKey(this.currentTime))
            {
                if (!this.data[this.currentTime].Contains(b))
                {
                    this.data[this.currentTime].Add(b);
                }
            }
            else
            {
                this.data.Add(this.currentTime, new List <BUDSignal>());
                this.data[this.currentTime].Add(b);
            }
        }
        else
        {
            string fakeTime = schedulerTime.FakeSum(tickOffset);

            if (this.data.ContainsKey(fakeTime))
            {
                if (!this.data[fakeTime].Contains(b))
                {
                    this.data[fakeTime].Add(b);
                }
            }
            else
            {
                this.data.Add(fakeTime, new List <BUDSignal>());
                this.data[fakeTime].Add(b);
            }
        }
    }
Пример #2
0
 // Deschedules a BUD request (probably when block is broken or updated)
 public void RemoveBUD(BUDSignal b)
 {
     foreach (string key in this.data.Keys)
     {
         this.data[key].RemoveAll(bud => bud.Equals(b));
     }
 }
Пример #3
0
    // Handles the emittion of BUD to neighboring blocks
    public void EmitBlockUpdate(BUDCode type, int x, int y, int z, int tickOffset, ChunkLoader_Server cl)
    {
        CastCoord thisPos = GetCoordinates(x, y, z);
        BUDSignal cachedBUD;

        CastCoord[] neighbors =
        {
            thisPos.Add(1,   0, 0),
            thisPos.Add(-1,  0, 0),
            thisPos.Add(0,   1, 0),
            thisPos.Add(0,  -1, 0),
            thisPos.Add(0,   0, 1),
            thisPos.Add(0,   0, -1)
        };

        int[] facings = { 2, 0, 4, 5, 1, 3 };

        int faceCounter = 0;

        foreach (CastCoord c in neighbors)
        {
            // Ignores void updates
            if (c.blockY < 0 || c.blockY > Chunk.chunkDepth - 1)
            {
                continue;
            }

            cachedBUD = new BUDSignal(type, c.GetWorldX(), c.GetWorldY(), c.GetWorldZ(), thisPos.GetWorldX(), thisPos.GetWorldY(), thisPos.GetWorldZ(), facings[faceCounter]);
            cl.budscheduler.ScheduleBUD(cachedBUD, tickOffset);

            faceCounter++;
        }
    }
Пример #4
0
 public bool Equals(BUDSignal b)
 {
     if (this.x == b.x && this.y == b.y && this.z == b.z)
     {
         return(true);
     }
     return(false);
 }
Пример #5
0
 // Schedules a BUD request in the system in the current tick
 public void ScheduleBUDNow(BUDSignal b)
 {
     if (this.data.ContainsKey(this.currentTime))
     {
         this.data[this.currentTime].Add(b);
     }
     else
     {
         this.data.Add(this.currentTime, new List <BUDSignal>());
         this.data[this.currentTime].Add(b);
     }
 }
Пример #6
0
 // Sends a BUD packet to the server
 public void SendBUD(BUDSignal bud, int timeOffset)
 {
     NetDecoder.WriteInt((int)bud.type, NetMessage.buffer, 1);
     NetDecoder.WriteInt(bud.x, NetMessage.buffer, 5);
     NetDecoder.WriteInt(bud.y, NetMessage.buffer, 9);
     NetDecoder.WriteInt(bud.z, NetMessage.buffer, 13);
     NetDecoder.WriteInt(bud.budX, NetMessage.buffer, 17);
     NetDecoder.WriteInt(bud.budY, NetMessage.buffer, 21);
     NetDecoder.WriteInt(bud.budZ, NetMessage.buffer, 25);
     NetDecoder.WriteInt(bud.facing, NetMessage.buffer, 29);
     NetDecoder.WriteInt(timeOffset, NetMessage.buffer, 33);
     this.size = 37;
 }
Пример #7
0
    // Processes a simple BUD request
    private void SendBUD(byte[] data)
    {
        BUDSignal bud;
        BUDCode   code;
        int       x, y, z, budX, budY, budZ, facing, offset;

        code   = (BUDCode)NetDecoder.ReadInt(data, 1);
        x      = NetDecoder.ReadInt(data, 5);
        y      = NetDecoder.ReadInt(data, 9);
        z      = NetDecoder.ReadInt(data, 13);
        budX   = NetDecoder.ReadInt(data, 17);
        budY   = NetDecoder.ReadInt(data, 21);
        budZ   = NetDecoder.ReadInt(data, 25);
        facing = NetDecoder.ReadInt(data, 29);
        offset = NetDecoder.ReadInt(data, 33);

        bud = new BUDSignal(code, x, y, z, budX, budY, budZ, facing);

        this.cl.budscheduler.ScheduleBUD(bud, offset);
    }