1
0

Pulled the BlockID and BlockInfo headers from Globals.h. (#4591)

The BlockID.h file was removed from Globals.h and renamed to BlockType.h (main change)
The BlockInfo.h file was removed from Globals.h (main change)
The ENUM_BLOCK_ID and ENUM_ITEM_ID enum names were replaced with ENUM_BLOCK_TYPE and ENUM_ITEM_TYPE (cosmetics)
The various enums, such as eDimension, eDamageType and eExplosionSource were moved from BlockType.h to Defines.h, together with the helper functions for converting between them and strings (StringToDimension et al.) (minor)
Many inline functions were moved from headers to their respective cpp files, so that BlockType.h could be included only into the cpp file, rather than the header.
That broke our tests a bit, since they pick bits and pieces out of the main code and provide stubs for the rest; they had to be re-stubbed and re-verified.
eMonsterType values are no longer tied to E_ITEM_SPAWN_EGG_META_* values
This commit is contained in:
Mattes D 2020-04-03 08:57:01 +02:00 committed by GitHub
parent f2810db380
commit 01b8ed5295
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
98 changed files with 1628 additions and 1386 deletions

View File

@ -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"

View File

@ -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

View File

@ -10,6 +10,7 @@
#include "../Entities/Player.h"
#include "LuaState.h"
#include "../Tracer.h"
#include "../BlockInfo.h"

View File

@ -2,6 +2,7 @@
#pragma once
#include "../BlockType.h"
#include "../Defines.h"
#include "../FunctionRef.h"

View File

@ -15,6 +15,8 @@
#include "ChunkData.h"
#include "BlockEntities/BlockEntity.h"
#include "Item.h"
#include "BlockInfo.h"

View File

@ -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 &)>;

View File

@ -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"

View File

@ -4,6 +4,7 @@
#pragma once
#include "BlockEntity.h"
#include "../BlockType.h"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -2,6 +2,7 @@
#pragma once
#include "BlockEntity.h"
#include "../BlockType.h"

View File

@ -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;

View File

@ -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>
{

View File

@ -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);

View File

@ -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);

View File

@ -12,6 +12,7 @@
// fwd:
class cBlockHandler;
class BlockState;

View File

@ -3,6 +3,7 @@
#include "BlockHandler.h"
#include "ChunkInterface.h"
#include "../BlockInfo.h"
#include "../Items/ItemHandler.h"

View File

@ -1,6 +1,7 @@
#pragma once
#include "BlockHandler.h"
#include "../BlockInfo.h"
#include "../Chunk.h"
#include "Mixins.h"

View File

@ -1,6 +1,7 @@
#pragma once
#include "BlockPlant.h"
#include "../BlockInfo.h"

View File

@ -2,6 +2,7 @@
#pragma once
#include "BlockHandler.h"
#include "../BlockInfo.h"
#include "../Entities/Player.h"
#include "../Chunk.h"
#include "Mixins.h"

View File

@ -2,7 +2,7 @@
#pragma once
#include "../Defines.h"
#include "../Item.h"
#include "../BoundingBox.h"

View File

@ -1,6 +1,7 @@
#include "Globals.h"
#include "BlockPiston.h"
#include "../BlockInfo.h"
#include "../Item.h"
#include "../World.h"
#include "../Entities/Player.h"

View File

@ -11,7 +11,9 @@
#include "BlockHandler.h"
#include "ChunkInterface.h"
#include "../BlockInfo.h"
#include "../Entities/Player.h"
#include "../BlockInfo.h"

View File

@ -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>
{

View File

@ -6,6 +6,7 @@
#include "WorldInterface.h"
#include "../ChunkMap.h"
#include "../World.h"
#include "../BlockInfo.h"

View File

@ -5,10 +5,17 @@
// fwd:
class cItem;
class cChunkMap;
class cWorldInterface;
class cPlayer;
class cChunkInterface:
public cForEachChunkProvider
{

View File

@ -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")

View File

@ -7,6 +7,7 @@
#include "Chunk.h"
#include "BlockInfo.h"
#include "World.h"
#include "ClientHandle.h"
#include "Server.h"

View File

@ -5,6 +5,7 @@
#include "Globals.h"
#include "ChunkData.h"
#include "BlockType.h"

View File

@ -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"

View File

@ -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"

View File

@ -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);
}

View File

@ -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);
}

627
src/Defines.cpp Normal file
View File

@ -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;
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -7,6 +7,7 @@
#include "WorldStorage/FastNBT.h"
#include "FastRandom.h"
#include "Noise/Noise.h"
#include "BlockType.h"

View File

@ -5,6 +5,7 @@
#include "Globals.h"
#include "Boat.h"
#include "../BlockInfo.h"
#include "../World.h"
#include "../ClientHandle.h"
#include "Player.h"

View File

@ -3,6 +3,7 @@
#include "Entity.h"
#include "Player.h"
#include "../BlockInfo.h"
#include "../World.h"
#include "../Root.h"
#include "../Matrix4.h"

View File

@ -1,6 +1,7 @@
#include "Globals.h"
#include "FallingBlock.h"
#include "../BlockInfo.h"
#include "../World.h"
#include "../ClientHandle.h"
#include "../Simulator/SandSimulator.h"

View File

@ -1,6 +1,7 @@
#include "Globals.h"
#include "../BlockInfo.h"
#include "../BoundingBox.h"
#include "../Chunk.h"
#include "Floater.h"

View File

@ -7,6 +7,7 @@
#include "Globals.h"
#include "Minecart.h"
#include "../BlockInfo.h"
#include "../ClientHandle.h"
#include "../Chunk.h"
#include "Player.h"

View File

@ -3,6 +3,7 @@
#include "Pawn.h"
#include "Player.h"
#include "../BlockInfo.h"
#include "../World.h"
#include "../Bindings/PluginManager.h"
#include "../BoundingBox.h"

View File

@ -7,6 +7,7 @@
#include "../Bindings/PluginManager.h"
#include "ProjectileEntity.h"
#include "../BlockInfo.h"
#include "../ClientHandle.h"
#include "../LineBlockTracer.h"
#include "../BoundingBox.h"

View File

@ -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"

View File

@ -1,5 +1,6 @@
#pragma once
#include "../Defines.h"

View File

@ -5,6 +5,7 @@
#include "Globals.h"
#include "DungeonRoomsFinisher.h"
#include "../BlockInfo.h"
#include "../FastRandom.h"
#include "../BlockEntities/ChestEntity.h"
#include "../BlockEntities/MobSpawnerEntity.h"

View File

@ -14,6 +14,7 @@
#include "../Simulator/FireSimulator.h"
#include "../IniFile.h"
#include "../MobSpawner.h"
#include "../BlockInfo.h"

View File

@ -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"

View File

@ -6,6 +6,7 @@
#include "Globals.h"
#include "RoughRavines.h"
#include "../BlockInfo.h"

View File

@ -6,6 +6,7 @@
#include "Trees.h"
#include "../BlockArea.h"
#include "../LinearUpscale.h"
#include "../BlockInfo.h"

View File

@ -5,6 +5,7 @@
#include "Globals.h"
#include "Trees.h"
#include "../BlockType.h"

View File

@ -6,6 +6,7 @@
#include "Globals.h"
#include "VillageGen.h"
#include "PieceGeneratorBFSTree.h"
#include "../BlockInfo.h"

View File

@ -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"

View File

@ -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());

View File

@ -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));

View File

@ -2,6 +2,7 @@
#pragma once
#include "ItemHandler.h"
#include "../BlockInfo.h"

View File

@ -2,6 +2,7 @@
#pragma once
#include "ItemHandler.h"
#include "../BlockInfo.h"
#include "../World.h"

View File

@ -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))
{

View File

@ -2,6 +2,7 @@
#pragma once
#include "ItemHandler.h"
#include "../BlockInfo.h"
#include "../Blocks/BlockChest.h"

View File

@ -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);
}

View File

@ -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;
}

View File

@ -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)
)

View File

@ -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.

View File

@ -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. */

View File

@ -5,6 +5,7 @@
#include "Globals.h"
#include "LineBlockTracer.h"
#include "BlockInfo.h"
#include "World.h"
#include "Chunk.h"
#include "BoundingBox.h"

View File

@ -4,7 +4,7 @@
#include "Globals.h"
#include "Map.h"
#include "BlockInfo.h"
#include "World.h"
#include "Chunk.h"
#include "Entities/Player.h"

View File

@ -9,6 +9,8 @@
#pragma once
#include "Defines.h"

View File

@ -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"

View File

@ -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"

View File

@ -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

View File

@ -2,6 +2,7 @@
#include "Globals.h"
#include "Path.h"
#include "../BlockInfo.h"
#include "../Chunk.h"
#define JUMP_G_COST 20

View File

@ -1,5 +1,6 @@
#include "Globals.h"
#include "PathFinder.h"
#include "../BlockInfo.h"
#include "../Chunk.h"

View File

@ -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"

View File

@ -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"

View File

@ -1,6 +1,7 @@
#pragma once
#include "../ChunkData.h"
#include "../Defines.h"

View File

@ -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();

View File

@ -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)
{

View File

@ -14,6 +14,7 @@
// fwd:
class cItem;
class cMonsterConfig;
class cBrewingRecipes;
class cCraftingRecipes;

View File

@ -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"

View File

@ -2,6 +2,7 @@
#pragma once
#include "Simulator.h"
#include "../IniFile.h"

View File

@ -7,6 +7,7 @@
#include "Globals.h"
#include "FloodyFluidSimulator.h"
#include "../BlockInfo.h"
#include "../World.h"
#include "../Chunk.h"
#include "../BlockArea.h"

View File

@ -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,

View File

@ -2,6 +2,7 @@
#pragma once
#include "Simulator.h"
#include "../IniFile.h"

View File

@ -4,6 +4,7 @@
#include "Globals.h"
#include "VanillaFluidSimulator.h"
#include "../BlockInfo.h"
#include "../World.h"
#include "../Chunk.h"
#include "../BlockArea.h"

View File

@ -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"

View File

@ -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"

View File

@ -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;

View File

@ -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)
{

View File

@ -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);

View File

@ -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())

View File

@ -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;

View File

@ -15,7 +15,8 @@
// fwd: ItemGrid.h
// fwd:
class cItem;
class cItemGrid;
class cMonster;
class cProjectileEntity;

View File

@ -175,7 +175,18 @@ static void testGenerateNether(cChunkGenerator & aDefaultNetherGen)
{
TEST_EQUAL_MSG(chd.GetBlockType(x, 0, z), E_BLOCK_BEDROCK, Printf("Bedrock floor at {%d, 0, %d}", x, z));
auto y = chd.GetHeight(x, z);
TEST_EQUAL(y, prevHeight); // Same height across the entire chunk
auto topBlockType = chd.GetBlockType(x, y, z);
// Skip the mushrooms generated on the top bedrock layer:
if (
(topBlockType == E_BLOCK_BROWN_MUSHROOM) ||
(topBlockType == E_BLOCK_RED_MUSHROOM)
)
{
y -= 1;
}
TEST_EQUAL_MSG(y, prevHeight, Printf("Failed: Same height across the entire chunk, at {%d, %d}: exp %d, got %d; top block: %d",
x, z, prevHeight, y, chd.GetBlockType(x, y, z)
))
auto blockType = chd.GetBlockType(x, y, z);
TEST_EQUAL_MSG(blockType, E_BLOCK_BEDROCK,
Printf("Bedrock ceiling at {%d, %d, %d}: %d", x, y, z, blockType)
@ -245,6 +256,11 @@ static void checkChunkChecksums(
{
cChunkDesc chd(coords.mCoords);
aGenerator.Generate(chd);
/*
cFile f(Printf("Repeatability_%s-%02d-%02d.raw", aDimension, coords.mCoords.m_ChunkX, coords.mCoords.m_ChunkZ), cFile::fmWrite);
f.Write(chd.GetBlockTypes(), sizeof(chd.GetBlockTypes()));
f.Close();
*/
auto checksum = chunkSHA1(chd);
TEST_EQUAL_MSG(checksum, coords.mChecksum,
Printf("%s chunk %s SHA1: expected %s, got %s", aDimension, coords.mCoords.ToString(), coords.mChecksum, checksum)
@ -275,11 +291,11 @@ static void testRepeatability(cChunkGenerator & aDefaultOverworldGenerator, cChu
// Test the default Nether generator:
std::vector<CoordsWithChecksum> netherChecksums =
{
{ 0, 0, "-25231a9ce4bc57eaeaf1f4ad01c32ddd5b2293e5"},
{ 1, 0, "-61ef8824b6b241b4f0e28c09505bad5d7898a8a4"},
{ 1, 1, "6b3ba6dcb18568e21b3a5aae9ea58368079fbaf8"},
{17, 0, "1acc3a28eb1be66b3e4a256f0712a48f96085a39"},
{ 8, 1024, "6f9b96e0613ca2fd879dbb53634b511e5649627a"},
{ 0, 0, "-487001a1ada9cdd7c8b557d3ff7081881f57c660"},
{ 1, 0, "a074ac7a1f2fbf4173324e5edd792197d6a29c2"},
{ 1, 1, "5867c5121f2a259ebc2aa53ecafed93dd3d6de95"},
{17, 0, "-300191cee5b30592f7b61cd22ea08669eba3f569"},
{ 8, 1024, "69bbda09be981f5e3adc53d0a49995aff43f1290"},
};
checkChunkChecksums(aDefaultNetherGenerator, netherChecksums, "Nether");
}

View File

@ -11,9 +11,11 @@ add_definitions(-DTEST_GLOBALS=1)
set (SHARED_SRCS
${CMAKE_SOURCE_DIR}/src/BiomeDef.cpp
${CMAKE_SOURCE_DIR}/src/BlockArea.cpp
${CMAKE_SOURCE_DIR}/src/BlockID.cpp
${CMAKE_SOURCE_DIR}/src/BlockInfo.cpp
${CMAKE_SOURCE_DIR}/src/BlockType.cpp
${CMAKE_SOURCE_DIR}/src/Cuboid.cpp
${CMAKE_SOURCE_DIR}/src/ChunkData.cpp
${CMAKE_SOURCE_DIR}/src/Defines.cpp
${CMAKE_SOURCE_DIR}/src/Enchantments.cpp
${CMAKE_SOURCE_DIR}/src/FastRandom.cpp
${CMAKE_SOURCE_DIR}/src/IniFile.cpp
@ -71,10 +73,12 @@ set (GENERATING_SRCS
set (SHARED_HDRS
${CMAKE_SOURCE_DIR}/src/BiomeDef.h
${CMAKE_SOURCE_DIR}/src/BlockArea.h
${CMAKE_SOURCE_DIR}/src/BlockID.h
${CMAKE_SOURCE_DIR}/src/BlockInfo.h
${CMAKE_SOURCE_DIR}/src/BlockType.h
${CMAKE_SOURCE_DIR}/src/Cuboid.h
${CMAKE_SOURCE_DIR}/src/ChunkData.h
${CMAKE_SOURCE_DIR}/src/ChunkDef.h
${CMAKE_SOURCE_DIR}/src/Defines.h
${CMAKE_SOURCE_DIR}/src/Enchantments.h
${CMAKE_SOURCE_DIR}/src/FastRandom.h
${CMAKE_SOURCE_DIR}/src/Globals.h
@ -157,7 +161,7 @@ add_library(GeneratorTestingSupport STATIC
${GENERATING_HDRS}
${STUBS}
)
target_link_libraries(GeneratorTestingSupport tolualib zlib fmt::fmt)
target_link_libraries(GeneratorTestingSupport tolualib zlib fmt::fmt jsoncpp_lib_static)
source_group("Stubs" FILES ${STUBS})
source_group("Generating" FILES ${GENERATING_HDRS} ${GENERATING_SRCS})

View File

@ -93,30 +93,6 @@ extern "C" int luaopen_lxp(lua_State * a_LuaState)
void cBlockInfo::sHandlerDeleter::operator () (cBlockHandler * a_Handler)
{
delete a_Handler;
}
cBlockInfo::cBlockInfoArray::cBlockInfoArray()
{
cBlockInfoArray & BlockInfos = *this;
// The piece-loading code uses the handlers for rotations, so we need valid handlers
// Insert dummy handlers:
for (size_t i = 0; i < BlockInfos.size(); i++)
{
BlockInfos[i].m_Handler.reset(new cBlockHandler(static_cast<BLOCKTYPE>(i)));
}
}
cBoundingBox::cBoundingBox(double, double, double, double, double, double)
{
}
@ -409,3 +385,43 @@ std::set<eMonsterType> cMobSpawner::GetAllowedMobTypes(EMCSBiome a_Biome)
{
return {};
}
cItem::cItem()
{
}
cItem::cItem(
short a_ItemType,
char a_ItemCount,
short a_ItemDamage,
const AString & a_Enchantments,
const AString & a_CustomName,
const AStringVector & a_LoreTable
)
{
}
void cItem::Empty()
{
}
cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType)
{
return new cBlockHandler(a_BlockType);
}

View File

@ -35,15 +35,6 @@ extern "C" int luaopen_lxp(lua_State * a_LuaState);
class cItems
{
// Empty class placeholder
};
void cManualBindings::Bind(lua_State * a_LuaState)
{
}
@ -104,6 +95,14 @@ void cBlockInfo::sHandlerDeleter::operator () (cBlockHandler * a_Handler)
cBlockInfo::cBlockInfo()
{
}
cBlockInfo::cBlockInfoArray::cBlockInfoArray()
{
cBlockInfoArray & BlockInfos = *this;

View File

@ -13,10 +13,9 @@
class cItems
cBlockInfo::cBlockInfo()
{
// Empty class placeholder
};
}