Esempio n. 1
0
        public override void execute(Client client, NetIncomingMessage data)
        {
            int
                _size  = data.ReadInt32(),
                _x     = data.ReadInt32(),
                _y     = data.ReadInt32(),
                _layer = data.ReadInt32(),
                _id    = data.ReadInt32();

            if (_layer < 0)
            {
                //_teID = data.ReadInt32();
            }

            //Setting the tile on the server
            for (int __x = -_size; __x <= _size; __x++)
            {
                for (int __y = -_size; __y <= _size; __y++)
                {
                    MapTile t = Rater193.StaticRooms.world.SetTile(__x + _x, __y + _y, _layer, _id);
                    ///t.tileEntity = TileEntityBase.GetTileEntity(0);
                }
            }

            //Sending the message created tile to the connected clients
            foreach (Client c in RegionalServer.clientList)
            {
                if (c != null && c.connection != null)
                {
                    NetOutgoingMessage msg = RegionalServer.server.CreateMessage();
                    msg.Write((byte)1);                     //WORLD
                    msg.Write((byte)255);                   //Rater193's header message group
                    msg.Write((byte)symmnet.regional.rater193.Messages.ClientReceiveTile);

                    msg.Write((int)_size);
                    msg.Write((int)_x);
                    msg.Write((int)_y);
                    msg.Write((int)_layer);
                    msg.Write((int)_layer >= 0 ? _id : TileEntityBase.GetTileEntity(_id).renderID);                    //Replace the 100 with the tile entity id!
                    if (_layer < 0)
                    {
                        //RegionalServer.logList.Add( new object[] {ConsoleColor.White, "id: " + _id });
                        //RegionalServer.UpdateConsole();
                    }

                    RegionalServer.server.SendMessage(msg, c.connection, NetDeliveryMethod.ReliableOrdered, 16);
                }

                //StaticRooms.hub.SendChunkToClient(c, (int)MathF.Floor((float)_x / (float)MapManager.Settings.chunkSize), (int)MathF.Floor((float)_y / (float)MapManager.Settings.chunkSize));
            }
            //TODO: Send the specific tile update to all other clients inside the room. (NOT THE WHOLE CHUNK!)
        }
Esempio n. 2
0
        /// <summary>
        /// Adds the passed TileEntity into the world, throwing an exception if there is already a TileEntity there.
        /// </summary>
        public void addTileEntity(BlockPos pos, TileEntityBase tileEntity)
        {
            Chunk chunk = this.getChunk(pos);

            if (chunk != null)
            {
                if (chunk.tileEntityDict.ContainsKey(pos))
                {
                    Debug.Log(chunk.tileEntityDict[pos]);
                    throw new Exception("Error!  Something tried to add a second TileEntity at " + pos.ToString() + "!");
                }
                this.getChunk(pos).tileEntityDict.Add(pos, tileEntity);
            }
        }
Esempio n. 3
0
        public void readFromNbt(NbtCompound tag)
        {
            this.hasDoneGen2 = tag.Get <NbtByte>("hasDoneGen2").ByteValue == 1 ? true : false;
            byte[] blockBytes = tag.Get <NbtByteArray>("blocks").ByteArrayValue;
            for (int i = 0; i < Chunk.BLOCK_COUNT; i++)
            {
                this.blocks[i] = Block.getBlockFromId(blockBytes[i]);
            }
            this.metaData   = tag.Get <NbtByteArray>("meta").ByteArrayValue;
            this.lightLevel = tag.Get <NbtByteArray>("light").ByteArrayValue;

            // Populate the tile entity dictionary.
            foreach (NbtCompound compound in tag.Get <NbtList>("tileEntities"))
            {
                BlockPos       pos = new BlockPos(compound.Get <NbtInt>("x").Value, compound.Get <NbtInt>("y").Value, compound.Get <NbtInt>("z").Value);
                TileEntityBase te  = TileEntityBase.getTileEntityFromId(this.world, pos, compound);
                te.readFromNbt(compound);
                this.world.addTileEntity(pos, te);
            }

            // Populate the tile entity dictionary.
            foreach (NbtCompound compound in tag.Get <NbtList>("scheduledTicks"))
            {
                this.scheduledTicks.Add(new ScheduledTick(compound));
            }

            // Spawn the entities that were saved in the chunk back into the world.
            foreach (NbtCompound compound in tag.Get <NbtList>("entities"))
            {
                int id = compound.Get <NbtInt>("id").Value;
                RegisteredEntity re = EntityRegistry.getRegisteredEntityFromId(id);
                if (re != null)
                {
                    this.world.spawnEntity(re, compound);
                }
                else
                {
                    print("Error!  Entity with an unknown ID of " + id + " was found!  Ignoring!");
                }
            }
        }
Esempio n. 4
0
        internal MapTile SetTileEntity(int localPosX, int localPosY, int tileEntityID)
        {
            //Keeping the values within the chunk size, JUST incase :P
            localPosX = localPosX % MapManager.Settings.chunkSize;
            localPosY = localPosY % MapManager.Settings.chunkSize;

            if (localPosX < 0)
            {
                localPosX += MapManager.Settings.chunkSize;
                localPosX  = (int)MathF.Abs(-localPosX);
            }
            if (localPosY < 0)
            {
                localPosY += MapManager.Settings.chunkSize;
                localPosY  = (int)MathF.Abs(-localPosY);
            }


            MapTile t = null;

            //Trying to set the map tile
            string tileKey = GetTileKey(localPosX, localPosY);

            if (!tiles.ContainsKey(tileKey))
            {
                t = new MapTile(-1);
                tiles.Add(tileKey, t);
            }
            else
            {
                tiles.TryGetValue(tileKey, out t);
                t.tileID = -1;
            }
            //t.tileEntity = TileEntityBase.GetTileEntity(tileEntityID);
            t.tileEntity = TileEntityBase.GetTileEntity(tileEntityID);
            //RegionalServer.logList.Add(new object[] { ConsoleColor.White, "Setting tile entity?" });
            //RegionalServer.UpdateConsole();
            return(GetTile(localPosX, localPosY));
        }
Esempio n. 5
0
        public static void OnPlayerJoined(Client client)
        {
            NetworkPlayer.OnClientConnect(client);
            if (RegionalServer.IsMapEditor())
            {
                //Send the tile entity data here

                NetOutgoingMessage msg = RegionalServer.server.CreateMessage();
                msg.Write((byte)1);                 //WORLD
                msg.Write((byte)255);               //Rater193's header message group
                msg.Write((byte)symmnet.regional.rater193.Messages.ClientReceiveTileEntityList);

                //Writing the ammount of tile entities to receive
                msg.Write((int)TileEntityBase.registeredEntities.Count);

                foreach (int key in TileEntityBase.registeredEntities.Keys)
                {
                    //Here we write the tile entity id, and the render id to use for it
                    msg.Write((int)key);
                    msg.Write((int)TileEntityBase.GetTileEntity(key).renderID);
                }
                client.connection.SendMessage(msg, NetDeliveryMethod.ReliableOrdered, 2);
            }
        }