summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--.gitignore1
-rwxr-xr-xCIbuild.sh4
-rw-r--r--CMakeLists.txt21
-rw-r--r--CONTRIBUTORS1
-rw-r--r--Install/ThirdPartyLicenses/Lua-LICENSE.txt (renamed from Install/Lua-LICENSE.txt)0
-rw-r--r--Install/ThirdPartyLicenses/LuaExpat-license.html (renamed from Install/LuaExpat-license.html)0
-rw-r--r--Install/ThirdPartyLicenses/LuaSQLite3-LICENSE.txt (renamed from Install/LuaSQLite3-LICENSE.txt)0
-rw-r--r--Install/ThirdPartyLicenses/MersenneTwister-LICENSE.txt (renamed from Install/MersenneTwister-LICENSE.txt)0
-rw-r--r--Install/ThirdPartyLicenses/SQLiteCpp-LICENSE.txt (renamed from Install/SQLiteCpp-LICENSE.txt)0
-rw-r--r--Install/Zip2008.list7
-rw-r--r--Install/Zip2008_PDBs.list3
-rw-r--r--MCServer/Plugins/APIDump/APIDesc.lua26
-rw-r--r--MCServer/Plugins/APIDump/Hooks/OnSpawningEntity.lua5
-rw-r--r--MCServer/Plugins/APIDump/Writing-a-MCServer-plugin.html6
-rw-r--r--MCServer/Plugins/Debuggers/Debuggers.lua67
-rw-r--r--MCServer/crafting.txt29
-rw-r--r--MCServer/items.ini274
-rw-r--r--MCServer/lang/items_de.ini603
-rw-r--r--MCServer/webadmin/files/background.gifbin0 -> 57 bytes
-rw-r--r--MCServer/webadmin/files/favicon.icobin0 -> 32038 bytes
-rw-r--r--MCServer/webadmin/files/logo.pngbin0 -> 3315 bytes
-rw-r--r--MCServer/webadmin/files/mc-logo.pngbin0 -> 66137 bytes
-rw-r--r--MCServer/webadmin/files/style.css326
-rw-r--r--MCServer/webadmin/login_template.html25
-rw-r--r--MCServer/webadmin/template.lua344
-rw-r--r--Nightbuild2008.cmd209
-rw-r--r--README.md8
-rw-r--r--SetFlags.cmake36
-rw-r--r--Tools/.gitignore1
-rw-r--r--Tools/BiomeVisualiser/.gitignore4
-rw-r--r--Tools/BiomeVisualiser/BiomeCache.cpp338
-rw-r--r--Tools/BiomeVisualiser/BiomeCache.h96
-rw-r--r--Tools/BiomeVisualiser/BiomeColors.cpp114
-rw-r--r--Tools/BiomeVisualiser/BiomeColors.h15
-rw-r--r--Tools/BiomeVisualiser/BiomeRenderer.cpp119
-rw-r--r--Tools/BiomeVisualiser/BiomeRenderer.h55
-rw-r--r--Tools/BiomeVisualiser/BiomeSource.h37
-rw-r--r--Tools/BiomeVisualiser/BiomeViewWnd.cpp247
-rw-r--r--Tools/BiomeVisualiser/BiomeViewWnd.h69
-rw-r--r--Tools/BiomeVisualiser/BiomeVisualiser.cpp52
-rw-r--r--Tools/BiomeVisualiser/BiomeVisualiser.h31
-rw-r--r--Tools/BiomeVisualiser/BiomeVisualiser.sln23
-rw-r--r--Tools/BiomeVisualiser/BiomeVisualiser.vcproj527
-rw-r--r--Tools/BiomeVisualiser/GeneratorBiomeSource.h42
-rw-r--r--Tools/BiomeVisualiser/Pixmap.cpp120
-rw-r--r--Tools/BiomeVisualiser/Pixmap.h39
-rw-r--r--Tools/BiomeVisualiser/Timer.h40
-rw-r--r--Tools/BiomeVisualiser/WndProcThunk.h143
-rw-r--r--Tools/BiomeVisualiser/profile_run.cmd70
-rw-r--r--Tools/QtBiomeVisualiser/.gitignore2
-rw-r--r--Tools/QtBiomeVisualiser/BiomeView.cpp427
-rw-r--r--Tools/QtBiomeVisualiser/BiomeView.h100
-rw-r--r--Tools/QtBiomeVisualiser/Chunk.cpp36
-rw-r--r--Tools/QtBiomeVisualiser/Chunk.h40
-rw-r--r--Tools/QtBiomeVisualiser/ChunkCache.cpp126
-rw-r--r--Tools/QtBiomeVisualiser/ChunkCache.h72
-rw-r--r--Tools/QtBiomeVisualiser/ChunkLoader.cpp29
-rw-r--r--Tools/QtBiomeVisualiser/ChunkLoader.h45
-rw-r--r--Tools/QtBiomeVisualiser/ChunkSource.cpp421
-rw-r--r--Tools/QtBiomeVisualiser/ChunkSource.h107
-rw-r--r--Tools/QtBiomeVisualiser/GeneratorSetup.cpp159
-rw-r--r--Tools/QtBiomeVisualiser/GeneratorSetup.h64
-rw-r--r--Tools/QtBiomeVisualiser/Globals.h386
-rw-r--r--Tools/QtBiomeVisualiser/MainWindow.cpp310
-rw-r--r--Tools/QtBiomeVisualiser/MainWindow.h96
-rw-r--r--Tools/QtBiomeVisualiser/QtBiomeVisualiser.pro94
-rw-r--r--Tools/QtBiomeVisualiser/main.cpp20
m---------lib/SQLiteCpp0
-rw-r--r--lib/inifile/iniFile.cpp18
-rw-r--r--lib/inifile/iniFile.h5
-rw-r--r--lib/tolua++/include/tolua++.h4
-rw-r--r--src/Bindings/LuaChunkStay.cpp2
-rw-r--r--src/Bindings/LuaState.cpp26
-rw-r--r--src/Bindings/LuaState.h18
-rw-r--r--src/Bindings/ManualBindings.cpp70
-rw-r--r--src/Bindings/gen_LuaState_Call.lua2
-rw-r--r--src/BlockEntities/RedstonePoweredEntity.h2
-rw-r--r--src/BlockEntities/SignEntity.cpp1
-rw-r--r--src/BlockID.h2
-rw-r--r--src/BlockInfo.cpp167
-rw-r--r--src/BlockInfo.h4
-rw-r--r--src/Blocks/BlockBed.cpp2
-rw-r--r--src/Blocks/BlockBigFlower.h12
-rw-r--r--src/Blocks/BlockButton.h6
-rw-r--r--src/Blocks/BlockCactus.h6
-rw-r--r--src/Blocks/BlockCake.h5
-rw-r--r--src/Blocks/BlockCarpet.h6
-rw-r--r--src/Blocks/BlockChest.h6
-rw-r--r--src/Blocks/BlockCloth.h5
-rw-r--r--src/Blocks/BlockCommandBlock.h5
-rw-r--r--src/Blocks/BlockComparator.h6
-rw-r--r--src/Blocks/BlockCrops.h6
-rw-r--r--src/Blocks/BlockDirt.h6
-rw-r--r--src/Blocks/BlockDoor.cpp11
-rw-r--r--src/Blocks/BlockDoor.h1
-rw-r--r--src/Blocks/BlockEnderchest.h5
-rw-r--r--src/Blocks/BlockFarmland.h99
-rw-r--r--src/Blocks/BlockFenceGate.h6
-rw-r--r--src/Blocks/BlockFire.h9
-rw-r--r--src/Blocks/BlockFlower.h6
-rw-r--r--src/Blocks/BlockGravel.h12
-rw-r--r--src/Blocks/BlockHandler.cpp77
-rw-r--r--src/Blocks/BlockHandler.h5
-rw-r--r--src/Blocks/BlockHayBale.h6
-rw-r--r--src/Blocks/BlockLadder.h6
-rw-r--r--src/Blocks/BlockLeaves.h6
-rw-r--r--src/Blocks/BlockLever.h6
-rw-r--r--src/Blocks/BlockMelon.h6
-rw-r--r--src/Blocks/BlockMobHead.h12
-rw-r--r--src/Blocks/BlockMobSpawner.h40
-rw-r--r--src/Blocks/BlockMushroom.h6
-rw-r--r--src/Blocks/BlockMycelium.h5
-rw-r--r--src/Blocks/BlockOre.h3
-rw-r--r--src/Blocks/BlockPiston.cpp2
-rw-r--r--src/Blocks/BlockPlanks.h6
-rw-r--r--src/Blocks/BlockRedstoneRepeater.h6
-rw-r--r--src/Blocks/BlockRedstoneTorch.h6
-rw-r--r--src/Blocks/BlockSand.h6
-rw-r--r--src/Blocks/BlockSapling.h6
-rw-r--r--src/Blocks/BlockSideways.h6
-rw-r--r--src/Blocks/BlockSignPost.h6
-rw-r--r--src/Blocks/BlockSlab.h23
-rw-r--r--src/Blocks/BlockSnow.h6
-rw-r--r--src/Blocks/BlockStairs.h18
-rw-r--r--src/Blocks/BlockStems.h6
-rw-r--r--src/Blocks/BlockSugarcane.h6
-rw-r--r--src/Blocks/BlockTNT.h5
-rw-r--r--src/Blocks/BlockTallGrass.h6
-rw-r--r--src/Blocks/BlockTorch.h6
-rw-r--r--src/Blocks/BlockTrapdoor.h5
-rw-r--r--src/Blocks/BlockTripwire.h5
-rw-r--r--src/Blocks/BlockTripwireHook.h5
-rw-r--r--src/Blocks/BlockVine.h6
-rw-r--r--src/Blocks/BlockWallSign.h6
-rw-r--r--src/Blocks/BlockWorkbench.h6
-rw-r--r--src/Blocks/ChunkInterface.h4
-rw-r--r--src/Blocks/WorldInterface.h7
-rw-r--r--src/BoundingBox.h11
-rw-r--r--src/BuildInfo.h.cmake15
-rw-r--r--src/ByteBuffer.cpp32
-rw-r--r--src/ByteBuffer.h2
-rw-r--r--src/CMakeLists.txt3
-rw-r--r--src/Chunk.cpp94
-rw-r--r--src/Chunk.h55
-rw-r--r--src/ChunkDef.h31
-rw-r--r--src/ChunkMap.cpp365
-rw-r--r--src/ChunkMap.h33
-rw-r--r--src/ChunkSender.cpp14
-rw-r--r--src/ChunkSender.h7
-rw-r--r--src/ChunkStay.cpp2
-rw-r--r--src/ClientHandle.cpp228
-rw-r--r--src/ClientHandle.h158
-rw-r--r--src/CompositeChat.cpp178
-rw-r--r--src/CompositeChat.h6
-rw-r--r--src/Defines.h2
-rw-r--r--src/Entities/Entity.cpp56
-rw-r--r--src/Entities/Entity.h6
-rw-r--r--src/Entities/EntityEffect.cpp91
-rw-r--r--src/Entities/EntityEffect.h8
-rw-r--r--src/Entities/ExpBottleEntity.cpp19
-rw-r--r--src/Entities/ExpBottleEntity.h5
-rw-r--r--src/Entities/ItemFrame.cpp2
-rw-r--r--src/Entities/Minecart.cpp85
-rw-r--r--src/Entities/Player.cpp54
-rw-r--r--src/Entities/Player.h7
-rw-r--r--src/Generating/BioGen.cpp203
-rw-r--r--src/Generating/BioGen.h30
-rw-r--r--src/Generating/Caves.cpp2
-rw-r--r--src/Generating/ChunkGenerator.cpp43
-rw-r--r--src/Generating/ChunkGenerator.h16
-rw-r--r--src/Generating/ComposableGenerator.cpp32
-rw-r--r--src/Generating/Noise3DGenerator.cpp4
-rw-r--r--src/HTTPServer/HTTPServer.cpp3
-rw-r--r--src/Item.cpp80
-rw-r--r--src/Item.h6
-rw-r--r--src/Items/ItemFood.h8
-rw-r--r--src/Items/ItemGoldenApple.h1
-rw-r--r--src/Items/ItemHandler.cpp16
-rw-r--r--src/Items/ItemHoe.h9
-rw-r--r--src/Items/ItemMilk.h8
-rw-r--r--src/Items/ItemMushroomSoup.h53
-rw-r--r--src/Items/ItemPickaxe.h1
-rw-r--r--src/Items/ItemPotion.h8
-rw-r--r--src/Items/ItemSeeds.h2
-rw-r--r--src/LineBlockTracer.cpp21
-rw-r--r--src/Map.cpp8
-rw-r--r--src/Mobs/Monster.cpp6
-rw-r--r--src/Mobs/Monster.h5
-rw-r--r--src/Mobs/Sheep.cpp7
-rw-r--r--src/OSSupport/File.cpp14
-rw-r--r--src/OSSupport/IsThread.h2
-rw-r--r--src/Protocol/CMakeLists.txt2
-rw-r--r--src/Protocol/ChunkDataSerializer.cpp79
-rw-r--r--src/Protocol/ChunkDataSerializer.h6
-rw-r--r--src/Protocol/Protocol.h145
-rw-r--r--src/Protocol/Protocol125.cpp77
-rw-r--r--src/Protocol/Protocol125.h144
-rw-r--r--src/Protocol/Protocol132.cpp2
-rw-r--r--src/Protocol/Protocol14x.cpp6
-rw-r--r--src/Protocol/Protocol15x.cpp4
-rw-r--r--src/Protocol/Protocol15x.h2
-rw-r--r--src/Protocol/Protocol17x.cpp296
-rw-r--r--src/Protocol/Protocol17x.h163
-rw-r--r--src/Protocol/Protocol18x.cpp3244
-rw-r--r--src/Protocol/Protocol18x.h335
-rw-r--r--src/Protocol/ProtocolRecognizer.cpp83
-rw-r--r--src/Protocol/ProtocolRecognizer.h147
-rw-r--r--src/Root.cpp7
-rw-r--r--src/Server.cpp7
-rw-r--r--src/Server.h8
-rw-r--r--src/SetChunkData.cpp1
-rw-r--r--src/StringCompression.cpp62
-rw-r--r--src/StringCompression.h2
-rw-r--r--src/StringUtils.cpp28
-rw-r--r--src/StringUtils.h5
-rw-r--r--src/Tracer.cpp4
-rw-r--r--src/UI/SlotArea.cpp189
-rw-r--r--src/UI/SlotArea.h7
-rw-r--r--src/UI/Window.cpp61
-rw-r--r--src/UI/Window.h6
-rw-r--r--src/VoronoiMap.cpp126
-rw-r--r--src/VoronoiMap.h44
-rw-r--r--src/WebAdmin.cpp150
-rw-r--r--src/WebAdmin.h12
-rw-r--r--src/World.cpp184
-rw-r--r--src/World.h94
-rw-r--r--src/WorldStorage/FastNBT.cpp2
-rw-r--r--src/WorldStorage/ScoreboardSerializer.cpp20
-rw-r--r--src/WorldStorage/WSSAnvil.cpp72
-rw-r--r--src/WorldStorage/WSSCompact.cpp6
-rw-r--r--src/WorldStorage/WorldStorage.cpp48
-rw-r--r--src/WorldStorage/WorldStorage.h45
232 files changed, 10892 insertions, 4784 deletions
diff --git a/.gitignore b/.gitignore
index a4cbef72f..6afc12116 100644
--- a/.gitignore
+++ b/.gitignore
@@ -56,6 +56,7 @@ Makefile
*.a
*.d
*.so
+BuildInfo.h
CMakeCache.txt
CMakeFiles
Makefile
diff --git a/CIbuild.sh b/CIbuild.sh
index 683c1fc74..5d95f88a6 100755
--- a/CIbuild.sh
+++ b/CIbuild.sh
@@ -2,6 +2,10 @@
set -e
+export MCSERVER_BUILD_SERIES_NAME="Travis $CC $TRAVIS_MCSERVER_BUILD_TYPE"
+export MCSERVER_BUILD_ID=$TRAVIS_JOB_NUMBER
+export MCSERVER_BUILD_DATETIME=`date`
+
cmake . -DBUILD_TOOLS=1 -DSELF_TEST=1;
make -j 2;
make -j 2 test;
diff --git a/CMakeLists.txt b/CMakeLists.txt
index dd9b1e67c..188cf81e3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,4 +1,4 @@
-cmake_minimum_required (VERSION 2.8.2)
+cmake_minimum_required (VERSION 2.8.7)
# Without this, the MSVC variable isn't defined for MSVC builds ( http://www.cmake.org/pipermail/cmake/2011-November/047130.html )
enable_language(CXX C)
@@ -18,6 +18,25 @@ if(DEFINED ENV{TRAVIS_BUILD_WITH_COVERAGE})
set(BUILD_WITH_COVERAGE $ENV{TRAVIS_BUILD_WITH_COVERAGE})
endif()
+if(DEFINED ENV{MCSERVER_BUILD_ID})
+ set(BUILD_ID $ENV{MCSERVER_BUILD_ID})
+ set(BUILD_SERIES_NAME $ENV{MCSERVER_BUILD_SERIES_NAME})
+ set(BUILD_DATETIME $ENV{MCSERVER_BUILD_DATETIME})
+ if(DEFINED ENV{MCSERVER_BUILD_COMMIT_ID})
+ set(BUILD_COMMIT_ID $ENV{MCSERVER_BUILD_COMMIT_ID})
+ else()
+ message("Commit id not set, attempting to determine id from git")
+ execute_process(
+ COMMAND git rev-parse HEAD
+ RESULT_VARIABLE GIT_EXECUTED
+ OUTPUT_VARIABLE BUILD_COMMIT_ID)
+ string(STRIP ${BUILD_COMMIT_ID} BUILD_COMMIT_ID)
+ if (NOT (GIT_EXECUTED EQUAL 0))
+ message(FATAL_ERROR "Could not identifiy git commit id")
+ endif()
+ endif()
+endif()
+
# This has to be done before any flags have been set up.
if(${BUILD_TOOLS})
add_subdirectory(Tools/MCADefrag/)
diff --git a/CONTRIBUTORS b/CONTRIBUTORS
index 925e8f35b..2d911a11d 100644
--- a/CONTRIBUTORS
+++ b/CONTRIBUTORS
@@ -29,5 +29,6 @@ worktycho
xoft
Yeeeeezus (Donated AlchemistVillage prefabs)
Howaner
+Masy98
Please add yourself to this list if you contribute to MCServer.
diff --git a/Install/Lua-LICENSE.txt b/Install/ThirdPartyLicenses/Lua-LICENSE.txt
index 3c6d06fcf..3c6d06fcf 100644
--- a/Install/Lua-LICENSE.txt
+++ b/Install/ThirdPartyLicenses/Lua-LICENSE.txt
diff --git a/Install/LuaExpat-license.html b/Install/ThirdPartyLicenses/LuaExpat-license.html
index bd4a54f9a..bd4a54f9a 100644
--- a/Install/LuaExpat-license.html
+++ b/Install/ThirdPartyLicenses/LuaExpat-license.html
diff --git a/Install/LuaSQLite3-LICENSE.txt b/Install/ThirdPartyLicenses/LuaSQLite3-LICENSE.txt
index cf1014378..cf1014378 100644
--- a/Install/LuaSQLite3-LICENSE.txt
+++ b/Install/ThirdPartyLicenses/LuaSQLite3-LICENSE.txt
diff --git a/Install/MersenneTwister-LICENSE.txt b/Install/ThirdPartyLicenses/MersenneTwister-LICENSE.txt
index 5c7a6ef04..5c7a6ef04 100644
--- a/Install/MersenneTwister-LICENSE.txt
+++ b/Install/ThirdPartyLicenses/MersenneTwister-LICENSE.txt
diff --git a/Install/SQLiteCpp-LICENSE.txt b/Install/ThirdPartyLicenses/SQLiteCpp-LICENSE.txt
index ec952abba..ec952abba 100644
--- a/Install/SQLiteCpp-LICENSE.txt
+++ b/Install/ThirdPartyLicenses/SQLiteCpp-LICENSE.txt
diff --git a/Install/Zip2008.list b/Install/Zip2008.list
index 5736867d8..e69857d09 100644
--- a/Install/Zip2008.list
+++ b/Install/Zip2008.list
@@ -6,10 +6,7 @@
..\MCServer\furnace.txt
..\MCServer\items.ini
..\MCServer\monsters.ini
+..\MCServer\buildinfo.txt
MCServer*debug.cmd
*.example.ini
-Lua-LICENSE.txt
-LuaExpat-license.html
-LuaSQLite3-LICENSE.txt
-SQLiteCpp-LICENSE.txt
-MersenneTwister-LICENSE.txt
+ThirdPartyLicenses
diff --git a/Install/Zip2008_PDBs.list b/Install/Zip2008_PDBs.list
index 608b0185b..96e4cd7d3 100644
--- a/Install/Zip2008_PDBs.list
+++ b/Install/Zip2008_PDBs.list
@@ -1,2 +1,3 @@
MCServer\*.pdb
-src\Bindings\Bindings.* \ No newline at end of file
+MCServer\buildinfo.txt
+src\Bindings\Bindings.*
diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua
index f109638e9..e6ee4ca10 100644
--- a/MCServer/Plugins/APIDump/APIDesc.lua
+++ b/MCServer/Plugins/APIDump/APIDesc.lua
@@ -524,6 +524,7 @@ end
Functions =
{
GenerateOfflineUUID = { Params = "Username", Return = "string", Notes = "(STATIC) Generates an UUID based on the player name provided. This is used for the offline (non-auth) mode, when there's no UUID source. Each username generates a unique and constant UUID, so that when the player reconnects with the same name, their UUID is the same. Returns a 32-char UUID (no dashes)." },
+ GetIPString = { Params = "", Return = "string", Notes = "Returns the IP address of the connection, as a string. Only the address part is returned, without the port number." },
GetLocale = { Params = "", Return = "Locale", Notes = "Returns the locale string that the client sends as part of the protocol handshake. Can be used to provide localized strings." },
GetPing = { Params = "", Return = "number", Notes = "Returns the ping time, in ms" },
GetPlayer = { Params = "", Return = "{{cPlayer|cPlayer}}", Notes = "Returns the player object connected to this client. Note that this may be nil, for example if the player object is not yet spawned." },
@@ -1188,7 +1189,7 @@ These ItemGrids are available in the API and can be manipulated by the plugins,
constructor =
{
{ Params = "", Return = "cItem", Notes = "Creates a new empty cItem object" },
- { Params = "ItemType, Count, Damage, EnchantmentString", Return = "cItem", Notes = "Creates a new cItem object of the specified type, count (1 by default), damage (0 by default) and enchantments (non-enchanted by default)" },
+ { Params = "ItemType, Count, Damage, EnchantmentString, CustomName, Lore", Return = "cItem", Notes = "Creates a new cItem object of the specified type, count (1 by default), damage (0 by default), enchantments (non-enchanted by default), CustomName (empty by default) and Lore (string, empty by default)" },
{ Params = "cItem", Return = "cItem", Notes = "Creates an exact copy of the cItem object in the parameter" },
} ,
AddCount = { Params = "AmountToAdd", Return = "cItem", Notes = "Adds the specified amount to the item count. Returns self (useful for chaining)." },
@@ -1201,12 +1202,14 @@ These ItemGrids are available in the API and can be manipulated by the plugins,
IsDamageable = { Params = "", Return = "bool", Notes = "Returns true if this item does account for its damage" },
IsEmpty = { Params = "", Return = "bool", Notes = "Returns true if this object represents an empty item (zero count or invalid ID)" },
IsEqual = { Params = "cItem", Return = "bool", Notes = "Returns true if the item in the parameter is the same as the one stored in the object (type, damage, lore, name and enchantments)" },
- IsEnchantable = { Params = "", Return = "bool", Notes = "Returns true if the item is enchantable" },
IsFullStack = { Params = "", Return = "bool", Notes = "Returns true if the item is stacked up to its maximum stacking" },
IsSameType = { Params = "cItem", Return = "bool", Notes = "Returns true if the item in the parameter is of the same ItemType as the one stored in the object. This is true even if the two items have different enchantments" },
IsBothNameAndLoreEmpty = { Params = "", Return = "bool", Notes = "Returns if both the custom name and lore are not set." },
IsCustomNameEmpty = { Params = "", Return = "bool", Notes = "Returns if the custom name of the cItem is empty." },
IsLoreEmpty = { Params = "", Return = "", Notes = "Returns if the lore of the cItem is empty." },
+ GetEnchantability = { Params = "", Return = "number", Notes = "Returns the enchantability of the item. When the item hasn't a enchantability, it will returns 0" },
+ EnchantByXPLevels = { Params = "NumXPLevels", Return = "bool", Notes = "Enchants the item using the specified number of XP levels. Returns true if item enchanted, false if not." },
+ IsEnchantable = { Params = "ItemType, WithBook", Return = "bool", Notes = "(STATIC) Returns true if the specified item type is enchantable. If WithBook is true, the function is used in the anvil inventory with book enchantments. So it checks the \"only book enchantments\" too. Example: You can only enchant a hoe with a book." },
},
Variables =
{
@@ -1214,8 +1217,10 @@ These ItemGrids are available in the API and can be manipulated by the plugins,
m_ItemCount = { Type = "number", Notes = "Number of items in this stack" },
m_ItemDamage = { Type = "number", Notes = "The damage of the item. Zero means no damage. Maximum damage can be queried with GetMaxDamage()" },
m_ItemType = { Type = "number", Notes = "The item type. One of E_ITEM_ or E_BLOCK_ constants" },
- m_CustomName = { Type = "string", Notes = "The custom name for an item." },
- m_Lore = { Type = "string", Notes = "The lore for an item. Line breaks are represented by the ` character." },
+ m_CustomName = { Type = "string", Notes = "The custom name for an item." },
+ m_Lore = { Type = "string", Notes = "The lore for an item. Line breaks are represented by the ` character." },
+ m_RepairCost = { Type = "number", Notes = "The repair cost of the item. The anvil need this value" },
+ m_Enchantments = { Type = "{{cEnchantments|cEnchantments}}}", Notes = "The enchantments of the item." },
},
AdditionalInfo =
{
@@ -1641,6 +1646,8 @@ a_Player:OpenWindow(Window);
MobTypeToString = { Params = "{{cMonster#MobType|MobType}}", Return = "string", Notes = "(STATIC) Returns the string representing the given mob type ({{cMonster#MobType|mtXXX}} constant), or empty string if unknown type." },
MoveToPosition = { Params = "Position", Return = "", Notes = "Moves mob to the specified position" },
StringToMobType = { Params = "string", Return = "{{cMonster#MobType|MobType}}", Notes = "(STATIC) Returns the mob type ({{cMonster#MobType|mtXXX}} constant) parsed from the string type (\"creeper\"), or mtInvalidType if unrecognized." },
+ GetRelativeWalkSpeed = { Params = "", Return = "number", Notes = "Returns the relative walk speed of this mob. Standard is 1.0" },
+ SetRelativeWalkSpeed = { Params = "number", Return = "", Notes = "Sets the relative walk speed of this mob. Standard is 1.0" },
},
Constants =
{
@@ -1757,7 +1764,7 @@ a_Player:OpenWindow(Window);
ForceSetSpeed = { Params = "{{Vector3d|Direction}}", Notes = "Forces the player to move to the given direction." },
GetClientHandle = { Params = "", Return = "{{cClientHandle}}", Notes = "Returns the client handle representing the player's connection. May be nil (AI players)." },
GetColor = { Return = "string", Notes = "Returns the full color code to be used for this player's messages (based on their rank). Prefix player messages with this code." },
- GetTabListName = { Return = "string", Notes = "Returns the name that is used in the tablist." },
+ GetPlayerListName = { Return = "string", Notes = "Returns the name that is used in the playerlist." },
GetCurrentXp = { Params = "", Return = "number", Notes = "Returns the current amount of XP" },
GetEffectiveGameMode = { Params = "", Return = "{{Globals#GameMode|GameMode}}", Notes = "(OBSOLETE) Returns the current resolved game mode of the player. If the player is set to inherit the world's gamemode, returns that instead. See also GetGameMode() and IsGameModeXXX() functions. Note that this function is the same as GetGameMode(), use that function instead." },
GetEquippedItem = { Params = "", Return = "{{cItem}}", Notes = "Returns the item that the player is currently holding; empty item if holding nothing." },
@@ -1889,13 +1896,13 @@ cPluginManager.AddHook(cPluginManager.HOOK_CHAT, OnChatMessage);
},
BindCommand =
{
- { Params = "Command, Permission, Callback, HelpString", Return = "[bool]", Notes = "(STATIC) Binds an in-game command with the specified callback function, permission and help string. By common convention, providing an empty string for HelpString will hide the command from the /help display. Returns true if successful, logs to console and returns no value on error." },
- { Params = "Command, Permission, Callback, HelpString", Return = "[bool]", Notes = "Binds an in-game command with the specified callback function, permission and help string. By common convention, providing an empty string for HelpString will hide the command from the /help display. Returns true if successful, logs to console and returns no value on error." },
+ { Params = "Command, Permission, Callback, HelpString", Return = "[bool]", Notes = "(STATIC) Binds an in-game command with the specified callback function, permission and help string. By common convention, providing an empty string for HelpString will hide the command from the /help display. Returns true if successful, logs to console and returns no value on error. The callback uses the following signature: <pre class=\"prettyprint lang-lua\">function(Split, {{cPlayer|Player}})</pre> The Split parameter contains an array-table of the words that the player has sent, Player is the {{cPlayer}} object representing the player who sent the command. If the callback returns true, the command is assumed to have executed successfully; in all other cases the server sends a warning to the player that the command is unknown (this is so that subcommands can be implemented)." },
+ { Params = "Command, Permission, Callback, HelpString", Return = "[bool]", Notes = "Binds an in-game command with the specified callback function, permission and help string. By common convention, providing an empty string for HelpString will hide the command from the /help display. Returns true if successful, logs to console and returns no value on error. The callback uses the following signature: <pre class=\"prettyprint lang-lua\">function(Split, {{cPlayer|Player}})</pre> The Split parameter contains an array-table of the words that the player has sent, Player is the {{cPlayer}} object representing the player who sent the command. If the callback returns true, the command is assumed to have executed successfully; in all other cases the server sends a warning to the player that the command is unknown (this is so that subcommands can be implemented)." },
},
BindConsoleCommand =
{
- { Params = "Command, Callback, HelpString", Return = "[bool]", Notes = "(STATIC) Binds a console command with the specified callback function and help string. By common convention, providing an empty string for HelpString will hide the command from the \"help\" console command. Returns true if successful, logs to console and returns no value on error." },
- { Params = "Command, Callback, HelpString", Return = "[bool]", Notes = "Binds a console command with the specified callback function and help string. By common convention, providing an empty string for HelpString will hide the command from the \"help\" console command. Returns true if successful, logs to console and returns no value on error." },
+ { Params = "Command, Callback, HelpString", Return = "[bool]", Notes = "(STATIC) Binds a console command with the specified callback function and help string. By common convention, providing an empty string for HelpString will hide the command from the \"help\" console command. Returns true if successful, logs to console and returns no value on error. The callback uses the following signature: <pre class=\"prettyprint lang-lua\">function(Split)</pre> The Split parameter contains an array-table of the words that the admin has typed. If the callback returns true, the command is assumed to have executed successfully; in all other cases the server issues a warning to the console that the command is unknown (this is so that subcommands can be implemented)." },
+ { Params = "Command, Callback, HelpString", Return = "[bool]", Notes = "Binds a console command with the specified callback function and help string. By common convention, providing an empty string for HelpString will hide the command from the \"help\" console command. Returns true if successful, logs to console and returns no value on error. The callback uses the following signature: <pre class=\"prettyprint lang-lua\">function(Split)</pre> The Split parameter contains an array-table of the words that the admin has typed. If the callback returns true, the command is assumed to have executed successfully; in all other cases the server issues a warning to the console that the command is unknown (this is so that subcommands can be implemented)." },
},
CallPlugin = { Params = "PluginName, FunctionName, [FunctionArgs...]", Return = "[FunctionRets]", Notes = "(STATIC) Calls the specified function in the specified plugin, passing all the given arguments to it. If it succeeds, it returns all the values returned by that function. If it fails, returns no value at all. Note that only strings, numbers, bools, nils and classes can be used for parameters and return values; tables and functions cannot be copied across plugins." },
DisablePlugin = { Params = "PluginName", Return = "bool", Notes = "Disables a plugin specified by its name. Returns true if the plugin was disabled, false if it wasn't found or wasn't active." },
@@ -2349,6 +2356,7 @@ end
ForEachBlockEntityInChunk = { Params = "ChunkX, ChunkZ, CallbackFunction, [CallbackData]", Return = "bool", Notes = "Calls the specified callback for each block entity in the chunk. Returns true if all block entities in the chunk have been processed (including when there are zero block entities), or false if the callback has aborted the enumeration by returning true. The CallbackFunction has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cBlockEntity|BlockEntity}}, [CallbackData])</pre> The callback should return false or no value to continue with the next block entity, or true to abort the enumeration. Use {{tolua}}.cast() to cast the Callback's BlockEntity parameter to the correct {{cBlockEntity}} descendant." },
ForEachChestInChunk = { Params = "ChunkX, ChunkZ, CallbackFunction, [CallbackData]", Return = "bool", Notes = "Calls the specified callback for each chest in the chunk. Returns true if all chests in the chunk have been processed (including when there are zero chests), or false if the callback has aborted the enumeration by returning true. The CallbackFunction has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cChestEntity|ChestEntity}}, [CallbackData])</pre> The callback should return false or no value to continue with the next chest, or true to abort the enumeration." },
ForEachEntity = { Params = "CallbackFunction, [CallbackData]", Return = "bool", Notes = "Calls the specified callback for each entity in the loaded world. Returns true if all the entities have been processed (including when there are zero entities), or false if the callback function has aborted the enumeration by returning true. The callback function has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cEntity|Entity}}, [CallbackData])</pre> The callback should return false or no value to continue with the next entity, or true to abort the enumeration." },
+ ForEachEntityInBox = { Params = "{{cBoundingBox|Box}}, CallbackFunction", Return = "bool", Notes = "Calls the specified callback for each entity in the specified bounding box. Returns true if all the entities have been processed (including when there are zero entities), or false if the callback function has aborted the enumeration by returning true. If any chunk within the bounding box is not valid, it is silently skipped without any notification. The callback function has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cEntity|Entity}})</pre> The callback should return false or no value to continue with the next entity, or true to abort the enumeration." },
ForEachEntityInChunk = { Params = "ChunkX, ChunkZ, CallbackFunction, [CallbackData]", Return = "bool", Notes = "Calls the specified callback for each entity in the specified chunk. Returns true if all the entities have been processed (including when there are zero entities), or false if the chunk is not loaded or the callback function has aborted the enumeration by returning true. The callback function has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cEntity|Entity}}, [CallbackData])</pre> The callback should return false or no value to continue with the next entity, or true to abort the enumeration." },
ForEachFurnaceInChunk = { Params = "ChunkX, ChunkZ, CallbackFunction, [CallbackData]", Return = "bool", Notes = "Calls the specified callback for each furnace in the chunk. Returns true if all furnaces in the chunk have been processed (including when there are zero furnaces), or false if the callback has aborted the enumeration by returning true. The CallbackFunction has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cFurnaceEntity|FurnaceEntity}}, [CallbackData])</pre> The callback should return false or no value to continue with the next furnace, or true to abort the enumeration." },
ForEachPlayer = { Params = "CallbackFunction, [CallbackData]", Return = "bool", Notes = "Calls the specified callback for each player in the loaded world. Returns true if all the players have been processed (including when there are zero players), or false if the callback function has aborted the enumeration by returning true. The callback function has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cPlayer|Player}}, [CallbackData])</pre> The callback should return false or no value to continue with the next player, or true to abort the enumeration." },
diff --git a/MCServer/Plugins/APIDump/Hooks/OnSpawningEntity.lua b/MCServer/Plugins/APIDump/Hooks/OnSpawningEntity.lua
index c4bff3916..e2bd1c940 100644
--- a/MCServer/Plugins/APIDump/Hooks/OnSpawningEntity.lua
+++ b/MCServer/Plugins/APIDump/Hooks/OnSpawningEntity.lua
@@ -6,8 +6,9 @@ return
DefaultFnName = "OnSpawningEntity", -- also used as pagename
Desc = [[
This hook is called before the server spawns an {{cEntity|entity}}. The plugin can either modify the
- entity before it is spawned, or disable the spawning altogether. If the entity spawning is a
- monster, the {{OnSpawningMonster|HOOK_SPAWNING_MONSTER}} hook is called before this hook.</p>
+ entity before it is spawned, or disable the spawning altogether. You can't disable the spawning if the
+ entity is a player. If the entity spawning is a monster, the {{OnSpawningMonster|HOOK_SPAWNING_MONSTER}}
+ hook is called before this hook.</p>
<p>
See also the {{OnSpawnedEntity|HOOK_SPAWNED_ENTITY}} hook for a similar hook called after the
entity is spawned.
diff --git a/MCServer/Plugins/APIDump/Writing-a-MCServer-plugin.html b/MCServer/Plugins/APIDump/Writing-a-MCServer-plugin.html
index 35c880b00..dd124e119 100644
--- a/MCServer/Plugins/APIDump/Writing-a-MCServer-plugin.html
+++ b/MCServer/Plugins/APIDump/Writing-a-MCServer-plugin.html
@@ -202,7 +202,7 @@ function Explode(Split, Player)
if (#Split ~= 2) then
-- There was more or less than one argument (excluding the "/explode" bit)
-- Send the proper usage to the player and exit
- SendMessage(Player, "Usage: /explode [playername]")
+ Player:SendMessage("Usage: /explode [playername]")
return true
end
@@ -213,7 +213,7 @@ function Explode(Split, Player)
if (Explodee:GetName() == Split[2]) then
-- Create an explosion at the same position as they are; see <a href="cWorld.html">API docs</a> for further details of this function
Player:GetWorld():DoExplosionAt(Explodee:GetPosX(), Explodee:GetPosY(), Explodee:GetPosZ(), false, esPlugin)
- SendMessageSuccess(Player, Split[2] .. " was successfully exploded")
+ Player:SendMessageSuccess(Split[2] .. " was successfully exploded")
HasExploded = true;
return true -- Signalize to MCS that we do not need to call this callback for any more players
end
@@ -224,7 +224,7 @@ function Explode(Split, Player)
if not(HasExploded) then
-- We have not broken out so far, therefore, the player must not exist, send failure
- SendMessageFailure(Player, Split[2] .. " was not found")
+ Player:SendMessageFailure(Split[2] .. " was not found")
end
return true
diff --git a/MCServer/Plugins/Debuggers/Debuggers.lua b/MCServer/Plugins/Debuggers/Debuggers.lua
index 65ce0993a..f66ac76a0 100644
--- a/MCServer/Plugins/Debuggers/Debuggers.lua
+++ b/MCServer/Plugins/Debuggers/Debuggers.lua
@@ -38,7 +38,7 @@ function Initialize(Plugin)
-- _X: Disabled so that the normal operation doesn't interfere with anything
-- PM:AddHook(cPluginManager.HOOK_CHUNK_GENERATED, OnChunkGenerated);
- PM:BindCommand("/cm", "debuggers", HandleCustomNameCmd, "- Gives you a custom name");
+ PM:BindCommand("/nick", "debuggers", HandleNickCmd, "- Gives you a custom name");
PM:BindCommand("/le", "debuggers", HandleListEntitiesCmd, "- Shows a list of all the loaded entities");
PM:BindCommand("/ke", "debuggers", HandleKillEntitiesCmd, "- Kills all the loaded entities");
PM:BindCommand("/wool", "debuggers", HandleWoolCmd, "- Sets all your armor to blue wool");
@@ -66,6 +66,8 @@ function Initialize(Plugin)
PM:BindCommand("/sb", "debuggers", HandleSetBiome, "- Sets the biome around you to the specified one");
PM:BindCommand("/wesel", "debuggers", HandleWESel, "- Expands the current WE selection by 1 block in X/Z");
PM:BindCommand("/rmitem", "debuggers", HandleRMItem, "- Remove the specified item from the inventory.");
+ PM:BindCommand("/pickups", "debuggers", HandlePickups, "- Spawns random pickups around you");
+ PM:BindCommand("/poof", "debuggers", HandlePoof, "- Nudges pickups close to you away from you");
Plugin:AddWebTab("Debuggers", HandleRequest_Debuggers)
Plugin:AddWebTab("StressTest", HandleRequest_StressTest)
@@ -769,14 +771,13 @@ end
-function HandleCustomNameCmd(Split, Player)
+function HandleNickCmd(Split, Player)
if (Split[2] == nil) then
- Player:SendMessage("Usage: /cm [CustomName]");
+ Player:SendMessage("Usage: /nick [CustomName]");
return true;
end
- local NewName = Split[2]
- Player:SetCustomName(NewName);
+ Player:SetCustomName(Split[2]);
Player:SendMessageSuccess("Custom name setted to " .. Player:GetCustomName() .. "!")
return true
end
@@ -1517,7 +1518,7 @@ function OnPlayerJoined(a_Player)
-- Test composite chat chaining:
a_Player:SendMessage(cCompositeChat()
:AddTextPart("Hello, ")
- :AddUrlPart(a_Player:GetName(), "www.mc-server.org", "u@2")
+ :AddUrlPart(a_Player:GetName(), "http://www.mc-server.org", "u@2")
:AddSuggestCommandPart(", and welcome.", "/help", "u")
:AddRunCommandPart(" SetDay", "/time set 0")
)
@@ -1575,3 +1576,57 @@ end
+
+local PossibleItems =
+{
+ cItem(E_ITEM_DIAMOND),
+ cItem(E_ITEM_GOLD),
+ cItem(E_ITEM_IRON),
+ cItem(E_ITEM_DYE, 1, E_META_DYE_BLUE), -- Lapis lazuli
+ cItem(E_ITEM_COAL),
+}
+
+
+
+
+
+function HandlePickups(a_Split, a_Player)
+ local PlayerX = a_Player:GetPosX()
+ local PlayerY = a_Player:GetPosY()
+ local PlayerZ = a_Player:GetPosZ()
+ local World = a_Player:GetWorld()
+ local Range = 12
+ for x = 0, Range do for z = 0, Range do
+ local px = PlayerX + x - Range / 2
+ local pz = PlayerZ + z - Range / 2
+ local Items = cItems()
+ Items:Add(PossibleItems[math.random(#PossibleItems)])
+ World:SpawnItemPickups(Items, px, PlayerY, pz, 0)
+ end end -- for z, for x
+ return true
+end
+
+
+
+
+function HandlePoof(a_Split, a_Player)
+ local PlayerPos = Vector3d(a_Player:GetPosition()) -- Create a copy of the position
+ PlayerPos.y = PlayerPos.y - 1
+ local Box = cBoundingBox(PlayerPos, 4, 2)
+ local NumEntities = 0
+ a_Player:GetWorld():ForEachEntityInBox(Box,
+ function (a_Entity)
+ if not(a_Entity:IsPlayer()) then
+ local AddSpeed = a_Entity:GetPosition() - PlayerPos -- Speed away from the player
+ a_Entity:AddSpeed(AddSpeed * 32 / (AddSpeed:SqrLength() + 1)) -- The further away, the less speed to add
+ NumEntities = NumEntities + 1
+ end
+ end
+ )
+ a_Player:SendMessage("Poof! (" .. NumEntities .. " entities)")
+ return true
+end
+
+
+
+
diff --git a/MCServer/crafting.txt b/MCServer/crafting.txt
index d29344b64..1236ab10e 100644
--- a/MCServer/crafting.txt
+++ b/MCServer/crafting.txt
@@ -40,8 +40,8 @@
# Need to list each of the four log types, otherwise all logs would get converted into apple planks (^0)
-ApplePlanks, 4 = AppleLog, *
-ConiferPlanks, 4 = ConiferLog, *
+OakPlanks, 4 = OakLog, *
+SprucePlanks, 4 = SpruceLog, *
BirchPlanks, 4 = BirchLog, *
JunglePlanks, 4 = JungleLog, *
AcaciaPlanks, 4 = AcaciaLog, *
@@ -67,6 +67,7 @@ DiamondBlock = Diamond, 1:1, 1:2, 1:3, 2:1, 2:2, 2:3, 3:1, 3:2, 3
LapisBlock = LapisLazuli, 1:1, 1:2, 1:3, 2:1, 2:2, 2:3, 3:1, 3:2, 3:3
EmeraldBlock = Emerald, 1:1, 1:2, 1:3, 2:1, 2:2, 2:3, 3:1, 3:2, 3:3
RedstoneBlock = RedstoneDust, 1:1, 1:2, 1:3, 2:1, 2:2, 2:3, 3:1, 3:2, 3:3
+CoalBlock = Coal, 1:1, 1:2, 1:3, 2:1, 2:2, 2:3, 3:1, 3:2, 3:3
QuartzBlock = NetherQuartz, 1:1, 1:2, 1:3, 2:1, 2:2, 2:3, 3:1, 3:2, 3:3
NetherBrick = netherbrickitem, 1:1, 1:2, 2:1, 2:2
Glowstone = GlowstoneDust, 1:1, 1:2, 2:1, 2:2
@@ -147,9 +148,6 @@ StoneBrickStairs, 4 = StoneBrick, 3:1, 2:2, 3:2, 1:3, 2:3, 3:3
RedSandstoneStairs, 4 = RedSandstone, 3:1, 2:2, 3:2, 1:3, 2:3, 3:3
RedSandstoneStairs, 4 = RedSandstone, 3:1, 2:2, 3:2, 1:3, 2:3, 3:3
-# Other
-Carpet = Wool, 1:3, 2:3
-
#******************************************************#
@@ -353,7 +351,7 @@ Clay, 4 = ClayBlock, *
Painting = Stick, 1:1, 1:2, 1:3, 2:1, 2:3, 3:1, 3:2, 3:3 | Wool, 2:2
ItemFrame = Stick, 1:1, 1:2, 1:3, 2:1, 2:3, 3:1, 3:2, 3:3 | Leather, 2:2
-Sign = Planks, 1:1, 2:1, 3:1, 1:2, 2:2, 3:2 | Stick, 2:3
+Sign, 3 = Planks, 1:1, 2:1, 3:1, 1:2, 2:2, 3:2 | Stick, 2:3
Ladder, 3 = Stick, 1:1, 3:1, 1:2, 2:2, 3:2, 1:3, 3:3
GlassPane, 16 = Glass, 1:1, 2:1, 3:1, 1:2, 2:2, 3:2
IronBars, 16 = IronIngot, 1:1, 2:1, 3:1, 1:2, 2:2, 3:2
@@ -451,13 +449,30 @@ PinkWool = Wool, * | PinkDye, *
GrayWool = Wool, * | GrayDye, *
LightGrayWool = Wool, * | LightGrayDye, *
CyanWool = Wool, * | CyanDye, *
-VioletWool = Wool, * | VioletDye, *
+PurpleWool = Wool, * | PurpleDye, *
BlueWool = Wool, * | BlueDye, *
BrownWool = Wool, * | BrownDye, *
GreenWool = Wool, * | GreenDye, *
RedWool = Wool, * | RedDye, *
BlackWool = Wool, * | BlackDye, *
+WhiteCarpet, 3 = WhiteWool, 1:1, 2:1
+OrangeCarpet, 3 = OrangeWool, 1:1, 2:1
+MagentaCarpet, 3 = MagentaWool, 1:1, 2:1
+LightBlueCarpet, 3 = LightBlueWool, 1:1, 2:1
+YellowCarpet, 3 = YellowWool, 1:1, 2:1
+LimeCarpet, 3 = LimeWool, 1:1, 2:1
+PinkCarpet, 3 = PinkWool, 1:1, 2:1
+GrayCarpet, 3 = GrayWool, 1:1, 2:1
+LightGrayCarpet, 3 = LightGrayWool, 1:1, 2:1
+CyanCarpet, 3 = CyanWool, 1:1, 2:1
+PurpleCarpet, 3 = PurpleWool, 1:1, 2:1
+BlueCarpet, 3 = BlueWool, 1:1, 2:1
+BrownCarpet, 3 = BrownWool, 1:1, 2:1
+GreenCarpet, 3 = GreenWool, 1:1, 2:1
+RedCarpet, 3 = RedWool, 1:1, 2:2
+BlackCarpet, 3 = BlackWool, 1:1, 2:1
+
#******************************************************#
# Stained Glass:
#
diff --git a/MCServer/items.ini b/MCServer/items.ini
index 6eb9eee6e..daf366654 100644
--- a/MCServer/items.ini
+++ b/MCServer/items.ini
@@ -1,5 +1,6 @@
[Items]
air=0
+stone=1
rock=1
granite=1:1
polishedgranite=1:2
@@ -7,7 +8,6 @@ diorite=1:3
polisheddiorite=1:4
andesite=1:5
polishedandesite=1:6
-stone=1
grass=2
dirt=3
coarseddirt=3:1
@@ -15,11 +15,11 @@ podzol=3:2
cobblestone=4
cobble=4
planks=5
-appleplanks=5:0
oakplanks=5:0
+appleplanks=5:0
+spruceplanks=5:1
coniferplanks=5:1
pineplanks=5:1
-spruceplanks=5:1
darkplanks=5:1
birchplanks=5:2
lightplanks=5:2
@@ -29,53 +29,59 @@ acaciaplanks=5:4
darkoakplanks=5:5
bigoakplanks=5:5
roofedoakplanks=5:5
-
-
-; Obsolete: do not use "wood", as its meaning is not clear - wiki uses log as wood, we use planks as wood.
-wood=5
-
sapling=6
-applesapling=6:0
oaksapling=6:0
+applesapling=6:0
+sprucesapling=6:1
conifersapling=6:1
pinesapling=6:1
-sprucesapling=6:1
+darkplanks=6:1
birchsapling=6:2
+whitesapling=6:2
junglesapling=6:3
-adminium=7
+redsapling=6:3
+acaciasapling=6:4
+darkoaksapling=6:5
+bigoaksapling=6:5
+roofedoaksapling=6:5
bedrock=7
+adminium=7
water=8
+flowingwater=8
+stationarywater=9
stillwater=9
swater=9
-stationarywater=9
lava=10
+flowinglava=10
+stationarylava=11
stilllava=11
slava=11
-stationarylava=11
sand=12
redsand=12:1
gravel=13
goldore=14
ironore=15
coalore=16
-tree=17
log=17
-applelog=17:0
+tree=17
oaklog=17:0
+applelog=17:0
+sprucelog=17:1
coniferlog=17:1
pinelog=17:1
-sprucelog=17:1
darklog=17:1
birchlog=17:2
whitelog=17:2
junglelog=17:3
leaves=18
-appleleaves=18:0
oakleaves=18:0
+appleleaves=18:0
+spruceleaves=18:1
coniferleaves=18:1
pineleaves=18:1
-spruceleaves=18:1
+darkleaves=18:1
birchleaves=18:2
+whiteleaves=18:2
jungleleaves=18:3
sponge=19
wetsponge=19:1
@@ -85,8 +91,9 @@ lapisblock=22
dispenser=23
sandstone=24
normalsandstone=24:0
-ornamentsandstone=24:1
+chiseledsandstone=24:1
decorativesandstone=24:1
+ornamentsandstone=24:1
smoothsandstone=24:2
noteblock=25
bedblock=26
@@ -101,14 +108,16 @@ deadbush=32
piston=33
pistonextension=34
pistonhead=34
-cloth=35
wool=35
+cloth=35
whitewool=35:0
orangewool=35:1
magentawool=35:2
lightbluewool=35:3
+ltbluewool=35:3
yellowwool=35:4
limewool=35:5
+ltbluewool=35:3
lightgreenwool=35:5
ltgreenwool=35:5
pinkwool=35:6
@@ -122,11 +131,13 @@ lightgraywool=35:8
lightgreywool=35:8
ltgraywool=35:8
ltgreywool=35:8
+silverwool=35:8
cyanwool=35:9
purplewool=35:10
violetwool=35:10
bluewool=35:11
darkbluewool=35:11
+dkbluewool=35:11
brownwool=35:12
greenwool=35:13
darkgreenwool=35:13
@@ -134,14 +145,12 @@ dkgreenwool=35:13
redwool=35:14
blackwool=35:15
dandelion=37
-
-; Renamed in 1.7, use "poppy" instead; kept for compatibility reasons, will be removed later on.
+poppy=38
rose=38
-
flower=38
-poppy=38
blueorchid=38:1
allium=38:2
+azurebluet=38:3
redtulip=38:4
orangetulip=38:5
whitetulip=38:6
@@ -149,11 +158,12 @@ pinktulip=38:7
oxeyedaisy=38:8
brownmushroom=39
redmushroom=40
-gold=41
goldblock=41
-iron=42
+gold=41
ironblock=42
+iron=42
doubleslab=43
+doublestep=43
stonedoubleslab=43:0
sandstonedoubleslab=43:1
wooddoubleslab=43:2
@@ -183,19 +193,19 @@ obsidian=49
torch=50
fire=51
mobspawner=52
-woodstairs=53
oakwoodstairs=53
+woodstairs=53
chest=54
-redstonedust=55
redstonewire=55
+redstonedust=55
diamondore=56
diamondblock=57
workbench=58
crop=59
crops=59
-soil=60
farmland=60
tilleddirt=60
+soil=60
furnace=61
litfurnace=62
signblock=63
@@ -207,11 +217,11 @@ track=66
tracks=66
cobblestonestairs=67
stairs=67
-signblocktop=68
wallsign=68
+signblocktop=68
lever=69
-rockplate=70
stoneplate=70
+rockplate=70
irondoorblock=71
woodplate=72
redstoneore=73
@@ -228,13 +238,13 @@ reedblock=83
jukebox=84
fence=85
pumpkin=86
-netherstone=87
netherrack=87
hellrock=87
-slowsand=88
+netherstone=87
soulsand=88
-lightstone=89
+slowsand=88
glowstone=89
+lightstone=89
portal=90
jackolantern=91
jacko=91
@@ -243,22 +253,39 @@ whitestainedglass=95
orangestainedglass=95:1
magentastainedglass=95:2
lightbluestainedglass=95:3
+ltbluestainedglass=95:3
yellowstainedglass=95:4
limestainedglass=95:5
+lightgreenstainedglass=95:5
+ltgreenstainedglass=95:5
pinkstainedglass=95:6
graystainedglass=95:7
+greystainedglass=95:7
+darkgraystainedglass=95:7
+darkgreystainedglass=95:7
+dkgraystainedglass=95:7
+dkgreystainedglass=95:7
lightgraystainedglass=95:8
+lightgreystainedglass=95:8
+ltgraystainedglass=95:8
+ltgreystainedglass=95:8
+silverstainedglass=95:8
cyanstainedglass=95:9
+purplestainedglass=95:10
violetstainedglass=95:10
bluestainedglass=95:11
+darkbluestainedglass=95:11
+dkbluestainedglass=95:11
brownstainedglass=95:12
greenstainedglass=95:13
+darkgreenstainedglass=95:13
+dkgreenstainedglass=95:13
redstainedglass=95:14
blackstainedglass=95:15
trapdoor=96
silverfishblock=97
-stonebricks=98
stonebrick=98
+stonebricks=98
mossystonebrick=98:1
crackedstonebrick=98:2
chiseledstonebrick=98:3
@@ -288,35 +315,36 @@ endstone=121
dragonegg=122
redstonelamp=123
redstonelampoff=123
+litredstonelamp=124
redstonelampon=124
woodendoubleslab=125
-appledoublewoodslab=125:0
oakwooddoubleslab=125:0
+appledoublewoodslab=125:0
+sprucewooddoubleslab=125:1
coniferwooddoubleslab=125:1
pinewooddoubleslab=125:1
-sprucewooddoubleslab=125:1
darkwooddoubleslab=125:1
birchwooddoubleslab=125:2
whitewooddoubleslab=125:2
junglewooddoubleslab=125:3
acaciawooddoubleslab=125:4
-bigoakwooddoubleslab=125:5
darkoakwooddoubleslab=125:5
+bigoakwooddoubleslab=125:5
roofedwooddoubleslab=125:5
woodenslab=126
-applewoodslab=126:0
oakwoodslab=126:0
+applewoodslab=126:0
+sprucewoodslab=126:1
coniferwoodslab=126:1
pinewoodslab=126:1
-sprucewoodslab=126:1
darkwoodslab=126:1
birchwoodslab=126:2
whitewoodslab=126:2
junglewoodslab=126:3
acaciawoodslab=126:4
-bigoakwoodslab=126:5
darkoakwoodslab=126:5
roofedwoodslab=126:5
+bigoakwoodslab=126:5
cocoabeans=127
sandstonestairs=128
emeraldore=129
@@ -324,9 +352,9 @@ enderchest=130
tripwirehook=131
tripwire=132
emeraldblock=133
+sprucewoodstairs=134
coniferwoodstairs=134
pinewoodstairs=134
-sprucewoodstairs=134
darkwoodstairs=134
birchwoodstairs=135
whitewoodstairs=135
@@ -342,6 +370,7 @@ woodenbutton=143
skeletonhead=144
witherhead=144:1
zombiehead=144:2
+playerhead=144:3
humanhead=144:3
stevehead=144:3
creeperhead=144:4
@@ -365,47 +394,84 @@ whitestainedclay=159
orangestainedclay=159:1
magentastainedclay=159:2
lightbluestainedclay=159:3
+ltbluestainedclay=159:3
yellowstainedclay=159:4
limestainedclay=159:5
+lightgreenstainedclay=159:5
+ltgreenstainedclay=159:5
pinkstainedclay=159:6
graystainedclay=159:7
+greystainedclay=159:7
+darkgraystainedclay=159:7
+darkgreystainedclay=159:7
+dkgraystainedclay=159:7
+dkgreystainedclay=159:7
lightgraystainedclay=159:8
+lightgreystainedclay=159:8
+ltgraystainedclay=159:8
+ltgreystainedclay=159:8
+silverstainedclay=159:8
cyanstainedclay=159:9
+purplestainedclay=159:10
violetstainedclay=159:10
bluestainedclay=159:11
+darkbluestainedclay=159:11
+dkbluestainedclay=159:11
brownstainedclay=159:12
greenstainedclay=159:13
+darkgreenstainedclay=159:13
+dkgreenstainedclay=159:13
redstainedclay=159:14
blackstainedclay=159:15
whitestainedglasspane=160
orangestainedglasspane=160:1
magentastainedglasspane=160:2
lightbluestainedglasspane=160:3
+ltbluestainedglasspane=160:3
yellowstainedglasspane=160:4
limestainedglasspane=160:5
+lightgreenstainedglasspane=160:5
+ltgreenstainedglasspane=160:5
pinkstainedglasspane=160:6
graystainedglasspane=160:7
+greystainedglasspane=160:7
+darkgraystainedglasspane=160:7
+darkgreystainedglasspane=160:7
+dkgraystainedglasspane=160:7
+dkgreystainedglasspane=160:7
lightgraystainedglasspane=160:8
+lightgreystainedglasspane=160:8
+ltgraystainedglasspane=160:8
+ltgreystainedglasspane=160:8
+silverstainedglasspane=160:8
cyanstainedglasspane=160:9
+purplestainedglasspane=160:10
violetstainedglasspane=160:10
bluestainedglasspane=160:11
+darkbluestainedglasspane=160:11
+dkbluestainedglasspane=160:11
brownstainedglasspane=160:12
greenstainedglasspane=160:13
+darkgreenstainedglasspane=160:13
+dkgreenstainedglasspane=160:13
redstainedglasspane=160:14
blackstainedglasspane=160:15
-acacialeaves=161
-bigoakleaves=161:1
+newleaves=161
+acacialeaves=161:0
darkoakleaves=161:1
+bigoakleaves=161:1
roofedoakleaves=161:1
-acacialog=162
-bigoaklog=162:1
+newlog=162
+acacialog=162:0
darkoaklog=162:1
+bigoaklog=162:1
roofedoaklog=162:1
acaciawoodstairs=163
-bigoakwoodstiars=164
darkoakwoodstairs=164
+bigoakwoodstiars=164
roofedoakwoodstairs=164
slimeblock=165
+barrier=166
irontrapdoor=167
prismarine=168
prismarinebricks=168:1
@@ -413,15 +479,58 @@ darkprismarine=168:2
sealantern=169
haybale=170
carpet=171
+whitecarpet=171:0
+orangecarpet=171:1
+magentacarpet=171:2
+lightbluecarpet=171:3
+ltbluecarpet=171:3
+yellowcarpet=171:4
+limecarpet=171:5
+lightgreencarpet=171:5
+ltgreencarpet=171:5
+pinkcarpet=171:6
+graycarpet=171:7
+greycarpet=171:7
+darkgraycarpet=171:7
+darkgreycarpet=171:7
+dkgraycarpet=171:7
+dkgreycarpet=171:7
+lightgraycarpet=171:8
+lightgreycarpet=171:8
+ltgraycarpet=171:8
+ltgreycarpet=171:8
+silvercarpet=171:8
+cyancarpet=171:9
+purplecarpet=171:10
+violetcarpet=171:10
+bluecarpet=171:11
+darkbluecarpet=171:11
+dkbluecarpet=171:11
+browncarpet=171:12
+greencarpet=171:13
+darkgreencarpet=171:13
+dkgreencarpet=171:13
+redcarpet=171:14
+blackcarpet=171:15
hardenedclay=172
+coalblock=173
+packedice=174
+doubleplant=175
+sunflower=175:0
+lilac=175:1
+doubletallgrass=175:2
+doubletallfern=175:3
+rosebush=175:4
+peony=175:5
redsandstone=179
chiseledredsandstone=179:1
smoothredsandstone=179:2
redsandstonestairs=180
-redsandstoneslab=182
+newstoneslab=182
+redsandstoneslab=182:0
+sprucefencegate=183
coniferfencegate=183
pinefencegate=183
-sprucefencegate=183
darkfencegate=183
birchfencegate=184
whitefencegate=184
@@ -430,9 +539,9 @@ darkoakfencegate=186
bigoakfencegate=186
roofedoakfencegate=186
acaciafencegate=187
+sprucefence=188
coniferfence=188
pinefence=188
-sprucefence=188
darkfence=188
birchfence=189
whitefence=189
@@ -453,7 +562,6 @@ redapple=260
bow=261
arrow=262
coal=263
-coalblock=173
charcoal=263:1
diamond=264
ironingot=265
@@ -466,9 +574,9 @@ ironsword=267
woodensword=268
woodsword=268
woodenshovel=269
+woodspade=269
woodshovel=269
woodenspade=269
-woodspade=269
woodenpickaxe=270
woodpickaxe=270
woodenpick=270
@@ -496,8 +604,8 @@ soup=282
goldensword=283
goldsword=283
goldenshovel=284
-goldshovel=284
goldenspade=284
+goldshovel=284
goldspade=284
goldenpickaxe=285
goldpickaxe=285
@@ -508,13 +616,13 @@ goldaxe=286
string=287
feather=288
gunpowder=289
-woodhoe=290
woodenhoe=290
+woodhoe=290
stonehoe=291
ironhoe=292
diamondhoe=293
-goldhoe=294
goldenhoe=294
+goldhoe=294
seeds=295
wheat=296
bread=297
@@ -543,19 +651,24 @@ goldpants=316
goldenboots=317
goldboots=317
flint=318
+porkchop=319
meat=319
pork=319
+cookedporkchop=320
cookedmeat=320
cookedpork=320
painting=321
paintings=321
goldenapple=322
goldapple=322
+notchapple=322:1
enchantedgoldenapple=322:1
enchantedgoldapple=322:1
sign=323
-wooddoor=324
+oakdoor=324
+appledoor=324
woodendoor=324
+wooddoor=324
bucket=325
waterbucket=326
lavabucket=327
@@ -569,32 +682,38 @@ leather=334
milkbucket=335
brick=336
clay=337
-reed=338
sugarcane=338
+reed=338
paper=339
book=340
-slimeorb=341
slimeball=341
+slimeorb=341
storageminecart=342
poweredminecart=343
egg=344
compass=345
fishingrod=346
watch=347
+glowstonedust=348
lightstonedust=348
lightdust=348
-glowstonedust=348
glowdust=348
-rawfish=349
fish=349
+rawfish=349
+rawsalmon=349:1
+clownfish=349:2
+pufferfish=349:3
cookedfish=350
+cookedsalmon=350:1
dye=351
inksac=351:0
blackdye=351:0
-reddye=351:1
rosered=351:1
-greendye=351:2
+reddye=351:1
cactusgreen=351:2
+greendye=351:2
+darkgreendye=351:2
+dkgreendye=351:2
cocoabeans=351:3
browndye=351:3
lapislazuli=351:4
@@ -604,12 +723,13 @@ dkbluedye=351:4
purpledye=351:5
violetdye=351:5
cyandye=351:6
-lightgreydye=351:7
lightgraydye=351:7
-ltgreydye=351:7
+lightgreydye=351:7
ltgraydye=351:7
-greydye=351:8
+ltgreydye=351:7
+silverdye=351:7
graydye=351:8
+greydye=351:8
darkgreydye=351:8
darkgraydye=351:8
dkgreydye=351:8
@@ -675,6 +795,7 @@ goldencarrot=396
skeletonhead=397
witherhead=397:1
zombiehead=397:2
+playerhead=397:3
stevehead=397:3
creeperhead=397:4
carrotonastick=398
@@ -709,30 +830,46 @@ banner=425
blackbanner=415:0
redbanner=415:1
greenbanner=415:2
+darkgreenbanner=415:2
+dkgreenbanner=415:2
brownbanner=415:3
bluebanner=415:4
+darkbluebanner=415:4
+dkbluebanner=415:4
purplebanner=415:5
+violetbanner=415:5
cyanbanner=415:6
-silverbanner=415:7
lightgraybanner=415:7
+lightgreybanner=415:7
+ltgraybanner=415:7
+ltgreybanner=415:7
+silverbanner=415:7
graybanner=415:8
+greybanner=415:8
+darkgraybanner=415:8
+darkgreybanner=415:8
+dkgraybanner=415:8
+dkgreybanner=415:8
pinkbanner=415:9
limebanner=415:10
+lightgreenbanner=415:10
+ltgreenbanner=415:10
yellowbanner=415:11
lightbluebanner=415:12
+ltbluebanner=415:12
magentabanner=415:13
orangebanner=415:14
whitebanner=415:15
+sprucedoor=427
coniferdoor=427
pinedoor=427
-sprucedoor=427
darkdoor=427
birchdoor=428
whitedoor=428
jungledoor=429
acaciadoor=430
-bigoakdoor=431
darkoakdoor=431
+bigoakdoor=431
roofedoakdoor=431
goldrecord=2256
greenrecord=2257
@@ -748,4 +885,3 @@ wardrecord=2265
-
diff --git a/MCServer/lang/items_de.ini b/MCServer/lang/items_de.ini
new file mode 100644
index 000000000..3c2ab87d1
--- /dev/null
+++ b/MCServer/lang/items_de.ini
@@ -0,0 +1,603 @@
+[Items]
+luft=0
+stein=1
+granit=1:1
+poliertergranit=1:2
+diorit=1:3
+polierterdiorit=1:4
+andesit=1:5
+polierterandesit=1:6
+grasblock=2
+erde=3
+grobeerde=3:1
+podsol=3:2
+bruchstein=4
+holzbretter=5
+eichenholzbretter=5:0
+fichtenholzbretter=5:1
+birkenholzbretter=5:2
+tropenholzbretter=5:3
+akazienholzbretter=5:4
+schwarzeichenholzbretter=5:5
+setzling=6
+eichensetzling=6:0
+fichtensetzling=6:1
+birkensetzling=6:2
+tropensetzling=6:3
+akaziensetzling=6:4
+schwarzeichensetzling=6:5
+grundgestein=7
+wasser=8
+fliessendeswasser=8
+stehendeswasser=9
+stilleswasser=9
+swasser=9
+lava=10
+fliessendelava=10
+stehendelava=11
+stillelava=11
+slava=11
+sand=12
+rotersand=12:1
+kies=13
+golderz=14
+eisenerz=15
+kohleerz=16
+stamm=17
+eichenholz=17:0
+fichtenholz=17:1
+birkenholz=17:2
+tropenholz=17:3
+laub=18
+eichenlaub=18:0
+fichtenlaub=18:1
+birkenlaub=18:2
+tropenlaub=18:3
+schwamm=19
+nasserschwamm=19:1
+glas=20
+lapislazulierz=21
+lapislazuliblock=22
+werfer=23
+sandstein=24
+normalersandstein=24:0
+gemeisseltersandstein=24:1
+glattersandstein=24:2
+notenblock=25
+bettblock=26
+antriebsschiene=27
+sensorschiene=28
+klebrigerkolben=29
+spinnenweben=30
+gras=31
+gras=31:1
+farn=31:2
+toterbusch=32
+kolben=33
+kolbenkopf=34
+wolle=35
+weissewolle=35:0
+orangenewolle=35:1
+magentawolle=35:2
+hellblauewolle=35:3
+gelbewolle=35:4
+hellgruene=35:5
+rosawolle=35:6
+grauwool=35:7
+greywool=35:7
+grauewolle=35:7
+hellgrauewolle=35:8
+tuerkisewolle=35:9
+violettewolle=35:10
+blauewolle=35:11
+braunewolle=35:12
+gruenewolle=35:13
+rotewolle=35:14
+schwarzewolle=35:15
+loewenzahn=37
+blume=38
+mohn=38:0
+blaueorchidee=38:1
+sternlauch=38:2
+porzellansternchen=38:3
+rotetulpe=38:4
+orangenetulpe=38:5
+weissetulpe=38:6
+rosatulpe=38:7
+margerite=38:8
+braunerpilz=39
+roterpilz=40
+goldblock=41
+eisenblock=42
+doppelstufe=43
+doppelsteinstufe=43:0
+doppelsandsteinstufe=43:1
+doppelholzstufe=43:2
+doppelbruchsteinstufe=43:3
+doppelziegelstufe=43:4
+doppelsteinziegelstufe=43:5
+doppelnetherziegelstufe=43:6
+doppelquarzstufe=43:7
+stufe=44
+steinstufe=44:0
+sandsteinstufe=44:1
+holzstufe=44:2
+bruchsteinstufe=44:3
+ziegelstufe=44:4
+steinziegelstufe=44:5
+netherziegelstufe=44:6
+quarzstufe=44:7
+ziegelsteine=45
+tnt=46
+buecherregal=47
+bemoosterbruchstein=48
+obsidian=49
+fackel=50
+feuer=51
+monsterspawner=52
+eichenholztreppe=53
+kiste=54
+rotstonekabel=55
+diamanterz=56
+diamantblock=57
+werkbank=58
+ernte=59
+farmland=60
+ofen=61
+brennenderofen=62
+schildblock=63
+holztuerblock=64
+leiter=65
+schiene=66
+bruchsteintreppe=67
+wandschild=68
+schalter=69
+steindruckplatte=70
+eisentuerblock=71
+holzdruckplatte=72
+rotstoneerz=73
+leuchtendesrotstoneerz=74
+erloschenerotstonefackel=75
+rotstonefackel=76
+setinknopf=77
+schnee=78
+eis=79
+schneeblock=80
+kaktus=81
+ton=82
+zuckerrohrblock=83
+plattenspieler=84
+eichenholzzaun=85
+kuerbis=86
+netherstein=87
+selensand=88
+leuchtstein=89
+portal=90
+kürbislaterne=91
+kuchenlock=92
+weissesglas=95
+orangenesglas=95:1
+magentaglas=95:2
+hellblauesglas=95:3
+gelbesglas=95:4
+hellgruenesglas=95:5
+rosagerfaerbtglas=95:6
+grauesglas=95:7
+hellgrauesglas=95:8
+tuerkisesglas=95:9
+violettesglas=95:10
+blauesglas=95:11
+braunesglas=95:12
+gruenesglas=95:13
+rotesglas=95:14
+schwarzesglas=95:15
+falltuer=96
+silberfischblock=97
+steinziegel=98
+bemoostesteinziegel=98:1
+rissigesteinziegel=98:2
+gemeisseltesteinziegel=98:3
+braunerpilzblock=99
+roterpilzblock=100
+eisengitter=101
+glasscheibe=102
+melone=103
+kuerbispflanze=104
+melonenpflanze=105
+ranken=106
+eichenholzzauntor=107
+ziegeltreppe=108
+steinziegeltreppe=109
+myzel=110
+seerosenblatt=111
+netherziegel=112
+netherziegelzaun=113
+netherziegeltreppe=114
+netherwarzenblock=115
+zaubertisch=116
+braustandblock=117
+kesselblock=118
+endportal=119
+endportalrahmen=120
+endstein=121
+drachenei=122
+redstonelampe=123
+erlosscheneredstonelampe=124
+doppelholzstufe=125
+doppeleichenholzstufe=125:0
+doppelfichtenholzstufe=125:1
+doppelbirkenholzstufe=125:2
+doppeltropenholzstufe=125:3
+doppelakazienholzstufe=125:4
+doppelschwarzeichenstufe=125:5
+holzstufe=126
+eichenholzstufe=126:0
+fichtenholzstufe=126:1
+birkenholzstufe=126:2
+tropenholzstufe=126:3
+akazienholzstufe=126:4
+schwarzeichenholzstufe=126:5
+kakaobohnen=127
+sandsteintreppe=128
+smaragderz=129
+endertruhe=130
+haken=131
+stolperdraht=132
+smaragdblock=133
+fichtenholztreppe=134
+birkenholztreppe=135
+tropenholztreppe=136
+kommandoblock=137
+leuchtfeuer=138
+bruchsteinmauer=139
+bemoostebruchsteinmauer=139:1
+blumentopfblock=140
+karottenpflanze=141
+kartoffelpflanze=142
+knopf=143
+skelettschaedel=144
+witherskelettschaedel=144:1
+zombieschaedel=144:2
+schaedel=144:3
+creeperschaedel=144:4
+amboss=145
+redstonetruhe=146
+waegeplatteniedrigegewichte=147 # WTF, that names are so stupid...
+waegeplattehohegewichte=148
+inaktiverkomparator=149
+aktiverkomparator=150
+tageslichtsensor=151
+redstoneblock=152
+netherquarzerz=153
+trichter=154
+quarzblock=155
+gemeisselterquarzblock=155:1
+quarzsaeule=155:2
+quarztreppe=156
+aktivierungsschiene=157
+spender=158
+weissgerfaerbterton=159
+orangegerfaerbterton=159:1
+magentagerfaerbterton=159:2
+hellblaugerfaerbterton=159:3
+gelbgerfaerbterton=159:4
+hellgruengerfaerbterton=159:5
+rosagerfaerbterton=159:6
+graugerfaerbterton=159:7
+hellgraugefaerbterton=159:8
+tuerkisgerfaerbterton=159:9
+purplegerfaerbterton=159:10
+violettegerfaerbterton=159:10
+blaugerfaerbterton=159:11
+braungerfaerbterton=159:12
+gruengerfaerbterton=159:13
+rotgerfaerbterton=159:14
+schwarzgerfaerbterton=159:15
+weisseglasscheibe=160
+orangeneglasscheibe=160:1
+magentaglasscheibe=160:2
+hellblaueglasscheibe=160:3
+gelbeglasscheibe=160:4
+hellgrueneglasscheibe=160:5
+rosaglasscheibe=160:6
+graueglasscheibe=160:7
+hellgraueglasscheibe=160:8
+tuerkiseglasscheibe=160:9
+violetteglasscheibe=160:10
+blaueglasscheibe=160:11
+brauneglasscheibe=160:12
+grueneglasscheibe=160:13
+roteglasscheibe=160:14
+schwarzeglasscheibe=160:15
+neueslaub=161
+akazienlaub=161:0
+schwarzeichenlaub=161:1
+neuestaemme=162
+akazienholz=162:0
+schwarzeichenholz=162:1
+akazientreppe=163
+schwarzeichentreppe=164
+schleimblock=165
+bartriere=166
+eisenfalltür=167
+prismarin=168
+prismarinziegel=168:1
+dunklerprismarin=168:2
+seelaterne=169
+strohballen=170
+teppich=171
+weisserteppich=171:0
+orangenerteppich=171:1
+magentateppich=171:2
+hellblauerteppich=171:3
+gelberteppich=171:4
+hellgruenerteppich=171:5
+rosateppich=171:6
+grauerteppich=171:7
+hellgrauerteppich=171:8
+tuerkiserteppich=171:9
+violetterteppich=171:10
+blauerteppich=171:11
+braunerteppich=171:12
+gruenerteppich=171:13
+roterteppich=171:14
+schwarzerteppich=171:15
+gebrannterton=172
+kohleblock=173
+packeis=174
+doppelpflanze=175
+sonnenblume=175:0
+Flieder=175:1
+hohesgras=175:2
+grosserfarn=175:3
+rosenstrauch=175:4
+pfingstrose=175:5
+rotersandstein=179
+gemeisselterrotersandstein=179:1
+glatterrotersandstein=179:2
+rotesandsteintreppe=180
+neuesteinstufe=182
+rotesandsteinstufe=182:0
+fichtenzauntor=183
+birkenzauntor=184
+tropenzauntor=185
+schwarzeichenzauntor=186
+akazienzauntor=187
+fichtenzaun=188
+birkenzaun=189
+tropenzaun=190
+schwarzeichenzaun=191
+akazienzaun=192
+eisenschaufel=256
+eisenspitzhacke=257
+eisenaxt=258
+feuerzeug=259
+apfel=260
+bogen=261
+pfeil=262
+kohle=263
+holzkohle=263:1
+diamant=264
+eisenbarren=265
+goldbarren=266
+eisenschwert=267
+holzschwert=268
+holzschaufel=269
+holzspitzhacke=270
+holzaxt=271
+steinschwert=272
+steinschaufel=273
+steinspitzhacke=274
+steinaxt=275
+diamantschwert=276
+diamantschaufel=277
+diamantspitzhacke=278
+diamantaxt=279
+stock=280
+schuessel=281
+pilzsuppe=282
+goldschwert=283
+goldschaufel=284
+goldspitzhacke=285
+goldaxt=286
+faden=287
+feder=288
+schwarzpulver=289
+holzhacke=290
+steinhacke=291
+eisenhacke=292
+diamanthacke=293
+goldhacke=294
+samen=295
+weizen=296
+brot=297
+lederkappe=298
+lederjacke=299
+lederhose=300
+lederstiefel=301
+kettenhaube=302
+kettenhemd=303
+kettenhose=304
+kettenstiefel=305
+eisenhelm=306
+eisenbrustplatte=307
+eisenbeinschutz=308
+eisenstiefel=309
+diamanthelm=310
+diamantbrustplatte=311
+diamantbeinschutz=312
+diamantstiefel=313
+goldhelm=314
+goldharnisch=315
+goldbeinschutz=316
+goldstiefel=317
+goldboots=317
+feuerstein=318
+rohesschweinefleisch=319
+gebratenesschweinefleisch=320
+gemaelde=321
+goldenerapfel=322
+goldenerapfel=322:1
+schild=323
+eichenholztuer=324
+eimer=325
+wassereimer=326
+lavaeimer=327
+lore=328
+sattel=329
+eisentuer=330
+redstone=331
+schneeballl=332
+boot=333
+leder=334
+milcht=335
+ziegel=336
+ton=337
+zuckercane=338
+papier=339
+buch=340
+schleimball=341
+gueterlore=342
+angetriebenelore=343
+ei=344
+kompass=345
+angel=346
+uhr=347
+glowstonestaub=348
+fisch=349
+roherfisch=349
+roherlachs=349:1
+clownfisch=349:2
+kugelfisch=349:3
+gebratenerfisch=350
+gebratenerlachs=350:1
+farbe=351
+tintenbeutel=351:0
+rosenrot=351:1
+kaktusgruen=351:2
+kakaobohnen=351:3
+lapislazuli=351:4
+violetterfarbstoff=351:5
+tuerkiserfarbstoff=351:6
+hellgrauerfarbstoff=351:7
+grauerfarbstoff=351:8
+rosafarbstoff=351:9
+hellgruenerfarbstoff=351:10
+gelberfarbstoff=351:11
+hellblauerfarbstoff=351:12
+magentafarbstoff=351:13
+orangenerfarbstoff=351:14
+knochenmehl=351:15
+knochen=352
+zucker=353
+kuchen=354
+bett=355
+redstoneverstaerker=356
+keks=357
+karte=358
+schere=359
+melone=360
+kürbiskerne=361
+melonenkerne=362
+rohesrindfleisch=363
+steak=364
+roheshühnchen=365
+gebrateneshühnchen=366
+verrottetesfleisch=367
+enderperle=368
+lohenrute=369
+ghasttraene=370
+goldnugget=371
+netherwarze=372
+trank=373
+glasflasche=374
+spinnenauge=375
+fermentiertesspinnenauge=376
+lohenstaub=377
+magmacreme=378
+braustand=379
+kessel=380
+enderauge=381
+glitzerndemelone=382
+spawnei=383
+erfahrungsfläschchen=384
+feuerkugel=385
+buchundfeder=386
+beschriebenesbuch=387
+smaragd=388
+rahmen=389
+blumentopf=390
+karotte=391
+kartoffel=392
+ofenkartoffel=393
+giftigekartoffel=394
+leerekarte=395
+goldenekarotte=396
+skelettschaedel=397
+witherschaedel=397:1
+zombieschaedel=397:2
+kopf=397:3
+creeperschaedel=397:4
+karottenrute=398
+netherstern=399
+kuerbiskuchen=400
+feuerwerksrakete=401
+feuerwerksstern=402
+verzauberungsbuch=403
+redstonekomparator=404
+netherziegelitem=405
+netherquarz=406
+tntlore=407
+trichterlore=408
+prismarinscherbe=409
+prismarinkristalle=410
+roheskaninchen=411
+gebrateneskaninchen=412
+kaninchenragout=413
+hasenpfote=414
+kaninchenfell=415
+ruestungsstaender=416
+eisernepferderuestung=417
+goldenepferderuestung=418
+diamantenepferderuestung=419
+leine=420
+namensschild=421
+kommandoblocklore=422
+roheshammelfleisch=423
+gebrateneshammelfleisch=424
+banner=425
+schwarzesbanner=415:0
+rotesbanner=415:1
+gruenesbanner=415:2
+braunbanner=415:3
+blauesbanner=415:4
+violettesbanner=415:5
+tuerkisesbanner=415:6
+hellgrauesbanner=415:7
+grauesbanner=415:8
+rosabanner=415:9
+hellgruenesbanner=415:10
+gelbesbanner=415:11
+hellblauesbanner=415:12
+magentabanner=415:13
+orangenesbanner=415:14
+weissesbanner=415:15
+fichtenholztuer=427
+birkenholztuer=428
+tropentuer=429
+akazientuer=430
+schwarzeichentuer=431
+goldeneschallplatte=2256
+grueneschallplatte=2257
+blocksschallplatte=2258
+chirpschallplatte=2259
+farschallplatte=2260
+mallschallplatte=2261
+mellohischallplatte=2262
+stalschallplatte=2263
+stradschallplatte=2264
+wardschallplatte=2265
+11schallplatte=2266
+
+
+
diff --git a/MCServer/webadmin/files/background.gif b/MCServer/webadmin/files/background.gif
new file mode 100644
index 000000000..cab9bed56
--- /dev/null
+++ b/MCServer/webadmin/files/background.gif
Binary files differ
diff --git a/MCServer/webadmin/files/favicon.ico b/MCServer/webadmin/files/favicon.ico
new file mode 100644
index 000000000..ea4bde926
--- /dev/null
+++ b/MCServer/webadmin/files/favicon.ico
Binary files differ
diff --git a/MCServer/webadmin/files/logo.png b/MCServer/webadmin/files/logo.png
new file mode 100644
index 000000000..50733e824
--- /dev/null
+++ b/MCServer/webadmin/files/logo.png
Binary files differ
diff --git a/MCServer/webadmin/files/mc-logo.png b/MCServer/webadmin/files/mc-logo.png
new file mode 100644
index 000000000..9a77a490f
--- /dev/null
+++ b/MCServer/webadmin/files/mc-logo.png
Binary files differ
diff --git a/MCServer/webadmin/files/style.css b/MCServer/webadmin/files/style.css
new file mode 100644
index 000000000..e7ffe3999
--- /dev/null
+++ b/MCServer/webadmin/files/style.css
@@ -0,0 +1,326 @@
+/* reset CSS */
+
+html, body, div, span, applet, object, iframe,
+h1, h2, h3, h4, h5, h6, p, blockquote, pre,
+a, abbr, acronym, address, big, cite, code,
+del, dfn, em, font, img, ins, kbd, q, s, samp,
+small, strike, strong, sub, sup, tt, var,
+b, u, i, center,
+dl, dt, dd, ol, ul, li,
+fieldset, form, label, legend,
+table, caption, tbody, tfoot, thead, tr, th, td {
+ margin: 0;
+ padding: 0;
+ border: 0;
+ outline: 0;
+ font-size: 100%;
+ vertical-align: baseline;
+ background: transparent;
+}
+body {
+ line-height: 1;
+}
+ol, ul {
+ list-style: none;
+}
+blockquote, q {
+ quotes: none;
+}
+
+/* remember to define focus styles! */
+:focus {
+ outline: 0;
+}
+
+/* remove textarea resize at Safari */
+textarea {
+ resize: none;
+}
+
+/* remember to highlight inserts somehow! */
+ins {
+ text-decoration: none;
+}
+del {
+ text-decoration: line-through;
+}
+
+/* tables still need 'cellspacing="0"' in the markup */
+table {
+ border-collapse: collapse;
+ border-spacing: 0;
+}
+
+
+/*
+ Origional from http://www.perspectived.com/
+ Modified by Ben Phelps
+ Made for FakeTruth - MCServer
+*/
+
+/* Basic ---------------------------------------- */
+
+.clear { clear: both; }
+
+body {
+ background: white;
+ font-family: Arial, Helvetica, sans-serif;
+ font-size: 12px;
+ color: #646464;
+ text-align: center;
+}
+
+#wrapper {
+ text-align: left;
+ width: 930px;
+ margin: 0 auto;
+}
+
+/* Logo ---------------------------------------- */
+
+h1 {
+ margin: 15px 0 10px 5px;
+ width: 180px;
+ height: 36px;
+ background: url(logo.png) no-repeat left top;
+}
+
+h1 a {
+ display: block;
+ width: 225px;
+ height: 28px;
+}
+
+h1 span { display: none; }
+
+a {
+ color: #646464;
+}
+
+/* Container ---------------------------------------- */
+
+#containerHolder {
+ background: #eee;
+ padding: 5px;
+}
+
+
+#container {
+ background: #fff url(background.gif) repeat-y left top;
+ border: 1px solid #ddd;
+ width: 918px;
+
+}
+
+#connectHolder {
+ background: #eee;
+ padding: 5px;
+ margin-bottom:8px;
+}
+
+
+#connect {
+ border: 1px solid #ddd;
+ background-color: #fff;
+ padding:5px;
+ width: 908px;
+}
+
+.pics {
+ height: 375px;
+ width: 600px;
+}
+
+.pics img {
+ padding: 5px;
+ border: 1px solid #ddd;
+ background-color: #eee;
+ width: 600px;
+ height: 375px;
+ margin-left: 15px;
+}
+
+/* Login -------------------------------------- */
+
+#loginLogo {
+ margin: 0 auto;
+ margin-top:100px;
+ width: 180px;
+ height: 36px;
+ background-image: url(logo.png);
+}
+
+#loginHolder {
+ background: #eee;
+ padding: 5px;
+ width: 310px;
+ margin: 0 auto;
+ height: 90px;
+ margin-top:20px;
+}
+
+#login {
+ padding:10px;
+ width: 288px;
+ height: 68px;
+ border: 1px solid #ddd;
+ background:#fff;
+ text-align: left;
+}
+
+
+/* Sidebar ---------------------------------------- */
+
+#sidebar {
+ width: 179px;
+ float: left;
+}
+
+#sidebar .sideNav { width: 179px; }
+
+#sidebar .sideNav li { border-bottom: 1px solid #ddd; width: 179px; }
+
+#sidebar .sideNav li a {
+ display: block;
+ color: #646464;
+ background: #f6f6f6;
+ text-decoration: none;
+ height: 29px;
+ line-height: 29px;
+ padding: 0 19px;
+ width: 141px;
+}
+
+#sidebar .sideNav li a:hover { background: #fdfcf6; }
+
+#sidebar .sideNav li a.active, #sidebar .sideNav li a.active:hover {
+ background: #f0f7fa;
+ color: #c66653;
+}
+
+/* Breadcrumb ---------------------------------------- */
+
+h2 {
+ width: 718px;
+ float: right;
+ color: #646464;
+ font-size: 16px;
+ line-height: 16px;
+ font-weight: bold;
+ margin: 20px 0 0 0;
+ padding: 0 0 10px 0;
+ border-bottom: 1px solid #ddd;
+}
+
+h2 a {
+ color: #646464;
+ text-decoration: none;
+}
+
+h2 a.active { color: #c66653; }
+
+h2 a:hover { text-decoration: underline; }
+
+/* Content ---------------------------------------- */
+
+#main {
+ width: 700px;
+ float: right;
+ padding: 0 19px 0 0;
+}
+
+#main p {
+
+ padding: 10px;
+
+}
+
+h3 {
+ font-size: 14px;
+ line-height: 14px;
+ font-weight: bold;
+ color: #5494af;
+ padding: 0 0 0 10px;
+ margin: 20px 0 10px;
+}
+
+h4 {
+ padding: 0 0 0 10px;
+ margin: 20px 0 10px;
+}
+
+#main ul {
+ padding: 0 0 0 10px;
+ list-style-type: circle;
+ list-style-position: inside;
+}
+
+#main table {
+ border-top: 1px solid #ddd;
+ width: 700px;
+}
+
+#main table tr th {
+ text-align: left;
+ background: #f6f6f6;
+ padding: 0px 20px;
+ height: 20px;
+ line-height: 20px;
+ border-bottom: 1px solid #ddd;
+}
+
+#main table tr td {
+ background: #f6f6f6;
+ padding: 0px 20px;
+ height: 29px;
+ line-height: 29px;
+ border-bottom: 1px solid #ddd;
+}
+
+#main table tr.odd td {
+ background: #fbfbfb;
+}
+
+#main table tr:hover td { background: #fdfcf6; }
+
+#main table .action {
+ text-align: right;
+ padding: 0 20px 0 10px;
+}
+
+#main table tr .action a { margin: 0 0 0 10px; text-decoration: none; color: #9b9b9b; }
+#main table tr:hover .action .edit { color: #c5a059; }
+#main table tr:hover .action .delete { color: #a02b2b; }
+#main table tr:hover .action .view { color: #55a34a; }
+
+#main table tr:hover .action a:hover { text-decoration: underline; }
+
+fieldset {
+ border: 1px solid #ddd;
+ padding: 19px;
+ margin: 0 0 20px 0;
+ background: #fbfbfb;
+}
+
+form p { margin: 0 0 14px 0; float: left; width: 100%; }
+
+label {
+ display: block;
+ width: 100%;
+ margin: 0 0 7px 0;
+ line-height: 12px;
+}
+
+/* Footer ---------------------------------------- */
+
+#footer {
+ margin: 10px 0 30px 0;
+ font-size: 11px;
+ line-height: 11px;
+ color: #9B9B9B;
+ padding: 0 0 0 5px;
+}
+
+#footer a { color: #9B9B9B; }
+
+#footer a:hover { text-decoration: none; }
diff --git a/MCServer/webadmin/login_template.html b/MCServer/webadmin/login_template.html
new file mode 100644
index 000000000..913a85db0
--- /dev/null
+++ b/MCServer/webadmin/login_template.html
@@ -0,0 +1,25 @@
+<html>
+<head>
+ <title>MCServer WebAdmin - Login</title>
+ <meta charset="UTF-8">
+ <link rel="icon" href="favicon.ico">
+ <style type="text/css">
+ header {
+ margin: 0 auto;
+ text-align: center;
+ vertical-align: middle;
+ }
+ </style>
+</head>
+
+<body>
+ <header>
+ <img src="mc-logo.png" alt="MCServer Logo" class="logo">
+ <h1>MCServer - WebAdmin</h1>
+ <form method="get" action="webadmin/">
+ <input type="submit" value="Log in">
+ </form>
+ </header>
+</body>
+
+</html>
diff --git a/MCServer/webadmin/template.lua b/MCServer/webadmin/template.lua
index a066d8b33..a7480f83e 100644
--- a/MCServer/webadmin/template.lua
+++ b/MCServer/webadmin/template.lua
@@ -57,7 +57,7 @@ end
function ShowPage(WebAdmin, TemplateRequest)
SiteContent = {}
local BaseURL = WebAdmin:GetBaseURL(TemplateRequest.Request.Path)
- local Title = "MCServer"
+ local Title = "MCServer WebAdmin"
local MemoryUsageKiB = cRoot:GetPhysicalRAMUsage()
local NumChunks = cRoot:Get():GetTotalChunkCount()
local PluginPage = WebAdmin:GetPage(TemplateRequest.Request)
@@ -74,339 +74,9 @@ function ShowPage(WebAdmin, TemplateRequest)
<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<link rel="icon" href="data:application/octet-stream;base64,AAABAAIAEBAAAAEAIABoBAAAJgAAACAgAAABACAAqBAAAI4EAAAoAAAAEAAAACAAAAABACAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQEBAQQAAAAAAgIDBRghJ5o5TlumCg0QCQAAAAABAgIEAAEBAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAEBAgAAAAMAAAAACQwPMxsnL88jMz3/S2d6/0xoetcaIig6AAAAAAEBAQMBAQEDAAAAAAAAAAAAAAAAAQEBAwAAAAAEAwMEFhwhgRomMPwfLTj/IC86/DJHWPxKaH3/TGN0/jk+QYgEBgcFAAAAAAEBAgMAAAAAAAAAAgAAAAAKDRAuHSMpzB8rNP8dKTP8FiIp/QkXGv8sSEr/QV1u/UhnefxWdIb/P1dm0BIYHDEAAAAAAAEBAgAAAAARGB1oIC44/R0rNf8PGiL7DxUa/gwdHv8JKSP/HUdC/x9HQf81W17+Qllv+0lkef9ObYH+Ii42bAAAAAAAAAAAFyIqyBopMf8THSX6BRkY/wIbGP8HHhv/FTs1/yJhVP8lZ1b/H05I/xcuNf8jPET6UWp+/0xqfdAAAAAAAQECBxEcI9oOHh//BRgV/QwsJv8NKyb/EDEr/xU3Mv8zeW7/MHpr/ydqXP8oalz/HVtO/i9KUf9AW2zgBwkLDQEEBBgKGhfuCCMd/w4uKf4RNC7/FTcy/w8yLv8PMi7/LXFn/y55av86gW//OoV7/y11av4YTkj/GkFB8gUICh4BCActCSUf+xAxKv8TNjD/EzYx/w8xLP8PMCr/Fjgy/zp+c/8yfXP/OoN5/zN9cf86hHb/NHlt/y1xZP4LGhc0BhEORQ8zLP8SNC7+EDIt/xEzLf8PMCv/DTAs/w4xKv8vdWT/PYh4/y93bf8sdWj/N4R3/zWBdv43hHn/EysoTQgXFWEQMy//DzEs/Q8xK/8SNC3/FjUv/xEuK/8WPjf/OIBw/0OEdP83e27/N31w/zN8bP8vdWj8Mn5z/xg3MmgLHRp8FDkz/xExLPwNKyT/EjIs/xpEPP8kX1T/OY2C/0KVhv8zgG//NH9z/zuBdf8xeGX/PIF1/DSAdf8cRDyEDCMenBEvJ/8VODT4IVZM/C11af06inv/QZaG/z2Rgf84iXz/O5F+/z2Nff85iX3+OYJ2/DuBdPg5g3X/IVBIohIzLaUydGb/RJiJ/TyYiv88k4P/O4t6/j+Rg/w+j3/9PYt5/TyOgfwuhHf+Nox+/zyViP9Aloj9Q5WC/yxiVa0ECgkHEyciLh1BOWwsZV2sN39y4juNfv5Cmon/O5OF/z2Shf86kYT/NoyA/ziGeeUqZlywHEI8chAjHzQDBwUKAAAAAAAAAAAAAAAAAAAAAAQIBwsSKCQ9JU9GgDN2a8owdGjLH0xFghMpJUAFDAsNAAAAAAAAAAAAAAAAAAAAAP5/AAD8PwAA8A8AAOAHAADAAwAAgAEAAIABAACAAQAAgAEAAIABAACAAQAAgAAAAAAAAAAAAAAA4AcAAPw/AAAoAAAAIAAAAEAAAAABACAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQEBBAAAAAEAAAAAGB4leTRGUpAICQsDAAAAAAECAgQAAAEBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEBAgABAQQAAAAADA4RHRsjK7UaJi7/U3SH/1Z1isgbJCosAAAAAAEBAgMBAQECAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEBAQMAAAABAAAAABgeJGEkMz3wHSw1/yExOvxLaHn8TWuA/2SJovkzRVB1AAAAAAAAAAACAgIEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEBAQIBAQEEAAAAAAoLDhkcJS2xHy03/xkmL/0fLjb8IC85/0FabP9IZHX8O1Jj/GCFnP9KZHTBEhccIwAAAAABAQIEAQEBAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAQEDAAAAAgAAAAAXHSJZICw27BQeJv8aJzD7JTZC/iQ1P/8nOUX/JzpJ/0hjdf9FX3H+V3iO+01tgv9Wanj0R0dHZwAAAAAAAAABAQICAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQEBAQEBBAAAAAAMDAwUJCouqSAwOv8XIir9Exwj/CM0P/8eLDf/IzM+/xclLv8oPlD/NUla/0Vhc/9EXnH/OU5f/DxPX/xudHn/Ulxjtg8WGxsAAAAAAQICBAEBAQIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQEBAwAAAAIAAAAAFhofUTI0NugdJSv/Gicw+yQ0P/0YJC7/GCQt/xEbJP8QGSD/CxUb/yhMTf9AWmz/PVds/z5Xaf8+VWf/Q15x/jtTZPtJX3D/VneK7iUxOlsAAAAAAAAAAgECAgMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIAAAAACAkLER4oMKIdKTL/GCEn/RQfJ/weLDb/Gigy/x0lLP8aJS7/DiAj/wgOE/8HFRn/Gks8/0BNS/8xUFv/VXyS/0ZseP9Ye5D/XH+U/0Zhc/xFX3L9SGN2/ztPXqkPFBYUAAAAAAEBAQIAAAAAAAAAAAAAAAAAAAABAAAAABUbIUoqOkbjHy43/xIcJPseLTb9Gicv/xQgKP8NEhn/ISIk/xYkKv8MKyP/Bh0b/wYiHf8RQzz/JTE2/yNYT/8tTVX/KVRM/1N5if9dgJj/RmBy/0pmev1KZXn7Qltt/1NxhOcgKjJOAAAAAAAAAAEAAAAAAQEBBAAAAAATGiBhIjE8/xwrNPwXIyv8His1/yMzPf8OFh7/BgwS/wQSEv8IDxT/CxQa/wUfG/8HJyL/ES0m/ylrYv8YPD//E0I2/xg8Mv8UQTP/LklT/zJHWf80Slv/Ql1x/1yAmP8/VWf8Smd7/E5rgP8fKTFuAAAAAAEBAQQAAQEEAAAAABYhJ5QaJy//FSAo+RglLv8iMz3/Ex8o/wUOEv8GIR3/BB8a/wQYFv8EEBL/Ax4a/wsqJv8VODL/JGhY/xhXTP8kWUv/KWNT/ypuWf8aMDX/HCU0/yEwPv8iMD7/M0dY/0FdcP9egpr6W36T/zlQXacAAAAAAQEBBAAAAAMAAAAAFR8mrR0rNP8YJCz8Fykt/xYiKv8FCRD/BRkY/wglIf8FHhr/AxsY/wYhHf8PKyb/FTo2/xU7N/8ralj/IGRY/ydpV/8wdWr/JW1g/xw9P/8dSkn/FjQ0/xQ/O/8aMDf/TVhi/0ljdvxYe5D/R2NyvgAAAAAAAAACAAAAAQAAAAANFRzGEh0m/x0uN/wKHRn/Bg4T/wMUEv8JJyH/Dy0p/wYjH/8IJB//Gjsz/xQyK/8TNDD/DjMu/z96a/8veG3/J3Fg/zd8b/8oa1//FExD/yhjVv8aWEb/ImRa/xhXTv86SUz/QlNl/Uhmff9bfpPWAAAAAAAAAAAAAAAAAQIDAxEaI9wSIyj/CBYW/QYWE/8HGRr/CSsi/wosI/8RMSz/ES4o/wwtKP8QMy7/Cisn/w8uKv8YNzD/Pod9/zB/df82e3L/Mnho/yduWP8ueW3/N3Zq/ypyZf8nbV3/IFxT/xE4Of8zT1z+Mldc/ztRY+kHCwwNAAAAAAAAAAABBQUSER0d7wwcGP8IIxv+CSId/wsgHP8QMiz/EjYx/w4vKv8XODP/EjIu/w4yLv8KLir/Cywn/w8wKv8qcWj/MH50/ylzYf8ve2j/JnFb/zh+bf8+hHr/LXhu/zJ+bf8wcGf/E09G/x4/Qv4jVEz/IS8++QcKDR0AAAAAAAAAAAEIBiUGFBP+BxgU/wsrJP4HJSD/ES8q/w4xLv8OMi7/FjUu/xM3Mv8XOzf/FDg0/xEzL/8TODT/Cy4q/yRlW/83e3H/KG9g/zSEeP9AhXj/P35u/0GMgf8wf3b/NoR8/yxzaP8hXVT/ED88/xdQSP4gVFL/Bg4QMgAAAAAAAAAAAwsKOgUdGv8NJyH9Dy8p/w8xKf8WOjb/DDEs/xI2MP8UNzD/DTAo/xM2MP8MLib/FTUx/xU1MP8OMy7/PXdo/0KLgP8udW3/JnJo/zyFef9Ai4H/PYd+/y54a/8mcmn/O3xv/zR1aP8obmD/I2JY/CFmWf8LIBpJAAAAAAAAAAAGFBFSCSsk/wssJPwMLib/EjEo/xU3Mv8OMij/HEA4/w4zMP8OMSz/EDAq/wktJ/8NMCv/FDEp/xU3Mf89gnj/PYyA/zyDef8udWv/N4Z8/zB8cv8zd27/LnZj/0GOev9FjYD/OoR7/zuEdv8+gHD7O4Z6/xo2L2IAAAAAAAAAAAcYE20MMCn/EDEr+w4vJv8WODP/EzMv/w8yLP8TODT/DS8q/xAwKv8IKyf/DC8s/w8wK/8MLST/FTQt/zaBdv8pd2P/P4t2/zaEef85e27/Nnpt/y11bP8xeW//QJCD/zyMgf8we2n/N4N6/yduZPtBkYj/Ik5JfAAAAAAAAAAADyMfiBA0Lv8PMiz7GDk1/xAxLf8RMS3/DzIt/xAyLP8PMCf/FzQu/w4vKf8OMC3/EzQv/wgsJ/8JLCf/ImlT/zV3Zf9IkHv/OYh7/yNuaP80e2//KXJp/yNtXf82gnb/MH10/yp3av9AjoX/MH10+zB7cP8eT0mWAAAAAAAAAAARLCiiDjMu/wotJvsTODT/DC8r/wkqJf8PMCj/EDIr/w0yKv8ZOzb/FjUv/xQ2M/8TOjb/DS8r/xk8NP8ocGL/QIV0/0WBcf9Cf3D/Mnhu/zd6bv84e27/KXRk/zh7bP8tdmX/M3lt/zR6bP8veWj8MHxx/y1dUq8AAAAAAAAAAAsnJLsRMi7/DC4q/BU0Lv8OMSz/DS4p/xg4Mv8SNi//ETAq/xs/N/8aPTX/ETEs/xQvKv8YMyv/H05F/yZya/9Km4j/SI+A/zp6a/9Cf23/RYh7/zuGe/86e2v/RYuA/y57af86e2r/J29l/ypyZ/w+jIL/KWVbxwAAAAAAAAAADysn0Rc6Nf8PMS39DS8q/xUzLf8QMiz/DS8l/xEyKv8UNC//EzEs/xAtI/8QMyv/H1FN/zeBeP9CnI//Q5SF/0aRff87h3f/LXVl/yJsWv8xe3T/Q4l+/zh5Zf8reWT/Lnlm/zqHef84fHD/Im9p/Th/dP8pa2HcAAYGBwQIBw4TMy3kFjsy/xI1L/4PMSz/GTo1/xIyKv8KKyL/EzAq/xA0MP8ZQjr/JF1T/zp/cP8xiHb/LIh6/0egkf9Gn5D/NYZ2/ziGcv8whXr/NYuA/zN9dP9Ahnz/Mn91/yNrWP85emb/QYJ3/0SLe/8vd2/+NXpq/zF2ZuwHEREXBxAPIRI3MPQVNSv/GTcw/hY0Lv8UNDH/Cysn/xQ2MP8oX1f/KnFn/0ONf/8yinz/MIh9/z6JeP85in//No+H/yyBdv82iX7/QZOE/yt/aP87jnn/R417/zaFef89kIP/M3dq/0OHev84gXf/R5KA/0KJfv4yf3P/NXhn+hEeGysDDww3EjQr/hcyLP8JJx//Ciwp/yJQSv8ybmD/MYJv/zmUiP8ug3X/QIp8/zyOfP9ElYX/T5yN/0KWhf88i3f/PYh4/ziHfP9El4X/P5aC/zaMf/9Ek4b/M4R2/z2ThP85iX7/Qop9/y+BeP83emz/NHlm/zeCef4mcmn/CyAcQgQTEVQVOTH/GT85/CRYTfstdWr8QJWL/j+Thv8thHT/N4l7/zaIdP85hnL/PI58/zmOfv8+lIb/RZF+/0COe/9AkH7/Qot2/0CTgv8+mI3/MIh2/zOFcv88joL/OY+F/zeFev83in//N4x+/jyFcPw3f237OHpv+0iQf/8fRj1fCh4cTyRkWOxFnIj+TqSR/0idiP9Qo5P/M4N5/Sp9cPs+k4X8RJeL/jqLev8/j37/RpaH/z2SiP84hnn/PZKI/zCHdv86jXz/P46E/zSIfv8xiHv/J31x/y6Eef4rgG/8OYx9+zyPhv05jIH/SZ6Q/1Wyof8/lH//Oohx9yJHPV4AAAAABhAOChw2LzkmTEV3MGxcuDuHdu1Akob/QpuP/0uZiP8yh3r/MIB0/DuKffs4in38PpaD/j6ZjP89kYT/PpCC/0CNgP82g3b+MIV6/S6EevspfHP8Po5//0ihkP8+mon/N4+B/zKCdPM1c2jDH01FhBoyK0YEDQoRAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAQsKDxUuKkIsXliDMnRpwjeEcfRCloH/RJuK/zyRgP9AlIP/PYx+/TKEdvw8kIH8Q5eM/TSLf/8+lYX/SJyM/zuYjf8+lIj3O4F1ySVZU4wWMy1LBhAMFgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAQEBAgIDAQICBAEBAQIAAAAAAAAAAAAAAAAAAAAACxQRFhk2MkomWFGLOXhryEiZhvRElYf/N46G/zCGef9Dk4P/O5CF9SVpYMsrWlCQFzg0UAwZFxoAAAAAAAAAAAAAAAAAAAAAAAAAAgECAgQBAgIDAAEBAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAQEBAgIDAQMCBAEBAQIAAAAAAAAAAAAAAAAAAAAACBcTHx4+OVw5dWmnK2peqBo5Ml0MHBkiAAICAQAAAAAAAAAAAAAAAAABAQEBAgIEAQICAwABAQIAAAAAAAAAAAAAAAAAAAAAAAAAAP//f////D////gf///gB///wAP//wAA//4AAH/4AAAf8AAAD+AAAAfAAAADwAAAA8AAAAPAAAADwAAAA8AAAAPAAAADwAAAA8AAAAOAAAABgAAAAYAAAAGAAAABgAAAAYAAAAGAAAABgAAAAYAAAAHwAAAH/gAAf//gB////n//">
+<link rel="icon" href="/favicon.ico">
<title>]] .. Title .. [[</title>
-
-<style type="text/css" media="screen">
-
- /* reset CSS */
-
- html, body, div, span, applet, object, iframe,
- h1, h2, h3, h4, h5, h6, p, blockquote, pre,
- a, abbr, acronym, address, big, cite, code,
- del, dfn, em, font, img, ins, kbd, q, s, samp,
- small, strike, strong, sub, sup, tt, var,
- b, u, i, center,
- dl, dt, dd, ol, ul, li,
- fieldset, form, label, legend,
- table, caption, tbody, tfoot, thead, tr, th, td {
- margin: 0;
- padding: 0;
- border: 0;
- outline: 0;
- font-size: 100%;
- vertical-align: baseline;
- background: transparent;
- }
- body {
- line-height: 1;
- }
- ol, ul {
- list-style: none;
- }
- blockquote, q {
- quotes: none;
- }
-
- /* remember to define focus styles! */
- :focus {
- outline: 0;
- }
-
- /* remove textarea resize at Safari */
- textarea {
- resize: none;
- }
-
- /* remember to highlight inserts somehow! */
- ins {
- text-decoration: none;
- }
- del {
- text-decoration: line-through;
- }
-
- /* tables still need 'cellspacing="0"' in the markup */
- table {
- border-collapse: collapse;
- border-spacing: 0;
- }
-
-
- /*
- Origional from http://www.perspectived.com/
- Modified by Ben Phelps
- Made for FakeTruth - MCServer
- */
-
- /* Basic ---------------------------------------- */
-
- .clear { clear: both; }
-
- body {
- background: white;
- font-family: Arial, Helvetica, sans-serif;
- font-size: 12px;
- color: #646464;
- text-align: center;
- }
-
- #wrapper {
- text-align: left;
- width: 930px;
- margin: 0 auto;
- }
-
- /* Logo ---------------------------------------- */
-
- h1 {
- margin: 15px 0 10px 5px;
- width: 180px;
- height: 36px;
- background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAALQAAAAkCAMAAAAXdeBDAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAuVQTFRFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAs7OzAAAAAAAAoqKiAAAAvLy8AAAAlZWVtbW1j4+Pra2tiYmJp6enAAAAhISEoaGhAAAAgICAm5ube3t7lZWVd3d3kZGRc3NzjIyMbGxsg4ODgICAeHh43NzcdXV1cnJyy8vLWVlZbGxswcHB09PTvLy8uLi4tLS0sLCwvLy8uLi4tbW1oaGhnp6era2tm5ubqqqq39/f29vblZWV09PT4ODgz8/P3NzckZGRxcXF0tLSwsLCzs7Oy8vLyMjIt7e3vLy85ubm7u7u3d3d5+fn2tra5OTk19fX1dXV3t7e29vb2dnZ1tbW0dHRv7+/8PDw7u7u6+vr8fHx5ubm4+Pj7Ozs4eHh3t7e5+fn5OTk2tra4uLi39/f1dXV3d3d29vb2dnZ19fX1dXV0tLS9fX18/Pzzs7O7u7u8/PzycnJ6urq6Ojo7+/v5ubm7Ozs4+Pj4eHh39/f5ubm5OTk4uLi4ODg2NjY3Nzc29vb19fX8vLy9/f39fX17e3t8/Pz6+vr8fHx7+/v5+fn7e3t5eXl6+vr6enp6Ojo4ODg39/f9PT0+Pj48fHx9vb27+/v9PT07e3t8/Pz7Ozs8fHx7+/v6Ojo7u7u5+fn7Ozs5eXl6urq5OTk6enp5+fn5ubm5OTk+Pj49/f39fX19PT0+fn58vLy8fHx9fX19PT08vLy8fHx6urq+Pj49vb29fX19PT08vLy8PDw+/v7+vr6+Pj49/f39vb29fX18/Pz/f39+/v7+vr6+fn5+Pj49/f3/f39/Pz8+vr6/v7+/f39a5KrdZmxf6G2iai8kq/BnLbHpr7NsMXSuszYxNPdxmZTynBeznpqztvj0YV11Y+B2OLp2ZmM3aOY4a2j4enu5Liv6MK66/D07MzG8NbR9ODd9fj59+vo+/X0ucu1kQAAANl0Uk5TAAECAwQFBgcICQoLDA0ODxAREhMUFBUWFhcXGBgYGRkaGhsbGxwcHB0dHh4fHyEhIiQkJSYnKCgpKSorLC0uLzAxMjIzMzc4Ojo6Ozs8Pj4/P0BBQ0VISUtLTExNTk5PUFFTV1dYWVpbXFxdXl5fYGBhYmJjZGVmZ2doaWprbGxtbW5ub3BxcXJzdHV2d3l6e3x9fX5+f4CAgYGCg4SIi4yNjY6Oj4+QkJGSkpOTlJSVlZaXmJqbnJ2dnp+foKGip6+wsbKztb6/wMHCw8TOz9DR0tPf4OHv8LXp8fEAAAi/SURBVHja3Zh/dBRXFcdhZ+a9eTPzZnaXmJam0FYUEQWLrVVbqdZaf6EWQW2txN/SWiAmxFqtIlWr9bdWqkbwF6WQYIq/+WFpwSZqTahhg6RhNptkl9nsbjeb2eyv+dv73g6wlcyewXMazvGek3Dm5jLv8+689733vTn/q81ldr5zzsWxuVWr55sbCAiiBCYKAeZ1nYIgigJ4Zh2Zj+0OXesTgQ987pOEZUVVVYXISIJQPi3mJETG0kXADggIL5CRWDMy57kCaDgdBMgK1de0gi2jGsESZJt5iXpjS8utGkHiLFMDIHrNgfJBFYs1i0Ei73iifIAggIEHrNDWnuGpFFg50vEKVYbcArNye0+lUCj13aUgYbahRbInbqbu1zAf2XXpR8bN1CZZYItA1jb0pcaiJrdYorxzIRYFYN7qZC2wTOVXMuR+dqGR2hU3Y4NLFSlwJtGIfmbKNFOt4BIkQndOj5rR8dMpsETMjCae+gASJbLKSSftUsWeSJbWz3aqgXBvPGomOnWWajfRoWOjAN2uIWBedOh0NJoYPvJgW1tb+47I1Jg5Vl6AsPrkZLLU+f5bdjjpzNOzDo1pdzw2Fi2vVlBVFgRMf5oyYXl8lmIk00MJc7S8e6mhU02jerC5JzFavgyRlztWbl9j2NC3lvJbpMDFgJ6Ojh/VZb4XA5KycmhkNAXQOpG1ncDfv9HQQNsQZsK3cNvTn5SQ0lKwCveEdYWQd25BrugxUQHjAl/fPKL9Q2t747F/x82pjSpXC0Gme+EJoNt1Vb2jHI1FVlMmawFWYiQgB6mWCIcOaVgCA2ZX3BEGQyI4vAsXWN1of9Bd8diJZ0dG+3QiwuSRsq4cHf8rgzao3jMWnX5Al88oMdNnAQRPlOlwMrcvrBMYk2WrWmyIqlGqqYRJPE+kwK2a0Jr8wo9nNPzRL/QvTpupH4HsAQ4DLX+ZQQeNN02b8W6DSLWVh5mA+EbcHaKkWhF5sdGWdfREIj0dyzSCBDAJY1nGCKo/r/9uguEB/uQZLQZ8Qe+JxwZffGx0ZGixgiSsbXzOTDz2RQYdDm1PmFNrNXTee+ZKMpO8fP+DhiYjAGLF5oYux86m01nb6bqBACr+4Id1/cZHH7pUxne+HkE63fp7522A5xn9IiHgF7ppM6DuokRWjD7Av+7zDHrevEgsFgkq0vndnVtcMvmhjkUKJFvEyqf7ckkrmU7Dr1zfXQTLXyoWv95ZydnblB8UKut5BYL/Rw4Uih9S6Qav6B9CnD/oSGPj0fFouVmn+sOwUH7W9DmmHg0Nw9H4Xp0IM1Z/KOOFjDVhR7ZqMpbVO5yMlS2eGhw8VYTJOC9RtOPp9Ak7adk/picnMv/UZL5jyO0ly+4INntGP+QfOhxeXY6O9c4L31QeGettaLyHQTeuKJsALQdm3PyI0Na+UtZKl3ZSjS7uzVr23z7e0Nj00t8Wk2nnZaoeSadtK1s6uJD+xLYKLSBOTJp6sklnxXLP6AOXin6XRyRoGLsS5nObm34HctccCrdz6GsYNJ0JmquFrOjNvcV0srQrFN5tW/bh5aHQvPm/KQHFVkULDsK3n/x7s0bURZDqPtAg+DxrSlau+5JOz2gVCX434nGod4uhpDzzielo/HFdD7bXzbSbbBHJmvEAbMjK5qZTyUz/8qCuhzsZxf0qUUODaSt94n06rB3aYVulZhVLMgXRcd5SL1oM+IamCtEeTpmn/wFyt1JV9ba6a9qlZtgKUE9kjn0vb+W/FdapsYtTaBgrDCP/3bAiQX4XD01ke6B8qisdkPf5364TDcy+oQkmRu/YyGmmITKhbXXVwy10DFtSgjsgjX/KWc41IeMshQj+wTT4dBxg3cx2iGHbvCuXdN58yb560XP8Q8sSUpunzOho/xICX73trE5P33yeTgOre0KDNYLp1Y5l/xkwrm0In6UICMSArTUYVmHGMLNlTjLbGw69chj+aWjorhftHxoECWrh43HoouEluAodNNZMzVQRWQty2wJJ5NRIexU0fAz6tU2dVQomyVUM+ExCtXGspvjnLOGh0N460RcELQQkcn15/AnAFxCHbvPqPUSE9xedKyBDHPpqBm1blXc/5lKwfkRSOIbBNwQ8vQEW8x+uexaWtqEb2z2jLxSaadjb/vJWLAUCLnRtlye4bQ7CYPK7Slb+ayrMhfUqt1Ss/PeLlv17RvFVqsisEcQqx2C7+FyqfwmJXqcp2ke9oi8YGl4tSkgSAM6Fph799KcU7SSkLEgJxoSGYYVW3v5MZqIAFN8I65qqvu6RLUQLcgx4r9ukO0n7X5lsr04w0fu9on1CI5VDY4F/fN5DAnRriq3u2pMLrTm5XKVBjcvvDoPTCO8uJSePzr+3YFlp5ztNDUEjuO6pXP4rtAaDp/rI5ETBKn5MRbDl2zyifUMrDFrFgdoeTuHQyrkz4hCcEcF29PMz4lXKlVAk8r3fXHtzey8rw+8JzTtsW5POH++9dkV7twM1ehtlH/w4K6duqteWLCgphiyyJeUd7cMAkDwK0AQ9D5psAuhN5NxpfMQ9jY/y07gsK6ucSSubL1UKWYttJ5UuBY5kruA4BWjf7IOXqxRaoLPJgK5Dh36j0Mo6EJjBEo9on9AifiQeG8BSLbSA7wbou7HHvYcsSUhZ9aQ9YYFN5CJbVRnJ6pLDxYzFLVM8dDkhykA6PSDDe91UQ39X7fV4i+gZ7ceA6tW/HviCVNumwAh4f3k/ljxvmAQBkSs7TpYKheLQnusVJIIMErqxr1TI5QqVvg0gZAjfNzBwH3Lfy0DJeod31ezBO9qXsfOPexqqnQlagGa8y1MJFqviB85bW1o+QiHNTHEENrn3tnZ1tb6RsmMBkyJUcznJ5PIyyRX8OtF+jEsGG/S/fPyIOdOtKZuf2+NhonAPBLqTI6qmKQTDLPhrmbjXjnPmuW60/wtqryt07/tp3oA8z8MdCHHXjBcC7mOd6Bfk7r3udC94aDf6/9T+AzWzIkAbVeu4AAAAAElFTkSuQmCC) no-repeat left top;
- }
-
- h1 a {
- display: block;
- width: 225px;
- height: 28px;
- }
-
- h1 span { display: none; }
-
- a {
- color: #646464;
- }
-
- /* Container ---------------------------------------- */
-
- #containerHolder {
- background: #eee;
- padding: 5px;
- }
-
-
- #container {
- background: #fff url(data:image/gif;base64,R0lGODlhtAABAIAAAN3d3f///yH5BAAAAAAALAAAAAC0AAEAAAIMjI+py+0Po5y0WgYKADs%3D) repeat-y left top;
- border: 1px solid #ddd;
- width: 918px;
-
- }
-
- #connectHolder {
- background: #eee;
- padding: 5px;
- margin-bottom:8px;
- }
-
-
- #connect {
- border: 1px solid #ddd;
- background-color: #fff;
- padding:5px;
- width: 908px;
- }
-
- .pics {
- height: 375px;
- width: 600px;
- }
-
- .pics img {
- padding: 5px;
- border: 1px solid #ddd;
- background-color: #eee;
- width: 600px;
- height: 375px;
- margin-left: 15px;
- }
-
- /* Login -------------------------------------- */
-
- #loginLogo {
- margin: 0 auto;
- margin-top:100px;
- width: 180px;
- height: 36px;
- background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAALQAAAAkCAMAAAAXdeBDAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAuVQTFRFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAs7OzAAAAAAAAoqKiAAAAvLy8AAAAlZWVtbW1j4+Pra2tiYmJp6enAAAAhISEoaGhAAAAgICAm5ube3t7lZWVd3d3kZGRc3NzjIyMbGxsg4ODgICAeHh43NzcdXV1cnJyy8vLWVlZbGxswcHB09PTvLy8uLi4tLS0sLCwvLy8uLi4tbW1oaGhnp6era2tm5ubqqqq39/f29vblZWV09PT4ODgz8/P3NzckZGRxcXF0tLSwsLCzs7Oy8vLyMjIt7e3vLy85ubm7u7u3d3d5+fn2tra5OTk19fX1dXV3t7e29vb2dnZ1tbW0dHRv7+/8PDw7u7u6+vr8fHx5ubm4+Pj7Ozs4eHh3t7e5+fn5OTk2tra4uLi39/f1dXV3d3d29vb2dnZ19fX1dXV0tLS9fX18/Pzzs7O7u7u8/PzycnJ6urq6Ojo7+/v5ubm7Ozs4+Pj4eHh39/f5ubm5OTk4uLi4ODg2NjY3Nzc29vb19fX8vLy9/f39fX17e3t8/Pz6+vr8fHx7+/v5+fn7e3t5eXl6+vr6enp6Ojo4ODg39/f9PT0+Pj48fHx9vb27+/v9PT07e3t8/Pz7Ozs8fHx7+/v6Ojo7u7u5+fn7Ozs5eXl6urq5OTk6enp5+fn5ubm5OTk+Pj49/f39fX19PT0+fn58vLy8fHx9fX19PT08vLy8fHx6urq+Pj49vb29fX19PT08vLy8PDw+/v7+vr6+Pj49/f39vb29fX18/Pz/f39+/v7+vr6+fn5+Pj49/f3/f39/Pz8+vr6/v7+/f39a5KrdZmxf6G2iai8kq/BnLbHpr7NsMXSuszYxNPdxmZTynBeznpqztvj0YV11Y+B2OLp2ZmM3aOY4a2j4enu5Liv6MK66/D07MzG8NbR9ODd9fj59+vo+/X0ucu1kQAAANl0Uk5TAAECAwQFBgcICQoLDA0ODxAREhMUFBUWFhcXGBgYGRkaGhsbGxwcHB0dHh4fHyEhIiQkJSYnKCgpKSorLC0uLzAxMjIzMzc4Ojo6Ozs8Pj4/P0BBQ0VISUtLTExNTk5PUFFTV1dYWVpbXFxdXl5fYGBhYmJjZGVmZ2doaWprbGxtbW5ub3BxcXJzdHV2d3l6e3x9fX5+f4CAgYGCg4SIi4yNjY6Oj4+QkJGSkpOTlJSVlZaXmJqbnJ2dnp+foKGip6+wsbKztb6/wMHCw8TOz9DR0tPf4OHv8LXp8fEAAAi/SURBVHja3Zh/dBRXFcdhZ+a9eTPzZnaXmJam0FYUEQWLrVVbqdZaf6EWQW2txN/SWiAmxFqtIlWr9bdWqkbwF6WQYIq/+WFpwSZqTahhg6RhNptkl9nsbjeb2eyv+dv73g6wlcyewXMazvGek3Dm5jLv8+689733vTn/q81ldr5zzsWxuVWr55sbCAiiBCYKAeZ1nYIgigJ4Zh2Zj+0OXesTgQ987pOEZUVVVYXISIJQPi3mJETG0kXADggIL5CRWDMy57kCaDgdBMgK1de0gi2jGsESZJt5iXpjS8utGkHiLFMDIHrNgfJBFYs1i0Ei73iifIAggIEHrNDWnuGpFFg50vEKVYbcArNye0+lUCj13aUgYbahRbInbqbu1zAf2XXpR8bN1CZZYItA1jb0pcaiJrdYorxzIRYFYN7qZC2wTOVXMuR+dqGR2hU3Y4NLFSlwJtGIfmbKNFOt4BIkQndOj5rR8dMpsETMjCae+gASJbLKSSftUsWeSJbWz3aqgXBvPGomOnWWajfRoWOjAN2uIWBedOh0NJoYPvJgW1tb+47I1Jg5Vl6AsPrkZLLU+f5bdjjpzNOzDo1pdzw2Fi2vVlBVFgRMf5oyYXl8lmIk00MJc7S8e6mhU02jerC5JzFavgyRlztWbl9j2NC3lvJbpMDFgJ6Ojh/VZb4XA5KycmhkNAXQOpG1ncDfv9HQQNsQZsK3cNvTn5SQ0lKwCveEdYWQd25BrugxUQHjAl/fPKL9Q2t747F/x82pjSpXC0Gme+EJoNt1Vb2jHI1FVlMmawFWYiQgB6mWCIcOaVgCA2ZX3BEGQyI4vAsXWN1of9Bd8diJZ0dG+3QiwuSRsq4cHf8rgzao3jMWnX5Al88oMdNnAQRPlOlwMrcvrBMYk2WrWmyIqlGqqYRJPE+kwK2a0Jr8wo9nNPzRL/QvTpupH4HsAQ4DLX+ZQQeNN02b8W6DSLWVh5mA+EbcHaKkWhF5sdGWdfREIj0dyzSCBDAJY1nGCKo/r/9uguEB/uQZLQZ8Qe+JxwZffGx0ZGixgiSsbXzOTDz2RQYdDm1PmFNrNXTee+ZKMpO8fP+DhiYjAGLF5oYux86m01nb6bqBACr+4Id1/cZHH7pUxne+HkE63fp7522A5xn9IiHgF7ppM6DuokRWjD7Av+7zDHrevEgsFgkq0vndnVtcMvmhjkUKJFvEyqf7ckkrmU7Dr1zfXQTLXyoWv95ZydnblB8UKut5BYL/Rw4Uih9S6Qav6B9CnD/oSGPj0fFouVmn+sOwUH7W9DmmHg0Nw9H4Xp0IM1Z/KOOFjDVhR7ZqMpbVO5yMlS2eGhw8VYTJOC9RtOPp9Ak7adk/picnMv/UZL5jyO0ly+4INntGP+QfOhxeXY6O9c4L31QeGettaLyHQTeuKJsALQdm3PyI0Na+UtZKl3ZSjS7uzVr23z7e0Nj00t8Wk2nnZaoeSadtK1s6uJD+xLYKLSBOTJp6sklnxXLP6AOXin6XRyRoGLsS5nObm34HctccCrdz6GsYNJ0JmquFrOjNvcV0srQrFN5tW/bh5aHQvPm/KQHFVkULDsK3n/x7s0bURZDqPtAg+DxrSlau+5JOz2gVCX434nGod4uhpDzzielo/HFdD7bXzbSbbBHJmvEAbMjK5qZTyUz/8qCuhzsZxf0qUUODaSt94n06rB3aYVulZhVLMgXRcd5SL1oM+IamCtEeTpmn/wFyt1JV9ba6a9qlZtgKUE9kjn0vb+W/FdapsYtTaBgrDCP/3bAiQX4XD01ke6B8qisdkPf5364TDcy+oQkmRu/YyGmmITKhbXXVwy10DFtSgjsgjX/KWc41IeMshQj+wTT4dBxg3cx2iGHbvCuXdN58yb560XP8Q8sSUpunzOho/xICX73trE5P33yeTgOre0KDNYLp1Y5l/xkwrm0In6UICMSArTUYVmHGMLNlTjLbGw69chj+aWjorhftHxoECWrh43HoouEluAodNNZMzVQRWQty2wJJ5NRIexU0fAz6tU2dVQomyVUM+ExCtXGspvjnLOGh0N460RcELQQkcn15/AnAFxCHbvPqPUSE9xedKyBDHPpqBm1blXc/5lKwfkRSOIbBNwQ8vQEW8x+uexaWtqEb2z2jLxSaadjb/vJWLAUCLnRtlye4bQ7CYPK7Slb+ayrMhfUqt1Ss/PeLlv17RvFVqsisEcQqx2C7+FyqfwmJXqcp2ke9oi8YGl4tSkgSAM6Fph799KcU7SSkLEgJxoSGYYVW3v5MZqIAFN8I65qqvu6RLUQLcgx4r9ukO0n7X5lsr04w0fu9on1CI5VDY4F/fN5DAnRriq3u2pMLrTm5XKVBjcvvDoPTCO8uJSePzr+3YFlp5ztNDUEjuO6pXP4rtAaDp/rI5ETBKn5MRbDl2zyifUMrDFrFgdoeTuHQyrkz4hCcEcF29PMz4lXKlVAk8r3fXHtzey8rw+8JzTtsW5POH++9dkV7twM1ehtlH/w4K6duqteWLCgphiyyJeUd7cMAkDwK0AQ9D5psAuhN5NxpfMQ9jY/y07gsK6ucSSubL1UKWYttJ5UuBY5kruA4BWjf7IOXqxRaoLPJgK5Dh36j0Mo6EJjBEo9on9AifiQeG8BSLbSA7wbou7HHvYcsSUhZ9aQ9YYFN5CJbVRnJ6pLDxYzFLVM8dDkhykA6PSDDe91UQ39X7fV4i+gZ7ceA6tW/HviCVNumwAh4f3k/ljxvmAQBkSs7TpYKheLQnusVJIIMErqxr1TI5QqVvg0gZAjfNzBwH3Lfy0DJeod31ezBO9qXsfOPexqqnQlagGa8y1MJFqviB85bW1o+QiHNTHEENrn3tnZ1tb6RsmMBkyJUcznJ5PIyyRX8OtF+jEsGG/S/fPyIOdOtKZuf2+NhonAPBLqTI6qmKQTDLPhrmbjXjnPmuW60/wtqryt07/tp3oA8z8MdCHHXjBcC7mOd6Bfk7r3udC94aDf6/9T+AzWzIkAbVeu4AAAAAElFTkSuQmCC);
- }
-
- #loginHolder {
- background: #eee;
- padding: 5px;
- width: 310px;
- margin: 0 auto;
- height: 90px;
- margin-top:20px;
- }
-
- #login {
- padding:10px;
- width: 288px;
- height: 68px;
- border: 1px solid #ddd;
- background:#fff;
- text-align: left;
- }
-
-
- /* Sidebar ---------------------------------------- */
-
- #sidebar {
- width: 179px;
- float: left;
- }
-
- #sidebar .sideNav { width: 179px; }
-
- #sidebar .sideNav li { border-bottom: 1px solid #ddd; width: 179px; }
-
- #sidebar .sideNav li a {
- display: block;
- color: #646464;
- background: #f6f6f6;
- text-decoration: none;
- height: 29px;
- line-height: 29px;
- padding: 0 19px;
- width: 141px;
- }
-
- #sidebar .sideNav li a:hover { background: #fdfcf6; }
-
- #sidebar .sideNav li a.active, #sidebar .sideNav li a.active:hover {
- background: #f0f7fa;
- color: #c66653;
- }
-
- /* Breadcrumb ---------------------------------------- */
-
- h2 {
- width: 718px;
- float: right;
- color: #646464;
- font-size: 16px;
- line-height: 16px;
- font-weight: bold;
- margin: 20px 0 0 0;
- padding: 0 0 10px 0;
- border-bottom: 1px solid #ddd;
- }
-
- h2 a {
- color: #646464;
- text-decoration: none;
- }
-
- h2 a.active { color: #c66653; }
-
- h2 a:hover { text-decoration: underline; }
-
- /* Content ---------------------------------------- */
-
- #main {
- width: 700px;
- float: right;
- padding: 0 19px 0 0;
- }
-
- #main p {
-
- padding: 10px;
-
- }
-
- h3 {
- font-size: 14px;
- line-height: 14px;
- font-weight: bold;
- color: #5494af;
- padding: 0 0 0 10px;
- margin: 20px 0 10px;
- }
-
- h4 {
- padding: 0 0 0 10px;
- margin: 20px 0 10px;
- }
-
- #main ul {
- padding: 0 0 0 10px;
- list-style-type: circle;
- list-style-position: inside;
- }
-
- #main table {
- border-top: 1px solid #ddd;
- width: 700px;
- }
-
- #main table tr th {
- text-align: left;
- background: #f6f6f6;
- padding: 0px 20px;
- height: 20px;
- line-height: 20px;
- border-bottom: 1px solid #ddd;
- }
-
- #main table tr td {
- background: #f6f6f6;
- padding: 0px 20px;
- height: 29px;
- line-height: 29px;
- border-bottom: 1px solid #ddd;
- }
-
- #main table tr.odd td {
- background: #fbfbfb;
- }
-
- #main table tr:hover td { background: #fdfcf6; }
-
- #main table .action {
- text-align: right;
- padding: 0 20px 0 10px;
- }
-
- #main table tr .action a { margin: 0 0 0 10px; text-decoration: none; color: #9b9b9b; }
- #main table tr:hover .action .edit { color: #c5a059; }
- #main table tr:hover .action .delete { color: #a02b2b; }
- #main table tr:hover .action .view { color: #55a34a; }
-
- #main table tr:hover .action a:hover { text-decoration: underline; }
-
- fieldset {
- border: 1px solid #ddd;
- padding: 19px;
- margin: 0 0 20px 0;
- background: #fbfbfb;
- }
-
- form p { margin: 0 0 14px 0; float: left; width: 100%; }
-
- label {
- display: block;
- width: 100%;
- margin: 0 0 7px 0;
- line-height: 12px;
- }
-
- /* Footer ---------------------------------------- */
-
- #footer {
- margin: 10px 0 30px 0;
- font-size: 11px;
- line-height: 11px;
- color: #9B9B9B;
- padding: 0 0 0 5px;
- }
-
- #footer a { color: #9B9B9B; }
-
- #footer a:hover { text-decoration: none; }
-</style>
-
+<link rel="stylesheet" type="text/css" media="screen" href="/style.css">
</head>
<body>
@@ -421,16 +91,16 @@ function ShowPage(WebAdmin, TemplateRequest)
<ul class="sideNav">
]])
-
+
local AllPlugins = WebAdmin:GetPlugins()
for key,value in pairs(AllPlugins) do
local PluginWebTitle = value:GetWebTitle()
local TabNames = value:GetTabNames()
if (GetTableSize(TabNames) > 0) then
- Output("<li>"..PluginWebTitle.."</li>");
+ Output("<li>"..PluginWebTitle.."</li>\n");
for webname,prettyname in pairs(TabNames) do
- Output("<li><a href='" .. BaseURL .. PluginWebTitle .. "/" .. webname .. "'>" .. prettyname .. "</a></li>")
+ Output("<li><a href='" .. BaseURL .. PluginWebTitle .. "/" .. webname .. "'>" .. prettyname .. "</a></li>\n")
end
end
end
@@ -464,4 +134,4 @@ function ShowPage(WebAdmin, TemplateRequest)
]])
return table.concat(SiteContent)
-end \ No newline at end of file
+end
diff --git a/Nightbuild2008.cmd b/Nightbuild2008.cmd
deleted file mode 100644
index bbaea0fb7..000000000
--- a/Nightbuild2008.cmd
+++ /dev/null
@@ -1,209 +0,0 @@
-@echo off
-:: Nightbbuild2008.cmd
-:: This script is run every night to produce a new version of MCServer, backup its PDB files and upload the packages to web.
-:: When run without parameters, this script pauses at the end and waits for a keypress.
-:: To run in an automated scheduler, add any parameter to disable waiting for a keystroke
-::
-:: The sript creates a symbol store (a database of PDB files) that can be used as a single entry in MSVC's symbol path,
-:: then any executable / crashdump built by this script can be debugged and its symbols will be found automatically by MSVC,
-:: without the users needing to specify the build version or anything.
-:: In order to support pruning the symstore, a per-month store is created, so that old months can be removed when no longer needed.
-::
-:: This script expects a few tools on specific paths, you can pass the correct paths for your system as env vars "zip" and "vc"
-:: This script assumes that "git", "symstore" and "touch" are available on PATH.
-:: git comes from msysgit
-:: symstore comes from Microsoft's Debugging Tools for Windows
-:: touch comes from unxtools
-:: This script is locale-dependent, because it parses the output of "time" and "date" shell commands
-
-
-:: 7-zip executable (by default it should be on PATH):
-if %zip%a == a set zip=7z
-
-:: Visual C++ compiler executable name:
-if %vc%a == a set vc="vcbuild.exe"
-
-
-
-
-:: Check that the required environment vars are available:
-if "a%ftppass%" == "a" (
- echo You need to set FTP password in the ftppass environment variable to upload the files
- goto haderror
-)
-if "a%ftpuser%" == "a" (
- echo You need to set FTP username in the ftpuser environment variable to upload the files
- goto haderror
-)
-if "a%ftpsite%" == "a" (
- echo You need to set FTP server in the ftpsite environment variable to upload the files
- goto haderror
-)
-
-
-
-
-:: Get the date and time into vars:
-:: This is locale-dependent!
-For /f "tokens=2-4 delims=/. " %%a in ('date /t') do (
- set MYYEAR=%%c
- set MYMONTH=%%b
- set MYDAY=%%a
-)
-For /f "tokens=1-2 delims=/:" %%a in ('time /t') do (set MYTIME=%%a_%%b)
-
-echo Performing nightbuild of MC-Server
-
-
-
-
-
-set DONOTPAUSE=y
-
-:: Update the sources to the latest revision:
-git pull
-if errorlevel 1 goto haderror
-
-
-
-:: Update the external plugins to the latest revision:
-git submodule update
-if errorlevel 1 goto haderror
-
-
-
-
-:: Get the Git commit ID into an environment var
-For /f "tokens=1 delims=/. " %%a in ('git log -1 --oneline --no-abbrev-commit') do (set COMMITID=%%a)
-if errorlevel 1 goto haderror
-
-
-
-:: Test if the version is already present, using a "tagfile" that we create upon successful build
-set TAGFOLDER=Install\%MYYEAR%_%MYMONTH%\
-set TAGFILE=%TAGFOLDER%built_%COMMITID%.tag
-echo Tag file: %TAGFILE%
-if exist %TAGFILE% (
- echo Latest version already present, bailing out
- goto end
-)
-
-
-
-
-
-:: Configure the sources to use the MSVC2008 compiler:
-cmake -G "Visual Studio 9 2008" .
-if errorlevel 1 goto haderror
-
-
-
-
-
-:: Update the Bindings:
-echo Updating Lua bindings
-del src\Bindings\Bindings.cpp
-del src\Bindings\Bindings.h
-set ALLTOLUA_WAIT=N
-cd src\Bindings
-call AllToLua.bat
-cd ..\..
-
-
-
-
-:: Compile using VC2008 Express. Do a full rebuild.
-echo Setting up VS environment...
-call "%VS90COMNTOOLS%\vsvars32.bat"
-echo Compiling MCServer...
-title MCS Nightbuild
-start "vc" /b /wait /low /min %vc% /r MCServer.sln "Release|Win32"
-if errorlevel 1 goto haderror
-
-
-
-
-:: Generate the .example.ini files by running the server without any ini files:
-cd MCServer
-del groups.ini
-del settings.ini
-del webadmin.ini
-echo stop | MCServer
-cd ..
-
-
-
-:: Copy all the example ini files into the Install folder for zipping:
-copy MCServer\groups.ini Install\groups.example.ini
-copy MCServer\settings.ini Install\settings.example.ini
-copy MCServer\webadmin.ini Install\webadmin.example.ini
-
-
-
-
-:: Use 7-zip to compress the resulting files into a single file:
-set FILESUFFIX=%MYYEAR%_%MYMONTH%_%MYDAY%_%MYTIME%_%COMMITID%
-echo FILESUFFIX=%FILESUFFIX%
-copy MCServer\MCServer.exe Install\MCServer.exe
-cd Install
-%zip% a -mx9 -y MCServer_Win_%FILESUFFIX%.7z -scsWIN -i@Zip2008.list -xr!*.git*
-if errorlevel 1 goto haderror
-cd ..
-
-:: Also pack PDBs into a separate archive:
-%zip% a -mx9 -y Install\PDBs_%FILESUFFIX%.7z -scsWIN @Install\Zip2008_PDBs.list
-if errorlevel 1 goto haderror
-
-
-
-
-
-:: upload to the FTP:
-:upload
-ncftpput -p %ftppass% -u %ftpuser% -T temp_ %ftpsite% / Install\MCServer_Win_%FILESUFFIX%.7z
-if errorlevel 1 goto haderror
-ncftpput -p %ftppass% -u %ftpuser% -T temp_ %ftpsite% /PDBs Install\PDBs_%FILESUFFIX%.7z
-if errorlevel 1 goto haderror
-echo Upload finished.
-
-
-
-
-:: Create the tagfile so that we know that this CommitID has been built already
-mkdir %TAGFOLDER%
-touch %TAGFILE%
-
-
-
-
-
-:: Add the symbols to a global symbol cache
-:: We want per-month symbol caches, so that the old ones can be easily deleted
-set SYMBOLS=Symbols\%MYYEAR%_%MYMONTH%\
-echo Storing symbols in %SYMBOLS%
-
-symstore add /f MCServer\MCServer.* /s %SYMBOLS% /t MCServer
-if errorlevel 1 goto haderror
-
-
-
-goto end
-
-
-
-
-:haderror
-echo an error was encountered, check command output above
-pause
-goto finished
-
-
-
-
-
-:end
-if "a%1" == "a" pause
-
-
-
-:finished \ No newline at end of file
diff --git a/README.md b/README.md
index 85ae459a0..b42467039 100644
--- a/README.md
+++ b/README.md
@@ -5,15 +5,15 @@ MCServer is a Minecraft server that is written in C++ and designed to be efficie
MCServer can run on PCs, Macs, and *nix. This includes android phones and tablets as well as Raspberry Pis.
-We currently support the protocol from Minecraft 1.2 all the way up to Minecraft 1.7.10.
+We currently support the protocol from Minecraft 1.2 all the way up to Minecraft 1.8.
Installation
------------
Normally, you will want to download a pre-compiled version of MCServer from one of the buildservers:
- * [Linux and Raspberry Pi](http://ci.bearbin.net) (Bearbin's CI Server)
- * [Windows](http://mc-server.xoft.cz) (xoft's nightly build service)
+ * [Windows and Linux](http://builds.mc-server.org)
+ * [Raspberry Pi](http://ci.bearbin.net)
You simply need to download and extract these files before you can use the server.
@@ -33,7 +33,7 @@ For other stuff, including plugins and discussion, check the [forums](http://for
Earn bitcoins for commits or donate to reward the MCServer developers: [![tip for next commit](http://tip4commit.com/projects/74.svg)](http://tip4commit.com/projects/74)
-Support Us on Gittip: [![Support via Gittip](http://img.shields.io/gittip/mcs_team.svg)](https://www.gittip.com/mcs_team)
+Support Us on Gratipay: [![Support via Gittip](http://img.shields.io/gittip/mcs_team.svg)](https://www.gittip.com/mcs_team)
Travis CI: [![Build Status](http://img.shields.io/travis/mc-server/MCServer.svg)](https://travis-ci.org/mc-server/MCServer)
diff --git a/SetFlags.cmake b/SetFlags.cmake
index 0e2e0c277..1827a4b66 100644
--- a/SetFlags.cmake
+++ b/SetFlags.cmake
@@ -205,6 +205,15 @@ macro(enable_profile)
endif()
endmacro()
+#this is a hack because we can't use cmake 2.8.10 because of travis
+macro(get_clang_version)
+ execute_process(
+ COMMAND "${CMAKE_CXX_COMPILER}" "--version"
+ OUTPUT_VARIABLE CLANG_VERSION_OUTPUT)
+ string(REGEX MATCH "version ([0-9]\\.[0-9])" x ${CLANG_VERSION_OUTPUT})
+ set(CLANG_VERSION ${CMAKE_MATCH_1})
+endmacro()
+
macro(set_exe_flags)
# Remove disabling the maximum warning level:
# clang does not like a command line that reads -Wall -Wextra -w -Wall -Wextra and does not output any warnings
@@ -223,17 +232,28 @@ macro(set_exe_flags)
add_flags_cxx("-ffast-math")
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
+ get_clang_version()
+ if ("${CLANG_VERSION}" VERSION_LESS 3.0)
+ message(FATAL_ERROR "MCServer requires clang version 3.0 or higher, version is ${CLANG_VERSION}")
+ endif()
# clang does not provide the __extern_always_inline macro and a part of libm depends on this when using fast-math
add_flags_cxx("-D__extern_always_inline=inline")
add_flags_cxx("-Werror -Weverything -Wno-c++98-compat-pedantic -Wno-string-conversion")
- add_flags_cxx("-Wno-error=switch-enum -Wno-documentation -Wno-exit-time-destructors")
- add_flags_cxx("-Wno-error=sign-conversion -Wno-error=conversion -Wno-padded")
- add_flags_cxx("-Wno-error=deprecated -Wno-error=weak-vtables -Wno-error=float-equal")
- add_flags_cxx("-Wno-error=missing-prototypes -Wno-error=non-virtual-dtor")
- add_flags_cxx("-Wno-error=covered-switch-default -Wno-error=shadow -Wno-error=old-style-cast")
- add_flags_cxx("-Wno-error=exit-time-destructors -Wno-error=missing-variable-declarations")
- add_flags_cxx("-Wno-error=global-constructors -Wno-implicit-fallthrough")
- add_flags_cxx("-Wno-error=extra-semi -Wno-weak-vtables -Wno-switch-enum")
+ add_flags_cxx("-Wno-exit-time-destructors -Wno-padded")
+ add_flags_cxx("-Wno-error=sign-conversion -Wno-error=conversion -Wno-error=deprecated")
+ add_flags_cxx("-Wno-error=missing-prototypes")
+ add_flags_cxx("-Wno-error=shadow -Wno-error=old-style-cast -Wno-error=global-constructors")
+ add_flags_cxx("-Wno-error=float-equal")
+ add_flags_cxx("-Wno-weak-vtables -Wno-switch-enum")
+ if ("${CLANG_VERSION}" VERSION_GREATER 3.0)
+ # flags that are not present in 3.0
+ add_flags_cxx("-Wno-error=covered-switch-default -Wno-error=missing-variable-declarations")
+ add_flags_cxx("-Wno-implicit-fallthrough -Wno-error=extra-semi")
+ endif()
+ if ("${CLANG_VERSION}" VERSION_GREATER 3.1)
+ # flags introduced in 3.2
+ add_flags_cxx("-Wno-documentation")
+ endif()
endif()
endif()
diff --git a/Tools/.gitignore b/Tools/.gitignore
new file mode 100644
index 000000000..f240e723e
--- /dev/null
+++ b/Tools/.gitignore
@@ -0,0 +1 @@
+Debug/
diff --git a/Tools/BiomeVisualiser/.gitignore b/Tools/BiomeVisualiser/.gitignore
deleted file mode 100644
index cfbc9164c..000000000
--- a/Tools/BiomeVisualiser/.gitignore
+++ /dev/null
@@ -1,4 +0,0 @@
-Debug/
-logs/
-Release/
-Release profiled/
diff --git a/Tools/BiomeVisualiser/BiomeCache.cpp b/Tools/BiomeVisualiser/BiomeCache.cpp
deleted file mode 100644
index 7d9301d8f..000000000
--- a/Tools/BiomeVisualiser/BiomeCache.cpp
+++ /dev/null
@@ -1,338 +0,0 @@
-
-// BiomeCache.cpp
-
-// Implements the cBiomeCache class representing a biome source that caches data from the underlying biome source
-
-#include "Globals.h"
-#include "BiomeCache.h"
-#include "Timer.h"
-
-
-
-
-
-static int GetNumCores(void)
-{
- // Get number of cores by querying the system process affinity mask
- DWORD Affinity, ProcAffinity;
- GetProcessAffinityMask(GetCurrentProcess(), &ProcAffinity, &Affinity);
- int NumCores = 0;
- while (Affinity > 0)
- {
- if ((Affinity & 1) == 1)
- {
- NumCores++;
- }
- Affinity >>= 1;
- } // while (Affinity > 0)
- return NumCores;
-}
-
-
-
-
-
-cBiomeCache::cBiomeCache(void) :
- m_Source(NULL),
- m_BaseX(-100000),
- m_BaseZ(-100000),
- m_Available(NULL),
- m_IsTerminatingThreads(false)
-{
- int NumThreads = GetNumCores();
- NumThreads--; // One core should be left for the system to run on ;)
- for (int i = NumThreads; i > 0; i--)
- {
- cThread * Thread = new cThread(*this);
- m_Threads.push_back(Thread);
- Thread->Start();
- }
-}
-
-
-
-
-cBiomeCache::~cBiomeCache()
-{
- m_IsTerminatingThreads = true;
- for (cThreads::iterator itr = m_Threads.begin(), end = m_Threads.end(); itr != end; ++itr)
- {
- m_evtQueued.Set();
- }
- for (cThreads::iterator itr = m_Threads.begin(), end = m_Threads.end(); itr != end; ++itr)
- {
- delete *itr;
- }
- m_Threads.clear();
-
- SetSource(NULL);
-}
-
-
-
-
-
-cBiomeSource::eAvailability cBiomeCache::GetBiome(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_Biomes)
-{
- if (m_Source == NULL)
- {
- return baNever;
- }
-
- // Look up using the cache:
- int x = a_ChunkX - m_BaseX;
- int z = a_ChunkZ - m_BaseZ;
- if ((x < 0) || (x >= m_Width) || (z < 0) || (z >= m_Height))
- {
- // Outside the cached region
- return baNever;
- }
-
- cCSLock Lock(m_CS);
- cItem * Item = m_Available[x + m_Width * z];
- if (Item == NULL)
- {
- // Item hasn't been processed yet
- return baLater;
- }
- if (Item->m_IsValid)
- {
- memcpy(a_Biomes, Item->m_Biomes, sizeof(a_Biomes));
- return baNow;
- }
-
- // Item has been processed, but the underlying source refused to give the data to us
- return baNever;
-}
-
-
-
-
-
-void cBiomeCache::HintViewArea(int a_MinChunkX, int a_MaxChunkX, int a_MinChunkZ, int a_MaxChunkZ)
-{
- cTimer Timer("Cache: HintViewArea");
-
- if (
- (a_MinChunkX == m_BaseX) &&
- (a_MaxChunkX == m_BaseX + m_Width - 1) &&
- (a_MinChunkZ == m_BaseZ) &&
- (a_MaxChunkZ == m_BaseZ + m_Height - 1)
- )
- {
- // The same set of parameters, bail out
- return;
- }
-
- if (m_Source != NULL)
- {
- m_Source->HintViewArea(a_MinChunkX, a_MaxChunkX, a_MinChunkZ, a_MaxChunkZ);
- }
-
- int NewWidth = a_MaxChunkX - a_MinChunkX + 1;
- int NewHeight = a_MaxChunkZ - a_MinChunkZ + 1;
-
- // Make a new empty cache table:
- pItem * NewAvailable = new pItem[NewWidth * NewHeight];
- for (int i = NewWidth * NewHeight - 1; i >= 0; --i)
- {
- NewAvailable[i] = NULL;
- }
-
- // Move the common contents of the old table into the new table:
- cCSLock Lock(m_CS);
- for (int z = 0; z < NewHeight; z++)
- {
- int OldZ = z + a_MinChunkZ - m_BaseZ;
- if ((OldZ < 0) || (OldZ >= m_Height))
- {
- continue;
- }
- for (int x = 0; x < NewWidth; x++)
- {
- int OldX = x + a_MinChunkX - m_BaseX;
- if ((OldX < 0) || (OldX >= m_Width))
- {
- continue;
- }
- NewAvailable[x + NewWidth * z] = m_Available[OldX + m_Width * OldZ];
- m_Available[OldX + m_Width * OldZ] = NULL;
- } // for x
- } // for z
-
- // All items that aren't common go into the pool:
- for (int idx = 0, z = 0; z < m_Height; z++)
- {
- for (int x = 0; x < m_Width; ++x, ++idx)
- {
- if (m_Available[idx] != NULL)
- {
- m_Pool.push_back(m_Available[idx]);
- m_Available[idx] = NULL;
- }
- }
- }
-
- // Replace the cache table:
- delete m_Available;
- m_Available = NewAvailable;
- m_Width = NewWidth;
- m_Height = NewHeight;
- m_BaseX = a_MinChunkX;
- m_BaseZ = a_MinChunkZ;
-
- // Remove all items outside the coords:
- FilterOutItems(m_Queue, a_MinChunkX, a_MaxChunkX, a_MinChunkZ, a_MaxChunkZ);
-
- // Queue all items from inside the coords into m_Queue:
- for (int z = 0; z < NewHeight; z++)
- {
- for (int x = 0; x < NewWidth; x++)
- {
- if (m_Available[x + m_Width * z] != NULL)
- {
- // Already calculated, skip
- continue;
- }
-
- if (m_Pool.empty())
- {
- m_Pool.push_back(new cItem(x + a_MinChunkX, z + a_MinChunkZ));
- }
- ASSERT(!m_Pool.empty());
- m_Pool.back()->m_ChunkX = x + a_MinChunkX;
- m_Pool.back()->m_ChunkZ = z + a_MinChunkZ;
- m_Queue.push_back(m_Pool.back());
- m_Pool.pop_back();
- m_evtQueued.Set();
- } // for x
- } // for z
-}
-
-
-
-
-
-void cBiomeCache::SetSource(cBiomeSource * a_Source)
-{
- // TODO: Stop all threads, so that they don't use the source anymore!
-
- delete m_Source;
- m_Source = a_Source;
-
- // Invalidate cache contents:
- cCSLock Lock(m_CS);
- m_BaseX = -10000;
- m_BaseZ = -10000;
- m_Pool.splice(m_Pool.end(), m_Queue);
-}
-
-
-
-
-
-void cBiomeCache::FilterOutItems(cItems & a_Items, int a_MinChunkX, int a_MaxChunkX, int a_MinChunkZ, int a_MaxChunkZ)
-{
- for (cItems::iterator itr = a_Items.begin(); itr != a_Items.end();)
- {
- if (
- ((*itr)->m_ChunkX < a_MinChunkX) ||
- ((*itr)->m_ChunkX > a_MaxChunkX) ||
- ((*itr)->m_ChunkX < a_MinChunkX) ||
- ((*itr)->m_ChunkX > a_MaxChunkX)
- )
- {
- m_Pool.push_back(*itr);
- itr = a_Items.erase(itr);
- }
- else
- {
- ++itr;
- }
- }
-}
-
-
-
-
-
-void cBiomeCache::thrProcessQueueItem(void)
-{
- if (m_Source == NULL)
- {
- return;
- }
-
- cItem * Item = NULL;
- {
- cCSLock Lock(m_CS);
- if (m_Queue.empty())
- {
- cCSUnlock Unlock(Lock);
- m_evtQueued.Wait();
- }
- if (m_IsTerminatingThreads || m_Queue.empty())
- {
- // We've been woken up only to die / spurious wakeup
- return;
- }
- Item = m_Queue.back();
- m_Queue.pop_back();
- }
-
- // Process the item:
- Item->m_IsValid = (m_Source->GetBiome(Item->m_ChunkX, Item->m_ChunkZ, Item->m_Biomes) == baNow);
-
- // Store result:
- cCSLock Lock(m_CS);
- int x = Item->m_ChunkX - m_BaseX;
- int z = Item->m_ChunkZ - m_BaseZ;
- if ((x < 0) || (x >= m_Width) || (z < 0) || (z >= m_Height))
- {
- // The cache rectangle has changed under our fingers, drop this chunk
- return;
- }
- m_Available[x + m_Width * z] = Item;
-}
-
-
-
-
-
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// cBiomeCache::cItem:
-
-cBiomeCache::cItem::cItem(int a_ChunkX, int a_ChunkZ) :
- m_ChunkX(a_ChunkX),
- m_ChunkZ(a_ChunkZ)
-{
-}
-
-
-
-
-
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// cBiomeCache::cThread:
-
-cBiomeCache::cThread::cThread(cBiomeCache & a_Parent) :
- super("Biome cache thread"),
- m_Parent(a_Parent)
-{
-}
-
-
-
-
-
-void cBiomeCache::cThread::Execute(void)
-{
- while (!m_ShouldTerminate && !m_Parent.m_IsTerminatingThreads)
- {
- m_Parent.thrProcessQueueItem();
- }
-}
-
-
-
-
diff --git a/Tools/BiomeVisualiser/BiomeCache.h b/Tools/BiomeVisualiser/BiomeCache.h
deleted file mode 100644
index da4d6c761..000000000
--- a/Tools/BiomeVisualiser/BiomeCache.h
+++ /dev/null
@@ -1,96 +0,0 @@
-
-// BiomeCache.h
-
-// Declares the cBiomeCache class representing a biome source that caches data from the underlying biome source
-
-/*
-This cache works a bit differently than regular caches.
-It first receives the hint of area that it will need to provide.
-The Cache uses several threads to request biomes from the underlying source to fill that area.
-While the area is being filled, requests for biomes may already come, such requests are answered with baLater if no data yet.
-*/
-
-#pragma once
-
-
-
-
-
-#include "BiomeSource.h"
-#include "../src/OSSupport/IsThread.h"
-
-
-
-
-
-class cBiomeCache :
- public cBiomeSource
-{
-public:
- cBiomeCache(void);
- ~cBiomeCache();
-
- // cBiomeSource overrides:
- virtual eAvailability GetBiome(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_Biomes) override;
- virtual void HintViewArea(int a_MinChunkX, int a_MaxChunkX, int a_MinChunkZ, int a_MaxChunkZ) override;
-
- void SetSource(cBiomeSource * a_Source); // Takes ownership of the source ptr
-
-protected:
- class cItem
- {
- public:
- cItem(int a_ChunkX, int a_ChunkZ);
-
- int m_ChunkX;
- int m_ChunkZ;
- bool m_IsValid;
- cChunkDef::BiomeMap m_Biomes;
- } ;
-
- typedef cItem * pItem;
- typedef std::list<pItem> cItems;
-
- class cThread :
- public cIsThread
- {
- typedef cIsThread super;
-
- public:
- cThread(cBiomeCache & a_Parent);
-
- // cIsThread overrides:
- virtual void Execute(void) override;
-
- protected:
- cBiomeCache & m_Parent;
- } ;
-
- typedef std::list<cThread *> cThreads;
-
- cBiomeSource * m_Source;
-
- cCriticalSection m_CS;
- int m_BaseX; ///< MinChunkX for the m_Available rectangle
- int m_BaseZ; ///< MinChunkZ for the m_Available rectangle
- int m_Width; ///< Width of the m_Available rectangle
- int m_Height; ///< Height of the m_Available rectangle
- pItem * m_Available; ///< Items that have already been processed (baNow or baNever), [x + m_Width * z]
- cItems m_Queue; ///< Items that are queued for processing (baLater)
- cItems m_Pool; ///< Items that are not needed anymore, can be reused for other coords
-
- cEvent m_evtQueued; // Triggerred when an item is added to m_Queue
-
- cThreads m_Threads; // Threads that update the cache.
- bool m_IsTerminatingThreads; // Set to true to indicate to all threads that they should exit
-
- /// Removes from a_Items all items that are outside of the given coords, moves those into m_Pool
- void FilterOutItems(cItems & a_Items, int a_MinChunkX, int a_MaxChunkX, int a_MinChunkZ, int a_MaxChunkZ);
-
- /// Processes one item from m_Queue into m_Available. Blocks if m_Queue is empty; respects m_IsTerminatingThreads
- void thrProcessQueueItem(void);
-} ;
-
-
-
-
diff --git a/Tools/BiomeVisualiser/BiomeColors.cpp b/Tools/BiomeVisualiser/BiomeColors.cpp
deleted file mode 100644
index 1fd0cb7a0..000000000
--- a/Tools/BiomeVisualiser/BiomeColors.cpp
+++ /dev/null
@@ -1,114 +0,0 @@
-
-// BiomeColors.cpp
-
-// Implements the g_BiomeColors[] array preparation based on a stored biome-to-color map
-
-#include "Globals.h"
-#include "BiomeColors.h"
-
-
-
-
-
-int g_BiomeColors[256];
-
-
-
-
-
-static struct
-{
- EMCSBiome Biome;
- int Color;
-} g_BiomeColorMap[] =
-{
- { biOcean, 0x000070 },
- { biPlains, 0x8db360 },
- { biDesert, 0xfa9418 },
- { biExtremeHills, 0x606060 },
- { biForest, 0x056621 },
- { biTaiga, 0x0b6659 },
- { biSwampland, 0x2fffda },
- { biRiver, 0x3030af },
- { biHell, 0x7f0000 },
- { biSky, 0x007fff },
- { biFrozenOcean, 0xa0a0df },
- { biFrozenRiver, 0xa0a0ff },
- { biIcePlains, 0xffffff },
- { biIceMountains, 0xa0a0a0 },
- { biMushroomIsland, 0xff00ff },
- { biMushroomShore, 0xa000ff },
- { biBeach, 0xfade55 },
- { biDesertHills, 0xd25f12 },
- { biForestHills, 0x22551c },
- { biTaigaHills, 0x163933 },
- { biExtremeHillsEdge, 0x7f8f7f },
- { biJungle, 0x537b09 },
- { biJungleHills, 0x2c4205 },
-
- { biJungleEdge, 0x628b17 },
- { biDeepOcean, 0x000030 },
- { biStoneBeach, 0xa2a284 },
- { biColdBeach, 0xfaf0c0 },
- { biBirchForest, 0x307444 },
- { biBirchForestHills, 0x1f5f32 },
- { biRoofedForest, 0x40511a },
- { biColdTaiga, 0x31554a },
- { biColdTaigaHills, 0x597d72 },
- { biMegaTaiga, 0x596651 },
- { biMegaTaigaHills, 0x596659 },
- { biExtremeHillsPlus, 0x507050 },
- { biSavanna, 0xbdb25f },
- { biSavannaPlateau, 0xa79d64 },
- { biMesa, 0xd94515 },
- { biMesaPlateauF, 0xb09765 },
- { biMesaPlateau, 0xca8c65 },
-
- // M variants:
- { biSunflowerPlains, 0xb5db88 },
- { biDesertM, 0xffbc40 },
- { biExtremeHillsM, 0x888888 },
- { biFlowerForest, 0x2d8e49 },
- { biTaigaM, 0x338e81 },
- { biSwamplandM, 0x07f9b2 },
- { biIcePlainsSpikes, 0xb4dcdc },
- { biJungleM, 0x7ba331 },
- { biJungleEdgeM, 0x628b17 },
- { biBirchForestM, 0x589c6c },
- { biBirchForestHillsM, 0x47875a },
- { biRoofedForestM, 0x687942 },
- { biColdTaigaM, 0x243f36 },
- { biMegaSpruceTaiga, 0x454f3e },
- { biMegaSpruceTaigaHills, 0x454f4e },
- { biExtremeHillsPlusM, 0x789878 },
- { biSavannaM, 0xe5da87 },
- { biSavannaPlateauM, 0xa79d74 },
- { biMesaBryce, 0xff6d3d },
- { biMesaPlateauFM, 0xd8bf8d },
- { biMesaPlateauM, 0xf2b48d },
-} ;
-
-
-
-
-
-static class cBiomeColorsInitializer
-{
-public:
- cBiomeColorsInitializer(void)
- {
- // Reset all colors to gray:
- for (size_t i = 0; i < ARRAYCOUNT(g_BiomeColors); i++)
- {
- g_BiomeColors[i] = 0x7f7f7f;
- }
- for (size_t i = 0; i < ARRAYCOUNT(g_BiomeColorMap); i++)
- {
- g_BiomeColors[g_BiomeColorMap[i].Biome] = g_BiomeColorMap[i].Color;
- }
- }
-} g_Initializer;
-
-
-
-
diff --git a/Tools/BiomeVisualiser/BiomeColors.h b/Tools/BiomeVisualiser/BiomeColors.h
deleted file mode 100644
index 0cb0f578c..000000000
--- a/Tools/BiomeVisualiser/BiomeColors.h
+++ /dev/null
@@ -1,15 +0,0 @@
-
-// BiomeColors.h
-
-// Declares the g_BiomeColors[] array used for biome color lookup
-
-
-
-
-
-extern int g_BiomeColors[256];
-
-
-
-
-
diff --git a/Tools/BiomeVisualiser/BiomeRenderer.cpp b/Tools/BiomeVisualiser/BiomeRenderer.cpp
deleted file mode 100644
index c0123c08a..000000000
--- a/Tools/BiomeVisualiser/BiomeRenderer.cpp
+++ /dev/null
@@ -1,119 +0,0 @@
-
-// BiomeRenderer.cpp
-
-// Implements the cBiomeRenderer class representing the rendering engine
-
-#include "Globals.h"
-#include "BiomeRenderer.h"
-#include "Pixmap.h"
-#include "Timer.h"
-#include "BiomeColors.h"
-
-
-
-
-
-cBiomeRenderer::cBiomeRenderer(void) :
- m_OriginX(160),
- m_OriginY(160),
- m_Zoom(1)
-{
-}
-
-
-
-
-void cBiomeRenderer::SetSource(cBiomeSource * a_Source)
-{
- m_Cache.SetSource(a_Source);
-}
-
-
-
-
-
-bool cBiomeRenderer::Render(cPixmap & a_Pixmap)
-{
- cTimer Timer("cBiomeRenderer::Render");
-
- int Wid = a_Pixmap.GetWidth();
- int Hei = a_Pixmap.GetHeight();
-
- // Hint the approximate view area to the biome source so that it can adjust its caches:
- int MinBlockX = ( - m_OriginX) * m_Zoom;
- int MaxBlockX = (Wid - m_OriginX) * m_Zoom;
- int MinBlockZ = ( - m_OriginY) * m_Zoom;
- int MaxBlockZ = (Hei - m_OriginY) * m_Zoom;
- m_Cache.HintViewArea(MinBlockX / 16 - 1, MaxBlockX / 16 + 1, MinBlockZ / 16 - 1, MaxBlockZ / 16 + 1);
-
- // Hold one current chunk of biome data:
- int CurChunkX = -10000;
- int CurChunkZ = -10000;
- cChunkDef::BiomeMap CurBiomes;
-
- bool res = false;
-
- for (int y = 0; y < Hei; y++)
- {
- int BlockZ = (y - m_OriginY) * m_Zoom;
- int ChunkZ = (BlockZ >= 0) ? (BlockZ / 16) : ((BlockZ + 1) / 16 - 1);
- int RelZ = BlockZ - ChunkZ * 16;
- for (int x = 0; x < Wid; x++)
- {
- int BlockX = (x - m_OriginX) * m_Zoom;
- int ChunkX = (BlockX >= 0) ? (BlockX / 16) : ((BlockX + 1) / 16 - 1);
- int RelX = BlockX - ChunkX * 16;
- if ((ChunkZ != CurChunkZ) || (ChunkX != CurChunkX))
- {
- CurChunkX = ChunkX;
- CurChunkZ = ChunkZ;
- switch (m_Cache.GetBiome(CurChunkX, CurChunkZ, CurBiomes))
- {
- case cBiomeSource::baLater:
- {
- res = true;
- // fallthrough:
- }
- case cBiomeSource::baNever:
- {
- for (int i = 0; i < ARRAYCOUNT(CurBiomes); i++)
- {
- CurBiomes[i] = biInvalidBiome;
- }
- break;
- }
- } // switch (Biome availability)
- }
- EMCSBiome Biome = cChunkDef::GetBiome(CurBiomes, RelX, RelZ);
- a_Pixmap.SetPixel(x, y, GetBiomeColor(Biome));
- } // for x
- } // for y
- return res;
-}
-
-
-
-
-
-int cBiomeRenderer::GetBiomeColor(EMCSBiome a_Biome)
-{
- if ((a_Biome < 0) || (a_Biome >= ARRAYCOUNT(g_BiomeColors)))
- {
- return 0xff0000;
- }
- return g_BiomeColors[a_Biome];
-}
-
-
-
-
-
-void cBiomeRenderer::MoveViewBy(int a_OffsX, int a_OffsY)
-{
- m_OriginX += a_OffsX;
- m_OriginY += a_OffsY;
-}
-
-
-
-
diff --git a/Tools/BiomeVisualiser/BiomeRenderer.h b/Tools/BiomeVisualiser/BiomeRenderer.h
deleted file mode 100644
index 752b61811..000000000
--- a/Tools/BiomeVisualiser/BiomeRenderer.h
+++ /dev/null
@@ -1,55 +0,0 @@
-
-// BiomeRenderer.h
-
-// Declares the cBiomeRenderer class representing the rendering engine
-
-
-
-
-
-#pragma once
-
-#include "BiomeCache.h"
-
-
-
-
-
-// fwd: Pixmap.h
-class cPixmap;
-
-
-
-
-
-class cBiomeRenderer
-{
-public:
- cBiomeRenderer(void);
-
- void SetSource(cBiomeSource * a_Source); // Takes ownership of the source
-
- /// Renders the biomes into the given pixmap. Returns true if some biome data was missing and can be retrieved later
- bool Render(cPixmap & a_Pixmap);
-
- /// Returns the RGB color value for the specified biome
- int GetBiomeColor(EMCSBiome a_Biome);
-
- void MoveViewBy(int a_OffsX, int a_OffsY);
-
- void SetZoom(int a_NewZoom)
- {
- m_Zoom = a_NewZoom;
- }
-
-protected:
- cBiomeCache m_Cache;
-
- int m_OriginX;
- int m_OriginY;
- int m_Zoom;
-} ;
-
-
-
-
diff --git a/Tools/BiomeVisualiser/BiomeSource.h b/Tools/BiomeVisualiser/BiomeSource.h
deleted file mode 100644
index 4a5153457..000000000
--- a/Tools/BiomeVisualiser/BiomeSource.h
+++ /dev/null
@@ -1,37 +0,0 @@
-
-// BiomeSource.h
-
-// Declares the cBiomeSource abstract class used as an interface for getting biomes from any source
-
-#pragma once
-
-
-
-
-
-#include "ChunkDef.h"
-
-
-
-
-
-class cBiomeSource abstract
-{
-public:
- enum eAvailability
- {
- baNow, // Data returned now
- baLater, // Data not returned, but will be available later, try again after a while
- baNever, // Data not returned, will not be available at all
- } ;
-
- /// Fills a_Biomes with the biomes for the chunk specified
- virtual eAvailability GetBiome(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_Biomes) = 0;
-
- /// Used to inform the source about the view area that will be queried in the near future.
- virtual void HintViewArea(int a_MinChunkX, int a_MaxChunkX, int a_MinChunkZ, int a_MaxChunkZ) = 0;
-} ;
-
-
-
-
diff --git a/Tools/BiomeVisualiser/BiomeViewWnd.cpp b/Tools/BiomeVisualiser/BiomeViewWnd.cpp
deleted file mode 100644
index 7fb61c062..000000000
--- a/Tools/BiomeVisualiser/BiomeViewWnd.cpp
+++ /dev/null
@@ -1,247 +0,0 @@
-
-// BiomeViewWnd.cpp
-
-// Implements the cBiomeViewWnd class representing the window that displays biomes
-
-#include "Globals.h"
-#include "BiomeViewWnd.h"
-#include "BiomeCache.h"
-#include "GeneratorBiomeSource.h"
-#include "iniFile/iniFile.h"
-
-
-
-
-
-const int TIMER_RERENDER = 1200;
-
-
-
-
-
-cBiomeViewWnd::cBiomeViewWnd(void) :
- m_Wnd(NULL),
- m_Thunk(&cBiomeViewWnd::WndProc, this),
- m_IsLButtonDown(false)
-{
-}
-
-
-
-
-
-bool cBiomeViewWnd::Create(HWND a_ParentWnd, LPCTSTR a_Title)
-{
- ASSERT(m_Wnd == NULL);
-
- InitBiomeView();
-
- // Create a regular STATIC window, then override its window procedure with our own. No need for obnoxious RegisterWindowClass() stuff.
- m_Wnd = CreateWindow("STATIC", a_Title, WS_OVERLAPPEDWINDOW | WS_VISIBLE, 0, 0, 400, 300, a_ParentWnd, NULL, GetModuleHandle(NULL), NULL);
- if (m_Wnd == NULL)
- {
- LOGERROR("Cannot create main window: %d", GetLastError());
- return false;
- }
- SetWindowLongPtr(m_Wnd, GWLP_WNDPROC, m_Thunk);
-
- return true;
-}
-
-
-
-
-
-void cBiomeViewWnd::InitBiomeView(void)
-{
- cIniFile IniFile;
- IniFile.ReadFile("world.ini");
- int Seed = IniFile.GetValueSetI("Generator", "Seed", 0);
- bool CacheOffByDefault = false;
- m_BiomeGen = cBiomeGen::CreateBiomeGen(IniFile, Seed, CacheOffByDefault);
- m_Renderer.SetSource(new cGeneratorBiomeSource(m_BiomeGen));
- IniFile.WriteFile("world.ini");
-}
-
-
-
-
-
-void cBiomeViewWnd::SetZoom(int a_NewZoom)
-{
- m_Renderer.SetZoom(a_NewZoom);
- Redraw();
-}
-
-
-
-
-
-void cBiomeViewWnd::Redraw(void)
-{
- if (m_Renderer.Render(m_Pixmap))
- {
- SetTimer(m_Wnd, TIMER_RERENDER, 200, NULL);
- }
- InvalidateRect(m_Wnd, NULL, FALSE);
-}
-
-
-
-
-
-LRESULT cBiomeViewWnd::WndProc(HWND a_Wnd, UINT a_Msg, WPARAM wParam, LPARAM lParam)
-{
- switch (a_Msg)
- {
- case WM_CHAR: return OnChar (wParam, lParam);
- case WM_CLOSE: return OnClose ();
- case WM_COMMAND: return OnCommand (wParam, lParam);
- case WM_LBUTTONDOWN: return OnLButtonDown(wParam, lParam);
- case WM_LBUTTONUP: return OnLButtonUp (wParam, lParam);
- case WM_MOUSEMOVE: return OnMouseMove (wParam, lParam);
- case WM_PAINT: return OnPaint ();
- case WM_TIMER: return OnTimer (wParam);
- }
- return ::DefWindowProc(a_Wnd, a_Msg, wParam, lParam);
-}
-
-
-
-
-
-LRESULT cBiomeViewWnd::OnChar(WPARAM wParam, LPARAM lParam)
-{
- switch (wParam)
- {
- case '1': SetZoom(1); break;
- case '2': SetZoom(2); break;
- case '3': SetZoom(3); break;
- case '4': SetZoom(4); break;
- case '5': SetZoom(5); break;
- case '6': SetZoom(6); break;
- case '7': SetZoom(7); break;
- case '8': SetZoom(8); break;
- case 27:
- {
- // Esc pressed, exit
- PostQuitMessage(0);
- break;
- }
- }
- return 0;
-}
-
-
-
-
-
-LRESULT cBiomeViewWnd::OnClose(void)
-{
- PostQuitMessage(0);
- return 0;
-}
-
-
-
-
-
-LRESULT cBiomeViewWnd::OnCommand(WPARAM wParam, LPARAM lParam)
-{
- // TODO: Handle menu commands, when we get menu
- return 0;
-}
-
-
-
-
-
-LRESULT cBiomeViewWnd::OnLButtonDown(WPARAM wParam, LPARAM lParam)
-{
- m_IsLButtonDown = true;
- GetCursorPos(&m_MouseDown);
- return 0;
-}
-
-
-
-
-
-LRESULT cBiomeViewWnd::OnMouseMove(WPARAM wParam, LPARAM lParam)
-{
- if (!m_IsLButtonDown)
- {
- return 0;
- }
- POINT pnt;
- GetCursorPos(&pnt);
- m_Renderer.MoveViewBy(pnt.x - m_MouseDown.x, pnt.y - m_MouseDown.y);
- m_MouseDown = pnt;
- Redraw();
- return 0;
-}
-
-
-
-
-
-LRESULT cBiomeViewWnd::OnLButtonUp(WPARAM wParam, LPARAM lParam)
-{
- OnMouseMove(wParam, lParam); // Last movement - if the mouse move hasn't been reported due to speed
- m_IsLButtonDown = false;
- InvalidateRect(m_Wnd, NULL, FALSE);
- return 0;
-}
-
-
-
-
-
-LRESULT cBiomeViewWnd::OnPaint(void)
-{
- PAINTSTRUCT ps;
- HDC DC = BeginPaint(m_Wnd, &ps);
-
- RECT rc;
- GetClientRect(m_Wnd, &rc);
- int Wid = rc.right - rc.left;
- int Hei = rc.bottom - rc.top;
- if ((m_Pixmap.GetWidth() != Wid) || (m_Pixmap.GetHeight() != Hei))
- {
- m_Pixmap.SetSize(Wid, Hei);
- if (m_Renderer.Render(m_Pixmap))
- {
- SetTimer(m_Wnd, TIMER_RERENDER, 200, NULL);
- }
- }
-
- m_Pixmap.DrawToDC(DC, 0, 0);
-
- EndPaint(m_Wnd, &ps);
- return 0;
-}
-
-
-
-
-
-LRESULT cBiomeViewWnd::OnTimer(WPARAM wParam)
-{
- switch (wParam)
- {
- case TIMER_RERENDER:
- {
- if (!m_Renderer.Render(m_Pixmap))
- {
- KillTimer(m_Wnd, TIMER_RERENDER);
- }
- InvalidateRect(m_Wnd, NULL, FALSE);
- break;
- }
- }
- return 0;
-}
-
-
-
-
diff --git a/Tools/BiomeVisualiser/BiomeViewWnd.h b/Tools/BiomeVisualiser/BiomeViewWnd.h
deleted file mode 100644
index 70c5e38f2..000000000
--- a/Tools/BiomeVisualiser/BiomeViewWnd.h
+++ /dev/null
@@ -1,69 +0,0 @@
-
-// BiomeViewWnd.h
-
-// Declares the cBiomeViewWnd class representing the window that displays biomes
-
-
-
-
-
-#pragma once
-
-#include "WndProcThunk.h"
-#include "BiomeRenderer.h"
-#include "BiomeCache.h"
-#include "Pixmap.h"
-
-
-
-
-
-// fwd:
-class cBiomeGen;
-
-
-
-
-
-class cBiomeViewWnd
-{
-public:
- cBiomeViewWnd(void);
-
- bool Create(HWND a_ParentWnd, LPCTSTR a_Title);
-
-protected:
- HWND m_Wnd;
- CWndProcThunk<cBiomeViewWnd> m_Thunk;
-
- cBiomeRenderer m_Renderer;
- cPixmap m_Pixmap;
-
- /// The generator that is to be visualised
- cBiomeGen * m_BiomeGen;
-
- bool m_IsLButtonDown;
- POINT m_MouseDown;
-
-
- void InitBiomeView(void);
-
- void SetZoom(int a_NewZoom);
- void Redraw(void);
-
- LRESULT WndProc(HWND a_Wnd, UINT a_Msg, WPARAM wParam, LPARAM lParam);
-
- // Message handlers:
- LRESULT OnChar (WPARAM wParam, LPARAM lParam);
- LRESULT OnClose (void);
- LRESULT OnCommand (WPARAM wParam, LPARAM lParam);
- LRESULT OnLButtonDown(WPARAM wParam, LPARAM lParam);
- LRESULT OnMouseMove (WPARAM wParam, LPARAM lParam);
- LRESULT OnLButtonUp (WPARAM wParam, LPARAM lParam);
- LRESULT OnPaint (void);
- LRESULT OnTimer (WPARAM wParam);
-} ;
-
-
-
-
diff --git a/Tools/BiomeVisualiser/BiomeVisualiser.cpp b/Tools/BiomeVisualiser/BiomeVisualiser.cpp
deleted file mode 100644
index a36111d77..000000000
--- a/Tools/BiomeVisualiser/BiomeVisualiser.cpp
+++ /dev/null
@@ -1,52 +0,0 @@
-
-// BiomeVisualiser.cpp
-
-// Implements the cBiomeVisualiser class representing the entire app. Also implements the WinMain() entrypoint
-
-#include "Globals.h"
-#include "time.h"
-#include "BiomeVisualiser.h"
-
-
-
-
-
-int WINAPI WinMain(HINSTANCE a_Instance, HINSTANCE a_PrevInstance, LPSTR a_CmdLine, int a_ShowCmd)
-{
- cBiomeVisualiser App;
- return App.Run();
-}
-
-
-
-
-
-cBiomeVisualiser::cBiomeVisualiser(void) :
- m_Logger(new cMCLogger(Printf("BiomeVisualiser_%08x.log", time(NULL))))
-{
-}
-
-
-
-
-
-int cBiomeVisualiser::Run(void)
-{
- if (!m_MainWnd.Create(GetDesktopWindow(), TEXT("BiomeVisualiser")))
- {
- LOGERROR("Cannot create main window: %d", GetLastError());
- return 1;
- }
-
- MSG msg;
- while (GetMessage(&msg, NULL, 0, 0))
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- } // while (GetMessage)
- return msg.lParam;
-}
-
-
-
-
diff --git a/Tools/BiomeVisualiser/BiomeVisualiser.h b/Tools/BiomeVisualiser/BiomeVisualiser.h
deleted file mode 100644
index 4f8ce7513..000000000
--- a/Tools/BiomeVisualiser/BiomeVisualiser.h
+++ /dev/null
@@ -1,31 +0,0 @@
-
-// BiomeVisualiser.h
-
-// Declares the cBiomeVisualiser class representing the entire application
-
-
-
-
-
-#include "BiomeViewWnd.h"
-
-
-
-
-
-class cBiomeVisualiser
-{
-public:
- cBiomeVisualiser(void);
-
- int Run(void);
-
-protected:
- cBiomeViewWnd m_MainWnd;
-
- cMCLogger * m_Logger;
-} ;
-
-
-
-
diff --git a/Tools/BiomeVisualiser/BiomeVisualiser.sln b/Tools/BiomeVisualiser/BiomeVisualiser.sln
deleted file mode 100644
index bdfb586b1..000000000
--- a/Tools/BiomeVisualiser/BiomeVisualiser.sln
+++ /dev/null
@@ -1,23 +0,0 @@
-
-Microsoft Visual Studio Solution File, Format Version 10.00
-# Visual C++ Express 2008
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BiomeVisualiser", "BiomeVisualiser.vcproj", "{6DF3D88B-AD47-45B6-B831-1BDE74F86B5C}"
-EndProject
-Global
- GlobalSection(SolutionConfigurationPlatforms) = preSolution
- Debug|Win32 = Debug|Win32
- Release profiled|Win32 = Release profiled|Win32
- Release|Win32 = Release|Win32
- EndGlobalSection
- GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {6DF3D88B-AD47-45B6-B831-1BDE74F86B5C}.Debug|Win32.ActiveCfg = Debug|Win32
- {6DF3D88B-AD47-45B6-B831-1BDE74F86B5C}.Debug|Win32.Build.0 = Debug|Win32
- {6DF3D88B-AD47-45B6-B831-1BDE74F86B5C}.Release profiled|Win32.ActiveCfg = Release profiled|Win32
- {6DF3D88B-AD47-45B6-B831-1BDE74F86B5C}.Release profiled|Win32.Build.0 = Release profiled|Win32
- {6DF3D88B-AD47-45B6-B831-1BDE74F86B5C}.Release|Win32.ActiveCfg = Release|Win32
- {6DF3D88B-AD47-45B6-B831-1BDE74F86B5C}.Release|Win32.Build.0 = Release|Win32
- EndGlobalSection
- GlobalSection(SolutionProperties) = preSolution
- HideSolutionNode = FALSE
- EndGlobalSection
-EndGlobal
diff --git a/Tools/BiomeVisualiser/BiomeVisualiser.vcproj b/Tools/BiomeVisualiser/BiomeVisualiser.vcproj
deleted file mode 100644
index 3de564ad4..000000000
--- a/Tools/BiomeVisualiser/BiomeVisualiser.vcproj
+++ /dev/null
@@ -1,527 +0,0 @@
-<?xml version="1.0" encoding="windows-1250"?>
-<VisualStudioProject
- ProjectType="Visual C++"
- Version="9,00"
- Name="BiomeVisualiser"
- ProjectGUID="{6DF3D88B-AD47-45B6-B831-1BDE74F86B5C}"
- RootNamespace="BiomeVisualiser"
- Keyword="Win32Proj"
- TargetFrameworkVersion="196613"
- >
- <Platforms>
- <Platform
- Name="Win32"
- />
- </Platforms>
- <ToolFiles>
- </ToolFiles>
- <Configurations>
- <Configuration
- Name="Debug|Win32"
- OutputDirectory="$(SolutionDir)$(ConfigurationName)"
- IntermediateDirectory="$(ConfigurationName)"
- ConfigurationType="1"
- CharacterSet="2"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- />
- <Tool
- Name="VCCLCompilerTool"
- Optimization="0"
- AdditionalIncludeDirectories="../../src;../../lib"
- PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS"
- MinimalRebuild="true"
- BasicRuntimeChecks="3"
- RuntimeLibrary="1"
- UsePrecompiledHeader="2"
- PrecompiledHeaderThrough="Globals.h"
- WarningLevel="3"
- DebugInformationFormat="4"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLinkerTool"
- AdditionalDependencies="ws2_32.lib"
- LinkIncremental="2"
- GenerateDebugInformation="true"
- SubSystem="2"
- TargetMachine="1"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCManifestTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCAppVerifierTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- />
- </Configuration>
- <Configuration
- Name="Release|Win32"
- OutputDirectory="$(SolutionDir)$(ConfigurationName)"
- IntermediateDirectory="$(ConfigurationName)"
- ConfigurationType="1"
- CharacterSet="2"
- WholeProgramOptimization="1"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- />
- <Tool
- Name="VCCLCompilerTool"
- Optimization="2"
- InlineFunctionExpansion="2"
- EnableIntrinsicFunctions="true"
- FavorSizeOrSpeed="1"
- AdditionalIncludeDirectories="../../src;../../lib"
- PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
- RuntimeLibrary="0"
- EnableFunctionLevelLinking="true"
- EnableEnhancedInstructionSet="2"
- UsePrecompiledHeader="2"
- PrecompiledHeaderThrough="Globals.h"
- WarningLevel="3"
- DebugInformationFormat="3"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLinkerTool"
- AdditionalDependencies="ws2_32.lib"
- LinkIncremental="1"
- GenerateDebugInformation="true"
- SubSystem="2"
- OptimizeReferences="2"
- EnableCOMDATFolding="2"
- TargetMachine="1"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCManifestTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCAppVerifierTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- />
- </Configuration>
- <Configuration
- Name="Release profiled|Win32"
- OutputDirectory="$(SolutionDir)$(ConfigurationName)"
- IntermediateDirectory="$(ConfigurationName)"
- ConfigurationType="1"
- CharacterSet="2"
- WholeProgramOptimization="1"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- />
- <Tool
- Name="VCCLCompilerTool"
- Optimization="2"
- InlineFunctionExpansion="2"
- EnableIntrinsicFunctions="true"
- FavorSizeOrSpeed="1"
- AdditionalIncludeDirectories="../../src;../../lib"
- PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
- RuntimeLibrary="0"
- EnableFunctionLevelLinking="true"
- EnableEnhancedInstructionSet="2"
- UsePrecompiledHeader="2"
- PrecompiledHeaderThrough="Globals.h"
- WarningLevel="3"
- DebugInformationFormat="3"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLinkerTool"
- AdditionalDependencies="ws2_32.lib"
- LinkIncremental="1"
- GenerateDebugInformation="true"
- SubSystem="2"
- OptimizeReferences="2"
- EnableCOMDATFolding="2"
- TargetMachine="1"
- Profile="true"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCManifestTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCAppVerifierTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- />
- </Configuration>
- </Configurations>
- <References>
- </References>
- <Files>
- <Filter
- Name="Source Files"
- Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
- UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
- >
- <File
- RelativePath=".\BiomeCache.cpp"
- >
- </File>
- <File
- RelativePath=".\BiomeCache.h"
- >
- </File>
- <File
- RelativePath=".\BiomeColors.cpp"
- >
- </File>
- <File
- RelativePath=".\BiomeColors.h"
- >
- </File>
- <File
- RelativePath=".\BiomeRenderer.cpp"
- >
- </File>
- <File
- RelativePath=".\BiomeRenderer.h"
- >
- </File>
- <File
- RelativePath=".\BiomeSource.h"
- >
- </File>
- <File
- RelativePath=".\BiomeViewWnd.cpp"
- >
- </File>
- <File
- RelativePath=".\BiomeViewWnd.h"
- >
- </File>
- <File
- RelativePath=".\BiomeVisualiser.cpp"
- >
- </File>
- <File
- RelativePath=".\BiomeVisualiser.h"
- >
- </File>
- <File
- RelativePath=".\GeneratorBiomeSource.h"
- >
- </File>
- <File
- RelativePath=".\Pixmap.cpp"
- >
- </File>
- <File
- RelativePath=".\Pixmap.h"
- >
- </File>
- <File
- RelativePath=".\Timer.h"
- >
- </File>
- <File
- RelativePath=".\WndProcThunk.h"
- >
- </File>
- <Filter
- Name="Shared"
- >
- <File
- RelativePath="..\..\src\BiomeDef.cpp"
- >
- </File>
- <File
- RelativePath="..\..\src\BiomeDef.h"
- >
- </File>
- <File
- RelativePath="..\..\src\BlockID.cpp"
- >
- </File>
- <File
- RelativePath="..\..\src\BlockID.h"
- >
- </File>
- <File
- RelativePath="..\..\src\ChunkDef.h"
- >
- </File>
- <File
- RelativePath="..\..\src\Enchantments.cpp"
- >
- </File>
- <File
- RelativePath="..\..\src\Enchantments.h"
- >
- </File>
- <File
- RelativePath="..\..\src\WorldStorage\FastNBT.cpp"
- >
- </File>
- <File
- RelativePath="..\..\src\WorldStorage\FastNBT.h"
- >
- </File>
- <File
- RelativePath="..\..\src\FastRandom.cpp"
- >
- </File>
- <File
- RelativePath="..\..\src\FastRandom.h"
- >
- </File>
- <File
- RelativePath="..\..\src\Globals.cpp"
- >
- <FileConfiguration
- Name="Debug|Win32"
- >
- <Tool
- Name="VCCLCompilerTool"
- UsePrecompiledHeader="1"
- />
- </FileConfiguration>
- <FileConfiguration
- Name="Release|Win32"
- >
- <Tool
- Name="VCCLCompilerTool"
- UsePrecompiledHeader="1"
- />
- </FileConfiguration>
- <FileConfiguration
- Name="Release profiled|Win32"
- >
- <Tool
- Name="VCCLCompilerTool"
- UsePrecompiledHeader="1"
- />
- </FileConfiguration>
- </File>
- <File
- RelativePath="..\..\src\Globals.h"
- >
- </File>
- <File
- RelativePath="..\..\src\Item.h"
- >
- </File>
- <File
- RelativePath="..\..\src\Log.cpp"
- >
- </File>
- <File
- RelativePath="..\..\src\Log.h"
- >
- </File>
- <File
- RelativePath="..\..\src\MCLogger.cpp"
- >
- </File>
- <File
- RelativePath="..\..\src\MCLogger.h"
- >
- </File>
- <File
- RelativePath="..\..\src\Noise.cpp"
- >
- </File>
- <File
- RelativePath="..\..\src\Noise.h"
- >
- </File>
- <File
- RelativePath="..\..\src\Noise.inc"
- >
- </File>
- <File
- RelativePath="..\..\src\StringUtils.cpp"
- >
- </File>
- <File
- RelativePath="..\..\src\StringUtils.h"
- >
- </File>
- <File
- RelativePath="..\..\src\VoronoiMap.cpp"
- >
- </File>
- <File
- RelativePath="..\..\src\VoronoiMap.h"
- >
- </File>
- <Filter
- Name="OSSupport"
- >
- <File
- RelativePath="..\..\src\OSSupport\CriticalSection.cpp"
- >
- </File>
- <File
- RelativePath="..\..\src\OSSupport\CriticalSection.h"
- >
- </File>
- <File
- RelativePath="..\..\src\OSSupport\Event.cpp"
- >
- </File>
- <File
- RelativePath="..\..\src\OSSupport\Event.h"
- >
- </File>
- <File
- RelativePath="..\..\src\OSSupport\File.cpp"
- >
- </File>
- <File
- RelativePath="..\..\src\OSSupport\File.h"
- >
- </File>
- <File
- RelativePath="..\..\src\OSSupport\IsThread.cpp"
- >
- </File>
- <File
- RelativePath="..\..\src\OSSupport\IsThread.h"
- >
- </File>
- <File
- RelativePath="..\..\src\OSSupport\Sleep.h"
- >
- </File>
- </Filter>
- <Filter
- Name="Generating"
- >
- <File
- RelativePath="..\..\src\Generating\BioGen.cpp"
- >
- </File>
- <File
- RelativePath="..\..\src\Generating\BioGen.h"
- >
- </File>
- <File
- RelativePath="..\..\src\Generating\ComposableGenerator.h"
- >
- </File>
- </Filter>
- <Filter
- Name="iniFile"
- >
- <File
- RelativePath="..\..\lib\iniFile\iniFile.cpp"
- >
- </File>
- <File
- RelativePath="..\..\lib\iniFile\iniFile.h"
- >
- </File>
- </Filter>
- </Filter>
- </Filter>
- </Files>
- <Globals>
- </Globals>
-</VisualStudioProject>
diff --git a/Tools/BiomeVisualiser/GeneratorBiomeSource.h b/Tools/BiomeVisualiser/GeneratorBiomeSource.h
deleted file mode 100644
index 751aed245..000000000
--- a/Tools/BiomeVisualiser/GeneratorBiomeSource.h
+++ /dev/null
@@ -1,42 +0,0 @@
-
-// GeneratorBiomeSource.h
-
-// Declares the cGeneratorBiomeSource that adapts a cBiomeGen into a cBiomeSource
-
-#include "../src/Generating/BioGen.h"
-#include "BiomeSource.h"
-
-
-
-
-
-class cGeneratorBiomeSource :
- public cBiomeSource
-{
-public:
- cGeneratorBiomeSource(cBiomeGen * a_Generator) : m_Generator(a_Generator) {} // Takes ownership of the generator ptr
-
- ~cGeneratorBiomeSource()
- {
- delete m_Generator;
- }
-
- // cBiomeSource overrides:
- virtual eAvailability GetBiome(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_Biomes) override
- {
- m_Generator->GenBiomes(a_ChunkX, a_ChunkZ, a_Biomes);
- return baNow;
- }
-
- virtual void HintViewArea(int a_MinChunkX, int a_MaxChunkX, int a_MinChunkZ, int a_MaxChunkZ) override
- {
- // Nothing needed
- }
-
-protected:
- cBiomeGen * m_Generator;
-} ;
-
-
-
-
diff --git a/Tools/BiomeVisualiser/Pixmap.cpp b/Tools/BiomeVisualiser/Pixmap.cpp
deleted file mode 100644
index 1a80cf465..000000000
--- a/Tools/BiomeVisualiser/Pixmap.cpp
+++ /dev/null
@@ -1,120 +0,0 @@
-
-// Pixmap.cpp
-
-// Implements the cPixmap class that represents a RGB pixmap and allows simple operations on it
-
-#include "Globals.h"
-#include "Pixmap.h"
-
-
-
-
-
-cPixmap::cPixmap(void) :
- m_Width(0),
- m_Height(0),
- m_Stride(0),
- m_Pixels(NULL)
-{
-}
-
-
-
-
-
-cPixmap::cPixmap(int a_Width, int a_Height) :
- m_Width(0),
- m_Height(0),
- m_Stride(0),
- m_Pixels(NULL)
-{
- SetSize(a_Width, a_Height);
-}
-
-
-
-
-
-cPixmap::~cPixmap()
-{
- delete m_Pixels;
-}
-
-
-
-
-
-void cPixmap::SetSize(int a_Width, int a_Height)
-{
- delete m_Pixels;
- m_Pixels = new int[a_Width * a_Height];
- m_Width = a_Width;
- m_Height = a_Height;
- m_Stride = m_Width; // Currently we don't need a special stride value, but let's support it for the future :)
-}
-
-
-
-
-
-void cPixmap::SetPixel(int a_X, int a_Y, int a_Color)
-{
- ASSERT(a_X >= 0);
- ASSERT(a_X < m_Width);
- ASSERT(a_Y >= 0);
- ASSERT(a_Y < m_Height);
-
- m_Pixels[a_X + a_Y * m_Stride] = a_Color;
-}
-
-
-
-
-
-int cPixmap::GetPixel(int a_X, int a_Y) const
-{
- ASSERT(a_X >= 0);
- ASSERT(a_X < m_Width);
- ASSERT(a_Y >= 0);
- ASSERT(a_Y < m_Height);
-
- return m_Pixels[a_X + a_Y * m_Stride];
-}
-
-
-
-
-
-void cPixmap::Fill(int a_Color)
-{
- int NumElements = m_Height * m_Stride;
- for (int i = 0; i < NumElements; i++)
- {
- m_Pixels[i] = a_Color;
- }
-}
-
-
-
-
-
-void cPixmap::DrawToDC(HDC a_DC, int a_OriginX, int a_OriginY)
-{
- BITMAPINFO bmi;
- bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
- bmi.bmiHeader.biWidth = m_Width;
- bmi.bmiHeader.biHeight = -m_Height; // Negative, we are top-down, unlike BMPs
- bmi.bmiHeader.biPlanes = 1;
- bmi.bmiHeader.biBitCount = 32;
- bmi.bmiHeader.biCompression = BI_RGB;
- bmi.bmiHeader.biSizeImage = m_Stride * m_Height * 4;
- bmi.bmiHeader.biXPelsPerMeter = 1440;
- bmi.bmiHeader.biYPelsPerMeter = 1440;
- bmi.bmiHeader.biClrUsed = 0;
- bmi.bmiHeader.biClrImportant = 0;
- SetDIBitsToDevice(a_DC, a_OriginX, a_OriginY, m_Width, m_Height, 0, 0, 0, m_Height, m_Pixels, &bmi, DIB_RGB_COLORS);
-}
-
-
-
-
diff --git a/Tools/BiomeVisualiser/Pixmap.h b/Tools/BiomeVisualiser/Pixmap.h
deleted file mode 100644
index e50f6e946..000000000
--- a/Tools/BiomeVisualiser/Pixmap.h
+++ /dev/null
@@ -1,39 +0,0 @@
-
-// Pixmap.h
-
-// Declares a cPixmap class that represents a RGB pixmap and allows simple operations on it
-
-#pragma once
-
-
-
-
-
-class cPixmap
-{
-public:
- cPixmap(void);
- cPixmap(int a_Width, int a_Height);
- ~cPixmap();
-
- void SetSize(int a_Width, int a_Height);
-
- int GetWidth (void) const { return m_Width; }
- int GetHeight(void) const { return m_Height; }
-
- void SetPixel(int a_X, int a_Y, int a_Color);
- int GetPixel(int a_X, int a_Y) const;
- void Fill(int a_Color);
-
- void DrawToDC(HDC a_DC, int a_OriginX, int a_OriginY);
-
-protected:
- int m_Width;
- int m_Height;
- int m_Stride;
- int * m_Pixels;
-} ;
-
-
-
-
diff --git a/Tools/BiomeVisualiser/Timer.h b/Tools/BiomeVisualiser/Timer.h
deleted file mode 100644
index 78c4b42c7..000000000
--- a/Tools/BiomeVisualiser/Timer.h
+++ /dev/null
@@ -1,40 +0,0 @@
-
-// Timer.h
-
-// Declares the cTimer class representing a RAII class that measures time from its creation till its destruction
-
-
-
-
-
-#pragma once
-
-#include "time.h"
-
-
-
-
-
-class cTimer
-{
-public:
- cTimer(const AString & a_Title) :
- m_Title(a_Title),
- m_StartTime(clock())
- {
- }
-
- ~cTimer()
- {
- clock_t NumTicks = clock() - m_StartTime;
- LOG("%s took %d ticks (%.02f sec)", m_Title.c_str(), NumTicks, (double)NumTicks / CLOCKS_PER_SEC);
- }
-
-protected:
- AString m_Title;
- clock_t m_StartTime;
-} ;
-
-
-
-
diff --git a/Tools/BiomeVisualiser/WndProcThunk.h b/Tools/BiomeVisualiser/WndProcThunk.h
deleted file mode 100644
index da995eb5f..000000000
--- a/Tools/BiomeVisualiser/WndProcThunk.h
+++ /dev/null
@@ -1,143 +0,0 @@
-
-// WndProcThunk.h
-
-// Interfaces to the CWndProcThunk class responsible for WNDPROC class-thunking
-// For details, see http://www.hackcraft.net/cpp/windowsThunk/thiscall/
-// Also available is a CDlgProcThunk class doing the same work for DIALOGPROC
-
-// MD: Made NX-compat by allocating the code structure using VirtualAlloc(..., PAGE_EXECUTE_READWRITE)
-
-
-
-
-
-// fwd:
-template <class W> class CWndProcThunk;
-
-
-
-
-
-#ifndef WNDPROCTHUNK_H_INCLUDED
-#define WNDPROCTHUNK_H_INCLUDED
-
-
-
-
-template<typename To, typename From> inline To union_cast(From fr) throw()
-{
- union
- {
- From f;
- To t;
- } uc;
- uc.f = fr;
- return uc.t;
-}
-
-
-
-
-
-#pragma warning(push)
-#pragma warning(disable : 4355)
-
-#if defined(_M_IX86)
-
-#pragma pack(push,1)
-
-template <class W> class CWndProcThunk
-{
- typedef ::LRESULT (W::* WndProc)(::HWND, ::UINT, ::WPARAM, ::LPARAM);
- typedef CWndProcThunk ThisClass;
-
- struct SCode
- {
- BYTE m_mov; // mov ECX, m_this
- W * m_this; //
- BYTE m_jmp; // jmp m_relproc
- ptrdiff_t m_relproc; // relative jmp
- };
-
- SCode * Code;
-
-public:
- ThisClass(WndProc proc, W * obj)
- {
- Code = (SCode *)VirtualAlloc(NULL, sizeof(SCode), MEM_COMMIT, PAGE_EXECUTE_READWRITE);
- Code->m_mov = 0xB9,
- Code->m_this = obj,
- Code->m_jmp = 0xE9,
- Code->m_relproc = union_cast<char *>(proc) - reinterpret_cast<char *>(Code) - sizeof(*Code);
- ::FlushInstructionCache(::GetCurrentProcess(), Code, sizeof(*Code));
- }
-
- virtual ~CWndProcThunk()
- {
- VirtualFree(Code, sizeof(*Code), MEM_RELEASE);
- Code = NULL;
- }
-
- operator ::WNDPROC() const {return reinterpret_cast<::WNDPROC>(Code); }
- operator ::LONG_PTR() const {return reinterpret_cast<::LONG_PTR>(Code); }
-} ;
-
-
-
-
-
-template <class W> class CDlgProcThunk
-{
- typedef ::BOOL (W::* DlgProc)(::HWND, ::UINT, ::WPARAM, ::LPARAM);
- typedef CDlgProcThunk ThisClass;
-
- struct SCode
- {
- BYTE m_mov; // mov ECX, m_this
- W * m_this; //
- BYTE m_jmp; // jmp m_relproc
- ptrdiff_t m_relproc; // relative jmp
- };
-
- SCode * Code;
-
-public:
- CDlgProcThunk(DlgProc proc, W * obj)
- {
- Code = (SCode *)VirtualAlloc(NULL, sizeof(SCode), MEM_COMMIT, PAGE_EXECUTE_READWRITE);
- Code->m_mov = 0xB9,
- Code->m_this = obj,
- Code->m_jmp = 0xE9,
- Code->m_relproc = union_cast<char *>(proc) - reinterpret_cast<char *>(Code) - sizeof(*Code);
- ::FlushInstructionCache(::GetCurrentProcess(), Code, sizeof(*Code));
- }
-
- virtual ~CDlgProcThunk()
- {
- VirtualFree(Code, sizeof(*Code), MEM_RELEASE);
- Code = NULL;
- }
-
- operator ::DLGPROC() const {return reinterpret_cast<::DLGPROC>(Code); }
- operator ::LONG_PTR() const {return reinterpret_cast<::LONG_PTR>(Code); }
-} ;
-
-
-
-
-
- #pragma pack(pop)
-
-#else // _M_IX86
- #error Only X86 supported
-#endif
-
-
-
-
-
-#endif // WNDPROCTHUNK_H_INCLUDED
-
-
-
-
diff --git a/Tools/BiomeVisualiser/profile_run.cmd b/Tools/BiomeVisualiser/profile_run.cmd
deleted file mode 100644
index d4826d06a..000000000
--- a/Tools/BiomeVisualiser/profile_run.cmd
+++ /dev/null
@@ -1,70 +0,0 @@
-@echo off
-::
-:: Profiling using a MSVC standalone profiler
-::
-:: See http://www.codeproject.com/Articles/144643/Profiling-of-C-Applications-in-Visual-Studio-for-F for details
-::
-
-
-
-
-set pt="C:\Program Files\Microsoft Visual Studio 9.0\Team Tools\Performance Tools"
-set appdir="Release profiled"
-set app="Release profiled\BiomeVisualiser.exe"
-set args=""
-
-:: outputdir is relative to appdir!
-set outputdir=Profiling
-set output=profile.vsp
-
-
-
-
-
-::Create the output directory, if it didn't exist
-mkdir %outputdir%
-
-
-
-
-
-:: Start the profiler
-%pt%\vsperfcmd /start:sample /output:%outputdir%\%output%
-if errorlevel 1 goto haderror
-
-:: Launch the application via the profiler
-%pt%\vsperfcmd /launch:%app% /args:%args%
-if errorlevel 1 goto haderror
-
-:: Shut down the profiler (this command waits, until the application is terminated)
-%pt%\vsperfcmd /shutdown
-if errorlevel 1 goto haderror
-
-
-
-
-
-:: cd to outputdir, so that the reports are generated there
-cd %outputdir%
-
-:: generate the report files (.csv)
-%pt%\vsperfreport /summary:all %output% /symbolpath:"srv*C:\Programovani\Symbols*http://msdl.microsoft.com/download/symbols"
-if errorlevel 1 goto haderror
-
-
-
-
-
-goto finished
-
-
-
-
-:haderror
-echo An error was encountered
-pause
-
-
-
-
-:finished
diff --git a/Tools/QtBiomeVisualiser/.gitignore b/Tools/QtBiomeVisualiser/.gitignore
new file mode 100644
index 000000000..c1b62a8a7
--- /dev/null
+++ b/Tools/QtBiomeVisualiser/.gitignore
@@ -0,0 +1,2 @@
+*.pro.user
+*.pro.user.*
diff --git a/Tools/QtBiomeVisualiser/BiomeView.cpp b/Tools/QtBiomeVisualiser/BiomeView.cpp
new file mode 100644
index 000000000..bbaccb369
--- /dev/null
+++ b/Tools/QtBiomeVisualiser/BiomeView.cpp
@@ -0,0 +1,427 @@
+#include "Globals.h"
+#include "BiomeView.h"
+#include "Chunk.h"
+#include <QPainter>
+#include <QResizeEvent>
+
+
+
+
+
+static const int DELTA_STEP = 120; // The normal per-notch wheel delta
+
+
+
+
+
+BiomeView::BiomeView(QWidget * parent) :
+ super(parent),
+ m_X(0),
+ m_Z(0),
+ m_Zoom(1),
+ m_IsMouseDragging(false),
+ m_MouseWheelDelta(0)
+{
+ // Create the image used for undefined chunks:
+ int offset = 0;
+ for (int y = 0; y < 16; y++)
+ {
+ for (int x = 0; x < 16; x++)
+ {
+ uchar color = (((x & 8) ^ (y & 8)) == 0) ? 0x44 : 0x88;
+ m_EmptyChunkImage[offset++] = color;
+ m_EmptyChunkImage[offset++] = color;
+ m_EmptyChunkImage[offset++] = color;
+ m_EmptyChunkImage[offset++] = 0xff;
+ }
+ }
+
+ // Create the startup image:
+ redraw();
+
+ // Add a chunk-update callback mechanism:
+ connect(&m_Cache, SIGNAL(chunkAvailable(int, int)), this, SLOT(chunkAvailable(int, int)));
+
+ // Allow keyboard interaction:
+ setFocusPolicy(Qt::StrongFocus);
+}
+
+
+
+
+QSize BiomeView::minimumSizeHint() const
+{
+ return QSize(300, 300);
+}
+
+
+
+
+
+QSize BiomeView::sizeHint() const
+{
+ return QSize(800, 600);
+}
+
+
+
+
+
+void BiomeView::setChunkSource(std::shared_ptr<ChunkSource> a_ChunkSource)
+{
+ // Replace the source in the cache:
+ m_Cache.setChunkSource(a_ChunkSource);
+
+ // Redraw with the new source:
+ redraw();
+}
+
+
+
+
+
+void BiomeView::redraw()
+{
+ if (!hasData())
+ {
+ // No data means no image is displayed, no need to compose:
+ update();
+ return;
+ }
+
+ int chunksize = 16 * m_Zoom;
+
+ // first find the center block position
+ int centerchunkx = floor(m_X / 16);
+ int centerchunkz = floor(m_Z / 16);
+ // and the center of the screen
+ int centerx = m_Image.width() / 2;
+ int centery = m_Image.height() / 2;
+ // and align for panning
+ centerx -= (m_X - centerchunkx * 16) * m_Zoom;
+ centery -= (m_Z - centerchunkz * 16) * m_Zoom;
+ // now calculate the topleft block on the screen
+ int startx = centerchunkx - centerx / chunksize - 1;
+ int startz = centerchunkz - centery / chunksize - 1;
+ // and the dimensions of the screen in blocks
+ int blockswide = m_Image.width() / chunksize + 3;
+ int blockstall = m_Image.height() / chunksize + 3;
+
+ for (int z = startz; z < startz + blockstall; z++)
+ {
+ for (int x = startx; x < startx + blockswide; x++)
+ {
+ drawChunk(x, z);
+ }
+ }
+ update();
+}
+
+
+
+
+
+void BiomeView::chunkAvailable(int a_ChunkX, int a_ChunkZ)
+{
+ drawChunk(a_ChunkX, a_ChunkZ);
+ update();
+}
+
+
+
+
+
+void BiomeView::reload()
+{
+ if (!hasData())
+ {
+ return;
+ }
+ m_Cache.reload();
+
+ redraw();
+}
+
+
+
+
+
+void BiomeView::drawChunk(int a_ChunkX, int a_ChunkZ)
+{
+ if (!hasData())
+ {
+ return;
+ }
+
+ //fetch the chunk:
+ ChunkPtr chunk = m_Cache.fetch(a_ChunkX, a_ChunkZ);
+
+ // Figure out where on the screen this chunk should be drawn:
+ // first find the center chunk
+ int centerchunkx = floor(m_X / 16);
+ int centerchunkz = floor(m_Z / 16);
+ // and the center chunk screen coordinates
+ int centerx = m_Image.width() / 2;
+ int centery = m_Image.height() / 2;
+ // which need to be shifted to account for panning inside that chunk
+ centerx -= (m_X - centerchunkx * 16) * m_Zoom;
+ centery -= (m_Z - centerchunkz * 16) * m_Zoom;
+ // centerx,y now points to the top left corner of the center chunk
+ // so now calculate our x,y in relation
+ double chunksize = 16 * m_Zoom;
+ centerx += (a_ChunkX - centerchunkx) * chunksize;
+ centery += (a_ChunkZ - centerchunkz) * chunksize;
+
+ int srcoffset = 0;
+ uchar * bits = m_Image.bits();
+ int imgstride = m_Image.bytesPerLine();
+
+ int skipx = 0,skipy = 0;
+ int blockwidth = chunksize, blockheight = chunksize;
+ // now if we're off the screen we need to crop
+ if (centerx < 0)
+ {
+ skipx = -centerx;
+ centerx = 0;
+ }
+ if (centery < 0)
+ {
+ skipy = -centery;
+ centery = 0;
+ }
+ // or the other side, we need to trim
+ if (centerx + blockwidth > m_Image.width())
+ {
+ blockwidth = m_Image.width() - centerx;
+ }
+ if (centery + blockheight > m_Image.height())
+ {
+ blockheight = m_Image.height() - centery;
+ }
+ if ((blockwidth <= 0) || (skipx >= blockwidth))
+ {
+ return;
+ }
+ int imgoffset = centerx * 4 + centery * imgstride;
+
+ // If the chunk is valid, use its data; otherwise use the empty placeholder:
+ const uchar * src = m_EmptyChunkImage;
+ if (chunk.get() != nullptr)
+ {
+ src = chunk->getImage();
+ }
+
+ // Blit or scale-blit the image:
+ for (int z = skipy; z < blockheight; z++, imgoffset += imgstride)
+ {
+ srcoffset = floor((double)z / m_Zoom) * 16 * 4;
+ if (m_Zoom == 1.0)
+ {
+ memcpy(bits + imgoffset, src + srcoffset + skipx * 4, (blockwidth - skipx) * 4);
+ }
+ else
+ {
+ int xofs = 0;
+ for (int x = skipx; x < blockwidth; x++, xofs +=4)
+ {
+ memcpy(bits + imgoffset + xofs, src + srcoffset + (int)floor((double)x / m_Zoom) * 4, 4);
+ }
+ }
+ }
+}
+
+
+
+
+
+void BiomeView::resizeEvent(QResizeEvent * a_Event)
+{
+ m_Image = QImage(a_Event->size(), QImage::Format_RGB32);
+ redraw();
+}
+
+
+
+
+
+void BiomeView::paintEvent(QPaintEvent * a_Event)
+{
+ QPainter p(this);
+ if (hasData())
+ {
+ p.drawImage(QPoint(0, 0), m_Image);
+ }
+ else
+ {
+ p.drawText(a_Event->rect(), Qt::AlignCenter, "No chunk source selected");
+ }
+ p.end();
+}
+
+
+
+
+
+void BiomeView::mousePressEvent(QMouseEvent * a_Event)
+{
+ m_LastX = a_Event->x();
+ m_LastY = a_Event->y();
+ m_IsMouseDragging = true;
+}
+
+
+
+
+
+void BiomeView::mouseMoveEvent(QMouseEvent * a_Event)
+{
+ if (m_IsMouseDragging)
+ {
+ // The user is dragging the mouse, move the view around:
+ m_X += (m_LastX - a_Event->x()) / m_Zoom;
+ m_Z += (m_LastY - a_Event->y()) / m_Zoom;
+ m_LastX = a_Event->x();
+ m_LastY = a_Event->y();
+ redraw();
+ return;
+ }
+
+ // TODO: Update the status bar info for the biome currently pointed at
+}
+
+
+
+
+
+void BiomeView::mouseReleaseEvent(QMouseEvent *)
+{
+ m_IsMouseDragging = false;
+}
+
+
+
+
+
+void BiomeView::wheelEvent(QWheelEvent * a_Event)
+{
+ m_MouseWheelDelta += a_Event->delta();
+ while (m_MouseWheelDelta >= DELTA_STEP)
+ {
+ increaseZoom();
+ m_MouseWheelDelta -= DELTA_STEP;
+ }
+ while (m_MouseWheelDelta <= -DELTA_STEP)
+ {
+ decreaseZoom();
+ m_MouseWheelDelta += DELTA_STEP;
+ }
+}
+
+
+
+
+
+void BiomeView::keyPressEvent(QKeyEvent * a_Event)
+{
+ switch (a_Event->key())
+ {
+ case Qt::Key_Up:
+ case Qt::Key_W:
+ {
+ m_Z -= 10.0 / m_Zoom;
+ redraw();
+ break;
+ }
+
+ case Qt::Key_Down:
+ case Qt::Key_S:
+ {
+ m_Z += 10.0 / m_Zoom;
+ redraw();
+ break;
+ }
+
+ case Qt::Key_Left:
+ case Qt::Key_A:
+ {
+ m_X -= 10.0 / m_Zoom;
+ redraw();
+ break;
+ }
+
+ case Qt::Key_Right:
+ case Qt::Key_D:
+ {
+ m_X += 10.0 / m_Zoom;
+ redraw();
+ break;
+ }
+
+ case Qt::Key_PageUp:
+ case Qt::Key_Q:
+ {
+ increaseZoom();
+ break;
+ }
+
+ case Qt::Key_PageDown:
+ case Qt::Key_E:
+ {
+ decreaseZoom();
+ break;
+ }
+ }
+}
+
+
+
+
+
+void BiomeView::decreaseZoom()
+{
+ if (m_Zoom > 1.001)
+ {
+ m_Zoom--;
+ if (m_Zoom < 1.0)
+ {
+ // Just crossed the 100%, fixate the 100% threshold:
+ m_Zoom = 1.0;
+ }
+ }
+ else if (m_Zoom > 0.01)
+ {
+ m_Zoom = m_Zoom / 2;
+ }
+ redraw();
+}
+
+
+
+
+
+void BiomeView::increaseZoom()
+{
+ if (m_Zoom > 0.99)
+ {
+ if (m_Zoom > 20.0)
+ {
+ // Zoom too large
+ return;
+ }
+ m_Zoom++;
+ }
+ else
+ {
+ m_Zoom = m_Zoom * 2;
+ if (m_Zoom > 1.0)
+ {
+ // Just crossed the 100%, fixate the 100% threshold:
+ m_Zoom = 1.0;
+ }
+ }
+ redraw();
+}
+
+
+
+
diff --git a/Tools/QtBiomeVisualiser/BiomeView.h b/Tools/QtBiomeVisualiser/BiomeView.h
new file mode 100644
index 000000000..f0521571d
--- /dev/null
+++ b/Tools/QtBiomeVisualiser/BiomeView.h
@@ -0,0 +1,100 @@
+#pragma once
+
+#include <QWidget>
+#include <memory>
+#include "ChunkCache.h"
+#include "ChunkSource.h"
+
+
+
+
+
+class BiomeView :
+ public QWidget
+{
+ typedef QWidget super;
+ Q_OBJECT
+
+public:
+ explicit BiomeView(QWidget * parent = NULL);
+
+ QSize minimumSizeHint() const;
+ QSize sizeHint() const;
+
+ /** Replaces the chunk source used by the biome view to get the chunk biome data.
+ The entire view is then invalidated and regenerated. */
+ void setChunkSource(std::shared_ptr<ChunkSource> a_ChunkSource);
+
+signals:
+
+public slots:
+ /** Redraw the entire widget area. */
+ void redraw();
+
+ /** A specified chunk has become available, redraw it. */
+ void chunkAvailable(int a_ChunkX, int a_ChunkZ);
+
+ /** Reloads the current chunk source and redraws the entire workspace. */
+ void reload();
+
+protected:
+ double m_X, m_Z;
+ double m_Zoom;
+
+ /** Cache for the loaded chunk data. */
+ ChunkCache m_Cache;
+
+ /** The entire view's contents in an offscreen image. */
+ QImage m_Image;
+
+ /** Coords of the mouse for the previous position, used while dragging. */
+ int m_LastX, m_LastY;
+
+ /** Set to true when the user has a mouse button depressed, and is dragging the view. */
+ bool m_IsMouseDragging;
+
+ /** Accumulator for the mouse wheel's delta. When the accumulator hits a threshold, the view zooms. */
+ int m_MouseWheelDelta;
+
+ /** Data used for rendering a chunk that hasn't been loaded yet */
+ uchar m_EmptyChunkImage[16 * 16 * 4];
+
+
+ /** Draws the specified chunk into m_Image */
+ void drawChunk(int a_ChunkX, int a_ChunkZ);
+
+ /** Returns true iff the biome view has been initialized to contain proper biome data. */
+ bool hasData(void) const { return m_Cache.hasData(); }
+
+ /** Called when the widget is resized */
+ virtual void resizeEvent(QResizeEvent *) override;
+
+ /** Paints the entire widget */
+ virtual void paintEvent(QPaintEvent *) override;
+
+ /** Called when the user presses any mouse button. */
+ virtual void mousePressEvent(QMouseEvent * a_Event);
+
+ /** Called when the user moves the mouse. */
+ virtual void mouseMoveEvent(QMouseEvent * a_Event);
+
+ /** Called when the user releases a previously held mouse button. */
+ virtual void mouseReleaseEvent(QMouseEvent * a_Event) override;
+
+ /** Called when the user rotates the mouse wheel. */
+ virtual void wheelEvent(QWheelEvent * a_Event) override;
+
+ /** Called when the user presses a key. */
+ virtual void keyPressEvent(QKeyEvent * a_Event) override;
+
+ /** Decreases the zoom level and queues a redraw. */
+ void decreaseZoom();
+
+ /** Increases the zoom level and queues a redraw. */
+ void increaseZoom();
+};
+
+
+
+
+
diff --git a/Tools/QtBiomeVisualiser/Chunk.cpp b/Tools/QtBiomeVisualiser/Chunk.cpp
new file mode 100644
index 000000000..d3419af9c
--- /dev/null
+++ b/Tools/QtBiomeVisualiser/Chunk.cpp
@@ -0,0 +1,36 @@
+#include "Globals.h"
+#include "Globals.h"
+#include "Chunk.h"
+
+
+
+
+
+Chunk::Chunk() :
+ m_IsValid(false)
+{
+}
+
+
+
+
+
+const uchar * Chunk::getImage(void) const
+{
+ ASSERT(m_IsValid);
+ return m_Image;
+}
+
+
+
+
+
+void Chunk::setImage(const Image & a_Image)
+{
+ memcpy(m_Image, a_Image, sizeof(a_Image));
+ m_IsValid = true;
+}
+
+
+
+
diff --git a/Tools/QtBiomeVisualiser/Chunk.h b/Tools/QtBiomeVisualiser/Chunk.h
new file mode 100644
index 000000000..03e7bd1b3
--- /dev/null
+++ b/Tools/QtBiomeVisualiser/Chunk.h
@@ -0,0 +1,40 @@
+#pragma once
+
+#include <qglobal.h>
+
+
+
+
+
+class Chunk
+{
+public:
+ /** The type used for storing image data for a chunk. */
+ typedef uchar Image[16 * 16 * 4];
+
+
+ Chunk(void);
+
+ /** Returns true iff the chunk data is valid - loaded or generated. */
+ bool isValid(void) const { return m_IsValid; }
+
+ /** Returns the image of the chunk's biomes. Assumes that the chunk is valid. */
+ const uchar * getImage(void) const;
+
+ /** Sets the image data for this chunk. */
+ void setImage(const Image & a_Image);
+
+protected:
+ /** Flag that specifies if the chunk data is valid - loaded or generated. */
+ bool m_IsValid;
+
+ /** Cached rendered image of this chunk's biomes. Updated in render(). */
+ Image m_Image;
+};
+
+typedef std::shared_ptr<Chunk> ChunkPtr;
+
+
+
+
+
diff --git a/Tools/QtBiomeVisualiser/ChunkCache.cpp b/Tools/QtBiomeVisualiser/ChunkCache.cpp
new file mode 100644
index 000000000..05c267d30
--- /dev/null
+++ b/Tools/QtBiomeVisualiser/ChunkCache.cpp
@@ -0,0 +1,126 @@
+#include "Globals.h"
+#include "ChunkCache.h"
+#include <QMutexLocker>
+#include <QThreadPool>
+#include "ChunkSource.h"
+#include "ChunkLoader.h"
+
+
+
+
+
+ChunkCache::ChunkCache(QObject * parent) :
+ super(parent)
+{
+ m_Cache.setMaxCost(1024 * 1024 * 1024); // 1 GiB of memory for the cache
+}
+
+
+
+
+
+ChunkPtr ChunkCache::fetch(int a_ChunkX, int a_ChunkZ)
+{
+ // Retrieve from the cache:
+ quint32 hash = getChunkHash(a_ChunkX, a_ChunkZ);
+ ChunkPtr * res;
+ {
+ QMutexLocker lock(&m_Mtx);
+ res = m_Cache[hash];
+ // If succesful and chunk loaded, return the retrieved value:
+ if ((res != nullptr) && (*res)->isValid())
+ {
+ return *res;
+ }
+ }
+
+ // If the chunk is in cache but not valid, it means it has been already queued for rendering, do nothing now:
+ if (res != nullptr)
+ {
+ return ChunkPtr(nullptr);
+ }
+
+ // There's no such item in the cache, create it now:
+ res = new ChunkPtr(new Chunk);
+ if (res == nullptr)
+ {
+ return ChunkPtr(nullptr);
+ }
+ {
+ QMutexLocker lock(&m_Mtx);
+ m_Cache.insert(hash, res, sizeof(Chunk));
+ }
+
+ // Queue the chunk for rendering:
+ queueChunkRender(a_ChunkX, a_ChunkZ, *res);
+
+ // Return failure, the chunk is not yet rendered:
+ return ChunkPtr(nullptr);
+}
+
+
+
+
+
+void ChunkCache::setChunkSource(std::shared_ptr<ChunkSource> a_ChunkSource)
+{
+ // Replace the chunk source:
+ m_ChunkSource = a_ChunkSource;
+
+ // Clear the cache:
+ QMutexLocker lock(&m_Mtx);
+ m_Cache.clear();
+}
+
+
+
+
+
+void ChunkCache::reload()
+{
+ assert(m_ChunkSource.get() != nullptr);
+
+ // Reload the chunk source:
+ m_ChunkSource->reload();
+
+ // Clear the cache:
+ QMutexLocker lock(&m_Mtx);
+ m_Cache.clear();
+}
+
+
+
+
+
+void ChunkCache::gotChunk(int a_ChunkX, int a_ChunkZ)
+{
+ emit chunkAvailable(a_ChunkX, a_ChunkZ);
+}
+
+
+
+
+
+quint32 ChunkCache::getChunkHash(int a_ChunkX, int a_ChunkZ)
+{
+ // Simply join the two coords into a single int
+ // The coords will never be larger than 16-bits, so we can do this safely
+ return (((static_cast<quint32>(a_ChunkX) & 0xffff) << 16) | (static_cast<quint32>(a_ChunkZ) & 0xffff));
+}
+
+
+
+
+
+void ChunkCache::queueChunkRender(int a_ChunkX, int a_ChunkZ, ChunkPtr & a_Chunk)
+{
+ // Create a new loader task:
+ ChunkLoader * loader = new ChunkLoader(a_ChunkX, a_ChunkZ, a_Chunk, m_ChunkSource);
+ connect(loader, SIGNAL(loaded(int, int)), this, SLOT(gotChunk(int, int)));
+
+ QThreadPool::globalInstance()->start(loader);
+}
+
+
+
+
diff --git a/Tools/QtBiomeVisualiser/ChunkCache.h b/Tools/QtBiomeVisualiser/ChunkCache.h
new file mode 100644
index 000000000..8d198f02f
--- /dev/null
+++ b/Tools/QtBiomeVisualiser/ChunkCache.h
@@ -0,0 +1,72 @@
+#pragma once
+
+#include <QObject>
+#include <QCache>
+#include <QMutex>
+#include <memory>
+
+
+
+
+
+class Chunk;
+typedef std::shared_ptr<Chunk> ChunkPtr;
+
+class ChunkSource;
+
+
+
+
+
+/** Caches chunk data for reuse */
+class ChunkCache :
+ public QObject
+{
+ typedef QObject super;
+ Q_OBJECT
+
+public:
+ explicit ChunkCache(QObject * parent = NULL);
+
+ /** Retrieves the specified chunk from the cache.
+ Only returns valid chunks; if the chunk is invalid, queues it for rendering and returns an empty ptr. */
+ ChunkPtr fetch(int a_ChunkX, int a_ChunkZ);
+
+ /** Replaces the chunk source used by the biome view to get the chunk biome data.
+ The cache is then invalidated. */
+ void setChunkSource(std::shared_ptr<ChunkSource> a_ChunkSource);
+
+ /** Returns true iff the chunk source has been initialized. */
+ bool hasData() const { return (m_ChunkSource.get() != nullptr); }
+
+ /** Reloads the current chunk source. */
+ void reload();
+
+signals:
+ void chunkAvailable(int a_ChunkX, int a_ChunkZ);
+
+protected slots:
+ void gotChunk(int a_ChunkX, int a_ChunkZ);
+
+protected:
+ /** The cache of the chunks */
+ QCache<quint32, ChunkPtr> m_Cache;
+
+ /** Locks te cache against multithreaded access */
+ QMutex m_Mtx;
+
+ /** The source used to get the biome data. */
+ std::shared_ptr<ChunkSource> m_ChunkSource;
+
+
+ /** Returns the hash used by the chunk in the cache */
+ quint32 getChunkHash(int a_ChunkX, int a_ChunkZ);
+
+ /** Queues the specified chunk for rendering by m_ChunkSource. */
+ void queueChunkRender(int a_ChunkX, int a_ChunkZ, ChunkPtr & a_Chunk);
+};
+
+
+
+
+
diff --git a/Tools/QtBiomeVisualiser/ChunkLoader.cpp b/Tools/QtBiomeVisualiser/ChunkLoader.cpp
new file mode 100644
index 000000000..3d0123b23
--- /dev/null
+++ b/Tools/QtBiomeVisualiser/ChunkLoader.cpp
@@ -0,0 +1,29 @@
+#include "Globals.h"
+#include "ChunkLoader.h"
+#include "ChunkSource.h"
+
+
+
+
+
+ChunkLoader::ChunkLoader(int a_ChunkX, int a_ChunkZ, ChunkPtr a_Chunk, ChunkSourcePtr a_ChunkSource) :
+ m_ChunkX(a_ChunkX),
+ m_ChunkZ(a_ChunkZ),
+ m_Chunk(a_Chunk),
+ m_ChunkSource(a_ChunkSource)
+{
+}
+
+
+
+
+
+void ChunkLoader::run()
+{
+ m_ChunkSource->getChunkBiomes(m_ChunkX, m_ChunkZ, m_Chunk);
+ emit loaded(m_ChunkX, m_ChunkZ);
+}
+
+
+
+
diff --git a/Tools/QtBiomeVisualiser/ChunkLoader.h b/Tools/QtBiomeVisualiser/ChunkLoader.h
new file mode 100644
index 000000000..4d026a45e
--- /dev/null
+++ b/Tools/QtBiomeVisualiser/ChunkLoader.h
@@ -0,0 +1,45 @@
+#pragma once
+
+#include <QObject>
+#include <QRunnable>
+#include <memory>
+
+
+
+
+// fwd:
+class Chunk;
+typedef std::shared_ptr<Chunk> ChunkPtr;
+
+class ChunkSource;
+typedef std::shared_ptr<ChunkSource> ChunkSourcePtr;
+
+
+
+
+
+class ChunkLoader :
+ public QObject,
+ public QRunnable
+{
+ Q_OBJECT
+
+public:
+ ChunkLoader(int a_ChunkX, int a_ChunkZ, ChunkPtr a_Chunk, ChunkSourcePtr a_ChunkSource);
+ virtual ~ChunkLoader() {}
+
+signals:
+ void loaded(int a_ChunkX, int a_ChunkZ);
+
+protected:
+ virtual void run() override;
+
+private:
+ int m_ChunkX, m_ChunkZ;
+ ChunkPtr m_Chunk;
+ ChunkSourcePtr m_ChunkSource;
+};
+
+
+
+
diff --git a/Tools/QtBiomeVisualiser/ChunkSource.cpp b/Tools/QtBiomeVisualiser/ChunkSource.cpp
new file mode 100644
index 000000000..28d184615
--- /dev/null
+++ b/Tools/QtBiomeVisualiser/ChunkSource.cpp
@@ -0,0 +1,421 @@
+#include "Globals.h"
+#include "ChunkSource.h"
+#include <QThread>
+#include "src/Generating/BioGen.h"
+#include "inifile/iniFile.h"
+#include "src/StringCompression.h"
+#include "src/WorldStorage/FastNBT.h"
+
+
+
+
+
+/** Map for converting biome values to colors. Initialized from biomeColors[]. */
+static uchar biomeToColor[256 * 4];
+
+/** Map for converting biome values to colors. Used to initialize biomeToColor[].*/
+static struct
+{
+ EMCSBiome m_Biome;
+ uchar m_Color[3];
+} biomeColors[] =
+{
+ { biOcean, { 0x00, 0x00, 0x70 }, },
+ { biPlains, { 0x8d, 0xb3, 0x60 }, },
+ { biDesert, { 0xfa, 0x94, 0x18 }, },
+ { biExtremeHills, { 0x60, 0x60, 0x60 }, },
+ { biForest, { 0x05, 0x66, 0x21 }, },
+ { biTaiga, { 0x0b, 0x66, 0x59 }, },
+ { biSwampland, { 0x2f, 0xff, 0xda }, },
+ { biRiver, { 0x30, 0x30, 0xaf }, },
+ { biHell, { 0x7f, 0x00, 0x00 }, },
+ { biSky, { 0x00, 0x7f, 0xff }, },
+ { biFrozenOcean, { 0xa0, 0xa0, 0xdf }, },
+ { biFrozenRiver, { 0xa0, 0xa0, 0xff }, },
+ { biIcePlains, { 0xff, 0xff, 0xff }, },
+ { biIceMountains, { 0xa0, 0xa0, 0xa0 }, },
+ { biMushroomIsland, { 0xff, 0x00, 0xff }, },
+ { biMushroomShore, { 0xa0, 0x00, 0xff }, },
+ { biBeach, { 0xfa, 0xde, 0x55 }, },
+ { biDesertHills, { 0xd2, 0x5f, 0x12 }, },
+ { biForestHills, { 0x22, 0x55, 0x1c }, },
+ { biTaigaHills, { 0x16, 0x39, 0x33 }, },
+ { biExtremeHillsEdge, { 0x7f, 0x8f, 0x7f }, },
+ { biJungle, { 0x53, 0x7b, 0x09 }, },
+ { biJungleHills, { 0x2c, 0x42, 0x05 }, },
+
+ { biJungleEdge, { 0x62, 0x8b, 0x17 }, },
+ { biDeepOcean, { 0x00, 0x00, 0x30 }, },
+ { biStoneBeach, { 0xa2, 0xa2, 0x84 }, },
+ { biColdBeach, { 0xfa, 0xf0, 0xc0 }, },
+ { biBirchForest, { 0x30, 0x74, 0x44 }, },
+ { biBirchForestHills, { 0x1f, 0x5f, 0x32 }, },
+ { biRoofedForest, { 0x40, 0x51, 0x1a }, },
+ { biColdTaiga, { 0x31, 0x55, 0x4a }, },
+ { biColdTaigaHills, { 0x59, 0x7d, 0x72 }, },
+ { biMegaTaiga, { 0x59, 0x66, 0x51 }, },
+ { biMegaTaigaHills, { 0x59, 0x66, 0x59 }, },
+ { biExtremeHillsPlus, { 0x50, 0x70, 0x50 }, },
+ { biSavanna, { 0xbd, 0xb2, 0x5f }, },
+ { biSavannaPlateau, { 0xa7, 0x9d, 0x64 }, },
+ { biMesa, { 0xd9, 0x45, 0x15 }, },
+ { biMesaPlateauF, { 0xb0, 0x97, 0x65 }, },
+ { biMesaPlateau, { 0xca, 0x8c, 0x65 }, },
+
+ // M variants:
+ { biSunflowerPlains, { 0xb5, 0xdb, 0x88 }, },
+ { biDesertM, { 0xff, 0xbc, 0x40 }, },
+ { biExtremeHillsM, { 0x88, 0x88, 0x88 }, },
+ { biFlowerForest, { 0x2d, 0x8e, 0x49 }, },
+ { biTaigaM, { 0x33, 0x8e, 0x81 }, },
+ { biSwamplandM, { 0x07, 0xf9, 0xb2 }, },
+ { biIcePlainsSpikes, { 0xb4, 0xdc, 0xdc }, },
+ { biJungleM, { 0x7b, 0xa3, 0x31 }, },
+ { biJungleEdgeM, { 0x62, 0x8b, 0x17 }, },
+ { biBirchForestM, { 0x58, 0x9c, 0x6c }, },
+ { biBirchForestHillsM, { 0x47, 0x87, 0x5a }, },
+ { biRoofedForestM, { 0x68, 0x79, 0x42 }, },
+ { biColdTaigaM, { 0x24, 0x3f, 0x36 }, },
+ { biMegaSpruceTaiga, { 0x45, 0x4f, 0x3e }, },
+ { biMegaSpruceTaigaHills, { 0x45, 0x4f, 0x4e }, },
+ { biExtremeHillsPlusM, { 0x78, 0x98, 0x78 }, },
+ { biSavannaM, { 0xe5, 0xda, 0x87 }, },
+ { biSavannaPlateauM, { 0xa7, 0x9d, 0x74 }, },
+ { biMesaBryce, { 0xff, 0x6d, 0x3d }, },
+ { biMesaPlateauFM, { 0xd8, 0xbf, 0x8d }, },
+ { biMesaPlateauM, { 0xf2, 0xb4, 0x8d }, },
+} ;
+
+
+
+
+
+static class BiomeColorsInitializer
+{
+public:
+ BiomeColorsInitializer(void)
+ {
+ // Reset all colors to gray:
+ for (size_t i = 0; i < ARRAYCOUNT(biomeToColor); i++)
+ {
+ biomeToColor[i] = 0x7f;
+ }
+
+ // Set known biomes to their colors:
+ for (size_t i = 0; i < ARRAYCOUNT(biomeColors); i++)
+ {
+ uchar * color = &biomeToColor[4 * biomeColors[i].m_Biome];
+ color[0] = biomeColors[i].m_Color[2];
+ color[1] = biomeColors[i].m_Color[1];
+ color[2] = biomeColors[i].m_Color[0];
+ color[3] = 0xff;
+ }
+ }
+} biomeColorInitializer;
+
+
+
+
+
+/** Converts biomes in an array into the chunk image data. */
+static void biomesToImage(cChunkDef::BiomeMap & a_Biomes, Chunk::Image & a_Image)
+{
+ // Make sure the two arrays are of the same size, compile-time.
+ // Note that a_Image is actually 4 items per pixel, so the array is 4 times bigger:
+ static const char Check1[4 * ARRAYCOUNT(a_Biomes) - ARRAYCOUNT(a_Image) + 1] = {};
+ static const char Check2[ARRAYCOUNT(a_Image) - 4 * ARRAYCOUNT(a_Biomes) + 1] = {};
+
+ // Convert the biomes into color:
+ for (size_t i = 0; i < ARRAYCOUNT(a_Biomes); i++)
+ {
+ a_Image[4 * i + 0] = biomeToColor[4 * a_Biomes[i] + 0];
+ a_Image[4 * i + 1] = biomeToColor[4 * a_Biomes[i] + 1];
+ a_Image[4 * i + 2] = biomeToColor[4 * a_Biomes[i] + 2];
+ a_Image[4 * i + 3] = biomeToColor[4 * a_Biomes[i] + 3];
+ }
+}
+
+
+
+
+
+////////////////////////////////////////////////////////////////////////////////
+// BioGenSource:
+
+BioGenSource::BioGenSource(cIniFilePtr a_IniFile) :
+ m_IniFile(a_IniFile),
+ m_Mtx(QMutex::Recursive)
+{
+ reload();
+}
+
+
+
+
+
+void BioGenSource::getChunkBiomes(int a_ChunkX, int a_ChunkZ, ChunkPtr a_DestChunk)
+{
+ cChunkDef::BiomeMap biomes;
+ {
+ QMutexLocker lock(&m_Mtx);
+ m_BiomeGen->GenBiomes(a_ChunkX, a_ChunkZ, biomes);
+ }
+ Chunk::Image img;
+ biomesToImage(biomes, img);
+ a_DestChunk->setImage(img);
+}
+
+
+
+
+
+void BioGenSource::reload()
+{
+ int seed = m_IniFile->GetValueSetI("Generator", "Seed", 0);
+ bool unused = false;
+ QMutexLocker lock(&m_Mtx);
+ m_BiomeGen.reset(cBiomeGen::CreateBiomeGen(*m_IniFile, seed, unused));
+}
+
+
+
+
+
+////////////////////////////////////////////////////////////////////////////////
+// AnvilSource::AnvilFile
+
+class AnvilSource::AnvilFile
+{
+public:
+ /** Coordinates of the region file. */
+ int m_RegionX, m_RegionZ;
+
+ /** True iff the file contains proper data. */
+ bool m_IsValid;
+
+
+
+ /** Creates a new instance with the specified region coords. Reads the file header. */
+ AnvilFile(int a_RegionX, int a_RegionZ, const AString & a_WorldPath) :
+ m_RegionX(a_RegionX),
+ m_RegionZ(a_RegionZ),
+ m_IsValid(false)
+ {
+ readFile(Printf("%s/r.%d.%d.mca", a_WorldPath.c_str(), a_RegionX, a_RegionZ));
+ }
+
+
+
+ /** Returns the compressed data of the specified chunk.
+ Returns an empty string when chunk not present. */
+ AString getChunkData(int a_ChunkX, int a_ChunkZ)
+ {
+ if (!m_IsValid)
+ {
+ return "";
+ }
+
+ // Translate to local coords:
+ int RelChunkX = a_ChunkX - m_RegionX * 32;
+ int RelChunkZ = a_ChunkZ - m_RegionZ * 32;
+ ASSERT((RelChunkX >= 0) && (RelChunkX < 32));
+ ASSERT((RelChunkZ >= 0) && (RelChunkZ < 32));
+
+ // Get the chunk data location:
+ UInt32 chunkOffset = m_Header[RelChunkX + 32 * RelChunkZ] >> 8;
+ UInt32 numChunkSectors = m_Header[RelChunkX + 32 * RelChunkZ] & 0xff;
+ if ((chunkOffset < 2) || (numChunkSectors == 0))
+ {
+ return "";
+ }
+
+ // Get the real data size:
+ const char * chunkData = m_FileData.data() + chunkOffset * 4096;
+ UInt32 chunkSize = GetBEInt(chunkData);
+ if ((chunkSize < 2) || (chunkSize / 4096 > numChunkSectors))
+ {
+ // Bad data, bail out
+ return "";
+ }
+
+ // Check the compression method:
+ if (chunkData[4] != 2)
+ {
+ // Chunk is in an unknown compression
+ return "";
+ }
+ chunkSize--;
+
+ // Read the chunk data:
+ return m_FileData.substr(chunkOffset * 4096 + 5, chunkSize);
+ }
+
+protected:
+ AString m_FileData;
+ UInt32 m_Header[2048];
+
+
+ /** Reads the whole specified file contents and parses the header. */
+ void readFile(const AString & a_FileName)
+ {
+ // Read the entire file:
+ m_FileData = cFile::ReadWholeFile(a_FileName);
+ if (m_FileData.size() < sizeof(m_Header))
+ {
+ return;
+ }
+
+ // Parse the header - change endianness:
+ const char * hdr = m_FileData.data();
+ for (size_t i = 0; i < ARRAYCOUNT(m_Header); i++)
+ {
+ m_Header[i] = GetBEInt(hdr + 4 * i);
+ }
+ m_IsValid = true;
+ }
+};
+
+
+
+
+
+////////////////////////////////////////////////////////////////////////////////
+// AnvilSource:
+
+AnvilSource::AnvilSource(QString a_WorldRegionFolder) :
+ m_WorldRegionFolder(a_WorldRegionFolder)
+{
+}
+
+
+
+
+
+void AnvilSource::getChunkBiomes(int a_ChunkX, int a_ChunkZ, ChunkPtr a_DestChunk)
+{
+ // Load the compressed data:
+ AString compressedChunkData = getCompressedChunkData(a_ChunkX, a_ChunkZ);
+ if (compressedChunkData.empty())
+ {
+ return;
+ }
+
+ // Uncompress the chunk data:
+ AString uncompressed;
+ int res = InflateString(compressedChunkData.data(), compressedChunkData.size(), uncompressed);
+ if (res != Z_OK)
+ {
+ return;
+ }
+
+ // Parse the NBT data:
+ cParsedNBT nbt(uncompressed.data(), uncompressed.size());
+ if (!nbt.IsValid())
+ {
+ return;
+ }
+
+ // Get the biomes out of the NBT:
+ int Level = nbt.FindChildByName(0, "Level");
+ if (Level < 0)
+ {
+ return;
+ }
+ cChunkDef::BiomeMap biomeMap;
+ int mcsBiomes = nbt.FindChildByName(Level, "MCSBiomes");
+ if ((mcsBiomes >= 0) && (nbt.GetDataLength(mcsBiomes) == sizeof(biomeMap)))
+ {
+ // Convert the biomes from BigEndian to platform native numbers:
+ const char * beBiomes = nbt.GetData(mcsBiomes);
+ for (size_t i = 0; i < ARRAYCOUNT(biomeMap); i++)
+ {
+ biomeMap[i] = (EMCSBiome)GetBEInt(beBiomes + 4 * i);
+ }
+ // Render the biomes:
+ Chunk::Image img;
+ biomesToImage(biomeMap, img);
+ a_DestChunk->setImage(img);
+ return;
+ }
+
+ // MCS biomes not found, load Vanilla biomes instead:
+ int biomes = nbt.FindChildByName(Level, "Biomes");
+ if ((biomes < 0) || (nbt.GetDataLength(biomes) != ARRAYCOUNT(biomeMap)))
+ {
+ return;
+ }
+ // Convert the biomes from Vanilla to EMCSBiome:
+ const char * vanillaBiomes = nbt.GetData(biomes);
+ for (size_t i = 0; i < ARRAYCOUNT(biomeMap); i++)
+ {
+ biomeMap[i] = EMCSBiome(vanillaBiomes[i]);
+ }
+ // Render the biomes:
+ Chunk::Image img;
+ biomesToImage(biomeMap, img);
+ a_DestChunk->setImage(img);
+}
+
+
+
+
+
+void AnvilSource::reload()
+{
+ // Remove all files from the cache:
+ QMutexLocker lock(&m_Mtx);
+ m_Files.clear();
+}
+
+
+
+
+
+void AnvilSource::chunkToRegion(int a_ChunkX, int a_ChunkZ, int & a_RegionX, int & a_RegionZ)
+{
+ a_RegionX = a_ChunkX >> 5;
+ a_RegionZ = a_ChunkZ >> 5;
+}
+
+
+
+
+
+AString AnvilSource::getCompressedChunkData(int a_ChunkX, int a_ChunkZ)
+{
+ return getAnvilFile(a_ChunkX, a_ChunkZ)->getChunkData(a_ChunkX, a_ChunkZ);
+}
+
+
+
+
+
+AnvilSource::AnvilFilePtr AnvilSource::getAnvilFile(int a_ChunkX, int a_ChunkZ)
+{
+ int RegionX, RegionZ;
+ chunkToRegion(a_ChunkX, a_ChunkZ, RegionX, RegionZ);
+
+ // Search the cache for the file:
+ QMutexLocker lock(&m_Mtx);
+ for (auto itr = m_Files.cbegin(), end = m_Files.cend(); itr != end; ++itr)
+ {
+ if (((*itr)->m_RegionX == RegionX) && ((*itr)->m_RegionZ == RegionZ))
+ {
+ // Found the file in the cache, move it to front and return it:
+ AnvilFilePtr file(*itr);
+ m_Files.erase(itr);
+ m_Files.push_front(file);
+ return file;
+ }
+ }
+
+ // File not in cache, create it:
+ AnvilFilePtr file(new AnvilFile(RegionX, RegionZ, m_WorldRegionFolder.toStdString()));
+ m_Files.push_front(file);
+ return file;
+}
+
+
+
+
+
diff --git a/Tools/QtBiomeVisualiser/ChunkSource.h b/Tools/QtBiomeVisualiser/ChunkSource.h
new file mode 100644
index 000000000..05e8ac5de
--- /dev/null
+++ b/Tools/QtBiomeVisualiser/ChunkSource.h
@@ -0,0 +1,107 @@
+#pragma once
+#include "Globals.h"
+#include <QString>
+#include <QMutex>
+#include "Chunk.h"
+
+
+
+
+
+// fwd:
+class cBiomeGen;
+typedef std::shared_ptr<cBiomeGen> cBiomeGenPtr;
+class cIniFile;
+typedef std::shared_ptr<cIniFile> cIniFilePtr;
+
+
+
+
+
+/** Abstract interface for getting biome data for chunks. */
+class ChunkSource
+{
+public:
+ virtual ~ChunkSource() {}
+
+ /** Fills the a_DestChunk with the biomes for the specified coords.
+ It is expected to be thread-safe and re-entrant. Usually QThread::idealThreadCount() threads are used. */
+ virtual void getChunkBiomes(int a_ChunkX, int a_ChunkZ, ChunkPtr a_DestChunk) = 0;
+
+ /** Forces a fresh reload of the source. Useful mainly for the generator, whose underlying definition file may have been changed. */
+ virtual void reload() = 0;
+};
+
+
+
+
+
+
+class BioGenSource :
+ public ChunkSource
+{
+public:
+ /** Constructs a new BioGenSource based on the biome generator that is defined in the specified world.ini file. */
+ BioGenSource(cIniFilePtr a_IniFile);
+
+ // ChunkSource overrides:
+ virtual void getChunkBiomes(int a_ChunkX, int a_ChunkZ, ChunkPtr a_DestChunk) override;
+ virtual void reload(void) override;
+
+protected:
+ /** The world.ini contents from which the generator is created and re-created on reload(). */
+ cIniFilePtr m_IniFile;
+
+ /** The generator used for generating biomes. */
+ std::unique_ptr<cBiomeGen> m_BiomeGen;
+
+ /** Guards m_BiomeGen against multithreaded access. */
+ QMutex m_Mtx;
+};
+
+
+
+
+class AnvilSource :
+ public ChunkSource
+{
+public:
+ /** Constructs a new AnvilSource based on the world path. */
+ AnvilSource(QString a_WorldRegionFolder);
+
+ // ChunkSource overrides:
+ virtual void getChunkBiomes(int a_ChunkX, int a_ChunkZ, ChunkPtr a_DestChunk) override;
+ virtual void reload() override;
+
+protected:
+ class AnvilFile;
+ typedef std::shared_ptr<AnvilFile> AnvilFilePtr;
+
+
+ /** Folder where the individual Anvil Region files are located. */
+ QString m_WorldRegionFolder;
+
+ /** List of currently loaded files. Acts as a cache so that a file is not opened and closed over and over again.
+ Protected against multithreaded access by m_Mtx. */
+ std::list<AnvilFilePtr> m_Files;
+
+ /** Guards m_Files agains multithreaded access. */
+ QMutex m_Mtx;
+
+
+ /** Converts chunk coords to region coords. */
+ void chunkToRegion(int a_ChunkX, int a_ChunkZ, int & a_RegionX, int & a_RegionZ);
+
+ /** Returns the compressed data of the specified chunk.
+ Returns an empty string if the chunk is not available. */
+ AString getCompressedChunkData(int a_ChunkX, int a_ChunkZ);
+
+ /** Returns the file object that contains the specified chunk.
+ The file is taken from the cache if available there, otherwise it is created anew. */
+ AnvilFilePtr getAnvilFile(int a_ChunkX, int a_ChunkZ);
+
+};
+
+
+
+
diff --git a/Tools/QtBiomeVisualiser/GeneratorSetup.cpp b/Tools/QtBiomeVisualiser/GeneratorSetup.cpp
new file mode 100644
index 000000000..f5412404c
--- /dev/null
+++ b/Tools/QtBiomeVisualiser/GeneratorSetup.cpp
@@ -0,0 +1,159 @@
+#include "Globals.h"
+#include "GeneratorSetup.h"
+#include <QLabel>
+#include <QLineEdit>
+#include "src/Generating/BioGen.h"
+#include "inifile/iniFile.h"
+
+
+
+
+
+static const QString s_GeneratorNames[] =
+{
+ QString("Checkerboard"),
+ QString("Constant"),
+ QString("DistortedVoronoi"),
+ QString("MultiStepMap"),
+ QString("TwoLevel"),
+ QString("Voronoi"),
+};
+
+
+
+
+
+GeneratorSetup::GeneratorSetup(const AString & a_IniFileName, QWidget * a_Parent) :
+ super(a_Parent),
+ m_IniFile(new cIniFile())
+{
+ // The seed and generator name is in a separate form layout at the top, always present:
+ m_eSeed = new QLineEdit();
+ m_eSeed->setValidator(new QIntValidator());
+ m_eSeed->setText("0");
+ m_eSeed->setProperty("INI.ItemName", QVariant("Seed"));
+ m_cbGenerator = new QComboBox();
+ m_cbGenerator->setMinimumWidth(120);
+ for (size_t i = 0; i < ARRAYCOUNT(s_GeneratorNames); i++)
+ {
+ m_cbGenerator->addItem(s_GeneratorNames[i]);
+ }
+ QFormLayout * baseLayout = new QFormLayout();
+ baseLayout->addRow(new QLabel(tr("Seed")), m_eSeed);
+ baseLayout->addRow(new QLabel(tr("Generator")), m_cbGenerator);
+
+ // The rest of the controls are in a dynamically created form layout:
+ m_FormLayout = new QFormLayout();
+
+ // The main layout joins these two vertically:
+ m_MainLayout = new QVBoxLayout();
+ m_MainLayout->addLayout(baseLayout);
+ m_MainLayout->addLayout(m_FormLayout);
+ m_MainLayout->addStretch();
+ setLayout(m_MainLayout);
+
+ // Load the INI file, if specified, otherwise set defaults:
+ if (!a_IniFileName.empty() && m_IniFile->ReadFile(a_IniFileName))
+ {
+ m_cbGenerator->setCurrentText(QString::fromStdString(m_IniFile->GetValue("Generator", "BiomeGen")));
+ m_eSeed->setText(QString::number(m_IniFile->GetValueI("Generator", "Seed")));
+ }
+ else
+ {
+ m_IniFile->SetValue("Generator", "Generator", "Composable");
+ m_IniFile->SetValue("Generator", "BiomeGen", m_cbGenerator->currentText().toStdString());
+ bool dummy;
+ delete cBiomeGen::CreateBiomeGen(*m_IniFile, 0, dummy);
+ }
+ updateFromIni();
+
+ // Connect the change events only after the data has been loaded:
+ connect(m_cbGenerator, SIGNAL(currentIndexChanged(QString)), this, SLOT(generatorChanged(QString)));
+ connect(m_eSeed, SIGNAL(textChanged(QString)), this, SLOT(editChanged(QString)));
+}
+
+
+
+
+
+void GeneratorSetup::generatorChanged(const QString & a_NewName)
+{
+ // Clear the current contents of the form layout by assigning it to a stack temporary:
+ {
+ m_MainLayout->takeAt(1);
+ QWidget().setLayout(m_FormLayout);
+ }
+
+ // Re-create the layout:
+ m_FormLayout = new QFormLayout();
+ m_MainLayout->insertLayout(1, m_FormLayout);
+
+ // Recreate the INI file:
+ m_IniFile->Clear();
+ m_IniFile->SetValue("Generator", "Generator", "Composable");
+ m_IniFile->SetValue("Generator", "BiomeGen", a_NewName.toStdString());
+
+ // Create a dummy biome gen from the INI file, this will create the defaults in the INI file:
+ bool dummy;
+ delete cBiomeGen::CreateBiomeGen(*m_IniFile, m_Seed, dummy);
+
+ // Read all values from the INI file and put them into the form layout:
+ updateFromIni();
+
+ // Notify of the changes:
+ emit generatorUpdated();
+}
+
+
+
+
+
+void GeneratorSetup::editChanged(const QString & a_NewValue)
+{
+ QString itemName = sender()->property("INI.ItemName").toString();
+ m_IniFile->SetValue("Generator", itemName.toStdString(), a_NewValue.toStdString());
+ emit generatorUpdated();
+}
+
+
+
+
+
+void GeneratorSetup::updateFromIni()
+{
+ int keyID = m_IniFile->FindKey("Generator");
+ if (keyID <= -1)
+ {
+ return;
+ }
+ int numItems = m_IniFile->GetNumValues(keyID);
+ AString generatorName = m_IniFile->GetValue("Generator", "BiomeGen");
+ size_t generatorNameLen = generatorName.length();
+ for (int i = 0; i < numItems; i++)
+ {
+ AString itemName = m_IniFile->GetValueName(keyID, i);
+ if ((itemName == "Generator") || (itemName == "BiomeGen"))
+ {
+ // These special cases are not to be added
+ continue;
+ }
+ AString itemValue = m_IniFile->GetValue(keyID, i);
+
+ QLineEdit * edit = new QLineEdit();
+ edit->setText(QString::fromStdString(itemValue));
+ edit->setProperty("INI.ItemName", QVariant(QString::fromStdString(itemName)));
+
+ // Remove the generator name prefix from the item name, for clarity purposes:
+ if (NoCaseCompare(itemName.substr(0, generatorNameLen), generatorName) == 0)
+ {
+ itemName.erase(0, generatorNameLen);
+ }
+
+ connect(edit, SIGNAL(textChanged(QString)), this, SLOT(editChanged(QString)));
+ m_FormLayout->addRow(new QLabel(QString::fromStdString(itemName)), edit);
+ } // for i - INI values[]
+}
+
+
+
+
diff --git a/Tools/QtBiomeVisualiser/GeneratorSetup.h b/Tools/QtBiomeVisualiser/GeneratorSetup.h
new file mode 100644
index 000000000..e72d3abbc
--- /dev/null
+++ b/Tools/QtBiomeVisualiser/GeneratorSetup.h
@@ -0,0 +1,64 @@
+#pragma once
+
+#include <memory>
+#include <QDialog>
+#include <QComboBox>
+#include <QVBoxLayout>
+#include <QFormLayout>
+
+
+
+
+
+class cIniFile;
+typedef std::shared_ptr<cIniFile> cIniFilePtr;
+
+
+
+
+
+class GeneratorSetup :
+ public QWidget
+{
+ typedef QWidget super;
+
+ Q_OBJECT
+
+public:
+ /** Creates the widget and loads the contents of the INI file, if not empty. */
+ explicit GeneratorSetup(const std::string & a_IniFileName, QWidget * parent = nullptr);
+
+ /** Returns the cIniFile instance that is being edited by this widget. */
+ cIniFilePtr getIniFile() { return m_IniFile; }
+
+signals:
+ /** Emitted when the generator parameters have changed. */
+ void generatorUpdated();
+
+public slots:
+ /** Called when the user selects a different generator from the top combobox.
+ Re-creates m_IniFile and updates the form layout. */
+ void generatorChanged(const QString & a_NewName);
+
+protected slots:
+ /** Called when any of the edit widgets are changed. */
+ void editChanged(const QString & a_NewValue);
+
+protected:
+ QComboBox * m_cbGenerator;
+ QLineEdit * m_eSeed;
+ QVBoxLayout * m_MainLayout;
+ QFormLayout * m_FormLayout;
+
+ cIniFilePtr m_IniFile;
+
+ int m_Seed;
+
+
+ /** Updates the form layout with the values from m_IniFile. */
+ void updateFromIni();
+};
+
+
+
+
diff --git a/Tools/QtBiomeVisualiser/Globals.h b/Tools/QtBiomeVisualiser/Globals.h
new file mode 100644
index 000000000..8d2e913b7
--- /dev/null
+++ b/Tools/QtBiomeVisualiser/Globals.h
@@ -0,0 +1,386 @@
+#pragma once
+
+
+
+
+
+// Compiler-dependent stuff:
+#if defined(_MSC_VER)
+ // MSVC produces warning C4481 on the override keyword usage, so disable the warning altogether
+ #pragma warning(disable:4481)
+
+ // Disable some warnings that we don't care about:
+ #pragma warning(disable:4100) // Unreferenced formal parameter
+
+ // Useful warnings from warning level 4:
+ #pragma warning(3 : 4127) // Conditional expression is constant
+ #pragma warning(3 : 4189) // Local variable is initialized but not referenced
+ #pragma warning(3 : 4245) // Conversion from 'type1' to 'type2', signed/unsigned mismatch
+ #pragma warning(3 : 4310) // Cast truncates constant value
+ #pragma warning(3 : 4389) // Signed/unsigned mismatch
+ #pragma warning(3 : 4505) // Unreferenced local function has been removed
+ #pragma warning(3 : 4701) // Potentially unitialized local variable used
+ #pragma warning(3 : 4702) // Unreachable code
+ #pragma warning(3 : 4706) // Assignment within conditional expression
+
+ // Disabling this warning, because we know what we're doing when we're doing this:
+ #pragma warning(disable: 4355) // 'this' used in initializer list
+
+ // Disabled because it's useless:
+ #pragma warning(disable: 4512) // 'class': assignment operator could not be generated - reported for each class that has a reference-type member
+
+ // 2014_01_06 xoft: Disabled this warning because MSVC is stupid and reports it in obviously wrong places
+ // #pragma warning(3 : 4244) // Conversion from 'type1' to 'type2', possible loss of data
+
+ #define OBSOLETE __declspec(deprecated)
+
+ // No alignment needed in MSVC
+ #define ALIGN_8
+ #define ALIGN_16
+
+ #define FORMATSTRING(formatIndex, va_argsIndex)
+
+ // MSVC has its own custom version of zu format
+ #define SIZE_T_FMT "%Iu"
+ #define SIZE_T_FMT_PRECISION(x) "%" #x "Iu"
+ #define SIZE_T_FMT_HEX "%Ix"
+
+ #define NORETURN __declspec(noreturn)
+
+#elif defined(__GNUC__)
+
+ // TODO: Can GCC explicitly mark classes as abstract (no instances can be created)?
+ #define abstract
+
+ // override is part of c++11
+ #if __cplusplus < 201103L
+ #define override
+ #endif
+
+ #define OBSOLETE __attribute__((deprecated))
+
+ #define ALIGN_8 __attribute__((aligned(8)))
+ #define ALIGN_16 __attribute__((aligned(16)))
+
+ // Some portability macros :)
+ #define stricmp strcasecmp
+
+ #define FORMATSTRING(formatIndex, va_argsIndex) __attribute__((format (printf, formatIndex, va_argsIndex)))
+
+ #if defined(_WIN32)
+ // We're compiling on MinGW, which uses an old MSVCRT library that has no support for size_t printfing.
+ // We need direct size formats:
+ #if defined(_WIN64)
+ #define SIZE_T_FMT "%I64u"
+ #define SIZE_T_FMT_PRECISION(x) "%" #x "I64u"
+ #define SIZE_T_FMT_HEX "%I64x"
+ #else
+ #define SIZE_T_FMT "%u"
+ #define SIZE_T_FMT_PRECISION(x) "%" #x "u"
+ #define SIZE_T_FMT_HEX "%x"
+ #endif
+ #else
+ // We're compiling on Linux, so we can use libc's size_t printf format:
+ #define SIZE_T_FMT "%zu"
+ #define SIZE_T_FMT_PRECISION(x) "%" #x "zu"
+ #define SIZE_T_FMT_HEX "%zx"
+ #endif
+
+ #define NORETURN __attribute((__noreturn__))
+
+#else
+
+ #error "You are using an unsupported compiler, you might need to #define some stuff here for your compiler"
+
+ /*
+ // Copy and uncomment this into another #elif section based on your compiler identification
+
+ // Explicitly mark classes as abstract (no instances can be created)
+ #define abstract
+
+ // Mark virtual methods as overriding (forcing them to have a virtual function of the same signature in the base class)
+ #define override
+
+ // Mark functions as obsolete, so that their usage results in a compile-time warning
+ #define OBSOLETE
+
+ // Mark types / variables for alignment. Do the platforms need it?
+ #define ALIGN_8
+ #define ALIGN_16
+ */
+
+#endif
+
+
+#ifdef _DEBUG
+ #define NORETURNDEBUG NORETURN
+#else
+ #define NORETURNDEBUG
+#endif
+
+
+#include <stddef.h>
+
+
+// Integral types with predefined sizes:
+typedef long long Int64;
+typedef int Int32;
+typedef short Int16;
+
+typedef unsigned long long UInt64;
+typedef unsigned int UInt32;
+typedef unsigned short UInt16;
+
+typedef unsigned char Byte;
+
+
+// If you get an error about specialization check the size of integral types
+template <typename T, size_t Size, bool x = sizeof(T) == Size>
+class SizeChecker;
+
+template <typename T, size_t Size>
+class SizeChecker<T, Size, true>
+{
+ T v;
+};
+
+template class SizeChecker<Int64, 8>;
+template class SizeChecker<Int32, 4>;
+template class SizeChecker<Int16, 2>;
+
+template class SizeChecker<UInt64, 8>;
+template class SizeChecker<UInt32, 4>;
+template class SizeChecker<UInt16, 2>;
+
+// A macro to disallow the copy constructor and operator = functions
+// This should be used in the private: declarations for any class that shouldn't allow copying itself
+#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
+ TypeName(const TypeName &); \
+ void operator =(const TypeName &)
+
+// A macro that is used to mark unused function parameters, to avoid pedantic warnings in gcc
+#define UNUSED(X) (void)(X)
+
+
+
+
+// OS-dependent stuff:
+#ifdef _WIN32
+ #define WIN32_LEAN_AND_MEAN
+
+ #define _WIN32_WINNT 0x501 // We want to target WinXP and higher
+
+ #include <Windows.h>
+ #include <winsock2.h>
+ #include <Ws2tcpip.h> // IPv6 stuff
+
+ // Windows SDK defines min and max macros, messing up with our std::min and std::max usage
+ #undef min
+ #undef max
+
+ // Windows SDK defines GetFreeSpace as a constant, probably a Win16 API remnant
+ #ifdef GetFreeSpace
+ #undef GetFreeSpace
+ #endif // GetFreeSpace
+#else
+ #include <sys/types.h>
+ #include <sys/time.h>
+ #include <sys/socket.h>
+ #include <netinet/in.h>
+ #include <arpa/inet.h>
+ #include <netdb.h>
+ #include <time.h>
+ #include <dirent.h>
+ #include <errno.h>
+ #include <iostream>
+ #include <cstdio>
+ #include <cstring>
+ #include <pthread.h>
+ #include <semaphore.h>
+ #include <errno.h>
+ #include <fcntl.h>
+#endif
+
+#if defined(ANDROID_NDK)
+ #define FILE_IO_PREFIX "/sdcard/mcserver/"
+#else
+ #define FILE_IO_PREFIX ""
+#endif
+
+
+
+
+
+// CRT stuff:
+#include <sys/stat.h>
+#include <assert.h>
+#include <stdio.h>
+#include <math.h>
+#include <stdarg.h>
+
+
+
+
+
+// STL stuff:
+#include <vector>
+#include <list>
+#include <deque>
+#include <string>
+#include <map>
+#include <algorithm>
+#include <memory>
+#include <set>
+#include <queue>
+#include <limits>
+
+
+
+#ifndef TEST_GLOBALS
+ // Common headers (part 1, without macros):
+ #include "src/StringUtils.h"
+ #include "src/OSSupport/Sleep.h"
+ #include "src/OSSupport/CriticalSection.h"
+ #include "src/OSSupport/Semaphore.h"
+ #include "src/OSSupport/Event.h"
+ #include "src/OSSupport/Thread.h"
+ #include "src/OSSupport/File.h"
+ #include "src/Logger.h"
+#else
+ // Logging functions
+void inline LOGERROR(const char* a_Format, ...) FORMATSTRING(1, 2);
+
+void inline LOGERROR(const char* a_Format, ...)
+{
+ va_list argList;
+ va_start(argList, a_Format);
+ vprintf(a_Format, argList);
+ va_end(argList);
+}
+#endif
+
+
+
+
+
+// Common definitions:
+
+/// Evaluates to the number of elements in an array (compile-time!)
+#define ARRAYCOUNT(X) (sizeof(X) / sizeof(*(X)))
+
+/// Allows arithmetic expressions like "32 KiB" (but consider using parenthesis around it, "(32 KiB)")
+#define KiB * 1024
+#define MiB * 1024 * 1024
+
+/// Faster than (int)floorf((float)x / (float)div)
+#define FAST_FLOOR_DIV( x, div) (((x) - (((x) < 0) ? ((div) - 1) : 0)) / (div))
+
+// Own version of assert() that writes failed assertions to the log for review
+#ifdef TEST_GLOBALS
+
+ class cAssertFailure
+ {
+ };
+
+ #ifdef _WIN32
+ #if (defined(_MSC_VER) && defined(_DEBUG))
+ #define DBG_BREAK _CrtDbgBreak()
+ #else
+ #define DBG_BREAK
+ #endif
+ #define REPORT_ERROR(FMT, ...) \
+ { \
+ AString msg = Printf(FMT, __VA_ARGS__); \
+ puts(msg.c_str()); \
+ fflush(stdout); \
+ OutputDebugStringA(msg.c_str()); \
+ DBG_BREAK; \
+ }
+ #else
+ #define REPORT_ERROR(FMT, ...) \
+ { \
+ AString msg = Printf(FMT, __VA_ARGS__); \
+ puts(msg.c_str()); \
+ fflush(stdout); \
+ }
+ #endif
+ #define ASSERT(x) do { if (!(x)) { throw cAssertFailure();} } while (0)
+ #define testassert(x) do { if (!(x)) { REPORT_ERROR("Test failure: %s, file %s, line %d\n", #x, __FILE__, __LINE__); exit(1); } } while (0)
+ #define CheckAsserts(x) do { try {x} catch (cAssertFailure) { break; } REPORT_ERROR("Test failure: assert didn't fire for %s, file %s, line %d\n", #x, __FILE__, __LINE__); exit(1); } while (0)
+
+#else
+ #ifdef _DEBUG
+ #define ASSERT( x) ( !!(x) || ( LOGERROR("Assertion failed: %s, file %s, line %i", #x, __FILE__, __LINE__), assert(0), 0))
+ #else
+ #define ASSERT(x) ((void)(x))
+ #endif
+#endif
+
+// Pretty much the same as ASSERT() but stays in Release builds
+#define VERIFY( x) ( !!(x) || ( LOGERROR("Verification failed: %s, file %s, line %i", #x, __FILE__, __LINE__), exit(1), 0))
+
+// Same as assert but in all Self test builds
+#ifdef SELF_TEST
+ #define assert_test(x) ( !!(x) || (assert(!#x), exit(1), 0))
+#endif
+
+// Allow both Older versions of MSVC and newer versions of everything use a shared_ptr:
+// Note that we cannot typedef, because C++ doesn't allow (partial) templates to be typedeffed.
+#if (defined(_MSC_VER) && (_MSC_VER < 1600))
+ // MSVC before 2010 doesn't have std::shared_ptr, but has std::tr1::shared_ptr, defined in <memory> included earlier
+ #define SharedPtr std::tr1::shared_ptr
+#elif (defined(_MSC_VER) || (__cplusplus >= 201103L))
+ // C++11 has std::shared_ptr in <memory>, included earlier
+ #define SharedPtr std::shared_ptr
+#else
+ // C++03 has std::tr1::shared_ptr in <tr1/memory>
+ #include <tr1/memory>
+ #define SharedPtr std::tr1::shared_ptr
+#endif
+
+
+
+
+
+/** A generic interface used mainly in ForEach() functions */
+template <typename Type> class cItemCallback
+{
+public:
+ virtual ~cItemCallback() {}
+
+ /** Called for each item in the internal list; return true to stop the loop, or false to continue enumerating */
+ virtual bool Item(Type * a_Type) = 0;
+} ;
+
+
+
+
+/** Clamp X to the specified range. */
+template <typename T>
+T Clamp(T a_Value, T a_Min, T a_Max)
+{
+ return (a_Value < a_Min) ? a_Min : ((a_Value > a_Max) ? a_Max : a_Value);
+}
+
+
+
+
+
+#ifndef TOLUA_TEMPLATE_BIND
+ #define TOLUA_TEMPLATE_BIND(x)
+#endif
+
+
+
+
+
+// Common headers (part 2, with macros):
+#include "src/ChunkDef.h"
+#include "src/BiomeDef.h"
+#include "src/BlockID.h"
+#include "src/BlockInfo.h"
+
+
+
+
+
diff --git a/Tools/QtBiomeVisualiser/MainWindow.cpp b/Tools/QtBiomeVisualiser/MainWindow.cpp
new file mode 100644
index 000000000..eb45690c1
--- /dev/null
+++ b/Tools/QtBiomeVisualiser/MainWindow.cpp
@@ -0,0 +1,310 @@
+#include "Globals.h"
+#include "MainWindow.h"
+#include <QVBoxLayout>
+#include <QAction>
+#include <QMenuBar>
+#include <QApplication>
+#include <QFileDialog>
+#include <QSettings>
+#include <QDirIterator>
+#include "inifile/iniFile.h"
+#include "ChunkSource.h"
+#include "src/Generating/BioGen.h"
+#include "src/StringCompression.h"
+#include "src/WorldStorage/FastNBT.h"
+#include "GeneratorSetup.h"
+
+
+
+
+
+MainWindow::MainWindow(QWidget * parent) :
+ QMainWindow(parent),
+ m_GeneratorSetup(nullptr),
+ m_LineSeparator(nullptr)
+{
+ initMinecraftPath();
+
+ m_BiomeView = new BiomeView();
+ m_MainLayout = new QHBoxLayout();
+ m_MainLayout->addWidget(m_BiomeView, 1);
+ m_MainLayout->setMenuBar(menuBar());
+ m_MainLayout->setMargin(0);
+ QWidget * central = new QWidget();
+ central->setLayout(m_MainLayout);
+ setCentralWidget(central);
+
+ createActions();
+ createMenus();
+}
+
+
+
+
+
+MainWindow::~MainWindow()
+{
+
+}
+
+
+
+
+
+void MainWindow::newGenerator()
+{
+ // (Re-)open the generator setup dialog with empty settings:
+ openGeneratorSetup("");
+
+ // Set the chunk source:
+ cIniFilePtr iniFile = m_GeneratorSetup->getIniFile();
+ m_BiomeView->setChunkSource(std::shared_ptr<BioGenSource>(new BioGenSource(iniFile)));
+ m_BiomeView->redraw();
+}
+
+
+
+
+
+void MainWindow::openGenerator()
+{
+ // Let the user specify the world.ini file:
+ QString worldIni = QFileDialog::getOpenFileName(this, tr("Open world.ini"), QString(), tr("world.ini (world.ini)"));
+ if (worldIni.isEmpty())
+ {
+ return;
+ }
+
+ // (Re-)open the generator setup dialog:
+ openGeneratorSetup(worldIni.toStdString());
+
+ // Set the chunk source:
+ m_BiomeView->setChunkSource(std::shared_ptr<BioGenSource>(new BioGenSource(m_GeneratorSetup->getIniFile())));
+ m_BiomeView->redraw();
+}
+
+
+
+
+
+void MainWindow::openWorld()
+{
+ // Let the user specify the world:
+ QString regionFolder = QFileDialog::getExistingDirectory(this, tr("Select the region folder"), QString());
+ if (regionFolder.isEmpty())
+ {
+ return;
+ }
+
+ // Remove the generator setup dialog, if open:
+ closeGeneratorSetup();
+
+ // Set the chunk source:
+ m_BiomeView->setChunkSource(std::shared_ptr<AnvilSource>(new AnvilSource(regionFolder)));
+ m_BiomeView->redraw();
+}
+
+
+
+
+
+void MainWindow::openVanillaWorld()
+{
+ // The world is stored in the sender action's data, retrieve it:
+ QAction * action = qobject_cast<QAction *>(sender());
+ if (action == nullptr)
+ {
+ return;
+ }
+
+ // Remove the generator setup dialog, if open:
+ closeGeneratorSetup();
+
+ // Set the chunk source:
+ m_BiomeView->setChunkSource(std::shared_ptr<AnvilSource>(new AnvilSource(action->data().toString())));
+ m_BiomeView->redraw();
+}
+
+
+
+
+
+void MainWindow::initMinecraftPath()
+{
+ #ifdef Q_OS_MAC
+ m_MinecraftPath = QDir::homePath() + QDir::toNativeSeparators("/Library/Application Support/minecraft");
+ #elif defined Q_OS_WIN32
+ QSettings ini(QSettings::IniFormat, QSettings::UserScope, ".minecraft", "minecraft1");
+ m_MinecraftPath = QFileInfo(ini.fileName()).absolutePath();
+ #else
+ m_MinecraftPath = QDir::homePath() + QDir::toNativeSeparators("/.minecraft");
+ #endif
+}
+
+
+
+
+
+void MainWindow::createActions()
+{
+ createWorldActions();
+
+ m_actNewGen = new QAction(tr("&New generator"), this);
+ m_actNewGen->setShortcut(tr("Ctrl+N"));
+ m_actNewGen->setStatusTip(tr("Open a generator INI file and display the generated biomes"));
+ connect(m_actNewGen, SIGNAL(triggered()), this, SLOT(newGenerator()));
+
+ m_actOpenGen = new QAction(tr("&Open generator..."), this);
+ m_actOpenGen->setShortcut(tr("Ctrl+G"));
+ m_actOpenGen->setStatusTip(tr("Open a generator INI file and display the generated biomes"));
+ connect(m_actOpenGen, SIGNAL(triggered()), this, SLOT(openGenerator()));
+
+ m_actOpenWorld = new QAction(tr("&Open world..."), this);
+ m_actOpenWorld->setShortcut(tr("Ctrl+O"));
+ m_actOpenWorld->setStatusTip(tr("Open an existing world and display its biomes"));
+ connect(m_actOpenWorld, SIGNAL(triggered()), this, SLOT(openWorld()));
+
+ m_actReload = new QAction(tr("&Reload"), this);
+ m_actReload->setShortcut(tr("F5"));
+ m_actReload->setStatusTip(tr("Clear the view cache and force a reload of all the data"));
+ connect(m_actReload, SIGNAL(triggered()), m_BiomeView, SLOT(reload()));
+
+ m_actExit = new QAction(tr("E&xit"), this);
+ m_actExit->setShortcut(tr("Alt+X"));
+ m_actExit->setStatusTip(tr("Exit %1").arg(QApplication::instance()->applicationName()));
+ connect(m_actExit, SIGNAL(triggered()), this, SLOT(close()));
+}
+
+
+
+
+
+void MainWindow::createWorldActions()
+{
+ QDir mc(m_MinecraftPath);
+ if (!mc.cd("saves"))
+ {
+ return;
+ }
+
+ QDirIterator it(mc);
+ int key = 1;
+ while (it.hasNext())
+ {
+ it.next();
+ if (!it.fileInfo().isDir())
+ {
+ continue;
+ }
+ QString name = getWorldName(it.filePath().toStdString());
+ if (name.isEmpty())
+ {
+ continue;
+ }
+ QAction * w = new QAction(this);
+ w->setText(name);
+ w->setData(it.filePath() + "/region");
+ if (key < 10)
+ {
+ w->setShortcut("Ctrl+" + QString::number(key));
+ key++;
+ }
+ connect(w, SIGNAL(triggered()), this, SLOT(openVanillaWorld()));
+ m_WorldActions.append(w);
+ }
+}
+
+
+
+
+
+void MainWindow::createMenus()
+{
+ QMenu * file = menuBar()->addMenu(tr("&Map"));
+ file->addAction(m_actNewGen);
+ file->addAction(m_actOpenGen);
+ file->addSeparator();
+ QMenu * worlds = file->addMenu(tr("Open existing"));
+ worlds->addActions(m_WorldActions);
+ if (m_WorldActions.empty())
+ {
+ worlds->setEnabled(false);
+ }
+ file->addAction(m_actOpenWorld);
+ file->addSeparator();
+ file->addAction(m_actReload);
+ file->addSeparator();
+ file->addAction(m_actExit);
+}
+
+
+
+
+
+QString MainWindow::getWorldName(const AString & a_Path)
+{
+ AString levelData = cFile::ReadWholeFile(a_Path + "/level.dat");
+ if (levelData.empty())
+ {
+ // No such file / no data
+ return QString();
+ }
+
+ AString uncompressed;
+ if (UncompressStringGZIP(levelData.data(), levelData.size(), uncompressed) != Z_OK)
+ {
+ return QString();
+ }
+ cParsedNBT nbt(uncompressed.data(), uncompressed.size());
+ if (!nbt.IsValid())
+ {
+ return QString();
+ }
+ AString name = nbt.GetName(1);
+ int levelNameTag = nbt.FindTagByPath(nbt.GetRoot(), "Data\\LevelName");
+ if ((levelNameTag <= 0) || (nbt.GetType(levelNameTag) != TAG_String))
+ {
+ return QString();
+ }
+ return QString::fromStdString(nbt.GetString(levelNameTag));
+}
+
+
+
+
+
+void MainWindow::openGeneratorSetup(const AString & a_IniFileName)
+{
+ // Close any previous editor:
+ closeGeneratorSetup();
+
+ // Open up a new editor:
+ m_GeneratorSetup = new GeneratorSetup(a_IniFileName);
+ m_LineSeparator = new QWidget();
+ m_LineSeparator->setFixedWidth(2);
+ m_LineSeparator->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
+ m_LineSeparator->setStyleSheet(QString("background-color: #c0c0c0;"));
+ m_MainLayout->addWidget(m_LineSeparator);
+ m_MainLayout->addWidget(m_GeneratorSetup);
+
+ // Connect the signals from the setup pane:
+ connect(m_GeneratorSetup, SIGNAL(generatorUpdated()), m_BiomeView, SLOT(reload()));
+}
+
+
+
+
+
+void MainWindow::closeGeneratorSetup()
+{
+ delete m_MainLayout->takeAt(2);
+ delete m_MainLayout->takeAt(1);
+ delete m_GeneratorSetup;
+ delete m_LineSeparator;
+ m_GeneratorSetup = nullptr;
+ m_LineSeparator = nullptr;
+}
+
+
+
+
diff --git a/Tools/QtBiomeVisualiser/MainWindow.h b/Tools/QtBiomeVisualiser/MainWindow.h
new file mode 100644
index 000000000..6490a937f
--- /dev/null
+++ b/Tools/QtBiomeVisualiser/MainWindow.h
@@ -0,0 +1,96 @@
+#pragma once
+
+#include <memory>
+#include <QList>
+#include <QMainWindow>
+#include <QHBoxLayout>
+#include "BiomeView.h"
+
+
+
+
+
+// fwd:
+class GeneratorSetup;
+
+
+
+
+
+class MainWindow :
+ public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow(QWidget * parent = nullptr);
+ ~MainWindow();
+
+private slots:
+ /** Creates a generator definition from scratch, lets user modify generator params in realtime. */
+ void newGenerator();
+
+ /** Opens a generator definition and generates the biomes based on that. */
+ void openGenerator();
+
+ /** Opens an existing world and displays the loaded biomes. */
+ void openWorld();
+
+ /** Opens a vanilla world that is specified by the calling action. */
+ void openVanillaWorld();
+
+protected:
+ // Actions:
+ QAction * m_actNewGen;
+ QAction * m_actOpenGen;
+ QAction * m_actOpenWorld;
+ QAction * m_actReload;
+ QAction * m_actExit;
+
+ /** List of actions that open the specific vanilla world. */
+ QList<QAction *> m_WorldActions;
+
+ /** Path to the vanilla folder. */
+ QString m_MinecraftPath;
+
+ /** The pane for setting up the generator, available when visualising a generator. */
+ GeneratorSetup * m_GeneratorSetup;
+
+ /** The main biome display widget. */
+ BiomeView * m_BiomeView;
+
+ /** The layout for the window. */
+ QHBoxLayout * m_MainLayout;
+
+ /** The separator line between biome view and generator setup. */
+ QWidget * m_LineSeparator;
+
+
+ /** Initializes the m_MinecraftPath based on the proper MC path */
+ void initMinecraftPath();
+
+ /** Creates the actions that the UI supports. */
+ void createActions();
+
+ /** Creates the actions that open a specific vanilla world. Iterates over the minecraft saves folder. */
+ void createWorldActions();
+
+ /** Creates the menu bar and connects its events. */
+ void createMenus();
+
+ /** Returns the name of the vanilla world in the specified path.
+ Reads the level.dat file for the name. Returns an empty string on failure. */
+ QString getWorldName(const AString & a_Path);
+
+ /** Opens the generator setup pane, if not already open, and loads the specified INI file to it. */
+ void openGeneratorSetup(const AString & a_IniFileName);
+
+ /** Closes and destroys the generator setup pane, if there is one. */
+ void closeGeneratorSetup();
+};
+
+
+
+
+
+
diff --git a/Tools/QtBiomeVisualiser/QtBiomeVisualiser.pro b/Tools/QtBiomeVisualiser/QtBiomeVisualiser.pro
new file mode 100644
index 000000000..d6630bd34
--- /dev/null
+++ b/Tools/QtBiomeVisualiser/QtBiomeVisualiser.pro
@@ -0,0 +1,94 @@
+#-------------------------------------------------
+#
+# Project created by QtCreator 2014-09-11T15:22:43
+#
+#-------------------------------------------------
+
+QT += core gui
+
+greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
+
+TARGET = QtBiomeVisualiser
+TEMPLATE = app
+
+
+SOURCES += main.cpp\
+ MainWindow.cpp \
+ BiomeView.cpp \
+ ../../src/Generating/BioGen.cpp \
+ ../../src/VoronoiMap.cpp \
+ ../../src/Noise.cpp \
+ ../../src/StringUtils.cpp \
+ ../../src/LoggerListeners.cpp \
+ ../../src/Logger.cpp \
+ ../../lib/inifile/iniFile.cpp \
+ ../../src/OSSupport/File.cpp \
+ ../../src/OSSupport/CriticalSection.cpp \
+ ../../src/OSSupport/IsThread.cpp \
+ ../../src/BiomeDef.cpp \
+ ChunkCache.cpp \
+ Chunk.cpp \
+ ChunkSource.cpp \
+ ChunkLoader.cpp \
+ ../../src/StringCompression.cpp \
+ ../../src/WorldStorage/FastNBT.cpp \
+ ../../lib/zlib/adler32.c \
+ ../../lib/zlib/compress.c \
+ ../../lib/zlib/crc32.c \
+ ../../lib/zlib/deflate.c \
+ ../../lib/zlib/gzclose.c \
+ ../../lib/zlib/gzlib.c \
+ ../../lib/zlib/gzread.c \
+ ../../lib/zlib/gzwrite.c \
+ ../../lib/zlib/infback.c \
+ ../../lib/zlib/inffast.c \
+ ../../lib/zlib/inflate.c \
+ ../../lib/zlib/inftrees.c \
+ ../../lib/zlib/trees.c \
+ ../../lib/zlib/uncompr.c \
+ ../../lib/zlib/zutil.c \
+ GeneratorSetup.cpp
+
+HEADERS += MainWindow.h \
+ Globals.h \
+ BiomeView.h \
+ ../../src/Generating/BioGen.h \
+ ../../src/VoronoiMap.h \
+ ../../src/Noise.h \
+ ../../src/StringUtils.h \
+ ../../src/LoggerListeners.h \
+ ../../src/Logger.h \
+ ../../lib/inifile/iniFile.h \
+ ../../src/OSSupport/File.h \
+ ../../src/OSSupport/CriticalSection.h \
+ ../../src/OSSupport/IsThread.h \
+ ../../src/BiomeDef.h \
+ ChunkCache.h \
+ Chunk.h \
+ ChunkSource.h \
+ ChunkLoader.h \
+ ../../src/StringCompression.h \
+ ../../src/WorldStorage/FastNBT.h \
+ ../../lib/zlib/crc32.h \
+ ../../lib/zlib/deflate.h \
+ ../../lib/zlib/gzguts.h \
+ ../../lib/zlib/inffast.h \
+ ../../lib/zlib/inffixed.h \
+ ../../lib/zlib/inflate.h \
+ ../../lib/zlib/inftrees.h \
+ ../../lib/zlib/trees.h \
+ ../../lib/zlib/zconf.h \
+ ../../lib/zlib/zlib.h \
+ ../../lib/zlib/zutil.h \
+ GeneratorSetup.h
+
+INCLUDEPATH += $$_PRO_FILE_PWD_ \
+ $$_PRO_FILE_PWD_/../../lib \
+ $$_PRO_FILE_PWD_/../../
+
+
+CONFIG += C++11
+
+OTHER_FILES +=
+
+
diff --git a/Tools/QtBiomeVisualiser/main.cpp b/Tools/QtBiomeVisualiser/main.cpp
new file mode 100644
index 000000000..f41cdcfb2
--- /dev/null
+++ b/Tools/QtBiomeVisualiser/main.cpp
@@ -0,0 +1,20 @@
+#include "Globals.h"
+#include "MainWindow.h"
+#include <QApplication>
+
+
+
+
+
+int main(int argc, char *argv[])
+{
+ QApplication a(argc, argv);
+ MainWindow w;
+ w.show();
+
+ return a.exec();
+}
+
+
+
+
diff --git a/lib/SQLiteCpp b/lib/SQLiteCpp
-Subproject 27b9d111818af3b05bcf4153bb6e380fe1dd681
+Subproject 203c2fb68bbf871eaf4ca98756a113d74d620de
diff --git a/lib/inifile/iniFile.cpp b/lib/inifile/iniFile.cpp
index 2bf6c91ed..7cfe7661f 100644
--- a/lib/inifile/iniFile.cpp
+++ b/lib/inifile/iniFile.cpp
@@ -668,6 +668,24 @@ void cIniFile::Clear(void)
+bool cIniFile::HasValue(const AString & a_KeyName, const AString & a_ValueName)
+{
+ // Find the key:
+ int keyID = FindKey(a_KeyName);
+ if (keyID == noID)
+ {
+ return false;
+ }
+
+ // Find the value:
+ int valueID = FindValue(keyID, a_ValueName);
+ return (valueID != noID);
+}
+
+
+
+
+
void cIniFile::AddHeaderComment(const AString & comment)
{
comments.push_back(comment);
diff --git a/lib/inifile/iniFile.h b/lib/inifile/iniFile.h
index 58fecd0cf..33229bff0 100644
--- a/lib/inifile/iniFile.h
+++ b/lib/inifile/iniFile.h
@@ -53,7 +53,9 @@ private:
/// Removes the UTF-8 BOMs (Byte order makers), if present.
void RemoveBom(AString & a_line) const;
+
public:
+
enum errors
{
noID = -1,
@@ -79,6 +81,9 @@ public:
/// Deletes all stored ini data (but doesn't touch the file)
void Clear(void);
+
+ /** Returns true iff the specified value exists. */
+ bool HasValue(const AString & a_KeyName, const AString & a_ValueName);
/// Returns index of specified key, or noID if not found
int FindKey(const AString & keyname) const;
diff --git a/lib/tolua++/include/tolua++.h b/lib/tolua++/include/tolua++.h
index 8da427fe3..c8b654ae6 100644
--- a/lib/tolua++/include/tolua++.h
+++ b/lib/tolua++/include/tolua++.h
@@ -36,7 +36,9 @@ extern "C" {
#define TEMPLATE_BIND(p)
#endif
-#define TOLUA_TEMPLATE_BIND(p)
+#ifndef TOLUA_TEMPLATE_BIND
+ #define TOLUA_TEMPLATE_BIND(p)
+#endif
#define TOLUA_PROTECTED_DESTRUCTOR
#define TOLUA_PROPERTY_TYPE(p)
diff --git a/src/Bindings/LuaChunkStay.cpp b/src/Bindings/LuaChunkStay.cpp
index 59b02d8f7..154bcb200 100644
--- a/src/Bindings/LuaChunkStay.cpp
+++ b/src/Bindings/LuaChunkStay.cpp
@@ -107,7 +107,7 @@ void cLuaChunkStay::AddChunkCoord(cLuaState & L, int a_Index)
}
} // for itr - m_Chunks[]
- m_Chunks.push_back(cChunkCoords(ChunkX, ZERO_CHUNK_Y, ChunkZ));
+ m_Chunks.push_back(cChunkCoords(ChunkX, ChunkZ));
}
diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp
index 9fe93ccc2..ba2f3c5e0 100644
--- a/src/Bindings/LuaState.cpp
+++ b/src/Bindings/LuaState.cpp
@@ -859,6 +859,32 @@ void cLuaState::GetStackValue(int a_StackPos, eWeather & a_ReturnedVal)
+void cLuaState::GetStackValue(int a_StackPos, pBoundingBox & a_ReturnedVal)
+{
+ tolua_Error err;
+ if (tolua_isusertype(m_LuaState, a_StackPos, "cBoundingBox", false, &err))
+ {
+ a_ReturnedVal = *((cBoundingBox **)lua_touserdata(m_LuaState, a_StackPos));
+ }
+}
+
+
+
+
+
+void cLuaState::GetStackValue(int a_StackPos, pWorld & a_ReturnedVal)
+{
+ tolua_Error err;
+ if (tolua_isusertype(m_LuaState, a_StackPos, "cWorld", false, &err))
+ {
+ a_ReturnedVal = *((cWorld **)lua_touserdata(m_LuaState, a_StackPos));
+ }
+}
+
+
+
+
+
bool cLuaState::CallFunction(int a_NumResults)
{
ASSERT (m_NumCurrentFunctionArgs >= 0); // A function must be pushed to stack first
diff --git a/src/Bindings/LuaState.h b/src/Bindings/LuaState.h
index eeb93fd4d..44f187701 100644
--- a/src/Bindings/LuaState.h
+++ b/src/Bindings/LuaState.h
@@ -59,6 +59,10 @@ class cTNTEntity;
class cCreeper;
class cHopperEntity;
class cBlockEntity;
+class cBoundingBox;
+
+typedef cBoundingBox * pBoundingBox;
+typedef cWorld * pWorld;
@@ -230,6 +234,12 @@ public:
/** Retrieve value at a_StackPos, if it is a valid number, converting and clamping it to eWeather.
If not, a_Value is unchanged. */
void GetStackValue(int a_StackPos, eWeather & a_Value);
+
+ /** Retrieve value at a_StackPos, if it is a valid cBoundingBox class. If not, a_Value is unchanged */
+ void GetStackValue(int a_StackPos, pBoundingBox & a_Value);
+
+ /** Retrieve value at a_StackPos, if it is a valid cWorld class. If not, a_Value is unchanged */
+ void GetStackValue(int a_StackPos, pWorld & a_Value);
// Include the cLuaState::Call() overload implementation that is generated by the gen_LuaState_Call.lua script:
@@ -328,6 +338,14 @@ protected:
*/
bool PushFunction(int a_FnRef);
+ /** Pushes a function that has been saved as a reference.
+ Returns true if successful. Logs a warning on failure
+ */
+ bool PushFunction(const cRef & a_FnRef)
+ {
+ return PushFunction((int)a_FnRef);
+ }
+
/** Pushes a function that is stored in a referenced table by name
Returns true if successful. Logs a warning on failure
*/
diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp
index adf10a72f..b7ea65759 100644
--- a/src/Bindings/ManualBindings.cpp
+++ b/src/Bindings/ManualBindings.cpp
@@ -679,6 +679,75 @@ static int tolua_ForEachInChunk(lua_State * tolua_S)
template <
class Ty1,
class Ty2,
+ bool (Ty1::*Func1)(const cBoundingBox &, cItemCallback<Ty2> &)
+>
+static int tolua_ForEachInBox(lua_State * tolua_S)
+{
+ // Check params:
+ cLuaState L(tolua_S);
+ if (
+ !L.CheckParamUserType(1, "cWorld") ||
+ !L.CheckParamUserType(2, "cBoundingBox") ||
+ !L.CheckParamFunction(3) ||
+ !L.CheckParamEnd(4)
+ )
+ {
+ return 0;
+ }
+
+ // Get the params:
+ Ty1 * Self = NULL;
+ cBoundingBox * Box = NULL;
+ L.GetStackValues(1, Self, Box);
+ ASSERT(Self != NULL); // We have verified the type at the top, so we should get valid objects here
+ ASSERT(Box != NULL);
+
+ // Create a reference for the function:
+ cLuaState::cRef FnRef(L, 3);
+
+ // Callback wrapper for the Lua function:
+ class cLuaCallback : public cItemCallback<Ty2>
+ {
+ public:
+ cLuaCallback(cLuaState & a_LuaState, cLuaState::cRef & a_FuncRef) :
+ m_LuaState(a_LuaState),
+ m_FnRef(a_FuncRef)
+ {}
+
+ private:
+ // cItemCallback<Ty2> overrides:
+ virtual bool Item(Ty2 * a_Item) override
+ {
+ bool res = false;
+ if (!m_LuaState.Call(m_FnRef, a_Item, cLuaState::Return, res))
+ {
+ LOGWARNING("Failed to call Lua callback");
+ m_LuaState.LogStackTrace();
+ return true; // Abort enumeration
+ }
+
+ return res;
+ }
+ cLuaState & m_LuaState;
+ cLuaState::cRef & m_FnRef;
+ } Callback(L, FnRef);
+
+ bool bRetVal = (Self->*Func1)(*Box, Callback);
+
+ FnRef.UnRef();
+
+ /* Push return value on stack */
+ tolua_pushboolean(tolua_S, bRetVal);
+ return 1;
+}
+
+
+
+
+
+template <
+ class Ty1,
+ class Ty2,
bool (Ty1::*Func1)(cItemCallback<Ty2> &)
>
static int tolua_ForEach(lua_State * tolua_S)
@@ -3327,6 +3396,7 @@ void ManualBindings::Bind(lua_State * tolua_S)
tolua_function(tolua_S, "ForEachBlockEntityInChunk", tolua_ForEachInChunk<cWorld, cBlockEntity, &cWorld::ForEachBlockEntityInChunk>);
tolua_function(tolua_S, "ForEachChestInChunk", tolua_ForEachInChunk<cWorld, cChestEntity, &cWorld::ForEachChestInChunk>);
tolua_function(tolua_S, "ForEachEntity", tolua_ForEach< cWorld, cEntity, &cWorld::ForEachEntity>);
+ tolua_function(tolua_S, "ForEachEntityInBox", tolua_ForEachInBox< cWorld, cEntity, &cWorld::ForEachEntityInBox>);
tolua_function(tolua_S, "ForEachEntityInChunk", tolua_ForEachInChunk<cWorld, cEntity, &cWorld::ForEachEntityInChunk>);
tolua_function(tolua_S, "ForEachFurnaceInChunk", tolua_ForEachInChunk<cWorld, cFurnaceEntity, &cWorld::ForEachFurnaceInChunk>);
tolua_function(tolua_S, "ForEachPlayer", tolua_ForEach< cWorld, cPlayer, &cWorld::ForEachPlayer>);
diff --git a/src/Bindings/gen_LuaState_Call.lua b/src/Bindings/gen_LuaState_Call.lua
index 2d8630d12..7f62573c7 100644
--- a/src/Bindings/gen_LuaState_Call.lua
+++ b/src/Bindings/gen_LuaState_Call.lua
@@ -109,7 +109,7 @@ local function WriteOverload(f, a_NumParams, a_NumReturns)
-- Write the function signature:
f:write("bool Call(")
- f:write("FnT a_Function")
+ f:write("const FnT & a_Function")
for i = 1, a_NumParams do
f:write(", ParamT", i, " a_Param", i)
end
diff --git a/src/BlockEntities/RedstonePoweredEntity.h b/src/BlockEntities/RedstonePoweredEntity.h
index f11df4fc4..eac4e35d4 100644
--- a/src/BlockEntities/RedstonePoweredEntity.h
+++ b/src/BlockEntities/RedstonePoweredEntity.h
@@ -6,7 +6,7 @@ class cRedstonePoweredEntity
{
public:
- virtual ~cRedstonePoweredEntity() {};
+ virtual ~cRedstonePoweredEntity() {}
/// Sets the internal redstone power flag to "on" or "off", depending on the parameter. Calls Activate() if appropriate
virtual void SetRedstonePower(bool a_IsPowered) = 0;
diff --git a/src/BlockEntities/SignEntity.cpp b/src/BlockEntities/SignEntity.cpp
index 97fed0f04..23d9ef926 100644
--- a/src/BlockEntities/SignEntity.cpp
+++ b/src/BlockEntities/SignEntity.cpp
@@ -15,6 +15,7 @@
cSignEntity::cSignEntity(BLOCKTYPE a_BlockType, int a_X, int a_Y, int a_Z, cWorld * a_World) :
super(a_BlockType, a_X, a_Y, a_Z, a_World)
{
+ ASSERT((a_Y >= 0) && (a_Y < cChunkDef::Height));
}
diff --git a/src/BlockID.h b/src/BlockID.h
index 08c576886..d835f9518 100644
--- a/src/BlockID.h
+++ b/src/BlockID.h
@@ -362,6 +362,8 @@ enum ENUM_ITEM_ID
E_ITEM_LEAD = 420,
E_ITEM_NAME_TAG = 421,
E_ITEM_MINECART_WITH_COMMAND_BLOCK = 422,
+ E_ITEM_RAW_MUTTON = 423,
+ E_ITEM_MUTTON = 424,
// Keep these two as the last values of the consecutive list, without a number - they will get their correct number assigned automagically by C++
// IsValidItem() depends on this!
diff --git a/src/BlockInfo.cpp b/src/BlockInfo.cpp
index a59229f87..0324cabf5 100644
--- a/src/BlockInfo.cpp
+++ b/src/BlockInfo.cpp
@@ -18,6 +18,7 @@ cBlockInfo::cBlockInfo()
, m_IsSolid(true)
, m_FullyOccupiesVoxel(false)
, m_CanBeTerraformed(false)
+ , m_PlaceSound("")
, m_Handler(NULL)
{}
@@ -571,6 +572,172 @@ void cBlockInfo::Initialize(cBlockInfoArray & a_Info)
a_Info[E_BLOCK_SOULSAND ].m_CanBeTerraformed = true;
a_Info[E_BLOCK_STAINED_CLAY ].m_CanBeTerraformed = true;
a_Info[E_BLOCK_STONE ].m_CanBeTerraformed = true;
+
+
+ // Block place sounds:
+ a_Info[E_BLOCK_STONE ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_GRASS ].m_PlaceSound = "dig.grass";
+ a_Info[E_BLOCK_DIRT ].m_PlaceSound = "dig.gravel";
+ a_Info[E_BLOCK_COBBLESTONE ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_PLANKS ].m_PlaceSound = "dig.wood";
+ a_Info[E_BLOCK_SAPLING ].m_PlaceSound = "dig.grass";
+ a_Info[E_BLOCK_BEDROCK ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_SAND ].m_PlaceSound = "dig.sand";
+ a_Info[E_BLOCK_GRAVEL ].m_PlaceSound = "dig.gravel";
+ a_Info[E_BLOCK_GOLD_ORE ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_IRON_ORE ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_COAL_ORE ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_LOG ].m_PlaceSound = "dig.wood";
+ a_Info[E_BLOCK_LEAVES ].m_PlaceSound = "dig.grass";
+ a_Info[E_BLOCK_SPONGE ].m_PlaceSound = "dig.grass";
+ a_Info[E_BLOCK_GLASS ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_LAPIS_ORE ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_LAPIS_BLOCK ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_DISPENSER ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_SANDSTONE ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_NOTE_BLOCK ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_POWERED_RAIL ].m_PlaceSound = "dig.metal";
+ a_Info[E_BLOCK_DETECTOR_RAIL ].m_PlaceSound = "dig.metal";
+ a_Info[E_BLOCK_STICKY_PISTON ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_COBWEB ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_TALL_GRASS ].m_PlaceSound = "dig.grass";
+ a_Info[E_BLOCK_DEAD_BUSH ].m_PlaceSound = "dig.grass";
+ a_Info[E_BLOCK_PISTON ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_PISTON_EXTENSION ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_WOOL ].m_PlaceSound = "dig.cloth";
+ a_Info[E_BLOCK_PISTON_MOVED_BLOCK ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_DANDELION ].m_PlaceSound = "dig.grass";
+ a_Info[E_BLOCK_FLOWER ].m_PlaceSound = "dig.grass";
+ a_Info[E_BLOCK_BROWN_MUSHROOM ].m_PlaceSound = "dig.grass";
+ a_Info[E_BLOCK_RED_MUSHROOM ].m_PlaceSound = "dig.grass";
+ a_Info[E_BLOCK_GOLD_BLOCK ].m_PlaceSound = "dig.metal";
+ a_Info[E_BLOCK_IRON_BLOCK ].m_PlaceSound = "dig.metal";
+ a_Info[E_BLOCK_DOUBLE_STONE_SLAB ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_STONE_SLAB ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_BRICK ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_TNT ].m_PlaceSound = "dig.grass";
+ a_Info[E_BLOCK_BOOKCASE ].m_PlaceSound = "dig.wood";
+ a_Info[E_BLOCK_MOSSY_COBBLESTONE ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_OBSIDIAN ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_TORCH ].m_PlaceSound = "dig.wood";
+ a_Info[E_BLOCK_FIRE ].m_PlaceSound = "dig.wood";
+ a_Info[E_BLOCK_MOB_SPAWNER ].m_PlaceSound = "dig.metal";
+ a_Info[E_BLOCK_WOODEN_STAIRS ].m_PlaceSound = "dig.wood";
+ a_Info[E_BLOCK_CHEST ].m_PlaceSound = "dig.wood";
+ a_Info[E_BLOCK_REDSTONE_WIRE ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_DIAMOND_ORE ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_DIAMOND_BLOCK ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_CRAFTING_TABLE ].m_PlaceSound = "dig.wood";
+ a_Info[E_BLOCK_FARMLAND ].m_PlaceSound = "dig.gravel";
+ a_Info[E_BLOCK_FURNACE ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_LIT_FURNACE ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_SIGN_POST ].m_PlaceSound = "dig.wood";
+ a_Info[E_BLOCK_WOODEN_DOOR ].m_PlaceSound = "dig.wood";
+ a_Info[E_BLOCK_LADDER ].m_PlaceSound = "dig.ladder";
+ a_Info[E_BLOCK_RAIL ].m_PlaceSound = "dig.metal";
+ a_Info[E_BLOCK_COBBLESTONE_STAIRS ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_WALLSIGN ].m_PlaceSound = "dig.wood";
+ a_Info[E_BLOCK_LEVER ].m_PlaceSound = "dig.wood";
+ a_Info[E_BLOCK_STONE_PRESSURE_PLATE ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_IRON_DOOR ].m_PlaceSound = "dig.metal";
+ a_Info[E_BLOCK_WOODEN_PRESSURE_PLATE ].m_PlaceSound = "dig.wood";
+ a_Info[E_BLOCK_REDSTONE_ORE ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_REDSTONE_ORE_GLOWING ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_REDSTONE_TORCH_OFF ].m_PlaceSound = "dig.wood";
+ a_Info[E_BLOCK_REDSTONE_TORCH_ON ].m_PlaceSound = "dig.wood";
+ a_Info[E_BLOCK_STONE_BUTTON ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_SNOW ].m_PlaceSound = "dig.snow";
+ a_Info[E_BLOCK_ICE ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_SNOW_BLOCK ].m_PlaceSound = "dig.snow";
+ a_Info[E_BLOCK_CACTUS ].m_PlaceSound = "dig.cloth";
+ a_Info[E_BLOCK_CLAY ].m_PlaceSound = "dig.gravel";
+ a_Info[E_BLOCK_SUGARCANE ].m_PlaceSound = "dig.grass";
+ a_Info[E_BLOCK_JUKEBOX ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_FENCE ].m_PlaceSound = "dig.wood";
+ a_Info[E_BLOCK_PUMPKIN ].m_PlaceSound = "dig.wood";
+ a_Info[E_BLOCK_NETHERRACK ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_SOULSAND ].m_PlaceSound = "dig.sand";
+ a_Info[E_BLOCK_GLOWSTONE ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_NETHER_PORTAL ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_JACK_O_LANTERN ].m_PlaceSound = "dig.wood";
+ a_Info[E_BLOCK_CAKE ].m_PlaceSound = "dig.snow";
+ a_Info[E_BLOCK_REDSTONE_REPEATER_OFF ].m_PlaceSound = "dig.wood";
+ a_Info[E_BLOCK_REDSTONE_REPEATER_ON ].m_PlaceSound = "dig.wood";
+ a_Info[E_BLOCK_STAINED_GLASS ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_TRAPDOOR ].m_PlaceSound = "dig.wood";
+ a_Info[E_BLOCK_SILVERFISH_EGG ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_STONE_BRICKS ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_HUGE_BROWN_MUSHROOM ].m_PlaceSound = "dig.wood";
+ a_Info[E_BLOCK_HUGE_RED_MUSHROOM ].m_PlaceSound = "dig.wood";
+ a_Info[E_BLOCK_IRON_BARS ].m_PlaceSound = "dig.metal";
+ a_Info[E_BLOCK_GLASS_PANE ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_MELON ].m_PlaceSound = "dig.wood";
+ a_Info[E_BLOCK_PUMPKIN_STEM ].m_PlaceSound = "dig.wood";
+ a_Info[E_BLOCK_MELON_STEM ].m_PlaceSound = "dig.wood";
+ a_Info[E_BLOCK_VINES ].m_PlaceSound = "dig.grass";
+ a_Info[E_BLOCK_FENCE_GATE ].m_PlaceSound = "dig.wood";
+ a_Info[E_BLOCK_BRICK_STAIRS ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_STONE_BRICK_STAIRS ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_MYCELIUM ].m_PlaceSound = "dig.grass";
+ a_Info[E_BLOCK_LILY_PAD ].m_PlaceSound = "dig.grass";
+ a_Info[E_BLOCK_NETHER_BRICK ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_NETHER_BRICK_FENCE ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_NETHER_BRICK_STAIRS ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_NETHER_WART ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_ENCHANTMENT_TABLE ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_BREWING_STAND ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_CAULDRON ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_END_PORTAL ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_END_PORTAL_FRAME ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_END_STONE ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_DRAGON_EGG ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_REDSTONE_LAMP_OFF ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_REDSTONE_LAMP_ON ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_DOUBLE_WOODEN_SLAB ].m_PlaceSound = "dig.wood";
+ a_Info[E_BLOCK_WOODEN_SLAB ].m_PlaceSound = "dig.wood";
+ a_Info[E_BLOCK_COCOA_POD ].m_PlaceSound = "dig.wood";
+ a_Info[E_BLOCK_SANDSTONE_STAIRS ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_EMERALD_ORE ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_ENDER_CHEST ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_TRIPWIRE_HOOK ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_TRIPWIRE ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_EMERALD_BLOCK ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_SPRUCE_WOOD_STAIRS ].m_PlaceSound = "dig.wood";
+ a_Info[E_BLOCK_BIRCH_WOOD_STAIRS ].m_PlaceSound = "dig.wood";
+ a_Info[E_BLOCK_JUNGLE_WOOD_STAIRS ].m_PlaceSound = "dig.wood";
+ a_Info[E_BLOCK_COMMAND_BLOCK ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_BEACON ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_COBBLESTONE_WALL ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_FLOWER_POT ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_CARROTS ].m_PlaceSound = "dig.grass";
+ a_Info[E_BLOCK_POTATOES ].m_PlaceSound = "dig.grass";
+ a_Info[E_BLOCK_HEAD ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_ANVIL ].m_PlaceSound = "random.anvil_land";
+ a_Info[E_BLOCK_TRAPPED_CHEST ].m_PlaceSound = "dig.wood";
+ a_Info[E_BLOCK_LIGHT_WEIGHTED_PRESSURE_PLATE ].m_PlaceSound = "dig.wood";
+ a_Info[E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE ].m_PlaceSound = "dig.wood";
+ a_Info[E_BLOCK_INACTIVE_COMPARATOR ].m_PlaceSound = "dig.wood";
+ a_Info[E_BLOCK_ACTIVE_COMPARATOR ].m_PlaceSound = "dig.wood";
+ a_Info[E_BLOCK_DAYLIGHT_SENSOR ].m_PlaceSound = "dig.wood";
+ a_Info[E_BLOCK_BLOCK_OF_REDSTONE ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_NETHER_QUARTZ_ORE ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_HOPPER ].m_PlaceSound = "dig.metal";
+ a_Info[E_BLOCK_QUARTZ_BLOCK ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_QUARTZ_STAIRS ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_ACTIVATOR_RAIL ].m_PlaceSound = "dig.metal";
+ a_Info[E_BLOCK_DROPPER ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_STAINED_CLAY ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_STAINED_GLASS_PANE ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_NEW_LEAVES ].m_PlaceSound = "dig.grass";
+ a_Info[E_BLOCK_NEW_LOG ].m_PlaceSound = "dig.wood";
+ a_Info[E_BLOCK_ACACIA_WOOD_STAIRS ].m_PlaceSound = "dig.wood";
+ a_Info[E_BLOCK_DARK_OAK_WOOD_STAIRS ].m_PlaceSound = "dig.wood";
+ a_Info[E_BLOCK_HAY_BALE ].m_PlaceSound = "dig.grass";
+ a_Info[E_BLOCK_CARPET ].m_PlaceSound = "dig.cloth";
+ a_Info[E_BLOCK_HARDENED_CLAY ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_BLOCK_OF_COAL ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_PACKED_ICE ].m_PlaceSound = "dig.stone";
+ a_Info[E_BLOCK_BIG_FLOWER ].m_PlaceSound = "dig.grass";
}
diff --git a/src/BlockInfo.h b/src/BlockInfo.h
index 4c66c095a..567070a7f 100644
--- a/src/BlockInfo.h
+++ b/src/BlockInfo.h
@@ -48,6 +48,9 @@ public:
/** Can a finisher change it? */
bool m_CanBeTerraformed;
+ /** Sound when placing this block */
+ AString m_PlaceSound;
+
// tolua_end
/** Associated block handler. */
@@ -64,6 +67,7 @@ public:
inline static bool IsSolid (BLOCKTYPE a_Type) { return Get(a_Type).m_IsSolid; }
inline static bool FullyOccupiesVoxel (BLOCKTYPE a_Type) { return Get(a_Type).m_FullyOccupiesVoxel; }
inline static bool CanBeTerraformed (BLOCKTYPE a_Type) { return Get(a_Type).m_CanBeTerraformed; }
+ inline static AString GetPlaceSound (BLOCKTYPE a_Type) { return Get(a_Type).m_PlaceSound; }
// tolua_end
diff --git a/src/Blocks/BlockBed.cpp b/src/Blocks/BlockBed.cpp
index cd5783f58..cd1cc2a5f 100644
--- a/src/Blocks/BlockBed.cpp
+++ b/src/Blocks/BlockBed.cpp
@@ -15,7 +15,7 @@ void cBlockBedHandler::OnPlacedByPlayer(
if (a_BlockMeta < 8)
{
Vector3i Direction = MetaDataToDirection(a_BlockMeta);
- a_ChunkInterface.SetBlock(a_WorldInterface, a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z, E_BLOCK_BED, a_BlockMeta | 0x8);
+ a_ChunkInterface.SetBlock(a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z, E_BLOCK_BED, a_BlockMeta | 0x8);
}
}
diff --git a/src/Blocks/BlockBigFlower.h b/src/Blocks/BlockBigFlower.h
index 72e552dee..89ffc864d 100644
--- a/src/Blocks/BlockBigFlower.h
+++ b/src/Blocks/BlockBigFlower.h
@@ -19,16 +19,16 @@ public:
}
- virtual void DropBlock(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cBlockPluginInterface & a_BlockPluginInterface, cEntity * a_Digger, int a_BlockX, int a_BlockY, int a_BlockZ, bool a_CanDrop, bool a_DropVerbatim) override
+ virtual void DropBlock(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cBlockPluginInterface & a_BlockPluginInterface, cEntity * a_Digger, int a_BlockX, int a_BlockY, int a_BlockZ, bool a_CanDrop) override
{
NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ);
if (Meta & 0x8)
{
- super::DropBlock(a_ChunkInterface, a_WorldInterface, a_BlockPluginInterface, a_Digger, a_BlockX, a_BlockY - 1, a_BlockZ, a_CanDrop, a_DropVerbatim);
+ super::DropBlock(a_ChunkInterface, a_WorldInterface, a_BlockPluginInterface, a_Digger, a_BlockX, a_BlockY - 1, a_BlockZ, a_CanDrop);
}
else
{
- super::DropBlock(a_ChunkInterface, a_WorldInterface, a_BlockPluginInterface, a_Digger, a_BlockX, a_BlockY, a_BlockZ, a_CanDrop, a_DropVerbatim);
+ super::DropBlock(a_ChunkInterface, a_WorldInterface, a_BlockPluginInterface, a_Digger, a_BlockX, a_BlockY, a_BlockZ, a_CanDrop);
}
}
@@ -118,12 +118,6 @@ public:
}
}
}
-
-
- virtual const char * GetStepSound(void) override
- {
- return "step.grass";
- }
} ;
diff --git a/src/Blocks/BlockButton.h b/src/Blocks/BlockButton.h
index 3b45afff8..8e4f04740 100644
--- a/src/Blocks/BlockButton.h
+++ b/src/Blocks/BlockButton.h
@@ -57,12 +57,6 @@ public:
}
- virtual const char * GetStepSound(void) override
- {
- return m_BlockType == E_BLOCK_WOODEN_BUTTON ? "step.wood" : "step.stone";
- }
-
-
inline static NIBBLETYPE BlockFaceToMetaData(eBlockFace a_BlockFace)
{
switch (a_BlockFace)
diff --git a/src/Blocks/BlockCactus.h b/src/Blocks/BlockCactus.h
index ed441517d..910966c43 100644
--- a/src/Blocks/BlockCactus.h
+++ b/src/Blocks/BlockCactus.h
@@ -69,12 +69,6 @@ public:
{
a_Chunk.GetWorld()->GrowCactus(a_RelX + a_Chunk.GetPosX() * cChunkDef::Width, a_RelY, a_RelZ + a_Chunk.GetPosZ() * cChunkDef::Width, 1);
}
-
-
- virtual const char * GetStepSound(void) override
- {
- return "step.cloth";
- }
} ;
diff --git a/src/Blocks/BlockCake.h b/src/Blocks/BlockCake.h
index f05f468e5..3a754ce18 100644
--- a/src/Blocks/BlockCake.h
+++ b/src/Blocks/BlockCake.h
@@ -43,11 +43,6 @@ public:
{
return true;
}
-
- virtual const char * GetStepSound(void) override
- {
- return "step.cloth";
- }
} ;
diff --git a/src/Blocks/BlockCarpet.h b/src/Blocks/BlockCarpet.h
index d1aa52687..4b287c664 100644
--- a/src/Blocks/BlockCarpet.h
+++ b/src/Blocks/BlockCarpet.h
@@ -22,12 +22,6 @@ public:
cBlockHandler(a_BlockType)
{
}
-
-
- virtual const char * GetStepSound(void) override
- {
- return "step.cloth";
- }
virtual bool GetPlacementBlockTypeMeta(
diff --git a/src/Blocks/BlockChest.h b/src/Blocks/BlockChest.h
index 28adbed4f..201f2309b 100644
--- a/src/Blocks/BlockChest.h
+++ b/src/Blocks/BlockChest.h
@@ -106,12 +106,6 @@ public:
// Single chest, no further processing needed
}
-
- virtual const char * GetStepSound(void) override
- {
- return "step.wood";
- }
-
virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override
{
int BlockX = a_RelX + a_Chunk.GetPosX() * cChunkDef::Width;
diff --git a/src/Blocks/BlockCloth.h b/src/Blocks/BlockCloth.h
index 3c1ae7c25..525176725 100644
--- a/src/Blocks/BlockCloth.h
+++ b/src/Blocks/BlockCloth.h
@@ -15,11 +15,6 @@ public:
: cBlockHandler(a_BlockType)
{
}
-
- virtual const char * GetStepSound(void) override
- {
- return "step.cloth";
- }
} ;
diff --git a/src/Blocks/BlockCommandBlock.h b/src/Blocks/BlockCommandBlock.h
index cf0103765..b66def201 100644
--- a/src/Blocks/BlockCommandBlock.h
+++ b/src/Blocks/BlockCommandBlock.h
@@ -20,11 +20,6 @@ public:
{
a_Pickups.push_back(cItem(E_BLOCK_AIR, 8, 0));
}
-
- virtual const char * GetStepSound(void) override
- {
- return "step.stone";
- }
} ;
diff --git a/src/Blocks/BlockComparator.h b/src/Blocks/BlockComparator.h
index 6caaaab13..3443fc69e 100644
--- a/src/Blocks/BlockComparator.h
+++ b/src/Blocks/BlockComparator.h
@@ -64,12 +64,6 @@ public:
a_BlockMeta = cBlockRedstoneRepeaterHandler::RepeaterRotationToMetaData(a_Player->GetYaw());
return true;
}
-
-
- virtual const char * GetStepSound(void) override
- {
- return "step.wood";
- }
} ;
diff --git a/src/Blocks/BlockCrops.h b/src/Blocks/BlockCrops.h
index ae6e490e1..53e996683 100644
--- a/src/Blocks/BlockCrops.h
+++ b/src/Blocks/BlockCrops.h
@@ -100,12 +100,6 @@ public:
{
return ((a_RelY > 0) && (a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ) == E_BLOCK_FARMLAND));
}
-
-
- virtual const char * GetStepSound(void) override
- {
- return "step.grass";
- }
} ;
diff --git a/src/Blocks/BlockDirt.h b/src/Blocks/BlockDirt.h
index d458c6062..23e5a3cde 100644
--- a/src/Blocks/BlockDirt.h
+++ b/src/Blocks/BlockDirt.h
@@ -88,12 +88,6 @@ public:
}
} // for i - repeat twice
}
-
-
- virtual const char * GetStepSound(void) override
- {
- return "step.gravel";
- }
} ;
diff --git a/src/Blocks/BlockDoor.cpp b/src/Blocks/BlockDoor.cpp
index e80473cb5..1a277f071 100644
--- a/src/Blocks/BlockDoor.cpp
+++ b/src/Blocks/BlockDoor.cpp
@@ -102,16 +102,7 @@ void cBlockDoorHandler::OnPlacedByPlayer(
{
a_TopBlockMeta = 9;
}
- a_ChunkInterface.SetBlock(a_WorldInterface, a_BlockX, a_BlockY + 1, a_BlockZ, m_BlockType, a_TopBlockMeta);
-}
-
-
-
-
-
-const char * cBlockDoorHandler::GetStepSound(void)
-{
- return (m_BlockType == E_BLOCK_WOODEN_DOOR) ? "step.wood" : "step.stone";
+ a_ChunkInterface.SetBlock(a_BlockX, a_BlockY + 1, a_BlockZ, m_BlockType, a_TopBlockMeta);
}
diff --git a/src/Blocks/BlockDoor.h b/src/Blocks/BlockDoor.h
index c86fe829b..69e30d9c8 100644
--- a/src/Blocks/BlockDoor.h
+++ b/src/Blocks/BlockDoor.h
@@ -19,7 +19,6 @@ public:
virtual void OnDestroyed(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ) override;
virtual void OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override;
virtual void OnCancelRightClick(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace) override;
- virtual const char * GetStepSound(void) override;
virtual NIBBLETYPE MetaRotateCCW(NIBBLETYPE a_Meta) override;
virtual NIBBLETYPE MetaRotateCW(NIBBLETYPE a_Meta) override;
diff --git a/src/Blocks/BlockEnderchest.h b/src/Blocks/BlockEnderchest.h
index 4672f1459..0bc67a8f5 100644
--- a/src/Blocks/BlockEnderchest.h
+++ b/src/Blocks/BlockEnderchest.h
@@ -33,11 +33,6 @@ public:
a_BlockMeta = RotationToMetaData(a_Player->GetYaw());
return true;
}
-
- virtual const char * GetStepSound(void) override
- {
- return "step.stone";
- }
static NIBBLETYPE RotationToMetaData(double a_Rotation)
{
diff --git a/src/Blocks/BlockFarmland.h b/src/Blocks/BlockFarmland.h
index bb624e54f..02a48a4af 100644
--- a/src/Blocks/BlockFarmland.h
+++ b/src/Blocks/BlockFarmland.h
@@ -28,49 +28,12 @@ public:
virtual void OnUpdate(cChunkInterface & cChunkInterface, cWorldInterface & a_WorldInterface, cBlockPluginInterface & a_PluginInterface, cChunk & a_Chunk, int a_RelX, int a_RelY, int a_RelZ) override
{
- bool Found = false;
-
- EMCSBiome Biome = a_Chunk.GetBiomeAt(a_RelX, a_RelZ);
- if (a_Chunk.GetWorld()->IsWeatherWet() && !IsBiomeNoDownfall(Biome))
- {
- // Rain hydrates farmland, too, except in Desert biomes.
- Found = true;
- }
- else
- {
- // Search for water in a close proximity:
- // Ref.: http://www.minecraftwiki.net/wiki/Farmland#Hydrated_Farmland_Tiles
- // TODO: Rewrite this to use the chunk and its neighbors directly
- cBlockArea Area;
- int BlockX = a_RelX + a_Chunk.GetPosX() * cChunkDef::Width;
- int BlockZ = a_RelZ + a_Chunk.GetPosZ() * cChunkDef::Width;
- if (!Area.Read(a_Chunk.GetWorld(), BlockX - 4, BlockX + 4, a_RelY, a_RelY + 1, BlockZ - 4, BlockZ + 4))
- {
- // Too close to the world edge, cannot check surroundings; don't tick at all
- return;
- }
-
- size_t NumBlocks = Area.GetBlockCount();
- BLOCKTYPE * BlockTypes = Area.GetBlockTypes();
- for (size_t i = 0; i < NumBlocks; i++)
- {
- if (IsBlockWater(BlockTypes[i]))
- {
- Found = true;
- break;
- }
- } // for i - BlockTypes[]
- }
-
NIBBLETYPE BlockMeta = a_Chunk.GetMeta(a_RelX, a_RelY, a_RelZ);
-
- if (Found)
+
+ if (IsWaterInNear(a_Chunk, a_RelX, a_RelY, a_RelZ))
{
- // Water was found, hydrate the block until hydration reaches 7:
- if (BlockMeta < 7)
- {
- a_Chunk.FastSetBlock(a_RelX, a_RelY, a_RelZ, m_BlockType, ++BlockMeta);
- }
+ // Water was found, set block meta to 7
+ a_Chunk.FastSetBlock(a_RelX, a_RelY, a_RelZ, m_BlockType, 7);
return;
}
@@ -80,9 +43,10 @@ public:
a_Chunk.FastSetBlock(a_RelX, a_RelY, a_RelZ, E_BLOCK_FARMLAND, --BlockMeta);
return;
}
-
+
// Farmland too dry. If nothing is growing on top, turn back to dirt:
- switch (a_Chunk.GetBlock(a_RelX, a_RelY + 1, a_RelZ))
+ BLOCKTYPE UpperBlock = (a_RelY >= cChunkDef::Height) ? E_BLOCK_AIR : a_Chunk.GetBlock(a_RelX, a_RelY + 1, a_RelZ);
+ switch (UpperBlock)
{
case E_BLOCK_CROPS:
case E_BLOCK_POTATOES:
@@ -95,16 +59,63 @@ public:
}
default:
{
- a_Chunk.FastSetBlock(a_RelX, a_RelY, a_RelZ, E_BLOCK_DIRT, 0);
+ a_Chunk.SetBlock(a_RelX, a_RelY, a_RelZ, E_BLOCK_DIRT, 0);
break;
}
}
}
+ virtual void OnNeighborChanged(cChunkInterface & a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ) override
+ {
+ if (a_BlockY >= cChunkDef::Height)
+ {
+ return;
+ }
+
+ BLOCKTYPE UpperBlock = a_ChunkInterface.GetBlock(a_BlockX, a_BlockY + 1, a_BlockZ);
+ if (cBlockInfo::FullyOccupiesVoxel(UpperBlock))
+ {
+ a_ChunkInterface.SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_DIRT, 0);
+ }
+ }
+
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
a_Pickups.Add(E_BLOCK_DIRT, 1, 0); // Reset meta
}
+
+ bool IsWaterInNear(cChunk & a_Chunk, int a_RelX, int a_RelY, int a_RelZ)
+ {
+ if (a_Chunk.GetWorld()->IsWeatherWetAt(a_RelX, a_RelZ))
+ {
+ // Rain hydrates farmland, too, except in Desert biomes.
+ return true;
+ }
+
+ // Search for water in a close proximity:
+ // Ref.: http://www.minecraftwiki.net/wiki/Farmland#Hydrated_Farmland_Tiles
+ // TODO: Rewrite this to use the chunk and its neighbors directly
+ cBlockArea Area;
+ int BlockX = a_RelX + a_Chunk.GetPosX() * cChunkDef::Width;
+ int BlockZ = a_RelZ + a_Chunk.GetPosZ() * cChunkDef::Width;
+ if (!Area.Read(a_Chunk.GetWorld(), BlockX - 4, BlockX + 4, a_RelY, a_RelY + 1, BlockZ - 4, BlockZ + 4))
+ {
+ // Too close to the world edge, cannot check surroundings
+ return false;
+ }
+
+ size_t NumBlocks = Area.GetBlockCount();
+ BLOCKTYPE * BlockTypes = Area.GetBlockTypes();
+ for (size_t i = 0; i < NumBlocks; i++)
+ {
+ if (IsBlockWater(BlockTypes[i]))
+ {
+ return true;
+ }
+ } // for i - BlockTypes[]
+
+ return false;
+ }
} ;
diff --git a/src/Blocks/BlockFenceGate.h b/src/Blocks/BlockFenceGate.h
index ae99a4f94..3041dd46c 100644
--- a/src/Blocks/BlockFenceGate.h
+++ b/src/Blocks/BlockFenceGate.h
@@ -17,6 +17,12 @@ public:
}
+ virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
+ {
+ a_Pickups.Add(E_BLOCK_FENCE_GATE, 1, 0); // Reset meta to zero
+ }
+
+
virtual bool GetPlacementBlockTypeMeta(
cChunkInterface & a_ChunkInterface, cPlayer * a_Player,
int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace,
diff --git a/src/Blocks/BlockFire.h b/src/Blocks/BlockFire.h
index b9f211042..07fcefe16 100644
--- a/src/Blocks/BlockFire.h
+++ b/src/Blocks/BlockFire.h
@@ -50,11 +50,6 @@ public:
return true;
}
- virtual const char * GetStepSound(void) override
- {
- return "step.wood";
- }
-
/** Traces along YP until it finds an obsidian block, returns Y difference or 0 if no portal, and -1 for border
Takes the X, Y, and Z of the base block; with an optional MaxY for portal border finding */
int FindObsidianCeiling(int X, int Y, int Z, cChunkInterface & a_ChunkInterface, int MaxY = 0)
@@ -131,11 +126,11 @@ public:
{
if (Dir == 1)
{
- a_ChunkInterface.SetBlock(a_WorldInterface, Width, Height, Z, E_BLOCK_NETHER_PORTAL, Dir);
+ a_ChunkInterface.SetBlock(Width, Height, Z, E_BLOCK_NETHER_PORTAL, Dir);
}
else
{
- a_ChunkInterface.SetBlock(a_WorldInterface, X, Height, Width, E_BLOCK_NETHER_PORTAL, Dir);
+ a_ChunkInterface.SetBlock(X, Height, Width, E_BLOCK_NETHER_PORTAL, Dir);
}
}
}
diff --git a/src/Blocks/BlockFlower.h b/src/Blocks/BlockFlower.h
index 6f64c062b..3eb8a0baa 100644
--- a/src/Blocks/BlockFlower.h
+++ b/src/Blocks/BlockFlower.h
@@ -28,12 +28,6 @@ public:
{
return (a_RelY > 0) && IsBlockTypeOfDirt(a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ));
}
-
-
- virtual const char * GetStepSound(void) override
- {
- return "step.grass";
- }
} ;
diff --git a/src/Blocks/BlockGravel.h b/src/Blocks/BlockGravel.h
index e1c9ff390..d076306fb 100644
--- a/src/Blocks/BlockGravel.h
+++ b/src/Blocks/BlockGravel.h
@@ -16,9 +16,17 @@ public:
{
}
- virtual const char * GetStepSound(void) override
+ virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
- return "step.gravel";
+ cFastRandom Random;
+ if (Random.NextInt(30) == 0)
+ {
+ a_Pickups.Add(E_ITEM_FLINT, 1, 0);
+ }
+ else
+ {
+ a_Pickups.Add(E_BLOCK_GRAVEL, 1, 0);
+ }
}
} ;
diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp
index 6767d4de4..30b303cfd 100644
--- a/src/Blocks/BlockHandler.cpp
+++ b/src/Blocks/BlockHandler.cpp
@@ -47,6 +47,7 @@
#include "BlockLilypad.h"
#include "BlockLever.h"
#include "BlockMelon.h"
+#include "BlockMobSpawner.h"
#include "BlockMushroom.h"
#include "BlockMycelium.h"
#include "BlockNetherWart.h"
@@ -244,6 +245,7 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType)
case E_BLOCK_LOG: return new cBlockSidewaysHandler (a_BlockType);
case E_BLOCK_MELON: return new cBlockMelonHandler (a_BlockType);
case E_BLOCK_MELON_STEM: return new cBlockStemsHandler (a_BlockType);
+ case E_BLOCK_MOB_SPAWNER: return new cBlockMobSpawnerHandler (a_BlockType);
case E_BLOCK_MYCELIUM: return new cBlockMyceliumHandler (a_BlockType);
case E_BLOCK_NETHER_BRICK_STAIRS: return new cBlockStairsHandler (a_BlockType);
case E_BLOCK_NETHER_PORTAL: return new cBlockPortalHandler (a_BlockType);
@@ -417,57 +419,45 @@ void cBlockHandler::ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta)
-void cBlockHandler::DropBlock(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cBlockPluginInterface & a_BlockPluginInterface, cEntity * a_Digger, int a_BlockX, int a_BlockY, int a_BlockZ, bool a_CanDrop, bool a_DropVerbatim)
+void cBlockHandler::DropBlock(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cBlockPluginInterface & a_BlockPluginInterface, cEntity * a_Digger, int a_BlockX, int a_BlockY, int a_BlockZ, bool a_CanDrop)
{
cItems Pickups;
NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ);
if (a_CanDrop)
{
- if (!a_DropVerbatim)
+ if ((a_Digger != NULL) && (a_Digger->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchSilkTouch) > 0))
{
- ConvertToPickups(Pickups, Meta);
- }
- else
- {
- // TODO: Add a proper overridable function for this
- if (a_Digger != NULL)
+ switch (m_BlockType)
{
- cEnchantments Enchantments = a_Digger->GetEquippedWeapon().m_Enchantments;
- if ((Enchantments.GetLevel(cEnchantments::enchSilkTouch) > 0) && a_Digger->IsPlayer())
+ case E_BLOCK_CAKE:
+ case E_BLOCK_CARROTS:
+ case E_BLOCK_COCOA_POD:
+ case E_BLOCK_DOUBLE_STONE_SLAB:
+ case E_BLOCK_DOUBLE_WOODEN_SLAB:
+ case E_BLOCK_FIRE:
+ case E_BLOCK_FARMLAND:
+ case E_BLOCK_MELON_STEM:
+ case E_BLOCK_MOB_SPAWNER:
+ case E_BLOCK_NETHER_WART:
+ case E_BLOCK_POTATOES:
+ case E_BLOCK_PUMPKIN_STEM:
+ case E_BLOCK_SNOW:
+ case E_BLOCK_SUGARCANE:
+ case E_BLOCK_TALL_GRASS:
+ case E_BLOCK_CROPS:
{
- switch (m_BlockType)
- {
- case E_BLOCK_CAKE:
- case E_BLOCK_CARROTS:
- case E_BLOCK_COCOA_POD:
- case E_BLOCK_DOUBLE_STONE_SLAB:
- case E_BLOCK_DOUBLE_WOODEN_SLAB:
- case E_BLOCK_FIRE:
- case E_BLOCK_FARMLAND:
- case E_BLOCK_MELON_STEM:
- case E_BLOCK_MOB_SPAWNER:
- case E_BLOCK_NETHER_WART:
- case E_BLOCK_POTATOES:
- case E_BLOCK_PUMPKIN_STEM:
- case E_BLOCK_SNOW:
- case E_BLOCK_SUGARCANE:
- case E_BLOCK_TALL_GRASS:
- case E_BLOCK_CROPS:
- {
- // Silktouch can't be used for this blocks
- ConvertToPickups(Pickups, Meta);
- break;
- };
- default: Pickups.Add(m_BlockType, 1, Meta);
- }
- }
- else
- {
- Pickups.Add(m_BlockType, 1, Meta);
+ // Silktouch can't be used for these blocks
+ ConvertToPickups(Pickups, Meta);
+ break;
}
+ default: Pickups.Add(m_BlockType, 1, Meta); break;
}
}
+ else
+ {
+ ConvertToPickups(Pickups, Meta);
+ }
}
// Allow plugins to modify the pickups:
@@ -495,15 +485,6 @@ void cBlockHandler::DropBlock(cChunkInterface & a_ChunkInterface, cWorldInterfac
-const char * cBlockHandler::GetStepSound()
-{
- return "step.stone";
-}
-
-
-
-
-
bool cBlockHandler::CanBeAt(cChunkInterface & a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ, const cChunk & a_Chunk)
{
return true;
diff --git a/src/Blocks/BlockHandler.h b/src/Blocks/BlockHandler.h
index de90ce55b..3a8115da0 100644
--- a/src/Blocks/BlockHandler.h
+++ b/src/Blocks/BlockHandler.h
@@ -82,10 +82,7 @@ public:
@param a_CanDrop Informs the handler whether the block should be dropped at all. One example when this is false is when stone is destroyed by hand
@param a_DropVerbatim Calls ConvertToVerbatimPickups() instead of its counterpart, meaning the block itself is dropped by default (due to a speical tool or enchantment)
*/
- virtual void DropBlock(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cBlockPluginInterface & a_BlockPluginInterface, cEntity * a_Digger, int a_BlockX, int a_BlockY, int a_BlockZ, bool a_CanDrop = true, bool a_DropVerbatim = false);
-
- /// Returns step sound name of block
- virtual const char * GetStepSound(void);
+ virtual void DropBlock(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cBlockPluginInterface & a_BlockPluginInterface, cEntity * a_Digger, int a_BlockX, int a_BlockY, int a_BlockZ, bool a_CanDrop = true);
/// Checks if the block can stay at the specified relative coords in the chunk
virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk);
diff --git a/src/Blocks/BlockHayBale.h b/src/Blocks/BlockHayBale.h
index 3c6472adb..8150b10d3 100644
--- a/src/Blocks/BlockHayBale.h
+++ b/src/Blocks/BlockHayBale.h
@@ -15,12 +15,6 @@ public:
: cBlockSidewaysHandler(a_BlockType)
{
}
-
-
- virtual const char * GetStepSound(void) override
- {
- return "step.grass";
- }
} ;
diff --git a/src/Blocks/BlockLadder.h b/src/Blocks/BlockLadder.h
index 284d1d732..ab3f55439 100644
--- a/src/Blocks/BlockLadder.h
+++ b/src/Blocks/BlockLadder.h
@@ -111,12 +111,6 @@ public:
int BlockZ = a_RelZ + a_Chunk.GetPosZ() * cChunkDef::Width;
return LadderCanBePlacedAt(a_ChunkInterface, BlockX, a_RelY, BlockZ, BlockFace);
}
-
-
- virtual const char * GetStepSound(void) override
- {
- return "step.wood";
- }
} ;
diff --git a/src/Blocks/BlockLeaves.h b/src/Blocks/BlockLeaves.h
index a8aa28a0f..add571675 100644
--- a/src/Blocks/BlockLeaves.h
+++ b/src/Blocks/BlockLeaves.h
@@ -112,12 +112,6 @@ public:
DropBlock(a_ChunkInterface, a_WorldInterface, a_PluginInterface, NULL, BlockX, a_RelY, BlockZ);
a_ChunkInterface.DigBlock(a_WorldInterface, BlockX, a_RelY, BlockZ);
}
-
-
- virtual const char * GetStepSound(void) override
- {
- return "step.grass";
- }
} ;
diff --git a/src/Blocks/BlockLever.h b/src/Blocks/BlockLever.h
index 4316fd06b..3b63b396c 100644
--- a/src/Blocks/BlockLever.h
+++ b/src/Blocks/BlockLever.h
@@ -70,12 +70,6 @@ public:
}
- virtual const char * GetStepSound(void) override
- {
- return "step.wood";
- }
-
-
inline static eBlockFace BlockMetaDataToBlockFace(NIBBLETYPE a_Meta)
{
switch (a_Meta & 0x7)
diff --git a/src/Blocks/BlockMelon.h b/src/Blocks/BlockMelon.h
index 60202d66e..22cdb4d29 100644
--- a/src/Blocks/BlockMelon.h
+++ b/src/Blocks/BlockMelon.h
@@ -22,12 +22,6 @@ public:
cFastRandom Random;
a_Pickups.push_back(cItem(E_ITEM_MELON_SLICE, (char)(3 + Random.NextInt(5)), 0));
}
-
-
- virtual const char * GetStepSound(void) override
- {
- return "step.wood";
- }
} ;
diff --git a/src/Blocks/BlockMobHead.h b/src/Blocks/BlockMobHead.h
index ff1ef97bf..b51155802 100644
--- a/src/Blocks/BlockMobHead.h
+++ b/src/Blocks/BlockMobHead.h
@@ -146,9 +146,9 @@ public:
a_ChunkInterface.FastSetBlock(a_BlockX, a_BlockY - 2, a_BlockZ, E_BLOCK_AIR, 0);
// Block entities
- a_ChunkInterface.SetBlock(a_WorldInterface, a_BlockX + 1, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0);
- a_ChunkInterface.SetBlock(a_WorldInterface, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0);
- a_ChunkInterface.SetBlock(a_WorldInterface, a_BlockX - 1, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0);
+ a_ChunkInterface.SetBlock(a_BlockX + 1, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0);
+ a_ChunkInterface.SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0);
+ a_ChunkInterface.SetBlock(a_BlockX - 1, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0);
// Spawn the wither:
a_WorldInterface.SpawnMob(a_BlockX + 0.5, a_BlockY - 2, a_BlockZ + 0.5, cMonster::mtWither);
@@ -176,9 +176,9 @@ public:
a_ChunkInterface.FastSetBlock(a_BlockX, a_BlockY - 2, a_BlockZ, E_BLOCK_AIR, 0);
// Block entities
- a_ChunkInterface.SetBlock(a_WorldInterface, a_BlockX, a_BlockY, a_BlockZ + 1, E_BLOCK_AIR, 0);
- a_ChunkInterface.SetBlock(a_WorldInterface, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0);
- a_ChunkInterface.SetBlock(a_WorldInterface, a_BlockX, a_BlockY, a_BlockZ - 1, E_BLOCK_AIR, 0);
+ a_ChunkInterface.SetBlock(a_BlockX, a_BlockY, a_BlockZ + 1, E_BLOCK_AIR, 0);
+ a_ChunkInterface.SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0);
+ a_ChunkInterface.SetBlock(a_BlockX, a_BlockY, a_BlockZ - 1, E_BLOCK_AIR, 0);
// Spawn the wither:
a_WorldInterface.SpawnMob(a_BlockX + 0.5, a_BlockY - 2, a_BlockZ + 0.5, cMonster::mtWither);
diff --git a/src/Blocks/BlockMobSpawner.h b/src/Blocks/BlockMobSpawner.h
new file mode 100644
index 000000000..a51fbaafc
--- /dev/null
+++ b/src/Blocks/BlockMobSpawner.h
@@ -0,0 +1,40 @@
+
+#pragma once
+
+#include "BlockHandler.h"
+#include "../World.h"
+#include "../Items/ItemHandler.h"
+
+
+
+
+
+class cBlockMobSpawnerHandler :
+ public cBlockHandler
+{
+public:
+ cBlockMobSpawnerHandler(BLOCKTYPE a_BlockType)
+ : cBlockHandler(a_BlockType)
+ {
+ }
+
+
+ virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
+ {
+ // No pickups
+ }
+
+
+ virtual void OnDestroyedByPlayer(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) override
+ {
+ cItemHandler * Handler = a_Player->GetEquippedItem().GetHandler();
+ if (a_Player->IsGameModeCreative() || !Handler->CanHarvestBlock(E_BLOCK_MOB_SPAWNER))
+ {
+ return;
+ }
+
+ cFastRandom Random;
+ int Reward = 15 + Random.NextInt(15) + Random.NextInt(15);
+ a_WorldInterface.SpawnExperienceOrb((double)a_BlockX, (double)a_BlockY + 1, (double)a_BlockZ, Reward);
+ }
+} ;
diff --git a/src/Blocks/BlockMushroom.h b/src/Blocks/BlockMushroom.h
index 135d418d7..7c06fcc74 100644
--- a/src/Blocks/BlockMushroom.h
+++ b/src/Blocks/BlockMushroom.h
@@ -50,12 +50,6 @@ public:
}
return true;
}
-
-
- virtual const char * GetStepSound(void) override
- {
- return "step.grass";
- }
} ;
diff --git a/src/Blocks/BlockMycelium.h b/src/Blocks/BlockMycelium.h
index 2a8ef5fca..628e87181 100644
--- a/src/Blocks/BlockMycelium.h
+++ b/src/Blocks/BlockMycelium.h
@@ -22,11 +22,6 @@ public:
{
a_Pickups.push_back(cItem(E_BLOCK_DIRT, 1, 0));
}
-
- virtual const char * GetStepSound(void) override
- {
- return "step.gravel";
- }
} ;
diff --git a/src/Blocks/BlockOre.h b/src/Blocks/BlockOre.h
index 0067d475f..f6ea3aa3c 100644
--- a/src/Blocks/BlockOre.h
+++ b/src/Blocks/BlockOre.h
@@ -51,7 +51,8 @@ public:
}
default:
{
- ASSERT(!"Unhandled ore!");
+ a_Pickups.push_back(cItem(m_BlockType));
+ break;
}
}
}
diff --git a/src/Blocks/BlockPiston.cpp b/src/Blocks/BlockPiston.cpp
index 164967621..0169fb266 100644
--- a/src/Blocks/BlockPiston.cpp
+++ b/src/Blocks/BlockPiston.cpp
@@ -52,7 +52,7 @@ void cBlockPistonHandler::OnDestroyed(cChunkInterface & a_ChunkInterface, cWorld
if (a_ChunkInterface.GetBlock(newX, newY, newZ) == E_BLOCK_PISTON_EXTENSION)
{
- a_ChunkInterface.SetBlock(a_WorldInterface, newX, newY, newZ, E_BLOCK_AIR, 0);
+ a_ChunkInterface.SetBlock(newX, newY, newZ, E_BLOCK_AIR, 0);
}
}
diff --git a/src/Blocks/BlockPlanks.h b/src/Blocks/BlockPlanks.h
index 4c5bb4860..3c243ebdc 100644
--- a/src/Blocks/BlockPlanks.h
+++ b/src/Blocks/BlockPlanks.h
@@ -27,12 +27,6 @@ public:
a_BlockMeta = (NIBBLETYPE)(a_Player->GetEquippedItem().m_ItemDamage);
return true;
}
-
-
- virtual const char * GetStepSound(void) override
- {
- return "step.wood";
- }
} ;
diff --git a/src/Blocks/BlockRedstoneRepeater.h b/src/Blocks/BlockRedstoneRepeater.h
index 4b18add12..3e5259c56 100644
--- a/src/Blocks/BlockRedstoneRepeater.h
+++ b/src/Blocks/BlockRedstoneRepeater.h
@@ -63,12 +63,6 @@ public:
}
- virtual const char * GetStepSound(void) override
- {
- return "step.wood";
- }
-
-
inline static NIBBLETYPE RepeaterRotationToMetaData(double a_Rotation)
{
a_Rotation += 90 + 45; // So its not aligned with axis
diff --git a/src/Blocks/BlockRedstoneTorch.h b/src/Blocks/BlockRedstoneTorch.h
index cb897ba3f..8416a415c 100644
--- a/src/Blocks/BlockRedstoneTorch.h
+++ b/src/Blocks/BlockRedstoneTorch.h
@@ -23,12 +23,6 @@ public:
// Always drop the ON torch, meta 0
a_Pickups.push_back(cItem(E_BLOCK_REDSTONE_TORCH_ON, 1, 0));
}
-
-
- virtual const char * GetStepSound(void) override
- {
- return "step.wood";
- }
} ;
diff --git a/src/Blocks/BlockSand.h b/src/Blocks/BlockSand.h
index 3fc271483..48beab138 100644
--- a/src/Blocks/BlockSand.h
+++ b/src/Blocks/BlockSand.h
@@ -15,12 +15,6 @@ public:
: cBlockHandler(a_BlockType)
{
}
-
- virtual const char * GetStepSound(void) override
- {
- return "step.sand";
- }
-
};
diff --git a/src/Blocks/BlockSapling.h b/src/Blocks/BlockSapling.h
index de28273d5..bec79c6f3 100644
--- a/src/Blocks/BlockSapling.h
+++ b/src/Blocks/BlockSapling.h
@@ -46,12 +46,6 @@ public:
a_Chunk.SetMeta(a_RelX, a_RelY, a_RelZ, Meta | 0x08);
}
}
-
-
- virtual const char * GetStepSound(void) override
- {
- return "step.grass";
- }
} ;
diff --git a/src/Blocks/BlockSideways.h b/src/Blocks/BlockSideways.h
index f5f10899d..4b1e38d6d 100644
--- a/src/Blocks/BlockSideways.h
+++ b/src/Blocks/BlockSideways.h
@@ -65,12 +65,6 @@ public:
}
}
}
-
-
- virtual const char * GetStepSound(void) override
- {
- return "step.wood";
- }
} ;
diff --git a/src/Blocks/BlockSignPost.h b/src/Blocks/BlockSignPost.h
index d0cc760b0..40e15c253 100644
--- a/src/Blocks/BlockSignPost.h
+++ b/src/Blocks/BlockSignPost.h
@@ -27,12 +27,6 @@ public:
}
- virtual const char * GetStepSound(void) override
- {
- return "step.wood";
- }
-
-
virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override
{
if (a_RelY <= 0)
diff --git a/src/Blocks/BlockSlab.h b/src/Blocks/BlockSlab.h
index e67f0e8b3..0ad30bb2b 100644
--- a/src/Blocks/BlockSlab.h
+++ b/src/Blocks/BlockSlab.h
@@ -85,18 +85,6 @@ public:
return true;
}
-
-
- virtual const char * GetStepSound(void) override
- {
- switch (m_BlockType)
- {
- case E_BLOCK_WOODEN_SLAB: return "step.wood";
- case E_BLOCK_STONE_SLAB: return "step.stone";
- }
- ASSERT(!"Unhandled slab type!");
- return "";
- }
virtual bool CanDirtGrowGrass(NIBBLETYPE a_Meta) override
@@ -174,17 +162,6 @@ public:
ASSERT(!"Unhandled double slab type!");
return a_BlockType;
}
-
- virtual const char * GetStepSound(void) override
- {
- switch (m_BlockType)
- {
- case E_BLOCK_DOUBLE_STONE_SLAB: return "step.stone";
- case E_BLOCK_DOUBLE_WOODEN_SLAB: return "step.wood";
- }
- ASSERT(!"Unhandled double slab type!");
- return "";
- }
} ;
diff --git a/src/Blocks/BlockSnow.h b/src/Blocks/BlockSnow.h
index 977f19a16..7b6094c9f 100644
--- a/src/Blocks/BlockSnow.h
+++ b/src/Blocks/BlockSnow.h
@@ -87,12 +87,6 @@ public:
{
return false;
}
-
-
- virtual const char * GetStepSound(void) override
- {
- return "step.cloth";
- }
} ;
diff --git a/src/Blocks/BlockStairs.h b/src/Blocks/BlockStairs.h
index 417969a82..d396204e0 100644
--- a/src/Blocks/BlockStairs.h
+++ b/src/Blocks/BlockStairs.h
@@ -55,24 +55,6 @@ public:
}
- virtual const char * GetStepSound(void) override
- {
- if (
- (m_BlockType == E_BLOCK_WOODEN_STAIRS) ||
- (m_BlockType == E_BLOCK_SPRUCE_WOOD_STAIRS) ||
- (m_BlockType == E_BLOCK_JUNGLE_WOOD_STAIRS) ||
- (m_BlockType == E_BLOCK_ACACIA_WOOD_STAIRS) ||
- (m_BlockType == E_BLOCK_BIRCH_WOOD_STAIRS) ||
- (m_BlockType == E_BLOCK_DARK_OAK_WOOD_STAIRS)
- )
- {
- return "step.wood";
- }
-
- return "step.stone";
- }
-
-
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
// Reset meta to zero
diff --git a/src/Blocks/BlockStems.h b/src/Blocks/BlockStems.h
index b726a0901..860c7dd45 100644
--- a/src/Blocks/BlockStems.h
+++ b/src/Blocks/BlockStems.h
@@ -47,12 +47,6 @@ public:
{
return ((a_RelY > 0) && (a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ) == E_BLOCK_FARMLAND));
}
-
-
- virtual const char * GetStepSound(void) override
- {
- return "step.wood";
- }
} ;
diff --git a/src/Blocks/BlockSugarcane.h b/src/Blocks/BlockSugarcane.h
index 5902c791b..c832ff218 100644
--- a/src/Blocks/BlockSugarcane.h
+++ b/src/Blocks/BlockSugarcane.h
@@ -78,12 +78,6 @@ public:
{
a_Chunk.GetWorld()->GrowSugarcane(a_RelX + a_Chunk.GetPosX() * cChunkDef::Width, a_RelY, a_RelZ + a_Chunk.GetPosZ() * cChunkDef::Width, 1);
}
-
-
- virtual const char * GetStepSound(void) override
- {
- return "step.grass";
- }
} ;
diff --git a/src/Blocks/BlockTNT.h b/src/Blocks/BlockTNT.h
index 283a03730..3a573ae67 100644
--- a/src/Blocks/BlockTNT.h
+++ b/src/Blocks/BlockTNT.h
@@ -16,11 +16,6 @@ public:
{
}
- virtual const char * GetStepSound(void) override
- {
- return "step.grass";
- }
-
virtual void OnCancelRightClick(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace) override
{
a_WorldInterface.SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, a_Player);
diff --git a/src/Blocks/BlockTallGrass.h b/src/Blocks/BlockTallGrass.h
index 9c008f793..f520414a7 100644
--- a/src/Blocks/BlockTallGrass.h
+++ b/src/Blocks/BlockTallGrass.h
@@ -53,12 +53,6 @@ public:
{
return ((a_RelY > 0) && (a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ) != E_BLOCK_AIR));
}
-
-
- virtual const char * GetStepSound(void) override
- {
- return "step.grass";
- }
} ;
diff --git a/src/Blocks/BlockTorch.h b/src/Blocks/BlockTorch.h
index df5574d5d..fa46b37a8 100644
--- a/src/Blocks/BlockTorch.h
+++ b/src/Blocks/BlockTorch.h
@@ -184,12 +184,6 @@ public:
// Always drop meta = 0
a_Pickups.push_back(cItem(m_BlockType, 1, 0));
}
-
-
- virtual const char * GetStepSound(void) override
- {
- return "step.wood";
- }
} ;
diff --git a/src/Blocks/BlockTrapdoor.h b/src/Blocks/BlockTrapdoor.h
index a6327b5c2..41256ae55 100644
--- a/src/Blocks/BlockTrapdoor.h
+++ b/src/Blocks/BlockTrapdoor.h
@@ -16,11 +16,6 @@ public:
{
}
- virtual const char * GetStepSound(void) override
- {
- return "step.wood";
- }
-
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
// Reset meta to zero
diff --git a/src/Blocks/BlockTripwire.h b/src/Blocks/BlockTripwire.h
index 3ab17bf4a..d03f37537 100644
--- a/src/Blocks/BlockTripwire.h
+++ b/src/Blocks/BlockTripwire.h
@@ -20,11 +20,6 @@ public:
{
a_Pickups.push_back(cItem(E_ITEM_STRING, 1, 0));
}
-
- virtual const char * GetStepSound(void) override
- {
- return "";
- }
};
diff --git a/src/Blocks/BlockTripwireHook.h b/src/Blocks/BlockTripwireHook.h
index 4f9d79483..88d389711 100644
--- a/src/Blocks/BlockTripwireHook.h
+++ b/src/Blocks/BlockTripwireHook.h
@@ -70,11 +70,6 @@ public:
return ((a_RelY > 0) && cBlockInfo::FullyOccupiesVoxel(BlockIsOn));
}
-
- virtual const char * GetStepSound(void) override
- {
- return "step.wood";
- }
};
diff --git a/src/Blocks/BlockVine.h b/src/Blocks/BlockVine.h
index 578224c61..b61673cc5 100644
--- a/src/Blocks/BlockVine.h
+++ b/src/Blocks/BlockVine.h
@@ -159,12 +159,6 @@ public:
{
return true;
}
-
-
- virtual const char * GetStepSound(void) override
- {
- return "step.grass";
- }
virtual bool DoesDropOnUnsuitable(void) override
diff --git a/src/Blocks/BlockWallSign.h b/src/Blocks/BlockWallSign.h
index 47649379e..0abe9c52c 100644
--- a/src/Blocks/BlockWallSign.h
+++ b/src/Blocks/BlockWallSign.h
@@ -27,12 +27,6 @@ public:
}
- virtual const char * GetStepSound(void) override
- {
- return "step.wood";
- }
-
-
virtual void OnPlacedByPlayer(
cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player,
int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace,
diff --git a/src/Blocks/BlockWorkbench.h b/src/Blocks/BlockWorkbench.h
index 70468369c..699badaf2 100644
--- a/src/Blocks/BlockWorkbench.h
+++ b/src/Blocks/BlockWorkbench.h
@@ -30,12 +30,6 @@ public:
{
return true;
}
-
-
- virtual const char * GetStepSound(void) override
- {
- return "step.wood";
- }
} ;
diff --git a/src/Blocks/ChunkInterface.h b/src/Blocks/ChunkInterface.h
index dea9d7c7e..d5f1f1273 100644
--- a/src/Blocks/ChunkInterface.h
+++ b/src/Blocks/ChunkInterface.h
@@ -37,9 +37,9 @@ public:
/** Sets the block at the specified coords to the specified value.
Full processing, incl. updating neighbors, is performed.
*/
- void SetBlock(cWorldInterface & a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
+ void SetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
{
- m_ChunkMap->SetBlock(a_WorldInterface, a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta);
+ m_ChunkMap->SetBlock(a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta);
}
void SetBlockMeta(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_MetaData)
diff --git a/src/Blocks/WorldInterface.h b/src/Blocks/WorldInterface.h
index d1c6f9bfc..889ef1d87 100644
--- a/src/Blocks/WorldInterface.h
+++ b/src/Blocks/WorldInterface.h
@@ -17,7 +17,7 @@ class cWorldInterface
public:
virtual ~cWorldInterface() {}
- virtual Int64 GetTimeOfDay(void) const = 0;
+ virtual int GetTimeOfDay(void) const = 0;
virtual Int64 GetWorldAge(void) const = 0;
virtual eDimension GetDimension(void) const = 0;
@@ -35,6 +35,9 @@ public:
/** Spawns a mob of the specified type. Returns the mob's EntityID if recognized and spawned, <0 otherwise */
virtual int SpawnMob(double a_PosX, double a_PosY, double a_PosZ, cMonster::eType a_MonsterType) = 0;
+ /** Spawns an experience orb at the given location with the given reward. It returns the UniqueID of the spawned experience orb. */
+ virtual int SpawnExperienceOrb(double a_X, double a_Y, double a_Z, int a_Reward) = 0;
+
/** Calls the callback for the block entity at the specified coords; returns false if there's no block entity at those coords, true if found */
virtual bool DoWithBlockEntityAt(int a_BlockX, int a_BlockY, int a_BlockZ, cBlockEntityCallback & a_Callback) = 0;
@@ -44,7 +47,7 @@ public:
/** Calls the callback for each player in the list; returns true if all players processed, false if the callback aborted by returning true */
virtual bool ForEachPlayer(cItemCallback<cPlayer> & a_Callback) = 0;
- virtual void SetTimeOfDay(Int64 a_TimeOfDay) = 0;
+ virtual void SetTimeOfDay(int a_TimeOfDay) = 0;
/** Returns true if it is raining, stormy or snowing at the specified location. This takes into account biomes. */
virtual bool IsWeatherWetAt(int a_BlockX, int a_BlockZ) = 0;
diff --git a/src/BoundingBox.h b/src/BoundingBox.h
index 793466302..928e62afa 100644
--- a/src/BoundingBox.h
+++ b/src/BoundingBox.h
@@ -80,6 +80,17 @@ public:
/// Calculates the intersection of the two bounding boxes; returns true if nonempty
bool Intersect(const cBoundingBox & a_Other, cBoundingBox & a_Intersection);
+ double GetMinX(void) const { return m_Min.x; }
+ double GetMinY(void) const { return m_Min.y; }
+ double GetMinZ(void) const { return m_Min.z; }
+
+ double GetMaxX(void) const { return m_Max.x; }
+ double GetMaxY(void) const { return m_Max.y; }
+ double GetMaxZ(void) const { return m_Max.z; }
+
+ const Vector3d & GetMin(void) const { return m_Min; }
+ const Vector3d & GetMax(void) const { return m_Max; }
+
protected:
Vector3d m_Min;
Vector3d m_Max;
diff --git a/src/BuildInfo.h.cmake b/src/BuildInfo.h.cmake
new file mode 100644
index 000000000..6337dab3e
--- /dev/null
+++ b/src/BuildInfo.h.cmake
@@ -0,0 +1,15 @@
+
+#pragma once
+
+#cmakedefine BUILD_ID
+
+#ifdef BUILD_ID
+
+#undef BUILD_ID
+
+#define BUILD_SERIES_NAME "@BUILD_SERIES_NAME@"
+#define BUILD_ID "@BUILD_ID@"
+#define BUILD_COMMIT_ID "@BUILD_COMMIT_ID@"
+#define BUILD_DATETIME "@BUILD_DATETIME@"
+#endif
+
diff --git a/src/ByteBuffer.cpp b/src/ByteBuffer.cpp
index 96556bf61..17e8091c7 100644
--- a/src/ByteBuffer.cpp
+++ b/src/ByteBuffer.cpp
@@ -267,7 +267,7 @@ size_t cByteBuffer::GetReadableSpace(void) const
}
// Single readable space partition:
ASSERT(m_WritePos >= m_ReadPos);
- return m_WritePos - m_ReadPos ;
+ return m_WritePos - m_ReadPos;
}
@@ -489,6 +489,27 @@ bool cByteBuffer::ReadLEInt(int & a_Value)
+bool cByteBuffer::ReadPosition(int & a_BlockX, int & a_BlockY, int & a_BlockZ)
+{
+ Int64 Value;
+ if (!ReadBEInt64(Value))
+ {
+ return false;
+ }
+
+ UInt32 BlockXRaw = (Value >> 38) & 0x3ffffff;
+ UInt32 BlockYRaw = (Value >> 26) & 0xfff;
+ UInt32 BlockZRaw = (Value & 0x3ffffff);
+ a_BlockX = ((BlockXRaw & 0x2000000) == 0) ? BlockXRaw : (~(BlockXRaw & 0x1ffffff)) + 1;
+ a_BlockY = ((BlockYRaw & 0x800) == 0) ? BlockYRaw : (~(BlockXRaw & 0x7ff)) + 1;
+ a_BlockZ = ((BlockZRaw & 0x2000000) == 0) ? BlockZRaw : (~(BlockZRaw & 0x1ffffff)) + 1;
+ return true;
+}
+
+
+
+
+
bool cByteBuffer::WriteChar(char a_Value)
{
CHECK_THREAD;
@@ -661,6 +682,15 @@ bool cByteBuffer::WriteLEInt(int a_Value)
+bool cByteBuffer::WritePosition(int a_BlockX, int a_BlockY, int a_BlockZ)
+{
+ return WriteBEInt64(((Int64)a_BlockX & 0x3FFFFFF) << 38 | ((Int64)a_BlockY & 0xFFF) << 26 | ((Int64)a_BlockZ & 0x3FFFFFF));
+}
+
+
+
+
+
bool cByteBuffer::ReadBuf(void * a_Buffer, size_t a_Count)
{
CHECK_THREAD;
diff --git a/src/ByteBuffer.h b/src/ByteBuffer.h
index adaa00330..c1c71d8c4 100644
--- a/src/ByteBuffer.h
+++ b/src/ByteBuffer.h
@@ -64,6 +64,7 @@ public:
bool ReadVarInt (UInt32 & a_Value);
bool ReadVarUTF8String (AString & a_Value); // string length as VarInt, then string as UTF-8
bool ReadLEInt (int & a_Value);
+ bool ReadPosition (int & a_BlockX, int & a_BlockY, int & a_BlockZ);
/** Reads VarInt, assigns it to anything that can be assigned from an UInt32 (unsigned short, char, Byte, double, ...) */
template <typename T> bool ReadVarInt(T & a_Value)
@@ -90,6 +91,7 @@ public:
bool WriteVarInt (UInt32 a_Value);
bool WriteVarUTF8String (const AString & a_Value); // string length as VarInt, then string as UTF-8
bool WriteLEInt (int a_Value);
+ bool WritePosition (int a_BlockX, int a_BlockY, int a_BlockZ);
/** Reads a_Count bytes into a_Buffer; returns true if successful */
bool ReadBuf(void * a_Buffer, size_t a_Count);
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 2d96662a9..9d0e2cede 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -75,6 +75,7 @@ SET (HDRS
BlockInfo.h
BlockTracer.h
BoundingBox.h
+ BuildInfo.h.cmake
ByteBuffer.h
ChatColor.h
Chunk.h
@@ -140,6 +141,8 @@ include_directories(".")
include_directories ("${CMAKE_CURRENT_SOURCE_DIR}/../lib/sqlite")
include_directories ("${CMAKE_CURRENT_SOURCE_DIR}/../lib/SQLiteCpp/include")
+configure_file("BuildInfo.h.cmake" "${CMAKE_CURRENT_SOURCE_DIR}/BuildInfo.h")
+
if (NOT MSVC)
# Bindings need to reference other folders, so they are done here instead
# lib dependencies are not included
diff --git a/src/Chunk.cpp b/src/Chunk.cpp
index 40ffff834..8b2655cc9 100644
--- a/src/Chunk.cpp
+++ b/src/Chunk.cpp
@@ -37,6 +37,7 @@
#include "MobSpawner.h"
#include "BlockInServerPluginInterface.h"
#include "SetChunkData.h"
+#include "BoundingBox.h"
#include "json/json.h"
@@ -65,19 +66,18 @@ sSetBlock::sSetBlock( int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_Bloc
// cChunk:
cChunk::cChunk(
- int a_ChunkX, int a_ChunkY, int a_ChunkZ,
+ int a_ChunkX, int a_ChunkZ,
cChunkMap * a_ChunkMap, cWorld * a_World,
cChunk * a_NeighborXM, cChunk * a_NeighborXP, cChunk * a_NeighborZM, cChunk * a_NeighborZP,
cAllocationPool<cChunkData::sChunkSection> & a_Pool
) :
- m_IsValid(false),
+ m_Presence(cpInvalid),
m_IsLightValid(false),
m_IsDirty(false),
m_IsSaving(false),
m_HasLoadFailed(false),
m_StayCount(0),
m_PosX(a_ChunkX),
- m_PosY(a_ChunkY),
m_PosZ(a_ChunkZ),
m_World(a_World),
m_ChunkMap(a_ChunkMap),
@@ -165,11 +165,22 @@ cChunk::~cChunk()
-void cChunk::SetValid(void)
+void cChunk::SetPresence(cChunk::ePresence a_Presence)
{
- m_IsValid = true;
-
- m_World->GetChunkMap()->ChunkValidated();
+ m_Presence = a_Presence;
+ if (a_Presence == cpPresent)
+ {
+ m_World->GetChunkMap()->ChunkValidated();
+ }
+}
+
+
+
+
+
+void cChunk::SetShouldGenerateIfLoadFailed(bool a_ShouldGenerateIfLoadFailed)
+{
+ m_ShouldGenerateIfLoadFailed = a_ShouldGenerateIfLoadFailed;
}
@@ -178,6 +189,9 @@ void cChunk::SetValid(void)
void cChunk::MarkRegenerating(void)
{
+ // Set as queued again:
+ SetPresence(cpQueued);
+
// Tell all clients attached to this chunk that they want this chunk:
for (cClientHandleList::iterator itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr)
{
@@ -191,7 +205,11 @@ void cChunk::MarkRegenerating(void)
bool cChunk::CanUnload(void)
{
- return m_LoadedByClient.empty() && !m_IsDirty && (m_StayCount == 0);
+ return
+ m_LoadedByClient.empty() && // The chunk is not used by any client
+ !m_IsDirty && // The chunk has been saved properly or hasn't been touched since the load / gen
+ (m_StayCount == 0) && // The chunk is not in a ChunkStay
+ (m_Presence != cpQueued) ; // The chunk is not queued for loading / generating (otherwise multi-load / multi-gen could occur)
}
@@ -223,7 +241,7 @@ void cChunk::MarkSaved(void)
void cChunk::MarkLoaded(void)
{
m_IsDirty = false;
- SetValid();
+ SetPresence(cpPresent);
}
@@ -232,12 +250,17 @@ void cChunk::MarkLoaded(void)
void cChunk::MarkLoadFailed(void)
{
- if (m_IsValid)
+ ASSERT(m_Presence == cpQueued);
+
+ // If the chunk is marked as needed, generate it:
+ if (m_ShouldGenerateIfLoadFailed)
{
- return;
+ m_World->GetGenerator().QueueGenerateChunk(m_PosX, m_PosZ, false);
+ }
+ else
+ {
+ m_Presence = cpInvalid;
}
-
- m_HasLoadFailed = true;
}
@@ -246,6 +269,8 @@ void cChunk::MarkLoadFailed(void)
void cChunk::GetAllData(cChunkDataCallback & a_Callback)
{
+ ASSERT(m_Presence == cpPresent);
+
a_Callback.HeightMap(&m_HeightMap);
a_Callback.BiomeData(&m_BiomeMap);
@@ -272,6 +297,7 @@ void cChunk::SetAllData(cSetChunkData & a_SetChunkData)
{
ASSERT(a_SetChunkData.IsHeightMapValid());
ASSERT(a_SetChunkData.AreBiomesValid());
+ ASSERT(IsQueued());
memcpy(m_BiomeMap, a_SetChunkData.GetBiomes(), sizeof(m_BiomeMap));
memcpy(m_HeightMap, a_SetChunkData.GetHeightMap(), sizeof(m_HeightMap));
@@ -317,7 +343,7 @@ void cChunk::SetAllData(cSetChunkData & a_SetChunkData)
CreateBlockEntities();
// Set the chunk data as valid. This may be needed for some simulators that perform actions upon block adding (Vaporize)
- SetValid();
+ SetPresence(cpPresent);
// Wake up all simulators for their respective blocks:
WakeUpSimulators();
@@ -653,7 +679,7 @@ void cChunk::MoveEntityToNewChunk(cEntity * a_Entity)
cChunk * Neighbor = GetNeighborChunk(a_Entity->GetChunkX() * cChunkDef::Width, a_Entity->GetChunkZ() * cChunkDef::Width);
if (Neighbor == NULL)
{
- Neighbor = m_ChunkMap->GetChunkNoLoad(a_Entity->GetChunkX(), ZERO_CHUNK_Y, a_Entity->GetChunkZ());
+ Neighbor = m_ChunkMap->GetChunkNoLoad(a_Entity->GetChunkX(), a_Entity->GetChunkZ());
if (Neighbor == NULL)
{
// TODO: What to do with this?
@@ -1319,11 +1345,11 @@ void cChunk::CreateBlockEntities(void)
case E_BLOCK_JUKEBOX:
case E_BLOCK_FLOWER_POT:
{
- if (!HasBlockEntityAt(x + m_PosX * Width, y + m_PosY * Height, z + m_PosZ * Width))
+ if (!HasBlockEntityAt(x + m_PosX * Width, y, z + m_PosZ * Width))
{
m_BlockEntities.push_back(cBlockEntity::CreateByBlockType(
BlockType, GetMeta(x, y, z),
- x + m_PosX * Width, y + m_PosY * Height, z + m_PosZ * Width, m_World
+ x + m_PosX * Width, y, z + m_PosZ * Width, m_World
));
}
break;
@@ -1960,6 +1986,30 @@ bool cChunk::ForEachEntity(cEntityCallback & a_Callback)
+bool cChunk::ForEachEntityInBox(const cBoundingBox & a_Box, cEntityCallback & a_Callback)
+{
+ // The entity list is locked by the parent chunkmap's CS
+ for (cEntityList::iterator itr = m_Entities.begin(), itr2 = itr; itr != m_Entities.end(); itr = itr2)
+ {
+ ++itr2;
+ cBoundingBox EntBox((*itr)->GetPosition(), (*itr)->GetWidth() / 2, (*itr)->GetHeight());
+ if (!EntBox.DoesIntersect(a_Box))
+ {
+ // The entity is not in the specified box
+ continue;
+ }
+ if (a_Callback.Item(*itr))
+ {
+ return false;
+ }
+ } // for itr - m_Entitites[]
+ return true;
+}
+
+
+
+
+
bool cChunk::DoWithEntityByID(int a_EntityID, cEntityCallback & a_Callback, bool & a_CallbackResult)
{
// The entity list is locked by the parent chunkmap's CS
@@ -2165,7 +2215,7 @@ bool cChunk::DoWithRedstonePoweredEntityAt(int a_BlockX, int a_BlockY, int a_Blo
}
}
- if (a_Callback.Item((cRedstonePoweredEntity *)*itr))
+ if (a_Callback.Item(dynamic_cast<cRedstonePoweredEntity *>(*itr))) // Needs dynamic_cast due to multiple inheritance
{
return false;
}
@@ -2603,7 +2653,7 @@ cChunk * cChunk::GetRelNeighborChunk(int a_RelX, int a_RelZ)
int BlockZ = m_PosZ * cChunkDef::Width + a_RelZ;
int ChunkX, ChunkZ;
BlockToChunk(BlockX, BlockZ, ChunkX, ChunkZ);
- return m_ChunkMap->GetChunkNoLoad(ChunkX, ZERO_CHUNK_Y, ChunkZ);
+ return m_ChunkMap->GetChunkNoLoad(ChunkX, ChunkZ);
}
// Walk the neighbors:
@@ -2993,7 +3043,7 @@ void cChunk::BroadcastEntityAnimation(const cEntity & a_Entity, char a_Animation
-void cChunk::BroadcastParticleEffect(const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmmount, cClientHandle * a_Exclude)
+void cChunk::BroadcastParticleEffect(const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmount, cClientHandle * a_Exclude)
{
for (cClientHandleList::iterator itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr)
{
@@ -3001,7 +3051,7 @@ void cChunk::BroadcastParticleEffect(const AString & a_ParticleName, float a_Src
{
continue;
}
- (*itr)->SendParticleEffect(a_ParticleName, a_SrcX, a_SrcY, a_SrcZ, a_OffsetX, a_OffsetY, a_OffsetZ, a_ParticleData, a_ParticleAmmount);
+ (*itr)->SendParticleEffect(a_ParticleName, a_SrcX, a_SrcY, a_SrcZ, a_OffsetX, a_OffsetY, a_OffsetZ, a_ParticleData, a_ParticleAmount);
} // for itr - LoadedByClient[]
}
@@ -3128,7 +3178,7 @@ void cChunk::PositionToWorldPosition(int a_RelX, int a_RelY, int a_RelZ, int & a
Vector3i cChunk::PositionToWorldPosition(int a_RelX, int a_RelY, int a_RelZ)
{
- return Vector3i(m_PosX * Width + a_RelX, m_PosY * Height + a_RelY, m_PosZ * Width + a_RelZ);
+ return Vector3i(m_PosX * Width + a_RelX, a_RelY, m_PosZ * Width + a_RelZ);
}
diff --git a/src/Chunk.h b/src/Chunk.h
index e5de22e3b..e88e72bdc 100644
--- a/src/Chunk.h
+++ b/src/Chunk.h
@@ -66,8 +66,16 @@ class cChunk :
public cChunkDef // The inheritance is "misused" here only to inherit the functions and constants defined in cChunkDef
{
public:
+ /** Represents the presence state of the chunk */
+ enum ePresence
+ {
+ cpInvalid, /**< The chunk is not present at all and is not queued in the loader / generator */
+ cpQueued, /**< The chunk is not present, but is queued for loading / generation */
+ cpPresent, /**< The chunk is present */
+ };
+
cChunk(
- int a_ChunkX, int a_ChunkY, int a_ChunkZ, // Chunk coords
+ int a_ChunkX, int a_ChunkZ, // Chunk coords
cChunkMap * a_ChunkMap, cWorld * a_World, // Parent objects
cChunk * a_NeighborXM, cChunk * a_NeighborXP, cChunk * a_NeighborZM, cChunk * a_NeighborZP, // Neighbor chunks
cAllocationPool<cChunkData::sChunkSection> & a_Pool
@@ -75,11 +83,25 @@ public:
cChunk(cChunk & other);
~cChunk();
- bool IsValid(void) const {return m_IsValid; } // Returns true if the chunk block data is valid (loaded / generated)
- void SetValid(void); // Also wakes up any calls to cChunkMap::GetHeight()
- void MarkRegenerating(void); // Marks all clients attached to this chunk as wanting this chunk
- bool IsDirty(void) const {return m_IsDirty; } // Returns true if the chunk has changed since it was last saved
- bool HasLoadFailed(void) const {return m_HasLoadFailed; } // Returns true if the chunk failed to load and hasn't been generated since then
+ /** Returns true iff the chunk block data is valid (loaded / generated) */
+ bool IsValid(void) const {return (m_Presence == cpPresent); }
+
+ /** Returns true iff the chunk is in the queue for loading / generating */
+ bool IsQueued(void) const {return (m_Presence == cpQueued); }
+
+ /** Sets the chunk's presence.
+ Wakes up any calls to cChunkMap::GetHeight() when setting to cpPresent. */
+ void SetPresence(ePresence a_Presence);
+
+ /** Called to indicate whether the chunk should be queued in the generator if it fails to load. Set by cChunkMap::GetChunk(). */
+ void SetShouldGenerateIfLoadFailed(bool a_ShouldGenerateIfLoadFailed);
+
+ /** Marks all clients attached to this chunk as wanting this chunk. Also sets presence to cpQueued. */
+ void MarkRegenerating(void);
+
+ /** Returns true iff the chunk has changed since it was last saved. */
+ bool IsDirty(void) const {return m_IsDirty; }
+
bool CanUnload(void);
bool IsLightValid(void) const {return m_IsLightValid; }
@@ -94,7 +116,10 @@ public:
void MarkSaving(void); // Marks the chunk as being saved.
void MarkSaved(void); // Marks the chunk as saved, if it didn't change from the last call to MarkSaving()
void MarkLoaded(void); // Marks the chunk as freshly loaded. Fails if the chunk is already valid
- void MarkLoadFailed(void); // Marks the chunk as failed to load. Ignored is the chunk is already valid
+
+ /** Marks the chunk as failed to load.
+ If m_ShouldGenerateIfLoadFailed is set, queues the chunk for generating. */
+ void MarkLoadFailed(void);
/** Gets all chunk data, calls the a_Callback's methods for each data type */
void GetAllData(cChunkDataCallback & a_Callback);
@@ -135,7 +160,6 @@ public:
void TickBlock(int a_RelX, int a_RelY, int a_RelZ);
int GetPosX(void) const { return m_PosX; }
- int GetPosY(void) const { return m_PosY; }
int GetPosZ(void) const { return m_PosZ; }
cWorld * GetWorld(void) const { return m_World; }
@@ -216,6 +240,10 @@ public:
/** Calls the callback for each entity; returns true if all entities processed, false if the callback aborted by returning true */
bool ForEachEntity(cEntityCallback & a_Callback); // Lua-accessible
+ /** Calls the callback for each entity that has a nonempty intersection with the specified boundingbox.
+ Returns true if all entities processed, false if the callback aborted by returning true. */
+ bool ForEachEntityInBox(const cBoundingBox & a_Box, cEntityCallback & a_Callback); // Lua-accessible
+
/** Calls the callback if the entity with the specified ID is found, with the entity object as the callback param. Returns true if entity found. */
bool DoWithEntityByID(int a_EntityID, cEntityCallback & a_Callback, bool & a_CallbackResult); // Lua-accessible
@@ -298,7 +326,7 @@ public:
void BroadcastEntityStatus (const cEntity & a_Entity, char a_Status, const cClientHandle * a_Exclude = NULL);
void BroadcastEntityVelocity (const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL);
void BroadcastEntityAnimation (const cEntity & a_Entity, char a_Animation, const cClientHandle * a_Exclude = NULL);
- void BroadcastParticleEffect (const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmmount, cClientHandle * a_Exclude = NULL);
+ void BroadcastParticleEffect (const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmount, cClientHandle * a_Exclude = NULL);
void BroadcastRemoveEntityEffect (const cEntity & a_Entity, int a_EffectID, const cClientHandle * a_Exclude = NULL);
void BroadcastSoundEffect (const AString & a_SoundName, double a_X, double a_Y, double a_Z, float a_Volume, float a_Pitch, const cClientHandle * a_Exclude = NULL);
void BroadcastSoundParticleEffect(int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data, const cClientHandle * a_Exclude = NULL);
@@ -430,7 +458,12 @@ private:
typedef std::vector<sSetBlockQueueItem> sSetBlockQueueVector;
- bool m_IsValid; // True if the chunk is loaded / generated
+ /** Holds the presence status of the chunk - if it is present, or in the loader / generator queue, or unloaded */
+ ePresence m_Presence;
+
+ /** If the chunk fails to load, should it be queued in the generator or reset back to invalid? */
+ bool m_ShouldGenerateIfLoadFailed;
+
bool m_IsLightValid; // True if the blocklight and skylight are calculated
bool m_IsDirty; // True if the chunk has changed since it was last saved
bool m_IsSaving; // True if the chunk is being saved
@@ -449,7 +482,7 @@ private:
/** Number of times the chunk has been requested to stay (by various cChunkStay objects); if zero, the chunk can be unloaded */
int m_StayCount;
- int m_PosX, m_PosY, m_PosZ;
+ int m_PosX, m_PosZ;
cWorld * m_World;
cChunkMap * m_ChunkMap;
diff --git a/src/ChunkDef.h b/src/ChunkDef.h
index b8b4291c7..f4ed66c4b 100644
--- a/src/ChunkDef.h
+++ b/src/ChunkDef.h
@@ -16,11 +16,6 @@
-/** This is really only a placeholder to be used in places where we need to "make up" a chunk's Y coord.
-It will help us when the new chunk format comes out and we need to patch everything up for compatibility.
-*/
-#define ZERO_CHUNK_Y 0
-
// Used to smoothly convert to new axis ordering. One will be removed when deemed stable.
#define AXIS_ORDER_YZX 1 // Original (1.1-)
#define AXIS_ORDER_XZY 2 // New (1.2+)
@@ -377,14 +372,13 @@ class cChunkCoords
{
public:
int m_ChunkX;
- int m_ChunkY;
int m_ChunkZ;
- cChunkCoords(int a_ChunkX, int a_ChunkY, int a_ChunkZ) : m_ChunkX(a_ChunkX), m_ChunkY(a_ChunkY), m_ChunkZ(a_ChunkZ) {}
+ cChunkCoords(int a_ChunkX, int a_ChunkZ) : m_ChunkX(a_ChunkX), m_ChunkZ(a_ChunkZ) {}
bool operator == (const cChunkCoords & a_Other) const
{
- return ((m_ChunkX == a_Other.m_ChunkX) && (m_ChunkY == a_Other.m_ChunkY) && (m_ChunkZ == a_Other.m_ChunkZ));
+ return ((m_ChunkX == a_Other.m_ChunkX) && (m_ChunkZ == a_Other.m_ChunkZ));
}
} ;
@@ -395,6 +389,27 @@ typedef std::vector<cChunkCoords> cChunkCoordsVector;
+class cChunkCoordsWithBool
+{
+public:
+ int m_ChunkX;
+ int m_ChunkZ;
+ bool m_ForceGenerate;
+
+ cChunkCoordsWithBool(int a_ChunkX, int a_ChunkZ, bool a_ForceGenerate) : m_ChunkX(a_ChunkX), m_ChunkZ(a_ChunkZ), m_ForceGenerate(a_ForceGenerate){}
+
+ bool operator == (const cChunkCoordsWithBool & a_Other) const
+ {
+ return ((m_ChunkX == a_Other.m_ChunkX) && (m_ChunkZ == a_Other.m_ChunkZ) && (m_ForceGenerate == a_Other.m_ForceGenerate));
+ }
+};
+
+typedef std::list<cChunkCoordsWithBool> cChunkCoordsWithBoolList;
+
+
+
+
+
/// Interface class used as a callback for operations that involve chunk coords
class cChunkCoordCallback
{
diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp
index a3692ef11..828d8f164 100644
--- a/src/ChunkMap.cpp
+++ b/src/ChunkMap.cpp
@@ -143,26 +143,27 @@ cChunkMap::cChunkLayer * cChunkMap::GetLayerForChunk(int a_ChunkX, int a_ChunkZ)
-cChunkPtr cChunkMap::GetChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ)
+cChunkPtr cChunkMap::GetChunk(int a_ChunkX, int a_ChunkZ)
{
- // No need to lock m_CSLayers, since it's already locked by the operation that called us
- ASSERT(m_CSLayers.IsLockedByCurrentThread());
+ ASSERT(m_CSLayers.IsLockedByCurrentThread()); // m_CSLayers should already be locked by the operation that called us
- cChunkLayer * Layer = GetLayerForChunk( a_ChunkX, a_ChunkZ);
+ cChunkLayer * Layer = GetLayerForChunk(a_ChunkX, a_ChunkZ);
if (Layer == NULL)
{
// An error must have occurred, since layers are automatically created if they don't exist
return NULL;
}
- cChunkPtr Chunk = Layer->GetChunk(a_ChunkX, a_ChunkY, a_ChunkZ);
+ cChunkPtr Chunk = Layer->GetChunk(a_ChunkX, a_ChunkZ);
if (Chunk == NULL)
{
return NULL;
}
- if (!(Chunk->IsValid()))
+ if (!Chunk->IsValid() && !Chunk->IsQueued())
{
- m_World->GetStorage().QueueLoadChunk(a_ChunkX, a_ChunkY, a_ChunkZ, true);
+ Chunk->SetPresence(cChunk::cpQueued);
+ Chunk->SetShouldGenerateIfLoadFailed(true);
+ m_World->GetStorage().QueueLoadChunk(a_ChunkX, a_ChunkZ);
}
return Chunk;
}
@@ -171,24 +172,26 @@ cChunkPtr cChunkMap::GetChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ)
-cChunkPtr cChunkMap::GetChunkNoGen( int a_ChunkX, int a_ChunkY, int a_ChunkZ)
+cChunkPtr cChunkMap::GetChunkNoGen(int a_ChunkX, int a_ChunkZ)
{
- // No need to lock m_CSLayers, since it's already locked by the operation that called us
- cChunkLayer * Layer = GetLayerForChunk( a_ChunkX, a_ChunkZ);
+ ASSERT(m_CSLayers.IsLockedByCurrentThread()); // m_CSLayers should already be locked by the operation that called us
+
+ cChunkLayer * Layer = GetLayerForChunk(a_ChunkX, a_ChunkZ);
if (Layer == NULL)
{
// An error must have occurred, since layers are automatically created if they don't exist
return NULL;
}
- cChunkPtr Chunk = Layer->GetChunk(a_ChunkX, a_ChunkY, a_ChunkZ);
+ cChunkPtr Chunk = Layer->GetChunk(a_ChunkX, a_ChunkZ);
if (Chunk == NULL)
{
return NULL;
}
- if (!(Chunk->IsValid()))
+ if (!Chunk->IsValid() && !Chunk->IsQueued())
{
- m_World->GetStorage().QueueLoadChunk(a_ChunkX, a_ChunkY, a_ChunkZ, false);
+ Chunk->SetPresence(cChunk::cpQueued);
+ m_World->GetStorage().QueueLoadChunk(a_ChunkX, a_ChunkZ);
}
return Chunk;
@@ -198,9 +201,10 @@ cChunkPtr cChunkMap::GetChunkNoGen( int a_ChunkX, int a_ChunkY, int a_ChunkZ)
-cChunkPtr cChunkMap::GetChunkNoLoad( int a_ChunkX, int a_ChunkY, int a_ChunkZ)
+cChunkPtr cChunkMap::GetChunkNoLoad( int a_ChunkX, int a_ChunkZ)
{
- // No need to lock m_CSLayers, since it's already locked by the operation that called us
+ ASSERT(m_CSLayers.IsLockedByCurrentThread()); // m_CSLayers should already be locked by the operation that called us
+
cChunkLayer * Layer = GetLayerForChunk( a_ChunkX, a_ChunkZ);
if (Layer == NULL)
{
@@ -208,7 +212,7 @@ cChunkPtr cChunkMap::GetChunkNoLoad( int a_ChunkX, int a_ChunkY, int a_ChunkZ)
return NULL;
}
- return Layer->GetChunk(a_ChunkX, a_ChunkY, a_ChunkZ);
+ return Layer->GetChunk(a_ChunkX, a_ChunkZ);
}
@@ -222,7 +226,7 @@ bool cChunkMap::LockedGetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTY
int ChunkX, ChunkZ;
cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ);
- cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ZERO_CHUNK_Y, ChunkZ);
+ cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ChunkZ);
if (Chunk == NULL)
{
return false;
@@ -244,7 +248,7 @@ bool cChunkMap::LockedGetBlockType(int a_BlockX, int a_BlockY, int a_BlockZ, BLO
int ChunkX, ChunkZ;
cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ);
- cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ZERO_CHUNK_Y, ChunkZ);
+ cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ChunkZ);
if (Chunk == NULL)
{
return false;
@@ -265,7 +269,7 @@ bool cChunkMap::LockedGetBlockMeta(int a_BlockX, int a_BlockY, int a_BlockZ, NIB
int ChunkX, ChunkZ;
cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ);
- cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ZERO_CHUNK_Y, ChunkZ);
+ cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ChunkZ);
if (Chunk == NULL)
{
return false;
@@ -284,7 +288,7 @@ bool cChunkMap::LockedSetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTY
// We already have m_CSLayers locked since this can be called only from within the tick thread
int ChunkX, ChunkZ;
cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ);
- cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ZERO_CHUNK_Y, ChunkZ);
+ cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ChunkZ);
if (Chunk == NULL)
{
return false;
@@ -303,7 +307,7 @@ bool cChunkMap::LockedFastSetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLO
// We already have m_CSLayers locked since this can be called only from within the tick thread
int ChunkX, ChunkZ;
cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ);
- cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ZERO_CHUNK_Y, ChunkZ);
+ cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ChunkZ);
if (Chunk == NULL)
{
return false;
@@ -336,7 +340,7 @@ cChunk * cChunkMap::FindChunk(int a_ChunkX, int a_ChunkZ)
void cChunkMap::BroadcastAttachEntity(const cEntity & a_Entity, const cEntity * a_Vehicle)
{
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), ZERO_CHUNK_Y, a_Entity.GetChunkZ());
+ cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), a_Entity.GetChunkZ());
if (Chunk == NULL)
{
return;
@@ -356,7 +360,7 @@ void cChunkMap::BroadcastBlockAction(int a_BlockX, int a_BlockY, int a_BlockZ, c
x = a_BlockX;
z = a_BlockZ;
cChunkDef::BlockToChunk(x, z, ChunkX, ChunkZ);
- cChunkPtr Chunk = GetChunkNoGen(ChunkX, ZERO_CHUNK_Y, ChunkZ);
+ cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ);
if (Chunk == NULL)
{
return;
@@ -375,7 +379,7 @@ void cChunkMap::BroadcastBlockBreakAnimation(int a_entityID, int a_blockX, int a
int ChunkX, ChunkZ;
cChunkDef::BlockToChunk(a_blockX, a_blockZ, ChunkX, ChunkZ);
- cChunkPtr Chunk = GetChunkNoGen(ChunkX, 0, ChunkZ);
+ cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ);
if (Chunk == NULL)
{
return;
@@ -393,7 +397,7 @@ void cChunkMap::BroadcastBlockEntity(int a_BlockX, int a_BlockY, int a_BlockZ, c
cCSLock Lock(m_CSLayers);
int ChunkX, ChunkZ;
cChunkDef::BlockToChunk(a_BlockX, a_BlockZ, ChunkX, ChunkZ);
- cChunkPtr Chunk = GetChunkNoGen(ChunkX, 0, ChunkZ);
+ cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid())
{
return;
@@ -408,7 +412,7 @@ void cChunkMap::BroadcastBlockEntity(int a_BlockX, int a_BlockY, int a_BlockZ, c
void cChunkMap::BroadcastChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer, const cClientHandle * a_Exclude)
{
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, 0, a_ChunkZ);
+ cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ);
if (Chunk == NULL)
{
return;
@@ -424,7 +428,7 @@ void cChunkMap::BroadcastChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataSeriali
void cChunkMap::BroadcastCollectEntity(const cEntity & a_Entity, const cPlayer & a_Player, const cClientHandle * a_Exclude)
{
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), ZERO_CHUNK_Y, a_Entity.GetChunkZ());
+ cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), a_Entity.GetChunkZ());
if (Chunk == NULL)
{
return;
@@ -440,7 +444,7 @@ void cChunkMap::BroadcastCollectEntity(const cEntity & a_Entity, const cPlayer &
void cChunkMap::BroadcastDestroyEntity(const cEntity & a_Entity, const cClientHandle * a_Exclude)
{
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), ZERO_CHUNK_Y, a_Entity.GetChunkZ());
+ cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), a_Entity.GetChunkZ());
if (Chunk == NULL)
{
return;
@@ -456,7 +460,7 @@ void cChunkMap::BroadcastDestroyEntity(const cEntity & a_Entity, const cClientHa
void cChunkMap::BroadcastEntityEffect(const cEntity & a_Entity, int a_EffectID, int a_Amplifier, short a_Duration, const cClientHandle * a_Exclude)
{
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), ZERO_CHUNK_Y, a_Entity.GetChunkZ());
+ cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), a_Entity.GetChunkZ());
if (Chunk == NULL)
{
return;
@@ -472,7 +476,7 @@ void cChunkMap::BroadcastEntityEffect(const cEntity & a_Entity, int a_EffectID,
void cChunkMap::BroadcastEntityEquipment(const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item, const cClientHandle * a_Exclude)
{
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), ZERO_CHUNK_Y, a_Entity.GetChunkZ());
+ cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), a_Entity.GetChunkZ());
if (Chunk == NULL)
{
return;
@@ -488,7 +492,7 @@ void cChunkMap::BroadcastEntityEquipment(const cEntity & a_Entity, short a_SlotN
void cChunkMap::BroadcastEntityHeadLook(const cEntity & a_Entity, const cClientHandle * a_Exclude)
{
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), ZERO_CHUNK_Y, a_Entity.GetChunkZ());
+ cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), a_Entity.GetChunkZ());
if (Chunk == NULL)
{
return;
@@ -504,7 +508,7 @@ void cChunkMap::BroadcastEntityHeadLook(const cEntity & a_Entity, const cClientH
void cChunkMap::BroadcastEntityLook(const cEntity & a_Entity, const cClientHandle * a_Exclude)
{
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), ZERO_CHUNK_Y, a_Entity.GetChunkZ());
+ cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), a_Entity.GetChunkZ());
if (Chunk == NULL)
{
return;
@@ -520,7 +524,7 @@ void cChunkMap::BroadcastEntityLook(const cEntity & a_Entity, const cClientHandl
void cChunkMap::BroadcastEntityMetadata(const cEntity & a_Entity, const cClientHandle * a_Exclude)
{
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), ZERO_CHUNK_Y, a_Entity.GetChunkZ());
+ cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), a_Entity.GetChunkZ());
if (Chunk == NULL)
{
return;
@@ -536,7 +540,7 @@ void cChunkMap::BroadcastEntityMetadata(const cEntity & a_Entity, const cClientH
void cChunkMap::BroadcastEntityRelMove(const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ, const cClientHandle * a_Exclude)
{
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), ZERO_CHUNK_Y, a_Entity.GetChunkZ());
+ cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), a_Entity.GetChunkZ());
if (Chunk == NULL)
{
return;
@@ -552,7 +556,7 @@ void cChunkMap::BroadcastEntityRelMove(const cEntity & a_Entity, char a_RelX, ch
void cChunkMap::BroadcastEntityRelMoveLook(const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ, const cClientHandle * a_Exclude)
{
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), ZERO_CHUNK_Y, a_Entity.GetChunkZ());
+ cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), a_Entity.GetChunkZ());
if (Chunk == NULL)
{
return;
@@ -568,7 +572,7 @@ void cChunkMap::BroadcastEntityRelMoveLook(const cEntity & a_Entity, char a_RelX
void cChunkMap::BroadcastEntityStatus(const cEntity & a_Entity, char a_Status, const cClientHandle * a_Exclude)
{
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), ZERO_CHUNK_Y, a_Entity.GetChunkZ());
+ cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), a_Entity.GetChunkZ());
if (Chunk == NULL)
{
return;
@@ -584,7 +588,7 @@ void cChunkMap::BroadcastEntityStatus(const cEntity & a_Entity, char a_Status, c
void cChunkMap::BroadcastEntityVelocity(const cEntity & a_Entity, const cClientHandle * a_Exclude)
{
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), ZERO_CHUNK_Y, a_Entity.GetChunkZ());
+ cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), a_Entity.GetChunkZ());
if (Chunk == NULL)
{
return;
@@ -600,7 +604,7 @@ void cChunkMap::BroadcastEntityVelocity(const cEntity & a_Entity, const cClientH
void cChunkMap::BroadcastEntityAnimation(const cEntity & a_Entity, char a_Animation, const cClientHandle * a_Exclude)
{
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), ZERO_CHUNK_Y, a_Entity.GetChunkZ());
+ cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), a_Entity.GetChunkZ());
if (Chunk == NULL)
{
return;
@@ -613,19 +617,19 @@ void cChunkMap::BroadcastEntityAnimation(const cEntity & a_Entity, char a_Animat
-void cChunkMap::BroadcastParticleEffect(const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmmount, cClientHandle * a_Exclude)
+void cChunkMap::BroadcastParticleEffect(const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmount, cClientHandle * a_Exclude)
{
cCSLock Lock(m_CSLayers);
int ChunkX, ChunkZ;
cChunkDef::BlockToChunk((int) a_SrcX, (int) a_SrcZ, ChunkX, ChunkZ);
- cChunkPtr Chunk = GetChunkNoGen(ChunkX, 0, ChunkZ);
+ cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ);
if (Chunk == NULL)
{
return;
}
// It's perfectly legal to broadcast packets even to invalid chunks!
- Chunk->BroadcastParticleEffect(a_ParticleName, a_SrcX, a_SrcY, a_SrcZ, a_OffsetX, a_OffsetY, a_OffsetZ, a_ParticleData, a_ParticleAmmount, a_Exclude);
+ Chunk->BroadcastParticleEffect(a_ParticleName, a_SrcX, a_SrcY, a_SrcZ, a_OffsetX, a_OffsetY, a_OffsetZ, a_ParticleData, a_ParticleAmount, a_Exclude);
}
@@ -636,7 +640,7 @@ void cChunkMap::BroadcastRemoveEntityEffect(const cEntity & a_Entity, int a_Effe
{
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), ZERO_CHUNK_Y, a_Entity.GetChunkZ());
+ cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), a_Entity.GetChunkZ());
if (Chunk == NULL)
{
return;
@@ -655,7 +659,7 @@ void cChunkMap::BroadcastSoundEffect(const AString & a_SoundName, double a_X, do
int ChunkX, ChunkZ;
cChunkDef::BlockToChunk((int)std::floor(a_X), (int)std::floor(a_Z), ChunkX, ChunkZ);
- cChunkPtr Chunk = GetChunkNoGen(ChunkX, 0, ChunkZ);
+ cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ);
if (Chunk == NULL)
{
return;
@@ -674,7 +678,7 @@ void cChunkMap::BroadcastSoundParticleEffect(int a_EffectID, int a_SrcX, int a_S
int ChunkX, ChunkZ;
cChunkDef::BlockToChunk(a_SrcX, a_SrcZ, ChunkX, ChunkZ);
- cChunkPtr Chunk = GetChunkNoGen(ChunkX, 0, ChunkZ);
+ cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ);
if (Chunk == NULL)
{
return;
@@ -690,7 +694,7 @@ void cChunkMap::BroadcastSoundParticleEffect(int a_EffectID, int a_SrcX, int a_S
void cChunkMap::BroadcastSpawnEntity(cEntity & a_Entity, const cClientHandle * a_Exclude)
{
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), ZERO_CHUNK_Y, a_Entity.GetChunkZ());
+ cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), a_Entity.GetChunkZ());
if (Chunk == NULL)
{
return;
@@ -708,7 +712,7 @@ void cChunkMap::BroadcastThunderbolt(int a_BlockX, int a_BlockY, int a_BlockZ, c
cCSLock Lock(m_CSLayers);
int ChunkX, ChunkZ;
cChunkDef::BlockToChunk(a_BlockX, a_BlockZ, ChunkX, ChunkZ);
- cChunkPtr Chunk = GetChunkNoGen(ChunkX, 0, ChunkZ);
+ cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ);
if (Chunk == NULL)
{
return;
@@ -727,7 +731,7 @@ void cChunkMap::BroadcastUseBed(const cEntity & a_Entity, int a_BlockX, int a_Bl
int ChunkX, ChunkZ;
cChunkDef::BlockToChunk(a_BlockX, a_BlockZ, ChunkX, ChunkZ);
- cChunkPtr Chunk = GetChunkNoGen(ChunkX, 0, ChunkZ);
+ cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ);
if (Chunk == NULL)
{
return;
@@ -745,7 +749,7 @@ void cChunkMap::SendBlockEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cClien
cCSLock Lock(m_CSLayers);
int ChunkX, ChunkZ;
cChunkDef::BlockToChunk(a_BlockX, a_BlockZ, ChunkX, ChunkZ);
- cChunkPtr Chunk = GetChunkNoGen(ChunkX, 0, ChunkZ);
+ cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid())
{
return;
@@ -763,7 +767,7 @@ void cChunkMap::UseBlockEntity(cPlayer * a_Player, int a_BlockX, int a_BlockY, i
cCSLock Lock(m_CSLayers);
int ChunkX, ChunkZ;
cChunkDef::BlockToChunk(a_BlockX, a_BlockZ, ChunkX, ChunkZ);
- cChunkPtr Chunk = GetChunkNoGen(ChunkX, 0, ChunkZ);
+ cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid())
{
return;
@@ -778,7 +782,7 @@ void cChunkMap::UseBlockEntity(cPlayer * a_Player, int a_BlockX, int a_BlockY, i
bool cChunkMap::DoWithChunk(int a_ChunkX, int a_ChunkZ, cChunkCallback & a_Callback)
{
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunkNoLoad(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ);
+ cChunkPtr Chunk = GetChunkNoLoad(a_ChunkX, a_ChunkZ);
if (Chunk == NULL)
{
return false;
@@ -795,7 +799,7 @@ void cChunkMap::WakeUpSimulators(int a_BlockX, int a_BlockY, int a_BlockZ)
cCSLock Lock(m_CSLayers);
int ChunkX, ChunkZ;
cChunkDef::BlockToChunk(a_BlockX, a_BlockZ, ChunkX, ChunkZ);
- cChunkPtr Chunk = GetChunkNoGen(ChunkX, 0, ChunkZ);
+ cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid())
{
return;
@@ -824,7 +828,7 @@ void cChunkMap::WakeUpSimulatorsInArea(int a_MinBlockX, int a_MaxBlockX, int a_M
int MaxZ = std::min(a_MaxBlockZ, z * cChunkDef::Width + cChunkDef::Width - 1);
for (int x = MinChunkX; x <= MaxChunkX; x++)
{
- cChunkPtr Chunk = GetChunkNoGen(x, 0, z);
+ cChunkPtr Chunk = GetChunkNoGen(x, z);
if ((Chunk == NULL) || !Chunk->IsValid())
{
continue;
@@ -852,7 +856,7 @@ void cChunkMap::WakeUpSimulatorsInArea(int a_MinBlockX, int a_MaxBlockX, int a_M
void cChunkMap::MarkRedstoneDirty(int a_ChunkX, int a_ChunkZ)
{
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ);
+ cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid())
{
return;
@@ -867,7 +871,7 @@ void cChunkMap::MarkRedstoneDirty(int a_ChunkX, int a_ChunkZ)
void cChunkMap::MarkChunkDirty(int a_ChunkX, int a_ChunkZ, bool a_MarkRedstoneDirty)
{
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ);
+ cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid())
{
return;
@@ -886,7 +890,7 @@ void cChunkMap::MarkChunkDirty(int a_ChunkX, int a_ChunkZ, bool a_MarkRedstoneDi
void cChunkMap::MarkChunkSaving(int a_ChunkX, int a_ChunkZ)
{
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ);
+ cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid())
{
return;
@@ -901,7 +905,7 @@ void cChunkMap::MarkChunkSaving(int a_ChunkX, int a_ChunkZ)
void cChunkMap::MarkChunkSaved (int a_ChunkX, int a_ChunkZ)
{
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ);
+ cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid())
{
return;
@@ -919,7 +923,7 @@ void cChunkMap::SetChunkData(cSetChunkData & a_SetChunkData)
int ChunkZ = a_SetChunkData.GetChunkZ();
{
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ZERO_CHUNK_Y, ChunkZ);
+ cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ChunkZ);
if (Chunk == NULL)
{
return;
@@ -964,7 +968,7 @@ void cChunkMap::ChunkLighted(
)
{
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunkNoLoad(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ);
+ cChunkPtr Chunk = GetChunkNoLoad(a_ChunkX, a_ChunkZ);
if (Chunk == NULL)
{
return;
@@ -980,7 +984,7 @@ void cChunkMap::ChunkLighted(
bool cChunkMap::GetChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataCallback & a_Callback)
{
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ);
+ cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid())
{
return false;
@@ -996,7 +1000,7 @@ bool cChunkMap::GetChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataCallback & a_
bool cChunkMap::GetChunkBlockTypes(int a_ChunkX, int a_ChunkZ, BLOCKTYPE * a_BlockTypes)
{
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ);
+ cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid())
{
return false;
@@ -1009,10 +1013,21 @@ bool cChunkMap::GetChunkBlockTypes(int a_ChunkX, int a_ChunkZ, BLOCKTYPE * a_Blo
+bool cChunkMap::IsChunkQueued(int a_ChunkX, int a_ChunkZ)
+{
+ cCSLock Lock(m_CSLayers);
+ cChunkPtr Chunk = GetChunkNoLoad(a_ChunkX, a_ChunkZ);
+ return (Chunk != NULL) && Chunk->IsQueued();
+}
+
+
+
+
+
bool cChunkMap::IsChunkValid(int a_ChunkX, int a_ChunkZ)
{
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunkNoLoad(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ);
+ cChunkPtr Chunk = GetChunkNoLoad(a_ChunkX, a_ChunkZ);
return (Chunk != NULL) && Chunk->IsValid();
}
@@ -1023,7 +1038,7 @@ bool cChunkMap::IsChunkValid(int a_ChunkX, int a_ChunkZ)
bool cChunkMap::HasChunkAnyClients(int a_ChunkX, int a_ChunkZ)
{
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ);
+ cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ);
return (Chunk != NULL) && Chunk->HasAnyClients();
}
@@ -1038,7 +1053,7 @@ int cChunkMap::GetHeight(int a_BlockX, int a_BlockZ)
cCSLock Lock(m_CSLayers);
int ChunkX, ChunkZ, BlockY = 0;
cChunkDef::AbsoluteToRelative(a_BlockX, BlockY, a_BlockZ, ChunkX, ChunkZ);
- cChunkPtr Chunk = GetChunk(ChunkX, ZERO_CHUNK_Y, ChunkZ);
+ cChunkPtr Chunk = GetChunk(ChunkX, ChunkZ);
if (Chunk == NULL)
{
return 0;
@@ -1065,7 +1080,7 @@ bool cChunkMap::TryGetHeight(int a_BlockX, int a_BlockZ, int & a_Height)
cCSLock Lock(m_CSLayers);
int ChunkX, ChunkZ, BlockY = 0;
cChunkDef::AbsoluteToRelative(a_BlockX, BlockY, a_BlockZ, ChunkX, ChunkZ);
- cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ZERO_CHUNK_Y, ChunkZ);
+ cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid())
{
return false;
@@ -1088,7 +1103,7 @@ void cChunkMap::FastSetBlocks(sSetBlockList & a_BlockList)
int ChunkX = a_BlockList.front().ChunkX;
int ChunkZ = a_BlockList.front().ChunkZ;
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunkNoGen(ChunkX, ZERO_CHUNK_Y, ChunkZ);
+ cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ);
if ((Chunk != NULL) && Chunk->IsValid())
{
for (sSetBlockList::iterator itr = a_BlockList.begin(); itr != a_BlockList.end();)
@@ -1135,7 +1150,7 @@ void cChunkMap::CollectPickupsByPlayer(cPlayer * a_Player)
int BlockX = (int)(a_Player->GetPosX()); // Truncating doesn't matter much; we're scanning entire chunks anyway
int BlockY = (int)(a_Player->GetPosY());
int BlockZ = (int)(a_Player->GetPosZ());
- int ChunkX, ChunkZ, ChunkY = ZERO_CHUNK_Y;
+ int ChunkX = 0, ChunkZ = 0;
cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ);
int OtherChunkX = ChunkX + ((BlockX > 8) ? 1 : -1);
int OtherChunkZ = ChunkZ + ((BlockZ > 8) ? 1 : -1);
@@ -1144,13 +1159,13 @@ void cChunkMap::CollectPickupsByPlayer(cPlayer * a_Player)
// The only time the chunks are not valid is when the player is downloading the initial world and they should not call this at that moment
cCSLock Lock(m_CSLayers);
- GetChunkNoLoad(ChunkX, ChunkY, ChunkZ)->CollectPickupsByPlayer(a_Player);
+ GetChunkNoLoad(ChunkX, ChunkZ)->CollectPickupsByPlayer(a_Player);
// Check the neighboring chunks as well:
- GetChunkNoLoad(OtherChunkX, ChunkY, ChunkZ)->CollectPickupsByPlayer (a_Player);
- GetChunkNoLoad(OtherChunkX, ChunkY, OtherChunkZ)->CollectPickupsByPlayer(a_Player);
- GetChunkNoLoad(ChunkX, ChunkY, ChunkZ)->CollectPickupsByPlayer (a_Player);
- GetChunkNoLoad(ChunkX, ChunkY, OtherChunkZ)->CollectPickupsByPlayer(a_Player);
+ GetChunkNoLoad(OtherChunkX, ChunkZ)->CollectPickupsByPlayer (a_Player);
+ GetChunkNoLoad(OtherChunkX, OtherChunkZ)->CollectPickupsByPlayer(a_Player);
+ GetChunkNoLoad(ChunkX, ChunkZ)->CollectPickupsByPlayer (a_Player);
+ GetChunkNoLoad(ChunkX, OtherChunkZ)->CollectPickupsByPlayer(a_Player);
}
@@ -1177,7 +1192,7 @@ BLOCKTYPE cChunkMap::GetBlock(int a_BlockX, int a_BlockY, int a_BlockZ)
cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ);
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunk(ChunkX, ZERO_CHUNK_Y, ChunkZ);
+ cChunkPtr Chunk = GetChunk(ChunkX, ChunkZ);
if ((Chunk != NULL) && Chunk->IsValid())
{
return Chunk->GetBlock(a_BlockX, a_BlockY, a_BlockZ);
@@ -1206,7 +1221,7 @@ NIBBLETYPE cChunkMap::GetBlockMeta(int a_BlockX, int a_BlockY, int a_BlockZ)
cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ);
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunk( ChunkX, ZERO_CHUNK_Y, ChunkZ);
+ cChunkPtr Chunk = GetChunk( ChunkX, ChunkZ);
if ((Chunk != NULL) && Chunk->IsValid())
{
return Chunk->GetMeta(a_BlockX, a_BlockY, a_BlockZ);
@@ -1224,7 +1239,7 @@ NIBBLETYPE cChunkMap::GetBlockSkyLight(int a_BlockX, int a_BlockY, int a_BlockZ)
cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ);
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunk( ChunkX, ZERO_CHUNK_Y, ChunkZ);
+ cChunkPtr Chunk = GetChunk( ChunkX, ChunkZ);
if ((Chunk != NULL) && Chunk->IsValid())
{
return Chunk->GetSkyLight(a_BlockX, a_BlockY, a_BlockZ);
@@ -1242,7 +1257,7 @@ NIBBLETYPE cChunkMap::GetBlockBlockLight(int a_BlockX, int a_BlockY, int a_Block
cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ);
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunk( ChunkX, ZERO_CHUNK_Y, ChunkZ);
+ cChunkPtr Chunk = GetChunk( ChunkX, ChunkZ);
if ((Chunk != NULL) && Chunk->IsValid())
{
return Chunk->GetBlockLight(a_BlockX, a_BlockY, a_BlockZ);
@@ -1261,7 +1276,7 @@ void cChunkMap::SetBlockMeta(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYP
// a_BlockXYZ now contains relative coords!
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunk(ChunkX, ZERO_CHUNK_Y, ChunkZ);
+ cChunkPtr Chunk = GetChunk(ChunkX, ChunkZ);
if ((Chunk != NULL) && Chunk->IsValid())
{
Chunk->SetMeta(a_BlockX, a_BlockY, a_BlockZ, a_BlockMeta);
@@ -1272,25 +1287,25 @@ void cChunkMap::SetBlockMeta(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYP
-void cChunkMap::SetBlock(cWorldInterface & a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, bool a_SendToClients)
+void cChunkMap::SetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, bool a_SendToClients)
{
cChunkInterface ChunkInterface(this);
if (a_BlockType == E_BLOCK_AIR)
{
- BlockHandler(GetBlock(a_BlockX, a_BlockY, a_BlockZ))->OnDestroyed(ChunkInterface, a_WorldInterface, a_BlockX, a_BlockY, a_BlockZ);
+ BlockHandler(GetBlock(a_BlockX, a_BlockY, a_BlockZ))->OnDestroyed(ChunkInterface, *m_World, a_BlockX, a_BlockY, a_BlockZ);
}
int ChunkX, ChunkZ, X = a_BlockX, Y = a_BlockY, Z = a_BlockZ;
cChunkDef::AbsoluteToRelative( X, Y, Z, ChunkX, ChunkZ);
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunk( ChunkX, ZERO_CHUNK_Y, ChunkZ);
+ cChunkPtr Chunk = GetChunk( ChunkX, ChunkZ);
if ((Chunk != NULL) && Chunk->IsValid())
{
Chunk->SetBlock(X, Y, Z, a_BlockType, a_BlockMeta, a_SendToClients);
m_World->GetSimulatorManager()->WakeUp(a_BlockX, a_BlockY, a_BlockZ, Chunk);
}
- BlockHandler(a_BlockType)->OnPlaced(ChunkInterface, a_WorldInterface, a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta);
+ BlockHandler(a_BlockType)->OnPlaced(ChunkInterface, *m_World, a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta);
}
@@ -1303,7 +1318,7 @@ void cChunkMap::QueueSetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYP
cChunkDef::AbsoluteToRelative(X, Y, Z, ChunkX, ChunkZ);
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunk(ChunkX, ZERO_CHUNK_Y, ChunkZ);
+ cChunkPtr Chunk = GetChunk(ChunkX, ChunkZ);
if ((Chunk != NULL) && Chunk->IsValid())
{
Chunk->QueueSetBlock(X, Y, Z, a_BlockType, a_BlockMeta, a_Tick, a_PreviousBlockType);
@@ -1320,7 +1335,7 @@ bool cChunkMap::GetBlockTypeMeta(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCK
cChunkDef::AbsoluteToRelative( X, Y, Z, ChunkX, ChunkZ);
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunk( ChunkX, ZERO_CHUNK_Y, ChunkZ);
+ cChunkPtr Chunk = GetChunk( ChunkX, ChunkZ);
if ((Chunk != NULL) && Chunk->IsValid())
{
Chunk->GetBlockTypeMeta(X, Y, Z, a_BlockType, a_BlockMeta);
@@ -1339,7 +1354,7 @@ bool cChunkMap::GetBlockInfo(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE
cChunkDef::AbsoluteToRelative( X, Y, Z, ChunkX, ChunkZ);
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunk( ChunkX, ZERO_CHUNK_Y, ChunkZ);
+ cChunkPtr Chunk = GetChunk( ChunkX, ChunkZ);
if ((Chunk != NULL) && Chunk->IsValid())
{
Chunk->GetBlockInfo(X, Y, Z, a_BlockType, a_Meta, a_SkyLight, a_BlockLight);
@@ -1357,7 +1372,7 @@ void cChunkMap::ReplaceBlocks(const sSetBlockVector & a_Blocks, BLOCKTYPE a_Filt
cCSLock Lock(m_CSLayers);
for (sSetBlockVector::const_iterator itr = a_Blocks.begin(); itr != a_Blocks.end(); ++itr)
{
- cChunkPtr Chunk = GetChunk(itr->ChunkX, ZERO_CHUNK_Y, itr->ChunkZ);
+ cChunkPtr Chunk = GetChunk(itr->ChunkX, itr->ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid())
{
continue;
@@ -1378,7 +1393,7 @@ void cChunkMap::ReplaceTreeBlocks(const sSetBlockVector & a_Blocks)
cCSLock Lock(m_CSLayers);
for (sSetBlockVector::const_iterator itr = a_Blocks.begin(); itr != a_Blocks.end(); ++itr)
{
- cChunkPtr Chunk = GetChunk(itr->ChunkX, ZERO_CHUNK_Y, itr->ChunkZ);
+ cChunkPtr Chunk = GetChunk(itr->ChunkX, itr->ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid())
{
continue;
@@ -1413,7 +1428,7 @@ EMCSBiome cChunkMap::GetBiomeAt (int a_BlockX, int a_BlockZ)
cChunkDef::AbsoluteToRelative(X, Y, Z, ChunkX, ChunkZ);
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunk(ChunkX, ZERO_CHUNK_Y, ChunkZ);
+ cChunkPtr Chunk = GetChunk(ChunkX, ChunkZ);
if ((Chunk != NULL) && Chunk->IsValid())
{
return Chunk->GetBiomeAt(X, Z);
@@ -1434,7 +1449,7 @@ bool cChunkMap::SetBiomeAt(int a_BlockX, int a_BlockZ, EMCSBiome a_Biome)
cChunkDef::AbsoluteToRelative(X, Y, Z, ChunkX, ChunkZ);
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunk(ChunkX, ZERO_CHUNK_Y, ChunkZ);
+ cChunkPtr Chunk = GetChunk(ChunkX, ChunkZ);
if ((Chunk != NULL) && Chunk->IsValid())
{
Chunk->SetBiomeAt(X, Z, a_Biome);
@@ -1467,7 +1482,7 @@ bool cChunkMap::SetAreaBiome(int a_MinX, int a_MaxX, int a_MinZ, int a_MaxZ, EMC
{
int MinRelZ = (z == MinChunkZ) ? MinZ : 0;
int MaxRelZ = (z == MaxChunkZ) ? MaxZ : cChunkDef::Width - 1;
- cChunkPtr Chunk = GetChunkNoLoad(x, ZERO_CHUNK_Y, z);
+ cChunkPtr Chunk = GetChunkNoLoad(x, z);
if ((Chunk != NULL) && Chunk->IsValid())
{
Chunk->SetAreaBiome(MinRelX, MaxRelX, MinRelZ, MaxRelZ, a_Biome);
@@ -1491,7 +1506,7 @@ bool cChunkMap::GetBlocks(sSetBlockVector & a_Blocks, bool a_ContinueOnFailure)
cCSLock Lock(m_CSLayers);
for (sSetBlockVector::iterator itr = a_Blocks.begin(); itr != a_Blocks.end(); ++itr)
{
- cChunkPtr Chunk = GetChunk(itr->ChunkX, ZERO_CHUNK_Y, itr->ChunkZ);
+ cChunkPtr Chunk = GetChunk(itr->ChunkX, itr->ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid())
{
if (!a_ContinueOnFailure)
@@ -1519,7 +1534,7 @@ bool cChunkMap::DigBlock(int a_X, int a_Y, int a_Z)
{
cCSLock Lock(m_CSLayers);
- cChunkPtr DestChunk = GetChunk( ChunkX, ZERO_CHUNK_Y, ChunkZ);
+ cChunkPtr DestChunk = GetChunk( ChunkX, ChunkZ);
if ((DestChunk == NULL) || !DestChunk->IsValid())
{
return false;
@@ -1542,7 +1557,7 @@ void cChunkMap::SendBlockTo(int a_X, int a_Y, int a_Z, cPlayer * a_Player)
cChunkDef::AbsoluteToRelative(a_X, a_Y, a_Z, ChunkX, ChunkZ);
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunk(ChunkX, ZERO_CHUNK_Y, ChunkZ);
+ cChunkPtr Chunk = GetChunk(ChunkX, ChunkZ);
if ((Chunk != NULL) && (Chunk->IsValid()))
{
Chunk->SendBlockTo(a_X, a_Y, a_Z, a_Player->GetClientHandle());
@@ -1556,12 +1571,12 @@ void cChunkMap::SendBlockTo(int a_X, int a_Y, int a_Z, cPlayer * a_Player)
void cChunkMap::CompareChunkClients(int a_ChunkX1, int a_ChunkZ1, int a_ChunkX2, int a_ChunkZ2, cClientDiffCallback & a_Callback)
{
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk1 = GetChunkNoGen(a_ChunkX1, ZERO_CHUNK_Y, a_ChunkZ1);
+ cChunkPtr Chunk1 = GetChunkNoGen(a_ChunkX1, a_ChunkZ1);
if (Chunk1 == NULL)
{
return;
}
- cChunkPtr Chunk2 = GetChunkNoGen(a_ChunkX2, ZERO_CHUNK_Y, a_ChunkZ2);
+ cChunkPtr Chunk2 = GetChunkNoGen(a_ChunkX2, a_ChunkZ2);
if (Chunk2 == NULL)
{
return;
@@ -1623,7 +1638,7 @@ void cChunkMap::CompareChunkClients(cChunk * a_Chunk1, cChunk * a_Chunk2, cClien
bool cChunkMap::AddChunkClient(int a_ChunkX, int a_ChunkZ, cClientHandle * a_Client)
{
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunk(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ);
+ cChunkPtr Chunk = GetChunk(a_ChunkX, a_ChunkZ);
if (Chunk == NULL)
{
return false;
@@ -1638,7 +1653,7 @@ bool cChunkMap::AddChunkClient(int a_ChunkX, int a_ChunkZ, cClientHandle * a_Cli
void cChunkMap::RemoveChunkClient(int a_ChunkX, int a_ChunkZ, cClientHandle * a_Client)
{
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ);
+ cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ);
if (Chunk == NULL)
{
return;
@@ -1667,7 +1682,7 @@ void cChunkMap::RemoveClientFromChunks(cClientHandle * a_Client)
void cChunkMap::AddEntity(cEntity * a_Entity)
{
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunkNoGen(a_Entity->GetChunkX(), ZERO_CHUNK_Y, a_Entity->GetChunkZ());
+ cChunkPtr Chunk = GetChunkNoGen(a_Entity->GetChunkX(), a_Entity->GetChunkZ());
if (
(Chunk == NULL) || // Chunk not present at all
(!Chunk->IsValid() && !a_Entity->IsPlayer()) // Chunk present, but no valid data; players need to spawn in such chunks (#953)
@@ -1688,7 +1703,7 @@ void cChunkMap::AddEntity(cEntity * a_Entity)
void cChunkMap::AddEntityIfNotPresent(cEntity * a_Entity)
{
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunkNoGen(a_Entity->GetChunkX(), ZERO_CHUNK_Y, a_Entity->GetChunkZ());
+ cChunkPtr Chunk = GetChunkNoGen(a_Entity->GetChunkX(), a_Entity->GetChunkZ());
if (
(Chunk == NULL) || // Chunk not present at all
(!Chunk->IsValid() && !a_Entity->IsPlayer()) // Chunk present, but no valid data; players need to spawn in such chunks (#953)
@@ -1729,7 +1744,7 @@ bool cChunkMap::HasEntity(int a_UniqueID)
void cChunkMap::RemoveEntity(cEntity * a_Entity)
{
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunkNoGen(a_Entity->GetChunkX(), ZERO_CHUNK_Y, a_Entity->GetChunkZ());
+ cChunkPtr Chunk = GetChunkNoGen(a_Entity->GetChunkX(), a_Entity->GetChunkZ());
// Even if a chunk is not valid, it may still contain entities such as players; make sure to remove them (#1190)
if (Chunk == NULL)
@@ -1763,7 +1778,7 @@ bool cChunkMap::ForEachEntity(cEntityCallback & a_Callback)
bool cChunkMap::ForEachEntityInChunk(int a_ChunkX, int a_ChunkZ, cEntityCallback & a_Callback)
{
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ);
+ cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid())
{
return false;
@@ -1775,6 +1790,38 @@ bool cChunkMap::ForEachEntityInChunk(int a_ChunkX, int a_ChunkZ, cEntityCallback
+bool cChunkMap::ForEachEntityInBox(const cBoundingBox & a_Box, cEntityCallback & a_Callback)
+{
+ // Calculate the chunk range for the box:
+ int MinChunkX = (int)floor(a_Box.GetMinX() / cChunkDef::Width);
+ int MinChunkZ = (int)floor(a_Box.GetMinZ() / cChunkDef::Width);
+ int MaxChunkX = (int)floor((a_Box.GetMaxX() + cChunkDef::Width) / cChunkDef::Width);
+ int MaxChunkZ = (int)floor((a_Box.GetMaxZ() + cChunkDef::Width) / cChunkDef::Width);
+
+ // Iterate over each chunk in the range:
+ cCSLock Lock(m_CSLayers);
+ for (int z = MinChunkZ; z <= MaxChunkZ; z++)
+ {
+ for (int x = MinChunkX; x <= MaxChunkX; x++)
+ {
+ cChunkPtr Chunk = GetChunkNoGen(x, z);
+ if ((Chunk == NULL) || !Chunk->IsValid())
+ {
+ continue;
+ }
+ if (!Chunk->ForEachEntityInBox(a_Box, a_Callback))
+ {
+ return false;
+ }
+ } // for x
+ } // for z
+ return true;
+}
+
+
+
+
+
void cChunkMap::DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_BlockY, double a_BlockZ, cVector3iArray & a_BlocksAffected)
{
// Don't explode if outside of Y range (prevents the following test running into unallocated memory):
@@ -1989,7 +2036,7 @@ bool cChunkMap::DoWithEntityByID(int a_UniqueID, cEntityCallback & a_Callback)
bool cChunkMap::ForEachBlockEntityInChunk(int a_ChunkX, int a_ChunkZ, cBlockEntityCallback & a_Callback)
{
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ);
+ cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid())
{
return false;
@@ -2004,7 +2051,7 @@ bool cChunkMap::ForEachBlockEntityInChunk(int a_ChunkX, int a_ChunkZ, cBlockEnti
bool cChunkMap::ForEachChestInChunk(int a_ChunkX, int a_ChunkZ, cChestCallback & a_Callback)
{
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ);
+ cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid())
{
return false;
@@ -2019,7 +2066,7 @@ bool cChunkMap::ForEachChestInChunk(int a_ChunkX, int a_ChunkZ, cChestCallback &
bool cChunkMap::ForEachDispenserInChunk(int a_ChunkX, int a_ChunkZ, cDispenserCallback & a_Callback)
{
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ);
+ cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid())
{
return false;
@@ -2034,7 +2081,7 @@ bool cChunkMap::ForEachDispenserInChunk(int a_ChunkX, int a_ChunkZ, cDispenserCa
bool cChunkMap::ForEachDropperInChunk(int a_ChunkX, int a_ChunkZ, cDropperCallback & a_Callback)
{
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ);
+ cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid())
{
return false;
@@ -2049,7 +2096,7 @@ bool cChunkMap::ForEachDropperInChunk(int a_ChunkX, int a_ChunkZ, cDropperCallba
bool cChunkMap::ForEachDropSpenserInChunk(int a_ChunkX, int a_ChunkZ, cDropSpenserCallback & a_Callback)
{
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ);
+ cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid())
{
return false;
@@ -2064,7 +2111,7 @@ bool cChunkMap::ForEachDropSpenserInChunk(int a_ChunkX, int a_ChunkZ, cDropSpens
bool cChunkMap::ForEachFurnaceInChunk(int a_ChunkX, int a_ChunkZ, cFurnaceCallback & a_Callback)
{
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ);
+ cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid())
{
return false;
@@ -2082,7 +2129,7 @@ bool cChunkMap::DoWithBlockEntityAt(int a_BlockX, int a_BlockY, int a_BlockZ, cB
int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ;
cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ);
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunkNoGen(ChunkX, ZERO_CHUNK_Y, ChunkZ);
+ cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid())
{
return false;
@@ -2100,7 +2147,7 @@ bool cChunkMap::DoWithBeaconAt(int a_BlockX, int a_BlockY, int a_BlockZ, cBeacon
int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ;
cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ);
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunkNoGen(ChunkX, ZERO_CHUNK_Y, ChunkZ);
+ cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid())
{
return false;
@@ -2118,7 +2165,7 @@ bool cChunkMap::DoWithChestAt(int a_BlockX, int a_BlockY, int a_BlockZ, cChestCa
int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ;
cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ);
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunkNoGen(ChunkX, ZERO_CHUNK_Y, ChunkZ);
+ cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid())
{
return false;
@@ -2136,7 +2183,7 @@ bool cChunkMap::DoWithDispenserAt(int a_BlockX, int a_BlockY, int a_BlockZ, cDis
int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ;
cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ);
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunkNoGen(ChunkX, ZERO_CHUNK_Y, ChunkZ);
+ cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid())
{
return false;
@@ -2154,7 +2201,7 @@ bool cChunkMap::DoWithDropperAt(int a_BlockX, int a_BlockY, int a_BlockZ, cDropp
int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ;
cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ);
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunkNoGen(ChunkX, ZERO_CHUNK_Y, ChunkZ);
+ cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid())
{
return false;
@@ -2172,7 +2219,7 @@ bool cChunkMap::DoWithDropSpenserAt(int a_BlockX, int a_BlockY, int a_BlockZ, cD
int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ;
cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ);
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunkNoGen(ChunkX, ZERO_CHUNK_Y, ChunkZ);
+ cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid())
{
return false;
@@ -2190,7 +2237,7 @@ bool cChunkMap::DoWithFurnaceAt(int a_BlockX, int a_BlockY, int a_BlockZ, cFurna
int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ;
cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ);
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunkNoGen(ChunkX, ZERO_CHUNK_Y, ChunkZ);
+ cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid())
{
return false;
@@ -2207,7 +2254,7 @@ bool cChunkMap::DoWithNoteBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cNot
int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ;
cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ);
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunkNoGen(ChunkX, ZERO_CHUNK_Y, ChunkZ);
+ cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid())
{
return false;
@@ -2224,7 +2271,7 @@ bool cChunkMap::DoWithCommandBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, c
int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ;
cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ);
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunkNoGen(ChunkX, ZERO_CHUNK_Y, ChunkZ);
+ cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid())
{
return false;
@@ -2242,7 +2289,7 @@ bool cChunkMap::DoWithMobHeadAt(int a_BlockX, int a_BlockY, int a_BlockZ, cMobHe
int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ;
cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ);
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunkNoGen(ChunkX, ZERO_CHUNK_Y, ChunkZ);
+ cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid())
{
return false;
@@ -2260,7 +2307,7 @@ bool cChunkMap::DoWithFlowerPotAt(int a_BlockX, int a_BlockY, int a_BlockZ, cFlo
int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ;
cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ);
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunkNoGen(ChunkX, ZERO_CHUNK_Y, ChunkZ);
+ cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid())
{
return false;
@@ -2278,7 +2325,7 @@ bool cChunkMap::GetSignLines(int a_BlockX, int a_BlockY, int a_BlockZ, AString &
int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ;
cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ);
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunkNoGen(ChunkX, ZERO_CHUNK_Y, ChunkZ);
+ cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid())
{
return false;
@@ -2290,62 +2337,20 @@ bool cChunkMap::GetSignLines(int a_BlockX, int a_BlockY, int a_BlockZ, AString &
-void cChunkMap::TouchChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ)
+void cChunkMap::TouchChunk(int a_ChunkX, int a_ChunkZ)
{
cCSLock Lock(m_CSLayers);
- GetChunk(a_ChunkX, a_ChunkY, a_ChunkZ);
-}
-
-
-
-
-
-/// Loads the chunk synchronously, if not already loaded. Doesn't generate. Returns true if chunk valid (even if already loaded before)
-bool cChunkMap::LoadChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ)
-{
- {
- cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkY, a_ChunkZ);
- if (Chunk == NULL)
- {
- // Internal error
- return false;
- }
- if (Chunk->IsValid())
- {
- // Already loaded
- return true;
- }
- if (Chunk->HasLoadFailed())
- {
- // Already tried loading and it failed
- return false;
- }
- }
- return m_World->GetStorage().LoadChunk(a_ChunkX, a_ChunkY, a_ChunkZ);
-}
-
-
-
-
-
-/// Loads the chunks specified. Doesn't report failure, other than chunks being !IsValid()
-void cChunkMap::LoadChunks(const cChunkCoordsList & a_Chunks)
-{
- for (cChunkCoordsList::const_iterator itr = a_Chunks.begin(); itr != a_Chunks.end(); ++itr)
- {
- LoadChunk(itr->m_ChunkX, itr->m_ChunkY, itr->m_ChunkZ);
- } // for itr - a_Chunks[]
+ GetChunk(a_ChunkX, a_ChunkZ);
}
-void cChunkMap::ChunkLoadFailed(int a_ChunkX, int a_ChunkY, int a_ChunkZ)
+void cChunkMap::ChunkLoadFailed(int a_ChunkX, int a_ChunkZ)
{
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunkNoLoad(a_ChunkX, a_ChunkY, a_ChunkZ);
+ cChunkPtr Chunk = GetChunkNoLoad(a_ChunkX, a_ChunkZ);
if (Chunk == NULL)
{
return;
@@ -2362,7 +2367,7 @@ bool cChunkMap::SetSignLines(int a_BlockX, int a_BlockY, int a_BlockZ, const ASt
cCSLock Lock(m_CSLayers);
int ChunkX, ChunkZ;
cChunkDef::BlockToChunk(a_BlockX, a_BlockZ, ChunkX, ChunkZ);
- cChunkPtr Chunk = GetChunkNoGen(ChunkX, ZERO_CHUNK_Y, ChunkZ);
+ cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid())
{
return false;
@@ -2377,7 +2382,7 @@ bool cChunkMap::SetSignLines(int a_BlockX, int a_BlockY, int a_BlockZ, const ASt
void cChunkMap::MarkChunkRegenerating(int a_ChunkX, int a_ChunkZ)
{
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunkNoLoad(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ);
+ cChunkPtr Chunk = GetChunkNoLoad(a_ChunkX, a_ChunkZ);
if (Chunk == NULL)
{
// Not present
@@ -2393,7 +2398,7 @@ void cChunkMap::MarkChunkRegenerating(int a_ChunkX, int a_ChunkZ)
bool cChunkMap::IsChunkLighted(int a_ChunkX, int a_ChunkZ)
{
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunkNoLoad(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ);
+ cChunkPtr Chunk = GetChunkNoLoad(a_ChunkX, a_ChunkZ);
if (Chunk == NULL)
{
// Not present
@@ -2414,7 +2419,7 @@ bool cChunkMap::ForEachChunkInRect(int a_MinChunkX, int a_MaxChunkX, int a_MinCh
{
for (int x = a_MinChunkX; x <= a_MaxChunkX; x++)
{
- cChunkPtr Chunk = GetChunkNoLoad(x, ZERO_CHUNK_Y, z);
+ cChunkPtr Chunk = GetChunkNoLoad(x, z);
if ((Chunk == NULL) || (!Chunk->IsValid()))
{
// Not present / not valid
@@ -2456,7 +2461,7 @@ bool cChunkMap::WriteBlockArea(cBlockArea & a_Area, int a_MinBlockX, int a_MinBl
{
for (int x = MinChunkX; x <= MaxChunkX; x++)
{
- cChunkPtr Chunk = GetChunkNoLoad(x, ZERO_CHUNK_Y, z);
+ cChunkPtr Chunk = GetChunkNoLoad(x, z);
if ((Chunk == NULL) || (!Chunk->IsValid()))
{
// Not present / not valid
@@ -2497,7 +2502,7 @@ void cChunkMap::GrowMelonPumpkin(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCK
cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ);
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ZERO_CHUNK_Y, ChunkZ);
+ cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ChunkZ);
if (Chunk != NULL)
{
Chunk->GrowMelonPumpkin(a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_Rand);
@@ -2514,7 +2519,7 @@ void cChunkMap::GrowSugarcane(int a_BlockX, int a_BlockY, int a_BlockZ, int a_Nu
cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ);
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ZERO_CHUNK_Y, ChunkZ);
+ cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ChunkZ);
if (Chunk != NULL)
{
Chunk->GrowSugarcane(a_BlockX, a_BlockY, a_BlockZ, a_NumBlocksToGrow);
@@ -2531,7 +2536,7 @@ void cChunkMap::GrowCactus(int a_BlockX, int a_BlockY, int a_BlockZ, int a_NumBl
cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ);
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ZERO_CHUNK_Y, ChunkZ);
+ cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ChunkZ);
if (Chunk != NULL)
{
Chunk->GrowCactus(a_BlockX, a_BlockY, a_BlockZ, a_NumBlocksToGrow);
@@ -2548,7 +2553,7 @@ void cChunkMap::SetNextBlockTick(int a_BlockX, int a_BlockY, int a_BlockZ)
cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ);
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ZERO_CHUNK_Y, ChunkZ);
+ cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ChunkZ);
if (Chunk != NULL)
{
Chunk->SetNextBlockTick(a_BlockX, a_BlockY, a_BlockZ);
@@ -2603,7 +2608,7 @@ void cChunkMap::TickBlock(int a_BlockX, int a_BlockY, int a_BlockZ)
cCSLock Lock(m_CSLayers);
int ChunkX, ChunkZ;
cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ);
- cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ZERO_CHUNK_Y, ChunkZ);
+ cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid())
{
return;
@@ -2672,7 +2677,7 @@ void cChunkMap::QueueTickBlock(int a_BlockX, int a_BlockY, int a_BlockZ)
// a_BlockXYZ now contains relative coords!
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ZERO_CHUNK_Y, ChunkZ);
+ cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ChunkZ);
if (Chunk != NULL)
{
Chunk->QueueTickBlock(a_BlockX, a_BlockY, a_BlockZ);
@@ -2686,7 +2691,7 @@ void cChunkMap::QueueTickBlock(int a_BlockX, int a_BlockY, int a_BlockZ)
void cChunkMap::SetChunkAlwaysTicked(int a_ChunkX, int a_ChunkZ, bool a_AlwaysTicked)
{
cCSLock Lock(m_CSLayers);
- cChunkPtr Chunk = GetChunkNoLoad(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ);
+ cChunkPtr Chunk = GetChunkNoLoad(a_ChunkX, a_ChunkZ);
if (Chunk != NULL)
{
Chunk->SetAlwaysTicked(a_AlwaysTicked);
@@ -2731,7 +2736,7 @@ cChunkMap::cChunkLayer::~cChunkLayer()
-cChunkPtr cChunkMap::cChunkLayer::GetChunk( int a_ChunkX, int a_ChunkY, int a_ChunkZ)
+cChunkPtr cChunkMap::cChunkLayer::GetChunk( int a_ChunkX, int a_ChunkZ)
{
// Always returns an assigned chunkptr, but the chunk needn't be valid (loaded / generated) - callers must check
@@ -2751,7 +2756,7 @@ cChunkPtr cChunkMap::cChunkLayer::GetChunk( int a_ChunkX, int a_ChunkY, int a_Ch
cChunk * neixp = (LocalX < LAYER_SIZE - 1) ? m_Chunks[Index + 1] : m_Parent->FindChunk(a_ChunkX + 1, a_ChunkZ);
cChunk * neizm = (LocalZ > 0) ? m_Chunks[Index - LAYER_SIZE] : m_Parent->FindChunk(a_ChunkX, a_ChunkZ - 1);
cChunk * neizp = (LocalZ < LAYER_SIZE - 1) ? m_Chunks[Index + LAYER_SIZE] : m_Parent->FindChunk(a_ChunkX, a_ChunkZ + 1);
- m_Chunks[Index] = new cChunk(a_ChunkX, 0, a_ChunkZ, m_Parent, m_Parent->GetWorld(), neixm, neixp, neizm, neizp, m_Pool);
+ m_Chunks[Index] = new cChunk(a_ChunkX, a_ChunkZ, m_Parent, m_Parent->GetWorld(), neixm, neixp, neizm, neizp, m_Pool);
}
return m_Chunks[Index];
}
@@ -2951,7 +2956,7 @@ void cChunkMap::cChunkLayer::Save(void)
{
if ((m_Chunks[i] != NULL) && m_Chunks[i]->IsValid() && m_Chunks[i]->IsDirty())
{
- World->GetStorage().QueueSaveChunk(m_Chunks[i]->GetPosX(), m_Chunks[i]->GetPosY(), m_Chunks[i]->GetPosZ());
+ World->GetStorage().QueueSaveChunk(m_Chunks[i]->GetPosX(), m_Chunks[i]->GetPosZ());
}
} // for i - m_Chunks[]
}
@@ -3024,7 +3029,7 @@ void cChunkMap::AddChunkStay(cChunkStay & a_ChunkStay)
const cChunkCoordsVector & WantedChunks = a_ChunkStay.GetChunks();
for (cChunkCoordsVector::const_iterator itr = WantedChunks.begin(); itr != WantedChunks.end(); ++itr)
{
- cChunkPtr Chunk = GetChunk(itr->m_ChunkX, itr->m_ChunkY, itr->m_ChunkZ);
+ cChunkPtr Chunk = GetChunk(itr->m_ChunkX, itr->m_ChunkZ);
if (Chunk == NULL)
{
continue;
@@ -3073,7 +3078,7 @@ void cChunkMap::DelChunkStay(cChunkStay & a_ChunkStay)
const cChunkCoordsVector & Chunks = a_ChunkStay.GetChunks();
for (cChunkCoordsVector::const_iterator itr = Chunks.begin(), end = Chunks.end(); itr != end; ++itr)
{
- cChunkPtr Chunk = GetChunkNoLoad(itr->m_ChunkX, itr->m_ChunkY, itr->m_ChunkZ);
+ cChunkPtr Chunk = GetChunkNoLoad(itr->m_ChunkX, itr->m_ChunkZ);
if (Chunk == NULL)
{
continue;
diff --git a/src/ChunkMap.h b/src/ChunkMap.h
index 1e9a0f982..6e92833f1 100644
--- a/src/ChunkMap.h
+++ b/src/ChunkMap.h
@@ -36,6 +36,7 @@ class cBlockArea;
class cMobCensus;
class cMobSpawner;
class cSetChunkData;
+class cBoundingBox;
typedef std::list<cClientHandle *> cClientHandleList;
typedef cChunk * cChunkPtr;
@@ -86,7 +87,7 @@ public:
void BroadcastEntityStatus(const cEntity & a_Entity, char a_Status, const cClientHandle * a_Exclude = NULL);
void BroadcastEntityVelocity(const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL);
void BroadcastEntityAnimation(const cEntity & a_Entity, char a_Animation, const cClientHandle * a_Exclude = NULL);
- void BroadcastParticleEffect(const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmmount, cClientHandle * a_Exclude = NULL);
+ void BroadcastParticleEffect(const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmount, cClientHandle * a_Exclude = NULL);
void BroadcastRemoveEntityEffect (const cEntity & a_Entity, int a_EffectID, const cClientHandle * a_Exclude = NULL);
void BroadcastSoundEffect(const AString & a_SoundName, double a_X, double a_Y, double a_Z, float a_Volume, float a_Pitch, const cClientHandle * a_Exclude = NULL);
void BroadcastSoundParticleEffect(int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data, const cClientHandle * a_Exclude = NULL);
@@ -132,6 +133,9 @@ public:
/** Copies the chunk's blocktypes into a_Blocks; returns true if successful */
bool GetChunkBlockTypes (int a_ChunkX, int a_ChunkZ, BLOCKTYPE * a_Blocks);
+ /** Returns true iff the chunk is in the loader / generator queue. */
+ bool IsChunkQueued(int a_ChunkX, int a_ChunkZ);
+
bool IsChunkValid (int a_ChunkX, int a_ChunkZ);
bool HasChunkAnyClients (int a_ChunkX, int a_ChunkZ);
int GetHeight (int a_BlockX, int a_BlockZ); // Waits for the chunk to get loaded / generated
@@ -147,8 +151,8 @@ public:
NIBBLETYPE GetBlockSkyLight (int a_BlockX, int a_BlockY, int a_BlockZ);
NIBBLETYPE GetBlockBlockLight(int a_BlockX, int a_BlockY, int a_BlockZ);
void SetBlockMeta (int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_BlockMeta);
- void SetBlock (cWorldInterface & a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, bool a_SendToClients = true);
- void QueueSetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Int64 a_Tick, BLOCKTYPE a_PreviousBlockType = E_BLOCK_AIR);
+ void SetBlock (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, bool a_SendToClients = true);
+ void QueueSetBlock (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Int64 a_Tick, BLOCKTYPE a_PreviousBlockType = E_BLOCK_AIR);
bool GetBlockTypeMeta (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta);
bool GetBlockInfo (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_Meta, NIBBLETYPE & a_SkyLight, NIBBLETYPE & a_BlockLight);
@@ -209,6 +213,11 @@ public:
/** Calls the callback for each entity in the specified chunk; returns true if all entities processed, false if the callback aborted by returning true */
bool ForEachEntityInChunk(int a_ChunkX, int a_ChunkZ, cEntityCallback & a_Callback); // Lua-accessible
+ /** Calls the callback for each entity that has a nonempty intersection with the specified boundingbox.
+ Returns true if all entities processed, false if the callback aborted by returning true.
+ If any chunk in the box is missing, ignores the entities in that chunk silently. */
+ bool ForEachEntityInBox(const cBoundingBox & a_Box, cEntityCallback & a_Callback); // Lua-accessible
+
/** Destroys and returns a list of blocks destroyed in the explosion at the specified coordinates */
void DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_BlockY, double a_BlockZ, cVector3iArray & a_BlockAffected);
@@ -270,16 +279,10 @@ public:
bool GetSignLines (int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4); // Lua-accessible
/** Touches the chunk, causing it to be loaded or generated */
- void TouchChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ);
+ void TouchChunk(int a_ChunkX, int a_ChunkZ);
- /** Loads the chunk, if not already loaded. Doesn't generate. Returns true if chunk valid (even if already loaded before) */
- bool LoadChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ);
-
- /** Loads the chunks specified. Doesn't report failure, other than chunks being !IsValid() */
- void LoadChunks(const cChunkCoordsList & a_Chunks);
-
/** Marks the chunk as failed-to-load */
- void ChunkLoadFailed(int a_ChunkX, int a_ChunkY, int a_ChunkZ);
+ void ChunkLoadFailed(int a_ChunkX, int a_ChunkZ);
/** Sets the sign text. Returns true if sign text changed. */
bool SetSignLines(int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4);
@@ -363,7 +366,7 @@ private:
~cChunkLayer();
/** Always returns an assigned chunkptr, but the chunk needn't be valid (loaded / generated) - callers must check */
- cChunkPtr GetChunk( int a_ChunkX, int a_ChunkY, int a_ChunkZ);
+ cChunkPtr GetChunk( int a_ChunkX, int a_ChunkZ);
/** Returns the specified chunk, or NULL if not created yet */
cChunk * FindChunk(int a_ChunkX, int a_ChunkZ);
@@ -456,9 +459,9 @@ private:
std::auto_ptr<cAllocationPool<cChunkData::sChunkSection> > m_Pool;
- cChunkPtr GetChunk (int a_ChunkX, int a_ChunkY, int a_ChunkZ); // Also queues the chunk for loading / generating if not valid
- cChunkPtr GetChunkNoGen (int a_ChunkX, int a_ChunkY, int a_ChunkZ); // Also queues the chunk for loading if not valid; doesn't generate
- cChunkPtr GetChunkNoLoad(int a_ChunkX, int a_ChunkY, int a_ChunkZ); // Doesn't load, doesn't generate
+ cChunkPtr GetChunk (int a_ChunkX, int a_ChunkZ); // Also queues the chunk for loading / generating if not valid
+ cChunkPtr GetChunkNoGen (int a_ChunkX, int a_ChunkZ); // Also queues the chunk for loading if not valid; doesn't generate
+ cChunkPtr GetChunkNoLoad(int a_ChunkX, int a_ChunkZ); // Doesn't load, doesn't generate
/** Gets a block in any chunk while in the cChunk's Tick() method; returns true if successful, false if chunk not loaded (doesn't queue load) */
bool LockedGetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta);
diff --git a/src/ChunkSender.cpp b/src/ChunkSender.cpp
index ebcf0e272..95c4d03d2 100644
--- a/src/ChunkSender.cpp
+++ b/src/ChunkSender.cpp
@@ -81,7 +81,7 @@ void cChunkSender::ChunkReady(int a_ChunkX, int a_ChunkZ)
// This is probably never gonna be called twice for the same chunk, and if it is, we don't mind, so we don't check
{
cCSLock Lock(m_CS);
- m_ChunksReady.push_back(cChunkCoords(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ));
+ m_ChunksReady.push_back(cChunkCoords(a_ChunkX, a_ChunkZ));
}
m_evtQueue.Set();
}
@@ -95,12 +95,12 @@ void cChunkSender::QueueSendChunkTo(int a_ChunkX, int a_ChunkZ, cClientHandle *
ASSERT(a_Client != NULL);
{
cCSLock Lock(m_CS);
- if (std::find(m_SendChunks.begin(), m_SendChunks.end(), sSendChunk(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ, a_Client)) != m_SendChunks.end())
+ if (std::find(m_SendChunks.begin(), m_SendChunks.end(), sSendChunk(a_ChunkX, a_ChunkZ, a_Client)) != m_SendChunks.end())
{
// Already queued, bail out
return;
}
- m_SendChunks.push_back(sSendChunk(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ, a_Client));
+ m_SendChunks.push_back(sSendChunk(a_ChunkX, a_ChunkZ, a_Client));
}
m_evtQueue.Set();
}
@@ -160,7 +160,7 @@ void cChunkSender::Execute(void)
m_ChunksReady.pop_front();
Lock.Unlock();
- SendChunk(Coords.m_ChunkX, Coords.m_ChunkY, Coords.m_ChunkZ, NULL);
+ SendChunk(Coords.m_ChunkX, Coords.m_ChunkZ, NULL);
}
else
{
@@ -169,7 +169,7 @@ void cChunkSender::Execute(void)
m_SendChunks.pop_front();
Lock.Unlock();
- SendChunk(Chunk.m_ChunkX, Chunk.m_ChunkY, Chunk.m_ChunkZ, Chunk.m_Client);
+ SendChunk(Chunk.m_ChunkX, Chunk.m_ChunkZ, Chunk.m_Client);
}
Lock.Lock();
int RemoveCount = m_RemoveCount;
@@ -186,14 +186,14 @@ void cChunkSender::Execute(void)
-void cChunkSender::SendChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, cClientHandle * a_Client)
+void cChunkSender::SendChunk(int a_ChunkX, int a_ChunkZ, cClientHandle * a_Client)
{
ASSERT(m_World != NULL);
// Ask the client if it still wants the chunk:
if (a_Client != NULL)
{
- if (!a_Client->WantsSendChunk(a_ChunkX, a_ChunkY, a_ChunkZ))
+ if (!a_Client->WantsSendChunk(a_ChunkX, a_ChunkZ))
{
return;
}
diff --git a/src/ChunkSender.h b/src/ChunkSender.h
index 624a3a0bd..a0e9087a9 100644
--- a/src/ChunkSender.h
+++ b/src/ChunkSender.h
@@ -95,13 +95,11 @@ protected:
struct sSendChunk
{
int m_ChunkX;
- int m_ChunkY;
int m_ChunkZ;
cClientHandle * m_Client;
- sSendChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, cClientHandle * a_Client) :
+ sSendChunk(int a_ChunkX, int a_ChunkZ, cClientHandle * a_Client) :
m_ChunkX(a_ChunkX),
- m_ChunkY(a_ChunkY),
m_ChunkZ(a_ChunkZ),
m_Client(a_Client)
{
@@ -111,7 +109,6 @@ protected:
{
return (
(a_Other.m_ChunkX == m_ChunkX) &&
- (a_Other.m_ChunkY == m_ChunkY) &&
(a_Other.m_ChunkZ == m_ChunkZ) &&
(a_Other.m_Client == m_Client)
);
@@ -162,7 +159,7 @@ protected:
virtual void BlockEntity (cBlockEntity * a_Entity) override;
/// Sends the specified chunk to a_Client, or to all chunk clients if a_Client == NULL
- void SendChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, cClientHandle * a_Client);
+ void SendChunk(int a_ChunkX, int a_ChunkZ, cClientHandle * a_Client);
} ;
diff --git a/src/ChunkStay.cpp b/src/ChunkStay.cpp
index b5002a63d..38aa89a37 100644
--- a/src/ChunkStay.cpp
+++ b/src/ChunkStay.cpp
@@ -51,7 +51,7 @@ void cChunkStay::Add(int a_ChunkX, int a_ChunkZ)
return;
}
} // for itr - Chunks[]
- m_Chunks.push_back(cChunkCoords(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ));
+ m_Chunks.push_back(cChunkCoords(a_ChunkX, a_ChunkZ));
}
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index e97c126a1..1e2f4ffad 100644
--- a/src/ClientHandle.cpp
+++ b/src/ClientHandle.cpp
@@ -126,9 +126,12 @@ cClientHandle::~cClientHandle()
cWorld * World = m_Player->GetWorld();
if (World != NULL)
{
- // Send the Offline PlayerList packet:
- World->BroadcastPlayerListItem(m_Player->GetTabListName(), false, 0, this);
-
+ if (!m_Username.empty())
+ {
+ // Send the Offline PlayerList packet:
+ World->BroadcastPlayerListRemovePlayer(*m_Player, this);
+ }
+
World->RemovePlayer(m_Player, true); // Must be called before cPlayer::Destroy() as otherwise cChunk tries to delete the player, and then we do it again
m_Player->Destroy();
}
@@ -310,8 +313,16 @@ void cClientHandle::Authenticate(const AString & a_Name, const AString & a_UUID,
ASSERT(m_Player == NULL);
m_Username = a_Name;
- m_UUID = a_UUID;
- m_Properties = a_Properties;
+
+ // Only assign UUID and properties if not already pre-assigned (BungeeCord sends those in the Handshake packet):
+ if (m_UUID.empty())
+ {
+ m_UUID = a_UUID;
+ }
+ if (m_Properties.empty())
+ {
+ m_Properties = a_Properties;
+ }
// Send login success (if the protocol supports it):
m_Protocol->SendLoginSuccess();
@@ -360,7 +371,12 @@ void cClientHandle::Authenticate(const AString & a_Name, const AString & a_UUID,
// Send experience
m_Player->SendExperience();
-
+
+ // Send player list items
+ SendPlayerListAddPlayer(*m_Player);
+ World->BroadcastPlayerListAddPlayer(*m_Player);
+ World->SendPlayerList(m_Player);
+
m_Player->Initialize(*World);
m_State = csAuthenticated;
@@ -470,13 +486,13 @@ void cClientHandle::StreamChunks(void)
// For each distance touch chunks in a hollow square centered around current position:
for (int i = -d; i <= d; ++i)
{
- World->TouchChunk(ChunkPosX + d, ZERO_CHUNK_Y, ChunkPosZ + i);
- World->TouchChunk(ChunkPosX - d, ZERO_CHUNK_Y, ChunkPosZ + i);
+ World->TouchChunk(ChunkPosX + d, ChunkPosZ + i);
+ World->TouchChunk(ChunkPosX - d, ChunkPosZ + i);
} // for i
for (int i = -d + 1; i < d; ++i)
{
- World->TouchChunk(ChunkPosX + i, ZERO_CHUNK_Y, ChunkPosZ + d);
- World->TouchChunk(ChunkPosX + i, ZERO_CHUNK_Y, ChunkPosZ - d);
+ World->TouchChunk(ChunkPosX + i, ChunkPosZ + d);
+ World->TouchChunk(ChunkPosX + i, ChunkPosZ - d);
} // for i
} // for d
}
@@ -499,8 +515,8 @@ void cClientHandle::StreamChunk(int a_ChunkX, int a_ChunkZ)
{
{
cCSLock Lock(m_CSChunkLists);
- m_LoadedChunks.push_back(cChunkCoords(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ));
- m_ChunksToSend.push_back(cChunkCoords(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ));
+ m_LoadedChunks.push_back(cChunkCoords(a_ChunkX, a_ChunkZ));
+ m_ChunksToSend.push_back(cChunkCoords(a_ChunkX, a_ChunkZ));
}
World->SendChunkTo(a_ChunkX, a_ChunkZ, this);
}
@@ -1061,7 +1077,7 @@ void cClientHandle::HandleBlockDigStarted(int a_BlockX, int a_BlockY, int a_Bloc
(m_Player->GetWorld()->GetBlock(a_BlockX, a_BlockY, a_BlockZ) != E_BLOCK_FIRE)
)
{
- // Players can't destroy blocks with a Sword in the hand.
+ // Players can't destroy blocks with a sword in the hand.
return;
}
@@ -1132,6 +1148,12 @@ void cClientHandle::HandleBlockDigFinished(int a_BlockX, int a_BlockY, int a_Blo
FinishDigAnimation();
+ if (!m_Player->IsGameModeCreative() && (a_OldBlock == E_BLOCK_BEDROCK))
+ {
+ Kick("You can't break a bedrock!");
+ return;
+ }
+
cWorld * World = m_Player->GetWorld();
cItemHandler * ItemHandler = cItemHandler::GetItemHandler(m_Player->GetEquippedItem());
@@ -1190,50 +1212,61 @@ void cClientHandle::FinishDigAnimation()
void cClientHandle::HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, const cItem & a_HeldItem)
{
+ // TODO: Rewrite this function
+
LOGD("HandleRightClick: {%d, %d, %d}, face %d, HeldItem: %s",
a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, ItemToFullString(a_HeldItem).c_str()
);
cWorld * World = m_Player->GetWorld();
+ bool AreRealCoords = (Vector3d(a_BlockX, a_BlockY, a_BlockZ) - m_Player->GetPosition()).Length() <= 5;
if (
(a_BlockFace != BLOCK_FACE_NONE) && // The client is interacting with a specific block
- (
- (Diff(m_Player->GetPosX(), (double)a_BlockX) > 6) || // The block is too far away
- (Diff(m_Player->GetPosY(), (double)a_BlockY) > 6) ||
- (Diff(m_Player->GetPosZ(), (double)a_BlockZ) > 6)
- )
+ IsValidBlock(a_HeldItem.m_ItemType) &&
+ !AreRealCoords
)
{
AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace);
- World->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, m_Player);
- if (a_BlockY < cChunkDef::Height - 1)
+ if ((a_BlockX != -1) && (a_BlockY >= 0) && (a_BlockZ != -1))
{
- World->SendBlockTo(a_BlockX, a_BlockY + 1, a_BlockZ, m_Player); // 2 block high things
- }
- if (a_BlockY > 0)
- {
- World->SendBlockTo(a_BlockX, a_BlockY - 1, a_BlockZ, m_Player); // 2 block high things
+ World->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, m_Player);
+ if (a_BlockY < cChunkDef::Height - 1)
+ {
+ World->SendBlockTo(a_BlockX, a_BlockY + 1, a_BlockZ, m_Player); // 2 block high things
+ }
+ if (a_BlockY > 0)
+ {
+ World->SendBlockTo(a_BlockX, a_BlockY - 1, a_BlockZ, m_Player); // 2 block high things
+ }
}
m_Player->GetInventory().SendEquippedSlot();
return;
}
+ if (!AreRealCoords)
+ {
+ a_BlockFace = BLOCK_FACE_NONE;
+ }
+
cPluginManager * PlgMgr = cRoot::Get()->GetPluginManager();
if (PlgMgr->CallHookPlayerRightClick(*m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ))
{
// A plugin doesn't agree with the action, replace the block on the client and quit:
- cChunkInterface ChunkInterface(World->GetChunkMap());
- BLOCKTYPE BlockType = World->GetBlock(a_BlockX, a_BlockY, a_BlockZ);
- cBlockHandler * BlockHandler = cBlockInfo::GetHandler(BlockType);
- BlockHandler->OnCancelRightClick(ChunkInterface, *World, m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace);
-
- if (a_BlockFace != BLOCK_FACE_NONE)
+ if (AreRealCoords)
{
- AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace);
- World->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, m_Player);
- World->SendBlockTo(a_BlockX, a_BlockY + 1, a_BlockZ, m_Player); // 2 block high things
- m_Player->GetInventory().SendEquippedSlot();
+ cChunkInterface ChunkInterface(World->GetChunkMap());
+ BLOCKTYPE BlockType = World->GetBlock(a_BlockX, a_BlockY, a_BlockZ);
+ cBlockHandler * BlockHandler = cBlockInfo::GetHandler(BlockType);
+ BlockHandler->OnCancelRightClick(ChunkInterface, *World, m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace);
+
+ if (a_BlockFace != BLOCK_FACE_NONE)
+ {
+ AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace);
+ World->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, m_Player);
+ World->SendBlockTo(a_BlockX, a_BlockY + 1, a_BlockZ, m_Player); // 2 block high things
+ m_Player->GetInventory().SendEquippedSlot();
+ }
}
return;
}
@@ -1266,22 +1299,25 @@ void cClientHandle::HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, e
return;
}
- BLOCKTYPE BlockType;
- NIBBLETYPE BlockMeta;
- World->GetBlockTypeMeta(a_BlockX, a_BlockY, a_BlockZ, BlockType, BlockMeta);
- cBlockHandler * BlockHandler = cBlockInfo::GetHandler(BlockType);
-
- if (BlockHandler->IsUseable() && !m_Player->IsCrouched())
+ if (AreRealCoords)
{
- if (PlgMgr->CallHookPlayerUsingBlock(*m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, BlockType, BlockMeta))
+ BLOCKTYPE BlockType;
+ NIBBLETYPE BlockMeta;
+ World->GetBlockTypeMeta(a_BlockX, a_BlockY, a_BlockZ, BlockType, BlockMeta);
+ cBlockHandler * BlockHandler = cBlockInfo::GetHandler(BlockType);
+
+ if (BlockHandler->IsUseable() && !m_Player->IsCrouched())
{
- // A plugin doesn't agree with using the block, abort
+ if (PlgMgr->CallHookPlayerUsingBlock(*m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, BlockType, BlockMeta))
+ {
+ // A plugin doesn't agree with using the block, abort
+ return;
+ }
+ cChunkInterface ChunkInterface(World->GetChunkMap());
+ BlockHandler->OnUse(ChunkInterface, *World, m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ);
+ PlgMgr->CallHookPlayerUsedBlock(*m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, BlockType, BlockMeta);
return;
}
- cChunkInterface ChunkInterface(World->GetChunkMap());
- BlockHandler->OnUse(ChunkInterface, *World, m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ);
- PlgMgr->CallHookPlayerUsedBlock(*m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, BlockType, BlockMeta);
- return;
}
short EquippedDamage = Equipped.m_ItemDamage;
@@ -1445,8 +1481,20 @@ void cClientHandle::HandlePlaceBlock(int a_BlockX, int a_BlockY, int a_BlockZ, e
cChunkInterface ChunkInterface(World->GetChunkMap());
NewBlock->OnPlacedByPlayer(ChunkInterface, *World, m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, BlockType, BlockMeta);
- // Step sound with 0.8f pitch is used as block placement sound
- World->BroadcastSoundEffect(NewBlock->GetStepSound(), (double)a_BlockX, (double)a_BlockY, (double)a_BlockZ, 1.0f, 0.8f);
+ AString PlaceSound = cBlockInfo::GetPlaceSound(BlockType);
+ float Volume = 1.0f, Pitch = 0.8f;
+ if (PlaceSound == "dig.metal")
+ {
+ Pitch = 1.2f;
+ PlaceSound = "dig.stone";
+ }
+ else if (PlaceSound == "random.anvil_land")
+ {
+ Volume = 0.65f;
+ }
+
+ World->BroadcastSoundEffect(PlaceSound, a_BlockX + 0.5, a_BlockY + 0.5, a_BlockZ + 0.5, Volume, Pitch);
+
cRoot::Get()->GetPluginManager()->CallHookPlayerPlacedBlock(*m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, BlockType, BlockMeta);
}
@@ -2298,18 +2346,18 @@ void cClientHandle::SendInventorySlot(char a_WindowID, short a_SlotNum, const cI
-void cClientHandle::SendMapColumn(int a_ID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length)
+void cClientHandle::SendMapColumn(int a_ID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length, unsigned int m_Scale)
{
- m_Protocol->SendMapColumn(a_ID, a_X, a_Y, a_Colors, a_Length);
+ m_Protocol->SendMapColumn(a_ID, a_X, a_Y, a_Colors, a_Length, m_Scale);
}
-void cClientHandle::SendMapDecorators(int a_ID, const cMapDecoratorList & a_Decorators)
+void cClientHandle::SendMapDecorators(int a_ID, const cMapDecoratorList & a_Decorators, unsigned int m_Scale)
{
- m_Protocol->SendMapDecorators(a_ID, a_Decorators);
+ m_Protocol->SendMapDecorators(a_ID, a_Decorators, m_Scale);
}
@@ -2325,9 +2373,9 @@ void cClientHandle::SendMapInfo(int a_ID, unsigned int a_Scale)
-void cClientHandle::SendParticleEffect(const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmmount)
+void cClientHandle::SendParticleEffect(const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmount)
{
- m_Protocol->SendParticleEffect(a_ParticleName, a_SrcX, a_SrcY, a_SrcZ, a_OffsetX, a_OffsetY, a_OffsetZ, a_ParticleData, a_ParticleAmmount);
+ m_Protocol->SendParticleEffect(a_ParticleName, a_SrcX, a_SrcY, a_SrcZ, a_OffsetX, a_OffsetY, a_OffsetZ, a_ParticleData, a_ParticleAmount);
}
@@ -2369,9 +2417,45 @@ void cClientHandle::SendPlayerAbilities()
-void cClientHandle::SendPlayerListItem(const AString & a_PlayerName, bool a_IsOnline, short a_Ping)
+void cClientHandle::SendPlayerListAddPlayer(const cPlayer & a_Player)
+{
+ m_Protocol->SendPlayerListAddPlayer(a_Player);
+}
+
+
+
+
+
+void cClientHandle::SendPlayerListRemovePlayer(const cPlayer & a_Player)
+{
+ m_Protocol->SendPlayerListRemovePlayer(a_Player);
+}
+
+
+
+
+
+void cClientHandle::SendPlayerListUpdateGameMode(const cPlayer & a_Player)
{
- m_Protocol->SendPlayerListItem(a_PlayerName, a_IsOnline, a_Ping);
+ m_Protocol->SendPlayerListUpdateGameMode(a_Player);
+}
+
+
+
+
+
+void cClientHandle::SendPlayerListUpdatePing(const cPlayer & a_Player)
+{
+ m_Protocol->SendPlayerListUpdatePing(a_Player);
+}
+
+
+
+
+
+void cClientHandle::SendPlayerListUpdateDisplayName(const cPlayer & a_Player, const AString & a_OldListName)
+{
+ m_Protocol->SendPlayerListUpdateDisplayName(a_Player, a_OldListName);
}
@@ -2732,7 +2816,7 @@ bool cClientHandle::HasPluginChannel(const AString & a_PluginChannel)
-bool cClientHandle::WantsSendChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ)
+bool cClientHandle::WantsSendChunk(int a_ChunkX, int a_ChunkZ)
{
if (m_State >= csDestroying)
{
@@ -2740,7 +2824,7 @@ bool cClientHandle::WantsSendChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ)
}
cCSLock Lock(m_CSChunkLists);
- return (std::find(m_ChunksToSend.begin(), m_ChunksToSend.end(), cChunkCoords(a_ChunkX, a_ChunkY, a_ChunkZ)) != m_ChunksToSend.end());
+ return (std::find(m_ChunksToSend.begin(), m_ChunksToSend.end(), cChunkCoords(a_ChunkX, a_ChunkZ)) != m_ChunksToSend.end());
}
@@ -2756,9 +2840,9 @@ void cClientHandle::AddWantedChunk(int a_ChunkX, int a_ChunkZ)
LOGD("Adding chunk [%d, %d] to wanted chunks for client %p", a_ChunkX, a_ChunkZ, this);
cCSLock Lock(m_CSChunkLists);
- if (std::find(m_ChunksToSend.begin(), m_ChunksToSend.end(), cChunkCoords(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ)) == m_ChunksToSend.end())
+ if (std::find(m_ChunksToSend.begin(), m_ChunksToSend.end(), cChunkCoords(a_ChunkX, a_ChunkZ)) == m_ChunksToSend.end())
{
- m_ChunksToSend.push_back(cChunkCoords(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ));
+ m_ChunksToSend.push_back(cChunkCoords(a_ChunkX, a_ChunkZ));
}
}
@@ -2856,11 +2940,27 @@ void cClientHandle::SocketClosed(void)
-void cClientHandle::HandleEnchantItem(Byte & WindowID, Byte & Enchantment)
+void cClientHandle::HandleEnchantItem(Byte & a_WindowID, Byte & a_Enchantment)
{
- cEnchantingWindow * Window = (cEnchantingWindow*)m_Player->GetWindow();
+ if (a_Enchantment > 2)
+ {
+ LOGWARNING("%s attempt to crash the server with invalid enchanting selection!", GetUsername().c_str());
+ Kick("Invalid enchanting!");
+ return;
+ }
+
+ if (
+ (m_Player->GetWindow() == NULL) ||
+ (m_Player->GetWindow()->GetWindowID() != a_WindowID) ||
+ (m_Player->GetWindow()->GetWindowType() != cWindow::wtEnchantment)
+ )
+ {
+ return;
+ }
+
+ cEnchantingWindow * Window = (cEnchantingWindow*) m_Player->GetWindow();
cItem Item = *Window->m_SlotArea->GetSlot(0, *m_Player);
- int BaseEnchantmentLevel = Window->GetPropertyValue(Enchantment);
+ int BaseEnchantmentLevel = Window->GetPropertyValue(a_Enchantment);
if (Item.EnchantByXPLevels(BaseEnchantmentLevel))
{
diff --git a/src/ClientHandle.h b/src/ClientHandle.h
index 529ee4555..b91c3722c 100644
--- a/src/ClientHandle.h
+++ b/src/ClientHandle.h
@@ -62,17 +62,29 @@ public:
cClientHandle(const cSocket * a_Socket, int a_ViewDistance);
virtual ~cClientHandle();
- const AString & GetIPString(void) const { return m_IPString; }
+ const AString & GetIPString(void) const { return m_IPString; } // tolua_export
+
+ /** Sets the IP string that the client is using. Overrides the IP string that was read from the socket.
+ Used mainly by BungeeCord compatibility code. */
+ void SetIPString(const AString & a_IPString) { m_IPString = a_IPString; }
cPlayer * GetPlayer(void) { return m_Player; } // tolua_export
/** Returns the player's UUID, as used by the protocol, in the short form (no dashes) */
const AString & GetUUID(void) const { return m_UUID; } // tolua_export
- void SetUUID(const AString & a_UUID) { m_UUID = a_UUID; }
+ /** Sets the player's UUID, as used by the protocol. Short UUID form (no dashes) is expected.
+ Used mainly by BungeeCord compatibility code - when authenticating is done on the BungeeCord server
+ and the results are passed to MCS running in offline mode. */
+ void SetUUID(const AString & a_UUID) { ASSERT(a_UUID.size() == 32); m_UUID = a_UUID; }
const Json::Value & GetProperties(void) const { return m_Properties; }
+ /** Sets the player's properties, such as skin image and signature.
+ Used mainly by BungeeCord compatibility code - property querying is done on the BungeeCord server
+ and the results are passed to MCS running in offline mode. */
+ void SetProperties(const Json::Value & a_Properties) { m_Properties = a_Properties; }
+
/** Generates an UUID based on the username stored for this client, and stores it in the m_UUID member.
This is used for the offline (non-auth) mode, when there's no UUID source.
Each username generates a unique and constant UUID, so that when the player reconnects with the same name, their UUID is the same.
@@ -122,73 +134,77 @@ public:
// The following functions send the various packets:
// (Please keep these alpha-sorted)
- void SendAttachEntity (const cEntity & a_Entity, const cEntity * a_Vehicle);
- void SendBlockAction (int a_BlockX, int a_BlockY, int a_BlockZ, char a_Byte1, char a_Byte2, BLOCKTYPE a_BlockType);
- void SendBlockBreakAnim (int a_EntityID, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Stage);
- void SendBlockChange (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); // tolua_export
- void SendBlockChanges (int a_ChunkX, int a_ChunkZ, const sSetBlockVector & a_Changes);
- void SendChat (const AString & a_Message, eMessageType a_ChatPrefix, const AString & a_AdditionalData = "");
- void SendChat (const cCompositeChat & a_Message);
- void SendChunkData (int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer);
- void SendCollectEntity (const cEntity & a_Entity, const cPlayer & a_Player);
- void SendDestroyEntity (const cEntity & a_Entity);
- void SendDisconnect (const AString & a_Reason);
- void SendEditSign (int a_BlockX, int a_BlockY, int a_BlockZ);
- void SendEntityEffect (const cEntity & a_Entity, int a_EffectID, int a_Amplifier, short a_Duration);
- void SendEntityEquipment (const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item);
- void SendEntityHeadLook (const cEntity & a_Entity);
- void SendEntityLook (const cEntity & a_Entity);
- void SendEntityMetadata (const cEntity & a_Entity);
- void SendEntityProperties (const cEntity & a_Entity);
- void SendEntityRelMove (const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ);
- void SendEntityRelMoveLook (const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ);
- void SendEntityStatus (const cEntity & a_Entity, char a_Status);
- void SendEntityVelocity (const cEntity & a_Entity);
- void SendExplosion (double a_BlockX, double a_BlockY, double a_BlockZ, float a_Radius, const cVector3iArray & a_BlocksAffected, const Vector3d & a_PlayerMotion);
- void SendGameMode (eGameMode a_GameMode);
- void SendHealth (void);
- void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item);
- void SendMapColumn (int a_ID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length);
- void SendMapDecorators (int a_ID, const cMapDecoratorList & a_Decorators);
- void SendMapInfo (int a_ID, unsigned int a_Scale);
- void SendPaintingSpawn (const cPainting & a_Painting);
- void SendPickupSpawn (const cPickup & a_Pickup);
- void SendEntityAnimation (const cEntity & a_Entity, char a_Animation); // tolua_export
- void SendParticleEffect (const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmmount);
- void SendPlayerAbilities (void);
- void SendPlayerListItem (const AString & a_PlayerName, bool a_IsOnline, short a_Ping = 0);
- void SendPlayerMaxSpeed (void); ///< Informs the client of the maximum player speed (1.6.1+)
- void SendPlayerMoveLook (void);
- void SendPlayerPosition (void);
- void SendPlayerSpawn (const cPlayer & a_Player);
- void SendPluginMessage (const AString & a_Channel, const AString & a_Message); // Exported in ManualBindings.cpp
- void SendRemoveEntityEffect (const cEntity & a_Entity, int a_EffectID);
- void SendRespawn (eDimension a_Dimension, bool a_ShouldIgnoreDimensionChecks = false);
- void SendExperience (void);
- void SendExperienceOrb (const cExpOrb & a_ExpOrb);
- void SendScoreboardObjective (const AString & a_Name, const AString & a_DisplayName, Byte a_Mode);
- void SendScoreUpdate (const AString & a_Objective, const AString & a_Player, cObjective::Score a_Score, Byte a_Mode);
- void SendDisplayObjective (const AString & a_Objective, cScoreboard::eDisplaySlot a_Display);
- void SendSoundEffect (const AString & a_SoundName, double a_X, double a_Y, double a_Z, float a_Volume, float a_Pitch); // tolua_export
- void SendSoundParticleEffect (int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data);
- void SendSpawnFallingBlock (const cFallingBlock & a_FallingBlock);
- void SendSpawnMob (const cMonster & a_Mob);
- void SendSpawnObject (const cEntity & a_Entity, char a_ObjectType, int a_ObjectData, Byte a_Yaw, Byte a_Pitch);
- void SendSpawnVehicle (const cEntity & a_Vehicle, char a_VehicleType, char a_VehicleSubType = 0);
- void SendStatistics (const cStatManager & a_Manager);
- void SendTabCompletionResults(const AStringVector & a_Results);
- void SendTeleportEntity (const cEntity & a_Entity);
- void SendThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ);
- void SendTimeUpdate (Int64 a_WorldAge, Int64 a_TimeOfDay, bool a_DoDaylightCycle); // tolua_export
- void SendUnloadChunk (int a_ChunkX, int a_ChunkZ);
- void SendUpdateBlockEntity (cBlockEntity & a_BlockEntity);
- void SendUpdateSign (int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4);
- void SendUseBed (const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ);
- void SendWeather (eWeather a_Weather);
- void SendWholeInventory (const cWindow & a_Window);
- void SendWindowClose (const cWindow & a_Window);
- void SendWindowOpen (const cWindow & a_Window);
- void SendWindowProperty (const cWindow & a_Window, int a_Property, int a_Value);
+ void SendAttachEntity (const cEntity & a_Entity, const cEntity * a_Vehicle);
+ void SendBlockAction (int a_BlockX, int a_BlockY, int a_BlockZ, char a_Byte1, char a_Byte2, BLOCKTYPE a_BlockType);
+ void SendBlockBreakAnim (int a_EntityID, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Stage);
+ void SendBlockChange (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); // tolua_export
+ void SendBlockChanges (int a_ChunkX, int a_ChunkZ, const sSetBlockVector & a_Changes);
+ void SendChat (const AString & a_Message, eMessageType a_ChatPrefix, const AString & a_AdditionalData = "");
+ void SendChat (const cCompositeChat & a_Message);
+ void SendChunkData (int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer);
+ void SendCollectEntity (const cEntity & a_Entity, const cPlayer & a_Player);
+ void SendDestroyEntity (const cEntity & a_Entity);
+ void SendDisconnect (const AString & a_Reason);
+ void SendEditSign (int a_BlockX, int a_BlockY, int a_BlockZ);
+ void SendEntityEffect (const cEntity & a_Entity, int a_EffectID, int a_Amplifier, short a_Duration);
+ void SendEntityEquipment (const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item);
+ void SendEntityHeadLook (const cEntity & a_Entity);
+ void SendEntityLook (const cEntity & a_Entity);
+ void SendEntityMetadata (const cEntity & a_Entity);
+ void SendEntityProperties (const cEntity & a_Entity);
+ void SendEntityRelMove (const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ);
+ void SendEntityRelMoveLook (const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ);
+ void SendEntityStatus (const cEntity & a_Entity, char a_Status);
+ void SendEntityVelocity (const cEntity & a_Entity);
+ void SendExplosion (double a_BlockX, double a_BlockY, double a_BlockZ, float a_Radius, const cVector3iArray & a_BlocksAffected, const Vector3d & a_PlayerMotion);
+ void SendGameMode (eGameMode a_GameMode);
+ void SendHealth (void);
+ void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item);
+ void SendMapColumn (int a_ID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length, unsigned int m_Scale);
+ void SendMapDecorators (int a_ID, const cMapDecoratorList & a_Decorators, unsigned int m_Scale);
+ void SendMapInfo (int a_ID, unsigned int a_Scale);
+ void SendPaintingSpawn (const cPainting & a_Painting);
+ void SendPickupSpawn (const cPickup & a_Pickup);
+ void SendEntityAnimation (const cEntity & a_Entity, char a_Animation); // tolua_export
+ void SendParticleEffect (const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmount);
+ void SendPlayerAbilities (void);
+ void SendPlayerListAddPlayer (const cPlayer & a_Player);
+ void SendPlayerListRemovePlayer (const cPlayer & a_Player);
+ void SendPlayerListUpdateGameMode (const cPlayer & a_Player);
+ void SendPlayerListUpdatePing (const cPlayer & a_Player);
+ void SendPlayerListUpdateDisplayName(const cPlayer & a_Player, const AString & a_OldListName);
+ void SendPlayerMaxSpeed (void); ///< Informs the client of the maximum player speed (1.6.1+)
+ void SendPlayerMoveLook (void);
+ void SendPlayerPosition (void);
+ void SendPlayerSpawn (const cPlayer & a_Player);
+ void SendPluginMessage (const AString & a_Channel, const AString & a_Message); // Exported in ManualBindings.cpp
+ void SendRemoveEntityEffect (const cEntity & a_Entity, int a_EffectID);
+ void SendRespawn (eDimension a_Dimension, bool a_ShouldIgnoreDimensionChecks = false);
+ void SendExperience (void);
+ void SendExperienceOrb (const cExpOrb & a_ExpOrb);
+ void SendScoreboardObjective (const AString & a_Name, const AString & a_DisplayName, Byte a_Mode);
+ void SendScoreUpdate (const AString & a_Objective, const AString & a_Player, cObjective::Score a_Score, Byte a_Mode);
+ void SendDisplayObjective (const AString & a_Objective, cScoreboard::eDisplaySlot a_Display);
+ void SendSoundEffect (const AString & a_SoundName, double a_X, double a_Y, double a_Z, float a_Volume, float a_Pitch); // tolua_export
+ void SendSoundParticleEffect (int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data);
+ void SendSpawnFallingBlock (const cFallingBlock & a_FallingBlock);
+ void SendSpawnMob (const cMonster & a_Mob);
+ void SendSpawnObject (const cEntity & a_Entity, char a_ObjectType, int a_ObjectData, Byte a_Yaw, Byte a_Pitch);
+ void SendSpawnVehicle (const cEntity & a_Vehicle, char a_VehicleType, char a_VehicleSubType = 0);
+ void SendStatistics (const cStatManager & a_Manager);
+ void SendTabCompletionResults (const AStringVector & a_Results);
+ void SendTeleportEntity (const cEntity & a_Entity);
+ void SendThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ);
+ void SendTimeUpdate (Int64 a_WorldAge, Int64 a_TimeOfDay, bool a_DoDaylightCycle); // tolua_export
+ void SendUnloadChunk (int a_ChunkX, int a_ChunkZ);
+ void SendUpdateBlockEntity (cBlockEntity & a_BlockEntity);
+ void SendUpdateSign (int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4);
+ void SendUseBed (const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ);
+ void SendWeather (eWeather a_Weather);
+ void SendWholeInventory (const cWindow & a_Window);
+ void SendWindowClose (const cWindow & a_Window);
+ void SendWindowOpen (const cWindow & a_Window);
+ void SendWindowProperty (const cWindow & a_Window, int a_Property, int a_Value);
// tolua_begin
const AString & GetUsername(void) const;
@@ -209,7 +225,7 @@ public:
// tolua_end
/** Returns true if the client wants the chunk specified to be sent (in m_ChunksToSend) */
- bool WantsSendChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ);
+ bool WantsSendChunk(int a_ChunkX, int a_ChunkZ);
/** Adds the chunk specified to the list of chunks wanted for sending (m_ChunksToSend) */
void AddWantedChunk(int a_ChunkX, int a_ChunkZ);
@@ -269,7 +285,7 @@ public:
void RemoveFromWorld(void);
/** Called when the player will enchant a Item */
- void HandleEnchantItem(Byte & WindowID, Byte & Enchantment);
+ void HandleEnchantItem(Byte & a_WindowID, Byte & a_Enchantment);
private:
diff --git a/src/CompositeChat.cpp b/src/CompositeChat.cpp
index 0d339021e..d1eb0b852 100644
--- a/src/CompositeChat.cpp
+++ b/src/CompositeChat.cpp
@@ -5,6 +5,7 @@
#include "Globals.h"
#include "CompositeChat.h"
+#include "ClientHandle.h"
@@ -399,6 +400,183 @@ void cCompositeChat::AddStyle(AString & a_Style, const AString & a_AddStyle)
+AString cCompositeChat::CreateJsonString(bool a_ShouldUseChatPrefixes) const
+{
+ Json::Value msg;
+ msg["text"] = cClientHandle::FormatMessageType(a_ShouldUseChatPrefixes, GetMessageType(), GetAdditionalMessageTypeData()); // The client crashes without this field being present
+ const cCompositeChat::cParts & Parts = GetParts();
+ for (cCompositeChat::cParts::const_iterator itr = Parts.begin(), end = Parts.end(); itr != end; ++itr)
+ {
+ Json::Value Part;
+ switch ((*itr)->m_PartType)
+ {
+ case cCompositeChat::ptText:
+ {
+ Part["text"] = (*itr)->m_Text;
+ AddChatPartStyle(Part, (*itr)->m_Style);
+ break;
+ }
+
+ case cCompositeChat::ptClientTranslated:
+ {
+ const cCompositeChat::cClientTranslatedPart & p = (const cCompositeChat::cClientTranslatedPart &)**itr;
+ Part["translate"] = p.m_Text;
+ Json::Value With;
+ for (AStringVector::const_iterator itrW = p.m_Parameters.begin(), endW = p.m_Parameters.end(); itrW != endW; ++itr)
+ {
+ With.append(*itrW);
+ }
+ if (!p.m_Parameters.empty())
+ {
+ Part["with"] = With;
+ }
+ AddChatPartStyle(Part, p.m_Style);
+ break;
+ }
+
+ case cCompositeChat::ptUrl:
+ {
+ const cCompositeChat::cUrlPart & p = (const cCompositeChat::cUrlPart &)**itr;
+ Part["text"] = p.m_Text;
+ Json::Value Url;
+ Url["action"] = "open_url";
+ Url["value"] = p.m_Url;
+ Part["clickEvent"] = Url;
+ AddChatPartStyle(Part, p.m_Style);
+ break;
+ }
+
+ case cCompositeChat::ptSuggestCommand:
+ case cCompositeChat::ptRunCommand:
+ {
+ const cCompositeChat::cCommandPart & p = (const cCompositeChat::cCommandPart &)**itr;
+ Part["text"] = p.m_Text;
+ Json::Value Cmd;
+ Cmd["action"] = (p.m_PartType == cCompositeChat::ptRunCommand) ? "run_command" : "suggest_command";
+ Cmd["value"] = p.m_Command;
+ Part["clickEvent"] = Cmd;
+ AddChatPartStyle(Part, p.m_Style);
+ break;
+ }
+
+ case cCompositeChat::ptShowAchievement:
+ {
+ const cCompositeChat::cShowAchievementPart & p = (const cCompositeChat::cShowAchievementPart &)**itr;
+ Part["translate"] = "chat.type.achievement";
+
+ Json::Value Ach;
+ Ach["action"] = "show_achievement";
+ Ach["value"] = p.m_Text;
+
+ Json::Value AchColourAndName;
+ AchColourAndName["color"] = "green";
+ AchColourAndName["translate"] = p.m_Text;
+ AchColourAndName["hoverEvent"] = Ach;
+
+ Json::Value Extra;
+ Extra.append(AchColourAndName);
+
+ Json::Value Name;
+ Name["text"] = p.m_PlayerName;
+
+ Json::Value With;
+ With.append(Name);
+ With.append(Extra);
+
+ Part["with"] = With;
+ AddChatPartStyle(Part, p.m_Style);
+ break;
+ }
+ }
+ msg["extra"].append(Part);
+ } // for itr - Parts[]
+
+ return msg.toStyledString();
+}
+
+
+
+
+
+void cCompositeChat::AddChatPartStyle(Json::Value & a_Value, const AString & a_PartStyle) const
+{
+ size_t len = a_PartStyle.length();
+ for (size_t i = 0; i < len; i++)
+ {
+ switch (a_PartStyle[i])
+ {
+ case 'b':
+ {
+ // bold
+ a_Value["bold"] = Json::Value(true);
+ break;
+ }
+
+ case 'i':
+ {
+ // italic
+ a_Value["italic"] = Json::Value(true);
+ break;
+ }
+
+ case 'u':
+ {
+ // Underlined
+ a_Value["underlined"] = Json::Value(true);
+ break;
+ }
+
+ case 's':
+ {
+ // strikethrough
+ a_Value["strikethrough"] = Json::Value(true);
+ break;
+ }
+
+ case 'o':
+ {
+ // obfuscated
+ a_Value["obfuscated"] = Json::Value(true);
+ break;
+ }
+
+ case '@':
+ {
+ // Color, specified by the next char:
+ i++;
+ if (i >= len)
+ {
+ // String too short, didn't contain a color
+ break;
+ }
+ switch (a_PartStyle[i])
+ {
+ case '0': a_Value["color"] = Json::Value("black"); break;
+ case '1': a_Value["color"] = Json::Value("dark_blue"); break;
+ case '2': a_Value["color"] = Json::Value("dark_green"); break;
+ case '3': a_Value["color"] = Json::Value("dark_aqua"); break;
+ case '4': a_Value["color"] = Json::Value("dark_red"); break;
+ case '5': a_Value["color"] = Json::Value("dark_purple"); break;
+ case '6': a_Value["color"] = Json::Value("gold"); break;
+ case '7': a_Value["color"] = Json::Value("gray"); break;
+ case '8': a_Value["color"] = Json::Value("dark_gray"); break;
+ case '9': a_Value["color"] = Json::Value("blue"); break;
+ case 'a': a_Value["color"] = Json::Value("green"); break;
+ case 'b': a_Value["color"] = Json::Value("aqua"); break;
+ case 'c': a_Value["color"] = Json::Value("red"); break;
+ case 'd': a_Value["color"] = Json::Value("light_purple"); break;
+ case 'e': a_Value["color"] = Json::Value("yellow"); break;
+ case 'f': a_Value["color"] = Json::Value("white"); break;
+ } // switch (color)
+ } // case '@'
+ } // switch (Style[i])
+ } // for i - a_PartStyle[]
+}
+
+
+
+
+
////////////////////////////////////////////////////////////////////////////////
// cCompositeChat::cBasePart:
diff --git a/src/CompositeChat.h b/src/CompositeChat.h
index 2dc21b98f..369eed196 100644
--- a/src/CompositeChat.h
+++ b/src/CompositeChat.h
@@ -4,6 +4,7 @@
// Declares the cCompositeChat class used to wrap a chat message with multiple parts (text, url, cmd)
#include "Defines.h"
+#include "json/json.h"
@@ -189,6 +190,8 @@ public:
Used for older protocols that don't support composite chat
and for console-logging. */
AString ExtractText(void) const;
+
+ AString CreateJsonString(bool a_ShouldUseChatPrefixes = true) const;
// tolua_end
@@ -197,6 +200,9 @@ public:
/** Converts the MessageType to a LogLevel value.
Used by the logging bindings when logging a cCompositeChat object. */
static cLogger::eLogLevel MessageTypeToLogLevel(eMessageType a_MessageType);
+
+ /** Adds the chat part's style (represented by the part's stylestring) into the Json object. */
+ void AddChatPartStyle(Json::Value & a_Value, const AString & a_PartStyle) const;
protected:
/** All the parts that */
diff --git a/src/Defines.h b/src/Defines.h
index 78c58034e..6355b75b4 100644
--- a/src/Defines.h
+++ b/src/Defines.h
@@ -115,12 +115,14 @@ enum eGameMode
eGameMode_Survival = 0,
eGameMode_Creative = 1,
eGameMode_Adventure = 2,
+ eGameMode_Spectator = 3,
// Easier-to-use synonyms:
gmNotSet = eGameMode_NotSet,
gmSurvival = eGameMode_Survival,
gmCreative = eGameMode_Creative,
gmAdventure = eGameMode_Adventure,
+ gmSpectator = eGameMode_Spectator,
// These two are used to check GameMode for validity when converting from integers.
gmMax, // Gets automatically assigned
diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp
index 89d1cffa1..8ef24828e 100644
--- a/src/Entities/Entity.cpp
+++ b/src/Entities/Entity.cpp
@@ -135,7 +135,7 @@ const char * cEntity::GetParentClass(void) const
bool cEntity::Initialize(cWorld & a_World)
{
- if (cPluginManager::Get()->CallHookSpawningEntity(a_World, *this))
+ if (cPluginManager::Get()->CallHookSpawningEntity(a_World, *this) && !IsPlayer())
{
return false;
}
@@ -260,7 +260,7 @@ void cEntity::TakeDamage(eDamageType a_DamageType, cEntity * a_Attacker, int a_R
void cEntity::SetYawFromSpeed(void)
{
const double EPS = 0.0000001;
- if ((abs(m_Speed.x) < EPS) && (abs(m_Speed.z) < EPS))
+ if ((std::abs(m_Speed.x) < EPS) && (std::abs(m_Speed.z) < EPS))
{
// atan2() may overflow or is undefined, pick any number
SetYaw(0);
@@ -277,7 +277,7 @@ void cEntity::SetPitchFromSpeed(void)
{
const double EPS = 0.0000001;
double xz = sqrt(m_Speed.x * m_Speed.x + m_Speed.z * m_Speed.z); // Speed XZ-plane component
- if ((abs(xz) < EPS) && (abs(m_Speed.y) < EPS))
+ if ((std::abs(xz) < EPS) && (std::abs(m_Speed.y) < EPS))
{
// atan2() may overflow or is undefined, pick any number
SetPitch(0);
@@ -342,6 +342,7 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI)
a_TDI.FinalDamage += (int)ceil(2.5 * SmiteLevel);
break;
}
+ default: break;
}
}
}
@@ -387,7 +388,7 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI)
case cMonster::mtGhast:
case cMonster::mtZombiePigman:
case cMonster::mtMagmaCube:
- {
+ {
break;
};
default: StartBurning(BurnTicks * 20);
@@ -417,7 +418,7 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI)
}
if (!Player->IsOnGround())
- {
+ {
if ((a_TDI.DamageType == dtAttack) || (a_TDI.DamageType == dtArrowAttack))
{
a_TDI.FinalDamage += 2;
@@ -927,12 +928,13 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk)
float fallspeed;
if (IsBlockWater(BlockIn))
{
- fallspeed = m_Gravity * a_Dt / 3; // Fall 3x slower in water.
+ fallspeed = m_Gravity * a_Dt / 3; // Fall 3x slower in water
+ ApplyFriction(NextSpeed, 0.7, a_Dt);
}
else if (BlockIn == E_BLOCK_COBWEB)
{
NextSpeed.y *= 0.05; // Reduce overall falling speed
- fallspeed = 0; // No falling.
+ fallspeed = 0; // No falling
}
else
{
@@ -941,20 +943,9 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk)
}
NextSpeed.y += fallspeed;
}
-
- // Friction
- if (NextSpeed.SqrLength() > 0.0004f)
+ else
{
- NextSpeed.x *= 0.7f / (1 + a_Dt);
- if (fabs(NextSpeed.x) < 0.05)
- {
- NextSpeed.x = 0;
- }
- NextSpeed.z *= 0.7f / (1 + a_Dt);
- if (fabs(NextSpeed.z) < 0.05)
- {
- NextSpeed.z = 0;
- }
+ ApplyFriction(NextSpeed, 0.7, a_Dt);
}
// Adjust X and Z speed for COBWEB temporary. This speed modification should be handled inside block handlers since we
@@ -1025,7 +1016,7 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk)
if (Tracer.HitNormal.y != 0.f) NextSpeed.y = 0.f;
if (Tracer.HitNormal.z != 0.f) NextSpeed.z = 0.f;
- if (Tracer.HitNormal.y == 1) // Hit BLOCK_FACE_YP, we are on the ground
+ if (Tracer.HitNormal.y == 1.f) // Hit BLOCK_FACE_YP, we are on the ground
{
m_bOnGround = true;
}
@@ -1060,6 +1051,27 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk)
+void cEntity::ApplyFriction(Vector3d & a_Speed, double a_SlowdownMultiplier, float a_Dt)
+{
+ if (a_Speed.SqrLength() > 0.0004f)
+ {
+ a_Speed.x *= a_SlowdownMultiplier / (1 + a_Dt);
+ if (fabs(a_Speed.x) < 0.05)
+ {
+ a_Speed.x = 0;
+ }
+ a_Speed.z *= a_SlowdownMultiplier / (1 + a_Dt);
+ if (fabs(a_Speed.z) < 0.05)
+ {
+ a_Speed.z = 0;
+ }
+ }
+}
+
+
+
+
+
void cEntity::TickBurning(cChunk & a_Chunk)
{
// Remember the current burning state:
@@ -1949,7 +1961,7 @@ void cEntity::SteerVehicle(float a_Forward, float a_Sideways)
{
return;
}
- if ((a_Forward != 0) || (a_Sideways != 0))
+ if ((a_Forward != 0.f) || (a_Sideways != 0.f))
{
m_AttachedTo->HandleSpeedFromAttachee(a_Forward, a_Sideways);
}
diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h
index 774cdb062..3fa7e80c1 100644
--- a/src/Entities/Entity.h
+++ b/src/Entities/Entity.h
@@ -535,6 +535,12 @@ protected:
virtual void Destroyed(void) {} // Called after the entity has been destroyed
+ /** Applies friction to an entity
+ @param a_Speed The speed vector to apply changes to
+ @param a_SlowdownMultiplier The factor to reduce the speed by
+ */
+ static void ApplyFriction(Vector3d & a_Speed, double a_SlowdownMultiplier, float a_Dt);
+
/** Called in each tick to handle air-related processing i.e. drowning */
virtual void HandleAir(void);
diff --git a/src/Entities/EntityEffect.cpp b/src/Entities/EntityEffect.cpp
index 3e28392f4..98c5d23b4 100644
--- a/src/Entities/EntityEffect.cpp
+++ b/src/Entities/EntityEffect.cpp
@@ -34,14 +34,14 @@ cEntityEffect::eType cEntityEffect::GetPotionEffectType(short a_ItemDamage)
case 0x08: return cEntityEffect::effWeakness;
case 0x09: return cEntityEffect::effStrength;
case 0x0a: return cEntityEffect::effSlowness;
+ case 0x0b: return cEntityEffect::effJumpBoost;
case 0x0c: return cEntityEffect::effInstantDamage;
case 0x0d: return cEntityEffect::effWaterBreathing;
case 0x0e: return cEntityEffect::effInvisibility;
-
+
// No effect potions
case 0x00:
case 0x07:
- case 0x0b: // Will be potion of leaping in 1.8
case 0x0f:
{
break;
@@ -96,6 +96,7 @@ int cEntityEffect::GetPotionEffectDuration(short a_ItemDamage)
base = 1800;
break;
}
+ default: break;
}
// If potion is level II, half the duration. If not, stays the same
@@ -233,6 +234,92 @@ void cEntityEffect::OnTick(cPawn & a_Target)
////////////////////////////////////////////////////////////////////////////////
+// cEntityEffectSpeed:
+
+void cEntityEffectSpeed::OnActivate(cPawn & a_Target)
+{
+ if (a_Target.IsMob())
+ {
+ cMonster * Mob = (cMonster*) &a_Target;
+ Mob->SetRelativeWalkSpeed(Mob->GetRelativeWalkSpeed() + 0.2 * m_Intensity);
+ }
+ else if (a_Target.IsPlayer())
+ {
+ cPlayer * Player = (cPlayer*) &a_Target;
+ Player->SetNormalMaxSpeed(Player->GetNormalMaxSpeed() + 0.2 * m_Intensity);
+ Player->SetSprintingMaxSpeed(Player->GetSprintingMaxSpeed() + 0.26 * m_Intensity);
+ Player->SetFlyingMaxSpeed(Player->GetFlyingMaxSpeed() + 0.2 * m_Intensity);
+ }
+}
+
+
+
+
+
+void cEntityEffectSpeed::OnDeactivate(cPawn & a_Target)
+{
+ if (a_Target.IsMob())
+ {
+ cMonster * Mob = (cMonster*) &a_Target;
+ Mob->SetRelativeWalkSpeed(Mob->GetRelativeWalkSpeed() - 0.2 * m_Intensity);
+ }
+ else if (a_Target.IsPlayer())
+ {
+ cPlayer * Player = (cPlayer*) &a_Target;
+ Player->SetNormalMaxSpeed(Player->GetNormalMaxSpeed() - 0.2 * m_Intensity);
+ Player->SetSprintingMaxSpeed(Player->GetSprintingMaxSpeed() - 0.26 * m_Intensity);
+ Player->SetFlyingMaxSpeed(Player->GetFlyingMaxSpeed() - 0.2 * m_Intensity);
+ }
+}
+
+
+
+
+
+////////////////////////////////////////////////////////////////////////////////
+// cEntityEffectSlowness:
+
+void cEntityEffectSlowness::OnActivate(cPawn & a_Target)
+{
+ if (a_Target.IsMob())
+ {
+ cMonster * Mob = (cMonster*) &a_Target;
+ Mob->SetRelativeWalkSpeed(Mob->GetRelativeWalkSpeed() - 0.15 * m_Intensity);
+ }
+ else if (a_Target.IsPlayer())
+ {
+ cPlayer * Player = (cPlayer*) &a_Target;
+ Player->SetNormalMaxSpeed(Player->GetNormalMaxSpeed() - 0.15 * m_Intensity);
+ Player->SetSprintingMaxSpeed(Player->GetSprintingMaxSpeed() - 0.195 * m_Intensity);
+ Player->SetFlyingMaxSpeed(Player->GetFlyingMaxSpeed() - 0.15 * m_Intensity);
+ }
+}
+
+
+
+
+
+void cEntityEffectSlowness::OnDeactivate(cPawn & a_Target)
+{
+ if (a_Target.IsMob())
+ {
+ cMonster * Mob = (cMonster*) &a_Target;
+ Mob->SetRelativeWalkSpeed(Mob->GetRelativeWalkSpeed() + 0.15 * m_Intensity);
+ }
+ else if (a_Target.IsPlayer())
+ {
+ cPlayer * Player = (cPlayer*) &a_Target;
+ Player->SetNormalMaxSpeed(Player->GetNormalMaxSpeed() + 0.15 * m_Intensity);
+ Player->SetSprintingMaxSpeed(Player->GetSprintingMaxSpeed() + 0.195 * m_Intensity);
+ Player->SetFlyingMaxSpeed(Player->GetFlyingMaxSpeed() + 0.15 * m_Intensity);
+ }
+}
+
+
+
+
+
+////////////////////////////////////////////////////////////////////////////////
// cEntityEffectInstantHealth:
void cEntityEffectInstantHealth::OnActivate(cPawn & a_Target)
diff --git a/src/Entities/EntityEffect.h b/src/Entities/EntityEffect.h
index 47c298f57..7cf9cd3d5 100644
--- a/src/Entities/EntityEffect.h
+++ b/src/Entities/EntityEffect.h
@@ -137,6 +137,10 @@ public:
super(a_Duration, a_Intensity, a_DistanceModifier)
{
}
+
+ virtual void OnActivate(cPawn & a_Target) override;
+
+ virtual void OnDeactivate(cPawn & a_Target) override;
};
@@ -152,6 +156,10 @@ public:
super(a_Duration, a_Intensity, a_DistanceModifier)
{
}
+
+ virtual void OnActivate(cPawn & a_Target) override;
+
+ virtual void OnDeactivate(cPawn & a_Target) override;
};
diff --git a/src/Entities/ExpBottleEntity.cpp b/src/Entities/ExpBottleEntity.cpp
index 202dde942..ee142a5a2 100644
--- a/src/Entities/ExpBottleEntity.cpp
+++ b/src/Entities/ExpBottleEntity.cpp
@@ -19,9 +19,26 @@ cExpBottleEntity::cExpBottleEntity(cEntity * a_Creator, double a_X, double a_Y,
void cExpBottleEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace)
{
+ Break(a_HitPos);
+}
+
+
+
+
+
+void cExpBottleEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos)
+{
+ Break(a_HitPos);
+}
+
+
+
+
+
+void cExpBottleEntity::Break(const Vector3d &a_HitPos)
+{
// Spawn an experience orb with a reward between 3 and 11.
m_World->BroadcastSoundParticleEffect(2002, POSX_TOINT, POSY_TOINT, POSZ_TOINT, 0);
m_World->SpawnExperienceOrb(GetPosX(), GetPosY(), GetPosZ(), 3 + m_World->GetTickRandomNumber(8));
-
Destroy();
}
diff --git a/src/Entities/ExpBottleEntity.h b/src/Entities/ExpBottleEntity.h
index d62a84469..d36110f97 100644
--- a/src/Entities/ExpBottleEntity.h
+++ b/src/Entities/ExpBottleEntity.h
@@ -29,5 +29,10 @@ protected:
// cProjectileEntity overrides:
virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override;
+ virtual void OnHitEntity (cEntity & a_EntityHit, const Vector3d & a_HitPos) override;
+
+ /** Breaks the bottle, fires its particle effects and sounds
+ @param a_HitPos The position where the bottle will break */
+ void Break(const Vector3d &a_HitPos);
}; // tolua_export
diff --git a/src/Entities/ItemFrame.cpp b/src/Entities/ItemFrame.cpp
index 3ccb95998..f512324eb 100644
--- a/src/Entities/ItemFrame.cpp
+++ b/src/Entities/ItemFrame.cpp
@@ -28,7 +28,7 @@ void cItemFrame::OnRightClicked(cPlayer & a_Player)
{
// Item not empty, rotate, clipping values to zero to three inclusive
m_Rotation++;
- if (m_Rotation >= 4)
+ if (m_Rotation >= 8)
{
m_Rotation = 0;
}
diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp
index 5fabbb542..2df64d5c1 100644
--- a/src/Entities/Minecart.cpp
+++ b/src/Entities/Minecart.cpp
@@ -13,6 +13,7 @@
#include "Player.h"
#include "../BoundingBox.h"
+#define NO_SPEED 0.0
#define MAX_SPEED 8
#define MAX_SPEED_NEGATIVE -MAX_SPEED
@@ -220,7 +221,7 @@ void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt)
bool BlckCol = TestBlockCollision(a_RailMeta), EntCol = TestEntityCollision(a_RailMeta);
if (EntCol || BlckCol) return;
- if (GetSpeedZ() != 0) // Don't do anything if cart is stationary
+ if (GetSpeedZ() != NO_SPEED) // Don't do anything if cart is stationary
{
if (GetSpeedZ() > 0)
{
@@ -239,13 +240,13 @@ void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt)
{
SetYaw(180);
SetPosY(floor(GetPosY()) + 0.55);
- SetSpeedY(0);
- SetSpeedZ(0);
+ SetSpeedY(NO_SPEED);
+ SetSpeedZ(NO_SPEED);
bool BlckCol = TestBlockCollision(a_RailMeta), EntCol = TestEntityCollision(a_RailMeta);
if (EntCol || BlckCol) return;
- if (GetSpeedX() != 0)
+ if (GetSpeedX() != NO_SPEED)
{
if (GetSpeedX() > 0)
{
@@ -305,9 +306,9 @@ void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt)
case E_META_RAIL_ASCEND_XM: // ASCEND EAST
{
SetYaw(180);
- SetSpeedZ(0);
+ SetSpeedZ(NO_SPEED);
- if (GetSpeedX() >= 0)
+ if (GetSpeedX() >= NO_SPEED)
{
if (GetSpeedX() <= MAX_SPEED)
{
@@ -424,9 +425,9 @@ void cMinecart::HandlePoweredRailPhysics(NIBBLETYPE a_RailMeta)
bool BlckCol = TestBlockCollision(a_RailMeta), EntCol = TestEntityCollision(a_RailMeta);
if (EntCol || BlckCol) return;
- if (GetSpeedZ() != 0)
+ if (GetSpeedZ() != NO_SPEED)
{
- if (GetSpeedZ() > 0)
+ if (GetSpeedZ() > NO_SPEED)
{
AddSpeedZ(AccelDecelSpeed);
}
@@ -441,15 +442,15 @@ void cMinecart::HandlePoweredRailPhysics(NIBBLETYPE a_RailMeta)
{
SetYaw(180);
SetPosY(floor(GetPosY()) + 0.55);
- SetSpeedY(0);
- SetSpeedZ(0);
+ SetSpeedY(NO_SPEED);
+ SetSpeedZ(NO_SPEED);
bool BlckCol = TestBlockCollision(a_RailMeta), EntCol = TestEntityCollision(a_RailMeta);
if (EntCol || BlckCol) return;
- if (GetSpeedX() != 0)
+ if (GetSpeedX() != NO_SPEED)
{
- if (GetSpeedX() > 0)
+ if (GetSpeedX() > NO_SPEED)
{
AddSpeedX(AccelDecelSpeed);
}
@@ -463,9 +464,9 @@ void cMinecart::HandlePoweredRailPhysics(NIBBLETYPE a_RailMeta)
case E_META_RAIL_ASCEND_XM: // ASCEND EAST
{
SetYaw(180);
- SetSpeedZ(0);
+ SetSpeedZ(NO_SPEED);
- if (GetSpeedX() >= 0)
+ if (GetSpeedX() >= NO_SPEED)
{
if (GetSpeedX() <= MAX_SPEED)
{
@@ -483,9 +484,9 @@ void cMinecart::HandlePoweredRailPhysics(NIBBLETYPE a_RailMeta)
case E_META_RAIL_ASCEND_XP: // ASCEND WEST
{
SetYaw(180);
- SetSpeedZ(0);
+ SetSpeedZ(NO_SPEED);
- if (GetSpeedX() > 0)
+ if (GetSpeedX() > NO_SPEED)
{
AddSpeedX(AccelDecelSpeed);
SetSpeedY(GetSpeedX());
@@ -503,9 +504,9 @@ void cMinecart::HandlePoweredRailPhysics(NIBBLETYPE a_RailMeta)
case E_META_RAIL_ASCEND_ZM: // ASCEND NORTH
{
SetYaw(270);
- SetSpeedX(0);
+ SetSpeedX(NO_SPEED);
- if (GetSpeedZ() >= 0)
+ if (GetSpeedZ() >= NO_SPEED)
{
if (GetSpeedZ() <= MAX_SPEED)
{
@@ -523,9 +524,9 @@ void cMinecart::HandlePoweredRailPhysics(NIBBLETYPE a_RailMeta)
case E_META_RAIL_ASCEND_ZP: // ASCEND SOUTH
{
SetYaw(270);
- SetSpeedX(0);
+ SetSpeedX(NO_SPEED);
- if (GetSpeedZ() > 0)
+ if (GetSpeedZ() > NO_SPEED)
{
AddSpeedZ(AccelDecelSpeed);
SetSpeedY(GetSpeedZ());
@@ -576,7 +577,7 @@ void cMinecart::SnapToRail(NIBBLETYPE a_RailMeta)
case E_META_RAIL_ASCEND_XP:
case E_META_RAIL_XM_XP:
{
- SetSpeedZ(0);
+ SetSpeedZ(NO_SPEED);
SetPosZ(floor(GetPosZ()) + 0.5);
break;
}
@@ -584,7 +585,7 @@ void cMinecart::SnapToRail(NIBBLETYPE a_RailMeta)
case E_META_RAIL_ASCEND_ZP:
case E_META_RAIL_ZM_ZP:
{
- SetSpeedX(0);
+ SetSpeedX(NO_SPEED);
SetPosX(floor(GetPosX()) + 0.5);
break;
}
@@ -593,12 +594,12 @@ void cMinecart::SnapToRail(NIBBLETYPE a_RailMeta)
{
if (GetPosZ() > floor(GetPosZ()) + 0.5)
{
- if (GetSpeedZ() > 0)
+ if (GetSpeedZ() > NO_SPEED)
{
SetSpeedX(-GetSpeedZ() * 0.7);
}
- SetSpeedZ(0);
+ SetSpeedZ(NO_SPEED);
SetPosZ(floor(GetPosZ()) + 0.5);
}
else if (GetPosX() > floor(GetPosX()) + 0.5)
@@ -608,82 +609,82 @@ void cMinecart::SnapToRail(NIBBLETYPE a_RailMeta)
SetSpeedZ(-GetSpeedX() * 0.7);
}
- SetSpeedX(0);
+ SetSpeedX(NO_SPEED);
SetPosX(floor(GetPosX()) + 0.5);
}
- SetSpeedY(0);
+ SetSpeedY(NO_SPEED);
break;
}
case E_META_RAIL_CURVED_ZM_XP:
{
if (GetPosZ() > floor(GetPosZ()) + 0.5)
{
- if (GetSpeedZ() > 0)
+ if (GetSpeedZ() > NO_SPEED)
{
SetSpeedX(GetSpeedZ() * 0.7);
}
- SetSpeedZ(0);
+ SetSpeedZ(NO_SPEED);
SetPosZ(floor(GetPosZ()) + 0.5);
}
else if (GetPosX() < floor(GetPosX()) + 0.5)
{
- if (GetSpeedX() < 0)
+ if (GetSpeedX() < NO_SPEED)
{
SetSpeedZ(GetSpeedX() * 0.7);
}
- SetSpeedX(0);
+ SetSpeedX(NO_SPEED);
SetPosX(floor(GetPosX()) + 0.5);
}
- SetSpeedY(0);
+ SetSpeedY(NO_SPEED);
break;
}
case E_META_RAIL_CURVED_ZP_XM:
{
if (GetPosZ() < floor(GetPosZ()) + 0.5)
{
- if (GetSpeedZ() < 0)
+ if (GetSpeedZ() < NO_SPEED)
{
SetSpeedX(GetSpeedZ() * 0.7);
}
- SetSpeedZ(0);
+ SetSpeedZ(NO_SPEED);
SetPosZ(floor(GetPosZ()) + 0.5);
}
else if (GetPosX() > floor(GetPosX()) + 0.5)
{
- if (GetSpeedX() > 0)
+ if (GetSpeedX() > NO_SPEED)
{
SetSpeedZ(GetSpeedX() * 0.7);
}
- SetSpeedX(0);
+ SetSpeedX(NO_SPEED);
SetPosX(floor(GetPosX()) + 0.5);
}
- SetSpeedY(0);
+ SetSpeedY(NO_SPEED);
break;
}
case E_META_RAIL_CURVED_ZP_XP:
{
if (GetPosZ() < floor(GetPosZ()) + 0.5)
{
- if (GetSpeedZ() < 0)
+ if (GetSpeedZ() < NO_SPEED)
{
SetSpeedX(-GetSpeedZ() * 0.7);
}
- SetSpeedZ(0);
+ SetSpeedZ(NO_SPEED);
SetPosZ(floor(GetPosZ()) + 0.5);
}
else if (GetPosX() < floor(GetPosX()) + 0.5)
{
- if (GetSpeedX() < 0)
+ if (GetSpeedX() < NO_SPEED)
{
SetSpeedZ(-GetSpeedX() * 0.7);
}
- SetSpeedX(0);
+ SetSpeedX(NO_SPEED);
SetPosX(floor(GetPosX()) + 0.5);
}
SetSpeedY(0);
@@ -876,7 +877,7 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta)
Vector3d Distance = MinecartCollisionCallback.GetCollidedEntityPosition() - Vector3d(GetPosX(), 0, GetPosZ());
// Prevent division by small numbers
- if (abs(Distance.z) < 0.001)
+ if (std::abs(Distance.z) < 0.001)
{
Distance.z = 0.001;
}
@@ -925,7 +926,7 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta)
Vector3d Distance = MinecartCollisionCallback.GetCollidedEntityPosition() - Vector3d(GetPosX(), 0, GetPosZ());
// Prevent division by small numbers
- if (abs(Distance.z) < 0.001)
+ if (std::abs(Distance.z) < 0.001)
{
Distance.z = 0.001;
}
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index a2934d036..1bdb752c5 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -267,7 +267,7 @@ void cPlayer::Tick(float a_Dt, cChunk & a_Chunk)
cTimer t1;
if (m_LastPlayerListTime + PLAYER_LIST_TIME_MS <= t1.GetNowTime())
{
- m_World->SendPlayerList(this);
+ m_World->BroadcastPlayerListUpdatePing(*this);
m_LastPlayerListTime = t1.GetNowTime();
}
@@ -452,6 +452,11 @@ void cPlayer::CancelChargingBow(void)
void cPlayer::SetTouchGround(bool a_bTouchGround)
{
+ if (IsGameModeSpectator()) // You can fly through the ground in Spectator
+ {
+ return;
+ }
+
m_bTouchGround = a_bTouchGround;
if (!m_bTouchGround)
@@ -586,7 +591,7 @@ bool cPlayer::Feed(int a_Food, double a_Saturation)
void cPlayer::AddFoodExhaustion(double a_Exhaustion)
{
- if (!IsGameModeCreative())
+ if (!(IsGameModeCreative() || IsGameModeSpectator()))
{
m_FoodExhaustionLevel = std::min(m_FoodExhaustionLevel + a_Exhaustion, 40.0);
}
@@ -628,15 +633,6 @@ void cPlayer::FinishEating(void)
return;
}
ItemHandler->OnFoodEaten(m_World, this, &Item);
-
- GetInventory().RemoveOneEquippedItem();
-
- // if the food is mushroom soup, return a bowl to the inventory
- if (Item.m_ItemType == E_ITEM_MUSHROOM_SOUP)
- {
- cItem EmptyBowl(E_ITEM_BOWL);
- GetInventory().AddItem(EmptyBowl, true, true);
- }
}
@@ -820,7 +816,7 @@ void cPlayer::SetCustomName(const AString & a_CustomName)
{
return;
}
- m_World->BroadcastPlayerListItem(GetTabListName(), false, 0); // Remove old tab-list entry
+ AString OldCustomName = m_CustomName;
m_CustomName = a_CustomName;
if (m_CustomName.length() > 16)
@@ -828,8 +824,8 @@ void cPlayer::SetCustomName(const AString & a_CustomName)
m_CustomName = m_CustomName.substr(0, 16);
}
+ m_World->BroadcastPlayerListUpdateDisplayName(*this, m_CustomName);
m_World->BroadcastSpawnEntity(*this, m_ClientHandle);
- m_World->BroadcastPlayerListItem(GetTabListName(), true, GetClientHandle()->GetPing());
}
@@ -855,9 +851,9 @@ bool cPlayer::DoTakeDamage(TakeDamageInfo & a_TDI)
{
if ((a_TDI.DamageType != dtInVoid) && (a_TDI.DamageType != dtPlugin))
{
- if (IsGameModeCreative())
+ if (IsGameModeCreative() || IsGameModeSpectator())
{
- // No damage / health in creative mode if not void or plugin damage
+ // No damage / health in creative or spectator mode if not void or plugin damage
return false;
}
}
@@ -1075,6 +1071,14 @@ bool cPlayer::IsGameModeAdventure(void) const
+bool cPlayer::IsGameModeSpectator(void) const
+{
+ return (m_GameMode == gmSpectator) || // Either the player is explicitly in Spectator
+ ((m_GameMode == gmNotSet) && m_World->IsGameModeSpectator()); // or they inherit from the world and the world is Adventure
+}
+
+
+
void cPlayer::SetTeam(cTeam * a_Team)
{
@@ -1190,11 +1194,13 @@ void cPlayer::SetGameMode(eGameMode a_GameMode)
m_GameMode = a_GameMode;
m_ClientHandle->SendGameMode(a_GameMode);
- if (!IsGameModeCreative())
+ if (!(IsGameModeCreative() || IsGameModeSpectator()))
{
SetFlying(false);
SetCanFly(false);
}
+
+ m_World->BroadcastPlayerListUpdateGameMode(*this);
}
@@ -1372,6 +1378,7 @@ void cPlayer::MoveTo( const Vector3d & a_NewPos)
void cPlayer::SetVisible(bool a_bVisible)
{
+ // Need to Check if the player or other players are in gamemode spectator, but will break compatibility
if (a_bVisible && !m_bVisible) // Make visible
{
m_bVisible = true;
@@ -1466,7 +1473,7 @@ AString cPlayer::GetColor(void) const
-AString cPlayer::GetTabListName(void) const
+AString cPlayer::GetPlayerListName(void) const
{
const AString & Color = GetColor();
@@ -1554,6 +1561,11 @@ void cPlayer::TossPickup(const cItem & a_Item)
void cPlayer::TossItems(const cItems & a_Items)
{
+ if (IsGameModeSpectator()) // Players can't toss items in spectator
+ {
+ return;
+ }
+
m_Stats.AddValue(statItemsDropped, (StatValue)a_Items.Size());
double vX = 0, vY = 0, vZ = 0;
@@ -1715,7 +1727,11 @@ bool cPlayer::LoadFromFile(const AString & a_FileName, cWorldPtr & a_World)
cEnderChestEntity::LoadFromJson(root["enderchestinventory"], m_EnderChestContents);
m_LoadedWorldName = root.get("world", "world").asString();
- a_World = cRoot::Get()->GetWorld(GetLoadedWorldName(), true);
+ a_World = cRoot::Get()->GetWorld(GetLoadedWorldName(), false);
+ if (a_World == NULL)
+ {
+ a_World = cRoot::Get()->GetDefaultWorld();
+ }
m_LastBedPos.x = root.get("SpawnX", a_World->GetSpawnX()).asInt();
m_LastBedPos.y = root.get("SpawnY", a_World->GetSpawnY()).asInt();
@@ -1836,7 +1852,7 @@ bool cPlayer::SaveToDisk()
void cPlayer::UseEquippedItem(int a_Amount)
{
- if (IsGameModeCreative()) // No damage in creative
+ if (IsGameModeCreative() || IsGameModeSpectator()) // No damage in creative or spectator
{
return;
}
diff --git a/src/Entities/Player.h b/src/Entities/Player.h
index 49380c776..ffd0b7e03 100644
--- a/src/Entities/Player.h
+++ b/src/Entities/Player.h
@@ -171,6 +171,9 @@ public:
/** Returns true if the player is in Adventure mode, either explicitly, or by inheriting from current world */
bool IsGameModeAdventure(void) const;
+ /** Returns true if the player is in Spectator mode, either explicitly, or by inheriting from current world */
+ bool IsGameModeSpectator(void) const;
+
AString GetIP(void) const { return m_IP; } // tolua_export
/** Returns the associated team, NULL if none */
@@ -251,8 +254,8 @@ public:
The returned value either is empty, or includes the cChatColor::Delimiter. */
AString GetColor(void) const;
- /** Returns the name that is used in the tablist. */
- AString GetTabListName(void) const;
+ /** Returns the name that is used in the playerlist. */
+ AString GetPlayerListName(void) const;
/** tosses the item in the selected hotbar slot */
void TossEquippedItem(char a_Amount = 1);
diff --git a/src/Generating/BioGen.cpp b/src/Generating/BioGen.cpp
index 8fad9f5c9..217ca8f80 100644
--- a/src/Generating/BioGen.cpp
+++ b/src/Generating/BioGen.cpp
@@ -13,72 +13,6 @@
////////////////////////////////////////////////////////////////////////////////
-// cBiomeGen:
-
-cBiomeGen * cBiomeGen::CreateBiomeGen(cIniFile & a_IniFile, int a_Seed, bool & a_CacheOffByDefault)
-{
- AString BiomeGenName = a_IniFile.GetValueSet("Generator", "BiomeGen", "");
- if (BiomeGenName.empty())
- {
- LOGWARN("[Generator] BiomeGen value not set in world.ini, using \"MultiStepMap\".");
- BiomeGenName = "MultiStepMap";
- }
-
- cBiomeGen * res = NULL;
- a_CacheOffByDefault = false;
- if (NoCaseCompare(BiomeGenName, "constant") == 0)
- {
- res = new cBioGenConstant;
- a_CacheOffByDefault = true; // we're generating faster than a cache would retrieve data :)
- }
- else if (NoCaseCompare(BiomeGenName, "checkerboard") == 0)
- {
- res = new cBioGenCheckerboard;
- a_CacheOffByDefault = true; // we're (probably) generating faster than a cache would retrieve data
- }
- else if (NoCaseCompare(BiomeGenName, "voronoi") == 0)
- {
- res = new cBioGenVoronoi(a_Seed);
- }
- else if (NoCaseCompare(BiomeGenName, "distortedvoronoi") == 0)
- {
- res = new cBioGenDistortedVoronoi(a_Seed);
- }
- else if (NoCaseCompare(BiomeGenName, "twolevel") == 0)
- {
- res = new cBioGenTwoLevel(a_Seed);
- }
- else
- {
- if (NoCaseCompare(BiomeGenName, "multistepmap") != 0)
- {
- LOGWARNING("Unknown BiomeGen \"%s\", using \"MultiStepMap\" instead.", BiomeGenName.c_str());
- }
- res = new cBioGenMultiStepMap(a_Seed);
-
- /*
- // Performance-testing:
- LOGINFO("Measuring performance of cBioGenMultiStepMap...");
- clock_t BeginTick = clock();
- for (int x = 0; x < 5000; x++)
- {
- cChunkDef::BiomeMap Biomes;
- res->GenBiomes(x * 5, x * 5, Biomes);
- }
- clock_t Duration = clock() - BeginTick;
- LOGINFO("cBioGenMultiStepMap for 5000 chunks took %d ticks (%.02f sec)", Duration, (double)Duration / CLOCKS_PER_SEC);
- //*/
- }
- res->InitializeBiomeGen(a_IniFile);
-
- return res;
-}
-
-
-
-
-
-////////////////////////////////////////////////////////////////////////////////
// cBioGenConstant:
void cBioGenConstant::GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap)
@@ -151,7 +85,7 @@ void cBioGenCache::GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a
LOGD("BioGenCache: %d hits, %d misses, saved %.2f %%", m_NumHits, m_NumMisses, 100.0 * m_NumHits / (m_NumHits + m_NumMisses));
LOGD("BioGenCache: Avg cache chain length: %.2f", (float)m_TotalChain / m_NumHits);
}
-
+
for (int i = 0; i < m_CacheSize; i++)
{
if (
@@ -208,6 +142,59 @@ void cBioGenCache::InitializeBiomeGen(cIniFile & a_IniFile)
+////////////////////////////////////////////////////////////////////////////////
+// cBioGenMulticache:
+
+cBioGenMulticache::cBioGenMulticache(cBiomeGen * a_BioGenToCache, size_t a_CacheSize, size_t a_CachesLength) :
+ m_CachesLength(a_CachesLength)
+{
+ m_Caches.reserve(a_CachesLength);
+ for (size_t i = 0; i < a_CachesLength; i++)
+ {
+ m_Caches.push_back(new cBioGenCache(a_BioGenToCache, a_CacheSize));
+ }
+}
+
+
+
+
+
+cBioGenMulticache::~cBioGenMulticache()
+{
+ for (cBiomeGens::iterator it = m_Caches.begin(); it != m_Caches.end(); it++)
+ {
+ delete *it;
+ }
+}
+
+
+
+
+
+void cBioGenMulticache::GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap)
+{
+ const size_t coefficient = 3;
+ const size_t cacheIdx = ((size_t)a_ChunkX + coefficient * (size_t)a_ChunkZ) % m_CachesLength;
+
+ m_Caches[cacheIdx]->GenBiomes(a_ChunkX, a_ChunkZ, a_BiomeMap);
+}
+
+
+
+
+
+void cBioGenMulticache::InitializeBiomeGen(cIniFile & a_IniFile)
+{
+ for (cBiomeGens::iterator it = m_Caches.begin(); it != m_Caches.end(); it++)
+ {
+ cBiomeGen * tmp = *it;
+ tmp->InitializeBiomeGen(a_IniFile);
+ }
+}
+
+
+
+
////////////////////////////////////////////////////////////////////////////////
// cBiomeGenList:
@@ -349,8 +336,13 @@ void cBioGenVoronoi::GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap &
void cBioGenVoronoi::InitializeBiomeGen(cIniFile & a_IniFile)
{
super::InitializeBiomeGen(a_IniFile);
- m_Voronoi.SetCellSize(a_IniFile.GetValueSetI("Generator", "VoronoiCellSize", 64));
- InitializeBiomes (a_IniFile.GetValueSet ("Generator", "VoronoiBiomes", ""));
+ int CellSize = a_IniFile.GetValueSetI("Generator", "VoronoiCellSize", 128);
+ int JitterSize = a_IniFile.GetValueSetI("Generator", "VoronoiJitterSize", CellSize);
+ int OddRowOffset = a_IniFile.GetValueSetI("Generator", "VoronoiOddRowOffset", 0);
+ m_Voronoi.SetCellSize(CellSize);
+ m_Voronoi.SetJitterSize(JitterSize);
+ m_Voronoi.SetOddRowOffset(OddRowOffset);
+ InitializeBiomes(a_IniFile.GetValueSet ("Generator", "VoronoiBiomes", ""));
}
@@ -793,9 +785,10 @@ void cBioGenTwoLevel::GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap
{
for (int x = 0; x < cChunkDef::Width; x++)
{
- int MinDist1, MinDist2;
- int BiomeGroup = m_VoronoiLarge.GetValueAt(DistortX[x][z], DistortZ[x][z], MinDist1, MinDist2) / 7;
- int BiomeIdx = m_VoronoiSmall.GetValueAt(DistortX[x][z], DistortZ[x][z], MinDist1, MinDist2) / 11;
+ int SeedX, SeedZ, MinDist2;
+ int BiomeGroup = m_VoronoiLarge.GetValueAt(DistortX[x][z], DistortZ[x][z], SeedX, SeedZ, MinDist2) / 7;
+ int BiomeIdx = m_VoronoiSmall.GetValueAt(DistortX[x][z], DistortZ[x][z], SeedX, SeedZ, MinDist2) / 11;
+ int MinDist1 = (DistortX[x][z] - SeedX) * (DistortX[x][z] - SeedX) + (DistortZ[x][z] - SeedZ) * (DistortZ[x][z] - SeedZ);
cChunkDef::SetBiome(a_BiomeMap, x, z, SelectBiome(BiomeGroup, BiomeIdx, (MinDist1 < MinDist2 / 4) ? 0 : 1));
}
}
@@ -934,3 +927,69 @@ void cBioGenTwoLevel::InitializeBiomeGen(cIniFile & a_IniFile)
+
+////////////////////////////////////////////////////////////////////////////////
+// cBiomeGen:
+
+cBiomeGen * cBiomeGen::CreateBiomeGen(cIniFile & a_IniFile, int a_Seed, bool & a_CacheOffByDefault)
+{
+ AString BiomeGenName = a_IniFile.GetValueSet("Generator", "BiomeGen", "");
+ if (BiomeGenName.empty())
+ {
+ LOGWARN("[Generator] BiomeGen value not set in world.ini, using \"MultiStepMap\".");
+ BiomeGenName = "MultiStepMap";
+ }
+
+ cBiomeGen * res = NULL;
+ a_CacheOffByDefault = false;
+ if (NoCaseCompare(BiomeGenName, "constant") == 0)
+ {
+ res = new cBioGenConstant;
+ a_CacheOffByDefault = true; // we're generating faster than a cache would retrieve data :)
+ }
+ else if (NoCaseCompare(BiomeGenName, "checkerboard") == 0)
+ {
+ res = new cBioGenCheckerboard;
+ a_CacheOffByDefault = true; // we're (probably) generating faster than a cache would retrieve data
+ }
+ else if (NoCaseCompare(BiomeGenName, "voronoi") == 0)
+ {
+ res = new cBioGenVoronoi(a_Seed);
+ }
+ else if (NoCaseCompare(BiomeGenName, "distortedvoronoi") == 0)
+ {
+ res = new cBioGenDistortedVoronoi(a_Seed);
+ }
+ else if (NoCaseCompare(BiomeGenName, "twolevel") == 0)
+ {
+ res = new cBioGenTwoLevel(a_Seed);
+ }
+ else
+ {
+ if (NoCaseCompare(BiomeGenName, "multistepmap") != 0)
+ {
+ LOGWARNING("Unknown BiomeGen \"%s\", using \"MultiStepMap\" instead.", BiomeGenName.c_str());
+ }
+ res = new cBioGenMultiStepMap(a_Seed);
+
+ /*
+ // Performance-testing:
+ LOGINFO("Measuring performance of cBioGenMultiStepMap...");
+ clock_t BeginTick = clock();
+ for (int x = 0; x < 5000; x++)
+ {
+ cChunkDef::BiomeMap Biomes;
+ res->GenBiomes(x * 5, x * 5, Biomes);
+ }
+ clock_t Duration = clock() - BeginTick;
+ LOGINFO("cBioGenMultiStepMap for 5000 chunks took %d ticks (%.02f sec)", Duration, (double)Duration / CLOCKS_PER_SEC);
+ //*/
+ }
+ res->InitializeBiomeGen(a_IniFile);
+
+ return res;
+}
+
+
+
+
diff --git a/src/Generating/BioGen.h b/src/Generating/BioGen.h
index 227ec97d7..20d199611 100644
--- a/src/Generating/BioGen.h
+++ b/src/Generating/BioGen.h
@@ -80,6 +80,36 @@ protected:
+class cBioGenMulticache :
+ public cBiomeGen
+{
+
+ typedef cBiomeGen super;
+
+public:
+ /*
+ a_CacheSize defines the size of each singular cache
+ a_CachesLength defines how many caches are used for the multicache
+ */
+ cBioGenMulticache(cBiomeGen * a_BioGenToCache, size_t a_CacheSize, size_t a_CachesLength); // Doesn't take ownership of a_BioGenToCache
+ ~cBioGenMulticache();
+
+protected:
+ typedef std::vector<cBiomeGen *> cBiomeGens;
+
+
+ size_t m_CachesLength;
+ cBiomeGens m_Caches;
+
+
+ virtual void GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap) override;
+ virtual void InitializeBiomeGen(cIniFile & a_IniFile) override;
+};
+
+
+
+
+
/// Base class for generators that use a list of available biomes. This class takes care of the list.
class cBiomeGenList :
public cBiomeGen
diff --git a/src/Generating/Caves.cpp b/src/Generating/Caves.cpp
index 71154dff9..fc925a150 100644
--- a/src/Generating/Caves.cpp
+++ b/src/Generating/Caves.cpp
@@ -755,7 +755,7 @@ void cStructGenDualRidgeCaves::GenFinish(cChunkDesc & a_ChunkDesc)
float n2 = m_Noise2.CubicNoise3D(xx, yy, zz);
float n3 = m_Noise1.CubicNoise3D(xx * 4, yy * 4, zz * 4) / 4;
float n4 = m_Noise2.CubicNoise3D(xx * 4, yy * 4, zz * 4) / 4;
- if ((abs(n1 + n3) * abs(n2 + n4)) > m_Threshold)
+ if ((std::abs(n1 + n3) * std::abs(n2 + n4)) > m_Threshold)
{
a_ChunkDesc.SetBlockType(x, y, z, E_BLOCK_AIR);
}
diff --git a/src/Generating/ChunkGenerator.cpp b/src/Generating/ChunkGenerator.cpp
index a1188f984..d615456c1 100644
--- a/src/Generating/ChunkGenerator.cpp
+++ b/src/Generating/ChunkGenerator.cpp
@@ -52,10 +52,21 @@ bool cChunkGenerator::Start(cPluginInterface & a_PluginInterface, cChunkSink & a
m_PluginInterface = &a_PluginInterface;
m_ChunkSink = &a_ChunkSink;
- MTRand rnd;
- m_Seed = a_IniFile.GetValueSetI("Seed", "Seed", (int)rnd.randInt());
+ // Get the seed; create a new one and log it if not found in the INI file:
+ if (a_IniFile.HasValue("Seed", "Seed"))
+ {
+ m_Seed = a_IniFile.GetValueI("Seed", "Seed");
+ }
+ else
+ {
+ MTRand rnd;
+ m_Seed = rnd.randInt();
+ LOGINFO("Chosen a new random seed for world: %d", m_Seed);
+ a_IniFile.SetValueI("Seed", "Seed", m_Seed);
+ }
+
+ // Get the generator engine based on the INI file settings:
AString GeneratorName = a_IniFile.GetValueSet("Generator", "Generator", "Composable");
-
if (NoCaseCompare(GeneratorName, "Noise3D") == 0)
{
m_Generator = new cNoise3DGenerator(*this);
@@ -99,15 +110,17 @@ void cChunkGenerator::Stop(void)
-void cChunkGenerator::QueueGenerateChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ)
+void cChunkGenerator::QueueGenerateChunk(int a_ChunkX, int a_ChunkZ, bool a_ForceGenerate)
{
+ ASSERT(m_ChunkSink->IsChunkQueued(a_ChunkX, a_ChunkZ));
+
{
cCSLock Lock(m_CS);
// Check if it is already in the queue:
- for (cChunkCoordsList::iterator itr = m_Queue.begin(); itr != m_Queue.end(); ++itr)
+ for (cChunkCoordsWithBoolList::iterator itr = m_Queue.begin(); itr != m_Queue.end(); ++itr)
{
- if ((itr->m_ChunkX == a_ChunkX) && (itr->m_ChunkY == a_ChunkY) && (itr->m_ChunkZ == a_ChunkZ))
+ if ((itr->m_ChunkX == a_ChunkX) && (itr->m_ChunkZ == a_ChunkZ))
{
// Already in the queue, bail out
return;
@@ -119,7 +132,7 @@ void cChunkGenerator::QueueGenerateChunk(int a_ChunkX, int a_ChunkY, int a_Chunk
{
LOGWARN("WARNING: Adding chunk [%i, %i] to generation queue; Queue is too big! (" SIZE_T_FMT ")", a_ChunkX, a_ChunkZ, m_Queue.size());
}
- m_Queue.push_back(cChunkCoords(a_ChunkX, a_ChunkY, a_ChunkZ));
+ m_Queue.push_back(cChunkCoordsWithBool(a_ChunkX, a_ChunkZ, a_ForceGenerate));
}
m_Event.Set();
@@ -229,9 +242,9 @@ void cChunkGenerator::Execute(void)
continue;
}
- cChunkCoords coords = m_Queue.front(); // Get next coord from queue
- m_Queue.erase( m_Queue.begin()); // Remove coordinate from queue
+ cChunkCoordsWithBool coords = m_Queue.front(); // Get next coord from queue
bool SkipEnabled = (m_Queue.size() > QUEUE_SKIP_LIMIT);
+ m_Queue.erase(m_Queue.begin()); // Remove coordinate from queue
Lock.Unlock(); // Unlock ASAP
m_evtRemoved.Set();
@@ -245,8 +258,7 @@ void cChunkGenerator::Execute(void)
LastReportTick = clock();
}
- // Hack for regenerating chunks: if Y != 0, the chunk is considered invalid, even if it has its data set
- if ((coords.m_ChunkY == 0) && m_ChunkSink->IsChunkValid(coords.m_ChunkX, coords.m_ChunkZ))
+ if (!coords.m_ForceGenerate && m_ChunkSink->IsChunkValid(coords.m_ChunkX, coords.m_ChunkZ))
{
LOGD("Chunk [%d, %d] already generated, skipping generation", coords.m_ChunkX, coords.m_ChunkZ);
// Already generated, ignore request
@@ -259,8 +271,8 @@ void cChunkGenerator::Execute(void)
continue;
}
- LOGD("Generating chunk [%d, %d, %d]", coords.m_ChunkX, coords.m_ChunkY, coords.m_ChunkZ);
- DoGenerate(coords.m_ChunkX, coords.m_ChunkY, coords.m_ChunkZ);
+ LOGD("Generating chunk [%d, %d]", coords.m_ChunkX, coords.m_ChunkZ);
+ DoGenerate(coords.m_ChunkX, coords.m_ChunkZ);
NumChunksGenerated++;
} // while (!bStop)
@@ -269,11 +281,12 @@ void cChunkGenerator::Execute(void)
-void cChunkGenerator::DoGenerate(int a_ChunkX, int a_ChunkY, int a_ChunkZ)
+void cChunkGenerator::DoGenerate(int a_ChunkX, int a_ChunkZ)
{
ASSERT(m_PluginInterface != NULL);
ASSERT(m_ChunkSink != NULL);
-
+ ASSERT(m_ChunkSink->IsChunkQueued(a_ChunkX, a_ChunkZ));
+
cChunkDesc ChunkDesc(a_ChunkX, a_ChunkZ);
m_PluginInterface->CallHookChunkGenerating(ChunkDesc);
m_Generator->DoGenerate(a_ChunkX, a_ChunkZ, ChunkDesc);
diff --git a/src/Generating/ChunkGenerator.h b/src/Generating/ChunkGenerator.h
index 88d71f3f9..190d9e616 100644
--- a/src/Generating/ChunkGenerator.h
+++ b/src/Generating/ChunkGenerator.h
@@ -106,6 +106,10 @@ public:
If this callback returns false, the chunk is not generated.
*/
virtual bool HasChunkAnyClients(int a_ChunkX, int a_ChunkZ) = 0;
+
+ /** Called to check whether the specified chunk is in the queued state.
+ Currently used only in Debug-mode asserts. */
+ virtual bool IsChunkQueued(int a_ChunkX, int a_ChunkZ) = 0;
} ;
@@ -116,7 +120,7 @@ public:
void Stop(void);
/// Queues the chunk for generation; removes duplicate requests
- void QueueGenerateChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ);
+ void QueueGenerateChunk(int a_ChunkX, int a_ChunkZ, bool a_ForceGenerate);
/// Generates the biomes for the specified chunk (directly, not in a separate thread). Used by the world loader if biomes failed loading.
void GenerateBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap);
@@ -137,10 +141,10 @@ private:
int m_Seed;
- cCriticalSection m_CS;
- cChunkCoordsList m_Queue;
- cEvent m_Event; ///< Set when an item is added to the queue or the thread should terminate
- cEvent m_evtRemoved; ///< Set when an item is removed from the queue
+ cCriticalSection m_CS;
+ cChunkCoordsWithBoolList m_Queue;
+ cEvent m_Event; ///< Set when an item is added to the queue or the thread should terminate
+ cEvent m_evtRemoved; ///< Set when an item is removed from the queue
cGenerator * m_Generator; ///< The actual generator engine used to generate chunks
@@ -154,7 +158,7 @@ private:
// cIsThread override:
virtual void Execute(void) override;
- void DoGenerate(int a_ChunkX, int a_ChunkY, int a_ChunkZ);
+ void DoGenerate(int a_ChunkX, int a_ChunkZ);
};
diff --git a/src/Generating/ComposableGenerator.cpp b/src/Generating/ComposableGenerator.cpp
index 6f4007d24..69068d231 100644
--- a/src/Generating/ComposableGenerator.cpp
+++ b/src/Generating/ComposableGenerator.cpp
@@ -230,17 +230,29 @@ void cComposableGenerator::InitBiomeGen(cIniFile & a_IniFile)
// Add a cache, if requested:
int CacheSize = a_IniFile.GetValueSetI("Generator", "BiomeGenCacheSize", CacheOffByDefault ? 0 : 64);
- if (CacheSize > 0)
+
+ if (CacheSize <= 0)
+ {
+ return;
+ }
+
+ int MultiCacheLength = a_IniFile.GetValueSetI("Generator", "BiomeGenMultiCacheLength", 4);
+ if (CacheSize < 4)
+ {
+ LOGWARNING("Biomegen cache size set too low, would hurt performance instead of helping. Increasing from %d to %d",
+ CacheSize, 4
+ );
+ CacheSize = 4;
+ }
+ LOGD("Using a cache for biomegen of size %d.", CacheSize);
+ m_UnderlyingBiomeGen = m_BiomeGen;
+ if (MultiCacheLength > 0)
+ {
+ LOGD("Enabling multicache for biomegen of length %d.", MultiCacheLength);
+ m_BiomeGen = new cBioGenMulticache(m_UnderlyingBiomeGen, CacheSize, MultiCacheLength);
+ }
+ else
{
- if (CacheSize < 4)
- {
- LOGWARNING("Biomegen cache size set too low, would hurt performance instead of helping. Increasing from %d to %d",
- CacheSize, 4
- );
- CacheSize = 4;
- }
- LOGD("Using a cache for biomegen of size %d.", CacheSize);
- m_UnderlyingBiomeGen = m_BiomeGen;
m_BiomeGen = new cBioGenCache(m_UnderlyingBiomeGen, CacheSize);
}
}
diff --git a/src/Generating/Noise3DGenerator.cpp b/src/Generating/Noise3DGenerator.cpp
index eb816f564..c3ca30384 100644
--- a/src/Generating/Noise3DGenerator.cpp
+++ b/src/Generating/Noise3DGenerator.cpp
@@ -236,7 +236,7 @@ void cNoise3DGenerator::GenerateNoiseArray(int a_ChunkX, int a_ChunkZ, NOISE_DAT
m_Cubic.Generate2D(Height, DIM_X, DIM_Z, StartX / 25, EndX / 25, StartZ / 25, EndZ / 25);
for (size_t i = 0; i < ARRAYCOUNT(Height); i++)
{
- Height[i] = abs(Height[i]) * m_HeightAmplification + 1;
+ Height[i] = std::abs(Height[i]) * m_HeightAmplification + 1;
}
// Modify the noise by height data:
@@ -395,7 +395,7 @@ void cNoise3DComposable::GenerateNoiseArrayIfNeeded(int a_ChunkX, int a_ChunkZ)
for (int x = 0; x < 17; x += UPSCALE_X)
{
NOISE_DATATYPE NoiseX = ((NOISE_DATATYPE)(a_ChunkX * cChunkDef::Width + x)) / m_FrequencyX;
- NOISE_DATATYPE val = abs(m_Noise1.CubicNoise2D(NoiseX / 5, NoiseZ / 5)) * m_HeightAmplification + 1;
+ NOISE_DATATYPE val = std::abs(m_Noise1.CubicNoise2D(NoiseX / 5, NoiseZ / 5)) * m_HeightAmplification + 1;
Height[x + 17 * z] = val * val * val;
}
}
diff --git a/src/HTTPServer/HTTPServer.cpp b/src/HTTPServer/HTTPServer.cpp
index 8eabe5cb2..0c41b54b2 100644
--- a/src/HTTPServer/HTTPServer.cpp
+++ b/src/HTTPServer/HTTPServer.cpp
@@ -170,7 +170,8 @@ bool cHTTPServer::Initialize(const AString & a_PortsIPv4, const AString & a_Port
// Notify the admin about the HTTPS / HTTP status
if (m_Cert.get() == NULL)
{
- LOGWARNING("WebServer: The server is running in unsecure HTTP mode.");
+ LOGWARNING("WebServer: The server is running in unsecured HTTP mode.");
+ LOGINFO("Put a valid HTTPS certificate in file 'webadmin/httpscert.crt' and its corresponding private key to 'webadmin/httpskey.pem' (without any password) to enable HTTPS support");
}
else
{
diff --git a/src/Item.cpp b/src/Item.cpp
index 2c5deaddf..ebdf99ca5 100644
--- a/src/Item.cpp
+++ b/src/Item.cpp
@@ -190,31 +190,35 @@ void cItem::FromJson(const Json::Value & a_Value)
-bool cItem::IsEnchantable(short item)
+bool cItem::IsEnchantable(short a_ItemType, bool a_WithBook)
{
- if ((item >= 256) && (item <= 259))
+ if (
+ ItemCategory::IsAxe(a_ItemType) ||
+ ItemCategory::IsSword(a_ItemType) ||
+ ItemCategory::IsShovel(a_ItemType) ||
+ ItemCategory::IsPickaxe(a_ItemType) ||
+ (a_WithBook && ItemCategory::IsHoe(a_ItemType)) ||
+ ItemCategory::IsArmor(a_ItemType)
+ )
{
return true;
}
- if ((item >= 267) && (item <= 279))
- {
- return true;
- }
- if ((item >= 283) && (item <= 286))
- {
- return true;
- }
- if ((item >= 290) && (item <= 294))
- {
- return true;
- }
- if ((item >= 298) && (item <= 317))
- {
- return true;
- }
- if ((item == 346) || (item == 359) || (item == 261))
+
+ switch (a_ItemType)
{
- return true;
+ case E_ITEM_BOOK:
+ case E_ITEM_BOW:
+ case E_ITEM_FISHING_ROD:
+ {
+ return true;
+ }
+
+ case E_ITEM_CARROT_ON_STICK:
+ case E_ITEM_SHEARS:
+ case E_ITEM_FLINT_AND_STEEL:
+ {
+ return a_WithBook;
+ }
}
return false;
@@ -299,73 +303,77 @@ int cItem::GetEnchantability()
bool cItem::EnchantByXPLevels(int a_NumXPLevels)
{
- if (!cItem::IsEnchantable(m_ItemType) && (m_ItemType != E_ITEM_BOOK))
+ if (!cItem::IsEnchantable(m_ItemType))
{
return false;
}
int Enchantability = GetEnchantability();
+ if (Enchantability == 0)
+ {
+ return false;
+ }
cFastRandom Random;
int ModifiedEnchantmentLevel = a_NumXPLevels + (int)Random.NextFloat((float)Enchantability / 4) + (int)Random.NextFloat((float)Enchantability / 4) + 1;
float RandomBonus = 1.0F + (Random.NextFloat(1) + Random.NextFloat(1) - 1.0F) * 0.15F;
int FinalEnchantmentLevel = (int)(ModifiedEnchantmentLevel * RandomBonus + 0.5F);
- cWeightedEnchantments enchantments;
- cEnchantments::AddItemEnchantmentWeights(enchantments, m_ItemType, FinalEnchantmentLevel);
+ cWeightedEnchantments Enchantments;
+ cEnchantments::AddItemEnchantmentWeights(Enchantments, m_ItemType, FinalEnchantmentLevel);
if (m_ItemType == E_ITEM_BOOK)
{
m_ItemType = E_ITEM_ENCHANTED_BOOK;
}
- cEnchantments Enchantment1 = cEnchantments::GetRandomEnchantmentFromVector(enchantments);
+ cEnchantments Enchantment1 = cEnchantments::GetRandomEnchantmentFromVector(Enchantments);
m_Enchantments.AddFromString(Enchantment1.ToString());
- cEnchantments::RemoveEnchantmentWeightFromVector(enchantments, Enchantment1);
+ cEnchantments::RemoveEnchantmentWeightFromVector(Enchantments, Enchantment1);
// Checking for conflicting enchantments
- cEnchantments::CheckEnchantmentConflictsFromVector(enchantments, Enchantment1);
+ cEnchantments::CheckEnchantmentConflictsFromVector(Enchantments, Enchantment1);
float NewEnchantmentLevel = (float)a_NumXPLevels;
// Next Enchantment (Second)
NewEnchantmentLevel = NewEnchantmentLevel / 2;
float SecondEnchantmentChance = (NewEnchantmentLevel + 1) / 50 * 100;
- if (enchantments.empty() || (Random.NextFloat(100) > SecondEnchantmentChance))
+ if (Enchantments.empty() || (Random.NextFloat(100) > SecondEnchantmentChance))
{
return true;
}
- cEnchantments Enchantment2 = cEnchantments::GetRandomEnchantmentFromVector(enchantments);
+ cEnchantments Enchantment2 = cEnchantments::GetRandomEnchantmentFromVector(Enchantments);
m_Enchantments.AddFromString(Enchantment2.ToString());
- cEnchantments::RemoveEnchantmentWeightFromVector(enchantments, Enchantment2);
+ cEnchantments::RemoveEnchantmentWeightFromVector(Enchantments, Enchantment2);
// Checking for conflicting enchantments
- cEnchantments::CheckEnchantmentConflictsFromVector(enchantments, Enchantment2);
+ cEnchantments::CheckEnchantmentConflictsFromVector(Enchantments, Enchantment2);
// Next Enchantment (Third)
NewEnchantmentLevel = NewEnchantmentLevel / 2;
float ThirdEnchantmentChance = (NewEnchantmentLevel + 1) / 50 * 100;
- if (enchantments.empty() || (Random.NextFloat(100) > ThirdEnchantmentChance))
+ if (Enchantments.empty() || (Random.NextFloat(100) > ThirdEnchantmentChance))
{
return true;
}
- cEnchantments Enchantment3 = cEnchantments::GetRandomEnchantmentFromVector(enchantments);
+ cEnchantments Enchantment3 = cEnchantments::GetRandomEnchantmentFromVector(Enchantments);
m_Enchantments.AddFromString(Enchantment3.ToString());
- cEnchantments::RemoveEnchantmentWeightFromVector(enchantments, Enchantment3);
+ cEnchantments::RemoveEnchantmentWeightFromVector(Enchantments, Enchantment3);
// Checking for conflicting enchantments
- cEnchantments::CheckEnchantmentConflictsFromVector(enchantments, Enchantment3);
+ cEnchantments::CheckEnchantmentConflictsFromVector(Enchantments, Enchantment3);
// Next Enchantment (Fourth)
NewEnchantmentLevel = NewEnchantmentLevel / 2;
float FourthEnchantmentChance = (NewEnchantmentLevel + 1) / 50 * 100;
- if (enchantments.empty() || (Random.NextFloat(100) > FourthEnchantmentChance))
+ if (Enchantments.empty() || (Random.NextFloat(100) > FourthEnchantmentChance))
{
return true;
}
- cEnchantments Enchantment4 = cEnchantments::GetRandomEnchantmentFromVector(enchantments);
+ cEnchantments Enchantment4 = cEnchantments::GetRandomEnchantmentFromVector(Enchantments);
m_Enchantments.AddFromString(Enchantment4.ToString());
return true;
diff --git a/src/Item.h b/src/Item.h
index d8b9e78a0..056b5eb8a 100644
--- a/src/Item.h
+++ b/src/Item.h
@@ -183,8 +183,10 @@ public:
/** Loads the item data from JSON representation */
void FromJson(const Json::Value & a_Value);
- /** Returns true if the specified item type is enchantable (as per 1.2.5 protocol requirements) */
- static bool IsEnchantable(short a_ItemType); // tolua_export
+ /** Returns true if the specified item type is enchantable.
+ If WithBook is true, the function is used in the anvil inventory with book enchantments.
+ So it checks the "only book enchantments" too. Example: You can only enchant a hoe with a book. */
+ static bool IsEnchantable(short a_ItemType, bool a_WithBook = false); // tolua_export
/** Returns the enchantability of the item. When the item hasn't a enchantability, it will returns 0 */
int GetEnchantability(); // tolua_export
diff --git a/src/Items/ItemFood.h b/src/Items/ItemFood.h
index 98050cad8..1af6e21e8 100644
--- a/src/Items/ItemFood.h
+++ b/src/Items/ItemFood.h
@@ -1,3 +1,4 @@
+
#pragma once
#include "ItemHandler.h"
@@ -29,7 +30,7 @@ public:
switch (m_ItemType)
{
// Please keep alpha-sorted.
- case E_ITEM_BAKED_POTATO: return FoodInfo(6, 7.2);
+ case E_ITEM_BAKED_POTATO: return FoodInfo(5, 7.2);
case E_ITEM_BREAD: return FoodInfo(5, 6);
// Carrots handled in ItemSeeds
case E_ITEM_COOKED_CHICKEN: return FoodInfo(6, 7.2);
@@ -39,18 +40,19 @@ public:
// Golden apple handled in ItemGoldenApple
case E_ITEM_GOLDEN_CARROT: return FoodInfo(6, 14.4);
case E_ITEM_MELON_SLICE: return FoodInfo(2, 1.2);
- case E_ITEM_MUSHROOM_SOUP: return FoodInfo(6, 7.2);
case E_ITEM_POISONOUS_POTATO: return FoodInfo(2, 1.2);
// Potatoes handled in ItemSeeds
case E_ITEM_PUMPKIN_PIE: return FoodInfo(8, 4.8);
+ case E_ITEM_RED_APPLE: return FoodInfo(4, 2.4);
case E_ITEM_RAW_BEEF: return FoodInfo(3, 1.8);
case E_ITEM_RAW_CHICKEN: return FoodInfo(2, 1.2);
case E_ITEM_RAW_FISH: return FoodInfo(2, 1.2);
+ case E_ITEM_RAW_MUTTON: return FoodInfo(2, 1.2);
case E_ITEM_RAW_PORKCHOP: return FoodInfo(3, 1.8);
- case E_ITEM_RED_APPLE: return FoodInfo(4, 2.4);
case E_ITEM_ROTTEN_FLESH: return FoodInfo(4, 0.8);
case E_ITEM_SPIDER_EYE: return FoodInfo(2, 3.2);
case E_ITEM_STEAK: return FoodInfo(8, 12.8);
+ case E_ITEM_MUTTON: return FoodInfo(6, 9.6);
}
LOGWARNING("%s: Unknown food item (%d), returning zero nutrition", __FUNCTION__, m_ItemType);
return FoodInfo(0, 0.f);
diff --git a/src/Items/ItemGoldenApple.h b/src/Items/ItemGoldenApple.h
index 02ac0202c..5f6f1de6c 100644
--- a/src/Items/ItemGoldenApple.h
+++ b/src/Items/ItemGoldenApple.h
@@ -36,6 +36,7 @@ public:
a_Player->AddEntityEffect(cEntityEffect::effFireResistance, 6000, 0);
}
+ a_Player->GetInventory().RemoveOneEquippedItem();
return true;
}
diff --git a/src/Items/ItemHandler.cpp b/src/Items/ItemHandler.cpp
index bceedaf69..8c3f28c74 100644
--- a/src/Items/ItemHandler.cpp
+++ b/src/Items/ItemHandler.cpp
@@ -33,6 +33,7 @@
#include "ItemLilypad.h"
#include "ItemMap.h"
#include "ItemMinecart.h"
+#include "ItemMushroomSoup.h"
#include "ItemNetherWart.h"
#include "ItemPainting.h"
#include "ItemPickaxe.h"
@@ -125,6 +126,7 @@ cItemHandler *cItemHandler::CreateItemHandler(int a_ItemType)
case E_BLOCK_LILY_PAD: return new cItemLilypadHandler(a_ItemType);
case E_ITEM_MAP: return new cItemMapHandler();
case E_ITEM_MILK: return new cItemMilkHandler();
+ case E_ITEM_MUSHROOM_SOUP: return new cItemMushroomSoupHandler(a_ItemType);
case E_ITEM_ITEM_FRAME: return new cItemItemFrameHandler(a_ItemType);
case E_ITEM_NETHER_WART: return new cItemNetherWartHandler(a_ItemType);
case E_ITEM_PAINTING: return new cItemPaintingHandler(a_ItemType);
@@ -207,7 +209,7 @@ cItemHandler *cItemHandler::CreateItemHandler(int a_ItemType)
}
// Food (please keep alpha-sorted):
- // (carrots and potatoes handled in SeedHandler as both seed and food
+ // (carrots and potatoes handled separately in SeedHandler as they're both seed and food)
case E_ITEM_BAKED_POTATO:
case E_ITEM_BREAD:
case E_ITEM_COOKED_CHICKEN:
@@ -216,14 +218,15 @@ cItemHandler *cItemHandler::CreateItemHandler(int a_ItemType)
case E_ITEM_COOKIE:
case E_ITEM_GOLDEN_CARROT:
case E_ITEM_MELON_SLICE:
- case E_ITEM_MUSHROOM_SOUP:
+ case E_ITEM_MUTTON:
case E_ITEM_POISONOUS_POTATO:
case E_ITEM_PUMPKIN_PIE:
+ case E_ITEM_RED_APPLE:
case E_ITEM_RAW_BEEF:
case E_ITEM_RAW_CHICKEN:
case E_ITEM_RAW_FISH:
+ case E_ITEM_RAW_MUTTON:
case E_ITEM_RAW_PORKCHOP:
- case E_ITEM_RED_APPLE:
case E_ITEM_ROTTEN_FLESH:
case E_ITEM_SPIDER_EYE:
case E_ITEM_STEAK:
@@ -331,7 +334,7 @@ void cItemHandler::OnBlockDestroyed(cWorld * a_World, cPlayer * a_Player, const
{
cChunkInterface ChunkInterface(a_World->GetChunkMap());
cBlockInServerPluginInterface PluginInterface(*a_World);
- Handler->DropBlock(ChunkInterface, *a_World, PluginInterface, a_Player, a_BlockX, a_BlockY, a_BlockZ, CanHarvestBlock(Block), a_Player->GetEquippedItem().m_Enchantments.GetLevel(cEnchantments::enchSilkTouch) > 0);
+ Handler->DropBlock(ChunkInterface, *a_World, PluginInterface, a_Player, a_BlockX, a_BlockY, a_BlockZ, CanHarvestBlock(Block));
}
if (!cBlockInfo::IsOneHitDig(Block))
@@ -580,6 +583,7 @@ bool cItemHandler::CanHarvestBlock(BLOCKTYPE a_BlockType)
case E_BLOCK_SNOW:
case E_BLOCK_VINES:
case E_BLOCK_PACKED_ICE:
+ case E_BLOCK_MOB_SPAWNER:
{
return false;
}
@@ -632,6 +636,10 @@ bool cItemHandler::GetEatEffect(cEntityEffect::eType & a_EffectType, int & a_Eff
bool cItemHandler::EatItem(cPlayer * a_Player, cItem * a_Item)
{
UNUSED(a_Item);
+ if (!a_Player->IsGameModeCreative())
+ {
+ a_Player->GetInventory().RemoveOneEquippedItem();
+ }
FoodInfo Info = GetFoodInfo();
if ((Info.FoodLevel > 0) || (Info.Saturation > 0.f))
diff --git a/src/Items/ItemHoe.h b/src/Items/ItemHoe.h
index 8d0b71478..de8b9a061 100644
--- a/src/Items/ItemHoe.h
+++ b/src/Items/ItemHoe.h
@@ -20,11 +20,17 @@ public:
virtual bool OnItemUse(cWorld *a_World, cPlayer *a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Dir) override
{
+ if ((a_Dir == BLOCK_FACE_NONE) || (a_BlockY >= cChunkDef::Height))
+ {
+ return false;
+ }
BLOCKTYPE Block = a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ);
+ BLOCKTYPE UpperBlock = a_World->GetBlock(a_BlockX, a_BlockY + 1, a_BlockZ);
- if ((Block == E_BLOCK_DIRT) || (Block == E_BLOCK_GRASS))
+ if (((Block == E_BLOCK_DIRT) || (Block == E_BLOCK_GRASS)) && (UpperBlock == E_BLOCK_AIR))
{
a_World->FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_FARMLAND, 0);
+ a_World->BroadcastSoundEffect("dig.gravel", a_BlockX + 0.5, a_BlockY + 0.5, a_BlockZ + 0.5, 1.0f, 0.8f);
a_Player->UseEquippedItem();
return true;
}
@@ -41,4 +47,3 @@ public:
-
diff --git a/src/Items/ItemMilk.h b/src/Items/ItemMilk.h
index db7bc13be..c9a90865a 100644
--- a/src/Items/ItemMilk.h
+++ b/src/Items/ItemMilk.h
@@ -21,8 +21,12 @@ public:
{
UNUSED(a_Item);
a_Player->ClearEntityEffects();
- a_Player->GetInventory().RemoveOneEquippedItem();
- a_Player->GetInventory().AddItem(E_ITEM_BUCKET);
+
+ if (!a_Player->IsGameModeCreative())
+ {
+ a_Player->GetInventory().RemoveOneEquippedItem();
+ a_Player->GetInventory().AddItem(E_ITEM_BUCKET);
+ }
return true;
}
};
diff --git a/src/Items/ItemMushroomSoup.h b/src/Items/ItemMushroomSoup.h
new file mode 100644
index 000000000..dba313ec5
--- /dev/null
+++ b/src/Items/ItemMushroomSoup.h
@@ -0,0 +1,53 @@
+
+#pragma once
+
+#include "ItemHandler.h"
+
+
+
+
+
+class cItemMushroomSoupHandler :
+ public cItemHandler
+{
+ typedef cItemHandler super;
+
+public:
+ cItemMushroomSoupHandler(int a_ItemType)
+ : super(a_ItemType)
+ {
+ }
+
+
+ virtual bool IsFood(void) override
+ {
+ return true;
+ }
+
+
+ virtual FoodInfo GetFoodInfo(void) override
+ {
+ return FoodInfo(6, 7.2);
+ }
+
+
+ virtual bool EatItem(cPlayer * a_Player, cItem * a_Item) override
+ {
+ if (!super::EatItem(a_Player, a_Item))
+ {
+ return false;
+ }
+
+ // Return a bowl to the inventory
+ if (!a_Player->IsGameModeCreative())
+ {
+ a_Player->GetInventory().AddItem(cItem(E_ITEM_BOWL), true, true);
+ }
+ return true;
+ }
+
+};
+
+
+
+
diff --git a/src/Items/ItemPickaxe.h b/src/Items/ItemPickaxe.h
index 17fd96822..e0cf5d711 100644
--- a/src/Items/ItemPickaxe.h
+++ b/src/Items/ItemPickaxe.h
@@ -81,6 +81,7 @@ public:
case E_BLOCK_STONE_BRICK_STAIRS:
case E_BLOCK_NETHER_BRICK_STAIRS:
case E_BLOCK_CAULDRON:
+ case E_BLOCK_MOB_SPAWNER:
{
return PickaxeLevel() >= 1;
}
diff --git a/src/Items/ItemPotion.h b/src/Items/ItemPotion.h
index 24614cd8a..398ef6805 100644
--- a/src/Items/ItemPotion.h
+++ b/src/Items/ItemPotion.h
@@ -68,8 +68,12 @@ public:
cEntityEffect::GetPotionEffectDuration(PotionDamage),
cEntityEffect::GetPotionEffectIntensity(PotionDamage)
);
- a_Player->GetInventory().RemoveOneEquippedItem();
- a_Player->GetInventory().AddItem(E_ITEM_GLASS_BOTTLE);
+
+ if (!a_Player->IsGameModeCreative())
+ {
+ a_Player->GetInventory().RemoveOneEquippedItem();
+ a_Player->GetInventory().AddItem(E_ITEM_GLASS_BOTTLE);
+ }
return true;
}
};
diff --git a/src/Items/ItemSeeds.h b/src/Items/ItemSeeds.h
index 54a1183d7..e1db7c5f4 100644
--- a/src/Items/ItemSeeds.h
+++ b/src/Items/ItemSeeds.h
@@ -37,7 +37,7 @@ public:
{
switch (m_ItemType)
{
- case E_ITEM_CARROT: return FoodInfo(4, 4.8);
+ case E_ITEM_CARROT: return FoodInfo(3, 4.8);
case E_ITEM_POTATO: return FoodInfo(1, 0.6);
default: return FoodInfo(0, 0);
}
diff --git a/src/LineBlockTracer.cpp b/src/LineBlockTracer.cpp
index f03e796d1..1b42081c2 100644
--- a/src/LineBlockTracer.cpp
+++ b/src/LineBlockTracer.cpp
@@ -146,7 +146,7 @@ bool cLineBlockTracer::MoveToNextBlock(void)
dirY,
dirZ,
} Direction = dirNONE;
- if (abs(m_DiffX) > EPS)
+ if (std::abs(m_DiffX) > EPS)
{
double DestX = (m_DirX > 0) ? (m_CurrentX + 1) : m_CurrentX;
Coeff = (DestX - m_StartX) / m_DiffX;
@@ -155,7 +155,7 @@ bool cLineBlockTracer::MoveToNextBlock(void)
Direction = dirX;
}
}
- if (abs(m_DiffY) > EPS)
+ if (std::abs(m_DiffY) > EPS)
{
double DestY = (m_DirY > 0) ? (m_CurrentY + 1) : m_CurrentY;
double CoeffY = (DestY - m_StartY) / m_DiffY;
@@ -165,7 +165,7 @@ bool cLineBlockTracer::MoveToNextBlock(void)
Direction = dirY;
}
}
- if (abs(m_DiffZ) > EPS)
+ if (std::abs(m_DiffZ) > EPS)
{
double DestZ = (m_DirZ > 0) ? (m_CurrentZ + 1) : m_CurrentZ;
double CoeffZ = (DestZ - m_StartZ) / m_DiffZ;
@@ -227,9 +227,11 @@ bool cLineBlockTracer::Item(cChunk * a_Chunk)
}
// Update the current chunk
- if (a_Chunk != NULL)
+ a_Chunk = a_Chunk->GetNeighborChunk(m_CurrentX, m_CurrentZ);
+ if (a_Chunk == NULL)
{
- a_Chunk = a_Chunk->GetNeighborChunk(m_CurrentX, m_CurrentZ);
+ m_Callbacks->OnNoChunk();
+ return false;
}
if (a_Chunk->IsValid())
@@ -245,13 +247,10 @@ bool cLineBlockTracer::Item(cChunk * a_Chunk)
return false;
}
}
- else
+ else if (m_Callbacks->OnNextBlockNoData(m_CurrentX, m_CurrentY, m_CurrentZ, m_CurrentFace))
{
- if (m_Callbacks->OnNextBlockNoData(m_CurrentX, m_CurrentY, m_CurrentZ, m_CurrentFace))
- {
- // The callback terminated the trace
- return false;
- }
+ // The callback terminated the trace
+ return false;
}
}
}
diff --git a/src/Map.cpp b/src/Map.cpp
index 8f205a606..c106ccd83 100644
--- a/src/Map.cpp
+++ b/src/Map.cpp
@@ -432,7 +432,7 @@ void cMap::StreamNext(cMapClient & a_Client)
// This is dangerous as the player object may have been destroyed before the decorator is erased from the list
UpdateDecorators();
- Handle->SendMapDecorators(m_ID, m_Decorators);
+ Handle->SendMapDecorators(m_ID, m_Decorators, m_Scale);
a_Client.m_NextDecoratorUpdate = 0;
}
@@ -444,7 +444,7 @@ void cMap::StreamNext(cMapClient & a_Client)
const Byte * Colors = &m_Data[Y * m_Height];
- Handle->SendMapColumn(m_ID, Y, 0, Colors, m_Height);
+ Handle->SendMapColumn(m_ID, Y, 0, Colors, m_Height, m_Scale);
}
}
@@ -595,10 +595,10 @@ void cMap::SendTo(cClientHandle & a_Client)
{
const Byte* Colors = &m_Data[i * m_Height];
- a_Client.SendMapColumn(m_ID, i, 0, Colors, m_Height);
+ a_Client.SendMapColumn(m_ID, i, 0, Colors, m_Height, m_Scale);
}
- a_Client.SendMapDecorators(m_ID, m_Decorators);
+ a_Client.SendMapDecorators(m_ID, m_Decorators, m_Scale);
}
diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp
index b0b836dff..339367f47 100644
--- a/src/Mobs/Monster.cpp
+++ b/src/Mobs/Monster.cpp
@@ -91,6 +91,7 @@ cMonster::cMonster(const AString & a_ConfigName, eType a_MobType, const AString
, m_DropChanceBoots(0.085f)
, m_CanPickUpLoot(true)
, m_BurnsInDaylight(false)
+ , m_RelativeWalkSpeed(1.0)
{
if (!a_ConfigName.empty())
{
@@ -284,7 +285,7 @@ void cMonster::Tick(float a_Dt, cChunk & a_Chunk)
}
}
- Vector3f Distance = m_Destination - GetPosition();
+ Vector3d Distance = m_Destination - GetPosition();
if (!ReachedDestination() && !ReachedFinalDestination()) // If we haven't reached any sort of destination, move
{
Distance.y = 0;
@@ -304,6 +305,9 @@ void cMonster::Tick(float a_Dt, cChunk & a_Chunk)
Distance *= 0.25f;
}
+ // Apply walk speed:
+ Distance *= m_RelativeWalkSpeed;
+
AddSpeedX(Distance.x);
AddSpeedZ(Distance.z);
diff --git a/src/Mobs/Monster.h b/src/Mobs/Monster.h
index 1d66d50e5..4865cb99e 100644
--- a/src/Mobs/Monster.h
+++ b/src/Mobs/Monster.h
@@ -140,6 +140,9 @@ public:
/// Sets whether the mob burns in daylight. Only evaluated at next burn-decision tick
void SetBurnsInDaylight(bool a_BurnsInDaylight) { m_BurnsInDaylight = a_BurnsInDaylight; }
+ double GetRelativeWalkSpeed(void) const { return m_RelativeWalkSpeed; } // tolua_export
+ void SetRelativeWalkSpeed(double a_WalkSpeed) { m_RelativeWalkSpeed = a_WalkSpeed; } // tolua_export
+
// Overridables to handle ageable mobs
virtual bool IsBaby (void) const { return false; }
virtual bool IsTame (void) const { return false; }
@@ -269,6 +272,8 @@ protected:
void HandleDaylightBurning(cChunk & a_Chunk);
bool m_BurnsInDaylight;
+ double m_RelativeWalkSpeed;
+
/** Adds a random number of a_Item between a_Min and a_Max to itemdrops a_Drops*/
void AddRandomDropItem(cItems & a_Drops, unsigned int a_Min, unsigned int a_Max, short a_Item, short a_ItemHealth = 0);
diff --git a/src/Mobs/Sheep.cpp b/src/Mobs/Sheep.cpp
index ee3236bba..c12e8d786 100644
--- a/src/Mobs/Sheep.cpp
+++ b/src/Mobs/Sheep.cpp
@@ -39,6 +39,13 @@ void cSheep::GetDrops(cItems & a_Drops, cEntity * a_Killer)
{
a_Drops.push_back(cItem(E_BLOCK_WOOL, 1, m_WoolColor));
}
+
+ int LootingLevel = 0;
+ if (a_Killer != NULL)
+ {
+ LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting);
+ }
+ AddRandomDropItem(a_Drops, 1, 3 + LootingLevel, IsOnFire() ? E_ITEM_MUTTON : E_ITEM_RAW_MUTTON);
}
diff --git a/src/OSSupport/File.cpp b/src/OSSupport/File.cpp
index 2194c46ee..cb6031da6 100644
--- a/src/OSSupport/File.cpp
+++ b/src/OSSupport/File.cpp
@@ -298,7 +298,7 @@ bool cFile::Rename(const AString & a_OrigFileName, const AString & a_NewFileName
bool cFile::Copy(const AString & a_SrcFileName, const AString & a_DstFileName)
{
#ifdef _WIN32
- return (CopyFile(a_SrcFileName.c_str(), a_DstFileName.c_str(), true) != 0);
+ return (CopyFileA(a_SrcFileName.c_str(), a_DstFileName.c_str(), true) != 0);
#else
// Other OSs don't have a direct CopyFile equivalent, do it the harder way:
std::ifstream src(a_SrcFileName.c_str(), std::ios::binary);
@@ -322,7 +322,7 @@ bool cFile::Copy(const AString & a_SrcFileName, const AString & a_DstFileName)
bool cFile::IsFolder(const AString & a_Path)
{
#ifdef _WIN32
- DWORD FileAttrib = GetFileAttributes(a_Path.c_str());
+ DWORD FileAttrib = GetFileAttributesA(a_Path.c_str());
return ((FileAttrib != INVALID_FILE_ATTRIBUTES) && ((FileAttrib & FILE_ATTRIBUTE_DIRECTORY) != 0));
#else
struct stat st;
@@ -337,7 +337,7 @@ bool cFile::IsFolder(const AString & a_Path)
bool cFile::IsFile(const AString & a_Path)
{
#ifdef _WIN32
- DWORD FileAttrib = GetFileAttributes(a_Path.c_str());
+ DWORD FileAttrib = GetFileAttributesA(a_Path.c_str());
return ((FileAttrib != INVALID_FILE_ATTRIBUTES) && ((FileAttrib & (FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_DEVICE)) == 0));
#else
struct stat st;
@@ -366,7 +366,7 @@ int cFile::GetSize(const AString & a_FileName)
bool cFile::CreateFolder(const AString & a_FolderPath)
{
#ifdef _WIN32
- return (CreateDirectory(a_FolderPath.c_str(), NULL) != 0);
+ return (CreateDirectoryA(a_FolderPath.c_str(), NULL) != 0);
#else
return (mkdir(a_FolderPath.c_str(), S_IRWXU | S_IRWXG | S_IRWXO) == 0);
#endif
@@ -396,13 +396,13 @@ AStringVector cFile::GetFolderContents(const AString & a_Folder)
// Find all files / folders:
FileFilter.append("*.*");
HANDLE hFind;
- WIN32_FIND_DATA FindFileData;
- if ((hFind = FindFirstFile(FileFilter.c_str(), &FindFileData)) != INVALID_HANDLE_VALUE)
+ WIN32_FIND_DATAA FindFileData;
+ if ((hFind = FindFirstFileA(FileFilter.c_str(), &FindFileData)) != INVALID_HANDLE_VALUE)
{
do
{
AllFiles.push_back(FindFileData.cFileName);
- } while (FindNextFile(hFind, &FindFileData));
+ } while (FindNextFileA(hFind, &FindFileData));
FindClose(hFind);
}
diff --git a/src/OSSupport/IsThread.h b/src/OSSupport/IsThread.h
index c20fc3e7e..5de5f31c4 100644
--- a/src/OSSupport/IsThread.h
+++ b/src/OSSupport/IsThread.h
@@ -69,7 +69,7 @@ protected:
static DWORD __stdcall thrExecute(LPVOID a_Param)
{
// Create a window so that the thread can be identified by 3rd party tools:
- HWND IdentificationWnd = CreateWindow("STATIC", ((cIsThread *)a_Param)->m_ThreadName.c_str(), 0, 0, 0, 0, WS_OVERLAPPED, NULL, NULL, NULL, NULL);
+ HWND IdentificationWnd = CreateWindowA("STATIC", ((cIsThread *)a_Param)->m_ThreadName.c_str(), 0, 0, 0, 0, WS_OVERLAPPED, NULL, NULL, NULL, NULL);
// Run the thread:
((cIsThread *)a_Param)->Execute();
diff --git a/src/Protocol/CMakeLists.txt b/src/Protocol/CMakeLists.txt
index 1ba66ff1f..5426c58fa 100644
--- a/src/Protocol/CMakeLists.txt
+++ b/src/Protocol/CMakeLists.txt
@@ -14,6 +14,7 @@ SET (SRCS
Protocol15x.cpp
Protocol16x.cpp
Protocol17x.cpp
+ Protocol18x.cpp
ProtocolRecognizer.cpp)
SET (HDRS
@@ -27,6 +28,7 @@ SET (HDRS
Protocol15x.h
Protocol16x.h
Protocol17x.h
+ Protocol18x.h
ProtocolRecognizer.h)
if(NOT MSVC)
diff --git a/src/Protocol/ChunkDataSerializer.cpp b/src/Protocol/ChunkDataSerializer.cpp
index ebe61631b..a133cc0e3 100644
--- a/src/Protocol/ChunkDataSerializer.cpp
+++ b/src/Protocol/ChunkDataSerializer.cpp
@@ -8,6 +8,8 @@
#include "Globals.h"
#include "ChunkDataSerializer.h"
#include "zlib/zlib.h"
+#include "ByteBuffer.h"
+#include "Protocol18x.h"
@@ -30,7 +32,7 @@ cChunkDataSerializer::cChunkDataSerializer(
-const AString & cChunkDataSerializer::Serialize(int a_Version)
+const AString & cChunkDataSerializer::Serialize(int a_Version, int a_ChunkX, int a_ChunkZ)
{
Serializations::const_iterator itr = m_Serializations.find(a_Version);
if (itr != m_Serializations.end())
@@ -43,6 +45,7 @@ const AString & cChunkDataSerializer::Serialize(int a_Version)
{
case RELEASE_1_2_5: Serialize29(data); break;
case RELEASE_1_3_2: Serialize39(data); break;
+ case RELEASE_1_8_0: Serialize47(data, a_ChunkX, a_ChunkZ); break;
// TODO: Other protocol versions may serialize the data differently; implement here
default:
@@ -52,7 +55,10 @@ const AString & cChunkDataSerializer::Serialize(int a_Version)
break;
}
}
- m_Serializations[a_Version] = data;
+ if (!data.empty())
+ {
+ m_Serializations[a_Version] = data;
+ }
return m_Serializations[a_Version];
}
@@ -174,3 +180,72 @@ void cChunkDataSerializer::Serialize39(AString & a_Data)
+
+void cChunkDataSerializer::Serialize47(AString & a_Data, int a_ChunkX, int a_ChunkZ)
+{
+ // This function returns the fully compressed packet (including packet size), not the raw packet!
+
+ // Create the packet:
+ cByteBuffer Packet(512 KiB);
+ Packet.WriteVarInt(0x21); // Packet id (Chunk Data packet)
+ Packet.WriteBEInt(a_ChunkX);
+ Packet.WriteBEInt(a_ChunkZ);
+ Packet.WriteBool(true); // "Ground-up continuous", or rather, "biome data present" flag
+ Packet.WriteBEShort((short) 0xffff); // We're aways sending the full chunk with no additional data, so the bitmap is 0xffff
+
+ // Write the chunk size:
+ const int BiomeDataSize = cChunkDef::Width * cChunkDef::Width;
+ UInt32 ChunkSize = (
+ (cChunkDef::NumBlocks * 2) + // Block meta + type
+ sizeof(m_BlockLight) + // Block light
+ sizeof(m_BlockSkyLight) + // Block sky light
+ BiomeDataSize // Biome data
+ );
+ Packet.WriteVarInt(ChunkSize);
+
+ // Write the block types to the packet:
+ for (size_t Index = 0; Index < cChunkDef::NumBlocks; Index++)
+ {
+ BLOCKTYPE BlockType = m_BlockTypes[Index] & 0xFF;
+ NIBBLETYPE BlockMeta = m_BlockMetas[Index / 2] >> ((Index & 1) * 4) & 0x0f;
+ Packet.WriteByte((unsigned char)(BlockType << 4) | BlockMeta);
+ Packet.WriteByte((unsigned char)(BlockType >> 4));
+ }
+
+ // Write the rest:
+ Packet.WriteBuf(m_BlockLight, sizeof(m_BlockLight));
+ Packet.WriteBuf(m_BlockSkyLight, sizeof(m_BlockSkyLight));
+ Packet.WriteBuf(m_BiomeData, BiomeDataSize);
+
+ AString PacketData;
+ Packet.ReadAll(PacketData);
+ Packet.CommitRead();
+
+ cByteBuffer Buffer(20);
+ if (PacketData.size() >= 256)
+ {
+ if (!cProtocol180::CompressPacket(PacketData, a_Data))
+ {
+ ASSERT(!"Packet compression failed.");
+ a_Data.clear();
+ return;
+ }
+ }
+ else
+ {
+ AString PostData;
+ Buffer.WriteVarInt((UInt32)Packet.GetUsedSpace() + 1);
+ Buffer.WriteVarInt(0);
+ Buffer.ReadAll(PostData);
+ Buffer.CommitRead();
+
+ a_Data.clear();
+ a_Data.reserve(PostData.size() + PacketData.size());
+ a_Data.append(PostData.data(), PostData.size());
+ a_Data.append(PacketData.data(), PacketData.size());
+ }
+}
+
+
+
+
diff --git a/src/Protocol/ChunkDataSerializer.h b/src/Protocol/ChunkDataSerializer.h
index a42856356..a082ef3d8 100644
--- a/src/Protocol/ChunkDataSerializer.h
+++ b/src/Protocol/ChunkDataSerializer.h
@@ -23,13 +23,15 @@ protected:
Serializations m_Serializations;
void Serialize29(AString & a_Data); // Release 1.2.4 and 1.2.5
- void Serialize39(AString & a_Data); // Release 1.3.1 and 1.3.2
+ void Serialize39(AString & a_Data); // Release 1.3.1 to 1.7.10
+ void Serialize47(AString & a_Data, int a_ChunkX, int a_ChunkZ); // Release 1.8
public:
enum
{
RELEASE_1_2_5 = 29,
RELEASE_1_3_2 = 39,
+ RELEASE_1_8_0 = 47,
} ;
cChunkDataSerializer(
@@ -40,7 +42,7 @@ public:
const unsigned char * a_BiomeData
);
- const AString & Serialize(int a_Version); // Returns one of the internal m_Serializations[]
+ const AString & Serialize(int a_Version, int a_ChunkX, int a_ChunkZ); // Returns one of the internal m_Serializations[]
} ;
diff --git a/src/Protocol/Protocol.h b/src/Protocol/Protocol.h
index 9b64faf79..f351ee4b9 100644
--- a/src/Protocol/Protocol.h
+++ b/src/Protocol/Protocol.h
@@ -50,82 +50,87 @@ public:
m_Client(a_Client)
{
}
+
virtual ~cProtocol() {}
/// Called when client sends some data
virtual void DataReceived(const char * a_Data, size_t a_Size) = 0;
// Sending stuff to clients (alphabetically sorted):
- virtual void SendAttachEntity (const cEntity & a_Entity, const cEntity * a_Vehicle) = 0;
- virtual void SendBlockAction (int a_BlockX, int a_BlockY, int a_BlockZ, char a_Byte1, char a_Byte2, BLOCKTYPE a_BlockType) = 0;
- virtual void SendBlockBreakAnim (int a_EntityID, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Stage) = 0;
- virtual void SendBlockChange (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) = 0;
- virtual void SendBlockChanges (int a_ChunkX, int a_ChunkZ, const sSetBlockVector & a_Changes) = 0;
- virtual void SendChat (const AString & a_Message) = 0;
- virtual void SendChat (const cCompositeChat & a_Message) = 0;
- virtual void SendChunkData (int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer) = 0;
- virtual void SendCollectEntity (const cEntity & a_Entity, const cPlayer & a_Player) = 0;
- virtual void SendDestroyEntity (const cEntity & a_Entity) = 0;
- virtual void SendDisconnect (const AString & a_Reason) = 0;
- virtual void SendEditSign (int a_BlockX, int a_BlockY, int a_BlockZ) = 0; ///< Request the client to open up the sign editor for the sign (1.6+)
- virtual void SendEntityEffect (const cEntity & a_Entity, int a_EffectID, int a_Amplifier, short a_Duration) = 0;
- virtual void SendEntityEquipment (const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item) = 0;
- virtual void SendEntityHeadLook (const cEntity & a_Entity) = 0;
- virtual void SendEntityLook (const cEntity & a_Entity) = 0;
- virtual void SendEntityMetadata (const cEntity & a_Entity) = 0;
- virtual void SendEntityProperties (const cEntity & a_Entity) = 0;
- virtual void SendEntityRelMove (const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ) = 0;
- virtual void SendEntityRelMoveLook (const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ) = 0;
- virtual void SendEntityStatus (const cEntity & a_Entity, char a_Status) = 0;
- virtual void SendEntityVelocity (const cEntity & a_Entity) = 0;
- virtual void SendExplosion (double a_BlockX, double a_BlockY, double a_BlockZ, float a_Radius, const cVector3iArray & a_BlocksAffected, const Vector3d & a_PlayerMotion) = 0;
- virtual void SendGameMode (eGameMode a_GameMode) = 0;
- virtual void SendHealth (void) = 0;
- virtual void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item) = 0;
- virtual void SendKeepAlive (int a_PingID) = 0;
- virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) = 0;
- virtual void SendLoginSuccess (void) = 0;
- virtual void SendMapColumn (int a_ID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length) = 0;
- virtual void SendMapDecorators (int a_ID, const cMapDecoratorList & a_Decorators) = 0;
- virtual void SendMapInfo (int a_ID, unsigned int a_Scale) = 0;
- virtual void SendPaintingSpawn (const cPainting & a_Painting) = 0;
- virtual void SendPickupSpawn (const cPickup & a_Pickup) = 0;
- virtual void SendPlayerAbilities (void) = 0;
- virtual void SendEntityAnimation (const cEntity & a_Entity, char a_Animation) = 0;
- virtual void SendParticleEffect (const AString & a_SoundName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmmount) = 0;
- virtual void SendPlayerListItem (const AString & a_PlayerName, bool a_IsOnline, short a_Ping = 0) = 0;
- virtual void SendPlayerMaxSpeed (void) = 0; ///< Informs the client of the maximum player speed (1.6.1+)
- virtual void SendPlayerMoveLook (void) = 0;
- virtual void SendPlayerPosition (void) = 0;
- virtual void SendPlayerSpawn (const cPlayer & a_Player) = 0;
- virtual void SendPluginMessage (const AString & a_Channel, const AString & a_Message) = 0;
- virtual void SendRemoveEntityEffect (const cEntity & a_Entity, int a_EffectID) = 0;
- virtual void SendRespawn (eDimension a_Dimension, bool a_ShouldIgnoreDimensionChecks) = 0;
- virtual void SendExperience (void) = 0;
- virtual void SendExperienceOrb (const cExpOrb & a_ExpOrb) = 0;
- virtual void SendScoreboardObjective (const AString & a_Name, const AString & a_DisplayName, Byte a_Mode) = 0;
- virtual void SendScoreUpdate (const AString & a_Objective, const AString & a_Player, cObjective::Score a_Score, Byte a_Mode) = 0;
- virtual void SendDisplayObjective (const AString & a_Objective, cScoreboard::eDisplaySlot a_Display) = 0;
- virtual void SendSoundEffect (const AString & a_SoundName, double a_X, double a_Y, double a_Z, float a_Volume, float a_Pitch) = 0;
- virtual void SendSoundParticleEffect (int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data) = 0;
- virtual void SendSpawnFallingBlock (const cFallingBlock & a_FallingBlock) = 0;
- virtual void SendSpawnMob (const cMonster & a_Mob) = 0;
- virtual void SendSpawnObject (const cEntity & a_Entity, char a_ObjectType, int a_ObjectData, Byte a_Yaw, Byte a_Pitch) = 0;
- virtual void SendSpawnVehicle (const cEntity & a_Vehicle, char a_VehicleType, char a_VehicleSubType) = 0;
- virtual void SendStatistics (const cStatManager & a_Manager) = 0;
- virtual void SendTabCompletionResults(const AStringVector & a_Results) = 0;
- virtual void SendTeleportEntity (const cEntity & a_Entity) = 0;
- virtual void SendThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ) = 0;
- virtual void SendTimeUpdate (Int64 a_WorldAge, Int64 a_TimeOfDay, bool a_DoDaylightCycle) = 0;
- virtual void SendUnloadChunk (int a_ChunkX, int a_ChunkZ) = 0;
- virtual void SendUpdateBlockEntity (cBlockEntity & a_BlockEntity) = 0;
- virtual void SendUpdateSign (int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4) = 0;
- virtual void SendUseBed (const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ) = 0;
- virtual void SendWeather (eWeather a_Weather) = 0;
- virtual void SendWholeInventory (const cWindow & a_Window) = 0;
- virtual void SendWindowClose (const cWindow & a_Window) = 0;
- virtual void SendWindowOpen (const cWindow & a_Window) = 0;
- virtual void SendWindowProperty (const cWindow & a_Window, int a_Property, int a_Value) = 0;
+ virtual void SendAttachEntity (const cEntity & a_Entity, const cEntity * a_Vehicle) = 0;
+ virtual void SendBlockAction (int a_BlockX, int a_BlockY, int a_BlockZ, char a_Byte1, char a_Byte2, BLOCKTYPE a_BlockType) = 0;
+ virtual void SendBlockBreakAnim (int a_EntityID, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Stage) = 0;
+ virtual void SendBlockChange (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) = 0;
+ virtual void SendBlockChanges (int a_ChunkX, int a_ChunkZ, const sSetBlockVector & a_Changes) = 0;
+ virtual void SendChat (const AString & a_Message) = 0;
+ virtual void SendChat (const cCompositeChat & a_Message) = 0;
+ virtual void SendChunkData (int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer) = 0;
+ virtual void SendCollectEntity (const cEntity & a_Entity, const cPlayer & a_Player) = 0;
+ virtual void SendDestroyEntity (const cEntity & a_Entity) = 0;
+ virtual void SendDisconnect (const AString & a_Reason) = 0;
+ virtual void SendEditSign (int a_BlockX, int a_BlockY, int a_BlockZ) = 0; ///< Request the client to open up the sign editor for the sign (1.6+)
+ virtual void SendEntityEffect (const cEntity & a_Entity, int a_EffectID, int a_Amplifier, short a_Duration) = 0;
+ virtual void SendEntityEquipment (const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item) = 0;
+ virtual void SendEntityHeadLook (const cEntity & a_Entity) = 0;
+ virtual void SendEntityLook (const cEntity & a_Entity) = 0;
+ virtual void SendEntityMetadata (const cEntity & a_Entity) = 0;
+ virtual void SendEntityProperties (const cEntity & a_Entity) = 0;
+ virtual void SendEntityRelMove (const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ) = 0;
+ virtual void SendEntityRelMoveLook (const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ) = 0;
+ virtual void SendEntityStatus (const cEntity & a_Entity, char a_Status) = 0;
+ virtual void SendEntityVelocity (const cEntity & a_Entity) = 0;
+ virtual void SendExplosion (double a_BlockX, double a_BlockY, double a_BlockZ, float a_Radius, const cVector3iArray & a_BlocksAffected, const Vector3d & a_PlayerMotion) = 0;
+ virtual void SendGameMode (eGameMode a_GameMode) = 0;
+ virtual void SendHealth (void) = 0;
+ virtual void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item) = 0;
+ virtual void SendKeepAlive (int a_PingID) = 0;
+ virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) = 0;
+ virtual void SendLoginSuccess (void) = 0;
+ virtual void SendMapColumn (int a_ID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length, unsigned int m_Scale) = 0;
+ virtual void SendMapDecorators (int a_ID, const cMapDecoratorList & a_Decorators, unsigned int m_Scale) = 0;
+ virtual void SendMapInfo (int a_ID, unsigned int a_Scale) = 0;
+ virtual void SendPaintingSpawn (const cPainting & a_Painting) = 0;
+ virtual void SendPickupSpawn (const cPickup & a_Pickup) = 0;
+ virtual void SendPlayerAbilities (void) = 0;
+ virtual void SendEntityAnimation (const cEntity & a_Entity, char a_Animation) = 0;
+ virtual void SendParticleEffect (const AString & a_SoundName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmount) = 0;
+ virtual void SendPlayerListAddPlayer (const cPlayer & a_Player) = 0;
+ virtual void SendPlayerListRemovePlayer (const cPlayer & a_Player) = 0;
+ virtual void SendPlayerListUpdateGameMode (const cPlayer & a_Player) = 0;
+ virtual void SendPlayerListUpdatePing (const cPlayer & a_Player) = 0;
+ virtual void SendPlayerListUpdateDisplayName(const cPlayer & a_Player, const AString & a_OldListName) = 0;
+ virtual void SendPlayerMaxSpeed (void) = 0; ///< Informs the client of the maximum player speed (1.6.1+)
+ virtual void SendPlayerMoveLook (void) = 0;
+ virtual void SendPlayerPosition (void) = 0;
+ virtual void SendPlayerSpawn (const cPlayer & a_Player) = 0;
+ virtual void SendPluginMessage (const AString & a_Channel, const AString & a_Message) = 0;
+ virtual void SendRemoveEntityEffect (const cEntity & a_Entity, int a_EffectID) = 0;
+ virtual void SendRespawn (eDimension a_Dimension, bool a_ShouldIgnoreDimensionChecks) = 0;
+ virtual void SendExperience (void) = 0;
+ virtual void SendExperienceOrb (const cExpOrb & a_ExpOrb) = 0;
+ virtual void SendScoreboardObjective (const AString & a_Name, const AString & a_DisplayName, Byte a_Mode) = 0;
+ virtual void SendScoreUpdate (const AString & a_Objective, const AString & a_Player, cObjective::Score a_Score, Byte a_Mode) = 0;
+ virtual void SendDisplayObjective (const AString & a_Objective, cScoreboard::eDisplaySlot a_Display) = 0;
+ virtual void SendSoundEffect (const AString & a_SoundName, double a_X, double a_Y, double a_Z, float a_Volume, float a_Pitch) = 0;
+ virtual void SendSoundParticleEffect (int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data) = 0;
+ virtual void SendSpawnFallingBlock (const cFallingBlock & a_FallingBlock) = 0;
+ virtual void SendSpawnMob (const cMonster & a_Mob) = 0;
+ virtual void SendSpawnObject (const cEntity & a_Entity, char a_ObjectType, int a_ObjectData, Byte a_Yaw, Byte a_Pitch) = 0;
+ virtual void SendSpawnVehicle (const cEntity & a_Vehicle, char a_VehicleType, char a_VehicleSubType) = 0;
+ virtual void SendStatistics (const cStatManager & a_Manager) = 0;
+ virtual void SendTabCompletionResults (const AStringVector & a_Results) = 0;
+ virtual void SendTeleportEntity (const cEntity & a_Entity) = 0;
+ virtual void SendThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ) = 0;
+ virtual void SendTimeUpdate (Int64 a_WorldAge, Int64 a_TimeOfDay, bool a_DoDaylightCycle) = 0;
+ virtual void SendUnloadChunk (int a_ChunkX, int a_ChunkZ) = 0;
+ virtual void SendUpdateBlockEntity (cBlockEntity & a_BlockEntity) = 0;
+ virtual void SendUpdateSign (int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4) = 0;
+ virtual void SendUseBed (const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ) = 0;
+ virtual void SendWeather (eWeather a_Weather) = 0;
+ virtual void SendWholeInventory (const cWindow & a_Window) = 0;
+ virtual void SendWindowClose (const cWindow & a_Window) = 0;
+ virtual void SendWindowOpen (const cWindow & a_Window) = 0;
+ virtual void SendWindowProperty (const cWindow & a_Window, int a_Property, int a_Value) = 0;
/// Returns the ServerID used for authentication through session.minecraft.net
virtual AString GetAuthServerID(void) = 0;
diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp
index 0b5e3de91..ba4cfa7ef 100644
--- a/src/Protocol/Protocol125.cpp
+++ b/src/Protocol/Protocol125.cpp
@@ -262,7 +262,7 @@ void cProtocol125::SendChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataSerialize
SendPreChunk(a_ChunkX, a_ChunkZ, true);
// Send the chunk data:
- AString Serialized = a_Serializer.Serialize(cChunkDataSerializer::RELEASE_1_2_5);
+ AString Serialized = a_Serializer.Serialize(cChunkDataSerializer::RELEASE_1_2_5, a_ChunkX, a_ChunkZ);
WriteByte(PACKET_MAP_CHUNK);
WriteInt (a_ChunkX);
WriteInt (a_ChunkZ);
@@ -608,7 +608,7 @@ void cProtocol125::SendLoginSuccess(void)
-void cProtocol125::SendMapColumn(int a_ID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length)
+void cProtocol125::SendMapColumn(int a_ID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length, unsigned int m_Scale)
{
cCSLock Lock(m_CSPacket);
@@ -630,7 +630,7 @@ void cProtocol125::SendMapColumn(int a_ID, int a_X, int a_Y, const Byte * a_Colo
-void cProtocol125::SendMapDecorators(int a_ID, const cMapDecoratorList & a_Decorators)
+void cProtocol125::SendMapDecorators(int a_ID, const cMapDecoratorList & a_Decorators, unsigned int m_Scale)
{
cCSLock Lock(m_CSPacket);
@@ -700,7 +700,7 @@ void cProtocol125::SendEntityAnimation(const cEntity & a_Entity, char a_Animatio
-void cProtocol125::SendParticleEffect(const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmmount)
+void cProtocol125::SendParticleEffect(const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmount)
{
// Not supported by this protocol version
}
@@ -719,13 +719,13 @@ void cProtocol125::SendPaintingSpawn(const cPainting & a_Painting)
-void cProtocol125::SendPlayerListItem(const AString & a_PlayerName, bool a_IsOnline, short a_Ping)
+void cProtocol125::SendPlayerListAddPlayer(const cPlayer & a_Player)
{
cCSLock Lock(m_CSPacket);
- WriteByte ((unsigned char)PACKET_PLAYER_LIST_ITEM);
- WriteString(a_PlayerName);
- WriteBool (a_IsOnline);
- WriteShort (a_Ping);
+ WriteByte (PACKET_PLAYER_LIST_ITEM);
+ WriteString(a_Player.GetPlayerListName());
+ WriteBool (true);
+ WriteShort (a_Player.GetClientHandle()->GetPing());
Flush();
}
@@ -733,6 +733,65 @@ void cProtocol125::SendPlayerListItem(const AString & a_PlayerName, bool a_IsOnl
+void cProtocol125::SendPlayerListRemovePlayer(const cPlayer & a_Player)
+{
+ cCSLock Lock(m_CSPacket);
+ WriteByte (PACKET_PLAYER_LIST_ITEM);
+ WriteString(a_Player.GetPlayerListName());
+ WriteBool (false);
+ WriteShort (0);
+ Flush();
+}
+
+
+
+
+
+void cProtocol125::SendPlayerListUpdateGameMode(const cPlayer & a_Player)
+{
+ // Not implemented in this protocol version
+ UNUSED(a_Player);
+}
+
+
+
+
+
+void cProtocol125::SendPlayerListUpdatePing(const cPlayer & a_Player)
+{
+ // It is a simple add player packet in this protocol.
+ SendPlayerListAddPlayer(a_Player);
+}
+
+
+
+
+
+void cProtocol125::SendPlayerListUpdateDisplayName(const cPlayer & a_Player, const AString & a_OldListName)
+{
+ if (a_OldListName == a_Player.GetPlayerListName())
+ {
+ return;
+ }
+
+ cCSLock Lock(m_CSPacket);
+
+ // Remove the old name from the tablist:
+ {
+ WriteByte (PACKET_PLAYER_LIST_ITEM);
+ WriteString(a_OldListName);
+ WriteBool (false);
+ WriteShort (0);
+ Flush();
+ }
+
+ SendPlayerListAddPlayer(a_Player);
+}
+
+
+
+
+
void cProtocol125::SendPlayerMaxSpeed(void)
{
// Not supported by this protocol version
diff --git a/src/Protocol/Protocol125.h b/src/Protocol/Protocol125.h
index 9ab0adfcd..4241c1fd4 100644
--- a/src/Protocol/Protocol125.h
+++ b/src/Protocol/Protocol125.h
@@ -28,76 +28,80 @@ public:
virtual void DataReceived(const char * a_Data, size_t a_Size) override;
/// Sending stuff to clients (alphabetically sorted):
- virtual void SendAttachEntity (const cEntity & a_Entity, const cEntity * a_Vehicle) override;
- virtual void SendBlockAction (int a_BlockX, int a_BlockY, int a_BlockZ, char a_Byte1, char a_Byte2, BLOCKTYPE a_BlockType) override;
- virtual void SendBlockBreakAnim (int a_EntityID, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Stage) override;
- virtual void SendBlockChange (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override;
- virtual void SendBlockChanges (int a_ChunkX, int a_ChunkZ, const sSetBlockVector & a_Changes) override;
- virtual void SendChat (const AString & a_Message) override;
- virtual void SendChat (const cCompositeChat & a_Message) override;
- virtual void SendChunkData (int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer) override;
- virtual void SendCollectEntity (const cEntity & a_Entity, const cPlayer & a_Player) override;
- virtual void SendDestroyEntity (const cEntity & a_Entity) override;
- virtual void SendDisconnect (const AString & a_Reason) override;
- virtual void SendEditSign (int a_BlockX, int a_BlockY, int a_BlockZ) override; ///< Request the client to open up the sign editor for the sign (1.6+)
- virtual void SendEntityEffect (const cEntity & a_Entity, int a_EffectID, int a_Amplifier, short a_Duration) override;
- virtual void SendEntityEquipment (const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item) override;
- virtual void SendEntityHeadLook (const cEntity & a_Entity) override;
- virtual void SendEntityLook (const cEntity & a_Entity) override;
- virtual void SendEntityMetadata (const cEntity & a_Entity) override;
- virtual void SendEntityProperties (const cEntity & a_Entity) override;
- virtual void SendEntityRelMove (const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ) override;
- virtual void SendEntityRelMoveLook (const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ) override;
- virtual void SendEntityStatus (const cEntity & a_Entity, char a_Status) override;
- virtual void SendEntityVelocity (const cEntity & a_Entity) override;
- virtual void SendExplosion (double a_BlockX, double a_BlockY, double a_BlockZ, float a_Radius, const cVector3iArray & a_BlocksAffected, const Vector3d & a_PlayerMotion) override;
- virtual void SendGameMode (eGameMode a_GameMode) override;
- virtual void SendHealth (void) override;
- virtual void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item) override;
- virtual void SendKeepAlive (int a_PingID) override;
- virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) override;
- virtual void SendLoginSuccess (void) override;
- virtual void SendMapColumn (int a_ID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length) override;
- virtual void SendMapDecorators (int a_ID, const cMapDecoratorList & a_Decorators) override;
- virtual void SendMapInfo (int a_ID, unsigned int a_Scale) override;
- virtual void SendParticleEffect (const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmmount) override;
- virtual void SendPaintingSpawn (const cPainting & a_Painting) override;
- virtual void SendPickupSpawn (const cPickup & a_Pickup) override;
- virtual void SendPlayerAbilities (void) override {} // This protocol doesn't support such message
- virtual void SendEntityAnimation (const cEntity & a_Entity, char a_Animation) override;
- virtual void SendPlayerListItem (const AString & a_PlayerName, bool a_IsOnline, short a_Ping = 0) override;
- virtual void SendPlayerMaxSpeed (void) override;
- virtual void SendPlayerMoveLook (void) override;
- virtual void SendPlayerPosition (void) override;
- virtual void SendPlayerSpawn (const cPlayer & a_Player) override;
- virtual void SendPluginMessage (const AString & a_Channel, const AString & a_Message) override;
- virtual void SendRemoveEntityEffect (const cEntity & a_Entity, int a_EffectID) override;
- virtual void SendRespawn (eDimension a_Dimension, bool a_ShouldIgnoreDimensionChecks) override;
- virtual void SendExperience (void) override;
- virtual void SendExperienceOrb (const cExpOrb & a_ExpOrb) override;
- virtual void SendScoreboardObjective (const AString & a_Name, const AString & a_DisplayName, Byte a_Mode) override;
- virtual void SendScoreUpdate (const AString & a_Objective, const AString & a_Player, cObjective::Score a_Score, Byte a_Mode) override {} // This protocol doesn't support such message
- virtual void SendDisplayObjective (const AString & a_Objective, cScoreboard::eDisplaySlot a_Display) override {} // This protocol doesn't support such message
- virtual void SendSoundEffect (const AString & a_SoundName, double a_X, double a_Y, double a_Z, float a_Volume, float a_Pitch) override;
- virtual void SendSoundParticleEffect (int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data) override;
- virtual void SendSpawnFallingBlock (const cFallingBlock & a_FallingBlock) override;
- virtual void SendSpawnMob (const cMonster & a_Mob) override;
- virtual void SendSpawnObject (const cEntity & a_Entity, char a_ObjectType, int a_ObjectData, Byte a_Yaw, Byte a_Pitch) override;
- virtual void SendSpawnVehicle (const cEntity & a_Vehicle, char a_VehicleType, char a_VehicleSubType) override;
- virtual void SendStatistics (const cStatManager & a_Manager) override;
- virtual void SendTabCompletionResults(const AStringVector & a_Results) override;
- virtual void SendTeleportEntity (const cEntity & a_Entity) override;
- virtual void SendThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ) override;
- virtual void SendTimeUpdate (Int64 a_WorldAge, Int64 a_TimeOfDay, bool a_DoDaylightCycle) override;
- virtual void SendUnloadChunk (int a_ChunkX, int a_ChunkZ) override;
- virtual void SendUpdateBlockEntity (cBlockEntity & a_BlockEntity) override {}
- virtual void SendUpdateSign (int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4) override;
- virtual void SendUseBed (const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ) override;
- virtual void SendWeather (eWeather a_Weather) override;
- virtual void SendWholeInventory (const cWindow & a_Window) override;
- virtual void SendWindowClose (const cWindow & a_Window) override;
- virtual void SendWindowOpen (const cWindow & a_Window) override;
- virtual void SendWindowProperty (const cWindow & a_Window, int a_Property, int a_Value) override;
+ virtual void SendAttachEntity (const cEntity & a_Entity, const cEntity * a_Vehicle) override;
+ virtual void SendBlockAction (int a_BlockX, int a_BlockY, int a_BlockZ, char a_Byte1, char a_Byte2, BLOCKTYPE a_BlockType) override;
+ virtual void SendBlockBreakAnim (int a_EntityID, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Stage) override;
+ virtual void SendBlockChange (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override;
+ virtual void SendBlockChanges (int a_ChunkX, int a_ChunkZ, const sSetBlockVector & a_Changes) override;
+ virtual void SendChat (const AString & a_Message) override;
+ virtual void SendChat (const cCompositeChat & a_Message) override;
+ virtual void SendChunkData (int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer) override;
+ virtual void SendCollectEntity (const cEntity & a_Entity, const cPlayer & a_Player) override;
+ virtual void SendDestroyEntity (const cEntity & a_Entity) override;
+ virtual void SendDisconnect (const AString & a_Reason) override;
+ virtual void SendEditSign (int a_BlockX, int a_BlockY, int a_BlockZ) override; ///< Request the client to open up the sign editor for the sign (1.6+)
+ virtual void SendEntityEffect (const cEntity & a_Entity, int a_EffectID, int a_Amplifier, short a_Duration) override;
+ virtual void SendEntityEquipment (const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item) override;
+ virtual void SendEntityHeadLook (const cEntity & a_Entity) override;
+ virtual void SendEntityLook (const cEntity & a_Entity) override;
+ virtual void SendEntityMetadata (const cEntity & a_Entity) override;
+ virtual void SendEntityProperties (const cEntity & a_Entity) override;
+ virtual void SendEntityRelMove (const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ) override;
+ virtual void SendEntityRelMoveLook (const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ) override;
+ virtual void SendEntityStatus (const cEntity & a_Entity, char a_Status) override;
+ virtual void SendEntityVelocity (const cEntity & a_Entity) override;
+ virtual void SendExplosion (double a_BlockX, double a_BlockY, double a_BlockZ, float a_Radius, const cVector3iArray & a_BlocksAffected, const Vector3d & a_PlayerMotion) override;
+ virtual void SendGameMode (eGameMode a_GameMode) override;
+ virtual void SendHealth (void) override;
+ virtual void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item) override;
+ virtual void SendKeepAlive (int a_PingID) override;
+ virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) override;
+ virtual void SendLoginSuccess (void) override;
+ virtual void SendMapColumn (int a_ID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length, unsigned int m_Scale) override;
+ virtual void SendMapDecorators (int a_ID, const cMapDecoratorList & a_Decorators, unsigned int m_Scale) override;
+ virtual void SendMapInfo (int a_ID, unsigned int a_Scale) override;
+ virtual void SendParticleEffect (const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmount) override;
+ virtual void SendPaintingSpawn (const cPainting & a_Painting) override;
+ virtual void SendPickupSpawn (const cPickup & a_Pickup) override;
+ virtual void SendPlayerAbilities (void) override {} // This protocol doesn't support such message
+ virtual void SendEntityAnimation (const cEntity & a_Entity, char a_Animation) override;
+ virtual void SendPlayerListAddPlayer (const cPlayer & a_Player) override;
+ virtual void SendPlayerListRemovePlayer (const cPlayer & a_Player) override;
+ virtual void SendPlayerListUpdateGameMode (const cPlayer & a_Player) override;
+ virtual void SendPlayerListUpdatePing (const cPlayer & a_Player) override;
+ virtual void SendPlayerListUpdateDisplayName(const cPlayer & a_Player, const AString & a_OldListName) override;
+ virtual void SendPlayerMaxSpeed (void) override;
+ virtual void SendPlayerMoveLook (void) override;
+ virtual void SendPlayerPosition (void) override;
+ virtual void SendPlayerSpawn (const cPlayer & a_Player) override;
+ virtual void SendPluginMessage (const AString & a_Channel, const AString & a_Message) override;
+ virtual void SendRemoveEntityEffect (const cEntity & a_Entity, int a_EffectID) override;
+ virtual void SendRespawn (eDimension a_Dimension, bool a_ShouldIgnoreDimensionChecks) override;
+ virtual void SendExperience (void) override;
+ virtual void SendExperienceOrb (const cExpOrb & a_ExpOrb) override;
+ virtual void SendScoreboardObjective (const AString & a_Name, const AString & a_DisplayName, Byte a_Mode) override;
+ virtual void SendScoreUpdate (const AString & a_Objective, const AString & a_Player, cObjective::Score a_Score, Byte a_Mode) override {} // This protocol doesn't support such message
+ virtual void SendDisplayObjective (const AString & a_Objective, cScoreboard::eDisplaySlot a_Display) override {} // This protocol doesn't support such message
+ virtual void SendSoundEffect (const AString & a_SoundName, double a_X, double a_Y, double a_Z, float a_Volume, float a_Pitch) override;
+ virtual void SendSoundParticleEffect (int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data) override;
+ virtual void SendSpawnFallingBlock (const cFallingBlock & a_FallingBlock) override;
+ virtual void SendSpawnMob (const cMonster & a_Mob) override;
+ virtual void SendSpawnObject (const cEntity & a_Entity, char a_ObjectType, int a_ObjectData, Byte a_Yaw, Byte a_Pitch) override;
+ virtual void SendSpawnVehicle (const cEntity & a_Vehicle, char a_VehicleType, char a_VehicleSubType) override;
+ virtual void SendStatistics (const cStatManager & a_Manager) override;
+ virtual void SendTabCompletionResults (const AStringVector & a_Results) override;
+ virtual void SendTeleportEntity (const cEntity & a_Entity) override;
+ virtual void SendThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ) override;
+ virtual void SendTimeUpdate (Int64 a_WorldAge, Int64 a_TimeOfDay, bool a_DoDaylightCycle) override;
+ virtual void SendUnloadChunk (int a_ChunkX, int a_ChunkZ) override;
+ virtual void SendUpdateBlockEntity (cBlockEntity & a_BlockEntity) override {}
+ virtual void SendUpdateSign (int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4) override;
+ virtual void SendUseBed (const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ) override;
+ virtual void SendWeather (eWeather a_Weather) override;
+ virtual void SendWholeInventory (const cWindow & a_Window) override;
+ virtual void SendWindowClose (const cWindow & a_Window) override;
+ virtual void SendWindowOpen (const cWindow & a_Window) override;
+ virtual void SendWindowProperty (const cWindow & a_Window, int a_Property, int a_Value) override;
virtual AString GetAuthServerID(void) override;
diff --git a/src/Protocol/Protocol132.cpp b/src/Protocol/Protocol132.cpp
index af3bc68ee..63a15c082 100644
--- a/src/Protocol/Protocol132.cpp
+++ b/src/Protocol/Protocol132.cpp
@@ -176,7 +176,7 @@ void cProtocol132::SendChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataSerialize
// Pre-chunk not used in 1.3.2. Finally.
// Send the chunk data:
- AString Serialized = a_Serializer.Serialize(cChunkDataSerializer::RELEASE_1_3_2);
+ AString Serialized = a_Serializer.Serialize(cChunkDataSerializer::RELEASE_1_3_2, a_ChunkX, a_ChunkZ);
WriteByte(PACKET_CHUNK_DATA);
WriteInt (a_ChunkX);
WriteInt (a_ChunkZ);
diff --git a/src/Protocol/Protocol14x.cpp b/src/Protocol/Protocol14x.cpp
index 3b6b6a42a..d33314a2f 100644
--- a/src/Protocol/Protocol14x.cpp
+++ b/src/Protocol/Protocol14x.cpp
@@ -132,12 +132,6 @@ void cProtocol142::SendSoundParticleEffect(int a_EffectID, int a_SrcX, int a_Src
void cProtocol142::SendTimeUpdate(Int64 a_WorldAge, Int64 a_TimeOfDay, bool a_DoDaylightCycle)
{
- if (!a_DoDaylightCycle)
- {
- // When writing a "-" before the number the client ignores it but it will stop the client-side time expiration.
- a_TimeOfDay = std::min(-a_TimeOfDay, -1LL);
- }
-
cCSLock Lock(m_CSPacket);
WriteByte (PACKET_UPDATE_TIME);
WriteInt64(a_WorldAge);
diff --git a/src/Protocol/Protocol15x.cpp b/src/Protocol/Protocol15x.cpp
index 2b1f01b08..089296fdf 100644
--- a/src/Protocol/Protocol15x.cpp
+++ b/src/Protocol/Protocol15x.cpp
@@ -80,7 +80,7 @@ void cProtocol150::SendWindowOpen(const cWindow & a_Window)
-void cProtocol150::SendParticleEffect(const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmmount)
+void cProtocol150::SendParticleEffect(const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmount)
{
cCSLock Lock(m_CSPacket);
WriteByte(PACKET_PARTICLE_EFFECT);
@@ -92,7 +92,7 @@ void cProtocol150::SendParticleEffect(const AString & a_ParticleName, float a_Sr
WriteFloat(a_OffsetY);
WriteFloat(a_OffsetZ);
WriteFloat(a_ParticleData);
- WriteInt(a_ParticleAmmount);
+ WriteInt(a_ParticleAmount);
Flush();
}
diff --git a/src/Protocol/Protocol15x.h b/src/Protocol/Protocol15x.h
index 0d171a67c..968d5ebcf 100644
--- a/src/Protocol/Protocol15x.h
+++ b/src/Protocol/Protocol15x.h
@@ -29,7 +29,7 @@ public:
cProtocol150(cClientHandle * a_Client);
virtual void SendWindowOpen (const cWindow & a_Window) override;
- virtual void SendParticleEffect (const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmmount) override;
+ virtual void SendParticleEffect (const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmount) override;
virtual void SendScoreboardObjective (const AString & a_Name, const AString & a_DisplayName, Byte a_Mode) override;
virtual void SendScoreUpdate (const AString & a_Objective, const AString & a_Player, cObjective::Score a_Score, Byte a_Mode) override;
virtual void SendDisplayObjective (const AString & a_Objective, cScoreboard::eDisplaySlot a_Display) override;
diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp
index 2ac1d0d0f..67a4c47a7 100644
--- a/src/Protocol/Protocol17x.cpp
+++ b/src/Protocol/Protocol17x.cpp
@@ -5,7 +5,8 @@
Implements the 1.7.x protocol classes:
- cProtocol172
- release 1.7.2 protocol (#4)
-(others may be added later in the future for the 1.7 release series)
+ - cProtocol176
+ - release 1.7.6 protocol (#5)
*/
#include "Globals.h"
@@ -101,6 +102,19 @@ cProtocol172::cProtocol172(cClientHandle * a_Client, const AString & a_ServerAdd
m_IsEncrypted(false),
m_LastSentDimension(dimNotSet)
{
+ // BungeeCord handling:
+ // If BC is setup with ip_forward == true, it sends additional data in the login packet's ServerAddress field:
+ // hostname\00ip-address\00uuid\00profile-properties-as-json
+ AStringVector Params;
+ if (cRoot::Get()->GetServer()->ShouldAllowBungeeCord() && SplitZeroTerminatedStrings(a_ServerAddress, Params) && (Params.size() == 4))
+ {
+ LOGD("Player at %s connected via BungeeCord", Params[1].c_str());
+ m_ServerAddress = Params[0];
+ m_Client->SetIPString(Params[1]);
+ m_Client->SetUUID(cMojangAPI::MakeUUIDShort(Params[2]));
+ m_Client->SetProperties(Params[3]);
+ }
+
// Create the comm log file, if so requested:
if (g_ShouldLogCommIn || g_ShouldLogCommOut)
{
@@ -238,101 +252,13 @@ void cProtocol172::SendChat(const AString & a_Message)
void cProtocol172::SendChat(const cCompositeChat & a_Message)
{
ASSERT(m_State == 3); // In game mode?
-
- // Compose the complete Json string to send:
- Json::Value msg;
+
cWorld * World = m_Client->GetPlayer()->GetWorld();
- msg["text"] = cClientHandle::FormatMessageType((World == NULL) ? false : World->ShouldUseChatPrefixes(), a_Message.GetMessageType(), a_Message.GetAdditionalMessageTypeData()); // The client crashes without this field being present
- const cCompositeChat::cParts & Parts = a_Message.GetParts();
- for (cCompositeChat::cParts::const_iterator itr = Parts.begin(), end = Parts.end(); itr != end; ++itr)
- {
- Json::Value Part;
- switch ((*itr)->m_PartType)
- {
- case cCompositeChat::ptText:
- {
- Part["text"] = (*itr)->m_Text;
- AddChatPartStyle(Part, (*itr)->m_Style);
- break;
- }
-
- case cCompositeChat::ptClientTranslated:
- {
- const cCompositeChat::cClientTranslatedPart & p = (const cCompositeChat::cClientTranslatedPart &)**itr;
- Part["translate"] = p.m_Text;
- Json::Value With;
- for (AStringVector::const_iterator itrW = p.m_Parameters.begin(), endW = p.m_Parameters.end(); itrW != endW; ++itr)
- {
- With.append(*itrW);
- }
- if (!p.m_Parameters.empty())
- {
- Part["with"] = With;
- }
- AddChatPartStyle(Part, p.m_Style);
- break;
- }
-
- case cCompositeChat::ptUrl:
- {
- const cCompositeChat::cUrlPart & p = (const cCompositeChat::cUrlPart &)**itr;
- Part["text"] = p.m_Text;
- Json::Value Url;
- Url["action"] = "open_url";
- Url["value"] = p.m_Url;
- Part["clickEvent"] = Url;
- AddChatPartStyle(Part, p.m_Style);
- break;
- }
-
- case cCompositeChat::ptSuggestCommand:
- case cCompositeChat::ptRunCommand:
- {
- const cCompositeChat::cCommandPart & p = (const cCompositeChat::cCommandPart &)**itr;
- Part["text"] = p.m_Text;
- Json::Value Cmd;
- Cmd["action"] = (p.m_PartType == cCompositeChat::ptRunCommand) ? "run_command" : "suggest_command";
- Cmd["value"] = p.m_Command;
- Part["clickEvent"] = Cmd;
- AddChatPartStyle(Part, p.m_Style);
- break;
- }
+ bool ShouldUseChatPrefixes = (World == NULL) ? false : World->ShouldUseChatPrefixes();
- case cCompositeChat::ptShowAchievement:
- {
- const cCompositeChat::cShowAchievementPart & p = (const cCompositeChat::cShowAchievementPart &)**itr;
- Part["translate"] = "chat.type.achievement";
-
- Json::Value Ach;
- Ach["action"] = "show_achievement";
- Ach["value"] = p.m_Text;
-
- Json::Value AchColourAndName;
- AchColourAndName["color"] = "green";
- AchColourAndName["translate"] = p.m_Text;
- AchColourAndName["hoverEvent"] = Ach;
-
- Json::Value Extra;
- Extra.append(AchColourAndName);
-
- Json::Value Name;
- Name["text"] = p.m_PlayerName;
-
- Json::Value With;
- With.append(Name);
- With.append(Extra);
-
- Part["with"] = With;
- AddChatPartStyle(Part, p.m_Style);
- break;
- }
- }
- msg["extra"].append(Part);
- } // for itr - Parts[]
-
// Send the message to the client:
cPacketizer Pkt(*this, 0x02);
- Pkt.WriteString(msg.toStyledString());
+ Pkt.WriteString(a_Message.CreateJsonString(ShouldUseChatPrefixes));
}
@@ -345,7 +271,7 @@ void cProtocol172::SendChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataSerialize
// Serialize first, before creating the Packetizer (the packetizer locks a CS)
// This contains the flags and bitmasks, too
- const AString & ChunkData = a_Serializer.Serialize(cChunkDataSerializer::RELEASE_1_3_2);
+ const AString & ChunkData = a_Serializer.Serialize(cChunkDataSerializer::RELEASE_1_3_2, a_ChunkX, a_ChunkZ);
cPacketizer Pkt(*this, 0x21); // Chunk Data packet
Pkt.WriteInt(a_ChunkX);
@@ -714,7 +640,7 @@ void cProtocol172::SendPaintingSpawn(const cPainting & a_Painting)
-void cProtocol172::SendMapColumn(int a_ID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length)
+void cProtocol172::SendMapColumn(int a_ID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length, unsigned int m_Scale)
{
ASSERT(m_State == 3); // In game mode?
@@ -736,7 +662,7 @@ void cProtocol172::SendMapColumn(int a_ID, int a_X, int a_Y, const Byte * a_Colo
-void cProtocol172::SendMapDecorators(int a_ID, const cMapDecoratorList & a_Decorators)
+void cProtocol172::SendMapDecorators(int a_ID, const cMapDecoratorList & a_Decorators, unsigned int m_Scale)
{
ASSERT(m_State == 3); // In game mode?
@@ -774,7 +700,6 @@ void cProtocol172::SendMapInfo(int a_ID, unsigned int a_Scale)
-
void cProtocol172::SendPickupSpawn(const cPickup & a_Pickup)
{
ASSERT(m_State == 3); // In game mode?
@@ -845,7 +770,7 @@ void cProtocol172::SendEntityAnimation(const cEntity & a_Entity, char a_Animatio
-void cProtocol172::SendParticleEffect(const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmmount)
+void cProtocol172::SendParticleEffect(const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmount)
{
ASSERT(m_State == 3); // In game mode?
@@ -858,21 +783,78 @@ void cProtocol172::SendParticleEffect(const AString & a_ParticleName, float a_Sr
Pkt.WriteFloat(a_OffsetY);
Pkt.WriteFloat(a_OffsetZ);
Pkt.WriteFloat(a_ParticleData);
- Pkt.WriteInt(a_ParticleAmmount);
+ Pkt.WriteInt(a_ParticleAmount);
}
-void cProtocol172::SendPlayerListItem(const AString & a_PlayerName, bool a_IsOnline, short a_Ping)
+void cProtocol172::SendPlayerListAddPlayer(const cPlayer & a_Player)
{
ASSERT(m_State == 3); // In game mode?
-
+
cPacketizer Pkt(*this, 0x38); // Playerlist Item packet
- Pkt.WriteString(a_PlayerName);
- Pkt.WriteBool(a_IsOnline);
- Pkt.WriteShort(a_Ping);
+ Pkt.WriteString(a_Player.GetPlayerListName());
+ Pkt.WriteBool(true);
+ Pkt.WriteShort(a_Player.GetClientHandle()->GetPing());
+}
+
+
+
+
+
+void cProtocol172::SendPlayerListRemovePlayer(const cPlayer & a_Player)
+{
+ ASSERT(m_State == 3); // In game mode?
+
+ cPacketizer Pkt(*this, 0x38);
+ Pkt.WriteString(a_Player.GetPlayerListName());
+ Pkt.WriteBool(false);
+ Pkt.WriteShort(0);
+}
+
+
+
+
+
+void cProtocol172::SendPlayerListUpdateGameMode(const cPlayer & a_Player)
+{
+ // Not implemented in this protocol version
+ UNUSED(a_Player);
+}
+
+
+
+
+
+void cProtocol172::SendPlayerListUpdatePing(const cPlayer & a_Player)
+{
+ // It is a simple add player packet in this protocol.
+ SendPlayerListAddPlayer(a_Player);
+}
+
+
+
+
+
+void cProtocol172::SendPlayerListUpdateDisplayName(const cPlayer & a_Player, const AString & a_OldListName)
+{
+ ASSERT(m_State == 3); // In game mode?
+ if (a_OldListName == a_Player.GetPlayerListName())
+ {
+ return;
+ }
+
+ // Remove the old name from the tablist:
+ {
+ cPacketizer Pkt(*this, 0x38);
+ Pkt.WriteString(a_OldListName);
+ Pkt.WriteBool(false);
+ Pkt.WriteShort(0);
+ }
+
+ SendPlayerListAddPlayer(a_Player);
}
@@ -1041,9 +1023,9 @@ void cProtocol172::SendExperienceOrb(const cExpOrb & a_ExpOrb)
cPacketizer Pkt(*this, 0x11);
Pkt.WriteVarInt(a_ExpOrb.GetUniqueID());
- Pkt.WriteInt((int) a_ExpOrb.GetPosX());
- Pkt.WriteInt((int) a_ExpOrb.GetPosY());
- Pkt.WriteInt((int) a_ExpOrb.GetPosZ());
+ Pkt.WriteFPInt(a_ExpOrb.GetPosX());
+ Pkt.WriteFPInt(a_ExpOrb.GetPosY());
+ Pkt.WriteFPInt(a_ExpOrb.GetPosZ());
Pkt.WriteShort(a_ExpOrb.GetReward());
}
@@ -1363,6 +1345,7 @@ void cProtocol172::SendUpdateBlockEntity(cBlockEntity & a_BlockEntity)
void cProtocol172::SendUpdateSign(int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4)
{
ASSERT(m_State == 3); // In game mode?
+ ASSERT((a_BlockY >= 0) && (a_BlockY < cChunkDef::Height));
cPacketizer Pkt(*this, 0x33);
Pkt.WriteInt(a_BlockX);
@@ -1508,14 +1491,14 @@ void cProtocol172::AddReceivedData(const char * a_Data, size_t a_Size)
);
m_CommLogFile.Flush();
}
-
+
if (!m_ReceivedData.Write(a_Data, a_Size))
{
// Too much data in the incoming queue, report to caller:
m_Client->PacketBufferFull();
return;
}
-
+
// Handle all complete packets:
for (;;)
{
@@ -1535,7 +1518,7 @@ void cProtocol172::AddReceivedData(const char * a_Data, size_t a_Size)
cByteBuffer bb(PacketLen + 1);
VERIFY(m_ReceivedData.ReadToByteBuffer(bb, (int)PacketLen));
m_ReceivedData.CommitRead();
-
+
// Write one NUL extra, so that we can detect over-reads
bb.Write("\0", 1);
@@ -1561,7 +1544,7 @@ void cProtocol172::AddReceivedData(const char * a_Data, size_t a_Size)
PacketType, PacketType, PacketLen, PacketLen, m_State, PacketDataHex.c_str()
);
}
-
+
if (!HandlePacket(bb, PacketType))
{
// Unknown packet, already been reported, but without the length. Log the length here:
@@ -1586,7 +1569,7 @@ void cProtocol172::AddReceivedData(const char * a_Data, size_t a_Size)
return;
}
-
+
if (bb.GetReadableSpace() != 1)
{
// Read more or less than packet length, report as error
@@ -1607,7 +1590,7 @@ void cProtocol172::AddReceivedData(const char * a_Data, size_t a_Size)
m_Client->PacketError(PacketType);
}
} // for (ever)
-
+
// Log any leftover bytes into the logfile:
if (g_ShouldLogCommIn && (m_ReceivedData.GetReadableSpace() > 0))
{
@@ -1718,7 +1701,7 @@ bool cProtocol172::HandlePacket(cByteBuffer & a_ByteBuffer, UInt32 a_PacketType)
void cProtocol172::HandlePacketStatusPing(cByteBuffer & a_ByteBuffer)
{
HANDLE_READ(a_ByteBuffer, ReadBEInt64, Int64, Timestamp);
-
+
cPacketizer Pkt(*this, 0x01); // Ping packet
Pkt.WriteInt64(Timestamp);
}
@@ -1930,7 +1913,7 @@ void cProtocol172::HandlePacketClientSettings(cByteBuffer & a_ByteBuffer)
HANDLE_READ(a_ByteBuffer, ReadByte, Byte, ShowCape);
m_Client->SetLocale(Locale);
- // TODO: handle in m_Client
+ // TODO: Do anything with the other values.
}
@@ -2284,7 +2267,6 @@ void cProtocol172::SendData(const char * a_Data, size_t a_Size)
-
bool cProtocol172::ReadItem(cByteBuffer & a_ByteBuffer, cItem & a_Item)
{
HANDLE_PACKET_READ(a_ByteBuffer, ReadBEShort, short, ItemType);
@@ -2429,85 +2411,6 @@ void cProtocol172::StartEncryption(const Byte * a_Key)
-void cProtocol172::AddChatPartStyle(Json::Value & a_Value, const AString & a_PartStyle)
-{
- size_t len = a_PartStyle.length();
- for (size_t i = 0; i < len; i++)
- {
- switch (a_PartStyle[i])
- {
- case 'b':
- {
- // bold
- a_Value["bold"] = Json::Value(true);
- break;
- }
-
- case 'i':
- {
- // italic
- a_Value["italic"] = Json::Value(true);
- break;
- }
-
- case 'u':
- {
- // Underlined
- a_Value["underlined"] = Json::Value(true);
- break;
- }
-
- case 's':
- {
- // strikethrough
- a_Value["strikethrough"] = Json::Value(true);
- break;
- }
-
- case 'o':
- {
- // obfuscated
- a_Value["obfuscated"] = Json::Value(true);
- break;
- }
-
- case '@':
- {
- // Color, specified by the next char:
- i++;
- if (i >= len)
- {
- // String too short, didn't contain a color
- break;
- }
- switch (a_PartStyle[i])
- {
- case '0': a_Value["color"] = Json::Value("black"); break;
- case '1': a_Value["color"] = Json::Value("dark_blue"); break;
- case '2': a_Value["color"] = Json::Value("dark_green"); break;
- case '3': a_Value["color"] = Json::Value("dark_aqua"); break;
- case '4': a_Value["color"] = Json::Value("dark_red"); break;
- case '5': a_Value["color"] = Json::Value("dark_purple"); break;
- case '6': a_Value["color"] = Json::Value("gold"); break;
- case '7': a_Value["color"] = Json::Value("gray"); break;
- case '8': a_Value["color"] = Json::Value("dark_gray"); break;
- case '9': a_Value["color"] = Json::Value("blue"); break;
- case 'a': a_Value["color"] = Json::Value("green"); break;
- case 'b': a_Value["color"] = Json::Value("aqua"); break;
- case 'c': a_Value["color"] = Json::Value("red"); break;
- case 'd': a_Value["color"] = Json::Value("light_purple"); break;
- case 'e': a_Value["color"] = Json::Value("yellow"); break;
- case 'f': a_Value["color"] = Json::Value("white"); break;
- } // switch (color)
- } // case '@'
- } // switch (Style[i])
- } // for i - a_PartStyle[]
-}
-
-
-
-
-
////////////////////////////////////////////////////////////////////////////////
// cProtocol172::cPacketizer:
@@ -2517,6 +2420,7 @@ cProtocol172::cPacketizer::~cPacketizer()
// Send the packet length
UInt32 PacketLen = (UInt32)m_Out.GetUsedSpace();
+
m_Protocol.m_OutPacketLenBuffer.WriteVarInt(PacketLen);
m_Protocol.m_OutPacketLenBuffer.ReadAll(DataToSend);
m_Protocol.SendData(DataToSend.data(), DataToSend.size());
@@ -2611,6 +2515,7 @@ void cProtocol172::cPacketizer::WriteItem(const cItem & a_Item)
cFireworkItem::WriteToNBTCompound(a_Item.m_FireworkItem, Writer, (ENUM_ITEM_ID)a_Item.m_ItemType);
}
Writer.Finish();
+
AString Compressed;
CompressStringGZIP(Writer.GetResult().data(), Writer.GetResult().size(), Compressed);
WriteShort((short)Compressed.size());
@@ -2620,6 +2525,7 @@ void cProtocol172::cPacketizer::WriteItem(const cItem & a_Item)
+
void cProtocol172::cPacketizer::WriteBlockEntity(const cBlockEntity & a_BlockEntity)
{
cFastNBTWriter Writer;
@@ -2831,7 +2737,7 @@ void cProtocol172::cPacketizer::WriteEntityMetadata(const cEntity & a_Entity)
WriteByte(0xA2);
WriteItem(Frame.GetItem());
WriteByte(0x3);
- WriteByte(Frame.GetRotation());
+ WriteByte(Frame.GetRotation() / 2);
break;
}
default: break;
diff --git a/src/Protocol/Protocol17x.h b/src/Protocol/Protocol17x.h
index eb64f6ad5..7ec7d0fce 100644
--- a/src/Protocol/Protocol17x.h
+++ b/src/Protocol/Protocol17x.h
@@ -5,7 +5,8 @@
Declares the 1.7.x protocol classes:
- cProtocol172
- release 1.7.2 protocol (#4)
-(others may be added later in the future for the 1.7 release series)
+ - cProtocol176
+ - release 1.7.6 protocol (#5)
*/
@@ -60,76 +61,80 @@ public:
virtual void DataReceived(const char * a_Data, size_t a_Size) override;
/** Sending stuff to clients (alphabetically sorted): */
- virtual void SendAttachEntity (const cEntity & a_Entity, const cEntity * a_Vehicle) override;
- virtual void SendBlockAction (int a_BlockX, int a_BlockY, int a_BlockZ, char a_Byte1, char a_Byte2, BLOCKTYPE a_BlockType) override;
- virtual void SendBlockBreakAnim (int a_EntityID, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Stage) override;
- virtual void SendBlockChange (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override;
- virtual void SendBlockChanges (int a_ChunkX, int a_ChunkZ, const sSetBlockVector & a_Changes) override;
- virtual void SendChat (const AString & a_Message) override;
- virtual void SendChat (const cCompositeChat & a_Message) override;
- virtual void SendChunkData (int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer) override;
- virtual void SendCollectEntity (const cEntity & a_Entity, const cPlayer & a_Player) override;
- virtual void SendDestroyEntity (const cEntity & a_Entity) override;
- virtual void SendDisconnect (const AString & a_Reason) override;
- virtual void SendEditSign (int a_BlockX, int a_BlockY, int a_BlockZ) override; ///< Request the client to open up the sign editor for the sign (1.6+)
- virtual void SendEntityEffect (const cEntity & a_Entity, int a_EffectID, int a_Amplifier, short a_Duration) override;
- virtual void SendEntityEquipment (const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item) override;
- virtual void SendEntityHeadLook (const cEntity & a_Entity) override;
- virtual void SendEntityLook (const cEntity & a_Entity) override;
- virtual void SendEntityMetadata (const cEntity & a_Entity) override;
- virtual void SendEntityProperties (const cEntity & a_Entity) override;
- virtual void SendEntityRelMove (const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ) override;
- virtual void SendEntityRelMoveLook (const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ) override;
- virtual void SendEntityStatus (const cEntity & a_Entity, char a_Status) override;
- virtual void SendEntityVelocity (const cEntity & a_Entity) override;
- virtual void SendExplosion (double a_BlockX, double a_BlockY, double a_BlockZ, float a_Radius, const cVector3iArray & a_BlocksAffected, const Vector3d & a_PlayerMotion) override;
- virtual void SendGameMode (eGameMode a_GameMode) override;
- virtual void SendHealth (void) override;
- virtual void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item) override;
- virtual void SendKeepAlive (int a_PingID) override;
- virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) override;
- virtual void SendLoginSuccess (void) override;
- virtual void SendMapColumn (int a_ID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length) override;
- virtual void SendMapDecorators (int a_ID, const cMapDecoratorList & a_Decorators) override;
- virtual void SendMapInfo (int a_ID, unsigned int a_Scale) override;
- virtual void SendPaintingSpawn (const cPainting & a_Painting) override;
- virtual void SendPickupSpawn (const cPickup & a_Pickup) override;
- virtual void SendPlayerAbilities (void) override;
- virtual void SendEntityAnimation (const cEntity & a_Entity, char a_Animation) override;
- virtual void SendParticleEffect (const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmmount) override;
- virtual void SendPlayerListItem (const AString & a_PlayerName, bool a_IsOnline, short a_Ping = 0) override;
- virtual void SendPlayerMaxSpeed (void) override;
- virtual void SendPlayerMoveLook (void) override;
- virtual void SendPlayerPosition (void) override;
- virtual void SendPlayerSpawn (const cPlayer & a_Player) override;
- virtual void SendPluginMessage (const AString & a_Channel, const AString & a_Message) override;
- virtual void SendRemoveEntityEffect (const cEntity & a_Entity, int a_EffectID) override;
- virtual void SendRespawn (eDimension a_Dimension, bool a_ShouldIgnoreDimensionChecks) override;
- virtual void SendSoundEffect (const AString & a_SoundName, double a_X, double a_Y, double a_Z, float a_Volume, float a_Pitch) override;
- virtual void SendExperience (void) override;
- virtual void SendExperienceOrb (const cExpOrb & a_ExpOrb) override;
- virtual void SendScoreboardObjective (const AString & a_Name, const AString & a_DisplayName, Byte a_Mode) override;
- virtual void SendScoreUpdate (const AString & a_Objective, const AString & a_Player, cObjective::Score a_Score, Byte a_Mode) override;
- virtual void SendDisplayObjective (const AString & a_Objective, cScoreboard::eDisplaySlot a_Display) override;
- virtual void SendSoundParticleEffect (int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data) override;
- virtual void SendSpawnFallingBlock (const cFallingBlock & a_FallingBlock) override;
- virtual void SendSpawnMob (const cMonster & a_Mob) override;
- virtual void SendSpawnObject (const cEntity & a_Entity, char a_ObjectType, int a_ObjectData, Byte a_Yaw, Byte a_Pitch) override;
- virtual void SendSpawnVehicle (const cEntity & a_Vehicle, char a_VehicleType, char a_VehicleSubType) override;
- virtual void SendStatistics (const cStatManager & a_Manager) override;
- virtual void SendTabCompletionResults(const AStringVector & a_Results) override;
- virtual void SendTeleportEntity (const cEntity & a_Entity) override;
- virtual void SendThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ) override;
- virtual void SendTimeUpdate (Int64 a_WorldAge, Int64 a_TimeOfDay, bool a_DoDaylightCycle) override;
- virtual void SendUnloadChunk (int a_ChunkX, int a_ChunkZ) override;
- virtual void SendUpdateBlockEntity (cBlockEntity & a_BlockEntity) override;
- virtual void SendUpdateSign (int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4) override;
- virtual void SendUseBed (const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ) override;
- virtual void SendWeather (eWeather a_Weather) override;
- virtual void SendWholeInventory (const cWindow & a_Window) override;
- virtual void SendWindowClose (const cWindow & a_Window) override;
- virtual void SendWindowOpen (const cWindow & a_Window) override;
- virtual void SendWindowProperty (const cWindow & a_Window, int a_Property, int a_Value) override;
+ virtual void SendAttachEntity (const cEntity & a_Entity, const cEntity * a_Vehicle) override;
+ virtual void SendBlockAction (int a_BlockX, int a_BlockY, int a_BlockZ, char a_Byte1, char a_Byte2, BLOCKTYPE a_BlockType) override;
+ virtual void SendBlockBreakAnim (int a_EntityID, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Stage) override;
+ virtual void SendBlockChange (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override;
+ virtual void SendBlockChanges (int a_ChunkX, int a_ChunkZ, const sSetBlockVector & a_Changes) override;
+ virtual void SendChat (const AString & a_Message) override;
+ virtual void SendChat (const cCompositeChat & a_Message) override;
+ virtual void SendChunkData (int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer) override;
+ virtual void SendCollectEntity (const cEntity & a_Entity, const cPlayer & a_Player) override;
+ virtual void SendDestroyEntity (const cEntity & a_Entity) override;
+ virtual void SendDisconnect (const AString & a_Reason) override;
+ virtual void SendDisplayObjective (const AString & a_Objective, cScoreboard::eDisplaySlot a_Display) override;
+ virtual void SendEditSign (int a_BlockX, int a_BlockY, int a_BlockZ) override; ///< Request the client to open up the sign editor for the sign (1.6+)
+ virtual void SendEntityAnimation (const cEntity & a_Entity, char a_Animation) override;
+ virtual void SendEntityEffect (const cEntity & a_Entity, int a_EffectID, int a_Amplifier, short a_Duration) override;
+ virtual void SendEntityEquipment (const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item) override;
+ virtual void SendEntityHeadLook (const cEntity & a_Entity) override;
+ virtual void SendEntityLook (const cEntity & a_Entity) override;
+ virtual void SendEntityMetadata (const cEntity & a_Entity) override;
+ virtual void SendEntityProperties (const cEntity & a_Entity) override;
+ virtual void SendEntityRelMove (const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ) override;
+ virtual void SendEntityRelMoveLook (const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ) override;
+ virtual void SendEntityStatus (const cEntity & a_Entity, char a_Status) override;
+ virtual void SendEntityVelocity (const cEntity & a_Entity) override;
+ virtual void SendExperience (void) override;
+ virtual void SendExperienceOrb (const cExpOrb & a_ExpOrb) override;
+ virtual void SendExplosion (double a_BlockX, double a_BlockY, double a_BlockZ, float a_Radius, const cVector3iArray & a_BlocksAffected, const Vector3d & a_PlayerMotion) override;
+ virtual void SendGameMode (eGameMode a_GameMode) override;
+ virtual void SendHealth (void) override;
+ virtual void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item) override;
+ virtual void SendKeepAlive (int a_PingID) override;
+ virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) override;
+ virtual void SendLoginSuccess (void) override;
+ virtual void SendMapColumn (int a_ID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length, unsigned int m_Scale) override;
+ virtual void SendMapDecorators (int a_ID, const cMapDecoratorList & a_Decorators, unsigned int m_Scale) override;
+ virtual void SendMapInfo (int a_ID, unsigned int a_Scale) override;
+ virtual void SendPaintingSpawn (const cPainting & a_Painting) override;
+ virtual void SendParticleEffect (const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmount) override;
+ virtual void SendPickupSpawn (const cPickup & a_Pickup) override;
+ virtual void SendPlayerAbilities (void) override;
+ virtual void SendPlayerListAddPlayer (const cPlayer & a_Player) override;
+ virtual void SendPlayerListRemovePlayer (const cPlayer & a_Player) override;
+ virtual void SendPlayerListUpdateGameMode (const cPlayer & a_Player) override;
+ virtual void SendPlayerListUpdatePing (const cPlayer & a_Player) override;
+ virtual void SendPlayerListUpdateDisplayName(const cPlayer & a_Player, const AString & a_OldListName) override;
+ virtual void SendPlayerMaxSpeed (void) override;
+ virtual void SendPlayerMoveLook (void) override;
+ virtual void SendPlayerPosition (void) override;
+ virtual void SendPlayerSpawn (const cPlayer & a_Player) override;
+ virtual void SendPluginMessage (const AString & a_Channel, const AString & a_Message) override;
+ virtual void SendRemoveEntityEffect (const cEntity & a_Entity, int a_EffectID) override;
+ virtual void SendRespawn (eDimension a_Dimension, bool a_ShouldIgnoreDimensionChecks) override;
+ virtual void SendScoreUpdate (const AString & a_Objective, const AString & a_Player, cObjective::Score a_Score, Byte a_Mode) override;
+ virtual void SendScoreboardObjective (const AString & a_Name, const AString & a_DisplayName, Byte a_Mode) override;
+ virtual void SendSoundEffect (const AString & a_SoundName, double a_X, double a_Y, double a_Z, float a_Volume, float a_Pitch) override;
+ virtual void SendSoundParticleEffect (int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data) override;
+ virtual void SendSpawnFallingBlock (const cFallingBlock & a_FallingBlock) override;
+ virtual void SendSpawnMob (const cMonster & a_Mob) override;
+ virtual void SendSpawnObject (const cEntity & a_Entity, char a_ObjectType, int a_ObjectData, Byte a_Yaw, Byte a_Pitch) override;
+ virtual void SendSpawnVehicle (const cEntity & a_Vehicle, char a_VehicleType, char a_VehicleSubType) override;
+ virtual void SendStatistics (const cStatManager & a_Manager) override;
+ virtual void SendTabCompletionResults (const AStringVector & a_Results) override;
+ virtual void SendTeleportEntity (const cEntity & a_Entity) override;
+ virtual void SendThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ) override;
+ virtual void SendTimeUpdate (Int64 a_WorldAge, Int64 a_TimeOfDay, bool a_DoDaylightCycle) override;
+ virtual void SendUnloadChunk (int a_ChunkX, int a_ChunkZ) override;
+ virtual void SendUpdateBlockEntity (cBlockEntity & a_BlockEntity) override;
+ virtual void SendUpdateSign (int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4) override;
+ virtual void SendUseBed (const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ) override;
+ virtual void SendWeather (eWeather a_Weather) override;
+ virtual void SendWholeInventory (const cWindow & a_Window) override;
+ virtual void SendWindowClose (const cWindow & a_Window) override;
+ virtual void SendWindowOpen (const cWindow & a_Window) override;
+ virtual void SendWindowProperty (const cWindow & a_Window, int a_Property, int a_Value) override;
virtual AString GetAuthServerID(void) override { return m_AuthServerID; }
@@ -251,19 +256,19 @@ protected:
/** Adds the received (unencrypted) data to m_ReceivedData, parses complete packets */
void AddReceivedData(const char * a_Data, size_t a_Size);
-
+
/** Reads and handles the packet. The packet length and type have already been read.
Returns true if the packet was understood, false if it was an unknown packet
*/
bool HandlePacket(cByteBuffer & a_ByteBuffer, UInt32 a_PacketType);
-
+
// Packet handlers while in the Status state (m_State == 1):
- void HandlePacketStatusPing (cByteBuffer & a_ByteBuffer);
+ void HandlePacketStatusPing(cByteBuffer & a_ByteBuffer);
virtual void HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer);
-
+
// Packet handlers while in the Login state (m_State == 2):
void HandlePacketLoginEncryptionResponse(cByteBuffer & a_ByteBuffer);
- void HandlePacketLoginStart (cByteBuffer & a_ByteBuffer);
+ void HandlePacketLoginStart(cByteBuffer & a_ByteBuffer);
// Packet handlers while in the Game state (m_State == 3):
void HandlePacketAnimation (cByteBuffer & a_ByteBuffer);
@@ -300,15 +305,13 @@ protected:
void SendCompass(const cWorld & a_World);
/** Reads an item out of the received data, sets a_Item to the values read. Returns false if not enough received data */
- bool ReadItem(cByteBuffer & a_ByteBuffer, cItem & a_Item);
+ virtual bool ReadItem(cByteBuffer & a_ByteBuffer, cItem & a_Item);
/** Parses item metadata as read by ReadItem(), into the item enchantments. */
void ParseItemMetadata(cItem & a_Item, const AString & a_Metadata);
void StartEncryption(const Byte * a_Key);
-
- /** Adds the chat part's style (represented by the part's stylestring) into the Json object. */
- void AddChatPartStyle(Json::Value & a_Value, const AString & a_PartStyle);
+
} ;
diff --git a/src/Protocol/Protocol18x.cpp b/src/Protocol/Protocol18x.cpp
new file mode 100644
index 000000000..e2ea6701a
--- /dev/null
+++ b/src/Protocol/Protocol18x.cpp
@@ -0,0 +1,3244 @@
+
+// Protocol18x.cpp
+
+/*
+Implements the 1.8.x protocol classes:
+ - cProtocol180
+ - release 1.8.0 protocol (#47)
+(others may be added later in the future for the 1.8 release series)
+*/
+
+#include "Globals.h"
+#include "json/json.h"
+#include "Protocol18x.h"
+#include "ChunkDataSerializer.h"
+#include "PolarSSL++/Sha1Checksum.h"
+
+#include "../ClientHandle.h"
+#include "../Root.h"
+#include "../Server.h"
+#include "../World.h"
+#include "../StringCompression.h"
+#include "../CompositeChat.h"
+#include "../Statistics.h"
+
+#include "../WorldStorage/FastNBT.h"
+#include "../WorldStorage/EnchantmentSerializer.h"
+
+#include "../Entities/ExpOrb.h"
+#include "../Entities/Minecart.h"
+#include "../Entities/FallingBlock.h"
+#include "../Entities/Painting.h"
+#include "../Entities/Pickup.h"
+#include "../Entities/Player.h"
+#include "../Entities/ItemFrame.h"
+#include "../Entities/ArrowEntity.h"
+#include "../Entities/FireworkEntity.h"
+
+#include "../Mobs/IncludeAllMonsters.h"
+#include "../UI/Window.h"
+
+#include "../BlockEntities/BeaconEntity.h"
+#include "../BlockEntities/CommandBlockEntity.h"
+#include "../BlockEntities/MobHeadEntity.h"
+#include "../BlockEntities/FlowerPotEntity.h"
+#include "Bindings/PluginManager.h"
+
+
+
+
+
+#define HANDLE_READ(ByteBuf, Proc, Type, Var) \
+ Type Var; \
+ if (!ByteBuf.Proc(Var))\
+ {\
+ return;\
+ }
+
+
+
+
+
+#define HANDLE_PACKET_READ(ByteBuf, Proc, Type, Var) \
+ Type Var; \
+ { \
+ if (!ByteBuf.Proc(Var)) \
+ { \
+ ByteBuf.CheckValid(); \
+ return false; \
+ } \
+ ByteBuf.CheckValid(); \
+ }
+
+
+
+
+
+const int MAX_ENC_LEN = 512; // Maximum size of the encrypted message; should be 128, but who knows...
+const uLongf MAX_COMPRESSED_PACKET_LEN = 200 KiB; // Maximum size of compressed packets.
+
+
+
+
+
+// fwd: main.cpp:
+extern bool g_ShouldLogCommIn, g_ShouldLogCommOut;
+
+
+
+
+
+////////////////////////////////////////////////////////////////////////////////
+// cProtocol180:
+
+cProtocol180::cProtocol180(cClientHandle * a_Client, const AString & a_ServerAddress, UInt16 a_ServerPort, UInt32 a_State) :
+ super(a_Client),
+ m_ServerAddress(a_ServerAddress),
+ m_ServerPort(a_ServerPort),
+ m_State(a_State),
+ m_ReceivedData(32 KiB),
+ m_OutPacketBuffer(64 KiB),
+ m_OutPacketLenBuffer(20), // 20 bytes is more than enough for one VarInt
+ m_IsEncrypted(false),
+ m_LastSentDimension(dimNotSet)
+{
+ // Create the comm log file, if so requested:
+ if (g_ShouldLogCommIn || g_ShouldLogCommOut)
+ {
+ static int sCounter = 0;
+ cFile::CreateFolder("CommLogs");
+ AString FileName = Printf("CommLogs/%x_%d__%s.log", (unsigned)time(NULL), sCounter++, a_Client->GetIPString().c_str());
+ m_CommLogFile.Open(FileName, cFile::fmWrite);
+ }
+}
+
+
+
+
+
+void cProtocol180::DataReceived(const char * a_Data, size_t a_Size)
+{
+ if (m_IsEncrypted)
+ {
+ Byte Decrypted[512];
+ while (a_Size > 0)
+ {
+ size_t NumBytes = (a_Size > sizeof(Decrypted)) ? sizeof(Decrypted) : a_Size;
+ m_Decryptor.ProcessData(Decrypted, (Byte *)a_Data, NumBytes);
+ AddReceivedData((const char *)Decrypted, NumBytes);
+ a_Size -= NumBytes;
+ a_Data += NumBytes;
+ }
+ }
+ else
+ {
+ AddReceivedData(a_Data, a_Size);
+ }
+}
+
+
+
+
+
+void cProtocol180::SendAttachEntity(const cEntity & a_Entity, const cEntity * a_Vehicle)
+{
+ ASSERT(m_State == 3); // In game mode?
+
+ cPacketizer Pkt(*this, 0x1b); // Attach Entity packet
+ Pkt.WriteInt(a_Entity.GetUniqueID());
+ Pkt.WriteInt((a_Vehicle != NULL) ? a_Vehicle->GetUniqueID() : 0);
+ Pkt.WriteBool(false);
+}
+
+
+
+
+
+void cProtocol180::SendBlockAction(int a_BlockX, int a_BlockY, int a_BlockZ, char a_Byte1, char a_Byte2, BLOCKTYPE a_BlockType)
+{
+ ASSERT(m_State == 3); // In game mode?
+
+ cPacketizer Pkt(*this, 0x24); // Block Action packet
+ Pkt.WritePosition(a_BlockX, a_BlockY, a_BlockZ);
+ Pkt.WriteByte(a_Byte1);
+ Pkt.WriteByte(a_Byte2);
+ Pkt.WriteVarInt(a_BlockType);
+}
+
+
+
+
+
+void cProtocol180::SendBlockBreakAnim(int a_EntityID, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Stage)
+{
+ ASSERT(m_State == 3); // In game mode?
+
+ cPacketizer Pkt(*this, 0x25); // Block Break Animation packet
+ Pkt.WriteVarInt(a_EntityID);
+ Pkt.WritePosition(a_BlockX, a_BlockY, a_BlockZ);
+ Pkt.WriteChar(a_Stage);
+}
+
+
+
+
+
+void cProtocol180::SendBlockChange(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
+{
+ ASSERT(m_State == 3); // In game mode?
+
+ cPacketizer Pkt(*this, 0x23); // Block Change packet
+ Pkt.WritePosition(a_BlockX, a_BlockY, a_BlockZ);
+ Pkt.WriteVarInt(((UInt32)a_BlockType << 4) | ((UInt32)a_BlockMeta & 15));
+}
+
+
+
+
+
+void cProtocol180::SendBlockChanges(int a_ChunkX, int a_ChunkZ, const sSetBlockVector & a_Changes)
+{
+ ASSERT(m_State == 3); // In game mode?
+
+ cPacketizer Pkt(*this, 0x22); // Multi Block Change packet
+ Pkt.WriteInt(a_ChunkX);
+ Pkt.WriteInt(a_ChunkZ);
+ Pkt.WriteVarInt((UInt32)a_Changes.size());
+ for (sSetBlockVector::const_iterator itr = a_Changes.begin(), end = a_Changes.end(); itr != end; ++itr)
+ {
+ short Coords = (short) (itr->y | (itr->z << 8) | (itr->x << 12));
+ Pkt.WriteShort(Coords);
+ Pkt.WriteVarInt((itr->BlockType & 0xFFF) << 4 | (itr->BlockMeta & 0xF));
+ } // for itr - a_Changes[]
+}
+
+
+
+
+
+void cProtocol180::SendChat(const AString & a_Message)
+{
+ ASSERT(m_State == 3); // In game mode?
+
+ cPacketizer Pkt(*this, 0x02); // Chat Message packet
+ Pkt.WriteString(Printf("{\"text\":\"%s\"}", EscapeString(a_Message).c_str()));
+ Pkt.WriteChar(0);
+}
+
+
+
+
+
+void cProtocol180::SendChat(const cCompositeChat & a_Message)
+{
+ ASSERT(m_State == 3); // In game mode?
+
+ cWorld * World = m_Client->GetPlayer()->GetWorld();
+ bool ShouldUseChatPrefixes = (World == NULL) ? false : World->ShouldUseChatPrefixes();
+
+ // Send the message to the client:
+ cPacketizer Pkt(*this, 0x02);
+ Pkt.WriteString(a_Message.CreateJsonString(ShouldUseChatPrefixes));
+ Pkt.WriteChar(0);
+}
+
+
+
+
+
+void cProtocol180::SendChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer)
+{
+ ASSERT(m_State == 3); // In game mode?
+
+ // Serialize first, before creating the Packetizer (the packetizer locks a CS)
+ // This contains the flags and bitmasks, too
+ const AString & ChunkData = a_Serializer.Serialize(cChunkDataSerializer::RELEASE_1_8_0, a_ChunkX, a_ChunkZ);
+
+ cCSLock Lock(m_CSPacket);
+ SendData(ChunkData.data(), ChunkData.size());
+}
+
+
+
+
+
+void cProtocol180::SendCollectEntity(const cEntity & a_Entity, const cPlayer & a_Player)
+{
+ ASSERT(m_State == 3); // In game mode?
+
+ cPacketizer Pkt(*this, 0x0d); // Collect Item packet
+ Pkt.WriteVarInt(a_Entity.GetUniqueID());
+ Pkt.WriteVarInt(a_Player.GetUniqueID());
+}
+
+
+
+
+
+void cProtocol180::SendDestroyEntity(const cEntity & a_Entity)
+{
+ ASSERT(m_State == 3); // In game mode?
+
+ cPacketizer Pkt(*this, 0x13); // Destroy Entities packet
+ Pkt.WriteVarInt(1);
+ Pkt.WriteVarInt(a_Entity.GetUniqueID());
+}
+
+
+
+
+
+void cProtocol180::SendDisconnect(const AString & a_Reason)
+{
+ switch (m_State)
+ {
+ case 2:
+ {
+ // During login:
+ cPacketizer Pkt(*this, 0);
+ Pkt.WriteString(Printf("{\"text\":\"%s\"}", EscapeString(a_Reason).c_str()));
+ break;
+ }
+ case 3:
+ {
+ // In-game:
+ cPacketizer Pkt(*this, 0x40);
+ Pkt.WriteString(Printf("{\"text\":\"%s\"}", EscapeString(a_Reason).c_str()));
+ break;
+ }
+ }
+}
+
+
+
+
+
+void cProtocol180::SendEditSign(int a_BlockX, int a_BlockY, int a_BlockZ)
+{
+ ASSERT(m_State == 3); // In game mode?
+
+ cPacketizer Pkt(*this, 0x36); // Sign Editor Open packet
+ Pkt.WritePosition(a_BlockX, a_BlockY, a_BlockZ);
+}
+
+
+
+
+
+void cProtocol180::SendEntityEffect(const cEntity & a_Entity, int a_EffectID, int a_Amplifier, short a_Duration)
+{
+ ASSERT(m_State == 3); // In game mode?
+
+ cPacketizer Pkt(*this, 0x1D); // Entity Effect packet
+ Pkt.WriteVarInt(a_Entity.GetUniqueID());
+ Pkt.WriteByte(a_EffectID);
+ Pkt.WriteByte(a_Amplifier);
+ Pkt.WriteVarInt((UInt32)a_Duration);
+ Pkt.WriteBool(false); // Hide particles
+}
+
+
+
+
+
+void cProtocol180::SendEntityEquipment(const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item)
+{
+ ASSERT(m_State == 3); // In game mode?
+
+ cPacketizer Pkt(*this, 0x04); // Entity Equipment packet
+ Pkt.WriteVarInt((UInt32)a_Entity.GetUniqueID());
+ Pkt.WriteShort(a_SlotNum);
+ Pkt.WriteItem(a_Item);
+}
+
+
+
+
+
+void cProtocol180::SendEntityHeadLook(const cEntity & a_Entity)
+{
+ ASSERT(m_State == 3); // In game mode?
+
+ cPacketizer Pkt(*this, 0x19); // Entity Head Look packet
+ Pkt.WriteVarInt((UInt32)a_Entity.GetUniqueID());
+ Pkt.WriteByteAngle(a_Entity.GetHeadYaw());
+}
+
+
+
+
+
+void cProtocol180::SendEntityLook(const cEntity & a_Entity)
+{
+ ASSERT(m_State == 3); // In game mode?
+
+ cPacketizer Pkt(*this, 0x16); // Entity Look packet
+ Pkt.WriteVarInt(a_Entity.GetUniqueID());
+ Pkt.WriteByteAngle(a_Entity.GetYaw());
+ Pkt.WriteByteAngle(a_Entity.GetPitch());
+ Pkt.WriteBool(true); // TODO: IsOnGround() on entities
+}
+
+
+
+
+
+void cProtocol180::SendEntityMetadata(const cEntity & a_Entity)
+{
+ ASSERT(m_State == 3); // In game mode?
+
+ cPacketizer Pkt(*this, 0x1c); // Entity Metadata packet
+ Pkt.WriteVarInt(a_Entity.GetUniqueID());
+ Pkt.WriteEntityMetadata(a_Entity);
+ Pkt.WriteByte(0x7f); // The termination byte
+}
+
+
+
+
+
+void cProtocol180::SendEntityProperties(const cEntity & a_Entity)
+{
+ ASSERT(m_State == 3); // In game mode?
+
+ cPacketizer Pkt(*this, 0x20); // Entity Properties packet
+ Pkt.WriteVarInt(a_Entity.GetUniqueID());
+ Pkt.WriteEntityProperties(a_Entity);
+}
+
+
+
+
+
+void cProtocol180::SendEntityRelMove(const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ)
+{
+ ASSERT(m_State == 3); // In game mode?
+
+ cPacketizer Pkt(*this, 0x15); // Entity Relative Move packet
+ Pkt.WriteVarInt(a_Entity.GetUniqueID());
+ Pkt.WriteByte(a_RelX);
+ Pkt.WriteByte(a_RelY);
+ Pkt.WriteByte(a_RelZ);
+ Pkt.WriteBool(true); // TODO: IsOnGround() on entities
+}
+
+
+
+
+
+void cProtocol180::SendEntityRelMoveLook(const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ)
+{
+ ASSERT(m_State == 3); // In game mode?
+
+ cPacketizer Pkt(*this, 0x17); // Entity Look And Relative Move packet
+ Pkt.WriteVarInt(a_Entity.GetUniqueID());
+ Pkt.WriteByte(a_RelX);
+ Pkt.WriteByte(a_RelY);
+ Pkt.WriteByte(a_RelZ);
+ Pkt.WriteByteAngle(a_Entity.GetYaw());
+ Pkt.WriteByteAngle(a_Entity.GetPitch());
+ Pkt.WriteBool(true); // TODO: IsOnGround() on entities
+}
+
+
+
+
+
+void cProtocol180::SendEntityStatus(const cEntity & a_Entity, char a_Status)
+{
+ ASSERT(m_State == 3); // In game mode?
+
+ cPacketizer Pkt(*this, 0x1a); // Entity Status packet
+ Pkt.WriteInt(a_Entity.GetUniqueID());
+ Pkt.WriteChar(a_Status);
+}
+
+
+
+
+
+void cProtocol180::SendEntityVelocity(const cEntity & a_Entity)
+{
+ ASSERT(m_State == 3); // In game mode?
+
+ cPacketizer Pkt(*this, 0x12); // Entity Velocity packet
+ Pkt.WriteVarInt(a_Entity.GetUniqueID());
+ // 400 = 8000 / 20 ... Conversion from our speed in m/s to 8000 m/tick
+ Pkt.WriteShort((short)(a_Entity.GetSpeedX() * 400));
+ Pkt.WriteShort((short)(a_Entity.GetSpeedY() * 400));
+ Pkt.WriteShort((short)(a_Entity.GetSpeedZ() * 400));
+}
+
+
+
+
+
+void cProtocol180::SendExplosion(double a_BlockX, double a_BlockY, double a_BlockZ, float a_Radius, const cVector3iArray & a_BlocksAffected, const Vector3d & a_PlayerMotion)
+{
+ ASSERT(m_State == 3); // In game mode?
+
+ cPacketizer Pkt(*this, 0x27); // Explosion packet
+ Pkt.WriteFloat((float)a_BlockX);
+ Pkt.WriteFloat((float)a_BlockY);
+ Pkt.WriteFloat((float)a_BlockZ);
+ Pkt.WriteFloat((float)a_Radius);
+ Pkt.WriteInt((int)a_BlocksAffected.size());
+ for (cVector3iArray::const_iterator itr = a_BlocksAffected.begin(), end = a_BlocksAffected.end(); itr != end; ++itr)
+ {
+ Pkt.WriteChar((char)itr->x);
+ Pkt.WriteChar((char)itr->y);
+ Pkt.WriteChar((char)itr->z);
+ } // for itr - a_BlockAffected[]
+ Pkt.WriteFloat((float)a_PlayerMotion.x);
+ Pkt.WriteFloat((float)a_PlayerMotion.y);
+ Pkt.WriteFloat((float)a_PlayerMotion.z);
+}
+
+
+
+
+
+void cProtocol180::SendGameMode(eGameMode a_GameMode)
+{
+ ASSERT(m_State == 3); // In game mode?
+
+ cPacketizer Pkt(*this, 0x2b); // Change Game State packet
+ Pkt.WriteByte(3); // Reason: Change game mode
+ Pkt.WriteFloat((float)a_GameMode);
+}
+
+
+
+
+
+void cProtocol180::SendHealth(void)
+{
+ ASSERT(m_State == 3); // In game mode?
+
+ cPacketizer Pkt(*this, 0x06); // Update Health packet
+ cPlayer * Player = m_Client->GetPlayer();
+ Pkt.WriteFloat((float)Player->GetHealth());
+ Pkt.WriteVarInt((UInt32)Player->GetFoodLevel());
+ Pkt.WriteFloat((float)Player->GetFoodSaturationLevel());
+}
+
+
+
+
+
+void cProtocol180::SendInventorySlot(char a_WindowID, short a_SlotNum, const cItem & a_Item)
+{
+ ASSERT(m_State == 3); // In game mode?
+
+ cPacketizer Pkt(*this, 0x2f); // Set Slot packet
+ Pkt.WriteChar(a_WindowID);
+ Pkt.WriteShort(a_SlotNum);
+ Pkt.WriteItem(a_Item);
+}
+
+
+
+
+
+void cProtocol180::SendKeepAlive(int a_PingID)
+{
+ // Drop the packet if the protocol is not in the Game state yet (caused a client crash):
+ if (m_State != 3)
+ {
+ LOGWARNING("Trying to send a KeepAlive packet to a player who's not yet fully logged in (%d). The protocol class prevented the packet.", m_State);
+ return;
+ }
+
+ cPacketizer Pkt(*this, 0x00); // Keep Alive packet
+ Pkt.WriteVarInt(a_PingID);
+}
+
+
+
+
+
+void cProtocol180::SendLogin(const cPlayer & a_Player, const cWorld & a_World)
+{
+ // Send the Join Game packet:
+ {
+ cServer * Server = cRoot::Get()->GetServer();
+ cPacketizer Pkt(*this, 0x01); // Join Game packet
+ Pkt.WriteInt(a_Player.GetUniqueID());
+ Pkt.WriteByte((Byte)a_Player.GetEffectiveGameMode() | (Server->IsHardcore() ? 0x08 : 0)); // Hardcore flag bit 4
+ Pkt.WriteChar((char)a_World.GetDimension());
+ Pkt.WriteByte(2); // TODO: Difficulty (set to Normal)
+ Pkt.WriteByte(Server->GetMaxPlayers());
+ Pkt.WriteString("default"); // Level type - wtf?
+ Pkt.WriteBool(false); // Reduced Debug Info - wtf?
+ }
+ m_LastSentDimension = a_World.GetDimension();
+
+ // Send the spawn position:
+ {
+ cPacketizer Pkt(*this, 0x05); // Spawn Position packet
+ Pkt.WritePosition(a_World.GetSpawnX(), a_World.GetSpawnY(), a_World.GetSpawnZ());
+ }
+
+ // Send the server difficulty:
+ {
+ cPacketizer Pkt(*this, 0x41);
+ Pkt.WriteChar(1);
+ }
+
+ // Send player abilities:
+ SendPlayerAbilities();
+}
+
+
+
+
+void cProtocol180::SendLoginSuccess(void)
+{
+ ASSERT(m_State == 2); // State: login?
+
+ // Enable compression:
+ {
+ cPacketizer Pkt(*this, 0x03); // Set compression packet
+ Pkt.WriteVarInt(256);
+ }
+
+ m_State = 3; // State = Game
+
+ {
+ cPacketizer Pkt(*this, 0x02); // Login success packet
+ Pkt.WriteString(cMojangAPI::MakeUUIDDashed(m_Client->GetUUID()));
+ Pkt.WriteString(m_Client->GetUsername());
+ }
+}
+
+
+
+
+
+void cProtocol180::SendPaintingSpawn(const cPainting & a_Painting)
+{
+ ASSERT(m_State == 3); // In game mode?
+ double PosX = a_Painting.GetPosX();
+ double PosY = a_Painting.GetPosY();
+ double PosZ = a_Painting.GetPosZ();
+
+ switch (a_Painting.GetDirection())
+ {
+ case 0: PosZ += 1; break;
+ case 1: PosX -= 1; break;
+ case 2: PosZ -= 1; break;
+ case 3: PosX += 1; break;
+ }
+
+ cPacketizer Pkt(*this, 0x10); // Spawn Painting packet
+ Pkt.WriteVarInt(a_Painting.GetUniqueID());
+ Pkt.WriteString(a_Painting.GetName().c_str());
+ Pkt.WritePosition(PosX, PosY, PosZ);
+ Pkt.WriteChar(a_Painting.GetDirection());
+}
+
+
+
+
+
+void cProtocol180::SendMapColumn(int a_ID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length, unsigned int m_Scale)
+{
+ ASSERT(m_State == 3); // In game mode?
+
+ cPacketizer Pkt(*this, 0x34);
+ Pkt.WriteVarInt(a_ID);
+ Pkt.WriteByte(m_Scale);
+
+ Pkt.WriteVarInt(0);
+ Pkt.WriteByte(1);
+ Pkt.WriteByte(a_Length);
+ Pkt.WriteByte(a_X);
+ Pkt.WriteByte(a_Y);
+
+ Pkt.WriteVarInt(a_Length);
+ for (unsigned int i = 0; i < a_Length; ++i)
+ {
+ Pkt.WriteByte(a_Colors[i]);
+ }
+}
+
+
+
+
+
+void cProtocol180::SendMapDecorators(int a_ID, const cMapDecoratorList & a_Decorators, unsigned int m_Scale)
+{
+ ASSERT(m_State == 3); // In game mode?
+
+ cPacketizer Pkt(*this, 0x34);
+ Pkt.WriteVarInt(a_ID);
+ Pkt.WriteByte(m_Scale);
+ Pkt.WriteVarInt(a_Decorators.size());
+
+ for (cMapDecoratorList::const_iterator it = a_Decorators.begin(); it != a_Decorators.end(); ++it)
+ {
+ Pkt.WriteByte((it->GetType() << 4) | (it->GetRot() & 0xf));
+ Pkt.WriteByte(it->GetPixelX());
+ Pkt.WriteByte(it->GetPixelZ());
+ }
+
+ Pkt.WriteByte(0);
+}
+
+
+
+
+
+void cProtocol180::SendMapInfo(int a_ID, unsigned int a_Scale)
+{
+ UNUSED(a_ID);
+ UNUSED(a_Scale);
+
+ // This packet was removed in 1.8
+}
+
+
+
+
+
+void cProtocol180::SendPickupSpawn(const cPickup & a_Pickup)
+{
+ ASSERT(m_State == 3); // In game mode?
+
+ {
+ cPacketizer Pkt(*this, 0x0e); // Spawn Object packet
+ Pkt.WriteVarInt(a_Pickup.GetUniqueID());
+ Pkt.WriteByte(2); // Type = Pickup
+ Pkt.WriteFPInt(a_Pickup.GetPosX());
+ Pkt.WriteFPInt(a_Pickup.GetPosY());
+ Pkt.WriteFPInt(a_Pickup.GetPosZ());
+ Pkt.WriteByteAngle(a_Pickup.GetYaw());
+ Pkt.WriteByteAngle(a_Pickup.GetPitch());
+ Pkt.WriteInt(0); // No object data
+ }
+
+ {
+ cPacketizer Pkt(*this, 0x1c); // Entity Metadata packet
+ Pkt.WriteVarInt(a_Pickup.GetUniqueID());
+ Pkt.WriteByte((0x05 << 5) | 10); // Slot type + index 10
+ Pkt.WriteItem(a_Pickup.GetItem());
+ Pkt.WriteByte(0x7f); // End of metadata
+ }
+}
+
+
+
+
+
+void cProtocol180::SendPlayerAbilities(void)
+{
+ ASSERT(m_State == 3); // In game mode?
+
+ cPacketizer Pkt(*this, 0x39); // Player Abilities packet
+ Byte Flags = 0;
+ cPlayer * Player = m_Client->GetPlayer();
+ if (Player->IsGameModeCreative())
+ {
+ Flags |= 0x01;
+ Flags |= 0x08; // Godmode, used for creative
+ }
+ if (Player->IsFlying())
+ {
+ Flags |= 0x02;
+ }
+ if (Player->CanFly())
+ {
+ Flags |= 0x04;
+ }
+ Pkt.WriteByte(Flags);
+ Pkt.WriteFloat((float)(0.05 * Player->GetFlyingMaxSpeed()));
+ Pkt.WriteFloat((float)(0.1 * Player->GetNormalMaxSpeed()));
+}
+
+
+
+
+
+void cProtocol180::SendEntityAnimation(const cEntity & a_Entity, char a_Animation)
+{
+ ASSERT(m_State == 3); // In game mode?
+
+ cPacketizer Pkt(*this, 0x0b); // Animation packet
+ Pkt.WriteVarInt(a_Entity.GetUniqueID());
+ Pkt.WriteChar(a_Animation);
+}
+
+
+
+
+
+void cProtocol180::SendParticleEffect(const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmount)
+{
+ ASSERT(m_State == 3); // In game mode?
+ int ParticleID = GetParticleID(a_ParticleName);
+
+ cPacketizer Pkt(*this, 0x2A);
+ Pkt.WriteInt(ParticleID);
+ Pkt.WriteBool(false);
+ Pkt.WriteFloat(a_SrcX);
+ Pkt.WriteFloat(a_SrcY);
+ Pkt.WriteFloat(a_SrcZ);
+ Pkt.WriteFloat(a_OffsetX);
+ Pkt.WriteFloat(a_OffsetY);
+ Pkt.WriteFloat(a_OffsetZ);
+ Pkt.WriteFloat(a_ParticleData);
+ Pkt.WriteInt(a_ParticleAmount);
+}
+
+
+
+
+
+void cProtocol180::SendPlayerListAddPlayer(const cPlayer & a_Player)
+{
+ ASSERT(m_State == 3); // In game mode?
+
+ cPacketizer Pkt(*this, 0x38); // Playerlist Item packet
+ Pkt.WriteVarInt(0);
+ Pkt.WriteVarInt(1);
+ Pkt.WriteUUID(a_Player.GetUUID());
+ Pkt.WriteString(a_Player.GetName());
+
+ const Json::Value & Properties = a_Player.GetClientHandle()->GetProperties();
+ Pkt.WriteVarInt(Properties.size());
+ for (Json::Value::iterator itr = Properties.begin(), end = Properties.end(); itr != end; ++itr)
+ {
+ Pkt.WriteString(((Json::Value)*itr).get("name", "").asString());
+ Pkt.WriteString(((Json::Value)*itr).get("value", "").asString());
+ AString Signature = ((Json::Value)*itr).get("signature", "").asString();
+ if (Signature.empty())
+ {
+ Pkt.WriteBool(false);
+ }
+ else
+ {
+ Pkt.WriteBool(true);
+ Pkt.WriteString(Signature);
+ }
+ }
+
+ Pkt.WriteVarInt((UInt32)a_Player.GetGameMode());
+ Pkt.WriteVarInt((UInt32)a_Player.GetClientHandle()->GetPing());
+
+ AString CustomName = a_Player.GetPlayerListName();
+ if (CustomName != a_Player.GetName())
+ {
+ Pkt.WriteBool(true);
+ Pkt.WriteString(Printf("{\"text\":\"%s\"}", CustomName.c_str()));
+ }
+ else
+ {
+ Pkt.WriteBool(false);
+ }
+}
+
+
+
+
+
+void cProtocol180::SendPlayerListRemovePlayer(const cPlayer & a_Player)
+{
+ ASSERT(m_State == 3); // In game mode?
+
+ cPacketizer Pkt(*this, 0x38); // Playerlist Item packet
+ Pkt.WriteVarInt(4);
+ Pkt.WriteVarInt(1);
+ Pkt.WriteUUID(a_Player.GetUUID());
+}
+
+
+
+
+
+void cProtocol180::SendPlayerListUpdateGameMode(const cPlayer & a_Player)
+{
+ ASSERT(m_State == 3); // In game mode?
+
+ cPacketizer Pkt(*this, 0x38); // Playerlist Item packet
+ Pkt.WriteVarInt(1);
+ Pkt.WriteVarInt(1);
+ Pkt.WriteUUID(a_Player.GetUUID());
+ Pkt.WriteVarInt((UInt32)a_Player.GetGameMode());
+}
+
+
+
+
+
+void cProtocol180::SendPlayerListUpdatePing(const cPlayer & a_Player)
+{
+ ASSERT(m_State == 3); // In game mode?
+
+ cPacketizer Pkt(*this, 0x38); // Playerlist Item packet
+ Pkt.WriteVarInt(2);
+ Pkt.WriteVarInt(1);
+ Pkt.WriteUUID(a_Player.GetUUID());
+ Pkt.WriteVarInt((UInt32)a_Player.GetClientHandle()->GetPing());
+}
+
+
+
+
+
+void cProtocol180::SendPlayerListUpdateDisplayName(const cPlayer & a_Player, const AString & a_OldListName)
+{
+ ASSERT(m_State == 3); // In game mode?
+
+ cPacketizer Pkt(*this, 0x38); // Playerlist Item packet
+ Pkt.WriteVarInt(3);
+ Pkt.WriteVarInt(1);
+ Pkt.WriteUUID(a_Player.GetUUID());
+
+ AString CustomName = a_Player.GetPlayerListName();
+ if (CustomName == a_Player.GetName())
+ {
+ Pkt.WriteBool(false);
+ }
+ else
+ {
+ Pkt.WriteBool(true);
+ Pkt.WriteString(Printf("{\"text\":\"%s\"}", CustomName.c_str()));
+ }
+}
+
+
+
+
+
+void cProtocol180::SendPlayerMaxSpeed(void)
+{
+ ASSERT(m_State == 3); // In game mode?
+
+ cPacketizer Pkt(*this, 0x20); // Entity Properties
+ cPlayer * Player = m_Client->GetPlayer();
+ Pkt.WriteVarInt(Player->GetUniqueID());
+ Pkt.WriteInt(1); // Count
+ Pkt.WriteString("generic.movementSpeed");
+ // The default game speed is 0.1, multiply that value by the relative speed:
+ Pkt.WriteDouble(0.1 * Player->GetNormalMaxSpeed());
+ if (Player->IsSprinting())
+ {
+ Pkt.WriteVarInt(1); // Modifier count
+ Pkt.WriteInt64(0x662a6b8dda3e4c1c);
+ Pkt.WriteInt64(0x881396ea6097278d); // UUID of the modifier
+ Pkt.WriteDouble(Player->GetSprintingMaxSpeed() - Player->GetNormalMaxSpeed());
+ Pkt.WriteByte(2);
+ }
+ else
+ {
+ Pkt.WriteVarInt(0); // Modifier count
+ }
+}
+
+
+
+
+
+void cProtocol180::SendPlayerMoveLook(void)
+{
+ ASSERT(m_State == 3); // In game mode?
+
+ cPacketizer Pkt(*this, 0x08); // Player Position And Look packet
+ cPlayer * Player = m_Client->GetPlayer();
+ Pkt.WriteDouble(Player->GetPosX());
+
+ // The "+ 0.001" is there because otherwise the player falls through the block they were standing on.
+ Pkt.WriteDouble(Player->GetStance() + 0.001);
+
+ Pkt.WriteDouble(Player->GetPosZ());
+ Pkt.WriteFloat((float)Player->GetYaw());
+ Pkt.WriteFloat((float)Player->GetPitch());
+ Pkt.WriteByte(0);
+}
+
+
+
+
+
+void cProtocol180::SendPlayerPosition(void)
+{
+ // There is no dedicated packet for this, send the whole thing:
+ SendPlayerMoveLook();
+}
+
+
+
+
+
+void cProtocol180::SendPlayerSpawn(const cPlayer & a_Player)
+{
+ // Called to spawn another player for the client
+ cPacketizer Pkt(*this, 0x0c); // Spawn Player packet
+ Pkt.WriteVarInt(a_Player.GetUniqueID());
+ Pkt.WriteUUID(cMojangAPI::MakeUUIDShort(a_Player.GetUUID()));
+ Pkt.WriteFPInt(a_Player.GetPosX());
+ Pkt.WriteFPInt(a_Player.GetPosY());
+ Pkt.WriteFPInt(a_Player.GetPosZ());
+ Pkt.WriteByteAngle(a_Player.GetYaw());
+ Pkt.WriteByteAngle(a_Player.GetPitch());
+ short ItemType = a_Player.GetEquippedItem().IsEmpty() ? 0 : a_Player.GetEquippedItem().m_ItemType;
+ Pkt.WriteShort(ItemType);
+ Pkt.WriteByte((3 << 5) | 6); // Metadata: float + index 6
+ Pkt.WriteFloat((float)a_Player.GetHealth());
+ Pkt.WriteByte((4 << 5 | (2 & 0x1F)) & 0xFF);
+ Pkt.WriteString(a_Player.GetName());
+ Pkt.WriteByte(0x7f); // Metadata: end
+}
+
+
+
+
+
+void cProtocol180::SendPluginMessage(const AString & a_Channel, const AString & a_Message)
+{
+ ASSERT(m_State == 3); // In game mode?
+
+ cPacketizer Pkt(*this, 0x3f);
+ Pkt.WriteString(a_Channel);
+ Pkt.WriteBuf(a_Message.data(), a_Message.size());
+}
+
+
+
+
+
+void cProtocol180::SendRemoveEntityEffect(const cEntity & a_Entity, int a_EffectID)
+{
+ ASSERT(m_State == 3); // In game mode?
+
+ cPacketizer Pkt(*this, 0x1e);
+ Pkt.WriteVarInt(a_Entity.GetUniqueID());
+ Pkt.WriteByte(a_EffectID);
+}
+
+
+
+
+
+void cProtocol180::SendRespawn(eDimension a_Dimension, bool a_ShouldIgnoreDimensionChecks)
+{
+ if ((m_LastSentDimension == a_Dimension) && !a_ShouldIgnoreDimensionChecks)
+ {
+ // Must not send a respawn for the world with the same dimension, the client goes cuckoo if we do (unless we are respawning from death)
+ return;
+ }
+
+ cPacketizer Pkt(*this, 0x07); // Respawn packet
+ cPlayer * Player = m_Client->GetPlayer();
+ Pkt.WriteInt((int)a_Dimension);
+ Pkt.WriteByte(2); // TODO: Difficulty (set to Normal)
+ Pkt.WriteByte((Byte)Player->GetEffectiveGameMode());
+ Pkt.WriteString("default");
+ m_LastSentDimension = a_Dimension;
+}
+
+
+
+
+
+void cProtocol180::SendExperience(void)
+{
+ ASSERT(m_State == 3); // In game mode?
+
+ cPacketizer Pkt(*this, 0x1f); // Experience Packet
+ cPlayer * Player = m_Client->GetPlayer();
+ Pkt.WriteFloat(Player->GetXpPercentage());
+ Pkt.WriteVarInt((UInt32)Player->GetXpLevel());
+ Pkt.WriteVarInt((UInt32)Player->GetCurrentXp());
+}
+
+
+
+
+
+void cProtocol180::SendExperienceOrb(const cExpOrb & a_ExpOrb)
+{
+ ASSERT(m_State == 3); // In game mode?
+
+ cPacketizer Pkt(*this, 0x11);
+ Pkt.WriteVarInt(a_ExpOrb.GetUniqueID());
+ Pkt.WriteFPInt(a_ExpOrb.GetPosX());
+ Pkt.WriteFPInt(a_ExpOrb.GetPosY());
+ Pkt.WriteFPInt(a_ExpOrb.GetPosZ());
+ Pkt.WriteShort(a_ExpOrb.GetReward());
+}
+
+
+
+
+
+void cProtocol180::SendScoreboardObjective(const AString & a_Name, const AString & a_DisplayName, Byte a_Mode)
+{
+ ASSERT(m_State == 3); // In game mode?
+
+ cPacketizer Pkt(*this, 0x3b);
+ Pkt.WriteString(a_Name);
+ Pkt.WriteByte(a_Mode);
+ if ((a_Mode == 0) || (a_Mode == 2))
+ {
+ Pkt.WriteString(a_DisplayName);
+ Pkt.WriteString("integer");
+ }
+}
+
+
+
+
+
+void cProtocol180::SendScoreUpdate(const AString & a_Objective, const AString & a_Player, cObjective::Score a_Score, Byte a_Mode)
+{
+ ASSERT(m_State == 3); // In game mode?
+
+ cPacketizer Pkt(*this, 0x3c);
+ Pkt.WriteString(a_Player);
+ Pkt.WriteByte(a_Mode);
+ Pkt.WriteString(a_Objective);
+
+ if (a_Mode != 1)
+ {
+ Pkt.WriteVarInt((UInt32) a_Score);
+ }
+}
+
+
+
+
+
+void cProtocol180::SendDisplayObjective(const AString & a_Objective, cScoreboard::eDisplaySlot a_Display)
+{
+ ASSERT(m_State == 3); // In game mode?
+
+ cPacketizer Pkt(*this, 0x3d);
+ Pkt.WriteByte((int) a_Display);
+ Pkt.WriteString(a_Objective);
+}
+
+
+
+
+
+void cProtocol180::SendSoundEffect(const AString & a_SoundName, double a_X, double a_Y, double a_Z, float a_Volume, float a_Pitch)
+{
+ ASSERT(m_State == 3); // In game mode?
+
+ cPacketizer Pkt(*this, 0x29); // Sound Effect packet
+ Pkt.WriteString(a_SoundName);
+ Pkt.WriteInt((int)(a_X * 8.0));
+ Pkt.WriteInt((int)(a_Y * 8.0));
+ Pkt.WriteInt((int)(a_Z * 8.0));
+ Pkt.WriteFloat(a_Volume);
+ Pkt.WriteByte((Byte)(a_Pitch * 63));
+}
+
+
+
+
+
+void cProtocol180::SendSoundParticleEffect(int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data)
+{
+ ASSERT(m_State == 3); // In game mode?
+
+ cPacketizer Pkt(*this, 0x28); // Effect packet
+ Pkt.WriteInt(a_EffectID);
+ Pkt.WritePosition(a_SrcX, a_SrcY, a_SrcZ);
+ Pkt.WriteInt(a_Data);
+ Pkt.WriteBool(false);
+}
+
+
+
+
+
+void cProtocol180::SendSpawnFallingBlock(const cFallingBlock & a_FallingBlock)
+{
+ ASSERT(m_State == 3); // In game mode?
+
+ cPacketizer Pkt(*this, 0x0e); // Spawn Object packet
+ Pkt.WriteVarInt(a_FallingBlock.GetUniqueID());
+ Pkt.WriteByte(70); // Falling block
+ Pkt.WriteFPInt(a_FallingBlock.GetPosX());
+ Pkt.WriteFPInt(a_FallingBlock.GetPosY());
+ Pkt.WriteFPInt(a_FallingBlock.GetPosZ());
+ Pkt.WriteByteAngle(a_FallingBlock.GetYaw());
+ Pkt.WriteByteAngle(a_FallingBlock.GetPitch());
+ Pkt.WriteInt(((int)a_FallingBlock.GetBlockType()) | (((int)a_FallingBlock.GetBlockMeta()) << 12));
+ Pkt.WriteShort((short)(a_FallingBlock.GetSpeedX() * 400));
+ Pkt.WriteShort((short)(a_FallingBlock.GetSpeedY() * 400));
+ Pkt.WriteShort((short)(a_FallingBlock.GetSpeedZ() * 400));
+}
+
+
+
+
+
+void cProtocol180::SendSpawnMob(const cMonster & a_Mob)
+{
+ ASSERT(m_State == 3); // In game mode?
+
+ cPacketizer Pkt(*this, 0x0f); // Spawn Mob packet
+ Pkt.WriteVarInt(a_Mob.GetUniqueID());
+ Pkt.WriteByte((Byte)a_Mob.GetMobType());
+ Pkt.WriteFPInt(a_Mob.GetPosX());
+ Pkt.WriteFPInt(a_Mob.GetPosY());
+ Pkt.WriteFPInt(a_Mob.GetPosZ());
+ Pkt.WriteByteAngle(a_Mob.GetPitch());
+ Pkt.WriteByteAngle(a_Mob.GetHeadYaw());
+ Pkt.WriteByteAngle(a_Mob.GetYaw());
+ Pkt.WriteShort((short)(a_Mob.GetSpeedX() * 400));
+ Pkt.WriteShort((short)(a_Mob.GetSpeedY() * 400));
+ Pkt.WriteShort((short)(a_Mob.GetSpeedZ() * 400));
+ Pkt.WriteEntityMetadata(a_Mob);
+ Pkt.WriteByte(0x7f); // Metadata terminator
+}
+
+
+
+
+
+void cProtocol180::SendSpawnObject(const cEntity & a_Entity, char a_ObjectType, int a_ObjectData, Byte a_Yaw, Byte a_Pitch)
+{
+ ASSERT(m_State == 3); // In game mode?
+ double PosX = a_Entity.GetPosX();
+ double PosZ = a_Entity.GetPosZ();
+ double Yaw = a_Entity.GetYaw();
+ if (a_ObjectType == 71)
+ {
+ FixItemFramePositions(a_ObjectData, PosX, PosZ, Yaw);
+ }
+
+ cPacketizer Pkt(*this, 0xe); // Spawn Object packet
+ Pkt.WriteVarInt(a_Entity.GetUniqueID());
+ Pkt.WriteByte(a_ObjectType);
+ Pkt.WriteFPInt(PosX);
+ Pkt.WriteFPInt(a_Entity.GetPosY());
+ Pkt.WriteFPInt(PosZ);
+ Pkt.WriteByteAngle(a_Entity.GetPitch());
+ Pkt.WriteByteAngle(Yaw);
+ Pkt.WriteInt(a_ObjectData);
+ if (a_ObjectData != 0)
+ {
+ Pkt.WriteShort((short)(a_Entity.GetSpeedX() * 400));
+ Pkt.WriteShort((short)(a_Entity.GetSpeedY() * 400));
+ Pkt.WriteShort((short)(a_Entity.GetSpeedZ() * 400));
+ }
+}
+
+
+
+
+
+void cProtocol180::SendSpawnVehicle(const cEntity & a_Vehicle, char a_VehicleType, char a_VehicleSubType)
+{
+ ASSERT(m_State == 3); // In game mode?
+
+ cPacketizer Pkt(*this, 0xe); // Spawn Object packet
+ Pkt.WriteVarInt(a_Vehicle.GetUniqueID());
+ Pkt.WriteByte(a_VehicleType);
+ Pkt.WriteFPInt(a_Vehicle.GetPosX());
+ Pkt.WriteFPInt(a_Vehicle.GetPosY());
+ Pkt.WriteFPInt(a_Vehicle.GetPosZ());
+ Pkt.WriteByteAngle(a_Vehicle.GetPitch());
+ Pkt.WriteByteAngle(a_Vehicle.GetYaw());
+ Pkt.WriteInt(a_VehicleSubType);
+ if (a_VehicleSubType != 0)
+ {
+ Pkt.WriteShort((short)(a_Vehicle.GetSpeedX() * 400));
+ Pkt.WriteShort((short)(a_Vehicle.GetSpeedY() * 400));
+ Pkt.WriteShort((short)(a_Vehicle.GetSpeedZ() * 400));
+ }
+}
+
+
+
+
+
+void cProtocol180::SendStatistics(const cStatManager & a_Manager)
+{
+ ASSERT(m_State == 3); // In game mode?
+
+ cPacketizer Pkt(*this, 0x37);
+ Pkt.WriteVarInt(statCount); // TODO 2014-05-11 xdot: Optimization: Send "dirty" statistics only
+
+ for (size_t i = 0; i < (size_t)statCount; ++i)
+ {
+ StatValue Value = a_Manager.GetValue((eStatistic) i);
+ const AString & StatName = cStatInfo::GetName((eStatistic) i);
+
+ Pkt.WriteString(StatName);
+ Pkt.WriteVarInt(Value);
+ }
+}
+
+
+
+
+
+void cProtocol180::SendTabCompletionResults(const AStringVector & a_Results)
+{
+ ASSERT(m_State == 3); // In game mode?
+
+ cPacketizer Pkt(*this, 0x3a); // Tab-Complete packet
+ Pkt.WriteVarInt((int)a_Results.size());
+
+ for (AStringVector::const_iterator itr = a_Results.begin(), end = a_Results.end(); itr != end; ++itr)
+ {
+ Pkt.WriteString(*itr);
+ }
+}
+
+
+
+
+
+void cProtocol180::SendTeleportEntity(const cEntity & a_Entity)
+{
+ ASSERT(m_State == 3); // In game mode?
+
+ cPacketizer Pkt(*this, 0x18);
+ Pkt.WriteVarInt(a_Entity.GetUniqueID());
+ Pkt.WriteFPInt(a_Entity.GetPosX());
+ Pkt.WriteFPInt(a_Entity.GetPosY());
+ Pkt.WriteFPInt(a_Entity.GetPosZ());
+ Pkt.WriteByteAngle(a_Entity.GetYaw());
+ Pkt.WriteByteAngle(a_Entity.GetPitch());
+ Pkt.WriteBool(true); // TODO: IsOnGrond() on entities
+}
+
+
+
+
+
+void cProtocol180::SendThunderbolt(int a_BlockX, int a_BlockY, int a_BlockZ)
+{
+ ASSERT(m_State == 3); // In game mode?
+
+ cPacketizer Pkt(*this, 0x2c); // Spawn Global Entity packet
+ Pkt.WriteVarInt(0); // EntityID = 0, always
+ Pkt.WriteByte(1); // Type = Thunderbolt
+ Pkt.WriteFPInt(a_BlockX);
+ Pkt.WriteFPInt(a_BlockY);
+ Pkt.WriteFPInt(a_BlockZ);
+}
+
+
+
+
+
+void cProtocol180::SendTimeUpdate(Int64 a_WorldAge, Int64 a_TimeOfDay, bool a_DoDaylightCycle)
+{
+ ASSERT(m_State == 3); // In game mode?
+ if (!a_DoDaylightCycle)
+ {
+ // When writing a "-" before the number the client ignores it but it will stop the client-side time expiration.
+ a_TimeOfDay = std::min(-a_TimeOfDay, -1LL);
+ }
+
+ cPacketizer Pkt(*this, 0x03);
+ Pkt.WriteInt64(a_WorldAge);
+ Pkt.WriteInt64(a_TimeOfDay);
+}
+
+
+
+
+
+void cProtocol180::SendUnloadChunk(int a_ChunkX, int a_ChunkZ)
+{
+ ASSERT(m_State == 3); // In game mode?
+
+ cPacketizer Pkt(*this, 0x21); // Chunk Data packet
+ Pkt.WriteInt(a_ChunkX);
+ Pkt.WriteInt(a_ChunkZ);
+ Pkt.WriteBool(true);
+ Pkt.WriteShort(0); // Primary bitmap
+ Pkt.WriteVarInt(0); // Data size
+}
+
+
+
+
+void cProtocol180::SendUpdateBlockEntity(cBlockEntity & a_BlockEntity)
+{
+ ASSERT(m_State == 3); // In game mode?
+
+ cPacketizer Pkt(*this, 0x35); // Update tile entity packet
+ Pkt.WritePosition(a_BlockEntity.GetPosX(), a_BlockEntity.GetPosY(), a_BlockEntity.GetPosZ());
+
+ Byte Action = 0;
+ switch (a_BlockEntity.GetBlockType())
+ {
+ case E_BLOCK_MOB_SPAWNER: Action = 1; break; // Update mob spawner spinny mob thing
+ case E_BLOCK_COMMAND_BLOCK: Action = 2; break; // Update command block text
+ case E_BLOCK_BEACON: Action = 3; break; // Update beacon entity
+ case E_BLOCK_HEAD: Action = 4; break; // Update Mobhead entity
+ case E_BLOCK_FLOWER_POT: Action = 5; break; // Update flower pot
+ default: ASSERT(!"Unhandled or unimplemented BlockEntity update request!"); break;
+ }
+ Pkt.WriteByte(Action);
+
+ Pkt.WriteBlockEntity(a_BlockEntity);
+}
+
+
+
+
+
+void cProtocol180::SendUpdateSign(int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4)
+{
+ ASSERT(m_State == 3); // In game mode?
+
+ cPacketizer Pkt(*this, 0x33);
+ Pkt.WritePosition(a_BlockX, a_BlockY, a_BlockZ);
+ Pkt.WriteString(Printf("{\"text\": \"%s\"}", a_Line1.c_str()));
+ Pkt.WriteString(Printf("{\"text\": \"%s\"}", a_Line2.c_str()));
+ Pkt.WriteString(Printf("{\"text\": \"%s\"}", a_Line3.c_str()));
+ Pkt.WriteString(Printf("{\"text\": \"%s\"}", a_Line4.c_str()));
+}
+
+
+
+
+
+void cProtocol180::SendUseBed(const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ)
+{
+ ASSERT(m_State == 3); // In game mode?
+
+ cPacketizer Pkt(*this, 0x0a);
+ Pkt.WriteVarInt(a_Entity.GetUniqueID());
+ Pkt.WritePosition(a_BlockX, a_BlockY, a_BlockZ);
+}
+
+
+
+
+
+void cProtocol180::SendWeather(eWeather a_Weather)
+{
+ ASSERT(m_State == 3); // In game mode?
+
+ {
+ cPacketizer Pkt(*this, 0x2b); // Change Game State packet
+ Pkt.WriteByte((a_Weather == wSunny) ? 1 : 2); // End rain / begin rain
+ Pkt.WriteFloat(0); // Unused for weather
+ }
+
+ // TODO: Fade effect, somehow
+}
+
+
+
+
+
+void cProtocol180::SendWholeInventory(const cWindow & a_Window)
+{
+ ASSERT(m_State == 3); // In game mode?
+
+ cPacketizer Pkt(*this, 0x30); // Window Items packet
+ Pkt.WriteChar(a_Window.GetWindowID());
+ Pkt.WriteShort(a_Window.GetNumSlots());
+ cItems Slots;
+ a_Window.GetSlots(*(m_Client->GetPlayer()), Slots);
+ for (cItems::const_iterator itr = Slots.begin(), end = Slots.end(); itr != end; ++itr)
+ {
+ Pkt.WriteItem(*itr);
+ } // for itr - Slots[]
+}
+
+
+
+
+
+void cProtocol180::SendWindowClose(const cWindow & a_Window)
+{
+ ASSERT(m_State == 3); // In game mode?
+
+ cPacketizer Pkt(*this, 0x2e);
+ Pkt.WriteChar(a_Window.GetWindowID());
+}
+
+
+
+
+
+void cProtocol180::SendWindowOpen(const cWindow & a_Window)
+{
+ ASSERT(m_State == 3); // In game mode?
+
+ if (a_Window.GetWindowType() < 0)
+ {
+ // Do not send this packet for player inventory windows
+ return;
+ }
+
+ cPacketizer Pkt(*this, 0x2d);
+ Pkt.WriteChar(a_Window.GetWindowID());
+ Pkt.WriteString(a_Window.GetWindowTypeName());
+ Pkt.WriteString(Printf("{\"text\":\"%s\"}", a_Window.GetWindowTitle().c_str()));
+
+ switch (a_Window.GetWindowType())
+ {
+ case cWindow::wtWorkbench:
+ case cWindow::wtEnchantment:
+ case cWindow::wtAnvil:
+ {
+ Pkt.WriteChar(0);
+ break;
+ }
+ default:
+ {
+ Pkt.WriteChar(a_Window.GetNumNonInventorySlots());
+ break;
+ }
+ }
+
+ if (a_Window.GetWindowType() == cWindow::wtAnimalChest)
+ {
+ Pkt.WriteInt(0); // TODO: The animal's EntityID
+ }
+}
+
+
+
+
+
+void cProtocol180::SendWindowProperty(const cWindow & a_Window, int a_Property, int a_Value)
+{
+ ASSERT(m_State == 3); // In game mode?
+
+ cPacketizer Pkt(*this, 0x31); // Window Property packet
+ Pkt.WriteChar(a_Window.GetWindowID());
+ Pkt.WriteShort(a_Property);
+ Pkt.WriteShort(a_Value);
+}
+
+
+
+
+
+bool cProtocol180::CompressPacket(const AString & a_Packet, AString & a_CompressedData)
+{
+ // Compress the data:
+ char CompressedData[MAX_COMPRESSED_PACKET_LEN];
+
+ uLongf CompressedSize = compressBound(a_Packet.size());
+ if (CompressedSize >= MAX_COMPRESSED_PACKET_LEN)
+ {
+ ASSERT(!"Too high packet size.");
+ return false;
+ }
+
+ int Status = compress2((Bytef*)CompressedData, &CompressedSize, (const Bytef*)a_Packet.data(), a_Packet.size(), Z_DEFAULT_COMPRESSION);
+ if (Status != Z_OK)
+ {
+ return false;
+ }
+
+ AString LengthData;
+ cByteBuffer Buffer(20);
+ Buffer.WriteVarInt((UInt32)a_Packet.size());
+ Buffer.ReadAll(LengthData);
+ Buffer.CommitRead();
+
+ Buffer.WriteVarInt(CompressedSize + LengthData.size());
+ Buffer.WriteVarInt(a_Packet.size());
+ Buffer.ReadAll(LengthData);
+ Buffer.CommitRead();
+
+ a_CompressedData.clear();
+ a_CompressedData.reserve(LengthData.size() + CompressedSize);
+ a_CompressedData.append(LengthData.data(), LengthData.size());
+ a_CompressedData.append(CompressedData, CompressedSize);
+ return true;
+}
+
+
+
+
+
+int cProtocol180::GetParticleID(const AString & a_ParticleName)
+{
+ static bool IsInitialized = false;
+ static std::map<AString, int> ParticleMap;
+ if (!IsInitialized)
+ {
+ // Initialize the ParticleMap:
+ ParticleMap["explode"] = 0;
+ ParticleMap["largeexplode"] = 1;
+ ParticleMap["hugeexplosion"] = 2;
+ ParticleMap["fireworksspark"] = 3;
+ ParticleMap["bubble"] = 4;
+ ParticleMap["splash"] = 5;
+ ParticleMap["wake"] = 6;
+ ParticleMap["suspended"] = 7;
+ ParticleMap["depthsuspend"] = 8;
+ ParticleMap["crit"] = 9;
+ ParticleMap["magiccrit"] = 10;
+ ParticleMap["smoke"] = 11;
+ ParticleMap["largesmoke"] = 12;
+ ParticleMap["spell"] = 13;
+ ParticleMap["instantspell"] = 14;
+ ParticleMap["mobspell"] = 15;
+ ParticleMap["mobspellambient"] = 16;
+ ParticleMap["witchmagic"] = 17;
+ ParticleMap["dripwater"] = 18;
+ ParticleMap["driplava"] = 19;
+ ParticleMap["angryvillager"] = 20;
+ ParticleMap["happyVillager"] = 21;
+ ParticleMap["townaura"] = 22;
+ ParticleMap["note"] = 23;
+ ParticleMap["portal"] = 24;
+ ParticleMap["enchantmenttable"] = 25;
+ ParticleMap["flame"] = 26;
+ ParticleMap["lava"] = 27;
+ ParticleMap["footstep"] = 28;
+ ParticleMap["cloud"] = 29;
+ ParticleMap["reddust"] = 30;
+ ParticleMap["snowballpoof"] = 31;
+ ParticleMap["snowshovel"] = 32;
+ ParticleMap["slime"] = 33;
+ ParticleMap["heart"] = 34;
+ ParticleMap["barrier"] = 35;
+ ParticleMap["iconcrack"] = 36;
+ ParticleMap["blockcrack"] = 37;
+ ParticleMap["blockdust"] = 38;
+ ParticleMap["droplet"] = 39;
+ ParticleMap["take"] = 40;
+ ParticleMap["mobappearance"] = 41;
+ }
+
+ AString ParticleName = StrToLower(a_ParticleName);
+ if (ParticleMap.find(ParticleName) == ParticleMap.end())
+ {
+ LOGWARNING("Unknown particle: %s", a_ParticleName.c_str());
+ ASSERT(!"Unknown particle");
+ return 0;
+ }
+
+ return ParticleMap[ParticleName];
+}
+
+
+
+
+
+void cProtocol180::FixItemFramePositions(int a_ObjectData, double & a_PosX, double & a_PosZ, double & a_Yaw)
+{
+ switch (a_ObjectData)
+ {
+ case 0:
+ {
+ a_PosZ += 1;
+ a_Yaw = 0;
+ break;
+ }
+ case 1:
+ {
+ a_PosX -= 1;
+ a_Yaw = 90;
+ break;
+ }
+ case 2:
+ {
+ a_PosZ -= 1;
+ a_Yaw = 180;
+ break;
+ }
+ case 3:
+ {
+ a_PosX += 1;
+ a_Yaw = 270;
+ break;
+ }
+ }
+}
+
+
+
+
+
+void cProtocol180::AddReceivedData(const char * a_Data, size_t a_Size)
+{
+ // Write the incoming data into the comm log file:
+ if (g_ShouldLogCommIn)
+ {
+ if (m_ReceivedData.GetReadableSpace() > 0)
+ {
+ AString AllData;
+ size_t OldReadableSpace = m_ReceivedData.GetReadableSpace();
+ m_ReceivedData.ReadAll(AllData);
+ m_ReceivedData.ResetRead();
+ m_ReceivedData.SkipRead(m_ReceivedData.GetReadableSpace() - OldReadableSpace);
+ ASSERT(m_ReceivedData.GetReadableSpace() == OldReadableSpace);
+ AString Hex;
+ CreateHexDump(Hex, AllData.data(), AllData.size(), 16);
+ m_CommLogFile.Printf("Incoming data, " SIZE_T_FMT " (0x" SIZE_T_FMT_HEX ") unparsed bytes already present in buffer:\n%s\n",
+ AllData.size(), AllData.size(), Hex.c_str()
+ );
+ }
+ AString Hex;
+ CreateHexDump(Hex, a_Data, a_Size, 16);
+ m_CommLogFile.Printf("Incoming data: %d (0x%x) bytes: \n%s\n",
+ (unsigned)a_Size, (unsigned)a_Size, Hex.c_str()
+ );
+ m_CommLogFile.Flush();
+ }
+
+ if (!m_ReceivedData.Write(a_Data, a_Size))
+ {
+ // Too much data in the incoming queue, report to caller:
+ m_Client->PacketBufferFull();
+ return;
+ }
+
+ // Handle all complete packets:
+ for (;;)
+ {
+ UInt32 PacketLen;
+ if (!m_ReceivedData.ReadVarInt(PacketLen))
+ {
+ // Not enough data
+ m_ReceivedData.ResetRead();
+ break;
+ }
+ if (!m_ReceivedData.CanReadBytes(PacketLen))
+ {
+ // The full packet hasn't been received yet
+ m_ReceivedData.ResetRead();
+ break;
+ }
+ cByteBuffer bb(PacketLen);
+ VERIFY(m_ReceivedData.ReadToByteBuffer(bb, (int)PacketLen));
+ m_ReceivedData.CommitRead();
+
+ // Compressed packets
+ if (m_State == 3)
+ {
+ UInt32 CompressedSize;
+ if (!bb.ReadVarInt(CompressedSize))
+ {
+ // Not enough data
+ break;
+ }
+ }
+
+ // Write one NUL extra, so that we can detect over-reads
+ bb.Write("\0", 1);
+
+ UInt32 PacketType;
+ if (!bb.ReadVarInt(PacketType))
+ {
+ // Not enough data
+ break;
+ }
+
+ // Log the packet info into the comm log file:
+ if (g_ShouldLogCommIn)
+ {
+ AString PacketData;
+ bb.ReadAll(PacketData);
+ bb.ResetRead();
+ bb.ReadVarInt(PacketType);
+ ASSERT(PacketData.size() > 0);
+ PacketData.resize(PacketData.size() - 1);
+ AString PacketDataHex;
+ CreateHexDump(PacketDataHex, PacketData.data(), PacketData.size(), 16);
+ m_CommLogFile.Printf("Next incoming packet is type %u (0x%x), length %u (0x%x) at state %d. Payload:\n%s\n",
+ PacketType, PacketType, PacketLen, PacketLen, m_State, PacketDataHex.c_str()
+ );
+ }
+
+ if (!HandlePacket(bb, PacketType))
+ {
+ // Unknown packet, already been reported, but without the length. Log the length here:
+ LOGWARNING("Unhandled packet: type 0x%x, state %d, length %u", PacketType, m_State, PacketLen);
+
+ #ifdef _DEBUG
+ // Dump the packet contents into the log:
+ bb.ResetRead();
+ AString Packet;
+ bb.ReadAll(Packet);
+ Packet.resize(Packet.size() - 1); // Drop the final NUL pushed there for over-read detection
+ AString Out;
+ CreateHexDump(Out, Packet.data(), (int)Packet.size(), 24);
+ LOGD("Packet contents:\n%s", Out.c_str());
+ #endif // _DEBUG
+
+ // Put a message in the comm log:
+ if (g_ShouldLogCommIn)
+ {
+ m_CommLogFile.Printf("^^^^^^ Unhandled packet ^^^^^^\n\n\n");
+ }
+
+ return;
+ }
+
+ if (bb.GetReadableSpace() != 0)
+ {
+ // Read more or less than packet length, report as error
+ LOGWARNING("Protocol 1.8: Wrong number of bytes read for packet 0x%x, state %d. Read " SIZE_T_FMT " bytes, packet contained %u bytes",
+ PacketType, m_State, bb.GetUsedSpace() - bb.GetReadableSpace(), PacketLen
+ );
+
+ // Put a message in the comm log:
+ if (g_ShouldLogCommIn)
+ {
+ m_CommLogFile.Printf("^^^^^^ Wrong number of bytes read for this packet (exp %d left, got " SIZE_T_FMT " left) ^^^^^^\n\n\n",
+ 1, bb.GetReadableSpace()
+ );
+ m_CommLogFile.Flush();
+ }
+
+ ASSERT(!"Read wrong number of bytes!");
+ m_Client->PacketError(PacketType);
+ }
+ } // for (ever)
+
+ // Log any leftover bytes into the logfile:
+ if (g_ShouldLogCommIn && (m_ReceivedData.GetReadableSpace() > 0))
+ {
+ AString AllData;
+ size_t OldReadableSpace = m_ReceivedData.GetReadableSpace();
+ m_ReceivedData.ReadAll(AllData);
+ m_ReceivedData.ResetRead();
+ m_ReceivedData.SkipRead(m_ReceivedData.GetReadableSpace() - OldReadableSpace);
+ ASSERT(m_ReceivedData.GetReadableSpace() == OldReadableSpace);
+ AString Hex;
+ CreateHexDump(Hex, AllData.data(), AllData.size(), 16);
+ m_CommLogFile.Printf("There are " SIZE_T_FMT " (0x" SIZE_T_FMT_HEX ") bytes of non-parse-able data left in the buffer:\n%s",
+ m_ReceivedData.GetReadableSpace(), m_ReceivedData.GetReadableSpace(), Hex.c_str()
+ );
+ m_CommLogFile.Flush();
+ }
+}
+
+
+
+
+bool cProtocol180::HandlePacket(cByteBuffer & a_ByteBuffer, UInt32 a_PacketType)
+{
+ switch (m_State)
+ {
+ case 1:
+ {
+ // Status
+ switch (a_PacketType)
+ {
+ case 0x00: HandlePacketStatusRequest(a_ByteBuffer); return true;
+ case 0x01: HandlePacketStatusPing (a_ByteBuffer); return true;
+ }
+ break;
+ }
+
+ case 2:
+ {
+ // Login
+ switch (a_PacketType)
+ {
+ case 0x00: HandlePacketLoginStart (a_ByteBuffer); return true;
+ case 0x01: HandlePacketLoginEncryptionResponse(a_ByteBuffer); return true;
+ }
+ break;
+ }
+
+ case 3:
+ {
+ // Game
+ switch (a_PacketType)
+ {
+ case 0x00: HandlePacketKeepAlive (a_ByteBuffer); return true;
+ case 0x01: HandlePacketChatMessage (a_ByteBuffer); return true;
+ case 0x02: HandlePacketUseEntity (a_ByteBuffer); return true;
+ case 0x03: HandlePacketPlayer (a_ByteBuffer); return true;
+ case 0x04: HandlePacketPlayerPos (a_ByteBuffer); return true;
+ case 0x05: HandlePacketPlayerLook (a_ByteBuffer); return true;
+ case 0x06: HandlePacketPlayerPosLook (a_ByteBuffer); return true;
+ case 0x07: HandlePacketBlockDig (a_ByteBuffer); return true;
+ case 0x08: HandlePacketBlockPlace (a_ByteBuffer); return true;
+ case 0x09: HandlePacketSlotSelect (a_ByteBuffer); return true;
+ case 0x0a: HandlePacketAnimation (a_ByteBuffer); return true;
+ case 0x0b: HandlePacketEntityAction (a_ByteBuffer); return true;
+ case 0x0c: HandlePacketSteerVehicle (a_ByteBuffer); return true;
+ case 0x0d: HandlePacketWindowClose (a_ByteBuffer); return true;
+ case 0x0e: HandlePacketWindowClick (a_ByteBuffer); return true;
+ case 0x0f: // Confirm transaction - not used in MCS
+ case 0x10: HandlePacketCreativeInventoryAction(a_ByteBuffer); return true;
+ case 0x11: HandlePacketEnchantItem (a_ByteBuffer); return true;
+ case 0x12: HandlePacketUpdateSign (a_ByteBuffer); return true;
+ case 0x13: HandlePacketPlayerAbilities (a_ByteBuffer); return true;
+ case 0x14: HandlePacketTabComplete (a_ByteBuffer); return true;
+ case 0x15: HandlePacketClientSettings (a_ByteBuffer); return true;
+ case 0x16: HandlePacketClientStatus (a_ByteBuffer); return true;
+ case 0x17: HandlePacketPluginMessage (a_ByteBuffer); return true;
+ }
+ break;
+ }
+ default:
+ {
+ // Received a packet in an unknown state, report:
+ LOGWARNING("Received a packet in an unknown protocol state %d. Ignoring further packets.", m_State);
+
+ // Cannot kick the client - we don't know this state and thus the packet number for the kick packet
+
+ // Switch to a state when all further packets are silently ignored:
+ m_State = 255;
+ return false;
+ }
+ case 255:
+ {
+ // This is the state used for "not processing packets anymore" when we receive a bad packet from a client.
+ // Do not output anything (the caller will do that for us), just return failure
+ return false;
+ }
+ } // switch (m_State)
+
+ // Unknown packet type, report to the ClientHandle:
+ m_Client->PacketUnknown(a_PacketType);
+ return false;
+}
+
+
+
+
+
+void cProtocol180::HandlePacketStatusPing(cByteBuffer & a_ByteBuffer)
+{
+ HANDLE_READ(a_ByteBuffer, ReadBEInt64, Int64, Timestamp);
+
+ cPacketizer Pkt(*this, 0x01); // Ping packet
+ Pkt.WriteInt64(Timestamp);
+}
+
+
+
+
+
+void cProtocol180::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer)
+{
+ cServer * Server = cRoot::Get()->GetServer();
+ AString ServerDescription = Server->GetDescription();
+ int NumPlayers = Server->GetNumPlayers();
+ int MaxPlayers = Server->GetMaxPlayers();
+ AString Favicon = Server->GetFaviconData();
+ cRoot::Get()->GetPluginManager()->CallHookServerPing(*m_Client, ServerDescription, NumPlayers, MaxPlayers, Favicon);
+
+ // Version:
+ Json::Value Version;
+ Version["name"] = "1.8";
+ Version["protocol"] = 47;
+
+ // Players:
+ Json::Value Players;
+ Players["online"] = NumPlayers;
+ Players["max"] = MaxPlayers;
+ // TODO: Add "sample"
+
+ // Description:
+ Json::Value Description;
+ Description["text"] = ServerDescription.c_str();
+
+ // Create the response:
+ Json::Value ResponseValue;
+ ResponseValue["version"] = Version;
+ ResponseValue["players"] = Players;
+ ResponseValue["description"] = Description;
+ if (!Favicon.empty())
+ {
+ ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str());
+ }
+
+ Json::StyledWriter Writer;
+ AString Response = Writer.write(ResponseValue);
+
+ cPacketizer Pkt(*this, 0x00); // Response packet
+ Pkt.WriteString(Response);
+}
+
+
+
+
+
+void cProtocol180::HandlePacketLoginEncryptionResponse(cByteBuffer & a_ByteBuffer)
+{
+ UInt32 EncKeyLength, EncNonceLength;
+ a_ByteBuffer.ReadVarInt(EncKeyLength);
+ AString EncKey;
+ if (!a_ByteBuffer.ReadString(EncKey, EncKeyLength))
+ {
+ return;
+ }
+ a_ByteBuffer.ReadVarInt(EncNonceLength);
+ AString EncNonce;
+ if (!a_ByteBuffer.ReadString(EncNonce, EncNonceLength))
+ {
+ return;
+ }
+ if ((EncKeyLength > MAX_ENC_LEN) || (EncNonceLength > MAX_ENC_LEN))
+ {
+ LOGD("Too long encryption");
+ m_Client->Kick("Hacked client");
+ return;
+ }
+
+ // Decrypt EncNonce using privkey
+ cRsaPrivateKey & rsaDecryptor = cRoot::Get()->GetServer()->GetPrivateKey();
+ Int32 DecryptedNonce[MAX_ENC_LEN / sizeof(Int32)];
+ int res = rsaDecryptor.Decrypt((const Byte *)EncNonce.data(), EncNonce.size(), (Byte *)DecryptedNonce, sizeof(DecryptedNonce));
+ if (res != 4)
+ {
+ LOGD("Bad nonce length: got %d, exp %d", res, 4);
+ m_Client->Kick("Hacked client");
+ return;
+ }
+ if (ntohl(DecryptedNonce[0]) != (unsigned)(uintptr_t)this)
+ {
+ LOGD("Bad nonce value");
+ m_Client->Kick("Hacked client");
+ return;
+ }
+
+ // Decrypt the symmetric encryption key using privkey:
+ Byte DecryptedKey[MAX_ENC_LEN];
+ res = rsaDecryptor.Decrypt((const Byte *)EncKey.data(), EncKey.size(), DecryptedKey, sizeof(DecryptedKey));
+ if (res != 16)
+ {
+ LOGD("Bad key length");
+ m_Client->Kick("Hacked client");
+ return;
+ }
+
+ StartEncryption(DecryptedKey);
+ m_Client->HandleLogin(4, m_Client->GetUsername());
+}
+
+
+
+
+
+void cProtocol180::HandlePacketLoginStart(cByteBuffer & a_ByteBuffer)
+{
+ AString Username;
+ if (!a_ByteBuffer.ReadVarUTF8String(Username))
+ {
+ m_Client->Kick("Bad username");
+ return;
+ }
+
+ if (!m_Client->HandleHandshake(Username))
+ {
+ // The client is not welcome here, they have been sent a Kick packet already
+ return;
+ }
+
+ cServer * Server = cRoot::Get()->GetServer();
+ // If auth is required, then send the encryption request:
+ if (Server->ShouldAuthenticate())
+ {
+ cPacketizer Pkt(*this, 0x01);
+ Pkt.WriteString(Server->GetServerID());
+ const AString & PubKeyDer = Server->GetPublicKeyDER();
+ Pkt.WriteVarInt((short)PubKeyDer.size());
+ Pkt.WriteBuf(PubKeyDer.data(), PubKeyDer.size());
+ Pkt.WriteVarInt(4);
+ Pkt.WriteInt((int)(intptr_t)this); // Using 'this' as the cryptographic nonce, so that we don't have to generate one each time :)
+ m_Client->SetUsername(Username);
+ return;
+ }
+
+ m_Client->HandleLogin(4, Username);
+}
+
+
+
+
+
+void cProtocol180::HandlePacketAnimation(cByteBuffer & a_ByteBuffer)
+{
+ HANDLE_READ(a_ByteBuffer, ReadBEInt, int, EntityID);
+ HANDLE_READ(a_ByteBuffer, ReadByte, Byte, Animation);
+ m_Client->HandleAnimation(Animation);
+}
+
+
+
+
+
+void cProtocol180::HandlePacketBlockDig(cByteBuffer & a_ByteBuffer)
+{
+ HANDLE_READ(a_ByteBuffer, ReadByte, Byte, Status);
+
+ int BlockX, BlockY, BlockZ;
+ if (!a_ByteBuffer.ReadPosition(BlockX, BlockY, BlockZ))
+ {
+ return;
+ }
+
+ HANDLE_READ(a_ByteBuffer, ReadByte, Byte, Face);
+ m_Client->HandleLeftClick(BlockX, BlockY, BlockZ, static_cast<eBlockFace>(Face), Status);
+}
+
+
+
+
+
+void cProtocol180::HandlePacketBlockPlace(cByteBuffer & a_ByteBuffer)
+{
+ int BlockX, BlockY, BlockZ;
+ if (!a_ByteBuffer.ReadPosition(BlockX, BlockY, BlockZ))
+ {
+ return;
+ }
+
+ HANDLE_READ(a_ByteBuffer, ReadByte, Byte, Face);
+ if (Face == 255)
+ {
+ Face = 0;
+ }
+
+ cItem Item;
+ ReadItem(a_ByteBuffer, Item, 3);
+
+ HANDLE_READ(a_ByteBuffer, ReadByte, Byte, CursorX);
+ HANDLE_READ(a_ByteBuffer, ReadByte, Byte, CursorY);
+ HANDLE_READ(a_ByteBuffer, ReadByte, Byte, CursorZ);
+ m_Client->HandleRightClick(BlockX, BlockY, BlockZ, static_cast<eBlockFace>(Face), CursorX, CursorY, CursorZ, m_Client->GetPlayer()->GetEquippedItem());
+}
+
+
+
+
+
+void cProtocol180::HandlePacketChatMessage(cByteBuffer & a_ByteBuffer)
+{
+ HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, Message);
+ m_Client->HandleChat(Message);
+}
+
+
+
+
+
+void cProtocol180::HandlePacketClientSettings(cByteBuffer & a_ByteBuffer)
+{
+ HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, Locale);
+ HANDLE_READ(a_ByteBuffer, ReadByte, Byte, ViewDistance);
+ HANDLE_READ(a_ByteBuffer, ReadByte, Byte, ChatFlags);
+ HANDLE_READ(a_ByteBuffer, ReadBool, bool, ChatColors);
+ HANDLE_READ(a_ByteBuffer, ReadChar, char, SkinFlags);
+
+ m_Client->SetLocale(Locale);
+ // TODO: Handle other values
+}
+
+
+
+
+
+void cProtocol180::HandlePacketClientStatus(cByteBuffer & a_ByteBuffer)
+{
+ HANDLE_READ(a_ByteBuffer, ReadChar, char, ActionID);
+ switch (ActionID)
+ {
+ case 0:
+ {
+ // Respawn
+ m_Client->HandleRespawn();
+ break;
+ }
+ case 1:
+ {
+ // Request stats
+ const cStatManager & Manager = m_Client->GetPlayer()->GetStatManager();
+ SendStatistics(Manager);
+
+ break;
+ }
+ case 2:
+ {
+ // Open Inventory achievement
+ m_Client->GetPlayer()->AwardAchievement(achOpenInv);
+ break;
+ }
+ }
+}
+
+
+
+
+
+void cProtocol180::HandlePacketCreativeInventoryAction(cByteBuffer & a_ByteBuffer)
+{
+ HANDLE_READ(a_ByteBuffer, ReadBEShort, short, SlotNum);
+ cItem Item;
+ if (!ReadItem(a_ByteBuffer, Item))
+ {
+ return;
+ }
+ m_Client->HandleCreativeInventory(SlotNum, Item);
+}
+
+
+
+
+
+void cProtocol180::HandlePacketEntityAction(cByteBuffer & a_ByteBuffer)
+{
+ HANDLE_READ(a_ByteBuffer, ReadVarInt, UInt32, PlayerID);
+ HANDLE_READ(a_ByteBuffer, ReadChar, char, Action);
+ HANDLE_READ(a_ByteBuffer, ReadVarInt, UInt32, JumpBoost);
+
+ switch (Action)
+ {
+ case 0: m_Client->HandleEntityCrouch(PlayerID, true); break; // Crouch
+ case 1: m_Client->HandleEntityCrouch(PlayerID, false); break; // Uncrouch
+ case 2: m_Client->HandleEntityLeaveBed(PlayerID); break; // Leave Bed
+ case 3: m_Client->HandleEntitySprinting(PlayerID, true); break; // Start sprinting
+ case 4: m_Client->HandleEntitySprinting(PlayerID, false); break; // Stop sprinting
+ }
+}
+
+
+
+
+
+void cProtocol180::HandlePacketKeepAlive(cByteBuffer & a_ByteBuffer)
+{
+ HANDLE_READ(a_ByteBuffer, ReadVarInt, UInt32, KeepAliveID);
+ m_Client->HandleKeepAlive((int)KeepAliveID);
+}
+
+
+
+
+
+void cProtocol180::HandlePacketPlayer(cByteBuffer & a_ByteBuffer)
+{
+ HANDLE_READ(a_ByteBuffer, ReadBool, bool, IsOnGround);
+ // TODO: m_Client->HandlePlayerOnGround(IsOnGround);
+}
+
+
+
+
+
+void cProtocol180::HandlePacketPlayerAbilities(cByteBuffer & a_ByteBuffer)
+{
+ HANDLE_READ(a_ByteBuffer, ReadByte, Byte, Flags);
+ HANDLE_READ(a_ByteBuffer, ReadBEFloat, float, FlyingSpeed);
+ HANDLE_READ(a_ByteBuffer, ReadBEFloat, float, WalkingSpeed);
+
+ bool IsFlying = false, CanFly = false;
+ if ((Flags & 2) != 0)
+ {
+ IsFlying = true;
+ }
+ if ((Flags & 4) != 0)
+ {
+ CanFly = true;
+ }
+
+ m_Client->HandlePlayerAbilities(CanFly, IsFlying, FlyingSpeed, WalkingSpeed);
+}
+
+
+
+
+
+void cProtocol180::HandlePacketPlayerLook(cByteBuffer & a_ByteBuffer)
+{
+ HANDLE_READ(a_ByteBuffer, ReadBEFloat, float, Yaw);
+ HANDLE_READ(a_ByteBuffer, ReadBEFloat, float, Pitch);
+ HANDLE_READ(a_ByteBuffer, ReadBool, bool, IsOnGround);
+ m_Client->HandlePlayerLook(Yaw, Pitch, IsOnGround);
+}
+
+
+
+
+
+void cProtocol180::HandlePacketPlayerPos(cByteBuffer & a_ByteBuffer)
+{
+ HANDLE_READ(a_ByteBuffer, ReadBEDouble, double, PosX);
+ HANDLE_READ(a_ByteBuffer, ReadBEDouble, double, PosY);
+ HANDLE_READ(a_ByteBuffer, ReadBEDouble, double, PosZ);
+ HANDLE_READ(a_ByteBuffer, ReadBool, bool, IsOnGround);
+ m_Client->HandlePlayerPos(PosX, PosY, PosZ, PosY + 1.62, IsOnGround);
+}
+
+
+
+
+
+void cProtocol180::HandlePacketPlayerPosLook(cByteBuffer & a_ByteBuffer)
+{
+ HANDLE_READ(a_ByteBuffer, ReadBEDouble, double, PosX);
+ HANDLE_READ(a_ByteBuffer, ReadBEDouble, double, PosY);
+ HANDLE_READ(a_ByteBuffer, ReadBEDouble, double, PosZ);
+ HANDLE_READ(a_ByteBuffer, ReadBEFloat, float, Yaw);
+ HANDLE_READ(a_ByteBuffer, ReadBEFloat, float, Pitch);
+ HANDLE_READ(a_ByteBuffer, ReadBool, bool, IsOnGround);
+ m_Client->HandlePlayerMoveLook(PosX, PosY, PosZ, PosY + 1.62, Yaw, Pitch, IsOnGround);
+}
+
+
+
+
+
+void cProtocol180::HandlePacketPluginMessage(cByteBuffer & a_ByteBuffer)
+{
+ HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, Channel);
+ AString Data;
+ a_ByteBuffer.ReadAll(Data);
+ m_Client->HandlePluginMessage(Channel, Data);
+}
+
+
+
+
+
+void cProtocol180::HandlePacketSlotSelect(cByteBuffer & a_ByteBuffer)
+{
+ HANDLE_READ(a_ByteBuffer, ReadBEShort, short, SlotNum);
+ m_Client->HandleSlotSelected(SlotNum);
+}
+
+
+
+
+
+void cProtocol180::HandlePacketSteerVehicle(cByteBuffer & a_ByteBuffer)
+{
+ HANDLE_READ(a_ByteBuffer, ReadBEFloat, float, Forward);
+ HANDLE_READ(a_ByteBuffer, ReadBEFloat, float, Sideways);
+ HANDLE_READ(a_ByteBuffer, ReadChar, char, Flags);
+
+ if ((Flags & 0x2) != 0)
+ {
+ m_Client->HandleUnmount();
+ }
+ else if ((Flags & 0x1) != 0)
+ {
+ m_Client->HandleSteerVehicle(Forward, Sideways);
+ }
+}
+
+
+
+
+
+void cProtocol180::HandlePacketTabComplete(cByteBuffer & a_ByteBuffer)
+{
+ HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, Text);
+ HANDLE_READ(a_ByteBuffer, ReadBool, bool, HasPosition);
+
+ if (HasPosition)
+ {
+ HANDLE_READ(a_ByteBuffer, ReadBEInt64, Int64, Position);
+ }
+
+ m_Client->HandleTabCompletion(Text);
+}
+
+
+
+
+
+void cProtocol180::HandlePacketUpdateSign(cByteBuffer & a_ByteBuffer)
+{
+ int BlockX, BlockY, BlockZ;
+ if (!a_ByteBuffer.ReadPosition(BlockX, BlockY, BlockZ))
+ {
+ return;
+ }
+
+ AString Lines[4];
+ for (int i = 0; i < 4; i++)
+ {
+ HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, Line);
+ Lines[i] = Line.substr(1, Line.length() - 2); // Remove ""
+ }
+
+ m_Client->HandleUpdateSign(BlockX, BlockY, BlockZ, Lines[0], Lines[1], Lines[2], Lines[3]);
+}
+
+
+
+
+
+void cProtocol180::HandlePacketUseEntity(cByteBuffer & a_ByteBuffer)
+{
+ HANDLE_READ(a_ByteBuffer, ReadVarInt, UInt32, EntityID);
+ HANDLE_READ(a_ByteBuffer, ReadVarInt, UInt32, Type);
+
+ switch (Type)
+ {
+ case 0:
+ {
+ m_Client->HandleUseEntity((int)EntityID, false);
+ break;
+ }
+ case 1:
+ {
+ m_Client->HandleUseEntity((int)EntityID, true);
+ break;
+ }
+ case 2:
+ {
+ HANDLE_READ(a_ByteBuffer, ReadBEFloat, float, TargetX);
+ HANDLE_READ(a_ByteBuffer, ReadBEFloat, float, TargetY);
+ HANDLE_READ(a_ByteBuffer, ReadBEFloat, float, TargetZ);
+
+ // TODO: Do anything
+ break;
+ }
+ default:
+ {
+ ASSERT(!"Unhandled use entity type!");
+ return;
+ }
+ }
+}
+
+
+
+
+
+void cProtocol180::HandlePacketEnchantItem(cByteBuffer & a_ByteBuffer)
+{
+ HANDLE_READ(a_ByteBuffer, ReadByte, Byte, WindowID);
+ HANDLE_READ(a_ByteBuffer, ReadByte, Byte, Enchantment);
+
+ m_Client->HandleEnchantItem(WindowID, Enchantment);
+}
+
+
+
+
+
+void cProtocol180::HandlePacketWindowClick(cByteBuffer & a_ByteBuffer)
+{
+ HANDLE_READ(a_ByteBuffer, ReadChar, char, WindowID);
+ HANDLE_READ(a_ByteBuffer, ReadBEShort, short, SlotNum);
+ HANDLE_READ(a_ByteBuffer, ReadByte, Byte, Button);
+ HANDLE_READ(a_ByteBuffer, ReadBEShort, short, TransactionID);
+ HANDLE_READ(a_ByteBuffer, ReadByte, Byte, Mode);
+ cItem Item;
+ ReadItem(a_ByteBuffer, Item);
+
+ // Convert Button, Mode, SlotNum and HeldItem into eClickAction:
+ eClickAction Action;
+ switch ((Mode << 8) | Button)
+ {
+ case 0x0000: Action = (SlotNum != -999) ? caLeftClick : caLeftClickOutside; break;
+ case 0x0001: Action = (SlotNum != -999) ? caRightClick : caRightClickOutside; break;
+ case 0x0100: Action = caShiftLeftClick; break;
+ case 0x0101: Action = caShiftRightClick; break;
+ case 0x0200: Action = caNumber1; break;
+ case 0x0201: Action = caNumber2; break;
+ case 0x0202: Action = caNumber3; break;
+ case 0x0203: Action = caNumber4; break;
+ case 0x0204: Action = caNumber5; break;
+ case 0x0205: Action = caNumber6; break;
+ case 0x0206: Action = caNumber7; break;
+ case 0x0207: Action = caNumber8; break;
+ case 0x0208: Action = caNumber9; break;
+ case 0x0300: Action = caMiddleClick; break;
+ case 0x0400: Action = (SlotNum == -999) ? caLeftClickOutsideHoldNothing : caDropKey; break;
+ case 0x0401: Action = (SlotNum == -999) ? caRightClickOutsideHoldNothing : caCtrlDropKey; break;
+ case 0x0500: Action = (SlotNum == -999) ? caLeftPaintBegin : caUnknown; break;
+ case 0x0501: Action = (SlotNum != -999) ? caLeftPaintProgress : caUnknown; break;
+ case 0x0502: Action = (SlotNum == -999) ? caLeftPaintEnd : caUnknown; break;
+ case 0x0504: Action = (SlotNum == -999) ? caRightPaintBegin : caUnknown; break;
+ case 0x0505: Action = (SlotNum != -999) ? caRightPaintProgress : caUnknown; break;
+ case 0x0506: Action = (SlotNum == -999) ? caRightPaintEnd : caUnknown; break;
+ case 0x0600: Action = caDblClick; break;
+ default:
+ {
+ LOGWARNING("Unhandled window click mode / button combination: %d (0x%x)", (Mode << 8) | Button, (Mode << 8) | Button);
+ Action = caUnknown;
+ break;
+ }
+ }
+
+ m_Client->HandleWindowClick(WindowID, SlotNum, Action, Item);
+}
+
+
+
+
+
+void cProtocol180::HandlePacketWindowClose(cByteBuffer & a_ByteBuffer)
+{
+ HANDLE_READ(a_ByteBuffer, ReadChar, char, WindowID);
+ m_Client->HandleWindowClose(WindowID);
+}
+
+
+
+
+
+void cProtocol180::WritePacket(cByteBuffer & a_Packet)
+{
+ cCSLock Lock(m_CSPacket);
+ AString Pkt;
+ a_Packet.ReadAll(Pkt);
+ WriteVarInt((UInt32)Pkt.size());
+ SendData(Pkt.data(), Pkt.size());
+ Flush();
+}
+
+
+
+
+
+void cProtocol180::SendData(const char * a_Data, size_t a_Size)
+{
+ if (m_IsEncrypted)
+ {
+ Byte Encrypted[8192]; // Larger buffer, we may be sending lots of data (chunks)
+ while (a_Size > 0)
+ {
+ size_t NumBytes = (a_Size > sizeof(Encrypted)) ? sizeof(Encrypted) : a_Size;
+ m_Encryptor.ProcessData(Encrypted, (Byte *)a_Data, NumBytes);
+ m_Client->SendData((const char *)Encrypted, NumBytes);
+ a_Size -= NumBytes;
+ a_Data += NumBytes;
+ }
+ }
+ else
+ {
+ m_Client->SendData(a_Data, a_Size);
+ }
+}
+
+
+
+
+
+bool cProtocol180::ReadItem(cByteBuffer & a_ByteBuffer, cItem & a_Item, size_t a_RemainingBytes)
+{
+ HANDLE_PACKET_READ(a_ByteBuffer, ReadBEShort, short, ItemType);
+ if (ItemType == -1)
+ {
+ // The item is empty, no more data follows
+ a_Item.Empty();
+ return true;
+ }
+ a_Item.m_ItemType = ItemType;
+
+ HANDLE_PACKET_READ(a_ByteBuffer, ReadChar, char, ItemCount);
+ HANDLE_PACKET_READ(a_ByteBuffer, ReadBEShort, short, ItemDamage);
+ a_Item.m_ItemCount = ItemCount;
+ a_Item.m_ItemDamage = ItemDamage;
+ if (ItemCount <= 0)
+ {
+ a_Item.Empty();
+ }
+
+ AString Metadata;
+ if (!a_ByteBuffer.ReadString(Metadata, a_ByteBuffer.GetReadableSpace() - a_RemainingBytes) || (Metadata.size() == 0) || (Metadata[0] == 0))
+ {
+ // No metadata
+ return true;
+ }
+
+ ParseItemMetadata(a_Item, Metadata);
+ return true;
+}
+
+
+
+
+
+void cProtocol180::ParseItemMetadata(cItem & a_Item, const AString & a_Metadata)
+{
+ // Parse into NBT:
+ cParsedNBT NBT(a_Metadata.data(), a_Metadata.size());
+ if (!NBT.IsValid())
+ {
+ AString HexDump;
+ CreateHexDump(HexDump, a_Metadata.data(), a_Metadata.size(), 16);
+ LOGWARNING("Cannot parse NBT item metadata: (" SIZE_T_FMT " bytes)\n%s", a_Metadata.size(), HexDump.c_str());
+ return;
+ }
+
+ // Load enchantments and custom display names from the NBT data:
+ for (int tag = NBT.GetFirstChild(NBT.GetRoot()); tag >= 0; tag = NBT.GetNextSibling(tag))
+ {
+ AString TagName = NBT.GetName(tag);
+ switch (NBT.GetType(tag))
+ {
+ case TAG_List:
+ {
+ if ((TagName == "ench") || (TagName == "StoredEnchantments")) // Enchantments tags
+ {
+ EnchantmentSerializer::ParseFromNBT(a_Item.m_Enchantments, NBT, tag);
+ }
+ break;
+ }
+ case TAG_Compound:
+ {
+ if (TagName == "display") // Custom name and lore tag
+ {
+ for (int displaytag = NBT.GetFirstChild(tag); displaytag >= 0; displaytag = NBT.GetNextSibling(displaytag))
+ {
+ if ((NBT.GetType(displaytag) == TAG_String) && (NBT.GetName(displaytag) == "Name")) // Custon name tag
+ {
+ a_Item.m_CustomName = NBT.GetString(displaytag);
+ }
+ else if ((NBT.GetType(displaytag) == TAG_List) && (NBT.GetName(displaytag) == "Lore")) // Lore tag
+ {
+ AString Lore;
+
+ for (int loretag = NBT.GetFirstChild(displaytag); loretag >= 0; loretag = NBT.GetNextSibling(loretag)) // Loop through array of strings
+ {
+ AppendPrintf(Lore, "%s`", NBT.GetString(loretag).c_str()); // Append the lore with a grave accent/backtick, used internally by MCS to display a new line in the client; don't forget to c_str ;)
+ }
+
+ a_Item.m_Lore = Lore;
+ }
+ }
+ }
+ else if ((TagName == "Fireworks") || (TagName == "Explosion"))
+ {
+ cFireworkItem::ParseFromNBT(a_Item.m_FireworkItem, NBT, tag, (ENUM_ITEM_ID)a_Item.m_ItemType);
+ }
+ break;
+ }
+ case TAG_Int:
+ {
+ if (TagName == "RepairCost")
+ {
+ a_Item.m_RepairCost = NBT.GetInt(tag);
+ }
+ }
+ default: LOGD("Unimplemented NBT data when parsing!"); break;
+ }
+ }
+}
+
+
+
+
+
+void cProtocol180::StartEncryption(const Byte * a_Key)
+{
+ m_Encryptor.Init(a_Key, a_Key);
+ m_Decryptor.Init(a_Key, a_Key);
+ m_IsEncrypted = true;
+
+ // Prepare the m_AuthServerID:
+ cSha1Checksum Checksum;
+ cServer * Server = cRoot::Get()->GetServer();
+ const AString & ServerID = Server->GetServerID();
+ Checksum.Update((const Byte *)ServerID.c_str(), ServerID.length());
+ Checksum.Update(a_Key, 16);
+ Checksum.Update((const Byte *)Server->GetPublicKeyDER().data(), Server->GetPublicKeyDER().size());
+ Byte Digest[20];
+ Checksum.Finalize(Digest);
+ cSha1Checksum::DigestToJava(Digest, m_AuthServerID);
+}
+
+
+
+
+
+////////////////////////////////////////////////////////////////////////////////
+// cProtocol180::cPacketizer:
+
+cProtocol180::cPacketizer::~cPacketizer()
+{
+ UInt32 PacketLen = (UInt32)m_Out.GetUsedSpace();
+ AString PacketData, CompressedPacket;
+ m_Out.ReadAll(PacketData);
+ m_Out.CommitRead();
+
+ if ((m_Protocol.m_State == 3) && (PacketLen >= 256))
+ {
+ if (!cProtocol180::CompressPacket(PacketData, CompressedPacket))
+ {
+ return;
+ }
+ }
+ else if (m_Protocol.m_State == 3)
+ {
+ m_Protocol.m_OutPacketLenBuffer.WriteVarInt(PacketLen + 1);
+ m_Protocol.m_OutPacketLenBuffer.WriteVarInt(0);
+
+ AString LengthData;
+ m_Protocol.m_OutPacketLenBuffer.ReadAll(LengthData);
+ m_Protocol.SendData(LengthData.data(), LengthData.size());
+ }
+ else
+ {
+ m_Protocol.m_OutPacketLenBuffer.WriteVarInt(PacketLen);
+
+ AString LengthData;
+ m_Protocol.m_OutPacketLenBuffer.ReadAll(LengthData);
+ m_Protocol.SendData(LengthData.data(), LengthData.size());
+ }
+
+ if (CompressedPacket.empty())
+ {
+ m_Protocol.m_OutPacketLenBuffer.CommitRead();
+ m_Protocol.SendData(PacketData.data(), PacketData.size());
+ }
+ else
+ {
+ m_Protocol.SendData(CompressedPacket.data(), CompressedPacket.size());
+ }
+
+ // Log the comm into logfile:
+ if (g_ShouldLogCommOut)
+ {
+ AString Hex;
+ ASSERT(PacketData.size() > 0);
+ CreateHexDump(Hex, PacketData.data() + 1, PacketData.size() - 1, 16);
+ m_Protocol.m_CommLogFile.Printf("Outgoing packet: type %d (0x%x), length %u (0x%x), state %d. Payload:\n%s\n",
+ PacketData[0], PacketData[0], PacketLen, PacketLen, m_Protocol.m_State, Hex.c_str()
+ );
+ }
+}
+
+
+
+
+
+void cProtocol180::cPacketizer::WriteUUID(const AString & a_UUID)
+{
+ if (a_UUID.length() != 32)
+ {
+ LOGWARNING("Attempt to send a bad uuid (length isn't 32): %s", a_UUID.c_str());
+ ASSERT(!"Wrong uuid length!");
+ return;
+ }
+ AString UUID_1 = a_UUID.substr(0, 16);
+ AString UUID_2 = a_UUID.substr(16);
+
+ Int64 Value_1, Value_2;
+ sscanf(UUID_1.c_str(), "%llx", &Value_1);
+ sscanf(UUID_2.c_str(), "%llx", &Value_2);
+
+ WriteInt64(Value_1);
+ WriteInt64(Value_2);
+}
+
+
+
+
+
+void cProtocol180::cPacketizer::WriteItem(const cItem & a_Item)
+{
+ short ItemType = a_Item.m_ItemType;
+ ASSERT(ItemType >= -1); // Check validity of packets in debug runtime
+ if (ItemType <= 0)
+ {
+ // Fix, to make sure no invalid values are sent.
+ ItemType = -1;
+ }
+
+ if (a_Item.IsEmpty())
+ {
+ WriteShort(-1);
+ return;
+ }
+
+ WriteShort(ItemType);
+ WriteByte (a_Item.m_ItemCount);
+ WriteShort(a_Item.m_ItemDamage);
+
+ if (a_Item.m_Enchantments.IsEmpty() && a_Item.IsBothNameAndLoreEmpty() && (a_Item.m_ItemType != E_ITEM_FIREWORK_ROCKET) && (a_Item.m_ItemType != E_ITEM_FIREWORK_STAR))
+ {
+ WriteChar(0);
+ return;
+ }
+
+ // Send the enchantments and custom names:
+ cFastNBTWriter Writer;
+ if (a_Item.m_RepairCost != 0)
+ {
+ Writer.AddInt("RepairCost", a_Item.m_RepairCost);
+ }
+ if (!a_Item.m_Enchantments.IsEmpty())
+ {
+ const char * TagName = (a_Item.m_ItemType == E_ITEM_BOOK) ? "StoredEnchantments" : "ench";
+ EnchantmentSerializer::WriteToNBTCompound(a_Item.m_Enchantments, Writer, TagName);
+ }
+ if (!a_Item.IsBothNameAndLoreEmpty())
+ {
+ Writer.BeginCompound("display");
+ if (!a_Item.IsCustomNameEmpty())
+ {
+ Writer.AddString("Name", a_Item.m_CustomName.c_str());
+ }
+ if (!a_Item.IsLoreEmpty())
+ {
+ Writer.BeginList("Lore", TAG_String);
+
+ AStringVector Decls = StringSplit(a_Item.m_Lore, "`");
+ for (AStringVector::const_iterator itr = Decls.begin(), end = Decls.end(); itr != end; ++itr)
+ {
+ if (itr->empty())
+ {
+ // The decl is empty (two `s), ignore
+ continue;
+ }
+ Writer.AddString("", itr->c_str());
+ }
+
+ Writer.EndList();
+ }
+ Writer.EndCompound();
+ }
+ if ((a_Item.m_ItemType == E_ITEM_FIREWORK_ROCKET) || (a_Item.m_ItemType == E_ITEM_FIREWORK_STAR))
+ {
+ cFireworkItem::WriteToNBTCompound(a_Item.m_FireworkItem, Writer, (ENUM_ITEM_ID)a_Item.m_ItemType);
+ }
+ Writer.Finish();
+
+ AString Result = Writer.GetResult();
+ if (Result.size() == 0)
+ {
+ WriteChar(0);
+ return;
+ }
+ WriteBuf(Result.data(), Result.size());
+}
+
+
+
+
+
+void cProtocol180::cPacketizer::WriteBlockEntity(const cBlockEntity & a_BlockEntity)
+{
+ cFastNBTWriter Writer;
+
+ switch (a_BlockEntity.GetBlockType())
+ {
+ case E_BLOCK_BEACON:
+ {
+ cBeaconEntity & BeaconEntity = (cBeaconEntity &)a_BlockEntity;
+
+ Writer.AddInt("x", BeaconEntity.GetPosX());
+ Writer.AddInt("y", BeaconEntity.GetPosY());
+ Writer.AddInt("z", BeaconEntity.GetPosZ());
+ Writer.AddInt("Primary", BeaconEntity.GetPrimaryEffect());
+ Writer.AddInt("Secondary", BeaconEntity.GetSecondaryEffect());
+ Writer.AddInt("Levels", BeaconEntity.GetBeaconLevel());
+ Writer.AddString("id", "Beacon"); // "Tile Entity ID" - MC wiki; vanilla server always seems to send this though
+ break;
+ }
+ case E_BLOCK_COMMAND_BLOCK:
+ {
+ cCommandBlockEntity & CommandBlockEntity = (cCommandBlockEntity &)a_BlockEntity;
+
+ Writer.AddByte("TrackOutput", 1); // Neither I nor the MC wiki has any idea about this
+ Writer.AddInt("SuccessCount", CommandBlockEntity.GetResult());
+ Writer.AddInt("x", CommandBlockEntity.GetPosX());
+ Writer.AddInt("y", CommandBlockEntity.GetPosY());
+ Writer.AddInt("z", CommandBlockEntity.GetPosZ());
+ Writer.AddString("Command", CommandBlockEntity.GetCommand().c_str());
+ // You can set custom names for windows in Vanilla
+ // For a command block, this would be the 'name' prepended to anything it outputs into global chat
+ // MCS doesn't have this, so just leave it @ '@'. (geddit?)
+ Writer.AddString("CustomName", "@");
+ Writer.AddString("id", "Control"); // "Tile Entity ID" - MC wiki; vanilla server always seems to send this though
+
+ if (!CommandBlockEntity.GetLastOutput().empty())
+ {
+ AString Output;
+ Printf(Output, "{\"text\":\"%s\"}", CommandBlockEntity.GetLastOutput().c_str());
+
+ Writer.AddString("LastOutput", Output.c_str());
+ }
+ break;
+ }
+ case E_BLOCK_HEAD:
+ {
+ cMobHeadEntity & MobHeadEntity = (cMobHeadEntity &)a_BlockEntity;
+
+ Writer.AddInt("x", MobHeadEntity.GetPosX());
+ Writer.AddInt("y", MobHeadEntity.GetPosY());
+ Writer.AddInt("z", MobHeadEntity.GetPosZ());
+ Writer.AddByte("SkullType", MobHeadEntity.GetType() & 0xFF);
+ Writer.AddByte("Rot", MobHeadEntity.GetRotation() & 0xFF);
+ Writer.AddString("ExtraType", MobHeadEntity.GetOwner().c_str());
+ Writer.AddString("id", "Skull"); // "Tile Entity ID" - MC wiki; vanilla server always seems to send this though
+ break;
+ }
+ case E_BLOCK_FLOWER_POT:
+ {
+ cFlowerPotEntity & FlowerPotEntity = (cFlowerPotEntity &)a_BlockEntity;
+
+ Writer.AddInt("x", FlowerPotEntity.GetPosX());
+ Writer.AddInt("y", FlowerPotEntity.GetPosY());
+ Writer.AddInt("z", FlowerPotEntity.GetPosZ());
+ Writer.AddInt("Item", (Int32) FlowerPotEntity.GetItem().m_ItemType);
+ Writer.AddInt("Data", (Int32) FlowerPotEntity.GetItem().m_ItemDamage);
+ Writer.AddString("id", "FlowerPot"); // "Tile Entity ID" - MC wiki; vanilla server always seems to send this though
+ break;
+ }
+ default: break;
+ }
+
+ Writer.Finish();
+ WriteBuf(Writer.GetResult().data(), Writer.GetResult().size());
+}
+
+
+
+
+
+void cProtocol180::cPacketizer::WriteByteAngle(double a_Angle)
+{
+ WriteByte((char)(255 * a_Angle / 360));
+}
+
+
+
+
+
+void cProtocol180::cPacketizer::WriteFPInt(double a_Value)
+{
+ int Value = (int)(a_Value * 32);
+ WriteInt(Value);
+}
+
+
+
+
+
+void cProtocol180::cPacketizer::WriteEntityMetadata(const cEntity & a_Entity)
+{
+ // Common metadata:
+ Byte Flags = 0;
+ if (a_Entity.IsOnFire())
+ {
+ Flags |= 0x01;
+ }
+ if (a_Entity.IsCrouched())
+ {
+ Flags |= 0x02;
+ }
+ if (a_Entity.IsSprinting())
+ {
+ Flags |= 0x08;
+ }
+ if (a_Entity.IsRclking())
+ {
+ Flags |= 0x10;
+ }
+ if (a_Entity.IsInvisible())
+ {
+ Flags |= 0x20;
+ }
+ WriteByte(0); // Byte(0) + index 0
+ WriteByte(Flags);
+
+ switch (a_Entity.GetEntityType())
+ {
+ case cEntity::etPlayer: break; // TODO?
+ case cEntity::etPickup:
+ {
+ WriteByte((5 << 5) | 10); // Slot(5) + index 10
+ WriteItem(((const cPickup &)a_Entity).GetItem());
+ break;
+ }
+ case cEntity::etMinecart:
+ {
+ WriteByte(0x51);
+
+ // The following expression makes Minecarts shake more with less health or higher damage taken
+ // It gets half the maximum health, and takes it away from the current health minus the half health:
+ /*
+ Health: 5 | 3 - (5 - 3) = 1 (shake power)
+ Health: 3 | 3 - (3 - 3) = 3
+ Health: 1 | 3 - (1 - 3) = 5
+ */
+ WriteInt((((a_Entity.GetMaxHealth() / 2) - (a_Entity.GetHealth() - (a_Entity.GetMaxHealth() / 2))) * ((const cMinecart &)a_Entity).LastDamage()) * 4);
+ WriteByte(0x52);
+ WriteInt(1); // Shaking direction, doesn't seem to affect anything
+ WriteByte(0x73);
+ WriteFloat((float)(((const cMinecart &)a_Entity).LastDamage() + 10)); // Damage taken / shake effect multiplyer
+
+ if (((cMinecart &)a_Entity).GetPayload() == cMinecart::mpNone)
+ {
+ cRideableMinecart & RideableMinecart = ((cRideableMinecart &)a_Entity);
+ const cItem & MinecartContent = RideableMinecart.GetContent();
+ if (!MinecartContent.IsEmpty())
+ {
+ WriteByte(0x54);
+ int Content = MinecartContent.m_ItemType;
+ Content |= MinecartContent.m_ItemDamage << 8;
+ WriteInt(Content);
+ WriteByte(0x55);
+ WriteInt(RideableMinecart.GetBlockHeight());
+ WriteByte(0x56);
+ WriteByte(1);
+ }
+ }
+ else if (((cMinecart &)a_Entity).GetPayload() == cMinecart::mpFurnace)
+ {
+ WriteByte(0x10);
+ WriteByte(((const cMinecartWithFurnace &)a_Entity).IsFueled() ? 1 : 0);
+ }
+ break;
+ }
+ case cEntity::etProjectile:
+ {
+ cProjectileEntity & Projectile = (cProjectileEntity &)a_Entity;
+ switch (Projectile.GetProjectileKind())
+ {
+ case cProjectileEntity::pkArrow:
+ {
+ WriteByte(0x10);
+ WriteByte(((const cArrowEntity &)a_Entity).IsCritical() ? 1 : 0);
+ break;
+ }
+ case cProjectileEntity::pkFirework:
+ {
+ WriteByte(0xA8);
+ WriteItem(((const cFireworkEntity &)a_Entity).GetItem());
+ break;
+ }
+ default: break;
+ }
+ break;
+ }
+ case cEntity::etMonster:
+ {
+ WriteMobMetadata((const cMonster &)a_Entity);
+ break;
+ }
+ case cEntity::etItemFrame:
+ {
+ cItemFrame & Frame = (cItemFrame &)a_Entity;
+ WriteByte(0xA8);
+ WriteItem(Frame.GetItem());
+ WriteByte(0x09);
+ WriteByte(Frame.GetRotation());
+ break;
+ }
+ default: break;
+ }
+}
+
+
+
+
+
+void cProtocol180::cPacketizer::WriteMobMetadata(const cMonster & a_Mob)
+{
+ switch (a_Mob.GetMobType())
+ {
+ case cMonster::mtCreeper:
+ {
+ WriteByte(0x10);
+ WriteByte(((const cCreeper &)a_Mob).IsBlowing() ? 1 : -1);
+ WriteByte(0x11);
+ WriteByte(((const cCreeper &)a_Mob).IsCharged() ? 1 : 0);
+ break;
+ }
+
+ case cMonster::mtBat:
+ {
+ WriteByte(0x10);
+ WriteByte(((const cBat &)a_Mob).IsHanging() ? 1 : 0);
+ break;
+ }
+
+ case cMonster::mtPig:
+ {
+ WriteByte(0x10);
+ WriteByte(((const cPig &)a_Mob).IsSaddled() ? 1 : 0);
+ break;
+ }
+
+ case cMonster::mtVillager:
+ {
+ WriteByte(0x50);
+ WriteInt(((const cVillager &)a_Mob).GetVilType());
+ break;
+ }
+
+ case cMonster::mtZombie:
+ {
+ WriteByte(0x0c);
+ WriteByte(((const cZombie &)a_Mob).IsBaby() ? 1 : 0);
+ WriteByte(0x0d);
+ WriteByte(((const cZombie &)a_Mob).IsVillagerZombie() ? 1 : 0);
+ WriteByte(0x0e);
+ WriteByte(((const cZombie &)a_Mob).IsConverting() ? 1 : 0);
+ break;
+ }
+
+ case cMonster::mtGhast:
+ {
+ WriteByte(0x10);
+ WriteByte(((const cGhast &)a_Mob).IsCharging());
+ break;
+ }
+
+ case cMonster::mtWolf:
+ {
+ const cWolf & Wolf = (const cWolf &)a_Mob;
+ Byte WolfStatus = 0;
+ if (Wolf.IsSitting())
+ {
+ WolfStatus |= 0x1;
+ }
+ if (Wolf.IsAngry())
+ {
+ WolfStatus |= 0x2;
+ }
+ if (Wolf.IsTame())
+ {
+ WolfStatus |= 0x4;
+ }
+ WriteByte(0x10);
+ WriteByte(WolfStatus);
+
+ WriteByte(0x72);
+ WriteFloat((float)(a_Mob.GetHealth()));
+ WriteByte(0x13);
+ WriteByte(Wolf.IsBegging() ? 1 : 0);
+ WriteByte(0x14);
+ WriteByte(Wolf.GetCollarColor());
+ break;
+ }
+
+ case cMonster::mtSheep:
+ {
+ WriteByte(0x10);
+ Byte SheepMetadata = 0;
+ SheepMetadata = ((const cSheep &)a_Mob).GetFurColor();
+ if (((const cSheep &)a_Mob).IsSheared())
+ {
+ SheepMetadata |= 0x10;
+ }
+ WriteByte(SheepMetadata);
+ break;
+ }
+
+ case cMonster::mtEnderman:
+ {
+ WriteByte(0x30);
+ WriteShort((Byte)(((const cEnderman &)a_Mob).GetCarriedBlock()));
+ WriteByte(0x11);
+ WriteByte((Byte)(((const cEnderman &)a_Mob).GetCarriedMeta()));
+ WriteByte(0x12);
+ WriteByte(((const cEnderman &)a_Mob).IsScreaming() ? 1 : 0);
+ break;
+ }
+
+ case cMonster::mtSkeleton:
+ {
+ WriteByte(0x0d);
+ WriteByte(((const cSkeleton &)a_Mob).IsWither() ? 1 : 0);
+ break;
+ }
+
+ case cMonster::mtWitch:
+ {
+ WriteByte(0x15);
+ WriteByte(((const cWitch &)a_Mob).IsAngry() ? 1 : 0);
+ break;
+ }
+
+ case cMonster::mtWither:
+ {
+ WriteByte(0x54); // Int at index 20
+ WriteInt(((const cWither &)a_Mob).GetWitherInvulnerableTicks());
+ WriteByte(0x66); // Float at index 6
+ WriteFloat((float)(a_Mob.GetHealth()));
+ break;
+ }
+
+ case cMonster::mtSlime:
+ {
+ WriteByte(0x10);
+ WriteByte(((const cSlime &)a_Mob).GetSize());
+ break;
+ }
+
+ case cMonster::mtMagmaCube:
+ {
+ WriteByte(0x10);
+ WriteByte(((const cMagmaCube &)a_Mob).GetSize());
+ break;
+ }
+
+ case cMonster::mtHorse:
+ {
+ const cHorse & Horse = (const cHorse &)a_Mob;
+ int Flags = 0;
+ if (Horse.IsTame())
+ {
+ Flags |= 0x02;
+ }
+ if (Horse.IsSaddled())
+ {
+ Flags |= 0x04;
+ }
+ if (Horse.IsChested())
+ {
+ Flags |= 0x08;
+ }
+ if (Horse.IsBaby())
+ {
+ Flags |= 0x10;
+ }
+ if (Horse.IsEating())
+ {
+ Flags |= 0x20;
+ }
+ if (Horse.IsRearing())
+ {
+ Flags |= 0x40;
+ }
+ if (Horse.IsMthOpen())
+ {
+ Flags |= 0x80;
+ }
+ WriteByte(0x50); // Int at index 16
+ WriteInt(Flags);
+ WriteByte(0x13); // Byte at index 19
+ WriteByte(Horse.GetHorseType());
+ WriteByte(0x54); // Int at index 20
+ int Appearance = 0;
+ Appearance = Horse.GetHorseColor();
+ Appearance |= Horse.GetHorseStyle() << 8;
+ WriteInt(Appearance);
+ WriteByte(0x56); // Int at index 22
+ WriteInt(Horse.GetHorseArmour());
+ break;
+ }
+ } // switch (a_Mob.GetType())
+}
+
+
+
+
+
+void cProtocol180::cPacketizer::WriteEntityProperties(const cEntity & a_Entity)
+{
+ if (!a_Entity.IsMob())
+ {
+ // No properties for anything else than mobs
+ WriteInt(0);
+ return;
+ }
+
+ // const cMonster & Mob = (const cMonster &)a_Entity;
+
+ // TODO: Send properties and modifiers based on the mob type
+
+ WriteInt(0); // NumProperties
+}
+
+
+
diff --git a/src/Protocol/Protocol18x.h b/src/Protocol/Protocol18x.h
new file mode 100644
index 000000000..eb0253663
--- /dev/null
+++ b/src/Protocol/Protocol18x.h
@@ -0,0 +1,335 @@
+
+// Protocol18x.h
+
+/*
+Declares the 1.8.x protocol classes:
+ - cProtocol180
+ - release 1.8.0 protocol (#47)
+(others may be added later in the future for the 1.8 release series)
+*/
+
+
+
+
+
+#pragma once
+
+#include "Protocol.h"
+#include "../ByteBuffer.h"
+
+#ifdef _MSC_VER
+ #pragma warning(push)
+ #pragma warning(disable:4127)
+ #pragma warning(disable:4244)
+ #pragma warning(disable:4231)
+ #pragma warning(disable:4189)
+ #pragma warning(disable:4702)
+#endif
+
+#ifdef _MSC_VER
+ #pragma warning(pop)
+#endif
+
+#include "PolarSSL++/AesCfb128Decryptor.h"
+#include "PolarSSL++/AesCfb128Encryptor.h"
+
+
+
+
+
+// fwd:
+namespace Json
+{
+ class Value;
+}
+
+
+
+
+
+class cProtocol180 :
+ public cProtocol
+{
+ typedef cProtocol super;
+
+public:
+
+ cProtocol180(cClientHandle * a_Client, const AString & a_ServerAddress, UInt16 a_ServerPort, UInt32 a_State);
+
+ /** Called when client sends some data: */
+ virtual void DataReceived(const char * a_Data, size_t a_Size) override;
+
+ /** Sending stuff to clients (alphabetically sorted): */
+ virtual void SendAttachEntity (const cEntity & a_Entity, const cEntity * a_Vehicle) override;
+ virtual void SendBlockAction (int a_BlockX, int a_BlockY, int a_BlockZ, char a_Byte1, char a_Byte2, BLOCKTYPE a_BlockType) override;
+ virtual void SendBlockBreakAnim (int a_EntityID, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Stage) override;
+ virtual void SendBlockChange (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override;
+ virtual void SendBlockChanges (int a_ChunkX, int a_ChunkZ, const sSetBlockVector & a_Changes) override;
+ virtual void SendChat (const AString & a_Message) override;
+ virtual void SendChat (const cCompositeChat & a_Message) override;
+ virtual void SendChunkData (int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer) override;
+ virtual void SendCollectEntity (const cEntity & a_Entity, const cPlayer & a_Player) override;
+ virtual void SendDestroyEntity (const cEntity & a_Entity) override;
+ virtual void SendDisconnect (const AString & a_Reason) override;
+ virtual void SendEditSign (int a_BlockX, int a_BlockY, int a_BlockZ) override; ///< Request the client to open up the sign editor for the sign (1.6+)
+ virtual void SendEntityEffect (const cEntity & a_Entity, int a_EffectID, int a_Amplifier, short a_Duration) override;
+ virtual void SendEntityEquipment (const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item) override;
+ virtual void SendEntityHeadLook (const cEntity & a_Entity) override;
+ virtual void SendEntityLook (const cEntity & a_Entity) override;
+ virtual void SendEntityMetadata (const cEntity & a_Entity) override;
+ virtual void SendEntityProperties (const cEntity & a_Entity) override;
+ virtual void SendEntityRelMove (const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ) override;
+ virtual void SendEntityRelMoveLook (const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ) override;
+ virtual void SendEntityStatus (const cEntity & a_Entity, char a_Status) override;
+ virtual void SendEntityVelocity (const cEntity & a_Entity) override;
+ virtual void SendExplosion (double a_BlockX, double a_BlockY, double a_BlockZ, float a_Radius, const cVector3iArray & a_BlocksAffected, const Vector3d & a_PlayerMotion) override;
+ virtual void SendGameMode (eGameMode a_GameMode) override;
+ virtual void SendHealth (void) override;
+ virtual void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item) override;
+ virtual void SendKeepAlive (int a_PingID) override;
+ virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) override;
+ virtual void SendLoginSuccess (void) override;
+ virtual void SendMapColumn (int a_ID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length, unsigned int m_Scale) override;
+ virtual void SendMapDecorators (int a_ID, const cMapDecoratorList & a_Decorators, unsigned int m_Scale) override;
+ virtual void SendMapInfo (int a_ID, unsigned int a_Scale) override;
+ virtual void SendPaintingSpawn (const cPainting & a_Painting) override;
+ virtual void SendPickupSpawn (const cPickup & a_Pickup) override;
+ virtual void SendPlayerAbilities (void) override;
+ virtual void SendEntityAnimation (const cEntity & a_Entity, char a_Animation) override;
+ virtual void SendParticleEffect (const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmount) override;
+ virtual void SendPlayerListAddPlayer (const cPlayer & a_Player) override;
+ virtual void SendPlayerListRemovePlayer (const cPlayer & a_Player) override;
+ virtual void SendPlayerListUpdateGameMode (const cPlayer & a_Player) override;
+ virtual void SendPlayerListUpdatePing (const cPlayer & a_Player) override;
+ virtual void SendPlayerListUpdateDisplayName(const cPlayer & a_Player, const AString & a_OldListName) override;
+ virtual void SendPlayerMaxSpeed (void) override;
+ virtual void SendPlayerMoveLook (void) override;
+ virtual void SendPlayerPosition (void) override;
+ virtual void SendPlayerSpawn (const cPlayer & a_Player) override;
+ virtual void SendPluginMessage (const AString & a_Channel, const AString & a_Message) override;
+ virtual void SendRemoveEntityEffect (const cEntity & a_Entity, int a_EffectID) override;
+ virtual void SendRespawn (eDimension a_Dimension, bool a_ShouldIgnoreDimensionChecks) override;
+ virtual void SendSoundEffect (const AString & a_SoundName, double a_X, double a_Y, double a_Z, float a_Volume, float a_Pitch) override;
+ virtual void SendExperience (void) override;
+ virtual void SendExperienceOrb (const cExpOrb & a_ExpOrb) override;
+ virtual void SendScoreboardObjective (const AString & a_Name, const AString & a_DisplayName, Byte a_Mode) override;
+ virtual void SendScoreUpdate (const AString & a_Objective, const AString & a_Player, cObjective::Score a_Score, Byte a_Mode) override;
+ virtual void SendDisplayObjective (const AString & a_Objective, cScoreboard::eDisplaySlot a_Display) override;
+ virtual void SendSoundParticleEffect (int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data) override;
+ virtual void SendSpawnFallingBlock (const cFallingBlock & a_FallingBlock) override;
+ virtual void SendSpawnMob (const cMonster & a_Mob) override;
+ virtual void SendSpawnObject (const cEntity & a_Entity, char a_ObjectType, int a_ObjectData, Byte a_Yaw, Byte a_Pitch) override;
+ virtual void SendSpawnVehicle (const cEntity & a_Vehicle, char a_VehicleType, char a_VehicleSubType) override;
+ virtual void SendStatistics (const cStatManager & a_Manager) override;
+ virtual void SendTabCompletionResults (const AStringVector & a_Results) override;
+ virtual void SendTeleportEntity (const cEntity & a_Entity) override;
+ virtual void SendThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ) override;
+ virtual void SendTimeUpdate (Int64 a_WorldAge, Int64 a_TimeOfDay, bool a_DoDaylightCycle) override;
+ virtual void SendUnloadChunk (int a_ChunkX, int a_ChunkZ) override;
+ virtual void SendUpdateBlockEntity (cBlockEntity & a_BlockEntity) override;
+ virtual void SendUpdateSign (int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4) override;
+ virtual void SendUseBed (const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ) override;
+ virtual void SendWeather (eWeather a_Weather) override;
+ virtual void SendWholeInventory (const cWindow & a_Window) override;
+ virtual void SendWindowClose (const cWindow & a_Window) override;
+ virtual void SendWindowOpen (const cWindow & a_Window) override;
+ virtual void SendWindowProperty (const cWindow & a_Window, int a_Property, int a_Value) override;
+
+ virtual AString GetAuthServerID(void) override { return m_AuthServerID; }
+
+ /** Compress the packet. a_Packet must be without packet length.
+ a_Compressed will be set to the compressed packet includes packet length and data length.
+ If compression fails, the function returns false. */
+ static bool CompressPacket(const AString & a_Packet, AString & a_Compressed);
+
+ /** The 1.8 protocol use a particle id instead of a string. This function converts the name to the id. If the name is incorrect, it returns 0. */
+ static int GetParticleID(const AString & a_ParticleName);
+
+ /** Minecraft 1.8 use other locations to spawn the item frame. This function converts the 1.7 positions to 1.8 positions. */
+ static void FixItemFramePositions(int a_ObjectData, double & a_PosX, double & a_PosZ, double & a_Yaw);
+
+protected:
+
+ /** Composes individual packets in the protocol's m_OutPacketBuffer; sends them upon being destructed */
+ class cPacketizer
+ {
+ public:
+ cPacketizer(cProtocol180 & a_Protocol, UInt32 a_PacketType) :
+ m_Protocol(a_Protocol),
+ m_Out(a_Protocol.m_OutPacketBuffer),
+ m_Lock(a_Protocol.m_CSPacket)
+ {
+ m_Out.WriteVarInt(a_PacketType);
+ }
+
+ ~cPacketizer();
+
+ void WriteBool(bool a_Value)
+ {
+ m_Out.WriteBool(a_Value);
+ }
+
+ void WriteByte(Byte a_Value)
+ {
+ m_Out.WriteByte(a_Value);
+ }
+
+ void WriteChar(char a_Value)
+ {
+ m_Out.WriteChar(a_Value);
+ }
+
+ void WriteShort(short a_Value)
+ {
+ m_Out.WriteBEShort(a_Value);
+ }
+
+ void WriteInt(int a_Value)
+ {
+ m_Out.WriteBEInt(a_Value);
+ }
+
+ void WriteInt64(Int64 a_Value)
+ {
+ m_Out.WriteBEInt64(a_Value);
+ }
+
+ void WriteFloat(float a_Value)
+ {
+ m_Out.WriteBEFloat(a_Value);
+ }
+
+ void WriteDouble(double a_Value)
+ {
+ m_Out.WriteBEDouble(a_Value);
+ }
+
+ void WriteVarInt(UInt32 a_Value)
+ {
+ m_Out.WriteVarInt(a_Value);
+ }
+
+ void WriteString(const AString & a_Value)
+ {
+ m_Out.WriteVarUTF8String(a_Value);
+ }
+
+ void WritePosition(int a_BlockX, int a_BlockY, int a_BlockZ)
+ {
+ m_Out.WritePosition(a_BlockX, a_BlockY, a_BlockZ);
+ }
+
+ void WriteUUID(const AString & a_UUID);
+
+ void WriteBuf(const char * a_Data, size_t a_Size)
+ {
+ m_Out.Write(a_Data, a_Size);
+ }
+
+ void WriteItem(const cItem & a_Item);
+ void WriteByteAngle(double a_Angle); // Writes the specified angle using a single byte
+ void WriteFPInt(double a_Value); // Writes the double value as a 27:5 fixed-point integer
+ void WriteEntityMetadata(const cEntity & a_Entity); // Writes the metadata for the specified entity, not including the terminating 0x7f
+ void WriteMobMetadata(const cMonster & a_Mob); // Writes the mob-specific metadata for the specified mob
+ void WriteEntityProperties(const cEntity & a_Entity); // Writes the entity properties for the specified entity, including the Count field
+ void WriteBlockEntity(const cBlockEntity & a_BlockEntity);
+
+ protected:
+ cProtocol180 & m_Protocol;
+ cByteBuffer & m_Out;
+ cCSLock m_Lock;
+ } ;
+
+ AString m_ServerAddress;
+
+ UInt16 m_ServerPort;
+
+ AString m_AuthServerID;
+
+ /** State of the protocol. 1 = status, 2 = login, 3 = game */
+ UInt32 m_State;
+
+ /** Buffer for the received data */
+ cByteBuffer m_ReceivedData;
+
+ /** Buffer for composing the outgoing packets, through cPacketizer */
+ cByteBuffer m_OutPacketBuffer;
+
+ /** Buffer for composing packet length (so that each cPacketizer instance doesn't allocate a new cPacketBuffer) */
+ cByteBuffer m_OutPacketLenBuffer;
+
+ bool m_IsEncrypted;
+
+ cAesCfb128Decryptor m_Decryptor;
+ cAesCfb128Encryptor m_Encryptor;
+
+ /** The logfile where the comm is logged, when g_ShouldLogComm is true */
+ cFile m_CommLogFile;
+
+ /** The dimension that was last sent to a player in a Respawn or Login packet.
+ Used to avoid Respawning into the same dimension, which confuses the client. */
+ eDimension m_LastSentDimension;
+
+
+ /** Adds the received (unencrypted) data to m_ReceivedData, parses complete packets */
+ void AddReceivedData(const char * a_Data, size_t a_Size);
+
+ /** Reads and handles the packet. The packet length and type have already been read.
+ Returns true if the packet was understood, false if it was an unknown packet
+ */
+ bool HandlePacket(cByteBuffer & a_ByteBuffer, UInt32 a_PacketType);
+
+ // Packet handlers while in the Status state (m_State == 1):
+ void HandlePacketStatusPing(cByteBuffer & a_ByteBuffer);
+ void HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer);
+
+ // Packet handlers while in the Login state (m_State == 2):
+ void HandlePacketLoginEncryptionResponse(cByteBuffer & a_ByteBuffer);
+ void HandlePacketLoginStart(cByteBuffer & a_ByteBuffer);
+
+ // Packet handlers while in the Game state (m_State == 3):
+ void HandlePacketAnimation (cByteBuffer & a_ByteBuffer);
+ void HandlePacketBlockDig (cByteBuffer & a_ByteBuffer);
+ void HandlePacketBlockPlace (cByteBuffer & a_ByteBuffer);
+ void HandlePacketChatMessage (cByteBuffer & a_ByteBuffer);
+ void HandlePacketClientSettings (cByteBuffer & a_ByteBuffer);
+ void HandlePacketClientStatus (cByteBuffer & a_ByteBuffer);
+ void HandlePacketCreativeInventoryAction(cByteBuffer & a_ByteBuffer);
+ void HandlePacketEntityAction (cByteBuffer & a_ByteBuffer);
+ void HandlePacketKeepAlive (cByteBuffer & a_ByteBuffer);
+ void HandlePacketPlayer (cByteBuffer & a_ByteBuffer);
+ void HandlePacketPlayerAbilities (cByteBuffer & a_ByteBuffer);
+ void HandlePacketPlayerLook (cByteBuffer & a_ByteBuffer);
+ void HandlePacketPlayerPos (cByteBuffer & a_ByteBuffer);
+ void HandlePacketPlayerPosLook (cByteBuffer & a_ByteBuffer);
+ void HandlePacketPluginMessage (cByteBuffer & a_ByteBuffer);
+ void HandlePacketSlotSelect (cByteBuffer & a_ByteBuffer);
+ void HandlePacketSteerVehicle (cByteBuffer & a_ByteBuffer);
+ void HandlePacketTabComplete (cByteBuffer & a_ByteBuffer);
+ void HandlePacketUpdateSign (cByteBuffer & a_ByteBuffer);
+ void HandlePacketUseEntity (cByteBuffer & a_ByteBuffer);
+ void HandlePacketEnchantItem (cByteBuffer & a_ByteBuffer);
+ void HandlePacketWindowClick (cByteBuffer & a_ByteBuffer);
+ void HandlePacketWindowClose (cByteBuffer & a_ByteBuffer);
+
+
+ /** Writes an entire packet into the output stream. a_Packet is expected to start with the packet type; data length is prepended here. */
+ void WritePacket(cByteBuffer & a_Packet);
+
+ /** Sends the data to the client, encrypting them if needed. */
+ virtual void SendData(const char * a_Data, size_t a_Size) override;
+
+ void SendCompass(const cWorld & a_World);
+
+ /** Reads an item out of the received data, sets a_Item to the values read. Returns false if not enough received data */
+ virtual bool ReadItem(cByteBuffer & a_ByteBuffer, cItem & a_Item, size_t a_RemainingBytes = 0);
+
+ /** Parses item metadata as read by ReadItem(), into the item enchantments. */
+ void ParseItemMetadata(cItem & a_Item, const AString & a_Metadata);
+
+ void StartEncryption(const Byte * a_Key);
+
+} ;
+
+
+
diff --git a/src/Protocol/ProtocolRecognizer.cpp b/src/Protocol/ProtocolRecognizer.cpp
index 2cd2a935b..a5b745c2f 100644
--- a/src/Protocol/ProtocolRecognizer.cpp
+++ b/src/Protocol/ProtocolRecognizer.cpp
@@ -13,6 +13,7 @@
#include "Protocol15x.h"
#include "Protocol16x.h"
#include "Protocol17x.h"
+#include "Protocol18x.h"
#include "../ClientHandle.h"
#include "../Root.h"
#include "../Server.h"
@@ -27,7 +28,7 @@
cProtocolRecognizer::cProtocolRecognizer(cClientHandle * a_Client) :
super(a_Client),
m_Protocol(NULL),
- m_Buffer(512)
+ m_Buffer(8192) // We need a larger buffer to support BungeeCord - it sends one huge packet at the start
{
}
@@ -51,7 +52,7 @@ AString cProtocolRecognizer::GetVersionTextFromInt(int a_ProtocolVersion)
{
case PROTO_VERSION_1_2_5: return "1.2.5";
case PROTO_VERSION_1_3_2: return "1.3.2";
- case PROTO_VERSION_1_4_2: return "1.4.2";
+ // case PROTO_VERSION_1_4_2: return "1.4.2";
case PROTO_VERSION_1_4_4: return "1.4.4";
case PROTO_VERSION_1_4_6: return "1.4.6";
case PROTO_VERSION_1_5_0: return "1.5";
@@ -62,6 +63,7 @@ AString cProtocolRecognizer::GetVersionTextFromInt(int a_ProtocolVersion)
case PROTO_VERSION_1_6_4: return "1.6.4";
case PROTO_VERSION_1_7_2: return "1.7.2";
case PROTO_VERSION_1_7_6: return "1.7.6";
+ case PROTO_VERSION_1_8_0: return "1.8";
}
ASSERT(!"Unknown protocol version");
return Printf("Unknown protocol (%d)", a_ProtocolVersion);
@@ -409,20 +411,20 @@ void cProtocolRecognizer::SendLoginSuccess(void)
-void cProtocolRecognizer::SendMapColumn(int a_ID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length)
+void cProtocolRecognizer::SendMapColumn(int a_ID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length, unsigned int m_Scale)
{
ASSERT(m_Protocol != NULL);
- m_Protocol->SendMapColumn(a_ID, a_X, a_Y, a_Colors, a_Length);
+ m_Protocol->SendMapColumn(a_ID, a_X, a_Y, a_Colors, a_Length, m_Scale);
}
-void cProtocolRecognizer::SendMapDecorators(int a_ID, const cMapDecoratorList & a_Decorators)
+void cProtocolRecognizer::SendMapDecorators(int a_ID, const cMapDecoratorList & a_Decorators, unsigned int m_Scale)
{
ASSERT(m_Protocol != NULL);
- m_Protocol->SendMapDecorators(a_ID, a_Decorators);
+ m_Protocol->SendMapDecorators(a_ID, a_Decorators, m_Scale);
}
@@ -439,10 +441,10 @@ void cProtocolRecognizer::SendMapInfo(int a_ID, unsigned int a_Scale)
-void cProtocolRecognizer::SendParticleEffect(const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmmount)
+void cProtocolRecognizer::SendParticleEffect(const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmount)
{
ASSERT(m_Protocol != NULL);
- m_Protocol->SendParticleEffect(a_ParticleName, a_SrcX, a_SrcY, a_SrcZ, a_OffsetX, a_OffsetY, a_OffsetZ, a_ParticleData, a_ParticleAmmount);
+ m_Protocol->SendParticleEffect(a_ParticleName, a_SrcX, a_SrcY, a_SrcZ, a_OffsetX, a_OffsetY, a_OffsetZ, a_ParticleData, a_ParticleAmount);
}
@@ -487,10 +489,50 @@ void cProtocolRecognizer::SendEntityAnimation(const cEntity & a_Entity, char a_A
-void cProtocolRecognizer::SendPlayerListItem(const AString & a_PlayerName, bool a_IsOnline, short a_Ping)
+void cProtocolRecognizer::SendPlayerListAddPlayer(const cPlayer & a_Player)
{
ASSERT(m_Protocol != NULL);
- m_Protocol->SendPlayerListItem(a_PlayerName, a_IsOnline, a_Ping);
+ m_Protocol->SendPlayerListAddPlayer(a_Player);
+}
+
+
+
+
+
+void cProtocolRecognizer::SendPlayerListRemovePlayer(const cPlayer & a_Player)
+{
+ ASSERT(m_Protocol != NULL);
+ m_Protocol->SendPlayerListRemovePlayer(a_Player);
+}
+
+
+
+
+
+void cProtocolRecognizer::SendPlayerListUpdateGameMode(const cPlayer & a_Player)
+{
+ ASSERT(m_Protocol != NULL);
+ m_Protocol->SendPlayerListUpdateGameMode(a_Player);
+}
+
+
+
+
+
+void cProtocolRecognizer::SendPlayerListUpdatePing(const cPlayer & a_Player)
+{
+ ASSERT(m_Protocol != NULL);
+ m_Protocol->SendPlayerListUpdatePing(a_Player);
+}
+
+
+
+
+
+void cProtocolRecognizer::SendPlayerListUpdateDisplayName(const cPlayer & a_Player, const AString & a_OldListName)
+{
+ ASSERT(m_Protocol != NULL);
+ m_Protocol->SendPlayerListUpdateDisplayName(a_Player, a_OldListName);
}
@@ -1016,6 +1058,27 @@ bool cProtocolRecognizer::TryRecognizeLengthedProtocol(UInt32 a_PacketLengthRema
m_Protocol = new cProtocol176(m_Client, ServerAddress, (UInt16)ServerPort, NextState);
return true;
}
+ case PROTO_VERSION_1_8_0:
+ {
+ AString ServerAddress;
+ short ServerPort;
+ UInt32 NextState;
+ if (!m_Buffer.ReadVarUTF8String(ServerAddress))
+ {
+ break;
+ }
+ if (!m_Buffer.ReadBEShort(ServerPort))
+ {
+ break;
+ }
+ if (!m_Buffer.ReadVarInt(NextState))
+ {
+ break;
+ }
+ m_Buffer.CommitRead();
+ m_Protocol = new cProtocol180(m_Client, ServerAddress, (UInt16)ServerPort, NextState);
+ return true;
+ }
}
LOGINFO("Client \"%s\" uses an unsupported protocol (lengthed, version %u)",
m_Client->GetIPString().c_str(), ProtocolVersion
diff --git a/src/Protocol/ProtocolRecognizer.h b/src/Protocol/ProtocolRecognizer.h
index 95fcae1d3..55348a758 100644
--- a/src/Protocol/ProtocolRecognizer.h
+++ b/src/Protocol/ProtocolRecognizer.h
@@ -18,7 +18,7 @@
// Adjust these if a new protocol is added or an old one is removed:
-#define MCS_CLIENT_VERSIONS "1.2.4, 1.2.5, 1.3.1, 1.3.2, 1.4.2, 1.4.4, 1.4.5, 1.4.6, 1.4.7, 1.5, 1.5.1, 1.5.2, 1.6.1, 1.6.2, 1.6.3, 1.6.4, 1.7.2, 1.7.4, 1.7.5, 1.7.6, 1.7.7, 1.7.8, 1.7.9, 1.7.10"
+#define MCS_CLIENT_VERSIONS "1.2.4, 1.2.5, 1.3.1, 1.3.2, 1.4.2, 1.4.4, 1.4.5, 1.4.6, 1.4.7, 1.5, 1.5.1, 1.5.2, 1.6.1, 1.6.2, 1.6.3, 1.6.4, 1.7.2, 1.7.4, 1.7.5, 1.7.6, 1.7.7, 1.7.8, 1.7.9, 1.7.10, 1.8"
#define MCS_PROTOCOL_VERSIONS "29, 39, 47, 49, 51, 60, 61, 73, 74, 77, 78, 4, 5"
@@ -51,6 +51,7 @@ public:
// These will be kept "under" the next / latest, because the next and latest are only needed for previous protocols
PROTO_VERSION_1_7_2 = 4,
PROTO_VERSION_1_7_6 = 5,
+ PROTO_VERSION_1_8_0 = 47,
} ;
cProtocolRecognizer(cClientHandle * a_Client);
@@ -63,76 +64,80 @@ public:
virtual void DataReceived(const char * a_Data, size_t a_Size) override;
/// Sending stuff to clients (alphabetically sorted):
- virtual void SendAttachEntity (const cEntity & a_Entity, const cEntity * a_Vehicle) override;
- virtual void SendBlockAction (int a_BlockX, int a_BlockY, int a_BlockZ, char a_Byte1, char a_Byte2, BLOCKTYPE a_BlockType) override;
- virtual void SendBlockBreakAnim (int a_EntityID, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Stage) override;
- virtual void SendBlockChange (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override;
- virtual void SendBlockChanges (int a_ChunkX, int a_ChunkZ, const sSetBlockVector & a_Changes) override;
- virtual void SendChat (const AString & a_Message) override;
- virtual void SendChat (const cCompositeChat & a_Message) override;
- virtual void SendChunkData (int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer) override;
- virtual void SendCollectEntity (const cEntity & a_Entity, const cPlayer & a_Player) override;
- virtual void SendDestroyEntity (const cEntity & a_Entity) override;
- virtual void SendDisconnect (const AString & a_Reason) override;
- virtual void SendEditSign (int a_BlockX, int a_BlockY, int a_BlockZ) override; ///< Request the client to open up the sign editor for the sign (1.6+)
- virtual void SendEntityEffect (const cEntity & a_Entity, int a_EffectID, int a_Amplifier, short a_Duration) override;
- virtual void SendEntityEquipment (const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item) override;
- virtual void SendEntityHeadLook (const cEntity & a_Entity) override;
- virtual void SendEntityLook (const cEntity & a_Entity) override;
- virtual void SendEntityMetadata (const cEntity & a_Entity) override;
- virtual void SendEntityProperties (const cEntity & a_Entity) override;
- virtual void SendEntityRelMove (const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ) override;
- virtual void SendEntityRelMoveLook (const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ) override;
- virtual void SendEntityStatus (const cEntity & a_Entity, char a_Status) override;
- virtual void SendEntityVelocity (const cEntity & a_Entity) override;
- virtual void SendExplosion (double a_BlockX, double a_BlockY, double a_BlockZ, float a_Radius, const cVector3iArray & a_BlocksAffected, const Vector3d & a_PlayerMotion) override;
- virtual void SendGameMode (eGameMode a_GameMode) override;
- virtual void SendHealth (void) override;
- virtual void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item) override;
- virtual void SendKeepAlive (int a_PingID) override;
- virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) override;
- virtual void SendLoginSuccess (void) override;
- virtual void SendMapColumn (int a_ID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length) override;
- virtual void SendMapDecorators (int a_ID, const cMapDecoratorList & a_Decorators) override;
- virtual void SendMapInfo (int a_ID, unsigned int a_Scale) override;
- virtual void SendParticleEffect (const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmmount) override;
- virtual void SendPaintingSpawn (const cPainting & a_Painting) override;
- virtual void SendPickupSpawn (const cPickup & a_Pickup) override;
- virtual void SendPlayerAbilities (void) override;
- virtual void SendEntityAnimation (const cEntity & a_Entity, char a_Animation) override;
- virtual void SendPlayerListItem (const AString & a_PlayerName, bool a_IsOnline, short a_Ping = 0) override;
- virtual void SendPlayerMaxSpeed (void) override;
- virtual void SendPlayerMoveLook (void) override;
- virtual void SendPlayerPosition (void) override;
- virtual void SendPlayerSpawn (const cPlayer & a_Player) override;
- virtual void SendPluginMessage (const AString & a_Channel, const AString & a_Message) override;
- virtual void SendRemoveEntityEffect (const cEntity & a_Entity, int a_EffectID) override;
- virtual void SendRespawn (eDimension a_Dimension, bool a_ShouldIgnoreDimensionChecks) override;
- virtual void SendExperience (void) override;
- virtual void SendExperienceOrb (const cExpOrb & a_ExpOrb) override;
- virtual void SendScoreboardObjective (const AString & a_Name, const AString & a_DisplayName, Byte a_Mode) override;
- virtual void SendScoreUpdate (const AString & a_Objective, const AString & a_Player, cObjective::Score a_Score, Byte a_Mode) override;
- virtual void SendDisplayObjective (const AString & a_Objective, cScoreboard::eDisplaySlot a_Display) override;
- virtual void SendSoundEffect (const AString & a_SoundName, double a_X, double a_Y, double a_Z, float a_Volume, float a_Pitch) override;
- virtual void SendSoundParticleEffect (int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data) override;
- virtual void SendSpawnFallingBlock (const cFallingBlock & a_FallingBlock) override;
- virtual void SendSpawnMob (const cMonster & a_Mob) override;
- virtual void SendSpawnObject (const cEntity & a_Entity, char a_ObjectType, int a_ObjectData, Byte a_Yaw, Byte a_Pitch) override;
- virtual void SendSpawnVehicle (const cEntity & a_Vehicle, char a_VehicleType, char a_VehicleSubType) override;
- virtual void SendStatistics (const cStatManager & a_Manager) override;
- virtual void SendTabCompletionResults(const AStringVector & a_Results) override;
- virtual void SendTeleportEntity (const cEntity & a_Entity) override;
- virtual void SendThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ) override;
- virtual void SendTimeUpdate (Int64 a_WorldAge, Int64 a_TimeOfDay, bool a_DoDaylightCycle) override;
- virtual void SendUnloadChunk (int a_ChunkX, int a_ChunkZ) override;
- virtual void SendUpdateBlockEntity (cBlockEntity & a_BlockEntity) override;
- virtual void SendUpdateSign (int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4) override;
- virtual void SendUseBed (const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ) override;
- virtual void SendWeather (eWeather a_Weather) override;
- virtual void SendWholeInventory (const cWindow & a_Window) override;
- virtual void SendWindowClose (const cWindow & a_Window) override;
- virtual void SendWindowOpen (const cWindow & a_Window) override;
- virtual void SendWindowProperty (const cWindow & a_Window, int a_Property, int a_Value) override;
+ virtual void SendAttachEntity (const cEntity & a_Entity, const cEntity * a_Vehicle) override;
+ virtual void SendBlockAction (int a_BlockX, int a_BlockY, int a_BlockZ, char a_Byte1, char a_Byte2, BLOCKTYPE a_BlockType) override;
+ virtual void SendBlockBreakAnim (int a_EntityID, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Stage) override;
+ virtual void SendBlockChange (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override;
+ virtual void SendBlockChanges (int a_ChunkX, int a_ChunkZ, const sSetBlockVector & a_Changes) override;
+ virtual void SendChat (const AString & a_Message) override;
+ virtual void SendChat (const cCompositeChat & a_Message) override;
+ virtual void SendChunkData (int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer) override;
+ virtual void SendCollectEntity (const cEntity & a_Entity, const cPlayer & a_Player) override;
+ virtual void SendDestroyEntity (const cEntity & a_Entity) override;
+ virtual void SendDisconnect (const AString & a_Reason) override;
+ virtual void SendEditSign (int a_BlockX, int a_BlockY, int a_BlockZ) override; ///< Request the client to open up the sign editor for the sign (1.6+)
+ virtual void SendEntityEffect (const cEntity & a_Entity, int a_EffectID, int a_Amplifier, short a_Duration) override;
+ virtual void SendEntityEquipment (const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item) override;
+ virtual void SendEntityHeadLook (const cEntity & a_Entity) override;
+ virtual void SendEntityLook (const cEntity & a_Entity) override;
+ virtual void SendEntityMetadata (const cEntity & a_Entity) override;
+ virtual void SendEntityProperties (const cEntity & a_Entity) override;
+ virtual void SendEntityRelMove (const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ) override;
+ virtual void SendEntityRelMoveLook (const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ) override;
+ virtual void SendEntityStatus (const cEntity & a_Entity, char a_Status) override;
+ virtual void SendEntityVelocity (const cEntity & a_Entity) override;
+ virtual void SendExplosion (double a_BlockX, double a_BlockY, double a_BlockZ, float a_Radius, const cVector3iArray & a_BlocksAffected, const Vector3d & a_PlayerMotion) override;
+ virtual void SendGameMode (eGameMode a_GameMode) override;
+ virtual void SendHealth (void) override;
+ virtual void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item) override;
+ virtual void SendKeepAlive (int a_PingID) override;
+ virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) override;
+ virtual void SendLoginSuccess (void) override;
+ virtual void SendMapColumn (int a_ID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length, unsigned int m_Scale) override;
+ virtual void SendMapDecorators (int a_ID, const cMapDecoratorList & a_Decorators, unsigned int m_Scale) override;
+ virtual void SendMapInfo (int a_ID, unsigned int a_Scale) override;
+ virtual void SendParticleEffect (const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmount) override;
+ virtual void SendPaintingSpawn (const cPainting & a_Painting) override;
+ virtual void SendPickupSpawn (const cPickup & a_Pickup) override;
+ virtual void SendPlayerAbilities (void) override;
+ virtual void SendEntityAnimation (const cEntity & a_Entity, char a_Animation) override;
+ virtual void SendPlayerListAddPlayer (const cPlayer & a_Player) override;
+ virtual void SendPlayerListRemovePlayer (const cPlayer & a_Player) override;
+ virtual void SendPlayerListUpdateGameMode (const cPlayer & a_Player) override;
+ virtual void SendPlayerListUpdatePing (const cPlayer & a_Player) override;
+ virtual void SendPlayerListUpdateDisplayName(const cPlayer & a_Player, const AString & a_OldListName) override;
+ virtual void SendPlayerMaxSpeed (void) override;
+ virtual void SendPlayerMoveLook (void) override;
+ virtual void SendPlayerPosition (void) override;
+ virtual void SendPlayerSpawn (const cPlayer & a_Player) override;
+ virtual void SendPluginMessage (const AString & a_Channel, const AString & a_Message) override;
+ virtual void SendRemoveEntityEffect (const cEntity & a_Entity, int a_EffectID) override;
+ virtual void SendRespawn (eDimension a_Dimension, bool a_ShouldIgnoreDimensionChecks) override;
+ virtual void SendExperience (void) override;
+ virtual void SendExperienceOrb (const cExpOrb & a_ExpOrb) override;
+ virtual void SendScoreboardObjective (const AString & a_Name, const AString & a_DisplayName, Byte a_Mode) override;
+ virtual void SendScoreUpdate (const AString & a_Objective, const AString & a_Player, cObjective::Score a_Score, Byte a_Mode) override;
+ virtual void SendDisplayObjective (const AString & a_Objective, cScoreboard::eDisplaySlot a_Display) override;
+ virtual void SendSoundEffect (const AString & a_SoundName, double a_X, double a_Y, double a_Z, float a_Volume, float a_Pitch) override;
+ virtual void SendSoundParticleEffect (int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data) override;
+ virtual void SendSpawnFallingBlock (const cFallingBlock & a_FallingBlock) override;
+ virtual void SendSpawnMob (const cMonster & a_Mob) override;
+ virtual void SendSpawnObject (const cEntity & a_Entity, char a_ObjectType, int a_ObjectData, Byte a_Yaw, Byte a_Pitch) override;
+ virtual void SendSpawnVehicle (const cEntity & a_Vehicle, char a_VehicleType, char a_VehicleSubType) override;
+ virtual void SendStatistics (const cStatManager & a_Manager) override;
+ virtual void SendTabCompletionResults (const AStringVector & a_Results) override;
+ virtual void SendTeleportEntity (const cEntity & a_Entity) override;
+ virtual void SendThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ) override;
+ virtual void SendTimeUpdate (Int64 a_WorldAge, Int64 a_TimeOfDay, bool a_DoDaylightCycle) override;
+ virtual void SendUnloadChunk (int a_ChunkX, int a_ChunkZ) override;
+ virtual void SendUpdateBlockEntity (cBlockEntity & a_BlockEntity) override;
+ virtual void SendUpdateSign (int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4) override;
+ virtual void SendUseBed (const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ) override;
+ virtual void SendWeather (eWeather a_Weather) override;
+ virtual void SendWholeInventory (const cWindow & a_Window) override;
+ virtual void SendWindowClose (const cWindow & a_Window) override;
+ virtual void SendWindowOpen (const cWindow & a_Window) override;
+ virtual void SendWindowProperty (const cWindow & a_Window, int a_Property, int a_Value) override;
virtual AString GetAuthServerID(void) override;
diff --git a/src/Root.cpp b/src/Root.cpp
index f04cbf08b..966a9b4ba 100644
--- a/src/Root.cpp
+++ b/src/Root.cpp
@@ -18,6 +18,7 @@
#include "DeadlockDetect.h"
#include "OSSupport/Timer.h"
#include "LoggerListeners.h"
+#include "BuildInfo.h"
#include "inifile/iniFile.h"
@@ -111,6 +112,11 @@ void cRoot::Start(void)
LOG("--- Started Log ---\n");
+ #ifdef BUILD_ID
+ LOG("MCServer " BUILD_SERIES_NAME " build id: " BUILD_ID);
+ LOG("from commit id: " BUILD_COMMIT_ID " built at: " BUILD_DATETIME);
+ #endif
+
cDeadlockDetect dd;
m_bStop = false;
@@ -151,6 +157,7 @@ void cRoot::Start(void)
m_MojangAPI.Start(IniFile); // Mojang API needs to be started before plugins, so that plugins may use it for DB upgrades on server init
if (!m_Server->InitServer(IniFile))
{
+ IniFile.WriteFile("settings.ini");
LOGERROR("Failure starting server, aborting...");
return;
}
diff --git a/src/Server.cpp b/src/Server.cpp
index 069e2a169..969ffd693 100644
--- a/src/Server.cpp
+++ b/src/Server.cpp
@@ -259,6 +259,13 @@ bool cServer::InitServer(cIniFile & a_SettingsIni)
m_ServerID = sid.str();
m_ServerID.resize(16, '0');
}
+
+ // Check if both BungeeCord and online mode are on, if so, warn the admin:
+ m_ShouldAllowBungeeCord = a_SettingsIni.GetValueSetB("Authentication", "AllowBungeeCord", false);
+ if (m_ShouldAllowBungeeCord && m_ShouldAuthenticate)
+ {
+ LOGWARNING("WARNING: BungeeCord is allowed and server set to online mode. This is unsafe and will not work properly. Disable either authentication or BungeeCord in settings.ini.");
+ }
m_ShouldLoadOfflinePlayerData = a_SettingsIni.GetValueSetB("PlayerData", "LoadOfflinePlayerData", false);
m_ShouldLoadNamedPlayerData = a_SettingsIni.GetValueSetB("PlayerData", "LoadNamedPlayerData", true);
diff --git a/src/Server.h b/src/Server.h
index f20e6932f..6d659fa40 100644
--- a/src/Server.h
+++ b/src/Server.h
@@ -131,6 +131,11 @@ public: // tolua_export
Loaded from the settings.ini [PlayerData].LoadNamedPlayerData setting. */
bool ShouldLoadNamedPlayerData(void) const { return m_ShouldLoadNamedPlayerData; }
+ /** Returns true if BungeeCord logins (that specify the player's UUID) are allowed.
+ Read from settings, admins should set this to true only when they chain to BungeeCord,
+ it makes the server vulnerable to identity theft through direct connections. */
+ bool ShouldAllowBungeeCord(void) const { return m_ShouldAllowBungeeCord; }
+
private:
friend class cRoot; // so cRoot can create and destroy cServer
@@ -230,6 +235,9 @@ private:
This allows a seamless transition from name-based to UUID-based player storage.
Loaded from the settings.ini [PlayerData].LoadNamedPlayerData setting. */
bool m_ShouldLoadNamedPlayerData;
+
+ /** True if BungeeCord handshake packets (with player UUID) should be accepted. */
+ bool m_ShouldAllowBungeeCord;
cServer(void);
diff --git a/src/SetChunkData.cpp b/src/SetChunkData.cpp
index bfe59fbcb..707dfb9e8 100644
--- a/src/SetChunkData.cpp
+++ b/src/SetChunkData.cpp
@@ -44,7 +44,6 @@ cSetChunkData::cSetChunkData(
// Check the params' validity:
ASSERT(a_BlockTypes != NULL);
ASSERT(a_BlockMetas != NULL);
- ASSERT(a_Biomes != NULL);
// Copy block types and metas:
memcpy(m_BlockTypes, a_BlockTypes, sizeof(cChunkDef::BlockTypes));
diff --git a/src/StringCompression.cpp b/src/StringCompression.cpp
index 71d64e71e..af9f1687f 100644
--- a/src/StringCompression.cpp
+++ b/src/StringCompression.cpp
@@ -180,3 +180,65 @@ extern int UncompressStringGZIP(const char * a_Data, size_t a_Length, AString &
+
+extern int InflateString(const char * a_Data, size_t a_Length, AString & a_Uncompressed)
+{
+ a_Uncompressed.reserve(a_Length);
+
+ char Buffer[64 KiB];
+ z_stream strm;
+ memset(&strm, 0, sizeof(strm));
+ strm.next_in = (Bytef *)a_Data;
+ strm.avail_in = (uInt)a_Length;
+ strm.next_out = (Bytef *)Buffer;
+ strm.avail_out = sizeof(Buffer);
+
+ int res = inflateInit(&strm); // Force GZIP decoding
+ if (res != Z_OK)
+ {
+ LOG("%s: inflation initialization failed: %d (\"%s\").", __FUNCTION__, res, strm.msg);
+ return res;
+ }
+
+ for (;;)
+ {
+ res = inflate(&strm, Z_NO_FLUSH);
+ switch (res)
+ {
+ case Z_OK:
+ {
+ // Some data has been uncompressed. Consume the buffer and continue uncompressing
+ a_Uncompressed.append(Buffer, sizeof(Buffer) - strm.avail_out);
+ strm.next_out = (Bytef *)Buffer;
+ strm.avail_out = sizeof(Buffer);
+ if (strm.avail_in == 0)
+ {
+ // All data has been uncompressed
+ inflateEnd(&strm);
+ return Z_OK;
+ }
+ break;
+ }
+
+ case Z_STREAM_END:
+ {
+ // Finished uncompressing. Consume the rest of the buffer and return
+ a_Uncompressed.append(Buffer, sizeof(Buffer) - strm.avail_out);
+ inflateEnd(&strm);
+ return Z_OK;
+ }
+
+ default:
+ {
+ // An error has occurred, log it and return the error value
+ LOG("%s: inflation failed: %d (\"%s\").", __FUNCTION__, res, strm.msg);
+ inflateEnd(&strm);
+ return res;
+ }
+ } // switch (res)
+ } // while (true)
+}
+
+
+
+
diff --git a/src/StringCompression.h b/src/StringCompression.h
index 038240797..dde17ce30 100644
--- a/src/StringCompression.h
+++ b/src/StringCompression.h
@@ -21,5 +21,7 @@ extern int CompressStringGZIP(const char * a_Data, size_t a_Length, AString & a_
/// Uncompresses a_Data into a_Uncompressed using GZIP; returns Z_OK for success or Z_XXX error constants same as zlib
extern int UncompressStringGZIP(const char * a_Data, size_t a_Length, AString & a_Uncompressed);
+/** Uncompresses a_Data into a_Uncompressed using Inflate; returns Z_OK for success or Z_XXX error constants same as zlib */
+extern int InflateString(const char * a_Data, size_t a_Length, AString & a_Uncompressed);
diff --git a/src/StringUtils.cpp b/src/StringUtils.cpp
index 5f88cbf64..73147eebc 100644
--- a/src/StringUtils.cpp
+++ b/src/StringUtils.cpp
@@ -869,3 +869,31 @@ void SetBEInt(char * a_Mem, Int32 a_Value)
+
+bool SplitZeroTerminatedStrings(const AString & a_Strings, AStringVector & a_Output)
+{
+ a_Output.clear();
+ size_t size = a_Strings.size();
+ size_t start = 0;
+ bool res = false;
+ for (size_t i = 0; i < size; i++)
+ {
+ if (a_Strings[i] == 0)
+ {
+ a_Output.push_back(a_Strings.substr(start, i - start));
+ start = i + 1;
+ res = true;
+ }
+ }
+ if (start < size)
+ {
+ a_Output.push_back(a_Strings.substr(start, size - start));
+ res = true;
+ }
+
+ return res;
+}
+
+
+
+
diff --git a/src/StringUtils.h b/src/StringUtils.h
index 72a90a8c2..a76894d05 100644
--- a/src/StringUtils.h
+++ b/src/StringUtils.h
@@ -99,6 +99,11 @@ extern int GetBEInt(const char * a_Mem);
/// Writes four bytes to the specified memory location so that they interpret as BigEndian int
extern void SetBEInt(char * a_Mem, Int32 a_Value);
+/** Splits a string that has embedded \0 characters, on those characters.
+a_Output is first cleared and then each separate string is pushed back into a_Output.
+Returns true if there are at least two strings in a_Output (there was at least one \0 separator). */
+extern bool SplitZeroTerminatedStrings(const AString & a_Strings, AStringVector & a_Output);
+
/// Parses any integer type. Checks bounds and returns errors out of band.
template <class T>
bool StringToInteger(const AString & a_str, T & a_Num)
diff --git a/src/Tracer.cpp b/src/Tracer.cpp
index 756147a7b..e125c6aa4 100644
--- a/src/Tracer.cpp
+++ b/src/Tracer.cpp
@@ -250,7 +250,7 @@ int LinesCross(float x0, float y0, float x1, float y1, float x2, float y2, float
// float linx, liny;
float d=(x1-x0)*(y3-y2)-(y1-y0)*(x3-x2);
- if (abs(d)<0.001) {return 0;}
+ if (std::abs(d)<0.001) {return 0;}
float AB=((y0-y2)*(x3-x2)-(x0-x2)*(y3-y2))/d;
if (AB>=0.0 && AB<=1.0)
{
@@ -283,7 +283,7 @@ int cTracer::intersect3D_SegmentPlane( const Vector3f & a_Origin, const Vector3f
if (fabs(D) < EPSILON)
{
// segment is parallel to plane
- if (N == 0)
+ if (N == 0.0)
{
// segment lies in plane
return 2;
diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp
index 4199bbf56..b4facb2d3 100644
--- a/src/UI/SlotArea.cpp
+++ b/src/UI/SlotArea.cpp
@@ -207,7 +207,7 @@ void cSlotArea::ShiftClicked(cPlayer & a_Player, int a_SlotNum, const cItem & a_
m_ParentWindow.DistributeStack(Slot, a_Player, this, true);
if (Slot.IsEmpty())
{
- // Empty the slot completely, the cilent doesn't like left-over ItemType with zero count
+ // Empty the slot completely, the client doesn't like left-over ItemType with zero count
Slot.Empty();
}
SetSlot(a_SlotNum, a_Player, Slot);
@@ -1389,8 +1389,11 @@ void cSlotAreaBeacon::OnSlotChanged(cItemGrid * a_ItemGrid, int a_SlotNum)
////////////////////////////////////////////////////////////////////////////////
// cSlotAreaEnchanting:
-cSlotAreaEnchanting::cSlotAreaEnchanting(cEnchantingWindow & a_ParentWindow) :
- cSlotAreaTemporary(1, a_ParentWindow)
+cSlotAreaEnchanting::cSlotAreaEnchanting(cEnchantingWindow & a_ParentWindow, int a_BlockX, int a_BlockY, int a_BlockZ) :
+ cSlotAreaTemporary(1, a_ParentWindow),
+ m_BlockX(a_BlockX),
+ m_BlockY(a_BlockY),
+ m_BlockZ(a_BlockZ)
{
a_ParentWindow.m_SlotArea = this;
}
@@ -1409,7 +1412,7 @@ void cSlotAreaEnchanting::Clicked(cPlayer & a_Player, int a_SlotNum, eClickActio
LOGWARNING("GetSlot(%d) returned NULL! Ignoring click", a_SlotNum);
return;
}
-
+
switch (a_ClickAction)
{
case caShiftLeftClick:
@@ -1428,6 +1431,25 @@ void cSlotAreaEnchanting::Clicked(cPlayer & a_Player, int a_SlotNum, eClickActio
MiddleClicked(a_Player, a_SlotNum);
return;
}
+ case caDropKey:
+ case caCtrlDropKey:
+ {
+ DropClicked(a_Player, a_SlotNum, false);
+ return;
+ }
+ case caNumber1:
+ case caNumber2:
+ case caNumber3:
+ case caNumber4:
+ case caNumber5:
+ case caNumber6:
+ case caNumber7:
+ case caNumber8:
+ case caNumber9:
+ {
+ NumberClicked(a_Player, a_SlotNum, a_ClickAction);
+ return;
+ }
default:
{
break;
@@ -1443,106 +1465,36 @@ void cSlotAreaEnchanting::Clicked(cPlayer & a_Player, int a_SlotNum, eClickActio
bAsync = true;
}
cItem & DraggingItem = a_Player.GetDraggingItem();
- switch (a_ClickAction)
+
+ if (DraggingItem.IsEmpty())
{
- case caRightClick:
+ // DraggingItem is empty -> Switch draggingitem and slot
+ if (!Slot.IsEmpty())
{
- // Right-clicked
- if (DraggingItem.IsEmpty())
- {
- DraggingItem = Slot.CopyOne();
- Slot.Empty();
- break;
- }
-
- if (Slot.IsEmpty())
- {
- Slot = DraggingItem.CopyOne();
- DraggingItem.m_ItemCount -= 1;
- if (DraggingItem.m_ItemCount <= 0)
- {
- DraggingItem.Empty();
- }
- }
- else if ((!DraggingItem.IsEqual(Slot)) && (DraggingItem.m_ItemCount == 1))
- {
- // Swap contents
- cItem tmp(DraggingItem);
- DraggingItem = Slot;
- Slot = tmp;
- }
- break;
+ std::swap(DraggingItem, Slot);
}
-
- case caLeftClick:
- {
- // Left-clicked
- if (DraggingItem.IsEmpty())
- {
- DraggingItem = Slot.CopyOne();
- Slot.Empty();
- break;
- }
-
- if (DraggingItem.IsEqual(Slot))
- {
- // Do nothing
- break;
- }
-
- if (!Slot.IsEmpty())
- {
- if (DraggingItem.m_ItemCount == 1)
- {
- // Swap contents
- cItem tmp(DraggingItem);
- DraggingItem = Slot;
- Slot = tmp;
- }
- }
- else
- {
- Slot = DraggingItem.CopyOne();
- DraggingItem.m_ItemCount -= 1;
- if (DraggingItem.m_ItemCount <= 0)
- {
- DraggingItem.Empty();
- }
- }
- break;
- }
- default:
+ }
+ else if (Slot.IsEmpty())
+ {
+ // DraggingItem isn't empty and slot is empty -> Set one dragging item in the slot
+ Slot = DraggingItem.CopyOne();
+ DraggingItem.m_ItemCount -= 1;
+
+ if (DraggingItem.m_ItemCount <= 0)
{
- LOGWARNING("SlotArea: Unhandled click action: %d (%s)", a_ClickAction, ClickActionToString(a_ClickAction));
- m_ParentWindow.BroadcastWholeWindow();
- return;
+ DraggingItem.Empty();
}
- } // switch (a_ClickAction
-
- SetSlot(a_SlotNum, a_Player, Slot);
- if (bAsync)
- {
- m_ParentWindow.BroadcastWholeWindow();
}
- UpdateResult(a_Player);
-}
-
-
-
-
-
-void cSlotAreaEnchanting::DblClicked(cPlayer & a_Player, int a_SlotNum)
-{
- cItem & Dragging = a_Player.GetDraggingItem();
- if ((!Dragging.IsEmpty()) || (a_SlotNum != 0))
+ else if ((DraggingItem.m_ItemCount == 1) && !DraggingItem.IsEqual(Slot))
{
- return;
+ // DraggingItem and slot aren't empty -> Switch items
+ std::swap(DraggingItem, Slot);
}
-
- cItem Item = *GetSlot(0, a_Player);
- if (!m_ParentWindow.CollectItemsToHand(Item, *this, a_Player, false))
+
+ SetSlot(a_SlotNum, a_Player, Slot);
+ if (bAsync)
{
- m_ParentWindow.CollectItemsToHand(Item, *this, a_Player, true);
+ m_ParentWindow.BroadcastWholeWindow();
}
}
@@ -1567,7 +1519,15 @@ void cSlotAreaEnchanting::DistributeStack(cItem & a_ItemStack, cPlayer & a_Playe
{
a_ItemStack.Empty();
}
+}
+
+
+
+
+void cSlotAreaEnchanting::OnPlayerAdded(cPlayer & a_Player)
+{
+ super::OnPlayerAdded(a_Player);
UpdateResult(a_Player);
}
@@ -1587,29 +1547,33 @@ void cSlotAreaEnchanting::OnPlayerRemoved(cPlayer & a_Player)
+void cSlotAreaEnchanting::SetSlot(int a_SlotNum, cPlayer & a_Player, const cItem & a_Item)
+{
+ super::SetSlot(a_SlotNum, a_Player, a_Item);
+ UpdateResult(a_Player);
+}
+
+
+
+
+
void cSlotAreaEnchanting::UpdateResult(cPlayer & a_Player)
{
cItem Item = *GetSlot(0, a_Player);
- if (Item.IsEmpty() || !Item.m_Enchantments.IsEmpty())
- {
- m_ParentWindow.SetProperty(0, 0, a_Player);
- m_ParentWindow.SetProperty(1, 0, a_Player);
- m_ParentWindow.SetProperty(2, 0, a_Player);
- }
- else if (cItem::IsEnchantable(Item.m_ItemType) || Item.m_ItemType == E_ITEM_BOOK)
+ if (cItem::IsEnchantable(Item.m_ItemType) && Item.m_Enchantments.IsEmpty())
{
int Bookshelves = std::min(GetBookshelvesCount(a_Player.GetWorld()), 15);
cFastRandom Random;
- int base = (Random.GenerateRandomInteger(1, 8) + (int)floor((float)Bookshelves / 2) + Random.GenerateRandomInteger(0, Bookshelves));
- int topSlot = std::max(base / 3, 1);
- int middleSlot = (base * 2) / 3 + 1;
- int bottomSlot = std::max(base, Bookshelves * 2);
+ int Base = (Random.GenerateRandomInteger(1, 8) + (int)floor((float)Bookshelves / 2) + Random.GenerateRandomInteger(0, Bookshelves));
+ int TopSlot = std::max(Base / 3, 1);
+ int MiddleSlot = (Base * 2) / 3 + 1;
+ int BottomSlot = std::max(Base, Bookshelves * 2);
- m_ParentWindow.SetProperty(0, topSlot, a_Player);
- m_ParentWindow.SetProperty(1, middleSlot, a_Player);
- m_ParentWindow.SetProperty(2, bottomSlot, a_Player);
+ m_ParentWindow.SetProperty(0, TopSlot, a_Player);
+ m_ParentWindow.SetProperty(1, MiddleSlot, a_Player);
+ m_ParentWindow.SetProperty(2, BottomSlot, a_Player);
}
else
{
@@ -1625,12 +1589,9 @@ void cSlotAreaEnchanting::UpdateResult(cPlayer & a_Player)
int cSlotAreaEnchanting::GetBookshelvesCount(cWorld * a_World)
{
- int PosX, PosY, PosZ;
- ((cEnchantingWindow*)&m_ParentWindow)->GetBlockPos(PosX, PosY, PosZ);
-
int Bookshelves = 0;
cBlockArea Area;
- Area.Read(a_World, PosX - 2, PosX + 2, PosY, PosY + 1, PosZ - 2, PosZ + 2);
+ Area.Read(a_World, m_BlockX - 2, m_BlockX + 2, m_BlockY, m_BlockY + 1, m_BlockZ - 2, m_BlockZ + 2);
static const struct
{
@@ -1678,7 +1639,7 @@ int cSlotAreaEnchanting::GetBookshelvesCount(cWorld * a_World)
if (
(Area.GetRelBlockType(CheckCoords[i].m_AirX, CheckCoords[i].m_AirY, CheckCoords[i].m_AirZ) == E_BLOCK_AIR) && // There's air in the checkspot
(Area.GetRelBlockType(CheckCoords[i].m_BookX, CheckCoords[i].m_BookY, CheckCoords[i].m_BookZ) == E_BLOCK_BOOKCASE) // There's bookcase in the wanted place
- )
+ )
{
Bookshelves++;
}
diff --git a/src/UI/SlotArea.h b/src/UI/SlotArea.h
index 9a96f2f3c..6bbc87b76 100644
--- a/src/UI/SlotArea.h
+++ b/src/UI/SlotArea.h
@@ -349,14 +349,15 @@ class cSlotAreaEnchanting :
typedef cSlotAreaTemporary super;
public:
- cSlotAreaEnchanting(cEnchantingWindow & a_ParentWindow);
+ cSlotAreaEnchanting(cEnchantingWindow & a_ParentWindow, int a_BlockX, int a_BlockY, int a_BlockZ);
// cSlotArea overrides:
virtual void Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) override;
- virtual void DblClicked(cPlayer & a_Player, int a_SlotNum) override;
virtual void DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_ShouldApply, bool a_KeepEmptySlots) override;
+ virtual void SetSlot(int a_SlotNum, cPlayer & a_Player, const cItem & a_Item) override;
// cSlotAreaTemporary overrides:
+ virtual void OnPlayerAdded (cPlayer & a_Player) override;
virtual void OnPlayerRemoved(cPlayer & a_Player) override;
/* Get the count of bookshelves who stand in the near of the enchanting table */
@@ -365,6 +366,8 @@ public:
protected:
/** Handles a click in the item slot. */
void UpdateResult(cPlayer & a_Player);
+
+ int m_BlockX, m_BlockY, m_BlockZ;
};
diff --git a/src/UI/Window.cpp b/src/UI/Window.cpp
index 8f4913030..1b7b07f77 100644
--- a/src/UI/Window.cpp
+++ b/src/UI/Window.cpp
@@ -57,6 +57,34 @@ cWindow::~cWindow()
+const AString cWindow::GetWindowTypeName(void) const
+{
+ switch (m_WindowType)
+ {
+ case wtChest: return "minecraft:chest";
+ case wtWorkbench: return "minecraft:crafting_table";
+ case wtFurnace: return "minecraft:furnace";
+ case wtDropSpenser: return "minecraft:dispenser";
+ case wtEnchantment: return "minecraft:enchanting_table";
+ case wtBrewery: return "minecraft:brewing_stand";
+ case wtNPCTrade: return "minecraft:villager";
+ case wtBeacon: return "minecraft:beacon";
+ case wtAnvil: return "minecraft:anvil";
+ case wtHopper: return "minecraft:hopper";
+ case wtDropper: return "minecraft:dropper";
+ case wtAnimalChest: return "EntityHorse";
+ default:
+ {
+ ASSERT(!"Unknown inventory type!");
+ return "";
+ }
+ }
+}
+
+
+
+
+
int cWindow::GetNumSlots(void) const
{
int res = 0;
@@ -881,7 +909,7 @@ cEnchantingWindow::cEnchantingWindow(int a_BlockX, int a_BlockY, int a_BlockZ) :
m_BlockY(a_BlockY),
m_BlockZ(a_BlockZ)
{
- m_SlotAreas.push_back(new cSlotAreaEnchanting(*this));
+ m_SlotAreas.push_back(new cSlotAreaEnchanting(*this, m_BlockX, m_BlockY, m_BlockZ));
m_SlotAreas.push_back(new cSlotAreaInventory(*this));
m_SlotAreas.push_back(new cSlotAreaHotBar(*this));
}
@@ -892,8 +920,13 @@ cEnchantingWindow::cEnchantingWindow(int a_BlockX, int a_BlockY, int a_BlockZ) :
void cEnchantingWindow::SetProperty(int a_Property, int a_Value)
{
- m_PropertyValue[a_Property] = a_Value;
+ if ((a_Property < 0) || ((size_t)a_Property >= ARRAYCOUNT(m_PropertyValue)))
+ {
+ ASSERT(!"a_Property is invalid");
+ return;
+ }
+ m_PropertyValue[a_Property] = a_Value;
super::SetProperty(a_Property, a_Value);
}
@@ -903,8 +936,13 @@ void cEnchantingWindow::SetProperty(int a_Property, int a_Value)
void cEnchantingWindow::SetProperty(int a_Property, int a_Value, cPlayer & a_Player)
{
- m_PropertyValue[a_Property] = a_Value;
+ if ((a_Property < 0) || ((size_t)a_Property >= ARRAYCOUNT(m_PropertyValue)))
+ {
+ ASSERT(!"a_Property is invalid");
+ return;
+ }
+ m_PropertyValue[a_Property] = a_Value;
super::SetProperty(a_Property, a_Value, a_Player);
}
@@ -914,18 +952,13 @@ void cEnchantingWindow::SetProperty(int a_Property, int a_Value, cPlayer & a_Pla
int cEnchantingWindow::GetPropertyValue(int a_Property)
{
- return m_PropertyValue[a_Property];
-}
-
-
-
-
+ if ((a_Property < 0) || ((size_t)a_Property >= ARRAYCOUNT(m_PropertyValue)))
+ {
+ ASSERT(!"a_Property is invalid");
+ return 0;
+ }
-void cEnchantingWindow::GetBlockPos(int & a_PosX, int & a_PosY, int & a_PosZ)
-{
- a_PosX = m_BlockX;
- a_PosY = m_BlockY;
- a_PosZ = m_BlockZ;
+ return m_PropertyValue[a_Property];
}
diff --git a/src/UI/Window.h b/src/UI/Window.h
index 9fb0e3b38..bc5becf11 100644
--- a/src/UI/Window.h
+++ b/src/UI/Window.h
@@ -63,7 +63,7 @@ public:
wtBeacon = 7,
wtAnvil = 8,
wtHopper = 9,
- // Unknown: 10
+ wtDropper = 10,
wtAnimalChest = 11,
};
@@ -76,6 +76,7 @@ public:
char GetWindowID(void) const { return m_WindowID; } // tolua_export
int GetWindowType(void) const { return m_WindowType; } // tolua_export
+ const AString GetWindowTypeName(void) const; // tolua_export
cWindowOwner * GetOwner(void) { return m_Owner; }
void SetOwner( cWindowOwner * a_Owner) { m_Owner = a_Owner; }
@@ -291,9 +292,6 @@ public:
/** Return the Value of a Property */
int GetPropertyValue(int a_Property);
- /** Get the Position from the Enchantment Table */
- void GetBlockPos(int & a_PosX, int & a_PosY, int & a_PosZ);
-
cSlotArea * m_SlotArea;
protected:
diff --git a/src/VoronoiMap.cpp b/src/VoronoiMap.cpp
index 5efd09c01..5ad634fe4 100644
--- a/src/VoronoiMap.cpp
+++ b/src/VoronoiMap.cpp
@@ -10,11 +10,13 @@
-cVoronoiMap::cVoronoiMap(int a_Seed, int a_CellSize) :
+cVoronoiMap::cVoronoiMap(int a_Seed, int a_CellSize, int a_JitterSize) :
m_Noise1(a_Seed + 1),
m_Noise2(a_Seed + 2),
m_Noise3(a_Seed + 3),
- m_CellSize(a_CellSize),
+ m_CellSize(std::max(a_CellSize, 2)),
+ m_JitterSize(Clamp(a_JitterSize, 1, a_CellSize)),
+ m_OddRowOffset(0),
m_CurrentCellX(9999999), // Cell coords that are definitely out of the range for normal generator, so that the first query will overwrite them
m_CurrentCellZ(9999999)
{
@@ -26,7 +28,29 @@ cVoronoiMap::cVoronoiMap(int a_Seed, int a_CellSize) :
void cVoronoiMap::SetCellSize(int a_CellSize)
{
+ a_CellSize = std::max(a_CellSize, 2); // Cell size must be at least 2
m_CellSize = a_CellSize;
+
+ // For compatibility with previous version, which didn't have the jitter, we set jitter here as well.
+ m_JitterSize = a_CellSize;
+}
+
+
+
+
+
+void cVoronoiMap::SetJitterSize(int a_JitterSize)
+{
+ m_JitterSize = Clamp(a_JitterSize, 1, m_CellSize);
+}
+
+
+
+
+
+void cVoronoiMap::SetOddRowOffset(int a_OddRowOffset)
+{
+ m_OddRowOffset = Clamp(a_OddRowOffset, -m_CellSize, m_CellSize);
}
@@ -35,8 +59,8 @@ void cVoronoiMap::SetCellSize(int a_CellSize)
int cVoronoiMap::GetValueAt(int a_X, int a_Y)
{
- int MinDist1, MinDist2;
- return GetValueAt(a_X, a_Y, MinDist1, MinDist2);
+ int SeedX, SeedY, MinDist2;
+ return GetValueAt(a_X, a_Y, SeedX, SeedY, MinDist2);
}
@@ -45,41 +69,47 @@ int cVoronoiMap::GetValueAt(int a_X, int a_Y)
int cVoronoiMap::GetValueAt(int a_X, int a_Y, int & a_MinDist)
{
- int MinDist2;
- return GetValueAt(a_X, a_Y, a_MinDist, MinDist2);
+ int SeedX, SeedY, MinDist2;
+ int res = GetValueAt(a_X, a_Y, SeedX, SeedY, MinDist2);
+ a_MinDist = (a_X - SeedX) * (a_X - SeedX) + (a_Y - SeedY) * (a_Y - SeedY);
+ return res;
}
-int cVoronoiMap::GetValueAt(int a_X, int a_Y, int & a_MinDist1, int & a_MinDist2)
+int cVoronoiMap::GetValueAt(
+ int a_X, int a_Y, // Coords to query
+ int & a_NearestSeedX, int & a_NearestSeedY, // Coords of the closest cell
+ int & a_MinDist2 // Distance to the second closest cell
+)
{
- // Note that due to historical reasons, the algorithm uses XZ coords, while the input uses XY coords.
- // This is because the algorithm was first implemented directly in the biome generators which use MC coords.
-
int CellX = a_X / m_CellSize;
- int CellZ = a_Y / m_CellSize;
+ int CellY = a_Y / m_CellSize;
- UpdateCell(CellX, CellZ);
+ UpdateCell(CellX, CellY);
// Get 5x5 neighboring cell seeds, compare distance to each. Return the value in the minumim-distance cell
+ int NearestSeedX = 0, NearestSeedY = 0;
int MinDist = m_CellSize * m_CellSize * 16; // There has to be a cell closer than this
int MinDist2 = MinDist;
int res = 0; // Will be overriden
for (int x = 0; x < 5; x++)
{
- for (int z = 0; z < 5; z++)
+ for (int y = 0; y < 5; y++)
{
- int SeedX = m_SeedX[x][z];
- int SeedZ = m_SeedZ[x][z];
+ int SeedX = m_SeedX[x][y];
+ int SeedY = m_SeedZ[x][y];
- int Dist = (SeedX - a_X) * (SeedX - a_X) + (SeedZ - a_Y) * (SeedZ - a_Y);
+ int Dist = (SeedX - a_X) * (SeedX - a_X) + (SeedY - a_Y) * (SeedY - a_Y);
if (Dist < MinDist)
{
+ NearestSeedX = SeedX;
+ NearestSeedY = SeedY;
MinDist2 = MinDist;
MinDist = Dist;
- res = m_Noise3.IntNoise2DInt(x + CellX - 2, z + CellZ - 2);
+ res = m_Noise3.IntNoise2DInt(x + CellX - 2, y + CellY - 2);
}
else if (Dist < MinDist2)
{
@@ -88,7 +118,8 @@ int cVoronoiMap::GetValueAt(int a_X, int a_Y, int & a_MinDist1, int & a_MinDist2
} // for z
} // for x
- a_MinDist1 = MinDist;
+ a_NearestSeedX = NearestSeedX;
+ a_NearestSeedY = NearestSeedY;
a_MinDist2 = MinDist2;
return res;
}
@@ -97,6 +128,58 @@ int cVoronoiMap::GetValueAt(int a_X, int a_Y, int & a_MinDist1, int & a_MinDist2
+void cVoronoiMap::FindNearestSeeds(
+ int a_X, int a_Y,
+ int & a_NearestSeedX, int & a_NearestSeedY,
+ int & a_SecondNearestSeedX, int & a_SecondNearestSeedY
+)
+{
+ int CellX = a_X / m_CellSize;
+ int CellY = a_Y / m_CellSize;
+
+ UpdateCell(CellX, CellY);
+
+ // Get 5x5 neighboring cell seeds, compare distance to each. Return the value in the minumim-distance cell
+ int NearestSeedX = 0, NearestSeedY = 0;
+ int SecondNearestSeedX = 0, SecondNearestSeedY = 0;
+ int MinDist = m_CellSize * m_CellSize * 16; // There has to be a cell closer than this
+ int MinDist2 = MinDist;
+ for (int x = 0; x < 5; x++)
+ {
+ for (int y = 0; y < 5; y++)
+ {
+ int SeedX = m_SeedX[x][y];
+ int SeedY = m_SeedZ[x][y];
+
+ int Dist = (SeedX - a_X) * (SeedX - a_X) + (SeedY - a_Y) * (SeedY - a_Y);
+ if (Dist < MinDist)
+ {
+ SecondNearestSeedX = NearestSeedX;
+ SecondNearestSeedY = NearestSeedY;
+ MinDist2 = MinDist;
+ NearestSeedX = SeedX;
+ NearestSeedY = SeedY;
+ MinDist = Dist;
+ }
+ else if (Dist < MinDist2)
+ {
+ SecondNearestSeedX = SeedX;
+ SecondNearestSeedY = SeedY;
+ MinDist2 = Dist;
+ }
+ } // for z
+ } // for x
+
+ a_NearestSeedX = NearestSeedX;
+ a_NearestSeedY = NearestSeedY;
+ a_SecondNearestSeedX = SecondNearestSeedX;
+ a_SecondNearestSeedY = SecondNearestSeedY;
+}
+
+
+
+
+
void cVoronoiMap::UpdateCell(int a_CellX, int a_CellZ)
{
// If the specified cell is currently cached, bail out:
@@ -111,12 +194,13 @@ void cVoronoiMap::UpdateCell(int a_CellX, int a_CellZ)
for (int x = 0; x < 5; x++)
{
int BaseX = (NoiseBaseX + x) * m_CellSize;
+ int OddRowOffset = ((NoiseBaseX + x) & 0x01) * m_OddRowOffset;
for (int z = 0; z < 5; z++)
{
- int OffsetX = (m_Noise1.IntNoise2DInt(NoiseBaseX + x, NoiseBaseZ + z) / 8) % m_CellSize;
- int OffsetZ = (m_Noise2.IntNoise2DInt(NoiseBaseX + x, NoiseBaseZ + z) / 8) % m_CellSize;
+ int OffsetX = (m_Noise1.IntNoise2DInt(NoiseBaseX + x, NoiseBaseZ + z) / 8) % m_JitterSize;
+ int OffsetZ = (m_Noise2.IntNoise2DInt(NoiseBaseX + x, NoiseBaseZ + z) / 8) % m_JitterSize;
m_SeedX[x][z] = BaseX + OffsetX;
- m_SeedZ[x][z] = (NoiseBaseZ + z) * m_CellSize + OffsetZ;
+ m_SeedZ[x][z] = (NoiseBaseZ + z) * m_CellSize + OddRowOffset + OffsetZ;
} // for z
} // for x
m_CurrentCellX = a_CellX;
diff --git a/src/VoronoiMap.h b/src/VoronoiMap.h
index 84cf206e9..dfb11e9ce 100644
--- a/src/VoronoiMap.h
+++ b/src/VoronoiMap.h
@@ -18,19 +18,40 @@
class cVoronoiMap
{
public:
- cVoronoiMap(int a_Seed, int a_CellSize = 128);
+ cVoronoiMap(int a_Seed, int a_CellSize = 128, int a_JitterSize = 128);
- /// Sets the cell size used for generating the Voronoi seeds
+ /** Sets both the cell size and jitter size used for generating the Voronoi seeds. */
void SetCellSize(int a_CellSize);
+
+ /** Sets the jitter size. Clamps it to current cell size. */
+ void SetJitterSize(int a_JitterSize);
+
+ /** Sets the offset that is added to each odd row of cells.
+ This offset makes the voronoi cells align to a non-grid.
+ Clamps the value to [-m_CellSize, +m_CellSize]. */
+ void SetOddRowOffset(int a_OddRowOffset);
- /// Returns the value in the cell into which the specified point lies
+ /** Returns the value in the cell into which the specified point lies. */
int GetValueAt(int a_X, int a_Y);
- /// Returns the value in the cell into which the specified point lies, and the distance to the nearest Voronoi seed
+ /** Returns the value in the cell into which the specified point lies,
+ and the distance to the nearest Voronoi seed. */
int GetValueAt(int a_X, int a_Y, int & a_MinDistance);
- /// Returns the value in the cell into which the specified point lies, and the distances to the 2 nearest Voronoi seeds. Uses a cache
- int GetValueAt(int a_X, int a_Y, int & a_MinDistance1, int & a_MinDistance2);
+ /** Returns the value in the cell into which the specified point lies,
+ and the distances to the 2 nearest Voronoi seeds. Uses a cache. */
+ int GetValueAt(
+ int a_X, int a_Y, // Coords to query
+ int & a_NearestSeedX, int & a_NearestSeedY, // Coords of the closest cell's seed
+ int & a_MinDist2 // Distance to the second closest cell's seed
+ );
+
+ /** Finds the nearest and second nearest seeds, returns their coords. */
+ void FindNearestSeeds(
+ int a_X, int a_Y,
+ int & a_NearestSeedX, int & a_NearestSeedY,
+ int & a_SecondNearestSeedX, int & a_SecondNearestSeedY
+ );
protected:
/// The noise used for generating Voronoi seeds
@@ -38,8 +59,17 @@ protected:
cNoise m_Noise2;
cNoise m_Noise3;
- /// Size of the Voronoi cells (avg X/Y distance between the seeds)
+ /** Size of the Voronoi cells (avg X/Y distance between the seeds). Expected to be at least 2. */
int m_CellSize;
+
+ /** The amount that the cell seeds may be offset from the grid.
+ Expected to be at least 1 and less than m_CellSize. */
+ int m_JitterSize;
+
+ /** The constant amount that the cell seeds of every odd row will be offset from the grid.
+ This allows us to have non-rectangular grids.
+ Expected to be between -m_CellSize and +m_CellSize. */
+ int m_OddRowOffset;
/** The X coordinate of the currently cached cell neighborhood */
int m_CurrentCellX;
diff --git a/src/WebAdmin.cpp b/src/WebAdmin.cpp
index 23eedbd14..db2ace386 100644
--- a/src/WebAdmin.cpp
+++ b/src/WebAdmin.cpp
@@ -43,6 +43,8 @@ public:
cWebAdmin::cWebAdmin(void) :
m_IsInitialized(false),
m_IsRunning(false),
+ m_PortsIPv4("8080"),
+ m_PortsIPv6(""),
m_TemplateScript("<webadmin_template>")
{
}
@@ -89,6 +91,8 @@ bool cWebAdmin::Init(void)
m_IniFile.AddHeaderComment(" Password format: Password=*password*; for example:");
m_IniFile.AddHeaderComment(" [User:admin]");
m_IniFile.AddHeaderComment(" Password=admin");
+ m_IniFile.SetValue("WebAdmin", "Port", m_PortsIPv4);
+ m_IniFile.SetValue("WebAdmin", "PortsIPv6", m_PortsIPv6);
m_IniFile.WriteFile("webadmin.ini");
}
@@ -100,8 +104,8 @@ bool cWebAdmin::Init(void)
LOGD("Initialising WebAdmin...");
- m_PortsIPv4 = m_IniFile.GetValueSet("WebAdmin", "Port", "8080");
- m_PortsIPv6 = m_IniFile.GetValueSet("WebAdmin", "PortsIPv6", "");
+ m_PortsIPv4 = m_IniFile.GetValueSet("WebAdmin", "Port", m_PortsIPv4);
+ m_PortsIPv6 = m_IniFile.GetValueSet("WebAdmin", "PortsIPv6", m_PortsIPv6);
if (!m_HTTPServer.Initialize(m_PortsIPv4, m_PortsIPv6))
{
@@ -131,8 +135,24 @@ bool cWebAdmin::Start(void)
m_TemplateScript.RegisterAPILibs();
if (!m_TemplateScript.LoadFile(FILE_IO_PREFIX "webadmin/template.lua"))
{
- LOGWARN("Could not load WebAdmin template \"%s\", using default template.", FILE_IO_PREFIX "webadmin/template.lua");
+ LOGWARN("Could not load WebAdmin template \"%s\". WebAdmin disabled!", FILE_IO_PREFIX "webadmin/template.lua");
m_TemplateScript.Close();
+ m_HTTPServer.Stop();
+ return false;
+ }
+
+ if (!LoadLoginTemplate())
+ {
+ LOGWARN("Could not load WebAdmin login template \"%s\", using fallback template.", FILE_IO_PREFIX "webadmin/login_template.html");
+
+ // Sets the fallback template:
+ m_LoginTemplate = \
+ "<h1>MCServer WebAdmin</h1>" \
+ "<center>" \
+ "<form method='get' action='webadmin/'>" \
+ "<input type='submit' value='Log in'>" \
+ "</form>" \
+ "</center>";
}
m_IsRunning = m_HTTPServer.Start(*this);
@@ -159,6 +179,28 @@ void cWebAdmin::Stop(void)
+bool cWebAdmin::LoadLoginTemplate(void)
+{
+ cFile File(FILE_IO_PREFIX "webadmin/login_template.html", cFile::fmRead);
+ if (!File.IsOpen())
+ {
+ return false;
+ }
+
+ AString TemplateContent;
+ if (File.ReadRestOfFile(TemplateContent) == -1)
+ {
+ return false;
+ }
+
+ m_LoginTemplate = TemplateContent;
+ return true;
+}
+
+
+
+
+
void cWebAdmin::HandleWebadminRequest(cHTTPConnection & a_Connection, cHTTPRequest & a_Request)
{
if (!a_Request.HasAuth())
@@ -298,17 +340,64 @@ void cWebAdmin::HandleWebadminRequest(cHTTPConnection & a_Connection, cHTTPReque
void cWebAdmin::HandleRootRequest(cHTTPConnection & a_Connection, cHTTPRequest & a_Request)
{
UNUSED(a_Request);
- static const char LoginForm[] = \
- "<h1>MCServer WebAdmin</h1>" \
- "<center>" \
- "<form method='get' action='webadmin/'>" \
- "<input type='submit' value='Log in'>" \
- "</form>" \
- "</center>";
+
cHTTPResponse Resp;
Resp.SetContentType("text/html");
a_Connection.Send(Resp);
- a_Connection.Send(LoginForm, sizeof(LoginForm) - 1);
+ a_Connection.Send(m_LoginTemplate);
+ a_Connection.FinishResponse();
+}
+
+
+
+
+
+void cWebAdmin::HandleFileRequest(cHTTPConnection & a_Connection, cHTTPRequest & a_Request)
+{
+ AString FileURL = a_Request.GetURL();
+ std::replace(FileURL.begin(), FileURL.end(), '\\', '/');
+
+ // Remove all leading backslashes:
+ if (FileURL[0] == '/')
+ {
+ size_t FirstCharToRead = FileURL.find_first_not_of('/');
+ if (FirstCharToRead != AString::npos)
+ {
+ FileURL = FileURL.substr(FirstCharToRead);
+ }
+ }
+
+ // Remove all "../" strings:
+ ReplaceString(FileURL, "../", "");
+
+ bool LoadedSuccessfull = false;
+ AString Content = "<h2>404 Not Found</h2>";
+ AString Path = Printf(FILE_IO_PREFIX "webadmin/files/%s", FileURL.c_str());
+ if (cFile::IsFile(Path))
+ {
+ cFile File(Path, cFile::fmRead);
+ AString FileContent;
+ if (File.IsOpen() && (File.ReadRestOfFile(FileContent) != -1))
+ {
+ LoadedSuccessfull = true;
+ Content = FileContent;
+ }
+ }
+
+ // Find content type (The currently method is very bad. We should change it later)
+ AString ContentType = "text/html";
+ size_t LastPointPosition = Path.find_last_of('.');
+ if (LoadedSuccessfull && (LastPointPosition != AString::npos) && (LastPointPosition < Path.length()))
+ {
+ AString FileExtension = Path.substr(LastPointPosition + 1);
+ ContentType = GetContentTypeFromFileExt(FileExtension);
+ }
+
+ // Send the response:
+ cHTTPResponse Resp;
+ Resp.SetContentType(ContentType);
+ a_Connection.Send(Resp);
+ a_Connection.Send(Content);
a_Connection.FinishResponse();
}
@@ -316,6 +405,41 @@ void cWebAdmin::HandleRootRequest(cHTTPConnection & a_Connection, cHTTPRequest &
+AString cWebAdmin::GetContentTypeFromFileExt(const AString & a_FileExtension)
+{
+ static bool IsInitialized = false;
+ static std::map<AString, AString> ContentTypeMap;
+ if (!IsInitialized)
+ {
+ // Initialize the ContentTypeMap:
+ ContentTypeMap["png"] = "image/png";
+ ContentTypeMap["fif"] = "image/fif";
+ ContentTypeMap["gif"] = "image/gif";
+ ContentTypeMap["jpeg"] = "image/jpeg";
+ ContentTypeMap["jpg"] = "image/jpeg";
+ ContentTypeMap["jpe"] = "image/jpeg";
+ ContentTypeMap["tiff"] = "image/tiff";
+ ContentTypeMap["ico"] = "image/ico";
+ ContentTypeMap["csv"] = "image/comma-separated-values";
+ ContentTypeMap["css"] = "text/css";
+ ContentTypeMap["js"] = "text/javascript";
+ ContentTypeMap["txt"] = "text/plain";
+ ContentTypeMap["rtx"] = "text/richtext";
+ ContentTypeMap["xml"] = "text/xml";
+ }
+
+ AString FileExtension = StrToLower(a_FileExtension);
+ if (ContentTypeMap.find(a_FileExtension) == ContentTypeMap.end())
+ {
+ return "text/html";
+ }
+ return ContentTypeMap[FileExtension];
+}
+
+
+
+
+
sWebAdminPage cWebAdmin::GetPage(const HTTPRequest & a_Request)
{
sWebAdminPage Page;
@@ -382,6 +506,7 @@ AString cWebAdmin::GetDefaultPage(void)
+
AString cWebAdmin::GetBaseURL( const AString& a_URL)
{
return GetBaseURL(StringSplit(a_URL, "/"));
@@ -528,7 +653,7 @@ void cWebAdmin::OnRequestFinished(cHTTPConnection & a_Connection, cHTTPRequest &
}
else
{
- // TODO: Handle other requests
+ HandleFileRequest(a_Connection, a_Request);
}
// Delete any request data assigned to the request:
@@ -551,4 +676,3 @@ void cWebAdmin::cWebadminRequestData::OnBody(const char * a_Data, size_t a_Size)
-
diff --git a/src/WebAdmin.h b/src/WebAdmin.h
index aefc1d145..94b95dbcf 100644
--- a/src/WebAdmin.h
+++ b/src/WebAdmin.h
@@ -116,6 +116,9 @@ public:
/** Stops the HTTP server, if it was started. */
void Stop(void);
+ /** Loads the login template. Returns true if the loading succeeds, false if not. */
+ bool LoadLoginTemplate(void);
+
void AddPlugin(cWebPlugin * a_Plugin);
void RemovePlugin(cWebPlugin * a_Plugin);
@@ -146,6 +149,9 @@ public:
/** Returns the prefix needed for making a link point to the webadmin root from the given URL ("../../../webadmin"-style) */
static AString GetBaseURL(const AStringVector & a_URLSplit);
+ /** Returns the content type from the file extension. If the extension isn't in the list, the function returns "text/html" */
+ static AString GetContentTypeFromFileExt(const AString & a_FileExtension);
+
protected:
/** Common base class for request body data handlers */
class cRequestData
@@ -205,6 +211,9 @@ protected:
/** The Lua template script to provide templates: */
cLuaState m_TemplateScript;
+ /** The template that provides the login site: */
+ AString m_LoginTemplate;
+
/** The HTTP server which provides the underlying HTTP parsing, serialization and events */
cHTTPServer m_HTTPServer;
@@ -214,6 +223,9 @@ protected:
/** Handles requests for the root page */
void HandleRootRequest(cHTTPConnection & a_Connection, cHTTPRequest & a_Request);
+ /** Handles requests for a file */
+ void HandleFileRequest(cHTTPConnection & a_Connection, cHTTPRequest & a_Request);
+
// cHTTPServer::cCallbacks overrides:
virtual void OnRequestBegun (cHTTPConnection & a_Connection, cHTTPRequest & a_Request) override;
virtual void OnRequestBody (cHTTPConnection & a_Connection, cHTTPRequest & a_Request, const char * a_Data, size_t a_Size) override;
diff --git a/src/World.cpp b/src/World.cpp
index 469606012..8664bbec6 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -442,7 +442,7 @@ void cWorld::InitializeSpawn(void)
{
for (int z = 0; z < ViewDist; z++)
{
- m_ChunkMap->TouchChunk(x + ChunkX-(ViewDist - 1) / 2, ZERO_CHUNK_Y, z + ChunkZ-(ViewDist - 1) / 2); // Queue the chunk in the generator / loader
+ m_ChunkMap->TouchChunk(x + ChunkX-(ViewDist - 1) / 2, z + ChunkZ-(ViewDist - 1) / 2); // Queue the chunk in the generator / loader
}
}
@@ -757,6 +757,11 @@ void cWorld::InitialiseGeneratorDefaults(cIniFile & a_IniFile)
a_IniFile.GetValueSet("Generator", "BottomLavaHeight", "30");
break;
}
+ case dimNotSet:
+ {
+ ASSERT(!"Dimension not set");
+ break;
+ }
}
}
@@ -772,6 +777,7 @@ void cWorld::InitialiseAndLoadMobSpawningValues(cIniFile & a_IniFile)
case dimOverworld: DefaultMonsters = "bat, cavespider, chicken, cow, creeper, enderman, horse, mooshroom, ocelot, pig, sheep, silverfish, skeleton, slime, spider, squid, wolf, zombie"; break;
case dimNether: DefaultMonsters = "blaze, ghast, magmacube, skeleton, zombie, zombiepigman"; break;
case dimEnd: DefaultMonsters = "enderman"; break;
+ case dimNotSet: ASSERT(!"Dimension not set"); break;
}
m_bAnimals = a_IniFile.GetValueSetB("Monsters", "AnimalsOn", true);
@@ -876,7 +882,7 @@ void cWorld::Tick(float a_Dt, int a_LastTickDurationMSec)
m_TimeOfDaySecs -= 1200.0;
}
- m_TimeOfDay = (Int64)(m_TimeOfDaySecs * 20.0);
+ m_TimeOfDay = static_cast<int>(m_TimeOfDaySecs * 20.0);
// Updates the sky darkness based on current time of day
UpdateSkyDarkness();
@@ -1130,7 +1136,7 @@ void cWorld::UpdateSkyDarkness(void)
}
else if (TempTime <= TIME_NIGHT_START)
{
- m_SkyDarkness = (TIME_NIGHT_START - TempTime) / TIME_SPAWN_DIVISOR;
+ m_SkyDarkness = static_cast<NIBBLETYPE>((TIME_NIGHT_START - TempTime) / TIME_SPAWN_DIVISOR);
}
else if (TempTime <= TIME_NIGHT_END)
{
@@ -1138,7 +1144,7 @@ void cWorld::UpdateSkyDarkness(void)
}
else
{
- m_SkyDarkness = (TIME_SUNRISE - TempTime) / TIME_SPAWN_DIVISOR;
+ m_SkyDarkness = static_cast<NIBBLETYPE>((TIME_SUNRISE - TempTime) / TIME_SPAWN_DIVISOR);
}
}
@@ -1592,9 +1598,9 @@ bool cWorld::GrowRipePlant(int a_BlockX, int a_BlockY, int a_BlockZ, bool a_IsBy
MTRand r1;
for (int i = 0; i < 60; i++)
{
- int OfsX = (r1.randInt(3) + r1.randInt(3) + r1.randInt(3) + r1.randInt(3)) / 2 - 3;
- int OfsY = r1.randInt(3) + r1.randInt(3) - 3;
- int OfsZ = (r1.randInt(3) + r1.randInt(3) + r1.randInt(3) + r1.randInt(3)) / 2 - 3;
+ int OfsX = static_cast<int>(r1.randInt(3) + r1.randInt(3) + r1.randInt(3) + r1.randInt(3)) / 2 - 3;
+ int OfsY = static_cast<int>(r1.randInt(3) + r1.randInt(3)) - 3;
+ int OfsZ = static_cast<int>(r1.randInt(3) + r1.randInt(3) + r1.randInt(3) + r1.randInt(3)) / 2 - 3;
BLOCKTYPE Ground = GetBlock(a_BlockX + OfsX, a_BlockY + OfsY, a_BlockZ + OfsZ);
if (Ground != E_BLOCK_GRASS)
{
@@ -1721,7 +1727,7 @@ bool cWorld::SetAreaBiome(const cCuboid & a_Area, EMCSBiome a_Biome)
void cWorld::SetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, bool a_SendToClients)
{
- m_ChunkMap->SetBlock(*this, a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, a_SendToClients);
+ m_ChunkMap->SetBlock(a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, a_SendToClients);
}
@@ -2138,16 +2144,88 @@ void cWorld::BroadcastEntityAnimation(const cEntity & a_Entity, char a_Animation
-void cWorld::BroadcastParticleEffect(const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmmount, cClientHandle * a_Exclude)
+void cWorld::BroadcastParticleEffect(const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmount, cClientHandle * a_Exclude)
+{
+ m_ChunkMap->BroadcastParticleEffect(a_ParticleName, a_SrcX, a_SrcY, a_SrcZ, a_OffsetX, a_OffsetY, a_OffsetZ, a_ParticleData, a_ParticleAmount, a_Exclude);
+}
+
+
+
+
+
+void cWorld::BroadcastPlayerListAddPlayer(const cPlayer & a_Player, const cClientHandle * a_Exclude)
+{
+ cCSLock Lock(m_CSPlayers);
+ for (cPlayerList::iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr)
+ {
+ cClientHandle * ch = (*itr)->GetClientHandle();
+ if ((ch == a_Exclude) || (ch == NULL) || !ch->IsLoggedIn() || ch->IsDestroyed())
+ {
+ continue;
+ }
+ ch->SendPlayerListAddPlayer(a_Player);
+ }
+}
+
+
+
+
+
+void cWorld::BroadcastPlayerListRemovePlayer(const cPlayer & a_Player, const cClientHandle * a_Exclude)
+{
+ cCSLock Lock(m_CSPlayers);
+ for (cPlayerList::iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr)
+ {
+ cClientHandle * ch = (*itr)->GetClientHandle();
+ if ((ch == a_Exclude) || (ch == NULL) || !ch->IsLoggedIn() || ch->IsDestroyed())
+ {
+ continue;
+ }
+ ch->SendPlayerListRemovePlayer(a_Player);
+ }
+}
+
+
+
+
+
+void cWorld::BroadcastPlayerListUpdateGameMode(const cPlayer & a_Player, const cClientHandle * a_Exclude)
+{
+ cCSLock Lock(m_CSPlayers);
+ for (cPlayerList::iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr)
+ {
+ cClientHandle * ch = (*itr)->GetClientHandle();
+ if ((ch == a_Exclude) || (ch == NULL) || !ch->IsLoggedIn() || ch->IsDestroyed())
+ {
+ continue;
+ }
+ ch->SendPlayerListUpdateGameMode(a_Player);
+ }
+}
+
+
+
+
+
+void cWorld::BroadcastPlayerListUpdatePing(const cPlayer & a_Player, const cClientHandle * a_Exclude)
{
- m_ChunkMap->BroadcastParticleEffect(a_ParticleName, a_SrcX, a_SrcY, a_SrcZ, a_OffsetX, a_OffsetY, a_OffsetZ, a_ParticleData, a_ParticleAmmount, a_Exclude);
+ cCSLock Lock(m_CSPlayers);
+ for (cPlayerList::iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr)
+ {
+ cClientHandle * ch = (*itr)->GetClientHandle();
+ if ((ch == a_Exclude) || (ch == NULL) || !ch->IsLoggedIn() || ch->IsDestroyed())
+ {
+ continue;
+ }
+ ch->SendPlayerListUpdatePing(a_Player);
+ }
}
-void cWorld::BroadcastPlayerListItem(const AString & a_PlayerName, bool a_IsOnline, short a_Ping, const cClientHandle * a_Exclude)
+void cWorld::BroadcastPlayerListUpdateDisplayName(const cPlayer & a_Player, const AString & a_OldListName, const cClientHandle * a_Exclude)
{
cCSLock Lock(m_CSPlayers);
for (cPlayerList::iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr)
@@ -2157,7 +2235,7 @@ void cWorld::BroadcastPlayerListItem(const AString & a_PlayerName, bool a_IsOnli
{
continue;
}
- ch->SendPlayerListItem(a_PlayerName, a_IsOnline, a_Ping);
+ ch->SendPlayerListUpdateDisplayName(a_Player, a_OldListName);
}
}
@@ -2374,6 +2452,8 @@ void cWorld::MarkChunkSaved (int a_ChunkX, int a_ChunkZ)
void cWorld::QueueSetChunkData(const cSetChunkDataPtr & a_SetChunkData)
{
+ ASSERT(IsChunkQueued(a_SetChunkData->GetChunkX(), a_SetChunkData->GetChunkZ()));
+
// Validate biomes, if needed:
if (!a_SetChunkData->AreBiomesValid())
{
@@ -2424,7 +2504,7 @@ void cWorld::SetChunkData(cSetChunkData & a_SetChunkData)
// Save the chunk right after generating, so that we don't have to generate it again on next run
if (a_SetChunkData.ShouldMarkDirty())
{
- m_Storage.QueueSaveChunk(ChunkX, 0, ChunkZ);
+ m_Storage.QueueSaveChunk(ChunkX, ChunkZ);
}
}
@@ -2463,6 +2543,15 @@ bool cWorld::GetChunkBlockTypes(int a_ChunkX, int a_ChunkZ, BLOCKTYPE * a_BlockT
+bool cWorld::IsChunkQueued(int a_ChunkX, int a_ChunkZ) const
+{
+ return m_ChunkMap->IsChunkQueued(a_ChunkX, a_ChunkZ);
+}
+
+
+
+
+
bool cWorld::IsChunkValid(int a_ChunkX, int a_ChunkZ) const
{
return m_ChunkMap->IsChunkValid(a_ChunkX, a_ChunkZ);
@@ -2669,7 +2758,7 @@ void cWorld::SendPlayerList(cPlayer * a_DestPlayer)
cClientHandle * ch = (*itr)->GetClientHandle();
if ((ch != NULL) && !ch->IsDestroyed())
{
- a_DestPlayer->GetClientHandle()->SendPlayerListItem((*itr)->GetTabListName(), true, (*itr)->GetClientHandle()->GetPing());
+ a_DestPlayer->GetClientHandle()->SendPlayerListAddPlayer(*(*itr));
}
}
}
@@ -2696,6 +2785,15 @@ bool cWorld::ForEachEntityInChunk(int a_ChunkX, int a_ChunkZ, cEntityCallback &
+bool cWorld::ForEachEntityInBox(const cBoundingBox & a_Box, cEntityCallback & a_Callback)
+{
+ return m_ChunkMap->ForEachEntityInBox(a_Box, a_Callback);
+}
+
+
+
+
+
bool cWorld::DoWithEntityByID(int a_UniqueID, cEntityCallback & a_Callback)
{
return m_ChunkMap->DoWithEntityByID(a_UniqueID, a_Callback);
@@ -2769,36 +2867,18 @@ void cWorld::RemoveClientFromChunkSender(cClientHandle * a_Client)
-void cWorld::TouchChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ)
-{
- m_ChunkMap->TouchChunk(a_ChunkX, a_ChunkY, a_ChunkZ);
-}
-
-
-
-
-
-bool cWorld::LoadChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ)
-{
- return m_ChunkMap->LoadChunk(a_ChunkX, a_ChunkY, a_ChunkZ);
-}
-
-
-
-
-
-void cWorld::LoadChunks(const cChunkCoordsList & a_Chunks)
+void cWorld::TouchChunk(int a_ChunkX, int a_ChunkZ)
{
- m_ChunkMap->LoadChunks(a_Chunks);
+ m_ChunkMap->TouchChunk(a_ChunkX, a_ChunkZ);
}
-void cWorld::ChunkLoadFailed(int a_ChunkX, int a_ChunkY, int a_ChunkZ)
+void cWorld::ChunkLoadFailed(int a_ChunkX, int a_ChunkZ)
{
- m_ChunkMap->ChunkLoadFailed(a_ChunkX, a_ChunkY, a_ChunkZ);
+ m_ChunkMap->ChunkLoadFailed(a_ChunkX, a_ChunkZ);
}
@@ -2842,7 +2922,7 @@ bool cWorld::SetCommandBlockCommand(int a_BlockX, int a_BlockY, int a_BlockZ, co
{
AString m_Command;
public:
- cUpdateCommandBlock(const AString & a_Command) : m_Command(a_Command) {}
+ cUpdateCommandBlock(const AString & a_CallbackCommand) : m_Command(a_CallbackCommand) {}
virtual bool Item(cCommandBlockEntity * a_CommandBlock) override
{
@@ -2903,8 +2983,7 @@ void cWorld::RegenerateChunk(int a_ChunkX, int a_ChunkZ)
{
m_ChunkMap->MarkChunkRegenerating(a_ChunkX, a_ChunkZ);
- // Trick: use Y=1 to force the chunk generation even though the chunk data is already present
- m_Generator.QueueGenerateChunk(a_ChunkX, 1, a_ChunkZ);
+ m_Generator.QueueGenerateChunk(a_ChunkX, a_ChunkZ, true);
}
@@ -2913,7 +2992,7 @@ void cWorld::RegenerateChunk(int a_ChunkX, int a_ChunkZ)
void cWorld::GenerateChunk(int a_ChunkX, int a_ChunkZ)
{
- m_Generator.QueueGenerateChunk(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ);
+ m_Generator.QueueGenerateChunk(a_ChunkX, a_ChunkZ, false);
}
@@ -3322,20 +3401,26 @@ cFluidSimulator * cWorld::InitializeFluidSimulator(cIniFile & a_IniFile, const c
int Falloff = a_IniFile.GetValueSetI(SimulatorSectionName, "Falloff", IsWater ? 1 : 2);
int TickDelay = a_IniFile.GetValueSetI(SimulatorSectionName, "TickDelay", IsWater ? 5 : 30);
int NumNeighborsForSource = a_IniFile.GetValueSetI(SimulatorSectionName, "NumNeighborsForSource", IsWater ? 2 : -1);
+
+ if ((Falloff > 15) || (Falloff < 0))
+ {
+ LOGWARNING("Falloff for %s simulator is out of range, assuming default of %d", a_FluidName, IsWater ? 1 : 2);
+ Falloff = IsWater ? 1 : 2;
+ }
if (NoCaseCompare(SimulatorName, "floody") == 0)
{
- res = new cFloodyFluidSimulator(*this, a_SimulateBlock, a_StationaryBlock, Falloff, TickDelay, NumNeighborsForSource);
+ res = new cFloodyFluidSimulator(*this, a_SimulateBlock, a_StationaryBlock, static_cast<NIBBLETYPE>(Falloff), TickDelay, NumNeighborsForSource);
}
else if (NoCaseCompare(SimulatorName, "vanilla") == 0)
{
- res = new cVanillaFluidSimulator(*this, a_SimulateBlock, a_StationaryBlock, Falloff, TickDelay, NumNeighborsForSource);
+ res = new cVanillaFluidSimulator(*this, a_SimulateBlock, a_StationaryBlock, static_cast<NIBBLETYPE>(Falloff), TickDelay, NumNeighborsForSource);
}
else
{
// The simulator name doesn't match anything we have, issue a warning:
LOGWARNING("%s [Physics]:%s specifies an unknown simulator, using the default \"Vanilla\".", GetIniFileName().c_str(), SimulatorNameKey.c_str());
- res = new cVanillaFluidSimulator(*this, a_SimulateBlock, a_StationaryBlock, Falloff, TickDelay, NumNeighborsForSource);
+ res = new cVanillaFluidSimulator(*this, a_SimulateBlock, a_StationaryBlock, static_cast<NIBBLETYPE>(Falloff), TickDelay, NumNeighborsForSource);
}
}
@@ -3445,9 +3530,9 @@ void cWorld::cTaskSendBlockToAllPlayers::Run(cWorld & a_World)
public cPlayerListCallback
{
public:
- cPlayerCallback(std::vector<Vector3i> & a_SendQueue, cWorld & a_World) :
+ cPlayerCallback(std::vector<Vector3i> & a_SendQueue, cWorld & a_CallbackWorld) :
m_SendQueue(a_SendQueue),
- m_World(a_World)
+ m_World(a_CallbackWorld)
{
}
@@ -3516,6 +3601,15 @@ bool cWorld::cChunkGeneratorCallbacks::IsChunkValid(int a_ChunkX, int a_ChunkZ)
+bool cWorld::cChunkGeneratorCallbacks::IsChunkQueued(int a_ChunkX, int a_ChunkZ)
+{
+ return m_World->IsChunkQueued(a_ChunkX, a_ChunkZ);
+}
+
+
+
+
+
bool cWorld::cChunkGeneratorCallbacks::HasChunkAnyClients(int a_ChunkX, int a_ChunkZ)
{
return m_World->HasChunkAnyClients(a_ChunkX, a_ChunkZ);
diff --git a/src/World.h b/src/World.h
index 5f4466603..eee0ced54 100644
--- a/src/World.h
+++ b/src/World.h
@@ -157,14 +157,14 @@ public:
}
virtual Int64 GetWorldAge (void) const override { return m_WorldAge; }
- virtual Int64 GetTimeOfDay(void) const override { return m_TimeOfDay; }
+ virtual int GetTimeOfDay(void) const override { return m_TimeOfDay; }
void SetTicksUntilWeatherChange(int a_WeatherInterval)
{
m_WeatherInterval = a_WeatherInterval;
}
- virtual void SetTimeOfDay(Int64 a_TimeOfDay) override
+ virtual void SetTimeOfDay(int a_TimeOfDay) override
{
m_TimeOfDay = a_TimeOfDay;
m_TimeOfDaySecs = (double)a_TimeOfDay / 20.0;
@@ -188,6 +188,9 @@ public:
/** Returns true if the world is in Adventure mode */
bool IsGameModeAdventure(void) const { return (m_GameMode == gmAdventure); }
+ /** Returns true if the world is in Spectator mode */
+ bool IsGameModeSpectator(void) const { return (m_GameMode == gmSpectator); }
+
bool IsPVPEnabled(void) const { return m_bEnabledPVP; }
bool IsDeepSnowEnabled(void) const { return m_IsDeepSnowEnabled; }
@@ -223,33 +226,37 @@ public:
void BroadcastChat (const cCompositeChat & a_Message, const cClientHandle * a_Exclude = NULL);
// tolua_end
- void BroadcastChunkData (int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer, const cClientHandle * a_Exclude = NULL);
- void BroadcastCollectEntity (const cEntity & a_Pickup, const cPlayer & a_Player, const cClientHandle * a_Exclude = NULL);
- void BroadcastDestroyEntity (const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL);
- void BroadcastEntityEffect (const cEntity & a_Entity, int a_EffectID, int a_Amplifier, short a_Duration, const cClientHandle * a_Exclude = NULL);
- void BroadcastEntityEquipment (const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item, const cClientHandle * a_Exclude = NULL);
- void BroadcastEntityHeadLook (const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL);
- void BroadcastEntityLook (const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL);
- void BroadcastEntityMetadata (const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL);
- void BroadcastEntityRelMove (const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ, const cClientHandle * a_Exclude = NULL);
- void BroadcastEntityRelMoveLook (const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ, const cClientHandle * a_Exclude = NULL);
- void BroadcastEntityStatus (const cEntity & a_Entity, char a_Status, const cClientHandle * a_Exclude = NULL);
- void BroadcastEntityVelocity (const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL);
- virtual void BroadcastEntityAnimation(const cEntity & a_Entity, char a_Animation, const cClientHandle * a_Exclude = NULL) override; // tolua_export
- void BroadcastParticleEffect (const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmmount, cClientHandle * a_Exclude = NULL); // tolua_export
- void BroadcastPlayerListItem (const AString & a_PlayerName, bool a_IsOnline, short a_Ping = 0, const cClientHandle * a_Exclude = NULL);
- void BroadcastRemoveEntityEffect (const cEntity & a_Entity, int a_EffectID, const cClientHandle * a_Exclude = NULL);
- void BroadcastScoreboardObjective (const AString & a_Name, const AString & a_DisplayName, Byte a_Mode);
- void BroadcastScoreUpdate (const AString & a_Objective, const AString & a_Player, cObjective::Score a_Score, Byte a_Mode);
- void BroadcastDisplayObjective (const AString & a_Objective, cScoreboard::eDisplaySlot a_Display);
- void BroadcastSoundEffect (const AString & a_SoundName, double a_X, double a_Y, double a_Z, float a_Volume, float a_Pitch, const cClientHandle * a_Exclude = NULL); // tolua_export
- void BroadcastSoundParticleEffect (int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data, const cClientHandle * a_Exclude = NULL); // tolua_export
- void BroadcastSpawnEntity (cEntity & a_Entity, const cClientHandle * a_Exclude = NULL);
- void BroadcastTeleportEntity (const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL);
- void BroadcastThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ, const cClientHandle * a_Exclude = NULL);
- void BroadcastTimeUpdate (const cClientHandle * a_Exclude = NULL);
- virtual void BroadcastUseBed (const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ) override;
- void BroadcastWeather (eWeather a_Weather, const cClientHandle * a_Exclude = NULL);
+ void BroadcastChunkData (int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer, const cClientHandle * a_Exclude = NULL);
+ void BroadcastCollectEntity (const cEntity & a_Pickup, const cPlayer & a_Player, const cClientHandle * a_Exclude = NULL);
+ void BroadcastDestroyEntity (const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL);
+ void BroadcastEntityEffect (const cEntity & a_Entity, int a_EffectID, int a_Amplifier, short a_Duration, const cClientHandle * a_Exclude = NULL);
+ void BroadcastEntityEquipment (const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item, const cClientHandle * a_Exclude = NULL);
+ void BroadcastEntityHeadLook (const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL);
+ void BroadcastEntityLook (const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL);
+ void BroadcastEntityMetadata (const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL);
+ void BroadcastEntityRelMove (const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ, const cClientHandle * a_Exclude = NULL);
+ void BroadcastEntityRelMoveLook (const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ, const cClientHandle * a_Exclude = NULL);
+ void BroadcastEntityStatus (const cEntity & a_Entity, char a_Status, const cClientHandle * a_Exclude = NULL);
+ void BroadcastEntityVelocity (const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL);
+ virtual void BroadcastEntityAnimation (const cEntity & a_Entity, char a_Animation, const cClientHandle * a_Exclude = NULL) override; // tolua_export
+ void BroadcastParticleEffect (const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmount, cClientHandle * a_Exclude = NULL); // tolua_export
+ void BroadcastPlayerListAddPlayer (const cPlayer & a_Player, const cClientHandle * a_Exclude = NULL);
+ void BroadcastPlayerListRemovePlayer (const cPlayer & a_Player, const cClientHandle * a_Exclude = NULL);
+ void BroadcastPlayerListUpdateGameMode (const cPlayer & a_Player, const cClientHandle * a_Exclude = NULL);
+ void BroadcastPlayerListUpdatePing (const cPlayer & a_Player, const cClientHandle * a_Exclude = NULL);
+ void BroadcastPlayerListUpdateDisplayName(const cPlayer & a_Player, const AString & a_OldListName, const cClientHandle * a_Exclude = NULL);
+ void BroadcastRemoveEntityEffect (const cEntity & a_Entity, int a_EffectID, const cClientHandle * a_Exclude = NULL);
+ void BroadcastScoreboardObjective (const AString & a_Name, const AString & a_DisplayName, Byte a_Mode);
+ void BroadcastScoreUpdate (const AString & a_Objective, const AString & a_Player, cObjective::Score a_Score, Byte a_Mode);
+ void BroadcastDisplayObjective (const AString & a_Objective, cScoreboard::eDisplaySlot a_Display);
+ void BroadcastSoundEffect (const AString & a_SoundName, double a_X, double a_Y, double a_Z, float a_Volume, float a_Pitch, const cClientHandle * a_Exclude = NULL); // tolua_export
+ void BroadcastSoundParticleEffect (int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data, const cClientHandle * a_Exclude = NULL); // tolua_export
+ void BroadcastSpawnEntity (cEntity & a_Entity, const cClientHandle * a_Exclude = NULL);
+ void BroadcastTeleportEntity (const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL);
+ void BroadcastThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ, const cClientHandle * a_Exclude = NULL);
+ void BroadcastTimeUpdate (const cClientHandle * a_Exclude = NULL);
+ virtual void BroadcastUseBed (const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ) override;
+ void BroadcastWeather (eWeather a_Weather, const cClientHandle * a_Exclude = NULL);
virtual cBroadcastInterface & GetBroadcastManager(void) override
{
@@ -279,7 +286,12 @@ public:
/** Gets the chunk's blocks, only the block types */
bool GetChunkBlockTypes(int a_ChunkX, int a_ChunkZ, BLOCKTYPE * a_BlockTypes);
- bool IsChunkValid (int a_ChunkX, int a_ChunkZ) const;
+ /** Returns true iff the chunk is in the loader / generator queue. */
+ bool IsChunkQueued(int a_ChunkX, int a_ChunkZ) const;
+
+ /** Returns true iff the chunk is present and valid. */
+ bool IsChunkValid(int a_ChunkX, int a_ChunkZ) const;
+
bool HasChunkAnyClients(int a_ChunkX, int a_ChunkZ) const;
/** Queues a task to unload unused chunks onto the tick thread. The prefferred way of unloading*/
@@ -324,6 +336,11 @@ public:
/** Calls the callback for each entity in the specified chunk; returns true if all entities processed, false if the callback aborted by returning true */
bool ForEachEntityInChunk(int a_ChunkX, int a_ChunkZ, cEntityCallback & a_Callback); // Exported in ManualBindings.cpp
+ /** Calls the callback for each entity that has a nonempty intersection with the specified boundingbox.
+ Returns true if all entities processed, false if the callback aborted by returning true.
+ If any chunk in the box is missing, ignores the entities in that chunk silently. */
+ bool ForEachEntityInBox(const cBoundingBox & a_Box, cEntityCallback & a_Callback); // Exported in ManualBindings.cpp
+
/** Calls the callback if the entity with the specified ID is found, with the entity object as the callback param. Returns true if entity found and callback returned false. */
bool DoWithEntityByID(int a_UniqueID, cEntityCallback & a_Callback); // Exported in ManualBindings.cpp
@@ -351,16 +368,10 @@ public:
void RemoveClientFromChunkSender(cClientHandle * a_Client);
/** Touches the chunk, causing it to be loaded or generated */
- void TouchChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ);
-
- /** Loads the chunk, if not already loaded. Doesn't generate. Returns true if chunk valid (even if already loaded before) */
- bool LoadChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ);
-
- /** Loads the chunks specified. Doesn't report failure, other than chunks being !IsValid() */
- void LoadChunks(const cChunkCoordsList & a_Chunks);
+ void TouchChunk(int a_ChunkX, int a_ChunkZ);
/** Marks the chunk as failed-to-load: */
- void ChunkLoadFailed(int a_ChunkX, int a_ChunkY, int a_ChunkZ);
+ void ChunkLoadFailed(int a_ChunkX, int a_ChunkZ);
/** Sets the sign text, asking plugins for permission first. a_Player is the player who this change belongs to, may be NULL. Returns true if sign text changed. Same as UpdateSign() */
bool SetSignLines(int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4, cPlayer * a_Player = NULL); // Exported in ManualBindings.cpp
@@ -380,7 +391,7 @@ public:
/** Regenerate the given chunk: */
void RegenerateChunk(int a_ChunkX, int a_ChunkZ); // tolua_export
- /** Generates the given chunk, if not already generated */
+ /** Generates the given chunk */
void GenerateChunk(int a_ChunkX, int a_ChunkZ); // tolua_export
/** Queues a chunk for lighting; a_Callback is called after the chunk is lighted */
@@ -465,7 +476,7 @@ public:
int SpawnMinecart(double a_X, double a_Y, double a_Z, int a_MinecartType, const cItem & a_Content = cItem(), int a_BlockHeight = 1);
/** Spawns an experience orb at the given location with the given reward. It returns the UniqueID of the spawned experience orb. */
- int SpawnExperienceOrb(double a_X, double a_Y, double a_Z, int a_Reward);
+ virtual int SpawnExperienceOrb(double a_X, double a_Y, double a_Z, int a_Reward) override;
/** Spawns a new primed TNT entity at the specified block coords and specified fuse duration. Initial velocity is given based on the relative coefficient provided */
void SpawnPrimedTNT(double a_X, double a_Y, double a_Z, int a_FuseTimeInSec = 80, double a_InitialVelocityCoeff = 1);
@@ -817,6 +828,7 @@ private:
virtual void OnChunkGenerated (cChunkDesc & a_ChunkDesc) override;
virtual bool IsChunkValid (int a_ChunkX, int a_ChunkZ) override;
virtual bool HasChunkAnyClients(int a_ChunkX, int a_ChunkZ) override;
+ virtual bool IsChunkQueued (int a_ChunkX, int a_ChunkZ) override;
// cPluginInterface overrides:
virtual void CallHookChunkGenerating(cChunkDesc & a_ChunkDesc) override;
@@ -883,7 +895,7 @@ private:
double m_WorldAgeSecs; // World age, in seconds. Is only incremented, cannot be set by plugins.
double m_TimeOfDaySecs; // Time of day in seconds. Can be adjusted. Is wrapped to zero each day.
Int64 m_WorldAge; // World age in ticks, calculated off of m_WorldAgeSecs
- Int64 m_TimeOfDay; // Time in ticks, calculated off of m_TimeOfDaySecs
+ int m_TimeOfDay; // Time in ticks, calculated off of m_TimeOfDaySecs
Int64 m_LastTimeUpdate; // The tick in which the last time update has been sent.
Int64 m_LastUnload; // The last WorldAge (in ticks) in which unloading was triggerred
Int64 m_LastSave; // The last WorldAge (in ticks) in which save-all was triggerred
diff --git a/src/WorldStorage/FastNBT.cpp b/src/WorldStorage/FastNBT.cpp
index c6294b99c..ed8e8bb14 100644
--- a/src/WorldStorage/FastNBT.cpp
+++ b/src/WorldStorage/FastNBT.cpp
@@ -310,7 +310,7 @@ int cParsedNBT::FindTagByPath(int a_Tag, const AString & a_Path) const
{
continue;
}
- Tag = FindChildByName(Tag, a_Path.c_str() + Begin, i - Begin - 1);
+ Tag = FindChildByName(Tag, a_Path.c_str() + Begin, i - Begin);
if (Tag < 0)
{
return -1;
diff --git a/src/WorldStorage/ScoreboardSerializer.cpp b/src/WorldStorage/ScoreboardSerializer.cpp
index da8236e0d..e30eecf67 100644
--- a/src/WorldStorage/ScoreboardSerializer.cpp
+++ b/src/WorldStorage/ScoreboardSerializer.cpp
@@ -283,37 +283,37 @@ bool cScoreboardSerializer::LoadScoreboardFromNBT(const cParsedNBT & a_NBT)
bool AllowsFriendlyFire = true, CanSeeFriendlyInvisible = false;
int CurrLine = a_NBT.FindChildByName(Child, "Name");
- if (CurrLine >= 0)
+ if ((CurrLine >= 0) && (a_NBT.GetType(CurrLine) == TAG_String))
{
- Name = a_NBT.GetInt(CurrLine);
+ Name = a_NBT.GetString(CurrLine);
}
CurrLine = a_NBT.FindChildByName(Child, "DisplayName");
- if (CurrLine >= 0)
+ if ((CurrLine >= 0) && (a_NBT.GetType(CurrLine) == TAG_String))
{
- DisplayName = a_NBT.GetInt(CurrLine);
+ DisplayName = a_NBT.GetString(CurrLine);
}
CurrLine = a_NBT.FindChildByName(Child, "Prefix");
- if (CurrLine >= 0)
+ if ((CurrLine >= 0) && (a_NBT.GetType(CurrLine) == TAG_String))
{
- Prefix = a_NBT.GetInt(CurrLine);
+ Prefix = a_NBT.GetString(CurrLine);
}
CurrLine = a_NBT.FindChildByName(Child, "Suffix");
- if (CurrLine >= 0)
+ if ((CurrLine >= 0) && (a_NBT.GetType(CurrLine) == TAG_String))
{
- Suffix = a_NBT.GetInt(CurrLine);
+ Suffix = a_NBT.GetString(CurrLine);
}
CurrLine = a_NBT.FindChildByName(Child, "AllowFriendlyFire");
- if (CurrLine >= 0)
+ if ((CurrLine >= 0) && (a_NBT.GetType(CurrLine) == TAG_Int))
{
AllowsFriendlyFire = (a_NBT.GetInt(CurrLine) != 0);
}
CurrLine = a_NBT.FindChildByName(Child, "SeeFriendlyInvisibles");
- if (CurrLine >= 0)
+ if ((CurrLine >= 0) && (a_NBT.GetType(CurrLine) == TAG_Int))
{
CanSeeFriendlyInvisible = (a_NBT.GetInt(CurrLine) != 0);
}
diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp
index 5c155aeef..10cc39083 100644
--- a/src/WorldStorage/WSSAnvil.cpp
+++ b/src/WorldStorage/WSSAnvil.cpp
@@ -66,8 +66,17 @@ Since only the header is actually in the memory, this number can be high, but st
*/
#define MAX_MCA_FILES 32
-/// The maximum size of an inflated chunk; raw chunk data is 192 KiB, allow 64 KiB more of entities
-#define CHUNK_INFLATE_MAX 256 KiB
+#define LOAD_FAILED(CHX, CHZ) \
+ { \
+ const int RegionX = FAST_FLOOR_DIV(CHX, 32); \
+ const int RegionZ = FAST_FLOOR_DIV(CHZ, 32); \
+ LOGERROR("%s (%d): Loading chunk [%d, %d] from file r.%d.%d.mca failed. " \
+ "The server will now abort in order to avoid further data loss. " \
+ "Please add the reported file and this message to the issue report.", \
+ __FUNCTION__, __LINE__, CHX, CHZ, RegionX, RegionZ \
+ ); \
+ *((volatile int *)0) = 0; /* Crash intentionally */ \
+ }
@@ -248,29 +257,22 @@ cWSSAnvil::cMCAFile * cWSSAnvil::LoadMCAFile(const cChunkCoords & a_Chunk)
bool cWSSAnvil::LoadChunkFromData(const cChunkCoords & a_Chunk, const AString & a_Data)
{
- // Decompress the data:
- char Uncompressed[CHUNK_INFLATE_MAX];
- z_stream strm;
- strm.zalloc = (alloc_func)NULL;
- strm.zfree = (free_func)NULL;
- strm.opaque = NULL;
- inflateInit(&strm);
- strm.next_out = (Bytef *)Uncompressed;
- strm.avail_out = sizeof(Uncompressed);
- strm.next_in = (Bytef *)a_Data.data();
- strm.avail_in = (uInt)a_Data.size();
- int res = inflate(&strm, Z_FINISH);
- inflateEnd(&strm);
- if (res != Z_STREAM_END)
+ // Uncompress the data:
+ AString Uncompressed;
+ int res = InflateString(a_Data.data(), a_Data.size(), Uncompressed);
+ if (res != Z_OK)
{
+ LOGWARNING("Uncompressing chunk [%d, %d] failed: %d", a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ, res);
+ LOAD_FAILED(a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ);
return false;
}
// Parse the NBT data:
- cParsedNBT NBT(Uncompressed, strm.total_out);
+ cParsedNBT NBT(Uncompressed.data(), Uncompressed.size());
if (!NBT.IsValid())
{
// NBT Parsing failed
+ LOAD_FAILED(a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ);
return false;
}
@@ -317,11 +319,19 @@ bool cWSSAnvil::LoadChunkFromNBT(const cChunkCoords & a_Chunk, const cParsedNBT
int Level = a_NBT.FindChildByName(0, "Level");
if (Level < 0)
{
+ LOAD_FAILED(a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ);
return false;
}
int Sections = a_NBT.FindChildByName(Level, "Sections");
- if ((Sections < 0) || (a_NBT.GetType(Sections) != TAG_List) || (a_NBT.GetChildrenType(Sections) != TAG_Compound))
+ if ((Sections < 0) || (a_NBT.GetType(Sections) != TAG_List))
+ {
+ LOAD_FAILED(a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ);
+ return false;
+ }
+ eTagType SectionsType = a_NBT.GetChildrenType(Sections);
+ if ((SectionsType != TAG_Compound) && (SectionsType != TAG_End))
{
+ LOAD_FAILED(a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ);
return false;
}
for (int Child = a_NBT.GetFirstChild(Sections); Child >= 0; Child = a_NBT.GetNextSibling(Child))
@@ -585,7 +595,7 @@ void cWSSAnvil::LoadBlockEntitiesFromNBT(cBlockEntityList & a_BlockEntities, con
// Get the BlockEntity's position
int x, y, z;
- if (!GetBlockEntityNBTPos(a_NBT, Child, x, y, z))
+ if (!GetBlockEntityNBTPos(a_NBT, Child, x, y, z) || (y < 0) || (y >= cChunkDef::Height))
{
LOGWARNING("Bad block entity, missing the coords. Will be ignored.");
continue;
@@ -613,6 +623,8 @@ void cWSSAnvil::LoadBlockEntitiesFromNBT(cBlockEntityList & a_BlockEntities, con
cBlockEntity * cWSSAnvil::LoadBlockEntityFromNBT(const cParsedNBT & a_NBT, int a_Tag, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
{
+ ASSERT((a_BlockY >= 0) && (a_BlockY < cChunkDef::Height));
+
// Load the specific BlockEntity type:
switch (a_BlockType)
{
@@ -2824,30 +2836,42 @@ bool cWSSAnvil::cMCAFile::GetChunkData(const cChunkCoords & a_Chunk, AString & a
}
unsigned ChunkLocation = ntohl(m_Header[LocalX + 32 * LocalZ]);
unsigned ChunkOffset = ChunkLocation >> 8;
+ if (ChunkOffset < 2)
+ {
+ return false;
+ }
m_File.Seek((int)ChunkOffset * 4096);
int ChunkSize = 0;
if (m_File.Read(&ChunkSize, 4) != 4)
{
+ LOAD_FAILED(a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ);
return false;
}
ChunkSize = ntohl((u_long)ChunkSize);
char CompressionType = 0;
if (m_File.Read(&CompressionType, 1) != 1)
{
+ LOAD_FAILED(a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ);
return false;
}
if (CompressionType != 2)
{
// Chunk is in an unknown compression
+ LOAD_FAILED(a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ);
return false;
}
ChunkSize--;
// HACK: This depends on the internal knowledge that AString's data() function returns the internal buffer directly
a_Data.assign(ChunkSize, '\0');
- return (m_File.Read((void *)a_Data.data(), ChunkSize) == ChunkSize);
+ if (m_File.Read((void *)a_Data.data(), ChunkSize) == ChunkSize)
+ {
+ return true;
+ }
+ LOAD_FAILED(a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ);
+ return false;
}
@@ -2902,7 +2926,13 @@ bool cWSSAnvil::cMCAFile::SetChunkData(const cChunkCoords & a_Chunk, const AStri
// Store the header:
ChunkSize = ((u_long)a_Data.size() + MCA_CHUNK_HEADER_LENGTH + 4095) / 4096; // Round data size *up* to nearest 4KB sector, make it a sector number
- ASSERT(ChunkSize < 256);
+ if (ChunkSize > 255)
+ {
+ LOGWARNING("Cannot save chunk [%d, %d], the data is too large (%u KiB, maximum is 1024 KiB). Remove some entities and retry.",
+ a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ, (unsigned)(ChunkSize * 4)
+ );
+ return false;
+ }
m_Header[LocalX + 32 * LocalZ] = htonl((ChunkSector << 8) | ChunkSize);
if (m_File.Seek(0) < 0)
{
diff --git a/src/WorldStorage/WSSCompact.cpp b/src/WorldStorage/WSSCompact.cpp
index 58f9e3cab..6760186b2 100644
--- a/src/WorldStorage/WSSCompact.cpp
+++ b/src/WorldStorage/WSSCompact.cpp
@@ -980,7 +980,7 @@ bool cWSSCompact::cPAKFile::SaveChunkToData(const cChunkCoords & a_Chunk, cWorld
if (!a_World->GetChunkData(a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ, Serializer))
{
// Chunk not valid
- LOG("cWSSCompact: Trying to save chunk [%d, %d, %d] that has no data, ignoring request.", a_Chunk.m_ChunkX, a_Chunk.m_ChunkY, a_Chunk.m_ChunkZ);
+ LOG("cWSSCompact: Trying to save chunk [%d, %d] that has no data, ignoring request.", a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ);
return false;
}
@@ -999,7 +999,7 @@ bool cWSSCompact::cPAKFile::SaveChunkToData(const cChunkCoords & a_Chunk, cWorld
int errorcode = CompressString(Data.data(), Data.size(), CompressedData, m_CompressionFactor);
if (errorcode != Z_OK)
{
- LOGERROR("Error %i compressing data for chunk [%d, %d, %d]", errorcode, a_Chunk.m_ChunkX, a_Chunk.m_ChunkY, a_Chunk.m_ChunkZ);
+ LOGERROR("Error %i compressing data for chunk [%d, %d]", errorcode, a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ);
return false;
}
@@ -1010,7 +1010,7 @@ bool cWSSCompact::cPAKFile::SaveChunkToData(const cChunkCoords & a_Chunk, cWorld
sChunkHeader * Header = new sChunkHeader;
if (Header == NULL)
{
- LOGWARNING("Cannot create a new chunk header to save chunk [%d, %d, %d]", a_Chunk.m_ChunkX, a_Chunk.m_ChunkY, a_Chunk.m_ChunkZ);
+ LOGWARNING("Cannot create a new chunk header to save chunk [%d, %d]", a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ);
return false;
}
Header->m_CompressedSize = (int)CompressedData.size();
diff --git a/src/WorldStorage/WorldStorage.cpp b/src/WorldStorage/WorldStorage.cpp
index 707e8f929..179cf9393 100644
--- a/src/WorldStorage/WorldStorage.cpp
+++ b/src/WorldStorage/WorldStorage.cpp
@@ -141,9 +141,11 @@ size_t cWorldStorage::GetSaveQueueLength(void)
-void cWorldStorage::QueueLoadChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, bool a_Generate)
+void cWorldStorage::QueueLoadChunk(int a_ChunkX, int a_ChunkZ)
{
- m_LoadQueue.EnqueueItem(sChunkLoad(a_ChunkX, a_ChunkY, a_ChunkZ, a_Generate));
+ ASSERT(m_World->IsChunkQueued(a_ChunkX, a_ChunkZ));
+
+ m_LoadQueue.EnqueueItem(cChunkCoords(a_ChunkX, a_ChunkZ));
m_Event.Set();
}
@@ -151,9 +153,11 @@ void cWorldStorage::QueueLoadChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, boo
-void cWorldStorage::QueueSaveChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ)
+void cWorldStorage::QueueSaveChunk(int a_ChunkX, int a_ChunkZ)
{
- m_SaveQueue.EnqueueItemIfNotPresent(cChunkCoords(a_ChunkX, a_ChunkY, a_ChunkZ));
+ ASSERT(m_World->IsChunkValid(a_ChunkX, a_ChunkZ));
+
+ m_SaveQueue.EnqueueItemIfNotPresent(cChunkCoords(a_ChunkX, a_ChunkZ));
m_Event.Set();
}
@@ -161,9 +165,9 @@ void cWorldStorage::QueueSaveChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ)
-void cWorldStorage::UnqueueLoad(int a_ChunkX, int a_ChunkY, int a_ChunkZ)
+void cWorldStorage::UnqueueLoad(int a_ChunkX, int a_ChunkZ)
{
- m_LoadQueue.Remove(sChunkLoad(a_ChunkX, a_ChunkY, a_ChunkZ, true));
+ m_LoadQueue.Remove(cChunkCoords(a_ChunkX, a_ChunkZ));
}
@@ -242,22 +246,14 @@ void cWorldStorage::Execute(void)
bool cWorldStorage::LoadOneChunk(void)
{
- sChunkLoad ToLoad(0, 0, 0, false);
+ cChunkCoords ToLoad(0, 0);
bool ShouldLoad = m_LoadQueue.TryDequeueItem(ToLoad);
- if (ShouldLoad && !LoadChunk(ToLoad.m_ChunkX, ToLoad.m_ChunkY, ToLoad.m_ChunkZ))
+
+ if (ShouldLoad)
{
- if (ToLoad.m_Generate)
- {
- // The chunk couldn't be loaded, generate it:
- m_World->GetGenerator().QueueGenerateChunk(ToLoad.m_ChunkX, ToLoad.m_ChunkY, ToLoad.m_ChunkZ);
- }
- else
- {
- // TODO: Notify the world that the load has failed:
- // m_World->ChunkLoadFailed(ToLoad.m_ChunkX, ToLoad.m_ChunkY, ToLoad.m_ChunkZ);
- }
+ return LoadChunk(ToLoad.m_ChunkX, ToLoad.m_ChunkZ);
}
- return ShouldLoad;
+ return false;
}
@@ -266,7 +262,7 @@ bool cWorldStorage::LoadOneChunk(void)
bool cWorldStorage::SaveOneChunk(void)
{
- cChunkCoords ToSave(0, 0, 0);
+ cChunkCoords ToSave(0, 0);
bool ShouldSave = m_SaveQueue.TryDequeueItem(ToSave);
if (ShouldSave && m_World->IsChunkValid(ToSave.m_ChunkX, ToSave.m_ChunkZ))
{
@@ -283,15 +279,11 @@ bool cWorldStorage::SaveOneChunk(void)
-bool cWorldStorage::LoadChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ)
+bool cWorldStorage::LoadChunk(int a_ChunkX, int a_ChunkZ)
{
- if (m_World->IsChunkValid(a_ChunkX, a_ChunkZ))
- {
- // Already loaded (can happen, since the queue is async)
- return true;
- }
+ ASSERT(m_World->IsChunkQueued(a_ChunkX, a_ChunkZ));
- cChunkCoords Coords(a_ChunkX, a_ChunkY, a_ChunkZ);
+ cChunkCoords Coords(a_ChunkX, a_ChunkZ);
// First try the schema that is used for saving
if (m_SaveSchema->LoadChunk(Coords))
@@ -309,7 +301,7 @@ bool cWorldStorage::LoadChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ)
}
// Notify the chunk owner that the chunk failed to load (sets cChunk::m_HasLoadFailed to true):
- m_World->ChunkLoadFailed(a_ChunkX, a_ChunkY, a_ChunkZ);
+ m_World->ChunkLoadFailed(a_ChunkX, a_ChunkZ);
return false;
}
diff --git a/src/WorldStorage/WorldStorage.h b/src/WorldStorage/WorldStorage.h
index dd07ecb64..fc7e9f84c 100644
--- a/src/WorldStorage/WorldStorage.h
+++ b/src/WorldStorage/WorldStorage.h
@@ -64,13 +64,10 @@ public:
cWorldStorage(void);
~cWorldStorage();
- void QueueLoadChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, bool a_Generate); // Queues the chunk for loading; if not loaded, the chunk will be generated if a_Generate is true
- void QueueSaveChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ);
+ void QueueLoadChunk(int a_ChunkX, int a_ChunkZ);
+ void QueueSaveChunk(int a_ChunkX, int a_ChunkZ);
- /// Loads the chunk specified; returns true on success, false on failure
- bool LoadChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ);
-
- void UnqueueLoad(int a_ChunkX, int a_ChunkY, int a_ChunkZ);
+ void UnqueueLoad(int a_ChunkX, int a_ChunkZ);
void UnqueueSave(const cChunkCoords & a_Chunk);
bool Start(cWorld * a_World, const AString & a_StorageSchemaName, int a_StorageCompressionFactor); // Hide the cIsThread's Start() method, we need to provide args
@@ -84,40 +81,10 @@ public:
protected:
- struct sChunkLoad
- {
- int m_ChunkX;
- int m_ChunkY;
- int m_ChunkZ;
- bool m_Generate; // If true, the chunk will be generated if it cannot be loaded
-
- sChunkLoad(int a_ChunkX, int a_ChunkY, int a_ChunkZ, bool a_Generate) : m_ChunkX(a_ChunkX), m_ChunkY(a_ChunkY), m_ChunkZ(a_ChunkZ), m_Generate(a_Generate) {}
-
- bool operator ==(const sChunkLoad other) const
- {
- return (
- (this->m_ChunkX == other.m_ChunkX) &&
- (this->m_ChunkY == other.m_ChunkY) &&
- (this->m_ChunkZ == other.m_ChunkZ)
- );
- }
- } ;
-
- struct FuncTable
- {
- static void Delete(sChunkLoad) {}
- static void Combine(sChunkLoad & a_orig, const sChunkLoad a_new)
- {
- a_orig.m_Generate |= a_new.m_Generate;
- }
- };
-
- typedef cQueue<sChunkLoad, FuncTable> sChunkLoadQueue;
-
cWorld * m_World;
AString m_StorageSchemaName;
- sChunkLoadQueue m_LoadQueue;
+ cChunkCoordsQueue m_LoadQueue;
cChunkCoordsQueue m_SaveQueue;
/// All the storage schemas (all used for loading)
@@ -125,7 +92,11 @@ protected:
/// The one storage schema used for saving
cWSSchema * m_SaveSchema;
+
+ /// Loads the chunk specified; returns true on success, false on failure
+ bool LoadChunk(int a_ChunkX, int a_ChunkZ);
+
void InitSchemas(int a_StorageCompressionFactor);
virtual void Execute(void) override;