forked from minecraft-dotnet/Substrate
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModule1.vb
More file actions
61 lines (47 loc) · 2.15 KB
/
Copy pathModule1.vb
File metadata and controls
61 lines (47 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
Imports Substrate
' This example replaces all instances of one block ID with another in a world.
' Substrate will handle all of the lower-level headaches that can pop up, such
' as maintaining correct lighting or replacing TileEntity records for blocks
' that need them.
' For a more advanced Block Replace example, see replace.cs in NBToolkit.
Module Module1
Sub Main(args As String())
If args.Length <> 3 Then
Console.WriteLine("Usage: BlockReplace <world> <before-id> <after-id>")
Return
End If
Dim dest As String = args(0)
Dim before As Integer = Convert.ToInt32(args(1))
Dim after As Integer = Convert.ToInt32(args(2))
' Open our world
Dim world As BetaWorld = BetaWorld.Open(dest)
' The chunk manager is more efficient than the block manager for
' this purpose, since we'll inspect every block
Dim cm As BetaChunkManager = world.GetChunkManager()
For Each chunk As ChunkRef In cm
' You could hardcode your dimensions, but maybe some day they
' won't always be 16. Also the CLR is a bit stupid and has
' trouble optimizing repeated calls to Chunk.Blocks.xx, so we
' cache them in locals
Dim xdim As Integer = chunk.Blocks.XDim
Dim ydim As Integer = chunk.Blocks.YDim
Dim zdim As Integer = chunk.Blocks.ZDim
chunk.Blocks.AutoFluid = True
' x, z, y is the most efficient order to scan blocks (not that
' you should care about internal detail)
For x As Integer = 0 To xdim - 1
For z As Integer = 0 To zdim - 1
For y As Integer = 0 To ydim - 1
' Replace the block with after if it matches before
If chunk.Blocks.GetID(x, y, z) = before Then
chunk.Blocks.SetData(x, y, z, 0)
chunk.Blocks.SetID(x, y, z, after)
End If
Next
Next
Next
' Save the chunk
cm.Save()
Next
End Sub
End Module