diff options
author | Mattes D <github@xoft.cz> | 2020-04-03 08:57:01 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-03 08:57:01 +0200 |
commit | 01b8ed5295875262a91b60af878bf2a18c1b7aae (patch) | |
tree | 52171974791a7529a3a69f9fe20d906158765954 /src | |
parent | Update Core (diff) | |
download | cuberite-01b8ed5295875262a91b60af878bf2a18c1b7aae.tar cuberite-01b8ed5295875262a91b60af878bf2a18c1b7aae.tar.gz cuberite-01b8ed5295875262a91b60af878bf2a18c1b7aae.tar.bz2 cuberite-01b8ed5295875262a91b60af878bf2a18c1b7aae.tar.lz cuberite-01b8ed5295875262a91b60af878bf2a18c1b7aae.tar.xz cuberite-01b8ed5295875262a91b60af878bf2a18c1b7aae.tar.zst cuberite-01b8ed5295875262a91b60af878bf2a18c1b7aae.zip |
Diffstat (limited to '')
93 files changed, 1522 insertions, 1314 deletions
diff --git a/src/Bindings/AllToLua.pkg b/src/Bindings/AllToLua.pkg index 778cdf42c..1af7e8a21 100644 --- a/src/Bindings/AllToLua.pkg +++ b/src/Bindings/AllToLua.pkg @@ -42,7 +42,7 @@ $cfile "Plugin.h" $cfile "PluginLua.h" $cfile "LuaWindow.h" -$cfile "../BlockID.h" +$cfile "../BlockType.h" $cfile "../BlockInfo.h" $cfile "../StringUtils.h" $cfile "../Defines.h" diff --git a/src/Bindings/CMakeLists.txt b/src/Bindings/CMakeLists.txt index 17f2bdf39..ccd3f4dde 100644 --- a/src/Bindings/CMakeLists.txt +++ b/src/Bindings/CMakeLists.txt @@ -79,7 +79,7 @@ set(BINDING_DEPENDENCIES ../BlockEntities/SignEntity.h ../BlockEntities/MobHeadEntity.h ../BlockEntities/FlowerPotEntity.h - ../BlockID.h + ../BlockType.h ../BlockInfo.h ../BoundingBox.h ../ChatColor.h diff --git a/src/Bindings/DeprecatedBindings.cpp b/src/Bindings/DeprecatedBindings.cpp index a297179f0..b9969ca65 100644 --- a/src/Bindings/DeprecatedBindings.cpp +++ b/src/Bindings/DeprecatedBindings.cpp @@ -10,6 +10,7 @@ #include "../Entities/Player.h" #include "LuaState.h" #include "../Tracer.h" +#include "../BlockInfo.h" diff --git a/src/Bindings/PluginManager.h b/src/Bindings/PluginManager.h index 04dbed67d..79b7511ea 100644 --- a/src/Bindings/PluginManager.h +++ b/src/Bindings/PluginManager.h @@ -2,6 +2,7 @@ #pragma once +#include "../BlockType.h" #include "../Defines.h" #include "../FunctionRef.h" diff --git a/src/BlockArea.cpp b/src/BlockArea.cpp index 4a07db39b..bf9c285c1 100644 --- a/src/BlockArea.cpp +++ b/src/BlockArea.cpp @@ -15,6 +15,8 @@ #include "ChunkData.h" #include "BlockEntities/BlockEntity.h" #include "Item.h" +#include "BlockInfo.h" + diff --git a/src/BlockArea.h b/src/BlockArea.h index b7bfded9a..9c0cb4ec9 100644 --- a/src/BlockArea.h +++ b/src/BlockArea.h @@ -14,6 +14,7 @@ #pragma once +#include "BlockType.h" #include "ForEachChunkProvider.h" #include "ChunkDataCallback.h" #include "Cuboid.h" @@ -24,6 +25,7 @@ // fwd: class cCuboid; +class cItem; class cItems; using cBlockEntityCallback = cFunctionRef<bool(cBlockEntity &)>; diff --git a/src/BlockEntities/BeaconEntity.cpp b/src/BlockEntities/BeaconEntity.cpp index 4c830fb61..00ef145fb 100644 --- a/src/BlockEntities/BeaconEntity.cpp +++ b/src/BlockEntities/BeaconEntity.cpp @@ -2,6 +2,7 @@ #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "BeaconEntity.h" +#include "../BlockInfo.h" #include "../BlockArea.h" #include "../Entities/Player.h" #include "../UI/BeaconWindow.h" diff --git a/src/BlockEntities/BedEntity.h b/src/BlockEntities/BedEntity.h index 6878a6429..265ed43dd 100644 --- a/src/BlockEntities/BedEntity.h +++ b/src/BlockEntities/BedEntity.h @@ -4,6 +4,7 @@ #pragma once #include "BlockEntity.h" +#include "../BlockType.h" diff --git a/src/BlockEntities/ChestEntity.cpp b/src/BlockEntities/ChestEntity.cpp index c73ff1985..902c9b17a 100644 --- a/src/BlockEntities/ChestEntity.cpp +++ b/src/BlockEntities/ChestEntity.cpp @@ -2,6 +2,7 @@ #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "ChestEntity.h" +#include "../BlockInfo.h" #include "../Item.h" #include "../Entities/Player.h" #include "../UI/ChestWindow.h" diff --git a/src/BlockEntities/DispenserEntity.cpp b/src/BlockEntities/DispenserEntity.cpp index 268a108c2..95e3c46b9 100644 --- a/src/BlockEntities/DispenserEntity.cpp +++ b/src/BlockEntities/DispenserEntity.cpp @@ -2,13 +2,13 @@ #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "DispenserEntity.h" -#include "../Simulator/FluidSimulator.h" -#include "../Entities/Boat.h" #include "../Chunk.h" - +#include "../BlockInfo.h" #include "../Defines.h" #include "../World.h" +#include "../Entities/Boat.h" #include "../Entities/ProjectileEntity.h" +#include "../Simulator/FluidSimulator.h" diff --git a/src/BlockEntities/EnderChestEntity.cpp b/src/BlockEntities/EnderChestEntity.cpp index 5f9e2d969..c324f1cec 100644 --- a/src/BlockEntities/EnderChestEntity.cpp +++ b/src/BlockEntities/EnderChestEntity.cpp @@ -3,6 +3,7 @@ #include "EnderChestEntity.h" #include "json/json.h" +#include "../BlockInfo.h" #include "../Item.h" #include "../Entities/Player.h" #include "../UI/EnderChestWindow.h" diff --git a/src/BlockEntities/JukeboxEntity.h b/src/BlockEntities/JukeboxEntity.h index 2fbd916eb..532f8905a 100644 --- a/src/BlockEntities/JukeboxEntity.h +++ b/src/BlockEntities/JukeboxEntity.h @@ -2,6 +2,7 @@ #pragma once #include "BlockEntity.h" +#include "../BlockType.h" diff --git a/src/BlockInfo.cpp b/src/BlockInfo.cpp index 7d2ae64a9..86dd2bae6 100644 --- a/src/BlockInfo.cpp +++ b/src/BlockInfo.cpp @@ -1,10 +1,441 @@ - #include "Globals.h" +#include "BlockInfo.h" +#include "BlockType.h" #include "Blocks/BlockHandler.h" + + +bool IsBlockWater(BLOCKTYPE a_BlockType) +{ + return ((a_BlockType == E_BLOCK_WATER) || (a_BlockType == E_BLOCK_STATIONARY_WATER)); +} + + + + + +bool IsBlockIce(BLOCKTYPE a_BlockType) +{ + switch (a_BlockType) + { + case E_BLOCK_ICE: + case E_BLOCK_PACKED_ICE: + case E_BLOCK_FROSTED_ICE: + { + return true; + } + default: + { + return false; + } + } +} + + + + + +bool IsBlockWaterOrIce(BLOCKTYPE a_BlockType) +{ + return (IsBlockWater(a_BlockType) || IsBlockIce(a_BlockType)); +} + + + + + +bool IsBlockLava(BLOCKTYPE a_BlockType) +{ + return ((a_BlockType == E_BLOCK_LAVA) || (a_BlockType == E_BLOCK_STATIONARY_LAVA)); +} + + + + + +bool IsBlockLiquid(BLOCKTYPE a_BlockType) +{ + return IsBlockWater(a_BlockType) || IsBlockLava(a_BlockType); +} + + + + + +bool IsBlockRail(BLOCKTYPE a_BlockType) +{ + switch (a_BlockType) + { + case E_BLOCK_RAIL: + case E_BLOCK_ACTIVATOR_RAIL: + case E_BLOCK_DETECTOR_RAIL: + case E_BLOCK_POWERED_RAIL: + { + return true; + } + default: return false; + } +} + + + + + +bool IsBlockTypeOfDirt(BLOCKTYPE a_BlockType) +{ + switch (a_BlockType) + { + case E_BLOCK_DIRT: + case E_BLOCK_GRASS: + case E_BLOCK_FARMLAND: + case E_BLOCK_GRASS_PATH: + { + return true; + } + } + return false; +} + + + + + +bool IsBlockFence(BLOCKTYPE a_BlockType) +{ + switch (a_BlockType) + { + case E_BLOCK_ACACIA_FENCE: + case E_BLOCK_ACACIA_FENCE_GATE: + case E_BLOCK_BIRCH_FENCE: + case E_BLOCK_BIRCH_FENCE_GATE: + case E_BLOCK_COBBLESTONE_WALL: + case E_BLOCK_DARK_OAK_FENCE: + case E_BLOCK_DARK_OAK_FENCE_GATE: + case E_BLOCK_FENCE: + case E_BLOCK_JUNGLE_FENCE: + case E_BLOCK_JUNGLE_FENCE_GATE: + case E_BLOCK_NETHER_BRICK_FENCE: + case E_BLOCK_OAK_FENCE_GATE: + case E_BLOCK_SPRUCE_FENCE: + case E_BLOCK_SPRUCE_FENCE_GATE: + { + return true; + } + default: + { + return false; + } + } +} + + + + + +bool IsBlockMaterialWood(BLOCKTYPE a_BlockType) +{ + switch (a_BlockType) + { + case E_BLOCK_PLANKS: + case E_BLOCK_LOG: + case E_BLOCK_NOTE_BLOCK: + case E_BLOCK_BOOKCASE: + case E_BLOCK_OAK_WOOD_STAIRS: + case E_BLOCK_CHEST: + case E_BLOCK_CRAFTING_TABLE: + case E_BLOCK_SIGN_POST: + case E_BLOCK_OAK_DOOR: + case E_BLOCK_WALLSIGN: + case E_BLOCK_WOODEN_PRESSURE_PLATE: + case E_BLOCK_JUKEBOX: + case E_BLOCK_FENCE: + case E_BLOCK_TRAPDOOR: + case E_BLOCK_HUGE_BROWN_MUSHROOM: + case E_BLOCK_HUGE_RED_MUSHROOM: + case E_BLOCK_OAK_FENCE_GATE: + case E_BLOCK_DOUBLE_WOODEN_SLAB: + case E_BLOCK_WOODEN_SLAB: + case E_BLOCK_SPRUCE_WOOD_STAIRS: + case E_BLOCK_BIRCH_WOOD_STAIRS: + case E_BLOCK_JUNGLE_WOOD_STAIRS: + case E_BLOCK_TRAPPED_CHEST: + case E_BLOCK_DAYLIGHT_SENSOR: + case E_BLOCK_NEW_LOG: + case E_BLOCK_ACACIA_WOOD_STAIRS: + case E_BLOCK_DARK_OAK_WOOD_STAIRS: + case E_BLOCK_STANDING_BANNER: + case E_BLOCK_WALL_BANNER: + case E_BLOCK_INVERTED_DAYLIGHT_SENSOR: + case E_BLOCK_SPRUCE_FENCE_GATE: + case E_BLOCK_BIRCH_FENCE_GATE: + case E_BLOCK_JUNGLE_FENCE_GATE: + case E_BLOCK_DARK_OAK_FENCE_GATE: + case E_BLOCK_ACACIA_FENCE_GATE: + case E_BLOCK_SPRUCE_FENCE: + case E_BLOCK_BIRCH_FENCE: + case E_BLOCK_JUNGLE_FENCE: + case E_BLOCK_DARK_OAK_FENCE: + case E_BLOCK_ACACIA_FENCE: + case E_BLOCK_SPRUCE_DOOR: + case E_BLOCK_BIRCH_DOOR: + case E_BLOCK_JUNGLE_DOOR: + case E_BLOCK_ACACIA_DOOR: + case E_BLOCK_DARK_OAK_DOOR: + { + return true; + } + default: + { + return false; + } + } +} + + + + + +bool IsBlockMaterialPlants(BLOCKTYPE a_BlockType) +{ + switch (a_BlockType) + { + case E_BLOCK_SAPLING: + case E_BLOCK_DANDELION: + case E_BLOCK_FLOWER: + case E_BLOCK_BROWN_MUSHROOM: + case E_BLOCK_RED_MUSHROOM: + case E_BLOCK_CROPS: + case E_BLOCK_REEDS: + case E_BLOCK_PUMPKIN_STEM: + case E_BLOCK_MELON_STEM: + case E_BLOCK_LILY_PAD: + case E_BLOCK_NETHER_WART: + case E_BLOCK_COCOA_POD: + case E_BLOCK_CARROTS: + case E_BLOCK_POTATOES: + case E_BLOCK_CHORUS_PLANT: + case E_BLOCK_CHORUS_FLOWER: + case E_BLOCK_BEETROOTS: + { + return true; + } + default: + { + return false; + } + } +} + + + + + +bool IsBlockMaterialVine(BLOCKTYPE a_BlockType) +{ + switch (a_BlockType) + { + case E_BLOCK_TALL_GRASS: + case E_BLOCK_DEAD_BUSH: + case E_BLOCK_VINES: + case E_BLOCK_BIG_FLOWER: + { + return true; + } + default: + { + return false; + } + } +} + + + + + +bool IsBlockMaterialIron(BLOCKTYPE a_BlockType) +{ + switch (a_BlockType) + { + case E_BLOCK_LAPIS_BLOCK: + case E_BLOCK_GOLD_BLOCK: + case E_BLOCK_IRON_BLOCK: + case E_BLOCK_DIAMOND_BLOCK: + case E_BLOCK_IRON_DOOR: + case E_BLOCK_IRON_BARS: + case E_BLOCK_BREWING_STAND: + case E_BLOCK_CAULDRON: + case E_BLOCK_EMERALD_BLOCK: + case E_BLOCK_COMMAND_BLOCK: + case E_BLOCK_LIGHT_WEIGHTED_PRESSURE_PLATE: + case E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE: + case E_BLOCK_BLOCK_OF_REDSTONE: + case E_BLOCK_HOPPER: + case E_BLOCK_IRON_TRAPDOOR: + case E_BLOCK_REPEATING_COMMAND_BLOCK: + case E_BLOCK_CHAIN_COMMAND_BLOCK: + case E_BLOCK_STRUCTURE_BLOCK: + { + return true; + } + default: + { + return false; + } + } +} + + + + + +bool IsBlockMaterialLeaves(BLOCKTYPE a_BlockType) +{ + return (a_BlockType == E_BLOCK_LEAVES) || (a_BlockType == E_BLOCK_NEW_LEAVES); +} + + + + + +bool IsBlockMaterialGourd(BLOCKTYPE a_BlockType) +{ + switch (a_BlockType) + { + case E_BLOCK_PUMPKIN: + case E_BLOCK_JACK_O_LANTERN: + case E_BLOCK_MELON: + { + return true; + } + default: + { + return false; + } + } +} + + + + + +bool IsBlockMaterialRock(BLOCKTYPE a_BlockType) +{ + switch (a_BlockType) + { + case E_BLOCK_STONE: + case E_BLOCK_COBBLESTONE: + case E_BLOCK_BEDROCK: + case E_BLOCK_GOLD_ORE: + case E_BLOCK_IRON_ORE: + case E_BLOCK_COAL_ORE: + case E_BLOCK_LAPIS_ORE: + case E_BLOCK_DISPENSER: + case E_BLOCK_SANDSTONE: + case E_BLOCK_DOUBLE_STONE_SLAB: + case E_BLOCK_STONE_SLAB: + case E_BLOCK_BRICK: + case E_BLOCK_MOSSY_COBBLESTONE: + case E_BLOCK_OBSIDIAN: + case E_BLOCK_MOB_SPAWNER: + case E_BLOCK_DIAMOND_ORE: + case E_BLOCK_FURNACE: + case E_BLOCK_LIT_FURNACE: + case E_BLOCK_COBBLESTONE_STAIRS: + case E_BLOCK_STONE_PRESSURE_PLATE: + case E_BLOCK_REDSTONE_ORE: + case E_BLOCK_REDSTONE_ORE_GLOWING: + case E_BLOCK_NETHERRACK: + case E_BLOCK_STONE_BRICKS: + case E_BLOCK_BRICK_STAIRS: + case E_BLOCK_STONE_BRICK_STAIRS: + case E_BLOCK_NETHER_BRICK: + case E_BLOCK_NETHER_BRICK_FENCE: + case E_BLOCK_NETHER_BRICK_STAIRS: + case E_BLOCK_ENCHANTMENT_TABLE: + case E_BLOCK_END_PORTAL_FRAME: + case E_BLOCK_END_STONE: + case E_BLOCK_SANDSTONE_STAIRS: + case E_BLOCK_EMERALD_ORE: + case E_BLOCK_ENDER_CHEST: + case E_BLOCK_COBBLESTONE_WALL: + case E_BLOCK_NETHER_QUARTZ_ORE: + case E_BLOCK_QUARTZ_BLOCK: + case E_BLOCK_QUARTZ_STAIRS: + case E_BLOCK_DROPPER: + case E_BLOCK_STAINED_CLAY: + case E_BLOCK_PRISMARINE_BLOCK: + case E_BLOCK_HARDENED_CLAY: + case E_BLOCK_BLOCK_OF_COAL: + case E_BLOCK_RED_SANDSTONE: + case E_BLOCK_RED_SANDSTONE_STAIRS: + case E_BLOCK_DOUBLE_RED_SANDSTONE_SLAB: + case E_BLOCK_RED_SANDSTONE_SLAB: + case E_BLOCK_PURPUR_BLOCK: + case E_BLOCK_PURPUR_PILLAR: + case E_BLOCK_PURPUR_STAIRS: + case E_BLOCK_PURPUR_DOUBLE_SLAB: + case E_BLOCK_PURPUR_SLAB: + case E_BLOCK_END_BRICKS: + case E_BLOCK_MAGMA: + case E_BLOCK_RED_NETHER_BRICK: + case E_BLOCK_BONE_BLOCK: + case E_BLOCK_OBSERVER: + { + return true; + } + default: + { + return false; + } + } +} + + + + + +//////////////////////////////////////////////////////////////////////////////// +// cBlockInfo: + +cBlockInfo::cBlockInfo(): + m_BlockType(E_BLOCK_STONE), + m_LightValue(0x00), + m_SpreadLightFalloff(0x0f), + m_Transparent(false), + m_OneHitDig(false), + m_PistonBreakable(false), + m_IsRainBlocker(false), + m_IsSkylightDispersant(false), + m_IsSolid(true), + m_UseableBySpectator(false), + m_FullyOccupiesVoxel(false), + m_CanBeTerraformed(false), + m_BlockHeight(1.0), + m_Hardness(0.0f), + m_Handler() +{ +} + + + + + +bool cBlockInfo::IsSnowable(BLOCKTYPE a_BlockType) +{ + return ( + (a_BlockType == E_BLOCK_ICE) || + (a_BlockType == E_BLOCK_LEAVES) || + (!IsTransparent(a_BlockType) && (a_BlockType != E_BLOCK_PACKED_ICE)) + ); +} + + + + + void cBlockInfo::sHandlerDeleter::operator () (cBlockHandler * a_Handler) { delete a_Handler; diff --git a/src/BlockInfo.h b/src/BlockInfo.h index 9ba89858f..9644eb208 100644 --- a/src/BlockInfo.h +++ b/src/BlockInfo.h @@ -37,14 +37,7 @@ public: { return ((Get(a_Type).m_IsSkylightDispersant) || (Get(a_Type).m_SpreadLightFalloff > 1)); } - inline static bool IsSnowable (BLOCKTYPE a_Type) - { - return ( - (a_Type == E_BLOCK_ICE) || - (a_Type == E_BLOCK_LEAVES) || - (!IsTransparent(a_Type) && (a_Type != E_BLOCK_PACKED_ICE)) - ); - } + static bool IsSnowable(BLOCKTYPE a_Type); inline static bool IsSolid (BLOCKTYPE a_Type) { return Get(a_Type).m_IsSolid; } inline static bool IsUseableBySpectator (BLOCKTYPE a_Type) { return Get(a_Type).m_UseableBySpectator; } inline static bool FullyOccupiesVoxel (BLOCKTYPE a_Type) { return Get(a_Type).m_FullyOccupiesVoxel; } @@ -57,24 +50,8 @@ public: inline static cBlockHandler * GetHandler (BLOCKTYPE a_Type) { return Get(a_Type).m_Handler.get(); } /** Creates a default BlockInfo structure, initializes all values to their defaults */ - cBlockInfo(): - m_BlockType(E_BLOCK_STONE), - m_LightValue(0x00), - m_SpreadLightFalloff(0x0f), - m_Transparent(false), - m_OneHitDig(false), - m_PistonBreakable(false), - m_IsRainBlocker(false), - m_IsSkylightDispersant(false), - m_IsSolid(true), - m_UseableBySpectator(false), - m_FullyOccupiesVoxel(false), - m_CanBeTerraformed(false), - m_BlockHeight(1.0), - m_Hardness(0.0f), - m_Handler() - { - } + cBlockInfo(); + private: /** Storage for all the BlockInfo structures. */ @@ -133,6 +110,40 @@ private: +bool IsBlockWater(BLOCKTYPE a_BlockType); + +bool IsBlockIce(BLOCKTYPE a_BlockType); + +bool IsBlockWaterOrIce(BLOCKTYPE a_BlockType); + +bool IsBlockLava(BLOCKTYPE a_BlockType); + +bool IsBlockLiquid(BLOCKTYPE a_BlockType); + +bool IsBlockRail(BLOCKTYPE a_BlockType); + +bool IsBlockTypeOfDirt(BLOCKTYPE a_BlockType); + +bool IsBlockFence(BLOCKTYPE a_BlockType); + +bool IsBlockMaterialWood(BLOCKTYPE a_BlockType); + +bool IsBlockMaterialPlants(BLOCKTYPE a_BlockType); + +bool IsBlockMaterialVine(BLOCKTYPE a_BlockType); + +bool IsBlockMaterialIron(BLOCKTYPE a_BlockType); + +bool IsBlockMaterialLeaves(BLOCKTYPE a_BlockType); + +bool IsBlockMaterialGourd(BLOCKTYPE a_BlockType); + +bool IsBlockMaterialRock(BLOCKTYPE a_BlockType); + + + + + class cBlockInfo::cBlockInfoArray: public std::array<cBlockInfo, 256> { diff --git a/src/BlockID.cpp b/src/BlockType.cpp index 399f9c3f6..cecfb752b 100644 --- a/src/BlockID.cpp +++ b/src/BlockType.cpp @@ -1,6 +1,6 @@ -// BlockID.cpp +// BlockType.cpp -// Implements the helper functions for converting Block ID string to int etc. +// Implements the helper functions for converting Block Type string to int etc. #include "Globals.h" #include "IniFile.h" @@ -291,188 +291,6 @@ AString ItemToFullString(const cItem & a_Item) -eDimension StringToDimension(const AString & a_DimensionString) -{ - // First try decoding as a number - int res; - if (StringToInteger(a_DimensionString, res)) - { - // It was a valid number - return static_cast<eDimension>(res); - } - - // Decode using a built-in map: - static struct - { - eDimension m_Dimension; - const char * m_String; - } DimensionMap [] = - { - { dimOverworld, "Overworld"}, - { dimOverworld, "Normal"}, - { dimOverworld, "World"}, - { dimNether, "Nether"}, - { dimNether, "Hell"}, // Alternate name for Nether - { dimEnd, "End"}, - { dimEnd, "Sky"}, // Old name for End - } ; - for (size_t i = 0; i < ARRAYCOUNT(DimensionMap); i++) - { - if (NoCaseCompare(DimensionMap[i].m_String, a_DimensionString) == 0) - { - return DimensionMap[i].m_Dimension; - } - } // for i - DimensionMap[] - - // Not found - LOGWARNING("Unknown dimension: \"%s\". Setting to Overworld", a_DimensionString.c_str()); - return dimOverworld; -} - - - - - -AString DimensionToString(eDimension a_Dimension) -{ - // Decode using a built-in map: - static struct - { - eDimension m_Dimension; - const char * m_String; - } DimensionMap[] = - { - { dimOverworld, "Overworld" }, - { dimNether, "Nether" }, - { dimEnd, "End" }, - }; - - for (size_t i = 0; i < ARRAYCOUNT(DimensionMap); i++) - { - if (DimensionMap[i].m_Dimension == a_Dimension) - { - return DimensionMap[i].m_String; - } - } // for i - DimensionMap[] - - // Not found - LOGWARNING("Unknown dimension: \"%i\". Setting to Overworld", static_cast<int>(a_Dimension)); - return "Overworld"; -} - - - - - -/** Translates damage type constant to a string representation (built-in) */ -AString DamageTypeToString(eDamageType a_DamageType) -{ - // Make sure to keep this alpha-sorted. - switch (a_DamageType) - { - case dtAdmin: return "dtAdmin"; - case dtAttack: return "dtAttack"; - case dtCactusContact: return "dtCactusContact"; - case dtDrowning: return "dtDrowning"; - case dtEnderPearl: return "dtEnderPearl"; - case dtFalling: return "dtFalling"; - case dtFireContact: return "dtFireContact"; - case dtInVoid: return "dtInVoid"; - case dtLavaContact: return "dtLavaContact"; - case dtLightning: return "dtLightning"; - case dtOnFire: return "dtOnFire"; - case dtPoisoning: return "dtPoisoning"; - case dtWithering: return "dtWithering"; - case dtPotionOfHarming: return "dtPotionOfHarming"; - case dtRangedAttack: return "dtRangedAttack"; - case dtStarving: return "dtStarving"; - case dtSuffocating: return "dtSuffocation"; - case dtExplosion: return "dtExplosion"; - } - UNREACHABLE("Unsupported damage type"); -} - - - - - -/** Translates a damage type string to damage type. Takes either a number or a damage type alias (built-in). -Returns -1 on failure. */ -eDamageType StringToDamageType(const AString & a_DamageTypeString) -{ - // First try decoding as a number: - int res; - if (!StringToInteger(a_DamageTypeString, res)) - { - // It was a valid number - return static_cast<eDamageType>(res); - } - - // Decode using a built-in map: - static struct - { - eDamageType m_DamageType; - const char * m_String; - } DamageTypeMap [] = - { - // Cannonical names: - { dtAttack, "dtAttack"}, - { dtRangedAttack, "dtRangedAttack"}, - { dtLightning, "dtLightning"}, - { dtFalling, "dtFalling"}, - { dtDrowning, "dtDrowning"}, - { dtSuffocating, "dtSuffocation"}, - { dtStarving, "dtStarving"}, - { dtCactusContact, "dtCactusContact"}, - { dtLavaContact, "dtLavaContact"}, - { dtPoisoning, "dtPoisoning"}, - { dtWithering, "dtWithering"}, - { dtOnFire, "dtOnFire"}, - { dtFireContact, "dtFireContact"}, - { dtInVoid, "dtInVoid"}, - { dtPotionOfHarming, "dtPotionOfHarming"}, - { dtAdmin, "dtAdmin"}, - { dtExplosion, "dtExplosion"}, - - // Common synonyms: - { dtAttack, "dtPawnAttack"}, - { dtAttack, "dtEntityAttack"}, - { dtAttack, "dtMob"}, - { dtAttack, "dtMobAttack"}, - { dtRangedAttack, "dtArrowAttack"}, - { dtRangedAttack, "dtArrow"}, - { dtRangedAttack, "dtProjectile"}, - { dtFalling, "dtFall"}, - { dtDrowning, "dtDrown"}, - { dtSuffocating, "dtSuffocation"}, - { dtStarving, "dtStarvation"}, - { dtStarving, "dtHunger"}, - { dtCactusContact, "dtCactus"}, - { dtCactusContact, "dtCactuses"}, - { dtCactusContact, "dtCacti"}, - { dtLavaContact, "dtLava"}, - { dtPoisoning, "dtPoison"}, - { dtWithering, "dtWither"}, - { dtOnFire, "dtBurning"}, - { dtFireContact, "dtInFire"}, - { dtAdmin, "dtPlugin"}, - } ; - for (size_t i = 0; i < ARRAYCOUNT(DamageTypeMap); i++) - { - if (NoCaseCompare(DamageTypeMap[i].m_String, a_DamageTypeString) == 0) - { - return DamageTypeMap[i].m_DamageType; - } - } // for i - DamageTypeMap[] - - // Not found: - return static_cast<eDamageType>(-1); -} - - - - - cItem GetIniItemSet(cIniFile & a_IniFile, const char * a_Section, const char * a_Key, const char * a_Default) { AString ItemStr = a_IniFile.GetValueSet(a_Section, a_Key, a_Default); diff --git a/src/BlockID.h b/src/BlockType.h index 07ef043c0..bd4b0c625 100644 --- a/src/BlockID.h +++ b/src/BlockType.h @@ -4,7 +4,7 @@ // tolua_begin -enum ENUM_BLOCK_ID : BLOCKTYPE +enum ENUM_BLOCK_TYPE : BLOCKTYPE { E_BLOCK_AIR = 0, E_BLOCK_STONE = 1, @@ -290,7 +290,7 @@ enum ENUM_BLOCK_ID : BLOCKTYPE -enum ENUM_ITEM_ID : short +enum ENUM_ITEM_TYPE : short { E_ITEM_EMPTY = -1, @@ -1119,124 +1119,6 @@ enum ENUM_ITEM_META : short E_META_SPAWN_EGG_ENDER_CRYSTAL = 200, } ; - - - - -/** Dimension of a world */ -enum eDimension -{ - dimNether = -1, - dimOverworld = 0, - dimEnd = 1, - dimNotSet = 255, // For things that need an "indeterminate" state, such as cProtocol's LastSentDimension -} ; - - - - - -/** Damage type, used in the TakeDamageInfo structure and related functions */ -enum eDamageType -{ - // Canonical names for the types (as documented in the plugin wiki): - dtAttack, // Being attacked by a mob - dtRangedAttack, // Being attacked by a projectile, possibly from a mob - dtLightning, // Hit by a lightning strike - dtFalling, // Falling down; dealt when hitting the ground - dtDrowning, // Drowning in water / lava - dtSuffocating, // Suffocating inside a block - dtStarving, // Hunger - dtCactusContact, // Contact with a cactus block - dtLavaContact, // Contact with a lava block - dtPoisoning, // Having the poison effect - dtWithering, // Having the wither effect - dtOnFire, // Being on fire - dtFireContact, // Standing inside a fire block - dtInVoid, // Falling into the Void (Y < 0) - dtPotionOfHarming, - dtEnderPearl, // Thrown an ender pearl, teleported by it - dtAdmin, // Damage applied by an admin command - dtExplosion, // Damage applied by an explosion - - // Some common synonyms: - dtPawnAttack = dtAttack, - dtEntityAttack = dtAttack, - dtMob = dtAttack, - dtMobAttack = dtAttack, - dtArrowAttack = dtRangedAttack, - dtArrow = dtRangedAttack, - dtProjectile = dtRangedAttack, - dtFall = dtFalling, - dtDrown = dtDrowning, - dtSuffocation = dtSuffocating, - dtStarvation = dtStarving, - dtHunger = dtStarving, - dtCactus = dtCactusContact, - dtCactuses = dtCactusContact, - dtCacti = dtCactusContact, - dtLava = dtLavaContact, - dtPoison = dtPoisoning, - dtWither = dtWithering, - dtBurning = dtOnFire, - dtInFire = dtFireContact, - dtPlugin = dtAdmin, -} ; - - - - - -/** The source of an explosion. -Also dictates the type of the additional data passed to the explosion handlers: -| esBed | Vector3i * | Bed exploding in the Nether or in the End -| esEnderCrystal | cEnderCrystal * | -| esGhastFireball | cGhastFireballEntity * | -| esMonster | cMonster * | -| esOther | nullptr | Any other explosion unaccounted for -| esPlugin | nullptr | Explosion primarily attributed to a plugin -| esPrimedTNT | cTNTEntity * | -| esWitherBirth | cMonster * | -| esWitherSkull | cProjectileEntity * | -*/ -enum eExplosionSource -{ - esBed, - esEnderCrystal, - esGhastFireball, - esMonster, - esOther, - esPlugin, - esPrimedTNT, - esWitherBirth, - esWitherSkull, - esMax, -} ; - - - - - -enum eShrapnelLevel -{ - slNone, - slGravityAffectedOnly, - slAll -} ; - - - - - -enum eSpreadSource -{ - ssFireSpread, - ssGrassSpread, - ssMushroomSpread, - ssMycelSpread, - ssVineSpread, -} ; - // tolua_end @@ -1267,19 +1149,6 @@ extern AString ItemTypeToString(short a_ItemType); /** Translates a full item into a fully-specified string (including meta and count). If the ItemType is not recognized, the ItemType number is output into the string. */ extern AString ItemToFullString(const cItem & a_Item); -/** Translates a dimension string to dimension enum. Takes either a number or a dimension alias (built-in). Returns dimOverworld on failure */ -extern eDimension StringToDimension(const AString & a_DimensionString); - -/** Translates a dimension enum to dimension string. -Takes an eDimension enum value and returns "Overworld" on failure. */ -extern AString DimensionToString(eDimension a_Dimension); - -/** Translates damage type constant to a string representation (built-in). */ -extern AString DamageTypeToString(eDamageType a_DamageType); - -/** Translates a damage type string to damage type. Takes either a number or a damage type alias (built-in). Returns -1 on failure */ -extern eDamageType StringToDamageType(const AString & a_DamageString); - /** Returns a cItem representing the item described in an IniFile's value; if the value doesn't exist, creates it with the provided default. */ extern cItem GetIniItemSet(cIniFile & a_IniFile, const char * a_Section, const char * a_Key, const char * a_Default); diff --git a/src/BlockTypeRegistry.h b/src/BlockTypeRegistry.h index 2048105df..529e13eb2 100644 --- a/src/BlockTypeRegistry.h +++ b/src/BlockTypeRegistry.h @@ -12,6 +12,7 @@ // fwd: +class cBlockHandler; class BlockState; diff --git a/src/Blocks/BlockBigFlower.h b/src/Blocks/BlockBigFlower.h index f81b16bd2..720c8f40a 100644 --- a/src/Blocks/BlockBigFlower.h +++ b/src/Blocks/BlockBigFlower.h @@ -3,6 +3,7 @@ #include "BlockHandler.h" #include "ChunkInterface.h" +#include "../BlockInfo.h" #include "../Items/ItemHandler.h" diff --git a/src/Blocks/BlockButton.h b/src/Blocks/BlockButton.h index 8f90f84e5..10d3569d0 100644 --- a/src/Blocks/BlockButton.h +++ b/src/Blocks/BlockButton.h @@ -1,6 +1,7 @@ #pragma once #include "BlockHandler.h" +#include "../BlockInfo.h" #include "../Chunk.h" #include "Mixins.h" diff --git a/src/Blocks/BlockCactus.h b/src/Blocks/BlockCactus.h index 8c24cda9f..a00f5b6d4 100644 --- a/src/Blocks/BlockCactus.h +++ b/src/Blocks/BlockCactus.h @@ -1,6 +1,7 @@ #pragma once #include "BlockPlant.h" +#include "../BlockInfo.h" diff --git a/src/Blocks/BlockDoor.h b/src/Blocks/BlockDoor.h index 596e69793..ccb34c5a9 100644 --- a/src/Blocks/BlockDoor.h +++ b/src/Blocks/BlockDoor.h @@ -2,6 +2,7 @@ #pragma once #include "BlockHandler.h" +#include "../BlockInfo.h" #include "../Entities/Player.h" #include "../Chunk.h" #include "Mixins.h" diff --git a/src/Blocks/BlockHandler.h b/src/Blocks/BlockHandler.h index 789ef4dd5..75f6610ce 100644 --- a/src/Blocks/BlockHandler.h +++ b/src/Blocks/BlockHandler.h @@ -2,7 +2,7 @@ #pragma once #include "../Defines.h" - +#include "../Item.h" #include "../BoundingBox.h" diff --git a/src/Blocks/BlockPiston.cpp b/src/Blocks/BlockPiston.cpp index 5c929c4c5..5a18cffac 100644 --- a/src/Blocks/BlockPiston.cpp +++ b/src/Blocks/BlockPiston.cpp @@ -1,6 +1,7 @@ #include "Globals.h" #include "BlockPiston.h" +#include "../BlockInfo.h" #include "../Item.h" #include "../World.h" #include "../Entities/Player.h" diff --git a/src/Blocks/BlockSlab.h b/src/Blocks/BlockSlab.h index a136cd6e0..ef58c243c 100644 --- a/src/Blocks/BlockSlab.h +++ b/src/Blocks/BlockSlab.h @@ -11,7 +11,9 @@ #include "BlockHandler.h" #include "ChunkInterface.h" +#include "../BlockInfo.h" #include "../Entities/Player.h" +#include "../BlockInfo.h" diff --git a/src/Blocks/BlockStems.h b/src/Blocks/BlockStems.h index 0eb091b3c..202d71b19 100644 --- a/src/Blocks/BlockStems.h +++ b/src/Blocks/BlockStems.h @@ -10,7 +10,7 @@ /** Handler for stems from which produce grows in an adjacent block (melon, pumpkin) after it becomes ripe (meta == 7). ProduceBlockType is the blocktype for the produce to be grown. StemPickupType is the item type for the pickup resulting from breaking the stem. */ -template <BLOCKTYPE ProduceBlockType, ENUM_ITEM_ID StemPickupType> +template <BLOCKTYPE ProduceBlockType, ENUM_ITEM_TYPE StemPickupType> class cBlockStemsHandler: public cBlockPlant<true> { diff --git a/src/Blocks/ChunkInterface.cpp b/src/Blocks/ChunkInterface.cpp index eff3f4da9..fd64ee9fc 100644 --- a/src/Blocks/ChunkInterface.cpp +++ b/src/Blocks/ChunkInterface.cpp @@ -6,6 +6,7 @@ #include "WorldInterface.h" #include "../ChunkMap.h" #include "../World.h" +#include "../BlockInfo.h" diff --git a/src/Blocks/ChunkInterface.h b/src/Blocks/ChunkInterface.h index 4ff2fb3fe..345fca4d2 100644 --- a/src/Blocks/ChunkInterface.h +++ b/src/Blocks/ChunkInterface.h @@ -5,10 +5,17 @@ + +// fwd: +class cItem; class cChunkMap; class cWorldInterface; class cPlayer; + + + + class cChunkInterface: public cForEachChunkProvider { diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 92f7b11b5..5012fc3e5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -15,9 +15,9 @@ set(FOLDERS SET (SRCS BiomeDef.cpp BlockArea.cpp - BlockID.cpp BlockInfo.cpp BlockState.cpp + BlockType.cpp BlockTypePalette.cpp BlockTypeRegistry.cpp BrewingRecipes.cpp @@ -38,6 +38,7 @@ SET (SRCS CraftingRecipes.cpp Cuboid.cpp DeadlockDetect.cpp + Defines.cpp Enchantments.cpp FastRandom.cpp FurnaceRecipe.cpp @@ -85,11 +86,11 @@ SET (HDRS AllocationPool.h BiomeDef.h BlockArea.h - BlockID.h BlockInServerPluginInterface.h BlockInfo.h BlockState.h BlockTracer.h + BlockType.h BlockTypePalette.h BlockTypeRegistry.h BrewingRecipes.h @@ -179,7 +180,7 @@ include_directories (SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/../lib/TCLAP/include") configure_file("BuildInfo.h.cmake" "${CMAKE_BINARY_DIR}/include/BuildInfo.h") if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - set_source_files_properties(BlockID.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=global-constructors") + set_source_files_properties(BlockType.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=global-constructors") set_source_files_properties(ByteBuffer.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=global-constructors") set_source_files_properties(ClientHandle.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=global-constructors ") set_source_files_properties(Statistics.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=global-constructors") diff --git a/src/Chunk.cpp b/src/Chunk.cpp index 9dc0e8aee..d9601e451 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -7,6 +7,7 @@ #include "Chunk.h" +#include "BlockInfo.h" #include "World.h" #include "ClientHandle.h" #include "Server.h" diff --git a/src/ChunkData.cpp b/src/ChunkData.cpp index a095880c3..a480c2c66 100644 --- a/src/ChunkData.cpp +++ b/src/ChunkData.cpp @@ -5,6 +5,7 @@ #include "Globals.h" #include "ChunkData.h" +#include "BlockType.h" diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp index fdaf7390d..cb6ba07ca 100644 --- a/src/ChunkMap.cpp +++ b/src/ChunkMap.cpp @@ -2,6 +2,7 @@ #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "ChunkMap.h" +#include "BlockInfo.h" #include "World.h" #include "Root.h" #include "Entities/Player.h" diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 9a92a3005..92ed2013f 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -1,6 +1,7 @@ #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "ClientHandle.h" +#include "BlockInfo.h" #include "Server.h" #include "World.h" #include "Chunk.h" diff --git a/src/CraftingRecipes.cpp b/src/CraftingRecipes.cpp index e986a2f87..1a8a68523 100644 --- a/src/CraftingRecipes.cpp +++ b/src/CraftingRecipes.cpp @@ -83,7 +83,7 @@ cItem & cCraftingGrid::GetItem(int x, int y) const -void cCraftingGrid::SetItem(int x, int y, ENUM_ITEM_ID a_ItemType, char a_ItemCount, short a_ItemHealth) +void cCraftingGrid::SetItem(int x, int y, ENUM_ITEM_TYPE a_ItemType, char a_ItemCount, short a_ItemHealth) { // Accessible through scripting, must verify parameters: if ((x < 0) || (x >= m_Width) || (y < 0) || (y >= m_Height)) @@ -235,7 +235,7 @@ void cCraftingRecipe::Clear(void) -void cCraftingRecipe::SetResult(ENUM_ITEM_ID a_ItemType, char a_ItemCount, short a_ItemHealth) +void cCraftingRecipe::SetResult(ENUM_ITEM_TYPE a_ItemType, char a_ItemCount, short a_ItemHealth) { m_Result = cItem(a_ItemType, a_ItemCount, a_ItemHealth); } diff --git a/src/CraftingRecipes.h b/src/CraftingRecipes.h index 1c4e87461..9659e53fc 100644 --- a/src/CraftingRecipes.h +++ b/src/CraftingRecipes.h @@ -33,7 +33,7 @@ public: int GetWidth (void) const {return m_Width; } int GetHeight(void) const {return m_Height; } cItem & GetItem (int x, int y) const; - void SetItem (int x, int y, ENUM_ITEM_ID a_ItemType, char a_ItemCount, short a_ItemHealth); + void SetItem (int x, int y, ENUM_ITEM_TYPE a_ItemType, char a_ItemCount, short a_ItemHealth); void SetItem (int x, int y, const cItem & a_Item); void Clear (void); @@ -72,13 +72,13 @@ public: int GetIngredientsHeight(void) const {return m_Ingredients.GetHeight(); } cItem & GetIngredient (int x, int y) const {return m_Ingredients.GetItem(x, y); } const cItem & GetResult (void) const {return m_Result; } - void SetResult (ENUM_ITEM_ID a_ItemType, char a_ItemCount, short a_ItemHealth); + void SetResult (ENUM_ITEM_TYPE a_ItemType, char a_ItemCount, short a_ItemHealth); void SetResult (const cItem & a_Item) { m_Result = a_Item; } - void SetIngredient (int x, int y, ENUM_ITEM_ID a_ItemType, char a_ItemCount, short a_ItemHealth) + void SetIngredient (int x, int y, ENUM_ITEM_TYPE a_ItemType, char a_ItemCount, short a_ItemHealth) { m_Ingredients.SetItem(x, y, a_ItemType, a_ItemCount, a_ItemHealth); } diff --git a/src/Defines.cpp b/src/Defines.cpp new file mode 100644 index 000000000..4e0ad775a --- /dev/null +++ b/src/Defines.cpp @@ -0,0 +1,627 @@ +#include "Globals.h" + +#include "Defines.h" +#include "BlockType.h" + + + + + +const char * ClickActionToString(int a_ClickAction) +{ + switch (a_ClickAction) + { + case caLeftClick: return "caLeftClick"; + case caRightClick: return "caRightClick"; + case caShiftLeftClick: return "caShiftLeftClick"; + case caShiftRightClick: return "caShiftRightClick"; + case caNumber1: return "caNumber1"; + case caNumber2: return "caNumber2"; + case caNumber3: return "caNumber3"; + case caNumber4: return "caNumber4"; + case caNumber5: return "caNumber5"; + case caNumber6: return "caNumber6"; + case caNumber7: return "caNumber7"; + case caNumber8: return "caNumber8"; + case caNumber9: return "caNumber9"; + case caMiddleClick: return "caMiddleClick"; + case caDropKey: return "caDropKey"; + case caCtrlDropKey: return "caCtrlDropKey"; + case caLeftClickOutside: return "caLeftClickOutside"; + case caRightClickOutside: return "caRightClickOutside"; + case caLeftClickOutsideHoldNothing: return "caLeftClickOutsideHoldNothing"; + case caRightClickOutsideHoldNothing: return "caRightClickOutsideHoldNothing"; + case caLeftPaintBegin: return "caLeftPaintBegin"; + case caRightPaintBegin: return "caRightPaintBegin"; + case caMiddlePaintBegin: return "caMiddlePaintBegin"; + case caLeftPaintProgress: return "caLeftPaintProgress"; + case caRightPaintProgress: return "caRightPaintProgress"; + case caMiddlePaintProgress: return "caMiddlePaintProgress"; + case caLeftPaintEnd: return "caLeftPaintEnd"; + case caRightPaintEnd: return "caRightPaintEnd"; + case caMiddlePaintEnd: return "caMiddlePaintEnd"; + case caDblClick: return "caDblClick"; + + case caUnknown: return "caUnknown"; + } + UNREACHABLE("Unknown click action"); +} + + + + + +/** Returns a blockface mirrored around the Y axis (doesn't change up / down). */ +eBlockFace MirrorBlockFaceY(eBlockFace a_BlockFace) +{ + switch (a_BlockFace) + { + case BLOCK_FACE_XM: return BLOCK_FACE_XP; + case BLOCK_FACE_XP: return BLOCK_FACE_XM; + case BLOCK_FACE_ZM: return BLOCK_FACE_ZP; + case BLOCK_FACE_ZP: return BLOCK_FACE_ZM; + case BLOCK_FACE_NONE: + case BLOCK_FACE_YM: + case BLOCK_FACE_YP: + { + return a_BlockFace; + } + } + UNREACHABLE("Unsupported block face"); +} + + + + + +/** Returns a blockface rotated around the Y axis counter-clockwise. */ +eBlockFace RotateBlockFaceCCW(eBlockFace a_BlockFace) +{ + switch (a_BlockFace) + { + case BLOCK_FACE_XM: return BLOCK_FACE_ZP; + case BLOCK_FACE_XP: return BLOCK_FACE_ZM; + case BLOCK_FACE_ZM: return BLOCK_FACE_XM; + case BLOCK_FACE_ZP: return BLOCK_FACE_XP; + case BLOCK_FACE_NONE: + case BLOCK_FACE_YM: + case BLOCK_FACE_YP: + { + return a_BlockFace; + } + } + UNREACHABLE("Unsupported block face"); +} + + + + + +eBlockFace RotateBlockFaceCW(eBlockFace a_BlockFace) +{ + switch (a_BlockFace) + { + case BLOCK_FACE_XM: return BLOCK_FACE_ZM; + case BLOCK_FACE_XP: return BLOCK_FACE_ZP; + case BLOCK_FACE_ZM: return BLOCK_FACE_XP; + case BLOCK_FACE_ZP: return BLOCK_FACE_XM; + case BLOCK_FACE_NONE: + case BLOCK_FACE_YM: + case BLOCK_FACE_YP: + { + return a_BlockFace; + } + } + UNREACHABLE("Unsupported block face"); +} + + + + + +eBlockFace ReverseBlockFace(eBlockFace a_BlockFace) +{ + switch (a_BlockFace) + { + case BLOCK_FACE_YP: return BLOCK_FACE_YM; + case BLOCK_FACE_XP: return BLOCK_FACE_XM; + case BLOCK_FACE_ZP: return BLOCK_FACE_ZM; + case BLOCK_FACE_YM: return BLOCK_FACE_YP; + case BLOCK_FACE_XM: return BLOCK_FACE_XP; + case BLOCK_FACE_ZM: return BLOCK_FACE_ZP; + case BLOCK_FACE_NONE: return a_BlockFace; + } + UNREACHABLE("Unsupported block face"); +} + + + + + +/** Returns the textual representation of the BlockFace constant. */ +AString BlockFaceToString(eBlockFace a_BlockFace) +{ + switch (a_BlockFace) + { + case BLOCK_FACE_XM: return "BLOCK_FACE_XM"; + case BLOCK_FACE_XP: return "BLOCK_FACE_XP"; + case BLOCK_FACE_YM: return "BLOCK_FACE_YM"; + case BLOCK_FACE_YP: return "BLOCK_FACE_YP"; + case BLOCK_FACE_ZM: return "BLOCK_FACE_ZM"; + case BLOCK_FACE_ZP: return "BLOCK_FACE_ZP"; + case BLOCK_FACE_NONE: return "BLOCK_FACE_NONE"; + } + UNREACHABLE("Unsupported block face"); +} + + + + + +bool IsValidBlock(int a_BlockType) +{ + if ( + ( + (a_BlockType > -1) && + (a_BlockType <= E_BLOCK_MAX_TYPE_ID) + ) || + (a_BlockType == 255) // the blocks 253-254 don't exist yet -> https://minecraft.gamepedia.com/Data_values#Block_IDs + ) + { + return true; + } + return false; +} + + + + + +bool IsValidItem(int a_ItemType) +{ + if ( + ((a_ItemType >= E_ITEM_FIRST) && (a_ItemType <= E_ITEM_MAX_CONSECUTIVE_TYPE_ID)) || // Basic items range + ((a_ItemType >= E_ITEM_FIRST_DISC) && (a_ItemType <= E_ITEM_LAST_DISC)) // Music discs' special range + ) + { + return true; + } + + if (a_ItemType == 0) + { + return false; + } + + return IsValidBlock(a_ItemType); +} + + + + + +eDimension StringToDimension(const AString & a_DimensionString) +{ + // First try decoding as a number + int res; + if (StringToInteger(a_DimensionString, res)) + { + // It was a valid number + return static_cast<eDimension>(res); + } + + // Decode using a built-in map: + static struct + { + eDimension m_Dimension; + const char * m_String; + } DimensionMap [] = + { + { dimOverworld, "Overworld"}, + { dimOverworld, "Normal"}, + { dimOverworld, "World"}, + { dimNether, "Nether"}, + { dimNether, "Hell"}, // Alternate name for Nether + { dimEnd, "End"}, + { dimEnd, "Sky"}, // Old name for End + } ; + for (size_t i = 0; i < ARRAYCOUNT(DimensionMap); i++) + { + if (NoCaseCompare(DimensionMap[i].m_String, a_DimensionString) == 0) + { + return DimensionMap[i].m_Dimension; + } + } // for i - DimensionMap[] + + // Not found + LOGWARNING("Unknown dimension: \"%s\". Setting to Overworld", a_DimensionString.c_str()); + return dimOverworld; +} + + + + + +AString DimensionToString(eDimension a_Dimension) +{ + // Decode using a built-in map: + static struct + { + eDimension m_Dimension; + const char * m_String; + } DimensionMap[] = + { + { dimOverworld, "Overworld" }, + { dimNether, "Nether" }, + { dimEnd, "End" }, + }; + + for (size_t i = 0; i < ARRAYCOUNT(DimensionMap); i++) + { + if (DimensionMap[i].m_Dimension == a_Dimension) + { + return DimensionMap[i].m_String; + } + } // for i - DimensionMap[] + + // Not found + LOGWARNING("Unknown dimension: \"%i\". Setting to Overworld", static_cast<int>(a_Dimension)); + return "Overworld"; +} + + + + + +AString DamageTypeToString(eDamageType a_DamageType) +{ + // Make sure to keep this alpha-sorted. + switch (a_DamageType) + { + case dtAdmin: return "dtAdmin"; + case dtAttack: return "dtAttack"; + case dtCactusContact: return "dtCactusContact"; + case dtDrowning: return "dtDrowning"; + case dtEnderPearl: return "dtEnderPearl"; + case dtFalling: return "dtFalling"; + case dtFireContact: return "dtFireContact"; + case dtInVoid: return "dtInVoid"; + case dtLavaContact: return "dtLavaContact"; + case dtLightning: return "dtLightning"; + case dtOnFire: return "dtOnFire"; + case dtPoisoning: return "dtPoisoning"; + case dtWithering: return "dtWithering"; + case dtPotionOfHarming: return "dtPotionOfHarming"; + case dtRangedAttack: return "dtRangedAttack"; + case dtStarving: return "dtStarving"; + case dtSuffocating: return "dtSuffocation"; + case dtExplosion: return "dtExplosion"; + } + UNREACHABLE("Unsupported damage type"); +} + + + + + +eDamageType StringToDamageType(const AString & a_DamageTypeString) +{ + // First try decoding as a number: + int res; + if (!StringToInteger(a_DamageTypeString, res)) + { + // It was a valid number + return static_cast<eDamageType>(res); + } + + // Decode using a built-in map: + static struct + { + eDamageType m_DamageType; + const char * m_String; + } DamageTypeMap [] = + { + // Cannonical names: + { dtAttack, "dtAttack"}, + { dtRangedAttack, "dtRangedAttack"}, + { dtLightning, "dtLightning"}, + { dtFalling, "dtFalling"}, + { dtDrowning, "dtDrowning"}, + { dtSuffocating, "dtSuffocation"}, + { dtStarving, "dtStarving"}, + { dtCactusContact, "dtCactusContact"}, + { dtLavaContact, "dtLavaContact"}, + { dtPoisoning, "dtPoisoning"}, + { dtWithering, "dtWithering"}, + { dtOnFire, "dtOnFire"}, + { dtFireContact, "dtFireContact"}, + { dtInVoid, "dtInVoid"}, + { dtPotionOfHarming, "dtPotionOfHarming"}, + { dtAdmin, "dtAdmin"}, + { dtExplosion, "dtExplosion"}, + + // Common synonyms: + { dtAttack, "dtPawnAttack"}, + { dtAttack, "dtEntityAttack"}, + { dtAttack, "dtMob"}, + { dtAttack, "dtMobAttack"}, + { dtRangedAttack, "dtArrowAttack"}, + { dtRangedAttack, "dtArrow"}, + { dtRangedAttack, "dtProjectile"}, + { dtFalling, "dtFall"}, + { dtDrowning, "dtDrown"}, + { dtSuffocating, "dtSuffocation"}, + { dtStarving, "dtStarvation"}, + { dtStarving, "dtHunger"}, + { dtCactusContact, "dtCactus"}, + { dtCactusContact, "dtCactuses"}, + { dtCactusContact, "dtCacti"}, + { dtLavaContact, "dtLava"}, + { dtPoisoning, "dtPoison"}, + { dtWithering, "dtWither"}, + { dtOnFire, "dtBurning"}, + { dtFireContact, "dtInFire"}, + { dtAdmin, "dtPlugin"}, + } ; + for (size_t i = 0; i < ARRAYCOUNT(DamageTypeMap); i++) + { + if (NoCaseCompare(DamageTypeMap[i].m_String, a_DamageTypeString) == 0) + { + return DamageTypeMap[i].m_DamageType; + } + } // for i - DamageTypeMap[] + + // Not found: + return static_cast<eDamageType>(-1); +} + + + + + +void AddFaceDirection(int & a_BlockX, int & a_BlockY, int & a_BlockZ, eBlockFace a_BlockFace, bool a_bInverse) +{ + if (!a_bInverse) + { + switch (a_BlockFace) + { + case BLOCK_FACE_YP: a_BlockY++; break; + case BLOCK_FACE_YM: a_BlockY--; break; + case BLOCK_FACE_ZM: a_BlockZ--; break; + case BLOCK_FACE_ZP: a_BlockZ++; break; + case BLOCK_FACE_XP: a_BlockX++; break; + case BLOCK_FACE_XM: a_BlockX--; break; + case BLOCK_FACE_NONE: + { + LOGWARNING("%s: Unknown face: %d", __FUNCTION__, a_BlockFace); + ASSERT(!"AddFaceDirection(): Unknown face"); + break; + } + } + } + else + { + switch (a_BlockFace) + { + case BLOCK_FACE_YP: a_BlockY--; break; + case BLOCK_FACE_YM: a_BlockY++; break; + case BLOCK_FACE_ZM: a_BlockZ++; break; + case BLOCK_FACE_ZP: a_BlockZ--; break; + case BLOCK_FACE_XP: a_BlockX--; break; + case BLOCK_FACE_XM: a_BlockX++; break; + case BLOCK_FACE_NONE: + { + LOGWARNING("%s: Unknown inv face: %d", __FUNCTION__, a_BlockFace); + ASSERT(!"AddFaceDirection(): Unknown face"); + break; + } + } + } +} + + + + + +bool ItemCategory::IsPickaxe(short a_ItemType) +{ + switch (a_ItemType) + { + case E_ITEM_WOODEN_PICKAXE: + case E_ITEM_STONE_PICKAXE: + case E_ITEM_IRON_PICKAXE: + case E_ITEM_GOLD_PICKAXE: + case E_ITEM_DIAMOND_PICKAXE: + { + return true; + } + default: + { + return false; + } + } +} + + + + + +bool ItemCategory::IsAxe(short a_ItemType) +{ + switch (a_ItemType) + { + case E_ITEM_WOODEN_AXE: + case E_ITEM_STONE_AXE: + case E_ITEM_IRON_AXE: + case E_ITEM_GOLD_AXE: + case E_ITEM_DIAMOND_AXE: + { + return true; + } + default: + { + return false; + } + } +} + + + + + +bool ItemCategory::IsSword(short a_ItemID) +{ + return (a_ItemID == E_ITEM_WOODEN_SWORD) + || (a_ItemID == E_ITEM_STONE_SWORD) + || (a_ItemID == E_ITEM_IRON_SWORD) + || (a_ItemID == E_ITEM_GOLD_SWORD) + || (a_ItemID == E_ITEM_DIAMOND_SWORD); +} + + + + + +bool ItemCategory::IsHoe(short a_ItemID) +{ + return (a_ItemID == E_ITEM_WOODEN_HOE) + || (a_ItemID == E_ITEM_STONE_HOE) + || (a_ItemID == E_ITEM_IRON_HOE) + || (a_ItemID == E_ITEM_GOLD_HOE) + || (a_ItemID == E_ITEM_DIAMOND_HOE); +} + + + + + +bool ItemCategory::IsShovel(short a_ItemID) +{ + return (a_ItemID == E_ITEM_WOODEN_SHOVEL) + || (a_ItemID == E_ITEM_STONE_SHOVEL) + || (a_ItemID == E_ITEM_IRON_SHOVEL) + || (a_ItemID == E_ITEM_GOLD_SHOVEL) + || (a_ItemID == E_ITEM_DIAMOND_SHOVEL); +} + + + + + +bool ItemCategory::IsTool(short a_ItemID) +{ + return IsPickaxe( a_ItemID) + || IsAxe ( a_ItemID) + || IsSword ( a_ItemID) + || IsHoe ( a_ItemID) + || IsShovel ( a_ItemID); +} + + + + + +bool ItemCategory::IsHelmet(short a_ItemType) +{ + return ( + (a_ItemType == E_ITEM_LEATHER_CAP) || + (a_ItemType == E_ITEM_GOLD_HELMET) || + (a_ItemType == E_ITEM_CHAIN_HELMET) || + (a_ItemType == E_ITEM_IRON_HELMET) || + (a_ItemType == E_ITEM_DIAMOND_HELMET) + ); +} + + + + + +bool ItemCategory::IsChestPlate(short a_ItemType) +{ + return ( + (a_ItemType == E_ITEM_LEATHER_TUNIC) || + (a_ItemType == E_ITEM_GOLD_CHESTPLATE) || + (a_ItemType == E_ITEM_CHAIN_CHESTPLATE) || + (a_ItemType == E_ITEM_IRON_CHESTPLATE) || + (a_ItemType == E_ITEM_DIAMOND_CHESTPLATE) + ); +} + + + + + +bool ItemCategory::IsLeggings(short a_ItemType) +{ + return ( + (a_ItemType == E_ITEM_LEATHER_PANTS) || + (a_ItemType == E_ITEM_GOLD_LEGGINGS) || + (a_ItemType == E_ITEM_CHAIN_LEGGINGS) || + (a_ItemType == E_ITEM_IRON_LEGGINGS) || + (a_ItemType == E_ITEM_DIAMOND_LEGGINGS) + ); +} + + + + + +bool ItemCategory::IsBoots(short a_ItemType) +{ + return ( + (a_ItemType == E_ITEM_LEATHER_BOOTS) || + (a_ItemType == E_ITEM_GOLD_BOOTS) || + (a_ItemType == E_ITEM_CHAIN_BOOTS) || + (a_ItemType == E_ITEM_IRON_BOOTS) || + (a_ItemType == E_ITEM_DIAMOND_BOOTS) + ); +} + + + + + +bool ItemCategory::IsMinecart(short a_ItemType) +{ + return ( + (a_ItemType == E_ITEM_MINECART) || + (a_ItemType == E_ITEM_CHEST_MINECART) || + (a_ItemType == E_ITEM_FURNACE_MINECART) || + (a_ItemType == E_ITEM_MINECART_WITH_TNT) || + (a_ItemType == E_ITEM_MINECART_WITH_HOPPER) + ); +} + + + + + +bool ItemCategory::IsArmor(short a_ItemType) +{ + return ( + IsHelmet(a_ItemType) || + IsChestPlate(a_ItemType) || + IsLeggings(a_ItemType) || + IsBoots(a_ItemType) + ); +} + + + + + +bool ItemCategory::IsHorseArmor(short a_ItemType) +{ + switch (a_ItemType) + { + case E_ITEM_IRON_HORSE_ARMOR: + case E_ITEM_GOLD_HORSE_ARMOR: + case E_ITEM_DIAMOND_HORSE_ARMOR: + { + return true; + } + default: + { + return false; + } + } +} diff --git a/src/Defines.h b/src/Defines.h index 1b17b6913..b7fd570b4 100644 --- a/src/Defines.h +++ b/src/Defines.h @@ -238,674 +238,194 @@ enum eSkinPart - -inline const char * ClickActionToString(int a_ClickAction) -{ - switch (a_ClickAction) - { - case caLeftClick: return "caLeftClick"; - case caRightClick: return "caRightClick"; - case caShiftLeftClick: return "caShiftLeftClick"; - case caShiftRightClick: return "caShiftRightClick"; - case caNumber1: return "caNumber1"; - case caNumber2: return "caNumber2"; - case caNumber3: return "caNumber3"; - case caNumber4: return "caNumber4"; - case caNumber5: return "caNumber5"; - case caNumber6: return "caNumber6"; - case caNumber7: return "caNumber7"; - case caNumber8: return "caNumber8"; - case caNumber9: return "caNumber9"; - case caMiddleClick: return "caMiddleClick"; - case caDropKey: return "caDropKey"; - case caCtrlDropKey: return "caCtrlDropKey"; - case caLeftClickOutside: return "caLeftClickOutside"; - case caRightClickOutside: return "caRightClickOutside"; - case caLeftClickOutsideHoldNothing: return "caLeftClickOutsideHoldNothing"; - case caRightClickOutsideHoldNothing: return "caRightClickOutsideHoldNothing"; - case caLeftPaintBegin: return "caLeftPaintBegin"; - case caRightPaintBegin: return "caRightPaintBegin"; - case caMiddlePaintBegin: return "caMiddlePaintBegin"; - case caLeftPaintProgress: return "caLeftPaintProgress"; - case caRightPaintProgress: return "caRightPaintProgress"; - case caMiddlePaintProgress: return "caMiddlePaintProgress"; - case caLeftPaintEnd: return "caLeftPaintEnd"; - case caRightPaintEnd: return "caRightPaintEnd"; - case caMiddlePaintEnd: return "caMiddlePaintEnd"; - case caDblClick: return "caDblClick"; - - case caUnknown: return "caUnknown"; - } - UNREACHABLE("Unknown click action"); -} - - - - - -/** Returns a blockface mirrored around the Y axis (doesn't change up / down). */ -inline eBlockFace MirrorBlockFaceY(eBlockFace a_BlockFace) -{ - switch (a_BlockFace) - { - case BLOCK_FACE_XM: return BLOCK_FACE_XP; - case BLOCK_FACE_XP: return BLOCK_FACE_XM; - case BLOCK_FACE_ZM: return BLOCK_FACE_ZP; - case BLOCK_FACE_ZP: return BLOCK_FACE_ZM; - case BLOCK_FACE_NONE: - case BLOCK_FACE_YM: - case BLOCK_FACE_YP: - { - return a_BlockFace; - } - } - UNREACHABLE("Unsupported block face"); -} - - - - - -/** Returns a blockface rotated around the Y axis counter-clockwise. */ -inline eBlockFace RotateBlockFaceCCW(eBlockFace a_BlockFace) -{ - switch (a_BlockFace) - { - case BLOCK_FACE_XM: return BLOCK_FACE_ZP; - case BLOCK_FACE_XP: return BLOCK_FACE_ZM; - case BLOCK_FACE_ZM: return BLOCK_FACE_XM; - case BLOCK_FACE_ZP: return BLOCK_FACE_XP; - case BLOCK_FACE_NONE: - case BLOCK_FACE_YM: - case BLOCK_FACE_YP: - { - return a_BlockFace; - } - } - UNREACHABLE("Unsupported block face"); -} - - - - - -inline eBlockFace RotateBlockFaceCW(eBlockFace a_BlockFace) -{ - switch (a_BlockFace) - { - case BLOCK_FACE_XM: return BLOCK_FACE_ZM; - case BLOCK_FACE_XP: return BLOCK_FACE_ZP; - case BLOCK_FACE_ZM: return BLOCK_FACE_XP; - case BLOCK_FACE_ZP: return BLOCK_FACE_XM; - case BLOCK_FACE_NONE: - case BLOCK_FACE_YM: - case BLOCK_FACE_YP: - { - return a_BlockFace; - } - } - UNREACHABLE("Unsupported block face"); -} - - - - - -inline eBlockFace ReverseBlockFace(eBlockFace a_BlockFace) -{ - switch (a_BlockFace) - { - case BLOCK_FACE_YP: return BLOCK_FACE_YM; - case BLOCK_FACE_XP: return BLOCK_FACE_XM; - case BLOCK_FACE_ZP: return BLOCK_FACE_ZM; - case BLOCK_FACE_YM: return BLOCK_FACE_YP; - case BLOCK_FACE_XM: return BLOCK_FACE_XP; - case BLOCK_FACE_ZM: return BLOCK_FACE_ZP; - case BLOCK_FACE_NONE: return a_BlockFace; - } - UNREACHABLE("Unsupported block face"); -} - - - - - -/** Returns the textual representation of the BlockFace constant. */ -inline AString BlockFaceToString(eBlockFace a_BlockFace) -{ - switch (a_BlockFace) - { - case BLOCK_FACE_XM: return "BLOCK_FACE_XM"; - case BLOCK_FACE_XP: return "BLOCK_FACE_XP"; - case BLOCK_FACE_YM: return "BLOCK_FACE_YM"; - case BLOCK_FACE_YP: return "BLOCK_FACE_YP"; - case BLOCK_FACE_ZM: return "BLOCK_FACE_ZM"; - case BLOCK_FACE_ZP: return "BLOCK_FACE_ZP"; - case BLOCK_FACE_NONE: return "BLOCK_FACE_NONE"; - } - UNREACHABLE("Unsupported block face"); -} - - - - - -inline bool IsValidBlock(int a_BlockType) -{ - if ( - ( - (a_BlockType > -1) && - (a_BlockType <= E_BLOCK_MAX_TYPE_ID) - ) || - (a_BlockType == 255) // the blocks 253-254 don't exist yet -> https://minecraft.gamepedia.com/Data_values#Block_IDs - ) - { - return true; - } - return false; -} - - - - - -inline bool IsValidItem(int a_ItemType) +/** Dimension of a world */ +enum eDimension { - if ( - ((a_ItemType >= E_ITEM_FIRST) && (a_ItemType <= E_ITEM_MAX_CONSECUTIVE_TYPE_ID)) || // Basic items range - ((a_ItemType >= E_ITEM_FIRST_DISC) && (a_ItemType <= E_ITEM_LAST_DISC)) // Music discs' special range - ) - { - return true; - } - - if (a_ItemType == 0) - { - return false; - } - - return IsValidBlock(a_ItemType); -} - -// tolua_end - - - - - -inline bool IsBlockWater(BLOCKTYPE a_BlockType) -{ - return ((a_BlockType == E_BLOCK_WATER) || (a_BlockType == E_BLOCK_STATIONARY_WATER)); -} - - - - - -inline bool IsBlockIce(BLOCKTYPE a_BlockType) -{ - switch (a_BlockType) - { - case E_BLOCK_ICE: - case E_BLOCK_PACKED_ICE: - case E_BLOCK_FROSTED_ICE: - { - return true; - } - default: - { - return false; - } - } -} - - - - - -inline bool IsBlockWaterOrIce(BLOCKTYPE a_BlockType) -{ - return (IsBlockWater(a_BlockType) || IsBlockIce(a_BlockType)); -} - - - - - -inline bool IsBlockLava(BLOCKTYPE a_BlockType) -{ - return ((a_BlockType == E_BLOCK_LAVA) || (a_BlockType == E_BLOCK_STATIONARY_LAVA)); -} - - - - - -inline bool IsBlockLiquid(BLOCKTYPE a_BlockType) -{ - return IsBlockWater(a_BlockType) || IsBlockLava(a_BlockType); -} - - - - -inline bool IsBlockRail(BLOCKTYPE a_BlockType) -{ - switch (a_BlockType) - { - case E_BLOCK_RAIL: - case E_BLOCK_ACTIVATOR_RAIL: - case E_BLOCK_DETECTOR_RAIL: - case E_BLOCK_POWERED_RAIL: - { - return true; - } - default: return false; - } -} - - - - - -inline bool IsBlockTypeOfDirt(BLOCKTYPE a_BlockType) -{ - switch (a_BlockType) - { - case E_BLOCK_DIRT: - case E_BLOCK_GRASS: - case E_BLOCK_FARMLAND: - case E_BLOCK_GRASS_PATH: - { - return true; - } - } - return false; -} - - - - -inline bool IsBlockFence(BLOCKTYPE a_BlockType) -{ - switch (a_BlockType) - { - case E_BLOCK_ACACIA_FENCE: - case E_BLOCK_ACACIA_FENCE_GATE: - case E_BLOCK_BIRCH_FENCE: - case E_BLOCK_BIRCH_FENCE_GATE: - case E_BLOCK_COBBLESTONE_WALL: - case E_BLOCK_DARK_OAK_FENCE: - case E_BLOCK_DARK_OAK_FENCE_GATE: - case E_BLOCK_FENCE: - case E_BLOCK_JUNGLE_FENCE: - case E_BLOCK_JUNGLE_FENCE_GATE: - case E_BLOCK_NETHER_BRICK_FENCE: - case E_BLOCK_OAK_FENCE_GATE: - case E_BLOCK_SPRUCE_FENCE: - case E_BLOCK_SPRUCE_FENCE_GATE: - { - return true; - } - default: - { - return false; - } - } -} - - - - - -inline bool IsBlockMaterialWood(BLOCKTYPE a_BlockType) -{ - switch (a_BlockType) - { - case E_BLOCK_PLANKS: - case E_BLOCK_LOG: - case E_BLOCK_NOTE_BLOCK: - case E_BLOCK_BOOKCASE: - case E_BLOCK_OAK_WOOD_STAIRS: - case E_BLOCK_CHEST: - case E_BLOCK_CRAFTING_TABLE: - case E_BLOCK_SIGN_POST: - case E_BLOCK_OAK_DOOR: - case E_BLOCK_WALLSIGN: - case E_BLOCK_WOODEN_PRESSURE_PLATE: - case E_BLOCK_JUKEBOX: - case E_BLOCK_FENCE: - case E_BLOCK_TRAPDOOR: - case E_BLOCK_HUGE_BROWN_MUSHROOM: - case E_BLOCK_HUGE_RED_MUSHROOM: - case E_BLOCK_OAK_FENCE_GATE: - case E_BLOCK_DOUBLE_WOODEN_SLAB: - case E_BLOCK_WOODEN_SLAB: - case E_BLOCK_SPRUCE_WOOD_STAIRS: - case E_BLOCK_BIRCH_WOOD_STAIRS: - case E_BLOCK_JUNGLE_WOOD_STAIRS: - case E_BLOCK_TRAPPED_CHEST: - case E_BLOCK_DAYLIGHT_SENSOR: - case E_BLOCK_NEW_LOG: - case E_BLOCK_ACACIA_WOOD_STAIRS: - case E_BLOCK_DARK_OAK_WOOD_STAIRS: - case E_BLOCK_STANDING_BANNER: - case E_BLOCK_WALL_BANNER: - case E_BLOCK_INVERTED_DAYLIGHT_SENSOR: - case E_BLOCK_SPRUCE_FENCE_GATE: - case E_BLOCK_BIRCH_FENCE_GATE: - case E_BLOCK_JUNGLE_FENCE_GATE: - case E_BLOCK_DARK_OAK_FENCE_GATE: - case E_BLOCK_ACACIA_FENCE_GATE: - case E_BLOCK_SPRUCE_FENCE: - case E_BLOCK_BIRCH_FENCE: - case E_BLOCK_JUNGLE_FENCE: - case E_BLOCK_DARK_OAK_FENCE: - case E_BLOCK_ACACIA_FENCE: - case E_BLOCK_SPRUCE_DOOR: - case E_BLOCK_BIRCH_DOOR: - case E_BLOCK_JUNGLE_DOOR: - case E_BLOCK_ACACIA_DOOR: - case E_BLOCK_DARK_OAK_DOOR: - { - return true; - } - default: - { - return false; - } - } -} - - - - - -inline bool IsBlockMaterialPlants(BLOCKTYPE a_BlockType) -{ - switch (a_BlockType) - { - case E_BLOCK_SAPLING: - case E_BLOCK_DANDELION: - case E_BLOCK_FLOWER: - case E_BLOCK_BROWN_MUSHROOM: - case E_BLOCK_RED_MUSHROOM: - case E_BLOCK_CROPS: - case E_BLOCK_REEDS: - case E_BLOCK_PUMPKIN_STEM: - case E_BLOCK_MELON_STEM: - case E_BLOCK_LILY_PAD: - case E_BLOCK_NETHER_WART: - case E_BLOCK_COCOA_POD: - case E_BLOCK_CARROTS: - case E_BLOCK_POTATOES: - case E_BLOCK_CHORUS_PLANT: - case E_BLOCK_CHORUS_FLOWER: - case E_BLOCK_BEETROOTS: - { - return true; - } - default: - { - return false; - } - } -} - - - - - -inline bool IsBlockMaterialVine(BLOCKTYPE a_BlockType) -{ - switch (a_BlockType) - { - case E_BLOCK_TALL_GRASS: - case E_BLOCK_DEAD_BUSH: - case E_BLOCK_VINES: - case E_BLOCK_BIG_FLOWER: - { - return true; - } - default: - { - return false; - } - } -} - - - - - -inline bool IsBlockMaterialIron(BLOCKTYPE a_BlockType) -{ - switch (a_BlockType) - { - case E_BLOCK_LAPIS_BLOCK: - case E_BLOCK_GOLD_BLOCK: - case E_BLOCK_IRON_BLOCK: - case E_BLOCK_DIAMOND_BLOCK: - case E_BLOCK_IRON_DOOR: - case E_BLOCK_IRON_BARS: - case E_BLOCK_BREWING_STAND: - case E_BLOCK_CAULDRON: - case E_BLOCK_EMERALD_BLOCK: - case E_BLOCK_COMMAND_BLOCK: - case E_BLOCK_LIGHT_WEIGHTED_PRESSURE_PLATE: - case E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE: - case E_BLOCK_BLOCK_OF_REDSTONE: - case E_BLOCK_HOPPER: - case E_BLOCK_IRON_TRAPDOOR: - case E_BLOCK_REPEATING_COMMAND_BLOCK: - case E_BLOCK_CHAIN_COMMAND_BLOCK: - case E_BLOCK_STRUCTURE_BLOCK: - { - return true; - } - default: - { - return false; - } - } -} + dimNether = -1, + dimOverworld = 0, + dimEnd = 1, + dimNotSet = 255, // For things that need an "indeterminate" state, such as cProtocol's LastSentDimension +} ; -inline bool IsBlockMaterialAnvil(BLOCKTYPE a_BlockType) -{ - return (a_BlockType == E_BLOCK_ANVIL); -} +/** Damage type, used in the TakeDamageInfo structure and related functions */ +enum eDamageType +{ + // Canonical names for the types (as documented in the plugin wiki): + dtAttack, // Being attacked by a mob + dtRangedAttack, // Being attacked by a projectile, possibly from a mob + dtLightning, // Hit by a lightning strike + dtFalling, // Falling down; dealt when hitting the ground + dtDrowning, // Drowning in water / lava + dtSuffocating, // Suffocating inside a block + dtStarving, // Hunger + dtCactusContact, // Contact with a cactus block + dtLavaContact, // Contact with a lava block + dtPoisoning, // Having the poison effect + dtWithering, // Having the wither effect + dtOnFire, // Being on fire + dtFireContact, // Standing inside a fire block + dtInVoid, // Falling into the Void (Y < 0) + dtPotionOfHarming, + dtEnderPearl, // Thrown an ender pearl, teleported by it + dtAdmin, // Damage applied by an admin command + dtExplosion, // Damage applied by an explosion + + // Some common synonyms: + dtPawnAttack = dtAttack, + dtEntityAttack = dtAttack, + dtMob = dtAttack, + dtMobAttack = dtAttack, + dtArrowAttack = dtRangedAttack, + dtArrow = dtRangedAttack, + dtProjectile = dtRangedAttack, + dtFall = dtFalling, + dtDrown = dtDrowning, + dtSuffocation = dtSuffocating, + dtStarvation = dtStarving, + dtHunger = dtStarving, + dtCactus = dtCactusContact, + dtCactuses = dtCactusContact, + dtCacti = dtCactusContact, + dtLava = dtLavaContact, + dtPoison = dtPoisoning, + dtWither = dtWithering, + dtBurning = dtOnFire, + dtInFire = dtFireContact, + dtPlugin = dtAdmin, +} ; -inline bool IsBlocksWeb(BLOCKTYPE a_BlockType) -{ - return (a_BlockType == E_BLOCK_COBWEB); -} +/** The source of an explosion. +Also dictates the type of the additional data passed to the explosion handlers: +| esBed | Vector3i * | Bed exploding in the Nether or in the End +| esEnderCrystal | cEnderCrystal * | +| esGhastFireball | cGhastFireballEntity * | +| esMonster | cMonster * | +| esOther | nullptr | Any other explosion unaccounted for +| esPlugin | nullptr | Explosion primarily attributed to a plugin +| esPrimedTNT | cTNTEntity * | +| esWitherBirth | cMonster * | +| esWitherSkull | cProjectileEntity * | +*/ +enum eExplosionSource +{ + esBed, + esEnderCrystal, + esGhastFireball, + esMonster, + esOther, + esPlugin, + esPrimedTNT, + esWitherBirth, + esWitherSkull, + esMax, +} ; -inline bool IsBlockMaterialLeaves(BLOCKTYPE a_BlockType) +enum eShrapnelLevel { - return (a_BlockType == E_BLOCK_LEAVES) || (a_BlockType == E_BLOCK_NEW_LEAVES); -} + slNone, + slGravityAffectedOnly, + slAll +} ; -inline bool IsBlocksWool(BLOCKTYPE a_BlockType) +enum eSpreadSource { - return (a_BlockType == E_BLOCK_WOOL); -} + ssFireSpread, + ssGrassSpread, + ssMushroomSpread, + ssMycelSpread, + ssVineSpread, +} ; -inline bool IsBlockMaterialGourd(BLOCKTYPE a_BlockType) +enum eMessageType { - switch (a_BlockType) - { - case E_BLOCK_PUMPKIN: - case E_BLOCK_JACK_O_LANTERN: - case E_BLOCK_MELON: - { - return true; - } - default: - { - return false; - } - } -} + // https://forum.cuberite.org/thread-1212.html + // MessageType... + mtCustom, // Send raw data without any processing + mtFailure, // Something could not be done (i.e. command not executed due to insufficient privilege) + mtInformation, // Informational message (i.e. command usage) + mtSuccess, // Something executed successfully + mtWarning, // Something concerning (i.e. reload) is about to happen + mtFatal, // Something catastrophic occured (i.e. plugin crash) + mtDeath, // Denotes death of player + mtPrivateMessage, // Player to player messaging identifier + mtJoin, // A player has joined the server + mtLeave, // A player has left the server + mtMaxPlusOne, // The first invalid type, used for checking on LuaAPI boundaries + // Common aliases: + mtFail = mtFailure, + mtError = mtFailure, + mtInfo = mtInformation, + mtPM = mtPrivateMessage, +}; -inline bool IsBlockMaterialCoral(BLOCKTYPE a_BlockType) -{ - return false; // yes, there is no block in minecraft which belongs to this type. -} +/** Returns a textual representation of the click action. */ +const char * ClickActionToString(int a_ClickAction); +/** Returns a blockface mirrored around the Y axis (doesn't change up / down). */ +eBlockFace MirrorBlockFaceY(eBlockFace a_BlockFace); +/** Returns a blockface rotated around the Y axis counter-clockwise. */ +eBlockFace RotateBlockFaceCCW(eBlockFace a_BlockFace); -inline bool IsBlockMaterialRock(BLOCKTYPE a_BlockType) -{ - switch (a_BlockType) - { - case E_BLOCK_STONE: - case E_BLOCK_COBBLESTONE: - case E_BLOCK_BEDROCK: - case E_BLOCK_GOLD_ORE: - case E_BLOCK_IRON_ORE: - case E_BLOCK_COAL_ORE: - case E_BLOCK_LAPIS_ORE: - case E_BLOCK_DISPENSER: - case E_BLOCK_SANDSTONE: - case E_BLOCK_DOUBLE_STONE_SLAB: - case E_BLOCK_STONE_SLAB: - case E_BLOCK_BRICK: - case E_BLOCK_MOSSY_COBBLESTONE: - case E_BLOCK_OBSIDIAN: - case E_BLOCK_MOB_SPAWNER: - case E_BLOCK_DIAMOND_ORE: - case E_BLOCK_FURNACE: - case E_BLOCK_LIT_FURNACE: - case E_BLOCK_COBBLESTONE_STAIRS: - case E_BLOCK_STONE_PRESSURE_PLATE: - case E_BLOCK_REDSTONE_ORE: - case E_BLOCK_REDSTONE_ORE_GLOWING: - case E_BLOCK_NETHERRACK: - case E_BLOCK_STONE_BRICKS: - case E_BLOCK_BRICK_STAIRS: - case E_BLOCK_STONE_BRICK_STAIRS: - case E_BLOCK_NETHER_BRICK: - case E_BLOCK_NETHER_BRICK_FENCE: - case E_BLOCK_NETHER_BRICK_STAIRS: - case E_BLOCK_ENCHANTMENT_TABLE: - case E_BLOCK_END_PORTAL_FRAME: - case E_BLOCK_END_STONE: - case E_BLOCK_SANDSTONE_STAIRS: - case E_BLOCK_EMERALD_ORE: - case E_BLOCK_ENDER_CHEST: - case E_BLOCK_COBBLESTONE_WALL: - case E_BLOCK_NETHER_QUARTZ_ORE: - case E_BLOCK_QUARTZ_BLOCK: - case E_BLOCK_QUARTZ_STAIRS: - case E_BLOCK_DROPPER: - case E_BLOCK_STAINED_CLAY: - case E_BLOCK_PRISMARINE_BLOCK: - case E_BLOCK_HARDENED_CLAY: - case E_BLOCK_BLOCK_OF_COAL: - case E_BLOCK_RED_SANDSTONE: - case E_BLOCK_RED_SANDSTONE_STAIRS: - case E_BLOCK_DOUBLE_RED_SANDSTONE_SLAB: - case E_BLOCK_RED_SANDSTONE_SLAB: - case E_BLOCK_PURPUR_BLOCK: - case E_BLOCK_PURPUR_PILLAR: - case E_BLOCK_PURPUR_STAIRS: - case E_BLOCK_PURPUR_DOUBLE_SLAB: - case E_BLOCK_PURPUR_SLAB: - case E_BLOCK_END_BRICKS: - case E_BLOCK_MAGMA: - case E_BLOCK_RED_NETHER_BRICK: - case E_BLOCK_BONE_BLOCK: - case E_BLOCK_OBSERVER: - { - return true; - } - default: - { - return false; - } - } -} +/** Returns a blockface rotated around the Y axis clockwise. */ +eBlockFace RotateBlockFaceCW(eBlockFace a_BlockFace); +/** Returns a blockface opposite to the one specified. */ +eBlockFace ReverseBlockFace(eBlockFace a_BlockFace); +/** Returns the textual representation of the BlockFace constant. */ +AString BlockFaceToString(eBlockFace a_BlockFace); +/** Returns true if the specified block type is valid (known). */ +bool IsValidBlock(int a_BlockType); +/** Returns true if the specified item type is valid (known). */ +bool IsValidItem(int a_ItemType); -inline void AddFaceDirection(int & a_BlockX, int & a_BlockY, int & a_BlockZ, eBlockFace a_BlockFace, bool a_bInverse = false) // tolua_export -{ // tolua_export - if (!a_bInverse) - { - switch (a_BlockFace) - { - case BLOCK_FACE_YP: a_BlockY++; break; - case BLOCK_FACE_YM: a_BlockY--; break; - case BLOCK_FACE_ZM: a_BlockZ--; break; - case BLOCK_FACE_ZP: a_BlockZ++; break; - case BLOCK_FACE_XP: a_BlockX++; break; - case BLOCK_FACE_XM: a_BlockX--; break; - case BLOCK_FACE_NONE: - { - LOGWARNING("%s: Unknown face: %d", __FUNCTION__, a_BlockFace); - ASSERT(!"AddFaceDirection(): Unknown face"); - break; - } - } - } - else - { - switch (a_BlockFace) - { - case BLOCK_FACE_YP: a_BlockY--; break; - case BLOCK_FACE_YM: a_BlockY++; break; - case BLOCK_FACE_ZM: a_BlockZ++; break; - case BLOCK_FACE_ZP: a_BlockZ--; break; - case BLOCK_FACE_XP: a_BlockX--; break; - case BLOCK_FACE_XM: a_BlockX++; break; - case BLOCK_FACE_NONE: - { - LOGWARNING("%s: Unknown inv face: %d", __FUNCTION__, a_BlockFace); - ASSERT(!"AddFaceDirection(): Unknown face"); - break; - } - } - } -} // tolua_export +/** Translates a dimension string to dimension enum. Takes either a number or a dimension alias (built-in). Returns dimOverworld on failure */ +extern eDimension StringToDimension(const AString & a_DimensionString); +/** Translates a dimension enum to dimension string. +Takes an eDimension enum value and returns "Overworld" on failure. */ +extern AString DimensionToString(eDimension a_Dimension); +/** Translates damage type constant to a string representation (built-in). */ +extern AString DamageTypeToString(eDamageType a_DamageType); +/** Translates a damage type string to damage type. Takes either a number or a damage type alias (built-in). Returns -1 on failure */ +extern eDamageType StringToDamageType(const AString & a_DamageString); +/** Modifies the specified coords so that they point to the block adjacent to the one specified through its specified face. +If a_Inverse is true, the opposite direction is used instead. */ +void AddFaceDirection(int & a_BlockX, int & a_BlockY, int & a_BlockZ, eBlockFace a_BlockFace, bool a_bInverse = false); -inline void AddFaceDirection(int & a_BlockX, unsigned char & a_BlockY, int & a_BlockZ, eBlockFace a_BlockFace, bool a_bInverse = false) -{ - int Y = a_BlockY; - AddFaceDirection(a_BlockX, Y, a_BlockZ, a_BlockFace, a_bInverse); - a_BlockY = Clamp<unsigned char>(static_cast<unsigned char>(Y), 0, cChunkDef::Height - 1); -} +// tolua_end @@ -944,24 +464,6 @@ inline void VectorToEuler(double a_X, double a_Y, double a_Z, double & a_Pan, do -inline float GetSignf(float a_Val) -{ - return (a_Val < 0.f) ? -1.f : 1.f; -} - - - - - -inline float GetSpecialSignf( float a_Val) -{ - return (a_Val <= 0.f) ? -1.f : 1.f; -} - - - - - template <class T> inline T Diff(T a_Val1, T a_Val2) { return std::abs(a_Val1 - a_Val2); @@ -973,34 +475,6 @@ template <class T> inline T Diff(T a_Val1, T a_Val2) // tolua_begin -enum eMessageType -{ - // https://forum.cuberite.org/thread-1212.html - // MessageType... - - mtCustom, // Send raw data without any processing - mtFailure, // Something could not be done (i.e. command not executed due to insufficient privilege) - mtInformation, // Informational message (i.e. command usage) - mtSuccess, // Something executed successfully - mtWarning, // Something concerning (i.e. reload) is about to happen - mtFatal, // Something catastrophic occured (i.e. plugin crash) - mtDeath, // Denotes death of player - mtPrivateMessage, // Player to player messaging identifier - mtJoin, // A player has joined the server - mtLeave, // A player has left the server - mtMaxPlusOne, // The first invalid type, used for checking on LuaAPI boundaries - - // Common aliases: - mtFail = mtFailure, - mtError = mtFailure, - mtInfo = mtInformation, - mtPM = mtPrivateMessage, -}; - - - - - /** Normalizes an angle in degrees to the [-180, +180) range: */ inline double NormalizeAngleDegrees(const double a_Degrees) { @@ -1018,165 +492,31 @@ inline double NormalizeAngleDegrees(const double a_Degrees) namespace ItemCategory { - inline bool IsPickaxe(short a_ItemID) - { - return (a_ItemID == E_ITEM_WOODEN_PICKAXE) - || (a_ItemID == E_ITEM_STONE_PICKAXE) - || (a_ItemID == E_ITEM_IRON_PICKAXE) - || (a_ItemID == E_ITEM_GOLD_PICKAXE) - || (a_ItemID == E_ITEM_DIAMOND_PICKAXE); - } + bool IsPickaxe(short a_ItemType); + bool IsAxe(short a_ItemType); + bool IsSword(short a_ItemType); - inline bool IsAxe(short a_ItemID) - { - return (a_ItemID == E_ITEM_WOODEN_AXE) - || (a_ItemID == E_ITEM_STONE_AXE) - || (a_ItemID == E_ITEM_IRON_AXE) - || (a_ItemID == E_ITEM_GOLD_AXE) - || (a_ItemID == E_ITEM_DIAMOND_AXE); - } + bool IsHoe(short a_ItemType); + bool IsShovel(short a_ItemType); + bool IsTool(short a_ItemType); - inline bool IsSword(short a_ItemID) - { - return (a_ItemID == E_ITEM_WOODEN_SWORD) - || (a_ItemID == E_ITEM_STONE_SWORD) - || (a_ItemID == E_ITEM_IRON_SWORD) - || (a_ItemID == E_ITEM_GOLD_SWORD) - || (a_ItemID == E_ITEM_DIAMOND_SWORD); - } - + bool IsHelmet(short a_ItemType); + bool IsChestPlate(short a_ItemType); - inline bool IsHoe(short a_ItemID) - { - return (a_ItemID == E_ITEM_WOODEN_HOE) - || (a_ItemID == E_ITEM_STONE_HOE) - || (a_ItemID == E_ITEM_IRON_HOE) - || (a_ItemID == E_ITEM_GOLD_HOE) - || (a_ItemID == E_ITEM_DIAMOND_HOE); - } + bool IsLeggings(short a_ItemType); + bool IsBoots(short a_ItemType); + bool IsMinecart(short a_ItemType); - inline bool IsShovel(short a_ItemID) - { - return (a_ItemID == E_ITEM_WOODEN_SHOVEL) - || (a_ItemID == E_ITEM_STONE_SHOVEL) - || (a_ItemID == E_ITEM_IRON_SHOVEL) - || (a_ItemID == E_ITEM_GOLD_SHOVEL) - || (a_ItemID == E_ITEM_DIAMOND_SHOVEL); - } + bool IsArmor(short a_ItemType); - - - inline bool IsTool(short a_ItemID) - { - return IsPickaxe( a_ItemID) - || IsAxe ( a_ItemID) - || IsSword ( a_ItemID) - || IsHoe ( a_ItemID) - || IsShovel ( a_ItemID); - } - - - - inline bool IsHelmet(short a_ItemType) - { - return ( - (a_ItemType == E_ITEM_LEATHER_CAP) || - (a_ItemType == E_ITEM_GOLD_HELMET) || - (a_ItemType == E_ITEM_CHAIN_HELMET) || - (a_ItemType == E_ITEM_IRON_HELMET) || - (a_ItemType == E_ITEM_DIAMOND_HELMET) - ); - } - - - - inline bool IsChestPlate(short a_ItemType) - { - return ( - (a_ItemType == E_ITEM_LEATHER_TUNIC) || - (a_ItemType == E_ITEM_GOLD_CHESTPLATE) || - (a_ItemType == E_ITEM_CHAIN_CHESTPLATE) || - (a_ItemType == E_ITEM_IRON_CHESTPLATE) || - (a_ItemType == E_ITEM_DIAMOND_CHESTPLATE) - ); - } - - - - inline bool IsLeggings(short a_ItemType) - { - return ( - (a_ItemType == E_ITEM_LEATHER_PANTS) || - (a_ItemType == E_ITEM_GOLD_LEGGINGS) || - (a_ItemType == E_ITEM_CHAIN_LEGGINGS) || - (a_ItemType == E_ITEM_IRON_LEGGINGS) || - (a_ItemType == E_ITEM_DIAMOND_LEGGINGS) - ); - } - - - - inline bool IsBoots(short a_ItemType) - { - return ( - (a_ItemType == E_ITEM_LEATHER_BOOTS) || - (a_ItemType == E_ITEM_GOLD_BOOTS) || - (a_ItemType == E_ITEM_CHAIN_BOOTS) || - (a_ItemType == E_ITEM_IRON_BOOTS) || - (a_ItemType == E_ITEM_DIAMOND_BOOTS) - ); - } - - - - inline bool IsMinecart(short a_ItemType) - { - return ( - (a_ItemType == E_ITEM_MINECART) || - (a_ItemType == E_ITEM_CHEST_MINECART) || - (a_ItemType == E_ITEM_FURNACE_MINECART) || - (a_ItemType == E_ITEM_MINECART_WITH_TNT) || - (a_ItemType == E_ITEM_MINECART_WITH_HOPPER) - ); - } - - - - inline bool IsArmor(short a_ItemType) - { - return ( - IsHelmet(a_ItemType) || - IsChestPlate(a_ItemType) || - IsLeggings(a_ItemType) || - IsBoots(a_ItemType) - ); - } - - - - inline bool IsHorseArmor(short a_ItemType) - { - switch (a_ItemType) - { - case E_ITEM_IRON_HORSE_ARMOR: - case E_ITEM_GOLD_HORSE_ARMOR: - case E_ITEM_DIAMOND_HORSE_ARMOR: - { - return true; - } - default: - { - return false; - } - } - } + bool IsHorseArmor(short a_ItemType); } // tolua_end diff --git a/src/Enchantments.cpp b/src/Enchantments.cpp index 1a6f72c9e..53a8212e8 100644 --- a/src/Enchantments.cpp +++ b/src/Enchantments.cpp @@ -7,6 +7,7 @@ #include "WorldStorage/FastNBT.h" #include "FastRandom.h" #include "Noise/Noise.h" +#include "BlockType.h" diff --git a/src/Entities/Boat.cpp b/src/Entities/Boat.cpp index d0ac27228..ec6b69326 100644 --- a/src/Entities/Boat.cpp +++ b/src/Entities/Boat.cpp @@ -5,6 +5,7 @@ #include "Globals.h" #include "Boat.h" +#include "../BlockInfo.h" #include "../World.h" #include "../ClientHandle.h" #include "Player.h" diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 209c10b44..a4d33db19 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -3,6 +3,7 @@ #include "Entity.h" #include "Player.h" +#include "../BlockInfo.h" #include "../World.h" #include "../Root.h" #include "../Matrix4.h" diff --git a/src/Entities/FallingBlock.cpp b/src/Entities/FallingBlock.cpp index 132acd09a..628e4d34c 100644 --- a/src/Entities/FallingBlock.cpp +++ b/src/Entities/FallingBlock.cpp @@ -1,6 +1,7 @@ #include "Globals.h" #include "FallingBlock.h" +#include "../BlockInfo.h" #include "../World.h" #include "../ClientHandle.h" #include "../Simulator/SandSimulator.h" diff --git a/src/Entities/Floater.cpp b/src/Entities/Floater.cpp index c4c89890b..5c16446c8 100644 --- a/src/Entities/Floater.cpp +++ b/src/Entities/Floater.cpp @@ -1,6 +1,7 @@ #include "Globals.h" +#include "../BlockInfo.h" #include "../BoundingBox.h" #include "../Chunk.h" #include "Floater.h" diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp index 01d89ceb4..d5e50fc41 100644 --- a/src/Entities/Minecart.cpp +++ b/src/Entities/Minecart.cpp @@ -7,6 +7,7 @@ #include "Globals.h" #include "Minecart.h" +#include "../BlockInfo.h" #include "../ClientHandle.h" #include "../Chunk.h" #include "Player.h" diff --git a/src/Entities/Pawn.cpp b/src/Entities/Pawn.cpp index dd218aec9..9481daa8c 100644 --- a/src/Entities/Pawn.cpp +++ b/src/Entities/Pawn.cpp @@ -3,6 +3,7 @@ #include "Pawn.h" #include "Player.h" +#include "../BlockInfo.h" #include "../World.h" #include "../Bindings/PluginManager.h" #include "../BoundingBox.h" diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp index b2148fa2b..9314c875d 100644 --- a/src/Entities/ProjectileEntity.cpp +++ b/src/Entities/ProjectileEntity.cpp @@ -7,6 +7,7 @@ #include "../Bindings/PluginManager.h" #include "ProjectileEntity.h" +#include "../BlockInfo.h" #include "../ClientHandle.h" #include "../LineBlockTracer.h" #include "../BoundingBox.h" diff --git a/src/Generating/Caves.cpp b/src/Generating/Caves.cpp index 240248b5a..193c75554 100644 --- a/src/Generating/Caves.cpp +++ b/src/Generating/Caves.cpp @@ -30,6 +30,7 @@ reduced in complexity in order for this generator to be useful, so the caves' sh #include "Globals.h" #include "Caves.h" +#include "../BlockInfo.h" diff --git a/src/Generating/ChunkGenerator.h b/src/Generating/ChunkGenerator.h index 5fe58c65a..52c9cd896 100644 --- a/src/Generating/ChunkGenerator.h +++ b/src/Generating/ChunkGenerator.h @@ -1,5 +1,6 @@ #pragma once +#include "../Defines.h" diff --git a/src/Generating/DungeonRoomsFinisher.cpp b/src/Generating/DungeonRoomsFinisher.cpp index 768dd27cf..c595a6451 100644 --- a/src/Generating/DungeonRoomsFinisher.cpp +++ b/src/Generating/DungeonRoomsFinisher.cpp @@ -5,6 +5,7 @@ #include "Globals.h" #include "DungeonRoomsFinisher.h" +#include "../BlockInfo.h" #include "../FastRandom.h" #include "../BlockEntities/ChestEntity.h" #include "../BlockEntities/MobSpawnerEntity.h" diff --git a/src/Generating/FinishGen.cpp b/src/Generating/FinishGen.cpp index 7aece7219..5b328ec49 100644 --- a/src/Generating/FinishGen.cpp +++ b/src/Generating/FinishGen.cpp @@ -14,6 +14,7 @@ #include "../Simulator/FireSimulator.h" #include "../IniFile.h" #include "../MobSpawner.h" +#include "../BlockInfo.h" diff --git a/src/Generating/Prefab.cpp b/src/Generating/Prefab.cpp index 1f2b5c916..903ca8eab 100644 --- a/src/Generating/Prefab.cpp +++ b/src/Generating/Prefab.cpp @@ -10,6 +10,7 @@ uses a prefabricate in a cBlockArea for drawing itself. #include "Prefab.h" #include "../WorldStorage/SchematicFileSerializer.h" #include "ChunkDesc.h" +#include "../BlockInfo.h" diff --git a/src/Generating/RoughRavines.cpp b/src/Generating/RoughRavines.cpp index a9e9a97de..a65f57268 100644 --- a/src/Generating/RoughRavines.cpp +++ b/src/Generating/RoughRavines.cpp @@ -6,6 +6,7 @@ #include "Globals.h" #include "RoughRavines.h" +#include "../BlockInfo.h" diff --git a/src/Generating/StructGen.cpp b/src/Generating/StructGen.cpp index d3bd6114e..0b45502a6 100644 --- a/src/Generating/StructGen.cpp +++ b/src/Generating/StructGen.cpp @@ -6,6 +6,7 @@ #include "Trees.h" #include "../BlockArea.h" #include "../LinearUpscale.h" +#include "../BlockInfo.h" diff --git a/src/Generating/Trees.cpp b/src/Generating/Trees.cpp index de6da5265..558b4619e 100644 --- a/src/Generating/Trees.cpp +++ b/src/Generating/Trees.cpp @@ -5,6 +5,7 @@ #include "Globals.h" #include "Trees.h" +#include "../BlockType.h" diff --git a/src/Generating/VillageGen.cpp b/src/Generating/VillageGen.cpp index c2693608d..340d9adb8 100644 --- a/src/Generating/VillageGen.cpp +++ b/src/Generating/VillageGen.cpp @@ -6,6 +6,7 @@ #include "Globals.h" #include "VillageGen.h" #include "PieceGeneratorBFSTree.h" +#include "../BlockInfo.h" diff --git a/src/Globals.h b/src/Globals.h index 890394e2e..94fc7ce27 100644 --- a/src/Globals.h +++ b/src/Globals.h @@ -404,9 +404,3 @@ using cTickTimeLong = std::chrono::duration<Int64, cTickTime::period>; #include "Vector3.h" #include "BiomeDef.h" #include "ChunkDef.h" -#include "BlockID.h" -#include "BlockInfo.h" - - - - diff --git a/src/Item.cpp b/src/Item.cpp index 16aa22b50..dd8f08f02 100644 --- a/src/Item.cpp +++ b/src/Item.cpp @@ -2,6 +2,7 @@ #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "Item.h" +#include "BlockType.h" #include "ItemGrid.h" #include "json/json.h" #include "Items/ItemHandler.h" @@ -12,6 +13,83 @@ +cItem::cItem(): + m_ItemType(E_ITEM_EMPTY), + m_ItemCount(0), + m_ItemDamage(0), + m_CustomName(""), + m_RepairCost(0), + m_FireworkItem(), + m_ItemColor() +{ +} + + + + + +cItem::cItem( + short a_ItemType, + char a_ItemCount, + short a_ItemDamage, + const AString & a_Enchantments, + const AString & a_CustomName, + const AStringVector & a_LoreTable +): + m_ItemType (a_ItemType), + m_ItemCount (a_ItemCount), + m_ItemDamage (a_ItemDamage), + m_Enchantments(a_Enchantments), + m_CustomName (a_CustomName), + m_LoreTable (a_LoreTable), + m_RepairCost (0), + m_FireworkItem(), + m_ItemColor() +{ + if (!IsValidItem(m_ItemType)) + { + if ((m_ItemType != E_BLOCK_AIR) && (m_ItemType != E_ITEM_EMPTY)) + { + LOGWARNING("%s: creating an invalid item type (%d), resetting to empty.", __FUNCTION__, a_ItemType); + } + Empty(); + } +} + + + + + +void cItem::Empty() +{ + m_ItemType = E_ITEM_EMPTY; + m_ItemCount = 0; + m_ItemDamage = 0; + m_Enchantments.Clear(); + m_CustomName = ""; + m_LoreTable.clear(); + m_RepairCost = 0; + m_FireworkItem.EmptyData(); + m_ItemColor.Clear(); +} + + + + + +void cItem::Clear() +{ + m_ItemType = E_ITEM_EMPTY; + m_ItemCount = 0; + m_ItemDamage = 0; + m_RepairCost = 0; + m_ItemColor.Clear(); +} + + + + + cItem cItem::CopyOne(void) const { cItem res(*this); @@ -196,7 +274,7 @@ void cItem::GetJson(Json::Value & a_OutValue) const void cItem::FromJson(const Json::Value & a_Value) { - m_ItemType = static_cast<ENUM_ITEM_ID>(a_Value.get("ID", -1).asInt()); + m_ItemType = static_cast<ENUM_ITEM_TYPE>(a_Value.get("ID", -1).asInt()); if (m_ItemType > 0) { m_ItemCount = static_cast<char>(a_Value.get("Count", -1).asInt()); diff --git a/src/Item.h b/src/Item.h index 306e36b0a..175f044b5 100644 --- a/src/Item.h +++ b/src/Item.h @@ -37,17 +37,7 @@ class cItem { public: /** Creates an empty item */ - cItem(void) : - m_ItemType(E_ITEM_EMPTY), - m_ItemCount(0), - m_ItemDamage(0), - m_CustomName(""), - m_RepairCost(0), - m_FireworkItem(), - m_ItemColor() - { - } - + cItem(void); /** Creates an item of the specified type, by default 1 piece with no damage and no enchantments */ cItem( @@ -57,27 +47,7 @@ public: const AString & a_Enchantments = "", const AString & a_CustomName = "", const AStringVector & a_LoreTable = {} - ) : - m_ItemType (a_ItemType), - m_ItemCount (a_ItemCount), - m_ItemDamage (a_ItemDamage), - m_Enchantments(a_Enchantments), - m_CustomName (a_CustomName), - m_LoreTable (a_LoreTable), - m_RepairCost (0), - m_FireworkItem(), - m_ItemColor() - { - if (!IsValidItem(m_ItemType)) - { - if ((m_ItemType != E_BLOCK_AIR) && (m_ItemType != E_ITEM_EMPTY)) - { - LOGWARNING("%s: creating an invalid item type (%d), resetting to empty.", __FUNCTION__, a_ItemType); - } - Empty(); - } - } - + ); // The constructor is disabled in code, because the compiler generates it anyway, // but it needs to stay because ToLua needs to generate the binding for it @@ -88,31 +58,14 @@ public: #endif + /** Empties the item and frees up any dynamic storage used by the internals. */ + void Empty(void); - void Empty(void) - { - m_ItemType = E_ITEM_EMPTY; - m_ItemCount = 0; - m_ItemDamage = 0; - m_Enchantments.Clear(); - m_CustomName = ""; - m_LoreTable.clear(); - m_RepairCost = 0; - m_FireworkItem.EmptyData(); - m_ItemColor.Clear(); - } - - - void Clear(void) - { - m_ItemType = E_ITEM_EMPTY; - m_ItemCount = 0; - m_ItemDamage = 0; - m_RepairCost = 0; - m_ItemColor.Clear(); - } - + /** Empties the item and frees up any dynamic storage used by the internals. + TODO: What is the usage difference? Merge with Empty()? */ + void Clear(void); + /** Returns true if the item represents an empty stack - either the type is invalid, or count is zero. */ bool IsEmpty(void) const { return ((m_ItemType <= 0) || (m_ItemCount <= 0)); diff --git a/src/Items/ItemBigFlower.h b/src/Items/ItemBigFlower.h index d433c4b87..8e96ad602 100644 --- a/src/Items/ItemBigFlower.h +++ b/src/Items/ItemBigFlower.h @@ -2,6 +2,7 @@ #pragma once #include "ItemHandler.h" +#include "../BlockInfo.h" diff --git a/src/Items/ItemBottle.h b/src/Items/ItemBottle.h index 18767dcde..319bc708f 100644 --- a/src/Items/ItemBottle.h +++ b/src/Items/ItemBottle.h @@ -2,6 +2,7 @@ #pragma once #include "ItemHandler.h" +#include "../BlockInfo.h" #include "../World.h" diff --git a/src/Items/ItemBucket.h b/src/Items/ItemBucket.h index 8affff6ca..7b837d449 100644 --- a/src/Items/ItemBucket.h +++ b/src/Items/ItemBucket.h @@ -2,6 +2,7 @@ #pragma once #include "ItemHandler.h" +#include "../BlockInfo.h" #include "../World.h" #include "../Simulator/FluidSimulator.h" #include "../Blocks/BlockHandler.h" @@ -70,7 +71,7 @@ public: } BLOCKTYPE Block = a_World->GetBlock(BlockPos.x, BlockPos.y, BlockPos.z); - ENUM_ITEM_ID NewItemType; + ENUM_ITEM_TYPE NewItemType; if (IsBlockWater(Block)) { diff --git a/src/Items/ItemChest.h b/src/Items/ItemChest.h index 817020a25..ac4e4b471 100644 --- a/src/Items/ItemChest.h +++ b/src/Items/ItemChest.h @@ -2,6 +2,7 @@ #pragma once #include "ItemHandler.h" +#include "../BlockInfo.h" #include "../Blocks/BlockChest.h" diff --git a/src/Items/ItemPickaxe.h b/src/Items/ItemPickaxe.h index a23e9ec6d..58df18428 100644 --- a/src/Items/ItemPickaxe.h +++ b/src/Items/ItemPickaxe.h @@ -168,7 +168,7 @@ public: virtual float GetBlockBreakingStrength(BLOCKTYPE a_Block) override { - if (!IsBlockMaterialIron(a_Block) && !IsBlockMaterialAnvil(a_Block) && !IsBlockMaterialRock(a_Block)) + if (!IsBlockMaterialIron(a_Block) && (a_Block != E_BLOCK_ANVIL) && !IsBlockMaterialRock(a_Block)) { return super::GetBlockBreakingStrength(a_Block); } diff --git a/src/Items/ItemShears.h b/src/Items/ItemShears.h index 9a6baa5e1..2ceb371f4 100644 --- a/src/Items/ItemShears.h +++ b/src/Items/ItemShears.h @@ -78,11 +78,11 @@ public: virtual float GetBlockBreakingStrength(BLOCKTYPE a_Block) override { - if (IsBlocksWeb(a_Block) || IsBlockMaterialLeaves(a_Block)) + if ((a_Block == E_BLOCK_COBWEB) || IsBlockMaterialLeaves(a_Block)) { return 15.0f; } - else if (IsBlocksWool(a_Block)) + else if (a_Block == E_BLOCK_WOOL) { return 5.0f; } diff --git a/src/Items/ItemSword.h b/src/Items/ItemSword.h index 06543c37e..cdb85727c 100644 --- a/src/Items/ItemSword.h +++ b/src/Items/ItemSword.h @@ -2,6 +2,7 @@ #pragma once #include "ItemHandler.h" +#include "../BlockInfo.h" @@ -12,8 +13,8 @@ class cItemSwordHandler : { typedef cItemHandler super; public: - cItemSwordHandler(int a_ItemType) - : cItemHandler(a_ItemType) + cItemSwordHandler(int a_ItemType): + cItemHandler(a_ItemType) { } @@ -66,7 +67,6 @@ public: if ( IsBlockMaterialPlants(a_Block) || IsBlockMaterialVine(a_Block) || - IsBlockMaterialCoral(a_Block) || IsBlockMaterialLeaves(a_Block) || IsBlockMaterialGourd(a_Block) ) diff --git a/src/LightingThread.cpp b/src/LightingThread.cpp index 53f6b2d86..426de86ac 100644 --- a/src/LightingThread.cpp +++ b/src/LightingThread.cpp @@ -7,6 +7,7 @@ #include "LightingThread.h" #include "ChunkMap.h" #include "World.h" +#include "BlockInfo.h" @@ -541,6 +542,33 @@ void cLightingThread::CompressLight(NIBBLETYPE * a_LightArray, NIBBLETYPE * a_Ch +void cLightingThread::PropagateLight( + NIBBLETYPE * a_Light, + unsigned int a_SrcIdx, unsigned int a_DstIdx, + size_t & a_NumSeedsOut, unsigned char * a_IsSeedOut, unsigned int * a_SeedIdxOut +) +{ + ASSERT(a_SrcIdx < ARRAYCOUNT(m_SkyLight)); + ASSERT(a_DstIdx < ARRAYCOUNT(m_BlockTypes)); + + if (a_Light[a_SrcIdx] <= a_Light[a_DstIdx] + cBlockInfo::GetSpreadLightFalloff(m_BlockTypes[a_DstIdx])) + { + // We're not offering more light than the dest block already has + return; + } + + a_Light[a_DstIdx] = a_Light[a_SrcIdx] - cBlockInfo::GetSpreadLightFalloff(m_BlockTypes[a_DstIdx]); + if (!a_IsSeedOut[a_DstIdx]) + { + a_IsSeedOut[a_DstIdx] = true; + a_SeedIdxOut[a_NumSeedsOut++] = a_DstIdx; + } +} + + + + + void cLightingThread::QueueChunkStay(cLightingChunkStay & a_ChunkStay) { // Move the ChunkStay from the Pending queue to the lighting queue. diff --git a/src/LightingThread.h b/src/LightingThread.h index 6c27ff7ba..4e009fd0c 100644 --- a/src/LightingThread.h +++ b/src/LightingThread.h @@ -159,28 +159,11 @@ protected: /** Compresses from 1-block-per-byte (faster calc) into 2-blocks-per-byte (MC storage): */ void CompressLight(NIBBLETYPE * a_LightArray, NIBBLETYPE * a_ChunkLight); - inline void PropagateLight( + void PropagateLight( NIBBLETYPE * a_Light, unsigned int a_SrcIdx, unsigned int a_DstIdx, size_t & a_NumSeedsOut, unsigned char * a_IsSeedOut, unsigned int * a_SeedIdxOut - ) - { - ASSERT(a_SrcIdx < ARRAYCOUNT(m_SkyLight)); - ASSERT(a_DstIdx < ARRAYCOUNT(m_BlockTypes)); - - if (a_Light[a_SrcIdx] <= a_Light[a_DstIdx] + cBlockInfo::GetSpreadLightFalloff(m_BlockTypes[a_DstIdx])) - { - // We're not offering more light than the dest block already has - return; - } - - a_Light[a_DstIdx] = a_Light[a_SrcIdx] - cBlockInfo::GetSpreadLightFalloff(m_BlockTypes[a_DstIdx]); - if (!a_IsSeedOut[a_DstIdx]) - { - a_IsSeedOut[a_DstIdx] = true; - a_SeedIdxOut[a_NumSeedsOut++] = a_DstIdx; - } - } + ); /** Queues a chunkstay that has all of its chunks loaded. Called by cLightingChunkStay when all of its chunks are loaded. */ diff --git a/src/LineBlockTracer.cpp b/src/LineBlockTracer.cpp index d8386574b..0f1d798be 100644 --- a/src/LineBlockTracer.cpp +++ b/src/LineBlockTracer.cpp @@ -5,6 +5,7 @@ #include "Globals.h" #include "LineBlockTracer.h" +#include "BlockInfo.h" #include "World.h" #include "Chunk.h" #include "BoundingBox.h" diff --git a/src/Map.cpp b/src/Map.cpp index 479ea0bae..a17e332da 100644 --- a/src/Map.cpp +++ b/src/Map.cpp @@ -4,7 +4,7 @@ #include "Globals.h" #include "Map.h" - +#include "BlockInfo.h" #include "World.h" #include "Chunk.h" #include "Entities/Player.h" @@ -9,6 +9,8 @@ #pragma once +#include "Defines.h" + diff --git a/src/MobSpawner.cpp b/src/MobSpawner.cpp index 41855a638..73531f2fc 100644 --- a/src/MobSpawner.cpp +++ b/src/MobSpawner.cpp @@ -2,6 +2,7 @@ #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "MobSpawner.h" +#include "BlockInfo.h" #include "Mobs/IncludeAllMonsters.h" #include "World.h" diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index 233ca70b3..5a01663e5 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -2,6 +2,7 @@ #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "IncludeAllMonsters.h" +#include "../BlockInfo.h" #include "../Root.h" #include "../Server.h" #include "../ClientHandle.h" diff --git a/src/Mobs/MonsterTypes.h b/src/Mobs/MonsterTypes.h index 96b4d0df0..6aaa61dc6 100644 --- a/src/Mobs/MonsterTypes.h +++ b/src/Mobs/MonsterTypes.h @@ -6,47 +6,42 @@ // tolua_begin -/** Identifies individual monster type, as well as their network type-ID. */ +/** Identifies individual monster type. */ enum eMonsterType { mtInvalidType = -1, - mtBat = E_META_SPAWN_EGG_BAT, - mtBlaze = E_META_SPAWN_EGG_BLAZE, - mtCaveSpider = E_META_SPAWN_EGG_CAVE_SPIDER, - mtChicken = E_META_SPAWN_EGG_CHICKEN, - mtCow = E_META_SPAWN_EGG_COW, - mtCreeper = E_META_SPAWN_EGG_CREEPER, - mtEnderDragon = E_META_SPAWN_EGG_ENDER_DRAGON, - mtEnderman = E_META_SPAWN_EGG_ENDERMAN, - mtGhast = E_META_SPAWN_EGG_GHAST, - mtGiant = E_META_SPAWN_EGG_GIANT, - mtGuardian = E_META_SPAWN_EGG_GUARDIAN, - mtHorse = E_META_SPAWN_EGG_HORSE, - mtIronGolem = E_META_SPAWN_EGG_IRON_GOLEM, - mtMagmaCube = E_META_SPAWN_EGG_MAGMA_CUBE, - mtMooshroom = E_META_SPAWN_EGG_MOOSHROOM, - mtOcelot = E_META_SPAWN_EGG_OCELOT, - mtPig = E_META_SPAWN_EGG_PIG, - mtRabbit = E_META_SPAWN_EGG_RABBIT, - mtSheep = E_META_SPAWN_EGG_SHEEP, - mtSilverfish = E_META_SPAWN_EGG_SILVERFISH, - mtSkeleton = E_META_SPAWN_EGG_SKELETON, - mtSlime = E_META_SPAWN_EGG_SLIME, - mtSnowGolem = E_META_SPAWN_EGG_SNOW_GOLEM, - mtSpider = E_META_SPAWN_EGG_SPIDER, - mtSquid = E_META_SPAWN_EGG_SQUID, - mtVillager = E_META_SPAWN_EGG_VILLAGER, - mtWitch = E_META_SPAWN_EGG_WITCH, - mtWither = E_META_SPAWN_EGG_WITHER, - mtWolf = E_META_SPAWN_EGG_WOLF, - mtZombie = E_META_SPAWN_EGG_ZOMBIE, - mtZombiePigman = E_META_SPAWN_EGG_ZOMBIE_PIGMAN, - mtMax = 120, // This is just a hotfix for https://forum.cuberite.org/thread-1616.html. Tolua is too bad to find the highest value, so this is needed. + mtBat, + mtBlaze, + mtCaveSpider, + mtChicken, + mtCow, + mtCreeper, + mtEnderDragon, + mtEnderman, + mtGhast, + mtGiant, + mtGuardian, + mtHorse, + mtIronGolem, + mtMagmaCube, + mtMooshroom, + mtOcelot, + mtPig, + mtRabbit, + mtSheep, + mtSilverfish, + mtSkeleton, + mtSlime, + mtSnowGolem, + mtSpider, + mtSquid, + mtVillager, + mtWitch, + mtWither, + mtWolf, + mtZombie, + mtZombiePigman, } ; // tolua_end - - - - diff --git a/src/Mobs/Path.cpp b/src/Mobs/Path.cpp index fa57fa1ca..a2a5cf51c 100644 --- a/src/Mobs/Path.cpp +++ b/src/Mobs/Path.cpp @@ -2,6 +2,7 @@ #include "Globals.h" #include "Path.h" +#include "../BlockInfo.h" #include "../Chunk.h" #define JUMP_G_COST 20 diff --git a/src/Mobs/PathFinder.cpp b/src/Mobs/PathFinder.cpp index a4f237fbd..f2542cebc 100644 --- a/src/Mobs/PathFinder.cpp +++ b/src/Mobs/PathFinder.cpp @@ -1,5 +1,6 @@ #include "Globals.h" #include "PathFinder.h" +#include "../BlockInfo.h" #include "../Chunk.h" diff --git a/src/Mobs/SnowGolem.cpp b/src/Mobs/SnowGolem.cpp index 3ea97173f..ce94c9dae 100644 --- a/src/Mobs/SnowGolem.cpp +++ b/src/Mobs/SnowGolem.cpp @@ -2,6 +2,7 @@ #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "SnowGolem.h" +#include "../BlockInfo.h" #include "../World.h" diff --git a/src/NetherPortalScanner.cpp b/src/NetherPortalScanner.cpp index a4564d0f1..8de0a6dcc 100644 --- a/src/NetherPortalScanner.cpp +++ b/src/NetherPortalScanner.cpp @@ -2,6 +2,7 @@ #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "NetherPortalScanner.h" +#include "BlockInfo.h" #include "Entities/Entity.h" #include "World.h" diff --git a/src/Protocol/ChunkDataSerializer.h b/src/Protocol/ChunkDataSerializer.h index a77935258..27a3d9426 100644 --- a/src/Protocol/ChunkDataSerializer.h +++ b/src/Protocol/ChunkDataSerializer.h @@ -1,6 +1,7 @@ #pragma once #include "../ChunkData.h" +#include "../Defines.h" diff --git a/src/Protocol/Protocol_1_8.cpp b/src/Protocol/Protocol_1_8.cpp index d381f0a42..9509fe51e 100644 --- a/src/Protocol/Protocol_1_8.cpp +++ b/src/Protocol/Protocol_1_8.cpp @@ -3092,7 +3092,7 @@ void cProtocol_1_8_0::ParseItemMetadata(cItem & a_Item, const AString & a_Metada } else if ((TagName == "Fireworks") || (TagName == "Explosion")) { - cFireworkItem::ParseFromNBT(a_Item.m_FireworkItem, NBT, tag, static_cast<ENUM_ITEM_ID>(a_Item.m_ItemType)); + cFireworkItem::ParseFromNBT(a_Item.m_FireworkItem, NBT, tag, static_cast<ENUM_ITEM_TYPE>(a_Item.m_ItemType)); } break; } @@ -3282,7 +3282,7 @@ void cProtocol_1_8_0::WriteItem(cPacketizer & a_Pkt, const cItem & a_Item) } if ((a_Item.m_ItemType == E_ITEM_FIREWORK_ROCKET) || (a_Item.m_ItemType == E_ITEM_FIREWORK_STAR)) { - cFireworkItem::WriteToNBTCompound(a_Item.m_FireworkItem, Writer, static_cast<ENUM_ITEM_ID>(a_Item.m_ItemType)); + cFireworkItem::WriteToNBTCompound(a_Item.m_FireworkItem, Writer, static_cast<ENUM_ITEM_TYPE>(a_Item.m_ItemType)); } Writer.Finish(); diff --git a/src/Protocol/Protocol_1_9.cpp b/src/Protocol/Protocol_1_9.cpp index eac539ce3..d31db7ec4 100644 --- a/src/Protocol/Protocol_1_9.cpp +++ b/src/Protocol/Protocol_1_9.cpp @@ -3227,7 +3227,7 @@ void cProtocol_1_9_0::ParseItemMetadata(cItem & a_Item, const AString & a_Metada } else if ((TagName == "Fireworks") || (TagName == "Explosion")) { - cFireworkItem::ParseFromNBT(a_Item.m_FireworkItem, NBT, tag, static_cast<ENUM_ITEM_ID>(a_Item.m_ItemType)); + cFireworkItem::ParseFromNBT(a_Item.m_FireworkItem, NBT, tag, static_cast<ENUM_ITEM_TYPE>(a_Item.m_ItemType)); } else if (TagName == "EntityTag") { @@ -3592,7 +3592,7 @@ void cProtocol_1_9_0::WriteItem(cPacketizer & a_Pkt, const cItem & a_Item) } if ((a_Item.m_ItemType == E_ITEM_FIREWORK_ROCKET) || (a_Item.m_ItemType == E_ITEM_FIREWORK_STAR)) { - cFireworkItem::WriteToNBTCompound(a_Item.m_FireworkItem, Writer, static_cast<ENUM_ITEM_ID>(a_Item.m_ItemType)); + cFireworkItem::WriteToNBTCompound(a_Item.m_FireworkItem, Writer, static_cast<ENUM_ITEM_TYPE>(a_Item.m_ItemType)); } if (a_Item.m_ItemType == E_ITEM_POTION) { diff --git a/src/Root.h b/src/Root.h index 90676a7df..6c84e6bf7 100644 --- a/src/Root.h +++ b/src/Root.h @@ -14,6 +14,7 @@ // fwd: +class cItem; class cMonsterConfig; class cBrewingRecipes; class cCraftingRecipes; diff --git a/src/Simulator/FireSimulator.cpp b/src/Simulator/FireSimulator.cpp index 304450b3c..2a9d6c289 100644 --- a/src/Simulator/FireSimulator.cpp +++ b/src/Simulator/FireSimulator.cpp @@ -2,6 +2,7 @@ #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "FireSimulator.h" +#include "../BlockInfo.h" #include "../World.h" #include "../Defines.h" #include "../Chunk.h" diff --git a/src/Simulator/FireSimulator.h b/src/Simulator/FireSimulator.h index 236be5686..f36407584 100644 --- a/src/Simulator/FireSimulator.h +++ b/src/Simulator/FireSimulator.h @@ -2,6 +2,7 @@ #pragma once #include "Simulator.h" +#include "../IniFile.h" diff --git a/src/Simulator/FloodyFluidSimulator.cpp b/src/Simulator/FloodyFluidSimulator.cpp index b620dddce..14573e0de 100644 --- a/src/Simulator/FloodyFluidSimulator.cpp +++ b/src/Simulator/FloodyFluidSimulator.cpp @@ -7,6 +7,7 @@ #include "Globals.h" #include "FloodyFluidSimulator.h" +#include "../BlockInfo.h" #include "../World.h" #include "../Chunk.h" #include "../BlockArea.h" diff --git a/src/Simulator/SandSimulator.cpp b/src/Simulator/SandSimulator.cpp index 5f0595d48..42bb521ed 100644 --- a/src/Simulator/SandSimulator.cpp +++ b/src/Simulator/SandSimulator.cpp @@ -2,6 +2,7 @@ #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "SandSimulator.h" +#include "../BlockInfo.h" #include "../World.h" #include "../Defines.h" #include "../Entities/FallingBlock.h" @@ -283,7 +284,7 @@ void cSandSimulator::FinishFalling( // Create a pickup instead: cItems Pickups; - Pickups.Add(static_cast<ENUM_ITEM_ID>(a_FallingBlockType), 1, a_FallingBlockMeta); + Pickups.Add(static_cast<ENUM_ITEM_TYPE>(a_FallingBlockType), 1, a_FallingBlockMeta); a_World->SpawnItemPickups( Pickups, static_cast<double>(a_BlockX) + 0.5, diff --git a/src/Simulator/SandSimulator.h b/src/Simulator/SandSimulator.h index cee0a85e6..d7a27edd4 100644 --- a/src/Simulator/SandSimulator.h +++ b/src/Simulator/SandSimulator.h @@ -2,6 +2,7 @@ #pragma once #include "Simulator.h" +#include "../IniFile.h" diff --git a/src/Simulator/VanillaFluidSimulator.cpp b/src/Simulator/VanillaFluidSimulator.cpp index f6fe1e9ec..0fc84be59 100644 --- a/src/Simulator/VanillaFluidSimulator.cpp +++ b/src/Simulator/VanillaFluidSimulator.cpp @@ -4,6 +4,7 @@ #include "Globals.h" #include "VanillaFluidSimulator.h" +#include "../BlockInfo.h" #include "../World.h" #include "../Chunk.h" #include "../BlockArea.h" diff --git a/src/Tracer.cpp b/src/Tracer.cpp index 91a89f96c..dd4cde479 100644 --- a/src/Tracer.cpp +++ b/src/Tracer.cpp @@ -2,6 +2,7 @@ #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "Tracer.h" +#include "BlockInfo.h" #include "World.h" #include "Entities/Entity.h" diff --git a/src/World.cpp b/src/World.cpp index 9c7928c89..464d84be5 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -2,6 +2,7 @@ #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "World.h" +#include "BlockInfo.h" #include "ClientHandle.h" #include "Server.h" #include "Root.h" diff --git a/src/World.h b/src/World.h index e1341c9cb..b46440410 100644 --- a/src/World.h +++ b/src/World.h @@ -739,7 +739,7 @@ public: /** Does an explosion with the specified strength at the specified coordinates. Executes the HOOK_EXPLODING and HOOK_EXPLODED hooks as part of the processing. - a_SourceData exact type depends on the a_Source, see the declaration of the esXXX constants in BlockID.h for details. + a_SourceData exact type depends on the a_Source, see the declaration of the esXXX constants in Defines.h for details. Exported to Lua manually in ManualBindings_World.cpp in order to support the variable a_SourceData param. */ virtual void DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_BlockY, double a_BlockZ, bool a_CanCauseFire, eExplosionSource a_Source, void * a_SourceData) override; diff --git a/src/WorldStorage/FireworksSerializer.cpp b/src/WorldStorage/FireworksSerializer.cpp index 891a67e62..7cf3c3eea 100644 --- a/src/WorldStorage/FireworksSerializer.cpp +++ b/src/WorldStorage/FireworksSerializer.cpp @@ -2,12 +2,13 @@ #include "Globals.h" #include "FireworksSerializer.h" #include "../WorldStorage/FastNBT.h" +#include "../BlockType.h" -void cFireworkItem::WriteToNBTCompound(const cFireworkItem & a_FireworkItem, cFastNBTWriter & a_Writer, const ENUM_ITEM_ID a_Type) +void cFireworkItem::WriteToNBTCompound(const cFireworkItem & a_FireworkItem, cFastNBTWriter & a_Writer, const ENUM_ITEM_TYPE a_Type) { switch (a_Type) { @@ -58,7 +59,7 @@ void cFireworkItem::WriteToNBTCompound(const cFireworkItem & a_FireworkItem, cFa -void cFireworkItem::ParseFromNBT(cFireworkItem & a_FireworkItem, const cParsedNBT & a_NBT, int a_TagIdx, const ENUM_ITEM_ID a_Type) +void cFireworkItem::ParseFromNBT(cFireworkItem & a_FireworkItem, const cParsedNBT & a_NBT, int a_TagIdx, const ENUM_ITEM_TYPE a_Type) { if (a_TagIdx < 0) { diff --git a/src/WorldStorage/FireworksSerializer.h b/src/WorldStorage/FireworksSerializer.h index 9a24edadd..32264d2f3 100644 --- a/src/WorldStorage/FireworksSerializer.h +++ b/src/WorldStorage/FireworksSerializer.h @@ -10,6 +10,12 @@ #pragma once +#include "../BlockType.h" + + + + + class cFastNBTWriter; class cParsedNBT; @@ -62,10 +68,10 @@ public: } /** Writes firework NBT data to a Writer object */ - static void WriteToNBTCompound(const cFireworkItem & a_FireworkItem, cFastNBTWriter & a_Writer, const ENUM_ITEM_ID a_Type); + static void WriteToNBTCompound(const cFireworkItem & a_FireworkItem, cFastNBTWriter & a_Writer, const ENUM_ITEM_TYPE a_Type); /** Reads NBT data from a NBT object and populates a FireworkItem with it */ - static void ParseFromNBT(cFireworkItem & a_FireworkItem, const cParsedNBT & a_NBT, int a_TagIdx, const ENUM_ITEM_ID a_Type); + static void ParseFromNBT(cFireworkItem & a_FireworkItem, const cParsedNBT & a_NBT, int a_TagIdx, const ENUM_ITEM_TYPE a_Type); /** Converts the firework's vector of colours into a string of values separated by a semicolon */ static AString ColoursToString(const cFireworkItem & a_FireworkItem); diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp index 0a18cb7b3..014ee2c27 100644 --- a/src/WorldStorage/NBTChunkSerializer.cpp +++ b/src/WorldStorage/NBTChunkSerializer.cpp @@ -322,7 +322,7 @@ public: if ((a_Item.m_ItemType == E_ITEM_FIREWORK_ROCKET) || (a_Item.m_ItemType == E_ITEM_FIREWORK_STAR)) { - cFireworkItem::WriteToNBTCompound(a_Item.m_FireworkItem, mWriter, static_cast<ENUM_ITEM_ID>(a_Item.m_ItemType)); + cFireworkItem::WriteToNBTCompound(a_Item.m_FireworkItem, mWriter, static_cast<ENUM_ITEM_TYPE>(a_Item.m_ItemType)); } if (!a_Item.m_Enchantments.IsEmpty()) diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index 4712e6ab1..0480680dd 100755 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -15,6 +15,7 @@ #include "../StringCompression.h" #include "../SetChunkData.h" #include "../Root.h" +#include "../BlockType.h" #include "../BlockEntities/BeaconEntity.h" #include "../BlockEntities/BedEntity.h" @@ -363,10 +364,10 @@ bool cWSSAnvil::LoadChunkFromNBT(const cChunkCoords & a_Chunk, const cParsedNBT cChunkDef::BlockNibbles BlockLight; cChunkDef::BlockNibbles SkyLight; - memset(BlockTypes, E_BLOCK_AIR, sizeof(BlockTypes)); - memset(MetaData, 0, sizeof(MetaData)); - memset(SkyLight, 0xff, sizeof(SkyLight)); // By default, data not present in the NBT means air, which means full skylight - memset(BlockLight, 0x00, sizeof(BlockLight)); + memset(BlockTypes, 0, sizeof(BlockTypes)); + memset(MetaData, 0, sizeof(MetaData)); + memset(SkyLight, 0xff, sizeof(SkyLight)); // By default, data not present in the NBT means air, which means full skylight + memset(BlockLight, 0x00, sizeof(BlockLight)); // Load the blockdata, blocklight and skylight: int Level = a_NBT.FindChildByName(0, "Level"); @@ -779,7 +780,7 @@ bool cWSSAnvil::LoadItemFromNBT(cItem & a_Item, const cParsedNBT & a_NBT, int a_ int FireworksTag = a_NBT.FindChildByName(TagTag, ((a_Item.m_ItemType == E_ITEM_FIREWORK_STAR) ? "Explosion" : "Fireworks")); if (FireworksTag > 0) { - cFireworkItem::ParseFromNBT(a_Item.m_FireworkItem, a_NBT, FireworksTag, static_cast<ENUM_ITEM_ID>(a_Item.m_ItemType)); + cFireworkItem::ParseFromNBT(a_Item.m_FireworkItem, a_NBT, FireworksTag, static_cast<ENUM_ITEM_TYPE>(a_Item.m_ItemType)); } return true; diff --git a/src/WorldStorage/WSSAnvil.h b/src/WorldStorage/WSSAnvil.h index 166230568..96945363e 100755 --- a/src/WorldStorage/WSSAnvil.h +++ b/src/WorldStorage/WSSAnvil.h @@ -15,7 +15,8 @@ -// fwd: ItemGrid.h +// fwd: +class cItem; class cItemGrid; class cMonster; class cProjectileEntity; |