diff --git a/Substrate/SubstrateCS/Examples/Examples.sln b/Substrate/SubstrateCS/Examples/Examples.sln
index 4347c9d..45c749a 100644
--- a/Substrate/SubstrateCS/Examples/Examples.sln
+++ b/Substrate/SubstrateCS/Examples/Examples.sln
@@ -19,48 +19,118 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Maze", "Maze\Maze.csproj",
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PurgeEntities", "PurgeEntities\PurgeEntities.csproj", "{A64F274A-D5B7-45C2-92BA-4C9A64863DDC}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GoodyChest", "GoodyChest\GoodyChest.csproj", "{6A998912-C939-4029-9F1D-D5C2A5E9C804}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
+ Debug|Mixed Platforms = Debug|Mixed Platforms
+ Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
+ Release|Mixed Platforms = Release|Mixed Platforms
+ Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{5BD42656-9BCF-4C55-8272-A5D3507EFDF3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5BD42656-9BCF-4C55-8272-A5D3507EFDF3}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {5BD42656-9BCF-4C55-8272-A5D3507EFDF3}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+ {5BD42656-9BCF-4C55-8272-A5D3507EFDF3}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
+ {5BD42656-9BCF-4C55-8272-A5D3507EFDF3}.Debug|x86.ActiveCfg = Debug|Any CPU
{5BD42656-9BCF-4C55-8272-A5D3507EFDF3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5BD42656-9BCF-4C55-8272-A5D3507EFDF3}.Release|Any CPU.Build.0 = Release|Any CPU
+ {5BD42656-9BCF-4C55-8272-A5D3507EFDF3}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {5BD42656-9BCF-4C55-8272-A5D3507EFDF3}.Release|Mixed Platforms.Build.0 = Release|Any CPU
+ {5BD42656-9BCF-4C55-8272-A5D3507EFDF3}.Release|x86.ActiveCfg = Release|Any CPU
{EDA894F2-00AF-456B-9D07-591ED61A9AE7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EDA894F2-00AF-456B-9D07-591ED61A9AE7}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {EDA894F2-00AF-456B-9D07-591ED61A9AE7}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+ {EDA894F2-00AF-456B-9D07-591ED61A9AE7}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
+ {EDA894F2-00AF-456B-9D07-591ED61A9AE7}.Debug|x86.ActiveCfg = Debug|Any CPU
{EDA894F2-00AF-456B-9D07-591ED61A9AE7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EDA894F2-00AF-456B-9D07-591ED61A9AE7}.Release|Any CPU.Build.0 = Release|Any CPU
+ {EDA894F2-00AF-456B-9D07-591ED61A9AE7}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {EDA894F2-00AF-456B-9D07-591ED61A9AE7}.Release|Mixed Platforms.Build.0 = Release|Any CPU
+ {EDA894F2-00AF-456B-9D07-591ED61A9AE7}.Release|x86.ActiveCfg = Release|Any CPU
{6D24D262-34D3-43A6-B066-1312A0C72B16}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6D24D262-34D3-43A6-B066-1312A0C72B16}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {6D24D262-34D3-43A6-B066-1312A0C72B16}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+ {6D24D262-34D3-43A6-B066-1312A0C72B16}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
+ {6D24D262-34D3-43A6-B066-1312A0C72B16}.Debug|x86.ActiveCfg = Debug|Any CPU
{6D24D262-34D3-43A6-B066-1312A0C72B16}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6D24D262-34D3-43A6-B066-1312A0C72B16}.Release|Any CPU.Build.0 = Release|Any CPU
+ {6D24D262-34D3-43A6-B066-1312A0C72B16}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {6D24D262-34D3-43A6-B066-1312A0C72B16}.Release|Mixed Platforms.Build.0 = Release|Any CPU
+ {6D24D262-34D3-43A6-B066-1312A0C72B16}.Release|x86.ActiveCfg = Release|Any CPU
{426B01F4-B0C0-488E-8A5A-5531C8DFA98C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{426B01F4-B0C0-488E-8A5A-5531C8DFA98C}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {426B01F4-B0C0-488E-8A5A-5531C8DFA98C}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+ {426B01F4-B0C0-488E-8A5A-5531C8DFA98C}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
+ {426B01F4-B0C0-488E-8A5A-5531C8DFA98C}.Debug|x86.ActiveCfg = Debug|Any CPU
{426B01F4-B0C0-488E-8A5A-5531C8DFA98C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{426B01F4-B0C0-488E-8A5A-5531C8DFA98C}.Release|Any CPU.Build.0 = Release|Any CPU
+ {426B01F4-B0C0-488E-8A5A-5531C8DFA98C}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {426B01F4-B0C0-488E-8A5A-5531C8DFA98C}.Release|Mixed Platforms.Build.0 = Release|Any CPU
+ {426B01F4-B0C0-488E-8A5A-5531C8DFA98C}.Release|x86.ActiveCfg = Release|Any CPU
{15C04C0C-FD50-47E9-B62C-AA0A814189ED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{15C04C0C-FD50-47E9-B62C-AA0A814189ED}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {15C04C0C-FD50-47E9-B62C-AA0A814189ED}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+ {15C04C0C-FD50-47E9-B62C-AA0A814189ED}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
+ {15C04C0C-FD50-47E9-B62C-AA0A814189ED}.Debug|x86.ActiveCfg = Debug|Any CPU
{15C04C0C-FD50-47E9-B62C-AA0A814189ED}.Release|Any CPU.ActiveCfg = Release|Any CPU
{15C04C0C-FD50-47E9-B62C-AA0A814189ED}.Release|Any CPU.Build.0 = Release|Any CPU
+ {15C04C0C-FD50-47E9-B62C-AA0A814189ED}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {15C04C0C-FD50-47E9-B62C-AA0A814189ED}.Release|Mixed Platforms.Build.0 = Release|Any CPU
+ {15C04C0C-FD50-47E9-B62C-AA0A814189ED}.Release|x86.ActiveCfg = Release|Any CPU
{83F55F54-7253-4B4D-BC37-E9D1CB63E0B8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{83F55F54-7253-4B4D-BC37-E9D1CB63E0B8}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {83F55F54-7253-4B4D-BC37-E9D1CB63E0B8}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+ {83F55F54-7253-4B4D-BC37-E9D1CB63E0B8}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
+ {83F55F54-7253-4B4D-BC37-E9D1CB63E0B8}.Debug|x86.ActiveCfg = Debug|Any CPU
{83F55F54-7253-4B4D-BC37-E9D1CB63E0B8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{83F55F54-7253-4B4D-BC37-E9D1CB63E0B8}.Release|Any CPU.Build.0 = Release|Any CPU
+ {83F55F54-7253-4B4D-BC37-E9D1CB63E0B8}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {83F55F54-7253-4B4D-BC37-E9D1CB63E0B8}.Release|Mixed Platforms.Build.0 = Release|Any CPU
+ {83F55F54-7253-4B4D-BC37-E9D1CB63E0B8}.Release|x86.ActiveCfg = Release|Any CPU
{EBDD447B-01FA-4A29-B4AB-380EC4379B5F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EBDD447B-01FA-4A29-B4AB-380EC4379B5F}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {EBDD447B-01FA-4A29-B4AB-380EC4379B5F}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+ {EBDD447B-01FA-4A29-B4AB-380EC4379B5F}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
+ {EBDD447B-01FA-4A29-B4AB-380EC4379B5F}.Debug|x86.ActiveCfg = Debug|Any CPU
{EBDD447B-01FA-4A29-B4AB-380EC4379B5F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EBDD447B-01FA-4A29-B4AB-380EC4379B5F}.Release|Any CPU.Build.0 = Release|Any CPU
+ {EBDD447B-01FA-4A29-B4AB-380EC4379B5F}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {EBDD447B-01FA-4A29-B4AB-380EC4379B5F}.Release|Mixed Platforms.Build.0 = Release|Any CPU
+ {EBDD447B-01FA-4A29-B4AB-380EC4379B5F}.Release|x86.ActiveCfg = Release|Any CPU
{62D70576-FE3A-4530-B283-889C14B52E9E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{62D70576-FE3A-4530-B283-889C14B52E9E}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {62D70576-FE3A-4530-B283-889C14B52E9E}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+ {62D70576-FE3A-4530-B283-889C14B52E9E}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
+ {62D70576-FE3A-4530-B283-889C14B52E9E}.Debug|x86.ActiveCfg = Debug|Any CPU
{62D70576-FE3A-4530-B283-889C14B52E9E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{62D70576-FE3A-4530-B283-889C14B52E9E}.Release|Any CPU.Build.0 = Release|Any CPU
+ {62D70576-FE3A-4530-B283-889C14B52E9E}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {62D70576-FE3A-4530-B283-889C14B52E9E}.Release|Mixed Platforms.Build.0 = Release|Any CPU
+ {62D70576-FE3A-4530-B283-889C14B52E9E}.Release|x86.ActiveCfg = Release|Any CPU
{A64F274A-D5B7-45C2-92BA-4C9A64863DDC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A64F274A-D5B7-45C2-92BA-4C9A64863DDC}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {A64F274A-D5B7-45C2-92BA-4C9A64863DDC}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+ {A64F274A-D5B7-45C2-92BA-4C9A64863DDC}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
+ {A64F274A-D5B7-45C2-92BA-4C9A64863DDC}.Debug|x86.ActiveCfg = Debug|Any CPU
{A64F274A-D5B7-45C2-92BA-4C9A64863DDC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A64F274A-D5B7-45C2-92BA-4C9A64863DDC}.Release|Any CPU.Build.0 = Release|Any CPU
+ {A64F274A-D5B7-45C2-92BA-4C9A64863DDC}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {A64F274A-D5B7-45C2-92BA-4C9A64863DDC}.Release|Mixed Platforms.Build.0 = Release|Any CPU
+ {A64F274A-D5B7-45C2-92BA-4C9A64863DDC}.Release|x86.ActiveCfg = Release|Any CPU
+ {6A998912-C939-4029-9F1D-D5C2A5E9C804}.Debug|Any CPU.ActiveCfg = Debug|x86
+ {6A998912-C939-4029-9F1D-D5C2A5E9C804}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
+ {6A998912-C939-4029-9F1D-D5C2A5E9C804}.Debug|Mixed Platforms.Build.0 = Debug|x86
+ {6A998912-C939-4029-9F1D-D5C2A5E9C804}.Debug|x86.ActiveCfg = Debug|x86
+ {6A998912-C939-4029-9F1D-D5C2A5E9C804}.Debug|x86.Build.0 = Debug|x86
+ {6A998912-C939-4029-9F1D-D5C2A5E9C804}.Release|Any CPU.ActiveCfg = Release|x86
+ {6A998912-C939-4029-9F1D-D5C2A5E9C804}.Release|Mixed Platforms.ActiveCfg = Release|x86
+ {6A998912-C939-4029-9F1D-D5C2A5E9C804}.Release|Mixed Platforms.Build.0 = Release|x86
+ {6A998912-C939-4029-9F1D-D5C2A5E9C804}.Release|x86.ActiveCfg = Release|x86
+ {6A998912-C939-4029-9F1D-D5C2A5E9C804}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/Substrate/SubstrateCS/Examples/GoodyChest/GoodyChest.csproj b/Substrate/SubstrateCS/Examples/GoodyChest/GoodyChest.csproj
new file mode 100644
index 0000000..e7779a3
--- /dev/null
+++ b/Substrate/SubstrateCS/Examples/GoodyChest/GoodyChest.csproj
@@ -0,0 +1,54 @@
+
+
+
+ Debug
+ x86
+ 8.0.30703
+ 2.0
+ {6A998912-C939-4029-9F1D-D5C2A5E9C804}
+ Exe
+ Properties
+ GoodyChest
+ GoodyChest
+ v4.0
+ Client
+ 512
+
+
+ x86
+ true
+ full
+ false
+ bin\Debug\
+ DEBUG;TRACE
+ prompt
+ 4
+
+
+ x86
+ pdbonly
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+
+
+
+ ..\..\bin\Release\Substrate.dll
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Substrate/SubstrateCS/Examples/GoodyChest/Program.cs b/Substrate/SubstrateCS/Examples/GoodyChest/Program.cs
new file mode 100644
index 0000000..8f6010c
--- /dev/null
+++ b/Substrate/SubstrateCS/Examples/GoodyChest/Program.cs
@@ -0,0 +1,103 @@
+using System;
+using Substrate;
+using 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.
+
+namespace GoodyChest
+{
+ class Program
+ {
+ static Random rand;
+
+ static void Main (string[] args)
+ {
+ if (args.Length != 2) {
+ Console.WriteLine("Usage: GoodyChest ");
+ return;
+ }
+
+ string dest = args[0];
+ double p = Convert.ToDouble(args[1]);
+
+ rand = new Random();
+
+ // Open our world
+ BetaWorld world = BetaWorld.Open(dest);
+ ChunkManager cm = world.GetChunkManager();
+
+ int added = 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
+ foreach (ChunkRef chunk in cm) {
+ if (rand.NextDouble() < p) {
+ int x = rand.Next(chunk.Blocks.XDim);
+ int z = rand.Next(chunk.Blocks.ZDim);
+ int y = 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) {
+ continue;
+ }
+
+ // Get a block object, then assign it to the chunk
+ Block block = BuildChest();
+ chunk.Blocks.SetBlock(x, y + 1, z, block);
+
+ // Save the chunk
+ cm.Save();
+
+ added++;
+ }
+ }
+
+ // And we're done
+ Console.WriteLine("Added {0} goody chests to world", added);
+ }
+
+ // This function will create a new Block object of type 'Chest', fills it
+ // with random items, and returns it
+ static Block BuildChest ()
+ {
+ // A default, appropriate TileEntity entry is created
+ Block block = new Block(BlockType.CHEST);
+ TileEntityChest ent = block.GetTileEntity() as TileEntityChest;
+
+ // Unless Substrate has a bug, the TileEntity was definitely a TileEntityChest
+ if (ent == null) {
+ Console.WriteLine("Catastrophic");
+ return null;
+ }
+
+ // Loop through each slot in the chest, assign an item
+ // with a probability
+ for (int i = 0; i < ent.Items.Capacity; i++) {
+ if (rand.NextDouble() < 0.3) {
+ // Ask the ItemTable for a random Item type registered with Substrate
+ ItemInfo itype = ItemInfo.ItemTable.Random();
+
+ // Create the item object, give it an appropriate, random count (items in stack)
+ Item item = new Item(itype.ID);
+ item.Count = 1 + rand.Next(itype.StackSize);
+
+ // Assign the item to the chest at slot i
+ ent.Items[i] = item;
+ }
+ }
+
+ // That's all, we've got a loaded chest block ready to be
+ // inserted into a chunk
+ return block;
+ }
+ }
+}
diff --git a/Substrate/SubstrateCS/Examples/GoodyChest/Properties/AssemblyInfo.cs b/Substrate/SubstrateCS/Examples/GoodyChest/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..0539aaf
--- /dev/null
+++ b/Substrate/SubstrateCS/Examples/GoodyChest/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("GoodyChest")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("Microsoft")]
+[assembly: AssemblyProduct("GoodyChest")]
+[assembly: AssemblyCopyright("Copyright © Microsoft 2011")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("c8a1b29d-5ba9-4a5a-891c-82627eb4b915")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/Substrate/SubstrateCS/Source/Block.cs b/Substrate/SubstrateCS/Source/Block.cs
index e0dd4ac..fee68ab 100644
--- a/Substrate/SubstrateCS/Source/Block.cs
+++ b/Substrate/SubstrateCS/Source/Block.cs
@@ -17,12 +17,14 @@ namespace Substrate
public Block (int id)
{
_id = id;
+ UpdateTileEntity(0, id);
}
public Block (int id, int data)
{
_id = id;
_data = data;
+ UpdateTileEntity(0, id);
}
public Block (IAlphaBlockCollection chunk, int lx, int ly, int lz)
@@ -45,19 +47,7 @@ namespace Substrate
get { return _id; }
set
{
- BlockInfoEx info1 = BlockInfo.BlockTable[_id] as BlockInfoEx;
- BlockInfoEx info2 = BlockInfo.BlockTable[value] as BlockInfoEx;
-
- if (info1 != info2) {
- if (info1 != null) {
- _tileEntity = null;
- }
-
- if (info2 != null) {
- _tileEntity = TileEntityFactory.Create(info2.TileEntityName);
- }
- }
-
+ UpdateTileEntity(_id, value);
_id = value;
}
}
@@ -124,5 +114,21 @@ namespace Substrate
}
#endregion
+
+ private void UpdateTileEntity (int old, int value)
+ {
+ BlockInfoEx info1 = BlockInfo.BlockTable[old] as BlockInfoEx;
+ BlockInfoEx info2 = BlockInfo.BlockTable[value] as BlockInfoEx;
+
+ if (info1 != info2) {
+ if (info1 != null) {
+ _tileEntity = null;
+ }
+
+ if (info2 != null) {
+ _tileEntity = TileEntityFactory.Create(info2.TileEntityName);
+ }
+ }
+ }
}
}
diff --git a/Substrate/SubstrateCS/Source/BlockTileEntities.cs b/Substrate/SubstrateCS/Source/BlockTileEntities.cs
index c3f479b..d6d98ab 100644
--- a/Substrate/SubstrateCS/Source/BlockTileEntities.cs
+++ b/Substrate/SubstrateCS/Source/BlockTileEntities.cs
@@ -95,11 +95,20 @@ namespace Substrate
? TranslateCoordinates(x, y, z)
: new BlockKey(x, y, z);
+ TagCompound oldte;
+
+ if (_tileEntityTable.TryGetValue(key, out oldte)) {
+ _tileEntities.Remove(oldte);
+ }
+
te.X = key.x;
te.Y = key.y;
te.Z = key.z;
- _tileEntities.Add(te.BuildTree());
+ TagCompound tree = te.BuildTree() as TagCompound;
+
+ _tileEntities.Add(tree);
+ _tileEntityTable[key] = tree;
}
public void ClearTileEntity (int x, int y, int z)
diff --git a/Substrate/SubstrateCS/Source/ChunkRef.cs b/Substrate/SubstrateCS/Source/ChunkRef.cs
index 03b247c..8149375 100644
--- a/Substrate/SubstrateCS/Source/ChunkRef.cs
+++ b/Substrate/SubstrateCS/Source/ChunkRef.cs
@@ -179,8 +179,8 @@ namespace Substrate
private BlockKey TranslateCoordinatesHandler (int lx, int ly, int lz)
{
- int x = _cx * _blocks.XDim + lx;
- int z = _cz * _blocks.ZDim + lz;
+ int x = X * _blocks.XDim + lx;
+ int z = Z * _blocks.ZDim + lz;
return new BlockKey(x, ly, z);
}
diff --git a/Substrate/SubstrateCS/Source/Item.cs b/Substrate/SubstrateCS/Source/Item.cs
index f92b33e..f852705 100644
--- a/Substrate/SubstrateCS/Source/Item.cs
+++ b/Substrate/SubstrateCS/Source/Item.cs
@@ -52,6 +52,11 @@ namespace Substrate
{
}
+ public Item (int id)
+ {
+ _id = (short)id;
+ }
+
#region ICopyable- Members
public Item Copy ()
diff --git a/Substrate/SubstrateCS/Source/ItemInfo.cs b/Substrate/SubstrateCS/Source/ItemInfo.cs
index 5b07640..cb4d1a0 100644
--- a/Substrate/SubstrateCS/Source/ItemInfo.cs
+++ b/Substrate/SubstrateCS/Source/ItemInfo.cs
@@ -120,6 +120,7 @@ namespace Substrate
public class ItemCache
{
private Dictionary _cache;
+ private static Random _rand = new Random();
public T this[int index]
{
@@ -137,6 +138,12 @@ namespace Substrate
{
_cache = cache;
}
+
+ public T Random ()
+ {
+ List list = new List(_cache.Values);
+ return list[_rand.Next(list.Count)];
+ }
}
private static Dictionary _itemTable;