Skip to content

Commit f7ed37d

Browse files
Fix MCSharp importer with door_wool blocks, also it now properly imports MCGalaxy maps with custom blocks, fixing #20
1 parent 6c998b8 commit f7ed37d

2 files changed

Lines changed: 62 additions & 168 deletions

File tree

‎fCraft/MapConversion/MapMCF.cs‎

Lines changed: 0 additions & 162 deletions
Original file line numberDiff line numberDiff line change
@@ -85,167 +85,5 @@ public override bool Save( Map mapToSave, string fileName )
8585
return true;
8686
}
8787
}
88-
89-
static MapMCF()
90-
{
91-
Mapping[70] = (byte) Block.BrownMushroom; //flagbase
92-
93-
Mapping[71] = (byte) Block.White; //fallsnow
94-
Mapping[72] = (byte) Block.White; //snow
95-
96-
Mapping[73] = (byte) Block.StillLava; //fastdeathlava
97-
98-
Mapping[74] = (byte) Block.TNT; //c4
99-
Mapping[75] = (byte) Block.Red; //c4det
100-
101-
//76-79 unused
102-
103-
Mapping[80] = (byte) Block.Cobblestone; //door_cobblestone
104-
Mapping[81] = (byte) Block.Air; //door_cobblestone_air
105-
//82 unused
106-
Mapping[83] = (byte) Block.Red; //door_red;
107-
Mapping[84] = (byte) Block.Air; //door_red_air
108-
109-
Mapping[85] = (byte) Block.Orange; //door_orange
110-
Mapping[86] = (byte) Block.Yellow; //door_yellow
111-
Mapping[87] = (byte)Block.Lime; //door_lightgreen
112-
//88 unused
113-
Mapping[89] = (byte)Block.Teal; //door_aquagreen
114-
Mapping[90] = (byte)Block.Cyan; //door_cyan
115-
Mapping[91] = (byte)Block.Aqua; //door_lightblue
116-
Mapping[92] = (byte)Block.Indigo; //door_purple
117-
Mapping[93] = (byte)Block.Violet; //door_lightpurple
118-
Mapping[94] = (byte)Block.Magenta; //door_pink
119-
Mapping[95] = (byte)Block.Pink; //door_darkpink
120-
Mapping[96] = (byte)Block.Black; //door_darkgray
121-
Mapping[97] = (byte)Block.Gray; //door_lightgray
122-
Mapping[98] = (byte)Block.White; //door_white
123-
//99 unused
124-
125-
Mapping[100] = (byte)Block.Glass; // op_glass
126-
Mapping[101] = (byte)Block.Obsidian; // opsidian
127-
Mapping[102] = (byte)Block.Brick; // op_brick
128-
Mapping[103] = (byte)Block.Stone; // op_stone
129-
Mapping[104] = (byte)Block.Cobblestone; // op_cobblestone
130-
// 105 = op_air
131-
Mapping[106] = (byte)Block.Water; // op_water
132-
133-
// 107-109 unused
134-
Mapping[110] = (byte)Block.Wood; // wood_float
135-
Mapping[111] = (byte)Block.Log; // door
136-
Mapping[112] = (byte)Block.Lava; // lava_fast
137-
Mapping[113] = (byte)Block.Obsidian; // door2
138-
Mapping[114] = (byte)Block.Glass; // door3
139-
Mapping[115] = (byte)Block.Stone; // door4
140-
Mapping[116] = (byte)Block.Leaves; // door5
141-
Mapping[117] = (byte)Block.Sand; // door6
142-
Mapping[118] = (byte)Block.Wood; // door7
143-
Mapping[119] = (byte)Block.Green; // door8
144-
Mapping[120] = (byte)Block.TNT; // door9
145-
Mapping[121] = (byte)Block.Slab; // door10
146-
147-
Mapping[122] = (byte)Block.Log; // tdoor
148-
Mapping[123] = (byte)Block.Obsidian; // tdoor2
149-
Mapping[124] = (byte)Block.Glass; // tdoor3
150-
Mapping[125] = (byte)Block.Stone; // tdoor4
151-
Mapping[126] = (byte)Block.Leaves; // tdoor5
152-
Mapping[127] = (byte)Block.Sand; // tdoor6
153-
Mapping[128] = (byte)Block.Wood; // tdoor7
154-
Mapping[129] = (byte)Block.Green; // tdoor8
155-
156-
Mapping[130] = (byte)Block.White; // MsgWhite
157-
Mapping[131] = (byte)Block.Black; // MsgBlack
158-
Mapping[132] = (byte)Block.Air; // MsgAir
159-
Mapping[133] = (byte)Block.Water; // MsgWater
160-
Mapping[134] = (byte)Block.Lava; // MsgLava
161-
162-
Mapping[135] = (byte)Block.TNT; // tdoor9
163-
Mapping[136] = (byte)Block.Slab; // tdoor10
164-
Mapping[137] = (byte)Block.Air; // tdoor11
165-
Mapping[138] = (byte)Block.Water; // tdoor12
166-
Mapping[139] = (byte)Block.Lava; // tdoor13
167-
168-
Mapping[140] = (byte)Block.Water; // WaterDown
169-
Mapping[141] = (byte)Block.Lava; // LavaDown
170-
Mapping[143] = (byte)Block.Aqua; // WaterFaucet
171-
Mapping[144] = (byte)Block.Orange; // LavaFaucet
172-
173-
// 143 unused
174-
Mapping[145] = (byte)Block.Water; // finiteWater
175-
Mapping[146] = (byte)Block.Lava; // finiteLava
176-
Mapping[147] = (byte)Block.Cyan; // finiteFaucet
177-
178-
Mapping[148] = (byte)Block.Log; // odoor1
179-
Mapping[149] = (byte)Block.Obsidian; // odoor2
180-
Mapping[150] = (byte)Block.Glass; // odoor3
181-
Mapping[151] = (byte)Block.Stone; // odoor4
182-
Mapping[152] = (byte)Block.Leaves; // odoor5
183-
Mapping[153] = (byte)Block.Sand; // odoor6
184-
Mapping[154] = (byte)Block.Wood; // odoor7
185-
Mapping[155] = (byte)Block.Green; // odoor8
186-
Mapping[156] = (byte)Block.TNT; // odoor9
187-
Mapping[157] = (byte)Block.Slab; // odoor10
188-
Mapping[158] = (byte)Block.Lava; // odoor11
189-
Mapping[159] = (byte)Block.Water; // odoor12
190-
191-
Mapping[160] = (byte)Block.Air; // air_portal
192-
Mapping[161] = (byte)Block.Water; // water_portal
193-
Mapping[162] = (byte)Block.Lava; // lava_portal
194-
195-
// 163 unused
196-
Mapping[164] = (byte)Block.Air; // air_door
197-
Mapping[165] = (byte)Block.Air; // air_switch
198-
Mapping[166] = (byte)Block.Water; // water_door
199-
Mapping[167] = (byte)Block.Lava; // lava_door
200-
201-
// 168-174 = odoor*_air
202-
Mapping[175] = (byte)Block.Cyan; // blue_portal
203-
Mapping[176] = (byte)Block.Orange; // orange_portal
204-
// 177-181 = odoor*_air
205-
206-
Mapping[182] = (byte)Block.TNT; // smalltnt
207-
Mapping[183] = (byte)Block.TNT; // bigtnt
208-
Mapping[184] = (byte)Block.Lava; // tntexplosion
209-
Mapping[185] = (byte)Block.Lava; // fire
210-
211-
// 186 unused
212-
Mapping[187] = (byte)Block.Glass; // rocketstart
213-
Mapping[188] = (byte)Block.Gold; // rockethead
214-
Mapping[189] = (byte)Block.Iron; // firework
215-
216-
Mapping[190] = (byte)Block.Lava; // deathlava
217-
Mapping[191] = (byte)Block.Water; // deathwater
218-
Mapping[192] = (byte)Block.Air; // deathair
219-
Mapping[193] = (byte)Block.Water; // activedeathwater
220-
Mapping[194] = (byte)Block.Lava; // activedeathlava
221-
222-
Mapping[195] = (byte)Block.Lava; // magma
223-
Mapping[196] = (byte)Block.Water; // geyser
224-
225-
// 197-210 = air
226-
Mapping[211] = (byte)Block.Red; // door8_air
227-
Mapping[212] = (byte)Block.Lava; // door9_air
228-
// 213-229 = air
229-
230-
Mapping[230] = (byte)Block.Aqua; // train
231-
Mapping[231] = (byte)Block.TNT; // creeper
232-
Mapping[232] = (byte)Block.MossyCobble; // zombiebody
233-
Mapping[233] = (byte)Block.Lime; // zombiehead
234-
235-
// 234 unused
236-
Mapping[235] = (byte)Block.White; // birdwhite
237-
Mapping[236] = (byte)Block.Black; // birdblack
238-
Mapping[237] = (byte)Block.Lava; // birdlava
239-
Mapping[238] = (byte)Block.Red; // birdred
240-
Mapping[239] = (byte)Block.Water; // birdwater
241-
Mapping[240] = (byte)Block.Blue; // birdblue
242-
Mapping[242] = (byte)Block.Lava; // birdkill
243-
244-
Mapping[245] = (byte)Block.Gold; // fishgold
245-
Mapping[246] = (byte)Block.Sponge; // fishsponge
246-
Mapping[247] = (byte)Block.Gray; // fishshark
247-
Mapping[248] = (byte)Block.Red; // fishsalmon
248-
Mapping[249] = (byte)Block.Blue; // fishbetta
249-
}
25088
}
25189
}

‎fCraft/MapConversion/MapMCSharp.cs‎

Lines changed: 62 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ protected static Map LoadHeaderInternal( [NotNull] Stream stream ) {
9191
L = bs.ReadByte(),
9292
};
9393

94-
stream.ReadByte();
95-
stream.ReadByte();
94+
stream.ReadByte(); // pervisit permission
95+
stream.ReadByte(); // perbuild permission
9696
return map;
9797
}
9898

@@ -110,11 +110,35 @@ public virtual Map Load( string fileName ) {
110110

111111
map.ConvertBlockTypes( Mapping );
112112

113+
if( gs.ReadByte() != 0xBD ) return map;
114+
ReadCustomBlocks( gs, map );
113115
return map;
114116
}
115117
}
116118
}
117119

120+
const byte customTile = 163;
121+
static void ReadCustomBlocks( Stream s, Map map) {
122+
byte[] chunk = new byte[16 * 16 * 16];
123+
124+
for( int z = 0; z < map.Height; z += 16 )
125+
for( int y = 0; y < map.Length; y += 16 )
126+
for( int x = 0; x < map.Width; x += 16 )
127+
{
128+
if( s.ReadByte() != 1 ) continue;
129+
s.Read( chunk, 0, chunk.Length );
130+
131+
int baseIndex = map.Index( x, y, z );
132+
for( int i = 0; i < chunk.Length; i++ ) {
133+
int xx = i & 0xF, yy = (i >> 4) & 0xF, zz = (i >> 8) & 0xF;
134+
int index = baseIndex + map.Index( xx, yy, zz );
135+
136+
if (map.Blocks[index] != customTile) continue;
137+
map.Blocks[index] = chunk[i];
138+
}
139+
}
140+
}
141+
118142

119143
public virtual bool Save( Map mapToSave, string fileName ) {
120144
if( mapToSave == null ) throw new ArgumentNullException( "mapToSave" );
@@ -140,7 +164,7 @@ public virtual bool Save( Map mapToSave, string fileName ) {
140164
bs.Write( mapToSave.Spawn.R );
141165
bs.Write( mapToSave.Spawn.L );
142166

143-
// Write the VistPermission and BuildPermission bytes
167+
// Write the VisitPermission and BuildPermission bytes
144168
bs.Write( (byte)0 );
145169
bs.Write( (byte)0 );
146170

@@ -157,11 +181,42 @@ public virtual bool Save( Map mapToSave, string fileName ) {
157181
protected static readonly byte[] Mapping = new byte[256];
158182

159183
static MapMCSharp() {
184+
Mapping[70] = (byte)Block.BrownMushroom;// flagbase
185+
Mapping[71] = (byte)Block.White; // fallsnow
186+
Mapping[72] = (byte)Block.White; // snow
187+
Mapping[73] = (byte)Block.StillLava; // fastdeathlava
188+
Mapping[74] = (byte)Block.TNT; // c4
189+
Mapping[75] = (byte)Block.Red; // c4det
190+
191+
// 76-79 unused
192+
Mapping[80] = (byte) Block.Cobblestone; // door_cobblestone
193+
// 81 = door_cobblestone_air
194+
195+
// 82 unused
196+
Mapping[83] = (byte)Block.Red; // door_red;
197+
// 84 = door_red_air
198+
Mapping[85] = (byte)Block.Orange; // door_orange
199+
Mapping[86] = (byte)Block.Yellow; // door_yellow
200+
Mapping[87] = (byte)Block.Lime; // door_lightgreen
201+
202+
// 88 unused
203+
Mapping[89] = (byte)Block.Teal; // door_aquagreen
204+
Mapping[90] = (byte)Block.Cyan; // door_cyan
205+
Mapping[91] = (byte)Block.Aqua; // door_lightblue
206+
Mapping[92] = (byte)Block.Indigo; // door_purple
207+
Mapping[93] = (byte)Block.Violet; // door_lightpurple
208+
Mapping[94] = (byte)Block.Magenta; // door_pink
209+
Mapping[95] = (byte)Block.Pink; // door_darkpink
210+
Mapping[96] = (byte)Block.Black; // door_darkgray
211+
Mapping[97] = (byte)Block.Gray; // door_lightgray
212+
Mapping[98] = (byte)Block.White; // door_white
213+
214+
// 99 unused
160215
Mapping[100] = (byte)Block.Glass; // op_glass
161216
Mapping[101] = (byte)Block.Obsidian; // opsidian
162-
Mapping[102] = (byte)Block.Brick; // op_brick
217+
Mapping[102] = (byte)Block.Brick; // op_brick
163218
Mapping[103] = (byte)Block.Stone; // op_stone
164-
Mapping[104] = (byte)Block.Cobblestone; // op_cobblestone
219+
Mapping[104] = (byte)Block.Cobblestone; // op_cobblestone
165220
// 105 = op_air
166221
Mapping[106] = (byte)Block.Water; // op_water
167222

@@ -227,7 +282,8 @@ static MapMCSharp() {
227282
Mapping[161] = (byte)Block.Water; // water_portal
228283
Mapping[162] = (byte)Block.Lava; // lava_portal
229284

230-
// 163 unused
285+
Mapping[customTile] = customTile; // handled specially
286+
231287
Mapping[164] = (byte)Block.Air; // air_door
232288
Mapping[165] = (byte)Block.Air; // air_switch
233289
Mapping[166] = (byte)Block.Water; // water_door

0 commit comments

Comments
 (0)