1
0

Merged branch 'master' into c++11.

This commit is contained in:
Mattes D 2014-10-23 08:40:39 +02:00
commit f8c54f4243
51 changed files with 820 additions and 527 deletions

View File

@ -35,12 +35,49 @@ return
Inherits = "cProjectileEntity",
}, -- cArrowEntity
cExpBottleEntity =
{
Desc = [[
Represents a thrown ExpBottle. A subclass of the {{cProjectileEntity}}.
]],
Functions =
{
},
Inherits = "cProjectileEntity",
}, -- cExpBottleEntity
cFireChargeEntity =
{
Desc = [[
Represents a fire charge that has been shot by a Blaze or a {{cDispenserEntity|Dispenser}}. A subclass
of the {{cProjectileEntity}}.
]],
Functions = {},
Inherits = "cProjectileEntity",
}, -- cFireChargeEntity
cFireworkEntity =
{
Desc = [[
Represents a firework rocket.
]],
Functions =
{
GetItem = { Params = "", Return = "{{cItem}}", Notes = "Returns the item that has been used to create the firework rocket. The item's m_FireworkItem member contains all the firework-related data." },
GetTicksToExplosion = { Params = "", Return = "number", Notes = "Returns the number of ticks left until the firework explodes." },
SetItem = { Params = "{{cItem}}", Return = "", Notes = "Sets a new item to be used for the firework." },
SetTicksToExplosion = { Params = "NumTicks", Return = "", Notes = "Sets the number of ticks left until the firework explodes." },
},
Inherits = "cProjectileEntity",
}, -- cFireworkEntity
cFloater =
{
Desc = "",
Functions = {},
Inherits = "cProjectileEntity",
}, -- cFireChargeEntity
}, -- cFloater
cGhastFireballEntity =
{
@ -64,14 +101,14 @@ return
pkArrow = { Notes = "The projectile is an {{cArrowEntity|arrow}}" },
pkEgg = { Notes = "The projectile is a {{cThrownEggEntity|thrown egg}}" },
pkEnderPearl = { Notes = "The projectile is a {{cThrownEnderPearlEntity|thrown enderpearl}}" },
pkExpBottle = { Notes = "The projectile is a thrown exp bottle (NYI)" },
pkExpBottle = { Notes = "The projectile is a {{cExpBottleEntity|thrown exp bottle}}" },
pkFireCharge = { Notes = "The projectile is a {{cFireChargeEntity|fire charge}}" },
pkFirework = { Notes = "The projectile is a (flying) firework (NYI)" },
pkFishingFloat = { Notes = "The projectile is a fishing float (NYI)" },
pkFirework = { Notes = "The projectile is a (flying) {{cFireworkEntity|firework}}" },
pkFishingFloat = { Notes = "The projectile is a {{cFloater|fishing float}}" },
pkGhastFireball = { Notes = "The projectile is a {{cGhastFireballEntity|ghast fireball}}" },
pkSnowball = { Notes = "The projectile is a {{cThrownSnowballEntity|thrown snowball}}" },
pkSplashPotion = { Notes = "The projectile is a thrown splash potion (NYI)" },
pkWitherSkull = { Notes = "The projectile is a wither skull (NYI)" },
pkSplashPotion = { Notes = "The projectile is a {{cSplashPotionEntity|thrown splash potion}}" },
pkWitherSkull = { Notes = "The projectile is a {{cWitherSkullEntity|wither skull}}" },
},
ConstantGroups =
{
@ -84,6 +121,13 @@ return
Inherits = "cEntity",
}, -- cProjectileEntity
cSplashPotionEntity =
{
Desc = "",
Functions = {},
Inherits = "cProjectileEntity",
}, -- cSplashPotionEntity
cThrownEggEntity =
{
Desc = "",
@ -104,6 +148,13 @@ return
Functions = {},
Inherits = "cProjectileEntity",
}, -- cThrownSnowballEntity
cWitherSkullEntity =
{
Desc = "",
Functions = {},
Inherits = "cProjectileEntity",
}, -- cWitherSkullEntity
}

@ -1 +1 @@
Subproject commit f8c2531fbef9bfd0b6f024d4d3319384a70a0831
Subproject commit 4702471943511f641458c7e8e89b430a723f43ea

View File

@ -625,7 +625,11 @@ local function LoadPluginInfo(a_FolderName)
-- This is Lua-5.1-specific and won't work in Lua 5.2!
local Sandbox = {}
setfenv(cfg, Sandbox)
cfg()
local isSuccess, errMsg = pcall(cfg)
if not(isSuccess) then
return nil, "Cannot load Info.lua: " .. (errMsg or "<unknown error>")
end
if (Sandbox.g_PluginInfo == nil) then
return nil, "Info.lua doesn't contain the g_PluginInfo declaration"
end

@ -1 +1 @@
Subproject commit 7765048fa740b8f119db72a4ccc546504f86b2ab
Subproject commit 624580e5b522ba2799dfe5b5902b4002b1a8da3e

View File

@ -33,7 +33,7 @@ function GetDefaultPage()
local AllPlugins = PM:GetAllPlugins()
for key,value in pairs(AllPlugins) do
if( value ~= nil and value ~= false ) then
Content = Content .. "<li>" .. key .. " V." .. value:GetVersion() .. "</li>"
Content = Content .. "<li>" .. key .. " (version " .. value:GetVersion() .. ")</li>"
end
end

View File

@ -33,15 +33,27 @@ $cfile "../StringUtils.h"
$cfile "../Defines.h"
$cfile "../ChatColor.h"
$cfile "../ClientHandle.h"
$cfile "../Entities/ArrowEntity.h"
$cfile "../Entities/Entity.h"
$cfile "../Entities/EntityEffect.h"
$cfile "../Entities/ExpBottleEntity.h"
$cfile "../Entities/FireChargeEntity.h"
$cfile "../Entities/FireworkEntity.h"
$cfile "../Entities/Floater.h"
$cfile "../Entities/GhastFireballEntity.h"
$cfile "../Entities/HangingEntity.h"
$cfile "../Entities/ItemFrame.h"
$cfile "../Entities/Pawn.h"
$cfile "../Entities/Player.h"
$cfile "../Entities/Painting.h"
$cfile "../Entities/Pickup.h"
$cfile "../Entities/ProjectileEntity.h"
$cfile "../Entities/SplashPotionEntity.h"
$cfile "../Entities/ThrownEggEntity.h"
$cfile "../Entities/ThrownEnderPearlEntity.h"
$cfile "../Entities/ThrownSnowballEntity.h"
$cfile "../Entities/TNTEntity.h"
$cfile "../Entities/EntityEffect.h"
$cfile "../Entities/WitherSkullEntity.h"
$cfile "../Server.h"
$cfile "../World.h"
$cfile "../Inventory.h"

View File

@ -74,26 +74,27 @@ set(BINDING_DEPENDENCIES
../Cuboid.h
../Defines.h
../Enchantments.h
../Entities/EntityEffect.h
../Entities/Entity.h
../Entities/Floater.h
../Entities/Pawn.h
../Entities/Painting.h
../Entities/Pickup.h
../Entities/Player.h
../Entities/ProjectileEntity.h
../Entities/ArrowEntity.h
../Entities/ThrownEggEntity.h
../Entities/ThrownEnderPearlEntity.h
../Entities/Entity.h
../Entities/EntityEffect.h
../Entities/ExpBottleEntity.h
../Entities/ThrownSnowballEntity.h
../Entities/FireChargeEntity.h
../Entities/FireworkEntity.h
../Entities/Floater.h
../Entities/GhastFireballEntity.h
../Entities/TNTEntity.h
../Entities/ExpOrb.h
../Entities/HangingEntity.h
../Entities/ItemFrame.h
../Entities/Pawn.h
../Entities/Player.h
../Entities/Painting.h
../Entities/Pickup.h
../Entities/ProjectileEntity.h
../Entities/SplashPotionEntity.h
../Entities/ThrownEggEntity.h
../Entities/ThrownEnderPearlEntity.h
../Entities/ThrownSnowballEntity.h
../Entities/TNTEntity.h
../Entities/WitherSkullEntity.h
../Generating/ChunkDesc.h
../Inventory.h
../Item.h
@ -123,6 +124,7 @@ if (NOT MSVC)
DEPENDS ${BINDING_DEPENDENCIES}
)
endif ()
set_source_files_properties(${CMAKE_SOURCE_DIR}/src/Bindings/Bindings.cpp PROPERTIES GENERATED TRUE)
set_source_files_properties(${CMAKE_SOURCE_DIR}/src/Bindings/Bindings.h PROPERTIES GENERATED TRUE)

View File

@ -562,16 +562,57 @@ void cLuaState::Push(cEntity * a_Entity)
{
lua_pushnil(m_LuaState);
}
else if (a_Entity->IsMob())
else
{
switch (a_Entity->GetEntityType())
{
case cEntity::etMonster:
{
// Don't push specific mob types, as those are not exported in the API:
tolua_pushusertype(m_LuaState, a_Entity, "cMonster");
break;
}
else
case cEntity::etPlayer:
{
// Push the specific class type:
tolua_pushusertype(m_LuaState, a_Entity, a_Entity->GetClass());
tolua_pushusertype(m_LuaState, a_Entity, "cPlayer");
break;
}
case cEntity::etPickup:
{
tolua_pushusertype(m_LuaState, a_Entity, "cPickup");
break;
}
case cEntity::etTNT:
{
tolua_pushusertype(m_LuaState, a_Entity, "cTNTEntity");
break;
}
case cEntity::etProjectile:
{
tolua_pushusertype(m_LuaState, a_Entity, a_Entity->GetClass());
break;
}
case cEntity::etFloater:
{
tolua_pushusertype(m_LuaState, a_Entity, "cFloater");
break;
}
case cEntity::etEntity:
case cEntity::etEnderCrystal:
case cEntity::etFallingBlock:
case cEntity::etMinecart:
case cEntity::etBoat:
case cEntity::etExpOrb:
case cEntity::etItemFrame:
case cEntity::etPainting:
{
// Push the generic entity class type:
tolua_pushusertype(m_LuaState, a_Entity, "cEntity");
}
} // switch (EntityType)
}
m_NumCurrentFunctionArgs += 1;
}

View File

@ -105,7 +105,7 @@ void cDispenserEntity::DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum)
{
double MobX = 0.5 + (DispX + DispChunk->GetPosX() * cChunkDef::Width);
double MobZ = 0.5 + (DispZ + DispChunk->GetPosZ() * cChunkDef::Width);
if (m_World->SpawnMob(MobX, DispY, MobZ, (eMonsterType)m_Contents.GetSlot(a_SlotNum).m_ItemDamage) >= 0)
if (m_World->SpawnMob(MobX, DispY, MobZ, static_cast<eMonsterType>(m_Contents.GetSlot(a_SlotNum).m_ItemDamage)) >= 0)
{
m_Contents.ChangeSlotCount(a_SlotNum, -1);
}
@ -190,7 +190,7 @@ void cDispenserEntity::DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum)
void cDispenserEntity::SpawnProjectileFromDispenser(int a_BlockX, int a_BlockY, int a_BlockZ, cProjectileEntity::eKind a_Kind, const Vector3d & a_ShootVector)
{
m_World->CreateProjectile((double)a_BlockX + 0.5, (double)a_BlockY + 0.5, (double)a_BlockZ + 0.5, a_Kind, nullptr, nullptr, &a_ShootVector);
m_World->CreateProjectile(static_cast<double>(a_BlockX + 0.5), static_cast<double>(a_BlockY + 0.5), static_cast<double>(a_BlockZ + 0.5), a_Kind, nullptr, nullptr, &a_ShootVector);
}
@ -275,6 +275,3 @@ bool cDispenserEntity::EmptyLiquidBucket(BLOCKTYPE a_BlockInFront, int a_SlotNum
m_Contents.AddItem(EmptyBucket);
return true;
}

View File

@ -88,7 +88,7 @@ bool cFlowerPotEntity::IsFlower(short m_ItemType, short m_ItemData)
}
case E_BLOCK_TALL_GRASS:
{
return (m_ItemData == (short) 2);
return (m_ItemData == static_cast<short>(2));
}
default:
{
@ -96,7 +96,3 @@ bool cFlowerPotEntity::IsFlower(short m_ItemType, short m_ItemData)
}
}
}

View File

@ -373,7 +373,3 @@ void cFurnaceEntity::SetIsCooking(bool a_IsCooking)
m_World->FastSetBlock(m_PosX, m_PosY, m_PosZ, E_BLOCK_LIT_FURNACE, m_BlockMeta);
}
}

View File

@ -161,7 +161,7 @@ bool cHopperEntity::MoveItemsIn(cChunk & a_Chunk, Int64 a_CurrentTick)
case E_BLOCK_DROPPER:
case E_BLOCK_HOPPER:
{
res = MoveItemsFromGrid(*(cBlockEntityWithItems *)a_Chunk.GetBlockEntity(m_PosX, m_PosY + 1, m_PosZ));
res = MoveItemsFromGrid(*static_cast<cBlockEntityWithItems *>(a_Chunk.GetBlockEntity(m_PosX, m_PosY + 1, m_PosZ)));
break;
}
}
@ -205,12 +205,12 @@ bool cHopperEntity::MovePickupsIn(cChunk & a_Chunk, Int64 a_CurrentTick)
}
Vector3f EntityPos = a_Entity->GetPosition();
Vector3f BlockPos(m_Pos.x + 0.5f, (float)m_Pos.y + 1, m_Pos.z + 0.5f); // One block above hopper, and search from center outwards
Vector3f BlockPos(m_Pos.x + 0.5f, static_cast<float>(m_Pos.y) + 1, m_Pos.z + 0.5f); // One block above hopper, and search from center outwards
double Distance = (EntityPos - BlockPos).Length();
if (Distance < 0.5)
{
if (TrySuckPickupIn((cPickup *)a_Entity))
if (TrySuckPickupIn(static_cast<cPickup *>(a_Entity)))
{
return false;
}
@ -327,7 +327,7 @@ bool cHopperEntity::MoveItemsOut(cChunk & a_Chunk, Int64 a_CurrentTick)
case E_BLOCK_DROPPER:
case E_BLOCK_HOPPER:
{
cBlockEntityWithItems * BlockEntity = (cBlockEntityWithItems *)DestChunk->GetBlockEntity(OutX, OutY, OutZ);
cBlockEntityWithItems * BlockEntity = static_cast<cBlockEntityWithItems *>(DestChunk->GetBlockEntity(OutX, OutY, OutZ));
if (BlockEntity == nullptr)
{
LOGWARNING("%s: A block entity was not found where expected at {%d, %d, %d}", __FUNCTION__, OutX, OutY, OutZ);
@ -354,7 +354,7 @@ bool cHopperEntity::MoveItemsOut(cChunk & a_Chunk, Int64 a_CurrentTick)
/// Moves items from a chest (dblchest) above the hopper into this hopper. Returns true if contents have changed.
bool cHopperEntity::MoveItemsFromChest(cChunk & a_Chunk)
{
cChestEntity * MainChest = (cChestEntity *)a_Chunk.GetBlockEntity(m_PosX, m_PosY + 1, m_PosZ);
cChestEntity * MainChest = static_cast<cChestEntity *>(a_Chunk.GetBlockEntity(m_PosX, m_PosY + 1, m_PosZ));
if (MainChest == nullptr)
{
LOGWARNING("%s: A chest entity was not found where expected, at {%d, %d, %d}", __FUNCTION__, m_PosX, m_PosY + 1, m_PosZ);
@ -395,7 +395,7 @@ bool cHopperEntity::MoveItemsFromChest(cChunk & a_Chunk)
continue;
}
cChestEntity * SideChest = (cChestEntity *)Neighbor->GetBlockEntity(m_PosX + Coords[i].x, m_PosY + 1, m_PosZ + Coords[i].z);
cChestEntity * SideChest = static_cast<cChestEntity *>(Neighbor->GetBlockEntity(m_PosX + Coords[i].x, m_PosY + 1, m_PosZ + Coords[i].z));
if (SideChest == nullptr)
{
LOGWARNING("%s: A chest entity was not found where expected, at {%d, %d, %d}", __FUNCTION__, m_PosX + Coords[i].x, m_PosY + 1, m_PosZ + Coords[i].z);
@ -421,7 +421,7 @@ bool cHopperEntity::MoveItemsFromChest(cChunk & a_Chunk)
/// Moves items from a furnace above the hopper into this hopper. Returns true if contents have changed.
bool cHopperEntity::MoveItemsFromFurnace(cChunk & a_Chunk)
{
cFurnaceEntity * Furnace = (cFurnaceEntity *)a_Chunk.GetBlockEntity(m_PosX, m_PosY + 1, m_PosZ);
cFurnaceEntity * Furnace = static_cast<cFurnaceEntity *>(a_Chunk.GetBlockEntity(m_PosX, m_PosY + 1, m_PosZ));
if (Furnace == nullptr)
{
LOGWARNING("%s: A furnace entity was not found where expected, at {%d, %d, %d}", __FUNCTION__, m_PosX, m_PosY + 1, m_PosZ);
@ -535,7 +535,7 @@ bool cHopperEntity::MoveItemsFromSlot(cBlockEntityWithItems & a_Entity, int a_Sl
bool cHopperEntity::MoveItemsToChest(cChunk & a_Chunk, int a_BlockX, int a_BlockY, int a_BlockZ)
{
// Try the chest directly connected to the hopper:
cChestEntity * ConnectedChest = (cChestEntity *)a_Chunk.GetBlockEntity(a_BlockX, a_BlockY, a_BlockZ);
cChestEntity * ConnectedChest = static_cast<cChestEntity *>(a_Chunk.GetBlockEntity(a_BlockX, a_BlockY, a_BlockZ));
if (ConnectedChest == nullptr)
{
LOGWARNING("%s: A chest entity was not found where expected, at {%d, %d, %d}", __FUNCTION__, a_BlockX, a_BlockY, a_BlockZ);
@ -578,7 +578,7 @@ bool cHopperEntity::MoveItemsToChest(cChunk & a_Chunk, int a_BlockX, int a_Block
continue;
}
cChestEntity * Chest = (cChestEntity *)Neighbor->GetBlockEntity(a_BlockX + Coords[i].x, a_BlockY, a_BlockZ + Coords[i].z);
cChestEntity * Chest = static_cast<cChestEntity *>(Neighbor->GetBlockEntity(a_BlockX + Coords[i].x, a_BlockY, a_BlockZ + Coords[i].z));
if (Chest == nullptr)
{
LOGWARNING("%s: A chest entity was not found where expected, at {%d, %d, %d} (%d, %d)", __FUNCTION__, a_BlockX + Coords[i].x, a_BlockY, a_BlockZ + Coords[i].z, x, z);
@ -602,7 +602,7 @@ bool cHopperEntity::MoveItemsToChest(cChunk & a_Chunk, int a_BlockX, int a_Block
/// Moves items to the furnace at the specified coords. Returns true if contents have changed
bool cHopperEntity::MoveItemsToFurnace(cChunk & a_Chunk, int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_HopperMeta)
{
cFurnaceEntity * Furnace = (cFurnaceEntity *)a_Chunk.GetBlockEntity(a_BlockX, a_BlockY, a_BlockZ);
cFurnaceEntity * Furnace = static_cast<cFurnaceEntity *>(a_Chunk.GetBlockEntity(a_BlockX, a_BlockY, a_BlockZ));
if (a_HopperMeta == E_META_HOPPER_FACING_YM)
{
// Feed the input slot of the furnace
@ -684,7 +684,3 @@ bool cHopperEntity::MoveItemsToSlot(cBlockEntityWithItems & a_Entity, int a_DstS
return false;
}
}

View File

@ -79,7 +79,7 @@ bool cJukeboxEntity::EjectRecord(void)
}
cItems Drops;
Drops.push_back(cItem(m_Record, 1, 0));
Drops.push_back(cItem(static_cast<short>(m_Record), 1, 0));
m_Record = 0;
m_World->SpawnItemPickups(Drops, m_PosX + 0.5, m_PosY + 1, m_PosZ + 0.5, 8);
m_World->BroadcastSoundParticleEffect(1005, m_PosX, m_PosY, m_PosZ, 0);
@ -113,7 +113,3 @@ void cJukeboxEntity::SetRecord(int a_Record)
{
m_Record = a_Record;
}

View File

@ -45,7 +45,7 @@ void cSignEntity::SetLines(const AString & a_Line1, const AString & a_Line2, con
void cSignEntity::SetLine(int a_Index, const AString & a_Line)
{
if ((a_Index < 0) || (a_Index >= (int)ARRAYCOUNT(m_Line)))
if ((a_Index < 0) || (a_Index >= static_cast<int>(ARRAYCOUNT(m_Line))))
{
LOGWARNING("%s: setting a non-existent line %d (value \"%s\"", __FUNCTION__, a_Index, a_Line.c_str());
return;
@ -59,7 +59,7 @@ void cSignEntity::SetLine(int a_Index, const AString & a_Line)
AString cSignEntity::GetLine(int a_Index) const
{
if ((a_Index < 0) || (a_Index >= (int)ARRAYCOUNT(m_Line)))
if ((a_Index < 0) || (a_Index >= static_cast<int>(ARRAYCOUNT(m_Line))))
{
LOGWARNING("%s: requesting a non-existent line %d", __FUNCTION__, a_Index);
return "";
@ -75,7 +75,3 @@ void cSignEntity::SendTo(cClientHandle & a_Client)
{
a_Client.SendUpdateSign(m_PosX, m_PosY, m_PosZ, m_Line[0], m_Line[1], m_Line[2], m_Line[3]);
}

View File

@ -17,15 +17,25 @@ public:
}
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
// Don't drop anything
}
virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override
{
return (a_RelY > 0) && (a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ) == E_BLOCK_SAND);
if (a_RelY <= 0)
{
return false;
}
BLOCKTYPE BelowBlock = a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ);
switch (BelowBlock)
{
case E_BLOCK_CLAY:
case E_BLOCK_HARDENED_CLAY:
case E_BLOCK_STAINED_CLAY:
case E_BLOCK_SAND:
{
return true;
}
default: return false;
}
}
} ;

View File

@ -2,6 +2,7 @@
#pragma once
#include "BlockHandler.h"
#include "ChunkInterface.h"
@ -10,6 +11,7 @@
class cBlockTallGrassHandler :
public cBlockHandler
{
typedef cBlockHandler super;
public:
cBlockTallGrassHandler(BLOCKTYPE a_BlockType)
: cBlockHandler(a_BlockType)
@ -26,32 +28,58 @@ public:
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
// Drop seeds, sometimes
MTRand r1;
if (r1.randInt(10) == 5)
cFastRandom Random;
if (Random.NextInt(8) == 0)
{
a_Pickups.push_back(cItem(E_ITEM_SEEDS, 1, 0));
}
}
virtual void OnDestroyedByPlayer(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) override
virtual void DropBlock(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cBlockPluginInterface & a_BlockPluginInterface, cEntity * a_Digger, int a_BlockX, int a_BlockY, int a_BlockZ, bool a_CanDrop) override
{
if (a_CanDrop && (a_Digger != NULL) && (a_Digger->GetEquippedWeapon().m_ItemType == E_ITEM_SHEARS))
{
NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ);
cItems Drops;
Drops.Add(m_BlockType, 1, Meta);
if ((!a_Player->IsGameModeCreative()) && (a_Player->GetEquippedItem().m_ItemType == E_ITEM_SHEARS))
// Allow plugins to modify the pickups:
a_BlockPluginInterface.CallHookBlockToPickups(a_Digger, a_BlockX, a_BlockY, a_BlockZ, m_BlockType, Meta, Drops);
// Spawn the pickups:
if (!Drops.empty())
{
cItems Pickups;
Pickups.Add(E_BLOCK_TALL_GRASS, 1, Meta);
a_WorldInterface.SpawnItemPickups(Pickups, a_BlockX, a_BlockY, a_BlockZ);
MTRand r1;
a_Player->UseEquippedItem();
// Mid-block position first
double MicroX, MicroY, MicroZ;
MicroX = a_BlockX + 0.5;
MicroY = a_BlockY + 0.5;
MicroZ = a_BlockZ + 0.5;
// Add random offset second
MicroX += r1.rand(1) - 0.5;
MicroZ += r1.rand(1) - 0.5;
a_WorldInterface.SpawnItemPickups(Drops, MicroX, MicroY, MicroZ);
}
return;
}
super::DropBlock(a_ChunkInterface, a_WorldInterface, a_BlockPluginInterface, a_Digger, a_BlockX, a_BlockY, a_BlockZ, a_CanDrop);
}
virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override
{
return ((a_RelY > 0) && (a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ) != E_BLOCK_AIR));
if (a_RelY <= 0)
{
return false;
}
BLOCKTYPE BelowBlock = a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ);
return IsBlockTypeOfDirt(BelowBlock);
}
} ;

View File

@ -23,10 +23,6 @@ public:
BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta
) override
{
UNUSED(a_Player);
UNUSED(a_CursorX);
UNUSED(a_CursorY);
UNUSED(a_CursorZ);
// TODO: Disallow placement where the vine doesn't attach to something properly
BLOCKTYPE BlockType = 0;
NIBBLETYPE BlockMeta;
@ -80,7 +76,21 @@ public:
/// Returns true if the specified block type is good for vines to attach to
static bool IsBlockAttachable(BLOCKTYPE a_BlockType)
{
return ((a_BlockType == E_BLOCK_LEAVES) || (a_BlockType == E_BLOCK_NEW_LEAVES) || cBlockInfo::IsSolid(a_BlockType));
switch (a_BlockType)
{
case E_BLOCK_GLASS:
case E_BLOCK_STAINED_GLASS:
case E_BLOCK_CHEST:
case E_BLOCK_TRAPPED_CHEST:
{
// You can't attach a vine to this solid blocks.
return false;
}
default:
{
return cBlockInfo::IsSolid(a_BlockType);
}
}
}

View File

@ -226,11 +226,11 @@ public:
{
if ((a_BlockIdx > -1) && (a_BlockIdx < NumBlocks))
{
if ((size_t)(a_BlockIdx / 2) >= a_Buffer.size())
if (static_cast<size_t>(a_BlockIdx / 2) >= a_Buffer.size())
{
return (a_IsSkyLightNibble ? 0xff : 0);
}
return (a_Buffer[(size_t)(a_BlockIdx / 2)] >> ((a_BlockIdx & 1) * 4)) & 0x0f;
return (a_Buffer[static_cast<size_t>(a_BlockIdx / 2)] >> ((a_BlockIdx & 1) * 4)) & 0x0f;
}
ASSERT(!"cChunkDef::GetNibble(): index out of chunk range!");
return 0;
@ -241,7 +241,7 @@ public:
{
if ((x < Width) && (x > -1) && (y < Height) && (y > -1) && (z < Width) && (z > -1))
{
size_t Index = (size_t)MakeIndexNoCheck(x, y, z);
size_t Index = static_cast<size_t>(MakeIndexNoCheck(x, y, z));
if ((Index / 2) >= a_Buffer.size())
{
return (a_IsSkyLightNibble ? 0xff : 0);
@ -258,7 +258,7 @@ public:
if ((x < Width) && (x > -1) && (y < Height) && (y > -1) && (z < Width) && (z > -1))
{
int Index = MakeIndexNoCheck(x, y, z);
return (a_Buffer[(size_t)(Index / 2)] >> ((Index & 1) * 4)) & 0x0f;
return (a_Buffer[static_cast<size_t>(Index / 2)] >> ((Index & 1) * 4)) & 0x0f;
}
ASSERT(!"cChunkDef::GetNibble(): coords out of chunk range!");
return 0;
@ -272,11 +272,11 @@ public:
ASSERT(!"cChunkDef::SetNibble(): index out of range!");
return;
}
if ((size_t)(a_BlockIdx / 2) >= a_Buffer.size())
if (static_cast<size_t>(a_BlockIdx / 2) >= a_Buffer.size())
{
a_Buffer.resize((size_t)((a_BlockIdx / 2) + 1));
a_Buffer.resize(static_cast<size_t>((a_BlockIdx / 2) + 1));
}
a_Buffer[(size_t)(a_BlockIdx / 2)] = PackNibble(a_Buffer, (size_t)a_BlockIdx, a_Nibble);
a_Buffer[static_cast<size_t>(a_BlockIdx / 2)] = PackNibble(a_Buffer, static_cast<size_t>(a_BlockIdx), a_Nibble);
}
@ -292,7 +292,7 @@ public:
return;
}
size_t Index = (size_t)MakeIndexNoCheck(x, y, z);
size_t Index = static_cast<size_t>(MakeIndexNoCheck(x, y, z));
if ((Index / 2) >= a_Buffer.size())
{
a_Buffer.resize(((Index / 2) + 1));
@ -478,7 +478,3 @@ public:
typedef cCoordWithDoubleData <BLOCKTYPE, bool> cCoordWithBlockAndBool;
typedef std::vector<cCoordWithBlockAndBool> cCoordWithBlockAndBoolVector;

View File

@ -472,7 +472,7 @@ inline void AddFaceDirection(int & a_BlockX, unsigned char & a_BlockY, int & a_B
{
int Y = a_BlockY;
AddFaceDirection(a_BlockX, Y, a_BlockZ, a_BlockFace, a_bInverse);
a_BlockY = Clamp<unsigned char>((unsigned char)Y, 0, 255);
a_BlockY = Clamp<unsigned char>(static_cast<unsigned char>(Y), 0, 255);
}
@ -715,7 +715,3 @@ namespace ItemCategory
}
// tolua_end

View File

@ -1,6 +1,11 @@
//
// ArrowEntity.h
//
// Declares the cArrowEntity representing the arrow that has been shot by the player or by a skeleton
#pragma once
@ -19,7 +24,7 @@ class cArrowEntity :
typedef cProjectileEntity super;
public:
/// Determines when the arrow can be picked up (depending on player gamemode). Corresponds to the MCA file "pickup" field
/** Determines when the arrow can be picked up (depending on player gamemode). Corresponds to the MCA file "pickup" field */
enum ePickupState
{
psNoPickup = 0,
@ -31,33 +36,33 @@ public:
CLASS_PROTODEF(cArrowEntity)
/// Creates a new arrow with psNoPickup state and default damage modifier coeff
/** Creates a new arrow with psNoPickup state and default damage modifier coeff */
cArrowEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed);
/// Creates a new arrow as shot by a player, initializes it from the player object
/** Creates a new arrow as shot by a player, initializes it from the player object */
cArrowEntity(cPlayer & a_Player, double a_Force);
// tolua_begin
/// Returns whether the arrow can be picked up by players
/** Returns whether the arrow can be picked up by players */
ePickupState GetPickupState(void) const { return m_PickupState; }
/// Sets a new pickup state
/** Sets a new pickup state */
void SetPickupState(ePickupState a_PickupState) { m_PickupState = a_PickupState; }
/// Returns the damage modifier coeff.
/** Returns the damage modifier coeff. */
double GetDamageCoeff(void) const { return m_DamageCoeff; }
/// Sets the damage modifier coeff
/** Sets the damage modifier coeff */
void SetDamageCoeff(double a_DamageCoeff) { m_DamageCoeff = a_DamageCoeff; }
/// Returns true if the specified player can pick the arrow up
/** Returns true if the specified player can pick the arrow up */
bool CanPickup(const cPlayer & a_Player) const;
/// Returns true if the arrow is set as critical
/** Returns true if the arrow is set as critical */
bool IsCritical(void) const { return m_IsCritical; }
/// Sets the IsCritical flag
/** Sets the IsCritical flag */
void SetIsCritical(bool a_IsCritical) { m_IsCritical = a_IsCritical; }
/** Gets the block arrow is in */
@ -70,28 +75,28 @@ public:
protected:
/// Determines when the arrow can be picked up by players
/** Determines when the arrow can be picked up by players */
ePickupState m_PickupState;
/// The coefficient applied to the damage that the arrow will deal, based on the bow enchantment. 2.0 for normal arrow
/** The coefficient applied to the damage that the arrow will deal, based on the bow enchantment. 2.0 for normal arrow */
double m_DamageCoeff;
/// If true, the arrow deals more damage
/** If true, the arrow deals more damage */
bool m_IsCritical;
/// Timer for pickup collection animation or five minute timeout
/** Timer for pickup collection animation or five minute timeout */
float m_Timer;
/// Timer for client arrow position confirmation via TeleportEntity
/** Timer for client arrow position confirmation via TeleportEntity */
float m_HitGroundTimer;
// Whether the arrow has already been teleported into the proper position in the ground.
bool m_HasTeleported;
/// If true, the arrow is in the process of being collected - don't go to anyone else
/** If true, the arrow is in the process of being collected - don't go to anyone else */
bool m_bIsCollected;
/// Stores the block position that arrow is lodged into, sets m_IsInGround to false if it becomes air
/** Stores the block position that arrow is lodged into, sets m_IsInGround to false if it becomes air */
Vector3i m_HitBlockPos;
// cProjectileEntity overrides:

View File

@ -1,6 +1,11 @@
//
// ExpBottleEntity.h
//
// Declares the cExpBottleEntity class representing the thrown exp bottle
#pragma once
@ -36,3 +41,7 @@ protected:
void Break(const Vector3d & a_HitPos);
}; // tolua_export

View File

@ -1,6 +1,11 @@
//
// FireChargeEntity.h
//
// Declares the cFireChargeEntity representing the fire charge shot by the blaze
#pragma once
@ -34,3 +39,7 @@ protected:
virtual void OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) override;
} ; // tolua_export

View File

@ -10,7 +10,7 @@
cFireworkEntity::cFireworkEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const cItem & a_Item) :
super(pkFirework, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25),
m_ExplodeTimer(0),
m_TicksToExplosion(a_Item.m_FireworkItem.m_FlightTimeInTicks),
m_FireworkItem(a_Item)
{
}
@ -27,7 +27,9 @@ void cFireworkEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk)
if ((PosY < 0) || (PosY >= cChunkDef::Height))
{
goto setspeed;
AddSpeedY(1);
AddPosition(GetSpeed() * (a_Dt / 1000));
return;
}
if (m_IsInGround)
@ -50,7 +52,6 @@ void cFireworkEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk)
}
}
setspeed:
AddSpeedY(1);
AddPosition(GetSpeed() * (a_Dt / 1000));
}
@ -63,11 +64,13 @@ void cFireworkEntity::Tick(float a_Dt, cChunk & a_Chunk)
{
super::Tick(a_Dt, a_Chunk);
if (m_ExplodeTimer == m_FireworkItem.m_FireworkItem.m_FlightTimeInTicks)
if (m_TicksToExplosion <= 0)
{
// TODO: Notify the plugins
m_World->BroadcastEntityStatus(*this, esFireworkExploding);
Destroy();
return;
}
m_ExplodeTimer++;
m_TicksToExplosion -= 1;
}

View File

@ -1,6 +1,11 @@
//
// FireworkEntity.h
//
// Declares the cFireworkEntity class representing the flying firework rocket
#pragma once
@ -24,8 +29,23 @@ public:
CLASS_PROTODEF(cFireworkEntity)
cFireworkEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const cItem & a_Item);
// tolua_begin
/** Returns the item used to create the rocket (has all the firework effects on it) */
const cItem & GetItem(void) const { return m_FireworkItem; }
/** Sets the item that is used to create the rocket (has all the firework effects on it) */
void SetItem(const cItem & a_Item) { m_FireworkItem = a_Item; }
/** Returns the number of ticks left until the firework explosion. */
int GetTicksToExplosion(void) const { return m_TicksToExplosion; }
/** Sets the number of ticks left until the firework explosion. */
void SetTicksToExplosion(int a_TicksToExplosion) { m_TicksToExplosion = a_TicksToExplosion; }
// tolua_end
protected:
// cProjectileEntity overrides:
@ -34,7 +54,11 @@ protected:
private:
int m_ExplodeTimer;
int m_TicksToExplosion;
cItem m_FireworkItem;
}; // tolua_export

View File

@ -1,6 +1,11 @@
//
// GhastFireballEntity.h
//
// Declares the cGhastFireballEntity class representing the ghast fireball in flight.
#pragma once
@ -36,3 +41,7 @@ protected:
// TODO: Deflecting the fireballs by arrow- or sword- hits
} ; // tolua_export

View File

@ -9,9 +9,9 @@
cHangingEntity::cHangingEntity(eEntityType a_EntityType, eBlockFace a_BlockFace, double a_X, double a_Y, double a_Z)
: cEntity(a_EntityType, a_X, a_Y, a_Z, 0.8, 0.8)
, m_BlockFace(a_BlockFace)
cHangingEntity::cHangingEntity(eEntityType a_EntityType, eBlockFace a_Facing, double a_X, double a_Y, double a_Z) :
cEntity(a_EntityType, a_X, a_Y, a_Z, 0.8, 0.8),
m_Facing(a_Facing)
{
SetMaxHealth(1);
SetHealth(1);
@ -21,15 +21,23 @@ cHangingEntity::cHangingEntity(eEntityType a_EntityType, eBlockFace a_BlockFace,
void cHangingEntity::SetDirection(eBlockFace a_BlockFace)
void cHangingEntity::SetFacing(eBlockFace a_Facing)
{
if ((a_BlockFace < 2) || (a_BlockFace > 5))
// Y-based faces are not allowed:
switch (a_Facing)
{
ASSERT(!"Tried to set a bad direction!");
case BLOCK_FACE_NONE:
case BLOCK_FACE_YM:
case BLOCK_FACE_YP:
{
LOGWARNING("%s: Invalid facing: %d. Ignoring.", __FUNCTION__, a_Facing);
ASSERT(!"Tried to set a bad facing!");
return;
}
default: break;
}
m_BlockFace = a_BlockFace;
m_Facing = a_Facing;
}
@ -41,7 +49,7 @@ void cHangingEntity::SpawnOn(cClientHandle & a_ClientHandle)
int Dir = 0;
// The client uses different values for item frame directions and block faces. Our constants are for the block faces, so we convert them here to item frame faces
switch (m_BlockFace)
switch (m_Facing)
{
case BLOCK_FACE_ZP: Dir = 0; break;
case BLOCK_FACE_ZM: Dir = 2; break;
@ -49,8 +57,8 @@ void cHangingEntity::SpawnOn(cClientHandle & a_ClientHandle)
case BLOCK_FACE_XP: Dir = 3; break;
default:
{
LOGINFO("Invalid face (%d) in a cHangingEntity at {%d, %d, %d}, adjusting to BLOCK_FACE_XP.",
m_BlockFace, (int)GetPosX(), (int)GetPosY(), (int)GetPosZ()
LOGINFO("Invalid facing (%d) in a cHangingEntity at {%d, %d, %d}, adjusting to BLOCK_FACE_XP.",
m_Facing, (int)GetPosX(), (int)GetPosY(), (int)GetPosZ()
);
Dir = 3;
}

View File

@ -11,36 +11,41 @@
class cHangingEntity :
public cEntity
{
// tolua_end
typedef cEntity super;
public:
// tolua_end
CLASS_PROTODEF(cHangingEntity)
cHangingEntity(eEntityType a_EntityType, eBlockFace a_BlockFace, double a_X, double a_Y, double a_Z);
/** Returns the orientation from the hanging entity */
eBlockFace GetDirection() const { return m_BlockFace; } // tolua_export
// tolua_begin
/** Set the orientation from the hanging entity */
void SetDirection(eBlockFace a_BlockFace); // tolua_export
/** Returns the direction in which the entity is facing. */
eBlockFace GetFacing() const { return m_Facing; }
/** Returns the X coord. */
int GetTileX() const { return POSX_TOINT; } // tolua_export
/** Set the direction in which the entity is facing. */
void SetFacing(eBlockFace a_Facing);
/** Returns the Y coord. */
int GetTileY() const { return POSY_TOINT; } // tolua_export
/** Returns the X coord of the block in which the entity resides. */
int GetBlockX() const { return POSX_TOINT; }
/** Returns the Z coord. */
int GetTileZ() const { return POSZ_TOINT; } // tolua_export
/** Returns the Y coord of the block in which the entity resides. */
int GetBlockY() const { return POSY_TOINT; }
/** Returns the Z coord of the block in which the entity resides. */
int GetBlockZ() const { return POSZ_TOINT; }
// tolua_end
private:
virtual void SpawnOn(cClientHandle & a_ClientHandle) override;
virtual void Tick(float a_Dt, cChunk & a_Chunk) override {}
eBlockFace m_BlockFace;
eBlockFace m_Facing;
}; // tolua_export

View File

@ -9,10 +9,10 @@
cItemFrame::cItemFrame(eBlockFace a_BlockFace, double a_X, double a_Y, double a_Z)
: cHangingEntity(etItemFrame, a_BlockFace, a_X, a_Y, a_Z)
, m_Item(E_BLOCK_AIR)
, m_Rotation(0)
cItemFrame::cItemFrame(eBlockFace a_BlockFace, double a_X, double a_Y, double a_Z) :
cHangingEntity(etItemFrame, a_BlockFace, a_X, a_Y, a_Z),
m_Item(E_BLOCK_AIR),
m_ItemRotation(0)
{
}
@ -27,10 +27,10 @@ void cItemFrame::OnRightClicked(cPlayer & a_Player)
if (!m_Item.IsEmpty())
{
// Item not empty, rotate, clipping values to zero to three inclusive
m_Rotation++;
if (m_Rotation >= 8)
m_ItemRotation++;
if (m_ItemRotation >= 8)
{
m_Rotation = 0;
m_ItemRotation = 0;
}
}
else if (!a_Player.GetEquippedItem().IsEmpty())
@ -72,7 +72,7 @@ void cItemFrame::KilledBy(TakeDamageInfo & a_TDI)
SetHealth(GetMaxHealth());
m_Item.Empty();
m_Rotation = 0;
m_ItemRotation = 0;
SetInvulnerableTicks(0);
GetWorld()->BroadcastEntityMetadata(*this);
}

View File

@ -11,26 +11,31 @@
class cItemFrame :
public cHangingEntity
{
// tolua_end
typedef cHangingEntity super;
public:
// tolua_end
CLASS_PROTODEF(cItemFrame)
cItemFrame(eBlockFace a_BlockFace, double a_X, double a_Y, double a_Z);
// tolua_begin
/** Returns the item in the frame */
const cItem & GetItem(void) { return m_Item; } // tolua_export
const cItem & GetItem(void) { return m_Item; }
/** Set the item in the frame */
void SetItem(cItem & a_Item) { m_Item = a_Item; } // tolua_export
void SetItem(cItem & a_Item) { m_Item = a_Item; }
/** Returns the rotation from the item in the frame */
Byte GetRotation(void) const { return m_Rotation; } // tolua_export
Byte GetItemRotation(void) const { return m_ItemRotation; }
/** Set the rotation from the item in the frame */
void SetRotation(Byte a_Rotation) { m_Rotation = a_Rotation; } // tolua_export
void SetItemRotation(Byte a_ItemRotation) { m_ItemRotation = a_ItemRotation; }
// tolua_end
private:
@ -39,7 +44,7 @@ private:
virtual void GetDrops(cItems & a_Items, cEntity * a_Killer) override;
cItem m_Item;
Byte m_Rotation;
Byte m_ItemRotation;
}; // tolua_export

View File

@ -11,15 +11,22 @@
class cPainting :
public cEntity
{
// tolua_end
typedef cEntity super;
public:
// tolua_end
CLASS_PROTODEF(cPainting)
cPainting(const AString & a_Name, int a_Direction, double a_X, double a_Y, double a_Z);
const AString & GetName(void) const { return m_Name; } // tolua_export
int GetDirection(void) const { return m_Direction; } // tolua_export
// tolua_begin
const AString & GetName(void) const { return m_Name; }
int GetDirection(void) const { return m_Direction; }
// tolua_end
private:

View File

@ -37,10 +37,10 @@ public:
virtual void Tick(float a_Dt, cChunk & a_Chunk) override;
/** Returns the number of ticks that this entity has existed */
int GetAge(void) const { return (int)(m_Timer / 50); } // tolua_export
int GetAge(void) const { return static_cast<int>(m_Timer / 50); } // tolua_export
/** Set the number of ticks that this entity has existed */
void SetAge(int a_Age) { m_Timer = (float)(a_Age * 50); } // tolua_export
void SetAge(int a_Age) { m_Timer = static_cast<float>(a_Age * 50); } // tolua_export
/** Returns true if the pickup has already been collected */
bool IsCollected(void) const { return m_bCollected; } // tolua_export
@ -59,7 +59,3 @@ private:
bool m_bIsPlayerCreated;
}; // tolua_export

View File

@ -1,7 +1,7 @@
// ProjectileEntity.h
// Declares the cProjectileEntity class representing the common base class for projectiles, as well as individual projectile types
// Declares the cProjectileEntity class representing the common base class for projectiles
@ -23,7 +23,7 @@ class cProjectileEntity :
typedef cEntity super;
public:
/// The kind of the projectile. The numbers correspond to the network type ID used for spawning via the 0x17 packet.
/** The kind of the projectile. The numbers correspond to the network type ID used for spawning them in the protocol. */
enum eKind
{
pkArrow = 60,
@ -48,22 +48,22 @@ public:
static cProjectileEntity * Create(eKind a_Kind, cEntity * a_Creator, double a_X, double a_Y, double a_Z, const cItem * a_Item, const Vector3d * a_Speed = nullptr);
/// Called by the physics blocktracer when the entity hits a solid block, the hit position and the face hit (BLOCK_FACE_) is given
/** Called by the physics blocktracer when the entity hits a solid block, the hit position and the face hit (BLOCK_FACE_) is given */
virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace);
/// Called by the physics blocktracer when the entity hits another entity
/** Called by the physics blocktracer when the entity hits another entity */
virtual void OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos)
{
UNUSED(a_EntityHit);
UNUSED(a_HitPos);
}
/// Called by Chunk when the projectile is eligible for player collection
/** Called by Chunk when the projectile is eligible for player collection */
virtual void CollectedBy(cPlayer & a_Dest);
// tolua_begin
/// Returns the kind of the projectile (fast class identification)
/** Returns the kind of the projectile (fast class identification) */
eKind GetProjectileKind(void) const { return m_ProjectileKind; }
/** Returns the unique ID of the entity who created this projectile
@ -76,15 +76,15 @@ public:
*/
AString GetCreatorName(void) const { return m_CreatorData.m_Name; }
/// Returns the string that is used as the entity type (class name) in MCA files
/** Returns the string that is used as the entity type (class name) in MCA files */
AString GetMCAClassName(void) const;
/// Returns true if the projectile has hit the ground and is stuck there
/** Returns true if the projectile has hit the ground and is stuck there */
bool IsInGround(void) const { return m_IsInGround; }
// tolua_end
/// Sets the internal InGround flag. To be used by MCA loader only!
/** Sets the internal InGround flag. To be used by MCA loader only! */
void SetIsInGround(bool a_IsInGround) { m_IsInGround = a_IsInGround; }
protected:
@ -114,7 +114,7 @@ protected:
*/
CreatorData m_CreatorData;
/// True if the projectile has hit the ground and is stuck there
/** True if the projectile has hit the ground and is stuck there */
bool m_IsInGround;
// cEntity overrides:

View File

@ -1,6 +1,11 @@
//
// SplashPotionEntity.h
//
// Declares the cSplashPotionEntity class representing a splash potion that has been thrown
#pragma once
@ -32,6 +37,7 @@ public:
const cItem & a_Item
);
// tolua_begin
cEntityEffect::eType GetEntityEffectType(void) const { return m_EntityEffectType; }
cEntityEffect GetEntityEffect(void) const { return m_EntityEffect; }
int GetPotionColor(void) const { return m_PotionColor; }
@ -40,6 +46,8 @@ public:
void SetEntityEffect(cEntityEffect a_EntityEffect) { m_EntityEffect = a_EntityEffect; }
void SetPotionColor(int a_PotionColor) { m_PotionColor = a_PotionColor; }
// tolua_end
protected:
cEntityEffect::eType m_EntityEffectType;
@ -77,3 +85,7 @@ private:
/** Time in ticks to wait for the hit animation to begin before destroying */
int m_DestroyTimer;
} ; // tolua_export

View File

@ -44,6 +44,27 @@ void cThrownEggEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_Hit
void cThrownEggEntity::Tick(float a_Dt, cChunk & a_Chunk)
{
if (m_DestroyTimer > 0)
{
m_DestroyTimer--;
if (m_DestroyTimer == 0)
{
Destroy();
return;
}
}
else
{
super::Tick(a_Dt, a_Chunk);
}
}
void cThrownEggEntity::TrySpawnChicken(const Vector3d & a_HitPos)
{
if (m_World->GetTickRandomNumber(7) == 1)

View File

@ -1,6 +1,11 @@
//
// ThrownEggEntity.h
//
// Declares the cThrownEggEntity class representing a regular thrown egg
#pragma once
@ -30,22 +35,7 @@ protected:
// cProjectileEntity overrides:
virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override;
virtual void OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) override;
virtual void Tick (float a_Dt, cChunk & a_Chunk) override
{
if (m_DestroyTimer > 0)
{
m_DestroyTimer--;
if (m_DestroyTimer == 0)
{
Destroy();
return;
}
}
else
{
super::Tick(a_Dt, a_Chunk);
}
}
virtual void Tick(float a_Dt, cChunk & a_Chunk) override;
// Randomly decides whether to spawn a chicken where the egg lands.
void TrySpawnChicken(const Vector3d & a_HitPos);
@ -56,3 +46,7 @@ private:
int m_DestroyTimer;
} ; // tolua_export

View File

@ -1,3 +1,4 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "ThrownEnderPearlEntity.h"
@ -45,6 +46,27 @@ void cThrownEnderPearlEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d
void cThrownEnderPearlEntity::Tick(float a_Dt, cChunk & a_Chunk)
{
if (m_DestroyTimer > 0)
{
m_DestroyTimer--;
if (m_DestroyTimer == 0)
{
Destroy();
return;
}
}
else
{
super::Tick(a_Dt, a_Chunk);
}
}
void cThrownEnderPearlEntity::TeleportCreator(const Vector3d & a_HitPos)
{
if (m_CreatorData.m_Name.empty())

View File

@ -1,6 +1,11 @@
//
// ThrownEnderPearlEntity.h
//
// Declares the cThrownEnderPeralEntity class representing an ender pearl being thrown
#pragma once
@ -30,22 +35,7 @@ protected:
// cProjectileEntity overrides:
virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override;
virtual void OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) override;
virtual void Tick (float a_Dt, cChunk & a_Chunk) override
{
if (m_DestroyTimer > 0)
{
m_DestroyTimer--;
if (m_DestroyTimer == 0)
{
Destroy();
return;
}
}
else
{
super::Tick(a_Dt, a_Chunk);
}
}
virtual void Tick(float a_Dt, cChunk & a_Chunk) override;
/** Teleports the creator where the ender pearl lands */
void TeleportCreator(const Vector3d & a_HitPos);
@ -56,3 +46,7 @@ private:
int m_DestroyTimer;
} ; // tolua_export

View File

@ -43,3 +43,28 @@ void cThrownSnowballEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d &
m_DestroyTimer = 5;
}
void cThrownSnowballEntity::Tick(float a_Dt, cChunk & a_Chunk)
{
if (m_DestroyTimer > 0)
{
m_DestroyTimer--;
if (m_DestroyTimer == 0)
{
Destroy();
return;
}
}
else
{
super::Tick(a_Dt, a_Chunk);
}
}

View File

@ -1,6 +1,11 @@
//
// ThrownSnowballEntity.h
//
// Declares the cThrownSnowballEntity representing a snowball that has been thrown
#pragma once
@ -30,22 +35,7 @@ protected:
// cProjectileEntity overrides:
virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override;
virtual void OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) override;
virtual void Tick (float a_Dt, cChunk & a_Chunk) override
{
if (m_DestroyTimer > 0)
{
m_DestroyTimer--;
if (m_DestroyTimer == 0)
{
Destroy();
return;
}
}
else
{
super::Tick(a_Dt, a_Chunk);
}
}
virtual void Tick(float a_Dt, cChunk & a_Chunk) override;
private:
@ -53,3 +43,7 @@ private:
int m_DestroyTimer;
} ; // tolua_export

View File

@ -3,6 +3,10 @@
// Declares the cWitherSkullEntity class representing the entity used by both blue and black wither skulls
#pragma once
#include "ProjectileEntity.h"
@ -33,3 +37,7 @@ protected:
virtual void OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) override;
} ; // tolua_export

View File

@ -119,9 +119,9 @@ cTerrainCompositionGenPtr cTerrainCompositionGen::CreateCompositionGen(cIniFile
cComposableGenerator::cComposableGenerator(cChunkGenerator & a_ChunkGenerator) :
super(a_ChunkGenerator),
m_BiomeGen(nullptr),
m_HeightGen(nullptr),
m_CompositionGen(nullptr)
m_BiomeGen(),
m_HeightGen(),
m_CompositionGen()
{
}

View File

@ -572,6 +572,8 @@ bool cItemHandler::CanHarvestBlock(BLOCKTYPE a_BlockType)
case E_BLOCK_COBBLESTONE:
case E_BLOCK_COBBLESTONE_STAIRS:
case E_BLOCK_COBBLESTONE_WALL:
case E_BLOCK_COBWEB:
case E_BLOCK_DEAD_BUSH:
case E_BLOCK_DIAMOND_BLOCK:
case E_BLOCK_DIAMOND_ORE:
case E_BLOCK_DOUBLE_NEW_STONE_SLAB:

View File

@ -28,21 +28,25 @@ public:
virtual bool OnDiggingBlock(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Dir) override
{
BLOCKTYPE Block = a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ);
BLOCKTYPE Block;
NIBBLETYPE BlockMeta;
a_World->GetBlockTypeMeta(a_BlockX, a_BlockY, a_BlockZ, Block, BlockMeta);
if ((Block == E_BLOCK_LEAVES) || (Block == E_BLOCK_NEW_LEAVES))
{
NIBBLETYPE Meta = a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ);
cItems Drops;
cBlockHandler * Handler = cBlockInfo::GetHandler(Block);
cItems Drops;
Handler->ConvertToPickups(Drops, Meta);
Drops.push_back(cItem(Block, 1, Meta & 3));
Handler->ConvertToPickups(Drops, BlockMeta);
Drops.Add(Block, 1, BlockMeta & 3);
a_World->SpawnItemPickups(Drops, a_BlockX, a_BlockY, a_BlockZ);
a_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0);
a_World->SpawnItemPickups(Drops, a_BlockX, a_BlockY, a_BlockZ);
a_Player->UseEquippedItem();
return true;
}
return false;
}
@ -53,12 +57,10 @@ public:
{
case E_BLOCK_COBWEB:
case E_BLOCK_VINES:
case E_BLOCK_LEAVES:
case E_BLOCK_NEW_LEAVES:
{
return true;
}
} // switch (a_BlockType)
}
return super::CanHarvestBlock(a_BlockType);
}
@ -71,14 +73,23 @@ public:
virtual void OnBlockDestroyed(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ) override
{
super::OnBlockDestroyed(a_World, a_Player, a_Item, a_BlockX, a_BlockY, a_BlockZ);
BLOCKTYPE Block;
NIBBLETYPE BlockMeta;
a_World->GetBlockTypeMeta(a_BlockX, a_BlockY, a_BlockZ, Block, BlockMeta);
BLOCKTYPE Block = a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ);
if ((Block == E_BLOCK_TRIPWIRE) || (Block == E_BLOCK_VINES))
super::OnBlockDestroyed(a_World, a_Player, a_Item, a_BlockX, a_BlockY, a_BlockZ);
switch (Block)
{
case E_BLOCK_COBWEB:
case E_BLOCK_DEAD_BUSH:
case E_BLOCK_TRIPWIRE:
case E_BLOCK_VINES:
case E_BLOCK_WOOL:
{
a_Player->UseEquippedItem();
}
}
}
} ;

View File

@ -84,7 +84,7 @@ public:
virtual void InStateChasing (float a_Dt);
virtual void InStateEscaping(float a_Dt);
int GetAttackRate() { return (int)m_AttackRate; }
int GetAttackRate() { return static_cast<int>(m_AttackRate); }
void SetAttackRate(float a_AttackRate) { m_AttackRate = a_AttackRate; }
void SetAttackRange(int a_AttackRange) { m_AttackRange = a_AttackRange; }
void SetAttackDamage(int a_AttackDamage) { m_AttackDamage = a_AttackDamage; }
@ -257,7 +257,3 @@ protected:
} ; // tolua_export

View File

@ -58,7 +58,3 @@ protected:
#endif // CISTHREAD_H_INCLUDED

View File

@ -2803,7 +2803,7 @@ void cProtocol172::cPacketizer::WriteEntityMetadata(const cEntity & a_Entity)
WriteByte(0xA2);
WriteItem(Frame.GetItem());
WriteByte(0x3);
WriteByte(Frame.GetRotation() / 2);
WriteByte(Frame.GetItemRotation() / 2);
break;
}
default: break;

View File

@ -3109,7 +3109,7 @@ void cProtocol180::cPacketizer::WriteEntityMetadata(const cEntity & a_Entity)
WriteByte(0xA8);
WriteItem(Frame.GetItem());
WriteByte(0x09);
WriteByte(Frame.GetRotation());
WriteByte(Frame.GetItemRotation());
break;
}
default: break;

View File

@ -685,21 +685,21 @@ void cNBTChunkSerializer::AddProjectileEntity(cProjectileEntity * a_Projectile)
void cNBTChunkSerializer::AddHangingEntity(cHangingEntity * a_Hanging)
{
m_Writer.AddByte("Direction", (unsigned char)a_Hanging->GetDirection());
m_Writer.AddInt("TileX", a_Hanging->GetTileX());
m_Writer.AddInt("TileY", a_Hanging->GetTileY());
m_Writer.AddInt("TileZ", a_Hanging->GetTileZ());
switch (a_Hanging->GetDirection())
m_Writer.AddInt("TileX", a_Hanging->GetBlockX());
m_Writer.AddInt("TileY", a_Hanging->GetBlockY());
m_Writer.AddInt("TileZ", a_Hanging->GetBlockZ());
switch (a_Hanging->GetFacing())
{
case BLOCK_FACE_YM: m_Writer.AddByte("Dir", (unsigned char)2); break;
case BLOCK_FACE_YP: m_Writer.AddByte("Dir", (unsigned char)1); break;
case BLOCK_FACE_ZM: m_Writer.AddByte("Dir", (unsigned char)0); break;
case BLOCK_FACE_ZP: m_Writer.AddByte("Dir", (unsigned char)3); break;
case BLOCK_FACE_XM: m_Writer.AddByte("Facing", 1); break;
case BLOCK_FACE_XP: m_Writer.AddByte("Facing", 3); break;
case BLOCK_FACE_ZM: m_Writer.AddByte("Facing", 2); break;
case BLOCK_FACE_ZP: m_Writer.AddByte("Facing", 0); break;
case BLOCK_FACE_XM:
case BLOCK_FACE_XP:
case BLOCK_FACE_YM:
case BLOCK_FACE_YP:
case BLOCK_FACE_NONE:
{
// These directions are invalid, but they may have been previously loaded, so keep them.
break;
}
}
@ -740,7 +740,7 @@ void cNBTChunkSerializer::AddItemFrameEntity(cItemFrame * a_ItemFrame)
AddBasicEntity(a_ItemFrame, "ItemFrame");
AddHangingEntity(a_ItemFrame);
AddItem(a_ItemFrame->GetItem(), -1, "Item");
m_Writer.AddByte("ItemRotation", (unsigned char)a_ItemFrame->GetRotation());
m_Writer.AddByte("ItemRotation", (unsigned char)a_ItemFrame->GetItemRotation());
m_Writer.AddFloat("ItemDropChance", 1.0F);
m_Writer.EndCompound();
}

View File

@ -1660,30 +1660,41 @@ void cWSSAnvil::LoadExpOrbFromNBT(cEntityList & a_Entities, const cParsedNBT & a
void cWSSAnvil::LoadHangingFromNBT(cHangingEntity & a_Hanging, const cParsedNBT & a_NBT, int a_TagIdx)
{
int Direction = a_NBT.FindChildByName(a_TagIdx, "Direction");
if (Direction > 0)
// "Facing" tag is the prime source of the Facing; if not available, translate from older "Direction" or "Dir"
int Facing = a_NBT.FindChildByName(a_TagIdx, "Facing");
if (Facing > 0)
{
Direction = (int)a_NBT.GetByte(Direction);
if ((Direction < 2) || (Direction > 5))
Facing = (int)a_NBT.GetByte(Facing);
if ((Facing >= 2) && (Facing <= 5))
{
a_Hanging.SetDirection(BLOCK_FACE_NORTH);
}
else
{
a_Hanging.SetDirection(static_cast<eBlockFace>(Direction));
a_Hanging.SetFacing(static_cast<eBlockFace>(Facing));
}
}
else
{
Direction = a_NBT.FindChildByName(a_TagIdx, "Dir");
if (Direction > 0)
Facing = a_NBT.FindChildByName(a_TagIdx, "Direction");
if (Facing > 0)
{
switch ((int)a_NBT.GetByte(Direction))
switch ((int)a_NBT.GetByte(Facing))
{
case 0: a_Hanging.SetDirection(BLOCK_FACE_NORTH); break;
case 1: a_Hanging.SetDirection(BLOCK_FACE_TOP); break;
case 2: a_Hanging.SetDirection(BLOCK_FACE_BOTTOM); break;
case 3: a_Hanging.SetDirection(BLOCK_FACE_SOUTH); break;
case 0: a_Hanging.SetFacing(BLOCK_FACE_ZM); break;
case 1: a_Hanging.SetFacing(BLOCK_FACE_XM); break;
case 2: a_Hanging.SetFacing(BLOCK_FACE_ZP); break;
case 3: a_Hanging.SetFacing(BLOCK_FACE_XP); break;
}
}
else
{
Facing = a_NBT.FindChildByName(a_TagIdx, "Dir"); // Has values 0 and 2 swapped
if (Facing > 0)
{
switch ((int)a_NBT.GetByte(Facing))
{
case 0: a_Hanging.SetFacing(BLOCK_FACE_ZP); break;
case 1: a_Hanging.SetFacing(BLOCK_FACE_XM); break;
case 2: a_Hanging.SetFacing(BLOCK_FACE_ZM); break;
case 3: a_Hanging.SetFacing(BLOCK_FACE_XP); break;
}
}
}
}
@ -1732,7 +1743,7 @@ void cWSSAnvil::LoadItemFrameFromNBT(cEntityList & a_Entities, const cParsedNBT
int Rotation = a_NBT.FindChildByName(a_TagIdx, "ItemRotation");
if (Rotation > 0)
{
ItemFrame->SetRotation((Byte)a_NBT.GetByte(Rotation));
ItemFrame->SetItemRotation((Byte)a_NBT.GetByte(Rotation));
}
a_Entities.push_back(ItemFrame.release());