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
98 lines (76 loc) · 3.46 KB
/
Copy pathModule1.vb
File metadata and controls
98 lines (76 loc) · 3.46 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
Imports Substrate
Imports Substrate.TileEntities
' GoodyChest is an example that creates chests filled with random
' items throughout the world, according to a probability of
' appearing per chunk.
' Note: This example picks a random item from Substrate's ItemTable,
' which includes all items up to the current version of MC (if Substrate
' itself is up to date). If a chest gets filled with some of these
' latest items and gets opened in an older MC client, MC will crash.
Module Module1
Dim rand As Random
Sub Main(args As String())
If args.Length <> 2 Then
Console.WriteLine("Usage: GoodyChest <world> <prob>")
Return
End If
Dim dest As String = args(0)
Dim p As Double = Convert.ToDouble(args(1))
rand = New Random()
' Open our world
Dim world As BetaWorld = BetaWorld.Open(dest)
Dim cm As BetaChunkManager = world.GetChunkManager()
Dim added As Integer = 0
' Iterate through every chunk in the world
' With proability p, pick a random location
' inside the chunk to place a chest, above the
' first solid block
For Each chunk As ChunkRef In cm
If rand.NextDouble() < p Then
Dim x As Integer = rand.[Next](chunk.Blocks.XDim)
Dim z As Integer = rand.[Next](chunk.Blocks.ZDim)
Dim y As Integer = chunk.Blocks.GetHeight(x, z)
' Can't build this high (-2 to account for new MC 1.6 height limitation)
If y >= chunk.Blocks.YDim - 2 Then
Continue For
End If
' Get a block object, then assign it to the chunk
Dim block As AlphaBlock = BuildChest()
chunk.Blocks.SetBlock(x, y + 1, z, block)
' Save the chunk
cm.Save()
added += 1
End If
Next
' And we're done
Console.WriteLine("Added {0} goody chests to world", added)
End Sub
' This function will create a new Block object of type 'Chest', fills it
' with random items, and returns it
Private Function BuildChest() As AlphaBlock
' A default, appropriate TileEntity entry is created
Dim block As New AlphaBlock(BlockType.CHEST)
Dim ent As TileEntityChest = TryCast(block.GetTileEntity(), TileEntityChest)
' Unless Substrate has a bug, the TileEntity was definitely a TileEntityChest
If ent Is Nothing Then
Console.WriteLine("Catastrophic")
Return Nothing
End If
' Loop through each slot in the chest, assign an item
' with a probability
For i As Integer = 0 To ent.Items.Capacity - 1
If rand.NextDouble() < 0.3 Then
' Ask the ItemTable for a random Item type registered with Substrate
Dim itype As ItemInfo = ItemInfo.GetRandomItem()
' Create the item object, give it an appropriate, random count (items in stack)
Dim item As New Item(itype.ID)
item.Count = 1 + rand.[Next](itype.StackSize)
' Assign the item to the chest at slot i
ent.Items(i) = item
End If
Next
' That's all, we've got a loaded chest block ready to be
' inserted into a chunk
Return block
End Function
End Module