Esempio n. 1
0
        public void UpdateWiresMesh(HangingWiresData data)
        {
            IBlockAccessor       accessor = capi?.World?.BlockAccessor;
            IClientWorldAccessor world    = capi?.World;

            if (data == null || accessor == null)
            {
                return;
            }



            Dictionary <Vec3i, MeshData> MeshPerChunk = new Dictionary <Vec3i, MeshData>();

            if (MeshRefPerChunk != null)
            {
                foreach (MeshRef meshRef in MeshRefPerChunk.Values)
                {
                    meshRef?.Dispose();
                }
            }
            MeshRefPerChunk = new Dictionary <Vec3i, MeshRef>();


            foreach (WireConnection con in data.connections)
            {
                IHangingWireAnchor block1 = accessor.GetBlock(con.pos1.blockPos) as IHangingWireAnchor;
                IHangingWireAnchor block2 = accessor.GetBlock(con.pos2.blockPos) as IHangingWireAnchor;
                if (block1 == null || block2 == null)
                {
                    continue;
                }


                BlockPos blockPos1 = con.pos1.blockPos;
                Vec3i    chunkpos  = new Vec3i(blockPos1.X / chunksize, blockPos1.Y / chunksize, blockPos1.Z / chunksize);

                Vec3f pos1 = con.pos1.blockPos.ToVec3f().AddCopy(-chunkpos.X * chunksize, -chunkpos.Y * chunksize, -chunkpos.Z * chunksize) + block1.GetAnchorPosInBlock(world, con.pos1);
                Vec3f pos2 = con.pos2.blockPos.ToVec3f().AddCopy(-chunkpos.X * chunksize, -chunkpos.Y * chunksize, -chunkpos.Z * chunksize) + block2.GetAnchorPosInBlock(world, con.pos2);

                if (MeshPerChunk.ContainsKey(chunkpos))
                {
                    MeshData newMesh = MakeWireMesh(pos1, pos2, 0);
                    MeshPerChunk[chunkpos].AddMeshData(newMesh);
                }
                else
                {
                    MeshPerChunk[chunkpos] = MakeWireMesh(pos1, pos2, 0);
                }
            }

            foreach (KeyValuePair <Vec3i, MeshData> mesh in MeshPerChunk)
            {
                mesh.Value.SetMode(EnumDrawMode.Triangles);
                MeshRefPerChunk[mesh.Key] = capi.Render.UploadMesh(mesh.Value);
            }
            MeshPerChunk.Clear();
        }
Esempio n. 2
0
        private void Event_SaveGameLoaded()
        {
            byte[] data = sapi.WorldManager.SaveGame.GetData("hangingWiresData");

            try
            {
                this.data = SerializerUtil.Deserialize <HangingWiresData>(data);
            }
            catch (Exception e)
            {
                this.data = new HangingWiresData();
            }
        }
Esempio n. 3
0
 private void onDataFromServer(HangingWiresData data)
 {
     this.data = data;
     Renderer.UpdateWiresMesh(data);
 }