forked from mirrors/NBTExplorer
TileEntity bugfixes, new example: GoodyChest
This commit is contained in:
parent
cbdf423567
commit
438cec3bdf
9 changed files with 306 additions and 16 deletions
|
@ -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
|
||||
|
|
54
Substrate/SubstrateCS/Examples/GoodyChest/GoodyChest.csproj
Normal file
54
Substrate/SubstrateCS/Examples/GoodyChest/GoodyChest.csproj
Normal file
|
@ -0,0 +1,54 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
|
||||
<ProductVersion>8.0.30703</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{6A998912-C939-4029-9F1D-D5C2A5E9C804}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>GoodyChest</RootNamespace>
|
||||
<AssemblyName>GoodyChest</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Substrate">
|
||||
<HintPath>..\..\bin\Release\Substrate.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
103
Substrate/SubstrateCS/Examples/GoodyChest/Program.cs
Normal file
103
Substrate/SubstrateCS/Examples/GoodyChest/Program.cs
Normal file
|
@ -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 <world> <prob>");
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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")]
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -52,6 +52,11 @@ namespace Substrate
|
|||
{
|
||||
}
|
||||
|
||||
public Item (int id)
|
||||
{
|
||||
_id = (short)id;
|
||||
}
|
||||
|
||||
#region ICopyable<Item> Members
|
||||
|
||||
public Item Copy ()
|
||||
|
|
|
@ -120,6 +120,7 @@ namespace Substrate
|
|||
public class ItemCache<T>
|
||||
{
|
||||
private Dictionary<int, T> _cache;
|
||||
private static Random _rand = new Random();
|
||||
|
||||
public T this[int index]
|
||||
{
|
||||
|
@ -137,6 +138,12 @@ namespace Substrate
|
|||
{
|
||||
_cache = cache;
|
||||
}
|
||||
|
||||
public T Random ()
|
||||
{
|
||||
List<T> list = new List<T>(_cache.Values);
|
||||
return list[_rand.Next(list.Count)];
|
||||
}
|
||||
}
|
||||
|
||||
private static Dictionary<int, ItemInfo> _itemTable;
|
||||
|
|
Loading…
Reference in a new issue