Compare commits
No commits in common. "gh-pages" and "master" have entirely different histories.
19
.gitignore
vendored
Normal file
19
.gitignore
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
bin/
|
||||
obj/
|
||||
*.user
|
||||
*.userprefs
|
||||
*.suo
|
||||
*.pidb
|
||||
_ReSharper*/
|
||||
TestResults/
|
||||
*.mdf
|
||||
*.psess
|
||||
*.vsp
|
||||
packages/
|
||||
|
||||
config.yaml
|
||||
|
||||
packets.log
|
||||
|
||||
world/manifest.nbt
|
||||
TestResult.xml
|
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
[submodule "externals/fNbt"]
|
||||
path = externals/fNbt
|
||||
url = https://github.com/SirCmpwn/fNbt.git
|
33
.settings/launch.json
Normal file
33
.settings/launch.json
Normal file
@ -0,0 +1,33 @@
|
||||
{
|
||||
"version": "0.1.0",
|
||||
// List of configurations. Add new configurations or edit existing ones.
|
||||
// ONLY "node" and "mono" are supported, change "type" to switch.
|
||||
"configurations": [
|
||||
{
|
||||
// Name of configuration; appears in the launch configuration drop down menu.
|
||||
"name": "Launch TrueCraft",
|
||||
// Type of configuration. Possible values: "node", "mono".
|
||||
"type": "mono",
|
||||
// Workspace relative or absolute path to the program.
|
||||
"program": "TrueCraft/bin/Debug/TrueCraft.exe",
|
||||
// Automatically stop program after launch.
|
||||
"stopOnEntry": false,
|
||||
// Command line arguments passed to the program.
|
||||
"args": [],
|
||||
// Workspace relative or absolute path to the working directory of the program being debugged. Default is the current workspace.
|
||||
"cwd": "TrueCraft/bin/Debug/",
|
||||
// Workspace relative or absolute path to the runtime executable to be used. Default is the runtime executable on the PATH.
|
||||
"runtimeExecutable": null,
|
||||
// Environment variables passed to the program.
|
||||
"env": { }
|
||||
},
|
||||
{
|
||||
"name": "Attach",
|
||||
"type": "node",
|
||||
// TCP/IP address. Default is "localhost".
|
||||
"address": "localhost",
|
||||
// Port to attach to.
|
||||
"port": 5858
|
||||
}
|
||||
]
|
||||
}
|
199
.settings/tasks.json
Normal file
199
.settings/tasks.json
Normal file
@ -0,0 +1,199 @@
|
||||
// Available variables which can be used inside of strings.
|
||||
// ${workspaceRoot}: the root folder of the team
|
||||
// ${file}: the current opened file
|
||||
// ${fileBasename}: the current opened file's basename
|
||||
// ${fileDirname}: the current opened file's dirname
|
||||
// ${fileExtname}: the current opened file's extension
|
||||
// ${cwd}: the current working directory of the spawned process
|
||||
|
||||
// A task runner that calls the Typescipt compiler (tsc) and
|
||||
// Compiles a HelloWorld.ts program
|
||||
{
|
||||
"version": "0.1.0",
|
||||
|
||||
// The command is tsc.
|
||||
"command": "xbuild",
|
||||
|
||||
// Show the output window only if unrecognized errors occur.
|
||||
"showOutput": "silent",
|
||||
|
||||
// Under windows use tsc.exe. This ensures we don't need a shell.
|
||||
"windows": {
|
||||
"command": "msbuild.exe"
|
||||
},
|
||||
|
||||
// args is the HelloWorld program to compile.
|
||||
"args": [],
|
||||
|
||||
// use the standard tsc problem matcher to find compile problems
|
||||
// in the output.
|
||||
"problemMatcher": "$msCompile"
|
||||
}
|
||||
|
||||
// A task runner configuration for gulp. Gulp provides a less task
|
||||
// which compiles less to css.
|
||||
/*
|
||||
{
|
||||
"version": "0.1.0",
|
||||
"command": "gulp",
|
||||
"isShellCommand": true,
|
||||
"tasks": [
|
||||
{
|
||||
"taskName": "less",
|
||||
// Make this the default build command.
|
||||
"isBuildCommand": true,
|
||||
// Show the output window only if unrecognized errors occur.
|
||||
"showOutput": "silent",
|
||||
// Use the standard less compilation problem matcher.
|
||||
"problemMatcher": "$lessCompile"
|
||||
}
|
||||
]
|
||||
}
|
||||
*/
|
||||
|
||||
// Uncomment the following section to use gulp in a watching mode that compiles a
|
||||
// less file. The gulp task prints "[hh:mm:ss] Starting 'clean-styles'" to the console
|
||||
// when existing css files get deleted and "[hh:mm:ss] Finished 'styles'" when the
|
||||
// overall less compilation has finished. When the clean pattern is detect internal less
|
||||
// problems are cleaned. When the finshed pattern is detected in the output less
|
||||
// problems are published.
|
||||
/*
|
||||
{
|
||||
"version": "0.1.0",
|
||||
"command": "gulp",
|
||||
"isShellCommand": true,
|
||||
"tasks": [
|
||||
{
|
||||
"taskName": "watch-less",
|
||||
// Make this the default build command.
|
||||
"isBuildCommand": true,
|
||||
// Show the output window only if unrecognized errors occur.
|
||||
"showOutput": "silent",
|
||||
// Task is running in watching mode.
|
||||
"isWatching": true,
|
||||
"problemMatcher": {
|
||||
// Use the standard less compilation problem matcher as the base.
|
||||
"base": "$lessCompile",
|
||||
// A regular expression signalling that a watched task begins executing (usually triggered through file watching).
|
||||
"watchedTaskBeginsRegExp": "^\\[\\d+:\\d+:\\d+\\] Starting 'clean-styles'\\.\\.\\.$",
|
||||
// A regular expression signalling that a watched tasks ends executing.
|
||||
"watchedTaskEndsRegExp": "^\\[\\d+:\\d+:\\d+\\] Finished 'styles' after \\d+"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
*/
|
||||
|
||||
// Uncomment the following section to use jake to build a workspace
|
||||
// cloned from https://github.com/Microsoft/TypeScript.git
|
||||
/*
|
||||
{
|
||||
"version": "0.1.0",
|
||||
// Task runner is jake
|
||||
"command": "jake",
|
||||
// Need to be executed in shell / cmd
|
||||
"isShellCommand": true,
|
||||
"showOutput": "silent",
|
||||
"tasks": [
|
||||
{
|
||||
// TS build command is local.
|
||||
"taskName": "local",
|
||||
// Make this the default build command.
|
||||
"isBuildCommand": true,
|
||||
// Show the output window only if unrecognized errors occur.
|
||||
"showOutput": "silent",
|
||||
// Use the redefined Typescript output problem matcher.
|
||||
"problemMatcher": [
|
||||
"$tsc"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
*/
|
||||
|
||||
// Uncomment the section below to use msbuild and generate problems
|
||||
// for csc, cpp, tsc and vb. The configuration assumes that msbuild
|
||||
// is available on the path and a solution file exists in the
|
||||
// workspace folder root.
|
||||
/*
|
||||
{
|
||||
"version": "0.1.0",
|
||||
"command": "msbuild",
|
||||
"args": [
|
||||
// Ask msbuild to generate full paths for file names.
|
||||
"/property:GenerateFullPaths=true"
|
||||
],
|
||||
"taskSelector": "/t:",
|
||||
"showOutput": "silent",
|
||||
"tasks": [
|
||||
{
|
||||
"taskName": "build",
|
||||
// Show the output window only if unrecognized errors occur.
|
||||
"showOutput": "silent",
|
||||
// Use the standard MS compiler pattern to detect errors, warnings
|
||||
// and infos in the output.
|
||||
"problemMatcher": "$msCompile"
|
||||
}
|
||||
]
|
||||
}
|
||||
*/
|
||||
|
||||
// Uncomment the following section to use msbuild which compiles Typescript
|
||||
// and less files.
|
||||
/*
|
||||
{
|
||||
"version": "0.1.0",
|
||||
"command": "msbuild",
|
||||
"args": [
|
||||
// Ask msbuild to generate full paths for file names.
|
||||
"/property:GenerateFullPaths=true"
|
||||
],
|
||||
"taskSelector": "/t:",
|
||||
"showOutput": "silent",
|
||||
"tasks": [
|
||||
{
|
||||
"taskName": "build",
|
||||
// Show the output window only if unrecognized errors occur.
|
||||
"showOutput": "silent",
|
||||
// Use the standard MS compiler pattern to detect errors, warnings
|
||||
// and infos in the output.
|
||||
"problemMatcher": [
|
||||
"$msCompile",
|
||||
"$lessCompile"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
*/
|
||||
// A task runner example that defines a problemMatcher inline instead of using
|
||||
// a predfined one.
|
||||
/*
|
||||
{
|
||||
"version": "0.1.0",
|
||||
"command": "tsc.exe",
|
||||
"args": ["HelloWorld.ts"],
|
||||
"showOutput": "silent",
|
||||
"problemMatcher": {
|
||||
// The problem is owned by the typescript language service. Ensure that the problems
|
||||
// are merged with problems produced by Visual Studio's language service.
|
||||
"owner": "typescript",
|
||||
// The file name for reported problems is relative to the current working directory.
|
||||
"fileLocation": ["relative", "${cwd}"],
|
||||
// The actual pattern to match problems in the output.
|
||||
"pattern": {
|
||||
// The regular expression. Matches HelloWorld.ts(2,10): error TS2339: Property 'logg' does not exist on type 'Console'.
|
||||
"regexp": "^([^\\s].*)\\((\\d+|\\d+,\\d+|\\d+,\\d+,\\d+,\\d+)\\):\\s+(error|warning|info)\\s+(TS\\d+)\\s*:\\s*(.*)$",
|
||||
// The match group that denotes the file containing the problem.
|
||||
"file": 1,
|
||||
// The match group that denotes the problem location.
|
||||
"location": 2,
|
||||
// The match group that denotes the problem's severity. Can be omitted.
|
||||
"severity": 3,
|
||||
// The match group that denotes the problem code. Can be omitted.
|
||||
"code": 4,
|
||||
// The match group that denotes the problem's message.
|
||||
"message": 5
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
15
.travis.yml
Normal file
15
.travis.yml
Normal file
@ -0,0 +1,15 @@
|
||||
language: csharp
|
||||
solution: TrueCraft.sln
|
||||
mono:
|
||||
- latest
|
||||
before_install:
|
||||
- git submodule update --init --recursive
|
||||
install:
|
||||
- nuget restore TrueCraft.sln
|
||||
- nuget install NUnit.Runners -Version 3.2.1 -OutputDirectory testrunner
|
||||
script:
|
||||
- xbuild TrueCraft.sln
|
||||
- |
|
||||
mono \
|
||||
./testrunner/NUnit.ConsoleRunner.3.2.1/tools/nunit3-console.exe \
|
||||
./TrueCraft.Core.Test/TrueCraft.Core.Test.csproj
|
19
LICENSE
Normal file
19
LICENSE
Normal file
@ -0,0 +1,19 @@
|
||||
Copyright (c) 2015 Drew DeVault
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
42
README-dist.txt
Normal file
42
README-dist.txt
Normal file
@ -0,0 +1,42 @@
|
||||
You've downloaded TrueCraft, an open source implementation of Minecraft beta
|
||||
1.7.3. Please note that TrueCraft is still experimental, and is likely to
|
||||
include bugs and unfinished features.
|
||||
|
||||
=== Running TrueCraft ===
|
||||
|
||||
On Windows, double click `TrueCraft.Launcher.exe`. This will allow you to play
|
||||
singleplayer and connect to multiplayer servers.
|
||||
|
||||
On Linux and OS X, run `mono TrueCraft.Launcher.exe` from a terminal.
|
||||
|
||||
=== Running Servers ===
|
||||
|
||||
You've also been given the TrueCraft server. If you want to run a server to play
|
||||
with your friends, you will need to forward port 25565 on your router.
|
||||
|
||||
Run `TrueCraft.exe` to host a server. On Linux and OS X, you can run `mono
|
||||
TrueCraft.exe` to host the server.
|
||||
|
||||
If you do not want to host the server yourself, try https://gamocosm.com.
|
||||
|
||||
=== Updating TrueCraft ===
|
||||
|
||||
TrueCraft is updated all the time. Download new versions from:
|
||||
|
||||
https://truecraft.io
|
||||
|
||||
Eventually TrueCraft will update itself automatically. Until then, you'll have
|
||||
to update it yourself manually.
|
||||
|
||||
=== Community ===
|
||||
|
||||
You aren't the only one playing TrueCraft! Come hang out with us:
|
||||
|
||||
* /r/truecraft
|
||||
* #truecraft on irc.esper.net
|
||||
|
||||
=== Source Code ===
|
||||
|
||||
The source code is available at https://github.com/SirCmpwn/TrueCraft
|
||||
|
||||
If you know how to code, you're welcome to help improve TrueCraft.
|
51
README.md
Normal file
51
README.md
Normal file
@ -0,0 +1,51 @@
|
||||
<p align="center">
|
||||
<img src="https://sr.ht/3O-k.png" width="728" />
|
||||
</p>
|
||||
|
||||
A completely [clean-room](https://en.wikipedia.org/wiki/Clean_room_design) implementation of Minecraft beta 1.7.3 (circa September 2011). No decompiled code has been used in the development of this software. This is an **implementation** - not a clone. TrueCraft is compatible with Minecraft beta 1.7.3 clients and servers.
|
||||
|
||||
[](https://travis-ci.org/SirCmpwn/TrueCraft) [](https://drewdevault.com/donate?project=1)
|
||||
|
||||

|
||||
|
||||
*Screenshot taken with [Eldpack](http://eldpack.com/)*
|
||||
|
||||
I miss the old days of Minecraft, when it was a simple game. It was nearly perfect. Most of what Mojang has added since beta 1.7.3 is fluff, life support for a game that was "done" years ago. This is my attempt to get back to the original spirit of Minecraft, before there were things like the End, or all-in-one redstone devices, or village gift shops. A simple sandbox where you can build and explore and fight with your friends. I miss that.
|
||||
|
||||
The goal of this project is effectively to fork Minecraft. Your contribution is welcome, but keep in mind that I will mercilessly reject changes that aren't in line with the vision. If you like the new Minecraft, please feel free to keep playing it. If you miss the old Minecraft, join me.
|
||||
|
||||
## Compiling
|
||||
|
||||
**Use a recursive git clone.**
|
||||
|
||||
git clone --recursive git://github.com/SirCmpwn/TrueCraft.git
|
||||
|
||||
You need to restore Nuget packages. The easiest way is to open the solution up in monodevelop or visual studio or the like and build from there. You can alternatively acquire Nuget yourself and run this:
|
||||
|
||||
mono path/to/nuget.exe restore
|
||||
|
||||
From the root directory of the git repository. Then run:
|
||||
|
||||
xbuild
|
||||
|
||||
To compile it and you'll receive binaries in `TrueCraft.Launcher/bin/Debug/`. Run `[mono] TrueCraft.Launcher.exe` to run the client and connect to servers and play singleplayer and so on. Run `[mono] TrueCraft.Server.exe` to host a server for others to play on.
|
||||
|
||||
Note: if you have a problem with nuget connecting, run `mozroots --import --sync`.
|
||||
|
||||
Note: TrueCraft requires mono 4.0 or newer.
|
||||
|
||||
## Get Involved
|
||||
|
||||
If you are not a developer, you can keep up with TrueCraft updates and participate in the community on [/r/truecraft](https://reddit.com/r/truecraft), or by joining us to chat in [#truecraft on irc.esper.net](http://webchat.esper.net/?nick=&channels=truecraft).
|
||||
|
||||
If you are a developer, you have two paths. If you *have not* read the Minecraft source code, you are what we call a "clean dev", and you should stay that way. If you *have* read the source code, you are what we call a "dirty dev", and the way you can contribute is different. If you are a clean dev, you're welcome to contribute to this repository by adding features and functionality from Minecraft Beta 1.7.3, fixing bugs, refactoring, etc - the usual. [Send pull requests](https://help.github.com/articles/using-pull-requests/) with your work.
|
||||
|
||||
If you are a dirty dev, you are more limited in how you can help. You can work on projects that are related to TrueCraft, but not on TrueCraft itself. Direct contributions that you can participate in includes [the website](https://github.com/SirCmpwn/truecraft.io) and the [artwork](https://github.com/SirCmpwn/TrueCraft/tree/master/TrueCraft.Client/Content). You can also work on things like helping to build a community by spreading the word, participating in IRC or the subreddit, etc. You may also work on reverse engineering Minecraft to provide documentation for clean devs to use - see [reverse engineering guidelines](https://github.com/SirCmpwn/TrueCraft/wiki/Reverse-engineering-guidelines) on the wiki for details on how you can do this. **Under no circumstances may you ever share any code with a clean dev, decompiled or otherwise**.
|
||||
|
||||
## Assets
|
||||
|
||||
TrueCraft is compatible with Minecraft beta 1.7.3 texture packs. We ship the Pixeludi Pack (by Wojtek Mroczek) by default. You can install the Mojang assets through the TrueCraft launcher if you wish.
|
||||
|
||||
## Blah blah blah
|
||||
|
||||
TrueCraft is not associated with Mojang or Minecraft in any sort of official capacity.
|
11
TrueCraft.API/AI/IMobState.cs
Normal file
11
TrueCraft.API/AI/IMobState.cs
Normal file
@ -0,0 +1,11 @@
|
||||
using System;
|
||||
using TrueCraft.API.Server;
|
||||
using TrueCraft.API.Entities;
|
||||
|
||||
namespace TrueCraft.API.AI
|
||||
{
|
||||
public interface IMobState
|
||||
{
|
||||
void Update(IMobEntity entity, IEntityManager manager);
|
||||
}
|
||||
}
|
24
TrueCraft.API/AI/ISpawnRule.cs
Normal file
24
TrueCraft.API/AI/ISpawnRule.cs
Normal file
@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using TrueCraft.API.World;
|
||||
using TrueCraft.API.Server;
|
||||
|
||||
namespace TrueCraft.API.AI
|
||||
{
|
||||
public interface ISpawnRule
|
||||
{
|
||||
/// <summary>
|
||||
/// One in every n chunks will spawn mobs (with randomness mixed in).
|
||||
/// </summary>
|
||||
int ChunkSpawnChance { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Spawns mobs on a given chunk immediately after the chunk has been generated.
|
||||
/// </summary>
|
||||
void GenerateMobs(IChunk chunk, IEntityManager entityManager);
|
||||
|
||||
/// <summary>
|
||||
/// Spawns mobs as part of the ongoing spawn cycle.
|
||||
/// </summary>
|
||||
void SpawnMobs(IChunk chunk, IEntityManager entityManager);
|
||||
}
|
||||
}
|
38
TrueCraft.API/ArmorMaterial.cs
Normal file
38
TrueCraft.API/ArmorMaterial.cs
Normal file
@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace TrueCraft.API
|
||||
{
|
||||
/// <summary>
|
||||
/// Enumerates the materials armor can be crafted from.
|
||||
/// </summary>
|
||||
public enum ArmorMaterial
|
||||
{
|
||||
/// <summary>
|
||||
/// The armor is made of leather.
|
||||
/// </summary>
|
||||
Leather,
|
||||
|
||||
/// <summary>
|
||||
/// The armor is made of chain (fire).
|
||||
/// </summary>
|
||||
Chain,
|
||||
|
||||
/// <summary>
|
||||
/// The armor is made of iron ingots.
|
||||
/// </summary>
|
||||
Iron,
|
||||
|
||||
/// <summary>
|
||||
/// The armor is made of gold ingots.
|
||||
/// </summary>
|
||||
Gold,
|
||||
|
||||
/// <summary>
|
||||
/// The armor is made of diamonds.
|
||||
/// </summary>
|
||||
Diamond
|
||||
}
|
||||
}
|
123
TrueCraft.API/Biome.cs
Normal file
123
TrueCraft.API/Biome.cs
Normal file
@ -0,0 +1,123 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace TrueCraft.API
|
||||
{
|
||||
/// <summary>
|
||||
/// Enumerates the biomes in TrueCraft.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The 13 vanilla b1.7.3 biomes as found on http://b.wiki.vg/json/b1.7
|
||||
/// </remarks>
|
||||
public enum Biome
|
||||
{
|
||||
/// <summary>
|
||||
/// A plains biome.
|
||||
/// </summary>
|
||||
Plains = 0,
|
||||
|
||||
/// <summary>
|
||||
/// A desert biome.
|
||||
/// </summary>
|
||||
Desert = 1,
|
||||
|
||||
/// <summary>
|
||||
/// A forest biome.
|
||||
/// </summary>
|
||||
Forest = 2,
|
||||
|
||||
/// <summary>
|
||||
/// A rainforest biome.
|
||||
/// </summary>
|
||||
Rainforest = 3,
|
||||
|
||||
/// <summary>
|
||||
/// A seasonal forest biome.
|
||||
/// </summary>
|
||||
SeasonalForest = 4,
|
||||
|
||||
/// <summary>
|
||||
/// A savanna biome.
|
||||
/// </summary>
|
||||
Savanna = 5,
|
||||
|
||||
/// <summary>
|
||||
/// A shrubland biome.
|
||||
/// </summary>
|
||||
Shrubland = 6,
|
||||
|
||||
/// <summary>
|
||||
/// A swampland biome.
|
||||
/// </summary>
|
||||
Swampland = 7,
|
||||
|
||||
/// <summary>
|
||||
/// A Nether biome.
|
||||
/// </summary>
|
||||
Hell = 8,
|
||||
|
||||
/// <summary>
|
||||
/// An End biome.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Implementation into TrueCraft is undetermined at this point
|
||||
/// </remarks>
|
||||
Sky = 9,
|
||||
|
||||
/// <summary>
|
||||
/// A taiga biome.
|
||||
/// </summary>
|
||||
Taiga = 10,
|
||||
|
||||
/// <summary>
|
||||
/// A tundra biome.
|
||||
/// </summary>
|
||||
Tundra = 11,
|
||||
|
||||
/// <summary>
|
||||
/// An ice desert biome.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Implementation into TrueCraft is undetermined at this point
|
||||
/// </remarks>
|
||||
IceDesert = 12,
|
||||
|
||||
//Below are "transitional" biomes/biomes which are not in b1.7.3
|
||||
|
||||
/// <summary>
|
||||
/// An ocean biome.
|
||||
/// </summary>
|
||||
Ocean = 13,
|
||||
|
||||
/// <summary>
|
||||
/// A river biome.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Implementation into TrueCraft is undetermined at this point
|
||||
/// </remarks>
|
||||
River = 14,
|
||||
|
||||
/// <summary>
|
||||
/// A beach biome.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Implementation into TrueCraft is undetermined at this point
|
||||
/// </remarks>
|
||||
Beach = 15,
|
||||
|
||||
/// <summary>
|
||||
/// A frozen ocean biome.
|
||||
/// </summary>
|
||||
FrozenOcean = 16,
|
||||
|
||||
/// <summary>
|
||||
/// A frozen river biome.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Implementation into TrueCraft is undetermined at this point
|
||||
/// </remarks>
|
||||
FrozenRiver = 17,
|
||||
}
|
||||
}
|
40
TrueCraft.API/BlockFace.cs
Normal file
40
TrueCraft.API/BlockFace.cs
Normal file
@ -0,0 +1,40 @@
|
||||
using System;
|
||||
|
||||
namespace TrueCraft.API
|
||||
{
|
||||
/// <summary>
|
||||
/// Enumerates the directions of block faces.
|
||||
/// </summary>
|
||||
public enum BlockFace
|
||||
{
|
||||
/// <summary>
|
||||
/// The block face points towards -Y.
|
||||
/// </summary>
|
||||
NegativeY = 0,
|
||||
|
||||
/// <summary>
|
||||
/// The block face points towards +Y.
|
||||
/// </summary>
|
||||
PositiveY = 1,
|
||||
|
||||
/// <summary>
|
||||
/// The block face points towards -Z.
|
||||
/// </summary>
|
||||
NegativeZ = 2,
|
||||
|
||||
/// <summary>
|
||||
/// The block face points towards +Z.
|
||||
/// </summary>
|
||||
PositiveZ = 3,
|
||||
|
||||
/// <summary>
|
||||
/// The block face points towards -X.
|
||||
/// </summary>
|
||||
NegativeX = 4,
|
||||
|
||||
/// <summary>
|
||||
/// The block face points towards +X.
|
||||
/// </summary>
|
||||
PositiveX = 5
|
||||
}
|
||||
}
|
308
TrueCraft.API/BoundingBox.cs
Normal file
308
TrueCraft.API/BoundingBox.cs
Normal file
@ -0,0 +1,308 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace TrueCraft.API
|
||||
{
|
||||
/// <summary>
|
||||
/// Enumerates the different types of containment between two bounding boxes.
|
||||
/// </summary>
|
||||
public enum ContainmentType
|
||||
{
|
||||
/// <summary>
|
||||
/// The two bounding boxes are disjoint.
|
||||
/// </summary>
|
||||
Disjoint,
|
||||
|
||||
/// <summary>
|
||||
/// One bounding box contains the other.
|
||||
/// </summary>
|
||||
Contains,
|
||||
|
||||
/// <summary>
|
||||
/// The two bounding boxes intersect.
|
||||
/// </summary>
|
||||
Intersects
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents an axis-aligned bounding box.
|
||||
/// </summary>
|
||||
// Mostly taken from the MonoXna project, which is licensed under the MIT license
|
||||
public struct BoundingBox : IEquatable<BoundingBox>
|
||||
{
|
||||
#region Public Fields
|
||||
|
||||
/// <summary>
|
||||
/// The minimum vector for the bounding box.
|
||||
/// </summary>
|
||||
public Vector3 Min;
|
||||
|
||||
/// <summary>
|
||||
/// The maximum vector for the bounding box.
|
||||
/// </summary>
|
||||
public Vector3 Max;
|
||||
|
||||
/// <summary>
|
||||
/// The number of corners a bounding box has.
|
||||
/// </summary>
|
||||
public const int CornerCount = 8;
|
||||
|
||||
#endregion Public Fields
|
||||
|
||||
|
||||
#region Public Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new bounding box from specified values
|
||||
/// </summary>
|
||||
/// <param name="min">The minimum vector for the bounding box.</param>
|
||||
/// <param name="max">The number of corners a bounding box has.</param>
|
||||
public BoundingBox(Vector3 min, Vector3 max)
|
||||
{
|
||||
this.Min = min;
|
||||
this.Max = max;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new bounding box by copying another.
|
||||
/// </summary>
|
||||
/// <param name="b">The bounding box to clone.</param>
|
||||
public BoundingBox(BoundingBox b)
|
||||
{
|
||||
this.Min = new Vector3(b.Min);
|
||||
this.Max = new Vector3(b.Max);
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Determines the type of containment between this and another bounding box.
|
||||
/// </summary>
|
||||
/// <param name="box">The other bounding box.</param>
|
||||
/// <returns></returns>
|
||||
public ContainmentType Contains(BoundingBox box)
|
||||
{
|
||||
//test if all corner is in the same side of a face by just checking min and max
|
||||
if (box.Max.X < Min.X
|
||||
|| box.Min.X > Max.X
|
||||
|| box.Max.Y < Min.Y
|
||||
|| box.Min.Y > Max.Y
|
||||
|| box.Max.Z < Min.Z
|
||||
|| box.Min.Z > Max.Z)
|
||||
return ContainmentType.Disjoint;
|
||||
|
||||
|
||||
if (box.Min.X >= Min.X
|
||||
&& box.Max.X <= Max.X
|
||||
&& box.Min.Y >= Min.Y
|
||||
&& box.Max.Y <= Max.Y
|
||||
&& box.Min.Z >= Min.Z
|
||||
&& box.Max.Z <= Max.Z)
|
||||
return ContainmentType.Contains;
|
||||
|
||||
return ContainmentType.Intersects;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the specified vector is contained within this bounding box.
|
||||
/// </summary>
|
||||
/// <param name="vec">The vector.</param>
|
||||
/// <returns></returns>
|
||||
public bool Contains(Vector3 vec)
|
||||
{
|
||||
return Min.X <= vec.X && vec.X <= Max.X &&
|
||||
Min.Y <= vec.Y && vec.Y <= Max.Y &&
|
||||
Min.Z <= vec.Z && vec.Z <= Max.Z;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates and returns a new bounding box from an enumeration of corner points.
|
||||
/// </summary>
|
||||
/// <param name="points">The enumeration of corner points.</param>
|
||||
/// <returns></returns>
|
||||
public static BoundingBox CreateFromPoints(IEnumerable<Vector3> points)
|
||||
{
|
||||
if (points == null)
|
||||
throw new ArgumentNullException();
|
||||
|
||||
bool empty = true;
|
||||
Vector3 vector2 = new Vector3(float.MaxValue);
|
||||
Vector3 vector1 = new Vector3(float.MinValue);
|
||||
foreach (Vector3 vector3 in points)
|
||||
{
|
||||
vector2 = Vector3.Min(vector2, vector3);
|
||||
vector1 = Vector3.Max(vector1, vector3);
|
||||
empty = false;
|
||||
}
|
||||
if (empty)
|
||||
throw new ArgumentException();
|
||||
|
||||
return new BoundingBox(vector2, vector1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Offsets this BoundingBox. Does not modify this object, but returns a new one
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// The offset bounding box.
|
||||
/// </returns>
|
||||
/// <param name='Offset'>
|
||||
/// The offset.
|
||||
/// </param>
|
||||
public BoundingBox OffsetBy(Vector3 Offset)
|
||||
{
|
||||
return new BoundingBox(Min + Offset, Max + Offset);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an array of vectors containing the corners of this bounding box.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Vector3[] GetCorners()
|
||||
{
|
||||
return new Vector3[]
|
||||
{
|
||||
new Vector3(this.Min.X, this.Max.Y, this.Max.Z),
|
||||
new Vector3(this.Max.X, this.Max.Y, this.Max.Z),
|
||||
new Vector3(this.Max.X, this.Min.Y, this.Max.Z),
|
||||
new Vector3(this.Min.X, this.Min.Y, this.Max.Z),
|
||||
new Vector3(this.Min.X, this.Max.Y, this.Min.Z),
|
||||
new Vector3(this.Max.X, this.Max.Y, this.Min.Z),
|
||||
new Vector3(this.Max.X, this.Min.Y, this.Min.Z),
|
||||
new Vector3(this.Min.X, this.Min.Y, this.Min.Z)
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether this and another bounding box are equal.
|
||||
/// </summary>
|
||||
/// <param name="other">The other bounding box.</param>
|
||||
/// <returns></returns>
|
||||
public bool Equals(BoundingBox other)
|
||||
{
|
||||
return (this.Min == other.Min) && (this.Max == other.Max);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether this and another object are equal.
|
||||
/// </summary>
|
||||
/// <param name="obj">The other object.</param>
|
||||
/// <returns></returns>
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return (obj is BoundingBox) && this.Equals((BoundingBox)obj);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the hash code for this bounding box.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return this.Min.GetHashCode() + this.Max.GetHashCode();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether this bounding box intersects another.
|
||||
/// </summary>
|
||||
/// <param name="box">The other bounding box.</param>
|
||||
/// <returns></returns>
|
||||
public bool Intersects(BoundingBox box)
|
||||
{
|
||||
bool result;
|
||||
Intersects(ref box, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether this bounding box intersects another.
|
||||
/// </summary>
|
||||
/// <param name="box">The other bounding box.</param>
|
||||
/// <param name="result">Set to whether the two bounding boxes intersect.</param>
|
||||
public void Intersects(ref BoundingBox box, out bool result)
|
||||
{
|
||||
if ((this.Max.X > box.Min.X) && (this.Min.X < box.Max.X))
|
||||
{
|
||||
if ((this.Max.Y < box.Min.Y) || (this.Min.Y > box.Max.Y))
|
||||
{
|
||||
result = false;
|
||||
return;
|
||||
}
|
||||
|
||||
result = (this.Max.Z > box.Min.Z) && (this.Min.Z < box.Max.Z);
|
||||
return;
|
||||
}
|
||||
|
||||
result = false;
|
||||
}
|
||||
|
||||
public static bool operator ==(BoundingBox a, BoundingBox b)
|
||||
{
|
||||
return a.Equals(b);
|
||||
}
|
||||
|
||||
public static bool operator !=(BoundingBox a, BoundingBox b)
|
||||
{
|
||||
return !a.Equals(b);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a string representation of this bounding box.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Format("{{Min:{0} Max:{1}}}", this.Min.ToString(), this.Max.ToString());
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Gets the height of this bounding box.
|
||||
/// </summary>
|
||||
public double Height
|
||||
{
|
||||
get { return Max.Y - Min.Y; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the width of this bounding box.
|
||||
/// </summary>
|
||||
public double Width
|
||||
{
|
||||
get { return Max.X - Min.X; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the depth of this bounding box.
|
||||
/// </summary>
|
||||
public double Depth
|
||||
{
|
||||
get { return Max.Z - Min.Z; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the center of this bounding box.
|
||||
/// </summary>
|
||||
public Vector3 Center
|
||||
{
|
||||
get
|
||||
{
|
||||
return (this.Min + this.Max) / 2;
|
||||
}
|
||||
}
|
||||
|
||||
public double Volume
|
||||
{
|
||||
get
|
||||
{
|
||||
return Width * Height * Depth;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
62
TrueCraft.API/BoundingCylinder.cs
Normal file
62
TrueCraft.API/BoundingCylinder.cs
Normal file
@ -0,0 +1,62 @@
|
||||
using System;
|
||||
namespace TrueCraft.API
|
||||
{
|
||||
public struct BoundingCylinder : IEquatable<BoundingCylinder>
|
||||
{
|
||||
public Vector3 Min;
|
||||
|
||||
public Vector3 Max;
|
||||
|
||||
public double Radius;
|
||||
|
||||
public BoundingCylinder(Vector3 min, Vector3 max, double radius)
|
||||
{
|
||||
Min = min;
|
||||
Max = max;
|
||||
Radius = radius;
|
||||
}
|
||||
|
||||
public bool Intersects(Vector3 q)
|
||||
{
|
||||
return DistancePointLine(q, Min, Max) < Radius;
|
||||
}
|
||||
|
||||
public bool Intersects(BoundingBox q)
|
||||
{
|
||||
var corners = q.GetCorners();
|
||||
for (int i = 0; i < corners.Length; i++)
|
||||
{
|
||||
if (Intersects(corners[i]))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// http://answers.unity3d.com/questions/62644/distance-between-a-ray-and-a-point.html
|
||||
public static double DistancePointLine(Vector3 point, Vector3 lineStart, Vector3 lineEnd)
|
||||
{
|
||||
return (ProjectPointLine(point, lineStart, lineEnd) - point).Distance;
|
||||
}
|
||||
|
||||
public static Vector3 ProjectPointLine(Vector3 point, Vector3 lineStart, Vector3 lineEnd)
|
||||
{
|
||||
var rhs = point - lineStart;
|
||||
var vector2 = lineEnd - lineStart;
|
||||
var magnitude = vector2.Distance;
|
||||
var lhs = vector2;
|
||||
if (magnitude > 1E-06f)
|
||||
lhs = lhs / magnitude;
|
||||
var num2 = Vector3.Dot(lhs, rhs);
|
||||
if (num2 < 0) num2 = 0;
|
||||
if (num2 > magnitude) num2 = magnitude;
|
||||
return lineStart + (lhs * num2);
|
||||
}
|
||||
|
||||
public bool Equals(BoundingCylinder other)
|
||||
{
|
||||
return other.Max == this.Max
|
||||
&& other.Min == this.Min
|
||||
&& other.Radius == this.Radius;
|
||||
}
|
||||
}
|
||||
}
|
113
TrueCraft.API/ChatColor.cs
Normal file
113
TrueCraft.API/ChatColor.cs
Normal file
@ -0,0 +1,113 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace TrueCraft.API
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides constants and functions for working with chat colors.
|
||||
/// </summary>
|
||||
public static class ChatColor
|
||||
{
|
||||
/// <summary>
|
||||
/// The color code for black.
|
||||
/// </summary>
|
||||
public const string Black = "§0";
|
||||
|
||||
/// <summary>
|
||||
/// The color code for dark blue.
|
||||
/// </summary>
|
||||
public const string DarkBlue = "§1";
|
||||
|
||||
/// <summary>
|
||||
/// The color code for dark green.
|
||||
/// </summary>
|
||||
public const string DarkGreen = "§2";
|
||||
|
||||
/// <summary>
|
||||
/// The color code for dark cyan.
|
||||
/// </summary>
|
||||
public const string DarkCyan = "§3";
|
||||
|
||||
/// <summary>
|
||||
/// The color code for dark red.
|
||||
/// </summary>
|
||||
public const string DarkRed = "§4";
|
||||
|
||||
/// <summary>
|
||||
/// The color code for dark purple.
|
||||
/// </summary>
|
||||
public const string Purple = "§5";
|
||||
|
||||
/// <summary>
|
||||
/// The color code for dark orange.
|
||||
/// </summary>
|
||||
public const string Orange = "§6";
|
||||
|
||||
/// <summary>
|
||||
/// The color code for gray.
|
||||
/// </summary>
|
||||
public const string Gray = "§7";
|
||||
|
||||
/// <summary>
|
||||
/// The color code for dark gray.
|
||||
/// </summary>
|
||||
public const string DarkGray = "§8";
|
||||
|
||||
/// <summary>
|
||||
/// The color code for blue.
|
||||
/// </summary>
|
||||
public const string Blue = "§9";
|
||||
|
||||
/// <summary>
|
||||
/// The color code for bright green.
|
||||
/// </summary>
|
||||
public const string BrightGreen = "§a";
|
||||
|
||||
/// <summary>
|
||||
/// The color code for cyan.
|
||||
/// </summary>
|
||||
public const string Cyan = "§b";
|
||||
|
||||
/// <summary>
|
||||
/// The color code for red.
|
||||
/// </summary>
|
||||
public const string Red = "§c";
|
||||
|
||||
/// <summary>
|
||||
/// The color code for pink.
|
||||
/// </summary>
|
||||
public const string Pink = "§d";
|
||||
|
||||
/// <summary>
|
||||
/// The color code for yellow.
|
||||
/// </summary>
|
||||
public const string Yellow = "§e";
|
||||
|
||||
/// <summary>
|
||||
/// The color code for white.
|
||||
/// </summary>
|
||||
public const string White = "§f";
|
||||
|
||||
/// <summary>
|
||||
/// Removes the color codes from the specified string.
|
||||
/// </summary>
|
||||
/// <param name="text">The string to remove color codes from.</param>
|
||||
/// <returns></returns>
|
||||
public static string RemoveColors(string text)
|
||||
{
|
||||
var sb = new StringBuilder(text.Length);
|
||||
for (int i = 0; i < text.Length; i++)
|
||||
{
|
||||
if (text[i] == '§')
|
||||
{
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
sb.Append(text[i]);
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
88
TrueCraft.API/ChatFormat.cs
Normal file
88
TrueCraft.API/ChatFormat.cs
Normal file
@ -0,0 +1,88 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
namespace TrueCraft.API
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides constants and functions for working with chat formatting.
|
||||
/// </summary>
|
||||
public static class ChatFormat
|
||||
{
|
||||
/// <summary>
|
||||
/// The following text should be obfuscated.
|
||||
/// </summary>
|
||||
public const string Obfuscated = "§k";
|
||||
|
||||
/// <summary>
|
||||
/// The following text should be bold.
|
||||
/// </summary>
|
||||
public const string Bold = "§l";
|
||||
|
||||
/// <summary>
|
||||
/// The following text should be striked-through.
|
||||
/// </summary>
|
||||
public const string Strikethrough = "§m";
|
||||
|
||||
/// <summary>
|
||||
/// The following text should be underlined.
|
||||
/// </summary>
|
||||
public const string Underline = "§n";
|
||||
|
||||
/// <summary>
|
||||
/// The following text should be italicized.
|
||||
/// </summary>
|
||||
public const string Italic = "§o";
|
||||
|
||||
/// <summary>
|
||||
/// The following text should be reset to normal.
|
||||
/// </summary>
|
||||
public const string Reset = "§r";
|
||||
|
||||
/// <summary>
|
||||
/// Returns whether the specified chat code is a valid formatting one.
|
||||
/// </summary>
|
||||
/// <param name="code"></param>
|
||||
/// <returns></returns>
|
||||
public static bool IsValid(string code)
|
||||
{
|
||||
if (string.IsNullOrEmpty(code))
|
||||
return false;
|
||||
|
||||
var comparison = StringComparison.InvariantCultureIgnoreCase;
|
||||
return
|
||||
code.Equals(ChatFormat.Obfuscated, comparison) ||
|
||||
code.Equals(ChatFormat.Bold, comparison) ||
|
||||
code.Equals(ChatFormat.Strikethrough, comparison) ||
|
||||
code.Equals(ChatFormat.Underline, comparison) ||
|
||||
code.Equals(ChatFormat.Italic, comparison) ||
|
||||
code.Equals(ChatFormat.Reset, comparison);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes any format codes from a chat string.
|
||||
/// </summary>
|
||||
/// <param name="text"></param>
|
||||
/// <returns></returns>
|
||||
public static string Remove(string text)
|
||||
{
|
||||
if (string.IsNullOrEmpty(text))
|
||||
return string.Empty;
|
||||
|
||||
var builder = new StringBuilder(text.Length);
|
||||
for (int i = 0; i < text.Length; i++)
|
||||
{
|
||||
if (text[i] == '§')
|
||||
{
|
||||
i++;
|
||||
var code = new string('§', text[i]);
|
||||
if (IsValid(code))
|
||||
continue;
|
||||
else
|
||||
builder.Append(code);
|
||||
}
|
||||
builder.Append(text[i]);
|
||||
}
|
||||
return builder.ToString();
|
||||
}
|
||||
}
|
||||
}
|
39
TrueCraft.API/Configuration.cs
Normal file
39
TrueCraft.API/Configuration.cs
Normal file
@ -0,0 +1,39 @@
|
||||
using System.IO;
|
||||
using YamlDotNet.Serialization;
|
||||
|
||||
namespace TrueCraft.API
|
||||
{
|
||||
/// <summary>
|
||||
/// Abstract base class for configurations read from YAML files.
|
||||
/// </summary>
|
||||
public abstract class Configuration
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates and returns a new configuration read from a YAML file.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The configuration type.</typeparam>
|
||||
/// <param name="configFileName">The path to the YAML file.</param>
|
||||
/// <returns></returns>
|
||||
public static T LoadConfiguration<T>(string configFileName) where T : new()
|
||||
{
|
||||
T config;
|
||||
|
||||
if (File.Exists(configFileName))
|
||||
{
|
||||
var deserializer = new Deserializer(ignoreUnmatched: true);
|
||||
using (var file = File.OpenText(configFileName))
|
||||
config = deserializer.Deserialize<T>(file);
|
||||
}
|
||||
else
|
||||
{
|
||||
config = new T();
|
||||
}
|
||||
|
||||
var serializer = new Serializer(SerializationOptions.EmitDefaults);
|
||||
using (var writer = new StreamWriter(configFileName))
|
||||
serializer.Serialize(writer, config);
|
||||
|
||||
return config;
|
||||
}
|
||||
}
|
||||
}
|
311
TrueCraft.API/Coordinates2D.cs
Normal file
311
TrueCraft.API/Coordinates2D.cs
Normal file
@ -0,0 +1,311 @@
|
||||
using System;
|
||||
|
||||
namespace TrueCraft.API
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a tuple of 2D coordinates.
|
||||
/// </summary>
|
||||
public struct Coordinates2D : IEquatable<Coordinates2D>
|
||||
{
|
||||
/// <summary>
|
||||
/// The X component of the coordinates.
|
||||
/// </summary>
|
||||
public int X;
|
||||
|
||||
/// <summary>
|
||||
/// The Y component of the coordinates.
|
||||
/// </summary>
|
||||
public int Z;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new pair of coordinates from the specified value.
|
||||
/// </summary>
|
||||
/// <param name="value">The value for the components of the coordinates.</param>
|
||||
public Coordinates2D(int value)
|
||||
{
|
||||
X = Z = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new pair of coordinates from the specified values.
|
||||
/// </summary>
|
||||
/// <param name="x">The X component of the coordinates.</param>
|
||||
/// <param name="z">The Y component of the coordinates.</param>
|
||||
public Coordinates2D(int x, int z)
|
||||
{
|
||||
X = x;
|
||||
Z = z;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new pair of coordinates by copying another.
|
||||
/// </summary>
|
||||
/// <param name="v">The coordinates to copy.</param>
|
||||
public Coordinates2D(Coordinates2D v)
|
||||
{
|
||||
X = v.X;
|
||||
Z = v.Z;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the string representation of this 2D coordinates.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Format("<{0},{1}>", X, Z);
|
||||
}
|
||||
|
||||
#region Math
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the distance between two Coordinates2D objects.
|
||||
/// </summary>
|
||||
public double DistanceTo(Coordinates2D other)
|
||||
{
|
||||
return Math.Sqrt(Square(other.X - X) +
|
||||
Square(other.Z - Z));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the square of a num.
|
||||
/// </summary>
|
||||
private int Square(int num)
|
||||
{
|
||||
return num * num;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finds the distance of this Coordinates2D from Coordinates2D.Zero
|
||||
/// </summary>
|
||||
public double Distance
|
||||
{
|
||||
get
|
||||
{
|
||||
return DistanceTo(Zero);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the component-wise minimum of two 2D coordinates.
|
||||
/// </summary>
|
||||
/// <param name="value1">The first coordinates.</param>
|
||||
/// <param name="value2">The second coordinates.</param>
|
||||
/// <returns></returns>
|
||||
public static Coordinates2D Min(Coordinates2D value1, Coordinates2D value2)
|
||||
{
|
||||
return new Coordinates2D(
|
||||
Math.Min(value1.X, value2.X),
|
||||
Math.Min(value1.Z, value2.Z)
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the component-wise maximum of two 2D coordinates.
|
||||
/// </summary>
|
||||
/// <param name="value1">The first coordinates.</param>
|
||||
/// <param name="value2">The second coordinates.</param>
|
||||
/// <returns></returns>
|
||||
public static Coordinates2D Max(Coordinates2D value1, Coordinates2D value2)
|
||||
{
|
||||
return new Coordinates2D(
|
||||
Math.Max(value1.X, value2.X),
|
||||
Math.Max(value1.Z, value2.Z)
|
||||
);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Operators
|
||||
|
||||
public static bool operator !=(Coordinates2D a, Coordinates2D b)
|
||||
{
|
||||
return !a.Equals(b);
|
||||
}
|
||||
|
||||
public static bool operator ==(Coordinates2D a, Coordinates2D b)
|
||||
{
|
||||
return a.Equals(b);
|
||||
}
|
||||
|
||||
public static Coordinates2D operator +(Coordinates2D a, Coordinates2D b)
|
||||
{
|
||||
return new Coordinates2D(a.X + b.X, a.Z + b.Z);
|
||||
}
|
||||
|
||||
public static Coordinates2D operator -(Coordinates2D a, Coordinates2D b)
|
||||
{
|
||||
return new Coordinates2D(a.X - b.X, a.Z - b.Z);
|
||||
}
|
||||
|
||||
public static Coordinates2D operator -(Coordinates2D a)
|
||||
{
|
||||
return new Coordinates2D(
|
||||
-a.X,
|
||||
-a.Z);
|
||||
}
|
||||
|
||||
public static Coordinates2D operator *(Coordinates2D a, Coordinates2D b)
|
||||
{
|
||||
return new Coordinates2D(a.X * b.X, a.Z * b.Z);
|
||||
}
|
||||
|
||||
public static Coordinates2D operator /(Coordinates2D a, Coordinates2D b)
|
||||
{
|
||||
return new Coordinates2D(a.X / b.X, a.Z / b.Z);
|
||||
}
|
||||
|
||||
public static Coordinates2D operator %(Coordinates2D a, Coordinates2D b)
|
||||
{
|
||||
return new Coordinates2D(a.X % b.X, a.Z % b.Z);
|
||||
}
|
||||
|
||||
public static Coordinates2D operator +(Coordinates2D a, int b)
|
||||
{
|
||||
return new Coordinates2D(a.X + b, a.Z + b);
|
||||
}
|
||||
|
||||
public static Coordinates2D operator -(Coordinates2D a, int b)
|
||||
{
|
||||
return new Coordinates2D(a.X - b, a.Z - b);
|
||||
}
|
||||
|
||||
public static Coordinates2D operator *(Coordinates2D a, int b)
|
||||
{
|
||||
return new Coordinates2D(a.X * b, a.Z * b);
|
||||
}
|
||||
|
||||
public static Coordinates2D operator /(Coordinates2D a, int b)
|
||||
{
|
||||
return new Coordinates2D(a.X / b, a.Z / b);
|
||||
}
|
||||
|
||||
public static Coordinates2D operator %(Coordinates2D a, int b)
|
||||
{
|
||||
return new Coordinates2D(a.X % b, a.Z % b);
|
||||
}
|
||||
|
||||
public static Coordinates2D operator +(int a, Coordinates2D b)
|
||||
{
|
||||
return new Coordinates2D(a + b.X, a + b.Z);
|
||||
}
|
||||
|
||||
public static Coordinates2D operator -(int a, Coordinates2D b)
|
||||
{
|
||||
return new Coordinates2D(a - b.X, a - b.Z);
|
||||
}
|
||||
|
||||
public static Coordinates2D operator *(int a, Coordinates2D b)
|
||||
{
|
||||
return new Coordinates2D(a * b.X, a * b.Z);
|
||||
}
|
||||
|
||||
public static Coordinates2D operator /(int a, Coordinates2D b)
|
||||
{
|
||||
return new Coordinates2D(a / b.X, a / b.Z);
|
||||
}
|
||||
|
||||
public static Coordinates2D operator %(int a, Coordinates2D b)
|
||||
{
|
||||
return new Coordinates2D(a % b.X, a % b.Z);
|
||||
}
|
||||
|
||||
public static explicit operator Coordinates2D(Coordinates3D a)
|
||||
{
|
||||
return new Coordinates2D(a.X, a.Z);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constants
|
||||
|
||||
/// <summary>
|
||||
/// A pair of 2D coordinates with components set to 0.0.
|
||||
/// </summary>
|
||||
public static readonly Coordinates2D Zero = new Coordinates2D(0);
|
||||
|
||||
/// <summary>
|
||||
/// A pair of 2D coordinates with components set to 1.0.
|
||||
/// </summary>
|
||||
public static readonly Coordinates2D One = new Coordinates2D(1);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A pair of 2D coordinates facing forwards.
|
||||
/// </summary>
|
||||
public static readonly Coordinates2D Forward = new Coordinates2D(0, 1);
|
||||
|
||||
/// <summary>
|
||||
/// A pair of 2D coordinates facing backwards.
|
||||
/// </summary>
|
||||
public static readonly Coordinates2D Backward = new Coordinates2D(0, -1);
|
||||
|
||||
/// <summary>
|
||||
/// A pair of 2D coordinates facing left.
|
||||
/// </summary>
|
||||
public static readonly Coordinates2D Left = new Coordinates2D(-1, 0);
|
||||
|
||||
/// <summary>
|
||||
/// A pair of 2D coordinates facing right.
|
||||
/// </summary>
|
||||
public static readonly Coordinates2D Right = new Coordinates2D(1, 0);
|
||||
|
||||
/// <summary>
|
||||
/// A trio of 3D coordinates facing to the east.
|
||||
/// </summary>
|
||||
public static readonly Coordinates2D East = new Coordinates2D(1, 0);
|
||||
|
||||
/// <summary>
|
||||
/// A trio of 3D coordinates facing to the west.
|
||||
/// </summary>
|
||||
public static readonly Coordinates2D West = new Coordinates2D(-1, 0);
|
||||
|
||||
/// <summary>
|
||||
/// A trio of 3D coordinates facing to the north.
|
||||
/// </summary>
|
||||
public static readonly Coordinates2D North = new Coordinates2D(0, -1);
|
||||
|
||||
/// <summary>
|
||||
/// A trio of 3D coordinates facing to the south.
|
||||
/// </summary>
|
||||
public static readonly Coordinates2D South = new Coordinates2D(0, 1);
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether this 2D coordinates and another are equal.
|
||||
/// </summary>
|
||||
/// <param name="other">The other coordinates.</param>
|
||||
/// <returns></returns>
|
||||
public bool Equals(Coordinates2D other)
|
||||
{
|
||||
return other.X.Equals(X) && other.Z.Equals(Z);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether this and another object are equal.
|
||||
/// </summary>
|
||||
/// <param name="obj">The other object.</param>
|
||||
/// <returns></returns>
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (ReferenceEquals(null, obj)) return false;
|
||||
if (obj.GetType() != typeof(Coordinates2D)) return false;
|
||||
return Equals((Coordinates2D)obj);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the hash code for this 2D coordinates.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public override int GetHashCode()
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
int result = X.GetHashCode();
|
||||
result = (result * 397) ^ Z.GetHashCode();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
385
TrueCraft.API/Coordinates3D.cs
Normal file
385
TrueCraft.API/Coordinates3D.cs
Normal file
@ -0,0 +1,385 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace TrueCraft.API
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a tuple of 3D coordinates.
|
||||
/// </summary>
|
||||
public struct Coordinates3D : IEquatable<Coordinates3D>
|
||||
{
|
||||
/// <summary>
|
||||
/// The X component of the coordinates.
|
||||
/// </summary>
|
||||
public int X;
|
||||
|
||||
/// <summary>
|
||||
/// The Y component of the coordinates.
|
||||
/// </summary>
|
||||
public int Y;
|
||||
|
||||
/// <summary>
|
||||
/// The Z component of the coordinates.
|
||||
/// </summary>
|
||||
public int Z;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new trio of coordinates from the specified value.
|
||||
/// </summary>
|
||||
/// <param name="value">The value for the components of the coordinates.</param>
|
||||
public Coordinates3D(int value)
|
||||
{
|
||||
X = Y = Z = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new trio of coordinates from the specified values.
|
||||
/// </summary>
|
||||
/// <param name="x">The X component of the coordinates.</param>
|
||||
/// <param name="z">The Y component of the coordinates.</param>
|
||||
/// <param name="z">The Z component of the coordinates.</param>
|
||||
public Coordinates3D(int x = 0, int y = 0, int z = 0)
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
Z = z;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new trio of coordinates by copying another.
|
||||
/// </summary>
|
||||
/// <param name="v">The coordinates to copy.</param>
|
||||
public Coordinates3D(Coordinates3D v)
|
||||
{
|
||||
X = v.X;
|
||||
Y = v.Y;
|
||||
Z = v.Z;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts this Coordinates3D to a string in the format <x, y, z>.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Format("<{0},{1},{2}>", X, Y, Z);
|
||||
}
|
||||
|
||||
#region Math
|
||||
|
||||
/// <summary>
|
||||
/// Clamps the coordinates to within the specified value.
|
||||
/// </summary>
|
||||
/// <param name="value">Value.</param>
|
||||
public void Clamp(int value)
|
||||
{
|
||||
// TODO: Fix for negative values
|
||||
if (Math.Abs(X) > value)
|
||||
X = value * (X < 0 ? -1 : 1);
|
||||
if (Math.Abs(Y) > value)
|
||||
Y = value * (Y < 0 ? -1 : 1);
|
||||
if (Math.Abs(Z) > value)
|
||||
Z = value * (Z < 0 ? -1 : 1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the distance between two Coordinates3D objects.
|
||||
/// </summary>
|
||||
public double DistanceTo(Coordinates3D other)
|
||||
{
|
||||
return Math.Sqrt(Square(other.X - X) +
|
||||
Square(other.Y - Y) +
|
||||
Square(other.Z - Z));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the square of a num.
|
||||
/// </summary>
|
||||
private int Square(int num)
|
||||
{
|
||||
return num * num;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finds the distance of this Coordinate3D from Coordinates3D.Zero
|
||||
/// </summary>
|
||||
public double Distance
|
||||
{
|
||||
get
|
||||
{
|
||||
return DistanceTo(Zero);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the component-wise minimum of two 3D coordinates.
|
||||
/// </summary>
|
||||
/// <param name="value1">The first coordinates.</param>
|
||||
/// <param name="value2">The second coordinates.</param>
|
||||
/// <returns></returns>
|
||||
public static Coordinates3D Min(Coordinates3D value1, Coordinates3D value2)
|
||||
{
|
||||
return new Coordinates3D(
|
||||
Math.Min(value1.X, value2.X),
|
||||
Math.Min(value1.Y, value2.Y),
|
||||
Math.Min(value1.Z, value2.Z)
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the component-wise maximum of two 3D coordinates.
|
||||
/// </summary>
|
||||
/// <param name="value1">The first coordinates.</param>
|
||||
/// <param name="value2">The second coordinates.</param>
|
||||
/// <returns></returns>
|
||||
public static Coordinates3D Max(Coordinates3D value1, Coordinates3D value2)
|
||||
{
|
||||
return new Coordinates3D(
|
||||
Math.Max(value1.X, value2.X),
|
||||
Math.Max(value1.Y, value2.Y),
|
||||
Math.Max(value1.Z, value2.Z)
|
||||
);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Operators
|
||||
|
||||
public static bool operator !=(Coordinates3D a, Coordinates3D b)
|
||||
{
|
||||
return !a.Equals(b);
|
||||
}
|
||||
|
||||
public static bool operator ==(Coordinates3D a, Coordinates3D b)
|
||||
{
|
||||
return a.Equals(b);
|
||||
}
|
||||
|
||||
public static Coordinates3D operator +(Coordinates3D a, Coordinates3D b)
|
||||
{
|
||||
return new Coordinates3D(a.X + b.X, a.Y + b.Y, a.Z + b.Z);
|
||||
}
|
||||
|
||||
public static Coordinates3D operator -(Coordinates3D a, Coordinates3D b)
|
||||
{
|
||||
return new Coordinates3D(a.X - b.X, a.Y - b.Y, a.Z - b.Z);
|
||||
}
|
||||
|
||||
public static Coordinates3D operator -(Coordinates3D a)
|
||||
{
|
||||
return new Coordinates3D(-a.X, -a.Y, -a.Z);
|
||||
}
|
||||
|
||||
public static Coordinates3D operator *(Coordinates3D a, Coordinates3D b)
|
||||
{
|
||||
return new Coordinates3D(a.X * b.X, a.Y * b.Y, a.Z * b.Z);
|
||||
}
|
||||
|
||||
public static Coordinates3D operator /(Coordinates3D a, Coordinates3D b)
|
||||
{
|
||||
return new Coordinates3D(a.X / b.X, a.Y / b.Y, a.Z / b.Z);
|
||||
}
|
||||
|
||||
public static Coordinates3D operator %(Coordinates3D a, Coordinates3D b)
|
||||
{
|
||||
return new Coordinates3D(a.X % b.X, a.Y % b.Y, a.Z % b.Z);
|
||||
}
|
||||
|
||||
public static Coordinates3D operator +(Coordinates3D a, int b)
|
||||
{
|
||||
return new Coordinates3D(a.X + b, a.Y + b, a.Z + b);
|
||||
}
|
||||
|
||||
public static Coordinates3D operator -(Coordinates3D a, int b)
|
||||
{
|
||||
return new Coordinates3D(a.X - b, a.Y - b, a.Z - b);
|
||||
}
|
||||
|
||||
public static Coordinates3D operator *(Coordinates3D a, int b)
|
||||
{
|
||||
return new Coordinates3D(a.X * b, a.Y * b, a.Z * b);
|
||||
}
|
||||
|
||||
public static Coordinates3D operator /(Coordinates3D a, int b)
|
||||
{
|
||||
return new Coordinates3D(a.X / b, a.Y / b, a.Z / b);
|
||||
}
|
||||
|
||||
public static Coordinates3D operator %(Coordinates3D a, int b)
|
||||
{
|
||||
return new Coordinates3D(a.X % b, a.Y % b, a.Z % b);
|
||||
}
|
||||
|
||||
public static Coordinates3D operator +(int a, Coordinates3D b)
|
||||
{
|
||||
return new Coordinates3D(a + b.X, a + b.Y, a + b.Z);
|
||||
}
|
||||
|
||||
public static Coordinates3D operator -(int a, Coordinates3D b)
|
||||
{
|
||||
return new Coordinates3D(a - b.X, a - b.Y, a - b.Z);
|
||||
}
|
||||
|
||||
public static Coordinates3D operator *(int a, Coordinates3D b)
|
||||
{
|
||||
return new Coordinates3D(a * b.X, a * b.Y, a * b.Z);
|
||||
}
|
||||
|
||||
public static Coordinates3D operator /(int a, Coordinates3D b)
|
||||
{
|
||||
return new Coordinates3D(a / b.X, a / b.Y, a / b.Z);
|
||||
}
|
||||
|
||||
public static Coordinates3D operator %(int a, Coordinates3D b)
|
||||
{
|
||||
return new Coordinates3D(a % b.X, a % b.Y, a % b.Z);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Conversion operators
|
||||
|
||||
public static explicit operator Coordinates3D(Coordinates2D a)
|
||||
{
|
||||
return new Coordinates3D(a.X, 0, a.Z);
|
||||
}
|
||||
|
||||
public static explicit operator Coordinates3D(Vector3 a)
|
||||
{
|
||||
return new Coordinates3D((int)a.X,
|
||||
(int)a.Y,
|
||||
(int)a.Z);
|
||||
}
|
||||
|
||||
public static explicit operator Coordinates3D(Size s)
|
||||
{
|
||||
return new Coordinates3D((int)s.Width,
|
||||
(int)s.Height,
|
||||
(int)s.Depth);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constants
|
||||
|
||||
/// <summary>
|
||||
/// A trio of 3D coordinates with components set to 0.0.
|
||||
/// </summary>
|
||||
public static readonly Coordinates3D Zero = new Coordinates3D(0);
|
||||
|
||||
/// <summary>
|
||||
/// A trio of 3D coordinates with components set to 0.0.
|
||||
/// </summary>
|
||||
public static readonly Coordinates3D One = new Coordinates3D(1);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A trio of 3D coordinates facing up.
|
||||
/// </summary>
|
||||
public static readonly Coordinates3D Up = new Coordinates3D(0, 1, 0);
|
||||
|
||||
/// <summary>
|
||||
/// A trio of 3D coordinates facing down.
|
||||
/// </summary>
|
||||
public static readonly Coordinates3D Down = new Coordinates3D(0, -1, 0);
|
||||
|
||||
/// <summary>
|
||||
/// A trio of 3D coordinates facing left.
|
||||
/// </summary>
|
||||
public static readonly Coordinates3D Left = new Coordinates3D(-1, 0, 0);
|
||||
|
||||
/// <summary>
|
||||
/// A trio of 3D coordinates facing right.
|
||||
/// </summary>
|
||||
public static readonly Coordinates3D Right = new Coordinates3D(1, 0, 0);
|
||||
|
||||
/// <summary>
|
||||
/// A trio of 3D coordinates facing backwards.
|
||||
/// </summary>
|
||||
public static readonly Coordinates3D Backwards = new Coordinates3D(0, 0, -1);
|
||||
|
||||
/// <summary>
|
||||
/// A trio of 3D coordinates facing forwards.
|
||||
/// </summary>
|
||||
public static readonly Coordinates3D Forwards = new Coordinates3D(0, 0, 1);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A trio of 3D coordinates facing to the east.
|
||||
/// </summary>
|
||||
public static readonly Coordinates3D East = new Coordinates3D(1, 0, 0);
|
||||
|
||||
/// <summary>
|
||||
/// A trio of 3D coordinates facing to the west.
|
||||
/// </summary>
|
||||
public static readonly Coordinates3D West = new Coordinates3D(-1, 0, 0);
|
||||
|
||||
/// <summary>
|
||||
/// A trio of 3D coordinates facing to the north.
|
||||
/// </summary>
|
||||
public static readonly Coordinates3D North = new Coordinates3D(0, 0, -1);
|
||||
|
||||
/// <summary>
|
||||
/// A trio of 3D coordinates facing to the south.
|
||||
/// </summary>
|
||||
public static readonly Coordinates3D South = new Coordinates3D(0, 0, 1);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A trio of 3D coordinates facing the X axis at unit length.
|
||||
/// </summary>
|
||||
public static readonly Coordinates3D OneX = new Coordinates3D(1, 0, 0);
|
||||
|
||||
/// <summary>
|
||||
/// A trio of 3D coordinates facing the Y axis at unit length.
|
||||
/// </summary>
|
||||
public static readonly Coordinates3D OneY = new Coordinates3D(0, 1, 0);
|
||||
|
||||
/// <summary>
|
||||
/// A trio of 3D coordinates facing the Z axis at unit length.
|
||||
/// </summary>
|
||||
public static readonly Coordinates3D OneZ = new Coordinates3D(0, 0, 1);
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether this 3D coordinates and another are equal.
|
||||
/// </summary>
|
||||
/// <param name="other">The other coordinates.</param>
|
||||
/// <returns></returns>
|
||||
public bool Equals(Coordinates3D other)
|
||||
{
|
||||
return other.X.Equals(X) && other.Y.Equals(Y) && other.Z.Equals(Z);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether this and another object are equal.
|
||||
/// </summary>
|
||||
/// <param name="obj">The other object.</param>
|
||||
/// <returns></returns>
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (ReferenceEquals(null, obj)) return false;
|
||||
if (obj.GetType() != typeof(Coordinates3D)) return false;
|
||||
return Equals((Coordinates3D)obj);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the hash code for this 3D coordinates.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public override int GetHashCode()
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
int result = X.GetHashCode();
|
||||
result = (result * 397) ^ Y.GetHashCode();
|
||||
result = (result * 397) ^ Z.GetHashCode();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
30
TrueCraft.API/Difficulty.cs
Normal file
30
TrueCraft.API/Difficulty.cs
Normal file
@ -0,0 +1,30 @@
|
||||
using System;
|
||||
|
||||
namespace TrueCraft.API
|
||||
{
|
||||
/// <summary>
|
||||
/// Enumerates the difficulty levels in TrueCraft.
|
||||
/// </summary>
|
||||
public enum Difficulty
|
||||
{
|
||||
/// <summary>
|
||||
/// Peaceful difficulty.
|
||||
/// </summary>
|
||||
Peaceful = 0,
|
||||
|
||||
/// <summary>
|
||||
/// Easy difficulty.
|
||||
/// </summary>
|
||||
Easy = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Normal difficulty.
|
||||
/// </summary>
|
||||
Normal = 2,
|
||||
|
||||
/// <summary>
|
||||
/// Hard difficulty.
|
||||
/// </summary>
|
||||
Hard = 3
|
||||
}
|
||||
}
|
20
TrueCraft.API/Dimension.cs
Normal file
20
TrueCraft.API/Dimension.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using System;
|
||||
|
||||
namespace TrueCraft.API
|
||||
{
|
||||
/// <summary>
|
||||
/// Enumerates the different dimensions in the world in TrueCraft.
|
||||
/// </summary>
|
||||
public enum Dimension
|
||||
{
|
||||
/// <summary>
|
||||
/// The Nether dimension.
|
||||
/// </summary>
|
||||
Nether = -1,
|
||||
|
||||
/// <summary>
|
||||
/// The Overworld dimension.
|
||||
/// </summary>
|
||||
Overworld = 0
|
||||
}
|
||||
}
|
11
TrueCraft.API/Entities/IBlockPhysicsProvider.cs
Normal file
11
TrueCraft.API/Entities/IBlockPhysicsProvider.cs
Normal file
@ -0,0 +1,11 @@
|
||||
using System;
|
||||
using TrueCraft.API;
|
||||
using TrueCraft.API.World;
|
||||
|
||||
namespace TrueCraft.API.Entities
|
||||
{
|
||||
public interface IBlockPhysicsProvider
|
||||
{
|
||||
BoundingBox? GetBoundingBox(IWorld world, Coordinates3D coordinates);
|
||||
}
|
||||
}
|
25
TrueCraft.API/Entities/IEntity.cs
Normal file
25
TrueCraft.API/Entities/IEntity.cs
Normal file
@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using TrueCraft.API.Networking;
|
||||
using TrueCraft.API.Server;
|
||||
using TrueCraft.API.World;
|
||||
|
||||
namespace TrueCraft.API.Entities
|
||||
{
|
||||
public interface IEntity : INotifyPropertyChanged
|
||||
{
|
||||
IPacket SpawnPacket { get; }
|
||||
int EntityID { get; set; }
|
||||
Vector3 Position { get; set; }
|
||||
float Yaw { get; set; }
|
||||
float Pitch { get; set; }
|
||||
bool Despawned { get; set; }
|
||||
DateTime SpawnTime { get; set; }
|
||||
MetadataDictionary Metadata { get; }
|
||||
Size Size { get; }
|
||||
IEntityManager EntityManager { get; set; }
|
||||
IWorld World { get; set; }
|
||||
bool SendMetadataToClients { get; }
|
||||
void Update(IEntityManager entityManager);
|
||||
}
|
||||
}
|
15
TrueCraft.API/Entities/IMobEntity.cs
Normal file
15
TrueCraft.API/Entities/IMobEntity.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using TrueCraft.API.AI;
|
||||
using TrueCraft.API.Physics;
|
||||
|
||||
namespace TrueCraft.API.Entities
|
||||
{
|
||||
public interface IMobEntity : IEntity, IAABBEntity
|
||||
{
|
||||
event EventHandler PathComplete;
|
||||
PathResult CurrentPath { get; set; }
|
||||
bool AdvancePath(TimeSpan time, bool faceRoute = true);
|
||||
IMobState CurrentState { get; set; }
|
||||
void Face(Vector3 target);
|
||||
}
|
||||
}
|
20
TrueCraft.API/GameMode.cs
Normal file
20
TrueCraft.API/GameMode.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using System;
|
||||
|
||||
namespace TrueCraft.API
|
||||
{
|
||||
/// <summary>
|
||||
/// Enumerates the different game modes in TrueCraft.
|
||||
/// </summary>
|
||||
public enum GameMode
|
||||
{
|
||||
/// <summary>
|
||||
/// The survival game mode.
|
||||
/// </summary>
|
||||
Survival = 0,
|
||||
|
||||
/// <summary>
|
||||
/// The creative game mode.
|
||||
/// </summary>
|
||||
Creative = 1
|
||||
}
|
||||
}
|
26
TrueCraft.API/IAccessConfiguration.cs
Normal file
26
TrueCraft.API/IAccessConfiguration.cs
Normal file
@ -0,0 +1,26 @@
|
||||
using System.Collections.Generic;
|
||||
using TrueCraft.API.Networking;
|
||||
|
||||
namespace TrueCraft.API
|
||||
{
|
||||
/// <summary>
|
||||
/// Interface for objects providing server access configuration.
|
||||
/// </summary>
|
||||
public interface IAccessConfiguration
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets a list of blacklisted players for the configuration.
|
||||
/// </summary>
|
||||
IList<string> Blacklist { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of whitelisted players for the configuration.
|
||||
/// </summary>
|
||||
IList<string> Whitelist { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of opped players for the configuration.
|
||||
/// </summary>
|
||||
IList<string> Oplist { get; }
|
||||
}
|
||||
}
|
13
TrueCraft.API/IEventSubject.cs
Normal file
13
TrueCraft.API/IEventSubject.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
|
||||
namespace TrueCraft.API
|
||||
{
|
||||
/// <summary>
|
||||
/// The subject of an event. When it's disposed, it raises an event and the associated
|
||||
/// scheduled events are discarded.
|
||||
/// </summary>
|
||||
public interface IEventSubject : IDisposable
|
||||
{
|
||||
event EventHandler Disposed;
|
||||
}
|
||||
}
|
319
TrueCraft.API/ItemStack.cs
Normal file
319
TrueCraft.API/ItemStack.cs
Normal file
@ -0,0 +1,319 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using fNbt;
|
||||
using fNbt.Serialization;
|
||||
using TrueCraft.API.Networking;
|
||||
|
||||
namespace TrueCraft.API
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a stack of items.
|
||||
/// </summary>
|
||||
public struct ItemStack : ICloneable, IEquatable<ItemStack>
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns the hash code for this item stack.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public override int GetHashCode()
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
int hashCode = _Id.GetHashCode();
|
||||
hashCode = (hashCode * 397) ^ _Count.GetHashCode();
|
||||
hashCode = (hashCode * 397) ^ _Metadata.GetHashCode();
|
||||
hashCode = (hashCode * 397) ^ Index;
|
||||
hashCode = (hashCode * 397) ^ (Nbt != null ? Nbt.GetHashCode() : 0);
|
||||
return hashCode;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool operator ==(ItemStack left, ItemStack right)
|
||||
{
|
||||
return left.Equals(right);
|
||||
}
|
||||
|
||||
public static bool operator !=(ItemStack left, ItemStack right)
|
||||
{
|
||||
return !left.Equals(right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new item stack with the specified values.
|
||||
/// </summary>
|
||||
/// <param name="id">The item ID for the item stack.</param>
|
||||
public ItemStack(short id) : this()
|
||||
{
|
||||
_Id = id;
|
||||
_Count = 1;
|
||||
Metadata = 0;
|
||||
Nbt = null;
|
||||
Index = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new item stack with the specified values.
|
||||
/// </summary>
|
||||
/// <param name="id">The item ID for the item stack.</param>
|
||||
/// <param name="count">The item count for the item stack.</param>
|
||||
public ItemStack(short id, sbyte count) : this(id)
|
||||
{
|
||||
Count = count;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new item stack with the specified values.
|
||||
/// </summary>
|
||||
/// <param name="id">The item ID for the item stack.</param>
|
||||
/// <param name="count">The item count for the item stack.</param>
|
||||
/// <param name="metadata">The metadata for the item stack.</param>
|
||||
public ItemStack(short id, sbyte count, short metadata) : this(id, count)
|
||||
{
|
||||
Metadata = metadata;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new item stack with the specified values.
|
||||
/// </summary>
|
||||
/// <param name="id">The item ID for the item stack.</param>
|
||||
/// <param name="count">The item count for the item stack.</param>
|
||||
/// <param name="metadata">The metadata for the item stack.</param>
|
||||
/// <param name="nbt">The NBT compound tag for the item stack.</param>
|
||||
public ItemStack(short id, sbyte count, short metadata, NbtCompound nbt) : this(id, count, metadata)
|
||||
{
|
||||
Nbt = nbt;
|
||||
if (Count == 0)
|
||||
{
|
||||
ID = -1;
|
||||
Metadata = 0;
|
||||
Nbt = null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates and returns a new item stack read from a Minecraft stream.
|
||||
/// </summary>
|
||||
/// <param name="stream">The stream to read from.</param>
|
||||
/// <returns></returns>
|
||||
public static ItemStack FromStream(IMinecraftStream stream)
|
||||
{
|
||||
var slot = ItemStack.EmptyStack;
|
||||
slot.ID = stream.ReadInt16();
|
||||
if (slot.Empty)
|
||||
return slot;
|
||||
slot.Count = stream.ReadInt8();
|
||||
slot.Metadata = stream.ReadInt16();
|
||||
var length = stream.ReadInt16();
|
||||
if (length == -1)
|
||||
return slot;
|
||||
slot.Nbt = new NbtCompound();
|
||||
var buffer = stream.ReadUInt8Array(length);
|
||||
var nbt = new NbtFile();
|
||||
nbt.LoadFromBuffer(buffer, 0, length, NbtCompression.GZip, null);
|
||||
slot.Nbt = nbt.RootTag;
|
||||
return slot;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes this item stack to a Minecraft stream.
|
||||
/// </summary>
|
||||
/// <param name="stream">The stream to write to.</param>
|
||||
public void WriteTo(IMinecraftStream stream)
|
||||
{
|
||||
stream.WriteInt16(ID);
|
||||
if (Empty)
|
||||
return;
|
||||
stream.WriteInt8(Count);
|
||||
stream.WriteInt16(Metadata);
|
||||
if (Nbt == null)
|
||||
{
|
||||
stream.WriteInt16(-1);
|
||||
return;
|
||||
}
|
||||
var mStream = new MemoryStream();
|
||||
var file = new NbtFile(Nbt);
|
||||
file.SaveToStream(mStream, NbtCompression.GZip);
|
||||
stream.WriteInt16((short)mStream.Position);
|
||||
stream.WriteUInt8Array(mStream.GetBuffer());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates and returns a new item stack created from an NBT compound tag.
|
||||
/// </summary>
|
||||
/// <param name="compound">The compound tag to create the item stack from.</param>
|
||||
/// <returns></returns>
|
||||
public static ItemStack FromNbt(NbtCompound compound)
|
||||
{
|
||||
var s = ItemStack.EmptyStack;
|
||||
s.ID = compound.Get<NbtShort>("id").Value;
|
||||
s.Metadata = compound.Get<NbtShort>("Damage").Value;
|
||||
s.Count = (sbyte)compound.Get<NbtByte>("Count").Value;
|
||||
s.Index = compound.Get<NbtByte>("Slot").Value;
|
||||
if (compound.Get<NbtCompound>("tag") != null)
|
||||
s.Nbt = compound.Get<NbtCompound>("tag");
|
||||
return s;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates and returns a new NBT compound tag containing this item stack.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public NbtCompound ToNbt()
|
||||
{
|
||||
var c = new NbtCompound();
|
||||
c.Add(new NbtShort("id", ID));
|
||||
c.Add(new NbtShort("Damage", Metadata));
|
||||
c.Add(new NbtByte("Count", (byte)Count));
|
||||
c.Add(new NbtByte("Slot", (byte)Index));
|
||||
if (Nbt != null)
|
||||
c.Add(new NbtCompound("tag"));
|
||||
return c;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether this item stack is empty.
|
||||
/// </summary>
|
||||
[NbtIgnore]
|
||||
public bool Empty
|
||||
{
|
||||
get { return ID == -1; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the item ID for this item stack.
|
||||
/// </summary>
|
||||
public short ID
|
||||
{
|
||||
get { return _Id; }
|
||||
set
|
||||
{
|
||||
_Id = value;
|
||||
if (_Id == -1)
|
||||
{
|
||||
_Count = 0;
|
||||
Metadata = 0;
|
||||
Nbt = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the item count for this item stack.
|
||||
/// </summary>
|
||||
public sbyte Count
|
||||
{
|
||||
get { return _Count; }
|
||||
set
|
||||
{
|
||||
_Count = value;
|
||||
if (_Count == 0)
|
||||
{
|
||||
_Id = -1;
|
||||
Metadata = 0;
|
||||
Nbt = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the metadata for this item stack.
|
||||
/// </summary>
|
||||
public short Metadata
|
||||
{
|
||||
get { return _Metadata; }
|
||||
set { _Metadata = value; }
|
||||
}
|
||||
|
||||
private short _Id;
|
||||
private sbyte _Count;
|
||||
private short _Metadata;
|
||||
|
||||
/// <summary>
|
||||
/// The NBT compound tag for this item stack, if any.
|
||||
/// </summary>
|
||||
[IgnoreOnNull]
|
||||
public NbtCompound Nbt { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The index (slot) of this item stack in an inventory.
|
||||
/// </summary>
|
||||
[NbtIgnore]
|
||||
public int Index;
|
||||
|
||||
/// <summary>
|
||||
/// Returns the string representation of this item stack.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public override string ToString()
|
||||
{
|
||||
if (Empty)
|
||||
return "(Empty)";
|
||||
|
||||
StringBuilder resultBuilder = new StringBuilder("ID: " + ID);
|
||||
|
||||
if (Count != 1) resultBuilder.Append("; Count: " + Count);
|
||||
if (Metadata != 0) resultBuilder.Append("; Metadata: " + Metadata);
|
||||
if (Nbt != null) resultBuilder.Append(Environment.NewLine + Nbt.ToString());
|
||||
|
||||
return "(" + resultBuilder.ToString() + ")";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a clone of this item stack.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public object Clone()
|
||||
{
|
||||
return new ItemStack(ID, Count, Metadata, Nbt);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets an empty item stack.
|
||||
/// </summary>
|
||||
[NbtIgnore]
|
||||
public static ItemStack EmptyStack
|
||||
{
|
||||
get
|
||||
{
|
||||
return new ItemStack(-1);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether this item stack can merge with another.
|
||||
/// </summary>
|
||||
/// <param name="other">The other item stack.</param>
|
||||
/// <returns></returns>
|
||||
public bool CanMerge(ItemStack other)
|
||||
{
|
||||
if (this.Empty || other.Empty)
|
||||
return true;
|
||||
return _Id == other._Id && _Metadata == other._Metadata && Equals(Nbt, other.Nbt);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether this item stack and another object are equal.
|
||||
/// </summary>
|
||||
/// <param name="obj">The other object.</param>
|
||||
/// <returns></returns>
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (ReferenceEquals(null, obj)) return false;
|
||||
return obj is ItemStack && Equals((ItemStack)obj);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether this item stack and another are equal.
|
||||
/// </summary>
|
||||
/// <param name="other">The other item stack.</param>
|
||||
/// <returns></returns>
|
||||
public bool Equals(ItemStack other)
|
||||
{
|
||||
return _Id == other._Id && _Count == other._Count && _Metadata == other._Metadata && Index == other.Index && Equals(Nbt, other.Nbt);
|
||||
}
|
||||
}
|
||||
}
|
9
TrueCraft.API/Logging/ILogProvider.cs
Normal file
9
TrueCraft.API/Logging/ILogProvider.cs
Normal file
@ -0,0 +1,9 @@
|
||||
using System;
|
||||
|
||||
namespace TrueCraft.API.Logging
|
||||
{
|
||||
public interface ILogProvider
|
||||
{
|
||||
void Log(LogCategory category, string text, params object[] parameters);
|
||||
}
|
||||
}
|
30
TrueCraft.API/Logging/LogCategory.cs
Normal file
30
TrueCraft.API/Logging/LogCategory.cs
Normal file
@ -0,0 +1,30 @@
|
||||
using System;
|
||||
|
||||
namespace TrueCraft.API.Logging
|
||||
{
|
||||
[Flags]
|
||||
public enum LogCategory
|
||||
{
|
||||
/// <summary>
|
||||
/// Packets transmitted and received.
|
||||
/// </summary>
|
||||
Packets = 1,
|
||||
/// <summary>
|
||||
/// Debug information.
|
||||
/// </summary>
|
||||
Debug = 2,
|
||||
/// <summary>
|
||||
/// Potentially harmful, but not catastrophic, problems.
|
||||
/// </summary>
|
||||
Warning = 4,
|
||||
/// <summary>
|
||||
/// Catastrophic errors.
|
||||
/// </summary>
|
||||
Error = 8,
|
||||
/// <summary>
|
||||
/// Generally useful information.
|
||||
/// </summary>
|
||||
Notice = 16,
|
||||
All = Packets | Debug | Warning | Error | Notice
|
||||
}
|
||||
}
|
17
TrueCraft.API/Logic/BlockDescriptor.cs
Normal file
17
TrueCraft.API/Logic/BlockDescriptor.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using TrueCraft.API.World;
|
||||
|
||||
namespace TrueCraft.API.Logic
|
||||
{
|
||||
public struct BlockDescriptor
|
||||
{
|
||||
public byte ID;
|
||||
public byte Metadata;
|
||||
public byte BlockLight;
|
||||
public byte SkyLight;
|
||||
// Optional
|
||||
public Coordinates3D Coordinates;
|
||||
// Optional
|
||||
public IChunk Chunk;
|
||||
}
|
||||
}
|
36
TrueCraft.API/Logic/IBlockProvider.cs
Normal file
36
TrueCraft.API/Logic/IBlockProvider.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using TrueCraft.API.World;
|
||||
using TrueCraft.API.Networking;
|
||||
using TrueCraft.API.Server;
|
||||
using fNbt;
|
||||
|
||||
namespace TrueCraft.API.Logic
|
||||
{
|
||||
public interface IBlockProvider : IItemProvider
|
||||
{
|
||||
byte ID { get; }
|
||||
double BlastResistance { get; }
|
||||
double Hardness { get; }
|
||||
byte Luminance { get; }
|
||||
bool Opaque { get; }
|
||||
bool RenderOpaque { get; }
|
||||
byte LightOpacity { get; }
|
||||
bool DiffuseSkyLight { get; }
|
||||
bool Flammable { get; }
|
||||
SoundEffectClass SoundEffect { get; }
|
||||
ToolMaterial EffectiveToolMaterials { get; }
|
||||
ToolType EffectiveTools { get; }
|
||||
string DisplayName { get; }
|
||||
BoundingBox? BoundingBox { get; } // NOTE: Will this eventually need to be metadata-aware?
|
||||
BoundingBox? InteractiveBoundingBox { get; } // NOTE: Will this eventually need to be metadata-aware?
|
||||
Tuple<int, int> GetTextureMap(byte metadata);
|
||||
void GenerateDropEntity(BlockDescriptor descriptor, IWorld world, IMultiplayerServer server, ItemStack heldItem);
|
||||
void BlockLeftClicked(BlockDescriptor descriptor, BlockFace face, IWorld world, IRemoteClient user);
|
||||
bool BlockRightClicked(BlockDescriptor descriptor, BlockFace face, IWorld world, IRemoteClient user);
|
||||
void BlockPlaced(BlockDescriptor descriptor, BlockFace face, IWorld world, IRemoteClient user);
|
||||
void BlockMined(BlockDescriptor descriptor, BlockFace face, IWorld world, IRemoteClient user);
|
||||
void BlockUpdate(BlockDescriptor descriptor, BlockDescriptor source, IMultiplayerServer server, IWorld world);
|
||||
void BlockLoadedFromChunk(Coordinates3D coords, IMultiplayerServer server, IWorld world);
|
||||
void TileEntityLoadedForClient(BlockDescriptor descriptor, IWorld world, NbtCompound compound, IRemoteClient client);
|
||||
}
|
||||
}
|
21
TrueCraft.API/Logic/IBlockRepository.cs
Normal file
21
TrueCraft.API/Logic/IBlockRepository.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using System;
|
||||
|
||||
namespace TrueCraft.API.Logic
|
||||
{
|
||||
/// <summary>
|
||||
/// Providers block providers for a server.
|
||||
/// </summary>
|
||||
public interface IBlockRepository
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets this repository's block provider for the specified block ID. This may return null
|
||||
/// if the block ID in question has no corresponding block provider.
|
||||
/// </summary>
|
||||
IBlockProvider GetBlockProvider(byte id);
|
||||
/// <summary>
|
||||
/// Registers a new block provider. This overrides any existing block providers that use the
|
||||
/// same block ID.
|
||||
/// </summary>
|
||||
void RegisterBlockProvider(IBlockProvider provider);
|
||||
}
|
||||
}
|
15
TrueCraft.API/Logic/IBurnableItem.cs
Normal file
15
TrueCraft.API/Logic/IBurnableItem.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
|
||||
namespace TrueCraft.API.Logic
|
||||
{
|
||||
/// <summary>
|
||||
/// Describes an item that can be burnt as fuel in a furnace.
|
||||
/// </summary>
|
||||
public interface IBurnableItem
|
||||
{
|
||||
/// <summary>
|
||||
/// The duration of time this item can act as fuel.
|
||||
/// </summary>
|
||||
TimeSpan BurnTime { get; }
|
||||
}
|
||||
}
|
11
TrueCraft.API/Logic/ICraftingRecipe.cs
Normal file
11
TrueCraft.API/Logic/ICraftingRecipe.cs
Normal file
@ -0,0 +1,11 @@
|
||||
using TrueCraft.API;
|
||||
|
||||
namespace TrueCraft.API.Logic
|
||||
{
|
||||
public interface ICraftingRecipe
|
||||
{
|
||||
ItemStack[,] Pattern { get; }
|
||||
ItemStack Output { get; }
|
||||
bool SignificantMetadata { get; }
|
||||
}
|
||||
}
|
10
TrueCraft.API/Logic/ICraftingRepository.cs
Normal file
10
TrueCraft.API/Logic/ICraftingRepository.cs
Normal file
@ -0,0 +1,10 @@
|
||||
using TrueCraft.API.Windows;
|
||||
|
||||
namespace TrueCraft.API.Logic
|
||||
{
|
||||
public interface ICraftingRepository
|
||||
{
|
||||
ICraftingRecipe GetRecipe(IWindowArea craftingArea);
|
||||
bool TestRecipe(IWindowArea craftingArea, ICraftingRecipe recipe, int x, int y);
|
||||
}
|
||||
}
|
18
TrueCraft.API/Logic/IItemProvider.cs
Normal file
18
TrueCraft.API/Logic/IItemProvider.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using TrueCraft.API.World;
|
||||
using TrueCraft.API.Networking;
|
||||
using TrueCraft.API.Entities;
|
||||
|
||||
namespace TrueCraft.API.Logic
|
||||
{
|
||||
public interface IItemProvider
|
||||
{
|
||||
short ID { get; }
|
||||
sbyte MaximumStack { get; }
|
||||
string DisplayName { get; }
|
||||
void ItemUsedOnNothing(ItemStack item, IWorld world, IRemoteClient user);
|
||||
void ItemUsedOnEntity(ItemStack item, IEntity usedOn, IWorld world, IRemoteClient user);
|
||||
void ItemUsedOnBlock(Coordinates3D coordinates, ItemStack item, BlockFace face, IWorld world, IRemoteClient user);
|
||||
Tuple<int, int> GetIconTexture(byte metadata);
|
||||
}
|
||||
}
|
21
TrueCraft.API/Logic/IItemRepository.cs
Normal file
21
TrueCraft.API/Logic/IItemRepository.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using System;
|
||||
|
||||
namespace TrueCraft.API.Logic
|
||||
{
|
||||
/// <summary>
|
||||
/// Providers item providers for a server.
|
||||
/// </summary>
|
||||
public interface IItemRepository
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets this repository's item provider for the specified item ID. This may return null
|
||||
/// if the item ID in question has no corresponding block provider.
|
||||
/// </summary>
|
||||
IItemProvider GetItemProvider(short id);
|
||||
/// <summary>
|
||||
/// Registers a new item provider. This overrides any existing item providers that use the
|
||||
/// same item ID.
|
||||
/// </summary>
|
||||
void RegisterItemProvider(IItemProvider provider);
|
||||
}
|
||||
}
|
15
TrueCraft.API/Logic/ISmeltableItem.cs
Normal file
15
TrueCraft.API/Logic/ISmeltableItem.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
|
||||
namespace TrueCraft.API.Logic
|
||||
{
|
||||
/// <summary>
|
||||
/// Describes an item that can be smelted in a furnace to produce a new item.
|
||||
/// </summary>
|
||||
public interface ISmeltableItem
|
||||
{
|
||||
/// <summary>
|
||||
/// The item this becomes when smelted.
|
||||
/// </summary>
|
||||
ItemStack SmeltingOutput { get; }
|
||||
}
|
||||
}
|
17
TrueCraft.API/Logic/SoundEffectClass.cs
Normal file
17
TrueCraft.API/Logic/SoundEffectClass.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
|
||||
namespace TrueCraft.API.Logic
|
||||
{
|
||||
public enum SoundEffectClass
|
||||
{
|
||||
None,
|
||||
Cloth,
|
||||
Grass,
|
||||
Gravel,
|
||||
Sand,
|
||||
Snow,
|
||||
Stone,
|
||||
Wood,
|
||||
Glass
|
||||
}
|
||||
}
|
1663
TrueCraft.API/Matrix.cs
Normal file
1663
TrueCraft.API/Matrix.cs
Normal file
File diff suppressed because it is too large
Load Diff
37
TrueCraft.API/MetadataByte.cs
Normal file
37
TrueCraft.API/MetadataByte.cs
Normal file
@ -0,0 +1,37 @@
|
||||
using TrueCraft.API.Networking;
|
||||
|
||||
namespace TrueCraft.API
|
||||
{
|
||||
public class MetadataByte : MetadataEntry
|
||||
{
|
||||
public override byte Identifier { get { return 0; } }
|
||||
public override string FriendlyName { get { return "byte"; } }
|
||||
|
||||
public byte Value;
|
||||
|
||||
public static implicit operator MetadataByte(byte value)
|
||||
{
|
||||
return new MetadataByte(value);
|
||||
}
|
||||
|
||||
public MetadataByte()
|
||||
{
|
||||
}
|
||||
|
||||
public MetadataByte(byte value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public override void FromStream(IMinecraftStream stream)
|
||||
{
|
||||
Value = stream.ReadUInt8();
|
||||
}
|
||||
|
||||
public override void WriteTo(IMinecraftStream stream, byte index)
|
||||
{
|
||||
stream.WriteUInt8(GetKey(index));
|
||||
stream.WriteUInt8(Value);
|
||||
}
|
||||
}
|
||||
}
|
89
TrueCraft.API/MetadataDictionary.cs
Normal file
89
TrueCraft.API/MetadataDictionary.cs
Normal file
@ -0,0 +1,89 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using TrueCraft.API.Networking;
|
||||
|
||||
namespace TrueCraft.API
|
||||
{
|
||||
/// <summary>
|
||||
/// Used to send metadata with entities
|
||||
/// </summary>
|
||||
public class MetadataDictionary
|
||||
{
|
||||
private readonly Dictionary<byte, MetadataEntry> entries;
|
||||
|
||||
public MetadataDictionary()
|
||||
{
|
||||
entries = new Dictionary<byte, MetadataEntry>();
|
||||
}
|
||||
|
||||
public int Count
|
||||
{
|
||||
get { return entries.Count; }
|
||||
}
|
||||
|
||||
public MetadataEntry this[byte index]
|
||||
{
|
||||
get { return entries[index]; }
|
||||
set { entries[index] = value; }
|
||||
}
|
||||
|
||||
public static MetadataDictionary FromStream(IMinecraftStream stream)
|
||||
{
|
||||
var value = new MetadataDictionary();
|
||||
while (true)
|
||||
{
|
||||
byte key = stream.ReadUInt8();
|
||||
if (key == 127) break;
|
||||
|
||||
byte type = (byte)((key & 0xE0) >> 5);
|
||||
byte index = (byte)(key & 0x1F);
|
||||
|
||||
var entry = EntryTypes[type]();
|
||||
entry.FromStream(stream);
|
||||
entry.Index = index;
|
||||
|
||||
value[index] = entry;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public void WriteTo(IMinecraftStream stream)
|
||||
{
|
||||
foreach (var entry in entries)
|
||||
entry.Value.WriteTo(stream, entry.Key);
|
||||
stream.WriteUInt8(0x7F);
|
||||
}
|
||||
|
||||
delegate MetadataEntry CreateEntryInstance();
|
||||
|
||||
private static readonly CreateEntryInstance[] EntryTypes = new CreateEntryInstance[]
|
||||
{
|
||||
() => new MetadataByte(), // 0
|
||||
() => new MetadataShort(), // 1
|
||||
() => new MetadataInt(), // 2
|
||||
() => new MetadataFloat(), // 3
|
||||
() => new MetadataString(), // 4
|
||||
() => new MetadataSlot(), // 5
|
||||
};
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
System.Text.StringBuilder sb = null;
|
||||
|
||||
foreach (var entry in entries.Values)
|
||||
{
|
||||
if (sb != null)
|
||||
sb.Append(", ");
|
||||
else
|
||||
sb = new System.Text.StringBuilder();
|
||||
|
||||
sb.Append(entry.ToString());
|
||||
}
|
||||
|
||||
if (sb != null)
|
||||
return sb.ToString();
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
63
TrueCraft.API/MetadataEntry.cs
Normal file
63
TrueCraft.API/MetadataEntry.cs
Normal file
@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using TrueCraft.API.Networking;
|
||||
|
||||
namespace TrueCraft.API
|
||||
{
|
||||
public abstract class MetadataEntry
|
||||
{
|
||||
public abstract byte Identifier { get; }
|
||||
public abstract string FriendlyName { get; }
|
||||
|
||||
public abstract void FromStream(IMinecraftStream stream);
|
||||
public abstract void WriteTo(IMinecraftStream stream, byte index);
|
||||
|
||||
internal byte Index { get; set; }
|
||||
|
||||
public static implicit operator MetadataEntry(byte value)
|
||||
{
|
||||
return new MetadataByte(value);
|
||||
}
|
||||
|
||||
public static implicit operator MetadataEntry(short value)
|
||||
{
|
||||
return new MetadataShort(value);
|
||||
}
|
||||
|
||||
public static implicit operator MetadataEntry(int value)
|
||||
{
|
||||
return new MetadataInt(value);
|
||||
}
|
||||
|
||||
public static implicit operator MetadataEntry(float value)
|
||||
{
|
||||
return new MetadataFloat(value);
|
||||
}
|
||||
|
||||
public static implicit operator MetadataEntry(string value)
|
||||
{
|
||||
return new MetadataString(value);
|
||||
}
|
||||
|
||||
public static implicit operator MetadataEntry(ItemStack value)
|
||||
{
|
||||
return new MetadataSlot(value);
|
||||
}
|
||||
|
||||
protected byte GetKey(byte index)
|
||||
{
|
||||
Index = index; // Cheat to get this for ToString
|
||||
return (byte)((Identifier << 5) | (index & 0x1F));
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
Type type = GetType();
|
||||
FieldInfo[] fields = type.GetFields();
|
||||
string result = FriendlyName + "[" + Index + "]: ";
|
||||
if (fields.Length != 0)
|
||||
result += fields[0].GetValue(this).ToString();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
38
TrueCraft.API/MetadataFloat.cs
Normal file
38
TrueCraft.API/MetadataFloat.cs
Normal file
@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using TrueCraft.API.Networking;
|
||||
|
||||
namespace TrueCraft.API
|
||||
{
|
||||
public class MetadataFloat : MetadataEntry
|
||||
{
|
||||
public override byte Identifier { get { return 3; } }
|
||||
public override string FriendlyName { get { return "float"; } }
|
||||
|
||||
public float Value;
|
||||
|
||||
public static implicit operator MetadataFloat(float value)
|
||||
{
|
||||
return new MetadataFloat(value);
|
||||
}
|
||||
|
||||
public MetadataFloat()
|
||||
{
|
||||
}
|
||||
|
||||
public MetadataFloat(float value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public override void FromStream(IMinecraftStream stream)
|
||||
{
|
||||
Value = stream.ReadSingle();
|
||||
}
|
||||
|
||||
public override void WriteTo(IMinecraftStream stream, byte index)
|
||||
{
|
||||
stream.WriteUInt8(GetKey(index));
|
||||
stream.WriteSingle(Value);
|
||||
}
|
||||
}
|
||||
}
|
38
TrueCraft.API/MetadataInt.cs
Normal file
38
TrueCraft.API/MetadataInt.cs
Normal file
@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using TrueCraft.API.Networking;
|
||||
|
||||
namespace TrueCraft.API
|
||||
{
|
||||
public class MetadataInt : MetadataEntry
|
||||
{
|
||||
public override byte Identifier { get { return 2; } }
|
||||
public override string FriendlyName { get { return "int"; } }
|
||||
|
||||
public int Value;
|
||||
|
||||
public static implicit operator MetadataInt(int value)
|
||||
{
|
||||
return new MetadataInt(value);
|
||||
}
|
||||
|
||||
public MetadataInt()
|
||||
{
|
||||
}
|
||||
|
||||
public MetadataInt(int value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public override void FromStream(IMinecraftStream stream)
|
||||
{
|
||||
Value = stream.ReadInt32();
|
||||
}
|
||||
|
||||
public override void WriteTo(IMinecraftStream stream, byte index)
|
||||
{
|
||||
stream.WriteUInt8(GetKey(index));
|
||||
stream.WriteInt32(Value);
|
||||
}
|
||||
}
|
||||
}
|
38
TrueCraft.API/MetadataShort.cs
Normal file
38
TrueCraft.API/MetadataShort.cs
Normal file
@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using TrueCraft.API.Networking;
|
||||
|
||||
namespace TrueCraft.API
|
||||
{
|
||||
public class MetadataShort : MetadataEntry
|
||||
{
|
||||
public override byte Identifier { get { return 1; } }
|
||||
public override string FriendlyName { get { return "short"; } }
|
||||
|
||||
public short Value;
|
||||
|
||||
public static implicit operator MetadataShort(short value)
|
||||
{
|
||||
return new MetadataShort(value);
|
||||
}
|
||||
|
||||
public MetadataShort()
|
||||
{
|
||||
}
|
||||
|
||||
public MetadataShort(short value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public override void FromStream(IMinecraftStream stream)
|
||||
{
|
||||
Value = stream.ReadInt16();
|
||||
}
|
||||
|
||||
public override void WriteTo(IMinecraftStream stream, byte index)
|
||||
{
|
||||
stream.WriteUInt8(GetKey(index));
|
||||
stream.WriteInt16(Value);
|
||||
}
|
||||
}
|
||||
}
|
54
TrueCraft.API/MetadataSlot.cs
Normal file
54
TrueCraft.API/MetadataSlot.cs
Normal file
@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using fNbt;
|
||||
using TrueCraft.API.Networking;
|
||||
|
||||
namespace TrueCraft.API
|
||||
{
|
||||
public class MetadataSlot : MetadataEntry
|
||||
{
|
||||
public override byte Identifier { get { return 5; } }
|
||||
public override string FriendlyName { get { return "slot"; } }
|
||||
|
||||
public ItemStack Value;
|
||||
|
||||
public static implicit operator MetadataSlot(ItemStack value)
|
||||
{
|
||||
return new MetadataSlot(value);
|
||||
}
|
||||
|
||||
public MetadataSlot()
|
||||
{
|
||||
}
|
||||
|
||||
public MetadataSlot(ItemStack value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public override void FromStream(IMinecraftStream stream)
|
||||
{
|
||||
Value = ItemStack.FromStream(stream);
|
||||
}
|
||||
|
||||
public override void WriteTo(IMinecraftStream stream, byte index)
|
||||
{
|
||||
stream.WriteUInt8(GetKey(index));
|
||||
stream.WriteInt16(Value.ID);
|
||||
if (Value.ID != -1)
|
||||
{
|
||||
stream.WriteInt8(Value.Count);
|
||||
stream.WriteInt16(Value.Metadata);
|
||||
if (Value.Nbt != null)
|
||||
{
|
||||
var file = new NbtFile(Value.Nbt);
|
||||
var data = file.SaveToBuffer(NbtCompression.GZip);
|
||||
stream.WriteInt16((short)data.Length);
|
||||
stream.WriteUInt8Array(data);
|
||||
}
|
||||
else
|
||||
stream.WriteInt16(-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
43
TrueCraft.API/MetadataString.cs
Normal file
43
TrueCraft.API/MetadataString.cs
Normal file
@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using TrueCraft.API.Networking;
|
||||
|
||||
namespace TrueCraft.API
|
||||
{
|
||||
public class MetadataString : MetadataEntry
|
||||
{
|
||||
public override byte Identifier { get { return 4; } }
|
||||
public override string FriendlyName { get { return "string"; } }
|
||||
|
||||
public string Value;
|
||||
|
||||
public static implicit operator MetadataString(string value)
|
||||
{
|
||||
return new MetadataString(value);
|
||||
}
|
||||
|
||||
public MetadataString()
|
||||
{
|
||||
}
|
||||
|
||||
public MetadataString(string value)
|
||||
{
|
||||
if (value.Length > 16)
|
||||
throw new ArgumentOutOfRangeException("value", "Maximum string length is 16 characters");
|
||||
while (value.Length < 16)
|
||||
value = value + "\0";
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public override void FromStream(IMinecraftStream stream)
|
||||
{
|
||||
Value = stream.ReadString();
|
||||
}
|
||||
|
||||
public override void WriteTo(IMinecraftStream stream, byte index)
|
||||
{
|
||||
stream.WriteUInt8(GetKey(index));
|
||||
stream.WriteString(Value);
|
||||
}
|
||||
}
|
||||
}
|
64
TrueCraft.API/Networking/IMinecraftStream.cs
Normal file
64
TrueCraft.API/Networking/IMinecraftStream.cs
Normal file
@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace TrueCraft.API.Networking
|
||||
{
|
||||
public interface IMinecraftStream
|
||||
{
|
||||
Stream BaseStream { get; }
|
||||
|
||||
byte ReadUInt8();
|
||||
sbyte ReadInt8();
|
||||
void WriteUInt8(byte value);
|
||||
void WriteInt8(sbyte value);
|
||||
|
||||
ushort ReadUInt16();
|
||||
short ReadInt16();
|
||||
void WriteUInt16(ushort value);
|
||||
void WriteInt16(short value);
|
||||
|
||||
uint ReadUInt32();
|
||||
int ReadInt32();
|
||||
void WriteUInt32(uint value);
|
||||
void WriteInt32(int value);
|
||||
|
||||
ulong ReadUInt64();
|
||||
long ReadInt64();
|
||||
void WriteUInt64(ulong value);
|
||||
void WriteInt64(long value);
|
||||
|
||||
float ReadSingle();
|
||||
void WriteSingle(float value);
|
||||
|
||||
double ReadDouble();
|
||||
void WriteDouble(double value);
|
||||
|
||||
string ReadString();
|
||||
void WriteString(string value);
|
||||
string ReadString8();
|
||||
void WriteString8(string value);
|
||||
|
||||
bool ReadBoolean();
|
||||
void WriteBoolean(bool value);
|
||||
|
||||
byte[] ReadUInt8Array(int length);
|
||||
void WriteUInt8Array(byte[] value);
|
||||
sbyte[] ReadInt8Array(int length);
|
||||
void WriteInt8Array(sbyte[] value);
|
||||
|
||||
ushort[] ReadUInt16Array(int length);
|
||||
void WriteUInt16Array(ushort[] value);
|
||||
short[] ReadInt16Array(int length);
|
||||
void WriteInt16Array(short[] value);
|
||||
|
||||
uint[] ReadUInt32Array(int length);
|
||||
void WriteUInt32Array(uint[] value);
|
||||
int[] ReadInt32Array(int length);
|
||||
void WriteInt32Array(int[] value);
|
||||
|
||||
ulong[] ReadUInt64Array(int length);
|
||||
void WriteUInt64Array(ulong[] value);
|
||||
long[] ReadInt64Array(int length);
|
||||
void WriteInt64Array(long[] value);
|
||||
}
|
||||
}
|
11
TrueCraft.API/Networking/IPacket.cs
Normal file
11
TrueCraft.API/Networking/IPacket.cs
Normal file
@ -0,0 +1,11 @@
|
||||
using System;
|
||||
|
||||
namespace TrueCraft.API.Networking
|
||||
{
|
||||
public interface IPacket
|
||||
{
|
||||
byte ID { get; }
|
||||
void ReadPacket(IMinecraftStream stream);
|
||||
void WritePacket(IMinecraftStream stream);
|
||||
}
|
||||
}
|
16
TrueCraft.API/Networking/IPacketReader.cs
Normal file
16
TrueCraft.API/Networking/IPacketReader.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace TrueCraft.API.Networking
|
||||
{
|
||||
public interface IPacketReader
|
||||
{
|
||||
int ProtocolVersion { get; }
|
||||
|
||||
ConcurrentDictionary<object, IPacketSegmentProcessor> Processors { get; }
|
||||
void RegisterPacketType<T>(bool clientbound = true, bool serverbound = true) where T : IPacket;
|
||||
IEnumerable<IPacket> ReadPackets(object key, byte[] buffer, int offset, int length, bool serverbound = true);
|
||||
void WritePacket(IMinecraftStream stream, IPacket packet);
|
||||
}
|
||||
}
|
12
TrueCraft.API/Networking/IPacketSegmentProcessor.cs
Normal file
12
TrueCraft.API/Networking/IPacketSegmentProcessor.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace TrueCraft.API.Networking
|
||||
{
|
||||
public interface IPacketSegmentProcessor
|
||||
{
|
||||
bool ProcessNextSegment(byte[] nextSegment, int offset, int len, out IPacket packet);
|
||||
}
|
||||
}
|
93
TrueCraft.API/Networking/IRemoteClient.cs
Normal file
93
TrueCraft.API/Networking/IRemoteClient.cs
Normal file
@ -0,0 +1,93 @@
|
||||
using System;
|
||||
using TrueCraft.API.World;
|
||||
using TrueCraft.API.Entities;
|
||||
using TrueCraft.API.Windows;
|
||||
using TrueCraft.API.Server;
|
||||
|
||||
namespace TrueCraft.API.Networking
|
||||
{
|
||||
public interface IRemoteClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Minecraft stream used to communicate with this client.
|
||||
/// </summary>
|
||||
IMinecraftStream MinecraftStream { get; }
|
||||
/// <summary>
|
||||
/// Returns true if this client has data pending in the network stream.
|
||||
/// </summary>
|
||||
bool DataAvailable { get; }
|
||||
/// <summary>
|
||||
/// The world this client is present in.
|
||||
/// </summary>
|
||||
IWorld World { get; }
|
||||
/// <summary>
|
||||
/// The entity associated with this client.
|
||||
/// </summary>
|
||||
IEntity Entity { get; }
|
||||
/// <summary>
|
||||
/// This client's inventory.
|
||||
/// </summary>
|
||||
IWindow Inventory { get; }
|
||||
/// <summary>
|
||||
/// The username of the connected client. May be null if not yet ascertained.
|
||||
/// </summary>
|
||||
string Username { get; }
|
||||
/// <summary>
|
||||
/// The slot index this user has selected in their hotbar.
|
||||
/// </summary>
|
||||
short SelectedSlot { get; }
|
||||
/// <summary>
|
||||
/// The item stack at the slot the user has selected in their hotbar.
|
||||
/// </summary>
|
||||
ItemStack SelectedItem { get; }
|
||||
/// <summary>
|
||||
/// The server this user is playing on.
|
||||
/// </summary>
|
||||
IMultiplayerServer Server { get; }
|
||||
/// <summary>
|
||||
/// If true, this client will be sent logging information as chat messages.
|
||||
/// </summary>
|
||||
bool EnableLogging { get; set; }
|
||||
/// <summary>
|
||||
/// The time the user is expected to complete the active digging operation,
|
||||
/// depending on what kind of block they are mining and what tool they're using
|
||||
/// to do it with.
|
||||
/// </summary>
|
||||
DateTime ExpectedDigComplete { get; set; }
|
||||
/// <summary>
|
||||
/// True if this client has been disconnected. You should cease sending packets and
|
||||
/// so on, this client is just waiting to be reaped.
|
||||
/// </summary>
|
||||
bool Disconnected { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Loads player data from disk for this client.
|
||||
/// </summary>
|
||||
bool Load();
|
||||
/// <summary>
|
||||
/// Saves player data to disk for this client.
|
||||
/// </summary>
|
||||
void Save();
|
||||
/// <summary>
|
||||
/// Queues a packet to be sent to this client.
|
||||
/// </summary>
|
||||
void QueuePacket(IPacket packet);
|
||||
/// <summary>
|
||||
/// Disconnects this client from the server.
|
||||
/// </summary>
|
||||
void Disconnect();
|
||||
/// <summary>
|
||||
/// Sends a chat message to this client.
|
||||
/// </summary>
|
||||
void SendMessage(string message);
|
||||
/// <summary>
|
||||
/// If logging is enabled, sends your message to the client as chat.
|
||||
/// </summary>
|
||||
void Log(string message, params object[] parameters);
|
||||
/// <summary>
|
||||
/// Opens a window on the client. This sends the appropriate packets and tracks
|
||||
/// this window as the currently open window.
|
||||
/// </summary>
|
||||
void OpenWindow(IWindow window);
|
||||
}
|
||||
}
|
82
TrueCraft.API/NibbleSlice.cs
Normal file
82
TrueCraft.API/NibbleSlice.cs
Normal file
@ -0,0 +1,82 @@
|
||||
using fNbt;
|
||||
using fNbt.Serialization;
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace TrueCraft.API
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a slice of an array of 4-bit values.
|
||||
/// </summary>
|
||||
public class NibbleSlice : INbtSerializable
|
||||
{
|
||||
/// <summary>
|
||||
/// The data in the nibble array. Each byte contains
|
||||
/// two nibbles, stored in big-endian.
|
||||
/// </summary>
|
||||
public byte[] Data { get; private set; }
|
||||
public int Offset { get; private set; }
|
||||
public int Length { get; private set; }
|
||||
|
||||
public NibbleSlice(byte[] data, int offset, int length)
|
||||
{
|
||||
Data = data;
|
||||
Offset = offset;
|
||||
Length = length;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a nibble at the given index.
|
||||
/// </summary>
|
||||
[NbtIgnore]
|
||||
public byte this[int index]
|
||||
{
|
||||
get { return (byte)(Data[Offset + index / 2] >> (index % 2 * 4) & 0xF); }
|
||||
set
|
||||
{
|
||||
value &= 0xF;
|
||||
Data[Offset + index / 2] &= (byte)(~(0xF << (index % 2 * 4)));
|
||||
Data[Offset + index / 2] |= (byte)(value << (index % 2 * 4));
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] ToArray()
|
||||
{
|
||||
byte[] array = new byte[Length];
|
||||
Buffer.BlockCopy(Data, Offset, array, 0, Length);
|
||||
return array;
|
||||
}
|
||||
|
||||
public NbtTag Serialize(string tagName)
|
||||
{
|
||||
return new NbtByteArray(tagName, ToArray());
|
||||
}
|
||||
|
||||
public void Deserialize(NbtTag value)
|
||||
{
|
||||
Length = value.ByteArrayValue.Length;
|
||||
Buffer.BlockCopy(value.ByteArrayValue, 0,
|
||||
Data, Offset, Length);
|
||||
}
|
||||
}
|
||||
|
||||
public class ReadOnlyNibbleArray
|
||||
{
|
||||
private NibbleSlice NibbleArray { get; set; }
|
||||
|
||||
public ReadOnlyNibbleArray(NibbleSlice array)
|
||||
{
|
||||
NibbleArray = array;
|
||||
}
|
||||
|
||||
public byte this[int index]
|
||||
{
|
||||
get { return NibbleArray[index]; }
|
||||
}
|
||||
|
||||
public ReadOnlyCollection<byte> Data
|
||||
{
|
||||
get { return Array.AsReadOnly(NibbleArray.Data); }
|
||||
}
|
||||
}
|
||||
}
|
43
TrueCraft.API/OreTypes.cs
Normal file
43
TrueCraft.API/OreTypes.cs
Normal file
@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace TrueCraft.API
|
||||
{
|
||||
/// <summary>
|
||||
/// Enumerates the different types of ore in TrueCraft.
|
||||
/// </summary>
|
||||
public enum OreTypes
|
||||
{
|
||||
/// <summary>
|
||||
/// Coal ore.
|
||||
/// </summary>
|
||||
Coal,
|
||||
|
||||
/// <summary>
|
||||
/// Lapis lazuli ore.
|
||||
/// </summary>
|
||||
Lapiz,
|
||||
|
||||
/// <summary>
|
||||
/// Iron ore.
|
||||
/// </summary>
|
||||
Iron,
|
||||
|
||||
/// <summary>
|
||||
/// Gold ore.
|
||||
/// </summary>
|
||||
Gold,
|
||||
|
||||
/// <summary>
|
||||
/// Redstone ore.
|
||||
/// </summary>
|
||||
Redstone,
|
||||
|
||||
/// <summary>
|
||||
/// Diamond ore.
|
||||
/// </summary>
|
||||
Diamond
|
||||
}
|
||||
}
|
16
TrueCraft.API/PathResult.cs
Normal file
16
TrueCraft.API/PathResult.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace TrueCraft.API
|
||||
{
|
||||
public class PathResult
|
||||
{
|
||||
public PathResult()
|
||||
{
|
||||
Index = 0;
|
||||
}
|
||||
|
||||
public IList<Coordinates3D> Waypoints;
|
||||
public int Index;
|
||||
}
|
||||
}
|
15
TrueCraft.API/Physics/IAABBEntity.cs
Normal file
15
TrueCraft.API/Physics/IAABBEntity.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace TrueCraft.API.Physics
|
||||
{
|
||||
public interface IAABBEntity : IPhysicsEntity
|
||||
{
|
||||
BoundingBox BoundingBox { get; }
|
||||
Size Size { get; }
|
||||
|
||||
void TerrainCollision(Vector3 collisionPoint, Vector3 collisionDirection);
|
||||
}
|
||||
}
|
14
TrueCraft.API/Physics/IPhysicsEngine.cs
Normal file
14
TrueCraft.API/Physics/IPhysicsEngine.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using TrueCraft.API.Entities;
|
||||
using TrueCraft.API.World;
|
||||
|
||||
namespace TrueCraft.API.Physics
|
||||
{
|
||||
public interface IPhysicsEngine
|
||||
{
|
||||
IWorld World { get; set; }
|
||||
void AddEntity(IPhysicsEntity entity);
|
||||
void RemoveEntity(IPhysicsEntity entity);
|
||||
void Update(TimeSpan time);
|
||||
}
|
||||
}
|
28
TrueCraft.API/Physics/IPhysicsEntity.cs
Normal file
28
TrueCraft.API/Physics/IPhysicsEntity.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace TrueCraft.API.Physics
|
||||
{
|
||||
public interface IPhysicsEntity
|
||||
{
|
||||
Vector3 Position { get; set; }
|
||||
Vector3 Velocity { get; set; }
|
||||
/// <summary>
|
||||
/// Acceleration due to gravity in meters per second squared.
|
||||
/// </summary>
|
||||
float AccelerationDueToGravity { get; }
|
||||
/// <summary>
|
||||
/// Velocity *= (1 - Drag) each second
|
||||
/// </summary>
|
||||
float Drag { get; }
|
||||
/// <summary>
|
||||
/// Terminal velocity in meters per second.
|
||||
/// </summary>
|
||||
float TerminalVelocity { get; }
|
||||
|
||||
bool BeginUpdate();
|
||||
void EndUpdate(Vector3 newPosition);
|
||||
}
|
||||
}
|
48
TrueCraft.API/PlantSpecies.cs
Normal file
48
TrueCraft.API/PlantSpecies.cs
Normal file
@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace TrueCraft.API
|
||||
{
|
||||
/// <summary>
|
||||
/// Enumerates the different species of plants in TrueCraft.
|
||||
/// </summary>
|
||||
public enum PlantSpecies
|
||||
{
|
||||
/// <summary>
|
||||
/// Rose flower.
|
||||
/// </summary>
|
||||
Rose,
|
||||
|
||||
/// <summary>
|
||||
/// Dandelion flower.
|
||||
/// </summary>
|
||||
Dandelion,
|
||||
|
||||
/// <summary>
|
||||
/// Tall grass.
|
||||
/// </summary>
|
||||
TallGrass,
|
||||
|
||||
/// <summary>
|
||||
/// Fern.
|
||||
/// </summary>
|
||||
Fern,
|
||||
|
||||
/// <summary>
|
||||
/// Dead bush.
|
||||
/// </summary>
|
||||
Deadbush,
|
||||
|
||||
/// <summary>
|
||||
/// Cactus.
|
||||
/// </summary>
|
||||
Cactus,
|
||||
|
||||
/// <summary>
|
||||
/// Sugarcane.
|
||||
/// </summary>
|
||||
SugarCane,
|
||||
}
|
||||
}
|
27
TrueCraft.API/Properties/AssemblyInfo.cs
Normal file
27
TrueCraft.API/Properties/AssemblyInfo.cs
Normal file
@ -0,0 +1,27 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
// Information about this assembly is defined by the following attributes.
|
||||
// Change them to the values specific to your project.
|
||||
|
||||
[assembly: AssemblyTitle("TrueCraft.API")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("")]
|
||||
[assembly: AssemblyCopyright("sircmpwn")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
|
||||
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
|
||||
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
|
||||
|
||||
[assembly: AssemblyVersion("1.0.*")]
|
||||
|
||||
// The following attributes are used to specify the signing key for the assembly,
|
||||
// if desired. See the Mono documentation for more information about signing.
|
||||
|
||||
//[assembly: AssemblyDelaySign(false)]
|
||||
//[assembly: AssemblyKeyFile("")]
|
||||
|
204
TrueCraft.API/Ray.cs
Normal file
204
TrueCraft.API/Ray.cs
Normal file
@ -0,0 +1,204 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace TrueCraft.API
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a ray; a line with a start and direction, but no end.
|
||||
/// </summary>
|
||||
// Mostly taken from the MonoXna project, which is licensed under the MIT license
|
||||
public struct Ray : IEquatable<Ray>
|
||||
{
|
||||
#region Public Fields
|
||||
|
||||
/// <summary>
|
||||
/// The direction of the ray.
|
||||
/// </summary>
|
||||
public readonly Vector3 Direction;
|
||||
|
||||
/// <summary>
|
||||
/// The position of the ray (its origin).
|
||||
/// </summary>
|
||||
public readonly Vector3 Position;
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Public Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new ray from specified values.
|
||||
/// </summary>
|
||||
/// <param name="position">The position of the ray (its origin).</param>
|
||||
/// <param name="direction">The direction of the ray.</param>
|
||||
public Ray(Vector3 position, Vector3 direction)
|
||||
{
|
||||
this.Position = position;
|
||||
this.Direction = direction;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether this and another object are equal.
|
||||
/// </summary>
|
||||
/// <param name="obj">The other object.</param>
|
||||
/// <returns></returns>
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return (obj is Ray) && Equals((Ray)obj);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether this and another ray are equal.
|
||||
/// </summary>
|
||||
/// <param name="other">The other ray.</param>
|
||||
/// <returns></returns>
|
||||
public bool Equals(Ray other)
|
||||
{
|
||||
return Position.Equals(other.Position) && Direction.Equals(other.Direction);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the hash code for this ray.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return Position.GetHashCode() ^ Direction.GetHashCode();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the distance along the ray where it intersects the specified bounding box, if it intersects at all.
|
||||
/// </summary>
|
||||
public double? Intersects(BoundingBox box, out BlockFace face)
|
||||
{
|
||||
face = BlockFace.PositiveY;
|
||||
//first test if start in box
|
||||
if (Position.X >= box.Min.X
|
||||
&& Position.X <= box.Max.X
|
||||
&& Position.Y >= box.Min.Y
|
||||
&& Position.Y <= box.Max.Y
|
||||
&& Position.Z >= box.Min.Z
|
||||
&& Position.Z <= box.Max.Z)
|
||||
return 0.0f;// here we concidere cube is full and origine is in cube so intersect at origine
|
||||
|
||||
//Second we check each face
|
||||
Vector3 maxT = new Vector3(-1.0f);
|
||||
//Vector3 minT = new Vector3(-1.0f);
|
||||
//calcul intersection with each faces
|
||||
if (Direction.X != 0.0f)
|
||||
{
|
||||
if (Position.X < box.Min.X)
|
||||
maxT.X = (box.Min.X - Position.X) / Direction.X;
|
||||
else if (Position.X > box.Max.X)
|
||||
maxT.X = (box.Max.X - Position.X) / Direction.X;
|
||||
}
|
||||
|
||||
if (Direction.Y != 0.0f)
|
||||
{
|
||||
if (Position.Y < box.Min.Y)
|
||||
maxT.Y = (box.Min.Y - Position.Y) / Direction.Y;
|
||||
else if (Position.Y > box.Max.Y)
|
||||
maxT.Y = (box.Max.Y - Position.Y) / Direction.Y;
|
||||
}
|
||||
|
||||
if (Direction.Z != 0.0f)
|
||||
{
|
||||
if (Position.Z < box.Min.Z)
|
||||
maxT.Z = (box.Min.Z - Position.Z) / Direction.Z;
|
||||
else if (Position.Z > box.Max.Z)
|
||||
maxT.Z = (box.Max.Z - Position.Z) / Direction.Z;
|
||||
}
|
||||
|
||||
//get the maximum maxT
|
||||
if (maxT.X > maxT.Y && maxT.X > maxT.Z)
|
||||
{
|
||||
if (maxT.X < 0.0f)
|
||||
return null;// ray go on opposite of face
|
||||
//coordonate of hit point of face of cube
|
||||
double coord = Position.Z + maxT.X * Direction.Z;
|
||||
// if hit point coord ( intersect face with ray) is out of other plane coord it miss
|
||||
if (coord < box.Min.Z || coord > box.Max.Z)
|
||||
return null;
|
||||
coord = Position.Y + maxT.X * Direction.Y;
|
||||
if (coord < box.Min.Y || coord > box.Max.Y)
|
||||
return null;
|
||||
|
||||
if (Position.X < box.Min.X)
|
||||
face = BlockFace.NegativeX;
|
||||
else if (Position.X > box.Max.X)
|
||||
face = BlockFace.PositiveX;
|
||||
|
||||
return maxT.X;
|
||||
}
|
||||
if (maxT.Y > maxT.X && maxT.Y > maxT.Z)
|
||||
{
|
||||
if (maxT.Y < 0.0f)
|
||||
return null;// ray go on opposite of face
|
||||
//coordonate of hit point of face of cube
|
||||
double coord = Position.Z + maxT.Y * Direction.Z;
|
||||
// if hit point coord ( intersect face with ray) is out of other plane coord it miss
|
||||
if (coord < box.Min.Z || coord > box.Max.Z)
|
||||
return null;
|
||||
coord = Position.X + maxT.Y * Direction.X;
|
||||
if (coord < box.Min.X || coord > box.Max.X)
|
||||
return null;
|
||||
|
||||
if (Position.Y < box.Min.Y)
|
||||
face = BlockFace.NegativeY;
|
||||
else if (Position.Y > box.Max.Y)
|
||||
face = BlockFace.PositiveY;
|
||||
|
||||
return maxT.Y;
|
||||
}
|
||||
else //Z
|
||||
{
|
||||
if (maxT.Z < 0.0f)
|
||||
return null;// ray go on opposite of face
|
||||
//coordonate of hit point of face of cube
|
||||
double coord = Position.X + maxT.Z * Direction.X;
|
||||
// if hit point coord ( intersect face with ray) is out of other plane coord it miss
|
||||
if (coord < box.Min.X || coord > box.Max.X)
|
||||
return null;
|
||||
coord = Position.Y + maxT.Z * Direction.Y;
|
||||
if (coord < box.Min.Y || coord > box.Max.Y)
|
||||
return null;
|
||||
|
||||
if (Position.Z < box.Min.Z)
|
||||
face = BlockFace.NegativeZ;
|
||||
else if (Position.Z > box.Max.Z)
|
||||
face = BlockFace.PositiveZ;
|
||||
|
||||
return maxT.Z;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool operator !=(Ray a, Ray b)
|
||||
{
|
||||
return !a.Equals(b);
|
||||
}
|
||||
|
||||
public static bool operator ==(Ray a, Ray b)
|
||||
{
|
||||
return a.Equals(b);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a string representation of this ray.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Format("{{Position:{0} Direction:{1}}}", Position.ToString(), Direction.ToString());
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
22
TrueCraft.API/Server/ChatMessageEventArgs.cs
Normal file
22
TrueCraft.API/Server/ChatMessageEventArgs.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using TrueCraft.API.Networking;
|
||||
|
||||
namespace TrueCraft.API.Server
|
||||
{
|
||||
public class ChatMessageEventArgs : EventArgs
|
||||
{
|
||||
public ChatMessageEventArgs(IRemoteClient client, string message)
|
||||
{
|
||||
Client = client;
|
||||
Message = message;
|
||||
PreventDefault = false;
|
||||
}
|
||||
|
||||
public IRemoteClient Client { get; set; }
|
||||
public string Message { get; set; }
|
||||
/// <summary>
|
||||
/// If set to true, the server won't send the default message back to the client.
|
||||
/// </summary>
|
||||
public bool PreventDefault { get; set; }
|
||||
}
|
||||
}
|
17
TrueCraft.API/Server/ICommand.cs
Normal file
17
TrueCraft.API/Server/ICommand.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using TrueCraft.API.Networking;
|
||||
|
||||
namespace TrueCraft.API.Server
|
||||
{
|
||||
public interface ICommand
|
||||
{
|
||||
string Name { get; }
|
||||
string Description { get; }
|
||||
string[] Aliases { get; }
|
||||
void Handle(IRemoteClient client, string alias, string[] arguments);
|
||||
void Help(IRemoteClient client, string alias, string[] arguments);
|
||||
}
|
||||
}
|
14
TrueCraft.API/Server/ICommandManager.cs
Normal file
14
TrueCraft.API/Server/ICommandManager.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using TrueCraft.API.Networking;
|
||||
|
||||
namespace TrueCraft.API.Server
|
||||
{
|
||||
public interface ICommandManager
|
||||
{
|
||||
IList<ICommand> Commands { get; }
|
||||
void HandleCommand(IRemoteClient Client, string Alias, string[] Arguments);
|
||||
}
|
||||
}
|
25
TrueCraft.API/Server/IEntityManager.cs
Normal file
25
TrueCraft.API/Server/IEntityManager.cs
Normal file
@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using TrueCraft.API.Entities;
|
||||
using System.Collections.Generic;
|
||||
using TrueCraft.API.Networking;
|
||||
using TrueCraft.API.World;
|
||||
|
||||
namespace TrueCraft.API.Server
|
||||
{
|
||||
public interface IEntityManager
|
||||
{
|
||||
IWorld World { get; }
|
||||
TimeSpan TimeSinceLastUpdate { get; }
|
||||
/// <summary>
|
||||
/// Adds an entity to the world and assigns it an entity ID.
|
||||
/// </summary>
|
||||
void SpawnEntity(IEntity entity);
|
||||
void DespawnEntity(IEntity entity);
|
||||
void FlushDespawns();
|
||||
IEntity GetEntityByID(int id);
|
||||
void Update();
|
||||
void SendEntitiesToClient(IRemoteClient client);
|
||||
IList<IEntity> EntitiesInRange(Vector3 center, float radius);
|
||||
IList<IRemoteClient> ClientsForEntity(IEntity entity);
|
||||
}
|
||||
}
|
21
TrueCraft.API/Server/IEventScheduler.cs
Normal file
21
TrueCraft.API/Server/IEventScheduler.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace TrueCraft.API.Server
|
||||
{
|
||||
public interface IEventScheduler
|
||||
{
|
||||
HashSet<string> DisabledEvents { get; }
|
||||
/// <summary>
|
||||
/// Schedules an event to occur some time in the future.
|
||||
/// </summary>
|
||||
/// <param name="subject">The subject of the event. If the subject is disposed, the event is cancelled.</param>
|
||||
/// <param name="when">When to trigger the event.</param>
|
||||
/// <param name="action">The event to trigger.</param>
|
||||
void ScheduleEvent(string name, IEventSubject subject, TimeSpan when, Action<IMultiplayerServer> action);
|
||||
/// <summary>
|
||||
/// Triggers all pending scheduled events whose scheduled time has transpired.
|
||||
/// </summary>
|
||||
void Update();
|
||||
}
|
||||
}
|
50
TrueCraft.API/Server/IMultiplayerServer.cs
Normal file
50
TrueCraft.API/Server/IMultiplayerServer.cs
Normal file
@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using TrueCraft.API.Networking;
|
||||
using System.Net;
|
||||
using System.Collections.Generic;
|
||||
using TrueCraft.API.World;
|
||||
using TrueCraft.API.Logging;
|
||||
using TrueCraft.API.Logic;
|
||||
|
||||
namespace TrueCraft.API.Server
|
||||
{
|
||||
/// <summary>
|
||||
/// Called when the given packet comes in from a remote client. Return false to cease communication
|
||||
/// with that client.
|
||||
/// </summary>
|
||||
public delegate void PacketHandler(IPacket packet, IRemoteClient client, IMultiplayerServer server);
|
||||
|
||||
public interface IMultiplayerServer
|
||||
{
|
||||
event EventHandler<ChatMessageEventArgs> ChatMessageReceived;
|
||||
event EventHandler<PlayerJoinedQuitEventArgs> PlayerJoined;
|
||||
event EventHandler<PlayerJoinedQuitEventArgs> PlayerQuit;
|
||||
|
||||
IAccessConfiguration AccessConfiguration { get; }
|
||||
IPacketReader PacketReader { get; }
|
||||
IList<IRemoteClient> Clients { get; }
|
||||
IList<IWorld> Worlds { get; }
|
||||
IEventScheduler Scheduler { get; }
|
||||
IBlockRepository BlockRepository { get; }
|
||||
ICraftingRepository CraftingRepository { get; }
|
||||
IItemRepository ItemRepository { get; }
|
||||
IPEndPoint EndPoint { get; }
|
||||
bool BlockUpdatesEnabled { get; set; }
|
||||
bool EnableClientLogging { get; set; }
|
||||
|
||||
void Start(IPEndPoint endPoint);
|
||||
void Stop();
|
||||
void RegisterPacketHandler(byte packetId, PacketHandler handler);
|
||||
void AddWorld(IWorld world);
|
||||
void AddLogProvider(ILogProvider provider);
|
||||
void Log(LogCategory category, string text, params object[] parameters);
|
||||
IEntityManager GetEntityManagerForWorld(IWorld world);
|
||||
void SendMessage(string message, params object[] parameters);
|
||||
|
||||
void DisconnectClient(IRemoteClient client);
|
||||
|
||||
bool PlayerIsWhitelisted(string client);
|
||||
bool PlayerIsBlacklisted(string client);
|
||||
bool PlayerIsOp(string client);
|
||||
}
|
||||
}
|
15
TrueCraft.API/Server/PlayerJoinedQuitEventArgs.cs
Normal file
15
TrueCraft.API/Server/PlayerJoinedQuitEventArgs.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using TrueCraft.API.Networking;
|
||||
|
||||
namespace TrueCraft.API.Server
|
||||
{
|
||||
public class PlayerJoinedQuitEventArgs : EventArgs
|
||||
{
|
||||
public IRemoteClient Client { get; set; }
|
||||
|
||||
public PlayerJoinedQuitEventArgs(IRemoteClient client)
|
||||
{
|
||||
Client = client;
|
||||
}
|
||||
}
|
||||
}
|
461
TrueCraft.API/Size.cs
Normal file
461
TrueCraft.API/Size.cs
Normal file
@ -0,0 +1,461 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace TrueCraft.API
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents the size of an object in 3D space.
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Explicit)]
|
||||
public struct Size : IEquatable<Size>
|
||||
{
|
||||
/// <summary>
|
||||
/// The width component for the size.
|
||||
/// </summary>
|
||||
[FieldOffset(0)]
|
||||
public double Width;
|
||||
|
||||
/// <summary>
|
||||
/// The height component for the size.
|
||||
/// </summary>
|
||||
[FieldOffset(8)]
|
||||
public double Height;
|
||||
|
||||
/// <summary>
|
||||
/// The depth component for the size.
|
||||
/// </summary>
|
||||
[FieldOffset(16)]
|
||||
public double Depth;
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new size from a specified value.
|
||||
/// </summary>
|
||||
/// <param name="d">The value of the components for the size.</param>
|
||||
public Size(double d)
|
||||
{
|
||||
this.Width = this.Height = this.Depth = d;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new size from specified values.
|
||||
/// </summary>
|
||||
/// <param name="width">The width component for the size.</param>
|
||||
/// <param name="height">The height component for the size.</param>
|
||||
/// <param name="depth">The depth component for the size.</param>
|
||||
public Size(double width, double height, double depth)
|
||||
{
|
||||
this.Width = width;
|
||||
this.Height = height;
|
||||
this.Depth = depth;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new size by copying another.
|
||||
/// </summary>
|
||||
/// <param name="s">The size to copy.</param>
|
||||
public Size(Size s)
|
||||
{
|
||||
this.Width = s.Width;
|
||||
this.Height = s.Height;
|
||||
this.Depth = s.Depth;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Operators
|
||||
|
||||
public static Size operator /(Size a, double b)
|
||||
{
|
||||
return new Size(a.Width / b,
|
||||
a.Height / b,
|
||||
a.Depth / b);
|
||||
}
|
||||
|
||||
public static Size operator *(Size a, double b)
|
||||
{
|
||||
return new Size(a.Width * b,
|
||||
a.Height * b,
|
||||
a.Depth * b);
|
||||
}
|
||||
|
||||
public static Size operator %(Size a, double b)
|
||||
{
|
||||
return new Size(a.Width % b,
|
||||
a.Height % b,
|
||||
a.Depth % b);
|
||||
}
|
||||
|
||||
public static Size operator +(Size a, double b)
|
||||
{
|
||||
return new Size(a.Width + b,
|
||||
a.Height + b,
|
||||
a.Depth + b);
|
||||
}
|
||||
|
||||
public static Size operator -(Size a, double b)
|
||||
{
|
||||
return new Size(a.Width - b,
|
||||
a.Height - b,
|
||||
a.Depth - b);
|
||||
}
|
||||
|
||||
public static Size operator /(double a, Size b)
|
||||
{
|
||||
return new Size(a / b.Width,
|
||||
a / b.Height,
|
||||
a / b.Depth);
|
||||
}
|
||||
|
||||
public static Size operator *(double a, Size b)
|
||||
{
|
||||
return new Size(a * b.Width,
|
||||
a * b.Height,
|
||||
a * b.Depth);
|
||||
}
|
||||
|
||||
public static Size operator %(double a, Size b)
|
||||
{
|
||||
return new Size(a % b.Width,
|
||||
a % b.Height,
|
||||
a % b.Depth);
|
||||
}
|
||||
|
||||
public static Size operator +(double a, Size b)
|
||||
{
|
||||
return new Size(a + b.Width,
|
||||
a + b.Height,
|
||||
a + b.Depth);
|
||||
}
|
||||
|
||||
public static Size operator -(double a, Size b)
|
||||
{
|
||||
return new Size(a - b.Width,
|
||||
a - b.Height,
|
||||
a - b.Depth);
|
||||
}
|
||||
|
||||
public static Size operator /(Size a, Size b)
|
||||
{
|
||||
return new Size(a.Width / b.Width,
|
||||
a.Height / b.Height,
|
||||
a.Depth / b.Depth);
|
||||
}
|
||||
|
||||
public static Size operator *(Size a, Size b)
|
||||
{
|
||||
return new Size(a.Width * b.Width,
|
||||
a.Height * b.Height,
|
||||
a.Depth * b.Depth);
|
||||
}
|
||||
|
||||
public static Size operator %(Size a, Size b)
|
||||
{
|
||||
return new Size(a.Width % b.Width,
|
||||
a.Height % b.Height,
|
||||
a.Depth % b.Depth);
|
||||
}
|
||||
|
||||
public static Size operator +(Size a, Size b)
|
||||
{
|
||||
return new Size(a.Width + b.Width,
|
||||
a.Height + b.Height,
|
||||
a.Depth + b.Depth);
|
||||
}
|
||||
|
||||
public static Size operator -(Size a, Size b)
|
||||
{
|
||||
return new Size(a.Width - b.Width,
|
||||
a.Height - b.Height,
|
||||
a.Depth - b.Depth);
|
||||
}
|
||||
|
||||
public static Size operator -(Size a)
|
||||
{
|
||||
return new Size(-a.Width, -a.Height, -a.Depth);
|
||||
}
|
||||
|
||||
public static Size operator +(Size a)
|
||||
{
|
||||
return new Size(a);
|
||||
}
|
||||
|
||||
public static Size operator ++(Size a)
|
||||
{
|
||||
return new Size(a.Width++,
|
||||
a.Height++,
|
||||
a.Depth++);
|
||||
}
|
||||
|
||||
public static Size operator --(Size a)
|
||||
{
|
||||
return new Size(a.Width--,
|
||||
a.Height--,
|
||||
a.Depth--);
|
||||
}
|
||||
|
||||
public static bool operator ==(Size a, Size b)
|
||||
{
|
||||
return a.Equals(b);
|
||||
}
|
||||
|
||||
public static bool operator !=(Size a, Size b)
|
||||
{
|
||||
return !a.Equals(b);
|
||||
}
|
||||
|
||||
public static bool operator >(Size a, Size b)
|
||||
{
|
||||
return a.Volume > b.Volume;
|
||||
}
|
||||
|
||||
public static bool operator <(Size a, Size b)
|
||||
{
|
||||
return a.Volume < b.Volume;
|
||||
}
|
||||
|
||||
public static bool operator >=(Size a, Size b)
|
||||
{
|
||||
return a.Volume >= b.Volume;
|
||||
}
|
||||
|
||||
public static bool operator <=(Size a, Size b)
|
||||
{
|
||||
return a.Volume <= b.Volume;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Conversion operators
|
||||
|
||||
public static implicit operator Size(Vector3 v)
|
||||
{
|
||||
return new Size(v.X, v.Y, v.Z);
|
||||
}
|
||||
|
||||
public static implicit operator Size(Coordinates3D c)
|
||||
{
|
||||
return new Size(c.X, c.Y, c.Z);
|
||||
}
|
||||
|
||||
|
||||
public static explicit operator Size(Coordinates2D c)
|
||||
{
|
||||
return new Size(c.X, 0, c.Z);
|
||||
}
|
||||
|
||||
public static explicit operator Size(Tuple<double, double, double> t)
|
||||
{
|
||||
return new Size(t.Item1,
|
||||
t.Item2,
|
||||
t.Item3);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Math methods
|
||||
|
||||
/// <summary>
|
||||
/// Returns the component-wise minimum of two sizes.
|
||||
/// </summary>
|
||||
/// <param name="a">The first size.</param>
|
||||
/// <param name="b">The second size.</param>
|
||||
/// <returns></returns>
|
||||
public static Size Min(Size a, Size b)
|
||||
{
|
||||
return new Size(Math.Min(a.Width, b.Width),
|
||||
Math.Min(a.Height, b.Height),
|
||||
Math.Min(a.Depth, b.Depth));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the component-wise minimum of this and another size.
|
||||
/// </summary>
|
||||
/// <param name="b">The other size.</param>
|
||||
/// <returns></returns>
|
||||
public Size Min(Size b)
|
||||
{
|
||||
return new Size(Math.Min(this.Width, b.Width),
|
||||
Math.Min(this.Height, b.Height),
|
||||
Math.Min(this.Depth, b.Depth));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the component-wise maximum of two sizes.
|
||||
/// </summary>
|
||||
/// <param name="a">The first size.</param>
|
||||
/// <param name="b">The second size.</param>
|
||||
/// <returns></returns>
|
||||
public static Size Max(Size a, Size b)
|
||||
{
|
||||
return new Size(Math.Max(a.Width, b.Width),
|
||||
Math.Max(a.Height, b.Height),
|
||||
Math.Max(a.Depth, b.Depth));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the component-wise maximum of this and another size.
|
||||
/// </summary>
|
||||
/// <param name="b">The other size.</param>
|
||||
/// <returns></returns>
|
||||
public Size Max(Size b)
|
||||
{
|
||||
return new Size(Math.Max(this.Width, b.Width),
|
||||
Math.Max(this.Height, b.Height),
|
||||
Math.Max(this.Depth, b.Depth));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the negate of a size.
|
||||
/// </summary>
|
||||
/// <param name="a">The size to negate.</param>
|
||||
/// <returns></returns>
|
||||
public static Size Negate(Size a)
|
||||
{
|
||||
return -a;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the negate of this size.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Size Negate()
|
||||
{
|
||||
return -this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the component-wise absolute value of a size.
|
||||
/// </summary>
|
||||
/// <param name="a">The size.</param>
|
||||
/// <returns></returns>
|
||||
public static Size Abs(Size a)
|
||||
{
|
||||
return new Size(Math.Abs(a.Width),
|
||||
Math.Abs(a.Height),
|
||||
Math.Abs(a.Depth));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the component-wise absolute value of this size.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Size Abs()
|
||||
{
|
||||
return new Size(Math.Abs(this.Width),
|
||||
Math.Abs(this.Height),
|
||||
Math.Abs(this.Depth));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Gets the volume of a cuboid with the same dimensions as this size.
|
||||
/// </summary>
|
||||
public double Volume
|
||||
{
|
||||
get
|
||||
{
|
||||
return Width * Height * Depth;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the surface area of a cuboid with the same dimensions as this size.
|
||||
/// </summary>
|
||||
public double SurfaceArea
|
||||
{
|
||||
get
|
||||
{
|
||||
return 2 * (Width * Depth +
|
||||
Width * Height +
|
||||
Depth * Height);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the lateral surface area of a cuboid with the same dimensions as this size.
|
||||
/// </summary>
|
||||
public double LateralSurfaceArea
|
||||
{
|
||||
get
|
||||
{
|
||||
return 2 * (Width * Depth +
|
||||
Depth * Height);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the length of a diagonal line passing through a cuboid with the same dimensions as this size.
|
||||
/// </summary>
|
||||
public double Diagonal
|
||||
{
|
||||
get
|
||||
{
|
||||
return Math.Sqrt(Width * Width +
|
||||
Height * Height +
|
||||
Depth * Depth);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the average dimension for this size.
|
||||
/// </summary>
|
||||
public double Average
|
||||
{
|
||||
get
|
||||
{
|
||||
return (Width + Height + Depth) / 3;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether this size and another are equal.
|
||||
/// </summary>
|
||||
/// <param name="other">The other size.</param>
|
||||
/// <returns></returns>
|
||||
public bool Equals(Size other)
|
||||
{
|
||||
return this.Width == other.Width &&
|
||||
this.Height == other.Height &&
|
||||
this.Depth == other.Depth;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether this and another object are equal.
|
||||
/// </summary>
|
||||
/// <param name="obj">The other object.</param>
|
||||
/// <returns></returns>
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return obj is Size && Equals((Size)obj);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the hash code for this size.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public override int GetHashCode()
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
int hash = 449;
|
||||
hash = (hash * 457) ^ Width.GetHashCode();
|
||||
hash = (hash * 457) ^ Height.GetHashCode();
|
||||
hash = (hash * 457) ^ Depth.GetHashCode();
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a string representing the <see cref="Size"/> object in the format of <Width,Height,Depth>.
|
||||
/// </summary>
|
||||
/// <returns>A string representation of the object</returns>
|
||||
/// <inheritdoc cref="Object.ToString"/>
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Format("<{0},{1},{2}>", Width, Height, Depth);
|
||||
}
|
||||
}
|
||||
}
|
49
TrueCraft.API/ToolMaterial.cs
Normal file
49
TrueCraft.API/ToolMaterial.cs
Normal file
@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace TrueCraft.API
|
||||
{
|
||||
/// <summary>
|
||||
/// Enumerates the materials tools can be crafted from.
|
||||
/// </summary>
|
||||
[Flags]
|
||||
public enum ToolMaterial
|
||||
{
|
||||
/// <summary>
|
||||
/// The tool is crafted from no material (special).
|
||||
/// </summary>
|
||||
None = 1,
|
||||
|
||||
/// <summary>
|
||||
/// The tool is crafted from wood.
|
||||
/// </summary>
|
||||
Wood = 2,
|
||||
|
||||
/// <summary>
|
||||
/// The tool is crafted from cobblestone.
|
||||
/// </summary>
|
||||
Stone = 4,
|
||||
|
||||
/// <summary>
|
||||
/// The tool is crafted from iron ingots.
|
||||
/// </summary>
|
||||
Iron = 8,
|
||||
|
||||
/// <summary>
|
||||
/// The tool is crafted from gold ingots.
|
||||
/// </summary>
|
||||
Gold = 16,
|
||||
|
||||
/// <summary>
|
||||
/// The tool is crafted from diamonds.
|
||||
/// </summary>
|
||||
Diamond = 32,
|
||||
|
||||
/// <summary>
|
||||
/// Any tool material is valid in these circumstances.
|
||||
/// </summary>
|
||||
All = None | Wood | Stone | Iron | Gold | Diamond
|
||||
}
|
||||
}
|
16
TrueCraft.API/ToolType.cs
Normal file
16
TrueCraft.API/ToolType.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
|
||||
namespace TrueCraft.API
|
||||
{
|
||||
[Flags]
|
||||
public enum ToolType
|
||||
{
|
||||
None = 1,
|
||||
Pickaxe = 2,
|
||||
Axe = 4,
|
||||
Shovel = 8,
|
||||
Hoe = 16,
|
||||
Sword = 32,
|
||||
All = None | Pickaxe | Axe | Shovel | Hoe | Sword
|
||||
}
|
||||
}
|
65
TrueCraft.API/TreeSpecies.cs
Normal file
65
TrueCraft.API/TreeSpecies.cs
Normal file
@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace TrueCraft.API
|
||||
{
|
||||
/// <summary>
|
||||
/// Enumerates the different species of trees in TrueCraft.
|
||||
/// </summary>
|
||||
public enum TreeSpecies
|
||||
{
|
||||
/// <summary>
|
||||
/// An oak tree.
|
||||
/// </summary>
|
||||
Oak,
|
||||
|
||||
/// <summary>
|
||||
/// A birch tree.
|
||||
/// </summary>
|
||||
Birch,
|
||||
|
||||
/// <summary>
|
||||
/// A spruce tree.
|
||||
/// </summary>
|
||||
Spruce
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enumerates the different types of spruce trees in TrueCraft.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The following enums are mainly for generation purposes only.
|
||||
/// </remarks>
|
||||
public enum SpruceType
|
||||
{
|
||||
//TODO: Spruce types.
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enumerates the different types of oak trees in TrueCraft.
|
||||
/// </summary>
|
||||
public enum OakType
|
||||
{
|
||||
/// <summary>
|
||||
/// Uses layered circles for leaves
|
||||
/// </summary>
|
||||
Normal,
|
||||
|
||||
/// <summary>
|
||||
/// Uses a "blocky" sphere for leaves
|
||||
/// </summary>
|
||||
BalloonBlocky,
|
||||
|
||||
/// <summary>
|
||||
/// Uses a sphere for leaves
|
||||
/// </summary>
|
||||
Balloon,
|
||||
|
||||
/// <summary>
|
||||
/// Uses multiple spheres for leaves and random extra logs acting as branches
|
||||
/// </summary>
|
||||
Branched
|
||||
}
|
||||
}
|
147
TrueCraft.API/TrueCraft.API.csproj
Normal file
147
TrueCraft.API/TrueCraft.API.csproj
Normal file
@ -0,0 +1,147 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{FEE55B54-91B0-4325-A2C3-D576C0B7A81F}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<RootNamespace>TrueCraft.API</RootNamespace>
|
||||
<AssemblyName>TrueCraft.API</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug</OutputPath>
|
||||
<DefineConstants>DEBUG;</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<ConsolePause>false</ConsolePause>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>none</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release</OutputPath>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<ConsolePause>false</ConsolePause>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Optimized Debug|AnyCPU' ">
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Optimized Debug</OutputPath>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<DefineConstants>DEBUG;</DefineConstants>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="YamlDotNet">
|
||||
<HintPath>..\packages\YamlDotNet.3.9.0\lib\net35\YamlDotNet.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Configuration.cs" />
|
||||
<Compile Include="Coordinates3D.cs" />
|
||||
<Compile Include="ChatFormat.cs" />
|
||||
<Compile Include="IAccessConfiguration.cs" />
|
||||
<Compile Include="Networking\IPacketSegmentProcessor.cs" />
|
||||
<Compile Include="PlantSpecies.cs" />
|
||||
<Compile Include="OreTypes.cs" />
|
||||
<Compile Include="ToolMaterial.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Networking\IPacket.cs" />
|
||||
<Compile Include="Networking\IPacketReader.cs" />
|
||||
<Compile Include="Networking\IMinecraftStream.cs" />
|
||||
<Compile Include="GameMode.cs" />
|
||||
<Compile Include="Difficulty.cs" />
|
||||
<Compile Include="Dimension.cs" />
|
||||
<Compile Include="BoundingBox.cs" />
|
||||
<Compile Include="Coordinates2D.cs" />
|
||||
<Compile Include="ItemStack.cs" />
|
||||
<Compile Include="MetadataByte.cs" />
|
||||
<Compile Include="MetadataDictionary.cs" />
|
||||
<Compile Include="MetadataEntry.cs" />
|
||||
<Compile Include="MetadataFloat.cs" />
|
||||
<Compile Include="MetadataInt.cs" />
|
||||
<Compile Include="MetadataShort.cs" />
|
||||
<Compile Include="MetadataSlot.cs" />
|
||||
<Compile Include="MetadataString.cs" />
|
||||
<Compile Include="Ray.cs" />
|
||||
<Compile Include="Server\ICommand.cs" />
|
||||
<Compile Include="Server\ICommandManager.cs" />
|
||||
<Compile Include="Size.cs" />
|
||||
<Compile Include="TreeSpecies.cs" />
|
||||
<Compile Include="Vector3.cs" />
|
||||
<Compile Include="Server\IMultiplayerServer.cs" />
|
||||
<Compile Include="Networking\IRemoteClient.cs" />
|
||||
<Compile Include="World\IBiomeRepository.cs" />
|
||||
<Compile Include="World\IBiomeMap.cs" />
|
||||
<Compile Include="World\IBiomeProvider.cs" />
|
||||
<Compile Include="World\IChunkDecorator.cs" />
|
||||
<Compile Include="World\INoise.cs" />
|
||||
<Compile Include="World\IDecoration.cs" />
|
||||
<Compile Include="World\IWorld.cs" />
|
||||
<Compile Include="World\IChunk.cs" />
|
||||
<Compile Include="World\IChunkProvider.cs" />
|
||||
<Compile Include="NibbleSlice.cs" />
|
||||
<Compile Include="World\IRegion.cs" />
|
||||
<Compile Include="Biome.cs" />
|
||||
<Compile Include="Logging\LogCategory.cs" />
|
||||
<Compile Include="Logging\ILogProvider.cs" />
|
||||
<Compile Include="Server\IEventScheduler.cs" />
|
||||
<Compile Include="Server\IEntityManager.cs" />
|
||||
<Compile Include="Entities\IEntity.cs" />
|
||||
<Compile Include="World\BlockChangeEventArgs.cs" />
|
||||
<Compile Include="Windows\IWindow.cs" />
|
||||
<Compile Include="Windows\IWindowArea.cs" />
|
||||
<Compile Include="Windows\WindowChangeEventArgs.cs" />
|
||||
<Compile Include="Logic\IBlockProvider.cs" />
|
||||
<Compile Include="Logic\IItemProvider.cs" />
|
||||
<Compile Include="Logic\ICraftingRepository.cs" />
|
||||
<Compile Include="Logic\ICraftingRecipe.cs" />
|
||||
<Compile Include="ChatColor.cs" />
|
||||
<Compile Include="Server\ChatMessageEventArgs.cs" />
|
||||
<Compile Include="BlockFace.cs" />
|
||||
<Compile Include="Logic\IBlockRepository.cs" />
|
||||
<Compile Include="Entities\IBlockPhysicsProvider.cs" />
|
||||
<Compile Include="Logic\IItemRepository.cs" />
|
||||
<Compile Include="Logic\BlockDescriptor.cs" />
|
||||
<Compile Include="ArmorMaterial.cs" />
|
||||
<Compile Include="Server\PlayerJoinedQuitEventArgs.cs" />
|
||||
<Compile Include="ToolType.cs" />
|
||||
<Compile Include="World\ChunkLoadedEventArgs.cs" />
|
||||
<Compile Include="IEventSubject.cs" />
|
||||
<Compile Include="PathResult.cs" />
|
||||
<Compile Include="AI\IMobState.cs" />
|
||||
<Compile Include="Entities\IMobEntity.cs" />
|
||||
<Compile Include="AI\ISpawnRule.cs" />
|
||||
<Compile Include="Physics\IPhysicsEngine.cs" />
|
||||
<Compile Include="Physics\IPhysicsEntity.cs" />
|
||||
<Compile Include="Physics\IAABBEntity.cs" />
|
||||
<Compile Include="Logic\ISmeltableItem.cs" />
|
||||
<Compile Include="Logic\IBurnableItem.cs" />
|
||||
<Compile Include="Logic\SoundEffectClass.cs" />
|
||||
<Compile Include="Matrix.cs" />
|
||||
<Compile Include="BoundingCylinder.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<ItemGroup />
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\externals\fNbt\fNbt\fNbt.csproj">
|
||||
<Project>{4488498D-976D-4DA3-BF72-109531AF0488}</Project>
|
||||
<Name>fNbt</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="AI\" />
|
||||
<Folder Include="Physics\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
</Project>
|
477
TrueCraft.API/Vector3.cs
Normal file
477
TrueCraft.API/Vector3.cs
Normal file
@ -0,0 +1,477 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace TrueCraft.API
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents the location of an object in 3D space.
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Explicit)]
|
||||
public struct Vector3 : IEquatable<Vector3>
|
||||
{
|
||||
/// <summary>
|
||||
/// The X component of this vector.
|
||||
/// </summary>
|
||||
[FieldOffset(0)]
|
||||
public double X;
|
||||
|
||||
/// <summary>
|
||||
/// The Y component of this vector.
|
||||
/// </summary>
|
||||
[FieldOffset(8)]
|
||||
public double Y;
|
||||
|
||||
/// <summary>
|
||||
/// The Z component of this vector.
|
||||
/// </summary>
|
||||
[FieldOffset(16)]
|
||||
public double Z;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new vector from the specified value.
|
||||
/// </summary>
|
||||
/// <param name="value">The value for the components of the vector.</param>
|
||||
public Vector3(double value)
|
||||
{
|
||||
X = Y = Z = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new vector from the specified values.
|
||||
/// </summary>
|
||||
/// <param name="x">The X component of the vector.</param>
|
||||
/// <param name="y">The Y component of the vector.</param>
|
||||
/// <param name="z">The Z component of the vector.</param>
|
||||
public Vector3(double x, double y, double z)
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
Z = z;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new vector from copying another.
|
||||
/// </summary>
|
||||
/// <param name="v">The vector to copy.</param>
|
||||
public Vector3(Vector3 v)
|
||||
{
|
||||
X = v.X;
|
||||
Y = v.Y;
|
||||
Z = v.Z;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts this Vector3 to a string in the format <x,y,z>.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Format("<{0},{1},{2}>", X, Y, Z);
|
||||
}
|
||||
|
||||
#region Math
|
||||
|
||||
/// <summary>
|
||||
/// Truncates the decimal component of each part of this Vector3.
|
||||
/// </summary>
|
||||
public Vector3 Floor()
|
||||
{
|
||||
return new Vector3(Math.Floor(X), Math.Floor(Y), Math.Floor(Z));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Rounds the decimal component of each part of this Vector3.
|
||||
/// </summary>
|
||||
public Vector3 Round()
|
||||
{
|
||||
return new Vector3(Math.Round(X), Math.Round(Y), Math.Round(Z));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clamps the vector to within the specified value.
|
||||
/// </summary>
|
||||
/// <param name="value">Value.</param>
|
||||
public void Clamp(double value)
|
||||
{
|
||||
if (Math.Abs(X) > value)
|
||||
X = value * (X < 0 ? -1 : 1);
|
||||
if (Math.Abs(Y) > value)
|
||||
Y = value * (Y < 0 ? -1 : 1);
|
||||
if (Math.Abs(Z) > value)
|
||||
Z = value * (Z < 0 ? -1 : 1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the distance between two Vector3 objects.
|
||||
/// </summary>
|
||||
public double DistanceTo(Vector3 other)
|
||||
{
|
||||
return Math.Sqrt(Square(other.X - X) +
|
||||
Square(other.Y - Y) +
|
||||
Square(other.Z - Z));
|
||||
}
|
||||
|
||||
public Vector3 Transform(Matrix matrix)
|
||||
{
|
||||
var x = (X * matrix.M11) + (Y * matrix.M21) + (Z * matrix.M31) + matrix.M41;
|
||||
var y = (X * matrix.M12) + (Y * matrix.M22) + (Z * matrix.M32) + matrix.M42;
|
||||
var z = (X * matrix.M13) + (Y * matrix.M23) + (Z * matrix.M33) + matrix.M43;
|
||||
return new Vector3(x, y, z);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the square of a num.
|
||||
/// </summary>
|
||||
private double Square(double num)
|
||||
{
|
||||
return num * num;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finds the distance of this vector from Vector3.Zero
|
||||
/// </summary>
|
||||
public double Distance
|
||||
{
|
||||
get
|
||||
{
|
||||
return DistanceTo(Zero);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the component-wise minumum of two vectors.
|
||||
/// </summary>
|
||||
/// <param name="value1">The first vector.</param>
|
||||
/// <param name="value2">The second vector.</param>
|
||||
/// <returns></returns>
|
||||
public static Vector3 Min(Vector3 value1, Vector3 value2)
|
||||
{
|
||||
return new Vector3(
|
||||
Math.Min(value1.X, value2.X),
|
||||
Math.Min(value1.Y, value2.Y),
|
||||
Math.Min(value1.Z, value2.Z)
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the component-wise maximum of two vectors.
|
||||
/// </summary>
|
||||
/// <param name="value1">The first vector.</param>
|
||||
/// <param name="value2">The second vector.</param>
|
||||
/// <returns></returns>
|
||||
public static Vector3 Max(Vector3 value1, Vector3 value2)
|
||||
{
|
||||
return new Vector3(
|
||||
Math.Max(value1.X, value2.X),
|
||||
Math.Max(value1.Y, value2.Y),
|
||||
Math.Max(value1.Z, value2.Z)
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the dot product between two vectors.
|
||||
/// </summary>
|
||||
public static double Dot(Vector3 value1, Vector3 value2)
|
||||
{
|
||||
return value1.X * value2.X + value1.Y * value2.Y + value1.Z * value2.Z;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Computes the cross product of two vectors.
|
||||
/// </summary>
|
||||
/// <param name="vector1">The first vector.</param>
|
||||
/// <param name="vector2">The second vector.</param>
|
||||
/// <returns>The cross product of two vectors.</returns>
|
||||
public static Vector3 Cross(Vector3 vector1, Vector3 vector2)
|
||||
{
|
||||
Cross(ref vector1, ref vector2, out vector1);
|
||||
return vector1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Computes the cross product of two vectors.
|
||||
/// </summary>
|
||||
/// <param name="vector1">The first vector.</param>
|
||||
/// <param name="vector2">The second vector.</param>
|
||||
/// <param name="result">The cross product of two vectors as an output parameter.</param>
|
||||
public static void Cross(ref Vector3 vector1, ref Vector3 vector2, out Vector3 result)
|
||||
{
|
||||
var x = vector1.Y * vector2.Z - vector2.Y * vector1.Z;
|
||||
var y = -(vector1.X * vector2.Z - vector2.X * vector1.Z);
|
||||
var z = vector1.X * vector2.Y - vector2.X * vector1.Y;
|
||||
result.X = x;
|
||||
result.Y = y;
|
||||
result.Z = z;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Operators
|
||||
|
||||
public static bool operator !=(Vector3 a, Vector3 b)
|
||||
{
|
||||
return !a.Equals(b);
|
||||
}
|
||||
|
||||
public static bool operator ==(Vector3 a, Vector3 b)
|
||||
{
|
||||
return a.Equals(b);
|
||||
}
|
||||
|
||||
public static Vector3 operator +(Vector3 a, Vector3 b)
|
||||
{
|
||||
return new Vector3(
|
||||
a.X + b.X,
|
||||
a.Y + b.Y,
|
||||
a.Z + b.Z);
|
||||
}
|
||||
|
||||
public static Vector3 operator -(Vector3 a, Vector3 b)
|
||||
{
|
||||
return new Vector3(
|
||||
a.X - b.X,
|
||||
a.Y - b.Y,
|
||||
a.Z - b.Z);
|
||||
}
|
||||
|
||||
public static Vector3 operator +(Vector3 a, Size b)
|
||||
{
|
||||
return new Vector3(
|
||||
a.X + b.Width,
|
||||
a.Y + b.Height,
|
||||
a.Z + b.Depth);
|
||||
}
|
||||
|
||||
public static Vector3 operator -(Vector3 a, Size b)
|
||||
{
|
||||
return new Vector3(
|
||||
a.X - b.Width,
|
||||
a.Y - b.Height,
|
||||
a.Z - b.Depth);
|
||||
}
|
||||
|
||||
public static Vector3 operator -(Vector3 a)
|
||||
{
|
||||
return new Vector3(
|
||||
-a.X,
|
||||
-a.Y,
|
||||
-a.Z);
|
||||
}
|
||||
|
||||
public static Vector3 operator *(Vector3 a, Vector3 b)
|
||||
{
|
||||
return new Vector3(
|
||||
a.X * b.X,
|
||||
a.Y * b.Y,
|
||||
a.Z * b.Z);
|
||||
}
|
||||
|
||||
public static Vector3 operator /(Vector3 a, Vector3 b)
|
||||
{
|
||||
return new Vector3(
|
||||
a.X / b.X,
|
||||
a.Y / b.Y,
|
||||
a.Z / b.Z);
|
||||
}
|
||||
|
||||
public static Vector3 operator %(Vector3 a, Vector3 b)
|
||||
{
|
||||
return new Vector3(a.X % b.X, a.Y % b.Y, a.Z % b.Z);
|
||||
}
|
||||
|
||||
public static Vector3 operator +(Vector3 a, double b)
|
||||
{
|
||||
return new Vector3(
|
||||
a.X + b,
|
||||
a.Y + b,
|
||||
a.Z + b);
|
||||
}
|
||||
|
||||
public static Vector3 operator -(Vector3 a, double b)
|
||||
{
|
||||
return new Vector3(
|
||||
a.X - b,
|
||||
a.Y - b,
|
||||
a.Z - b);
|
||||
}
|
||||
|
||||
public static Vector3 operator *(Vector3 a, double b)
|
||||
{
|
||||
return new Vector3(
|
||||
a.X * b,
|
||||
a.Y * b,
|
||||
a.Z * b);
|
||||
}
|
||||
|
||||
public static Vector3 operator /(Vector3 a, double b)
|
||||
{
|
||||
return new Vector3(
|
||||
a.X / b,
|
||||
a.Y / b,
|
||||
a.Z / b);
|
||||
}
|
||||
|
||||
public static Vector3 operator %(Vector3 a, double b)
|
||||
{
|
||||
return new Vector3(a.X % b, a.Y % b, a.Y % b);
|
||||
}
|
||||
|
||||
public static Vector3 operator +(double a, Vector3 b)
|
||||
{
|
||||
return new Vector3(
|
||||
a + b.X,
|
||||
a + b.Y,
|
||||
a + b.Z);
|
||||
}
|
||||
|
||||
public static Vector3 operator -(double a, Vector3 b)
|
||||
{
|
||||
return new Vector3(
|
||||
a - b.X,
|
||||
a - b.Y,
|
||||
a - b.Z);
|
||||
}
|
||||
|
||||
public static Vector3 operator *(double a, Vector3 b)
|
||||
{
|
||||
return new Vector3(
|
||||
a * b.X,
|
||||
a * b.Y,
|
||||
a * b.Z);
|
||||
}
|
||||
|
||||
public static Vector3 operator /(double a, Vector3 b)
|
||||
{
|
||||
return new Vector3(
|
||||
a / b.X,
|
||||
a / b.Y,
|
||||
a / b.Z);
|
||||
}
|
||||
|
||||
public static Vector3 operator %(double a, Vector3 b)
|
||||
{
|
||||
return new Vector3(a % b.X, a % b.Y, a % b.Y);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Conversion operators
|
||||
|
||||
public static implicit operator Vector3(Coordinates3D a)
|
||||
{
|
||||
return new Vector3(a.X, a.Y, a.Z);
|
||||
}
|
||||
|
||||
public static explicit operator Vector3(Coordinates2D c)
|
||||
{
|
||||
return new Vector3(c.X, 0, c.Z);
|
||||
}
|
||||
|
||||
public static implicit operator Vector3(Size s)
|
||||
{
|
||||
return new Vector3(s.Width, s.Height, s.Depth);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Constants
|
||||
|
||||
/// <summary>
|
||||
/// A vector with its components set to 0.0.
|
||||
/// </summary>
|
||||
public static readonly Vector3 Zero = new Vector3(0);
|
||||
|
||||
/// <summary>
|
||||
/// A vector with its components set to 1.0.
|
||||
/// </summary>
|
||||
public static readonly Vector3 One = new Vector3(1);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A vector that points upward.
|
||||
/// </summary>
|
||||
public static readonly Vector3 Up = new Vector3(0, 1, 0);
|
||||
|
||||
/// <summary>
|
||||
/// A vector that points downward.
|
||||
/// </summary>
|
||||
public static readonly Vector3 Down = new Vector3(0, -1, 0);
|
||||
|
||||
/// <summary>
|
||||
/// A vector that points to the left.
|
||||
/// </summary>
|
||||
public static readonly Vector3 Left = new Vector3(-1, 0, 0);
|
||||
|
||||
/// <summary>
|
||||
/// A vector that points to the right.
|
||||
/// </summary>
|
||||
public static readonly Vector3 Right = new Vector3(1, 0, 0);
|
||||
|
||||
/// <summary>
|
||||
/// A vector that points backward.
|
||||
/// </summary>
|
||||
public static readonly Vector3 Backwards = new Vector3(0, 0, -1);
|
||||
|
||||
/// <summary>
|
||||
/// A vector that points forward.
|
||||
/// </summary>
|
||||
public static readonly Vector3 Forwards = new Vector3(0, 0, 1);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A vector that points to the east.
|
||||
/// </summary>
|
||||
public static readonly Vector3 East = new Vector3(1, 0, 0);
|
||||
|
||||
/// <summary>
|
||||
/// A vector that points to the west.
|
||||
/// </summary>
|
||||
public static readonly Vector3 West = new Vector3(-1, 0, 0);
|
||||
|
||||
/// <summary>
|
||||
/// A vector that points to the north.
|
||||
/// </summary>
|
||||
public static readonly Vector3 North = new Vector3(0, 0, -1);
|
||||
|
||||
/// <summary>
|
||||
/// A vector that points to the south.
|
||||
/// </summary>
|
||||
public static readonly Vector3 South = new Vector3(0, 0, 1);
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether this and another vector are equal.
|
||||
/// </summary>
|
||||
/// <param name="other">The other vector.</param>
|
||||
/// <returns></returns>
|
||||
public bool Equals(Vector3 other)
|
||||
{
|
||||
return other.X.Equals(X) && other.Y.Equals(Y) && other.Z.Equals(Z);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether this and another object are equal.
|
||||
/// </summary>
|
||||
/// <param name="obj">The other object.</param>
|
||||
/// <returns></returns>
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return obj is Vector3 && Equals((Vector3)obj);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the hash code for this vector.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public override int GetHashCode()
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
int result = X.GetHashCode();
|
||||
result = (result * 397) ^ Y.GetHashCode();
|
||||
result = (result * 397) ^ Z.GetHashCode();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
39
TrueCraft.API/Windows/IWindow.cs
Normal file
39
TrueCraft.API/Windows/IWindow.cs
Normal file
@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using TrueCraft.API.Networking;
|
||||
|
||||
namespace TrueCraft.API.Windows
|
||||
{
|
||||
public interface IWindow : IDisposable, IEventSubject
|
||||
{
|
||||
event EventHandler<WindowChangeEventArgs> WindowChange;
|
||||
|
||||
IRemoteClient Client { get; set; }
|
||||
IWindowArea[] WindowAreas { get; }
|
||||
sbyte ID { get; set; }
|
||||
string Name { get; }
|
||||
sbyte Type { get; }
|
||||
int Length { get; }
|
||||
int MinecraftWasWrittenByFuckingIdiotsLength { get; }
|
||||
ItemStack this[int index] { get; set; }
|
||||
bool Empty { get; }
|
||||
short[] ReadOnlySlots { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Call this to "shift+click" an item from one area to another.
|
||||
/// </summary>
|
||||
void MoveToAlternateArea(int index);
|
||||
/// <summary>
|
||||
/// Gets an array of all slots in this window. Suitable for sending to clients over the network.
|
||||
/// </summary>
|
||||
ItemStack[] GetSlots();
|
||||
void SetSlots(ItemStack[] slots);
|
||||
/// <summary>
|
||||
/// Adds the specified item stack to this window, merging with established slots as neccessary.
|
||||
/// </summary>
|
||||
bool PickUpStack(ItemStack slot);
|
||||
/// <summary>
|
||||
/// Copy the contents of this window back into an inventory window after changes have been made.
|
||||
/// </summary>
|
||||
void CopyToInventory(IWindow inventoryWindow);
|
||||
}
|
||||
}
|
20
TrueCraft.API/Windows/IWindowArea.cs
Normal file
20
TrueCraft.API/Windows/IWindowArea.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using System;
|
||||
|
||||
namespace TrueCraft.API.Windows
|
||||
{
|
||||
public interface IWindowArea : IDisposable
|
||||
{
|
||||
event EventHandler<WindowChangeEventArgs> WindowChange;
|
||||
|
||||
int StartIndex { get; set; }
|
||||
int Length { get; set; }
|
||||
int Width { get; }
|
||||
int Height { get; }
|
||||
ItemStack[] Items { get; set; }
|
||||
|
||||
ItemStack this[int index] { get; set; }
|
||||
|
||||
void CopyTo(IWindowArea area);
|
||||
int MoveOrMergeItem(int index, ItemStack item, IWindowArea from);
|
||||
}
|
||||
}
|
21
TrueCraft.API/Windows/WindowChangeEventArgs.cs
Normal file
21
TrueCraft.API/Windows/WindowChangeEventArgs.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace TrueCraft.API.Windows
|
||||
{
|
||||
public class WindowChangeEventArgs : EventArgs
|
||||
{
|
||||
public int SlotIndex { get; set; }
|
||||
public ItemStack Value { get; set; }
|
||||
public bool Handled { get; set; }
|
||||
|
||||
public WindowChangeEventArgs(int slotIndex, ItemStack value)
|
||||
{
|
||||
SlotIndex = slotIndex;
|
||||
Value = value;
|
||||
Handled = false;
|
||||
}
|
||||
}
|
||||
}
|
19
TrueCraft.API/World/BlockChangeEventArgs.cs
Normal file
19
TrueCraft.API/World/BlockChangeEventArgs.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using TrueCraft.API.Logic;
|
||||
|
||||
namespace TrueCraft.API.World
|
||||
{
|
||||
public class BlockChangeEventArgs : EventArgs
|
||||
{
|
||||
public BlockChangeEventArgs(Coordinates3D position, BlockDescriptor oldBlock, BlockDescriptor newBlock)
|
||||
{
|
||||
Position = position;
|
||||
OldBlock = oldBlock;
|
||||
NewBlock = newBlock;
|
||||
}
|
||||
|
||||
public Coordinates3D Position;
|
||||
public BlockDescriptor OldBlock;
|
||||
public BlockDescriptor NewBlock;
|
||||
}
|
||||
}
|
17
TrueCraft.API/World/ChunkLoadedEventArgs.cs
Normal file
17
TrueCraft.API/World/ChunkLoadedEventArgs.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
|
||||
namespace TrueCraft.API.World
|
||||
{
|
||||
public class ChunkLoadedEventArgs : EventArgs
|
||||
{
|
||||
public Coordinates2D Coordinates { get; set; }
|
||||
public IChunk Chunk { get; set; }
|
||||
|
||||
public ChunkLoadedEventArgs(IChunk chunk)
|
||||
{
|
||||
Chunk = chunk;
|
||||
Coordinates = chunk.Coordinates;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
29
TrueCraft.API/World/IBiomeMap.cs
Normal file
29
TrueCraft.API/World/IBiomeMap.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace TrueCraft.API.World
|
||||
{
|
||||
public class BiomeCell
|
||||
{
|
||||
public byte BiomeID;
|
||||
public Coordinates2D CellPoint;
|
||||
|
||||
public BiomeCell(byte biomeID, Coordinates2D cellPoint)
|
||||
{
|
||||
this.BiomeID = biomeID;
|
||||
this.CellPoint = cellPoint;
|
||||
}
|
||||
}
|
||||
|
||||
public interface IBiomeMap
|
||||
{
|
||||
IList<BiomeCell> BiomeCells { get; }
|
||||
void AddCell(BiomeCell cell);
|
||||
byte GetBiome(Coordinates2D location);
|
||||
byte GenerateBiome(int seed, IBiomeRepository biomes, Coordinates2D location, bool spawn);
|
||||
BiomeCell ClosestCell(Coordinates2D location);
|
||||
double ClosestCellPoint(Coordinates2D location);
|
||||
}
|
||||
}
|
26
TrueCraft.API/World/IBiomeProvider.cs
Normal file
26
TrueCraft.API/World/IBiomeProvider.cs
Normal file
@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using TrueCraft.API.Logic;
|
||||
|
||||
namespace TrueCraft.API.World
|
||||
{
|
||||
public interface IBiomeProvider
|
||||
{
|
||||
bool Spawn { get; }
|
||||
byte ID { get; }
|
||||
int Elevation { get; }
|
||||
double Temperature { get; }
|
||||
double Rainfall { get; }
|
||||
TreeSpecies[] Trees { get; }
|
||||
PlantSpecies[] Plants { get; }
|
||||
OreTypes[] Ores { get; }
|
||||
double TreeDensity { get; }
|
||||
byte WaterBlock { get; }
|
||||
byte SurfaceBlock { get; }
|
||||
byte FillerBlock { get; }
|
||||
int SurfaceDepth { get; }
|
||||
int FillerDepth { get; }
|
||||
}
|
||||
}
|
14
TrueCraft.API/World/IBiomeRepository.cs
Normal file
14
TrueCraft.API/World/IBiomeRepository.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace TrueCraft.API.World
|
||||
{
|
||||
public interface IBiomeRepository
|
||||
{
|
||||
IBiomeProvider GetBiome(byte id);
|
||||
IBiomeProvider GetBiome(double temperature, double rainfall, bool spawn);
|
||||
void RegisterBiomeProvider(IBiomeProvider provider);
|
||||
}
|
||||
}
|
38
TrueCraft.API/World/IChunk.cs
Normal file
38
TrueCraft.API/World/IChunk.cs
Normal file
@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using fNbt;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace TrueCraft.API.World
|
||||
{
|
||||
public interface IChunk : IEventSubject, IDisposable
|
||||
{
|
||||
int X { get; }
|
||||
int Z { get; }
|
||||
int MaxHeight { get; }
|
||||
Coordinates2D Coordinates { get; set; }
|
||||
bool IsModified { get; set; }
|
||||
bool LightPopulated { get; set; }
|
||||
int[] HeightMap { get; }
|
||||
byte[] Biomes { get; }
|
||||
DateTime LastAccessed { get; set; }
|
||||
byte[] Data { get; }
|
||||
bool TerrainPopulated { get; set; }
|
||||
Dictionary<Coordinates3D, NbtCompound> TileEntities { get; set; }
|
||||
NibbleSlice Metadata { get; }
|
||||
NibbleSlice BlockLight { get; }
|
||||
NibbleSlice SkyLight { get; }
|
||||
IRegion ParentRegion { get; set; }
|
||||
int GetHeight(byte x, byte z);
|
||||
void UpdateHeightMap();
|
||||
byte GetBlockID(Coordinates3D coordinates);
|
||||
byte GetMetadata(Coordinates3D coordinates);
|
||||
byte GetSkyLight(Coordinates3D coordinates);
|
||||
byte GetBlockLight(Coordinates3D coordinates);
|
||||
void SetBlockID(Coordinates3D coordinates, byte value);
|
||||
void SetMetadata(Coordinates3D coordinates, byte value);
|
||||
void SetSkyLight(Coordinates3D coordinates, byte value);
|
||||
void SetBlockLight(Coordinates3D coordinates, byte value);
|
||||
NbtCompound GetTileEntity(Coordinates3D coordinates);
|
||||
void SetTileEntity(Coordinates3D coordinates, NbtCompound value);
|
||||
}
|
||||
}
|
15
TrueCraft.API/World/IChunkDecorator.cs
Normal file
15
TrueCraft.API/World/IChunkDecorator.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace TrueCraft.API.World
|
||||
{
|
||||
/// <summary>
|
||||
/// Used to decorate chunks with "decorations" such as trees, flowers, ores, etc.
|
||||
/// </summary>
|
||||
public interface IChunkDecorator
|
||||
{
|
||||
void Decorate(IWorld world, IChunk chunk, IBiomeRepository biomes);
|
||||
}
|
||||
}
|
16
TrueCraft.API/World/IChunkProvider.cs
Normal file
16
TrueCraft.API/World/IChunkProvider.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace TrueCraft.API.World
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides new chunks to worlds. Generally speaking this is a terrain generator.
|
||||
/// </summary>
|
||||
public interface IChunkProvider
|
||||
{
|
||||
IList<IChunkDecorator> ChunkDecorators { get; }
|
||||
IChunk GenerateChunk(IWorld world, Coordinates2D coordinates);
|
||||
Coordinates3D GetSpawn(IWorld world);
|
||||
void Initialize(IWorld world);
|
||||
}
|
||||
}
|
13
TrueCraft.API/World/IDecoration.cs
Normal file
13
TrueCraft.API/World/IDecoration.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace TrueCraft.API.World
|
||||
{
|
||||
public interface IDecoration
|
||||
{
|
||||
bool ValidLocation(Coordinates3D location);
|
||||
bool GenerateAt(IWorld world, IChunk chunk, Coordinates3D location);
|
||||
}
|
||||
}
|
13
TrueCraft.API/World/INoise.cs
Normal file
13
TrueCraft.API/World/INoise.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace TrueCraft.API.World
|
||||
{
|
||||
public interface INoise
|
||||
{
|
||||
double Value2D(double x, double y);
|
||||
double Value3D(double x, double y, double z);
|
||||
}
|
||||
}
|
19
TrueCraft.API/World/IRegion.cs
Normal file
19
TrueCraft.API/World/IRegion.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace TrueCraft.API.World
|
||||
{
|
||||
public interface IRegion : IDisposable
|
||||
{
|
||||
IDictionary<Coordinates2D, IChunk> Chunks { get; }
|
||||
Coordinates2D Position { get; }
|
||||
|
||||
IChunk GetChunk(Coordinates2D position, bool generate = true);
|
||||
/// <summary>
|
||||
/// Marks the chunk for saving in the next Save().
|
||||
/// </summary>
|
||||
void DamageChunk(Coordinates2D position);
|
||||
void UnloadChunk(Coordinates2D position);
|
||||
void Save(string path);
|
||||
}
|
||||
}
|
45
TrueCraft.API/World/IWorld.cs
Normal file
45
TrueCraft.API/World/IWorld.cs
Normal file
@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using TrueCraft.API.Logic;
|
||||
using fNbt;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace TrueCraft.API.World
|
||||
{
|
||||
// TODO: Entities
|
||||
/// <summary>
|
||||
/// An in-game world composed of chunks and blocks.
|
||||
/// </summary>
|
||||
public interface IWorld : IEnumerable<IChunk>
|
||||
{
|
||||
string Name { get; set; }
|
||||
IBlockRepository BlockRepository { get; set; }
|
||||
int Seed { get; set; }
|
||||
IBiomeMap BiomeDiagram { get; set; }
|
||||
IChunkProvider ChunkProvider { get; set; }
|
||||
Coordinates3D SpawnPoint { get; set; }
|
||||
long Time { get; set; }
|
||||
|
||||
event EventHandler<BlockChangeEventArgs> BlockChanged;
|
||||
event EventHandler<ChunkLoadedEventArgs> ChunkGenerated;
|
||||
event EventHandler<ChunkLoadedEventArgs> ChunkLoaded;
|
||||
|
||||
IChunk GetChunk(Coordinates2D coordinates, bool generate = true);
|
||||
IChunk FindChunk(Coordinates3D coordinates, bool generate = true);
|
||||
byte GetBlockID(Coordinates3D coordinates);
|
||||
byte GetMetadata(Coordinates3D coordinates);
|
||||
byte GetBlockLight(Coordinates3D coordinates);
|
||||
byte GetSkyLight(Coordinates3D coordinates);
|
||||
Coordinates3D FindBlockPosition(Coordinates3D coordinates, out IChunk chunk, bool generate = true);
|
||||
NbtCompound GetTileEntity(Coordinates3D coordinates);
|
||||
BlockDescriptor GetBlockData(Coordinates3D coordinates);
|
||||
void SetBlockData(Coordinates3D coordinates, BlockDescriptor block);
|
||||
void SetBlockID(Coordinates3D coordinates, byte value);
|
||||
void SetMetadata(Coordinates3D coordinates, byte value);
|
||||
void SetSkyLight(Coordinates3D coordinates, byte value);
|
||||
void SetBlockLight(Coordinates3D coordinates, byte value);
|
||||
void SetTileEntity(Coordinates3D coordinates, NbtCompound value);
|
||||
bool IsValidPosition(Coordinates3D position);
|
||||
void Save();
|
||||
void Save(string path);
|
||||
}
|
||||
}
|
4
TrueCraft.API/packages.config
Normal file
4
TrueCraft.API/packages.config
Normal file
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="YamlDotNet" version="3.9.0" targetFramework="net45" />
|
||||
</packages>
|
123
TrueCraft.Client/AudioManager.cs
Normal file
123
TrueCraft.Client/AudioManager.cs
Normal file
@ -0,0 +1,123 @@
|
||||
using System;
|
||||
using Microsoft.Xna.Framework.Audio;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using TrueCraft.Core;
|
||||
using Microsoft.Xna.Framework.Content;
|
||||
using NVorbis;
|
||||
|
||||
namespace TrueCraft.Client
|
||||
{
|
||||
public class AudioManager
|
||||
{
|
||||
private Dictionary<string, SoundEffect[]> AudioPacks { get; set; }
|
||||
|
||||
public float EffectVolume { get; set; }
|
||||
public float MusicVolume { get; set; }
|
||||
|
||||
public AudioManager()
|
||||
{
|
||||
AudioPacks = new Dictionary<string, SoundEffect[]>();
|
||||
EffectVolume = MusicVolume = 1;
|
||||
}
|
||||
|
||||
public void LoadDefaultPacks(ContentManager content)
|
||||
{
|
||||
string[][] packs = new[]
|
||||
{
|
||||
new[]
|
||||
{
|
||||
"footstep.cloth",
|
||||
"default_sand_footstep.1.ogg", "default_sand_footstep.2.ogg" // TODO: Cloth sound effects
|
||||
},
|
||||
new[]
|
||||
{
|
||||
"footstep.grass",
|
||||
"default_grass_footstep.1.ogg", "default_grass_footstep.2.ogg", "default_grass_footstep.3.ogg"
|
||||
},
|
||||
new[]
|
||||
{
|
||||
"footstep.gravel",
|
||||
"default_gravel_footstep.1.ogg", "default_gravel_footstep.2.ogg", "default_gravel_footstep.3.ogg",
|
||||
"default_gravel_footstep.4.ogg"
|
||||
},
|
||||
new[]
|
||||
{
|
||||
"footstep.sand",
|
||||
"default_sand_footstep.1.ogg", "default_sand_footstep.2.ogg"
|
||||
},
|
||||
new[]
|
||||
{
|
||||
"footstep.snow",
|
||||
"default_snow_footstep.1.ogg", "default_snow_footstep.2.ogg", "default_snow_footstep.3.ogg"
|
||||
},
|
||||
new[]
|
||||
{
|
||||
"footstep.stone",
|
||||
"default_hard_footstep.1.ogg", "default_hard_footstep.2.ogg", "default_hard_footstep.3.ogg"
|
||||
},
|
||||
new[]
|
||||
{
|
||||
"footstep.wood",
|
||||
"default_wood_footstep.1.ogg", "default_wood_footstep.2.ogg"
|
||||
},
|
||||
new[]
|
||||
{
|
||||
"footstep.glass",
|
||||
"default_glass_footstep.ogg"
|
||||
},
|
||||
new[]
|
||||
{
|
||||
"hurt",
|
||||
"default_hurt.wav"
|
||||
}
|
||||
};
|
||||
foreach (var pack in packs)
|
||||
{
|
||||
var name = pack[0];
|
||||
LoadAudioPack(name, pack.Skip(1).ToArray());
|
||||
}
|
||||
}
|
||||
|
||||
private SoundEffect LoadOgg(Stream stream)
|
||||
{
|
||||
using (var reader = new VorbisReader(stream, false))
|
||||
{
|
||||
float[] _buffer = new float[reader.TotalSamples];
|
||||
byte[] buffer = new byte[reader.TotalSamples * 2];
|
||||
reader.ReadSamples(_buffer, 0, _buffer.Length);
|
||||
for (int i = 0; i < _buffer.Length; i++)
|
||||
{
|
||||
short val = (short)Math.Max(Math.Min(short.MaxValue * _buffer[i], short.MaxValue), short.MinValue);
|
||||
var decoded = BitConverter.GetBytes(val);
|
||||
buffer[i * 2] = decoded[0];
|
||||
buffer[i * 2 + 1] = decoded[1];
|
||||
}
|
||||
return new SoundEffect(buffer, reader.SampleRate, reader.Channels == 1 ? AudioChannels.Mono : AudioChannels.Stereo);
|
||||
}
|
||||
}
|
||||
|
||||
public void LoadAudioPack(string pack, string[] filenames)
|
||||
{
|
||||
var effects = new SoundEffect[filenames.Length];
|
||||
for (int i = 0; i < filenames.Length; i++)
|
||||
{
|
||||
using (var f = File.OpenRead(Path.Combine("Content", "Audio", filenames[i])))
|
||||
{
|
||||
if (filenames[i].EndsWith(".wav"))
|
||||
effects[i] = SoundEffect.FromStream(f);
|
||||
else if (filenames[i].EndsWith(".ogg"))
|
||||
effects[i] = LoadOgg(f);
|
||||
}
|
||||
}
|
||||
AudioPacks[pack] = effects;
|
||||
}
|
||||
|
||||
public void PlayPack(string pack, float volume = 1.0f)
|
||||
{
|
||||
var i = MathHelper.Random.Next(0, AudioPacks[pack].Length);
|
||||
AudioPacks[pack][i].Play(volume * EffectVolume, 1.0f, 0.0f);
|
||||
}
|
||||
}
|
||||
}
|
361
TrueCraft.Client/BMFont.cs
Normal file
361
TrueCraft.Client/BMFont.cs
Normal file
@ -0,0 +1,361 @@
|
||||
// ---- AngelCode BmFont XML serializer ----------------------
|
||||
// ---- By DeadlyDan @ deadlydan@gmail.com -------------------
|
||||
// ---- There's no license restrictions, use as you will. ----
|
||||
// ---- Credits to http://www.angelcode.com/ -----------------
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Xml.Serialization;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.Xna.Framework;
|
||||
|
||||
namespace TrueCraft.Client
|
||||
{
|
||||
[Serializable]
|
||||
[XmlRoot ( "font" )]
|
||||
public class FontFile
|
||||
{
|
||||
[XmlElement ( "info" )]
|
||||
public FontInfo Info
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[XmlElement ( "common" )]
|
||||
public FontCommon Common
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[XmlArray ( "pages" )]
|
||||
[XmlArrayItem ( "page" )]
|
||||
public List<FontPage> Pages
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[XmlArray ( "chars" )]
|
||||
[XmlArrayItem ( "char" )]
|
||||
public List<FontChar> Chars
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[XmlArray ( "kernings" )]
|
||||
[XmlArrayItem ( "kerning" )]
|
||||
public List<FontKerning> Kernings
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class FontInfo
|
||||
{
|
||||
[XmlAttribute ( "face" )]
|
||||
public String Face
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[XmlAttribute ( "size" )]
|
||||
public Int32 Size
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[XmlAttribute ( "bold" )]
|
||||
public Int32 Bold
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[XmlAttribute ( "italic" )]
|
||||
public Int32 Italic
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[XmlAttribute ( "charset" )]
|
||||
public String CharSet
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[XmlAttribute ( "unicode" )]
|
||||
public Int32 Unicode
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[XmlAttribute ( "stretchH" )]
|
||||
public Int32 StretchHeight
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[XmlAttribute ( "smooth" )]
|
||||
public Int32 Smooth
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[XmlAttribute ( "aa" )]
|
||||
public Int32 SuperSampling
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
private Rectangle _Padding;
|
||||
[XmlAttribute ( "padding" )]
|
||||
public String Padding
|
||||
{
|
||||
get
|
||||
{
|
||||
return _Padding.X + "," + _Padding.Y + "," + _Padding.Width + "," + _Padding.Height;
|
||||
}
|
||||
set
|
||||
{
|
||||
String[] padding = value.Split ( ',' );
|
||||
_Padding = new Rectangle ( Convert.ToInt32 ( padding[0] ), Convert.ToInt32 ( padding[1] ), Convert.ToInt32 ( padding[2] ), Convert.ToInt32 ( padding[3] ) );
|
||||
}
|
||||
}
|
||||
|
||||
private Point _Spacing;
|
||||
[XmlAttribute ( "spacing" )]
|
||||
public String Spacing
|
||||
{
|
||||
get
|
||||
{
|
||||
return _Spacing.X + "," + _Spacing.Y;
|
||||
}
|
||||
set
|
||||
{
|
||||
String[] spacing = value.Split ( ',' );
|
||||
_Spacing = new Point ( Convert.ToInt32 ( spacing[0] ), Convert.ToInt32 ( spacing[1] ) );
|
||||
}
|
||||
}
|
||||
|
||||
[XmlAttribute ( "outline" )]
|
||||
public Int32 OutLine
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class FontCommon
|
||||
{
|
||||
[XmlAttribute ( "lineHeight" )]
|
||||
public Int32 LineHeight
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[XmlAttribute ( "base" )]
|
||||
public Int32 Base
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[XmlAttribute ( "scaleW" )]
|
||||
public Int32 ScaleW
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[XmlAttribute ( "scaleH" )]
|
||||
public Int32 ScaleH
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[XmlAttribute ( "pages" )]
|
||||
public Int32 Pages
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[XmlAttribute ( "packed" )]
|
||||
public Int32 Packed
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[XmlAttribute ( "alphaChnl" )]
|
||||
public Int32 AlphaChannel
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[XmlAttribute ( "redChnl" )]
|
||||
public Int32 RedChannel
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[XmlAttribute ( "greenChnl" )]
|
||||
public Int32 GreenChannel
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[XmlAttribute ( "blueChnl" )]
|
||||
public Int32 BlueChannel
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class FontPage
|
||||
{
|
||||
[XmlAttribute ( "id" )]
|
||||
public Int32 ID
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[XmlAttribute ( "file" )]
|
||||
public String File
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class FontChar
|
||||
{
|
||||
[XmlAttribute ( "id" )]
|
||||
public Int32 ID
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[XmlAttribute ( "x" )]
|
||||
public Int32 X
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[XmlAttribute ( "y" )]
|
||||
public Int32 Y
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[XmlAttribute ( "width" )]
|
||||
public Int32 Width
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[XmlAttribute ( "height" )]
|
||||
public Int32 Height
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[XmlAttribute ( "xoffset" )]
|
||||
public Int32 XOffset
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[XmlAttribute ( "yoffset" )]
|
||||
public Int32 YOffset
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[XmlAttribute ( "xadvance" )]
|
||||
public Int32 XAdvance
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[XmlAttribute ( "page" )]
|
||||
public Int32 Page
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[XmlAttribute ( "chnl" )]
|
||||
public Int32 Channel
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class FontKerning
|
||||
{
|
||||
[XmlAttribute ( "first" )]
|
||||
public Int32 First
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[XmlAttribute ( "second" )]
|
||||
public Int32 Second
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[XmlAttribute ( "amount" )]
|
||||
public Int32 Amount
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
}
|
||||
|
||||
public class FontLoader
|
||||
{
|
||||
public static FontFile Load(Stream stream)
|
||||
{
|
||||
XmlSerializer deserializer = new XmlSerializer(typeof(FontFile));
|
||||
FontFile file = (FontFile) deserializer.Deserialize(stream);
|
||||
return file;
|
||||
}
|
||||
}
|
||||
}
|
2
TrueCraft.Client/Content/Audio/credits.txt
Normal file
2
TrueCraft.Client/Content/Audio/credits.txt
Normal file
@ -0,0 +1,2 @@
|
||||
The footstep and mining/placement sound effects were sourced from Minetest under CC-BY-SA: https://github.com/minetest/minetest_game
|
||||
default_hurt.wav is the same sound effect Minecraft uses, which is CC-BY-SA from http://freesound.org/people/thecheeseman/sounds/44429/
|
BIN
TrueCraft.Client/Content/Audio/default_break_glass.1.ogg
Normal file
BIN
TrueCraft.Client/Content/Audio/default_break_glass.1.ogg
Normal file
Binary file not shown.
BIN
TrueCraft.Client/Content/Audio/default_break_glass.2.ogg
Normal file
BIN
TrueCraft.Client/Content/Audio/default_break_glass.2.ogg
Normal file
Binary file not shown.
BIN
TrueCraft.Client/Content/Audio/default_break_glass.3.ogg
Normal file
BIN
TrueCraft.Client/Content/Audio/default_break_glass.3.ogg
Normal file
Binary file not shown.
BIN
TrueCraft.Client/Content/Audio/default_cool_lava.1.ogg
Normal file
BIN
TrueCraft.Client/Content/Audio/default_cool_lava.1.ogg
Normal file
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user