From baf2d8892127cd6da9d2f6f2f8d991d617c87800 Mon Sep 17 00:00:00 2001
From: Tiger Wang
Date: Wed, 26 Feb 2014 23:29:14 +0000
Subject: Implemented ballistic missiles (fireworks)
+ Added fireworks
---
MCServer/crafting.txt | 49 +++++-
src/CraftingRecipes.cpp | 89 ++++++++++-
src/Entities/ProjectileEntity.cpp | 87 ++++++-----
src/Entities/ProjectileEntity.h | 12 +-
src/Item.cpp | 22 ++-
src/Item.h | 16 +-
src/Items/ItemThrowable.h | 6 +-
src/Protocol/Protocol17x.cpp | 77 ++++++----
src/World.cpp | 4 +-
src/World.h | 2 +-
src/WorldStorage/FastNBT.h | 2 +-
src/WorldStorage/FireworksSerializer.cpp | 250 +++++++++++++++++++++++++++++++
src/WorldStorage/FireworksSerializer.h | 88 +++++++++++
src/WorldStorage/NBTChunkSerializer.cpp | 14 +-
src/WorldStorage/WSSAnvil.cpp | 6 +
15 files changed, 637 insertions(+), 87 deletions(-)
create mode 100644 src/WorldStorage/FireworksSerializer.cpp
create mode 100644 src/WorldStorage/FireworksSerializer.h
diff --git a/MCServer/crafting.txt b/MCServer/crafting.txt
index 92abe24cb..bce0c5e9e 100644
--- a/MCServer/crafting.txt
+++ b/MCServer/crafting.txt
@@ -39,6 +39,7 @@
#
# Need to list each of the four log types, otherwise all logs would get converted into apple planks (^0)
+
ApplePlanks, 4 = AppleLog, *
ConiferPlanks, 4 = ConiferLog, *
BirchPlanks, 4 = BirchLog, *
@@ -434,6 +435,48 @@ GoldNugget, 9 = GoldIngot, *
EnchantmentTable = Obsidian, 1:3, 2:3, 3:3, 2:2 | Diamond, 1:2, 3:2 | Book, 2:1
-
-
-
+#******************************************************#
+# Fireworks & Co.
+# (Best not to add non-vanilla items to this as it will cause internal firework data handling code to log warnings)
+
+# Ballistic firework rockets - plain and with firework star, all with 1 - 3 gunpowder
+FireworkRocket = Paper, * | Gunpowder, *
+FireworkRocket = Paper, * | Gunpowder, * | Gunpowder, *
+FireworkRocket = Paper, * | Gunpowder, * | Gunpowder, * | Gunpowder, *
+FireworkRocket = FireworkStar, * | Paper, * | Gunpowder, *
+FireworkRocket = FireworkStar, * | Paper, * | Gunpowder, * | Gunpowder, *
+FireworkRocket = FireworkStar, * | Paper, * | Gunpowder, * | Gunpowder, * | Gunpowder, *
+
+# Radioactive firework stars
+# Plain powder and dye
+FireworkStar = Gunpowder, * | Dye ^-1, *
+
+# Powder and effect, with effect combining
+FireworkStar = Gunpowder, * | Dye ^-1, * | Diamond, *
+FireworkStar = Gunpowder, * | Dye ^-1, * | Glowdust, *
+FireworkStar = Gunpowder, * | Dye ^-1, * | Glowdust, * | Diamond, *
+
+# Powder and shape (no shape combining possible)
+FireworkStar = Gunpowder, * | Dye ^-1, * | Firecharge, *
+FireworkStar = Gunpowder, * | Dye ^-1, * | Goldnugget, *
+FireworkStar = Gunpowder, * | Dye ^-1, * | Feather, *
+FireworkStar = Gunpowder, * | Dye ^-1, * | SkeletonHead ^-1, *
+
+# Power and shape (no shape combining possible), combined with effect
+FireworkStar = Gunpowder, * | Dye ^-1, * | Firecharge, * | Diamond, *
+FireworkStar = Gunpowder, * | Dye ^-1, * | Firecharge, * | Glowdust, *
+FireworkStar = Gunpowder, * | Dye ^-1, * | Goldnugget, * | Diamond, *
+FireworkStar = Gunpowder, * | Dye ^-1, * | Goldnugget, * | Glowdust, *
+FireworkStar = Gunpowder, * | Dye ^-1, * | Feather, * | Diamond, *
+FireworkStar = Gunpowder, * | Dye ^-1, * | Feather, * | Glowdust, *
+FireworkStar = Gunpowder, * | Dye ^-1, * | SkeletonHead ^-1, * | Diamond, *
+FireworkStar = Gunpowder, * | Dye ^-1, * | SkeletonHead ^-1, * | Glowdust, *
+
+# Power and shape (no shape combining possible), combined with effect (with effect combining)
+FireworkStar = Gunpowder, * | Dye ^-1, * | Firecharge, * | Glowdust, * | Diamond, *
+FireworkStar = Gunpowder, * | Dye ^-1, * | Goldnugget, * | Glowdust, * | Diamond, *
+FireworkStar = Gunpowder, * | Dye ^-1, * | Feather, * | Glowdust, * | Diamond, *
+FireworkStar = Gunpowder, * | Dye ^-1, * | SkeletonHead ^-1, * | Glowdust, * | Diamond, *
+
+# Star colour-change
+FireworkStar = FireworkStar, * | Dye ^-1, *
diff --git a/src/CraftingRecipes.cpp b/src/CraftingRecipes.cpp
index fb1a10cca..41de0da8c 100644
--- a/src/CraftingRecipes.cpp
+++ b/src/CraftingRecipes.cpp
@@ -1,4 +1,4 @@
-
+
// CraftingRecipes.cpp
// Interfaces to the cCraftingRecipes class representing the storage of crafting recipes
@@ -762,6 +762,93 @@ cCraftingRecipes::cRecipe * cCraftingRecipes::MatchRecipe(const cItem * a_Crafti
Recipe->m_Ingredients.push_back(*itrS);
}
Recipe->m_Ingredients.insert(Recipe->m_Ingredients.end(), MatchedSlots.begin(), MatchedSlots.end());
+
+
+ // Henceforth is code to handle fireworks
+ // We use Recipe instead of a_Recipe because we want the wildcard ingredients' slot numbers as well, which was just added previously
+
+ if (Recipe->m_Result.m_ItemType == E_ITEM_FIREWORK_ROCKET)
+ {
+ for (cRecipeSlots::const_iterator itr = Recipe->m_Ingredients.begin(); itr != Recipe->m_Ingredients.end(); ++itr)
+ {
+ switch (itr->m_Item.m_ItemType)
+ {
+ case E_ITEM_FIREWORK_STAR:
+ {
+ // Result was a rocket, found a star - copy star data to rocket data
+ int GridID = (itr->x + a_OffsetX) + a_GridStride * (itr->y + a_OffsetY);
+ Recipe->m_Result.m_FireworkItem.CopyFrom(a_CraftingGrid[GridID].m_FireworkItem);
+ break;
+ }
+ case E_ITEM_GUNPOWDER:
+ {
+ // Gunpowder - increase flight time
+ Recipe->m_Result.m_FireworkItem.m_FlightTimeInTicks += 20;
+ break;
+ }
+ case E_ITEM_PAPER: break;
+ default: LOG("Unexpected item in firework rocket recipe, was the crafting file fireworks section changed?"); break;
+ }
+ }
+ }
+ else if (Recipe->m_Result.m_ItemType == E_ITEM_FIREWORK_STAR)
+ {
+ for (cRecipeSlots::const_iterator itr = Recipe->m_Ingredients.begin(); itr != Recipe->m_Ingredients.end(); ++itr)
+ {
+ switch (itr->m_Item.m_ItemType)
+ {
+ case E_ITEM_FIREWORK_STAR:
+ {
+ // Result was star, found another star - probably adding fade colours, but copy data over anyhow
+ int GridID = (itr->x + a_OffsetX) + a_GridStride * (itr->y + a_OffsetY);
+ Recipe->m_Result.m_FireworkItem.CopyFrom(a_CraftingGrid[GridID].m_FireworkItem);
+ break;
+ }
+ case E_ITEM_DYE:
+ {
+ // Found a dye in ingredients...
+ for (cRecipeSlots::const_iterator itrnumerodos = Recipe->m_Ingredients.begin(); itrnumerodos != Recipe->m_Ingredients.end(); ++itrnumerodos)
+ {
+ // Loop through ingredients. Can we find a star?
+ if (itrnumerodos->m_Item.m_ItemType == E_ITEM_FIREWORK_STAR)
+ {
+ // Yes, this is definately adding fade colours, unless crafting.txt was changed :/
+ for (cRecipeSlots::const_iterator itrnumerotres = Recipe->m_Ingredients.begin(); itrnumerotres != Recipe->m_Ingredients.end(); ++itrnumerotres)
+ {
+ // Loop again, can we find dye?
+ if (itrnumerotres->m_Item.m_ItemType == E_ITEM_DYE)
+ {
+ // Yep, push back fade colour and exit the loop
+ // There is a potential for flexibility here - we can move the goto out of the loop, so we can add multiple dyes (∴ multiple fade colours)
+ // That will require lots of dye-adding to crafting.txt though - TODO, perchance?
+ int GridID = (itrnumerotres->x + a_OffsetX) + a_GridStride * (itrnumerotres->y + a_OffsetY);
+ Recipe->m_Result.m_FireworkItem.m_FadeColours.push_back(cFireworkItem::GetVanillaColourCodeFromDye(a_CraftingGrid[GridID].m_ItemDamage));
+ goto next;
+ }
+ }
+ }
+ }
+
+ // Just normal crafting of star, push back normal colours
+ int GridID = (itr->x + a_OffsetX) + a_GridStride * (itr->y + a_OffsetY);
+ Recipe->m_Result.m_FireworkItem.m_Colours.push_back(cFireworkItem::GetVanillaColourCodeFromDye(a_CraftingGrid[GridID].m_ItemDamage));
+
+ next:
+ break;
+ }
+ case E_ITEM_GUNPOWDER: break;
+ case E_ITEM_DIAMOND: Recipe->m_Result.m_FireworkItem.m_HasTrail = true; break;
+ case E_ITEM_GLOWSTONE_DUST: Recipe->m_Result.m_FireworkItem.m_HasFlicker = true; break;
+
+ case E_ITEM_FIRE_CHARGE: Recipe->m_Result.m_FireworkItem.m_Type = 1; break;
+ case E_ITEM_GOLD_NUGGET: Recipe->m_Result.m_FireworkItem.m_Type = 2; break;
+ case E_ITEM_FEATHER: Recipe->m_Result.m_FireworkItem.m_Type = 4; break;
+ case E_ITEM_HEAD: Recipe->m_Result.m_FireworkItem.m_Type = 3; break;
+ default: LOG("Unexpected item in firework star recipe, was the crafting file fireworks section changed?"); break; // ermahgerd BARD ardmins
+ }
+ }
+ }
+
return Recipe.release();
}
diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp
index ef82c6e94..be8e24540 100644
--- a/src/Entities/ProjectileEntity.cpp
+++ b/src/Entities/ProjectileEntity.cpp
@@ -214,7 +214,7 @@ cProjectileEntity::cProjectileEntity(eKind a_Kind, cEntity * a_Creator, const Ve
-cProjectileEntity * cProjectileEntity::Create(eKind a_Kind, cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d * a_Speed)
+cProjectileEntity * 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)
{
Vector3d Speed;
if (a_Speed != NULL)
@@ -231,8 +231,15 @@ cProjectileEntity * cProjectileEntity::Create(eKind a_Kind, cEntity * a_Creator,
case pkGhastFireball: return new cGhastFireballEntity (a_Creator, a_X, a_Y, a_Z, Speed);
case pkFireCharge: return new cFireChargeEntity (a_Creator, a_X, a_Y, a_Z, Speed);
case pkExpBottle: return new cExpBottleEntity (a_Creator, a_X, a_Y, a_Z, Speed);
- case pkFirework: return new cFireworkEntity (a_Creator, a_X, a_Y, a_Z );
- // TODO: the rest
+ case pkFirework:
+ {
+ if (a_Item.m_FireworkItem.m_Colours.empty())
+ {
+ return NULL;
+ }
+
+ return new cFireworkEntity(a_Creator, a_X, a_Y, a_Z, a_Item);
+ }
}
LOGWARNING("%s: Unknown projectile kind: %d", __FUNCTION__, a_Kind);
@@ -276,6 +283,7 @@ AString cProjectileEntity::GetMCAClassName(void) const
case pkExpBottle: return "ThrownExpBottle";
case pkSplashPotion: return "ThrownPotion";
case pkWitherSkull: return "WitherSkull";
+ case pkFirework: return "Firework";
case pkFishingFloat: return ""; // Unknown, perhaps MC doesn't save this?
}
ASSERT(!"Unhandled projectile entity kind!");
@@ -693,8 +701,10 @@ void cExpBottleEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_H
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cFireworkEntity :
-cFireworkEntity::cFireworkEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z) :
-super(pkFirework, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25)
+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_FireworkItem(a_Item)
{
}
@@ -702,30 +712,20 @@ super(pkFirework, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25)
-void cFireworkEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace)
+void cFireworkEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk)
{
- if ((a_HitFace != BLOCK_FACE_BOTTOM) && (a_HitFace != BLOCK_FACE_NONE))
+ int RelX = POSX_TOINT - a_Chunk.GetPosX() * cChunkDef::Width;
+ int RelZ = POSZ_TOINT - a_Chunk.GetPosZ() * cChunkDef::Width;
+ int PosY = POSY_TOINT;
+
+ if ((PosY < 0) || (PosY >= cChunkDef::Height))
{
- return;
+ goto setspeed;
}
- SetSpeed(0, 0, 0);
- SetPosition(GetPosX(), GetPosY() - 0.5, GetPosZ());
-
- m_IsInGround = true;
-
- BroadcastMovementUpdate();
-}
-
-
-
-
-
-void cFireworkEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk)
-{
if (m_IsInGround)
{
- if (a_Chunk.GetBlock((int)GetPosX(), (int)GetPosY() + 1, (int)GetPosZ()) == E_BLOCK_AIR)
+ if (a_Chunk.GetBlock(RelX, POSY_TOINT + 1, RelZ) == E_BLOCK_AIR)
{
m_IsInGround = false;
}
@@ -734,28 +734,35 @@ void cFireworkEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk)
return;
}
}
+ else
+ {
+ if (a_Chunk.GetBlock(RelX, POSY_TOINT + 1, RelZ) != E_BLOCK_AIR)
+ {
+ OnHitSolidBlock(GetPosition(), BLOCK_FACE_YM);
+ return;
+ }
+ }
- Vector3d PerTickSpeed = GetSpeed() / 20;
- Vector3d Pos = GetPosition();
+setspeed:
+ AddSpeedY(1);
+ AddPosition(GetSpeed() * (a_Dt / 1000));
+}
- // Trace the tick's worth of movement as a line:
- Vector3d NextPos = Pos + PerTickSpeed;
- cProjectileTracerCallback TracerCallback(this);
- if (!cLineBlockTracer::Trace(*m_World, TracerCallback, Pos, NextPos))
+
+
+
+
+void cFireworkEntity::Tick(float a_Dt, cChunk & a_Chunk)
+{
+ super::Tick(a_Dt, a_Chunk);
+
+ if (m_ExplodeTimer == m_FireworkItem.m_FireworkItem.m_FlightTimeInTicks)
{
- // Something has been hit, abort all other processing
- return;
+ m_World->BroadcastEntityStatus(*this, ENTITY_STATUS_FIREWORK_EXPLODE);
+ Destroy();
}
- // The tracer also checks the blocks for slowdown blocks - water and lava - and stores it for later in its SlowdownCoeff
-
- // Update the position:
- SetPosition(NextPos);
- // Add slowdown and gravity effect to the speed:
- Vector3d NewSpeed(GetSpeed());
- NewSpeed.y += 2;
- NewSpeed *= TracerCallback.GetSlowdownCoeff();
- SetSpeed(NewSpeed);
+ m_ExplodeTimer++;
}
diff --git a/src/Entities/ProjectileEntity.h b/src/Entities/ProjectileEntity.h
index e80592999..fac592d16 100644
--- a/src/Entities/ProjectileEntity.h
+++ b/src/Entities/ProjectileEntity.h
@@ -46,7 +46,7 @@ public:
cProjectileEntity(eKind a_Kind, cEntity * a_Creator, double a_X, double a_Y, double a_Z, double a_Width, double a_Height);
cProjectileEntity(eKind a_Kind, cEntity * a_Creator, const Vector3d & a_Pos, const Vector3d & a_Speed, double a_Width, double a_Height);
- static cProjectileEntity * Create(eKind a_Kind, cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d * a_Speed = NULL);
+ 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 = NULL);
/// 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);
@@ -305,13 +305,19 @@ public:
CLASS_PROTODEF(cFireworkEntity);
- cFireworkEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z);
+ cFireworkEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const cItem & a_Item);
+ const cItem & GetItem(void) const { return m_FireworkItem; }
protected:
// cProjectileEntity overrides:
- virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override;
virtual void HandlePhysics(float a_Dt, cChunk & a_Chunk) override;
+ virtual void Tick(float a_Dt, cChunk & a_Chunk) override;
+
+private:
+
+ int m_ExplodeTimer;
+ cItem m_FireworkItem;
// tolua_begin
diff --git a/src/Item.cpp b/src/Item.cpp
index 9170006b6..61d57e763 100644
--- a/src/Item.cpp
+++ b/src/Item.cpp
@@ -1,4 +1,4 @@
-
+
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "Item.h"
@@ -139,6 +139,16 @@ void cItem::GetJson(Json::Value & a_OutValue) const
{
a_OutValue["Lore"] = m_Lore;
}
+
+ if ((m_ItemType == E_ITEM_FIREWORK_ROCKET) || (m_ItemType == E_ITEM_FIREWORK_STAR))
+ {
+ a_OutValue["Flicker"] = m_FireworkItem.m_HasFlicker;
+ a_OutValue["Trail"] = m_FireworkItem.m_HasTrail;
+ a_OutValue["Type"] = m_FireworkItem.m_Type;
+ a_OutValue["FlightTimeInTicks"] = m_FireworkItem.m_FlightTimeInTicks;
+ a_OutValue["Colours"] = m_FireworkItem.ColoursToString(m_FireworkItem);
+ a_OutValue["FadeColours"] = m_FireworkItem.FadeColoursToString(m_FireworkItem);
+ }
}
}
@@ -157,6 +167,16 @@ void cItem::FromJson(const Json::Value & a_Value)
m_Enchantments.AddFromString(a_Value.get("ench", "").asString());
m_CustomName = a_Value.get("Name", "").asString();
m_Lore = a_Value.get("Lore", "").asString();
+
+ if ((m_ItemType == E_ITEM_FIREWORK_ROCKET) || (m_ItemType == E_ITEM_FIREWORK_STAR))
+ {
+ m_FireworkItem.m_HasFlicker = a_Value.get("Flicker", false).asBool();
+ m_FireworkItem.m_HasTrail = a_Value.get("Trail", false).asBool();
+ m_FireworkItem.m_Type = (NIBBLETYPE)a_Value.get("Type", 0).asInt();
+ m_FireworkItem.m_FlightTimeInTicks = (short)a_Value.get("FlightTimeInTicks", 0).asInt();
+ m_FireworkItem.ColoursFromString(a_Value.get("Colours", "").asString(), m_FireworkItem);
+ m_FireworkItem.FadeColoursFromString(a_Value.get("FadeColours", "").asString(), m_FireworkItem);
+ }
}
}
diff --git a/src/Item.h b/src/Item.h
index cc3b3c961..4bdfb12dd 100644
--- a/src/Item.h
+++ b/src/Item.h
@@ -11,6 +11,7 @@
#include "Defines.h"
#include "Enchantments.h"
+#include "WorldStorage/FireworksSerializer.h"
@@ -38,7 +39,8 @@ public:
m_ItemCount(0),
m_ItemDamage(0),
m_CustomName(""),
- m_Lore("")
+ m_Lore(""),
+ m_FireworkItem()
{
}
@@ -57,7 +59,8 @@ public:
m_ItemDamage (a_ItemDamage),
m_Enchantments(a_Enchantments),
m_CustomName (a_CustomName),
- m_Lore (a_Lore)
+ m_Lore (a_Lore),
+ m_FireworkItem()
{
if (!IsValidItem(m_ItemType))
{
@@ -77,7 +80,8 @@ public:
m_ItemDamage (a_CopyFrom.m_ItemDamage),
m_Enchantments(a_CopyFrom.m_Enchantments),
m_CustomName (a_CopyFrom.m_CustomName),
- m_Lore (a_CopyFrom.m_Lore)
+ m_Lore (a_CopyFrom.m_Lore),
+ m_FireworkItem(a_CopyFrom.m_FireworkItem)
{
}
@@ -90,6 +94,7 @@ public:
m_Enchantments.Clear();
m_CustomName = "";
m_Lore = "";
+ m_FireworkItem.EmptyData();
}
@@ -115,7 +120,8 @@ public:
(m_ItemDamage == a_Item.m_ItemDamage) &&
(m_Enchantments == a_Item.m_Enchantments) &&
(m_CustomName == a_Item.m_CustomName) &&
- (m_Lore == a_Item.m_Lore)
+ (m_Lore == a_Item.m_Lore) &&
+ m_FireworkItem.IsEqualTo(a_Item.m_FireworkItem)
);
}
@@ -177,6 +183,8 @@ public:
cEnchantments m_Enchantments;
AString m_CustomName;
AString m_Lore;
+
+ cFireworkItem m_FireworkItem;
};
// tolua_end
diff --git a/src/Items/ItemThrowable.h b/src/Items/ItemThrowable.h
index 46049f961..c6a4e714e 100644
--- a/src/Items/ItemThrowable.h
+++ b/src/Items/ItemThrowable.h
@@ -35,7 +35,7 @@ public:
Vector3d Pos = a_Player->GetThrowStartPos();
Vector3d Speed = a_Player->GetLookVector() * m_SpeedCoeff;
- a_World->CreateProjectile(Pos.x, Pos.y, Pos.z, m_ProjectileKind, a_Player, &Speed);
+ a_World->CreateProjectile(Pos.x, Pos.y, Pos.z, m_ProjectileKind, a_Player, a_Player->GetEquippedItem(), &Speed);
return true;
}
@@ -127,13 +127,13 @@ public:
return false;
}
+ a_World->CreateProjectile(a_BlockX + 0.5, a_BlockY + 1, a_BlockZ + 0.5, m_ProjectileKind, a_Player, a_Player->GetEquippedItem());
+
if (!a_Player->IsGameModeCreative())
{
a_Player->GetInventory().RemoveOneEquippedItem();
}
- a_World->CreateProjectile(a_BlockX + 0.5, a_BlockY + 1, a_BlockZ + 0.5, m_ProjectileKind, a_Player, 0);
-
return true;
}
diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp
index 992023464..e0f02930c 100644
--- a/src/Protocol/Protocol17x.cpp
+++ b/src/Protocol/Protocol17x.cpp
@@ -2069,36 +2069,47 @@ void cProtocol172::ParseItemMetadata(cItem & a_Item, const AString & a_Metadata)
// Load enchantments and custom display names from the NBT data:
for (int tag = NBT.GetFirstChild(NBT.GetRoot()); tag >= 0; tag = NBT.GetNextSibling(tag))
{
- if (
- (NBT.GetType(tag) == TAG_List) &&
- (
- (NBT.GetName(tag) == "ench") ||
- (NBT.GetName(tag) == "StoredEnchantments")
- )
- )
+ AString TagName = NBT.GetName(tag);
+ switch (NBT.GetType(tag))
{
- EnchantmentSerializer::ParseFromNBT(a_Item.m_Enchantments, NBT, tag);
- }
- else if ((NBT.GetType(tag) == TAG_Compound) && (NBT.GetName(tag) == "display")) // Custom name and lore tag
- {
- for (int displaytag = NBT.GetFirstChild(tag); displaytag >= 0; displaytag = NBT.GetNextSibling(displaytag))
+ case TAG_List:
{
- if ((NBT.GetType(displaytag) == TAG_String) && (NBT.GetName(displaytag) == "Name")) // Custon name tag
+ if ((TagName == "ench") || (TagName == "StoredEnchantments")) // Enchantments tags
{
- a_Item.m_CustomName = NBT.GetString(displaytag);
+ EnchantmentSerializer::ParseFromNBT(a_Item.m_Enchantments, NBT, tag);
}
- else if ((NBT.GetType(displaytag) == TAG_List) && (NBT.GetName(displaytag) == "Lore")) // Lore tag
+ break;
+ }
+ case TAG_Compound:
+ {
+ if (TagName == "display") // Custom name and lore tag
{
- AString Lore;
-
- for (int loretag = NBT.GetFirstChild(displaytag); loretag >= 0; loretag = NBT.GetNextSibling(loretag)) // Loop through array of strings
+ for (int displaytag = NBT.GetFirstChild(tag); displaytag >= 0; displaytag = NBT.GetNextSibling(displaytag))
{
- AppendPrintf(Lore, "%s`", NBT.GetString(loretag).c_str()); // Append the lore with a newline, used internally by MCS to display a new line in the client; don't forget to c_str ;)
+ if ((NBT.GetType(displaytag) == TAG_String) && (NBT.GetName(displaytag) == "Name")) // Custon name tag
+ {
+ a_Item.m_CustomName = NBT.GetString(displaytag);
+ }
+ else if ((NBT.GetType(displaytag) == TAG_List) && (NBT.GetName(displaytag) == "Lore")) // Lore tag
+ {
+ AString Lore;
+
+ for (int loretag = NBT.GetFirstChild(displaytag); loretag >= 0; loretag = NBT.GetNextSibling(loretag)) // Loop through array of strings
+ {
+ AppendPrintf(Lore, "%s`", NBT.GetString(loretag).c_str()); // Append the lore with a newline, used internally by MCS to display a new line in the client; don't forget to c_str ;)
+ }
+
+ a_Item.m_Lore = Lore;
+ }
}
-
- a_Item.m_Lore = Lore;
}
+ else if ((TagName == "Fireworks") || (TagName == "Explosion"))
+ {
+ cFireworkItem::ParseFromNBT(a_Item.m_FireworkItem, NBT, tag, (ENUM_ITEM_ID)a_Item.m_ItemType);
+ }
+ break;
}
+ default: LOGD("Unimplemented NBT data when parsing!"); break;
}
}
}
@@ -2262,7 +2273,7 @@ void cProtocol172::cPacketizer::WriteItem(const cItem & a_Item)
WriteByte (a_Item.m_ItemCount);
WriteShort(a_Item.m_ItemDamage);
- if (a_Item.m_Enchantments.IsEmpty() && a_Item.IsBothNameAndLoreEmpty())
+ if (a_Item.m_Enchantments.IsEmpty() && a_Item.IsBothNameAndLoreEmpty() && (a_Item.m_ItemType != E_ITEM_FIREWORK_ROCKET) && (a_Item.m_ItemType != E_ITEM_FIREWORK_STAR))
{
WriteShort(-1);
return;
@@ -2301,6 +2312,10 @@ void cProtocol172::cPacketizer::WriteItem(const cItem & a_Item)
}
Writer.EndCompound();
}
+ if ((a_Item.m_ItemType == E_ITEM_FIREWORK_ROCKET) || (a_Item.m_ItemType == E_ITEM_FIREWORK_STAR))
+ {
+ cFireworkItem::WriteToNBTCompound(a_Item.m_FireworkItem, Writer, (ENUM_ITEM_ID)a_Item.m_ItemType);
+ }
Writer.Finish();
AString Compressed;
CompressStringGZIP(Writer.GetResult().data(), Writer.GetResult().size(), Compressed);
@@ -2465,10 +2480,22 @@ void cProtocol172::cPacketizer::WriteEntityMetadata(const cEntity & a_Entity)
}
case cEntity::etProjectile:
{
- if (((cProjectileEntity &)a_Entity).GetProjectileKind() == cProjectileEntity::pkArrow)
+ cProjectileEntity & Projectile = (cProjectileEntity &)a_Entity;
+ switch (Projectile.GetProjectileKind())
{
- WriteByte(0x10);
- WriteByte(((const cArrowEntity &)a_Entity).IsCritical() ? 1 : 0);
+ case cProjectileEntity::pkArrow:
+ {
+ WriteByte(0x10);
+ WriteByte(((const cArrowEntity &)a_Entity).IsCritical() ? 1 : 0);
+ break;
+ }
+ case cProjectileEntity::pkFirework:
+ {
+ WriteByte(0xA8);
+ WriteItem(((const cFireworkEntity &)a_Entity).GetItem());
+ break;
+ }
+ default: break;
}
break;
}
diff --git a/src/World.cpp b/src/World.cpp
index ffdae2a37..ffb463169 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -2904,9 +2904,9 @@ int cWorld::SpawnMobFinalize(cMonster * a_Monster)
-int cWorld::CreateProjectile(double a_PosX, double a_PosY, double a_PosZ, cProjectileEntity::eKind a_Kind, cEntity * a_Creator, const Vector3d * a_Speed)
+int cWorld::CreateProjectile(double a_PosX, double a_PosY, double a_PosZ, cProjectileEntity::eKind a_Kind, cEntity * a_Creator, const cItem a_Item, const Vector3d * a_Speed)
{
- cProjectileEntity * Projectile = cProjectileEntity::Create(a_Kind, a_Creator, a_PosX, a_PosY, a_PosZ, a_Speed);
+ cProjectileEntity * Projectile = cProjectileEntity::Create(a_Kind, a_Creator, a_PosX, a_PosY, a_PosZ, a_Item, a_Speed);
if (Projectile == NULL)
{
return -1;
diff --git a/src/World.h b/src/World.h
index 4b74f7aba..4fdbd8c0d 100644
--- a/src/World.h
+++ b/src/World.h
@@ -693,7 +693,7 @@ public:
int SpawnMobFinalize(cMonster* a_Monster);
/** Creates a projectile of the specified type. Returns the projectile's EntityID if successful, <0 otherwise */
- int CreateProjectile(double a_PosX, double a_PosY, double a_PosZ, cProjectileEntity::eKind a_Kind, cEntity * a_Creator, const Vector3d * a_Speed = NULL); // tolua_export
+ int CreateProjectile(double a_PosX, double a_PosY, double a_PosZ, cProjectileEntity::eKind a_Kind, cEntity * a_Creator, const cItem a_Item, const Vector3d * a_Speed = NULL); // tolua_export
/** Returns a random number from the m_TickRand in range [0 .. a_Range]. To be used only in the tick thread! */
int GetTickRandomNumber(unsigned a_Range) { return (int)(m_TickRand.randInt(a_Range)); }
diff --git a/src/WorldStorage/FastNBT.h b/src/WorldStorage/FastNBT.h
index a78b610cb..e7e56282f 100644
--- a/src/WorldStorage/FastNBT.h
+++ b/src/WorldStorage/FastNBT.h
@@ -266,7 +266,7 @@ protected:
eTagType m_ItemType; // for TAG_List, the element type
} ;
- static const int MAX_STACK = 50; // Highliy doubtful that an NBT would be constructed this many levels deep
+ static const int MAX_STACK = 50; // Highly doubtful that an NBT would be constructed this many levels deep
// These two fields emulate a stack. A raw array is used due to speed issues - no reallocations are allowed.
sParent m_Stack[MAX_STACK];
diff --git a/src/WorldStorage/FireworksSerializer.cpp b/src/WorldStorage/FireworksSerializer.cpp
new file mode 100644
index 000000000..eeb4e39ee
--- /dev/null
+++ b/src/WorldStorage/FireworksSerializer.cpp
@@ -0,0 +1,250 @@
+
+#include "Globals.h"
+#include "FireworksSerializer.h"
+#include "WorldStorage/FastNBT.h"
+#include
+
+
+
+
+
+void cFireworkItem::WriteToNBTCompound(const cFireworkItem & a_FireworkItem, cFastNBTWriter & a_Writer, const ENUM_ITEM_ID a_Type)
+{
+ switch (a_Type)
+ {
+ case E_ITEM_FIREWORK_ROCKET:
+ {
+ a_Writer.BeginCompound("Fireworks");
+ a_Writer.AddByte("Flight", a_FireworkItem.m_FlightTimeInTicks / 20);
+ a_Writer.BeginList("Explosions", TAG_Compound);
+ a_Writer.BeginCompound("");
+ a_Writer.AddByte("Flicker", a_FireworkItem.m_HasFlicker);
+ a_Writer.AddByte("Trail", a_FireworkItem.m_HasTrail);
+ a_Writer.AddByte("Type", a_FireworkItem.m_Type);
+ a_Writer.AddIntArray("Colors", a_FireworkItem.m_Colours.data(), a_FireworkItem.m_Colours.size());
+ a_Writer.AddIntArray("FadeColors", a_FireworkItem.m_FadeColours.data(), a_FireworkItem.m_FadeColours.size());
+ a_Writer.EndCompound();
+ a_Writer.EndList();
+ a_Writer.EndCompound();
+ break;
+ }
+ case E_ITEM_FIREWORK_STAR:
+ {
+ a_Writer.BeginCompound("Explosion");
+ a_Writer.AddByte("Flicker", a_FireworkItem.m_HasFlicker);
+ a_Writer.AddByte("Trail", a_FireworkItem.m_HasTrail);
+ a_Writer.AddByte("Type", a_FireworkItem.m_Type);
+ if (!a_FireworkItem.m_Colours.empty())
+ {
+ a_Writer.AddIntArray("Colors", a_FireworkItem.m_Colours.data(), a_FireworkItem.m_Colours.size());
+ }
+ if (!a_FireworkItem.m_FadeColours.empty())
+ {
+ a_Writer.AddIntArray("FadeColors", a_FireworkItem.m_FadeColours.data(), a_FireworkItem.m_FadeColours.size());
+ }
+ a_Writer.EndCompound();
+ break;
+ }
+ default: ASSERT(!"Unhandled firework item!"); break;
+ }
+}
+
+
+
+
+
+void cFireworkItem::ParseFromNBT(cFireworkItem & a_FireworkItem, const cParsedNBT & a_NBT, int a_TagIdx, const ENUM_ITEM_ID a_Type)
+{
+ if (a_TagIdx < 0)
+ {
+ return;
+ }
+
+ switch (a_Type)
+ {
+ case E_ITEM_FIREWORK_STAR:
+ {
+ for (int explosiontag = a_NBT.GetFirstChild(a_TagIdx); explosiontag >= 0; explosiontag = a_NBT.GetNextSibling(explosiontag))
+ {
+ eTagType TagType = a_NBT.GetType(explosiontag);
+ if (TagType == TAG_Byte) // Custon name tag
+ {
+ AString ExplosionName = a_NBT.GetName(explosiontag);
+
+ if (ExplosionName == "Flicker")
+ {
+ a_FireworkItem.m_HasFlicker = (a_NBT.GetByte(explosiontag) == 1);
+ }
+ else if (ExplosionName == "Trail")
+ {
+ a_FireworkItem.m_HasTrail = (a_NBT.GetByte(explosiontag) == 1);
+ }
+ else if (ExplosionName == "Type")
+ {
+ a_FireworkItem.m_Type = a_NBT.GetByte(explosiontag);
+ }
+ }
+ else if (TagType == TAG_IntArray)
+ {
+ AString ExplosionName = a_NBT.GetName(explosiontag);
+
+ if (ExplosionName == "Colors")
+ {
+ if (a_NBT.GetDataLength(explosiontag) == 0)
+ {
+ continue;
+ }
+
+ const int * ColourData = (const int *)(a_NBT.GetData(explosiontag));
+ for (int i = 0; i < ARRAYCOUNT(ColourData); i++)
+ {
+ a_FireworkItem.m_Colours.push_back(ntohl(ColourData[i]));
+ }
+ }
+ else if (ExplosionName == "FadeColors")
+ {
+ if (a_NBT.GetDataLength(explosiontag) == 0)
+ {
+ continue;
+ }
+
+ const int * FadeColourData = (const int *)(a_NBT.GetData(explosiontag));
+ for (int i = 0; i < ARRAYCOUNT(FadeColourData); i++)
+ {
+ a_FireworkItem.m_FadeColours.push_back(ntohl(FadeColourData[i]));
+ }
+ }
+ }
+ }
+ break;
+ }
+ case E_ITEM_FIREWORK_ROCKET:
+ {
+ for (int fireworkstag = a_NBT.GetFirstChild(a_TagIdx); fireworkstag >= 0; fireworkstag = a_NBT.GetNextSibling(fireworkstag))
+ {
+ eTagType TagType = a_NBT.GetType(fireworkstag);
+ if (TagType == TAG_Byte) // Custon name tag
+ {
+ if (a_NBT.GetName(fireworkstag) == "Flight")
+ {
+ a_FireworkItem.m_FlightTimeInTicks = a_NBT.GetByte(fireworkstag) * 20;
+ }
+ }
+ else if ((TagType == TAG_List) && (a_NBT.GetName(fireworkstag) == "Explosions"))
+ {
+ int ExplosionsChild = a_NBT.GetFirstChild(fireworkstag);
+ if ((a_NBT.GetType(ExplosionsChild) == TAG_Compound) && (a_NBT.GetName(ExplosionsChild).empty()))
+ {
+ ParseFromNBT(a_FireworkItem, a_NBT, ExplosionsChild, E_ITEM_FIREWORK_STAR);
+ }
+ }
+ }
+ break;
+ }
+ default: ASSERT(!"Unhandled firework item!"); break;
+ }
+}
+
+
+
+
+
+AString cFireworkItem::ColoursToString(const cFireworkItem & a_FireworkItem)
+{
+ AString Result;
+
+ for (std::vector::const_iterator itr = a_FireworkItem.m_Colours.begin(); itr != a_FireworkItem.m_Colours.end(); ++itr)
+ {
+ AppendPrintf(Result, "%i;", *itr);
+ }
+
+ return Result;
+}
+
+
+
+
+
+void cFireworkItem::ColoursFromString(const AString & a_String, cFireworkItem & a_FireworkItem)
+{
+ AStringVector Split = StringSplit(a_String, ";");
+
+ for (size_t itr = 0; itr < Split.size(); ++itr)
+ {
+ if (Split[itr].empty())
+ {
+ continue;
+ }
+
+ a_FireworkItem.m_Colours.push_back(atoi(Split[itr].c_str()));
+ }
+}
+
+
+
+
+
+AString cFireworkItem::FadeColoursToString(const cFireworkItem & a_FireworkItem)
+{
+ AString Result;
+
+ for (std::vector::const_iterator itr = a_FireworkItem.m_FadeColours.begin(); itr != a_FireworkItem.m_FadeColours.end(); ++itr)
+ {
+ AppendPrintf(Result, "%i;", *itr);
+ }
+
+ return Result;
+}
+
+
+
+
+
+void cFireworkItem::FadeColoursFromString(const AString & a_String, cFireworkItem & a_FireworkItem)
+{
+ AStringVector Split = StringSplit(a_String, ";");
+
+ for (size_t itr = 0; itr < Split.size(); ++itr)
+ {
+ if (Split[itr].empty())
+ {
+ continue;
+ }
+
+ a_FireworkItem.m_FadeColours.push_back(atoi(Split[itr].c_str()));
+ }
+}
+
+
+
+
+
+int GetVanillaColourCodeFromDye(short a_DyeMeta)
+{
+ /*
+ Colours are supposed to be calculated via: R << 16 + G << 8 + B
+ However, the RGB values fireworks use aren't the same as the ones for dyes (the ones listed in the MC Wiki)
+ Therefore, here is a list of numbers gotten via the Protocol Proxy
+ */
+
+ switch (a_DyeMeta)
+ {
+ case E_META_DYE_BLACK: return 1973019;
+ case E_META_DYE_RED: return 11743532;
+ case E_META_DYE_GREEN: return 3887386;
+ case E_META_DYE_BROWN: return 5320730;
+ case E_META_DYE_BLUE: return 2437522;
+ case E_META_DYE_PURPLE: return 8073150;
+ case E_META_DYE_CYAN: return 2651799;
+ case E_META_DYE_LIGHTGRAY: return 11250603;
+ case E_META_DYE_GRAY: return 4408131;
+ case E_META_DYE_PINK: return 14188952;
+ case E_META_DYE_LIGHTGREEN: return 4312372;
+ case E_META_DYE_YELLOW: return 14602026;
+ case E_META_DYE_LIGHTBLUE: return 6719955;
+ case E_META_DYE_MAGENTA: return 12801229;
+ case E_META_DYE_ORANGE: return 15435844;
+ case E_META_DYE_WHITE: return 15790320;
+ default: ASSERT(!"Unhandled dye meta whilst trying to get colour code for fireworks!"); break;
+ }
+}
diff --git a/src/WorldStorage/FireworksSerializer.h b/src/WorldStorage/FireworksSerializer.h
new file mode 100644
index 000000000..475d80bda
--- /dev/null
+++ b/src/WorldStorage/FireworksSerializer.h
@@ -0,0 +1,88 @@
+
+// FireworksSerializer.h
+
+// Declares the cFireworkItem class representing a firework or firework star
+
+
+
+
+
+#pragma once
+
+#include "Defines.h"
+
+class cFastNBTWriter;
+class cParsedNBT;
+
+
+
+
+
+class cFireworkItem
+{
+public:
+ cFireworkItem(void) :
+ m_HasFlicker(false),
+ m_HasTrail(false),
+ m_Type(0),
+ m_FlightTimeInTicks(0)
+ {
+ }
+
+ inline void CopyFrom(const cFireworkItem & a_Item)
+ {
+ m_FlightTimeInTicks = a_Item.m_FlightTimeInTicks;
+ m_HasFlicker = a_Item.m_HasFlicker;
+ m_HasTrail = a_Item.m_HasTrail;
+ m_Type = a_Item.m_Type;
+ m_Colours = a_Item.m_Colours;
+ m_FadeColours = a_Item.m_FadeColours;
+ }
+
+ inline void EmptyData(void)
+ {
+ m_FlightTimeInTicks = 0;
+ m_HasFlicker = false;
+ m_Type = 0;
+ m_HasTrail = false;
+ m_Colours.clear();
+ m_FadeColours.clear();
+ }
+
+ inline bool IsEqualTo(const cFireworkItem & a_Item) const
+ {
+ return
+ (
+ (m_FlightTimeInTicks == a_Item.m_FlightTimeInTicks) &&
+ (m_HasFlicker == a_Item.m_HasFlicker) &&
+ (m_HasTrail == a_Item.m_HasTrail) &&
+ (m_Type == a_Item.m_Type) &&
+ (m_Colours == a_Item.m_Colours) &&
+ (m_FadeColours == a_Item.m_FadeColours)
+ );
+ }
+
+ /** Writes firework NBT data to a Writer object */
+ static void WriteToNBTCompound(const cFireworkItem & a_FireworkItem, cFastNBTWriter & a_Writer, const ENUM_ITEM_ID 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);
+
+ /** Converts the firework's vector of colours into a string of values separated by a semicolon */
+ static AString ColoursToString(const cFireworkItem & a_FireworkItem);
+ /** Parses a string containing encoded firework colours and populates a FireworkItem with it */
+ static void ColoursFromString(const AString & a_String, cFireworkItem & a_FireworkItem);
+ /** Converts the firework's vector of fade colours into a string of values separated by a semicolon */
+ static AString FadeColoursToString(const cFireworkItem & a_FireworkItem);
+ /** Parses a string containing encoded firework fade colours and populates a FireworkItem with it */
+ static void FadeColoursFromString(const AString & a_String, cFireworkItem & a_FireworkItem);
+
+ /** Returns a colour code for fireworks used by the network code */
+ static const inline int GetVanillaColourCodeFromDye(short a_DyeMeta);
+
+ bool m_HasFlicker;
+ bool m_HasTrail;
+ NIBBLETYPE m_Type;
+ short m_FlightTimeInTicks;
+ std::vector m_Colours;
+ std::vector m_FadeColours;
+};
\ No newline at end of file
diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp
index c1c659b36..6d82cba86 100644
--- a/src/WorldStorage/NBTChunkSerializer.cpp
+++ b/src/WorldStorage/NBTChunkSerializer.cpp
@@ -90,11 +90,19 @@ void cNBTChunkSerializer::AddItem(const cItem & a_Item, int a_Slot, const AStrin
}
// Write the enchantments:
- if (!a_Item.m_Enchantments.IsEmpty())
+ if (!a_Item.m_Enchantments.IsEmpty() || ((a_Item.m_ItemType == E_ITEM_FIREWORK_ROCKET) || (a_Item.m_ItemType == E_ITEM_FIREWORK_STAR)))
{
- const char * TagName = (a_Item.m_ItemType == E_ITEM_BOOK) ? "StoredEnchantments" : "ench";
m_Writer.BeginCompound("tag");
- EnchantmentSerializer::WriteToNBTCompound(a_Item.m_Enchantments, m_Writer, TagName);
+ if ((a_Item.m_ItemType == E_ITEM_FIREWORK_ROCKET) || (a_Item.m_ItemType == E_ITEM_FIREWORK_STAR))
+ {
+ cFireworkItem::WriteToNBTCompound(a_Item.m_FireworkItem, m_Writer, (ENUM_ITEM_ID)a_Item.m_ItemType);
+ }
+
+ if (!a_Item.m_Enchantments.IsEmpty())
+ {
+ const char * TagName = (a_Item.m_ItemType == E_ITEM_BOOK) ? "StoredEnchantments" : "ench";
+ EnchantmentSerializer::WriteToNBTCompound(a_Item.m_Enchantments, m_Writer, TagName);
+ }
m_Writer.EndCompound();
}
diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp
index 05332d23d..0658d5029 100644
--- a/src/WorldStorage/WSSAnvil.cpp
+++ b/src/WorldStorage/WSSAnvil.cpp
@@ -658,6 +658,12 @@ bool cWSSAnvil::LoadItemFromNBT(cItem & a_Item, const cParsedNBT & a_NBT, int a_
{
EnchantmentSerializer::ParseFromNBT(a_Item.m_Enchantments, a_NBT, EnchTag);
}
+
+ int FireworksTag = a_NBT.FindChildByName(TagTag, ((a_Item.m_ItemType == E_ITEM_FIREWORK_STAR) ? "Fireworks" : "Explosion"));
+ if (EnchTag > 0)
+ {
+ cFireworkItem::ParseFromNBT(a_Item.m_FireworkItem, a_NBT, FireworksTag, (ENUM_ITEM_ID)a_Item.m_ItemType);
+ }
return true;
}
--
cgit v1.2.3
From a97f28939fb706cbe26bc0de400c7bf2f14f19f4 Mon Sep 17 00:00:00 2001
From: Tiger Wang
Date: Wed, 26 Feb 2014 23:30:10 +0000
Subject: Fixed sheep ASSERTing sometimes
---
src/Mobs/Sheep.cpp | 26 ++++++++++++++++++--------
1 file changed, 18 insertions(+), 8 deletions(-)
diff --git a/src/Mobs/Sheep.cpp b/src/Mobs/Sheep.cpp
index 4761103e5..c64360153 100644
--- a/src/Mobs/Sheep.cpp
+++ b/src/Mobs/Sheep.cpp
@@ -68,17 +68,28 @@ void cSheep::OnRightClicked(cPlayer & a_Player)
void cSheep::Tick(float a_Dt, cChunk & a_Chunk)
{
- // The sheep should not move when he's eating so only handle the physics.
+ super::Tick(a_Dt, a_Chunk);
+ int PosX = POSX_TOINT;
+ int PosY = POSY_TOINT - 1;
+ int PosZ = POSZ_TOINT;
+
+ if ((PosY <= 0) || (PosY > cChunkDef::Height))
+ {
+ return;
+ }
+
if (m_TimeToStopEating > 0)
{
- HandlePhysics(a_Dt, a_Chunk);
+ m_bMovingToDestination = false; // The sheep should not move when he's eating
m_TimeToStopEating--;
+
if (m_TimeToStopEating == 0)
{
- if (m_World->GetBlock((int) GetPosX(), (int) GetPosY() - 1, (int) GetPosZ()) == E_BLOCK_GRASS)
+ if (m_World->GetBlock(PosX, PosY, PosZ) == E_BLOCK_GRASS) // Make sure grass hasn't been destroyed in the meantime
{
- // The sheep ate the grass so we change it to dirt.
- m_World->SetBlock((int) GetPosX(), (int) GetPosY() - 1, (int) GetPosZ(), E_BLOCK_DIRT, 0);
+ // The sheep ate the grass so we change it to dirt
+ m_World->SetBlock(PosX, PosY, PosZ, E_BLOCK_DIRT, 0);
+ GetWorld()->BroadcastSoundParticleEffect(2001, PosX, PosY, PosX, E_BLOCK_GRASS);
m_IsSheared = false;
m_World->BroadcastEntityMetadata(*this);
}
@@ -86,12 +97,11 @@ void cSheep::Tick(float a_Dt, cChunk & a_Chunk)
}
else
{
- super::Tick(a_Dt, a_Chunk);
if (m_World->GetTickRandomNumber(600) == 1)
{
- if (m_World->GetBlock((int) GetPosX(), (int) GetPosY() - 1, (int) GetPosZ()) == E_BLOCK_GRASS)
+ if (m_World->GetBlock(PosX, PosY, PosZ) == E_BLOCK_GRASS)
{
- m_World->BroadcastEntityStatus(*this, 10);
+ m_World->BroadcastEntityStatus(*this, ENTITY_STATUS_SHEEP_EATING);
m_TimeToStopEating = 40;
}
}
--
cgit v1.2.3
From 84913299f45a28d3bd6146b3decbf14764449030 Mon Sep 17 00:00:00 2001
From: Tycho
Date: Thu, 27 Feb 2014 11:33:35 -0800
Subject: Added some Metadate rotaters using templated Mixin
---
src/Blocks/BlockBed.h | 5 +--
src/Blocks/BlockButton.h | 4 +--
src/Blocks/BlockChest.h | 4 +--
src/Blocks/BlockComparator.h | 4 +--
src/Blocks/BlockDoor.cpp | 2 +-
src/Blocks/BlockDoor.h | 57 +++++++++++++++++++++++++++++-
src/Blocks/BlockDropSpenser.h | 18 ++++++++--
src/Blocks/BlockEnderchest.h | 4 +--
src/Blocks/BlockFenceGate.h | 4 +--
src/Blocks/MetaRotater.h | 82 +++++++++++++++++++++++++++++++++++++++++++
10 files changed, 168 insertions(+), 16 deletions(-)
create mode 100644 src/Blocks/MetaRotater.h
diff --git a/src/Blocks/BlockBed.h b/src/Blocks/BlockBed.h
index caec2b56f..6e8884114 100644
--- a/src/Blocks/BlockBed.h
+++ b/src/Blocks/BlockBed.h
@@ -4,6 +4,7 @@
#include "BlockHandler.h"
#include "ChunkInterface.h"
#include "WorldInterface.h"
+#include "MetaRotater.h"
#include "../Entities/Player.h"
@@ -11,11 +12,11 @@
class cBlockBedHandler :
- public cBlockHandler
+ public cMetaRotater
{
public:
cBlockBedHandler(BLOCKTYPE a_BlockType)
- : cBlockHandler(a_BlockType)
+ : cMetaRotater(a_BlockType)
{
}
diff --git a/src/Blocks/BlockButton.h b/src/Blocks/BlockButton.h
index ca6850ced..5a4bf7c96 100644
--- a/src/Blocks/BlockButton.h
+++ b/src/Blocks/BlockButton.h
@@ -7,11 +7,11 @@
class cBlockButtonHandler :
- public cBlockHandler
+ public cMetaRotater
{
public:
cBlockButtonHandler(BLOCKTYPE a_BlockType)
- : cBlockHandler(a_BlockType)
+ : cMetaRotater(a_BlockType)
{
}
diff --git a/src/Blocks/BlockChest.h b/src/Blocks/BlockChest.h
index 02ecc4346..4ab23bced 100644
--- a/src/Blocks/BlockChest.h
+++ b/src/Blocks/BlockChest.h
@@ -10,11 +10,11 @@
class cBlockChestHandler :
- public cBlockEntityHandler
+ public cMetaRotater
{
public:
cBlockChestHandler(BLOCKTYPE a_BlockType)
- : cBlockEntityHandler(a_BlockType)
+ : cMetaRotater(a_BlockType)
{
}
diff --git a/src/Blocks/BlockComparator.h b/src/Blocks/BlockComparator.h
index aba390d9d..7e672eece 100644
--- a/src/Blocks/BlockComparator.h
+++ b/src/Blocks/BlockComparator.h
@@ -9,11 +9,11 @@
class cBlockComparatorHandler :
- public cBlockHandler
+ public cMetaRotater
{
public:
cBlockComparatorHandler(BLOCKTYPE a_BlockType)
- : cBlockHandler(a_BlockType)
+ : cMetaRotater(a_BlockType)
{
}
diff --git a/src/Blocks/BlockDoor.cpp b/src/Blocks/BlockDoor.cpp
index 2ff5c1c37..f0d0b4b7f 100644
--- a/src/Blocks/BlockDoor.cpp
+++ b/src/Blocks/BlockDoor.cpp
@@ -9,7 +9,7 @@
cBlockDoorHandler::cBlockDoorHandler(BLOCKTYPE a_BlockType)
- : cBlockHandler(a_BlockType)
+ : super(a_BlockType)
{
}
diff --git a/src/Blocks/BlockDoor.h b/src/Blocks/BlockDoor.h
index ef0dbb787..c3647b203 100644
--- a/src/Blocks/BlockDoor.h
+++ b/src/Blocks/BlockDoor.h
@@ -9,8 +9,9 @@
class cBlockDoorHandler :
- public cBlockHandler
+ public cMetaRotater
{
+ typedef super cMetaRotater;
public:
cBlockDoorHandler(BLOCKTYPE a_BlockType);
@@ -167,6 +168,60 @@ public:
}
+ virtual NIBBLETYPE MetaRotateCCW(NIBBLETYPE a_Meta) override
+ {
+ if (a_Meta & 0x08)
+ {
+ return a_Meta;
+ }
+ else
+ {
+ return super::MetaRotateCCW(a_Meta);
+ }
+ }
+
+
+
+ virtual NIBBLETYPE MetaRotateCW(NIBBLETYPE a_Meta) override
+ {
+ if (a_Meta & 0x08)
+ {
+ return a_Meta;
+ }
+ else
+ {
+ return super::MetaRotateCW(a_Meta);
+ }
+ }
+
+
+
+ virtual NIBBLETYPE MetaMirrorXY(NIBBLETYPE a_Meta) override
+ {
+ if (a_Meta & 0x08)
+ {
+ return a_Meta;
+ }
+ else
+ {
+ return super::MetaMirrorXY(a_Meta);
+ }
+ }
+
+
+
+ virtual NIBBLETYPE MetaMirrorYZ(NIBBLETYPE a_Meta) override
+ {
+ if (a_Meta & 0x08)
+ {
+ return a_Meta;
+ }
+ else
+ {
+ return super::MetaMirrorYZ(a_Meta);
+ }
+ }
+
} ;
diff --git a/src/Blocks/BlockDropSpenser.h b/src/Blocks/BlockDropSpenser.h
index 30d347ec9..2253fcd1b 100644
--- a/src/Blocks/BlockDropSpenser.h
+++ b/src/Blocks/BlockDropSpenser.h
@@ -12,11 +12,11 @@
class cBlockDropSpenserHandler :
- public cBlockEntityHandler
+ public cMetaRotater
{
public:
cBlockDropSpenserHandler(BLOCKTYPE a_BlockType) :
- cBlockEntityHandler(a_BlockType)
+ cMetaRotater(a_BlockType)
{
}
@@ -34,6 +34,20 @@ public:
a_BlockMeta = cPiston::RotationPitchToMetaData(a_Player->GetYaw(), a_Player->GetPitch());
return true;
}
+
+ virtual NIBBLETYPE MetaMirrorXZ(NIBBLETYPE a_Meta) override
+ {
+ // Bit 0x08 is a flag. Lowest three bits are position. 0x08 == 1000
+ NIBBLETYPE OtherMeta = a_Meta & 0x08;
+ // Mirrors defined by by a table. (Source, mincraft.gamepedia.com) 0x07 == 0111
+ switch (a_Meta & 0x07)
+ {
+ case 0x00: return 0x01 + OtherMeta; // Down -> Up
+ case 0x01: return 0x00 + OtherMeta; // Up -> Down
+ }
+ // Not Facing Up or Down; No change.
+ return a_Meta;
+ }
} ;
diff --git a/src/Blocks/BlockEnderchest.h b/src/Blocks/BlockEnderchest.h
index b4b0b995d..ed3f37013 100644
--- a/src/Blocks/BlockEnderchest.h
+++ b/src/Blocks/BlockEnderchest.h
@@ -8,11 +8,11 @@
class cBlockEnderchestHandler :
- public cBlockEntityHandler
+ public cMetaRotater
{
public:
cBlockEnderchestHandler(BLOCKTYPE a_BlockType)
- : cBlockEntityHandler(a_BlockType)
+ : cMetaRotater(a_BlockType)
{
}
diff --git a/src/Blocks/BlockFenceGate.h b/src/Blocks/BlockFenceGate.h
index fb984f345..035579e8e 100644
--- a/src/Blocks/BlockFenceGate.h
+++ b/src/Blocks/BlockFenceGate.h
@@ -8,11 +8,11 @@
class cBlockFenceGateHandler :
- public cBlockHandler
+ public cMetaRotater
{
public:
cBlockFenceGateHandler(BLOCKTYPE a_BlockType) :
- cBlockHandler(a_BlockType)
+ cMetaRotater(a_BlockType)
{
}
diff --git a/src/Blocks/MetaRotater.h b/src/Blocks/MetaRotater.h
new file mode 100644
index 000000000..f1656f1bd
--- /dev/null
+++ b/src/Blocks/MetaRotater.h
@@ -0,0 +1,82 @@
+
+#pragma once
+
+template
+class cMetaRotater : public Base
+{
+public:
+
+ cMetaRotater(BLOCKTYPE a_BlockType) :
+ Base(a_BlockType)
+ {}
+
+ virtual ~cMetaRotater() {}
+
+ virtual NIBBLETYPE MetaRotateCCW(NIBBLETYPE a_Meta) override;
+ virtual NIBBLETYPE MetaRotateCW(NIBBLETYPE a_Meta) override;
+ virtual NIBBLETYPE MetaMirrorXY(NIBBLETYPE a_Meta) override;
+ virtual NIBBLETYPE MetaMirrorYZ(NIBBLETYPE a_Meta) override;
+};
+
+
+template
+NIBBLETYPE cMetaRotater::MetaRotateCW(NIBBLETYPE a_Meta)
+{
+NIBBLETYPE OtherMeta = a_Meta & (~BitFilter);
+switch (a_Meta & BitFilter)
+{
+case South: return West | OtherMeta;
+case West: return North | OtherMeta;
+case North: return East | OtherMeta;
+case East: return South | OtherMeta;
+}
+ASSERT(!"Invalid Meta value");
+return a_Meta;
+}
+
+
+template
+NIBBLETYPE cMetaRotater::MetaRotateCCW(NIBBLETYPE a_Meta)
+{
+NIBBLETYPE OtherMeta = a_Meta & (~BitFilter);
+switch (a_Meta & BitFilter)
+{
+case South: return East | OtherMeta;
+case East: return North | OtherMeta;
+case North: return West | OtherMeta;
+case West: return South | OtherMeta;
+}
+ASSERT(!"Invalid Meta value");
+return a_Meta;
+}
+
+
+
+template
+NIBBLETYPE cMetaRotater::MetaMirrorXY(NIBBLETYPE a_Meta)
+{
+NIBBLETYPE OtherMeta = a_Meta & (~BitFilter);
+switch (a_Meta & BitFilter)
+{
+case South: return North | OtherMeta;
+case North: return South | OtherMeta;
+}
+// Not Facing North or South; No change.
+return a_Meta;
+}
+
+
+
+
+template
+NIBBLETYPE cMetaRotater::MetaMirrorYZ(NIBBLETYPE a_Meta)
+{
+NIBBLETYPE OtherMeta = a_Meta & (~BitFilter);
+switch (a_Meta & BitFilter)
+{
+case West: return East | OtherMeta;
+case East: return West | OtherMeta;
+}
+// Not Facing East or West; No change.
+return a_Meta;
+}
--
cgit v1.2.3
From 528467bc5c514d8ef193c4e9dd06fb5aeb9f0dd9 Mon Sep 17 00:00:00 2001
From: Tiger Wang
Date: Thu, 27 Feb 2014 21:48:49 +0000
Subject: Fixed compile
---
src/WorldStorage/FireworksSerializer.cpp | 3 +--
src/WorldStorage/FireworksSerializer.h | 2 +-
2 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/src/WorldStorage/FireworksSerializer.cpp b/src/WorldStorage/FireworksSerializer.cpp
index eeb4e39ee..7f5077912 100644
--- a/src/WorldStorage/FireworksSerializer.cpp
+++ b/src/WorldStorage/FireworksSerializer.cpp
@@ -2,7 +2,6 @@
#include "Globals.h"
#include "FireworksSerializer.h"
#include "WorldStorage/FastNBT.h"
-#include
@@ -219,7 +218,7 @@ void cFireworkItem::FadeColoursFromString(const AString & a_String, cFireworkIte
-int GetVanillaColourCodeFromDye(short a_DyeMeta)
+int cFireworkItem::GetVanillaColourCodeFromDye(short a_DyeMeta)
{
/*
Colours are supposed to be calculated via: R << 16 + G << 8 + B
diff --git a/src/WorldStorage/FireworksSerializer.h b/src/WorldStorage/FireworksSerializer.h
index 475d80bda..37fb6c883 100644
--- a/src/WorldStorage/FireworksSerializer.h
+++ b/src/WorldStorage/FireworksSerializer.h
@@ -77,7 +77,7 @@ public:
static void FadeColoursFromString(const AString & a_String, cFireworkItem & a_FireworkItem);
/** Returns a colour code for fireworks used by the network code */
- static const inline int GetVanillaColourCodeFromDye(short a_DyeMeta);
+ static int GetVanillaColourCodeFromDye(short a_DyeMeta);
bool m_HasFlicker;
bool m_HasTrail;
--
cgit v1.2.3
From 9ac9249acaf21d01af41b4cdfc862961b1f9e286 Mon Sep 17 00:00:00 2001
From: Tiger Wang
Date: Thu, 27 Feb 2014 21:49:10 +0000
Subject: Removed unneeded includes in Player.cpp
---
src/Entities/Player.cpp | 7 -------
1 file changed, 7 deletions(-)
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index 0152bfc5b..f4039e548 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -10,18 +10,11 @@
#include "../BlockEntities/BlockEntity.h"
#include "../GroupManager.h"
#include "../Group.h"
-#include "../ChatColor.h"
-#include "../Item.h"
-#include "../Tracer.h"
#include "../Root.h"
#include "../OSSupport/Timer.h"
-#include "../MersenneTwister.h"
#include "../Chunk.h"
#include "../Items/ItemHandler.h"
-#include "../Vector3d.h"
-#include "../Vector3f.h"
-
#include "inifile/iniFile.h"
#include "json/json.h"
--
cgit v1.2.3
From 35def963f06dd46823300aebf09af0009189328b Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Fri, 28 Feb 2014 15:31:20 +0100
Subject: Moved common cGroupManager code to a separate function.
This fixes my concerns in PR #709.
---
src/Entities/Player.cpp | 18 +++++++++++-------
src/GroupManager.cpp | 21 ++++++++++++++++-----
src/GroupManager.h | 3 +++
3 files changed, 30 insertions(+), 12 deletions(-)
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index e0f0b9222..f419ee09c 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -1529,14 +1529,14 @@ void cPlayer::LoadPermissionsFromDisk()
std::string Groups = IniFile.GetValue(m_PlayerName, "Groups", "");
if (!Groups.empty())
{
- AStringVector Split = StringSplit( Groups, "," );
- for( unsigned int i = 0; i < Split.size(); i++ )
+ AStringVector Split = StringSplitAndTrim(Groups, ",");
+ for (AStringVector::const_iterator itr = Split.begin(), end = Split.end(); itr != end; ++itr)
{
- if (!cRoot::Get()->GetGroupManager()->ExistsGroup(Split[i]))
+ if (!cRoot::Get()->GetGroupManager()->ExistsGroup(*itr))
{
- LOGWARNING("The group %s for player %s was not found!", Split[i].c_str(), m_PlayerName.c_str());
+ LOGWARNING("The group %s for player %s was not found!", itr->c_str(), m_PlayerName.c_str());
}
- AddToGroup(Split[i].c_str());
+ AddToGroup(*itr);
}
}
else
@@ -1544,11 +1544,15 @@ void cPlayer::LoadPermissionsFromDisk()
AddToGroup("Default");
}
- m_Color = IniFile.GetValue(m_PlayerName, "Color", "-")[0];
+ AString Color = IniFile.GetValue(m_PlayerName, "Color", "-");
+ if (!Color.empty())
+ {
+ m_Color = Color[0];
+ }
}
else
{
- cRoot::Get()->GetGroupManager()->CheckUsers();
+ cGroupManager::GenerateDefaultUsersIni(IniFile);
AddToGroup("Default");
}
ResolvePermissions();
diff --git a/src/GroupManager.cpp b/src/GroupManager.cpp
index 5125e7586..33b601e82 100644
--- a/src/GroupManager.cpp
+++ b/src/GroupManager.cpp
@@ -55,16 +55,27 @@ cGroupManager::cGroupManager()
+void cGroupManager::GenerateDefaultUsersIni(cIniFile & a_IniFile)
+{
+ LOGWARN("Regenerating users.ini, all users will be reset");
+ a_IniFile.AddHeaderComment(" This file stores the players' groups.");
+ a_IniFile.AddHeaderComment(" The format is:");
+ a_IniFile.AddHeaderComment(" [PlayerName]");
+ a_IniFile.AddHeaderComment(" Groups = GroupName1, GroupName2, ...");
+
+ a_IniFile.WriteFile("users.ini");
+}
+
+
+
+
+
void cGroupManager::CheckUsers(void)
{
cIniFile IniFile;
if (!IniFile.ReadFile("users.ini"))
{
- LOGWARN("Regenerating users.ini, all users will be reset");
- IniFile.AddHeaderComment(" This is the file in which the group the player belongs to is stored");
- IniFile.AddHeaderComment(" The format is: [PlayerName] | Groups=GroupName");
-
- IniFile.WriteFile("users.ini");
+ GenerateDefaultUsersIni(IniFile);
return;
}
diff --git a/src/GroupManager.h b/src/GroupManager.h
index 377a54c98..9e1689a76 100644
--- a/src/GroupManager.h
+++ b/src/GroupManager.h
@@ -19,6 +19,9 @@ public:
void LoadGroups(void);
void CheckUsers(void);
+ /** Writes the default header to the specified ini file, and saves it as "users.ini". */
+ static void GenerateDefaultUsersIni(cIniFile & a_IniFile);
+
private:
friend class cRoot;
cGroupManager();
--
cgit v1.2.3
From d97363a1b39fd94a77bb84a4d9732ab4f46b08b7 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Fri, 28 Feb 2014 15:41:46 +0100
Subject: Documented the changes in cJukeboxEntity.
---
MCServer/Plugins/APIDump/Classes/BlockEntities.lua | 6 ++++--
src/BlockEntities/JukeboxEntity.h | 5 +++--
2 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/MCServer/Plugins/APIDump/Classes/BlockEntities.lua b/MCServer/Plugins/APIDump/Classes/BlockEntities.lua
index cf258160c..61a8e8d22 100644
--- a/MCServer/Plugins/APIDump/Classes/BlockEntities.lua
+++ b/MCServer/Plugins/APIDump/Classes/BlockEntities.lua
@@ -196,9 +196,11 @@ World:ForEachChestInChunk(Player:GetChunkX(), Player:GetChunkZ(),
Inherits = "cBlockEntity",
Functions =
{
- EjectRecord = { Params = "", Return = "", Notes = "Ejects the current record as a {{cPickup|pickup}}. No action if there's no current record. To remove record without generating the pickup, use SetRecord(0)" },
+ EjectRecord = { Params = "", Return = "bool", Notes = "Ejects the current record as a {{cPickup|pickup}}. No action if there's no current record. To remove record without generating the pickup, use SetRecord(0). Returns true if pickup ejected." },
GetRecord = { Params = "", Return = "number", Notes = "Returns the record currently present. Zero for no record, E_ITEM_*_DISC for records." },
- PlayRecord = { Params = "", Return = "", Notes = "Plays the currently present record. No action if there's no current record." },
+ IsPlayingRecord = { Params = "", Return = "bool", Notes = "Returns true if the jukebox is playing a record." },
+ IsRecordItem = { Params = "ItemType", Return = "bool", Notes = "Returns true if the specified item is a record that can be played." },
+ PlayRecord = { Params = "RecordItemType", Return = "bool", Notes = "Plays the specified Record. Return false if the parameter isn't a playable Record (E_ITEM_XXX_DISC). If there is a record already playing, ejects it first." },
SetRecord = { Params = "number", Return = "", Notes = "Sets the currently present record. Use zero for no record, or E_ITEM_*_DISC for records." },
},
}, -- cJukeboxEntity
diff --git a/src/BlockEntities/JukeboxEntity.h b/src/BlockEntities/JukeboxEntity.h
index 01ce52494..3d1d604f7 100644
--- a/src/BlockEntities/JukeboxEntity.h
+++ b/src/BlockEntities/JukeboxEntity.h
@@ -38,10 +38,11 @@ public:
int GetRecord(void);
void SetRecord(int a_Record);
- /** Play a Record. Return false, when a_Record isn't a Record */
+ /** Plays the specified Record. Return false if a_Record isn't a playable Record (E_ITEM_XXX_DISC).
+ If there is a record already playing, ejects it first. */
bool PlayRecord(int a_Record);
- /** Ejects the currently held record as a pickup. Return false when no record inserted. */
+ /** Ejects the currently held record as a pickup. Return false when no record had been inserted. */
bool EjectRecord(void);
/** Is in the Jukebox a Record? */
--
cgit v1.2.3
From 182646188448f9fd8df0b4c0391a2db04575c49d Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Fri, 28 Feb 2014 16:26:23 +0100
Subject: Fixed multiple gcc warnings about unused params.
---
src/Entities/Painting.cpp | 11 +++++++++++
src/Entities/Painting.h | 2 +-
src/HTTPServer/HTTPServer.cpp | 4 ++++
src/Items/ItemHandler.cpp | 26 +++++++++++++++++++++++++-
src/OSSupport/BlockingTCPLink.cpp | 4 ++++
src/UI/SlotArea.cpp | 30 ++++++++++++++++++++++++++++++
src/UI/SlotArea.h | 6 +++---
7 files changed, 78 insertions(+), 5 deletions(-)
diff --git a/src/Entities/Painting.cpp b/src/Entities/Painting.cpp
index b98c1e67a..e217556c7 100644
--- a/src/Entities/Painting.cpp
+++ b/src/Entities/Painting.cpp
@@ -4,6 +4,7 @@
#include "Painting.h"
#include "ClientHandle.h"
#include "Player.h"
+#include "../Chunk.h"
@@ -30,6 +31,16 @@ void cPainting::SpawnOn(cClientHandle & a_Client)
+void cPainting::Tick(float a_Dt, cChunk & a_Chunk)
+{
+ UNUSED(a_Dt);
+ UNUSED(a_Chunk);
+}
+
+
+
+
+
void cPainting::GetDrops(cItems & a_Items, cEntity * a_Killer)
{
if ((a_Killer != NULL) && a_Killer->IsPlayer() && !((cPlayer *)a_Killer)->IsGameModeCreative())
diff --git a/src/Entities/Painting.h b/src/Entities/Painting.h
index 95afbed1e..c1024bd1b 100644
--- a/src/Entities/Painting.h
+++ b/src/Entities/Painting.h
@@ -24,7 +24,7 @@ public:
private:
virtual void SpawnOn(cClientHandle & a_Client) override;
- virtual void Tick(float a_Dt, cChunk & a_Chunk) override {};
+ virtual void Tick(float a_Dt, cChunk & a_Chunk) override;
virtual void GetDrops(cItems & a_Items, cEntity * a_Killer) override;
virtual void KilledBy(cEntity * a_Killer) override
{
diff --git a/src/HTTPServer/HTTPServer.cpp b/src/HTTPServer/HTTPServer.cpp
index f6f5b0f8b..4e9195a00 100644
--- a/src/HTTPServer/HTTPServer.cpp
+++ b/src/HTTPServer/HTTPServer.cpp
@@ -29,6 +29,8 @@ class cDebugCallbacks :
{
virtual void OnRequestBegun(cHTTPConnection & a_Connection, cHTTPRequest & a_Request) override
{
+ UNUSED(a_Connection);
+
if (cHTTPFormParser::HasFormData(a_Request))
{
a_Request.SetUserData(new cHTTPFormParser(a_Request, *this));
@@ -38,6 +40,8 @@ class cDebugCallbacks :
virtual void OnRequestBody(cHTTPConnection & a_Connection, cHTTPRequest & a_Request, const char * a_Data, int a_Size) override
{
+ UNUSED(a_Connection);
+
cHTTPFormParser * FormParser = (cHTTPFormParser *)(a_Request.GetUserData());
if (FormParser != NULL)
{
diff --git a/src/Items/ItemHandler.cpp b/src/Items/ItemHandler.cpp
index c10d13edc..507f7fa86 100644
--- a/src/Items/ItemHandler.cpp
+++ b/src/Items/ItemHandler.cpp
@@ -248,6 +248,14 @@ cItemHandler::cItemHandler(int a_ItemType)
bool cItemHandler::OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Dir)
{
+ UNUSED(a_World);
+ UNUSED(a_Player);
+ UNUSED(a_Item);
+ UNUSED(a_BlockX);
+ UNUSED(a_BlockY);
+ UNUSED(a_BlockZ);
+ UNUSED(a_Dir);
+
return false;
}
@@ -257,6 +265,14 @@ bool cItemHandler::OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem &
bool cItemHandler::OnDiggingBlock(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Dir)
{
+ UNUSED(a_World);
+ UNUSED(a_Player);
+ UNUSED(a_Item);
+ UNUSED(a_BlockX);
+ UNUSED(a_BlockY);
+ UNUSED(a_BlockZ);
+ UNUSED(a_Dir);
+
return false;
}
@@ -266,6 +282,8 @@ bool cItemHandler::OnDiggingBlock(cWorld * a_World, cPlayer * a_Player, const cI
void cItemHandler::OnBlockDestroyed(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ)
{
+ UNUSED(a_Item);
+
BLOCKTYPE Block = a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ);
cBlockHandler * Handler = cBlockHandler::GetBlockHandler(Block);
@@ -288,7 +306,9 @@ void cItemHandler::OnBlockDestroyed(cWorld * a_World, cPlayer * a_Player, const
void cItemHandler::OnFoodEaten(cWorld * a_World, cPlayer * a_Player, cItem * a_Item)
{
-
+ UNUSED(a_World);
+ UNUSED(a_Player);
+ UNUSED(a_Item);
}
@@ -461,6 +481,8 @@ bool cItemHandler::IsPlaceable(void)
bool cItemHandler::CanHarvestBlock(BLOCKTYPE a_BlockType)
{
+ UNUSED(a_BlockType);
+
return false;
}
@@ -499,6 +521,8 @@ bool cItemHandler::GetPlacementBlockTypeMeta(
bool cItemHandler::EatItem(cPlayer * a_Player, cItem * a_Item)
{
+ UNUSED(a_Item);
+
FoodInfo Info = GetFoodInfo();
if ((Info.FoodLevel > 0) || (Info.Saturation > 0.f))
diff --git a/src/OSSupport/BlockingTCPLink.cpp b/src/OSSupport/BlockingTCPLink.cpp
index af50eda5d..e9c00d6d4 100644
--- a/src/OSSupport/BlockingTCPLink.cpp
+++ b/src/OSSupport/BlockingTCPLink.cpp
@@ -89,6 +89,8 @@ bool cBlockingTCPLink::Connect(const char * iAddress, unsigned int iPort)
int cBlockingTCPLink::Send(char * a_Data, unsigned int a_Size, int a_Flags /* = 0 */ )
{
+ UNUSED(a_Flags);
+
ASSERT(m_Socket.IsValid());
if (!m_Socket.IsValid())
{
@@ -104,6 +106,8 @@ int cBlockingTCPLink::Send(char * a_Data, unsigned int a_Size, int a_Flags /* =
int cBlockingTCPLink::SendMessage( const char* a_Message, int a_Flags /* = 0 */ )
{
+ UNUSED(a_Flags);
+
ASSERT(m_Socket.IsValid());
if (!m_Socket.IsValid())
{
diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp
index bfcad3d92..88977e005 100644
--- a/src/UI/SlotArea.cpp
+++ b/src/UI/SlotArea.cpp
@@ -224,6 +224,24 @@ void cSlotArea::DblClicked(cPlayer & a_Player, int a_SlotNum)
+void cSlotArea::OnPlayerAdded(cPlayer & a_Player)
+{
+ UNUSED(a_Player);
+}
+
+
+
+
+
+void cSlotArea::OnPlayerRemoved(cPlayer & a_Player)
+{
+ UNUSED(a_Player);
+}
+
+
+
+
+
void cSlotArea::DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_Apply, bool a_KeepEmptySlots)
{
for (int i = 0; i < m_NumSlots; i++)
@@ -447,6 +465,18 @@ void cSlotAreaCrafting::OnPlayerRemoved(cPlayer & a_Player)
+
+void cSlotAreaCrafting::DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_ShouldApply, bool a_KeepEmptySlots)
+{
+ UNUSED(a_ItemStack);
+ UNUSED(a_Player);
+ UNUSED(a_ShouldApply);
+ UNUSED(a_KeepEmptySlots);
+}
+
+
+
+
void cSlotAreaCrafting::ClickedResult(cPlayer & a_Player)
{
cItem & DraggingItem = a_Player.GetDraggingItem();
diff --git a/src/UI/SlotArea.h b/src/UI/SlotArea.h
index d31c87e0c..25b367cff 100644
--- a/src/UI/SlotArea.h
+++ b/src/UI/SlotArea.h
@@ -48,10 +48,10 @@ public:
virtual void DblClicked(cPlayer & a_Player, int a_SlotNum);
/// Called when a new player opens the same parent window. The window already tracks the player. CS-locked.
- virtual void OnPlayerAdded(cPlayer & a_Player) {} ;
+ virtual void OnPlayerAdded(cPlayer & a_Player);
/// Called when one of the players closes the parent window. The window already doesn't track the player. CS-locked.
- virtual void OnPlayerRemoved(cPlayer & a_Player) {} ;
+ virtual void OnPlayerRemoved(cPlayer & a_Player);
/** Called to store as much of a_ItemStack in the area as possible. a_ItemStack is modified to reflect the change.
The default implementation searches each slot for available space and distributes the stack there.
@@ -226,7 +226,7 @@ public:
virtual void OnPlayerRemoved(cPlayer & a_Player) override;
// Distributing items into this area is completely disabled
- virtual void DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_ShouldApply, bool a_KeepEmptySlots) override {}
+ virtual void DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_ShouldApply, bool a_KeepEmptySlots) override;
protected:
/// Maps player's EntityID -> current recipe; not a std::map because cCraftingGrid needs proper constructor params
--
cgit v1.2.3
From 3991c04d478b0e929faff4ce95fdb53eae67b888 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Sat, 1 Mar 2014 02:43:35 +0100
Subject: Improved comments in float size check.
---
src/WorldStorage/FastNBT.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/WorldStorage/FastNBT.h b/src/WorldStorage/FastNBT.h
index 49f97c458..d68ebd54c 100644
--- a/src/WorldStorage/FastNBT.h
+++ b/src/WorldStorage/FastNBT.h
@@ -175,8 +175,8 @@ public:
// Cause a compile-time error if sizeof(float) != 4
// If your platform produces a compiler error here, you'll need to add code that manually decodes 32-bit floats
- char Check1[5 - sizeof(float)]; // sizeof(float) <= 4
- char Check2[sizeof(float) - 3]; // sizeof(float) >= 4
+ char Check1[5 - sizeof(float)]; // Fails if sizeof(float) > 4
+ char Check2[sizeof(float) - 3]; // Fails if sizeof(float) < 4
UNUSED(Check1);
UNUSED(Check2);
--
cgit v1.2.3
From aecbf772932792d122d191f8a45b75ddb2756d6f Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Sat, 1 Mar 2014 02:46:50 +0100
Subject: Removed cBlockHandler forward declaration from cChunkInterface.
Wasn't needed. Also reformatted the code.
---
src/Blocks/ChunkInterface.h | 31 ++++++++++++++++++++++---------
1 file changed, 22 insertions(+), 9 deletions(-)
diff --git a/src/Blocks/ChunkInterface.h b/src/Blocks/ChunkInterface.h
index b30eff1e4..b58c0c086 100644
--- a/src/Blocks/ChunkInterface.h
+++ b/src/Blocks/ChunkInterface.h
@@ -5,31 +5,35 @@
#include "../ForEachChunkProvider.h"
#include "WorldInterface.h"
-class cBlockHandler;
-class cChunkInterface : public cForEachChunkProvider
+
+
+
+class cChunkInterface:
+ public cForEachChunkProvider
{
public:
cChunkInterface(cChunkMap * a_ChunkMap) : m_ChunkMap(a_ChunkMap) {}
- BLOCKTYPE GetBlock (int a_BlockX, int a_BlockY, int a_BlockZ)
+ BLOCKTYPE GetBlock(int a_BlockX, int a_BlockY, int a_BlockZ)
{
return m_ChunkMap->GetBlock(a_BlockX,a_BlockY,a_BlockZ);
}
- BLOCKTYPE GetBlock (const Vector3i & a_Pos )
+ BLOCKTYPE GetBlock(const Vector3i & a_Pos )
{
- return GetBlock( a_Pos.x, a_Pos.y, a_Pos.z );
+ return GetBlock( a_Pos.x, a_Pos.y, a_Pos.z );
}
- NIBBLETYPE GetBlockMeta (int a_BlockX, int a_BlockY, int a_BlockZ)
+ NIBBLETYPE GetBlockMeta(int a_BlockX, int a_BlockY, int a_BlockZ)
{
return m_ChunkMap->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ);
}
- bool GetBlockTypeMeta (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta)
+ bool GetBlockTypeMeta(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta)
{
return m_ChunkMap->GetBlockTypeMeta(a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta);
}
+
/** Sets the block at the specified coords to the specified value.
Full processing, incl. updating neighbors, is performed.
*/
@@ -37,7 +41,8 @@ public:
{
m_ChunkMap->SetBlock(a_WorldInterface, a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta);
}
- void SetBlockMeta (int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_MetaData)
+
+ void SetBlockMeta(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_MetaData)
{
m_ChunkMap->SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, a_MetaData);
}
@@ -55,7 +60,11 @@ public:
{
m_ChunkMap->FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta);
}
- void FastSetBlock(const Vector3i & a_Pos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta ) { FastSetBlock( a_Pos.x, a_Pos.y, a_Pos.z, a_BlockType, a_BlockMeta ); }
+
+ void FastSetBlock(const Vector3i & a_Pos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta )
+ {
+ FastSetBlock( a_Pos.x, a_Pos.y, a_Pos.z, a_BlockType, a_BlockMeta );
+ }
void UseBlockEntity(cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ)
{
@@ -77,3 +86,7 @@ public:
private:
cChunkMap * m_ChunkMap;
};
+
+
+
+
--
cgit v1.2.3
From c18748648d791911e5e2df81ae600859c8522e9a Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Sat, 1 Mar 2014 02:54:46 +0100
Subject: Forgotten changes to cChunkInterface.
---
src/Blocks/ChunkInterface.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/Blocks/ChunkInterface.h b/src/Blocks/ChunkInterface.h
index b58c0c086..be7c2e0e5 100644
--- a/src/Blocks/ChunkInterface.h
+++ b/src/Blocks/ChunkInterface.h
@@ -20,9 +20,9 @@ public:
{
return m_ChunkMap->GetBlock(a_BlockX,a_BlockY,a_BlockZ);
}
- BLOCKTYPE GetBlock(const Vector3i & a_Pos )
+ BLOCKTYPE GetBlock(const Vector3i & a_Pos)
{
- return GetBlock( a_Pos.x, a_Pos.y, a_Pos.z );
+ return GetBlock(a_Pos.x, a_Pos.y, a_Pos.z);
}
NIBBLETYPE GetBlockMeta(int a_BlockX, int a_BlockY, int a_BlockZ)
{
--
cgit v1.2.3
From ce07a22fe6f210cd6461d54cd7fd8eaaaa47be4f Mon Sep 17 00:00:00 2001
From: STRWarrior
Date: Sat, 1 Mar 2014 10:44:34 +0100
Subject: APIDump: Documented cRoot:CreateAndInitializeWorld.
---
MCServer/Plugins/APIDump/APIDesc.lua | 1 +
1 file changed, 1 insertion(+)
diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua
index c6221f30d..241aa05ad 100644
--- a/MCServer/Plugins/APIDump/APIDesc.lua
+++ b/MCServer/Plugins/APIDump/APIDesc.lua
@@ -1773,6 +1773,7 @@ cPluginManager.AddHook(cPluginManager.HOOK_CHAT, OnChatMessage);
BroadcastChatInfo = { Params = "Message", Return = "", Notes = "Prepends Yellow [INFO] / colours entire text (depending on ShouldUseChatPrefixes()) and broadcasts message. For informational messages, such as command usage." },
BroadcastChatSuccess = { Params = "Message", Return = "", Notes = "Prepends Green [INFO] / colours entire text (depending on ShouldUseChatPrefixes()) and broadcasts message. For success messages." },
BroadcastChatWarning = { Params = "Message", Return = "", Notes = "Prepends Rose [WARN] / colours entire text (depending on ShouldUseChatPrefixes()) and broadcasts message. For concerning events, such as plugin reload etc." },
+ CreateAndInitializeWorld = { Params = "WorldName", Return = "{{cWorld|cWorld}}", Notes = "Creates a new world and initializes it. If there is a world whith the same name it returns nil." },
FindAndDoWithPlayer = { Params = "PlayerName, CallbackFunction", Return = "", Notes = "Calls the given callback function for the given player." },
ForEachPlayer = { Params = "CallbackFunction", Return = "", Notes = "Calls the given callback function for each player. The callback function has the following signature: function Callback({{cPlayer|cPlayer}})
" },
ForEachWorld = { Params = "CallbackFunction", Return = "", Notes = "Calls the given callback function for each world. The callback function has the following signature: function Callback({{cWorld|cWorld}})
" },
--
cgit v1.2.3
From 5c449452871340eeae9df8f34c5e145fda991d92 Mon Sep 17 00:00:00 2001
From: andrew
Date: Sat, 1 Mar 2014 12:06:19 +0200
Subject: Exported and documented cScoreboard
---
MCServer/Plugins/APIDump/APIDesc.lua | 90 ++++++++++++++++++++++++++++++++++++
src/Bindings/AllToLua.pkg | 1 +
src/Entities/Player.cpp | 21 ++-------
src/Scoreboard.cpp | 30 ++++++++++++
src/Scoreboard.h | 67 ++++++++++++++-------------
5 files changed, 160 insertions(+), 49 deletions(-)
diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua
index c6221f30d..c2dd6ba99 100644
--- a/MCServer/Plugins/APIDump/APIDesc.lua
+++ b/MCServer/Plugins/APIDump/APIDesc.lua
@@ -1115,6 +1115,42 @@ local Item5 = cItem(E_ITEM_DIAMOND_CHESTPLATE, 1, 0, "thorns=1;unbreaking=3");
},
}, -- cItem
+ cObjective =
+ {
+ Desc = [[
+ This class represents a single scoreboard objective.
+ ]],
+ Functions =
+ {
+ AddScore = { Params = "string, number", Return = "Score", Notes = "Adds a value to the score of the specified player and returns the new value." },
+ GetDisplayName = { Params = "", Return = "string", Notes = "Returns the display name of the objective. This name will be shown to the connected players." },
+ GetName = { Params = "", Return = "string", Notes = "Returns the internal name of the objective." },
+ GetScore = { Params = "string", Return = "Score", Notes = "Returns the score of the specified player." },
+ GetType = { Params = "", Return = "eType", Notes = "Returns the type of the objective. (i.e what is being tracked)" },
+ Reset = { Params = "", Return = "", Notes = "Resets the scores of the tracked players." },
+ ResetScore = { Params = "string", Return = "", Notes = "Reset the score of the specified player." },
+ SetDisplayName = { Params = "string", Return = "", Notes = "Sets the display name of the objective." },
+ SetScore = { Params = "string, Score", Return = "", Notes = "Sets the score of the specified player." },
+ SubScore = { Params = "string, number", Return = "Score", Notes = "Subtracts a value from the score of the specified player and returns the new value." },
+ },
+ Constants =
+ {
+ E_TYPE_ACHIEVEMENT = { Notes = "" },
+ E_TYPE_DEATH_COUNT = { Notes = "" },
+ E_TYPE_DUMMY = { Notes = "" },
+ E_TYPE_HEALTH = { Notes = "" },
+ E_TYPE_PLAYER_KILL_COUNT = { Notes = "" },
+ E_TYPE_STAT = { Notes = "" },
+ E_TYPE_STAT_BLOCK_MINE = { Notes = "" },
+ E_TYPE_STAT_ENTITY_KILL = { Notes = "" },
+ E_TYPE_STAT_ENTITY_KILLED_BY = { Notes = "" },
+ E_TYPE_STAT_ITEM_BREAK = { Notes = "" },
+ E_TYPE_STAT_ITEM_CRAFT = { Notes = "" },
+ E_TYPE_STAT_ITEM_USE = { Notes = "" },
+ E_TYPE_TOTAL_KILL_COUNT = { Notes = "" },
+ },
+ }, -- cObjective
+
cPainting =
{
Desc = "This class represents a painting in the world. These paintings are special and different from Vanilla in that they can be critical-hit.",
@@ -1821,6 +1857,34 @@ end
},
}, -- cRoot
+ cScoreboard =
+ {
+ Desc = [[
+ This class manages the objectives and teams of a single world.
+ ]],
+ Functions =
+ {
+ AddPlayerScore = { Params = "Name, Type, Value", Return = "", Notes = "Adds a value to all player scores of the specified objective type." },
+ GetNumObjectives = { Params = "", Return = "number", Notes = "Returns the nuber of registered objectives." },
+ GetNumTeams = { Params = "", Return = "number", Notes = "Returns the number of registered teams." },
+ GetObjective = { Params = "string", Return = "{{cObjective}}", Notes = "Returns the objective with the specified name." },
+ GetObjectiveIn = { Params = "DisplaySlot", Return = "{{cObjective}}", Notes = "Returns the objective in the specified display slot. Can be nil." },
+ GetTeam = { Params = "string", Return = "{{cTeam}}", Notes = "Returns the team with the specified name." },
+ RegisterObjective = { Params = "Name, DisplayName, Type", Return = "{{cObjective}}", Notes = "Registers a new scoreboard objective. Returns the {{cObjective}} instance, nil on error." },
+ RegisterTeam = { Params = "Name, DisplayName, Prefix, Suffix", Return = "{{cTeam}}", Notes = "Registers a new team. Returns the {{cTeam}} instance, nil on error." },
+ RemoveObjective = { Params = "string", Return = "bool", Notes = "Removes the objective with the specified name. Returns true if operation was successful." },
+ RemoveTeam = { Params = "string", Return = "bool", Notes = "Removes the team with the specified name. Returns true if operation was successful." },
+ SetDisplay = { Params = "Name, DisplaySlot", Return = "", Notes = "Updates the currently displayed objective." },
+ },
+ Constants =
+ {
+ E_DISPLAY_SLOT_COUNT = { Notes = "" },
+ E_DISPLAY_SLOT_LIST = { Notes = "" },
+ E_DISPLAY_SLOT_NAME = { Notes = "" },
+ E_DISPLAY_SLOT_SIDEBAR = { Notes = "" },
+ },
+ }, -- cScoreboard
+
cServer =
{
Desc = [[
@@ -1841,6 +1905,32 @@ end
},
}, -- cServer
+ cTeam =
+ {
+ Desc = [[
+ This class manages a single player team.
+ ]],
+ Functions =
+ {
+ AddPlayer = { Params = "string", Returns = "bool", Notes = "Adds a player to this team. Returns true if the operation was successful." },
+ AllowsFriendlyFire = { Params = "", Return = "bool", Notes = "Returns whether team friendly fire is allowed." },
+ CanSeeFriendlyInvisible = { Params = "", Return = "bool", Notes = "Returns whether players can see invisible teammates." },
+ HasPlayer = { Params = "string", Returns = "bool", Notes = "Returns whether the specified player is a member of this team." },
+ GetDisplayName = { Params = "", Return = "string", Notes = "Returns the display name of the team." },
+ GetName = { Params = "", Return = "string", Notes = "Returns the internal name of the team." },
+ GetNumPlayers = { Params = "", Return = "number", Notes = "Returns the number of registered players." },
+ GetPrefix = { Params = "", Return = "string", Notes = "Returns the prefix prepended to the names of the members of this team." },
+ RemovePlayer = { Params = "string", Returns = "bool", Notes = "Removes the player with the specified name from this team. Returns true if the operation was successful." },
+ Reset = { Params = "", Returns = "", Notes = "Removes all players from this team." },
+ GetSuffix = { Params = "", Return = "string", Notes = "Returns the suffix appended to the names of the members of this team." },
+ SetCanSeeFriendlyInvisible = { Params = "bool", Return = "", Notes = "Set whether players can see invisible teammates." },
+ SetDisplayName = { Params = "string", Return = "", Notes = "Sets the display name of this team. (i.e. what will be shown to the players)" },
+ SetFriendlyFire = { Params = "bool", Return = "", Notes = "Sets whether team friendly fire is allowed." },
+ SetPrefix = { Params = "string", Return = "", Notes = "Sets the prefix prepended to the names of the members of this team." },
+ SetSuffix = { Params = "string", Return = "", Notes = "Sets the suffix appended to the names of the members of this team." },
+ },
+ }, -- cTeam
+
cTNTEntity =
{
Desc = "This class manages a TNT entity.",
diff --git a/src/Bindings/AllToLua.pkg b/src/Bindings/AllToLua.pkg
index 6537437cd..1a2140771 100644
--- a/src/Bindings/AllToLua.pkg
+++ b/src/Bindings/AllToLua.pkg
@@ -75,6 +75,7 @@ $cfile "../Mobs/Monster.h"
$cfile "../CompositeChat.h"
$cfile "../Map.h"
$cfile "../MapManager.h"
+$cfile "../Scoreboard.h"
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index f419ee09c..416bda2ec 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -858,6 +858,8 @@ void cPlayer::KilledBy(cEntity * a_Killer)
else if (a_Killer->IsPlayer())
{
GetWorld()->BroadcastChatDeath(Printf("%s was killed by %s", GetName().c_str(), ((cPlayer *)a_Killer)->GetName().c_str()));
+
+ m_World->GetScoreBoard().AddPlayerScore(((cPlayer *)a_Killer)->GetName(), cObjective::E_TYPE_PLAYER_KILL_COUNT, 1);
}
else
{
@@ -867,24 +869,7 @@ void cPlayer::KilledBy(cEntity * a_Killer)
GetWorld()->BroadcastChatDeath(Printf("%s was killed by a %s", GetName().c_str(), KillerClass.c_str()));
}
- class cIncrementCounterCB
- : public cObjectiveCallback
- {
- AString m_Name;
- public:
- cIncrementCounterCB(const AString & a_Name) : m_Name(a_Name) {}
-
- virtual bool Item(cObjective * a_Objective) override
- {
- a_Objective->AddScore(m_Name, 1);
- return true;
- }
- } IncrementCounter (GetName());
-
- cScoreboard & Scoreboard = m_World->GetScoreBoard();
-
- // Update scoreboard objectives
- Scoreboard.ForEachObjectiveWith(cObjective::E_TYPE_DEATH_COUNT, IncrementCounter);
+ m_World->GetScoreBoard().AddPlayerScore(GetName(), cObjective::E_TYPE_DEATH_COUNT, 1);
}
diff --git a/src/Scoreboard.cpp b/src/Scoreboard.cpp
index 61ecac5b7..1c5a22eff 100644
--- a/src/Scoreboard.cpp
+++ b/src/Scoreboard.cpp
@@ -246,6 +246,17 @@ void cTeam::Reset(void)
+void cTeam::SetDisplayName(const AString & a_Name)
+{
+ m_DisplayName = a_Name;
+
+ // TODO 2014-03-01 xdot: Update clients
+}
+
+
+
+
+
unsigned int cTeam::GetNumPlayers(void) const
{
return m_Players.size();
@@ -306,6 +317,8 @@ bool cScoreboard::RemoveObjective(const AString & a_Name)
ASSERT(m_World != NULL);
m_World->BroadcastScoreboardObjective(it->second.GetName(), it->second.GetDisplayName(), 1);
+ // TODO 2014-03-01 xdot: Remove objective from display slot
+
return true;
}
@@ -465,6 +478,23 @@ void cScoreboard::ForEachObjectiveWith(cObjective::eType a_Type, cObjectiveCallb
+void cScoreboard::AddPlayerScore(const AString & a_Name, cObjective::eType a_Type, cObjective::Score a_Value)
+{
+ cCSLock Lock(m_CSObjectives);
+
+ for (cObjectiveMap::iterator it = m_Objectives.begin(); it != m_Objectives.end(); ++it)
+ {
+ if (it->second.GetType() == a_Type)
+ {
+ it->second.AddScore(a_Name, a_Value);
+ }
+ }
+}
+
+
+
+
+
void cScoreboard::SendTo(cClientHandle & a_Client)
{
cCSLock Lock(m_CSObjectives);
diff --git a/src/Scoreboard.h b/src/Scoreboard.h
index f64ba2bce..f9a8665da 100644
--- a/src/Scoreboard.h
+++ b/src/Scoreboard.h
@@ -67,29 +67,29 @@ public:
const AString & GetName(void) const { return m_Name; }
const AString & GetDisplayName(void) const { return m_DisplayName; }
- /// Resets the objective
+ /** Resets the objective */
void Reset(void);
- /// Returns the score of the specified player
+ /** Returns the score of the specified player */
Score GetScore(const AString & a_Name) const;
- /// Sets the score of the specified player
+ /** Sets the score of the specified player */
void SetScore(const AString & a_Name, Score a_Score);
- /// Resets the score of the specified player
+ /** Resets the score of the specified player */
void ResetScore(const AString & a_Name);
- /// Adds a_Delta and returns the new score
+ /** Adds a_Delta and returns the new score */
Score AddScore(const AString & a_Name, Score a_Delta);
- /// Subtracts a_Delta and returns the new score
+ /** Subtracts a_Delta and returns the new score */
Score SubScore(const AString & a_Name, Score a_Delta);
void SetDisplayName(const AString & a_Name);
// tolua_end
- /// Send this objective to the specified client
+ /** Send this objective to the specified client */
void SendTo(cClientHandle & a_Client);
private:
@@ -109,7 +109,8 @@ private:
friend class cScoreboardSerializer;
-};
+
+}; // tolua_export
@@ -127,21 +128,21 @@ public:
const AString & a_Prefix, const AString & a_Suffix
);
- /// Adds a new player to the team
+ // tolua_begin
+
+ /** Adds a new player to the team */
bool AddPlayer(const AString & a_Name);
- /// Removes a player from the team
+ /** Removes a player from the team */
bool RemovePlayer(const AString & a_Name);
- /// Returns whether the specified player is in this team
+ /** Returns whether the specified player is in this team */
bool HasPlayer(const AString & a_Name) const;
- /// Removes all registered players
+ /** Removes all registered players */
void Reset(void);
- // tolua_begin
-
- /// Returns the number of registered players
+ /** Returns the number of registered players */
unsigned int GetNumPlayers(void) const;
bool AllowsFriendlyFire(void) const { return m_AllowsFriendlyFire; }
@@ -180,7 +181,8 @@ private:
friend class cScoreboardSerializer;
-};
+
+}; // tolua_export
@@ -209,44 +211,46 @@ public:
// tolua_begin
- /// Registers a new scoreboard objective, returns the cObjective instance, NULL on name collision
+ /** Registers a new scoreboard objective, returns the cObjective instance, NULL on name collision */
cObjective * RegisterObjective(const AString & a_Name, const AString & a_DisplayName, cObjective::eType a_Type);
- /// Removes a registered objective, returns true if operation was successful
+ /** Removes a registered objective, returns true if operation was successful */
bool RemoveObjective(const AString & a_Name);
- /// Retrieves the objective with the specified name, NULL if not found
+ /** Retrieves the objective with the specified name, NULL if not found */
cObjective * GetObjective(const AString & a_Name);
- /// Registers a new team, returns the cTeam instance, NULL on name collision
+ /** Registers a new team, returns the cTeam instance, NULL on name collision */
cTeam * RegisterTeam(const AString & a_Name, const AString & a_DisplayName, const AString & a_Prefix, const AString & a_Suffix);
- /// Removes a registered team, returns true if operation was successful
+ /** Removes a registered team, returns true if operation was successful */
bool RemoveTeam(const AString & a_Name);
- /// Retrieves the team with the specified name, NULL if not found
+ /** Retrieves the team with the specified name, NULL if not found */
cTeam * GetTeam(const AString & a_Name);
- cTeam * QueryPlayerTeam(const AString & a_Name); // WARNING: O(n logn)
-
void SetDisplay(const AString & a_Objective, eDisplaySlot a_Slot);
- void SetDisplay(cObjective * a_Objective, eDisplaySlot a_Slot);
-
cObjective * GetObjectiveIn(eDisplaySlot a_Slot);
- /// Execute callback for each objective with the specified type
- void ForEachObjectiveWith(cObjective::eType a_Type, cObjectiveCallback& a_Callback);
-
unsigned int GetNumObjectives(void) const;
unsigned int GetNumTeams(void) const;
+ void AddPlayerScore(const AString & a_Name, cObjective::eType a_Type, cObjective::Score a_Value = 1);
+
// tolua_end
- /// Send this scoreboard to the specified client
+ /** Send this scoreboard to the specified client */
void SendTo(cClientHandle & a_Client);
+ cTeam * QueryPlayerTeam(const AString & a_Name); // WARNING: O(n logn)
+
+ /** Execute callback for each objective with the specified type */
+ void ForEachObjectiveWith(cObjective::eType a_Type, cObjectiveCallback& a_Callback);
+
+ void SetDisplay(cObjective * a_Objective, eDisplaySlot a_Slot);
+
private:
@@ -269,7 +273,8 @@ private:
friend class cScoreboardSerializer;
-} ;
+
+}; // tolua_export
--
cgit v1.2.3
From a28e5eca1835e1be868c3bcd22d87e3cfae2f547 Mon Sep 17 00:00:00 2001
From: andrew
Date: Sat, 1 Mar 2014 14:03:16 +0200
Subject: Exported cScoreboard::ForEachObjective
---
MCServer/Plugins/APIDump/APIDesc.lua | 1 +
src/Bindings/ManualBindings.cpp | 4 ++++
src/Scoreboard.cpp | 24 ++++++++++++++++++++++--
src/Scoreboard.h | 19 +++++++++++++++++--
4 files changed, 44 insertions(+), 4 deletions(-)
diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua
index c2dd6ba99..5bc69eb24 100644
--- a/MCServer/Plugins/APIDump/APIDesc.lua
+++ b/MCServer/Plugins/APIDump/APIDesc.lua
@@ -1865,6 +1865,7 @@ end
Functions =
{
AddPlayerScore = { Params = "Name, Type, Value", Return = "", Notes = "Adds a value to all player scores of the specified objective type." },
+ ForEachObjective = { Params = "CallBackFunction, [CallbackData]", Return = "bool", Notes = "Calls the specified callback for each objective in the scoreboard. Returns true if all objectives have been processed (including when there are zero objectives), or false if the callback function has aborted the enumeration by returning true. The callback function has the following signature: function Callback({{cObjective|Objective}}, [CallbackData])
The callback should return false or no value to continue with the next objective, or true to abort the enumeration." },
GetNumObjectives = { Params = "", Return = "number", Notes = "Returns the nuber of registered objectives." },
GetNumTeams = { Params = "", Return = "number", Notes = "Returns the number of registered teams." },
GetObjective = { Params = "string", Return = "{{cObjective}}", Notes = "Returns the objective with the specified name." },
diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp
index 461186d3b..3c3e78d25 100644
--- a/src/Bindings/ManualBindings.cpp
+++ b/src/Bindings/ManualBindings.cpp
@@ -2583,6 +2583,10 @@ void ManualBindings::Bind(lua_State * tolua_S)
tolua_beginmodule(tolua_S, "cMapManager");
tolua_function(tolua_S, "DoWithMap", tolua_DoWithID);
tolua_endmodule(tolua_S);
+
+ tolua_beginmodule(tolua_S, "cScoreboard");
+ tolua_function(tolua_S, "ForEachObjective", tolua_ForEach);
+ tolua_endmodule(tolua_S);
tolua_beginmodule(tolua_S, "cPlugin");
tolua_function(tolua_S, "Call", tolua_cPlugin_Call);
diff --git a/src/Scoreboard.cpp b/src/Scoreboard.cpp
index 1c5a22eff..43b8ba1ad 100644
--- a/src/Scoreboard.cpp
+++ b/src/Scoreboard.cpp
@@ -457,7 +457,7 @@ cObjective * cScoreboard::GetObjectiveIn(eDisplaySlot a_Slot)
-void cScoreboard::ForEachObjectiveWith(cObjective::eType a_Type, cObjectiveCallback& a_Callback)
+bool cScoreboard::ForEachObjectiveWith(cObjective::eType a_Type, cObjectiveCallback& a_Callback)
{
cCSLock Lock(m_CSObjectives);
@@ -468,10 +468,30 @@ void cScoreboard::ForEachObjectiveWith(cObjective::eType a_Type, cObjectiveCallb
// Call callback
if (a_Callback.Item(&it->second))
{
- return;
+ return false;
}
}
}
+ return true;
+}
+
+
+
+
+
+bool cScoreboard::ForEachObjective(cObjectiveCallback& a_Callback)
+{
+ cCSLock Lock(m_CSObjectives);
+
+ for (cObjectiveMap::iterator it = m_Objectives.begin(); it != m_Objectives.end(); ++it)
+ {
+ // Call callback
+ if (a_Callback.Item(&it->second))
+ {
+ return false;
+ }
+ }
+ return true;
}
diff --git a/src/Scoreboard.h b/src/Scoreboard.h
index f9a8665da..8e268516d 100644
--- a/src/Scoreboard.h
+++ b/src/Scoreboard.h
@@ -92,6 +92,12 @@ public:
/** Send this objective to the specified client */
void SendTo(cClientHandle & a_Client);
+ static const char * GetClassStatic(void) // Needed for ManualBindings's ForEach templates
+ {
+ return "cObjective";
+ }
+
+
private:
typedef std::pair cTrackedPlayer;
@@ -246,8 +252,17 @@ public:
cTeam * QueryPlayerTeam(const AString & a_Name); // WARNING: O(n logn)
- /** Execute callback for each objective with the specified type */
- void ForEachObjectiveWith(cObjective::eType a_Type, cObjectiveCallback& a_Callback);
+ /** Execute callback for each objective with the specified type
+ *
+ * Returns true if all objectives processed, false if the callback aborted by returning true.
+ */
+ bool ForEachObjectiveWith(cObjective::eType a_Type, cObjectiveCallback& a_Callback);
+
+ /** Execute callback for each objective.
+ *
+ * Returns true if all objectives processed, false if the callback aborted by returning true.
+ */
+ bool ForEachObjective(cObjectiveCallback& a_Callback); // Exported in ManualBindings.cpp
void SetDisplay(cObjective * a_Objective, eDisplaySlot a_Slot);
--
cgit v1.2.3
From 692a84af31889af7a83b780009b1fcc81bfa3d99 Mon Sep 17 00:00:00 2001
From: andrew
Date: Sat, 1 Mar 2014 14:20:29 +0200
Subject: Shortened enums
---
src/Entities/Player.cpp | 4 +-
src/Scoreboard.cpp | 62 +++++++++++++++----------------
src/Scoreboard.h | 36 +++++++++---------
src/WorldStorage/ScoreboardSerializer.cpp | 14 +++----
4 files changed, 58 insertions(+), 58 deletions(-)
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index 416bda2ec..8f94f1feb 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -859,7 +859,7 @@ void cPlayer::KilledBy(cEntity * a_Killer)
{
GetWorld()->BroadcastChatDeath(Printf("%s was killed by %s", GetName().c_str(), ((cPlayer *)a_Killer)->GetName().c_str()));
- m_World->GetScoreBoard().AddPlayerScore(((cPlayer *)a_Killer)->GetName(), cObjective::E_TYPE_PLAYER_KILL_COUNT, 1);
+ m_World->GetScoreBoard().AddPlayerScore(((cPlayer *)a_Killer)->GetName(), cObjective::otPlayerKillCount, 1);
}
else
{
@@ -869,7 +869,7 @@ void cPlayer::KilledBy(cEntity * a_Killer)
GetWorld()->BroadcastChatDeath(Printf("%s was killed by a %s", GetName().c_str(), KillerClass.c_str()));
}
- m_World->GetScoreBoard().AddPlayerScore(GetName(), cObjective::E_TYPE_DEATH_COUNT, 1);
+ m_World->GetScoreBoard().AddPlayerScore(GetName(), cObjective::otDeathCount, 1);
}
diff --git a/src/Scoreboard.cpp b/src/Scoreboard.cpp
index 43b8ba1ad..ee56a1145 100644
--- a/src/Scoreboard.cpp
+++ b/src/Scoreboard.cpp
@@ -17,19 +17,19 @@ AString cObjective::TypeToString(eType a_Type)
{
switch (a_Type)
{
- case E_TYPE_DUMMY: return "dummy";
- case E_TYPE_DEATH_COUNT: return "deathCount";
- case E_TYPE_PLAYER_KILL_COUNT: return "playerKillCount";
- case E_TYPE_TOTAL_KILL_COUNT: return "totalKillCount";
- case E_TYPE_HEALTH: return "health";
- case E_TYPE_ACHIEVEMENT: return "achievement";
- case E_TYPE_STAT: return "stat";
- case E_TYPE_STAT_ITEM_CRAFT: return "stat.craftItem";
- case E_TYPE_STAT_ITEM_USE: return "stat.useItem";
- case E_TYPE_STAT_ITEM_BREAK: return "stat.breakItem";
- case E_TYPE_STAT_BLOCK_MINE: return "stat.mineBlock";
- case E_TYPE_STAT_ENTITY_KILL: return "stat.killEntity";
- case E_TYPE_STAT_ENTITY_KILLED_BY: return "stat.entityKilledBy";
+ case otDummy: return "dummy";
+ case otDeathCount: return "deathCount";
+ case otPlayerKillCount: return "playerKillCount";
+ case otTotalKillCount: return "totalKillCount";
+ case otHealth: return "health";
+ case otAchievement: return "achievement";
+ case otStat: return "stat";
+ case otStatItemCraft: return "stat.craftItem";
+ case otStatItemUse: return "stat.useItem";
+ case otStatItemBreak: return "stat.breakItem";
+ case otStatBlockMine: return "stat.mineBlock";
+ case otStatEntityKill: return "stat.killEntity";
+ case otStatEntityKilledBy: return "stat.entityKilledBy";
default: return "";
}
@@ -46,19 +46,19 @@ cObjective::eType cObjective::StringToType(const AString & a_Name)
const char * m_String;
} TypeMap [] =
{
- {E_TYPE_DUMMY, "dummy"},
- {E_TYPE_DEATH_COUNT, "deathCount"},
- {E_TYPE_PLAYER_KILL_COUNT, "playerKillCount"},
- {E_TYPE_TOTAL_KILL_COUNT, "totalKillCount"},
- {E_TYPE_HEALTH, "health"},
- {E_TYPE_ACHIEVEMENT, "achievement"},
- {E_TYPE_STAT, "stat"},
- {E_TYPE_STAT_ITEM_CRAFT, "stat.craftItem"},
- {E_TYPE_STAT_ITEM_USE, "stat.useItem"},
- {E_TYPE_STAT_ITEM_BREAK, "stat.breakItem"},
- {E_TYPE_STAT_BLOCK_MINE, "stat.mineBlock"},
- {E_TYPE_STAT_ENTITY_KILL, "stat.killEntity"},
- {E_TYPE_STAT_ENTITY_KILLED_BY, "stat.entityKilledBy"}
+ {otDummy, "dummy" },
+ {otDeathCount, "deathCount" },
+ {otPlayerKillCount, "playerKillCount" },
+ {otTotalKillCount, "totalKillCount" },
+ {otHealth, "health" },
+ {otAchievement, "achievement" },
+ {otStat, "stat" },
+ {otStatItemCraft, "stat.craftItem" },
+ {otStatItemUse, "stat.useItem" },
+ {otStatItemBreak, "stat.breakItem" },
+ {otStatBlockMine, "stat.mineBlock" },
+ {otStatEntityKill, "stat.killEntity" },
+ {otStatEntityKilledBy, "stat.entityKilledBy"}
};
for (size_t i = 0; i < ARRAYCOUNT(TypeMap); i++)
{
@@ -67,7 +67,7 @@ cObjective::eType cObjective::StringToType(const AString & a_Name)
return TypeMap[i].m_Type;
}
} // for i - TypeMap[]
- return E_TYPE_DUMMY;
+ return otDummy;
}
@@ -268,7 +268,7 @@ unsigned int cTeam::GetNumPlayers(void) const
cScoreboard::cScoreboard(cWorld * a_World) : m_World(a_World)
{
- for (int i = 0; i < (int) E_DISPLAY_SLOT_COUNT; ++i)
+ for (int i = 0; i < (int) dsCount; ++i)
{
m_Display[i] = NULL;
}
@@ -423,7 +423,7 @@ cTeam * cScoreboard::QueryPlayerTeam(const AString & a_Name)
void cScoreboard::SetDisplay(const AString & a_Objective, eDisplaySlot a_Slot)
{
- ASSERT(a_Slot < E_DISPLAY_SLOT_COUNT);
+ ASSERT(a_Slot < dsCount);
cObjective * Objective = GetObjective(a_Objective);
@@ -448,7 +448,7 @@ void cScoreboard::SetDisplay(cObjective * a_Objective, eDisplaySlot a_Slot)
cObjective * cScoreboard::GetObjectiveIn(eDisplaySlot a_Slot)
{
- ASSERT(a_Slot < E_DISPLAY_SLOT_COUNT);
+ ASSERT(a_Slot < dsCount);
return m_Display[a_Slot];
}
@@ -524,7 +524,7 @@ void cScoreboard::SendTo(cClientHandle & a_Client)
it->second.SendTo(a_Client);
}
- for (int i = 0; i < (int) E_DISPLAY_SLOT_COUNT; ++i)
+ for (int i = 0; i < (int) dsCount; ++i)
{
// Avoid race conditions
cObjective * Objective = m_Display[i];
diff --git a/src/Scoreboard.h b/src/Scoreboard.h
index 8e268516d..2abd1564b 100644
--- a/src/Scoreboard.h
+++ b/src/Scoreboard.h
@@ -31,23 +31,23 @@ public:
enum eType
{
- E_TYPE_DUMMY,
+ otDummy,
- E_TYPE_DEATH_COUNT,
- E_TYPE_PLAYER_KILL_COUNT,
- E_TYPE_TOTAL_KILL_COUNT,
- E_TYPE_HEALTH,
+ otDeathCount,
+ otPlayerKillCount,
+ otTotalKillCount,
+ otHealth,
- E_TYPE_ACHIEVEMENT,
+ otAchievement,
- E_TYPE_STAT,
- E_TYPE_STAT_ITEM_CRAFT,
- E_TYPE_STAT_ITEM_USE,
- E_TYPE_STAT_ITEM_BREAK,
+ otStat,
+ otStatItemCraft,
+ otStatItemUse,
+ otStatItemBreak,
- E_TYPE_STAT_BLOCK_MINE,
- E_TYPE_STAT_ENTITY_KILL,
- E_TYPE_STAT_ENTITY_KILLED_BY
+ otStatBlockMine,
+ otStatEntityKill,
+ otStatEntityKilledBy
};
// tolua_end
@@ -201,11 +201,11 @@ public:
enum eDisplaySlot
{
- E_DISPLAY_SLOT_LIST = 0,
- E_DISPLAY_SLOT_SIDEBAR,
- E_DISPLAY_SLOT_NAME,
+ dsList = 0,
+ dsSidebar,
+ dsName,
- E_DISPLAY_SLOT_COUNT
+ dsCount
};
// tolua_end
@@ -284,7 +284,7 @@ private:
cWorld * m_World;
- cObjective* m_Display[E_DISPLAY_SLOT_COUNT];
+ cObjective * m_Display[dsCount];
friend class cScoreboardSerializer;
diff --git a/src/WorldStorage/ScoreboardSerializer.cpp b/src/WorldStorage/ScoreboardSerializer.cpp
index 9b8b661c4..6c885bb45 100644
--- a/src/WorldStorage/ScoreboardSerializer.cpp
+++ b/src/WorldStorage/ScoreboardSerializer.cpp
@@ -173,13 +173,13 @@ void cScoreboardSerializer::SaveScoreboardToNBT(cFastNBTWriter & a_Writer)
a_Writer.BeginCompound("DisplaySlots");
- cObjective * Objective = m_ScoreBoard->GetObjectiveIn(cScoreboard::E_DISPLAY_SLOT_LIST);
+ cObjective * Objective = m_ScoreBoard->GetObjectiveIn(cScoreboard::dsList);
a_Writer.AddString("slot_0", (Objective == NULL) ? "" : Objective->GetName());
- Objective = m_ScoreBoard->GetObjectiveIn(cScoreboard::E_DISPLAY_SLOT_SIDEBAR);
+ Objective = m_ScoreBoard->GetObjectiveIn(cScoreboard::dsSidebar);
a_Writer.AddString("slot_1", (Objective == NULL) ? "" : Objective->GetName());
- Objective = m_ScoreBoard->GetObjectiveIn(cScoreboard::E_DISPLAY_SLOT_NAME);
+ Objective = m_ScoreBoard->GetObjectiveIn(cScoreboard::dsName);
a_Writer.AddString("slot_2", (Objective == NULL) ? "" : Objective->GetName());
a_Writer.EndCompound(); // DisplaySlots
@@ -280,7 +280,7 @@ bool cScoreboardSerializer::LoadScoreboardFromNBT(const cParsedNBT & a_NBT)
{
AString Name, DisplayName, Prefix, Suffix;
- bool AllowsFriendlyFire = false, CanSeeFriendlyInvisible = false;
+ bool AllowsFriendlyFire = true, CanSeeFriendlyInvisible = false;
int CurrLine = a_NBT.FindChildByName(Child, "Name");
if (CurrLine >= 0)
@@ -346,7 +346,7 @@ bool cScoreboardSerializer::LoadScoreboardFromNBT(const cParsedNBT & a_NBT)
{
AString Name = a_NBT.GetString(CurrLine);
- m_ScoreBoard->SetDisplay(Name, cScoreboard::E_DISPLAY_SLOT_LIST);
+ m_ScoreBoard->SetDisplay(Name, cScoreboard::dsList);
}
CurrLine = a_NBT.FindChildByName(DisplaySlots, "slot_1");
@@ -354,7 +354,7 @@ bool cScoreboardSerializer::LoadScoreboardFromNBT(const cParsedNBT & a_NBT)
{
AString Name = a_NBT.GetString(CurrLine);
- m_ScoreBoard->SetDisplay(Name, cScoreboard::E_DISPLAY_SLOT_SIDEBAR);
+ m_ScoreBoard->SetDisplay(Name, cScoreboard::dsSidebar);
}
CurrLine = a_NBT.FindChildByName(DisplaySlots, "slot_2");
@@ -362,7 +362,7 @@ bool cScoreboardSerializer::LoadScoreboardFromNBT(const cParsedNBT & a_NBT)
{
AString Name = a_NBT.GetString(CurrLine);
- m_ScoreBoard->SetDisplay(Name, cScoreboard::E_DISPLAY_SLOT_NAME);
+ m_ScoreBoard->SetDisplay(Name, cScoreboard::dsName);
}
return true;
--
cgit v1.2.3
From 39c8e68ef030b70f1f50165e74d26100bc1988cc Mon Sep 17 00:00:00 2001
From: andrew
Date: Sat, 1 Mar 2014 14:27:55 +0200
Subject: Exported cScoreboard::ForEachTeam
---
MCServer/Plugins/APIDump/APIDesc.lua | 1 +
src/Bindings/ManualBindings.cpp | 1 +
src/Scoreboard.cpp | 19 +++++++++++++++++++
src/Scoreboard.h | 15 ++++++++++++++-
4 files changed, 35 insertions(+), 1 deletion(-)
diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua
index 5bc69eb24..e45c5c475 100644
--- a/MCServer/Plugins/APIDump/APIDesc.lua
+++ b/MCServer/Plugins/APIDump/APIDesc.lua
@@ -1866,6 +1866,7 @@ end
{
AddPlayerScore = { Params = "Name, Type, Value", Return = "", Notes = "Adds a value to all player scores of the specified objective type." },
ForEachObjective = { Params = "CallBackFunction, [CallbackData]", Return = "bool", Notes = "Calls the specified callback for each objective in the scoreboard. Returns true if all objectives have been processed (including when there are zero objectives), or false if the callback function has aborted the enumeration by returning true. The callback function has the following signature: function Callback({{cObjective|Objective}}, [CallbackData])
The callback should return false or no value to continue with the next objective, or true to abort the enumeration." },
+ ForEachTeam = { Params = "CallBackFunction, [CallbackData]", Return = "bool", Notes = "Calls the specified callback for each team in the scoreboard. Returns true if all teams have been processed (including when there are zero teams), or false if the callback function has aborted the enumeration by returning true. The callback function has the following signature: function Callback({{cObjective|Objective}}, [CallbackData])
The callback should return false or no value to continue with the next team, or true to abort the enumeration." },
GetNumObjectives = { Params = "", Return = "number", Notes = "Returns the nuber of registered objectives." },
GetNumTeams = { Params = "", Return = "number", Notes = "Returns the number of registered teams." },
GetObjective = { Params = "string", Return = "{{cObjective}}", Notes = "Returns the objective with the specified name." },
diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp
index 3c3e78d25..fcdd728be 100644
--- a/src/Bindings/ManualBindings.cpp
+++ b/src/Bindings/ManualBindings.cpp
@@ -2586,6 +2586,7 @@ void ManualBindings::Bind(lua_State * tolua_S)
tolua_beginmodule(tolua_S, "cScoreboard");
tolua_function(tolua_S, "ForEachObjective", tolua_ForEach);
+ tolua_function(tolua_S, "ForEachTeam", tolua_ForEach);
tolua_endmodule(tolua_S);
tolua_beginmodule(tolua_S, "cPlugin");
diff --git a/src/Scoreboard.cpp b/src/Scoreboard.cpp
index ee56a1145..05fd0314d 100644
--- a/src/Scoreboard.cpp
+++ b/src/Scoreboard.cpp
@@ -498,6 +498,25 @@ bool cScoreboard::ForEachObjective(cObjectiveCallback& a_Callback)
+bool cScoreboard::ForEachTeam(cTeamCallback& a_Callback)
+{
+ cCSLock Lock(m_CSObjectives);
+
+ for (cTeamMap::iterator it = m_Teams.begin(); it != m_Teams.end(); ++it)
+ {
+ // Call callback
+ if (a_Callback.Item(&it->second))
+ {
+ return false;
+ }
+ }
+ return true;
+}
+
+
+
+
+
void cScoreboard::AddPlayerScore(const AString & a_Name, cObjective::eType a_Type, cObjective::Score a_Value)
{
cCSLock Lock(m_CSObjectives);
diff --git a/src/Scoreboard.h b/src/Scoreboard.h
index 2abd1564b..e22ecaeb1 100644
--- a/src/Scoreboard.h
+++ b/src/Scoreboard.h
@@ -14,9 +14,11 @@
class cObjective;
+class cTeam;
class cWorld;
typedef cItemCallback cObjectiveCallback;
+typedef cItemCallback cTeamCallback;
@@ -170,6 +172,11 @@ public:
// tolua_end
+ static const char * GetClassStatic(void) // Needed for ManualBindings's ForEach templates
+ {
+ return "cTeam";
+ }
+
private:
typedef std::set cPlayerNameSet;
@@ -260,10 +267,16 @@ public:
/** Execute callback for each objective.
*
- * Returns true if all objectives processed, false if the callback aborted by returning true.
+ * Returns true if all objectives have been processed, false if the callback aborted by returning true.
*/
bool ForEachObjective(cObjectiveCallback& a_Callback); // Exported in ManualBindings.cpp
+ /** Execute callback for each team.
+ *
+ * Returns true if all teams have been processed, false if the callback aborted by returning true.
+ */
+ bool ForEachTeam(cTeamCallback& a_Callback); // Exported in ManualBindings.cpp
+
void SetDisplay(cObjective * a_Objective, eDisplaySlot a_Slot);
--
cgit v1.2.3
From add9955255ffc3dba012d4adfa743b244b240ea5 Mon Sep 17 00:00:00 2001
From: andrew
Date: Sat, 1 Mar 2014 15:03:27 +0200
Subject: APIDump: Fixed cScoreboard enums
---
MCServer/Plugins/APIDump/APIDesc.lua | 34 +++++++++++++++++-----------------
1 file changed, 17 insertions(+), 17 deletions(-)
diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua
index e45c5c475..ea89d04af 100644
--- a/MCServer/Plugins/APIDump/APIDesc.lua
+++ b/MCServer/Plugins/APIDump/APIDesc.lua
@@ -1135,19 +1135,19 @@ local Item5 = cItem(E_ITEM_DIAMOND_CHESTPLATE, 1, 0, "thorns=1;unbreaking=3");
},
Constants =
{
- E_TYPE_ACHIEVEMENT = { Notes = "" },
- E_TYPE_DEATH_COUNT = { Notes = "" },
- E_TYPE_DUMMY = { Notes = "" },
- E_TYPE_HEALTH = { Notes = "" },
- E_TYPE_PLAYER_KILL_COUNT = { Notes = "" },
- E_TYPE_STAT = { Notes = "" },
- E_TYPE_STAT_BLOCK_MINE = { Notes = "" },
- E_TYPE_STAT_ENTITY_KILL = { Notes = "" },
- E_TYPE_STAT_ENTITY_KILLED_BY = { Notes = "" },
- E_TYPE_STAT_ITEM_BREAK = { Notes = "" },
- E_TYPE_STAT_ITEM_CRAFT = { Notes = "" },
- E_TYPE_STAT_ITEM_USE = { Notes = "" },
- E_TYPE_TOTAL_KILL_COUNT = { Notes = "" },
+ otAchievement = { Notes = "" },
+ otDeathCount = { Notes = "" },
+ otDummy = { Notes = "" },
+ otHealth = { Notes = "" },
+ otPlayerKillCount = { Notes = "" },
+ otStat = { Notes = "" },
+ otStatBlockMine = { Notes = "" },
+ otStatEntityKill = { Notes = "" },
+ otStatEntityKilledBy = { Notes = "" },
+ otStatItemBreak = { Notes = "" },
+ otStatItemCraft = { Notes = "" },
+ otStatItemUse = { Notes = "" },
+ otTotalKillCount = { Notes = "" },
},
}, -- cObjective
@@ -1880,10 +1880,10 @@ end
},
Constants =
{
- E_DISPLAY_SLOT_COUNT = { Notes = "" },
- E_DISPLAY_SLOT_LIST = { Notes = "" },
- E_DISPLAY_SLOT_NAME = { Notes = "" },
- E_DISPLAY_SLOT_SIDEBAR = { Notes = "" },
+ dsCount = { Notes = "" },
+ dsList = { Notes = "" },
+ dsName = { Notes = "" },
+ dsSidebar = { Notes = "" },
},
}, -- cScoreboard
--
cgit v1.2.3
From 48288992041eb89eb0d21380b9e1326426c3a61b Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Sat, 1 Mar 2014 14:23:53 +0100
Subject: DoxyFile: Updated after all the folder renaming.
---
Doxyfile | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/Doxyfile b/Doxyfile
index 33f15c4b1..d4dae6ec5 100644
--- a/Doxyfile
+++ b/Doxyfile
@@ -665,9 +665,7 @@ WARN_LOGFILE =
# directories like "/usr/src/myproject". Separate the files or directories
# with spaces.
-INPUT = source \
- iniFile \
- WebServer
+INPUT = src
# This tag can be used to specify the character encoding of the source files
# that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is
--
cgit v1.2.3
From 6129b6edf161c61db91d91145e9b1f23db688529 Mon Sep 17 00:00:00 2001
From: STRWarrior
Date: Sat, 1 Mar 2014 14:29:40 +0100
Subject: If there is a SourceLocation available the InfoDump will note it in
the forum version.
---
MCServer/Plugins/InfoDump.lua | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/MCServer/Plugins/InfoDump.lua b/MCServer/Plugins/InfoDump.lua
index 8fac09d60..03ce46d99 100644
--- a/MCServer/Plugins/InfoDump.lua
+++ b/MCServer/Plugins/InfoDump.lua
@@ -578,7 +578,10 @@ local function DumpPluginInfoForum(a_PluginFolder, a_PluginInfo)
DumpAdditionalInfoForum(a_PluginInfo, f);
DumpCommandsForum(a_PluginInfo, f);
DumpPermissionsForum(a_PluginInfo, f);
-
+ if (a_PluginInfo.SourceLocation ~= nil) then
+ f:write("[b][color=blue]Source:[/color] [url=" .. a_PluginInfo.SourceLocation .. "]Link[/url][/b]");
+ end
+
f:close();
end
--
cgit v1.2.3
From 854cf9df999691463aa382bc760d3a4322d015a5 Mon Sep 17 00:00:00 2001
From: STRWarrior
Date: Sat, 1 Mar 2014 14:45:38 +0100
Subject: Using comma instead of string concatenation.
---
MCServer/Plugins/InfoDump.lua | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/MCServer/Plugins/InfoDump.lua b/MCServer/Plugins/InfoDump.lua
index 03ce46d99..e7ed157e3 100644
--- a/MCServer/Plugins/InfoDump.lua
+++ b/MCServer/Plugins/InfoDump.lua
@@ -579,7 +579,7 @@ local function DumpPluginInfoForum(a_PluginFolder, a_PluginInfo)
DumpCommandsForum(a_PluginInfo, f);
DumpPermissionsForum(a_PluginInfo, f);
if (a_PluginInfo.SourceLocation ~= nil) then
- f:write("[b][color=blue]Source:[/color] [url=" .. a_PluginInfo.SourceLocation .. "]Link[/url][/b]");
+ f:write("[b][color=blue]Source:[/color] [url=", a_PluginInfo.SourceLocation, "]Link[/url][/b]");
end
f:close();
--
cgit v1.2.3
From 5c5502be9e46a0a5d44b6994e8075e5588598912 Mon Sep 17 00:00:00 2001
From: andrew
Date: Sat, 1 Mar 2014 17:04:17 +0200
Subject: Refactored global block property arrays
---
src/BlockInfo.cpp | 423 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/BlockInfo.h | 54 +++++++
2 files changed, 477 insertions(+)
create mode 100644 src/BlockInfo.cpp
create mode 100644 src/BlockInfo.h
diff --git a/src/BlockInfo.cpp b/src/BlockInfo.cpp
new file mode 100644
index 000000000..6ae59db53
--- /dev/null
+++ b/src/BlockInfo.cpp
@@ -0,0 +1,423 @@
+
+#include "Globals.h"
+
+#include "BlockInfo.h"
+
+
+
+
+
+BlockInfo BlockInfo::ms_Info[256];
+
+
+
+
+
+BlockInfo::BlockInfo()
+ : m_LightValue(0x00)
+ , m_SpreadLightFalloff(0x0f)
+ , m_Transparent(false)
+ , m_OneHitDig(false)
+ , m_PistonBreakable(false)
+ , m_IsSnowable(true)
+ , m_RequiresSpecialTool(false)
+ , m_IsSolid(true)
+ , m_FullyOccupiesVoxel(false)
+{}
+
+
+
+
+
+BlockInfo & BlockInfo::GetById(unsigned int a_ID)
+{
+ ASSERT(a_ID < 256);
+
+ return ms_Info[a_ID];
+}
+
+
+
+
+
+void BlockInfo::Initialize(void)
+{
+ // Emissive blocks
+ ms_Info[E_BLOCK_FIRE ].m_LightValue = 15;
+ ms_Info[E_BLOCK_GLOWSTONE ].m_LightValue = 15;
+ ms_Info[E_BLOCK_JACK_O_LANTERN ].m_LightValue = 15;
+ ms_Info[E_BLOCK_LAVA ].m_LightValue = 15;
+ ms_Info[E_BLOCK_STATIONARY_LAVA ].m_LightValue = 15;
+ ms_Info[E_BLOCK_END_PORTAL ].m_LightValue = 15;
+ ms_Info[E_BLOCK_REDSTONE_LAMP_ON ].m_LightValue = 15;
+ ms_Info[E_BLOCK_TORCH ].m_LightValue = 14;
+ ms_Info[E_BLOCK_BURNING_FURNACE ].m_LightValue = 13;
+ ms_Info[E_BLOCK_NETHER_PORTAL ].m_LightValue = 11;
+ ms_Info[E_BLOCK_REDSTONE_ORE_GLOWING].m_LightValue = 9;
+ ms_Info[E_BLOCK_REDSTONE_REPEATER_ON].m_LightValue = 9;
+ ms_Info[E_BLOCK_REDSTONE_TORCH_ON ].m_LightValue = 7;
+ ms_Info[E_BLOCK_BREWING_STAND ].m_LightValue = 1;
+ ms_Info[E_BLOCK_BROWN_MUSHROOM ].m_LightValue = 1;
+ ms_Info[E_BLOCK_DRAGON_EGG ].m_LightValue = 1;
+
+
+ // Spread blocks
+ ms_Info[E_BLOCK_AIR ].m_SpreadLightFalloff = 1;
+ ms_Info[E_BLOCK_CAKE ].m_SpreadLightFalloff = 1;
+ ms_Info[E_BLOCK_CHEST ].m_SpreadLightFalloff = 1;
+ ms_Info[E_BLOCK_COBWEB ].m_SpreadLightFalloff = 1;
+ ms_Info[E_BLOCK_CROPS ].m_SpreadLightFalloff = 1;
+ ms_Info[E_BLOCK_FENCE ].m_SpreadLightFalloff = 1;
+ ms_Info[E_BLOCK_FENCE_GATE ].m_SpreadLightFalloff = 1;
+ ms_Info[E_BLOCK_FIRE ].m_SpreadLightFalloff = 1;
+ ms_Info[E_BLOCK_GLASS ].m_SpreadLightFalloff = 1;
+ ms_Info[E_BLOCK_GLASS_PANE ].m_SpreadLightFalloff = 1;
+ ms_Info[E_BLOCK_GLOWSTONE ].m_SpreadLightFalloff = 1;
+ ms_Info[E_BLOCK_IRON_BARS ].m_SpreadLightFalloff = 1;
+ ms_Info[E_BLOCK_IRON_DOOR ].m_SpreadLightFalloff = 1;
+ ms_Info[E_BLOCK_LEAVES ].m_SpreadLightFalloff = 1;
+ ms_Info[E_BLOCK_SIGN_POST ].m_SpreadLightFalloff = 1;
+ ms_Info[E_BLOCK_TORCH ].m_SpreadLightFalloff = 1;
+ ms_Info[E_BLOCK_VINES ].m_SpreadLightFalloff = 1;
+ ms_Info[E_BLOCK_WALLSIGN ].m_SpreadLightFalloff = 1;
+ ms_Info[E_BLOCK_WOODEN_DOOR ].m_SpreadLightFalloff = 1;
+
+ // Light in water and lava dissapears faster:
+ ms_Info[E_BLOCK_LAVA ].m_SpreadLightFalloff = 3;
+ ms_Info[E_BLOCK_STATIONARY_LAVA ].m_SpreadLightFalloff = 3;
+ ms_Info[E_BLOCK_STATIONARY_WATER ].m_SpreadLightFalloff = 3;
+ ms_Info[E_BLOCK_WATER ].m_SpreadLightFalloff = 3;
+
+
+ // Transparent blocks
+ ms_Info[E_BLOCK_ACTIVATOR_RAIL ].m_Transparent = true;
+ ms_Info[E_BLOCK_AIR ].m_Transparent = true;
+ ms_Info[E_BLOCK_BIG_FLOWER ].m_Transparent = true;
+ ms_Info[E_BLOCK_BROWN_MUSHROOM ].m_Transparent = true;
+ ms_Info[E_BLOCK_CARROTS ].m_Transparent = true;
+ ms_Info[E_BLOCK_CHEST ].m_Transparent = true;
+ ms_Info[E_BLOCK_COBWEB ].m_Transparent = true;
+ ms_Info[E_BLOCK_CROPS ].m_Transparent = true;
+ ms_Info[E_BLOCK_DANDELION ].m_Transparent = true;
+ ms_Info[E_BLOCK_DETECTOR_RAIL ].m_Transparent = true;
+ ms_Info[E_BLOCK_ENDER_CHEST ].m_Transparent = true;
+ ms_Info[E_BLOCK_FENCE ].m_Transparent = true;
+ ms_Info[E_BLOCK_FENCE_GATE ].m_Transparent = true;
+ ms_Info[E_BLOCK_FIRE ].m_Transparent = true;
+ ms_Info[E_BLOCK_FLOWER ].m_Transparent = true;
+ ms_Info[E_BLOCK_FLOWER_POT ].m_Transparent = true;
+ ms_Info[E_BLOCK_GLASS ].m_Transparent = true;
+ ms_Info[E_BLOCK_GLASS_PANE ].m_Transparent = true;
+ ms_Info[E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE].m_Transparent = true;
+ ms_Info[E_BLOCK_ICE ].m_Transparent = true;
+ ms_Info[E_BLOCK_IRON_DOOR ].m_Transparent = true;
+ ms_Info[E_BLOCK_LAVA ].m_Transparent = true;
+ ms_Info[E_BLOCK_LEAVES ].m_Transparent = true;
+ ms_Info[E_BLOCK_LEVER ].m_Transparent = true;
+ ms_Info[E_BLOCK_LIGHT_WEIGHTED_PRESSURE_PLATE].m_Transparent = true;
+ ms_Info[E_BLOCK_MELON_STEM ].m_Transparent = true;
+ ms_Info[E_BLOCK_NETHER_BRICK_FENCE ].m_Transparent = true;
+ ms_Info[E_BLOCK_NEW_LEAVES ].m_Transparent = true;
+ ms_Info[E_BLOCK_POTATOES ].m_Transparent = true;
+ ms_Info[E_BLOCK_POWERED_RAIL ].m_Transparent = true;
+ ms_Info[E_BLOCK_PISTON_EXTENSION ].m_Transparent = true;
+ ms_Info[E_BLOCK_PUMPKIN_STEM ].m_Transparent = true;
+ ms_Info[E_BLOCK_RAIL ].m_Transparent = true;
+ ms_Info[E_BLOCK_RED_MUSHROOM ].m_Transparent = true;
+ ms_Info[E_BLOCK_SIGN_POST ].m_Transparent = true;
+ ms_Info[E_BLOCK_SNOW ].m_Transparent = true;
+ ms_Info[E_BLOCK_STAINED_GLASS ].m_Transparent = true;
+ ms_Info[E_BLOCK_STAINED_GLASS_PANE ].m_Transparent = true;
+ ms_Info[E_BLOCK_STATIONARY_LAVA ].m_Transparent = true;
+ ms_Info[E_BLOCK_STATIONARY_WATER ].m_Transparent = true;
+ ms_Info[E_BLOCK_STONE_BUTTON ].m_Transparent = true;
+ ms_Info[E_BLOCK_STONE_PRESSURE_PLATE].m_Transparent = true;
+ ms_Info[E_BLOCK_TALL_GRASS ].m_Transparent = true;
+ ms_Info[E_BLOCK_TORCH ].m_Transparent = true;
+ ms_Info[E_BLOCK_VINES ].m_Transparent = true;
+ ms_Info[E_BLOCK_WALLSIGN ].m_Transparent = true;
+ ms_Info[E_BLOCK_WATER ].m_Transparent = true;
+ ms_Info[E_BLOCK_WOODEN_BUTTON ].m_Transparent = true;
+ ms_Info[E_BLOCK_WOODEN_DOOR ].m_Transparent = true;
+ ms_Info[E_BLOCK_WOODEN_PRESSURE_PLATE].m_Transparent = true;
+
+ // TODO: Any other transparent blocks?
+
+
+ // One hit break blocks:
+ ms_Info[E_BLOCK_ACTIVE_COMPARATOR ].m_OneHitDig = true;
+ ms_Info[E_BLOCK_BIG_FLOWER ].m_OneHitDig = true;
+ ms_Info[E_BLOCK_BROWN_MUSHROOM ].m_OneHitDig = true;
+ ms_Info[E_BLOCK_CARROTS ].m_OneHitDig = true;
+ ms_Info[E_BLOCK_CROPS ].m_OneHitDig = true;
+ ms_Info[E_BLOCK_DANDELION ].m_OneHitDig = true;
+ ms_Info[E_BLOCK_FIRE ].m_OneHitDig = true;
+ ms_Info[E_BLOCK_FLOWER ].m_OneHitDig = true;
+ ms_Info[E_BLOCK_FLOWER_POT ].m_OneHitDig = true;
+ ms_Info[E_BLOCK_INACTIVE_COMPARATOR ].m_OneHitDig = true;
+ ms_Info[E_BLOCK_MELON_STEM ].m_OneHitDig = true;
+ ms_Info[E_BLOCK_POTATOES ].m_OneHitDig = true;
+ ms_Info[E_BLOCK_PUMPKIN_STEM ].m_OneHitDig = true;
+ ms_Info[E_BLOCK_REDSTONE_REPEATER_OFF].m_OneHitDig = true;
+ ms_Info[E_BLOCK_REDSTONE_REPEATER_ON].m_OneHitDig = true;
+ ms_Info[E_BLOCK_REDSTONE_TORCH_OFF ].m_OneHitDig = true;
+ ms_Info[E_BLOCK_REDSTONE_TORCH_ON ].m_OneHitDig = true;
+ ms_Info[E_BLOCK_REDSTONE_WIRE ].m_OneHitDig = true;
+ ms_Info[E_BLOCK_RED_MUSHROOM ].m_OneHitDig = true;
+ ms_Info[E_BLOCK_REEDS ].m_OneHitDig = true;
+ ms_Info[E_BLOCK_SAPLING ].m_OneHitDig = true;
+ ms_Info[E_BLOCK_TNT ].m_OneHitDig = true;
+ ms_Info[E_BLOCK_TALL_GRASS ].m_OneHitDig = true;
+ ms_Info[E_BLOCK_TORCH ].m_OneHitDig = true;
+
+
+ // Blocks that break when pushed by piston:
+ ms_Info[E_BLOCK_ACTIVE_COMPARATOR ].m_PistonBreakable = true;
+ ms_Info[E_BLOCK_AIR ].m_PistonBreakable = true;
+ ms_Info[E_BLOCK_BED ].m_PistonBreakable = true;
+ ms_Info[E_BLOCK_BIG_FLOWER ].m_PistonBreakable = true;
+ ms_Info[E_BLOCK_BROWN_MUSHROOM ].m_PistonBreakable = true;
+ ms_Info[E_BLOCK_COBWEB ].m_PistonBreakable = true;
+ ms_Info[E_BLOCK_CROPS ].m_PistonBreakable = true;
+ ms_Info[E_BLOCK_DANDELION ].m_PistonBreakable = true;
+ ms_Info[E_BLOCK_DEAD_BUSH ].m_PistonBreakable = true;
+ ms_Info[E_BLOCK_FIRE ].m_PistonBreakable = true;
+ ms_Info[E_BLOCK_FLOWER ].m_PistonBreakable = true;
+ ms_Info[E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE].m_PistonBreakable = true;
+ ms_Info[E_BLOCK_INACTIVE_COMPARATOR ].m_PistonBreakable = true;
+ ms_Info[E_BLOCK_IRON_DOOR ].m_PistonBreakable = true;
+ ms_Info[E_BLOCK_JACK_O_LANTERN ].m_PistonBreakable = true;
+ ms_Info[E_BLOCK_LIGHT_WEIGHTED_PRESSURE_PLATE].m_PistonBreakable = true;
+ ms_Info[E_BLOCK_LADDER ].m_PistonBreakable = true;
+ ms_Info[E_BLOCK_LAVA ].m_PistonBreakable = true;
+ ms_Info[E_BLOCK_LEVER ].m_PistonBreakable = true;
+ ms_Info[E_BLOCK_MELON ].m_PistonBreakable = true;
+ ms_Info[E_BLOCK_MELON_STEM ].m_PistonBreakable = true;
+ ms_Info[E_BLOCK_PUMPKIN ].m_PistonBreakable = true;
+ ms_Info[E_BLOCK_PUMPKIN_STEM ].m_PistonBreakable = true;
+ ms_Info[E_BLOCK_REDSTONE_REPEATER_OFF].m_PistonBreakable = true;
+ ms_Info[E_BLOCK_REDSTONE_REPEATER_ON].m_PistonBreakable = true;
+ ms_Info[E_BLOCK_REDSTONE_TORCH_OFF ].m_PistonBreakable = true;
+ ms_Info[E_BLOCK_REDSTONE_TORCH_ON ].m_PistonBreakable = true;
+ ms_Info[E_BLOCK_REDSTONE_WIRE ].m_PistonBreakable = true;
+ ms_Info[E_BLOCK_RED_MUSHROOM ].m_PistonBreakable = true;
+ ms_Info[E_BLOCK_REEDS ].m_PistonBreakable = true;
+ ms_Info[E_BLOCK_SNOW ].m_PistonBreakable = true;
+ ms_Info[E_BLOCK_STATIONARY_LAVA ].m_PistonBreakable = true;
+ ms_Info[E_BLOCK_STATIONARY_WATER ].m_PistonBreakable = true;
+ ms_Info[E_BLOCK_STONE_BUTTON ].m_PistonBreakable = true;
+ ms_Info[E_BLOCK_STONE_PRESSURE_PLATE].m_PistonBreakable = true;
+ ms_Info[E_BLOCK_TALL_GRASS ].m_PistonBreakable = true;
+ ms_Info[E_BLOCK_TORCH ].m_PistonBreakable = true;
+ ms_Info[E_BLOCK_VINES ].m_PistonBreakable = true;
+ ms_Info[E_BLOCK_WATER ].m_PistonBreakable = true;
+ ms_Info[E_BLOCK_WOODEN_BUTTON ].m_PistonBreakable = true;
+ ms_Info[E_BLOCK_WOODEN_DOOR ].m_PistonBreakable = true;
+ ms_Info[E_BLOCK_WOODEN_PRESSURE_PLATE].m_PistonBreakable = true;
+
+
+ // Blocks that cannot be snowed over:
+ ms_Info[E_BLOCK_ACTIVE_COMPARATOR ].m_IsSnowable = false;
+ ms_Info[E_BLOCK_AIR ].m_IsSnowable = false;
+ ms_Info[E_BLOCK_BIG_FLOWER ].m_IsSnowable = false;
+ ms_Info[E_BLOCK_BROWN_MUSHROOM ].m_IsSnowable = false;
+ ms_Info[E_BLOCK_CACTUS ].m_IsSnowable = false;
+ ms_Info[E_BLOCK_CHEST ].m_IsSnowable = false;
+ ms_Info[E_BLOCK_CROPS ].m_IsSnowable = false;
+ ms_Info[E_BLOCK_DANDELION ].m_IsSnowable = false;
+ ms_Info[E_BLOCK_FIRE ].m_IsSnowable = false;
+ ms_Info[E_BLOCK_FLOWER ].m_IsSnowable = false;
+ ms_Info[E_BLOCK_GLASS ].m_IsSnowable = false;
+ ms_Info[E_BLOCK_ICE ].m_IsSnowable = false;
+ ms_Info[E_BLOCK_INACTIVE_COMPARATOR ].m_IsSnowable = false;
+ ms_Info[E_BLOCK_LAVA ].m_IsSnowable = false;
+ ms_Info[E_BLOCK_LILY_PAD ].m_IsSnowable = false;
+ ms_Info[E_BLOCK_REDSTONE_REPEATER_OFF].m_IsSnowable = false;
+ ms_Info[E_BLOCK_REDSTONE_REPEATER_ON].m_IsSnowable = false;
+ ms_Info[E_BLOCK_REDSTONE_TORCH_OFF ].m_IsSnowable = false;
+ ms_Info[E_BLOCK_REDSTONE_TORCH_ON ].m_IsSnowable = false;
+ ms_Info[E_BLOCK_REDSTONE_WIRE ].m_IsSnowable = false;
+ ms_Info[E_BLOCK_RED_MUSHROOM ].m_IsSnowable = false;
+ ms_Info[E_BLOCK_REEDS ].m_IsSnowable = false;
+ ms_Info[E_BLOCK_SAPLING ].m_IsSnowable = false;
+ ms_Info[E_BLOCK_SIGN_POST ].m_IsSnowable = false;
+ ms_Info[E_BLOCK_SNOW ].m_IsSnowable = false;
+ ms_Info[E_BLOCK_STAINED_GLASS ].m_IsSnowable = false;
+ ms_Info[E_BLOCK_STAINED_GLASS_PANE ].m_IsSnowable = false;
+ ms_Info[E_BLOCK_STATIONARY_LAVA ].m_IsSnowable = false;
+ ms_Info[E_BLOCK_STATIONARY_WATER ].m_IsSnowable = false;
+ ms_Info[E_BLOCK_TALL_GRASS ].m_IsSnowable = false;
+ ms_Info[E_BLOCK_TNT ].m_IsSnowable = false;
+ ms_Info[E_BLOCK_TORCH ].m_IsSnowable = false;
+ ms_Info[E_BLOCK_VINES ].m_IsSnowable = false;
+ ms_Info[E_BLOCK_WALLSIGN ].m_IsSnowable = false;
+ ms_Info[E_BLOCK_WATER ].m_IsSnowable = false;
+
+
+ // Blocks that don't drop without a special tool:
+ ms_Info[E_BLOCK_BRICK ].m_RequiresSpecialTool = true;
+ ms_Info[E_BLOCK_CAULDRON ].m_RequiresSpecialTool = true;
+ ms_Info[E_BLOCK_COAL_ORE ].m_RequiresSpecialTool = true;
+ ms_Info[E_BLOCK_COBBLESTONE ].m_RequiresSpecialTool = true;
+ ms_Info[E_BLOCK_COBBLESTONE_STAIRS ].m_RequiresSpecialTool = true;
+ ms_Info[E_BLOCK_COBWEB ].m_RequiresSpecialTool = true;
+ ms_Info[E_BLOCK_DIAMOND_BLOCK ].m_RequiresSpecialTool = true;
+ ms_Info[E_BLOCK_DIAMOND_ORE ].m_RequiresSpecialTool = true;
+ ms_Info[E_BLOCK_DOUBLE_STONE_SLAB ].m_RequiresSpecialTool = true;
+ ms_Info[E_BLOCK_EMERALD_ORE ].m_RequiresSpecialTool = true;
+ ms_Info[E_BLOCK_END_STONE ].m_RequiresSpecialTool = true;
+ ms_Info[E_BLOCK_GOLD_BLOCK ].m_RequiresSpecialTool = true;
+ ms_Info[E_BLOCK_GOLD_ORE ].m_RequiresSpecialTool = true;
+ ms_Info[E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE].m_RequiresSpecialTool = true;
+ ms_Info[E_BLOCK_IRON_BLOCK ].m_RequiresSpecialTool = true;
+ ms_Info[E_BLOCK_IRON_ORE ].m_RequiresSpecialTool = true;
+ ms_Info[E_BLOCK_LAPIS_BLOCK ].m_RequiresSpecialTool = true;
+ ms_Info[E_BLOCK_LAPIS_ORE ].m_RequiresSpecialTool = true;
+ ms_Info[E_BLOCK_LIGHT_WEIGHTED_PRESSURE_PLATE].m_RequiresSpecialTool = true;
+ ms_Info[E_BLOCK_MOSSY_COBBLESTONE ].m_RequiresSpecialTool = true;
+ ms_Info[E_BLOCK_NETHERRACK ].m_RequiresSpecialTool = true;
+ ms_Info[E_BLOCK_NETHER_BRICK ].m_RequiresSpecialTool = true;
+ ms_Info[E_BLOCK_NETHER_BRICK_STAIRS ].m_RequiresSpecialTool = true;
+ ms_Info[E_BLOCK_OBSIDIAN ].m_RequiresSpecialTool = true;
+ ms_Info[E_BLOCK_REDSTONE_ORE ].m_RequiresSpecialTool = true;
+ ms_Info[E_BLOCK_REDSTONE_ORE_GLOWING].m_RequiresSpecialTool = true;
+ ms_Info[E_BLOCK_SANDSTONE ].m_RequiresSpecialTool = true;
+ ms_Info[E_BLOCK_SANDSTONE_STAIRS ].m_RequiresSpecialTool = true;
+ ms_Info[E_BLOCK_SNOW ].m_RequiresSpecialTool = true;
+ ms_Info[E_BLOCK_STONE ].m_RequiresSpecialTool = true;
+ ms_Info[E_BLOCK_STONE_BRICKS ].m_RequiresSpecialTool = true;
+ ms_Info[E_BLOCK_STONE_BRICK_STAIRS ].m_RequiresSpecialTool = true;
+ ms_Info[E_BLOCK_STONE_PRESSURE_PLATE].m_RequiresSpecialTool = true;
+ ms_Info[E_BLOCK_STONE_SLAB ].m_RequiresSpecialTool = true;
+ ms_Info[E_BLOCK_VINES ].m_RequiresSpecialTool = true;
+
+
+ // Nonsolid blocks:
+ ms_Info[E_BLOCK_ACTIVATOR_RAIL ].m_IsSolid = false;
+ ms_Info[E_BLOCK_AIR ].m_IsSolid = false;
+ ms_Info[E_BLOCK_BIG_FLOWER ].m_IsSolid = false;
+ ms_Info[E_BLOCK_BROWN_MUSHROOM ].m_IsSolid = false;
+ ms_Info[E_BLOCK_CARROTS ].m_IsSolid = false;
+ ms_Info[E_BLOCK_COBWEB ].m_IsSolid = false;
+ ms_Info[E_BLOCK_CROPS ].m_IsSolid = false;
+ ms_Info[E_BLOCK_DANDELION ].m_IsSolid = false;
+ ms_Info[E_BLOCK_DETECTOR_RAIL ].m_IsSolid = false;
+ ms_Info[E_BLOCK_END_PORTAL ].m_IsSolid = false;
+ ms_Info[E_BLOCK_FIRE ].m_IsSolid = false;
+ ms_Info[E_BLOCK_FLOWER ].m_IsSolid = false;
+ ms_Info[E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE].m_IsSolid = false;
+ ms_Info[E_BLOCK_LAVA ].m_IsSolid = false;
+ ms_Info[E_BLOCK_LEVER ].m_IsSolid = false;
+ ms_Info[E_BLOCK_LIGHT_WEIGHTED_PRESSURE_PLATE].m_IsSolid = false;
+ ms_Info[E_BLOCK_MELON_STEM ].m_IsSolid = false;
+ ms_Info[E_BLOCK_NETHER_PORTAL ].m_IsSolid = false;
+ ms_Info[E_BLOCK_PISTON_EXTENSION ].m_IsSolid = false;
+ ms_Info[E_BLOCK_POTATOES ].m_IsSolid = false;
+ ms_Info[E_BLOCK_POWERED_RAIL ].m_IsSolid = false;
+ ms_Info[E_BLOCK_RAIL ].m_IsSolid = false;
+ ms_Info[E_BLOCK_REDSTONE_TORCH_OFF ].m_IsSolid = false;
+ ms_Info[E_BLOCK_REDSTONE_TORCH_ON ].m_IsSolid = false;
+ ms_Info[E_BLOCK_REDSTONE_WIRE ].m_IsSolid = false;
+ ms_Info[E_BLOCK_RED_MUSHROOM ].m_IsSolid = false;
+ ms_Info[E_BLOCK_REEDS ].m_IsSolid = false;
+ ms_Info[E_BLOCK_SAPLING ].m_IsSolid = false;
+ ms_Info[E_BLOCK_SIGN_POST ].m_IsSolid = false;
+ ms_Info[E_BLOCK_SNOW ].m_IsSolid = false;
+ ms_Info[E_BLOCK_STATIONARY_LAVA ].m_IsSolid = false;
+ ms_Info[E_BLOCK_STATIONARY_WATER ].m_IsSolid = false;
+ ms_Info[E_BLOCK_STONE_BUTTON ].m_IsSolid = false;
+ ms_Info[E_BLOCK_STONE_PRESSURE_PLATE].m_IsSolid = false;
+ ms_Info[E_BLOCK_TALL_GRASS ].m_IsSolid = false;
+ ms_Info[E_BLOCK_TORCH ].m_IsSolid = false;
+ ms_Info[E_BLOCK_TRIPWIRE ].m_IsSolid = false;
+ ms_Info[E_BLOCK_VINES ].m_IsSolid = false;
+ ms_Info[E_BLOCK_WALLSIGN ].m_IsSolid = false;
+ ms_Info[E_BLOCK_WATER ].m_IsSolid = false;
+ ms_Info[E_BLOCK_WOODEN_BUTTON ].m_IsSolid = false;
+ ms_Info[E_BLOCK_WOODEN_PRESSURE_PLATE].m_IsSolid = false;
+ ms_Info[E_BLOCK_WOODEN_SLAB ].m_IsSolid = false;
+
+
+ // Torch placeable blocks:
+ ms_Info[E_BLOCK_NEW_LOG ].m_FullyOccupiesVoxel = true;
+ ms_Info[E_BLOCK_BEDROCK ].m_FullyOccupiesVoxel = true;
+ ms_Info[E_BLOCK_BLOCK_OF_COAL ].m_FullyOccupiesVoxel = true;
+ ms_Info[E_BLOCK_BLOCK_OF_REDSTONE ].m_FullyOccupiesVoxel = true;
+ ms_Info[E_BLOCK_BOOKCASE ].m_FullyOccupiesVoxel = true;
+ ms_Info[E_BLOCK_BRICK ].m_FullyOccupiesVoxel = true;
+ ms_Info[E_BLOCK_CLAY ].m_FullyOccupiesVoxel = true;
+ ms_Info[E_BLOCK_COAL_ORE ].m_FullyOccupiesVoxel = true;
+ ms_Info[E_BLOCK_COBBLESTONE ].m_FullyOccupiesVoxel = true;
+ ms_Info[E_BLOCK_COMMAND_BLOCK ].m_FullyOccupiesVoxel = true;
+ ms_Info[E_BLOCK_CRAFTING_TABLE ].m_FullyOccupiesVoxel = true;
+ ms_Info[E_BLOCK_DIAMOND_BLOCK ].m_FullyOccupiesVoxel = true;
+ ms_Info[E_BLOCK_DIAMOND_ORE ].m_FullyOccupiesVoxel = true;
+ ms_Info[E_BLOCK_DIRT ].m_FullyOccupiesVoxel = true;
+ ms_Info[E_BLOCK_DISPENSER ].m_FullyOccupiesVoxel = true;
+ ms_Info[E_BLOCK_DOUBLE_STONE_SLAB ].m_FullyOccupiesVoxel = true;
+ ms_Info[E_BLOCK_DOUBLE_WOODEN_SLAB ].m_FullyOccupiesVoxel = true;
+ ms_Info[E_BLOCK_DROPPER ].m_FullyOccupiesVoxel = true;
+ ms_Info[E_BLOCK_EMERALD_BLOCK ].m_FullyOccupiesVoxel = true;
+ ms_Info[E_BLOCK_EMERALD_ORE ].m_FullyOccupiesVoxel = true;
+ ms_Info[E_BLOCK_END_STONE ].m_FullyOccupiesVoxel = true;
+ ms_Info[E_BLOCK_FURNACE ].m_FullyOccupiesVoxel = true;
+ ms_Info[E_BLOCK_GLOWSTONE ].m_FullyOccupiesVoxel = true;
+ ms_Info[E_BLOCK_GOLD_BLOCK ].m_FullyOccupiesVoxel = true;
+ ms_Info[E_BLOCK_GOLD_ORE ].m_FullyOccupiesVoxel = true;
+ ms_Info[E_BLOCK_GRASS ].m_FullyOccupiesVoxel = true;
+ ms_Info[E_BLOCK_GRAVEL ].m_FullyOccupiesVoxel = true;
+ ms_Info[E_BLOCK_HARDENED_CLAY ].m_FullyOccupiesVoxel = true;
+ ms_Info[E_BLOCK_HAY_BALE ].m_FullyOccupiesVoxel = true;
+ ms_Info[E_BLOCK_HUGE_BROWN_MUSHROOM ].m_FullyOccupiesVoxel = true;
+ ms_Info[E_BLOCK_HUGE_RED_MUSHROOM ].m_FullyOccupiesVoxel = true;
+ ms_Info[E_BLOCK_IRON_BLOCK ].m_FullyOccupiesVoxel = true;
+ ms_Info[E_BLOCK_IRON_ORE ].m_FullyOccupiesVoxel = true;
+ ms_Info[E_BLOCK_JACK_O_LANTERN ].m_FullyOccupiesVoxel = true;
+ ms_Info[E_BLOCK_JUKEBOX ].m_FullyOccupiesVoxel = true;
+ ms_Info[E_BLOCK_LAPIS_BLOCK ].m_FullyOccupiesVoxel = true;
+ ms_Info[E_BLOCK_LAPIS_ORE ].m_FullyOccupiesVoxel = true;
+ ms_Info[E_BLOCK_LOG ].m_FullyOccupiesVoxel = true;
+ ms_Info[E_BLOCK_MELON ].m_FullyOccupiesVoxel = true;
+ ms_Info[E_BLOCK_MOSSY_COBBLESTONE ].m_FullyOccupiesVoxel = true;
+ ms_Info[E_BLOCK_MYCELIUM ].m_FullyOccupiesVoxel = true;
+ ms_Info[E_BLOCK_NETHERRACK ].m_FullyOccupiesVoxel = true;
+ ms_Info[E_BLOCK_NETHER_BRICK ].m_FullyOccupiesVoxel = true;
+ ms_Info[E_BLOCK_NETHER_QUARTZ_ORE ].m_FullyOccupiesVoxel = true;
+ ms_Info[E_BLOCK_NOTE_BLOCK ].m_FullyOccupiesVoxel = true;
+ ms_Info[E_BLOCK_OBSIDIAN ].m_FullyOccupiesVoxel = true;
+ ms_Info[E_BLOCK_PACKED_ICE ].m_FullyOccupiesVoxel = true;
+ ms_Info[E_BLOCK_PLANKS ].m_FullyOccupiesVoxel = true;
+ ms_Info[E_BLOCK_PUMPKIN ].m_FullyOccupiesVoxel = true;
+ ms_Info[E_BLOCK_QUARTZ_BLOCK ].m_FullyOccupiesVoxel = true;
+ ms_Info[E_BLOCK_REDSTONE_LAMP_OFF ].m_FullyOccupiesVoxel = true;
+ ms_Info[E_BLOCK_REDSTONE_LAMP_ON ].m_FullyOccupiesVoxel = true;
+ ms_Info[E_BLOCK_REDSTONE_ORE ].m_FullyOccupiesVoxel = true;
+ ms_Info[E_BLOCK_REDSTONE_ORE_GLOWING].m_FullyOccupiesVoxel = true;
+ ms_Info[E_BLOCK_SANDSTONE ].m_FullyOccupiesVoxel = true;
+ ms_Info[E_BLOCK_SAND ].m_FullyOccupiesVoxel = true;
+ ms_Info[E_BLOCK_SILVERFISH_EGG ].m_FullyOccupiesVoxel = true;
+ ms_Info[E_BLOCK_SPONGE ].m_FullyOccupiesVoxel = true;
+ ms_Info[E_BLOCK_STAINED_CLAY ].m_FullyOccupiesVoxel = true;
+ ms_Info[E_BLOCK_WOOL ].m_FullyOccupiesVoxel = true;
+ ms_Info[E_BLOCK_STONE ].m_FullyOccupiesVoxel = true;
+ ms_Info[E_BLOCK_STONE_BRICKS ].m_FullyOccupiesVoxel = true;
+}
+
+
+
+
+
+// This is actually just some code that needs to run at program startup, so it is wrapped into a global var's constructor:
+class cBlockInfoInitializer
+{
+public:
+ cBlockInfoInitializer(void)
+ {
+ BlockInfo::Initialize();
+ }
+} BlockInfoInitializer;
+
+
+
+
+
diff --git a/src/BlockInfo.h b/src/BlockInfo.h
new file mode 100644
index 000000000..1e09b0df5
--- /dev/null
+++ b/src/BlockInfo.h
@@ -0,0 +1,54 @@
+
+#pragma once
+
+
+
+
+
+
+class BlockInfo
+{
+public:
+
+ BlockInfo();
+
+ /** (Re-)Initializes the internal BlockInfo structures. */
+ static void Initialize(void);
+
+ /** Returns the associated BlockInfo structure. */
+ static BlockInfo & GetById(unsigned int a_ID);
+
+ NIBBLETYPE m_LightValue;
+ NIBBLETYPE m_SpreadLightFalloff;
+
+ bool m_Transparent;
+ bool m_OneHitDig;
+ bool m_PistonBreakable;
+ bool m_IsSnowable;
+ bool m_RequiresSpecialTool;
+ bool m_IsSolid;
+ bool m_FullyOccupiesVoxel;
+
+
+ inline static NIBBLETYPE GetLightValue (unsigned int a_ID) { return GetById(a_ID).m_LightValue; }
+ inline static NIBBLETYPE GetSpreadLightFalloff(unsigned int a_ID) { return GetById(a_ID).m_SpreadLightFalloff; }
+ inline static bool IsTransparent (unsigned int a_ID) { return GetById(a_ID).m_Transparent; }
+ inline static bool IsOneHitDig (unsigned int a_ID) { return GetById(a_ID).m_OneHitDig; }
+ inline static bool IsPistoneBreakable (unsigned int a_ID) { return GetById(a_ID).m_PistonBreakable; }
+ inline static bool IsSnowable (unsigned int a_ID) { return GetById(a_ID).m_IsSnowable; }
+ inline static bool RequiresSpecialTool (unsigned int a_ID) { return GetById(a_ID).m_RequiresSpecialTool; }
+ inline static bool IsSolid (unsigned int a_ID) { return GetById(a_ID).m_IsSolid; }
+ inline static bool FullyOccupiesVoxel (unsigned int a_ID) { return GetById(a_ID).m_FullyOccupiesVoxel; }
+
+
+protected:
+
+ // TODO xdot: Change to std::vector to support dynamic block IDs
+ static BlockInfo ms_Info[256];
+
+
+};
+
+
+
+
--
cgit v1.2.3
From 0acfbdd91283c96fd0f371f51029a72d6c9cd3de Mon Sep 17 00:00:00 2001
From: Tycho
Date: Sat, 1 Mar 2014 09:47:27 -0800
Subject: Final implementation of MetaRotater
---
src/Blocks/MetaRotater.h | 96 +++++++++++++++++++++++++-----------------------
1 file changed, 51 insertions(+), 45 deletions(-)
diff --git a/src/Blocks/MetaRotater.h b/src/Blocks/MetaRotater.h
index f1656f1bd..b83ed177a 100644
--- a/src/Blocks/MetaRotater.h
+++ b/src/Blocks/MetaRotater.h
@@ -1,7 +1,7 @@
#pragma once
-template
+template
class cMetaRotater : public Base
{
public:
@@ -19,64 +19,70 @@ public:
};
-template
-NIBBLETYPE cMetaRotater::MetaRotateCW(NIBBLETYPE a_Meta)
+template
+NIBBLETYPE cMetaRotater::MetaRotateCW(NIBBLETYPE a_Meta)
{
-NIBBLETYPE OtherMeta = a_Meta & (~BitFilter);
-switch (a_Meta & BitFilter)
-{
-case South: return West | OtherMeta;
-case West: return North | OtherMeta;
-case North: return East | OtherMeta;
-case East: return South | OtherMeta;
-}
-ASSERT(!"Invalid Meta value");
-return a_Meta;
+ NIBBLETYPE OtherMeta = a_Meta & (~BitFilter);
+ switch (a_Meta & BitFilter)
+ {
+ case South: return West | OtherMeta;
+ case West: return North | OtherMeta;
+ case North: return East | OtherMeta;
+ case East: return South | OtherMeta;
+ }
+ if(AssertIfNotMatched)
+ {
+ ASSERT(!"Invalid Meta value");
+ return a_Meta;
+ }
}
-template
-NIBBLETYPE cMetaRotater::MetaRotateCCW(NIBBLETYPE a_Meta)
+template
+NIBBLETYPE cMetaRotater::MetaRotateCCW(NIBBLETYPE a_Meta)
{
-NIBBLETYPE OtherMeta = a_Meta & (~BitFilter);
-switch (a_Meta & BitFilter)
-{
-case South: return East | OtherMeta;
-case East: return North | OtherMeta;
-case North: return West | OtherMeta;
-case West: return South | OtherMeta;
-}
-ASSERT(!"Invalid Meta value");
-return a_Meta;
+ NIBBLETYPE OtherMeta = a_Meta & (~BitFilter);
+ switch (a_Meta & BitFilter)
+ {
+ case South: return East | OtherMeta;
+ case East: return North | OtherMeta;
+ case North: return West | OtherMeta;
+ case West: return South | OtherMeta;
+ }
+ if(AssertIfNotMatched)
+ {
+ ASSERT(!"Invalid Meta value");
+ return a_Meta;
+ }
}
-template
-NIBBLETYPE cMetaRotater::MetaMirrorXY(NIBBLETYPE a_Meta)
+template
+NIBBLETYPE cMetaRotater::MetaMirrorXY(NIBBLETYPE a_Meta)
{
-NIBBLETYPE OtherMeta = a_Meta & (~BitFilter);
-switch (a_Meta & BitFilter)
-{
-case South: return North | OtherMeta;
-case North: return South | OtherMeta;
-}
-// Not Facing North or South; No change.
-return a_Meta;
+ NIBBLETYPE OtherMeta = a_Meta & (~BitFilter);
+ switch (a_Meta & BitFilter)
+ {
+ case South: return North | OtherMeta;
+ case North: return South | OtherMeta;
+ }
+ // Not Facing North or South; No change.
+ return a_Meta;
}
-template
-NIBBLETYPE cMetaRotater::MetaMirrorYZ(NIBBLETYPE a_Meta)
+template
+NIBBLETYPE cMetaRotater::MetaMirrorYZ(NIBBLETYPE a_Meta)
{
-NIBBLETYPE OtherMeta = a_Meta & (~BitFilter);
-switch (a_Meta & BitFilter)
-{
-case West: return East | OtherMeta;
-case East: return West | OtherMeta;
-}
-// Not Facing East or West; No change.
-return a_Meta;
+ NIBBLETYPE OtherMeta = a_Meta & (~BitFilter);
+ switch (a_Meta & BitFilter)
+ {
+ case West: return East | OtherMeta;
+ case East: return West | OtherMeta;
+ }
+ // Not Facing East or West; No change.
+ return a_Meta;
}
--
cgit v1.2.3
From 65edffd5b04623dcd4cebbd1afb2575e98eee5db Mon Sep 17 00:00:00 2001
From: Tycho
Date: Sat, 1 Mar 2014 10:04:50 -0800
Subject: Implemented Rotations
---
src/Blocks/BlockBed.h | 4 +--
src/Blocks/BlockButton.h | 5 ++--
src/Blocks/BlockChest.h | 5 ++--
src/Blocks/BlockComparator.h | 5 ++--
src/Blocks/BlockDoor.h | 5 ++--
src/Blocks/BlockDropSpenser.h | 1 +
src/Blocks/BlockEnderchest.h | 2 +-
src/Blocks/BlockFenceGate.h | 6 ++--
src/Blocks/BlockStairs.h | 68 ++-----------------------------------------
src/Blocks/BlockTorch.h | 67 ++----------------------------------------
src/Blocks/BlockVine.h | 30 ++-----------------
11 files changed, 28 insertions(+), 170 deletions(-)
diff --git a/src/Blocks/BlockBed.h b/src/Blocks/BlockBed.h
index 6e8884114..d8a796735 100644
--- a/src/Blocks/BlockBed.h
+++ b/src/Blocks/BlockBed.h
@@ -12,11 +12,11 @@
class cBlockBedHandler :
- public cMetaRotater
+ public cMetaRotater
{
public:
cBlockBedHandler(BLOCKTYPE a_BlockType)
- : cMetaRotater(a_BlockType)
+ : cMetaRotater(a_BlockType)
{
}
diff --git a/src/Blocks/BlockButton.h b/src/Blocks/BlockButton.h
index 5a4bf7c96..4daa03005 100644
--- a/src/Blocks/BlockButton.h
+++ b/src/Blocks/BlockButton.h
@@ -2,16 +2,17 @@
#include "BlockHandler.h"
#include "Chunk.h"
+#include "MetaRotater.h"
class cBlockButtonHandler :
- public cMetaRotater
+ public cMetaRotater
{
public:
cBlockButtonHandler(BLOCKTYPE a_BlockType)
- : cMetaRotater(a_BlockType)
+ : cMetaRotater(a_BlockType)
{
}
diff --git a/src/Blocks/BlockChest.h b/src/Blocks/BlockChest.h
index 4ab23bced..6a13e826e 100644
--- a/src/Blocks/BlockChest.h
+++ b/src/Blocks/BlockChest.h
@@ -4,17 +4,18 @@
#include "BlockEntity.h"
#include "../BlockArea.h"
#include "../Entities/Player.h"
+#include "MetaRotater.h"
class cBlockChestHandler :
- public cMetaRotater
+ public cMetaRotater
{
public:
cBlockChestHandler(BLOCKTYPE a_BlockType)
- : cMetaRotater(a_BlockType)
+ : cMetaRotater(a_BlockType)
{
}
diff --git a/src/Blocks/BlockComparator.h b/src/Blocks/BlockComparator.h
index 7e672eece..238e687ab 100644
--- a/src/Blocks/BlockComparator.h
+++ b/src/Blocks/BlockComparator.h
@@ -3,17 +3,18 @@
#include "BlockHandler.h"
#include "BlockRedstoneRepeater.h"
+#include "MetaRotater.h"
class cBlockComparatorHandler :
- public cMetaRotater
+ public cMetaRotater
{
public:
cBlockComparatorHandler(BLOCKTYPE a_BlockType)
- : cMetaRotater(a_BlockType)
+ : cMetaRotater(a_BlockType)
{
}
diff --git a/src/Blocks/BlockDoor.h b/src/Blocks/BlockDoor.h
index c3647b203..8e3f2d83f 100644
--- a/src/Blocks/BlockDoor.h
+++ b/src/Blocks/BlockDoor.h
@@ -4,14 +4,15 @@
#include "BlockHandler.h"
#include "../Entities/Player.h"
#include "Chunk.h"
+#include "MetaRotater.h"
class cBlockDoorHandler :
- public cMetaRotater
+ public cMetaRotater
{
- typedef super cMetaRotater;
+ typedef super cMetaRotater;
public:
cBlockDoorHandler(BLOCKTYPE a_BlockType);
diff --git a/src/Blocks/BlockDropSpenser.h b/src/Blocks/BlockDropSpenser.h
index 2253fcd1b..73937577a 100644
--- a/src/Blocks/BlockDropSpenser.h
+++ b/src/Blocks/BlockDropSpenser.h
@@ -6,6 +6,7 @@
#pragma once
#include "../Piston.h"
+#include "MetaRotater.h"
diff --git a/src/Blocks/BlockEnderchest.h b/src/Blocks/BlockEnderchest.h
index ed3f37013..6ca83399a 100644
--- a/src/Blocks/BlockEnderchest.h
+++ b/src/Blocks/BlockEnderchest.h
@@ -2,7 +2,7 @@
#pragma once
#include "BlockEntity.h"
-
+#include "MetaRotater.h"
diff --git a/src/Blocks/BlockFenceGate.h b/src/Blocks/BlockFenceGate.h
index 035579e8e..c33393590 100644
--- a/src/Blocks/BlockFenceGate.h
+++ b/src/Blocks/BlockFenceGate.h
@@ -2,17 +2,17 @@
#pragma once
#include "BlockHandler.h"
-
+#include "MetaRotater.h"
class cBlockFenceGateHandler :
- public cMetaRotater
+ public cMetaRotater
{
public:
cBlockFenceGateHandler(BLOCKTYPE a_BlockType) :
- cMetaRotater(a_BlockType)
+ cMetaRotater(a_BlockType)
{
}
diff --git a/src/Blocks/BlockStairs.h b/src/Blocks/BlockStairs.h
index c1887bc46..f07afc9f0 100644
--- a/src/Blocks/BlockStairs.h
+++ b/src/Blocks/BlockStairs.h
@@ -2,17 +2,17 @@
#pragma once
#include "BlockHandler.h"
-
+#include "MetaRotater.h"
class cBlockStairsHandler :
- public cBlockHandler
+ public cMetaRotater
{
public:
cBlockStairsHandler(BLOCKTYPE a_BlockType) :
- cBlockHandler(a_BlockType)
+ cMetaRotater(a_BlockType)
{
}
@@ -96,54 +96,6 @@ public:
}
- virtual NIBBLETYPE MetaRotateCCW(NIBBLETYPE a_Meta) override
- {
- // Bits 3 and 4 stay, the rest is swapped around according to a table:
- NIBBLETYPE TopBits = (a_Meta & 0x0c);
- switch (a_Meta & 0x03)
- {
- case 0x00: return TopBits | 0x03; // East -> North
- case 0x01: return TopBits | 0x02; // West -> South
- case 0x02: return TopBits | 0x00; // South -> East
- case 0x03: return TopBits | 0x01; // North -> West
- }
- // Not reachable, but to avoid a compiler warning:
- return 0;
- }
-
-
- virtual NIBBLETYPE MetaRotateCW(NIBBLETYPE a_Meta) override
- {
- // Bits 3 and 4 stay, the rest is swapped around according to a table:
- NIBBLETYPE TopBits = (a_Meta & 0x0c);
- switch (a_Meta & 0x03)
- {
- case 0x00: return TopBits | 0x02; // East -> South
- case 0x01: return TopBits | 0x03; // West -> North
- case 0x02: return TopBits | 0x01; // South -> West
- case 0x03: return TopBits | 0x00; // North -> East
- }
- // Not reachable, but to avoid a compiler warning:
- return 0;
- }
-
-
- virtual NIBBLETYPE MetaMirrorXY(NIBBLETYPE a_Meta) override
- {
- // Bits 3 and 4 stay, the rest is swapped around according to a table:
- NIBBLETYPE TopBits = (a_Meta & 0x0c);
- switch (a_Meta & 0x03)
- {
- case 0x00: return TopBits | 0x00; // East -> East
- case 0x01: return TopBits | 0x01; // West -> West
- case 0x02: return TopBits | 0x03; // South -> North
- case 0x03: return TopBits | 0x02; // North -> South
- }
- // Not reachable, but to avoid a compiler warning:
- return 0;
- }
-
-
virtual NIBBLETYPE MetaMirrorXZ(NIBBLETYPE a_Meta) override
{
// Toggle bit 3:
@@ -151,20 +103,6 @@ public:
}
- virtual NIBBLETYPE MetaMirrorYZ(NIBBLETYPE a_Meta) override
- {
- // Bits 3 and 4 stay, the rest is swapped around according to a table:
- NIBBLETYPE TopBits = (a_Meta & 0x0c);
- switch (a_Meta & 0x03)
- {
- case 0x00: return TopBits | 0x01; // East -> West
- case 0x01: return TopBits | 0x00; // West -> East
- case 0x02: return TopBits | 0x02; // South -> South
- case 0x03: return TopBits | 0x03; // North -> North
- }
- // Not reachable, but to avoid a compiler warning:
- return 0;
- }
} ;
diff --git a/src/Blocks/BlockTorch.h b/src/Blocks/BlockTorch.h
index f2a4c8665..59c896857 100644
--- a/src/Blocks/BlockTorch.h
+++ b/src/Blocks/BlockTorch.h
@@ -2,17 +2,17 @@
#include "BlockHandler.h"
#include "../Chunk.h"
-
+#include "MetaRotater.h"
class cBlockTorchHandler :
- public cBlockHandler
+ public cMetaRotater
{
public:
cBlockTorchHandler(BLOCKTYPE a_BlockType)
- : cBlockHandler(a_BlockType)
+ : cMetaRotater(a_BlockType)
{
}
@@ -185,67 +185,6 @@ public:
{
return "step.wood";
}
-
-
- virtual NIBBLETYPE MetaRotateCCW(NIBBLETYPE a_Meta) override
- {
- // Bit 4 stays, the rest is swapped around according to a table:
- NIBBLETYPE TopBits = (a_Meta & 0x08);
- switch (a_Meta & 0x07)
- {
- case 0x01: return TopBits | 0x04; // East -> North
- case 0x02: return TopBits | 0x03; // West -> South
- case 0x03: return TopBits | 0x01; // South -> East
- case 0x04: return TopBits | 0x02; // North -> West
- default: return a_Meta; // Floor -> Floor
- }
- }
-
-
- virtual NIBBLETYPE MetaRotateCW(NIBBLETYPE a_Meta) override
- {
- // Bit 4 stays, the rest is swapped around according to a table:
- NIBBLETYPE TopBits = (a_Meta & 0x08);
- switch (a_Meta & 0x07)
- {
- case 0x01: return TopBits | 0x03; // East -> South
- case 0x02: return TopBits | 0x04; // West -> North
- case 0x03: return TopBits | 0x02; // South -> West
- case 0x04: return TopBits | 0x01; // North -> East
- default: return a_Meta; // Floor -> Floor
- }
- }
-
-
- virtual NIBBLETYPE MetaMirrorXY(NIBBLETYPE a_Meta) override
- {
- // Bit 4 stays, the rest is swapped around according to a table:
- NIBBLETYPE TopBits = (a_Meta & 0x08);
- switch (a_Meta & 0x07)
- {
- case 0x03: return TopBits | 0x04; // South -> North
- case 0x04: return TopBits | 0x03; // North -> South
- default: return a_Meta; // Keep the rest
- }
- }
-
-
- // Mirroring around the XZ plane doesn't make sense for floor torches,
- // the others stay the same, so let's keep all the metas the same.
- // The base class does tht for us, no need to override MetaMirrorXZ()
-
-
- virtual NIBBLETYPE MetaMirrorYZ(NIBBLETYPE a_Meta) override
- {
- // Bit 4 stays, the rest is swapped around according to a table:
- NIBBLETYPE TopBits = (a_Meta & 0x08);
- switch (a_Meta & 0x07)
- {
- case 0x01: return TopBits | 0x02; // East -> West
- case 0x02: return TopBits | 0x01; // West -> East
- default: return a_Meta; // Keep the rest
- }
- }
} ;
diff --git a/src/Blocks/BlockVine.h b/src/Blocks/BlockVine.h
index ee7dcee8a..9e2105f67 100644
--- a/src/Blocks/BlockVine.h
+++ b/src/Blocks/BlockVine.h
@@ -2,17 +2,17 @@
#pragma once
#include "BlockHandler.h"
-
+#include "MetaRotater.h"
class cBlockVineHandler :
- public cBlockHandler
+ public cMetaRotater
{
public:
cBlockVineHandler(BLOCKTYPE a_BlockType)
- : cBlockHandler(a_BlockType)
+ : cMetaRotater(a_BlockType)
{
}
@@ -169,31 +169,7 @@ public:
a_World->SetBlock(X, Y - 1, Z, E_BLOCK_VINES, a_World->GetBlockMeta(X, Y, Z));
}
}
-
- virtual NIBBLETYPE MetaRotateCCW(NIBBLETYPE a_Meta) override
- {
- return ((a_Meta >> 1) | (a_Meta << 3)) & 0x0f; // Rotate bits to the right
- }
-
- virtual NIBBLETYPE MetaRotateCW(NIBBLETYPE a_Meta) override
- {
- return ((a_Meta << 1) | (a_Meta >> 3)) & 0x0f; // Rotate bits to the left
- }
-
-
- virtual NIBBLETYPE MetaMirrorXY(NIBBLETYPE a_Meta) override
- {
- // Bits 2 and 4 stay, bits 1 and 3 swap
- return ((a_Meta & 0x0a) | ((a_Meta & 0x01) << 2) | ((a_Meta & 0x04) >> 2));
- }
-
-
- virtual NIBBLETYPE MetaMirrorYZ(NIBBLETYPE a_Meta) override
- {
- // Bits 1 and 3 stay, bits 2 and 4 swap
- return ((a_Meta & 0x05) | ((a_Meta & 0x02) << 2) | ((a_Meta & 0x08) >> 2));
- }
} ;
--
cgit v1.2.3
From 5093b75ef1488b3687e1c54c893ab68b4475e451 Mon Sep 17 00:00:00 2001
From: Tycho
Date: Sat, 1 Mar 2014 10:14:24 -0800
Subject: Revesed typedef
---
src/Blocks/BlockDoor.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/Blocks/BlockDoor.h b/src/Blocks/BlockDoor.h
index 8e3f2d83f..0caeb7dba 100644
--- a/src/Blocks/BlockDoor.h
+++ b/src/Blocks/BlockDoor.h
@@ -12,7 +12,7 @@
class cBlockDoorHandler :
public cMetaRotater
{
- typedef super cMetaRotater;
+ typedef cMetaRotater super;
public:
cBlockDoorHandler(BLOCKTYPE a_BlockType);
--
cgit v1.2.3
From 1e1d89fd2005ee634094fd3d55638965d41acecf Mon Sep 17 00:00:00 2001
From: Tycho
Date: Sat, 1 Mar 2014 10:17:55 -0800
Subject: Fixed errors
---
src/Blocks/BlockChest.h | 2 +-
src/Blocks/BlockDropSpenser.h | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/Blocks/BlockChest.h b/src/Blocks/BlockChest.h
index 6a13e826e..1646454a7 100644
--- a/src/Blocks/BlockChest.h
+++ b/src/Blocks/BlockChest.h
@@ -15,7 +15,7 @@ class cBlockChestHandler :
{
public:
cBlockChestHandler(BLOCKTYPE a_BlockType)
- : cMetaRotater(a_BlockType)
+ : cMetaRotater(a_BlockType)
{
}
diff --git a/src/Blocks/BlockDropSpenser.h b/src/Blocks/BlockDropSpenser.h
index 73937577a..adc819a4c 100644
--- a/src/Blocks/BlockDropSpenser.h
+++ b/src/Blocks/BlockDropSpenser.h
@@ -17,7 +17,7 @@ class cBlockDropSpenserHandler :
{
public:
cBlockDropSpenserHandler(BLOCKTYPE a_BlockType) :
- cMetaRotater(a_BlockType)
+ cMetaRotater(a_BlockType)
{
}
--
cgit v1.2.3
From d73cdba1f66a92f011ac881b581595c0959139ef Mon Sep 17 00:00:00 2001
From: andrew
Date: Sat, 1 Mar 2014 21:34:19 +0200
Subject: g_BlockXXX => cBlockInfo::XXX
---
src/BlockInfo.cpp | 10 +++++-----
src/BlockInfo.h | 27 +++++++++++++++++++++-----
src/Blocks/BlockButton.h | 2 +-
src/Blocks/BlockCactus.h | 2 +-
src/Blocks/BlockDirt.h | 4 ++--
src/Blocks/BlockLadder.h | 2 +-
src/Blocks/BlockLever.h | 2 +-
src/Blocks/BlockRail.h | 4 ++--
src/Blocks/BlockRedstone.h | 2 +-
src/Blocks/BlockSnow.h | 2 +-
src/Blocks/BlockTorch.h | 6 +++---
src/Blocks/BlockTrapdoor.h | 2 +-
src/Blocks/BlockVine.h | 2 +-
src/Chunk.cpp | 10 +++++-----
src/ClientHandle.cpp | 2 +-
src/Defines.h | 2 +-
src/Entities/Entity.cpp | 6 +++---
src/Entities/Minecart.cpp | 16 +++++++--------
src/Entities/Player.cpp | 2 +-
src/Entities/ProjectileEntity.cpp | 4 ++--
src/Generating/FinishGen.cpp | 6 +++---
src/Globals.h | 1 +
src/Items/ItemRedstoneDust.h | 2 +-
src/LightingThread.cpp | 4 ++--
src/LightingThread.h | 4 ++--
src/MobSpawner.cpp | 14 ++++++-------
src/Mobs/Monster.cpp | 10 +++++-----
src/Mobs/SnowGolem.cpp | 2 +-
src/Piston.cpp | 2 +-
src/Simulator/FireSimulator.cpp | 2 +-
src/Simulator/IncrementalRedstoneSimulator.cpp | 4 ++--
src/Simulator/IncrementalRedstoneSimulator.h | 2 +-
src/Tracer.cpp | 2 +-
33 files changed, 91 insertions(+), 73 deletions(-)
diff --git a/src/BlockInfo.cpp b/src/BlockInfo.cpp
index 6ae59db53..5fd6d33c1 100644
--- a/src/BlockInfo.cpp
+++ b/src/BlockInfo.cpp
@@ -7,13 +7,13 @@
-BlockInfo BlockInfo::ms_Info[256];
+cBlockInfo cBlockInfo::ms_Info[256];
-BlockInfo::BlockInfo()
+cBlockInfo::cBlockInfo()
: m_LightValue(0x00)
, m_SpreadLightFalloff(0x0f)
, m_Transparent(false)
@@ -29,7 +29,7 @@ BlockInfo::BlockInfo()
-BlockInfo & BlockInfo::GetById(unsigned int a_ID)
+cBlockInfo & cBlockInfo::GetById(unsigned int a_ID)
{
ASSERT(a_ID < 256);
@@ -40,7 +40,7 @@ BlockInfo & BlockInfo::GetById(unsigned int a_ID)
-void BlockInfo::Initialize(void)
+void cBlockInfo::Initialize(void)
{
// Emissive blocks
ms_Info[E_BLOCK_FIRE ].m_LightValue = 15;
@@ -413,7 +413,7 @@ class cBlockInfoInitializer
public:
cBlockInfoInitializer(void)
{
- BlockInfo::Initialize();
+ cBlockInfo::Initialize();
}
} BlockInfoInitializer;
diff --git a/src/BlockInfo.h b/src/BlockInfo.h
index 1e09b0df5..a06c47a47 100644
--- a/src/BlockInfo.h
+++ b/src/BlockInfo.h
@@ -6,27 +6,44 @@
-class BlockInfo
+class cBlockInfo
{
public:
- BlockInfo();
+ cBlockInfo();
/** (Re-)Initializes the internal BlockInfo structures. */
static void Initialize(void);
/** Returns the associated BlockInfo structure. */
- static BlockInfo & GetById(unsigned int a_ID);
+ static cBlockInfo & GetById(unsigned int a_ID);
+
+ /** How much light do the blocks emit on their own? */
NIBBLETYPE m_LightValue;
+
+ /** How much light do the blocks consume? */
NIBBLETYPE m_SpreadLightFalloff;
+ /** Is a block completely transparent? (light doesn't get decreased(?)) */
bool m_Transparent;
+
+ /** Is a block destroyed after a single hit? */
bool m_OneHitDig;
+
+ /** Can a piston break this block? */
bool m_PistonBreakable;
+
+ /** Can this block hold snow atop? */
bool m_IsSnowable;
+
+ /** Does this block require a tool to drop? */
bool m_RequiresSpecialTool;
+
+ /** Is this block solid (player cannot walk through)? */
bool m_IsSolid;
+
+ /** Does this block fully occupy it's voxel - is it a 'full' block? */
bool m_FullyOccupiesVoxel;
@@ -34,7 +51,7 @@ public:
inline static NIBBLETYPE GetSpreadLightFalloff(unsigned int a_ID) { return GetById(a_ID).m_SpreadLightFalloff; }
inline static bool IsTransparent (unsigned int a_ID) { return GetById(a_ID).m_Transparent; }
inline static bool IsOneHitDig (unsigned int a_ID) { return GetById(a_ID).m_OneHitDig; }
- inline static bool IsPistoneBreakable (unsigned int a_ID) { return GetById(a_ID).m_PistonBreakable; }
+ inline static bool IsPistonBreakable (unsigned int a_ID) { return GetById(a_ID).m_PistonBreakable; }
inline static bool IsSnowable (unsigned int a_ID) { return GetById(a_ID).m_IsSnowable; }
inline static bool RequiresSpecialTool (unsigned int a_ID) { return GetById(a_ID).m_RequiresSpecialTool; }
inline static bool IsSolid (unsigned int a_ID) { return GetById(a_ID).m_IsSolid; }
@@ -44,7 +61,7 @@ public:
protected:
// TODO xdot: Change to std::vector to support dynamic block IDs
- static BlockInfo ms_Info[256];
+ static cBlockInfo ms_Info[256];
};
diff --git a/src/Blocks/BlockButton.h b/src/Blocks/BlockButton.h
index ca6850ced..2db9b7ec7 100644
--- a/src/Blocks/BlockButton.h
+++ b/src/Blocks/BlockButton.h
@@ -101,7 +101,7 @@ public:
AddFaceDirection(a_RelX, a_RelY, a_RelZ, BlockMetaDataToBlockFace(Meta), true);
BLOCKTYPE BlockIsOn; a_Chunk.UnboundedRelGetBlockType(a_RelX, a_RelY, a_RelZ, BlockIsOn);
- return (a_RelY > 0) && (g_BlockIsSolid[BlockIsOn]);
+ return (a_RelY > 0) && (cBlockInfo::IsSolid(BlockIsOn));
}
} ;
diff --git a/src/Blocks/BlockCactus.h b/src/Blocks/BlockCactus.h
index 83595d2b9..ed441517d 100644
--- a/src/Blocks/BlockCactus.h
+++ b/src/Blocks/BlockCactus.h
@@ -54,7 +54,7 @@ public:
NIBBLETYPE BlockMeta;
if (
a_Chunk.UnboundedRelGetBlock(a_RelX + Coords[i].x, a_RelY, a_RelZ + Coords[i].z, BlockType, BlockMeta) &&
- (g_BlockIsSolid[BlockType])
+ cBlockInfo::IsSolid(BlockType)
)
{
return false;
diff --git a/src/Blocks/BlockDirt.h b/src/Blocks/BlockDirt.h
index 91534c5e5..544424a04 100644
--- a/src/Blocks/BlockDirt.h
+++ b/src/Blocks/BlockDirt.h
@@ -36,7 +36,7 @@ public:
if (a_RelY < cChunkDef::Height - 1)
{
BLOCKTYPE Above = a_Chunk.GetBlock(a_RelX, a_RelY + 1, a_RelZ);
- if ((!g_BlockTransparent[Above] && !g_BlockOneHitDig[Above]) || IsBlockWater(Above))
+ if ((!cBlockInfo::IsTransparent(Above) && !cBlockInfo::IsOneHitDig(Above)) || IsBlockWater(Above))
{
a_Chunk.FastSetBlock(a_RelX, a_RelY, a_RelZ, E_BLOCK_DIRT, E_META_DIRT_NORMAL);
return;
@@ -77,7 +77,7 @@ public:
BLOCKTYPE AboveDest;
NIBBLETYPE AboveMeta;
Chunk->GetBlockTypeMeta(BlockX, BlockY + 1, BlockZ, AboveDest, AboveMeta);
- if ((g_BlockOneHitDig[AboveDest] || g_BlockTransparent[AboveDest]) && !IsBlockWater(AboveDest))
+ if ((cBlockInfo::IsOneHitDig(AboveDest) || cBlockInfo::IsTransparent(AboveDest)) && !IsBlockWater(AboveDest))
{
Chunk->FastSetBlock(BlockX, BlockY, BlockZ, E_BLOCK_GRASS, 0);
}
diff --git a/src/Blocks/BlockLadder.h b/src/Blocks/BlockLadder.h
index 6a105d5c9..a3e9edc6b 100644
--- a/src/Blocks/BlockLadder.h
+++ b/src/Blocks/BlockLadder.h
@@ -91,7 +91,7 @@ public:
AddFaceDirection( a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, true);
- return g_BlockIsSolid[a_ChunkInterface.GetBlock(a_BlockX, a_BlockY, a_BlockZ)];
+ return cBlockInfo::IsSolid(a_ChunkInterface.GetBlock(a_BlockX, a_BlockY, a_BlockZ));
}
diff --git a/src/Blocks/BlockLever.h b/src/Blocks/BlockLever.h
index 48c7e774b..ef6e102cd 100644
--- a/src/Blocks/BlockLever.h
+++ b/src/Blocks/BlockLever.h
@@ -102,7 +102,7 @@ public:
AddFaceDirection(a_RelX, a_RelY, a_RelZ, BlockMetaDataToBlockFace(Meta), true);
BLOCKTYPE BlockIsOn; a_Chunk.UnboundedRelGetBlockType(a_RelX, a_RelY, a_RelZ, BlockIsOn);
- return (a_RelY > 0) && (g_BlockIsSolid[BlockIsOn]);
+ return (a_RelY > 0) && cBlockInfo::IsSolid(BlockIsOn);
}
} ;
diff --git a/src/Blocks/BlockRail.h b/src/Blocks/BlockRail.h
index 52d6f60b3..07e9814cd 100644
--- a/src/Blocks/BlockRail.h
+++ b/src/Blocks/BlockRail.h
@@ -98,7 +98,7 @@ public:
{
return false;
}
- if (!g_BlockIsSolid[a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ)])
+ if (!cBlockInfo::IsSolid(a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ)))
{
return false;
}
@@ -130,7 +130,7 @@ public:
// Too close to the edge, cannot simulate
return true;
}
- return g_BlockIsSolid[BlockType];
+ return cBlockInfo::IsSolid(BlockType);
}
}
return true;
diff --git a/src/Blocks/BlockRedstone.h b/src/Blocks/BlockRedstone.h
index 10de96197..a898c9acb 100644
--- a/src/Blocks/BlockRedstone.h
+++ b/src/Blocks/BlockRedstone.h
@@ -20,7 +20,7 @@ public:
virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override
{
- return ((a_RelY > 0) && g_BlockFullyOccupiesVoxel[a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ)]);
+ return ((a_RelY > 0) && cBlockInfo::FullyOccupiesVoxel(a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ)));
}
diff --git a/src/Blocks/BlockSnow.h b/src/Blocks/BlockSnow.h
index a3daf0393..b21995d3c 100644
--- a/src/Blocks/BlockSnow.h
+++ b/src/Blocks/BlockSnow.h
@@ -72,7 +72,7 @@ public:
BLOCKTYPE BlockBelow = a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ);
NIBBLETYPE MetaBelow = a_Chunk.GetMeta(a_RelX, a_RelY - 1, a_RelZ);
- if (g_BlockIsSnowable[BlockBelow] || ((BlockBelow == E_BLOCK_SNOW) && (MetaBelow == 7)))
+ if (cBlockInfo::IsSnowable(BlockBelow) || ((BlockBelow == E_BLOCK_SNOW) && (MetaBelow == 7)))
{
// If block below is snowable, or it is a thin slow block and has a meta of 7 (full thin snow block), say yay
return true;
diff --git a/src/Blocks/BlockTorch.h b/src/Blocks/BlockTorch.h
index f2a4c8665..84bbb37ec 100644
--- a/src/Blocks/BlockTorch.h
+++ b/src/Blocks/BlockTorch.h
@@ -99,7 +99,7 @@ public:
static bool CanBePlacedOn(BLOCKTYPE a_BlockType, eBlockFace a_BlockFace)
{
- if ( !g_BlockFullyOccupiesVoxel[a_BlockType] )
+ if ( !cBlockInfo::FullyOccupiesVoxel(a_BlockType) )
{
return (a_BlockFace == BLOCK_FACE_TOP); // Allow placement only when torch upright (for glass, etc.); exceptions won't even be sent by client, no need to handle
}
@@ -129,7 +129,7 @@ public:
{
return Face;
}
- else if ((g_BlockFullyOccupiesVoxel[BlockInQuestion]) && (i != BLOCK_FACE_BOTTOM))
+ else if (cBlockInfo::FullyOccupiesVoxel(BlockInQuestion) && (i != BLOCK_FACE_BOTTOM))
{
// Otherwise, if block in that direction is torch placeable and we haven't gotten to it via the bottom face, return that face
return Face;
@@ -163,7 +163,7 @@ public:
// No need to check for upright orientation, it was done when the torch was placed
return true;
}
- else if ( !g_BlockFullyOccupiesVoxel[BlockInQuestion] )
+ else if ( !cBlockInfo::FullyOccupiesVoxel(BlockInQuestion) )
{
return false;
}
diff --git a/src/Blocks/BlockTrapdoor.h b/src/Blocks/BlockTrapdoor.h
index 08fc28327..70a369e69 100644
--- a/src/Blocks/BlockTrapdoor.h
+++ b/src/Blocks/BlockTrapdoor.h
@@ -97,7 +97,7 @@ public:
AddFaceDirection(a_RelX, a_RelY, a_RelZ, BlockMetaDataToBlockFace(Meta), true);
BLOCKTYPE BlockIsOn; a_Chunk.UnboundedRelGetBlockType(a_RelX, a_RelY, a_RelZ, BlockIsOn);
- return (a_RelY > 0) && (g_BlockIsSolid[BlockIsOn]);
+ return (a_RelY > 0) && cBlockInfo::IsSolid(BlockIsOn);
}
};
diff --git a/src/Blocks/BlockVine.h b/src/Blocks/BlockVine.h
index ee7dcee8a..d8c114284 100644
--- a/src/Blocks/BlockVine.h
+++ b/src/Blocks/BlockVine.h
@@ -70,7 +70,7 @@ 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) || g_BlockIsSolid[a_BlockType];
+ return (a_BlockType == E_BLOCK_LEAVES) || cBlockInfo::IsSolid(a_BlockType);
}
diff --git a/src/Chunk.cpp b/src/Chunk.cpp
index 8dfbbeef5..a75828461 100644
--- a/src/Chunk.cpp
+++ b/src/Chunk.cpp
@@ -883,7 +883,7 @@ void cChunk::ApplyWeatherToTop()
FastSetBlock(X, Height, Z, E_BLOCK_SNOW, TopMeta - 1);
}
}
- else if (g_BlockIsSnowable[TopBlock])
+ else if (cBlockInfo::IsSnowable(TopBlock))
{
SetBlock(X, Height + 1, Z, E_BLOCK_SNOW, 0);
}
@@ -1540,10 +1540,10 @@ void cChunk::FastSetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockT
SetNibble(m_BlockMeta, index, a_BlockMeta);
// ONLY recalculate lighting if it's necessary!
- if(
- (g_BlockLightValue[OldBlockType ] != g_BlockLightValue[a_BlockType]) ||
- (g_BlockSpreadLightFalloff[OldBlockType] != g_BlockSpreadLightFalloff[a_BlockType]) ||
- (g_BlockTransparent[OldBlockType] != g_BlockTransparent[a_BlockType])
+ if (
+ (cBlockInfo::GetLightValue (OldBlockType) != cBlockInfo::GetLightValue (a_BlockType)) ||
+ (cBlockInfo::GetSpreadLightFalloff(OldBlockType) != cBlockInfo::GetSpreadLightFalloff(a_BlockType)) ||
+ (cBlockInfo::IsTransparent (OldBlockType) != cBlockInfo::IsTransparent (a_BlockType))
)
{
m_IsLightValid = false;
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index b08ceb5f6..60f14af54 100644
--- a/src/ClientHandle.cpp
+++ b/src/ClientHandle.cpp
@@ -819,7 +819,7 @@ void cClientHandle::HandleBlockDigStarted(int a_BlockX, int a_BlockY, int a_Bloc
if (
(m_Player->IsGameModeCreative()) || // In creative mode, digging is done immediately
- g_BlockOneHitDig[a_OldBlock] // One-hit blocks get destroyed immediately, too
+ cBlockInfo::IsOneHitDig(a_OldBlock) // One-hit blocks get destroyed immediately, too
)
{
HandleBlockDigFinished(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_OldBlock, a_OldMeta);
diff --git a/src/Defines.h b/src/Defines.h
index ba2866f83..31d48860f 100644
--- a/src/Defines.h
+++ b/src/Defines.h
@@ -654,7 +654,7 @@ namespace ItemCategory
inline bool BlockRequiresSpecialTool(BLOCKTYPE a_BlockType)
{
if(!IsValidBlock(a_BlockType)) return false;
- return g_BlockRequiresSpecialTool[a_BlockType];
+ return cBlockInfo::RequiresSpecialTool(a_BlockType);
}
diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp
index 8554ab2a5..96e8c15a5 100644
--- a/src/Entities/Entity.cpp
+++ b/src/Entities/Entity.cpp
@@ -582,11 +582,11 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk)
int RelBlockZ = BlockZ - (NextChunk->GetPosZ() * cChunkDef::Width);
BLOCKTYPE BlockIn = NextChunk->GetBlock( RelBlockX, BlockY, RelBlockZ );
BLOCKTYPE BlockBelow = (BlockY > 0) ? NextChunk->GetBlock(RelBlockX, BlockY - 1, RelBlockZ) : E_BLOCK_AIR;
- if (!g_BlockIsSolid[BlockIn]) // Making sure we are not inside a solid block
+ if (!cBlockInfo::IsSolid(BlockIn)) // Making sure we are not inside a solid block
{
if (m_bOnGround) // check if it's still on the ground
{
- if (!g_BlockIsSolid[BlockBelow]) // Check if block below is air or water.
+ if (!cBlockInfo::IsSolid(BlockBelow)) // Check if block below is air or water.
{
m_bOnGround = false;
}
@@ -616,7 +616,7 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk)
// The pickup is too close to an unloaded chunk, bail out of any physics handling
return;
}
- if (!g_BlockIsSolid[GotBlock])
+ if (!cBlockInfo::IsSolid(GotBlock))
{
NextPos.x += gCrossCoords[i].x;
NextPos.z += gCrossCoords[i].z;
diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp
index d854906b7..f52a7b6d9 100644
--- a/src/Entities/Minecart.cpp
+++ b/src/Entities/Minecart.cpp
@@ -720,7 +720,7 @@ bool cMinecart::TestBlockCollision(NIBBLETYPE a_RailMeta)
if (GetSpeedZ() > 0)
{
BLOCKTYPE Block = m_World->GetBlock((int)floor(GetPosX()), (int)floor(GetPosY()), (int)ceil(GetPosZ()));
- if (!IsBlockRail(Block) && g_BlockIsSolid[Block])
+ if (!IsBlockRail(Block) && cBlockInfo::IsSolid(Block))
{
// We could try to detect a block in front based purely on coordinates, but xoft made a bounding box system - why not use? :P
cBoundingBox bbBlock(Vector3d((int)floor(GetPosX()), (int)floor(GetPosY()), (int)ceil(GetPosZ())), 0.5, 1);
@@ -737,7 +737,7 @@ bool cMinecart::TestBlockCollision(NIBBLETYPE a_RailMeta)
else if (GetSpeedZ() < 0)
{
BLOCKTYPE Block = m_World->GetBlock((int)floor(GetPosX()), (int)floor(GetPosY()), (int)floor(GetPosZ()) - 1);
- if (!IsBlockRail(Block) && g_BlockIsSolid[Block])
+ if (!IsBlockRail(Block) && cBlockInfo::IsSolid(Block))
{
cBoundingBox bbBlock(Vector3d((int)floor(GetPosX()), (int)floor(GetPosY()), (int)floor(GetPosZ()) - 1), 0.5, 1);
cBoundingBox bbMinecart(Vector3d(GetPosX(), floor(GetPosY()), GetPosZ() - 1), GetWidth() / 2, GetHeight());
@@ -757,7 +757,7 @@ bool cMinecart::TestBlockCollision(NIBBLETYPE a_RailMeta)
if (GetSpeedX() > 0)
{
BLOCKTYPE Block = m_World->GetBlock((int)ceil(GetPosX()), (int)floor(GetPosY()), (int)floor(GetPosZ()));
- if (!IsBlockRail(Block) && g_BlockIsSolid[Block])
+ if (!IsBlockRail(Block) && cBlockInfo::IsSolid(Block))
{
cBoundingBox bbBlock(Vector3d((int)ceil(GetPosX()), (int)floor(GetPosY()), (int)floor(GetPosZ())), 0.5, 1);
cBoundingBox bbMinecart(Vector3d(GetPosX(), floor(GetPosY()), GetPosZ()), GetWidth() / 2, GetHeight());
@@ -773,7 +773,7 @@ bool cMinecart::TestBlockCollision(NIBBLETYPE a_RailMeta)
else if (GetSpeedX() < 0)
{
BLOCKTYPE Block = m_World->GetBlock((int)floor(GetPosX()) - 1, (int)floor(GetPosY()), (int)floor(GetPosZ()));
- if (!IsBlockRail(Block) && g_BlockIsSolid[Block])
+ if (!IsBlockRail(Block) && cBlockInfo::IsSolid(Block))
{
cBoundingBox bbBlock(Vector3d((int)floor(GetPosX()) - 1, (int)floor(GetPosY()), (int)floor(GetPosZ())), 0.5, 1);
cBoundingBox bbMinecart(Vector3d(GetPosX() - 1, floor(GetPosY()), GetPosZ()), GetWidth() / 2, GetHeight());
@@ -798,10 +798,10 @@ bool cMinecart::TestBlockCollision(NIBBLETYPE a_RailMeta)
BLOCKTYPE BlockZM = m_World->GetBlock((int)floor(GetPosX()), (int)floor(GetPosY()), (int)floor(GetPosZ()) + 1);
BLOCKTYPE BlockZP = m_World->GetBlock((int)floor(GetPosX()), (int)floor(GetPosY()), (int)floor(GetPosZ()) + 1);
if (
- (!IsBlockRail(BlockXM) && g_BlockIsSolid[BlockXM]) ||
- (!IsBlockRail(BlockXP) && g_BlockIsSolid[BlockXP]) ||
- (!IsBlockRail(BlockZM) && g_BlockIsSolid[BlockZM]) ||
- (!IsBlockRail(BlockZP) && g_BlockIsSolid[BlockZP])
+ (!IsBlockRail(BlockXM) && cBlockInfo::IsSolid(BlockXM)) ||
+ (!IsBlockRail(BlockXP) && cBlockInfo::IsSolid(BlockXP)) ||
+ (!IsBlockRail(BlockZM) && cBlockInfo::IsSolid(BlockZM)) ||
+ (!IsBlockRail(BlockZP) && cBlockInfo::IsSolid(BlockZP))
)
{
SetSpeed(0, 0, 0);
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index 8f94f1feb..42ee14cf3 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -1904,7 +1904,7 @@ void cPlayer::Detach()
{
for (int z = PosZ - 2; z <= (PosZ + 2); ++z)
{
- if (!g_BlockIsSolid[m_World->GetBlock(x, y, z)] && g_BlockIsSolid[m_World->GetBlock(x, y - 1, z)])
+ if (!cBlockInfo::IsSolid(m_World->GetBlock(x, y, z)) && cBlockInfo::IsSolid(m_World->GetBlock(x, y - 1, z)))
{
TeleportToCoords(x, y, z);
return;
diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp
index ef82c6e94..03bc0c99d 100644
--- a/src/Entities/ProjectileEntity.cpp
+++ b/src/Entities/ProjectileEntity.cpp
@@ -50,12 +50,12 @@ protected:
LOGD("Hit block %d:%d at {%d, %d, %d} face %d, %s (%s)",
a_BlockType, a_BlockMeta,
a_BlockX, a_BlockY, a_BlockZ, a_EntryFace,
- g_BlockIsSolid[a_BlockType] ? "solid" : "non-solid",
+ cBlockInfo::IsSolid(a_BlockType) ? "solid" : "non-solid",
ItemToString(cItem(a_BlockType, 1, a_BlockMeta)).c_str()
);
*/
- if (g_BlockIsSolid[a_BlockType])
+ if (cBlockInfo::IsSolid(a_BlockType))
{
// The projectile hit a solid block
// Calculate the exact hit coords:
diff --git a/src/Generating/FinishGen.cpp b/src/Generating/FinishGen.cpp
index 02045f76a..f2d66af70 100644
--- a/src/Generating/FinishGen.cpp
+++ b/src/Generating/FinishGen.cpp
@@ -88,7 +88,7 @@ void cFinishGenNetherClumpFoliage::GenFinish(cChunkDesc & a_ChunkDesc)
{
continue;
}
- if (!g_BlockIsSolid[a_ChunkDesc.GetBlockType(PosX, y - 1, PosZ)]) // Only place on solid blocks
+ if (!cBlockInfo::IsSolid(a_ChunkDesc.GetBlockType(PosX, y - 1, PosZ))) // Only place on solid blocks
{
continue;
}
@@ -131,7 +131,7 @@ void cFinishGenNetherClumpFoliage::TryPlaceClump(cChunkDesc & a_ChunkDesc, int a
}
BLOCKTYPE BlockBelow = a_ChunkDesc.GetBlockType(x, y - 1, z);
- if (!g_BlockIsSolid[BlockBelow]) // Only place on solid blocks
+ if (!cBlockInfo::IsSolid(BlockBelow)) // Only place on solid blocks
{
continue;
}
@@ -329,7 +329,7 @@ void cFinishGenSnow::GenFinish(cChunkDesc & a_ChunkDesc)
case biFrozenOcean:
{
int Height = a_ChunkDesc.GetHeight(x, z);
- if (g_BlockIsSnowable[a_ChunkDesc.GetBlockType(x, Height, z)])
+ if (cBlockInfo::IsSnowable(a_ChunkDesc.GetBlockType(x, Height, z)))
{
a_ChunkDesc.SetBlockType(x, Height + 1, z, E_BLOCK_SNOW);
a_ChunkDesc.SetHeight(x, z, Height + 1);
diff --git a/src/Globals.h b/src/Globals.h
index e4737a98a..28805a83f 100644
--- a/src/Globals.h
+++ b/src/Globals.h
@@ -250,6 +250,7 @@ T Clamp(T a_Value, T a_Min, T a_Max)
#include "ChunkDef.h"
#include "BiomeDef.h"
#include "BlockID.h"
+#include "BlockInfo.h"
#include "Entities/Effects.h"
diff --git a/src/Items/ItemRedstoneDust.h b/src/Items/ItemRedstoneDust.h
index 18c6b8615..274d905a5 100644
--- a/src/Items/ItemRedstoneDust.h
+++ b/src/Items/ItemRedstoneDust.h
@@ -27,7 +27,7 @@ public:
BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta
) override
{
- if (!g_BlockFullyOccupiesVoxel[a_World->GetBlock(a_BlockX, a_BlockY - 1, a_BlockZ)]) // Some solid blocks, such as cocoa beans, are not suitable for dust
+ if (!cBlockInfo::FullyOccupiesVoxel(a_World->GetBlock(a_BlockX, a_BlockY - 1, a_BlockZ))) // Some solid blocks, such as cocoa beans, are not suitable for dust
{
return false;
}
diff --git a/src/LightingThread.cpp b/src/LightingThread.cpp
index 9c81d004d..44dadb8a9 100644
--- a/src/LightingThread.cpp
+++ b/src/LightingThread.cpp
@@ -391,7 +391,7 @@ void cLightingThread::PrepareBlockLight(void)
int idx = BaseZ + x;
for (int y = m_HeightMap[idx], Index = idx + y * BlocksPerYLayer; y >= 0; y--, Index -= BlocksPerYLayer)
{
- if (g_BlockLightValue[m_BlockTypes[Index]] == 0)
+ if (cBlockInfo::GetLightValue(m_BlockTypes[Index]) == 0)
{
continue;
}
@@ -401,7 +401,7 @@ void cLightingThread::PrepareBlockLight(void)
m_SeedIdx1[m_NumSeeds++] = Index;
// Light it up:
- m_BlockLight[Index] = g_BlockLightValue[m_BlockTypes[Index]];
+ m_BlockLight[Index] = cBlockInfo::GetLightValue(m_BlockTypes[Index]);
}
}
}
diff --git a/src/LightingThread.h b/src/LightingThread.h
index 72d561348..198f27248 100644
--- a/src/LightingThread.h
+++ b/src/LightingThread.h
@@ -169,13 +169,13 @@ protected:
ASSERT(a_DstIdx >= 0);
ASSERT(a_DstIdx < (int)ARRAYCOUNT(m_BlockTypes));
- if (a_Light[a_SrcIdx] <= a_Light[a_DstIdx] + g_BlockSpreadLightFalloff[m_BlockTypes[a_DstIdx]])
+ 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] - g_BlockSpreadLightFalloff[m_BlockTypes[a_DstIdx]];
+ a_Light[a_DstIdx] = a_Light[a_SrcIdx] - cBlockInfo::GetSpreadLightFalloff(m_BlockTypes[a_DstIdx]);
if (!a_IsSeedOut[a_DstIdx])
{
a_IsSeedOut[a_DstIdx] = true;
diff --git a/src/MobSpawner.cpp b/src/MobSpawner.cpp
index c86268e63..7704f6cf3 100644
--- a/src/MobSpawner.cpp
+++ b/src/MobSpawner.cpp
@@ -145,7 +145,7 @@ bool cMobSpawner::CanSpawnHere(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_R
case cMonster::mtBat:
{
- return (a_RelY <= 63) && (BlockLight <= 4) && (SkyLight <= 4) && (TargetBlock == E_BLOCK_AIR) && (!g_BlockTransparent[BlockAbove]);
+ return (a_RelY <= 63) && (BlockLight <= 4) && (SkyLight <= 4) && (TargetBlock == E_BLOCK_AIR) && !cBlockInfo::IsTransparent(BlockAbove);
}
case cMonster::mtChicken:
@@ -157,7 +157,7 @@ bool cMobSpawner::CanSpawnHere(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_R
return (
(TargetBlock == E_BLOCK_AIR) &&
(BlockAbove == E_BLOCK_AIR) &&
- (!g_BlockTransparent[BlockBelow]) &&
+ (!cBlockInfo::IsTransparent(BlockBelow)) &&
(BlockBelow == E_BLOCK_GRASS) &&
(SkyLight >= 9)
);
@@ -188,7 +188,7 @@ bool cMobSpawner::CanSpawnHere(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_R
(TargetBlock == E_BLOCK_AIR) &&
(BlockAbove == E_BLOCK_AIR) &&
(BlockTop == E_BLOCK_AIR) &&
- (!g_BlockTransparent[BlockBelow]) &&
+ (!cBlockInfo::IsTransparent(BlockBelow)) &&
(SkyLight <= 7) &&
(BlockLight <= 7)
);
@@ -215,7 +215,7 @@ bool cMobSpawner::CanSpawnHere(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_R
HaveFloor ||
(
a_Chunk->UnboundedRelGetBlockType(a_RelX + x, a_RelY - 1, a_RelZ + z, TargetBlock) &&
- !g_BlockTransparent[TargetBlock]
+ !cBlockInfo::IsTransparent(TargetBlock)
)
);
}
@@ -230,7 +230,7 @@ bool cMobSpawner::CanSpawnHere(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_R
return (
(TargetBlock == E_BLOCK_AIR) &&
(BlockAbove == E_BLOCK_AIR) &&
- (!g_BlockTransparent[BlockBelow]) &&
+ (!cBlockInfo::IsTransparent(BlockBelow)) &&
(SkyLight <= 7) &&
(BlockLight <= 7) &&
(m_Random.NextInt(2, a_Biome) == 0)
@@ -242,7 +242,7 @@ bool cMobSpawner::CanSpawnHere(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_R
return (
(TargetBlock == E_BLOCK_AIR) &&
(BlockAbove == E_BLOCK_AIR) &&
- (!g_BlockTransparent[BlockBelow]) &&
+ (!cBlockInfo::IsTransparent(BlockBelow)) &&
(
(a_RelY <= 40) || (a_Biome == biSwampland)
)
@@ -255,7 +255,7 @@ bool cMobSpawner::CanSpawnHere(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_R
return (
(TargetBlock == E_BLOCK_AIR) &&
(BlockAbove == E_BLOCK_AIR) &&
- (!g_BlockTransparent[BlockBelow]) &&
+ (!cBlockInfo::IsTransparent(BlockBelow)) &&
(m_Random.NextInt(20, a_Biome) == 0)
);
}
diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp
index ac9137ccd..6e3c91d58 100644
--- a/src/Mobs/Monster.cpp
+++ b/src/Mobs/Monster.cpp
@@ -148,11 +148,11 @@ void cMonster::TickPathFinding()
BLOCKTYPE BlockAtYPP = m_World->GetBlock(gCrossCoords[i].x + PosX, PosY + 2, gCrossCoords[i].z + PosZ);
BLOCKTYPE BlockAtYM = m_World->GetBlock(gCrossCoords[i].x + PosX, PosY - 1, gCrossCoords[i].z + PosZ);
- if ((!g_BlockIsSolid[BlockAtY]) && (!g_BlockIsSolid[BlockAtYP]) && (!IsBlockLava(BlockAtYM)) && (BlockAtY != E_BLOCK_FENCE) && (BlockAtY != E_BLOCK_FENCE_GATE))
+ if ((!cBlockInfo::IsSolid(BlockAtY)) && (!cBlockInfo::IsSolid(BlockAtYP)) && (!IsBlockLava(BlockAtYM)) && (BlockAtY != E_BLOCK_FENCE) && (BlockAtY != E_BLOCK_FENCE_GATE))
{
m_PotentialCoordinates.push_back(Vector3d((gCrossCoords[i].x + PosX), PosY, gCrossCoords[i].z + PosZ));
}
- else if ((g_BlockIsSolid[BlockAtY]) && (!g_BlockIsSolid[BlockAtYP]) && (!g_BlockIsSolid[BlockAtYPP]) && (!IsBlockLava(BlockAtYM)) && (BlockAtY != E_BLOCK_FENCE) && (BlockAtY != E_BLOCK_FENCE_GATE))
+ else if ((cBlockInfo::IsSolid(BlockAtY)) && (!cBlockInfo::IsSolid(BlockAtYP)) && (!cBlockInfo::IsSolid(BlockAtYPP)) && (!IsBlockLava(BlockAtYM)) && (BlockAtY != E_BLOCK_FENCE) && (BlockAtY != E_BLOCK_FENCE_GATE))
{
m_PotentialCoordinates.push_back(Vector3d((gCrossCoords[i].x + PosX), PosY + 1, gCrossCoords[i].z + PosZ));
}
@@ -416,9 +416,9 @@ int cMonster::FindFirstNonAirBlockPosition(double a_PosX, double a_PosZ)
else if (PosY > cChunkDef::Height)
PosY = cChunkDef::Height;
- if (!g_BlockIsSolid[m_World->GetBlock((int)floor(a_PosX), PosY, (int)floor(a_PosZ))])
+ if (!cBlockInfo::IsSolid(m_World->GetBlock((int)floor(a_PosX), PosY, (int)floor(a_PosZ))))
{
- while (!g_BlockIsSolid[m_World->GetBlock((int)floor(a_PosX), PosY, (int)floor(a_PosZ))] && (PosY > 0))
+ while (!cBlockInfo::IsSolid(m_World->GetBlock((int)floor(a_PosX), PosY, (int)floor(a_PosZ))) && (PosY > 0))
{
PosY--;
}
@@ -427,7 +427,7 @@ int cMonster::FindFirstNonAirBlockPosition(double a_PosX, double a_PosZ)
}
else
{
- while (g_BlockIsSolid[m_World->GetBlock((int)floor(a_PosX), PosY, (int)floor(a_PosZ))] && (PosY < cChunkDef::Height))
+ while (cBlockInfo::IsSolid(m_World->GetBlock((int)floor(a_PosX), PosY, (int)floor(a_PosZ))) && (PosY < cChunkDef::Height))
{
PosY++;
}
diff --git a/src/Mobs/SnowGolem.cpp b/src/Mobs/SnowGolem.cpp
index 67e3a3bb8..c1979a495 100644
--- a/src/Mobs/SnowGolem.cpp
+++ b/src/Mobs/SnowGolem.cpp
@@ -38,7 +38,7 @@ void cSnowGolem::Tick(float a_Dt, cChunk & a_Chunk)
{
BLOCKTYPE BlockBelow = m_World->GetBlock((int) floor(GetPosX()), (int) floor(GetPosY()) - 1, (int) floor(GetPosZ()));
BLOCKTYPE Block = m_World->GetBlock((int) floor(GetPosX()), (int) floor(GetPosY()), (int) floor(GetPosZ()));
- if (Block == E_BLOCK_AIR && g_BlockIsSolid[BlockBelow])
+ if (Block == E_BLOCK_AIR && cBlockInfo::IsSolid(BlockBelow))
{
m_World->SetBlock((int) floor(GetPosX()), (int) floor(GetPosY()), (int) floor(GetPosZ()), E_BLOCK_SNOW, 0);
}
diff --git a/src/Piston.cpp b/src/Piston.cpp
index 5eb14451d..b21d576f3 100644
--- a/src/Piston.cpp
+++ b/src/Piston.cpp
@@ -242,7 +242,7 @@ bool cPiston::CanPush(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
bool cPiston::CanBreakPush(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
{
UNUSED(a_BlockMeta);
- return g_BlockPistonBreakable[a_BlockType];
+ return cBlockInfo::IsPistonBreakable(a_BlockType);
}
diff --git a/src/Simulator/FireSimulator.cpp b/src/Simulator/FireSimulator.cpp
index b77fa1658..6aef97079 100644
--- a/src/Simulator/FireSimulator.cpp
+++ b/src/Simulator/FireSimulator.cpp
@@ -239,7 +239,7 @@ int cFireSimulator::GetBurnStepTime(cChunk * a_Chunk, int a_RelX, int a_RelY, in
{
return m_BurnStepTimeFuel;
}
- IsBlockBelowSolid = g_BlockIsSolid[BlockBelow];
+ IsBlockBelowSolid = cBlockInfo::IsSolid(BlockBelow);
}
for (size_t i = 0; i < ARRAYCOUNT(gCrossCoords); i++)
diff --git a/src/Simulator/IncrementalRedstoneSimulator.cpp b/src/Simulator/IncrementalRedstoneSimulator.cpp
index 91de9e0cc..0640227b0 100644
--- a/src/Simulator/IncrementalRedstoneSimulator.cpp
+++ b/src/Simulator/IncrementalRedstoneSimulator.cpp
@@ -566,14 +566,14 @@ void cIncrementalRedstoneSimulator::HandleRedstoneWire(int a_BlockX, int a_Block
{
if ((i >= 4) && (i <= 7)) // If we are currently checking for wire surrounding ourself one block above...
{
- if (g_BlockIsSolid[m_World.GetBlock(a_BlockX, a_BlockY + 1, a_BlockZ)]) // If there is something solid above us (wire cut off)...
+ if (cBlockInfo::IsSolid(m_World.GetBlock(a_BlockX, a_BlockY + 1, a_BlockZ))) // If there is something solid above us (wire cut off)...
{
continue; // We don't receive power from that wire
}
}
else if ((i >= 8) && (i <= 11)) // See above, but this is for wire below us
{
- if (g_BlockIsSolid[m_World.GetBlock(a_BlockX + gCrossCoords[i].x, a_BlockY + gCrossCoords[i].y + 1, a_BlockZ + gCrossCoords[i].z)])
+ if (cBlockInfo::IsSolid(m_World.GetBlock(a_BlockX + gCrossCoords[i].x, a_BlockY + gCrossCoords[i].y + 1, a_BlockZ + gCrossCoords[i].z)))
{
continue;
}
diff --git a/src/Simulator/IncrementalRedstoneSimulator.h b/src/Simulator/IncrementalRedstoneSimulator.h
index e6bc28621..8b7363366 100644
--- a/src/Simulator/IncrementalRedstoneSimulator.h
+++ b/src/Simulator/IncrementalRedstoneSimulator.h
@@ -170,7 +170,7 @@ private:
/* ====== Misc Functions ====== */
/** Returns if a block is viable to be the MiddleBlock of a SetLinkedPowered operation */
- inline static bool IsViableMiddleBlock(BLOCKTYPE Block) { return g_BlockFullyOccupiesVoxel[Block]; }
+ inline static bool IsViableMiddleBlock(BLOCKTYPE Block) { return cBlockInfo::FullyOccupiesVoxel(Block); }
/** Returns if a block is a mechanism (something that accepts power and does something) */
inline static bool IsMechanism(BLOCKTYPE Block)
diff --git a/src/Tracer.cpp b/src/Tracer.cpp
index ef136302f..968a64439 100644
--- a/src/Tracer.cpp
+++ b/src/Tracer.cpp
@@ -226,7 +226,7 @@ bool cTracer::Trace( const Vector3f & a_Start, const Vector3f & a_Direction, int
BLOCKTYPE BlockID = m_World->GetBlock(pos.x, pos.y, pos.z);
// Block is counted as a collision if we are not doing a line of sight and it is solid,
// or if the block is not air and not water. That way mobs can still see underwater.
- if ((!a_LineOfSight && g_BlockIsSolid[BlockID]) || (a_LineOfSight && (BlockID != E_BLOCK_AIR) && !IsBlockWater(BlockID)))
+ if ((!a_LineOfSight && cBlockInfo::IsSolid(BlockID)) || (a_LineOfSight && (BlockID != E_BLOCK_AIR) && !IsBlockWater(BlockID)))
{
BlockHitPosition = pos;
int Normal = GetHitNormal(a_Start, End, pos );
--
cgit v1.2.3
From 29cc1ed05160955d1a17e63a0e9b26b9203e5d0f Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Sat, 1 Mar 2014 20:51:58 +0100
Subject: Ignoring all plugin subfolders.
Plugins developed directly with MCS have been added explicitly; other plugins are ignored.
---
MCServer/Plugins/.gitignore | 1 +
1 file changed, 1 insertion(+)
diff --git a/MCServer/Plugins/.gitignore b/MCServer/Plugins/.gitignore
index 89eab800a..8553945b5 100644
--- a/MCServer/Plugins/.gitignore
+++ b/MCServer/Plugins/.gitignore
@@ -1,2 +1,3 @@
*.txt
*.md
+*/
--
cgit v1.2.3
From 2f85c9648b3f109bb579611dbb9af45b64c8a2f8 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Sat, 1 Mar 2014 20:56:09 +0100
Subject: Unified StructureGens and FinisherGens.
Now they are all Finishers. Fixes #398.
---
src/Generating/Caves.cpp | 6 +-
src/Generating/Caves.h | 16 ++--
src/Generating/ComposableGenerator.cpp | 157 +++++++++++++++------------------
src/Generating/ComposableGenerator.h | 56 ++++--------
src/Generating/MineShafts.cpp | 2 +-
src/Generating/MineShafts.h | 6 +-
src/Generating/Ravines.cpp | 2 +-
src/Generating/Ravines.h | 6 +-
src/Generating/StructGen.cpp | 10 +--
src/Generating/StructGen.h | 30 +++----
10 files changed, 128 insertions(+), 163 deletions(-)
diff --git a/src/Generating/Caves.cpp b/src/Generating/Caves.cpp
index 2571e6b77..98b7c8681 100644
--- a/src/Generating/Caves.cpp
+++ b/src/Generating/Caves.cpp
@@ -762,7 +762,7 @@ void cStructGenWormNestCaves::ClearCache(void)
-void cStructGenWormNestCaves::GenStructures(cChunkDesc & a_ChunkDesc)
+void cStructGenWormNestCaves::GenFinish(cChunkDesc & a_ChunkDesc)
{
int ChunkX = a_ChunkDesc.GetChunkX();
int ChunkZ = a_ChunkDesc.GetChunkZ();
@@ -902,7 +902,7 @@ static float GetMarbleNoise( float x, float y, float z, cNoise & a_Noise )
-void cStructGenMarbleCaves::GenStructures(cChunkDesc & a_ChunkDesc)
+void cStructGenMarbleCaves::GenFinish(cChunkDesc & a_ChunkDesc)
{
cNoise Noise(m_Seed);
for (int z = 0; z < cChunkDef::Width; z++)
@@ -938,7 +938,7 @@ void cStructGenMarbleCaves::GenStructures(cChunkDesc & a_ChunkDesc)
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cStructGenDualRidgeCaves:
-void cStructGenDualRidgeCaves::GenStructures(cChunkDesc & a_ChunkDesc)
+void cStructGenDualRidgeCaves::GenFinish(cChunkDesc & a_ChunkDesc)
{
for (int z = 0; z < cChunkDef::Width; z++)
{
diff --git a/src/Generating/Caves.h b/src/Generating/Caves.h
index ea7f10bf4..7c45c056b 100644
--- a/src/Generating/Caves.h
+++ b/src/Generating/Caves.h
@@ -20,7 +20,7 @@
class cStructGenMarbleCaves :
- public cStructureGen
+ public cFinishGen
{
public:
cStructGenMarbleCaves(int a_Seed) : m_Seed(a_Seed) {}
@@ -29,8 +29,8 @@ protected:
int m_Seed;
- // cStructureGen override:
- virtual void GenStructures(cChunkDesc & a_ChunkDesc) override;
+ // cFinishGen override:
+ virtual void GenFinish(cChunkDesc & a_ChunkDesc) override;
} ;
@@ -38,7 +38,7 @@ protected:
class cStructGenDualRidgeCaves :
- public cStructureGen
+ public cFinishGen
{
public:
cStructGenDualRidgeCaves(int a_Seed, float a_Threshold) :
@@ -55,8 +55,8 @@ protected:
int m_Seed;
float m_Threshold;
- // cStructureGen override:
- virtual void GenStructures(cChunkDesc & a_ChunkDesc) override;
+ // cFinishGen override:
+ virtual void GenFinish(cChunkDesc & a_ChunkDesc) override;
} ;
@@ -64,7 +64,7 @@ protected:
class cStructGenWormNestCaves :
- public cStructureGen
+ public cFinishGen
{
public:
cStructGenWormNestCaves(int a_Seed, int a_Size = 64, int a_Grid = 96, int a_MaxOffset = 128) :
@@ -94,7 +94,7 @@ protected:
void GetCavesForChunk(int a_ChunkX, int a_ChunkZ, cCaveSystems & a_Caves);
// cStructGen override:
- virtual void GenStructures(cChunkDesc & a_ChunkDesc) override;
+ virtual void GenFinish(cChunkDesc & a_ChunkDesc) override;
} ;
diff --git a/src/Generating/ComposableGenerator.cpp b/src/Generating/ComposableGenerator.cpp
index cfa7e9c6f..e96e9a645 100644
--- a/src/Generating/ComposableGenerator.cpp
+++ b/src/Generating/ComposableGenerator.cpp
@@ -133,11 +133,6 @@ cComposableGenerator::~cComposableGenerator()
delete *itr;
}
m_FinishGens.clear();
- for (cStructureGenList::const_iterator itr = m_StructureGens.begin(); itr != m_StructureGens.end(); ++itr)
- {
- delete *itr;
- }
- m_StructureGens.clear();
delete m_CompositionGen;
m_CompositionGen = NULL;
@@ -164,7 +159,6 @@ void cComposableGenerator::Initialize(cIniFile & a_IniFile)
InitBiomeGen(a_IniFile);
InitHeightGen(a_IniFile);
InitCompositionGen(a_IniFile);
- InitStructureGens(a_IniFile);
InitFinishGens(a_IniFile);
}
@@ -201,14 +195,6 @@ void cComposableGenerator::DoGenerate(int a_ChunkX, int a_ChunkZ, cChunkDesc & a
m_CompositionGen->ComposeTerrain(a_ChunkDesc);
}
- if (a_ChunkDesc.IsUsingDefaultStructures())
- {
- for (cStructureGenList::iterator itr = m_StructureGens.begin(); itr != m_StructureGens.end(); ++itr)
- {
- (*itr)->GenStructures(a_ChunkDesc);
- } // for itr - m_StructureGens[]
- }
-
if (a_ChunkDesc.IsUsingDefaultFinish())
{
for (cFinishGenList::iterator itr = m_FinishGens.begin(); itr != m_FinishGens.end(); ++itr)
@@ -290,35 +276,69 @@ void cComposableGenerator::InitCompositionGen(cIniFile & a_IniFile)
-void cComposableGenerator::InitStructureGens(cIniFile & a_IniFile)
+void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile)
{
- AString Structures = a_IniFile.GetValueSet("Generator", "Structures", "Ravines, WormNestCaves, WaterLakes, LavaLakes, OreNests, Trees");
-
int Seed = m_ChunkGenerator.GetSeed();
- AStringVector Str = StringSplitAndTrim(Structures, ",");
+ eDimension Dimension = StringToDimension(a_IniFile.GetValue("General", "Dimension", "Overworld"));
+
+ // Older configuration used "Structures" in addition to "Finishers"; we don't distinguish between the two anymore (#398)
+ // Therefore, we load Structures from the ini file for compatibility, but move its contents over to Finishers:
+ AString Structures = a_IniFile.GetValue("Generator", "Structures", "");
+ AString Finishers = a_IniFile.GetValueSet("Generator", "Finishers", "Ravines, WormNestCaves, WaterLakes, LavaLakes, OreNests, Trees, SprinkleFoliage, Ice, Snow, Lilypads, BottomLava, DeadBushes, PreSimulator");
+ if (!Structures.empty())
+ {
+ LOGINFO("[Generator].Structures is deprecated, moving the contents to [Generator].Finishers.");
+ // Structures used to generate before Finishers, so place them first:
+ Structures.append(", ");
+ Finishers = Structures + Finishers;
+ a_IniFile.SetValue("Generator", "Finishers", Finishers);
+ }
+ a_IniFile.DeleteValue("Generator", "Structures");
+
+ // Create all requested finishers:
+ AStringVector Str = StringSplitAndTrim(Finishers, ",");
for (AStringVector::const_iterator itr = Str.begin(); itr != Str.end(); ++itr)
{
- if (NoCaseCompare(*itr, "DualRidgeCaves") == 0)
+ // Finishers, alpha-sorted:
+ if (NoCaseCompare(*itr, "BottomLava") == 0)
{
- float Threshold = (float)a_IniFile.GetValueSetF("Generator", "DualRidgeCavesThreshold", 0.3);
- m_StructureGens.push_back(new cStructGenDualRidgeCaves(Seed, Threshold));
+ int DefaultBottomLavaLevel = (Dimension == dimNether) ? 30 : 10;
+ int BottomLavaLevel = a_IniFile.GetValueSetI("Generator", "BottomLavaLevel", DefaultBottomLavaLevel);
+ m_FinishGens.push_back(new cFinishGenBottomLava(BottomLavaLevel));
+ }
+ else if (NoCaseCompare(*itr, "DeadBushes") == 0)
+ {
+ m_FinishGens.push_back(new cFinishGenSingleBiomeSingleTopBlock(Seed, E_BLOCK_DEAD_BUSH, biDesert, 2, E_BLOCK_SAND, E_BLOCK_SAND));
}
else if (NoCaseCompare(*itr, "DirectOverhangs") == 0)
{
- m_StructureGens.push_back(new cStructGenDirectOverhangs(Seed));
+ m_FinishGens.push_back(new cStructGenDirectOverhangs(Seed));
}
else if (NoCaseCompare(*itr, "DistortedMembraneOverhangs") == 0)
{
- m_StructureGens.push_back(new cStructGenDistortedMembraneOverhangs(Seed));
+ m_FinishGens.push_back(new cStructGenDistortedMembraneOverhangs(Seed));
+ }
+ else if (NoCaseCompare(*itr, "DualRidgeCaves") == 0)
+ {
+ float Threshold = (float)a_IniFile.GetValueSetF("Generator", "DualRidgeCavesThreshold", 0.3);
+ m_FinishGens.push_back(new cStructGenDualRidgeCaves(Seed, Threshold));
+ }
+ else if (NoCaseCompare(*itr, "Ice") == 0)
+ {
+ m_FinishGens.push_back(new cFinishGenIce);
}
else if (NoCaseCompare(*itr, "LavaLakes") == 0)
{
int Probability = a_IniFile.GetValueSetI("Generator", "LavaLakesProbability", 10);
- m_StructureGens.push_back(new cStructGenLakes(Seed * 5 + 16873, E_BLOCK_STATIONARY_LAVA, *m_HeightGen, Probability));
+ m_FinishGens.push_back(new cStructGenLakes(Seed * 5 + 16873, E_BLOCK_STATIONARY_LAVA, *m_HeightGen, Probability));
+ }
+ else if (NoCaseCompare(*itr, "LavaSprings") == 0)
+ {
+ m_FinishGens.push_back(new cFinishGenFluidSprings(Seed, E_BLOCK_LAVA, a_IniFile, Dimension));
}
else if (NoCaseCompare(*itr, "MarbleCaves") == 0)
{
- m_StructureGens.push_back(new cStructGenMarbleCaves(Seed));
+ m_FinishGens.push_back(new cStructGenMarbleCaves(Seed));
}
else if (NoCaseCompare(*itr, "MineShafts") == 0)
{
@@ -327,71 +347,11 @@ void cComposableGenerator::InitStructureGens(cIniFile & a_IniFile)
int ChanceCorridor = a_IniFile.GetValueSetI("Generator", "MineShaftsChanceCorridor", 600);
int ChanceCrossing = a_IniFile.GetValueSetI("Generator", "MineShaftsChanceCrossing", 200);
int ChanceStaircase = a_IniFile.GetValueSetI("Generator", "MineShaftsChanceStaircase", 200);
- m_StructureGens.push_back(new cStructGenMineShafts(
+ m_FinishGens.push_back(new cStructGenMineShafts(
Seed, GridSize, MaxSystemSize,
ChanceCorridor, ChanceCrossing, ChanceStaircase
));
}
- else if (NoCaseCompare(*itr, "OreNests") == 0)
- {
- m_StructureGens.push_back(new cStructGenOreNests(Seed));
- }
- else if (NoCaseCompare(*itr, "Ravines") == 0)
- {
- m_StructureGens.push_back(new cStructGenRavines(Seed, 128));
- }
- else if (NoCaseCompare(*itr, "Trees") == 0)
- {
- m_StructureGens.push_back(new cStructGenTrees(Seed, m_BiomeGen, m_HeightGen, m_CompositionGen));
- }
- else if (NoCaseCompare(*itr, "WaterLakes") == 0)
- {
- int Probability = a_IniFile.GetValueSetI("Generator", "WaterLakesProbability", 25);
- m_StructureGens.push_back(new cStructGenLakes(Seed * 3 + 652, E_BLOCK_STATIONARY_WATER, *m_HeightGen, Probability));
- }
- else if (NoCaseCompare(*itr, "WormNestCaves") == 0)
- {
- m_StructureGens.push_back(new cStructGenWormNestCaves(Seed));
- }
- else
- {
- LOGWARNING("Unknown structure generator: \"%s\". Ignoring.", itr->c_str());
- }
- } // for itr - Str[]
-}
-
-
-
-
-
-void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile)
-{
- int Seed = m_ChunkGenerator.GetSeed();
- eDimension Dimension = StringToDimension(a_IniFile.GetValue("General", "Dimension", "Overworld"));
-
- AString Finishers = a_IniFile.GetValueSet("Generator", "Finishers", "SprinkleFoliage,Ice,Snow,Lilypads,BottomLava,DeadBushes,PreSimulator");
- AStringVector Str = StringSplitAndTrim(Finishers, ",");
- for (AStringVector::const_iterator itr = Str.begin(); itr != Str.end(); ++itr)
- {
- // Finishers, alpha-sorted:
- if (NoCaseCompare(*itr, "BottomLava") == 0)
- {
- int DefaultBottomLavaLevel = (Dimension == dimNether) ? 30 : 10;
- int BottomLavaLevel = a_IniFile.GetValueSetI("Generator", "BottomLavaLevel", DefaultBottomLavaLevel);
- m_FinishGens.push_back(new cFinishGenBottomLava(BottomLavaLevel));
- }
- else if (NoCaseCompare(*itr, "DeadBushes") == 0)
- {
- m_FinishGens.push_back(new cFinishGenSingleBiomeSingleTopBlock(Seed, E_BLOCK_DEAD_BUSH, biDesert, 2, E_BLOCK_SAND, E_BLOCK_SAND));
- }
- else if (NoCaseCompare(*itr, "Ice") == 0)
- {
- m_FinishGens.push_back(new cFinishGenIce);
- }
- else if (NoCaseCompare(*itr, "LavaSprings") == 0)
- {
- m_FinishGens.push_back(new cFinishGenFluidSprings(Seed, E_BLOCK_LAVA, a_IniFile, Dimension));
- }
else if (NoCaseCompare(*itr, "Lilypads") == 0)
{
m_FinishGens.push_back(new cFinishGenSingleBiomeSingleTopBlock(Seed, E_BLOCK_LILY_PAD, biSwampland, 4, E_BLOCK_WATER, E_BLOCK_STATIONARY_WATER));
@@ -400,10 +360,18 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile)
{
m_FinishGens.push_back(new cFinishGenNetherClumpFoliage(Seed));
}
+ else if (NoCaseCompare(*itr, "OreNests") == 0)
+ {
+ m_FinishGens.push_back(new cStructGenOreNests(Seed));
+ }
else if (NoCaseCompare(*itr, "PreSimulator") == 0)
{
m_FinishGens.push_back(new cFinishGenPreSimulator);
}
+ else if (NoCaseCompare(*itr, "Ravines") == 0)
+ {
+ m_FinishGens.push_back(new cStructGenRavines(Seed, 128));
+ }
else if (NoCaseCompare(*itr, "Snow") == 0)
{
m_FinishGens.push_back(new cFinishGenSnow);
@@ -412,10 +380,27 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile)
{
m_FinishGens.push_back(new cFinishGenSprinkleFoliage(Seed));
}
+ else if (NoCaseCompare(*itr, "Trees") == 0)
+ {
+ m_FinishGens.push_back(new cStructGenTrees(Seed, m_BiomeGen, m_HeightGen, m_CompositionGen));
+ }
+ else if (NoCaseCompare(*itr, "WaterLakes") == 0)
+ {
+ int Probability = a_IniFile.GetValueSetI("Generator", "WaterLakesProbability", 25);
+ m_FinishGens.push_back(new cStructGenLakes(Seed * 3 + 652, E_BLOCK_STATIONARY_WATER, *m_HeightGen, Probability));
+ }
else if (NoCaseCompare(*itr, "WaterSprings") == 0)
{
m_FinishGens.push_back(new cFinishGenFluidSprings(Seed, E_BLOCK_WATER, a_IniFile, Dimension));
}
+ else if (NoCaseCompare(*itr, "WormNestCaves") == 0)
+ {
+ m_FinishGens.push_back(new cStructGenWormNestCaves(Seed));
+ }
+ else
+ {
+ LOGWARNING("Unknown Finisher in the [Generator] section: \"%s\". Ignoring.", itr->c_str());
+ }
} // for itr - Str[]
}
diff --git a/src/Generating/ComposableGenerator.h b/src/Generating/ComposableGenerator.h
index 29add0636..6b7627d2e 100644
--- a/src/Generating/ComposableGenerator.h
+++ b/src/Generating/ComposableGenerator.h
@@ -43,16 +43,16 @@ class cBiomeGen
public:
virtual ~cBiomeGen() {} // Force a virtual destructor in descendants
- /// Generates biomes for the given chunk
+ /** Generates biomes for the given chunk */
virtual void GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap) = 0;
- /// Reads parameters from the ini file, prepares generator for use.
+ /** Reads parameters from the ini file, prepares generator for use. */
virtual void InitializeBiomeGen(cIniFile & a_IniFile) {}
- /// Creates the correct BiomeGen descendant based on the ini file settings and the seed provided.
- /// a_CacheOffByDefault gets set to whether the cache should be disabled by default
- /// Used in BiomeVisualiser, too.
- /// Implemented in BioGen.cpp!
+ /** Creates the correct BiomeGen descendant based on the ini file settings and the seed provided.
+ a_CacheOffByDefault gets set to whether the cache should be disabled by default.
+ Used in BiomeVisualiser, too.
+ Implemented in BioGen.cpp! */
static cBiomeGen * CreateBiomeGen(cIniFile & a_IniFile, int a_Seed, bool & a_CacheOffByDefault);
} ;
@@ -72,10 +72,10 @@ class cTerrainHeightGen
public:
virtual ~cTerrainHeightGen() {} // Force a virtual destructor in descendants
- /// Generates heightmap for the given chunk
+ /** Generates heightmap for the given chunk */
virtual void GenHeightMap(int a_ChunkX, int a_ChunkZ, cChunkDef::HeightMap & a_HeightMap) = 0;
- /// Reads parameters from the ini file, prepares generator for use.
+ /** Reads parameters from the ini file, prepares generator for use. */
virtual void InitializeHeightGen(cIniFile & a_IniFile) {}
/** Creates the correct TerrainHeightGen descendant based on the ini file settings and the seed provided.
@@ -102,7 +102,7 @@ public:
virtual void ComposeTerrain(cChunkDesc & a_ChunkDesc) = 0;
- /// Reads parameters from the ini file, prepares generator for use.
+ /** Reads parameters from the ini file, prepares generator for use. */
virtual void InitializeCompoGen(cIniFile & a_IniFile) {}
/** Creates the correct TerrainCompositionGen descendant based on the ini file settings and the seed provided.
@@ -116,28 +116,12 @@ public:
-/** The interface that a structure generator must implement
-Structures are generated after the terrain composition took place. It should modify the blocktype data to account
-for whatever structures the generator is generating.
-Note that ores are considered structures too, at least from the interface point of view.
-Also note that a worldgenerator may contain multiple structure generators, one for each type of structure
-*/
-class cStructureGen
-{
-public:
- virtual ~cStructureGen() {} // Force a virtual destructor in descendants
-
- virtual void GenStructures(cChunkDesc & a_ChunkDesc) = 0;
-} ;
-
-typedef std::list cStructureGenList;
-
-
-
-
-
/** The interface that a finisher must implement
-Finisher implements small additions after all structures have been generated.
+Finisher implements changes to the chunk after the rough terrain has been generated.
+Examples of finishers are trees, snow, ore, lilypads and others.
+Note that a worldgenerator may contain multiple finishers.
+Also note that previously we used to distinguish between a structuregen and a finisher; this distinction is
+no longer relevant, all structure generators are considered finishers now (#398)
*/
class cFinishGen
{
@@ -171,7 +155,6 @@ protected:
cBiomeGen * m_BiomeGen;
cTerrainHeightGen * m_HeightGen;
cTerrainCompositionGen * m_CompositionGen;
- cStructureGenList m_StructureGens;
cFinishGenList m_FinishGens;
// Generators underlying the caches:
@@ -180,19 +163,16 @@ protected:
cTerrainCompositionGen * m_UnderlyingCompositionGen;
- /// Reads the biome gen settings from the ini and initializes m_BiomeGen accordingly
+ /** Reads the biome gen settings from the ini and initializes m_BiomeGen accordingly */
void InitBiomeGen(cIniFile & a_IniFile);
- /// Reads the HeightGen settings from the ini and initializes m_HeightGen accordingly
+ /** Reads the HeightGen settings from the ini and initializes m_HeightGen accordingly */
void InitHeightGen(cIniFile & a_IniFile);
- /// Reads the CompositionGen settings from the ini and initializes m_CompositionGen accordingly
+ /** Reads the CompositionGen settings from the ini and initializes m_CompositionGen accordingly */
void InitCompositionGen(cIniFile & a_IniFile);
- /// Reads the structures to generate from the ini and initializes m_StructureGens accordingly
- void InitStructureGens(cIniFile & a_IniFile);
-
- /// Reads the finishers from the ini and initializes m_FinishGens accordingly
+ /** Reads the finishers from the ini and initializes m_FinishGens accordingly */
void InitFinishGens(cIniFile & a_IniFile);
} ;
diff --git a/src/Generating/MineShafts.cpp b/src/Generating/MineShafts.cpp
index cc39cef7b..d9acc57bb 100644
--- a/src/Generating/MineShafts.cpp
+++ b/src/Generating/MineShafts.cpp
@@ -1407,7 +1407,7 @@ void cStructGenMineShafts::GetMineShaftSystemsForChunk(
-void cStructGenMineShafts::GenStructures(cChunkDesc & a_ChunkDesc)
+void cStructGenMineShafts::GenFinish(cChunkDesc & a_ChunkDesc)
{
int ChunkX = a_ChunkDesc.GetChunkX();
int ChunkZ = a_ChunkDesc.GetChunkZ();
diff --git a/src/Generating/MineShafts.h b/src/Generating/MineShafts.h
index c53d3bc53..ba32e75ad 100644
--- a/src/Generating/MineShafts.h
+++ b/src/Generating/MineShafts.h
@@ -17,7 +17,7 @@
class cStructGenMineShafts :
- public cStructureGen
+ public cFinishGen
{
public:
cStructGenMineShafts(
@@ -52,8 +52,8 @@ protected:
*/
void GetMineShaftSystemsForChunk(int a_ChunkX, int a_ChunkZ, cMineShaftSystems & a_MineShaftSystems);
- // cStructureGen overrides:
- virtual void GenStructures(cChunkDesc & a_ChunkDesc) override;
+ // cFinishGen overrides:
+ virtual void GenFinish(cChunkDesc & a_ChunkDesc) override;
} ;
diff --git a/src/Generating/Ravines.cpp b/src/Generating/Ravines.cpp
index cfda47e32..e64f55214 100644
--- a/src/Generating/Ravines.cpp
+++ b/src/Generating/Ravines.cpp
@@ -117,7 +117,7 @@ void cStructGenRavines::ClearCache(void)
-void cStructGenRavines::GenStructures(cChunkDesc & a_ChunkDesc)
+void cStructGenRavines::GenFinish(cChunkDesc & a_ChunkDesc)
{
int ChunkX = a_ChunkDesc.GetChunkX();
int ChunkZ = a_ChunkDesc.GetChunkZ();
diff --git a/src/Generating/Ravines.h b/src/Generating/Ravines.h
index 05164a5b2..c76b9f19f 100644
--- a/src/Generating/Ravines.h
+++ b/src/Generating/Ravines.h
@@ -17,7 +17,7 @@
class cStructGenRavines :
- public cStructureGen
+ public cFinishGen
{
public:
cStructGenRavines(int a_Seed, int a_Size);
@@ -37,8 +37,8 @@ protected:
/// Returns all ravines that *may* intersect the given chunk. All the ravines are valid until the next call to this function.
void GetRavinesForChunk(int a_ChunkX, int a_ChunkZ, cRavines & a_Ravines);
- // cStructureGen override:
- virtual void GenStructures(cChunkDesc & a_ChunkDesc) override;
+ // cFinishGen override:
+ virtual void GenFinish(cChunkDesc & a_ChunkDesc) override;
} ;
diff --git a/src/Generating/StructGen.cpp b/src/Generating/StructGen.cpp
index 47945cc2b..3cc8a09c3 100644
--- a/src/Generating/StructGen.cpp
+++ b/src/Generating/StructGen.cpp
@@ -54,7 +54,7 @@ const int NEST_SIZE_GRAVEL = 32;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cStructGenTrees:
-void cStructGenTrees::GenStructures(cChunkDesc & a_ChunkDesc)
+void cStructGenTrees::GenFinish(cChunkDesc & a_ChunkDesc)
{
int ChunkX = a_ChunkDesc.GetChunkX();
int ChunkZ = a_ChunkDesc.GetChunkZ();
@@ -306,7 +306,7 @@ int cStructGenTrees::GetNumTrees(
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cStructGenOreNests:
-void cStructGenOreNests::GenStructures(cChunkDesc & a_ChunkDesc)
+void cStructGenOreNests::GenFinish(cChunkDesc & a_ChunkDesc)
{
int ChunkX = a_ChunkDesc.GetChunkX();
int ChunkZ = a_ChunkDesc.GetChunkZ();
@@ -413,7 +413,7 @@ void cStructGenOreNests::GenerateOre(int a_ChunkX, int a_ChunkZ, BLOCKTYPE a_Ore
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cStructGenLakes:
-void cStructGenLakes::GenStructures(cChunkDesc & a_ChunkDesc)
+void cStructGenLakes::GenFinish(cChunkDesc & a_ChunkDesc)
{
int ChunkX = a_ChunkDesc.GetChunkX();
int ChunkZ = a_ChunkDesc.GetChunkZ();
@@ -545,7 +545,7 @@ cStructGenDirectOverhangs::cStructGenDirectOverhangs(int a_Seed) :
-void cStructGenDirectOverhangs::GenStructures(cChunkDesc & a_ChunkDesc)
+void cStructGenDirectOverhangs::GenFinish(cChunkDesc & a_ChunkDesc)
{
// If there is no column of the wanted biome, bail out:
if (!HasWantedBiome(a_ChunkDesc))
@@ -665,7 +665,7 @@ cStructGenDistortedMembraneOverhangs::cStructGenDistortedMembraneOverhangs(int a
-void cStructGenDistortedMembraneOverhangs::GenStructures(cChunkDesc & a_ChunkDesc)
+void cStructGenDistortedMembraneOverhangs::GenFinish(cChunkDesc & a_ChunkDesc)
{
const NOISE_DATATYPE Frequency = (NOISE_DATATYPE)16;
const NOISE_DATATYPE Amount = (NOISE_DATATYPE)1;
diff --git a/src/Generating/StructGen.h b/src/Generating/StructGen.h
index 853748bb8..9176bc192 100644
--- a/src/Generating/StructGen.h
+++ b/src/Generating/StructGen.h
@@ -21,7 +21,7 @@
class cStructGenTrees :
- public cStructureGen
+ public cFinishGen
{
public:
cStructGenTrees(int a_Seed, cBiomeGen * a_BiomeGen, cTerrainHeightGen * a_HeightGen, cTerrainCompositionGen * a_CompositionGen) :
@@ -64,8 +64,8 @@ protected:
const cChunkDef::BiomeMap & a_Biomes
);
- // cStructureGen override:
- virtual void GenStructures(cChunkDesc & a_ChunkDesc) override;
+ // cFinishGen override:
+ virtual void GenFinish(cChunkDesc & a_ChunkDesc) override;
} ;
@@ -73,7 +73,7 @@ protected:
class cStructGenOreNests :
- public cStructureGen
+ public cFinishGen
{
public:
cStructGenOreNests(int a_Seed) : m_Noise(a_Seed), m_Seed(a_Seed) {}
@@ -82,8 +82,8 @@ protected:
cNoise m_Noise;
int m_Seed;
- // cStructureGen override:
- virtual void GenStructures(cChunkDesc & a_ChunkDesc) override;
+ // cFinishGen override:
+ virtual void GenFinish(cChunkDesc & a_ChunkDesc) override;
void GenerateOre(int a_ChunkX, int a_ChunkZ, BLOCKTYPE a_OreType, int a_MaxHeight, int a_NumNests, int a_NestSize, cChunkDef::BlockTypes & a_BlockTypes, int a_Seq);
} ;
@@ -93,7 +93,7 @@ protected:
class cStructGenLakes :
- public cStructureGen
+ public cFinishGen
{
public:
cStructGenLakes(int a_Seed, BLOCKTYPE a_Fluid, cTerrainHeightGen & a_HeiGen, int a_Probability) :
@@ -112,8 +112,8 @@ protected:
cTerrainHeightGen & m_HeiGen;
int m_Probability; ///< Chance, 0 .. 100, of a chunk having the lake
- // cStructureGen override:
- virtual void GenStructures(cChunkDesc & a_ChunkDesc) override;
+ // cFinishGen override:
+ virtual void GenFinish(cChunkDesc & a_ChunkDesc) override;
/// Creates a lake image for the specified chunk into a_Lake
void CreateLakeImage(int a_ChunkX, int a_ChunkZ, cBlockArea & a_Lake);
@@ -125,7 +125,7 @@ protected:
class cStructGenDirectOverhangs :
- public cStructureGen
+ public cFinishGen
{
public:
cStructGenDirectOverhangs(int a_Seed);
@@ -134,8 +134,8 @@ protected:
cNoise m_Noise1;
cNoise m_Noise2;
- // cStructureGen override:
- virtual void GenStructures(cChunkDesc & a_ChunkDesc) override;
+ // cFinishGen override:
+ virtual void GenFinish(cChunkDesc & a_ChunkDesc) override;
bool HasWantedBiome(cChunkDesc & a_ChunkDesc) const;
} ;
@@ -145,7 +145,7 @@ protected:
class cStructGenDistortedMembraneOverhangs :
- public cStructureGen
+ public cFinishGen
{
public:
cStructGenDistortedMembraneOverhangs(int a_Seed);
@@ -156,8 +156,8 @@ protected:
cNoise m_NoiseZ;
cNoise m_NoiseH;
- // cStructureGen override:
- virtual void GenStructures(cChunkDesc & a_ChunkDesc) override;
+ // cFinishGen override:
+ virtual void GenFinish(cChunkDesc & a_ChunkDesc) override;
} ;
--
cgit v1.2.3
From 2325a1a162a888e34ed7f80b2e59d3987b034b51 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Sat, 1 Mar 2014 20:59:22 +0100
Subject: ChunkDesc warns about StructureGen's deprecation.
---
src/Generating/ChunkDesc.cpp | 2 ++
1 file changed, 2 insertions(+)
diff --git a/src/Generating/ChunkDesc.cpp b/src/Generating/ChunkDesc.cpp
index d9529b4b0..308fbe423 100644
--- a/src/Generating/ChunkDesc.cpp
+++ b/src/Generating/ChunkDesc.cpp
@@ -209,6 +209,7 @@ bool cChunkDesc::IsUsingDefaultComposition(void) const
void cChunkDesc::SetUseDefaultStructures(bool a_bUseDefaultStructures)
{
+ LOGWARNING("%s: Structures are no longer accounted for, use Finishers instead", __FUNCTION__);
m_bUseDefaultStructures = a_bUseDefaultStructures;
}
@@ -218,6 +219,7 @@ void cChunkDesc::SetUseDefaultStructures(bool a_bUseDefaultStructures)
bool cChunkDesc::IsUsingDefaultStructures(void) const
{
+ LOGWARNING("%s: Structures are no longer accounted for, use Finishers instead", __FUNCTION__);
return m_bUseDefaultStructures;
}
--
cgit v1.2.3
From 2998228e85bb535ea49f3ef0d7314274a72dd9b9 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Sun, 2 Mar 2014 08:22:27 +0100
Subject: Added more documentation for FastNBT parser.
---
src/WorldStorage/FastNBT.h | 48 +++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 45 insertions(+), 3 deletions(-)
diff --git a/src/WorldStorage/FastNBT.h b/src/WorldStorage/FastNBT.h
index d68ebd54c..01a9ad274 100644
--- a/src/WorldStorage/FastNBT.h
+++ b/src/WorldStorage/FastNBT.h
@@ -106,6 +106,10 @@ public:
/** Parses and contains the parsed data
Also implements data accessor functions for tree traversal and value getters
The data pointer passed in the constructor is assumed to be valid throughout the object's life. Care must be taken not to initialize from a temporary.
+The parser decomposes the input data into a tree of tags that is stored as an array of cFastNBTTag items,
+and accessing the tree is done by using the array indices for tags. Each tag stores the indices for its parent,
+first child, last child, prev sibling and next sibling, a value of -1 indicates that the indice is not valid.
+Each primitive tag also stores the length of the contained data, in bytes.
*/
class cParsedNBT
{
@@ -114,13 +118,32 @@ public:
bool IsValid(void) const {return m_IsValid; }
+ /** Returns the root tag of the hierarchy. */
int GetRoot(void) const {return 0; }
+
+ /** Returns the first child of the specified tag, or -1 if none / not applicable. */
int GetFirstChild (int a_Tag) const { return m_Tags[a_Tag].m_FirstChild; }
+
+ /** Returns the last child of the specified tag, or -1 if none / not applicable. */
int GetLastChild (int a_Tag) const { return m_Tags[a_Tag].m_LastChild; }
+
+ /** Returns the next sibling of the specified tag, or -1 if none. */
int GetNextSibling(int a_Tag) const { return m_Tags[a_Tag].m_NextSibling; }
+
+ /** Returns the previous sibling of the specified tag, or -1 if none. */
int GetPrevSibling(int a_Tag) const { return m_Tags[a_Tag].m_PrevSibling; }
- int GetDataLength (int a_Tag) const { return m_Tags[a_Tag].m_DataLength; }
+
+ /** Returns the length of the tag's data, in bytes.
+ Not valid for Compound or List tags! */
+ int GetDataLength (int a_Tag) const
+ {
+ ASSERT(m_Tags[a_Tag].m_Type != TAG_List);
+ ASSERT(m_Tags[a_Tag].m_Type != TAG_Compound);
+ return m_Tags[a_Tag].m_DataLength;
+ }
+ /** Returns the data stored in this tag.
+ Not valid for Compound or List tags! */
const char * GetData(int a_Tag) const
{
ASSERT(m_Tags[a_Tag].m_Type != TAG_List);
@@ -128,47 +151,56 @@ public:
return m_Data + m_Tags[a_Tag].m_DataStart;
}
+ /** Returns the direct child tag of the specified name, or -1 if no such tag. */
int FindChildByName(int a_Tag, const AString & a_Name) const
{
return FindChildByName(a_Tag, a_Name.c_str(), a_Name.length());
}
+ /** Returns the direct child tag of the specified name, or -1 if no such tag. */
int FindChildByName(int a_Tag, const char * a_Name, size_t a_NameLength = 0) const;
- int FindTagByPath (int a_Tag, const AString & a_Path) const;
+
+ /** Returns the child tag of the specified path (Name1\Name2\Name3...), or -1 if no such tag. */
+ int FindTagByPath(int a_Tag, const AString & a_Path) const;
eTagType GetType(int a_Tag) const { return m_Tags[a_Tag].m_Type; }
- /// Returns the children type for a list tag; undefined on other tags. If list empty, returns TAG_End
+ /** Returns the children type for a List tag; undefined on other tags. If list empty, returns TAG_End. */
eTagType GetChildrenType(int a_Tag) const
{
ASSERT(m_Tags[a_Tag].m_Type == TAG_List);
return (m_Tags[a_Tag].m_FirstChild < 0) ? TAG_End : m_Tags[m_Tags[a_Tag].m_FirstChild].m_Type;
}
+ /** Returns the value stored in a Byte tag. Not valid for any other tag type. */
inline unsigned char GetByte(int a_Tag) const
{
ASSERT(m_Tags[a_Tag].m_Type == TAG_Byte);
return (unsigned char)(m_Data[m_Tags[a_Tag].m_DataStart]);
}
+ /** Returns the value stored in a Short tag. Not valid for any other tag type. */
inline Int16 GetShort(int a_Tag) const
{
ASSERT(m_Tags[a_Tag].m_Type == TAG_Short);
return GetBEShort(m_Data + m_Tags[a_Tag].m_DataStart);
}
+ /** Returns the value stored in an Int tag. Not valid for any other tag type. */
inline Int32 GetInt(int a_Tag) const
{
ASSERT(m_Tags[a_Tag].m_Type == TAG_Int);
return GetBEInt(m_Data + m_Tags[a_Tag].m_DataStart);
}
+ /** Returns the value stored in a Long tag. Not valid for any other tag type. */
inline Int64 GetLong(int a_Tag) const
{
ASSERT(m_Tags[a_Tag].m_Type == TAG_Long);
return NetworkToHostLong8(m_Data + m_Tags[a_Tag].m_DataStart);
}
+ /** Returns the value stored in a Float tag. Not valid for any other tag type. */
inline float GetFloat(int a_Tag) const
{
ASSERT(m_Tags[a_Tag].m_Type == TAG_Float);
@@ -186,12 +218,21 @@ public:
return f;
}
+ /** Returns the value stored in a Double tag. Not valid for any other tag type. */
inline double GetDouble(int a_Tag) const
{
+ // Cause a compile-time error if sizeof(double) != 8
+ // If your platform produces a compiler error here, you'll need to add code that manually decodes 64-bit doubles
+ char Check1[9 - sizeof(double)]; // Fails if sizeof(double) > 8
+ char Check2[sizeof(double) - 7]; // Fails if sizeof(double) < 8
+ UNUSED(Check1);
+ UNUSED(Check2);
+
ASSERT(m_Tags[a_Tag].m_Type == TAG_Double);
return NetworkToHostDouble8(m_Data + m_Tags[a_Tag].m_DataStart);
}
+ /** Returns the value stored in a String tag. Not valid for any other tag type. */
inline AString GetString(int a_Tag) const
{
ASSERT(m_Tags[a_Tag].m_Type == TAG_String);
@@ -200,6 +241,7 @@ public:
return res;
}
+ /** Returns the tag's name. For tags that are not named, returns an empty string. */
inline AString GetName(int a_Tag) const
{
AString res;
--
cgit v1.2.3
From 3ca56b39bce5ad59625d2ffb5ae730858fed8bcd Mon Sep 17 00:00:00 2001
From: andrew
Date: Sun, 2 Mar 2014 10:50:24 +0200
Subject: Exported cBlockInfo
---
MCServer/Plugins/APIDump/APIDesc.lua | 32 ++++++++++++++++++++++++++++++++
src/Bindings/AllToLua.pkg | 1 +
src/BlockInfo.h | 11 ++++++++---
3 files changed, 41 insertions(+), 3 deletions(-)
diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua
index 4d0113223..695d1a853 100644
--- a/MCServer/Plugins/APIDump/APIDesc.lua
+++ b/MCServer/Plugins/APIDump/APIDesc.lua
@@ -290,6 +290,38 @@ g_APIDesc =
}, -- AdditionalInfo
}, -- cBlockArea
+ cBlockInfo =
+ {
+ Desc = [[
+ This class is used to query and register block properties.
+ ]],
+ Functions =
+ {
+ FullyOccupiesVoxel = { Params = "ID", Return = "bool", Notes = "Returns whether the specified block fully occupies its voxel." },
+ GetById = { Params = "ID", Return = "{{cBlockInfo}}", Notes = "Returns the {{cBlockInfo}} structure for the block with the specified ID." },
+ GetLightValue = { Params = "ID", Return = "number", Notes = "Returns how much light the specified block emits on its own." },
+ GetSpreadLightFalloff = { Params = "ID", Return = "number", Notes = "Returns how much light the specified block consumes." },
+ IsOneHitDig = { Params = "ID", Return = "bool", Notes = "Returns whether the specified block will be destroyed after a single hit." },
+ IsPistonBreakable = { Params = "ID", Return = "bool", Notes = "Returns whether a piston can break the specified block." },
+ IsSnowable = { Params = "ID", Return = "bool", Notes = "Returns whether the specified block can hold snow atop." },
+ IsSolid = { Params = "ID", Return = "bool", Notes = "Returns whether the specified block is solid." },
+ IsTransparent = { Params = "ID", Return = "bool", Notes = "Returns whether the specified block is transparent." },
+ RequiresSpecialTool = { Params = "ID", Return = "bool", Notes = "Returns whether the specified block requires a special tool to drop." },
+ },
+ Variables =
+ {
+ m_FullyOccupiesVoxel = { Type = "bool", Notes = "Does this block fully occupy its voxel - is it a 'full' block?" },
+ m_IsSnowable = { Type = "bool", Notes = "Can this block hold snow atop?" },
+ m_IsSolid = { Type = "bool", Notes = "Is this block solid (player cannot walk through)?" },
+ m_LightValue = { Type = "number", Notes = "How much light do the blocks emit on their own?" },
+ m_OneHitDig = { Type = "bool", Notes = "Is a block destroyed after a single hit?" },
+ m_PistonBreakable = { Type = "bool", Notes = "Can a piston break this block?" },
+ m_RequiresSpecialTool = { Type = "bool", Notes = "Does this block require a tool to drop?" },
+ m_SpreadLightFalloff = { Type = "number", Notes = "How much light do the blocks consume?" },
+ m_Transparent = { Type = "bool", Notes = "Is a block completely transparent? (light doesn't get decreased(?))" },
+ },
+ }, -- cBlockInfo
+
cChatColor =
{
Desc = [[
diff --git a/src/Bindings/AllToLua.pkg b/src/Bindings/AllToLua.pkg
index 1a2140771..6b067b1e5 100644
--- a/src/Bindings/AllToLua.pkg
+++ b/src/Bindings/AllToLua.pkg
@@ -26,6 +26,7 @@ $cfile "WebPlugin.h"
$cfile "LuaWindow.h"
$cfile "../BlockID.h"
+$cfile "../BlockInfo.h"
$cfile "../StringUtils.h"
$cfile "../Defines.h"
$cfile "../ChatColor.h"
diff --git a/src/BlockInfo.h b/src/BlockInfo.h
index a06c47a47..57092ca54 100644
--- a/src/BlockInfo.h
+++ b/src/BlockInfo.h
@@ -5,16 +5,19 @@
-
+// tolua_begin
class cBlockInfo
{
public:
+ // tolua_end
cBlockInfo();
/** (Re-)Initializes the internal BlockInfo structures. */
static void Initialize(void);
+ // tolua_begin
+
/** Returns the associated BlockInfo structure. */
static cBlockInfo & GetById(unsigned int a_ID);
@@ -43,7 +46,7 @@ public:
/** Is this block solid (player cannot walk through)? */
bool m_IsSolid;
- /** Does this block fully occupy it's voxel - is it a 'full' block? */
+ /** Does this block fully occupy its voxel - is it a 'full' block? */
bool m_FullyOccupiesVoxel;
@@ -57,6 +60,8 @@ public:
inline static bool IsSolid (unsigned int a_ID) { return GetById(a_ID).m_IsSolid; }
inline static bool FullyOccupiesVoxel (unsigned int a_ID) { return GetById(a_ID).m_FullyOccupiesVoxel; }
+ // tolua_end
+
protected:
@@ -64,7 +69,7 @@ protected:
static cBlockInfo ms_Info[256];
-};
+}; // tolua_export
--
cgit v1.2.3
From 68b75f7b7a2ff09b55526c80f4201c029fae7ce7 Mon Sep 17 00:00:00 2001
From: andrew
Date: Sun, 2 Mar 2014 11:12:29 +0200
Subject: Manually exported g_Block tables
---
src/Bindings/DeprecatedBindings.cpp | 434 ++++++++++++++++++++++++++++++++++++
src/Bindings/DeprecatedBindings.h | 8 +
src/Bindings/LuaState.cpp | 2 +
src/CMakeLists.txt | 1 +
4 files changed, 445 insertions(+)
create mode 100644 src/Bindings/DeprecatedBindings.cpp
create mode 100644 src/Bindings/DeprecatedBindings.h
diff --git a/src/Bindings/DeprecatedBindings.cpp b/src/Bindings/DeprecatedBindings.cpp
new file mode 100644
index 000000000..08d775f10
--- /dev/null
+++ b/src/Bindings/DeprecatedBindings.cpp
@@ -0,0 +1,434 @@
+
+#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
+
+#include "DeprecatedBindings.h"
+#include "tolua++/include/tolua++.h"
+
+#include "Plugin.h"
+#include "PluginLua.h"
+#include "PluginManager.h"
+#include "LuaWindow.h"
+#include "LuaChunkStay.h"
+
+#include "../BlockInfo.h"
+
+
+
+
+
+/* get function: g_BlockLightValue */
+#ifndef TOLUA_DISABLE_tolua_get_AllToLua_g_BlockLightValue
+static int tolua_get_AllToLua_g_BlockLightValue(lua_State* tolua_S)
+{
+ int tolua_index;
+ #ifndef TOLUA_RELEASE
+ {
+ tolua_Error tolua_err;
+ if (!tolua_isnumber(tolua_S,2,0,&tolua_err))
+ tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err);
+ }
+ #endif
+ tolua_index = (int)tolua_tonumber(tolua_S,2,0);
+ #ifndef TOLUA_RELEASE
+ if (tolua_index<0)
+ tolua_error(tolua_S,"array indexing out of range.",NULL);
+ #endif
+ tolua_pushnumber(tolua_S,(lua_Number)cBlockInfo::GetLightValue(tolua_index));
+ return 1;
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* set function: g_BlockLightValue */
+#ifndef TOLUA_DISABLE_tolua_set_AllToLua_g_BlockLightValue
+static int tolua_set_AllToLua_g_BlockLightValue(lua_State* tolua_S)
+{
+ int tolua_index;
+ #ifndef TOLUA_RELEASE
+ {
+ tolua_Error tolua_err;
+ if (!tolua_isnumber(tolua_S,2,0,&tolua_err))
+ tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err);
+ }
+ #endif
+ tolua_index = (int)tolua_tonumber(tolua_S,2,0);
+ #ifndef TOLUA_RELEASE
+ if (tolua_index<0)
+ tolua_error(tolua_S,"array indexing out of range.",NULL);
+ #endif
+ cBlockInfo::GetById(tolua_index).m_LightValue = ((unsigned char) tolua_tonumber(tolua_S,3,0));
+ return 0;
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* get function: g_BlockSpreadLightFalloff */
+#ifndef TOLUA_DISABLE_tolua_get_AllToLua_g_BlockSpreadLightFalloff
+static int tolua_get_AllToLua_g_BlockSpreadLightFalloff(lua_State* tolua_S)
+{
+ int tolua_index;
+ #ifndef TOLUA_RELEASE
+ {
+ tolua_Error tolua_err;
+ if (!tolua_isnumber(tolua_S,2,0,&tolua_err))
+ tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err);
+ }
+ #endif
+ tolua_index = (int)tolua_tonumber(tolua_S,2,0);
+ #ifndef TOLUA_RELEASE
+ if (tolua_index<0)
+ tolua_error(tolua_S,"array indexing out of range.",NULL);
+ #endif
+ tolua_pushnumber(tolua_S,(lua_Number)cBlockInfo::GetSpreadLightFalloff(tolua_index));
+ return 1;
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* set function: g_BlockSpreadLightFalloff */
+#ifndef TOLUA_DISABLE_tolua_set_AllToLua_g_BlockSpreadLightFalloff
+static int tolua_set_AllToLua_g_BlockSpreadLightFalloff(lua_State* tolua_S)
+{
+ int tolua_index;
+ #ifndef TOLUA_RELEASE
+ {
+ tolua_Error tolua_err;
+ if (!tolua_isnumber(tolua_S,2,0,&tolua_err))
+ tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err);
+ }
+ #endif
+ tolua_index = (int)tolua_tonumber(tolua_S,2,0);
+ #ifndef TOLUA_RELEASE
+ if (tolua_index<0)
+ tolua_error(tolua_S,"array indexing out of range.",NULL);
+ #endif
+ cBlockInfo::GetById(tolua_index).m_SpreadLightFalloff = ((unsigned char) tolua_tonumber(tolua_S,3,0));
+ return 0;
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* get function: g_BlockTransparent */
+#ifndef TOLUA_DISABLE_tolua_get_AllToLua_g_BlockTransparent
+static int tolua_get_AllToLua_g_BlockTransparent(lua_State* tolua_S)
+{
+ int tolua_index;
+ #ifndef TOLUA_RELEASE
+ {
+ tolua_Error tolua_err;
+ if (!tolua_isnumber(tolua_S,2,0,&tolua_err))
+ tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err);
+ }
+ #endif
+ tolua_index = (int)tolua_tonumber(tolua_S,2,0);
+ #ifndef TOLUA_RELEASE
+ if (tolua_index<0)
+ tolua_error(tolua_S,"array indexing out of range.",NULL);
+ #endif
+ tolua_pushboolean(tolua_S,(bool)cBlockInfo::IsTransparent(tolua_index));
+ return 1;
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* set function: g_BlockTransparent */
+#ifndef TOLUA_DISABLE_tolua_set_AllToLua_g_BlockTransparent
+static int tolua_set_AllToLua_g_BlockTransparent(lua_State* tolua_S)
+{
+ int tolua_index;
+ #ifndef TOLUA_RELEASE
+ {
+ tolua_Error tolua_err;
+ if (!tolua_isnumber(tolua_S,2,0,&tolua_err))
+ tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err);
+ }
+ #endif
+ tolua_index = (int)tolua_tonumber(tolua_S,2,0);
+ #ifndef TOLUA_RELEASE
+ if (tolua_index<0)
+ tolua_error(tolua_S,"array indexing out of range.",NULL);
+ #endif
+ cBlockInfo::GetById(tolua_index).m_Transparent = ((bool) tolua_toboolean(tolua_S,3,0));
+ return 0;
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* get function: g_BlockOneHitDig */
+#ifndef TOLUA_DISABLE_tolua_get_AllToLua_g_BlockOneHitDig
+static int tolua_get_AllToLua_g_BlockOneHitDig(lua_State* tolua_S)
+{
+ int tolua_index;
+ #ifndef TOLUA_RELEASE
+ {
+ tolua_Error tolua_err;
+ if (!tolua_isnumber(tolua_S,2,0,&tolua_err))
+ tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err);
+ }
+ #endif
+ tolua_index = (int)tolua_tonumber(tolua_S,2,0);
+ #ifndef TOLUA_RELEASE
+ if (tolua_index<0)
+ tolua_error(tolua_S,"array indexing out of range.",NULL);
+ #endif
+ tolua_pushboolean(tolua_S,(bool)cBlockInfo::IsOneHitDig(tolua_index));
+ return 1;
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* set function: g_BlockOneHitDig */
+#ifndef TOLUA_DISABLE_tolua_set_AllToLua_g_BlockOneHitDig
+static int tolua_set_AllToLua_g_BlockOneHitDig(lua_State* tolua_S)
+{
+ int tolua_index;
+ #ifndef TOLUA_RELEASE
+ {
+ tolua_Error tolua_err;
+ if (!tolua_isnumber(tolua_S,2,0,&tolua_err))
+ tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err);
+ }
+ #endif
+ tolua_index = (int)tolua_tonumber(tolua_S,2,0);
+ #ifndef TOLUA_RELEASE
+ if (tolua_index<0)
+ tolua_error(tolua_S,"array indexing out of range.",NULL);
+ #endif
+ cBlockInfo::GetById(tolua_index).m_OneHitDig = ((bool) tolua_toboolean(tolua_S,3,0));
+ return 0;
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* get function: g_BlockPistonBreakable */
+#ifndef TOLUA_DISABLE_tolua_get_AllToLua_g_BlockPistonBreakable
+static int tolua_get_AllToLua_g_BlockPistonBreakable(lua_State* tolua_S)
+{
+ int tolua_index;
+ #ifndef TOLUA_RELEASE
+ {
+ tolua_Error tolua_err;
+ if (!tolua_isnumber(tolua_S,2,0,&tolua_err))
+ tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err);
+ }
+ #endif
+ tolua_index = (int)tolua_tonumber(tolua_S,2,0);
+ #ifndef TOLUA_RELEASE
+ if (tolua_index<0 || tolua_index>=256)
+ tolua_error(tolua_S,"array indexing out of range.",NULL);
+ #endif
+ tolua_pushboolean(tolua_S,(bool)cBlockInfo::IsPistonBreakable(tolua_index));
+ return 1;
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* set function: g_BlockPistonBreakable */
+#ifndef TOLUA_DISABLE_tolua_set_AllToLua_g_BlockPistonBreakable
+static int tolua_set_AllToLua_g_BlockPistonBreakable(lua_State* tolua_S)
+{
+ int tolua_index;
+ #ifndef TOLUA_RELEASE
+ {
+ tolua_Error tolua_err;
+ if (!tolua_isnumber(tolua_S,2,0,&tolua_err))
+ tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err);
+ }
+ #endif
+ tolua_index = (int)tolua_tonumber(tolua_S,2,0);
+ #ifndef TOLUA_RELEASE
+ if (tolua_index<0 || tolua_index>=256)
+ tolua_error(tolua_S,"array indexing out of range.",NULL);
+ #endif
+ cBlockInfo::GetById(tolua_index).m_PistonBreakable = ((bool) tolua_toboolean(tolua_S,3,0));
+ return 0;
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* get function: g_BlockIsSnowable */
+#ifndef TOLUA_DISABLE_tolua_get_AllToLua_g_BlockIsSnowable
+static int tolua_get_AllToLua_g_BlockIsSnowable(lua_State* tolua_S)
+{
+ int tolua_index;
+ #ifndef TOLUA_RELEASE
+ {
+ tolua_Error tolua_err;
+ if (!tolua_isnumber(tolua_S,2,0,&tolua_err))
+ tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err);
+ }
+ #endif
+ tolua_index = (int)tolua_tonumber(tolua_S,2,0);
+ #ifndef TOLUA_RELEASE
+ if (tolua_index<0 || tolua_index>=256)
+ tolua_error(tolua_S,"array indexing out of range.",NULL);
+ #endif
+ tolua_pushboolean(tolua_S,(bool)cBlockInfo::IsSnowable(tolua_index));
+ return 1;
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* set function: g_BlockIsSnowable */
+#ifndef TOLUA_DISABLE_tolua_set_AllToLua_g_BlockIsSnowable
+static int tolua_set_AllToLua_g_BlockIsSnowable(lua_State* tolua_S)
+{
+ int tolua_index;
+ #ifndef TOLUA_RELEASE
+ {
+ tolua_Error tolua_err;
+ if (!tolua_isnumber(tolua_S,2,0,&tolua_err))
+ tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err);
+ }
+ #endif
+ tolua_index = (int)tolua_tonumber(tolua_S,2,0);
+ #ifndef TOLUA_RELEASE
+ if (tolua_index<0 || tolua_index>=256)
+ tolua_error(tolua_S,"array indexing out of range.",NULL);
+ #endif
+ cBlockInfo::GetById(tolua_index).m_IsSnowable = ((bool) tolua_toboolean(tolua_S,3,0));
+ return 0;
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* get function: g_BlockRequiresSpecialTool */
+#ifndef TOLUA_DISABLE_tolua_get_AllToLua_g_BlockRequiresSpecialTool
+static int tolua_get_AllToLua_g_BlockRequiresSpecialTool(lua_State* tolua_S)
+{
+ int tolua_index;
+ #ifndef TOLUA_RELEASE
+ {
+ tolua_Error tolua_err;
+ if (!tolua_isnumber(tolua_S,2,0,&tolua_err))
+ tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err);
+ }
+ #endif
+ tolua_index = (int)tolua_tonumber(tolua_S,2,0);
+ #ifndef TOLUA_RELEASE
+ if (tolua_index<0 || tolua_index>=256)
+ tolua_error(tolua_S,"array indexing out of range.",NULL);
+ #endif
+ tolua_pushboolean(tolua_S,(bool)cBlockInfo::RequiresSpecialTool(tolua_index));
+ return 1;
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* set function: g_BlockRequiresSpecialTool */
+#ifndef TOLUA_DISABLE_tolua_set_AllToLua_g_BlockRequiresSpecialTool
+static int tolua_set_AllToLua_g_BlockRequiresSpecialTool(lua_State* tolua_S)
+{
+ int tolua_index;
+ #ifndef TOLUA_RELEASE
+ {
+ tolua_Error tolua_err;
+ if (!tolua_isnumber(tolua_S,2,0,&tolua_err))
+ tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err);
+ }
+ #endif
+ tolua_index = (int)tolua_tonumber(tolua_S,2,0);
+ #ifndef TOLUA_RELEASE
+ if (tolua_index<0 || tolua_index>=256)
+ tolua_error(tolua_S,"array indexing out of range.",NULL);
+ #endif
+ cBlockInfo::GetById(tolua_index).m_RequiresSpecialTool = ((bool) tolua_toboolean(tolua_S,3,0));
+ return 0;
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* get function: g_BlockIsSolid */
+#ifndef TOLUA_DISABLE_tolua_get_AllToLua_g_BlockIsSolid
+static int tolua_get_AllToLua_g_BlockIsSolid(lua_State* tolua_S)
+{
+ int tolua_index;
+ #ifndef TOLUA_RELEASE
+ {
+ tolua_Error tolua_err;
+ if (!tolua_isnumber(tolua_S,2,0,&tolua_err))
+ tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err);
+ }
+ #endif
+ tolua_index = (int)tolua_tonumber(tolua_S,2,0);
+ #ifndef TOLUA_RELEASE
+ if (tolua_index<0 || tolua_index>=256)
+ tolua_error(tolua_S,"array indexing out of range.",NULL);
+ #endif
+ tolua_pushboolean(tolua_S,(bool)cBlockInfo::IsSolid(tolua_index));
+ return 1;
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* set function: g_BlockIsSolid */
+#ifndef TOLUA_DISABLE_tolua_set_AllToLua_g_BlockIsSolid
+static int tolua_set_AllToLua_g_BlockIsSolid(lua_State* tolua_S)
+{
+ int tolua_index;
+ #ifndef TOLUA_RELEASE
+ {
+ tolua_Error tolua_err;
+ if (!tolua_isnumber(tolua_S,2,0,&tolua_err))
+ tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err);
+ }
+ #endif
+ tolua_index = (int)tolua_tonumber(tolua_S,2,0);
+ #ifndef TOLUA_RELEASE
+ if (tolua_index<0 || tolua_index>=256)
+ tolua_error(tolua_S,"array indexing out of range.",NULL);
+ #endif
+ cBlockInfo::GetById(tolua_index).m_IsSolid = ((bool) tolua_toboolean(tolua_S,3,0));
+ return 0;
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* get function: g_BlockFullyOccupiesVoxel */
+#ifndef TOLUA_DISABLE_tolua_get_AllToLua_g_BlockFullyOccupiesVoxel
+static int tolua_get_AllToLua_g_BlockFullyOccupiesVoxel(lua_State* tolua_S)
+{
+ int tolua_index;
+ #ifndef TOLUA_RELEASE
+ {
+ tolua_Error tolua_err;
+ if (!tolua_isnumber(tolua_S,2,0,&tolua_err))
+ tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err);
+ }
+ #endif
+ tolua_index = (int)tolua_tonumber(tolua_S,2,0);
+ #ifndef TOLUA_RELEASE
+ if (tolua_index<0 || tolua_index>=256)
+ tolua_error(tolua_S,"array indexing out of range.",NULL);
+ #endif
+ tolua_pushboolean(tolua_S,(bool)cBlockInfo::FullyOccupiesVoxel(tolua_index));
+ return 1;
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* set function: g_BlockFullyOccupiesVoxel */
+#ifndef TOLUA_DISABLE_tolua_set_AllToLua_g_BlockFullyOccupiesVoxel
+static int tolua_set_AllToLua_g_BlockFullyOccupiesVoxel(lua_State* tolua_S)
+{
+ int tolua_index;
+ #ifndef TOLUA_RELEASE
+ {
+ tolua_Error tolua_err;
+ if (!tolua_isnumber(tolua_S,2,0,&tolua_err))
+ tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err);
+ }
+ #endif
+ tolua_index = (int)tolua_tonumber(tolua_S,2,0);
+ #ifndef TOLUA_RELEASE
+ if (tolua_index<0 || tolua_index>=256)
+ tolua_error(tolua_S,"array indexing out of range.",NULL);
+ #endif
+ cBlockInfo::GetById(tolua_index).m_FullyOccupiesVoxel = ((bool) tolua_toboolean(tolua_S,3,0));
+ return 0;
+}
+#endif //#ifndef TOLUA_DISABLE
+
+
+
+
+
+void DeprecatedBindings::Bind(lua_State * tolua_S)
+{
+ tolua_array(tolua_S, "g_BlockLightValue", tolua_get_AllToLua_g_BlockLightValue, tolua_set_AllToLua_g_BlockLightValue);
+ tolua_array(tolua_S, "g_BlockSpreadLightFalloff", tolua_get_AllToLua_g_BlockSpreadLightFalloff, tolua_set_AllToLua_g_BlockSpreadLightFalloff);
+ tolua_array(tolua_S, "g_BlockTransparent", tolua_get_AllToLua_g_BlockTransparent, tolua_set_AllToLua_g_BlockTransparent);
+ tolua_array(tolua_S, "g_BlockOneHitDig", tolua_get_AllToLua_g_BlockOneHitDig, tolua_set_AllToLua_g_BlockOneHitDig);
+ tolua_array(tolua_S, "g_BlockPistonBreakable", tolua_get_AllToLua_g_BlockPistonBreakable, tolua_set_AllToLua_g_BlockPistonBreakable);
+ tolua_array(tolua_S, "g_BlockIsSnowable", tolua_get_AllToLua_g_BlockIsSnowable, tolua_set_AllToLua_g_BlockIsSnowable);
+ tolua_array(tolua_S, "g_BlockRequiresSpecialTool", tolua_get_AllToLua_g_BlockRequiresSpecialTool, tolua_set_AllToLua_g_BlockRequiresSpecialTool);
+ tolua_array(tolua_S, "g_BlockIsSolid", tolua_get_AllToLua_g_BlockIsSolid, tolua_set_AllToLua_g_BlockIsSolid);
+ tolua_array(tolua_S, "g_BlockFullyOccupiesVoxel", tolua_get_AllToLua_g_BlockFullyOccupiesVoxel, tolua_set_AllToLua_g_BlockFullyOccupiesVoxel);
+}
+
+
+
+
diff --git a/src/Bindings/DeprecatedBindings.h b/src/Bindings/DeprecatedBindings.h
new file mode 100644
index 000000000..5fc3cfa80
--- /dev/null
+++ b/src/Bindings/DeprecatedBindings.h
@@ -0,0 +1,8 @@
+#pragma once
+
+struct lua_State;
+class DeprecatedBindings
+{
+public:
+ static void Bind( lua_State* tolua_S );
+};
diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp
index 45a066efe..a5540df17 100644
--- a/src/Bindings/LuaState.cpp
+++ b/src/Bindings/LuaState.cpp
@@ -14,6 +14,7 @@ extern "C"
#include "tolua++/include/tolua++.h"
#include "Bindings.h"
#include "ManualBindings.h"
+#include "DeprecatedBindings.h"
// fwd: SQLite/lsqlite3.c
extern "C"
@@ -95,6 +96,7 @@ void cLuaState::Create(void)
luaL_openlibs(m_LuaState);
tolua_AllToLua_open(m_LuaState);
ManualBindings::Bind(m_LuaState);
+ DeprecatedBindings::Bind(m_LuaState);
luaopen_lsqlite3(m_LuaState);
luaopen_lxp(m_LuaState);
m_IsOwned = true;
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 387556775..5e0731264 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -95,6 +95,7 @@ if (NOT MSVC)
#add cpp files here
add_library(Bindings
Bindings/Bindings
+ Bindings/DeprecatedBindings
Bindings/LuaChunkStay
Bindings/LuaState
Bindings/LuaWindow
--
cgit v1.2.3
From cff4ee11f125efb0b10ffe19d84869b858416584 Mon Sep 17 00:00:00 2001
From: andrew
Date: Sun, 2 Mar 2014 11:30:20 +0200
Subject: Removed g_BlockXXX arrays
---
src/Bindings/DeprecatedBindings.cpp | 4 +
src/BlockID.cpp | 399 ------------------------------------
src/BlockID.h | 14 --
src/Defines.h | 27 ---
4 files changed, 4 insertions(+), 440 deletions(-)
diff --git a/src/Bindings/DeprecatedBindings.cpp b/src/Bindings/DeprecatedBindings.cpp
index 08d775f10..3e4940494 100644
--- a/src/Bindings/DeprecatedBindings.cpp
+++ b/src/Bindings/DeprecatedBindings.cpp
@@ -418,6 +418,8 @@ static int tolua_set_AllToLua_g_BlockFullyOccupiesVoxel(lua_State* tolua_S)
void DeprecatedBindings::Bind(lua_State * tolua_S)
{
+ tolua_beginmodule(tolua_S, NULL);
+
tolua_array(tolua_S, "g_BlockLightValue", tolua_get_AllToLua_g_BlockLightValue, tolua_set_AllToLua_g_BlockLightValue);
tolua_array(tolua_S, "g_BlockSpreadLightFalloff", tolua_get_AllToLua_g_BlockSpreadLightFalloff, tolua_set_AllToLua_g_BlockSpreadLightFalloff);
tolua_array(tolua_S, "g_BlockTransparent", tolua_get_AllToLua_g_BlockTransparent, tolua_set_AllToLua_g_BlockTransparent);
@@ -427,6 +429,8 @@ void DeprecatedBindings::Bind(lua_State * tolua_S)
tolua_array(tolua_S, "g_BlockRequiresSpecialTool", tolua_get_AllToLua_g_BlockRequiresSpecialTool, tolua_set_AllToLua_g_BlockRequiresSpecialTool);
tolua_array(tolua_S, "g_BlockIsSolid", tolua_get_AllToLua_g_BlockIsSolid, tolua_set_AllToLua_g_BlockIsSolid);
tolua_array(tolua_S, "g_BlockFullyOccupiesVoxel", tolua_get_AllToLua_g_BlockFullyOccupiesVoxel, tolua_set_AllToLua_g_BlockFullyOccupiesVoxel);
+
+ tolua_endmodule(tolua_S);
}
diff --git a/src/BlockID.cpp b/src/BlockID.cpp
index ff1c54e3f..79e122032 100644
--- a/src/BlockID.cpp
+++ b/src/BlockID.cpp
@@ -12,20 +12,6 @@
-NIBBLETYPE g_BlockLightValue[256];
-NIBBLETYPE g_BlockSpreadLightFalloff[256];
-bool g_BlockTransparent[256];
-bool g_BlockOneHitDig[256];
-bool g_BlockPistonBreakable[256];
-bool g_BlockIsSnowable[256];
-bool g_BlockRequiresSpecialTool[256];
-bool g_BlockIsSolid[256];
-bool g_BlockFullyOccupiesVoxel[256];
-
-
-
-
-
class cBlockIDMap
{
// Making the map case-insensitive:
@@ -481,389 +467,4 @@ cItem GetIniItemSet(cIniFile & a_IniFile, const char * a_Section, const char * a
-// This is actually just some code that needs to run at program startup, so it is wrapped into a global var's constructor:
-class cBlockPropertiesInitializer
-{
-public:
- cBlockPropertiesInitializer(void)
- {
- memset(g_BlockLightValue, 0x00, sizeof(g_BlockLightValue));
- memset(g_BlockSpreadLightFalloff, 0x0f, sizeof(g_BlockSpreadLightFalloff)); // 0x0f means total falloff
- memset(g_BlockTransparent, 0x00, sizeof(g_BlockTransparent));
- memset(g_BlockOneHitDig, 0x00, sizeof(g_BlockOneHitDig));
- memset(g_BlockPistonBreakable, 0x00, sizeof(g_BlockPistonBreakable));
- memset(g_BlockFullyOccupiesVoxel, 0x00, sizeof(g_BlockFullyOccupiesVoxel));
-
- // Setting bools to true must be done manually, see http://forum.mc-server.org/showthread.php?tid=629&pid=5415#pid5415
- for (size_t i = 0; i < ARRAYCOUNT(g_BlockIsSnowable); i++)
- {
- g_BlockIsSnowable[i] = true;
- }
- memset(g_BlockRequiresSpecialTool, 0x00, sizeof(g_BlockRequiresSpecialTool)); // Set all blocks to false
-
- // Setting bools to true must be done manually, see http://forum.mc-server.org/showthread.php?tid=629&pid=5415#pid5415
- for (size_t i = 0; i < ARRAYCOUNT(g_BlockIsSolid); i++)
- {
- g_BlockIsSolid[i] = true;
- }
-
- // Emissive blocks
- g_BlockLightValue[E_BLOCK_FIRE] = 15;
- g_BlockLightValue[E_BLOCK_GLOWSTONE] = 15;
- g_BlockLightValue[E_BLOCK_JACK_O_LANTERN] = 15;
- g_BlockLightValue[E_BLOCK_LAVA] = 15;
- g_BlockLightValue[E_BLOCK_STATIONARY_LAVA] = 15;
- g_BlockLightValue[E_BLOCK_END_PORTAL] = 15;
- g_BlockLightValue[E_BLOCK_REDSTONE_LAMP_ON] = 15;
- g_BlockLightValue[E_BLOCK_TORCH] = 14;
- g_BlockLightValue[E_BLOCK_BURNING_FURNACE] = 13;
- g_BlockLightValue[E_BLOCK_NETHER_PORTAL] = 11;
- g_BlockLightValue[E_BLOCK_REDSTONE_ORE_GLOWING] = 9;
- g_BlockLightValue[E_BLOCK_REDSTONE_REPEATER_ON] = 9;
- g_BlockLightValue[E_BLOCK_REDSTONE_TORCH_ON] = 7;
- g_BlockLightValue[E_BLOCK_BREWING_STAND] = 1;
- g_BlockLightValue[E_BLOCK_BROWN_MUSHROOM] = 1;
- g_BlockLightValue[E_BLOCK_DRAGON_EGG] = 1;
-
- // Spread blocks
- g_BlockSpreadLightFalloff[E_BLOCK_AIR] = 1;
- g_BlockSpreadLightFalloff[E_BLOCK_CAKE] = 1;
- g_BlockSpreadLightFalloff[E_BLOCK_CHEST] = 1;
- g_BlockSpreadLightFalloff[E_BLOCK_COBWEB] = 1;
- g_BlockSpreadLightFalloff[E_BLOCK_CROPS] = 1;
- g_BlockSpreadLightFalloff[E_BLOCK_FENCE] = 1;
- g_BlockSpreadLightFalloff[E_BLOCK_FENCE_GATE] = 1;
- g_BlockSpreadLightFalloff[E_BLOCK_FIRE] = 1;
- g_BlockSpreadLightFalloff[E_BLOCK_GLASS] = 1;
- g_BlockSpreadLightFalloff[E_BLOCK_GLASS_PANE] = 1;
- g_BlockSpreadLightFalloff[E_BLOCK_GLOWSTONE] = 1;
- g_BlockSpreadLightFalloff[E_BLOCK_IRON_BARS] = 1;
- g_BlockSpreadLightFalloff[E_BLOCK_IRON_DOOR] = 1;
- g_BlockSpreadLightFalloff[E_BLOCK_LEAVES] = 1;
- g_BlockSpreadLightFalloff[E_BLOCK_SIGN_POST] = 1;
- g_BlockSpreadLightFalloff[E_BLOCK_TORCH] = 1;
- g_BlockSpreadLightFalloff[E_BLOCK_VINES] = 1;
- g_BlockSpreadLightFalloff[E_BLOCK_WALLSIGN] = 1;
- g_BlockSpreadLightFalloff[E_BLOCK_WOODEN_DOOR] = 1;
-
- // Light in water and lava dissapears faster:
- g_BlockSpreadLightFalloff[E_BLOCK_LAVA] = 3;
- g_BlockSpreadLightFalloff[E_BLOCK_STATIONARY_LAVA] = 3;
- g_BlockSpreadLightFalloff[E_BLOCK_STATIONARY_WATER] = 3;
- g_BlockSpreadLightFalloff[E_BLOCK_WATER] = 3;
-
- // Transparent blocks
- g_BlockTransparent[E_BLOCK_ACTIVATOR_RAIL] = true;
- g_BlockTransparent[E_BLOCK_AIR] = true;
- g_BlockTransparent[E_BLOCK_BIG_FLOWER] = true;
- g_BlockTransparent[E_BLOCK_BROWN_MUSHROOM] = true;
- g_BlockTransparent[E_BLOCK_CARROTS] = true;
- g_BlockTransparent[E_BLOCK_CHEST] = true;
- g_BlockTransparent[E_BLOCK_COBWEB] = true;
- g_BlockTransparent[E_BLOCK_CROPS] = true;
- g_BlockTransparent[E_BLOCK_DANDELION] = true;
- g_BlockTransparent[E_BLOCK_DETECTOR_RAIL] = true;
- g_BlockTransparent[E_BLOCK_ENDER_CHEST] = true;
- g_BlockTransparent[E_BLOCK_FENCE] = true;
- g_BlockTransparent[E_BLOCK_FENCE_GATE] = true;
- g_BlockTransparent[E_BLOCK_FIRE] = true;
- g_BlockTransparent[E_BLOCK_FLOWER] = true;
- g_BlockTransparent[E_BLOCK_FLOWER_POT] = true;
- g_BlockTransparent[E_BLOCK_GLASS] = true;
- g_BlockTransparent[E_BLOCK_GLASS_PANE] = true;
- g_BlockTransparent[E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE] = true;
- g_BlockTransparent[E_BLOCK_ICE] = true;
- g_BlockTransparent[E_BLOCK_IRON_DOOR] = true;
- g_BlockTransparent[E_BLOCK_LAVA] = true;
- g_BlockTransparent[E_BLOCK_LEAVES] = true;
- g_BlockTransparent[E_BLOCK_LEVER] = true;
- g_BlockTransparent[E_BLOCK_LIGHT_WEIGHTED_PRESSURE_PLATE] = true;
- g_BlockTransparent[E_BLOCK_MELON_STEM] = true;
- g_BlockTransparent[E_BLOCK_NETHER_BRICK_FENCE] = true;
- g_BlockTransparent[E_BLOCK_NEW_LEAVES] = true;
- g_BlockTransparent[E_BLOCK_POTATOES] = true;
- g_BlockTransparent[E_BLOCK_POWERED_RAIL] = true;
- g_BlockTransparent[E_BLOCK_PISTON_EXTENSION] = true;
- g_BlockTransparent[E_BLOCK_PUMPKIN_STEM] = true;
- g_BlockTransparent[E_BLOCK_RAIL] = true;
- g_BlockTransparent[E_BLOCK_RED_MUSHROOM] = true;
- g_BlockTransparent[E_BLOCK_SIGN_POST] = true;
- g_BlockTransparent[E_BLOCK_SNOW] = true;
- g_BlockTransparent[E_BLOCK_STAINED_GLASS] = true;
- g_BlockTransparent[E_BLOCK_STAINED_GLASS_PANE] = true;
- g_BlockTransparent[E_BLOCK_STATIONARY_LAVA] = true;
- g_BlockTransparent[E_BLOCK_STATIONARY_WATER] = true;
- g_BlockTransparent[E_BLOCK_STONE_BUTTON] = true;
- g_BlockTransparent[E_BLOCK_STONE_PRESSURE_PLATE] = true;
- g_BlockTransparent[E_BLOCK_TALL_GRASS] = true;
- g_BlockTransparent[E_BLOCK_TORCH] = true;
- g_BlockTransparent[E_BLOCK_VINES] = true;
- g_BlockTransparent[E_BLOCK_WALLSIGN] = true;
- g_BlockTransparent[E_BLOCK_WATER] = true;
- g_BlockTransparent[E_BLOCK_WOODEN_BUTTON] = true;
- g_BlockTransparent[E_BLOCK_WOODEN_DOOR] = true;
- g_BlockTransparent[E_BLOCK_WOODEN_PRESSURE_PLATE] = true;
-
- // TODO: Any other transparent blocks?
-
- // One hit break blocks:
- g_BlockOneHitDig[E_BLOCK_ACTIVE_COMPARATOR] = true;
- g_BlockOneHitDig[E_BLOCK_BIG_FLOWER] = true;
- g_BlockOneHitDig[E_BLOCK_BROWN_MUSHROOM] = true;
- g_BlockOneHitDig[E_BLOCK_CARROTS] = true;
- g_BlockOneHitDig[E_BLOCK_CROPS] = true;
- g_BlockOneHitDig[E_BLOCK_DANDELION] = true;
- g_BlockOneHitDig[E_BLOCK_FIRE] = true;
- g_BlockOneHitDig[E_BLOCK_FLOWER] = true;
- g_BlockOneHitDig[E_BLOCK_FLOWER_POT] = true;
- g_BlockOneHitDig[E_BLOCK_INACTIVE_COMPARATOR] = true;
- g_BlockOneHitDig[E_BLOCK_MELON_STEM] = true;
- g_BlockOneHitDig[E_BLOCK_POTATOES] = true;
- g_BlockOneHitDig[E_BLOCK_PUMPKIN_STEM] = true;
- g_BlockOneHitDig[E_BLOCK_REDSTONE_REPEATER_OFF] = true;
- g_BlockOneHitDig[E_BLOCK_REDSTONE_REPEATER_ON] = true;
- g_BlockOneHitDig[E_BLOCK_REDSTONE_TORCH_OFF] = true;
- g_BlockOneHitDig[E_BLOCK_REDSTONE_TORCH_ON] = true;
- g_BlockOneHitDig[E_BLOCK_REDSTONE_WIRE] = true;
- g_BlockOneHitDig[E_BLOCK_RED_MUSHROOM] = true;
- g_BlockOneHitDig[E_BLOCK_REEDS] = true;
- g_BlockOneHitDig[E_BLOCK_SAPLING] = true;
- g_BlockOneHitDig[E_BLOCK_TNT] = true;
- g_BlockOneHitDig[E_BLOCK_TALL_GRASS] = true;
- g_BlockOneHitDig[E_BLOCK_TORCH] = true;
-
- // Blocks that break when pushed by piston:
- g_BlockPistonBreakable[E_BLOCK_ACTIVE_COMPARATOR] = true;
- g_BlockPistonBreakable[E_BLOCK_AIR] = true;
- g_BlockPistonBreakable[E_BLOCK_BED] = true;
- g_BlockPistonBreakable[E_BLOCK_BIG_FLOWER] = true;
- g_BlockPistonBreakable[E_BLOCK_BROWN_MUSHROOM] = true;
- g_BlockPistonBreakable[E_BLOCK_COBWEB] = true;
- g_BlockPistonBreakable[E_BLOCK_CROPS] = true;
- g_BlockPistonBreakable[E_BLOCK_DANDELION] = true;
- g_BlockPistonBreakable[E_BLOCK_DEAD_BUSH] = true;
- g_BlockPistonBreakable[E_BLOCK_FIRE] = true;
- g_BlockPistonBreakable[E_BLOCK_FLOWER] = true;
- g_BlockPistonBreakable[E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE] = true;
- g_BlockPistonBreakable[E_BLOCK_INACTIVE_COMPARATOR] = true;
- g_BlockPistonBreakable[E_BLOCK_IRON_DOOR] = true;
- g_BlockPistonBreakable[E_BLOCK_JACK_O_LANTERN] = true;
- g_BlockPistonBreakable[E_BLOCK_LIGHT_WEIGHTED_PRESSURE_PLATE] = true;
- g_BlockPistonBreakable[E_BLOCK_LADDER] = true;
- g_BlockPistonBreakable[E_BLOCK_LAVA] = true;
- g_BlockPistonBreakable[E_BLOCK_LEVER] = true;
- g_BlockPistonBreakable[E_BLOCK_MELON] = true;
- g_BlockPistonBreakable[E_BLOCK_MELON_STEM] = true;
- g_BlockPistonBreakable[E_BLOCK_PUMPKIN] = true;
- g_BlockPistonBreakable[E_BLOCK_PUMPKIN_STEM] = true;
- g_BlockPistonBreakable[E_BLOCK_REDSTONE_REPEATER_OFF] = true;
- g_BlockPistonBreakable[E_BLOCK_REDSTONE_REPEATER_ON] = true;
- g_BlockPistonBreakable[E_BLOCK_REDSTONE_TORCH_OFF] = true;
- g_BlockPistonBreakable[E_BLOCK_REDSTONE_TORCH_ON] = true;
- g_BlockPistonBreakable[E_BLOCK_REDSTONE_WIRE] = true;
- g_BlockPistonBreakable[E_BLOCK_RED_MUSHROOM] = true;
- g_BlockPistonBreakable[E_BLOCK_REEDS] = true;
- g_BlockPistonBreakable[E_BLOCK_SNOW] = true;
- g_BlockPistonBreakable[E_BLOCK_STATIONARY_LAVA] = true;
- g_BlockPistonBreakable[E_BLOCK_STATIONARY_WATER] = true;
- g_BlockPistonBreakable[E_BLOCK_STONE_BUTTON] = true;
- g_BlockPistonBreakable[E_BLOCK_STONE_PRESSURE_PLATE] = true;
- g_BlockPistonBreakable[E_BLOCK_TALL_GRASS] = true;
- g_BlockPistonBreakable[E_BLOCK_TORCH] = true;
- g_BlockPistonBreakable[E_BLOCK_VINES] = true;
- g_BlockPistonBreakable[E_BLOCK_WATER] = true;
- g_BlockPistonBreakable[E_BLOCK_WOODEN_BUTTON] = true;
- g_BlockPistonBreakable[E_BLOCK_WOODEN_DOOR] = true;
- g_BlockPistonBreakable[E_BLOCK_WOODEN_PRESSURE_PLATE] = true;
-
-
- // Blocks that cannot be snowed over:
- g_BlockIsSnowable[E_BLOCK_ACTIVE_COMPARATOR] = false;
- g_BlockIsSnowable[E_BLOCK_AIR] = false;
- g_BlockIsSnowable[E_BLOCK_BIG_FLOWER] = false;
- g_BlockIsSnowable[E_BLOCK_BROWN_MUSHROOM] = false;
- g_BlockIsSnowable[E_BLOCK_CACTUS] = false;
- g_BlockIsSnowable[E_BLOCK_CHEST] = false;
- g_BlockIsSnowable[E_BLOCK_CROPS] = false;
- g_BlockIsSnowable[E_BLOCK_DANDELION] = false;
- g_BlockIsSnowable[E_BLOCK_FIRE] = false;
- g_BlockIsSnowable[E_BLOCK_FLOWER] = false;
- g_BlockIsSnowable[E_BLOCK_GLASS] = false;
- g_BlockIsSnowable[E_BLOCK_ICE] = false;
- g_BlockIsSnowable[E_BLOCK_INACTIVE_COMPARATOR] = false;
- g_BlockIsSnowable[E_BLOCK_LAVA] = false;
- g_BlockIsSnowable[E_BLOCK_LILY_PAD] = false;
- g_BlockIsSnowable[E_BLOCK_REDSTONE_REPEATER_OFF] = false;
- g_BlockIsSnowable[E_BLOCK_REDSTONE_REPEATER_ON] = false;
- g_BlockIsSnowable[E_BLOCK_REDSTONE_TORCH_OFF] = false;
- g_BlockIsSnowable[E_BLOCK_REDSTONE_TORCH_ON] = false;
- g_BlockIsSnowable[E_BLOCK_REDSTONE_WIRE] = false;
- g_BlockIsSnowable[E_BLOCK_RED_MUSHROOM] = false;
- g_BlockIsSnowable[E_BLOCK_REEDS] = false;
- g_BlockIsSnowable[E_BLOCK_SAPLING] = false;
- g_BlockIsSnowable[E_BLOCK_SIGN_POST] = false;
- g_BlockIsSnowable[E_BLOCK_SNOW] = false;
- g_BlockIsSnowable[E_BLOCK_STAINED_GLASS] = false;
- g_BlockIsSnowable[E_BLOCK_STAINED_GLASS_PANE] = false;
- g_BlockIsSnowable[E_BLOCK_STATIONARY_LAVA] = false;
- g_BlockIsSnowable[E_BLOCK_STATIONARY_WATER] = false;
- g_BlockIsSnowable[E_BLOCK_TALL_GRASS] = false;
- g_BlockIsSnowable[E_BLOCK_TNT] = false;
- g_BlockIsSnowable[E_BLOCK_TORCH] = false;
- g_BlockIsSnowable[E_BLOCK_VINES] = false;
- g_BlockIsSnowable[E_BLOCK_WALLSIGN] = false;
- g_BlockIsSnowable[E_BLOCK_WATER] = false;
-
-
- // Blocks that don't drop without a special tool:
- g_BlockRequiresSpecialTool[E_BLOCK_BRICK] = true;
- g_BlockRequiresSpecialTool[E_BLOCK_CAULDRON] = true;
- g_BlockRequiresSpecialTool[E_BLOCK_COAL_ORE] = true;
- g_BlockRequiresSpecialTool[E_BLOCK_COBBLESTONE] = true;
- g_BlockRequiresSpecialTool[E_BLOCK_COBBLESTONE_STAIRS] = true;
- g_BlockRequiresSpecialTool[E_BLOCK_COBWEB] = true;
- g_BlockRequiresSpecialTool[E_BLOCK_DIAMOND_BLOCK] = true;
- g_BlockRequiresSpecialTool[E_BLOCK_DIAMOND_ORE] = true;
- g_BlockRequiresSpecialTool[E_BLOCK_DOUBLE_STONE_SLAB] = true;
- g_BlockRequiresSpecialTool[E_BLOCK_EMERALD_ORE] = true;
- g_BlockRequiresSpecialTool[E_BLOCK_END_STONE] = true;
- g_BlockRequiresSpecialTool[E_BLOCK_GOLD_BLOCK] = true;
- g_BlockRequiresSpecialTool[E_BLOCK_GOLD_ORE] = true;
- g_BlockRequiresSpecialTool[E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE] = true;
- g_BlockRequiresSpecialTool[E_BLOCK_IRON_BLOCK] = true;
- g_BlockRequiresSpecialTool[E_BLOCK_IRON_ORE] = true;
- g_BlockRequiresSpecialTool[E_BLOCK_LAPIS_BLOCK] = true;
- g_BlockRequiresSpecialTool[E_BLOCK_LAPIS_ORE] = true;
- g_BlockRequiresSpecialTool[E_BLOCK_LIGHT_WEIGHTED_PRESSURE_PLATE] = true;
- g_BlockRequiresSpecialTool[E_BLOCK_MOSSY_COBBLESTONE] = true;
- g_BlockRequiresSpecialTool[E_BLOCK_NETHERRACK] = true;
- g_BlockRequiresSpecialTool[E_BLOCK_NETHER_BRICK] = true;
- g_BlockRequiresSpecialTool[E_BLOCK_NETHER_BRICK_STAIRS] = true;
- g_BlockRequiresSpecialTool[E_BLOCK_OBSIDIAN] = true;
- g_BlockRequiresSpecialTool[E_BLOCK_REDSTONE_ORE] = true;
- g_BlockRequiresSpecialTool[E_BLOCK_REDSTONE_ORE_GLOWING] = true;
- g_BlockRequiresSpecialTool[E_BLOCK_SANDSTONE] = true;
- g_BlockRequiresSpecialTool[E_BLOCK_SANDSTONE_STAIRS] = true;
- g_BlockRequiresSpecialTool[E_BLOCK_SNOW] = true;
- g_BlockRequiresSpecialTool[E_BLOCK_STONE] = true;
- g_BlockRequiresSpecialTool[E_BLOCK_STONE_BRICKS] = true;
- g_BlockRequiresSpecialTool[E_BLOCK_STONE_BRICK_STAIRS] = true;
- g_BlockRequiresSpecialTool[E_BLOCK_STONE_PRESSURE_PLATE] = true;
- g_BlockRequiresSpecialTool[E_BLOCK_STONE_SLAB] = true;
- g_BlockRequiresSpecialTool[E_BLOCK_VINES] = true;
-
- // Nonsolid blocks:
- g_BlockIsSolid[E_BLOCK_ACTIVATOR_RAIL] = false;
- g_BlockIsSolid[E_BLOCK_AIR] = false;
- g_BlockIsSolid[E_BLOCK_BIG_FLOWER] = false;
- g_BlockIsSolid[E_BLOCK_BROWN_MUSHROOM] = false;
- g_BlockIsSolid[E_BLOCK_CARROTS] = false;
- g_BlockIsSolid[E_BLOCK_COBWEB] = false;
- g_BlockIsSolid[E_BLOCK_CROPS] = false;
- g_BlockIsSolid[E_BLOCK_DANDELION] = false;
- g_BlockIsSolid[E_BLOCK_DETECTOR_RAIL] = false;
- g_BlockIsSolid[E_BLOCK_END_PORTAL] = false;
- g_BlockIsSolid[E_BLOCK_FIRE] = false;
- g_BlockIsSolid[E_BLOCK_FLOWER] = false;
- g_BlockIsSolid[E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE] = false;
- g_BlockIsSolid[E_BLOCK_LAVA] = false;
- g_BlockIsSolid[E_BLOCK_LEVER] = false;
- g_BlockIsSolid[E_BLOCK_LIGHT_WEIGHTED_PRESSURE_PLATE] = false;
- g_BlockIsSolid[E_BLOCK_MELON_STEM] = false;
- g_BlockIsSolid[E_BLOCK_NETHER_PORTAL] = false;
- g_BlockIsSolid[E_BLOCK_PISTON_EXTENSION] = false;
- g_BlockIsSolid[E_BLOCK_POTATOES] = false;
- g_BlockIsSolid[E_BLOCK_POWERED_RAIL] = false;
- g_BlockIsSolid[E_BLOCK_RAIL] = false;
- g_BlockIsSolid[E_BLOCK_REDSTONE_TORCH_OFF] = false;
- g_BlockIsSolid[E_BLOCK_REDSTONE_TORCH_ON] = false;
- g_BlockIsSolid[E_BLOCK_REDSTONE_WIRE] = false;
- g_BlockIsSolid[E_BLOCK_RED_MUSHROOM] = false;
- g_BlockIsSolid[E_BLOCK_REEDS] = false;
- g_BlockIsSolid[E_BLOCK_SAPLING] = false;
- g_BlockIsSolid[E_BLOCK_SIGN_POST] = false;
- g_BlockIsSolid[E_BLOCK_SNOW] = false;
- g_BlockIsSolid[E_BLOCK_STATIONARY_LAVA] = false;
- g_BlockIsSolid[E_BLOCK_STATIONARY_WATER] = false;
- g_BlockIsSolid[E_BLOCK_STONE_BUTTON] = false;
- g_BlockIsSolid[E_BLOCK_STONE_PRESSURE_PLATE] = false;
- g_BlockIsSolid[E_BLOCK_TALL_GRASS] = false;
- g_BlockIsSolid[E_BLOCK_TORCH] = false;
- g_BlockIsSolid[E_BLOCK_TRIPWIRE] = false;
- g_BlockIsSolid[E_BLOCK_VINES] = false;
- g_BlockIsSolid[E_BLOCK_WALLSIGN] = false;
- g_BlockIsSolid[E_BLOCK_WATER] = false;
- g_BlockIsSolid[E_BLOCK_WOODEN_BUTTON] = false;
- g_BlockIsSolid[E_BLOCK_WOODEN_PRESSURE_PLATE] = false;
- g_BlockIsSolid[E_BLOCK_WOODEN_SLAB] = false;
-
- // Torch placeable blocks:
- g_BlockFullyOccupiesVoxel[E_BLOCK_NEW_LOG] = true;
- g_BlockFullyOccupiesVoxel[E_BLOCK_BEDROCK] = true;
- g_BlockFullyOccupiesVoxel[E_BLOCK_BLOCK_OF_COAL] = true;
- g_BlockFullyOccupiesVoxel[E_BLOCK_BLOCK_OF_REDSTONE] = true;
- g_BlockFullyOccupiesVoxel[E_BLOCK_BOOKCASE] = true;
- g_BlockFullyOccupiesVoxel[E_BLOCK_BRICK] = true;
- g_BlockFullyOccupiesVoxel[E_BLOCK_CLAY] = true;
- g_BlockFullyOccupiesVoxel[E_BLOCK_COAL_ORE] = true;
- g_BlockFullyOccupiesVoxel[E_BLOCK_COBBLESTONE] = true;
- g_BlockFullyOccupiesVoxel[E_BLOCK_COMMAND_BLOCK] = true;
- g_BlockFullyOccupiesVoxel[E_BLOCK_CRAFTING_TABLE] = true;
- g_BlockFullyOccupiesVoxel[E_BLOCK_DIAMOND_BLOCK] = true;
- g_BlockFullyOccupiesVoxel[E_BLOCK_DIAMOND_ORE] = true;
- g_BlockFullyOccupiesVoxel[E_BLOCK_DIRT] = true;
- g_BlockFullyOccupiesVoxel[E_BLOCK_DISPENSER] = true;
- g_BlockFullyOccupiesVoxel[E_BLOCK_DOUBLE_STONE_SLAB] = true;
- g_BlockFullyOccupiesVoxel[E_BLOCK_DOUBLE_WOODEN_SLAB] = true;
- g_BlockFullyOccupiesVoxel[E_BLOCK_DROPPER] = true;
- g_BlockFullyOccupiesVoxel[E_BLOCK_EMERALD_BLOCK] = true;
- g_BlockFullyOccupiesVoxel[E_BLOCK_EMERALD_ORE] = true;
- g_BlockFullyOccupiesVoxel[E_BLOCK_END_STONE] = true;
- g_BlockFullyOccupiesVoxel[E_BLOCK_FURNACE] = true;
- g_BlockFullyOccupiesVoxel[E_BLOCK_GLOWSTONE] = true;
- g_BlockFullyOccupiesVoxel[E_BLOCK_GOLD_BLOCK] = true;
- g_BlockFullyOccupiesVoxel[E_BLOCK_GOLD_ORE] = true;
- g_BlockFullyOccupiesVoxel[E_BLOCK_GRASS] = true;
- g_BlockFullyOccupiesVoxel[E_BLOCK_GRAVEL] = true;
- g_BlockFullyOccupiesVoxel[E_BLOCK_HARDENED_CLAY] = true;
- g_BlockFullyOccupiesVoxel[E_BLOCK_HAY_BALE] = true;
- g_BlockFullyOccupiesVoxel[E_BLOCK_HUGE_BROWN_MUSHROOM] = true;
- g_BlockFullyOccupiesVoxel[E_BLOCK_HUGE_RED_MUSHROOM] = true;
- g_BlockFullyOccupiesVoxel[E_BLOCK_IRON_BLOCK] = true;
- g_BlockFullyOccupiesVoxel[E_BLOCK_IRON_ORE] = true;
- g_BlockFullyOccupiesVoxel[E_BLOCK_JACK_O_LANTERN] = true;
- g_BlockFullyOccupiesVoxel[E_BLOCK_JUKEBOX] = true;
- g_BlockFullyOccupiesVoxel[E_BLOCK_LAPIS_BLOCK] = true;
- g_BlockFullyOccupiesVoxel[E_BLOCK_LAPIS_ORE] = true;
- g_BlockFullyOccupiesVoxel[E_BLOCK_LOG] = true;
- g_BlockFullyOccupiesVoxel[E_BLOCK_MELON] = true;
- g_BlockFullyOccupiesVoxel[E_BLOCK_MOSSY_COBBLESTONE] = true;
- g_BlockFullyOccupiesVoxel[E_BLOCK_MYCELIUM] = true;
- g_BlockFullyOccupiesVoxel[E_BLOCK_NETHERRACK] = true;
- g_BlockFullyOccupiesVoxel[E_BLOCK_NETHER_BRICK] = true;
- g_BlockFullyOccupiesVoxel[E_BLOCK_NETHER_QUARTZ_ORE] = true;
- g_BlockFullyOccupiesVoxel[E_BLOCK_NOTE_BLOCK] = true;
- g_BlockFullyOccupiesVoxel[E_BLOCK_OBSIDIAN] = true;
- g_BlockFullyOccupiesVoxel[E_BLOCK_PACKED_ICE] = true;
- g_BlockFullyOccupiesVoxel[E_BLOCK_PLANKS] = true;
- g_BlockFullyOccupiesVoxel[E_BLOCK_PUMPKIN] = true;
- g_BlockFullyOccupiesVoxel[E_BLOCK_QUARTZ_BLOCK] = true;
- g_BlockFullyOccupiesVoxel[E_BLOCK_REDSTONE_LAMP_OFF] = true;
- g_BlockFullyOccupiesVoxel[E_BLOCK_REDSTONE_LAMP_ON] = true;
- g_BlockFullyOccupiesVoxel[E_BLOCK_REDSTONE_ORE] = true;
- g_BlockFullyOccupiesVoxel[E_BLOCK_REDSTONE_ORE_GLOWING] = true;
- g_BlockFullyOccupiesVoxel[E_BLOCK_SANDSTONE] = true;
- g_BlockFullyOccupiesVoxel[E_BLOCK_SAND] = true;
- g_BlockFullyOccupiesVoxel[E_BLOCK_SILVERFISH_EGG] = true;
- g_BlockFullyOccupiesVoxel[E_BLOCK_SPONGE] = true;
- g_BlockFullyOccupiesVoxel[E_BLOCK_STAINED_CLAY] = true;
- g_BlockFullyOccupiesVoxel[E_BLOCK_WOOL] = true;
- g_BlockFullyOccupiesVoxel[E_BLOCK_STONE] = true;
- g_BlockFullyOccupiesVoxel[E_BLOCK_STONE_BRICKS] = true;
- }
-} BlockPropertiesInitializer;
-
-
-
-
diff --git a/src/BlockID.h b/src/BlockID.h
index 861bb8dae..1c454cd23 100644
--- a/src/BlockID.h
+++ b/src/BlockID.h
@@ -909,17 +909,3 @@ extern cItem GetIniItemSet(cIniFile & a_IniFile, const char * a_Section, const c
-// Block properties:
-extern NIBBLETYPE g_BlockLightValue[256];
-extern NIBBLETYPE g_BlockSpreadLightFalloff[256];
-extern bool g_BlockTransparent[256];
-extern bool g_BlockOneHitDig[256];
-extern bool g_BlockPistonBreakable[256];
-extern bool g_BlockIsSnowable[256];
-extern bool g_BlockRequiresSpecialTool[256];
-extern bool g_BlockIsSolid[256];
-extern bool g_BlockFullyOccupiesVoxel[256];
-
-
-
-
diff --git a/src/Defines.h b/src/Defines.h
index 31d48860f..6d3d28c80 100644
--- a/src/Defines.h
+++ b/src/Defines.h
@@ -17,33 +17,6 @@ typedef std::vector cSlotNums;
// tolua_begin
-/// How much light do the blocks emit on their own?
-extern unsigned char g_BlockLightValue[];
-
-/// How much light do the block consume?
-extern unsigned char g_BlockSpreadLightFalloff[];
-
-/// Is a block completely transparent? (light doesn't get decreased(?))
-extern bool g_BlockTransparent[];
-
-/// Is a block destroyed after a single hit?
-extern bool g_BlockOneHitDig[];
-
-/// Can a piston break this block?
-extern bool g_BlockPistonBreakable[256];
-
-/// Can this block hold snow atop?
-extern bool g_BlockIsSnowable[256];
-
-/// Does this block require a tool to drop?
-extern bool g_BlockRequiresSpecialTool[256];
-
-/// Is this block solid (player cannot walk through)?
-extern bool g_BlockIsSolid[256];
-
-/// Does this block fully occupy it's voxel - is it a 'full' block?
-extern bool g_BlockFullyOccupiesVoxel[256];
-
/// Experience Orb setup
enum
{
--
cgit v1.2.3
From f40f2ad9283bd5aa587cd0943adc5f8c7a3b41c1 Mon Sep 17 00:00:00 2001
From: andrew
Date: Sun, 2 Mar 2014 12:59:09 +0200
Subject: APIDump: ID -> Type
---
MCServer/Plugins/APIDump/APIDesc.lua | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua
index 695d1a853..ed9c32d32 100644
--- a/MCServer/Plugins/APIDump/APIDesc.lua
+++ b/MCServer/Plugins/APIDump/APIDesc.lua
@@ -297,16 +297,16 @@ g_APIDesc =
]],
Functions =
{
- FullyOccupiesVoxel = { Params = "ID", Return = "bool", Notes = "Returns whether the specified block fully occupies its voxel." },
- GetById = { Params = "ID", Return = "{{cBlockInfo}}", Notes = "Returns the {{cBlockInfo}} structure for the block with the specified ID." },
- GetLightValue = { Params = "ID", Return = "number", Notes = "Returns how much light the specified block emits on its own." },
- GetSpreadLightFalloff = { Params = "ID", Return = "number", Notes = "Returns how much light the specified block consumes." },
- IsOneHitDig = { Params = "ID", Return = "bool", Notes = "Returns whether the specified block will be destroyed after a single hit." },
- IsPistonBreakable = { Params = "ID", Return = "bool", Notes = "Returns whether a piston can break the specified block." },
- IsSnowable = { Params = "ID", Return = "bool", Notes = "Returns whether the specified block can hold snow atop." },
- IsSolid = { Params = "ID", Return = "bool", Notes = "Returns whether the specified block is solid." },
- IsTransparent = { Params = "ID", Return = "bool", Notes = "Returns whether the specified block is transparent." },
- RequiresSpecialTool = { Params = "ID", Return = "bool", Notes = "Returns whether the specified block requires a special tool to drop." },
+ FullyOccupiesVoxel = { Params = "Type", Return = "bool", Notes = "Returns whether the specified block fully occupies its voxel." },
+ GetById = { Params = "Type", Return = "{{cBlockInfo}}", Notes = "Returns the {{cBlockInfo}} structure for the specified type." },
+ GetLightValue = { Params = "Type", Return = "number", Notes = "Returns how much light the specified block emits on its own." },
+ GetSpreadLightFalloff = { Params = "Type", Return = "number", Notes = "Returns how much light the specified block consumes." },
+ IsOneHitDig = { Params = "Type", Return = "bool", Notes = "Returns whether the specified block will be destroyed after a single hit." },
+ IsPistonBreakable = { Params = "Type", Return = "bool", Notes = "Returns whether a piston can break the specified block." },
+ IsSnowable = { Params = "Type", Return = "bool", Notes = "Returns whether the specified block can hold snow atop." },
+ IsSolid = { Params = "Type", Return = "bool", Notes = "Returns whether the specified block is solid." },
+ IsTransparent = { Params = "Type", Return = "bool", Notes = "Returns whether the specified block is transparent." },
+ RequiresSpecialTool = { Params = "Type", Return = "bool", Notes = "Returns whether the specified block requires a special tool to drop." },
},
Variables =
{
--
cgit v1.2.3
From 8990410f18a03ca553cca0103cd167bac06443cc Mon Sep 17 00:00:00 2001
From: worktycho
Date: Sun, 2 Mar 2014 12:02:29 +0000
Subject: Reverted BlockVine
---
src/Blocks/BlockVine.h | 30 +++++++++++++++++++++++++++---
1 file changed, 27 insertions(+), 3 deletions(-)
diff --git a/src/Blocks/BlockVine.h b/src/Blocks/BlockVine.h
index 9e2105f67..b8213f29b 100644
--- a/src/Blocks/BlockVine.h
+++ b/src/Blocks/BlockVine.h
@@ -1,4 +1,3 @@
-
#pragma once
#include "BlockHandler.h"
@@ -8,11 +7,11 @@
class cBlockVineHandler :
- public cMetaRotater
+ public cBlockHandler
{
public:
cBlockVineHandler(BLOCKTYPE a_BlockType)
- : cMetaRotater(a_BlockType)
+ : cBlockHandler(a_BlockType)
{
}
@@ -169,6 +168,31 @@ public:
a_World->SetBlock(X, Y - 1, Z, E_BLOCK_VINES, a_World->GetBlockMeta(X, Y, Z));
}
}
+
+ virtual NIBBLETYPE MetaRotateCCW(NIBBLETYPE a_Meta) override
+ {
+ return ((a_Meta >> 1) | (a_Meta << 3)) & 0x0f; // Rotate bits to the right
+ }
+
+
+ virtual NIBBLETYPE MetaRotateCW(NIBBLETYPE a_Meta) override
+ {
+ return ((a_Meta << 1) | (a_Meta >> 3)) & 0x0f; // Rotate bits to the left
+ }
+
+
+ virtual NIBBLETYPE MetaMirrorXY(NIBBLETYPE a_Meta) override
+ {
+ // Bits 2 and 4 stay, bits 1 and 3 swap
+ return ((a_Meta & 0x0a) | ((a_Meta & 0x01) << 2) | ((a_Meta & 0x04) >> 2));
+ }
+
+
+ virtual NIBBLETYPE MetaMirrorYZ(NIBBLETYPE a_Meta) override
+ {
+ // Bits 1 and 3 stay, bits 2 and 4 swap
+ return ((a_Meta & 0x05) | ((a_Meta & 0x02) << 2) | ((a_Meta & 0x08) >> 2));
+ }
} ;
--
cgit v1.2.3
From 10fdc51b0a9b571b118b257109014e1c29591698 Mon Sep 17 00:00:00 2001
From: tonibm19
Date: Sun, 2 Mar 2014 14:35:03 +0100
Subject: Creeper fixes
- Fixed explosion time (1.5s, according to minecraftwiki)
- Creeper explodes if right clicked with flint and steel
---
src/Mobs/Creeper.cpp | 41 ++++++++++++++++++++++++++++++++---------
src/Mobs/Creeper.h | 3 ++-
2 files changed, 34 insertions(+), 10 deletions(-)
diff --git a/src/Mobs/Creeper.cpp b/src/Mobs/Creeper.cpp
index 40ee20e44..3471b4cf1 100644
--- a/src/Mobs/Creeper.cpp
+++ b/src/Mobs/Creeper.cpp
@@ -4,6 +4,7 @@
#include "Creeper.h"
#include "../World.h"
#include "../Entities/ProjectileEntity.h"
+#include "../Entities/Player.h"
@@ -13,6 +14,7 @@ cCreeper::cCreeper(void) :
super("Creeper", mtCreeper, "mob.creeper.say", "mob.creeper.say", 0.6, 1.8),
m_bIsBlowing(false),
m_bIsCharged(false),
+ m_BurnedWithFlintAndSteel(false),
m_ExplodingTimer(0)
{
}
@@ -25,12 +27,25 @@ void cCreeper::Tick(float a_Dt, cChunk & a_Chunk)
{
super::Tick(a_Dt, a_Chunk);
- if (!ReachedFinalDestination())
+ if (!ReachedFinalDestination() && !m_BurnedWithFlintAndSteel)
{
m_ExplodingTimer = 0;
m_bIsBlowing = false;
m_World->BroadcastEntityMetadata(*this);
}
+ else
+ {
+ if (m_bIsBlowing)
+ {
+ m_ExplodingTimer += 1;
+ }
+
+ if (m_ExplodingTimer == 30)
+ {
+ m_World->DoExplosionAt((m_bIsCharged ? 5 : 3), GetPosX(), GetPosY(), GetPosZ(), false, esMonster, this);
+ Destroy();
+ }
+ }
}
@@ -80,22 +95,30 @@ void cCreeper::Attack(float a_Dt)
{
UNUSED(a_Dt);
- m_ExplodingTimer += 1;
-
if (!m_bIsBlowing)
{
m_World->BroadcastSoundEffect("game.tnt.primed", (int)GetPosX() * 8, (int)GetPosY() * 8, (int)GetPosZ() * 8, 1.f, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64));
m_bIsBlowing = true;
m_World->BroadcastEntityMetadata(*this);
}
-
- if (m_ExplodingTimer == 20)
- {
- m_World->DoExplosionAt((m_bIsCharged ? 5 : 3), GetPosX(), GetPosY(), GetPosZ(), false, esMonster, this);
- Destroy();
- }
}
+
+void cCreeper::OnRightClicked(cPlayer & a_Player)
+{
+ if ((a_Player.GetEquippedItem().m_ItemType == E_ITEM_FLINT_AND_STEEL))
+ {
+ if (!a_Player.IsGameModeCreative())
+ {
+ a_Player.UseEquippedItem();
+ }
+ m_World->BroadcastSoundEffect("game.tnt.primed", (int)GetPosX() * 8, (int)GetPosY() * 8, (int)GetPosZ() * 8, 1.f, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64));
+ m_bIsBlowing = true;
+ m_World->BroadcastEntityMetadata(*this);
+ m_BurnedWithFlintAndSteel = true;
+ }
+}
+
diff --git a/src/Mobs/Creeper.h b/src/Mobs/Creeper.h
index 0f71e5ad2..9abca369b 100644
--- a/src/Mobs/Creeper.h
+++ b/src/Mobs/Creeper.h
@@ -21,13 +21,14 @@ public:
virtual void DoTakeDamage(TakeDamageInfo & a_TDI) override;
virtual void Attack(float a_Dt) override;
virtual void Tick(float a_Dt, cChunk & a_Chunk) override;
+ virtual void OnRightClicked(cPlayer & a_Player) override;
bool IsBlowing(void) const {return m_bIsBlowing; }
bool IsCharged(void) const {return m_bIsCharged; }
private:
- bool m_bIsBlowing, m_bIsCharged;
+ bool m_bIsBlowing, m_bIsCharged, m_BurnedWithFlintAndSteel;
int m_ExplodingTimer;
} ;
--
cgit v1.2.3
From 0c87341631198386c765bc18848fbd93e66c1aab Mon Sep 17 00:00:00 2001
From: andrew
Date: Sun, 2 Mar 2014 16:24:09 +0200
Subject: GetById => Get
---
MCServer/Plugins/APIDump/APIDesc.lua | 20 ++++++++++----------
src/Bindings/DeprecatedBindings.cpp | 18 +++++++++---------
src/BlockInfo.cpp | 6 +++---
src/BlockInfo.h | 20 ++++++++++----------
4 files changed, 32 insertions(+), 32 deletions(-)
diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua
index ed9c32d32..0b6f33b37 100644
--- a/MCServer/Plugins/APIDump/APIDesc.lua
+++ b/MCServer/Plugins/APIDump/APIDesc.lua
@@ -297,16 +297,16 @@ g_APIDesc =
]],
Functions =
{
- FullyOccupiesVoxel = { Params = "Type", Return = "bool", Notes = "Returns whether the specified block fully occupies its voxel." },
- GetById = { Params = "Type", Return = "{{cBlockInfo}}", Notes = "Returns the {{cBlockInfo}} structure for the specified type." },
- GetLightValue = { Params = "Type", Return = "number", Notes = "Returns how much light the specified block emits on its own." },
- GetSpreadLightFalloff = { Params = "Type", Return = "number", Notes = "Returns how much light the specified block consumes." },
- IsOneHitDig = { Params = "Type", Return = "bool", Notes = "Returns whether the specified block will be destroyed after a single hit." },
- IsPistonBreakable = { Params = "Type", Return = "bool", Notes = "Returns whether a piston can break the specified block." },
- IsSnowable = { Params = "Type", Return = "bool", Notes = "Returns whether the specified block can hold snow atop." },
- IsSolid = { Params = "Type", Return = "bool", Notes = "Returns whether the specified block is solid." },
- IsTransparent = { Params = "Type", Return = "bool", Notes = "Returns whether the specified block is transparent." },
- RequiresSpecialTool = { Params = "Type", Return = "bool", Notes = "Returns whether the specified block requires a special tool to drop." },
+ FullyOccupiesVoxel = { Params = "Type", Return = "bool", Notes = "(STATIC) Returns whether the specified block fully occupies its voxel." },
+ Get = { Params = "Type", Return = "{{cBlockInfo}}", Notes = "(STATIC) Returns the {{cBlockInfo}} structure for the specified type." },
+ GetLightValue = { Params = "Type", Return = "number", Notes = "(STATIC) Returns how much light the specified block emits on its own." },
+ GetSpreadLightFalloff = { Params = "Type", Return = "number", Notes = "(STATIC) Returns how much light the specified block consumes." },
+ IsOneHitDig = { Params = "Type", Return = "bool", Notes = "(STATIC) Returns whether the specified block will be destroyed after a single hit." },
+ IsPistonBreakable = { Params = "Type", Return = "bool", Notes = "(STATIC) Returns whether a piston can break the specified block." },
+ IsSnowable = { Params = "Type", Return = "bool", Notes = "(STATIC) Returns whether the specified block can hold snow atop." },
+ IsSolid = { Params = "Type", Return = "bool", Notes = "(STATIC) Returns whether the specified block is solid." },
+ IsTransparent = { Params = "Type", Return = "bool", Notes = "(STATIC) Returns whether the specified block is transparent." },
+ RequiresSpecialTool = { Params = "Type", Return = "bool", Notes = "(STATIC) Returns whether the specified block requires a special tool to drop." },
},
Variables =
{
diff --git a/src/Bindings/DeprecatedBindings.cpp b/src/Bindings/DeprecatedBindings.cpp
index 3e4940494..7c0d8dca1 100644
--- a/src/Bindings/DeprecatedBindings.cpp
+++ b/src/Bindings/DeprecatedBindings.cpp
@@ -55,7 +55,7 @@ static int tolua_set_AllToLua_g_BlockLightValue(lua_State* tolua_S)
if (tolua_index<0)
tolua_error(tolua_S,"array indexing out of range.",NULL);
#endif
- cBlockInfo::GetById(tolua_index).m_LightValue = ((unsigned char) tolua_tonumber(tolua_S,3,0));
+ cBlockInfo::Get(tolua_index).m_LightValue = ((unsigned char) tolua_tonumber(tolua_S,3,0));
return 0;
}
#endif //#ifndef TOLUA_DISABLE
@@ -99,7 +99,7 @@ static int tolua_set_AllToLua_g_BlockSpreadLightFalloff(lua_State* tolua_S)
if (tolua_index<0)
tolua_error(tolua_S,"array indexing out of range.",NULL);
#endif
- cBlockInfo::GetById(tolua_index).m_SpreadLightFalloff = ((unsigned char) tolua_tonumber(tolua_S,3,0));
+ cBlockInfo::Get(tolua_index).m_SpreadLightFalloff = ((unsigned char) tolua_tonumber(tolua_S,3,0));
return 0;
}
#endif //#ifndef TOLUA_DISABLE
@@ -143,7 +143,7 @@ static int tolua_set_AllToLua_g_BlockTransparent(lua_State* tolua_S)
if (tolua_index<0)
tolua_error(tolua_S,"array indexing out of range.",NULL);
#endif
- cBlockInfo::GetById(tolua_index).m_Transparent = ((bool) tolua_toboolean(tolua_S,3,0));
+ cBlockInfo::Get(tolua_index).m_Transparent = ((bool) tolua_toboolean(tolua_S,3,0));
return 0;
}
#endif //#ifndef TOLUA_DISABLE
@@ -187,7 +187,7 @@ static int tolua_set_AllToLua_g_BlockOneHitDig(lua_State* tolua_S)
if (tolua_index<0)
tolua_error(tolua_S,"array indexing out of range.",NULL);
#endif
- cBlockInfo::GetById(tolua_index).m_OneHitDig = ((bool) tolua_toboolean(tolua_S,3,0));
+ cBlockInfo::Get(tolua_index).m_OneHitDig = ((bool) tolua_toboolean(tolua_S,3,0));
return 0;
}
#endif //#ifndef TOLUA_DISABLE
@@ -231,7 +231,7 @@ static int tolua_set_AllToLua_g_BlockPistonBreakable(lua_State* tolua_S)
if (tolua_index<0 || tolua_index>=256)
tolua_error(tolua_S,"array indexing out of range.",NULL);
#endif
- cBlockInfo::GetById(tolua_index).m_PistonBreakable = ((bool) tolua_toboolean(tolua_S,3,0));
+ cBlockInfo::Get(tolua_index).m_PistonBreakable = ((bool) tolua_toboolean(tolua_S,3,0));
return 0;
}
#endif //#ifndef TOLUA_DISABLE
@@ -275,7 +275,7 @@ static int tolua_set_AllToLua_g_BlockIsSnowable(lua_State* tolua_S)
if (tolua_index<0 || tolua_index>=256)
tolua_error(tolua_S,"array indexing out of range.",NULL);
#endif
- cBlockInfo::GetById(tolua_index).m_IsSnowable = ((bool) tolua_toboolean(tolua_S,3,0));
+ cBlockInfo::Get(tolua_index).m_IsSnowable = ((bool) tolua_toboolean(tolua_S,3,0));
return 0;
}
#endif //#ifndef TOLUA_DISABLE
@@ -319,7 +319,7 @@ static int tolua_set_AllToLua_g_BlockRequiresSpecialTool(lua_State* tolua_S)
if (tolua_index<0 || tolua_index>=256)
tolua_error(tolua_S,"array indexing out of range.",NULL);
#endif
- cBlockInfo::GetById(tolua_index).m_RequiresSpecialTool = ((bool) tolua_toboolean(tolua_S,3,0));
+ cBlockInfo::Get(tolua_index).m_RequiresSpecialTool = ((bool) tolua_toboolean(tolua_S,3,0));
return 0;
}
#endif //#ifndef TOLUA_DISABLE
@@ -363,7 +363,7 @@ static int tolua_set_AllToLua_g_BlockIsSolid(lua_State* tolua_S)
if (tolua_index<0 || tolua_index>=256)
tolua_error(tolua_S,"array indexing out of range.",NULL);
#endif
- cBlockInfo::GetById(tolua_index).m_IsSolid = ((bool) tolua_toboolean(tolua_S,3,0));
+ cBlockInfo::Get(tolua_index).m_IsSolid = ((bool) tolua_toboolean(tolua_S,3,0));
return 0;
}
#endif //#ifndef TOLUA_DISABLE
@@ -407,7 +407,7 @@ static int tolua_set_AllToLua_g_BlockFullyOccupiesVoxel(lua_State* tolua_S)
if (tolua_index<0 || tolua_index>=256)
tolua_error(tolua_S,"array indexing out of range.",NULL);
#endif
- cBlockInfo::GetById(tolua_index).m_FullyOccupiesVoxel = ((bool) tolua_toboolean(tolua_S,3,0));
+ cBlockInfo::Get(tolua_index).m_FullyOccupiesVoxel = ((bool) tolua_toboolean(tolua_S,3,0));
return 0;
}
#endif //#ifndef TOLUA_DISABLE
diff --git a/src/BlockInfo.cpp b/src/BlockInfo.cpp
index 5fd6d33c1..c73ae18b6 100644
--- a/src/BlockInfo.cpp
+++ b/src/BlockInfo.cpp
@@ -29,11 +29,11 @@ cBlockInfo::cBlockInfo()
-cBlockInfo & cBlockInfo::GetById(unsigned int a_ID)
+cBlockInfo & cBlockInfo::Get(BLOCKTYPE a_Type)
{
- ASSERT(a_ID < 256);
+ ASSERT(a_Type < 256);
- return ms_Info[a_ID];
+ return ms_Info[a_Type];
}
diff --git a/src/BlockInfo.h b/src/BlockInfo.h
index 57092ca54..34a845b20 100644
--- a/src/BlockInfo.h
+++ b/src/BlockInfo.h
@@ -19,7 +19,7 @@ public:
// tolua_begin
/** Returns the associated BlockInfo structure. */
- static cBlockInfo & GetById(unsigned int a_ID);
+ static cBlockInfo & Get(BLOCKTYPE a_Type);
/** How much light do the blocks emit on their own? */
@@ -50,15 +50,15 @@ public:
bool m_FullyOccupiesVoxel;
- inline static NIBBLETYPE GetLightValue (unsigned int a_ID) { return GetById(a_ID).m_LightValue; }
- inline static NIBBLETYPE GetSpreadLightFalloff(unsigned int a_ID) { return GetById(a_ID).m_SpreadLightFalloff; }
- inline static bool IsTransparent (unsigned int a_ID) { return GetById(a_ID).m_Transparent; }
- inline static bool IsOneHitDig (unsigned int a_ID) { return GetById(a_ID).m_OneHitDig; }
- inline static bool IsPistonBreakable (unsigned int a_ID) { return GetById(a_ID).m_PistonBreakable; }
- inline static bool IsSnowable (unsigned int a_ID) { return GetById(a_ID).m_IsSnowable; }
- inline static bool RequiresSpecialTool (unsigned int a_ID) { return GetById(a_ID).m_RequiresSpecialTool; }
- inline static bool IsSolid (unsigned int a_ID) { return GetById(a_ID).m_IsSolid; }
- inline static bool FullyOccupiesVoxel (unsigned int a_ID) { return GetById(a_ID).m_FullyOccupiesVoxel; }
+ inline static NIBBLETYPE GetLightValue (BLOCKTYPE a_Type) { return Get(a_Type).m_LightValue; }
+ inline static NIBBLETYPE GetSpreadLightFalloff(BLOCKTYPE a_Type) { return Get(a_Type).m_SpreadLightFalloff; }
+ inline static bool IsTransparent (BLOCKTYPE a_Type) { return Get(a_Type).m_Transparent; }
+ inline static bool IsOneHitDig (BLOCKTYPE a_Type) { return Get(a_Type).m_OneHitDig; }
+ inline static bool IsPistonBreakable (BLOCKTYPE a_Type) { return Get(a_Type).m_PistonBreakable; }
+ inline static bool IsSnowable (BLOCKTYPE a_Type) { return Get(a_Type).m_IsSnowable; }
+ inline static bool RequiresSpecialTool (BLOCKTYPE a_Type) { return Get(a_Type).m_RequiresSpecialTool; }
+ inline static bool IsSolid (BLOCKTYPE a_Type) { return Get(a_Type).m_IsSolid; }
+ inline static bool FullyOccupiesVoxel (BLOCKTYPE a_Type) { return Get(a_Type).m_FullyOccupiesVoxel; }
// tolua_end
--
cgit v1.2.3
From 274d2bcb17791c292a2095af649b1a4c51246d23 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Sun, 2 Mar 2014 16:05:39 +0100
Subject: Added blockface mirroring and rotating.
---
src/Defines.h | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 50 insertions(+)
diff --git a/src/Defines.h b/src/Defines.h
index 6d3d28c80..018ecb1d3 100644
--- a/src/Defines.h
+++ b/src/Defines.h
@@ -226,6 +226,56 @@ inline const char * ClickActionToString(eClickAction a_ClickAction)
+/** Returns a blockface mirrored around the Y axis (doesn't change up/down). */
+inline eBlockFace MirrorBlockFaceY(eBlockFace a_BlockFace)
+{
+ switch (a_BlockFace)
+ {
+ case BLOCK_FACE_XM: return BLOCK_FACE_XP;
+ case BLOCK_FACE_XP: return BLOCK_FACE_XM;
+ case BLOCK_FACE_ZM: return BLOCK_FACE_ZP;
+ case BLOCK_FACE_ZP: return BLOCK_FACE_ZM;
+ }
+ return a_BlockFace;
+}
+
+
+
+
+
+/** Returns a blockface rotated around the Y axis counter-clockwise. */
+inline eBlockFace RotateBlockFaceCCW(eBlockFace a_BlockFace)
+{
+ switch (a_BlockFace)
+ {
+ case BLOCK_FACE_XM: return BLOCK_FACE_ZP;
+ case BLOCK_FACE_XP: return BLOCK_FACE_ZM;
+ case BLOCK_FACE_ZM: return BLOCK_FACE_XM;
+ case BLOCK_FACE_ZP: return BLOCK_FACE_XP;
+ }
+ return a_BlockFace;
+}
+
+
+
+
+
+inline eBlockFace RotateBlockFaceCW(eBlockFace a_BlockFace)
+{
+ switch (a_BlockFace)
+ {
+ case BLOCK_FACE_XM: return BLOCK_FACE_ZM;
+ case BLOCK_FACE_XP: return BLOCK_FACE_ZP;
+ case BLOCK_FACE_ZM: return BLOCK_FACE_XP;
+ case BLOCK_FACE_ZP: return BLOCK_FACE_XM;
+ }
+ return a_BlockFace;
+}
+
+
+
+
+
inline bool IsValidBlock(int a_BlockType)
{
if (
--
cgit v1.2.3
From 7fb354e8f09d16832b1261a5dc9b43d6a8d2fd0e Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Sun, 2 Mar 2014 16:34:16 +0100
Subject: Fixed MSVC warnings in DeprecatedBindings.
---
src/Bindings/DeprecatedBindings.cpp | 84 +++++++++++++++++++++++++++++++++----
1 file changed, 76 insertions(+), 8 deletions(-)
diff --git a/src/Bindings/DeprecatedBindings.cpp b/src/Bindings/DeprecatedBindings.cpp
index 7c0d8dca1..408b1b84a 100644
--- a/src/Bindings/DeprecatedBindings.cpp
+++ b/src/Bindings/DeprecatedBindings.cpp
@@ -38,6 +38,10 @@ static int tolua_get_AllToLua_g_BlockLightValue(lua_State* tolua_S)
}
#endif //#ifndef TOLUA_DISABLE
+
+
+
+
/* set function: g_BlockLightValue */
#ifndef TOLUA_DISABLE_tolua_set_AllToLua_g_BlockLightValue
static int tolua_set_AllToLua_g_BlockLightValue(lua_State* tolua_S)
@@ -60,6 +64,10 @@ static int tolua_set_AllToLua_g_BlockLightValue(lua_State* tolua_S)
}
#endif //#ifndef TOLUA_DISABLE
+
+
+
+
/* get function: g_BlockSpreadLightFalloff */
#ifndef TOLUA_DISABLE_tolua_get_AllToLua_g_BlockSpreadLightFalloff
static int tolua_get_AllToLua_g_BlockSpreadLightFalloff(lua_State* tolua_S)
@@ -82,6 +90,10 @@ static int tolua_get_AllToLua_g_BlockSpreadLightFalloff(lua_State* tolua_S)
}
#endif //#ifndef TOLUA_DISABLE
+
+
+
+
/* set function: g_BlockSpreadLightFalloff */
#ifndef TOLUA_DISABLE_tolua_set_AllToLua_g_BlockSpreadLightFalloff
static int tolua_set_AllToLua_g_BlockSpreadLightFalloff(lua_State* tolua_S)
@@ -104,6 +116,10 @@ static int tolua_set_AllToLua_g_BlockSpreadLightFalloff(lua_State* tolua_S)
}
#endif //#ifndef TOLUA_DISABLE
+
+
+
+
/* get function: g_BlockTransparent */
#ifndef TOLUA_DISABLE_tolua_get_AllToLua_g_BlockTransparent
static int tolua_get_AllToLua_g_BlockTransparent(lua_State* tolua_S)
@@ -121,11 +137,15 @@ static int tolua_get_AllToLua_g_BlockTransparent(lua_State* tolua_S)
if (tolua_index<0)
tolua_error(tolua_S,"array indexing out of range.",NULL);
#endif
- tolua_pushboolean(tolua_S,(bool)cBlockInfo::IsTransparent(tolua_index));
+ tolua_pushboolean(tolua_S, cBlockInfo::IsTransparent(tolua_index));
return 1;
}
#endif //#ifndef TOLUA_DISABLE
+
+
+
+
/* set function: g_BlockTransparent */
#ifndef TOLUA_DISABLE_tolua_set_AllToLua_g_BlockTransparent
static int tolua_set_AllToLua_g_BlockTransparent(lua_State* tolua_S)
@@ -143,11 +163,15 @@ static int tolua_set_AllToLua_g_BlockTransparent(lua_State* tolua_S)
if (tolua_index<0)
tolua_error(tolua_S,"array indexing out of range.",NULL);
#endif
- cBlockInfo::Get(tolua_index).m_Transparent = ((bool) tolua_toboolean(tolua_S,3,0));
+ cBlockInfo::Get(tolua_index).m_Transparent = (tolua_toboolean(tolua_S,3,0) != 0);
return 0;
}
#endif //#ifndef TOLUA_DISABLE
+
+
+
+
/* get function: g_BlockOneHitDig */
#ifndef TOLUA_DISABLE_tolua_get_AllToLua_g_BlockOneHitDig
static int tolua_get_AllToLua_g_BlockOneHitDig(lua_State* tolua_S)
@@ -170,6 +194,10 @@ static int tolua_get_AllToLua_g_BlockOneHitDig(lua_State* tolua_S)
}
#endif //#ifndef TOLUA_DISABLE
+
+
+
+
/* set function: g_BlockOneHitDig */
#ifndef TOLUA_DISABLE_tolua_set_AllToLua_g_BlockOneHitDig
static int tolua_set_AllToLua_g_BlockOneHitDig(lua_State* tolua_S)
@@ -187,11 +215,15 @@ static int tolua_set_AllToLua_g_BlockOneHitDig(lua_State* tolua_S)
if (tolua_index<0)
tolua_error(tolua_S,"array indexing out of range.",NULL);
#endif
- cBlockInfo::Get(tolua_index).m_OneHitDig = ((bool) tolua_toboolean(tolua_S,3,0));
+ cBlockInfo::Get(tolua_index).m_OneHitDig = (tolua_toboolean(tolua_S,3,0) != 0);
return 0;
}
#endif //#ifndef TOLUA_DISABLE
+
+
+
+
/* get function: g_BlockPistonBreakable */
#ifndef TOLUA_DISABLE_tolua_get_AllToLua_g_BlockPistonBreakable
static int tolua_get_AllToLua_g_BlockPistonBreakable(lua_State* tolua_S)
@@ -214,6 +246,10 @@ static int tolua_get_AllToLua_g_BlockPistonBreakable(lua_State* tolua_S)
}
#endif //#ifndef TOLUA_DISABLE
+
+
+
+
/* set function: g_BlockPistonBreakable */
#ifndef TOLUA_DISABLE_tolua_set_AllToLua_g_BlockPistonBreakable
static int tolua_set_AllToLua_g_BlockPistonBreakable(lua_State* tolua_S)
@@ -231,11 +267,15 @@ static int tolua_set_AllToLua_g_BlockPistonBreakable(lua_State* tolua_S)
if (tolua_index<0 || tolua_index>=256)
tolua_error(tolua_S,"array indexing out of range.",NULL);
#endif
- cBlockInfo::Get(tolua_index).m_PistonBreakable = ((bool) tolua_toboolean(tolua_S,3,0));
+ cBlockInfo::Get(tolua_index).m_PistonBreakable = (tolua_toboolean(tolua_S,3,0) != 0);
return 0;
}
#endif //#ifndef TOLUA_DISABLE
+
+
+
+
/* get function: g_BlockIsSnowable */
#ifndef TOLUA_DISABLE_tolua_get_AllToLua_g_BlockIsSnowable
static int tolua_get_AllToLua_g_BlockIsSnowable(lua_State* tolua_S)
@@ -258,6 +298,10 @@ static int tolua_get_AllToLua_g_BlockIsSnowable(lua_State* tolua_S)
}
#endif //#ifndef TOLUA_DISABLE
+
+
+
+
/* set function: g_BlockIsSnowable */
#ifndef TOLUA_DISABLE_tolua_set_AllToLua_g_BlockIsSnowable
static int tolua_set_AllToLua_g_BlockIsSnowable(lua_State* tolua_S)
@@ -275,11 +319,15 @@ static int tolua_set_AllToLua_g_BlockIsSnowable(lua_State* tolua_S)
if (tolua_index<0 || tolua_index>=256)
tolua_error(tolua_S,"array indexing out of range.",NULL);
#endif
- cBlockInfo::Get(tolua_index).m_IsSnowable = ((bool) tolua_toboolean(tolua_S,3,0));
+ cBlockInfo::Get(tolua_index).m_IsSnowable = (tolua_toboolean(tolua_S,3,0) != 0);
return 0;
}
#endif //#ifndef TOLUA_DISABLE
+
+
+
+
/* get function: g_BlockRequiresSpecialTool */
#ifndef TOLUA_DISABLE_tolua_get_AllToLua_g_BlockRequiresSpecialTool
static int tolua_get_AllToLua_g_BlockRequiresSpecialTool(lua_State* tolua_S)
@@ -302,6 +350,10 @@ static int tolua_get_AllToLua_g_BlockRequiresSpecialTool(lua_State* tolua_S)
}
#endif //#ifndef TOLUA_DISABLE
+
+
+
+
/* set function: g_BlockRequiresSpecialTool */
#ifndef TOLUA_DISABLE_tolua_set_AllToLua_g_BlockRequiresSpecialTool
static int tolua_set_AllToLua_g_BlockRequiresSpecialTool(lua_State* tolua_S)
@@ -319,11 +371,15 @@ static int tolua_set_AllToLua_g_BlockRequiresSpecialTool(lua_State* tolua_S)
if (tolua_index<0 || tolua_index>=256)
tolua_error(tolua_S,"array indexing out of range.",NULL);
#endif
- cBlockInfo::Get(tolua_index).m_RequiresSpecialTool = ((bool) tolua_toboolean(tolua_S,3,0));
+ cBlockInfo::Get(tolua_index).m_RequiresSpecialTool = (tolua_toboolean(tolua_S,3,0) != 0);
return 0;
}
#endif //#ifndef TOLUA_DISABLE
+
+
+
+
/* get function: g_BlockIsSolid */
#ifndef TOLUA_DISABLE_tolua_get_AllToLua_g_BlockIsSolid
static int tolua_get_AllToLua_g_BlockIsSolid(lua_State* tolua_S)
@@ -346,6 +402,10 @@ static int tolua_get_AllToLua_g_BlockIsSolid(lua_State* tolua_S)
}
#endif //#ifndef TOLUA_DISABLE
+
+
+
+
/* set function: g_BlockIsSolid */
#ifndef TOLUA_DISABLE_tolua_set_AllToLua_g_BlockIsSolid
static int tolua_set_AllToLua_g_BlockIsSolid(lua_State* tolua_S)
@@ -363,11 +423,15 @@ static int tolua_set_AllToLua_g_BlockIsSolid(lua_State* tolua_S)
if (tolua_index<0 || tolua_index>=256)
tolua_error(tolua_S,"array indexing out of range.",NULL);
#endif
- cBlockInfo::Get(tolua_index).m_IsSolid = ((bool) tolua_toboolean(tolua_S,3,0));
+ cBlockInfo::Get(tolua_index).m_IsSolid = (tolua_toboolean(tolua_S,3,0) != 0);
return 0;
}
#endif //#ifndef TOLUA_DISABLE
+
+
+
+
/* get function: g_BlockFullyOccupiesVoxel */
#ifndef TOLUA_DISABLE_tolua_get_AllToLua_g_BlockFullyOccupiesVoxel
static int tolua_get_AllToLua_g_BlockFullyOccupiesVoxel(lua_State* tolua_S)
@@ -390,6 +454,10 @@ static int tolua_get_AllToLua_g_BlockFullyOccupiesVoxel(lua_State* tolua_S)
}
#endif //#ifndef TOLUA_DISABLE
+
+
+
+
/* set function: g_BlockFullyOccupiesVoxel */
#ifndef TOLUA_DISABLE_tolua_set_AllToLua_g_BlockFullyOccupiesVoxel
static int tolua_set_AllToLua_g_BlockFullyOccupiesVoxel(lua_State* tolua_S)
@@ -407,7 +475,7 @@ static int tolua_set_AllToLua_g_BlockFullyOccupiesVoxel(lua_State* tolua_S)
if (tolua_index<0 || tolua_index>=256)
tolua_error(tolua_S,"array indexing out of range.",NULL);
#endif
- cBlockInfo::Get(tolua_index).m_FullyOccupiesVoxel = ((bool) tolua_toboolean(tolua_S,3,0));
+ cBlockInfo::Get(tolua_index).m_FullyOccupiesVoxel = (tolua_toboolean(tolua_S,3,0) != 0);
return 0;
}
#endif //#ifndef TOLUA_DISABLE
--
cgit v1.2.3
From 0c8d08cb0962640bb3688f80ff782245daa2747c Mon Sep 17 00:00:00 2001
From: STRWarrior
Date: Sun, 2 Mar 2014 16:48:55 +0100
Subject: Simplified and more clearer infodump for Github.
---
MCServer/Plugins/InfoDump.lua | 21 +++++++--------------
1 file changed, 7 insertions(+), 14 deletions(-)
diff --git a/MCServer/Plugins/InfoDump.lua b/MCServer/Plugins/InfoDump.lua
index e7ed157e3..ede4c0e8b 100644
--- a/MCServer/Plugins/InfoDump.lua
+++ b/MCServer/Plugins/InfoDump.lua
@@ -317,26 +317,19 @@ local function WriteCommandsCategoryGithub(a_Category, f)
if (CategoryName == "") then
CategoryName = "General";
end
- f:write("\n## ", GithubizeString(a_Category.DisplayName or CategoryName), "\n");
+ f:write("\n### ", GithubizeString(a_Category.DisplayName or CategoryName), "\n");
-- Write description:
if (a_Category.Description ~= "") then
- f:write(GithubizeString(a_Category.Description), "\n");
+ f:write(GithubizeString(a_Category.Description), "\n\n");
end
+ f:write("| Command | Permission | Discription | \n")
+ f:write("| ------- | ---------- | ----------- | \n")
+
-- Write commands:
- f:write("\n");
for idx2, cmd in ipairs(a_Category.Commands) do
- f:write("\n### ", cmd.CommandString, "\n", GithubizeString(cmd.Info.HelpString or "UNDOCUMENTED"), "\n\n");
- if (cmd.Info.Permission ~= nil) then
- f:write("Permission required: **", cmd.Info.Permission, "**\n\n");
- end
- if (cmd.Info.DetailedDescription ~= nil) then
- f:write(GithubizeString(cmd.Info.DetailedDescription));
- end
- if (cmd.Info.ParameterCombinations ~= nil) then
- WriteCommandParameterCombinationsGithub(cmd.CommandString, cmd.Info.ParameterCombinations, f);
- end
+ f:write("|", cmd.CommandString, " | ", cmd.Info.Permission or "", " | ", GithubizeString(cmd.Info.HelpString or "UNDOCUMENTED"), "| \n")
end
f:write("\n\n")
end
@@ -601,7 +594,7 @@ local function DumpPluginInfoGithub(a_PluginFolder, a_PluginInfo)
f:write(GithubizeString(a_PluginInfo.Description), "\n");
DumpAdditionalInfoGithub(a_PluginInfo, f);
DumpCommandsGithub(a_PluginInfo, f);
- DumpPermissionsGithub(a_PluginInfo, f);
+ --DumpPermissionsGithub(a_PluginInfo, f); -- Seems a little overkill since they are already mentioned in the commands.
f:close();
end
--
cgit v1.2.3
From 20e377ea7b64f60bd5565b8c97ce26750e0eeb5e Mon Sep 17 00:00:00 2001
From: STRWarrior
Date: Sun, 2 Mar 2014 16:55:04 +0100
Subject: Fixed typo Discription => Description
---
MCServer/Plugins/InfoDump.lua | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/MCServer/Plugins/InfoDump.lua b/MCServer/Plugins/InfoDump.lua
index ede4c0e8b..59263d056 100644
--- a/MCServer/Plugins/InfoDump.lua
+++ b/MCServer/Plugins/InfoDump.lua
@@ -324,7 +324,7 @@ local function WriteCommandsCategoryGithub(a_Category, f)
f:write(GithubizeString(a_Category.Description), "\n\n");
end
- f:write("| Command | Permission | Discription | \n")
+ f:write("| Command | Permission | Description | \n")
f:write("| ------- | ---------- | ----------- | \n")
-- Write commands:
--
cgit v1.2.3
From 070d483236279e69c736e740fa8459d3ac627790 Mon Sep 17 00:00:00 2001
From: andrew
Date: Sun, 2 Mar 2014 21:25:05 +0200
Subject: cBlockInfo now manages the respective cBlockHandler
---
src/BlockInfo.cpp | 22 +++++++++++++++++++++
src/BlockInfo.h | 27 ++++++++++++++++++++++++++
src/Blocks/BlockHandler.cpp | 45 ++-----------------------------------------
src/Blocks/BlockHandler.h | 22 +++------------------
src/Blocks/ChunkInterface.cpp | 2 +-
src/ClientHandle.cpp | 6 +++---
src/Items/ItemHandler.cpp | 2 +-
src/Mobs/Villager.cpp | 2 +-
src/Root.cpp | 1 -
src/Scoreboard.cpp | 12 +++++++++---
src/World.cpp | 2 +-
11 files changed, 70 insertions(+), 73 deletions(-)
diff --git a/src/BlockInfo.cpp b/src/BlockInfo.cpp
index c73ae18b6..195af49c7 100644
--- a/src/BlockInfo.cpp
+++ b/src/BlockInfo.cpp
@@ -2,6 +2,7 @@
#include "Globals.h"
#include "BlockInfo.h"
+#include "Blocks/BlockHandler.h"
@@ -23,12 +24,25 @@ cBlockInfo::cBlockInfo()
, m_RequiresSpecialTool(false)
, m_IsSolid(true)
, m_FullyOccupiesVoxel(false)
+ , m_Handler(NULL)
{}
+cBlockInfo::~cBlockInfo()
+{
+ if (m_Handler != NULL)
+ {
+ delete m_Handler;
+ }
+}
+
+
+
+
+
cBlockInfo & cBlockInfo::Get(BLOCKTYPE a_Type)
{
ASSERT(a_Type < 256);
@@ -42,6 +56,14 @@ cBlockInfo & cBlockInfo::Get(BLOCKTYPE a_Type)
void cBlockInfo::Initialize(void)
{
+ for (unsigned int i = 0; i < 256; ++i)
+ {
+ if (ms_Info[i].m_Handler == NULL)
+ {
+ ms_Info[i].m_Handler = cBlockHandler::CreateBlockHandler((BLOCKTYPE) i);
+ }
+ }
+
// Emissive blocks
ms_Info[E_BLOCK_FIRE ].m_LightValue = 15;
ms_Info[E_BLOCK_GLOWSTONE ].m_LightValue = 15;
diff --git a/src/BlockInfo.h b/src/BlockInfo.h
index 34a845b20..40c1db867 100644
--- a/src/BlockInfo.h
+++ b/src/BlockInfo.h
@@ -5,6 +5,13 @@
+// fwd:
+class cBlockHandler;
+
+
+
+
+
// tolua_begin
class cBlockInfo
{
@@ -13,6 +20,8 @@ public:
cBlockInfo();
+ ~cBlockInfo();
+
/** (Re-)Initializes the internal BlockInfo structures. */
static void Initialize(void);
@@ -49,6 +58,12 @@ public:
/** Does this block fully occupy its voxel - is it a 'full' block? */
bool m_FullyOccupiesVoxel;
+ // tolua_end
+
+ /** Associated block handler. */
+ cBlockHandler * m_Handler;
+
+ // tolua_begin
inline static NIBBLETYPE GetLightValue (BLOCKTYPE a_Type) { return Get(a_Type).m_LightValue; }
inline static NIBBLETYPE GetSpreadLightFalloff(BLOCKTYPE a_Type) { return Get(a_Type).m_SpreadLightFalloff; }
@@ -62,6 +77,8 @@ public:
// tolua_end
+ inline static cBlockHandler * GetHandler (BLOCKTYPE a_Type) { return Get(a_Type).m_Handler; }
+
protected:
@@ -74,3 +91,13 @@ protected:
+
+// Shortcut to get the blockhandler for a specific block
+inline cBlockHandler * BlockHandler(BLOCKTYPE a_BlockType)
+{
+ return cBlockInfo::Get(a_BlockType).m_Handler;
+}
+
+
+
+
diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp
index 834727c9a..052f88f7a 100644
--- a/src/Blocks/BlockHandler.cpp
+++ b/src/Blocks/BlockHandler.cpp
@@ -77,33 +77,6 @@
-bool cBlockHandler::m_HandlerInitialized = false;
-cBlockHandler * cBlockHandler::m_BlockHandler[256];
-
-
-
-
-
-cBlockHandler * cBlockHandler::GetBlockHandler(BLOCKTYPE a_BlockType)
-{
- if (!m_HandlerInitialized)
- {
- // We have to initialize
- memset(m_BlockHandler, 0, sizeof(m_BlockHandler));
- m_HandlerInitialized = true;
- }
- if (m_BlockHandler[a_BlockType] != NULL)
- {
- return m_BlockHandler[a_BlockType];
- }
-
- return m_BlockHandler[a_BlockType] = CreateBlockHandler(a_BlockType);
-}
-
-
-
-
-
cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType)
{
switch(a_BlockType)
@@ -192,7 +165,7 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType)
case E_BLOCK_REDSTONE_REPEATER_ON: return new cBlockRedstoneRepeaterHandler(a_BlockType);
case E_BLOCK_REDSTONE_TORCH_OFF: return new cBlockRedstoneTorchHandler (a_BlockType);
case E_BLOCK_REDSTONE_TORCH_ON: return new cBlockRedstoneTorchHandler (a_BlockType);
- case E_BLOCK_REDSTONE_WIRE: return new cBlockRedstoneHandler (a_BlockType);
+ case E_BLOCK_REDSTONE_WIRE: return new cBlockRedstoneHandler (a_BlockType);
case E_BLOCK_RED_MUSHROOM: return new cBlockMushroomHandler (a_BlockType);
case E_BLOCK_RED_ROSE: return new cBlockFlowerHandler (a_BlockType);
case E_BLOCK_SAND: return new cBlockSandHandler (a_BlockType);
@@ -231,20 +204,6 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType)
-void cBlockHandler::Deinit()
-{
- for (int i = 0; i < 256; i++)
- {
- delete m_BlockHandler[i];
- }
- memset(m_BlockHandler, 0, sizeof(m_BlockHandler)); // Don't leave any dangling pointers around, just in case
- m_HandlerInitialized = false;
-}
-
-
-
-
-
cBlockHandler::cBlockHandler(BLOCKTYPE a_BlockType)
{
m_BlockType = a_BlockType;
@@ -329,7 +288,7 @@ void cBlockHandler::NeighborChanged(cChunkInterface & a_ChunkInterface, int a_Bl
{
if ((a_BlockY >= 0) && (a_BlockY < cChunkDef::Height))
{
- GetBlockHandler(a_ChunkInterface.GetBlock(a_BlockX, a_BlockY, a_BlockZ))->OnNeighborChanged(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ);
+ cBlockInfo::GetHandler(a_ChunkInterface.GetBlock(a_BlockX, a_BlockY, a_BlockZ))->OnNeighborChanged(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ);
}
}
diff --git a/src/Blocks/BlockHandler.h b/src/Blocks/BlockHandler.h
index a2913d7f8..c46a46045 100644
--- a/src/Blocks/BlockHandler.h
+++ b/src/Blocks/BlockHandler.h
@@ -136,30 +136,14 @@ public:
/// Block meta following mirroring
virtual NIBBLETYPE MetaMirrorYZ(NIBBLETYPE a_Meta) { return a_Meta; }
- /// Get the blockhandler for a specific block id
- static cBlockHandler * GetBlockHandler(BLOCKTYPE a_BlockType);
-
- /// Deletes all initialised block handlers
- static void Deinit();
-
protected:
BLOCKTYPE m_BlockType;
// Creates a new blockhandler for the given block type. For internal use only, use ::GetBlockHandler() instead.
- static cBlockHandler *CreateBlockHandler(BLOCKTYPE a_BlockType);
- static cBlockHandler *m_BlockHandler[256];
- static bool m_HandlerInitialized; //used to detect if the blockhandlers are initialized
-};
-
-
+ static cBlockHandler * CreateBlockHandler(BLOCKTYPE a_BlockType);
-
-
-// Shortcut to get the blockhandler for a specific block
-inline cBlockHandler * BlockHandler(BLOCKTYPE a_BlockType)
-{
- return cBlockHandler::GetBlockHandler(a_BlockType);
-}
+ friend class cBlockInfo;
+};
diff --git a/src/Blocks/ChunkInterface.cpp b/src/Blocks/ChunkInterface.cpp
index b2dda19f4..540581ae7 100644
--- a/src/Blocks/ChunkInterface.cpp
+++ b/src/Blocks/ChunkInterface.cpp
@@ -6,7 +6,7 @@
bool cChunkInterface::DigBlock(cWorldInterface & a_WorldInterface, int a_X, int a_Y, int a_Z)
{
- cBlockHandler *Handler = cBlockHandler::GetBlockHandler(GetBlock(a_X, a_Y, a_Z));
+ cBlockHandler * Handler = cBlockInfo::GetHandler(GetBlock(a_X, a_Y, a_Z));
Handler->OnDestroyed(*this, a_WorldInterface, a_X, a_Y, a_Z);
return m_ChunkMap->DigBlock(a_X, a_Y, a_Z);
}
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index 07a8984c5..6982a6227 100644
--- a/src/ClientHandle.cpp
+++ b/src/ClientHandle.cpp
@@ -838,7 +838,7 @@ void cClientHandle::HandleBlockDigStarted(int a_BlockX, int a_BlockY, int a_Bloc
cWorld * World = m_Player->GetWorld();
cChunkInterface ChunkInterface(World->GetChunkMap());
- cBlockHandler * Handler = cBlockHandler::GetBlockHandler(a_OldBlock);
+ cBlockHandler * Handler = cBlockInfo::GetHandler(a_OldBlock);
Handler->OnDigging(ChunkInterface, *World, m_Player, a_BlockX, a_BlockY, a_BlockZ);
cItemHandler * ItemHandler = cItemHandler::GetItemHandler(m_Player->GetEquippedItem());
@@ -852,7 +852,7 @@ void cClientHandle::HandleBlockDigStarted(int a_BlockX, int a_BlockY, int a_Bloc
int pZ = a_BlockZ;
AddFaceDirection(pX, pY, pZ, a_BlockFace); // Get the block in front of the clicked coordinates (m_bInverse defaulted to false)
- Handler = cBlockHandler::GetBlockHandler(World->GetBlock(pX, pY, pZ));
+ Handler = cBlockInfo::GetHandler(World->GetBlock(pX, pY, pZ));
if (Handler->IsClickedThrough())
{
@@ -963,7 +963,7 @@ void cClientHandle::HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, e
BLOCKTYPE BlockType;
NIBBLETYPE BlockMeta;
World->GetBlockTypeMeta(a_BlockX, a_BlockY, a_BlockZ, BlockType, BlockMeta);
- cBlockHandler * BlockHandler = cBlockHandler::GetBlockHandler(BlockType);
+ cBlockHandler * BlockHandler = cBlockInfo::GetHandler(BlockType);
if (BlockHandler->IsUseable() && !m_Player->IsCrouched())
{
diff --git a/src/Items/ItemHandler.cpp b/src/Items/ItemHandler.cpp
index 507f7fa86..1d357fcf1 100644
--- a/src/Items/ItemHandler.cpp
+++ b/src/Items/ItemHandler.cpp
@@ -285,7 +285,7 @@ void cItemHandler::OnBlockDestroyed(cWorld * a_World, cPlayer * a_Player, const
UNUSED(a_Item);
BLOCKTYPE Block = a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ);
- cBlockHandler * Handler = cBlockHandler::GetBlockHandler(Block);
+ cBlockHandler * Handler = cBlockInfo::GetHandler(Block);
if (a_Player->IsGameModeSurvival())
{
diff --git a/src/Mobs/Villager.cpp b/src/Mobs/Villager.cpp
index 09a6e2d09..bbd8d6aaa 100644
--- a/src/Mobs/Villager.cpp
+++ b/src/Mobs/Villager.cpp
@@ -150,7 +150,7 @@ void cVillager::HandleFarmerTryHarvestCrops()
BLOCKTYPE CropBlock = m_World->GetBlock(m_CropsPos.x, m_CropsPos.y, m_CropsPos.z);
if (IsBlockFarmable(CropBlock) && m_World->GetBlockMeta(m_CropsPos.x, m_CropsPos.y, m_CropsPos.z) == 0x7)
{
- cBlockHandler * Handler = cBlockHandler::GetBlockHandler(CropBlock);
+ cBlockHandler * Handler = cBlockInfo::GetHandler(CropBlock);
cChunkInterface ChunkInterface(m_World->GetChunkMap());
cBlockInServerPluginInterface PluginInterface(*m_World);
Handler->DropBlock(ChunkInterface, *m_World, PluginInterface, this, m_CropsPos.x, m_CropsPos.y, m_CropsPos.z);
diff --git a/src/Root.cpp b/src/Root.cpp
index af2cb9e4b..78c94888d 100644
--- a/src/Root.cpp
+++ b/src/Root.cpp
@@ -245,7 +245,6 @@ void cRoot::Start(void)
delete m_PluginManager; m_PluginManager = NULL;
cItemHandler::Deinit();
- cBlockHandler::Deinit();
LOG("Cleaning up...");
delete m_Server; m_Server = NULL;
diff --git a/src/Scoreboard.cpp b/src/Scoreboard.cpp
index 05fd0314d..c1da27086 100644
--- a/src/Scoreboard.cpp
+++ b/src/Scoreboard.cpp
@@ -312,12 +312,18 @@ bool cScoreboard::RemoveObjective(const AString & a_Name)
return false;
}
- m_Objectives.erase(it);
-
ASSERT(m_World != NULL);
m_World->BroadcastScoreboardObjective(it->second.GetName(), it->second.GetDisplayName(), 1);
- // TODO 2014-03-01 xdot: Remove objective from display slot
+ for (unsigned int i = 0; i < (unsigned int) dsCount; ++i)
+ {
+ if (m_Display[i] == &it->second)
+ {
+ SetDisplay(NULL, (eDisplaySlot) i);
+ }
+ }
+
+ m_Objectives.erase(it);
return true;
}
diff --git a/src/World.cpp b/src/World.cpp
index ffdae2a37..2dfa85d64 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -1723,7 +1723,7 @@ bool cWorld::GetBlocks(sSetBlockVector & a_Blocks, bool a_ContinueOnFailure)
bool cWorld::DigBlock(int a_X, int a_Y, int a_Z)
{
- cBlockHandler *Handler = cBlockHandler::GetBlockHandler(GetBlock(a_X, a_Y, a_Z));
+ cBlockHandler * Handler = cBlockInfo::GetHandler(GetBlock(a_X, a_Y, a_Z));
cChunkInterface ChunkInterface(GetChunkMap());
Handler->OnDestroyed(ChunkInterface, *this, a_X, a_Y, a_Z);
return m_ChunkMap->DigBlock(a_X, a_Y, a_Z);
--
cgit v1.2.3
From 6536233f4d0bb9411895ce78d1c57e37a7aac044 Mon Sep 17 00:00:00 2001
From: Tycho
Date: Sun, 2 Mar 2014 12:29:20 -0800
Subject: Reformated MetaRotater
---
src/Blocks/MetaRotater.h | 49 +++++++++++++++++++++++++++++-------------------
1 file changed, 30 insertions(+), 19 deletions(-)
diff --git a/src/Blocks/MetaRotater.h b/src/Blocks/MetaRotater.h
index b83ed177a..5493c87e2 100644
--- a/src/Blocks/MetaRotater.h
+++ b/src/Blocks/MetaRotater.h
@@ -1,7 +1,18 @@
+// MetaRotater.h
+
+// Provides a mixin for rotations and reflections
+
#pragma once
-template
+/*
+Provides a mixin for rotations and reflections following the standard pattern of apply mask then use case.
+
+Usage:
+Inherit from this class providing your base class as Base, the BitMask for the direction bits in bitmask and the masked value for the directions in North, East, South, West. There is also an aptional parameter AssertIfNotMatched. Set this if it is invalid for a block to exist in any other state.
+*/
+
+template
class cMetaRotater : public Base
{
public:
@@ -19,18 +30,18 @@ public:
};
-template
-NIBBLETYPE cMetaRotater::MetaRotateCW(NIBBLETYPE a_Meta)
+template
+NIBBLETYPE cMetaRotater::MetaRotateCW(NIBBLETYPE a_Meta)
{
- NIBBLETYPE OtherMeta = a_Meta & (~BitFilter);
- switch (a_Meta & BitFilter)
+ NIBBLETYPE OtherMeta = a_Meta & (~BitMask);
+ switch (a_Meta & BitMask)
{
case South: return West | OtherMeta;
case West: return North | OtherMeta;
case North: return East | OtherMeta;
case East: return South | OtherMeta;
}
- if(AssertIfNotMatched)
+ if (AssertIfNotMatched)
{
ASSERT(!"Invalid Meta value");
return a_Meta;
@@ -38,18 +49,18 @@ NIBBLETYPE cMetaRotater
-NIBBLETYPE cMetaRotater::MetaRotateCCW(NIBBLETYPE a_Meta)
+template
+NIBBLETYPE cMetaRotater::MetaRotateCCW(NIBBLETYPE a_Meta)
{
- NIBBLETYPE OtherMeta = a_Meta & (~BitFilter);
- switch (a_Meta & BitFilter)
+ NIBBLETYPE OtherMeta = a_Meta & (~BitMask);
+ switch (a_Meta & BitMask)
{
case South: return East | OtherMeta;
case East: return North | OtherMeta;
case North: return West | OtherMeta;
case West: return South | OtherMeta;
}
- if(AssertIfNotMatched)
+ if (AssertIfNotMatched)
{
ASSERT(!"Invalid Meta value");
return a_Meta;
@@ -58,11 +69,11 @@ NIBBLETYPE cMetaRotater
-NIBBLETYPE cMetaRotater::MetaMirrorXY(NIBBLETYPE a_Meta)
+template
+NIBBLETYPE cMetaRotater::MetaMirrorXY(NIBBLETYPE a_Meta)
{
- NIBBLETYPE OtherMeta = a_Meta & (~BitFilter);
- switch (a_Meta & BitFilter)
+ NIBBLETYPE OtherMeta = a_Meta & (~BitMask);
+ switch (a_Meta & BitMask)
{
case South: return North | OtherMeta;
case North: return South | OtherMeta;
@@ -74,11 +85,11 @@ NIBBLETYPE cMetaRotater
-NIBBLETYPE cMetaRotater::MetaMirrorYZ(NIBBLETYPE a_Meta)
+template
+NIBBLETYPE cMetaRotater::MetaMirrorYZ(NIBBLETYPE a_Meta)
{
- NIBBLETYPE OtherMeta = a_Meta & (~BitFilter);
- switch (a_Meta & BitFilter)
+ NIBBLETYPE OtherMeta = a_Meta & (~BitMask);
+ switch (a_Meta & BitMask)
{
case West: return East | OtherMeta;
case East: return West | OtherMeta;
--
cgit v1.2.3
From a38be148ba980e7d54bf72c9056502850d81c77a Mon Sep 17 00:00:00 2001
From: Tycho
Date: Sun, 2 Mar 2014 12:33:08 -0800
Subject: Reformatted
---
src/Blocks/BlockBed.h | 4 ++--
src/Blocks/BlockButton.h | 4 ++--
src/Blocks/BlockChest.h | 4 ++--
src/Blocks/BlockComparator.h | 4 ++--
src/Blocks/BlockDoor.h | 4 ++--
src/Blocks/BlockDropSpenser.h | 4 ++--
src/Blocks/BlockEnderchest.h | 4 ++--
src/Blocks/BlockFenceGate.h | 4 ++--
src/Blocks/BlockStairs.h | 4 ++--
src/Blocks/BlockTorch.h | 4 ++--
10 files changed, 20 insertions(+), 20 deletions(-)
diff --git a/src/Blocks/BlockBed.h b/src/Blocks/BlockBed.h
index d8a796735..6daa94730 100644
--- a/src/Blocks/BlockBed.h
+++ b/src/Blocks/BlockBed.h
@@ -12,11 +12,11 @@
class cBlockBedHandler :
- public cMetaRotater
+ public cMetaRotater
{
public:
cBlockBedHandler(BLOCKTYPE a_BlockType)
- : cMetaRotater(a_BlockType)
+ : cMetaRotater(a_BlockType)
{
}
diff --git a/src/Blocks/BlockButton.h b/src/Blocks/BlockButton.h
index 4daa03005..e4923c441 100644
--- a/src/Blocks/BlockButton.h
+++ b/src/Blocks/BlockButton.h
@@ -8,11 +8,11 @@
class cBlockButtonHandler :
- public cMetaRotater
+ public cMetaRotater
{
public:
cBlockButtonHandler(BLOCKTYPE a_BlockType)
- : cMetaRotater(a_BlockType)
+ : cMetaRotater(a_BlockType)
{
}
diff --git a/src/Blocks/BlockChest.h b/src/Blocks/BlockChest.h
index 1646454a7..30588d8fc 100644
--- a/src/Blocks/BlockChest.h
+++ b/src/Blocks/BlockChest.h
@@ -11,11 +11,11 @@
class cBlockChestHandler :
- public cMetaRotater
+ public cMetaRotater
{
public:
cBlockChestHandler(BLOCKTYPE a_BlockType)
- : cMetaRotater(a_BlockType)
+ : cMetaRotater(a_BlockType)
{
}
diff --git a/src/Blocks/BlockComparator.h b/src/Blocks/BlockComparator.h
index 238e687ab..a8536b149 100644
--- a/src/Blocks/BlockComparator.h
+++ b/src/Blocks/BlockComparator.h
@@ -10,11 +10,11 @@
class cBlockComparatorHandler :
- public cMetaRotater
+ public cMetaRotater
{
public:
cBlockComparatorHandler(BLOCKTYPE a_BlockType)
- : cMetaRotater(a_BlockType)
+ : cMetaRotater(a_BlockType)
{
}
diff --git a/src/Blocks/BlockDoor.h b/src/Blocks/BlockDoor.h
index 0caeb7dba..ef73a5d42 100644
--- a/src/Blocks/BlockDoor.h
+++ b/src/Blocks/BlockDoor.h
@@ -10,9 +10,9 @@
class cBlockDoorHandler :
- public cMetaRotater
+ public cMetaRotater
{
- typedef cMetaRotater super;
+ typedef cMetaRotater super;
public:
cBlockDoorHandler(BLOCKTYPE a_BlockType);
diff --git a/src/Blocks/BlockDropSpenser.h b/src/Blocks/BlockDropSpenser.h
index adc819a4c..7e0ad0e55 100644
--- a/src/Blocks/BlockDropSpenser.h
+++ b/src/Blocks/BlockDropSpenser.h
@@ -13,11 +13,11 @@
class cBlockDropSpenserHandler :
- public cMetaRotater
+ public cMetaRotater
{
public:
cBlockDropSpenserHandler(BLOCKTYPE a_BlockType) :
- cMetaRotater(a_BlockType)
+ cMetaRotater(a_BlockType)
{
}
diff --git a/src/Blocks/BlockEnderchest.h b/src/Blocks/BlockEnderchest.h
index 6ca83399a..97cf484fb 100644
--- a/src/Blocks/BlockEnderchest.h
+++ b/src/Blocks/BlockEnderchest.h
@@ -8,11 +8,11 @@
class cBlockEnderchestHandler :
- public cMetaRotater
+ public cMetaRotater
{
public:
cBlockEnderchestHandler(BLOCKTYPE a_BlockType)
- : cMetaRotater(a_BlockType)
+ : cMetaRotater(a_BlockType)
{
}
diff --git a/src/Blocks/BlockFenceGate.h b/src/Blocks/BlockFenceGate.h
index c33393590..8c94e4875 100644
--- a/src/Blocks/BlockFenceGate.h
+++ b/src/Blocks/BlockFenceGate.h
@@ -8,11 +8,11 @@
class cBlockFenceGateHandler :
- public cMetaRotater
+ public cMetaRotater
{
public:
cBlockFenceGateHandler(BLOCKTYPE a_BlockType) :
- cMetaRotater(a_BlockType)
+ cMetaRotater(a_BlockType)
{
}
diff --git a/src/Blocks/BlockStairs.h b/src/Blocks/BlockStairs.h
index f07afc9f0..bbbe0ee84 100644
--- a/src/Blocks/BlockStairs.h
+++ b/src/Blocks/BlockStairs.h
@@ -8,11 +8,11 @@
class cBlockStairsHandler :
- public cMetaRotater
+ public cMetaRotater
{
public:
cBlockStairsHandler(BLOCKTYPE a_BlockType) :
- cMetaRotater(a_BlockType)
+ cMetaRotater(a_BlockType)
{
}
diff --git a/src/Blocks/BlockTorch.h b/src/Blocks/BlockTorch.h
index 59c896857..03a63ac72 100644
--- a/src/Blocks/BlockTorch.h
+++ b/src/Blocks/BlockTorch.h
@@ -8,11 +8,11 @@
class cBlockTorchHandler :
- public cMetaRotater
+ public cMetaRotater
{
public:
cBlockTorchHandler(BLOCKTYPE a_BlockType)
- : cMetaRotater(a_BlockType)
+ : cMetaRotater(a_BlockType)
{
}
--
cgit v1.2.3
From 36fd78af35b49d64b97e93df6428ace787c88c4c Mon Sep 17 00:00:00 2001
From: andrew
Date: Sun, 2 Mar 2014 22:55:14 +0200
Subject: Removed if condition
---
src/BlockInfo.cpp | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/src/BlockInfo.cpp b/src/BlockInfo.cpp
index 195af49c7..399efcd9b 100644
--- a/src/BlockInfo.cpp
+++ b/src/BlockInfo.cpp
@@ -33,10 +33,7 @@ cBlockInfo::cBlockInfo()
cBlockInfo::~cBlockInfo()
{
- if (m_Handler != NULL)
- {
- delete m_Handler;
- }
+ delete m_Handler;
}
--
cgit v1.2.3
From 442c1d96fc77a91b917c7a7aefb7f8f23c0a7e10 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Mon, 3 Mar 2014 20:55:04 +0100
Subject: Fixed previous weather changes.
cWorld::GetDefaultWeatherInterval() returns -1 for unknown weather.
---
src/World.cpp | 6 +++---
src/World.h | 3 ++-
2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/src/World.cpp b/src/World.cpp
index 58d50d3a8..6ee0def91 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -325,8 +325,8 @@ int cWorld::GetDefaultWeatherInterval(eWeather a_Weather)
}
default:
{
- LOGWARNING("Missing default weather interval for weather %d.", a_Weather);
- return 1200;
+ LOGWARNING("%s: Missing default weather interval for weather %d.", __FUNCTION__, a_Weather);
+ return -1;
}
} // switch (Weather)
}
@@ -348,7 +348,7 @@ void cWorld::SetWeather(eWeather a_NewWeather)
m_WeatherInterval = GetDefaultWeatherInterval(a_NewWeather);
// The weather can't be found:
- if (m_WeatherInterval == 1200)
+ if (m_WeatherInterval < 0)
{
return;
}
diff --git a/src/World.h b/src/World.h
index 27f1482e5..93397c014 100644
--- a/src/World.h
+++ b/src/World.h
@@ -139,7 +139,8 @@ public:
BroadcastTimeUpdate();
}
- /** Returns the default weather interval for the specific weather type */
+ /** Returns the default weather interval for the specific weather type.
+ Returns -1 for any unknown weather. */
int GetDefaultWeatherInterval(eWeather a_Weather);
/** Returns the current game mode. Partly OBSOLETE, you should use IsGameModeXXX() functions wherever applicable */
--
cgit v1.2.3
From e50ffba1ad1cae0154828ccc210ba4949af088f3 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Tue, 4 Mar 2014 18:40:55 +0100
Subject: Fixed an assert in map-loading.
The maps were loaded too soon, the world wasn't initialized yet.
---
src/World.cpp | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/src/World.cpp b/src/World.cpp
index 6ee0def91..37c07b398 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -264,8 +264,6 @@ cWorld::cWorld(const AString & a_WorldName) :
// Load the scoreboard
cScoreboardSerializer Serializer(m_WorldName, &m_Scoreboard);
Serializer.Load();
-
- m_MapManager.LoadMapData();
}
@@ -652,13 +650,13 @@ void cWorld::Start(void)
m_LastSpawnMonster.insert(std::map::value_type(cMonster::mfAmbient, 0));
m_LastSpawnMonster.insert(std::map::value_type(cMonster::mfWater, 0));
+ m_MapManager.LoadMapData();
// Save any changes that the defaults may have done to the ini file:
if (!IniFile.WriteFile(m_IniFileName))
{
LOGWARNING("Could not write world config to %s", m_IniFileName.c_str());
}
-
}
--
cgit v1.2.3
From ecfe17b096994649610c03561496d8506648322c Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Tue, 4 Mar 2014 21:55:24 +0100
Subject: cLuaState: Made public the GetStackValue() functions.
---
src/Bindings/LuaState.cpp | 18 ++++++---
src/Bindings/LuaState.h | 97 ++++++++++++++++++++++++-----------------------
2 files changed, 61 insertions(+), 54 deletions(-)
diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp
index a5540df17..1890dcfe5 100644
--- a/src/Bindings/LuaState.cpp
+++ b/src/Bindings/LuaState.cpp
@@ -716,7 +716,7 @@ void cLuaState::Push(cBlockEntity * a_BlockEntity)
-void cLuaState::GetReturn(int a_StackPos, bool & a_ReturnedVal)
+void cLuaState::GetStackValue(int a_StackPos, bool & a_ReturnedVal)
{
a_ReturnedVal = (tolua_toboolean(m_LuaState, a_StackPos, a_ReturnedVal ? 1 : 0) > 0);
}
@@ -725,11 +725,17 @@ void cLuaState::GetReturn(int a_StackPos, bool & a_ReturnedVal)
-void cLuaState::GetReturn(int a_StackPos, AString & a_ReturnedVal)
+void cLuaState::GetStackValue(int a_StackPos, AString & a_Value)
{
- if (lua_isstring(m_LuaState, a_StackPos))
+ size_t len = 0;
+ const char * data = lua_tolstring(m_LuaState, a_StackPos, &len);
+ if (data != NULL)
+ {
+ a_Value.assign(data, len);
+ }
+ else
{
- a_ReturnedVal = tolua_tocppstring(m_LuaState, a_StackPos, a_ReturnedVal.c_str());
+ a_Value.clear();
}
}
@@ -737,7 +743,7 @@ void cLuaState::GetReturn(int a_StackPos, AString & a_ReturnedVal)
-void cLuaState::GetReturn(int a_StackPos, int & a_ReturnedVal)
+void cLuaState::GetStackValue(int a_StackPos, int & a_ReturnedVal)
{
if (lua_isnumber(m_LuaState, a_StackPos))
{
@@ -749,7 +755,7 @@ void cLuaState::GetReturn(int a_StackPos, int & a_ReturnedVal)
-void cLuaState::GetReturn(int a_StackPos, double & a_ReturnedVal)
+void cLuaState::GetStackValue(int a_StackPos, double & a_ReturnedVal)
{
if (lua_isnumber(m_LuaState, a_StackPos))
{
diff --git a/src/Bindings/LuaState.h b/src/Bindings/LuaState.h
index dcb660c3f..4a7a6fadb 100644
--- a/src/Bindings/LuaState.h
+++ b/src/Bindings/LuaState.h
@@ -197,6 +197,19 @@ public:
void Push(void * a_Ptr);
void Push(cHopperEntity * a_Hopper);
void Push(cBlockEntity * a_BlockEntity);
+
+ /** Retrieve value at a_StackPos, if it is a valid bool. If not, a_Value is unchanged */
+ void GetStackValue(int a_StackPos, bool & a_Value);
+
+ /** Retrieve value at a_StackPos, if it is a valid string. If not, a_Value is unchanged */
+ void GetStackValue(int a_StackPos, AString & a_Value);
+
+ /** Retrieve value at a_StackPos, if it is a valid number. If not, a_Value is unchanged */
+ void GetStackValue(int a_StackPos, int & a_Value);
+
+ /** Retrieve value at a_StackPos, if it is a valid number. If not, a_Value is unchanged */
+ void GetStackValue(int a_StackPos, double & a_Value);
+
/** Call any 0-param 0-return Lua function in a single line: */
template
@@ -270,7 +283,7 @@ public:
{
return false;
}
- GetReturn(-1, a_Ret1);
+ GetStackValue(-1, a_Ret1);
lua_pop(m_LuaState, 1);
return true;
}
@@ -292,7 +305,7 @@ public:
{
return false;
}
- GetReturn(-1, a_Ret1);
+ GetStackValue(-1, a_Ret1);
lua_pop(m_LuaState, 1);
ASSERT(InitialTop == lua_gettop(m_LuaState));
return true;
@@ -315,7 +328,7 @@ public:
{
return false;
}
- GetReturn(-1, a_Ret1);
+ GetStackValue(-1, a_Ret1);
lua_pop(m_LuaState, 1);
return true;
}
@@ -338,7 +351,7 @@ public:
{
return false;
}
- GetReturn(-1, a_Ret1);
+ GetStackValue(-1, a_Ret1);
lua_pop(m_LuaState, 1);
return true;
}
@@ -362,7 +375,7 @@ public:
{
return false;
}
- GetReturn(-1, a_Ret1);
+ GetStackValue(-1, a_Ret1);
lua_pop(m_LuaState, 1);
return true;
}
@@ -387,7 +400,7 @@ public:
{
return false;
}
- GetReturn(-1, a_Ret1);
+ GetStackValue(-1, a_Ret1);
lua_pop(m_LuaState, 1);
return true;
}
@@ -414,7 +427,7 @@ public:
{
return false;
}
- GetReturn(-1, a_Ret1);
+ GetStackValue(-1, a_Ret1);
lua_pop(m_LuaState, 1);
return true;
}
@@ -442,7 +455,7 @@ public:
{
return false;
}
- GetReturn(-1, a_Ret1);
+ GetStackValue(-1, a_Ret1);
lua_pop(m_LuaState, 1);
return true;
}
@@ -471,7 +484,7 @@ public:
{
return false;
}
- GetReturn(-1, a_Ret1);
+ GetStackValue(-1, a_Ret1);
lua_pop(m_LuaState, 1);
return true;
}
@@ -501,7 +514,7 @@ public:
{
return false;
}
- GetReturn(-1, a_Ret1);
+ GetStackValue(-1, a_Ret1);
lua_pop(m_LuaState, 1);
return true;
}
@@ -532,7 +545,7 @@ public:
{
return false;
}
- GetReturn(-1, a_Ret1);
+ GetStackValue(-1, a_Ret1);
lua_pop(m_LuaState, 1);
return true;
}
@@ -553,8 +566,8 @@ public:
{
return false;
}
- GetReturn(-2, a_Ret1);
- GetReturn(-1, a_Ret2);
+ GetStackValue(-2, a_Ret1);
+ GetStackValue(-1, a_Ret2);
lua_pop(m_LuaState, 2);
return true;
}
@@ -576,8 +589,8 @@ public:
{
return false;
}
- GetReturn(-2, a_Ret1);
- GetReturn(-1, a_Ret2);
+ GetStackValue(-2, a_Ret1);
+ GetStackValue(-1, a_Ret2);
lua_pop(m_LuaState, 2);
return true;
}
@@ -601,8 +614,8 @@ public:
{
return false;
}
- GetReturn(-2, a_Ret1);
- GetReturn(-1, a_Ret2);
+ GetStackValue(-2, a_Ret1);
+ GetStackValue(-1, a_Ret2);
lua_pop(m_LuaState, 2);
return true;
}
@@ -627,8 +640,8 @@ public:
{
return false;
}
- GetReturn(-2, a_Ret1);
- GetReturn(-1, a_Ret2);
+ GetStackValue(-2, a_Ret1);
+ GetStackValue(-1, a_Ret2);
lua_pop(m_LuaState, 2);
return true;
}
@@ -654,8 +667,8 @@ public:
{
return false;
}
- GetReturn(-2, a_Ret1);
- GetReturn(-1, a_Ret2);
+ GetStackValue(-2, a_Ret1);
+ GetStackValue(-1, a_Ret2);
lua_pop(m_LuaState, 2);
return true;
}
@@ -683,8 +696,8 @@ public:
{
return false;
}
- GetReturn(-2, a_Ret1);
- GetReturn(-1, a_Ret2);
+ GetStackValue(-2, a_Ret1);
+ GetStackValue(-1, a_Ret2);
lua_pop(m_LuaState, 2);
return true;
}
@@ -713,8 +726,8 @@ public:
{
return false;
}
- GetReturn(-2, a_Ret1);
- GetReturn(-1, a_Ret2);
+ GetStackValue(-2, a_Ret1);
+ GetStackValue(-1, a_Ret2);
lua_pop(m_LuaState, 2);
return true;
}
@@ -743,9 +756,9 @@ public:
{
return false;
}
- GetReturn(-3, a_Ret1);
- GetReturn(-2, a_Ret2);
- GetReturn(-1, a_Ret3);
+ GetStackValue(-3, a_Ret1);
+ GetStackValue(-2, a_Ret2);
+ GetStackValue(-1, a_Ret3);
lua_pop(m_LuaState, 3);
return true;
}
@@ -775,9 +788,9 @@ public:
{
return false;
}
- GetReturn(-3, a_Ret1);
- GetReturn(-2, a_Ret2);
- GetReturn(-1, a_Ret3);
+ GetStackValue(-3, a_Ret1);
+ GetStackValue(-2, a_Ret2);
+ GetStackValue(-1, a_Ret3);
lua_pop(m_LuaState, 3);
return true;
}
@@ -808,11 +821,11 @@ public:
{
return false;
}
- GetReturn(-5, a_Ret1);
- GetReturn(-4, a_Ret2);
- GetReturn(-3, a_Ret3);
- GetReturn(-2, a_Ret4);
- GetReturn(-1, a_Ret5);
+ GetStackValue(-5, a_Ret1);
+ GetStackValue(-4, a_Ret2);
+ GetStackValue(-3, a_Ret3);
+ GetStackValue(-2, a_Ret4);
+ GetStackValue(-1, a_Ret5);
lua_pop(m_LuaState, 5);
return true;
}
@@ -918,18 +931,6 @@ protected:
/** Pushes a usertype of the specified class type onto the stack */
void PushUserType(void * a_Object, const char * a_Type);
- /** Retrieve value returned at a_StackPos, if it is a valid bool. If not, a_ReturnedVal is unchanged */
- void GetReturn(int a_StackPos, bool & a_ReturnedVal);
-
- /** Retrieve value returned at a_StackPos, if it is a valid string. If not, a_ReturnedVal is unchanged */
- void GetReturn(int a_StackPos, AString & a_ReturnedVal);
-
- /** Retrieve value returned at a_StackPos, if it is a valid number. If not, a_ReturnedVal is unchanged */
- void GetReturn(int a_StackPos, int & a_ReturnedVal);
-
- /** Retrieve value returned at a_StackPos, if it is a valid number. If not, a_ReturnedVal is unchanged */
- void GetReturn(int a_StackPos, double & a_ReturnedVal);
-
/**
Calls the function that has been pushed onto the stack by PushFunction(),
with arguments pushed by PushXXX().
--
cgit v1.2.3
From 8f782885640a270bfe23843dff82367d28f9fb23 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Tue, 4 Mar 2014 22:17:23 +0100
Subject: Manually exported cCompositeChat modifiers.
This adds chaining support to them. Fixes #755.
---
src/Bindings/ManualBindings.cpp | 258 ++++++++++++++++++++++++++++++++++++++++
src/CompositeChat.h | 17 +--
2 files changed, 268 insertions(+), 7 deletions(-)
diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp
index fcdd728be..9fbc2e842 100644
--- a/src/Bindings/ManualBindings.cpp
+++ b/src/Bindings/ManualBindings.cpp
@@ -26,6 +26,7 @@
#include "md5/md5.h"
#include "../LineBlockTracer.h"
#include "../WorldStorage/SchematicFileSerializer.h"
+#include "../CompositeChat.h"
@@ -2511,6 +2512,253 @@ static int tolua_cBlockArea_SaveToSchematicFile(lua_State * tolua_S)
+static int tolua_cCompositeChat_AddRunCommandPart(lua_State * tolua_S)
+{
+ // function cCompositeChat:AddRunCommandPart(Message, Command, [Style])
+ // Exported manually to support call-chaining (return *this)
+
+ // Check params:
+ cLuaState L(tolua_S);
+ if (
+ !L.CheckParamUserType(1, "cCompositeChat") ||
+ !L.CheckParamString(2, 3)
+ )
+ {
+ return 0;
+ }
+ cCompositeChat * self = (cCompositeChat *)tolua_tousertype(tolua_S, 1, NULL);
+ if (self == NULL)
+ {
+ tolua_error(tolua_S, "invalid 'self' in function 'cCompositeChat:AddRunCommandPart'", NULL);
+ return 0;
+ }
+
+ // Add the part:
+ AString Text, Command, Style;
+ L.GetStackValue(2, Text);
+ L.GetStackValue(3, Command);
+ L.GetStackValue(4, Style);
+ self->AddRunCommandPart(Text, Command, Style);
+
+ // Cut away everything from the stack except for the cCompositeChat instance; return that:
+ lua_settop(L, 1);
+ return 1;
+}
+
+
+
+
+
+static int tolua_cCompositeChat_AddSuggestCommandPart(lua_State * tolua_S)
+{
+ // function cCompositeChat:AddSuggestCommandPart(Message, Command, [Style])
+ // Exported manually to support call-chaining (return *this)
+
+ // Check params:
+ cLuaState L(tolua_S);
+ if (
+ !L.CheckParamUserType(1, "cCompositeChat") ||
+ !L.CheckParamString(2, 3)
+ )
+ {
+ return 0;
+ }
+ cCompositeChat * self = (cCompositeChat *)tolua_tousertype(tolua_S, 1, NULL);
+ if (self == NULL)
+ {
+ tolua_error(tolua_S, "invalid 'self' in function 'cCompositeChat:AddSuggestCommandPart'", NULL);
+ return 0;
+ }
+
+ // Add the part:
+ AString Text, Command, Style;
+ L.GetStackValue(2, Text);
+ L.GetStackValue(3, Command);
+ L.GetStackValue(4, Style);
+ self->AddSuggestCommandPart(Text, Command, Style);
+
+ // Cut away everything from the stack except for the cCompositeChat instance; return that:
+ lua_settop(L, 1);
+ return 1;
+}
+
+
+
+
+
+static int tolua_cCompositeChat_AddTextPart(lua_State * tolua_S)
+{
+ // function cCompositeChat:AddTextPart(Message, [Style])
+ // Exported manually to support call-chaining (return *this)
+
+ // Check params:
+ cLuaState L(tolua_S);
+ if (
+ !L.CheckParamUserType(1, "cCompositeChat") ||
+ !L.CheckParamString(2)
+ )
+ {
+ return 0;
+ }
+ cCompositeChat * self = (cCompositeChat *)tolua_tousertype(tolua_S, 1, NULL);
+ if (self == NULL)
+ {
+ tolua_error(tolua_S, "invalid 'self' in function 'cCompositeChat:AddTextPart'", NULL);
+ return 0;
+ }
+
+ // Add the part:
+ AString Text, Style;
+ L.GetStackValue(2, Text);
+ L.GetStackValue(3, Style);
+ self->AddTextPart(Text, Style);
+
+ // Cut away everything from the stack except for the cCompositeChat instance; return that:
+ lua_settop(L, 1);
+ return 1;
+}
+
+
+
+
+
+static int tolua_cCompositeChat_AddUrlPart(lua_State * tolua_S)
+{
+ // function cCompositeChat:AddTextPart(Message, Url, [Style])
+ // Exported manually to support call-chaining (return *this)
+
+ // Check params:
+ cLuaState L(tolua_S);
+ if (
+ !L.CheckParamUserType(1, "cCompositeChat") ||
+ !L.CheckParamString(2, 3)
+ )
+ {
+ return 0;
+ }
+ cCompositeChat * self = (cCompositeChat *)tolua_tousertype(tolua_S, 1, NULL);
+ if (self == NULL)
+ {
+ tolua_error(tolua_S, "invalid 'self' in function 'cCompositeChat:AddUrlPart'", NULL);
+ return 0;
+ }
+
+ // Add the part:
+ AString Text, Url, Style;
+ L.GetStackValue(2, Text);
+ L.GetStackValue(3, Url);
+ L.GetStackValue(4, Style);
+ self->AddUrlPart(Text, Url, Style);
+
+ // Cut away everything from the stack except for the cCompositeChat instance; return that:
+ lua_settop(L, 1);
+ return 1;
+}
+
+
+
+
+
+static int tolua_cCompositeChat_ParseText(lua_State * tolua_S)
+{
+ // function cCompositeChat:ParseText(TextMessage)
+ // Exported manually to support call-chaining (return *this)
+
+ // Check params:
+ cLuaState L(tolua_S);
+ if (
+ !L.CheckParamUserType(1, "cCompositeChat") ||
+ !L.CheckParamString(2)
+ )
+ {
+ return 0;
+ }
+ cCompositeChat * self = (cCompositeChat *)tolua_tousertype(tolua_S, 1, NULL);
+ if (self == NULL)
+ {
+ tolua_error(tolua_S, "invalid 'self' in function 'cCompositeChat:ParseText'", NULL);
+ return 0;
+ }
+
+ // Parse the text:
+ AString Text;
+ L.GetStackValue(2, Text);
+ self->ParseText(Text);
+
+ // Cut away everything from the stack except for the cCompositeChat instance; return that:
+ lua_settop(L, 1);
+ return 1;
+}
+
+
+
+
+
+static int tolua_cCompositeChat_SetMessageType(lua_State * tolua_S)
+{
+ // function cCompositeChat:SetMessageType(MessageType)
+ // Exported manually to support call-chaining (return *this)
+
+ // Check params:
+ cLuaState L(tolua_S);
+ if (
+ !L.CheckParamUserType(1, "cCompositeChat") ||
+ !L.CheckParamNumber(2)
+ )
+ {
+ return 0;
+ }
+ cCompositeChat * self = (cCompositeChat *)tolua_tousertype(tolua_S, 1, NULL);
+ if (self == NULL)
+ {
+ tolua_error(tolua_S, "invalid 'self' in function 'cCompositeChat:SetMessageType'", NULL);
+ return 0;
+ }
+
+ // Set the type:
+ int MessageType;
+ L.GetStackValue(1, MessageType);
+ self->SetMessageType((eMessageType)MessageType);
+
+ // Cut away everything from the stack except for the cCompositeChat instance; return that:
+ lua_settop(L, 1);
+ return 1;
+}
+
+
+
+
+
+static int tolua_cCompositeChat_UnderlineUrls(lua_State * tolua_S)
+{
+ // function cCompositeChat:UnderlineUrls()
+ // Exported manually to support call-chaining (return *this)
+
+ // Check params:
+ cLuaState L(tolua_S);
+ if (!L.CheckParamUserType(1, "cCompositeChat"))
+ {
+ return 0;
+ }
+ cCompositeChat * self = (cCompositeChat *)tolua_tousertype(tolua_S, 1, NULL);
+ if (self == NULL)
+ {
+ tolua_error(tolua_S, "invalid 'self' in function 'cCompositeChat:UnderlineUrls'", NULL);
+ return 0;
+ }
+
+ // Call the processing
+ self->UnderlineUrls();
+
+ // Cut away everything from the stack except for the cCompositeChat instance; return that:
+ lua_settop(L, 1);
+ return 1;
+}
+
+
+
+
+
void ManualBindings::Bind(lua_State * tolua_S)
{
tolua_beginmodule(tolua_S, NULL);
@@ -2535,6 +2783,16 @@ void ManualBindings::Bind(lua_State * tolua_S)
tolua_function(tolua_S, "SaveToSchematicFile", tolua_cBlockArea_SaveToSchematicFile);
tolua_endmodule(tolua_S);
+ tolua_beginmodule(tolua_S, "cCompositeChat");
+ tolua_function(tolua_S, "AddRunCommandPart", tolua_cCompositeChat_AddRunCommandPart);
+ tolua_function(tolua_S, "AddSuggestCommandPart", tolua_cCompositeChat_AddSuggestCommandPart);
+ tolua_function(tolua_S, "AddTextPart", tolua_cCompositeChat_AddTextPart);
+ tolua_function(tolua_S, "AddUrlPart", tolua_cCompositeChat_AddUrlPart);
+ tolua_function(tolua_S, "ParseText", tolua_cCompositeChat_ParseText);
+ tolua_function(tolua_S, "SetMessageType", tolua_cCompositeChat_SetMessageType);
+ tolua_function(tolua_S, "UnderlineUrls", tolua_cCompositeChat_UnderlineUrls);
+ tolua_endmodule(tolua_S);
+
tolua_beginmodule(tolua_S, "cHopperEntity");
tolua_function(tolua_S, "GetOutputBlockPos", tolua_cHopperEntity_GetOutputBlockPos);
tolua_endmodule(tolua_S);
diff --git a/src/CompositeChat.h b/src/CompositeChat.h
index 51600da4f..27319490d 100644
--- a/src/CompositeChat.h
+++ b/src/CompositeChat.h
@@ -124,14 +124,15 @@ public:
/** Removes all parts from the object. */
void Clear(void);
+ // tolua_end
+
+ // The following are exported in ManualBindings in order to support chaining - they return *this in Lua (#755)
+
/** Adds a plain text part, with optional style.
The default style is plain white text. */
void AddTextPart(const AString & a_Message, const AString & a_Style = "");
- // tolua_end
-
- /** Adds a part that is translated client-side, with the formatting parameters and optional style.
- Exported in ManualBindings due to AStringVector usage - Lua uses an array-table of strings. */
+ /** Adds a part that is translated client-side, with the formatting parameters and optional style. */
void AddClientTranslatedPart(const AString & a_TranslationID, const AStringVector & a_Parameters, const AString & a_Style = "");
// tolua_begin
@@ -155,12 +156,14 @@ public:
/** Sets the message type, which is indicated by prefixes added to the message when serializing. */
void SetMessageType(eMessageType a_MessageType);
- /** Returns the message type set previously by SetMessageType(). */
- eMessageType GetMessageType(void) const { return m_MessageType; }
-
/** Adds the "underline" style to each part that is an URL. */
void UnderlineUrls(void);
+ // tolua_begin
+
+ /** Returns the message type set previously by SetMessageType(). */
+ eMessageType GetMessageType(void) const { return m_MessageType; }
+
// tolua_end
const cParts & GetParts(void) const { return m_Parts; }
--
cgit v1.2.3
From ab30d94b2fed330bb487e30960d82c0bedff37b4 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Tue, 4 Mar 2014 22:17:47 +0100
Subject: Debuggers: Added simple test for cCompositeChat.
---
MCServer/Plugins/Debuggers/Debuggers.lua | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/MCServer/Plugins/Debuggers/Debuggers.lua b/MCServer/Plugins/Debuggers/Debuggers.lua
index 66894d835..329a652cd 100644
--- a/MCServer/Plugins/Debuggers/Debuggers.lua
+++ b/MCServer/Plugins/Debuggers/Debuggers.lua
@@ -30,6 +30,7 @@ function Initialize(Plugin)
PM:AddHook(cPluginManager.HOOK_CHUNK_GENERATED, OnChunkGenerated);
PM:AddHook(cPluginManager.HOOK_PLUGINS_LOADED, OnPluginsLoaded);
PM:AddHook(cPluginManager.HOOK_PLUGIN_MESSAGE, OnPluginMessage);
+ PM:AddHook(cPluginManager.HOOK_PLAYER_JOINED, OnPlayerJoined)
PM:BindCommand("/le", "debuggers", HandleListEntitiesCmd, "- Shows a list of all the loaded entities");
PM:BindCommand("/ke", "debuggers", HandleKillEntitiesCmd, "- Kills all the loaded entities");
@@ -1258,3 +1259,17 @@ end
+
+function OnPlayerJoined(a_Player)
+ -- Test composite chat chaining:
+ a_Player:SendMessage(cCompositeChat()
+ :AddTextPart("Hello, ")
+ :AddUrlPart(a_Player:GetName(), "www.mc-server.org", "u@2")
+ :AddSuggestCommandPart(", and welcome.", "/help", "u")
+ :AddRunCommandPart(" SetDay", "/time set 0")
+ )
+end
+
+
+
+
--
cgit v1.2.3
From a845c051b8df10c6eaf1f68d3c37abe71425e9d6 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Tue, 4 Mar 2014 22:25:31 +0100
Subject: Fixed some gcc warnings in Defines.h.
---
src/Defines.h | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/Defines.h b/src/Defines.h
index 018ecb1d3..6ab2274a4 100644
--- a/src/Defines.h
+++ b/src/Defines.h
@@ -235,8 +235,8 @@ inline eBlockFace MirrorBlockFaceY(eBlockFace a_BlockFace)
case BLOCK_FACE_XP: return BLOCK_FACE_XM;
case BLOCK_FACE_ZM: return BLOCK_FACE_ZP;
case BLOCK_FACE_ZP: return BLOCK_FACE_ZM;
+ default: return a_BlockFace;
}
- return a_BlockFace;
}
@@ -252,8 +252,8 @@ inline eBlockFace RotateBlockFaceCCW(eBlockFace a_BlockFace)
case BLOCK_FACE_XP: return BLOCK_FACE_ZM;
case BLOCK_FACE_ZM: return BLOCK_FACE_XM;
case BLOCK_FACE_ZP: return BLOCK_FACE_XP;
+ default: return a_BlockFace;
}
- return a_BlockFace;
}
@@ -268,8 +268,8 @@ inline eBlockFace RotateBlockFaceCW(eBlockFace a_BlockFace)
case BLOCK_FACE_XP: return BLOCK_FACE_ZP;
case BLOCK_FACE_ZM: return BLOCK_FACE_XP;
case BLOCK_FACE_ZP: return BLOCK_FACE_XM;
+ default: return a_BlockFace;
}
- return a_BlockFace;
}
--
cgit v1.2.3
From 1ea17c0a75b84d5f4070c57ad2a7d6cbb4e8b79b Mon Sep 17 00:00:00 2001
From: andrew
Date: Wed, 5 Mar 2014 15:54:38 +0200
Subject: Implemented vanilla-like fluid simulator
---
src/Scoreboard.cpp | 2 +-
src/Simulator/FloodyFluidSimulator.cpp | 23 +++--
src/Simulator/FloodyFluidSimulator.h | 12 ++-
src/Simulator/VanillaFluidSimulator.cpp | 150 ++++++++++++++++++++++++++++++++
src/Simulator/VanillaFluidSimulator.h | 42 +++++++++
src/World.cpp | 26 ++++--
6 files changed, 238 insertions(+), 17 deletions(-)
create mode 100644 src/Simulator/VanillaFluidSimulator.cpp
create mode 100644 src/Simulator/VanillaFluidSimulator.h
diff --git a/src/Scoreboard.cpp b/src/Scoreboard.cpp
index c1da27086..8088e624b 100644
--- a/src/Scoreboard.cpp
+++ b/src/Scoreboard.cpp
@@ -506,7 +506,7 @@ bool cScoreboard::ForEachObjective(cObjectiveCallback& a_Callback)
bool cScoreboard::ForEachTeam(cTeamCallback& a_Callback)
{
- cCSLock Lock(m_CSObjectives);
+ cCSLock Lock(m_CSTeams);
for (cTeamMap::iterator it = m_Teams.begin(); it != m_Teams.end(); ++it)
{
diff --git a/src/Simulator/FloodyFluidSimulator.cpp b/src/Simulator/FloodyFluidSimulator.cpp
index 95182345c..b1ac734d7 100644
--- a/src/Simulator/FloodyFluidSimulator.cpp
+++ b/src/Simulator/FloodyFluidSimulator.cpp
@@ -86,7 +86,12 @@ void cFloodyFluidSimulator::SimulateBlock(cChunk * a_Chunk, int a_RelX, int a_Re
{
// Spread only down, possibly washing away what's there or turning lava to stone / cobble / obsidian:
SpreadToNeighbor(a_Chunk, a_RelX, a_RelY - 1, a_RelZ, 8);
- SpreadFurther = false;
+
+ // Source blocks spread both downwards and sideways
+ if (MyMeta != 0)
+ {
+ SpreadFurther = false;
+ }
}
// If source creation is on, check for it here:
else if (
@@ -105,10 +110,7 @@ void cFloodyFluidSimulator::SimulateBlock(cChunk * a_Chunk, int a_RelX, int a_Re
if (SpreadFurther && (NewMeta < 8))
{
// Spread to the neighbors:
- SpreadToNeighbor(a_Chunk, a_RelX - 1, a_RelY, a_RelZ, NewMeta);
- SpreadToNeighbor(a_Chunk, a_RelX + 1, a_RelY, a_RelZ, NewMeta);
- SpreadToNeighbor(a_Chunk, a_RelX, a_RelY, a_RelZ - 1, NewMeta);
- SpreadToNeighbor(a_Chunk, a_RelX, a_RelY, a_RelZ + 1, NewMeta);
+ Spread(a_Chunk, a_RelX, a_RelY, a_RelZ, NewMeta);
}
// Mark as processed:
@@ -119,6 +121,17 @@ void cFloodyFluidSimulator::SimulateBlock(cChunk * a_Chunk, int a_RelX, int a_Re
+void cFloodyFluidSimulator::Spread(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_NewMeta)
+{
+ SpreadToNeighbor(a_Chunk, a_RelX - 1, a_RelY, a_RelZ, a_NewMeta);
+ SpreadToNeighbor(a_Chunk, a_RelX + 1, a_RelY, a_RelZ, a_NewMeta);
+ SpreadToNeighbor(a_Chunk, a_RelX, a_RelY, a_RelZ - 1, a_NewMeta);
+ SpreadToNeighbor(a_Chunk, a_RelX, a_RelY, a_RelZ + 1, a_NewMeta);
+}
+
+
+
+
bool cFloodyFluidSimulator::CheckTributaries(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_MyMeta)
{
// If we have a section above, check if there's fluid above this block that would feed it:
diff --git a/src/Simulator/FloodyFluidSimulator.h b/src/Simulator/FloodyFluidSimulator.h
index c4af2e246..5fd91b2b1 100644
--- a/src/Simulator/FloodyFluidSimulator.h
+++ b/src/Simulator/FloodyFluidSimulator.h
@@ -38,14 +38,20 @@ protected:
// cDelayedFluidSimulator overrides:
virtual void SimulateBlock(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ) override;
- /// Checks tributaries, if not fed, decreases the block's level and returns true
+ /** Checks tributaries, if not fed, decreases the block's level and returns true. */
bool CheckTributaries(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_MyMeta);
- /// Spreads into the specified block, if the blocktype there allows. a_Area is for checking.
+ /** Spreads into the specified block, if the blocktype there allows. a_Area is for checking. */
void SpreadToNeighbor(cChunk * a_NearChunk, int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_NewMeta);
- /// Checks if there are enough neighbors to create a source at the coords specified; turns into source and returns true if so
+ /** Checks if there are enough neighbors to create a source at the coords specified; turns into source and returns true if so. */
bool CheckNeighborsForSource(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ);
+
+ /** Spread water to neighbors.
+ *
+ * May be overridden to provide more sophisticated algorithms.
+ */
+ virtual void Spread(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_NewMeta);
} ;
diff --git a/src/Simulator/VanillaFluidSimulator.cpp b/src/Simulator/VanillaFluidSimulator.cpp
new file mode 100644
index 000000000..5308d162b
--- /dev/null
+++ b/src/Simulator/VanillaFluidSimulator.cpp
@@ -0,0 +1,150 @@
+
+// VanillaFluidSimulator.cpp
+
+#include "Globals.h"
+
+#include "VanillaFluidSimulator.h"
+#include "../World.h"
+#include "../Chunk.h"
+#include "../BlockArea.h"
+#include "../Blocks/BlockHandler.h"
+#include "../BlockInServerPluginInterface.h"
+
+
+
+
+
+static const int InfiniteCost = 100;
+
+
+
+
+
+cVanillaFluidSimulator::cVanillaFluidSimulator(
+ cWorld & a_World,
+ BLOCKTYPE a_Fluid,
+ BLOCKTYPE a_StationaryFluid,
+ NIBBLETYPE a_Falloff,
+ int a_TickDelay,
+ int a_NumNeighborsForSource
+) : super(a_World, a_Fluid, a_StationaryFluid, a_Falloff, a_TickDelay, a_NumNeighborsForSource)
+{
+}
+
+
+
+
+
+void cVanillaFluidSimulator::Spread(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_NewMeta)
+{
+ int Cost[4];
+ Cost[0] = CalculateFlowCost(a_Chunk, a_RelX + 1, a_RelY, a_RelZ, X_PLUS);
+ Cost[1] = CalculateFlowCost(a_Chunk, a_RelX - 1, a_RelY, a_RelZ, X_MINUS);
+ Cost[2] = CalculateFlowCost(a_Chunk, a_RelX, a_RelY, a_RelZ + 1, Z_PLUS);
+ Cost[3] = CalculateFlowCost(a_Chunk, a_RelX, a_RelY, a_RelZ - 1, Z_MINUS);
+
+ int MinCost = InfiniteCost;
+ for (unsigned int i = 0; i < ARRAYCOUNT(Cost); ++i)
+ {
+ if (Cost[i] < MinCost)
+ {
+ MinCost = Cost[i];
+ }
+ }
+
+ if (Cost[0] == MinCost)
+ {
+ SpreadToNeighbor(a_Chunk, a_RelX + 1, a_RelY, a_RelZ, a_NewMeta);
+ }
+ if (Cost[1] == MinCost)
+ {
+ SpreadToNeighbor(a_Chunk, a_RelX - 1, a_RelY, a_RelZ, a_NewMeta);
+ }
+ if (Cost[2] == MinCost)
+ {
+ SpreadToNeighbor(a_Chunk, a_RelX, a_RelY, a_RelZ + 1, a_NewMeta);
+ }
+ if (Cost[3] == MinCost)
+ {
+ SpreadToNeighbor(a_Chunk, a_RelX, a_RelY, a_RelZ - 1, a_NewMeta);
+ }
+}
+
+
+
+
+
+int cVanillaFluidSimulator::CalculateFlowCost(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ, Direction a_Dir, unsigned a_Iteration)
+{
+ int Cost = InfiniteCost;
+
+ BLOCKTYPE BlockType;
+ NIBBLETYPE BlockMeta;
+
+ // Check if block is passable
+ if (!a_Chunk->UnboundedRelGetBlock(a_RelX, a_RelY, a_RelZ, BlockType, BlockMeta))
+ {
+ return Cost;
+ }
+ if (!IsPassableForFluid(BlockType))
+ {
+ return Cost;
+ }
+
+ // Check if block below is passable
+ if (!a_Chunk->UnboundedRelGetBlock(a_RelX, a_RelY - 1, a_RelZ, BlockType, BlockMeta))
+ {
+ return Cost;
+ }
+ if (IsPassableForFluid(BlockType))
+ {
+ // Path found, exit
+ return a_Iteration;
+ }
+
+ // 5 blocks away, bail out
+ if (a_Iteration > 3)
+ {
+ return Cost;
+ }
+
+ // Recurse
+ if (a_Dir != X_MINUS)
+ {
+ int NextCost = CalculateFlowCost(a_Chunk, a_RelX + 1, a_RelY, a_RelZ, X_PLUS, a_Iteration + 1);
+ if (NextCost < Cost)
+ {
+ Cost = NextCost;
+ }
+ }
+ if (a_Dir != X_PLUS)
+ {
+ int NextCost = CalculateFlowCost(a_Chunk, a_RelX - 1, a_RelY, a_RelZ, X_MINUS, a_Iteration + 1);
+ if (NextCost < Cost)
+ {
+ Cost = NextCost;
+ }
+ }
+ if (a_Dir != Z_MINUS)
+ {
+ int NextCost = CalculateFlowCost(a_Chunk, a_RelX, a_RelY, a_RelZ + 1, Z_PLUS, a_Iteration + 1);
+ if (NextCost < Cost)
+ {
+ Cost = NextCost;
+ }
+ }
+ if (a_Dir != Z_PLUS)
+ {
+ int NextCost = CalculateFlowCost(a_Chunk, a_RelX, a_RelY, a_RelZ - 1, Z_MINUS, a_Iteration + 1);
+ if (NextCost < Cost)
+ {
+ Cost = NextCost;
+ }
+ }
+
+ return Cost;
+}
+
+
+
+
diff --git a/src/Simulator/VanillaFluidSimulator.h b/src/Simulator/VanillaFluidSimulator.h
new file mode 100644
index 000000000..a9ea98b5a
--- /dev/null
+++ b/src/Simulator/VanillaFluidSimulator.h
@@ -0,0 +1,42 @@
+
+// VanillaFluidSimulator.h
+
+
+
+
+
+#pragma once
+
+#include "FloodyFluidSimulator.h"
+
+
+
+
+
+// fwd:
+class cBlockArea;
+
+
+
+
+
+class cVanillaFluidSimulator :
+ public cFloodyFluidSimulator
+{
+ typedef cFloodyFluidSimulator super;
+
+public:
+ cVanillaFluidSimulator(cWorld & a_World, BLOCKTYPE a_Fluid, BLOCKTYPE a_StationaryFluid, NIBBLETYPE a_Falloff, int a_TickDelay, int a_NumNeighborsForSource);
+
+protected:
+ // cFloodyFluidSimulator overrides:
+ virtual void Spread(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_NewMeta) override;
+
+ /** Recursively calculates the minimum number of blocks needed to descend a level. */
+ int CalculateFlowCost(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ, Direction a_Dir, unsigned a_Iteration = 0);
+
+} ;
+
+
+
+
diff --git a/src/World.cpp b/src/World.cpp
index 2dfa85d64..01ba5e503 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -34,6 +34,7 @@
#include "Simulator/NoopRedstoneSimulator.h"
#include "Simulator/SandSimulator.h"
#include "Simulator/IncrementalRedstoneSimulator.h"
+#include "Simulator/VanillaFluidSimulator.h"
#include "Simulator/VaporizeFluidSimulator.h"
// Mobs:
@@ -2987,8 +2988,8 @@ cFluidSimulator * cWorld::InitializeFluidSimulator(cIniFile & a_IniFile, const c
AString SimulatorName = a_IniFile.GetValueSet("Physics", SimulatorNameKey, "");
if (SimulatorName.empty())
{
- LOGWARNING("[Physics] %s not present or empty in %s, using the default of \"Floody\".", SimulatorNameKey.c_str(), GetIniFileName().c_str());
- SimulatorName = "Floody";
+ LOGWARNING("[Physics] %s not present or empty in %s, using the default of \"Vanilla\".", SimulatorNameKey.c_str(), GetIniFileName().c_str());
+ SimulatorName = "Vanilla";
}
cFluidSimulator * res = NULL;
@@ -3012,15 +3013,24 @@ cFluidSimulator * cWorld::InitializeFluidSimulator(cIniFile & a_IniFile, const c
}
else
{
- if (NoCaseCompare(SimulatorName, "floody") != 0)
- {
- // The simulator name doesn't match anything we have, issue a warning:
- LOGWARNING("%s [Physics]:%s specifies an unknown simulator, using the default \"Floody\".", GetIniFileName().c_str(), SimulatorNameKey.c_str());
- }
int Falloff = a_IniFile.GetValueSetI(SimulatorSectionName, "Falloff", IsWater ? 1 : 2);
int TickDelay = a_IniFile.GetValueSetI(SimulatorSectionName, "TickDelay", IsWater ? 5 : 30);
int NumNeighborsForSource = a_IniFile.GetValueSetI(SimulatorSectionName, "NumNeighborsForSource", IsWater ? 2 : -1);
- res = new cFloodyFluidSimulator(*this, a_SimulateBlock, a_StationaryBlock, Falloff, TickDelay, NumNeighborsForSource);
+
+ if (NoCaseCompare(SimulatorName, "floody") == 0)
+ {
+ res = new cFloodyFluidSimulator(*this, a_SimulateBlock, a_StationaryBlock, Falloff, TickDelay, NumNeighborsForSource);
+ }
+ else if (NoCaseCompare(SimulatorName, "vanilla") == 0)
+ {
+ res = new cVanillaFluidSimulator(*this, a_SimulateBlock, a_StationaryBlock, Falloff, TickDelay, NumNeighborsForSource);
+ }
+ else
+ {
+ // The simulator name doesn't match anything we have, issue a warning:
+ LOGWARNING("%s [Physics]:%s specifies an unknown simulator, using the default \"Vanilla\".", GetIniFileName().c_str(), SimulatorNameKey.c_str());
+ res = new cVanillaFluidSimulator(*this, a_SimulateBlock, a_StationaryBlock, Falloff, TickDelay, NumNeighborsForSource);
+ }
}
m_SimulatorManager->RegisterSimulator(res, Rate);
--
cgit v1.2.3
From d4a5b16c52c41da59d2fe3405570653521e5d36e Mon Sep 17 00:00:00 2001
From: Howaner
Date: Wed, 5 Mar 2014 15:10:20 +0100
Subject: Add data backsending, when the Client interacts a Block and the
Interact is cancelled.
---
src/Blocks/BlockComparator.h | 6 ++++++
src/Blocks/BlockDoor.cpp | 21 +++++++++++++++++++++
src/Blocks/BlockDoor.h | 1 +
src/Blocks/BlockFenceGate.h | 6 ++++++
src/Blocks/BlockHandler.cpp | 10 ++++++++++
src/Blocks/BlockHandler.h | 5 ++++-
src/Blocks/BlockRedstoneRepeater.h | 8 +++++++-
src/Blocks/BlockTNT.h | 32 ++++++++++++++++++++++++++++++++
src/Blocks/BlockTrapdoor.h | 5 +++++
src/ClientHandle.cpp | 14 ++++++++++----
10 files changed, 102 insertions(+), 6 deletions(-)
create mode 100644 src/Blocks/BlockTNT.h
diff --git a/src/Blocks/BlockComparator.h b/src/Blocks/BlockComparator.h
index aba390d9d..b0ac75aaf 100644
--- a/src/Blocks/BlockComparator.h
+++ b/src/Blocks/BlockComparator.h
@@ -26,6 +26,12 @@ public:
}
+ virtual void OnCancelRightClick(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace) override
+ {
+ a_Player->GetWorld()->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, a_Player);
+ }
+
+
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
// Reset meta to 0
diff --git a/src/Blocks/BlockDoor.cpp b/src/Blocks/BlockDoor.cpp
index 2ff5c1c37..6c51feab3 100644
--- a/src/Blocks/BlockDoor.cpp
+++ b/src/Blocks/BlockDoor.cpp
@@ -55,6 +55,27 @@ void cBlockDoorHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterfac
+void cBlockDoorHandler::OnCancelRightClick(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace)
+{
+ NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ);
+ a_Player->GetClientHandle()->SendBlockChange(a_BlockX, a_BlockY, a_BlockZ, m_BlockType, Meta);
+
+ if (Meta & 8)
+ {
+ // Current block is top of the door
+ a_Player->GetWorld()->SendBlockTo(a_BlockX, a_BlockY - 1, a_BlockZ, a_Player);
+ }
+ else
+ {
+ // Current block is bottom of the door
+ a_Player->GetWorld()->SendBlockTo(a_BlockX, a_BlockY + 1, a_BlockZ, a_Player);
+ }
+}
+
+
+
+
+
void cBlockDoorHandler::OnPlacedByPlayer(
cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player,
int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace,
diff --git a/src/Blocks/BlockDoor.h b/src/Blocks/BlockDoor.h
index ef0dbb787..68be2c658 100644
--- a/src/Blocks/BlockDoor.h
+++ b/src/Blocks/BlockDoor.h
@@ -16,6 +16,7 @@ public:
virtual void OnDestroyed(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ) override;
virtual void OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override;
+ virtual void OnCancelRightClick(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace) override;
virtual const char * GetStepSound(void) override;
diff --git a/src/Blocks/BlockFenceGate.h b/src/Blocks/BlockFenceGate.h
index fb984f345..a14510724 100644
--- a/src/Blocks/BlockFenceGate.h
+++ b/src/Blocks/BlockFenceGate.h
@@ -48,6 +48,12 @@ public:
}
+ virtual void OnCancelRightClick(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace) override
+ {
+ a_Player->GetWorld()->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, a_Player);
+ }
+
+
virtual bool IsUseable(void) override
{
return true;
diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp
index 052f88f7a..c5165986c 100644
--- a/src/Blocks/BlockHandler.cpp
+++ b/src/Blocks/BlockHandler.cpp
@@ -57,6 +57,7 @@
#include "BlockRedstoneLamp.h"
#include "BlockRedstoneRepeater.h"
#include "BlockRedstoneTorch.h"
+#include "BlockTNT.h"
#include "BlockSand.h"
#include "BlockSapling.h"
#include "BlockSideways.h"
@@ -185,6 +186,7 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType)
case E_BLOCK_TALL_GRASS: return new cBlockTallGrassHandler (a_BlockType);
case E_BLOCK_TORCH: return new cBlockTorchHandler (a_BlockType);
case E_BLOCK_TRAPDOOR: return new cBlockTrapdoorHandler (a_BlockType);
+ case E_BLOCK_TNT: return new cBlockTNTHandler (a_BlockType);
case E_BLOCK_VINES: return new cBlockVineHandler (a_BlockType);
case E_BLOCK_WALLSIGN: return new cBlockSignHandler (a_BlockType);
case E_BLOCK_WATER: return new cBlockFluidHandler (a_BlockType);
@@ -320,6 +322,14 @@ void cBlockHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface &
+void cBlockHandler::OnCancelRightClick(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer *a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace)
+{
+}
+
+
+
+
+
void cBlockHandler::ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta)
{
// Setting the meta to a_BlockMeta keeps most textures. The few other blocks have to override this.
diff --git a/src/Blocks/BlockHandler.h b/src/Blocks/BlockHandler.h
index c46a46045..fbb36d96a 100644
--- a/src/Blocks/BlockHandler.h
+++ b/src/Blocks/BlockHandler.h
@@ -69,6 +69,9 @@ public:
/// Called if the user right clicks the block and the block is useable
virtual void OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ);
+ /** Called when a Right Click to this Block is cancelled */
+ virtual void OnCancelRightClick(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace);
+
/// Called when the item is mined to convert it into pickups. Pickups may specify multiple items. Appends items to a_Pickups, preserves its original contents
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta);
@@ -80,7 +83,7 @@ public:
/// Checks if the block can stay at the specified relative coords in the chunk
virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk);
-
+
/** Checks if the block can be placed at this point.
Default: CanBeAt(...)
NOTE: This call doesn't actually place the block
diff --git a/src/Blocks/BlockRedstoneRepeater.h b/src/Blocks/BlockRedstoneRepeater.h
index eb0918acf..81e3f2b8f 100644
--- a/src/Blocks/BlockRedstoneRepeater.h
+++ b/src/Blocks/BlockRedstoneRepeater.h
@@ -29,7 +29,7 @@ public:
a_BlockMeta = RepeaterRotationToMetaData(a_Player->GetYaw());
return true;
}
-
+
virtual void OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override
{
@@ -37,6 +37,12 @@ public:
}
+ virtual void OnCancelRightClick(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace) override
+ {
+ a_Player->GetWorld()->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, a_Player);
+ }
+
+
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
// Reset meta to 0
diff --git a/src/Blocks/BlockTNT.h b/src/Blocks/BlockTNT.h
new file mode 100644
index 000000000..a9044d65e
--- /dev/null
+++ b/src/Blocks/BlockTNT.h
@@ -0,0 +1,32 @@
+
+#pragma once
+
+#include "BlockHandler.h"
+
+
+
+
+
+class cBlockTNTHandler :
+ public cBlockHandler
+{
+public:
+ cBlockTNTHandler(BLOCKTYPE a_BlockType)
+ : cBlockHandler(a_BlockType)
+ {
+ }
+
+ virtual const char * GetStepSound(void) override
+ {
+ return "step.wood";
+ }
+
+ virtual void OnCancelRightClick(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace) override
+ {
+ a_Player->GetWorld()->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, a_Player);
+ }
+};
+
+
+
+
diff --git a/src/Blocks/BlockTrapdoor.h b/src/Blocks/BlockTrapdoor.h
index a28861e69..ffeebd647 100644
--- a/src/Blocks/BlockTrapdoor.h
+++ b/src/Blocks/BlockTrapdoor.h
@@ -42,6 +42,11 @@ public:
World->BroadcastSoundParticleEffect(1003, a_BlockX, a_BlockY, a_BlockZ, 0, a_Player->GetClientHandle());
}
+ virtual void OnCancelRightClick(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace) override
+ {
+ a_Player->GetWorld()->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, a_Player);
+ }
+
virtual bool GetPlacementBlockTypeMeta(
cChunkInterface & a_ChunkInterface, cPlayer * a_Player,
int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace,
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index 6982a6227..870568cdf 100644
--- a/src/ClientHandle.cpp
+++ b/src/ClientHandle.cpp
@@ -920,14 +920,22 @@ void cClientHandle::HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, e
a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, ItemToFullString(a_HeldItem).c_str()
);
+ cWorld * World = m_Player->GetWorld();
+
cPluginManager * PlgMgr = cRoot::Get()->GetPluginManager();
if (PlgMgr->CallHookPlayerRightClick(*m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ))
{
// A plugin doesn't agree with the action, replace the block on the client and quit:
+ cChunkInterface ChunkInterface(World->GetChunkMap());
+ BLOCKTYPE BlockType = World->GetBlock(a_BlockX, a_BlockY, a_BlockZ);
+ cBlockHandler * BlockHandler = cBlockInfo::GetHandler(BlockType);
+ BlockHandler->OnCancelRightClick(ChunkInterface, *World, m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace);
+
if (a_BlockFace > -1)
{
AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace);
- m_Player->GetWorld()->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, m_Player);
+ World->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, m_Player);
+ World->SendBlockTo(a_BlockX, a_BlockY + 1, a_BlockZ, m_Player); //2 block high things
}
return;
}
@@ -953,12 +961,10 @@ void cClientHandle::HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, e
if (a_BlockFace > -1)
{
AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace);
- m_Player->GetWorld()->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, m_Player);
+ World->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, m_Player);
}
return;
}
-
- cWorld * World = m_Player->GetWorld();
BLOCKTYPE BlockType;
NIBBLETYPE BlockMeta;
--
cgit v1.2.3
From ee1ba3e0b094ce80965eb2f1dd599fca6ff6736c Mon Sep 17 00:00:00 2001
From: Howaner
Date: Wed, 5 Mar 2014 15:14:20 +0100
Subject: Set tnt step sound to step.grass
---
src/Blocks/BlockTNT.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/Blocks/BlockTNT.h b/src/Blocks/BlockTNT.h
index a9044d65e..f5cdecb9a 100644
--- a/src/Blocks/BlockTNT.h
+++ b/src/Blocks/BlockTNT.h
@@ -18,7 +18,7 @@ public:
virtual const char * GetStepSound(void) override
{
- return "step.wood";
+ return "step.grass";
}
virtual void OnCancelRightClick(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace) override
--
cgit v1.2.3
From 86615428cd3d967c8bd73628fe8946405060d24c Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Wed, 5 Mar 2014 18:28:42 +0100
Subject: APIDump: Ignoring classes by exact match.
"cCompositeChat" was ignored because it matched "os".
---
MCServer/Plugins/APIDump/APIDesc.lua | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua
index 0b6f33b37..1d30ea72d 100644
--- a/MCServer/Plugins/APIDump/APIDesc.lua
+++ b/MCServer/Plugins/APIDump/APIDesc.lua
@@ -2701,16 +2701,16 @@ end
IgnoreClasses =
{
- "coroutine",
- "debug",
- "io",
- "math",
- "package",
- "os",
- "string",
- "table",
- "g_Stats",
- "g_TrackedPages",
+ "^coroutine$",
+ "^debug$",
+ "^io$",
+ "^math$",
+ "^package$",
+ "^os$",
+ "^string$",
+ "^table$",
+ "^g_Stats$",
+ "^g_TrackedPages$",
},
IgnoreFunctions =
--
cgit v1.2.3
From 036608c6453857e7faf3b32f05fa5d9f62b93fa0 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Wed, 5 Mar 2014 18:56:32 +0100
Subject: APIDump: Documented the cCompositeChat class.
---
MCServer/Plugins/APIDump/APIDesc.lua | 52 ++++++++++++++++++++++++++++++++++++
1 file changed, 52 insertions(+)
diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua
index 1d30ea72d..94cdd0063 100644
--- a/MCServer/Plugins/APIDump/APIDesc.lua
+++ b/MCServer/Plugins/APIDump/APIDesc.lua
@@ -483,6 +483,58 @@ end
},
}, -- cClientHandle
+ cCompositeChat =
+ {
+ Desc = [[
+ Encapsulates a chat message that can contain various formatting, URLs, commands executed on click
+ and commands suggested on click. The chat message can be sent by the regular chat-sending functions,
+ {{cPlayer}}:SendMessage(), {{cWorld}}:BroadcastChat() and {{cRoot}}:BroadcastChat().
+
+ Note that most of the functions in this class are so-called modifiers - they modify the object and
+ then return the object itself, so that they can be chained one after another.
+ ]],
+ Functions =
+ {
+ constructor =
+ {
+ { Params = "", Return = "", Notes = "Creates an empty chat message" },
+ { Params = "Text", Return = "", Notes = "Creates a chat message containing the specified text, parsed by the ParseText() function. This allows easy migration from old chat messages." },
+ },
+ AddRunCommandPart = { Params = "Text, Command, [Style]", Return = "self", Notes = "Adds a text which, when clicked, runs the specified command. Chaining." },
+ AddSuggestCommandPart = { Params = "Text, Command, [Style]", Return = "self", Notes = "Adds a text which, when clicked, puts the specified command into the player's chat input area. Chaining." },
+ AddTextPart = { Params = "Text, [Style]", Return = "self", Notes = "Adds a regular text. Chaining." },
+ AddUrlPart = { Params = "Text, Url, [Style]", Return = "self", Notes = "Adds a text which, when clicked, opens up a browser at the specified URL. Chaining." },
+ Clear = { Params = "", Return = "", Notes = "Removes all parts from this object" },
+ GetMessageType = { Params = "", Return = "MessageType", Notes = "Returns the MessageType (mtXXX constant) that is associated with this message. When sent to a player, the message will be formatted according to this message type and the player's settings (adding \"[INFO]\" prefix etc.)" },
+ ParseText = { Params = "Text", Return = "self", Notes = "Adds text, while recognizing http and https URLs and old-style formatting codes (\"@2\"). Chaining." },
+ SetMessageType = { Params = "MessageType", Return = "self", Notes = "Sets the MessageType (mtXXX constant) that is associated with this message. When sent to a player, the message will be formatted according to this message type and the player's settings (adding \"[INFO]\" prefix etc.) Chaining." },
+ UnderlineUrls = { Params = "", Return = "self", Notes = "Makes all URL parts contained in the message underlined. Doesn't affect parts added in the future. Chaining." },
+ },
+
+ AdditionalInfo =
+ {
+ {
+ Header = "Chaining example",
+ Contents = [[
+ Sending a chat message that is composed of multiple different parts has been made easy thanks to
+ chaining. Consider the following example that shows how a message containing all kinds of parts
+ is sent (adapted from the Debuggers plugin):
+
+function OnPlayerJoined(a_Player)
+ -- Send an example composite chat message to the player:
+ a_Player:SendMessage(cCompositeChat()
+ :AddTextPart("Hello, ")
+ :AddUrlPart(a_Player:GetName(), "www.mc-server.org", "u@2") -- Colored underlined link
+ :AddSuggestCommandPart(", and welcome.", "/help", "u") -- Underlined suggest-command
+ :AddRunCommandPart(" SetDay", "/time set 0") -- Regular text that will execute command when clicked
+ :SetMessageType(mtJoin) -- It is a join-message
+ )
+end
+ ]],
+ },
+ }, -- AdditionalInfo
+ }, -- cCompositeChat
+
cCraftingGrid =
{
Desc = [[
--
cgit v1.2.3
From dc0cbd594c05395b5d71af8a8a1f24b10c2d0d50 Mon Sep 17 00:00:00 2001
From: STRWarrior
Date: Wed, 5 Mar 2014 19:17:59 +0100
Subject: The APIDump generates a list of all the permissions again.
---
MCServer/Plugins/InfoDump.lua | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/MCServer/Plugins/InfoDump.lua b/MCServer/Plugins/InfoDump.lua
index 59263d056..c61f9c9e6 100644
--- a/MCServer/Plugins/InfoDump.lua
+++ b/MCServer/Plugins/InfoDump.lua
@@ -530,12 +530,13 @@ local function DumpPermissionsGithub(a_PluginInfo, f)
-- Dump the permissions:
f:write("\n# Permissions\n");
+ f:write("| Permissions | Description | Commands | Recommended groups |\n")
+ f:write("| ----------- | ----------- | -------- | ------------------ |\n")
for idx, perm in ipairs(Permissions) do
- f:write("### ", perm.Name, "\n");
- f:write(GithubizeString(perm.Info.Description or ""));
+ f:write(perm.Name, " | ");
+ f:write(GithubizeString(perm.Info.Description or ""), " | ");
local CommandsAffected = perm.Info.CommandsAffected or {};
if (#CommandsAffected > 0) then
- f:write("\n\nCommands affected:\n - ");
local Affects = {};
for idx2, cmd in ipairs(CommandsAffected) do
if (type(cmd) == "string") then
@@ -544,11 +545,10 @@ local function DumpPermissionsGithub(a_PluginInfo, f)
table.insert(Affects, GetCommandRefGithub(cmd.Name, cmd));
end
end
- f:write(table.concat(Affects, "\n - "));
- f:write("\n");
+ f:write(table.concat(Affects, ", "), " | ");
end
if (perm.Info.RecommendedGroups ~= nil) then
- f:write("\n\nRecommended groups: ", perm.Info.RecommendedGroups, "\n");
+ f:write(perm.Info.RecommendedGroups, " |");
end
f:write("\n");
end
@@ -594,7 +594,7 @@ local function DumpPluginInfoGithub(a_PluginFolder, a_PluginInfo)
f:write(GithubizeString(a_PluginInfo.Description), "\n");
DumpAdditionalInfoGithub(a_PluginInfo, f);
DumpCommandsGithub(a_PluginInfo, f);
- --DumpPermissionsGithub(a_PluginInfo, f); -- Seems a little overkill since they are already mentioned in the commands.
+ DumpPermissionsGithub(a_PluginInfo, f);
f:close();
end
--
cgit v1.2.3
From 594ddd86a04d895fdecb1cd4767031abc5c8dcca Mon Sep 17 00:00:00 2001
From: Howaner
Date: Wed, 5 Mar 2014 19:33:43 +0100
Subject: Add SendBlockTo to cWorldInterface
---
src/Blocks/BlockComparator.h | 3 ++-
src/Blocks/BlockDoor.cpp | 8 +++++---
src/Blocks/BlockFenceGate.h | 2 +-
src/Blocks/BlockHandler.h | 2 +-
src/Blocks/BlockRedstoneRepeater.h | 3 ++-
src/Blocks/BlockTNT.h | 2 +-
src/Blocks/BlockTrapdoor.h | 3 ++-
src/Blocks/WorldInterface.h | 3 +++
src/World.h | 2 +-
9 files changed, 18 insertions(+), 10 deletions(-)
diff --git a/src/Blocks/BlockComparator.h b/src/Blocks/BlockComparator.h
index b0ac75aaf..cea35a864 100644
--- a/src/Blocks/BlockComparator.h
+++ b/src/Blocks/BlockComparator.h
@@ -28,7 +28,8 @@ public:
virtual void OnCancelRightClick(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace) override
{
- a_Player->GetWorld()->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, a_Player);
+ UNUSED(a_ChunkInterface);
+ a_WorldInterface.SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, a_Player);
}
diff --git a/src/Blocks/BlockDoor.cpp b/src/Blocks/BlockDoor.cpp
index 6c51feab3..0acf04852 100644
--- a/src/Blocks/BlockDoor.cpp
+++ b/src/Blocks/BlockDoor.cpp
@@ -57,18 +57,20 @@ void cBlockDoorHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterfac
void cBlockDoorHandler::OnCancelRightClick(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace)
{
+ UNUSED(a_ChunkInterface);
+
+ a_WorldInterface.SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, a_Player);
NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ);
- a_Player->GetClientHandle()->SendBlockChange(a_BlockX, a_BlockY, a_BlockZ, m_BlockType, Meta);
if (Meta & 8)
{
// Current block is top of the door
- a_Player->GetWorld()->SendBlockTo(a_BlockX, a_BlockY - 1, a_BlockZ, a_Player);
+ a_WorldInterface.SendBlockTo(a_BlockX, a_BlockY - 1, a_BlockZ, a_Player);
}
else
{
// Current block is bottom of the door
- a_Player->GetWorld()->SendBlockTo(a_BlockX, a_BlockY + 1, a_BlockZ, a_Player);
+ a_WorldInterface.SendBlockTo(a_BlockX, a_BlockY + 1, a_BlockZ, a_Player);
}
}
diff --git a/src/Blocks/BlockFenceGate.h b/src/Blocks/BlockFenceGate.h
index a14510724..1abe1eecf 100644
--- a/src/Blocks/BlockFenceGate.h
+++ b/src/Blocks/BlockFenceGate.h
@@ -50,7 +50,7 @@ public:
virtual void OnCancelRightClick(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace) override
{
- a_Player->GetWorld()->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, a_Player);
+ a_WorldInterface.SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, a_Player);
}
diff --git a/src/Blocks/BlockHandler.h b/src/Blocks/BlockHandler.h
index fbb36d96a..50c2e2ad5 100644
--- a/src/Blocks/BlockHandler.h
+++ b/src/Blocks/BlockHandler.h
@@ -83,7 +83,7 @@ public:
/// Checks if the block can stay at the specified relative coords in the chunk
virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk);
-
+
/** Checks if the block can be placed at this point.
Default: CanBeAt(...)
NOTE: This call doesn't actually place the block
diff --git a/src/Blocks/BlockRedstoneRepeater.h b/src/Blocks/BlockRedstoneRepeater.h
index 81e3f2b8f..1e2a86949 100644
--- a/src/Blocks/BlockRedstoneRepeater.h
+++ b/src/Blocks/BlockRedstoneRepeater.h
@@ -39,7 +39,8 @@ public:
virtual void OnCancelRightClick(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace) override
{
- a_Player->GetWorld()->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, a_Player);
+ UNUSED(a_ChunkInterface);
+ a_WorldInterface.SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, a_Player);
}
diff --git a/src/Blocks/BlockTNT.h b/src/Blocks/BlockTNT.h
index f5cdecb9a..283a03730 100644
--- a/src/Blocks/BlockTNT.h
+++ b/src/Blocks/BlockTNT.h
@@ -23,7 +23,7 @@ public:
virtual void OnCancelRightClick(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace) override
{
- a_Player->GetWorld()->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, a_Player);
+ a_WorldInterface.SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, a_Player);
}
};
diff --git a/src/Blocks/BlockTrapdoor.h b/src/Blocks/BlockTrapdoor.h
index ffeebd647..9bae92c4d 100644
--- a/src/Blocks/BlockTrapdoor.h
+++ b/src/Blocks/BlockTrapdoor.h
@@ -44,7 +44,8 @@ public:
virtual void OnCancelRightClick(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace) override
{
- a_Player->GetWorld()->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, a_Player);
+ UNUSED(a_ChunkInterface);
+ a_WorldInterface.SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, a_Player);
}
virtual bool GetPlacementBlockTypeMeta(
diff --git a/src/Blocks/WorldInterface.h b/src/Blocks/WorldInterface.h
index b6f2f55a7..c38ffc6db 100644
--- a/src/Blocks/WorldInterface.h
+++ b/src/Blocks/WorldInterface.h
@@ -27,4 +27,7 @@ public:
/** Spawns a mob of the specified type. Returns the mob's EntityID if recognized and spawned, <0 otherwise */
virtual int SpawnMob(double a_PosX, double a_PosY, double a_PosZ, cMonster::eType a_MonsterType) = 0;
+
+ /** If there is a block entity at the specified coords, sends it to the client specified */
+ virtual void SendBlockTo(int a_BlockX, int a_BlockY, int a_BlockZ, cPlayer * a_Player) = 0;
};
diff --git a/src/World.h b/src/World.h
index 93397c014..69d0d6b41 100644
--- a/src/World.h
+++ b/src/World.h
@@ -455,7 +455,7 @@ public:
// tolua_begin
bool DigBlock (int a_X, int a_Y, int a_Z);
- void SendBlockTo(int a_X, int a_Y, int a_Z, cPlayer * a_Player );
+ virtual void SendBlockTo(int a_X, int a_Y, int a_Z, cPlayer * a_Player);
double GetSpawnX(void) const { return m_SpawnX; }
double GetSpawnY(void) const { return m_SpawnY; }
--
cgit v1.2.3
From 53231bebd650b9398060cee1434ad4c44152d36e Mon Sep 17 00:00:00 2001
From: Tiger Wang
Date: Wed, 5 Mar 2014 22:12:48 +0000
Subject: Added extra awesomeness to TNT
+ TNT now has a chance of flinging FallingBlock entities around
* Improved TNT damage
* Improved TNT spawning visuals
* Possible fix for 'SetSwimState failure' messages in debug
---
src/ChunkMap.cpp | 31 +-
src/Entities/Entity.cpp | 380 +++++++++++++------------
src/Entities/Entity.h | 1 +
src/Entities/FallingBlock.cpp | 19 +-
src/Items/ItemLighter.h | 2 +-
src/Simulator/IncrementalRedstoneSimulator.cpp | 2 +-
src/World.cpp | 6 +-
7 files changed, 232 insertions(+), 209 deletions(-)
diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp
index b5795fbaf..b13337b44 100644
--- a/src/ChunkMap.cpp
+++ b/src/ChunkMap.cpp
@@ -1832,8 +1832,17 @@ void cChunkMap::DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_
Handler->ConvertToPickups(Drops, area.GetBlockMeta(bx + x, by + y, bz + z)); // Stone becomes cobblestone, coal ore becomes coal, etc.
m_World->SpawnItemPickups(Drops, bx + x, by + y, bz + z);
}
+ else if (m_World->GetTickRandomNumber(100) < 20) // 20% chance of flinging stuff around
+ {
+ if (!cBlockInfo::FullyOccupiesVoxel(area.GetBlockType(bx + x, by + y, bz + z)))
+ {
+ break;
+ }
+ m_World->SpawnFallingBlock(bx + x, by + y + 5, bz + z, area.GetBlockType(bx + x, by + y, bz + z), area.GetBlockMeta(bx + x, by + y, bz + z));
+ }
area.SetBlockType(bx + x, by + y, bz + z, E_BLOCK_AIR);
a_BlocksAffected.push_back(Vector3i(bx + x, by + y, bz + z));
+ break;
}
} // switch (BlockType)
} // for z
@@ -1846,11 +1855,10 @@ void cChunkMap::DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_
public cEntityCallback
{
public:
- cTNTDamageCallback(cBoundingBox & a_bbTNT, Vector3d a_ExplosionPos, int a_ExplosionSize, int a_ExplosionSizeSq) :
+ cTNTDamageCallback(cBoundingBox & a_bbTNT, Vector3d a_ExplosionPos, int a_ExplosionSize) :
m_bbTNT(a_bbTNT),
m_ExplosionPos(a_ExplosionPos),
- m_ExplosionSize(a_ExplosionSize),
- m_ExplosionSizeSq(a_ExplosionSizeSq)
+ m_ExplosionSize(a_ExplosionSize)
{
}
@@ -1873,14 +1881,16 @@ void cChunkMap::DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_
}
Vector3d AbsoluteEntityPos(abs(EntityPos.x), abs(EntityPos.y), abs(EntityPos.z));
- Vector3d MaxExplosionBoundary(m_ExplosionSizeSq, m_ExplosionSizeSq, m_ExplosionSizeSq);
// Work out how far we are from the edge of the TNT's explosive effect
AbsoluteEntityPos -= m_ExplosionPos;
- AbsoluteEntityPos = MaxExplosionBoundary - AbsoluteEntityPos;
- double FinalDamage = ((AbsoluteEntityPos.x + AbsoluteEntityPos.y + AbsoluteEntityPos.z) / 3) * m_ExplosionSize;
- FinalDamage = a_Entity->GetMaxHealth() - abs(FinalDamage);
+ // All to positive
+ AbsoluteEntityPos.x = abs(AbsoluteEntityPos.x);
+ AbsoluteEntityPos.y = abs(AbsoluteEntityPos.y);
+ AbsoluteEntityPos.z = abs(AbsoluteEntityPos.z);
+
+ double FinalDamage = (((1 / AbsoluteEntityPos.x) + (1 / AbsoluteEntityPos.y) + (1 / AbsoluteEntityPos.z)) * 2) * m_ExplosionSize;
// Clip damage values
if (FinalDamage > a_Entity->GetMaxHealth())
@@ -1888,7 +1898,7 @@ void cChunkMap::DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_
else if (FinalDamage < 0)
FinalDamage = 0;
- if (!a_Entity->IsTNT()) // Don't apply damage to other TNT entities, they should be invincible
+ if (!a_Entity->IsTNT() && !a_Entity->IsFallingBlock()) // Don't apply damage to other TNT entities, they should be invincible
{
a_Entity->TakeDamage(dtExplosion, NULL, (int)FinalDamage, 0);
}
@@ -1898,7 +1908,7 @@ void cChunkMap::DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_
if (distance_explosion.SqrLength() < 4096.0)
{
distance_explosion.Normalize();
- distance_explosion *= m_ExplosionSizeSq;
+ distance_explosion *= m_ExplosionSize * m_ExplosionSize;
a_Entity->AddSpeed(distance_explosion);
}
@@ -1910,14 +1920,13 @@ void cChunkMap::DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_
cBoundingBox & m_bbTNT;
Vector3d m_ExplosionPos;
int m_ExplosionSize;
- int m_ExplosionSizeSq;
};
cBoundingBox bbTNT(Vector3d(a_BlockX, a_BlockY, a_BlockZ), 0.5, 1);
bbTNT.Expand(ExplosionSizeInt * 2, ExplosionSizeInt * 2, ExplosionSizeInt * 2);
- cTNTDamageCallback TNTDamageCallback(bbTNT, Vector3d(a_BlockX, a_BlockY, a_BlockZ), ExplosionSizeInt, ExplosionSizeSq);
+ cTNTDamageCallback TNTDamageCallback(bbTNT, Vector3d(a_BlockX, a_BlockY, a_BlockZ), ExplosionSizeInt);
ForEachEntity(TNTDamageCallback);
// Wake up all simulators for the area, so that water and lava flows and sand falls into the blasted holes (FS #391):
diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp
index 96e8c15a5..3eac0e2e8 100644
--- a/src/Entities/Entity.cpp
+++ b/src/Entities/Entity.cpp
@@ -521,27 +521,35 @@ void cEntity::Tick(float a_Dt, cChunk & a_Chunk)
{
if (a_Chunk.IsValid())
{
- HandlePhysics(a_Dt, a_Chunk);
- }
- }
- if (a_Chunk.IsValid())
- {
- TickBurning(a_Chunk);
- }
- if ((a_Chunk.IsValid()) && (GetPosY() < -46))
- {
- TickInVoid(a_Chunk);
- }
- else
- m_TicksSinceLastVoidDamage = 0;
+ cChunk * NextChunk = a_Chunk.GetNeighborChunk(POSX_TOINT, POSZ_TOINT);
- if (IsMob() || IsPlayer())
- {
- // Set swimming state
- SetSwimState(a_Chunk);
+ if ((NextChunk == NULL) || !NextChunk->IsValid())
+ {
+ return;
+ }
+
+ TickBurning(*NextChunk);
- // Handle drowning
- HandleAir();
+ if (GetPosY() < VOID_BOUNDARY)
+ {
+ TickInVoid(*NextChunk);
+ }
+ else
+ {
+ m_TicksSinceLastVoidDamage = 0;
+ }
+
+ if (IsMob() || IsPlayer())
+ {
+ // Set swimming state
+ SetSwimState(*NextChunk);
+
+ // Handle drowning
+ HandleAir();
+ }
+
+ HandlePhysics(a_Dt, *NextChunk);
+ }
}
}
@@ -562,7 +570,7 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk)
if ((BlockY >= cChunkDef::Height) || (BlockY < 0))
{
// Outside of the world
-
+
cChunk * NextChunk = a_Chunk.GetNeighborChunk(BlockX, BlockZ);
// See if we can commit our changes. If not, we will discard them.
if (NextChunk != NULL)
@@ -571,210 +579,208 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk)
NextPos += (NextSpeed * a_Dt);
SetPosition(NextPos);
}
+
return;
}
- // Make sure we got the correct chunk and a valid one. No one ever knows...
- cChunk * NextChunk = a_Chunk.GetNeighborChunk(BlockX, BlockZ);
- if (NextChunk != NULL)
+ int RelBlockX = BlockX - (a_Chunk.GetPosX() * cChunkDef::Width);
+ int RelBlockZ = BlockZ - (a_Chunk.GetPosZ() * cChunkDef::Width);
+ BLOCKTYPE BlockIn = a_Chunk.GetBlock( RelBlockX, BlockY, RelBlockZ );
+ BLOCKTYPE BlockBelow = (BlockY > 0) ? a_Chunk.GetBlock(RelBlockX, BlockY - 1, RelBlockZ) : E_BLOCK_AIR;
+ if (!cBlockInfo::IsSolid(BlockIn)) // Making sure we are not inside a solid block
{
- int RelBlockX = BlockX - (NextChunk->GetPosX() * cChunkDef::Width);
- int RelBlockZ = BlockZ - (NextChunk->GetPosZ() * cChunkDef::Width);
- BLOCKTYPE BlockIn = NextChunk->GetBlock( RelBlockX, BlockY, RelBlockZ );
- BLOCKTYPE BlockBelow = (BlockY > 0) ? NextChunk->GetBlock(RelBlockX, BlockY - 1, RelBlockZ) : E_BLOCK_AIR;
- if (!cBlockInfo::IsSolid(BlockIn)) // Making sure we are not inside a solid block
+ if (m_bOnGround) // check if it's still on the ground
{
- if (m_bOnGround) // check if it's still on the ground
+ if (!cBlockInfo::IsSolid(BlockBelow)) // Check if block below is air or water.
{
- if (!cBlockInfo::IsSolid(BlockBelow)) // Check if block below is air or water.
- {
- m_bOnGround = false;
- }
+ m_bOnGround = false;
}
}
- else
- {
- // Push out entity.
- BLOCKTYPE GotBlock;
+ }
+ else
+ {
+ // Push out entity.
+ BLOCKTYPE GotBlock;
- static const struct
- {
- int x, y, z;
- } gCrossCoords[] =
- {
- { 1, 0, 0},
- {-1, 0, 0},
- { 0, 0, 1},
- { 0, 0, -1},
- } ;
-
- bool IsNoAirSurrounding = true;
- for (size_t i = 0; i < ARRAYCOUNT(gCrossCoords); i++)
+ static const struct
+ {
+ int x, y, z;
+ } gCrossCoords[] =
+ {
+ { 1, 0, 0},
+ {-1, 0, 0},
+ { 0, 0, 1},
+ { 0, 0, -1},
+ } ;
+
+ bool IsNoAirSurrounding = true;
+ for (size_t i = 0; i < ARRAYCOUNT(gCrossCoords); i++)
+ {
+ if (!a_Chunk.UnboundedRelGetBlockType(RelBlockX + gCrossCoords[i].x, BlockY, RelBlockZ + gCrossCoords[i].z, GotBlock))
{
- if (!NextChunk->UnboundedRelGetBlockType(RelBlockX + gCrossCoords[i].x, BlockY, RelBlockZ + gCrossCoords[i].z, GotBlock))
- {
- // The pickup is too close to an unloaded chunk, bail out of any physics handling
- return;
- }
- if (!cBlockInfo::IsSolid(GotBlock))
- {
- NextPos.x += gCrossCoords[i].x;
- NextPos.z += gCrossCoords[i].z;
- IsNoAirSurrounding = false;
- break;
- }
- } // for i - gCrossCoords[]
-
- if (IsNoAirSurrounding)
+ // The pickup is too close to an unloaded chunk, bail out of any physics handling
+ return;
+ }
+ if (!cBlockInfo::IsSolid(GotBlock))
{
- NextPos.y += 0.5;
+ NextPos.x += gCrossCoords[i].x;
+ NextPos.z += gCrossCoords[i].z;
+ IsNoAirSurrounding = false;
+ break;
}
+ } // for i - gCrossCoords[]
+
+ if (IsNoAirSurrounding)
+ {
+ NextPos.y += 0.5;
+ }
- m_bOnGround = true;
+ m_bOnGround = true;
- /*
- // DEBUG:
- LOGD("Entity #%d (%s) is inside a block at {%d, %d, %d}",
- m_UniqueID, GetClass(), BlockX, BlockY, BlockZ
- );
- */
- }
+ /*
+ // DEBUG:
+ LOGD("Entity #%d (%s) is inside a block at {%d, %d, %d}",
+ m_UniqueID, GetClass(), BlockX, BlockY, BlockZ
+ );
+ */
+ }
- if (!m_bOnGround)
+ if (!m_bOnGround)
+ {
+ float fallspeed;
+ if (IsBlockWater(BlockIn))
{
- float fallspeed;
- if (IsBlockWater(BlockIn))
- {
- fallspeed = m_Gravity * a_Dt / 3; // Fall 3x slower in water.
- }
- else if (BlockIn == E_BLOCK_COBWEB)
- {
- NextSpeed.y *= 0.05; // Reduce overall falling speed
- fallspeed = 0; // No falling.
- }
- else
- {
- // Normal gravity
- fallspeed = m_Gravity * a_Dt;
- }
- NextSpeed.y += fallspeed;
+ fallspeed = m_Gravity * a_Dt / 3; // Fall 3x slower in water.
+ }
+ else if (BlockIn == E_BLOCK_COBWEB)
+ {
+ NextSpeed.y *= 0.05; // Reduce overall falling speed
+ fallspeed = 0; // No falling.
}
else
{
- // Friction
- if (NextSpeed.SqrLength() > 0.0004f)
+ // Normal gravity
+ fallspeed = m_Gravity * a_Dt;
+ }
+ NextSpeed.y += fallspeed;
+ }
+ else
+ {
+ // Friction
+ if (NextSpeed.SqrLength() > 0.0004f)
+ {
+ NextSpeed.x *= 0.7f / (1 + a_Dt);
+ if (fabs(NextSpeed.x) < 0.05)
{
- NextSpeed.x *= 0.7f / (1 + a_Dt);
- if (fabs(NextSpeed.x) < 0.05)
- {
- NextSpeed.x = 0;
- }
- NextSpeed.z *= 0.7f / (1 + a_Dt);
- if (fabs(NextSpeed.z) < 0.05)
- {
- NextSpeed.z = 0;
- }
+ NextSpeed.x = 0;
+ }
+ NextSpeed.z *= 0.7f / (1 + a_Dt);
+ if (fabs(NextSpeed.z) < 0.05)
+ {
+ NextSpeed.z = 0;
}
}
+ }
- // Adjust X and Z speed for COBWEB temporary. This speed modification should be handled inside block handlers since we
- // might have different speed modifiers according to terrain.
- if (BlockIn == E_BLOCK_COBWEB)
- {
- NextSpeed.x *= 0.25;
- NextSpeed.z *= 0.25;
- }
+ // Adjust X and Z speed for COBWEB temporary. This speed modification should be handled inside block handlers since we
+ // might have different speed modifiers according to terrain.
+ if (BlockIn == E_BLOCK_COBWEB)
+ {
+ NextSpeed.x *= 0.25;
+ NextSpeed.z *= 0.25;
+ }
- //Get water direction
- Direction WaterDir = m_World->GetWaterSimulator()->GetFlowingDirection(BlockX, BlockY, BlockZ);
+ //Get water direction
+ Direction WaterDir = m_World->GetWaterSimulator()->GetFlowingDirection(BlockX, BlockY, BlockZ);
- m_WaterSpeed *= 0.9f; //Reduce speed each tick
+ m_WaterSpeed *= 0.9f; //Reduce speed each tick
- switch(WaterDir)
- {
- case X_PLUS:
- m_WaterSpeed.x = 0.2f;
- m_bOnGround = false;
- break;
- case X_MINUS:
- m_WaterSpeed.x = -0.2f;
- m_bOnGround = false;
- break;
- case Z_PLUS:
- m_WaterSpeed.z = 0.2f;
- m_bOnGround = false;
- break;
- case Z_MINUS:
- m_WaterSpeed.z = -0.2f;
- m_bOnGround = false;
- break;
-
- default:
+ switch(WaterDir)
+ {
+ case X_PLUS:
+ m_WaterSpeed.x = 0.2f;
+ m_bOnGround = false;
break;
- }
+ case X_MINUS:
+ m_WaterSpeed.x = -0.2f;
+ m_bOnGround = false;
+ break;
+ case Z_PLUS:
+ m_WaterSpeed.z = 0.2f;
+ m_bOnGround = false;
+ break;
+ case Z_MINUS:
+ m_WaterSpeed.z = -0.2f;
+ m_bOnGround = false;
+ break;
+
+ default:
+ break;
+ }
- if (fabs(m_WaterSpeed.x) < 0.05)
- {
- m_WaterSpeed.x = 0;
- }
+ if (fabs(m_WaterSpeed.x) < 0.05)
+ {
+ m_WaterSpeed.x = 0;
+ }
- if (fabs(m_WaterSpeed.z) < 0.05)
- {
- m_WaterSpeed.z = 0;
- }
+ if (fabs(m_WaterSpeed.z) < 0.05)
+ {
+ m_WaterSpeed.z = 0;
+ }
- NextSpeed += m_WaterSpeed;
+ NextSpeed += m_WaterSpeed;
- if( NextSpeed.SqrLength() > 0.f )
+ if( NextSpeed.SqrLength() > 0.f )
+ {
+ cTracer Tracer( GetWorld() );
+ int Ret = Tracer.Trace( NextPos, NextSpeed, 2 );
+ if( Ret ) // Oh noez! we hit something
{
- cTracer Tracer( GetWorld() );
- int Ret = Tracer.Trace( NextPos, NextSpeed, 2 );
- if( Ret ) // Oh noez! we hit something
+ // Set to hit position
+ if( (Tracer.RealHit - NextPos).SqrLength() <= ( NextSpeed * a_Dt ).SqrLength() )
{
- // Set to hit position
- if( (Tracer.RealHit - NextPos).SqrLength() <= ( NextSpeed * a_Dt ).SqrLength() )
+ if( Ret == 1 )
{
- if( Ret == 1 )
+ if( Tracer.HitNormal.x != 0.f ) NextSpeed.x = 0.f;
+ if( Tracer.HitNormal.y != 0.f ) NextSpeed.y = 0.f;
+ if( Tracer.HitNormal.z != 0.f ) NextSpeed.z = 0.f;
+
+ if( Tracer.HitNormal.y > 0 ) // means on ground
{
- if( Tracer.HitNormal.x != 0.f ) NextSpeed.x = 0.f;
- if( Tracer.HitNormal.y != 0.f ) NextSpeed.y = 0.f;
- if( Tracer.HitNormal.z != 0.f ) NextSpeed.z = 0.f;
-
- if( Tracer.HitNormal.y > 0 ) // means on ground
- {
- m_bOnGround = true;
- }
+ m_bOnGround = true;
}
- NextPos.Set(Tracer.RealHit.x,Tracer.RealHit.y,Tracer.RealHit.z);
- NextPos.x += Tracer.HitNormal.x * 0.3f;
- NextPos.y += Tracer.HitNormal.y * 0.05f; // Any larger produces entity vibration-upon-the-spot
- NextPos.z += Tracer.HitNormal.z * 0.3f;
- }
- else
- {
- NextPos += (NextSpeed * a_Dt);
}
+ NextPos.Set(Tracer.RealHit.x,Tracer.RealHit.y,Tracer.RealHit.z);
+ NextPos.x += Tracer.HitNormal.x * 0.3f;
+ NextPos.y += Tracer.HitNormal.y * 0.05f; // Any larger produces entity vibration-upon-the-spot
+ NextPos.z += Tracer.HitNormal.z * 0.3f;
}
else
{
- // We didn't hit anything, so move =]
NextPos += (NextSpeed * a_Dt);
}
}
- BlockX = (int) floor(NextPos.x);
- BlockZ = (int) floor(NextPos.z);
- NextChunk = NextChunk->GetNeighborChunk(BlockX,BlockZ);
- // See if we can commit our changes. If not, we will discard them.
- if (NextChunk != NULL)
+ else
{
- if (NextPos.x != GetPosX()) SetPosX(NextPos.x);
- if (NextPos.y != GetPosY()) SetPosY(NextPos.y);
- if (NextPos.z != GetPosZ()) SetPosZ(NextPos.z);
- if (NextSpeed.x != GetSpeedX()) SetSpeedX(NextSpeed.x);
- if (NextSpeed.y != GetSpeedY()) SetSpeedY(NextSpeed.y);
- if (NextSpeed.z != GetSpeedZ()) SetSpeedZ(NextSpeed.z);
+ // We didn't hit anything, so move =]
+ NextPos += (NextSpeed * a_Dt);
}
}
+
+ BlockX = (int) floor(NextPos.x);
+ BlockZ = (int) floor(NextPos.z);
+
+ cChunk * NextChunk = a_Chunk.GetNeighborChunk(BlockX, BlockZ);
+ // See if we can commit our changes. If not, we will discard them.
+ if (NextChunk != NULL)
+ {
+ if (NextPos.x != GetPosX()) SetPosX(NextPos.x);
+ if (NextPos.y != GetPosY()) SetPosY(NextPos.y);
+ if (NextPos.z != GetPosZ()) SetPosZ(NextPos.z);
+ if (NextSpeed.x != GetSpeedX()) SetSpeedX(NextSpeed.x);
+ if (NextSpeed.y != GetSpeedY()) SetSpeedY(NextSpeed.y);
+ if (NextSpeed.z != GetSpeedZ()) SetSpeedZ(NextSpeed.z);
+ }
}
@@ -815,14 +821,13 @@ void cEntity::TickBurning(cChunk & a_Chunk)
{
int RelX = x;
int RelZ = z;
- cChunk * CurChunk = a_Chunk.GetRelNeighborChunkAdjustCoords(RelX, RelZ);
- if (CurChunk == NULL)
- {
- continue;
- }
+
for (int y = MinY; y <= MaxY; y++)
{
- switch (CurChunk->GetBlock(RelX, y, RelZ))
+ BLOCKTYPE Block;
+ a_Chunk.UnboundedRelGetBlockType(RelX, y, RelZ, Block);
+
+ switch (Block)
{
case E_BLOCK_FIRE:
{
@@ -922,7 +927,7 @@ void cEntity::TickInVoid(cChunk & a_Chunk)
void cEntity::SetSwimState(cChunk & a_Chunk)
{
- int RelY = (int)floor(m_LastPosY + 0.1);
+ int RelY = (int)floor(GetPosY() + 0.1);
if ((RelY < 0) || (RelY >= cChunkDef::Height - 1))
{
m_IsSwimming = false;
@@ -931,11 +936,10 @@ void cEntity::SetSwimState(cChunk & a_Chunk)
}
BLOCKTYPE BlockIn;
- int RelX = (int)floor(m_LastPosX) - a_Chunk.GetPosX() * cChunkDef::Width;
- int RelZ = (int)floor(m_LastPosZ) - a_Chunk.GetPosZ() * cChunkDef::Width;
+ int RelX = POSX_TOINT - a_Chunk.GetPosX() * cChunkDef::Width;
+ int RelZ = POSZ_TOINT - a_Chunk.GetPosZ() * cChunkDef::Width;
// Check if the player is swimming:
- // Use Unbounded, because we're being called *after* processing super::Tick(), which could have changed our chunk
if (!a_Chunk.UnboundedRelGetBlockType(RelX, RelY, RelZ, BlockIn))
{
// This sometimes happens on Linux machines
diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h
index b3b1cef83..ee3f25cd8 100644
--- a/src/Entities/Entity.h
+++ b/src/Entities/Entity.h
@@ -119,6 +119,7 @@ public:
BURN_TICKS = 200, ///< How long to keep an entity burning after it has stood in lava / fire
MAX_AIR_LEVEL = 300, ///< Maximum air an entity can have
DROWNING_TICKS = 20, ///< Number of ticks per heart of damage
+ VOID_BOUNDARY = -46 ///< At what position Y to begin applying void damage
} ;
cEntity(eEntityType a_EntityType, double a_X, double a_Y, double a_Z, double a_Width, double a_Height);
diff --git a/src/Entities/FallingBlock.cpp b/src/Entities/FallingBlock.cpp
index 9fcd9ac80..a66c7e4ae 100644
--- a/src/Entities/FallingBlock.cpp
+++ b/src/Entities/FallingBlock.cpp
@@ -33,20 +33,16 @@ void cFallingBlock::SpawnOn(cClientHandle & a_ClientHandle)
void cFallingBlock::Tick(float a_Dt, cChunk & a_Chunk)
{
- float MilliDt = a_Dt * 0.001f;
- AddSpeedY(MilliDt * -9.8f);
- AddPosY(GetSpeedY() * MilliDt);
-
// GetWorld()->BroadcastTeleportEntity(*this); // Test position
- int BlockX = m_OriginalPosition.x;
+ int BlockX = POSX_TOINT;
int BlockY = (int)(GetPosY() - 0.5);
- int BlockZ = m_OriginalPosition.z;
+ int BlockZ = POSZ_TOINT;
if (BlockY < 0)
{
// Fallen out of this world, just continue falling until out of sight, then destroy:
- if (BlockY < 100)
+ if (BlockY < VOID_BOUNDARY)
{
Destroy(true);
}
@@ -86,6 +82,15 @@ void cFallingBlock::Tick(float a_Dt, cChunk & a_Chunk)
Destroy(true);
return;
}
+
+ float MilliDt = a_Dt * 0.001f;
+ AddSpeedY(MilliDt * -9.8f);
+ AddPosition(GetSpeed() * MilliDt);
+
+ if ((GetSpeedX() != 0) || (GetSpeedZ() != 0))
+ {
+ BroadcastMovementUpdate();
+ }
}
diff --git a/src/Items/ItemLighter.h b/src/Items/ItemLighter.h
index cc7daeb08..a828cd4fa 100644
--- a/src/Items/ItemLighter.h
+++ b/src/Items/ItemLighter.h
@@ -34,8 +34,8 @@ public:
{
// Activate the TNT:
a_World->BroadcastSoundEffect("game.tnt.primed", a_BlockX * 8, a_BlockY * 8, a_BlockZ * 8, 0.5f, 0.6f);
- a_World->SpawnPrimedTNT(a_BlockX + 0.5, a_BlockY + 0.5, a_BlockZ + 0.5, 4); // 4 seconds to boom
a_World->SetBlock(a_BlockX,a_BlockY,a_BlockZ, E_BLOCK_AIR, 0);
+ a_World->SpawnPrimedTNT(a_BlockX + 0.5, a_BlockY + 0.5, a_BlockZ + 0.5, 4); // 4 seconds to boom
break;
}
default:
diff --git a/src/Simulator/IncrementalRedstoneSimulator.cpp b/src/Simulator/IncrementalRedstoneSimulator.cpp
index 0640227b0..c9305b8ff 100644
--- a/src/Simulator/IncrementalRedstoneSimulator.cpp
+++ b/src/Simulator/IncrementalRedstoneSimulator.cpp
@@ -838,8 +838,8 @@ void cIncrementalRedstoneSimulator::HandleTNT(int a_BlockX, int a_BlockY, int a_
if (AreCoordsPowered(a_BlockX, a_BlockY, a_BlockZ))
{
m_World.BroadcastSoundEffect("game.tnt.primed", a_BlockX * 8, a_BlockY * 8, a_BlockZ * 8, 0.5f, 0.6f);
- m_World.SpawnPrimedTNT(a_BlockX + 0.5, a_BlockY + 0.5, a_BlockZ + 0.5, 4); // 4 seconds to boom
m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0);
+ m_World.SpawnPrimedTNT(a_BlockX + 0.5, a_BlockY + 0.5, a_BlockZ + 0.5, 4); // 4 seconds to boom
}
}
diff --git a/src/World.cpp b/src/World.cpp
index ffdae2a37..d6b88f187 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -1696,7 +1696,11 @@ void cWorld::SpawnPrimedTNT(double a_X, double a_Y, double a_Z, double a_FuseTim
UNUSED(a_InitialVelocityCoeff);
cTNTEntity * TNT = new cTNTEntity(a_X, a_Y, a_Z, a_FuseTimeInSec);
TNT->Initialize(this);
- // TODO: Add a bit of speed in horiz and vert axes, based on the a_InitialVelocityCoeff
+ TNT->SetSpeed(
+ a_InitialVelocityCoeff * (GetTickRandomNumber(2) - 1), /** -1, 0, 1 */
+ a_InitialVelocityCoeff * 2,
+ a_InitialVelocityCoeff * (GetTickRandomNumber(2) - 1)
+ );
}
--
cgit v1.2.3
From 99b9e6dce5ee49c1062074ce9f6d0669b2b265cc Mon Sep 17 00:00:00 2001
From: Howaner
Date: Thu, 6 Mar 2014 11:08:47 +0100
Subject: Broadcast the Equipped Item, if the Slot is changed.
---
src/Inventory.cpp | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/src/Inventory.cpp b/src/Inventory.cpp
index 7f434adfd..c7c089d5f 100644
--- a/src/Inventory.cpp
+++ b/src/Inventory.cpp
@@ -204,6 +204,12 @@ void cInventory::SetSlot(int a_SlotNum, const cItem & a_Item)
return;
}
Grid->SetSlot(GridSlotNum, a_Item);
+
+ // Broadcast the Equipped Item, if the Slot is changed.
+ if ((Grid == &m_HotbarSlots) && (m_EquippedSlotNum == (a_SlotNum - invHotbarOffset)))
+ {
+ m_Owner.GetWorld()->BroadcastEntityEquipment(m_Owner, 0, a_Item, m_Owner.GetClientHandle());
+ }
}
--
cgit v1.2.3
From 1c7a580e520ba6c28936e46d36abba658bd477b1 Mon Sep 17 00:00:00 2001
From: Howaner
Date: Thu, 6 Mar 2014 13:35:53 +0100
Subject: Fix comment
---
src/Blocks/WorldInterface.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/Blocks/WorldInterface.h b/src/Blocks/WorldInterface.h
index c38ffc6db..e59b00eff 100644
--- a/src/Blocks/WorldInterface.h
+++ b/src/Blocks/WorldInterface.h
@@ -28,6 +28,6 @@ public:
/** Spawns a mob of the specified type. Returns the mob's EntityID if recognized and spawned, <0 otherwise */
virtual int SpawnMob(double a_PosX, double a_PosY, double a_PosZ, cMonster::eType a_MonsterType) = 0;
- /** If there is a block entity at the specified coords, sends it to the client specified */
+ /** Sends the block on those coords to the player */
virtual void SendBlockTo(int a_BlockX, int a_BlockY, int a_BlockZ, cPlayer * a_Player) = 0;
};
--
cgit v1.2.3
From 787a71929cd4095681b37acf81332b7b9c3ddf89 Mon Sep 17 00:00:00 2001
From: Howaner
Date: Fri, 7 Mar 2014 01:30:34 +0100
Subject: Add Flower Pots
---
src/Bindings/ManualBindings.cpp | 2 +
src/BlockEntities/BlockEntity.cpp | 2 +
src/BlockEntities/FlowerPotEntity.cpp | 134 ++++++++++++++++++++++++++++++++
src/BlockEntities/FlowerPotEntity.h | 74 ++++++++++++++++++
src/Blocks/BlockFlowerPot.h | 83 +-------------------
src/Chunk.cpp | 35 +++++++++
src/Chunk.h | 7 +-
src/ChunkMap.cpp | 18 +++++
src/ChunkMap.h | 5 ++
src/Protocol/Protocol17x.cpp | 16 +++-
src/World.cpp | 9 +++
src/World.h | 9 ++-
src/WorldStorage/NBTChunkSerializer.cpp | 15 ++++
src/WorldStorage/NBTChunkSerializer.h | 2 +
src/WorldStorage/WSSAnvil.cpp | 36 +++++++++
src/WorldStorage/WSSAnvil.h | 1 +
src/WorldStorage/WSSCompact.cpp | 40 +++++++++-
17 files changed, 401 insertions(+), 87 deletions(-)
create mode 100644 src/BlockEntities/FlowerPotEntity.cpp
create mode 100644 src/BlockEntities/FlowerPotEntity.h
diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp
index 9fbc2e842..3570b2c1e 100644
--- a/src/Bindings/ManualBindings.cpp
+++ b/src/Bindings/ManualBindings.cpp
@@ -23,6 +23,7 @@
#include "../BlockEntities/HopperEntity.h"
#include "../BlockEntities/NoteEntity.h"
#include "../BlockEntities/MobHeadEntity.h"
+#include "../BlockEntities/FlowerPotEntity.h"
#include "md5/md5.h"
#include "../LineBlockTracer.h"
#include "../WorldStorage/SchematicFileSerializer.h"
@@ -2820,6 +2821,7 @@ void ManualBindings::Bind(lua_State * tolua_S)
tolua_function(tolua_S, "DoWithNoteBlockAt", tolua_DoWithXYZ);
tolua_function(tolua_S, "DoWithCommandBlockAt", tolua_DoWithXYZ);
tolua_function(tolua_S, "DoWithMobHeadBlockAt", tolua_DoWithXYZ);
+ tolua_function(tolua_S, "DoWithFlowerPotAt", tolua_DoWithXYZ);
tolua_function(tolua_S, "DoWithPlayer", tolua_DoWith< cWorld, cPlayer, &cWorld::DoWithPlayer>);
tolua_function(tolua_S, "FindAndDoWithPlayer", tolua_DoWith< cWorld, cPlayer, &cWorld::FindAndDoWithPlayer>);
tolua_function(tolua_S, "ForEachBlockEntityInChunk", tolua_ForEachInChunk);
diff --git a/src/BlockEntities/BlockEntity.cpp b/src/BlockEntities/BlockEntity.cpp
index 57ad83de9..b42318c2f 100644
--- a/src/BlockEntities/BlockEntity.cpp
+++ b/src/BlockEntities/BlockEntity.cpp
@@ -10,6 +10,7 @@
#include "DispenserEntity.h"
#include "DropperEntity.h"
#include "EnderChestEntity.h"
+#include "FlowerPotEntity.h"
#include "FurnaceEntity.h"
#include "HopperEntity.h"
#include "JukeboxEntity.h"
@@ -30,6 +31,7 @@ cBlockEntity * cBlockEntity::CreateByBlockType(BLOCKTYPE a_BlockType, NIBBLETYPE
case E_BLOCK_DISPENSER: return new cDispenserEntity (a_BlockX, a_BlockY, a_BlockZ, a_World);
case E_BLOCK_DROPPER: return new cDropperEntity (a_BlockX, a_BlockY, a_BlockZ, a_World);
case E_BLOCK_ENDER_CHEST: return new cEnderChestEntity (a_BlockX, a_BlockY, a_BlockZ, a_World);
+ case E_BLOCK_FLOWER_POT: return new cFlowerPotEntity (a_BlockX, a_BlockY, a_BlockZ, a_World);
case E_BLOCK_HEAD: return new cMobHeadEntity (a_BlockX, a_BlockY, a_BlockZ, a_World);
case E_BLOCK_LIT_FURNACE: return new cFurnaceEntity (a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, a_World);
case E_BLOCK_FURNACE: return new cFurnaceEntity (a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, a_World);
diff --git a/src/BlockEntities/FlowerPotEntity.cpp b/src/BlockEntities/FlowerPotEntity.cpp
new file mode 100644
index 000000000..87bf8b921
--- /dev/null
+++ b/src/BlockEntities/FlowerPotEntity.cpp
@@ -0,0 +1,134 @@
+
+// FlowerPotEntity.cpp
+
+// Implements the cFlowerPotEntity class representing a single sign in the world
+
+#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
+#include "json/json.h"
+#include "FlowerPotEntity.h"
+#include "../Entities/Player.h"
+#include "../Item.h"
+
+
+
+
+
+cFlowerPotEntity::cFlowerPotEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World) :
+ super(E_BLOCK_FLOWER_POT, a_BlockX, a_BlockY, a_BlockZ, a_World)
+{
+}
+
+
+
+
+
+// It don't do anything when 'used'
+void cFlowerPotEntity::UsedBy(cPlayer * a_Player)
+{
+ if (IsItemInPot())
+ {
+ return;
+ }
+
+ cItem SelectedItem = a_Player->GetInventory().GetEquippedItem();
+ if (IsFlower(SelectedItem.m_ItemType, SelectedItem.m_ItemDamage))
+ {
+ m_Item = SelectedItem.CopyOne();
+ if (!a_Player->IsGameModeCreative())
+ {
+ a_Player->GetInventory().RemoveOneEquippedItem();
+ }
+ m_World->BroadcastBlockEntity(m_PosX, m_PosY, m_PosZ, a_Player->GetClientHandle());
+ }
+}
+
+
+
+
+
+void cFlowerPotEntity::SendTo(cClientHandle & a_Client)
+{
+ a_Client.SendUpdateBlockEntity(*this);
+}
+
+
+
+
+
+void cFlowerPotEntity::Destroy(void)
+{
+ // Drop the contents as pickups:
+ if (!m_Item.IsEmpty())
+ {
+ ASSERT(m_World != NULL);
+ cItems Pickups;
+ Pickups.Add(m_Item);
+ m_World->SpawnItemPickups(Pickups, m_PosX + 0.5, m_PosY + 0.5, m_PosZ + 0.5);
+
+ m_Item.Empty();
+ }
+}
+
+
+
+
+
+bool cFlowerPotEntity::LoadFromJson(const Json::Value & a_Value)
+{
+ m_PosX = a_Value.get("x", 0).asInt();
+ m_PosY = a_Value.get("y", 0).asInt();
+ m_PosZ = a_Value.get("z", 0).asInt();
+
+ m_Item = cItem();
+ m_Item.FromJson(a_Value.get("Item", 0));
+
+ return true;
+}
+
+
+
+
+
+void cFlowerPotEntity::SaveToJson(Json::Value & a_Value)
+{
+ a_Value["x"] = m_PosX;
+ a_Value["y"] = m_PosY;
+ a_Value["z"] = m_PosZ;
+
+ Json::Value Item;
+ m_Item.GetJson(Item);
+ a_Value["Item"] = Item;
+}
+
+
+
+
+
+bool cFlowerPotEntity::IsFlower(short m_ItemType, short m_ItemData)
+{
+ switch (m_ItemType)
+ {
+ case E_BLOCK_DANDELION:
+ case E_BLOCK_FLOWER:
+ case E_BLOCK_CACTUS:
+ case E_BLOCK_BROWN_MUSHROOM:
+ case E_BLOCK_RED_MUSHROOM:
+ case E_BLOCK_SAPLING:
+ case E_BLOCK_DEAD_BUSH:
+ {
+ return true;
+ }
+ case E_BLOCK_TALL_GRASS:
+ {
+ return (m_ItemData == (short) 2);
+ }
+ default:
+ {
+ return false;
+ }
+ }
+}
+
+
+
+
diff --git a/src/BlockEntities/FlowerPotEntity.h b/src/BlockEntities/FlowerPotEntity.h
new file mode 100644
index 000000000..da3fe9b7e
--- /dev/null
+++ b/src/BlockEntities/FlowerPotEntity.h
@@ -0,0 +1,74 @@
+// FlowerPotEntity.h
+
+// Declares the cFlowerPotEntity class representing a single sign in the world
+
+
+
+
+
+#pragma once
+
+#include "BlockEntity.h"
+
+class cItem;
+
+
+
+
+
+namespace Json
+{
+ class Value;
+}
+
+
+
+
+
+// tolua_begin
+
+class cFlowerPotEntity :
+ public cBlockEntity
+{
+ typedef cBlockEntity super;
+
+public:
+
+ // tolua_end
+
+ /** Creates a new flowerpot entity at the specified block coords. a_World may be NULL */
+ cFlowerPotEntity(int a_BlocX, int a_BlockY, int a_BlockZ, cWorld * a_World);
+
+ bool LoadFromJson( const Json::Value& a_Value );
+ virtual void SaveToJson(Json::Value& a_Value ) override;
+
+ virtual void Destroy(void) override;
+
+ // tolua_begin
+
+ /** Is a flower in the pot? */
+ bool IsItemInPot(void) { return !m_Item.IsEmpty(); }
+
+ /** Get the item in the flower pot */
+ cItem GetItem(void) const { return m_Item; }
+
+ /** Set the item in the flower pot */
+ void SetItem(const cItem a_Item) { m_Item = a_Item; }
+
+ // tolua_end
+
+ virtual void UsedBy(cPlayer * a_Player) override;
+ virtual void SendTo(cClientHandle & a_Client) override;
+
+ static bool IsFlower(short m_ItemType, short m_ItemData);
+
+ static const char * GetClassStatic(void) { return "cFlowerPotEntity"; }
+
+private:
+
+ cItem m_Item;
+} ; // tolua_export
+
+
+
+
diff --git a/src/Blocks/BlockFlowerPot.h b/src/Blocks/BlockFlowerPot.h
index 4de85f629..fc75ef638 100644
--- a/src/Blocks/BlockFlowerPot.h
+++ b/src/Blocks/BlockFlowerPot.h
@@ -2,101 +2,24 @@
#pragma once
#include "BlockHandler.h"
+#include "BlockEntity.h"
class cBlockFlowerPotHandler :
- public cBlockHandler
+ public cBlockEntityHandler
{
public:
cBlockFlowerPotHandler(BLOCKTYPE a_BlockType) :
- cBlockHandler(a_BlockType)
+ cBlockEntityHandler(a_BlockType)
{
}
-
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
a_Pickups.push_back(cItem(E_ITEM_FLOWER_POT, 1, 0));
- if (a_BlockMeta == 0)
- {
- return;
- }
- cItem Plant;
- switch (a_BlockMeta)
- {
- case 1: Plant = cItem(E_BLOCK_RED_ROSE, 1, 0); break;
- case 2: Plant = cItem(E_BLOCK_YELLOW_FLOWER, 1, 0); break;
- case 3: Plant = cItem(E_BLOCK_SAPLING, 1, E_META_SAPLING_APPLE); break;
- case 4: Plant = cItem(E_BLOCK_SAPLING, 1, E_META_SAPLING_CONIFER); break;
- case 5: Plant = cItem(E_BLOCK_SAPLING, 1, E_META_SAPLING_BIRCH); break;
- case 6: Plant = cItem(E_BLOCK_SAPLING, 1, E_META_SAPLING_JUNGLE); break;
- case 7: Plant = cItem(E_BLOCK_RED_MUSHROOM, 1, 0); break;
- case 8: Plant = cItem(E_BLOCK_BROWN_MUSHROOM, 1, 0); break;
- case 9: Plant = cItem(E_BLOCK_CACTUS, 1, 0); break;
- case 10: Plant = cItem(E_BLOCK_DEAD_BUSH, 1, 0); break;
- case 11: Plant = cItem(E_BLOCK_TALL_GRASS, 1, E_META_TALL_GRASS_FERN); break;
- default: return;
- }
- a_Pickups.push_back(Plant);
- }
-
-
- void OnUse(cWorld * a_World, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ)
- {
- NIBBLETYPE Meta = a_World->GetBlockMeta( a_BlockX, a_BlockY, a_BlockZ );
- if (Meta != 0)
- {
- // Already filled
- return;
- }
-
- switch (a_Player->GetEquippedItem().m_ItemType)
- {
- case E_BLOCK_RED_ROSE: Meta = 1; break;
- case E_BLOCK_YELLOW_FLOWER: Meta = 2; break;
- case E_BLOCK_SAPLING:
- {
- switch (a_Player->GetEquippedItem().m_ItemDamage)
- {
- case E_META_SAPLING_APPLE: Meta = 3; break;
- case E_META_SAPLING_CONIFER: Meta = 4; break;
- case E_META_SAPLING_BIRCH: Meta = 5; break;
- case E_META_SAPLING_JUNGLE: Meta = 6; break;
- }
- break;
- }
- case E_BLOCK_RED_MUSHROOM: Meta = 7; break;
- case E_BLOCK_BROWN_MUSHROOM: Meta = 8; break;
- case E_BLOCK_CACTUS: Meta = 9; break;
- case E_BLOCK_DEAD_BUSH: Meta = 10; break;
- case E_BLOCK_TALL_GRASS:
- {
- if (a_Player->GetEquippedItem().m_ItemDamage == E_META_TALL_GRASS_FERN)
- {
- Meta = 11;
- }
- else
- {
- return;
- }
- break;
- }
- }
-
- if (a_Player->GetGameMode() != gmCreative)
- {
- a_Player->GetInventory().RemoveOneEquippedItem();
- }
- a_World->SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, Meta);
- }
-
-
- virtual bool IsUseable(void) override
- {
- return true;
}
} ;
diff --git a/src/Chunk.cpp b/src/Chunk.cpp
index a75828461..b5b776147 100644
--- a/src/Chunk.cpp
+++ b/src/Chunk.cpp
@@ -20,6 +20,7 @@
#include "BlockEntities/NoteEntity.h"
#include "BlockEntities/SignEntity.h"
#include "BlockEntities/MobHeadEntity.h"
+#include "BlockEntities/FlowerPotEntity.h"
#include "Entities/Pickup.h"
#include "Item.h"
#include "Noise.h"
@@ -1311,6 +1312,7 @@ void cChunk::CreateBlockEntities(void)
case E_BLOCK_HEAD:
case E_BLOCK_NOTE_BLOCK:
case E_BLOCK_JUKEBOX:
+ case E_BLOCK_FLOWER_POT:
{
if (!HasBlockEntityAt(x + m_PosX * Width, y + m_PosY * Height, z + m_PosZ * Width))
{
@@ -1440,6 +1442,7 @@ void cChunk::SetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType,
case E_BLOCK_HEAD:
case E_BLOCK_NOTE_BLOCK:
case E_BLOCK_JUKEBOX:
+ case E_BLOCK_FLOWER_POT:
{
AddBlockEntity(cBlockEntity::CreateByBlockType(a_BlockType, a_BlockMeta, WorldPos.x, WorldPos.y, WorldPos.z, m_World));
break;
@@ -2369,6 +2372,38 @@ bool cChunk::DoWithMobHeadBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cMob
+bool cChunk::DoWithFlowerPotAt(int a_BlockX, int a_BlockY, int a_BlockZ, cFlowerPotCallback & a_Callback)
+{
+ // The blockentity list is locked by the parent chunkmap's CS
+ for (cBlockEntityList::iterator itr = m_BlockEntities.begin(), itr2 = itr; itr != m_BlockEntities.end(); itr = itr2)
+ {
+ ++itr2;
+ if (((*itr)->GetPosX() != a_BlockX) || ((*itr)->GetPosY() != a_BlockY) || ((*itr)->GetPosZ() != a_BlockZ))
+ {
+ continue;
+ }
+ if ((*itr)->GetBlockType() != E_BLOCK_FLOWER_POT)
+ {
+ // There is a block entity here, but of different type. No other block entity can be here, so we can safely bail out
+ return false;
+ }
+
+ // The correct block entity is here,
+ if (a_Callback.Item((cFlowerPotEntity *)*itr))
+ {
+ return false;
+ }
+ return true;
+ } // for itr - m_BlockEntitites[]
+
+ // Not found:
+ return false;
+}
+
+
+
+
+
bool cChunk::GetSignLines(int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4)
{
// The blockentity list is locked by the parent chunkmap's CS
diff --git a/src/Chunk.h b/src/Chunk.h
index c9e9697ca..e8b46f631 100644
--- a/src/Chunk.h
+++ b/src/Chunk.h
@@ -32,6 +32,7 @@ class cDispenserEntity;
class cFurnaceEntity;
class cNoteEntity;
class cMobHeadEntity;
+class cFlowerPotEntity;
class cBlockArea;
class cPawn;
class cPickup;
@@ -49,6 +50,7 @@ typedef cItemCallback cFurnaceCallback;
typedef cItemCallback cNoteBlockCallback;
typedef cItemCallback cCommandBlockCallback;
typedef cItemCallback cMobHeadBlockCallback;
+typedef cItemCallback cFlowerPotCallback;
@@ -253,9 +255,12 @@ public:
/** Calls the callback for the command block at the specified coords; returns false if there's no command block at those coords or callback returns true, returns true if found */
bool DoWithCommandBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cCommandBlockCallback & a_Callback);
- /** Calls the callback for the mob head block at the specified coords; returns false if there's no mob header block at those coords or callback returns true, returns true if found */
+ /** Calls the callback for the mob head block at the specified coords; returns false if there's no mob head block at those coords or callback returns true, returns true if found */
bool DoWithMobHeadBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cMobHeadBlockCallback & a_Callback);
+ /** Calls the callback for the flower pot at the specified coords; returns false if there's no flower pot at those coords or callback returns true, returns true if found */
+ bool DoWithFlowerPotAt(int a_BlockX, int a_BlockY, int a_BlockZ, cFlowerPotCallback & a_Callback);
+
/** Retrieves the test on the sign at the specified coords; returns false if there's no sign at those coords, true if found */
bool GetSignLines (int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4); // Lua-accessible
diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp
index b5795fbaf..7f999fd31 100644
--- a/src/ChunkMap.cpp
+++ b/src/ChunkMap.cpp
@@ -2200,6 +2200,24 @@ bool cChunkMap::DoWithMobHeadBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, c
+bool cChunkMap::DoWithFlowerPotAt(int a_BlockX, int a_BlockY, int a_BlockZ, cFlowerPotCallback & a_Callback)
+{
+ int ChunkX, ChunkZ;
+ int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ;
+ cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ);
+ cCSLock Lock(m_CSLayers);
+ cChunkPtr Chunk = GetChunkNoGen(ChunkX, ZERO_CHUNK_Y, ChunkZ);
+ if ((Chunk == NULL) && !Chunk->IsValid())
+ {
+ return false;
+ }
+ return Chunk->DoWithFlowerPotAt(a_BlockX, a_BlockY, a_BlockZ, a_Callback);
+}
+
+
+
+
+
bool cChunkMap::GetSignLines(int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4)
{
int ChunkX, ChunkZ;
diff --git a/src/ChunkMap.h b/src/ChunkMap.h
index 9df68c403..6d35b2ebf 100644
--- a/src/ChunkMap.h
+++ b/src/ChunkMap.h
@@ -26,6 +26,7 @@ class cFurnaceEntity;
class cNoteEntity;
class cCommandBlockEntity;
class cMobHeadEntity;
+class cFlowerPotEntity;
class cPawn;
class cPickup;
class cChunkDataSerializer;
@@ -41,6 +42,7 @@ typedef cItemCallback cChestCallback;
typedef cItemCallback cDispenserCallback;
typedef cItemCallback cDropperCallback;
typedef cItemCallback cDropSpenserCallback;
+typedef cItemCallback cFlowerPotCallback;
typedef cItemCallback cFurnaceCallback;
typedef cItemCallback cNoteBlockCallback;
typedef cItemCallback cCommandBlockCallback;
@@ -259,6 +261,9 @@ public:
/** Calls the callback for the mob head block at the specified coords; returns false if there's no mob head block at those coords or callback returns true, returns true if found */
bool DoWithMobHeadBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cMobHeadBlockCallback & a_Callback); // Lua-accessible
+ /** Calls the callback for the flower pot at the specified coords; returns false if there's no flower pot at those coords or callback returns true, returns true if found */
+ bool DoWithFlowerPotAt(int a_BlockX, int a_BlockY, int a_BlockZ, cFlowerPotCallback & a_Callback); // Lua-accessible
+
/** Retrieves the test on the sign at the specified coords; returns false if there's no sign at those coords, true if found */
bool GetSignLines (int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4); // Lua-accessible
diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp
index 992023464..18646254f 100644
--- a/src/Protocol/Protocol17x.cpp
+++ b/src/Protocol/Protocol17x.cpp
@@ -29,6 +29,7 @@ Implements the 1.7.x protocol classes:
#include "../UI/Window.h"
#include "../BlockEntities/CommandBlockEntity.h"
#include "../BlockEntities/MobHeadEntity.h"
+#include "../BlockEntities/FlowerPotEntity.h"
#include "../CompositeChat.h"
@@ -1115,6 +1116,7 @@ void cProtocol172::SendUpdateBlockEntity(cBlockEntity & a_BlockEntity)
case E_BLOCK_MOB_SPAWNER: Action = 1; break; // Update mob spawner spinny mob thing
case E_BLOCK_COMMAND_BLOCK: Action = 2; break; // Update command block text
case E_BLOCK_HEAD: Action = 4; break; // Update Mobhead entity
+ case E_BLOCK_FLOWER_POT: Action = 5; break; // Update flower pot
default: ASSERT(!"Unhandled or unimplemented BlockEntity update request!"); break;
}
Pkt.WriteByte(Action);
@@ -2345,7 +2347,7 @@ void cProtocol172::cPacketizer::WriteBlockEntity(const cBlockEntity & a_BlockEnt
case E_BLOCK_HEAD:
{
cMobHeadEntity & MobHeadEntity = (cMobHeadEntity &)a_BlockEntity;
-
+
Writer.AddInt("x", MobHeadEntity.GetPosX());
Writer.AddInt("y", MobHeadEntity.GetPosY());
Writer.AddInt("z", MobHeadEntity.GetPosZ());
@@ -2355,6 +2357,18 @@ void cProtocol172::cPacketizer::WriteBlockEntity(const cBlockEntity & a_BlockEnt
Writer.AddString("id", "Skull"); // "Tile Entity ID" - MC wiki; vanilla server always seems to send this though
break;
}
+ case E_BLOCK_FLOWER_POT:
+ {
+ cFlowerPotEntity & FlowerPotEntity = (cFlowerPotEntity &)a_BlockEntity;
+
+ Writer.AddInt("x", FlowerPotEntity.GetPosX());
+ Writer.AddInt("y", FlowerPotEntity.GetPosY());
+ Writer.AddInt("z", FlowerPotEntity.GetPosZ());
+ Writer.AddInt("Item", (Int32) FlowerPotEntity.GetItem().m_ItemType);
+ Writer.AddInt("Data", (Int32) FlowerPotEntity.GetItem().m_ItemDamage);
+ Writer.AddString("id", "FlowerPot"); // "Tile Entity ID" - MC wiki; vanilla server always seems to send this though
+ break;
+ }
default: break;
}
diff --git a/src/World.cpp b/src/World.cpp
index 37c07b398..335c6a00d 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -1206,6 +1206,15 @@ bool cWorld::DoWithMobHeadBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cMob
+bool cWorld::DoWithFlowerPotAt(int a_BlockX, int a_BlockY, int a_BlockZ, cFlowerPotCallback & a_Callback)
+{
+ return m_ChunkMap->DoWithFlowerPotAt(a_BlockX, a_BlockY, a_BlockZ, a_Callback);
+}
+
+
+
+
+
bool cWorld::GetSignLines(int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4)
{
return m_ChunkMap->GetSignLines(a_BlockX, a_BlockY, a_BlockZ, a_Line1, a_Line2, a_Line3, a_Line4);
diff --git a/src/World.h b/src/World.h
index 93397c014..ee74742c4 100644
--- a/src/World.h
+++ b/src/World.h
@@ -44,6 +44,7 @@ class cWorldGenerator; // The generator that actually generates the chunks for
class cChunkGenerator; // The thread responsible for generating chunks
class cChestEntity;
class cDispenserEntity;
+class cFlowerPotEntity;
class cFurnaceEntity;
class cNoteEntity;
class cMobHeadEntity;
@@ -61,6 +62,7 @@ typedef cItemCallback cFurnaceCallback;
typedef cItemCallback cNoteBlockCallback;
typedef cItemCallback cCommandBlockCallback;
typedef cItemCallback cMobHeadBlockCallback;
+typedef cItemCallback cFlowerPotCallback;
@@ -531,10 +533,13 @@ public:
/** Calls the callback for the command block at the specified coords; returns false if there's no command block at those coords or callback returns true, returns true if found */
bool DoWithCommandBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cCommandBlockCallback & a_Callback); // Exported in ManualBindings.cpp
-
+
/** Calls the callback for the mob head block at the specified coords; returns false if there's no mob head block at those coords or callback returns true, returns true if found */
bool DoWithMobHeadBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cMobHeadBlockCallback & a_Callback); // Exported in ManualBindings.cpp
-
+
+ /** Calls the callback for the flower pot at the specified coords; returns false if there's no flower pot at those coords or callback returns true, returns true if found */
+ bool DoWithFlowerPotAt(int a_BlockX, int a_BlockY, int a_BlockZ, cFlowerPotCallback & a_Callback); // Exported in ManualBindings.cpp
+
/** Retrieves the test on the sign at the specified coords; returns false if there's no sign at those coords, true if found */
bool GetSignLines (int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4); // Exported in ManualBindings.cpp
diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp
index c1c659b36..6d0e29958 100644
--- a/src/WorldStorage/NBTChunkSerializer.cpp
+++ b/src/WorldStorage/NBTChunkSerializer.cpp
@@ -20,6 +20,7 @@
#include "../BlockEntities/NoteEntity.h"
#include "../BlockEntities/SignEntity.h"
#include "../BlockEntities/MobHeadEntity.h"
+#include "../BlockEntities/FlowerPotEntity.h"
#include "../Entities/Entity.h"
#include "../Entities/FallingBlock.h"
@@ -275,6 +276,19 @@ void cNBTChunkSerializer::AddMobHeadEntity(cMobHeadEntity * a_MobHead)
+void cNBTChunkSerializer::AddFlowerPotEntity(cFlowerPotEntity * a_FlowerPot)
+{
+ m_Writer.BeginCompound("");
+ AddBasicTileEntity(a_FlowerPot, "FlowerPot");
+ m_Writer.AddInt ("Item", (Int32) a_FlowerPot->GetItem().m_ItemType);
+ m_Writer.AddInt ("Data", (Int32) a_FlowerPot->GetItem().m_ItemDamage);
+ m_Writer.EndCompound();
+}
+
+
+
+
+
void cNBTChunkSerializer::AddBasicEntity(cEntity * a_Entity, const AString & a_ClassName)
{
m_Writer.AddString("id", a_ClassName);
@@ -687,6 +701,7 @@ void cNBTChunkSerializer::BlockEntity(cBlockEntity * a_Entity)
case E_BLOCK_CHEST: AddChestEntity ((cChestEntity *) a_Entity); break;
case E_BLOCK_DISPENSER: AddDispenserEntity ((cDispenserEntity *) a_Entity); break;
case E_BLOCK_DROPPER: AddDropperEntity ((cDropperEntity *) a_Entity); break;
+ case E_BLOCK_FLOWER_POT: AddFlowerPotEntity ((cFlowerPotEntity *) a_Entity); break;
case E_BLOCK_FURNACE: AddFurnaceEntity ((cFurnaceEntity *) a_Entity); break;
case E_BLOCK_HOPPER: AddHopperEntity ((cHopperEntity *) a_Entity); break;
case E_BLOCK_SIGN_POST:
diff --git a/src/WorldStorage/NBTChunkSerializer.h b/src/WorldStorage/NBTChunkSerializer.h
index 5f9e16ed1..8a9e18413 100644
--- a/src/WorldStorage/NBTChunkSerializer.h
+++ b/src/WorldStorage/NBTChunkSerializer.h
@@ -30,6 +30,7 @@ class cJukeboxEntity;
class cNoteEntity;
class cSignEntity;
class cMobHeadEntity;
+class cFlowerPotEntity;
class cFallingBlock;
class cMinecart;
class cMinecartWithChest;
@@ -96,6 +97,7 @@ protected:
void AddSignEntity (cSignEntity * a_Sign);
void AddMobHeadEntity (cMobHeadEntity * a_MobHead);
void AddCommandBlockEntity(cCommandBlockEntity * a_CmdBlock);
+ void AddFlowerPotEntity(cFlowerPotEntity * a_FlowerPot);
// Entities:
void AddBasicEntity (cEntity * a_Entity, const AString & a_ClassName);
diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp
index 05332d23d..680f2458f 100644
--- a/src/WorldStorage/WSSAnvil.cpp
+++ b/src/WorldStorage/WSSAnvil.cpp
@@ -25,6 +25,7 @@
#include "../BlockEntities/NoteEntity.h"
#include "../BlockEntities/SignEntity.h"
#include "../BlockEntities/MobHeadEntity.h"
+#include "../BlockEntities/FlowerPotEntity.h"
#include "../Mobs/Monster.h"
@@ -578,6 +579,10 @@ void cWSSAnvil::LoadBlockEntitiesFromNBT(cBlockEntityList & a_BlockEntities, con
{
LoadDropperFromNBT(a_BlockEntities, a_NBT, Child);
}
+ else if (strncmp(a_NBT.GetData(sID), "FlowerPot", a_NBT.GetDataLength(sID)) == 0)
+ {
+ LoadFlowerPotFromNBT(a_BlockEntities, a_NBT, Child);
+ }
else if (strncmp(a_NBT.GetData(sID), "Furnace", a_NBT.GetDataLength(sID)) == 0)
{
LoadFurnaceFromNBT(a_BlockEntities, a_NBT, Child, a_BlockTypes, a_BlockMetas);
@@ -760,6 +765,37 @@ void cWSSAnvil::LoadDropperFromNBT(cBlockEntityList & a_BlockEntities, const cPa
+void cWSSAnvil::LoadFlowerPotFromNBT(cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx)
+{
+ ASSERT(a_NBT.GetType(a_TagIdx) == TAG_Compound);
+ int x, y, z;
+ if (!GetBlockEntityNBTPos(a_NBT, a_TagIdx, x, y, z))
+ {
+ return;
+ }
+ std::auto_ptr FlowerPot(new cFlowerPotEntity(x, y, z, m_World));
+ short ItemType = 0, ItemData = 0;
+
+ int currentLine = a_NBT.FindChildByName(a_TagIdx, "Item");
+ if (currentLine >= 0)
+ {
+ ItemType = (short) a_NBT.GetInt(currentLine);
+ }
+
+ currentLine = a_NBT.FindChildByName(a_TagIdx, "Data");
+ if (currentLine >= 0)
+ {
+ ItemData = (short) a_NBT.GetInt(currentLine);
+ }
+
+ FlowerPot->SetItem(cItem(ItemType, 1, ItemData));
+ a_BlockEntities.push_back(FlowerPot.release());
+}
+
+
+
+
+
void cWSSAnvil::LoadFurnaceFromNBT(cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx, BLOCKTYPE * a_BlockTypes, NIBBLETYPE * a_BlockMetas)
{
ASSERT(a_NBT.GetType(a_TagIdx) == TAG_Compound);
diff --git a/src/WorldStorage/WSSAnvil.h b/src/WorldStorage/WSSAnvil.h
index 4acf3f2a1..b26345b13 100644
--- a/src/WorldStorage/WSSAnvil.h
+++ b/src/WorldStorage/WSSAnvil.h
@@ -135,6 +135,7 @@ protected:
void LoadChestFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx);
void LoadDispenserFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx);
void LoadDropperFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx);
+ void LoadFlowerPotFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx);
void LoadFurnaceFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx, BLOCKTYPE * a_BlockTypes, NIBBLETYPE * a_BlockMetas);
void LoadHopperFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx);
void LoadJukeboxFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx);
diff --git a/src/WorldStorage/WSSCompact.cpp b/src/WorldStorage/WSSCompact.cpp
index 4c0684dd8..5e49e4909 100644
--- a/src/WorldStorage/WSSCompact.cpp
+++ b/src/WorldStorage/WSSCompact.cpp
@@ -12,8 +12,10 @@
#include "../BlockEntities/ChestEntity.h"
#include "../BlockEntities/CommandBlockEntity.h"
#include "../BlockEntities/DispenserEntity.h"
+#include "../BlockEntities/FlowerPotEntity.h"
#include "../BlockEntities/FurnaceEntity.h"
#include "../BlockEntities/JukeboxEntity.h"
+#include "../BlockEntities/MobHeadEntity.h"
#include "../BlockEntities/NoteEntity.h"
#include "../BlockEntities/SignEntity.h"
@@ -75,12 +77,14 @@ void cJsonChunkSerializer::BlockEntity(cBlockEntity * a_BlockEntity)
case E_BLOCK_CHEST: SaveInto = "Chests"; break;
case E_BLOCK_DISPENSER: SaveInto = "Dispensers"; break;
case E_BLOCK_DROPPER: SaveInto = "Droppers"; break;
+ case E_BLOCK_FLOWER_POT: SaveInto = "FlowerPots"; break;
case E_BLOCK_FURNACE: SaveInto = "Furnaces"; break;
case E_BLOCK_SIGN_POST: SaveInto = "Signs"; break;
case E_BLOCK_WALLSIGN: SaveInto = "Signs"; break;
case E_BLOCK_NOTE_BLOCK: SaveInto = "Notes"; break;
case E_BLOCK_JUKEBOX: SaveInto = "Jukeboxes"; break;
case E_BLOCK_COMMAND_BLOCK: SaveInto = "CommandBlocks"; break;
+ case E_BLOCK_HEAD: SaveInto = "MobHeads"; break;
default:
{
@@ -298,6 +302,21 @@ void cWSSCompact::LoadEntitiesFromJson(Json::Value & a_Value, cEntityList & a_En
}
} // for itr - AllDispensers[]
+ // Load Flowerpots:
+ Json::Value AllFlowerPots = a_Value.get("FlowerPots", Json::nullValue);
+ for (Json::Value::iterator itr = AllFlowerPots.begin(); itr != AllFlowerPots.end(); ++itr)
+ {
+ std::auto_ptr FlowerPotEntity(new cFlowerPotEntity(0, 0, 0, a_World));
+ if (!FlowerPotEntity->LoadFromJson(*itr))
+ {
+ LOGWARNING("ERROR READING FLOWERPOT FROM JSON!" );
+ }
+ else
+ {
+ a_BlockEntities.push_back(FlowerPotEntity.release());
+ }
+ } // for itr - AllFlowerPots[]
+
// Load furnaces:
Json::Value AllFurnaces = a_Value.get("Furnaces", Json::nullValue);
for (Json::Value::iterator itr = AllFurnaces.begin(); itr != AllFurnaces.end(); ++itr)
@@ -331,7 +350,7 @@ void cWSSCompact::LoadEntitiesFromJson(Json::Value & a_Value, cEntityList & a_En
// Load note blocks:
Json::Value AllNotes = a_Value.get("Notes", Json::nullValue);
- for( Json::Value::iterator itr = AllNotes.begin(); itr != AllNotes.end(); ++itr )
+ for (Json::Value::iterator itr = AllNotes.begin(); itr != AllNotes.end(); ++itr)
{
std::auto_ptr NoteEntity(new cNoteEntity(0, 0, 0, a_World));
if (!NoteEntity->LoadFromJson(*itr))
@@ -346,7 +365,7 @@ void cWSSCompact::LoadEntitiesFromJson(Json::Value & a_Value, cEntityList & a_En
// Load jukeboxes:
Json::Value AllJukeboxes = a_Value.get("Jukeboxes", Json::nullValue);
- for( Json::Value::iterator itr = AllJukeboxes.begin(); itr != AllJukeboxes.end(); ++itr )
+ for (Json::Value::iterator itr = AllJukeboxes.begin(); itr != AllJukeboxes.end(); ++itr)
{
std::auto_ptr JukeboxEntity(new cJukeboxEntity(0, 0, 0, a_World));
if (!JukeboxEntity->LoadFromJson(*itr))
@@ -361,7 +380,7 @@ void cWSSCompact::LoadEntitiesFromJson(Json::Value & a_Value, cEntityList & a_En
// Load command blocks:
Json::Value AllCommandBlocks = a_Value.get("CommandBlocks", Json::nullValue);
- for( Json::Value::iterator itr = AllCommandBlocks.begin(); itr != AllCommandBlocks.end(); ++itr )
+ for (Json::Value::iterator itr = AllCommandBlocks.begin(); itr != AllCommandBlocks.end(); ++itr)
{
std::auto_ptr CommandBlockEntity(new cCommandBlockEntity(0, 0, 0, a_World));
if (!CommandBlockEntity->LoadFromJson(*itr))
@@ -373,6 +392,21 @@ void cWSSCompact::LoadEntitiesFromJson(Json::Value & a_Value, cEntityList & a_En
a_BlockEntities.push_back(CommandBlockEntity.release());
}
} // for itr - AllCommandBlocks[]
+
+ // Load mob heads:
+ Json::Value AllMobHeads = a_Value.get("MobHeads", Json::nullValue);
+ for (Json::Value::iterator itr = AllMobHeads.begin(); itr != AllMobHeads.end(); ++itr)
+ {
+ std::auto_ptr MobHeadEntity(new cMobHeadEntity(0, 0, 0, a_World));
+ if (!MobHeadEntity->LoadFromJson(*itr))
+ {
+ LOGWARNING("ERROR READING MOB HEAD FROM JSON!" );
+ }
+ else
+ {
+ a_BlockEntities.push_back(MobHeadEntity.release());
+ }
+ } // for itr - AllMobHeads[]
}
--
cgit v1.2.3
From 97d803e34f51470774a6bfc2232cae0b041a1aa0 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Fri, 7 Mar 2014 09:17:13 +0100
Subject: Added cBlockArea serialization to string.
Fixes #665.
---
src/Bindings/ManualBindings.cpp | 73 +++++++++++++--
src/WorldStorage/SchematicFileSerializer.cpp | 134 +++++++++++++++++++++------
src/WorldStorage/SchematicFileSerializer.h | 33 ++++++-
3 files changed, 202 insertions(+), 38 deletions(-)
diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp
index 9fbc2e842..f9d04ce90 100644
--- a/src/Bindings/ManualBindings.cpp
+++ b/src/Bindings/ManualBindings.cpp
@@ -2483,6 +2483,37 @@ static int tolua_cBlockArea_LoadFromSchematicFile(lua_State * tolua_S)
+static int tolua_cBlockArea_LoadFromSchematicString(lua_State * tolua_S)
+{
+ // function cBlockArea::LoadFromSchematicString
+ // Exported manually because function has been moved to SchematicFileSerilizer.cpp
+ cLuaState L(tolua_S);
+ if (
+ !L.CheckParamUserType(1, "cBlockArea") ||
+ !L.CheckParamString (2) ||
+ !L.CheckParamEnd (3)
+ )
+ {
+ return 0;
+ }
+ cBlockArea * self = (cBlockArea *)tolua_tousertype(tolua_S, 1, NULL);
+ if (self == NULL)
+ {
+ tolua_error(tolua_S, "invalid 'self' in function 'cBlockArea::LoadFromSchematicFile'", NULL);
+ return 0;
+ }
+
+ AString Data;
+ L.GetStackValue(2, Data);
+ bool res = cSchematicFileSerializer::LoadFromSchematicString(*self, Data);
+ tolua_pushboolean(tolua_S, res);
+ return 1;
+}
+
+
+
+
+
static int tolua_cBlockArea_SaveToSchematicFile(lua_State * tolua_S)
{
// function cBlockArea::SaveToSchematicFile
@@ -2512,6 +2543,34 @@ static int tolua_cBlockArea_SaveToSchematicFile(lua_State * tolua_S)
+static int tolua_cBlockArea_SaveToSchematicString(lua_State * tolua_S)
+{
+ // function cBlockArea::SaveToSchematicString
+ // Exported manually because function has been moved to SchematicFileSerilizer.cpp
+ cLuaState L(tolua_S);
+ if (
+ !L.CheckParamUserType(1, "cBlockArea") ||
+ !L.CheckParamEnd (2)
+ )
+ {
+ return 0;
+ }
+ cBlockArea * self = (cBlockArea *)tolua_tousertype(tolua_S, 1, NULL);
+ if (self == NULL)
+ {
+ tolua_error(tolua_S, "invalid 'self' in function 'cBlockArea::SaveToSchematicFile'", NULL);
+ return 0;
+ }
+
+ AString Data = cSchematicFileSerializer::SaveToSchematicString(*self);
+ L.Push(Data);
+ return 1;
+}
+
+
+
+
+
static int tolua_cCompositeChat_AddRunCommandPart(lua_State * tolua_S)
{
// function cCompositeChat:AddRunCommandPart(Message, Command, [Style])
@@ -2775,12 +2834,14 @@ void ManualBindings::Bind(lua_State * tolua_S)
tolua_endmodule(tolua_S);
tolua_beginmodule(tolua_S, "cBlockArea");
- tolua_function(tolua_S, "GetBlockTypeMeta", tolua_cBlockArea_GetBlockTypeMeta);
- tolua_function(tolua_S, "GetOrigin", tolua_cBlockArea_GetOrigin);
- tolua_function(tolua_S, "GetRelBlockTypeMeta", tolua_cBlockArea_GetRelBlockTypeMeta);
- tolua_function(tolua_S, "GetSize", tolua_cBlockArea_GetSize);
- tolua_function(tolua_S, "LoadFromSchematicFile", tolua_cBlockArea_LoadFromSchematicFile);
- tolua_function(tolua_S, "SaveToSchematicFile", tolua_cBlockArea_SaveToSchematicFile);
+ tolua_function(tolua_S, "GetBlockTypeMeta", tolua_cBlockArea_GetBlockTypeMeta);
+ tolua_function(tolua_S, "GetOrigin", tolua_cBlockArea_GetOrigin);
+ tolua_function(tolua_S, "GetRelBlockTypeMeta", tolua_cBlockArea_GetRelBlockTypeMeta);
+ tolua_function(tolua_S, "GetSize", tolua_cBlockArea_GetSize);
+ tolua_function(tolua_S, "LoadFromSchematicFile", tolua_cBlockArea_LoadFromSchematicFile);
+ tolua_function(tolua_S, "LoadFromSchematicString", tolua_cBlockArea_LoadFromSchematicString);
+ tolua_function(tolua_S, "SaveToSchematicFile", tolua_cBlockArea_SaveToSchematicFile);
+ tolua_function(tolua_S, "SaveToSchematicString", tolua_cBlockArea_SaveToSchematicString);
tolua_endmodule(tolua_S);
tolua_beginmodule(tolua_S, "cCompositeChat");
diff --git a/src/WorldStorage/SchematicFileSerializer.cpp b/src/WorldStorage/SchematicFileSerializer.cpp
index 45fd967bd..a6ae8d8e0 100644
--- a/src/WorldStorage/SchematicFileSerializer.cpp
+++ b/src/WorldStorage/SchematicFileSerializer.cpp
@@ -1,10 +1,18 @@
+// SchematicFileSerializer.cpp
+
+// Implements the cSchematicFileSerializer class representing the interface to load and save cBlockArea to a .schematic file
+
#include "Globals.h"
#include "OSSupport/GZipFile.h"
#include "FastNBT.h"
-
#include "SchematicFileSerializer.h"
+#include "../StringCompression.h"
+
+
+
+
bool cSchematicFileSerializer::LoadFromSchematicFile(cBlockArea & a_BlockArea, const AString & a_FileName)
{
@@ -40,48 +48,51 @@ bool cSchematicFileSerializer::LoadFromSchematicFile(cBlockArea & a_BlockArea, c
-bool cSchematicFileSerializer::SaveToSchematicFile(cBlockArea & a_BlockArea, const AString & a_FileName)
+bool cSchematicFileSerializer::LoadFromSchematicString(cBlockArea & a_BlockArea, const AString & a_SchematicData)
{
- cFastNBTWriter Writer("Schematic");
- Writer.AddShort("Width", a_BlockArea.m_SizeX);
- Writer.AddShort("Height", a_BlockArea.m_SizeY);
- Writer.AddShort("Length", a_BlockArea.m_SizeZ);
- Writer.AddString("Materials", "Alpha");
- if (a_BlockArea.HasBlockTypes())
+ // Uncompress the data:
+ AString UngzippedData;
+ if (UncompressStringGZIP(a_SchematicData.data(), a_SchematicData.size(), UngzippedData) != Z_OK)
{
- Writer.AddByteArray("Blocks", (const char *)a_BlockArea.m_BlockTypes, a_BlockArea.GetBlockCount());
- }
- else
- {
- AString Dummy(a_BlockArea.GetBlockCount(), 0);
- Writer.AddByteArray("Blocks", Dummy.data(), Dummy.size());
+ LOG("%s: Cannot unGZip the schematic data.", __FUNCTION__);
+ return false;
}
- if (a_BlockArea.HasBlockMetas())
+
+ // Parse the NBT:
+ cParsedNBT NBT(UngzippedData.data(), UngzippedData.size());
+ if (!NBT.IsValid())
{
- Writer.AddByteArray("Data", (const char *)a_BlockArea.m_BlockMetas, a_BlockArea.GetBlockCount());
+ LOG("%s: Cannot parse the NBT in the schematic data.", __FUNCTION__);
+ return false;
}
- else
+
+ return LoadFromSchematicNBT(a_BlockArea, NBT);
+}
+
+
+
+
+
+bool cSchematicFileSerializer::SaveToSchematicFile(const cBlockArea & a_BlockArea, const AString & a_FileName)
+{
+ // Serialize into NBT data:
+ AString NBT = SaveToSchematicNBT(a_BlockArea);
+ if (NBT.empty())
{
- AString Dummy(a_BlockArea.GetBlockCount(), 0);
- Writer.AddByteArray("Data", Dummy.data(), Dummy.size());
+ LOG("%s: Cannot serialize the area into an NBT representation for file \"%s\".", __FUNCTION__, a_FileName.c_str());
+ return false;
}
- // TODO: Save entities and block entities
- Writer.BeginList("Entities", TAG_Compound);
- Writer.EndList();
- Writer.BeginList("TileEntities", TAG_Compound);
- Writer.EndList();
- Writer.Finish();
// Save to file
cGZipFile File;
if (!File.Open(a_FileName, cGZipFile::fmWrite))
{
- LOG("Cannot open file \"%s\" for writing.", a_FileName.c_str());
+ LOG("%s: Cannot open file \"%s\" for writing.", __FUNCTION__, a_FileName.c_str());
return false;
}
- if (!File.Write(Writer.GetResult()))
+ if (!File.Write(NBT))
{
- LOG("Cannot write data to file \"%s\".", a_FileName.c_str());
+ LOG("%s: Cannot write data to file \"%s\".", __FUNCTION__, a_FileName.c_str());
return false;
}
return true;
@@ -92,6 +103,31 @@ bool cSchematicFileSerializer::SaveToSchematicFile(cBlockArea & a_BlockArea, con
+AString cSchematicFileSerializer::SaveToSchematicString(const cBlockArea & a_BlockArea)
+{
+ // Serialize into NBT data:
+ AString NBT = SaveToSchematicNBT(a_BlockArea);
+ if (NBT.empty())
+ {
+ LOG("%s: Cannot serialize the area into an NBT representation.", __FUNCTION__);
+ return false;
+ }
+
+ // Gzip the data:
+ AString Compressed;
+ int res = CompressStringGZIP(NBT.data(), NBT.size(), Compressed);
+ if (res != Z_OK)
+ {
+ LOG("%s: Cannot Gzip the area data NBT representation: %d", __FUNCTION__, res);
+ return false;
+ }
+ return Compressed;
+}
+
+
+
+
+
bool cSchematicFileSerializer::LoadFromSchematicNBT(cBlockArea & a_BlockArea, cParsedNBT & a_NBT)
{
int TMaterials = a_NBT.FindChildByName(a_NBT.GetRoot(), "Materials");
@@ -170,3 +206,45 @@ bool cSchematicFileSerializer::LoadFromSchematicNBT(cBlockArea & a_BlockArea, cP
}
+
+
+
+AString cSchematicFileSerializer::SaveToSchematicNBT(const cBlockArea & a_BlockArea)
+{
+ cFastNBTWriter Writer("Schematic");
+ Writer.AddShort("Width", a_BlockArea.m_SizeX);
+ Writer.AddShort("Height", a_BlockArea.m_SizeY);
+ Writer.AddShort("Length", a_BlockArea.m_SizeZ);
+ Writer.AddString("Materials", "Alpha");
+ if (a_BlockArea.HasBlockTypes())
+ {
+ Writer.AddByteArray("Blocks", (const char *)a_BlockArea.m_BlockTypes, a_BlockArea.GetBlockCount());
+ }
+ else
+ {
+ AString Dummy(a_BlockArea.GetBlockCount(), 0);
+ Writer.AddByteArray("Blocks", Dummy.data(), Dummy.size());
+ }
+ if (a_BlockArea.HasBlockMetas())
+ {
+ Writer.AddByteArray("Data", (const char *)a_BlockArea.m_BlockMetas, a_BlockArea.GetBlockCount());
+ }
+ else
+ {
+ AString Dummy(a_BlockArea.GetBlockCount(), 0);
+ Writer.AddByteArray("Data", Dummy.data(), Dummy.size());
+ }
+
+ // TODO: Save entities and block entities
+ Writer.BeginList("Entities", TAG_Compound);
+ Writer.EndList();
+ Writer.BeginList("TileEntities", TAG_Compound);
+ Writer.EndList();
+ Writer.Finish();
+
+ return Writer.GetResult();
+}
+
+
+
+
diff --git a/src/WorldStorage/SchematicFileSerializer.h b/src/WorldStorage/SchematicFileSerializer.h
index 9be2e5b57..f6ce1c16c 100644
--- a/src/WorldStorage/SchematicFileSerializer.h
+++ b/src/WorldStorage/SchematicFileSerializer.h
@@ -1,4 +1,12 @@
+// SchematicFileSerializer.h
+
+// Declares the cSchematicFileSerializer class representing the interface to load and save cBlockArea to a .schematic file
+
+
+
+
+
#pragma once
#include "../BlockArea.h"
@@ -13,17 +21,34 @@ class cParsedNBT;
+
class cSchematicFileSerializer
{
public:
- /// Loads an area from a .schematic file. Returns true if successful
+ /** Loads an area from a .schematic file. Returns true if successful. */
static bool LoadFromSchematicFile(cBlockArea & a_BlockArea, const AString & a_FileName);
- /// Saves the area into a .schematic file. Returns true if successful
- static bool SaveToSchematicFile(cBlockArea & a_BlockArea, const AString & a_FileName);
+ /** Loads an area from a string containing the .schematic file data. Returns true if successful. */
+ static bool LoadFromSchematicString(cBlockArea & a_BlockArea, const AString & a_SchematicData);
+
+ /** Saves the area into a .schematic file. Returns true if successful. */
+ static bool SaveToSchematicFile(const cBlockArea & a_BlockArea, const AString & a_FileName);
+
+ /** Saves the area into a string containing the .schematic file data.
+ Returns the data, or empty string if failed. */
+ static AString SaveToSchematicString(const cBlockArea & a_BlockArea);
private:
- /// Loads the area from a schematic file uncompressed and parsed into a NBT tree. Returns true if successful.
+ /** Loads the area from a schematic file uncompressed and parsed into a NBT tree.
+ Returns true if successful. */
static bool LoadFromSchematicNBT(cBlockArea & a_BlockArea, cParsedNBT & a_NBT);
+
+ /** Saves the area into a NBT representation and returns the NBT data as a string.
+ Returns an empty string if failed. */
+ static AString SaveToSchematicNBT(const cBlockArea & a_BlockArea);
};
+
+
+
+
--
cgit v1.2.3
From 166ab59582d90194a6fcd6849afe8f2e60d64019 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Fri, 7 Mar 2014 09:17:42 +0100
Subject: APIDump: Documented cBlockArea string-serialization functions.
---
MCServer/Plugins/APIDump/APIDesc.lua | 2 ++
1 file changed, 2 insertions(+)
diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua
index 94cdd0063..30ce4cc2b 100644
--- a/MCServer/Plugins/APIDump/APIDesc.lua
+++ b/MCServer/Plugins/APIDump/APIDesc.lua
@@ -134,6 +134,7 @@ g_APIDesc =
HasBlockSkyLights = { Params = "", Return = "bool", Notes = "Returns true if current datatypes include skylight" },
HasBlockTypes = { Params = "", Return = "bool", Notes = "Returns true if current datatypes include block types" },
LoadFromSchematicFile = { Params = "FileName", Return = "", Notes = "Clears current content and loads new content from the specified schematic file. Returns true if successful. Returns false and logs error if unsuccessful, old content is preserved in such a case." },
+ LoadFromSchematicString = { Params = "SchematicData", Return = "", Notes = "Clears current content and loads new content from the specified string (assumed to contain .schematic data). Returns true if successful. Returns false and logs error if unsuccessful, old content is preserved in such a case." },
Merge =
{
{ Params = "BlockAreaSrc, {{Vector3i|RelMinCoords}}, Strategy", Return = "", Notes = "Merges BlockAreaSrc into this object at the specified relative coords, using the specified strategy" },
@@ -161,6 +162,7 @@ g_APIDesc =
RotateCW = { Params = "", Return = "", Notes = "Rotates the block area around the Y axis, clockwise (north -> east). Modifies blocks' metas (if present) to match." },
RotateCWNoMeta = { Params = "", Return = "", Notes = "Rotates the block area around the Y axis, clockwise (north -> east). Doesn't modify blocks' metas." },
SaveToSchematicFile = { Params = "FileName", Return = "", Notes = "Saves the current contents to a schematic file. Returns true if successful." },
+ SaveToSchematicString = { Params = "", Return = "string", Notes = "Saves the current contents to a string (in a .schematic file format). Returns the data if successful, empty string if failed." },
SetBlockLight = { Params = "BlockX, BlockY, BlockZ, BlockLight", Return = "", Notes = "Sets the blocklight at the specified absolute coords" },
SetBlockMeta = { Params = "BlockX, BlockY, BlockZ, BlockMeta", Return = "", Notes = "Sets the block meta at the specified absolute coords" },
SetBlockSkyLight = { Params = "BlockX, BlockY, BlockZ, SkyLight", Return = "", Notes = "Sets the skylight at the specified absolute coords" },
--
cgit v1.2.3
From f6aaeb74a9bb50488c2c5b5732f43dae4beef15c Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Fri, 7 Mar 2014 09:18:10 +0100
Subject: Debuggers: Added a test of the cBlockArea string-serialization.
---
MCServer/Plugins/Debuggers/Debuggers.lua | 38 ++++++++++++++++++++++++++++++++
1 file changed, 38 insertions(+)
diff --git a/MCServer/Plugins/Debuggers/Debuggers.lua b/MCServer/Plugins/Debuggers/Debuggers.lua
index 329a652cd..f99c48242 100644
--- a/MCServer/Plugins/Debuggers/Debuggers.lua
+++ b/MCServer/Plugins/Debuggers/Debuggers.lua
@@ -71,6 +71,8 @@ function Initialize(Plugin)
-- TestExpatBindings();
-- TestPluginCalls();
+ TestBlockAreasString()
+
return true
end;
@@ -202,6 +204,42 @@ end
+function TestBlockAreasString()
+ -- Write one area to string, then to file:
+ local BA1 = cBlockArea()
+ BA1:Create(5, 5, 5, cBlockArea.baTypes + cBlockArea.baMetas)
+ BA1:Fill(cBlockArea.baTypes, E_BLOCK_DIAMOND_BLOCK)
+ BA1:FillRelCuboid(1, 3, 1, 3, 1, 3, cBlockArea.baTypes, E_BLOCK_GOLD_BLOCK)
+ local Data = BA1:SaveToSchematicString()
+ if ((type(Data) ~= "string") or (Data == "")) then
+ LOG("Cannot save schematic to string")
+ return
+ end
+ cFile:CreateFolder("schematics")
+ local f = io.open("schematics/StringTest.schematic", "w")
+ f:write(Data)
+ f:close()
+
+ -- Load a second area from that file:
+ local BA2 = cBlockArea()
+ if not(BA2:LoadFromSchematicFile("schematics/StringTest.schematic")) then
+ LOG("Cannot read schematic from string test file")
+ return
+ end
+ BA2:Clear()
+
+ -- Load another area from a string in that file:
+ f = io.open("schematics/StringTest.schematic", "r")
+ Data = f:read("*all")
+ if not(BA2:LoadFromSchematicString(Data)) then
+ LOG("Cannot load schematic from string")
+ end
+end
+
+
+
+
+
function TestSQLiteBindings()
LOG("Testing SQLite bindings...");
--
cgit v1.2.3
From 31df0268089b931b36d009bcf843a59107682d02 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Fri, 7 Mar 2014 10:25:18 +0100
Subject: Rewound PolarSSL to master branch.
The current Devel branch fails to build on RasPi.
---
lib/polarssl | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/polarssl b/lib/polarssl
index 2ceda5798..2cb1a0c40 160000
--- a/lib/polarssl
+++ b/lib/polarssl
@@ -1 +1 @@
-Subproject commit 2ceda579893ceb23c5eb0d56df47dc235644e0f4
+Subproject commit 2cb1a0c4009ecf368ecc74eb428394e10f9e6d00
--
cgit v1.2.3
From c2090c0d11313bd67b02c482f1ca80d5c4567d27 Mon Sep 17 00:00:00 2001
From: Howaner
Date: Fri, 7 Mar 2014 11:44:16 +0100
Subject: Add Lua Bindings for FlowerPotEntity.h and add documentation.
---
src/Bindings/AllToLua.pkg | 2 ++
src/Bindings/ManualBindings.cpp | 2 +-
src/Blocks/BlockMobHead.h | 5 +++--
src/CMakeLists.txt | 1 +
src/Chunk.cpp | 2 +-
src/Chunk.h | 4 ++--
src/ChunkMap.cpp | 4 ++--
src/ChunkMap.h | 4 ++--
src/World.cpp | 4 ++--
src/World.h | 4 ++--
10 files changed, 18 insertions(+), 14 deletions(-)
diff --git a/src/Bindings/AllToLua.pkg b/src/Bindings/AllToLua.pkg
index 6b067b1e5..2676281f9 100644
--- a/src/Bindings/AllToLua.pkg
+++ b/src/Bindings/AllToLua.pkg
@@ -58,6 +58,8 @@ $cfile "../BlockEntities/HopperEntity.h"
$cfile "../BlockEntities/JukeboxEntity.h"
$cfile "../BlockEntities/NoteEntity.h"
$cfile "../BlockEntities/SignEntity.h"
+$cfile "../BlockEntities/MobHeadEntity.h"
+$cfile "../BlockEntities/FlowerPotEntity.h"
$cfile "../WebAdmin.h"
$cfile "../Root.h"
$cfile "../Vector3f.h"
diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp
index 3570b2c1e..b094da5fc 100644
--- a/src/Bindings/ManualBindings.cpp
+++ b/src/Bindings/ManualBindings.cpp
@@ -2820,7 +2820,7 @@ void ManualBindings::Bind(lua_State * tolua_S)
tolua_function(tolua_S, "DoWithFurnaceAt", tolua_DoWithXYZ);
tolua_function(tolua_S, "DoWithNoteBlockAt", tolua_DoWithXYZ);
tolua_function(tolua_S, "DoWithCommandBlockAt", tolua_DoWithXYZ);
- tolua_function(tolua_S, "DoWithMobHeadBlockAt", tolua_DoWithXYZ);
+ tolua_function(tolua_S, "DoWithMobHeadAt", tolua_DoWithXYZ);
tolua_function(tolua_S, "DoWithFlowerPotAt", tolua_DoWithXYZ);
tolua_function(tolua_S, "DoWithPlayer", tolua_DoWith< cWorld, cPlayer, &cWorld::DoWithPlayer>);
tolua_function(tolua_S, "FindAndDoWithPlayer", tolua_DoWith< cWorld, cPlayer, &cWorld::FindAndDoWithPlayer>);
diff --git a/src/Blocks/BlockMobHead.h b/src/Blocks/BlockMobHead.h
index 6a00c3acd..2b128f13b 100644
--- a/src/Blocks/BlockMobHead.h
+++ b/src/Blocks/BlockMobHead.h
@@ -29,7 +29,7 @@ public:
BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta
) override
{
- class cCallback : public cMobHeadBlockCallback
+ class cCallback : public cMobHeadCallback
{
cPlayer * m_Player;
NIBBLETYPE m_OldBlockMeta;
@@ -45,6 +45,7 @@ public:
a_MobHeadEntity->SetType(static_cast(m_OldBlockMeta));
a_MobHeadEntity->SetRotation(static_cast(Rotation));
+ a_MobHeadEntity->GetWorld()->BroadcastBlockEntity(a_MobHeadEntity->GetPosX(), a_MobHeadEntity->GetPosY(), a_MobHeadEntity->GetPosZ(), m_Player->GetClientHandle());
return false;
}
@@ -59,7 +60,7 @@ public:
a_BlockMeta = a_BlockFace;
cWorld * World = (cWorld *) &a_WorldInterface;
- World->DoWithMobHeadBlockAt(a_BlockX, a_BlockY, a_BlockZ, Callback);
+ World->DoWithMobHeadAt(a_BlockX, a_BlockY, a_BlockZ, Callback);
a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, a_BlockMeta);
}
} ;
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 5e0731264..5029906aa 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -40,6 +40,7 @@ if (NOT MSVC)
BlockEntities/NoteEntity.h
BlockEntities/SignEntity.h
BlockEntities/MobHeadEntity.h
+ BlockEntities/FlowerPotEntity.h
BlockID.h
BoundingBox.h
ChatColor.h
diff --git a/src/Chunk.cpp b/src/Chunk.cpp
index b5b776147..957d7d575 100644
--- a/src/Chunk.cpp
+++ b/src/Chunk.cpp
@@ -2340,7 +2340,7 @@ bool cChunk::DoWithCommandBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cCom
-bool cChunk::DoWithMobHeadBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cMobHeadBlockCallback & a_Callback)
+bool cChunk::DoWithMobHeadAt(int a_BlockX, int a_BlockY, int a_BlockZ, cMobHeadCallback & a_Callback)
{
// The blockentity list is locked by the parent chunkmap's CS
for (cBlockEntityList::iterator itr = m_BlockEntities.begin(), itr2 = itr; itr != m_BlockEntities.end(); itr = itr2)
diff --git a/src/Chunk.h b/src/Chunk.h
index e8b46f631..b3fa563cc 100644
--- a/src/Chunk.h
+++ b/src/Chunk.h
@@ -49,7 +49,7 @@ typedef cItemCallback cDispenserCallback;
typedef cItemCallback cFurnaceCallback;
typedef cItemCallback cNoteBlockCallback;
typedef cItemCallback cCommandBlockCallback;
-typedef cItemCallback cMobHeadBlockCallback;
+typedef cItemCallback cMobHeadCallback;
typedef cItemCallback cFlowerPotCallback;
@@ -256,7 +256,7 @@ public:
bool DoWithCommandBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cCommandBlockCallback & a_Callback);
/** Calls the callback for the mob head block at the specified coords; returns false if there's no mob head block at those coords or callback returns true, returns true if found */
- bool DoWithMobHeadBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cMobHeadBlockCallback & a_Callback);
+ bool DoWithMobHeadAt(int a_BlockX, int a_BlockY, int a_BlockZ, cMobHeadCallback & a_Callback);
/** Calls the callback for the flower pot at the specified coords; returns false if there's no flower pot at those coords or callback returns true, returns true if found */
bool DoWithFlowerPotAt(int a_BlockX, int a_BlockY, int a_BlockZ, cFlowerPotCallback & a_Callback);
diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp
index 7f999fd31..40964c654 100644
--- a/src/ChunkMap.cpp
+++ b/src/ChunkMap.cpp
@@ -2182,7 +2182,7 @@ bool cChunkMap::DoWithCommandBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, c
-bool cChunkMap::DoWithMobHeadBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cMobHeadBlockCallback & a_Callback)
+bool cChunkMap::DoWithMobHeadAt(int a_BlockX, int a_BlockY, int a_BlockZ, cMobHeadCallback & a_Callback)
{
int ChunkX, ChunkZ;
int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ;
@@ -2193,7 +2193,7 @@ bool cChunkMap::DoWithMobHeadBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, c
{
return false;
}
- return Chunk->DoWithMobHeadBlockAt(a_BlockX, a_BlockY, a_BlockZ, a_Callback);
+ return Chunk->DoWithMobHeadAt(a_BlockX, a_BlockY, a_BlockZ, a_Callback);
}
diff --git a/src/ChunkMap.h b/src/ChunkMap.h
index 6d35b2ebf..9d973f2a9 100644
--- a/src/ChunkMap.h
+++ b/src/ChunkMap.h
@@ -46,7 +46,7 @@ typedef cItemCallback cFlowerPotCallback;
typedef cItemCallback cFurnaceCallback;
typedef cItemCallback cNoteBlockCallback;
typedef cItemCallback cCommandBlockCallback;
-typedef cItemCallback cMobHeadBlockCallback;
+typedef cItemCallback cMobHeadCallback;
typedef cItemCallback cChunkCallback;
@@ -259,7 +259,7 @@ public:
bool DoWithCommandBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cCommandBlockCallback & a_Callback); // Lua-accessible
/** Calls the callback for the mob head block at the specified coords; returns false if there's no mob head block at those coords or callback returns true, returns true if found */
- bool DoWithMobHeadBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cMobHeadBlockCallback & a_Callback); // Lua-accessible
+ bool DoWithMobHeadAt(int a_BlockX, int a_BlockY, int a_BlockZ, cMobHeadCallback & a_Callback); // Lua-accessible
/** Calls the callback for the flower pot at the specified coords; returns false if there's no flower pot at those coords or callback returns true, returns true if found */
bool DoWithFlowerPotAt(int a_BlockX, int a_BlockY, int a_BlockZ, cFlowerPotCallback & a_Callback); // Lua-accessible
diff --git a/src/World.cpp b/src/World.cpp
index 335c6a00d..ecb278e85 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -1197,9 +1197,9 @@ bool cWorld::DoWithCommandBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cCom
-bool cWorld::DoWithMobHeadBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cMobHeadBlockCallback & a_Callback)
+bool cWorld::DoWithMobHeadAt(int a_BlockX, int a_BlockY, int a_BlockZ, cMobHeadCallback & a_Callback)
{
- return m_ChunkMap->DoWithMobHeadBlockAt(a_BlockX, a_BlockY, a_BlockZ, a_Callback);
+ return m_ChunkMap->DoWithMobHeadAt(a_BlockX, a_BlockY, a_BlockZ, a_Callback);
}
diff --git a/src/World.h b/src/World.h
index ee74742c4..e6c665785 100644
--- a/src/World.h
+++ b/src/World.h
@@ -61,7 +61,7 @@ typedef cItemCallback cDispenserCallback;
typedef cItemCallback cFurnaceCallback;
typedef cItemCallback cNoteBlockCallback;
typedef cItemCallback cCommandBlockCallback;
-typedef cItemCallback cMobHeadBlockCallback;
+typedef cItemCallback cMobHeadCallback;
typedef cItemCallback cFlowerPotCallback;
@@ -535,7 +535,7 @@ public:
bool DoWithCommandBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cCommandBlockCallback & a_Callback); // Exported in ManualBindings.cpp
/** Calls the callback for the mob head block at the specified coords; returns false if there's no mob head block at those coords or callback returns true, returns true if found */
- bool DoWithMobHeadBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cMobHeadBlockCallback & a_Callback); // Exported in ManualBindings.cpp
+ bool DoWithMobHeadAt(int a_BlockX, int a_BlockY, int a_BlockZ, cMobHeadCallback & a_Callback); // Exported in ManualBindings.cpp
/** Calls the callback for the flower pot at the specified coords; returns false if there's no flower pot at those coords or callback returns true, returns true if found */
bool DoWithFlowerPotAt(int a_BlockX, int a_BlockY, int a_BlockZ, cFlowerPotCallback & a_Callback); // Exported in ManualBindings.cpp
--
cgit v1.2.3
From 880852394275c4cc3c458582fc245f6f22f9d200 Mon Sep 17 00:00:00 2001
From: andrew
Date: Fri, 7 Mar 2014 15:42:03 +0200
Subject: Fixed water/lava interaction
---
src/Simulator/FloodyFluidSimulator.cpp | 66 ++++++++++++++++++++++++++++++++-
src/Simulator/FloodyFluidSimulator.h | 3 ++
src/Simulator/VanillaFluidSimulator.cpp | 4 +-
3 files changed, 69 insertions(+), 4 deletions(-)
diff --git a/src/Simulator/FloodyFluidSimulator.cpp b/src/Simulator/FloodyFluidSimulator.cpp
index b1ac734d7..48655afb3 100644
--- a/src/Simulator/FloodyFluidSimulator.cpp
+++ b/src/Simulator/FloodyFluidSimulator.cpp
@@ -54,14 +54,21 @@ void cFloodyFluidSimulator::SimulateBlock(cChunk * a_Chunk, int a_RelX, int a_Re
a_Chunk->GetMeta(a_RelX, a_RelY, a_RelZ)
);
- NIBBLETYPE MyMeta = a_Chunk->GetMeta(a_RelX, a_RelY, a_RelZ);
- if (!IsAnyFluidBlock(a_Chunk->GetBlock(a_RelX, a_RelY, a_RelZ)))
+ BLOCKTYPE MyBlock; NIBBLETYPE MyMeta;
+ a_Chunk->GetBlockTypeMeta(a_RelX, a_RelY, a_RelZ, MyBlock, MyMeta);
+
+ if (!IsAnyFluidBlock(MyBlock))
{
// Can happen - if a block is scheduled for simulating and gets replaced in the meantime.
FLOG(" BadBlockType exit");
return;
}
+ if (HardenBlock(a_Chunk, a_RelX, a_RelY, a_RelZ, MyBlock, MyMeta))
+ {
+ return;
+ }
+
if (MyMeta != 0)
{
// Source blocks aren't checked for tributaries, others are.
@@ -309,6 +316,8 @@ void cFloodyFluidSimulator::SpreadToNeighbor(cChunk * a_NearChunk, int a_RelX, i
a_NewMeta
);
a_NearChunk->UnboundedRelSetBlock(a_RelX, a_RelY, a_RelZ, m_FluidBlock, a_NewMeta);
+
+ HardenBlock(a_NearChunk, a_RelX, a_RelY, a_RelZ, m_FluidBlock, a_NewMeta);
}
@@ -361,3 +370,56 @@ bool cFloodyFluidSimulator::CheckNeighborsForSource(cChunk * a_Chunk, int a_RelX
+
+bool cFloodyFluidSimulator::HardenBlock(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta)
+{
+ // Only lava blocks can harden
+ if (!IsBlockLava(a_BlockType))
+ {
+ return false;
+ }
+
+ bool ShouldHarden = false;
+
+ BLOCKTYPE BlockType;
+ NIBBLETYPE BlockMeta;
+ static const Vector3i Coords[] =
+ {
+ Vector3i( 1, 0, 0),
+ Vector3i(-1, 0, 0),
+ Vector3i( 0, 0, 1),
+ Vector3i( 0, 0, -1),
+ };
+ for (size_t i = 0; i < ARRAYCOUNT(Coords); i++)
+ {
+ if (!a_Chunk->UnboundedRelGetBlock(a_RelX + Coords[i].x, a_RelY, a_RelZ + Coords[i].z, BlockType, BlockMeta))
+ {
+ continue;
+ }
+ if (IsBlockWater(BlockType))
+ {
+ ShouldHarden = true;
+ }
+ } // for i - Coords[]
+
+ if (ShouldHarden)
+ {
+ if (a_Meta == 0)
+ {
+ // Source lava block
+ a_Chunk->UnboundedRelSetBlock(a_RelX, a_RelY, a_RelZ, E_BLOCK_OBSIDIAN, 0);
+ return true;
+ }
+ // Ignore last lava level
+ else if (a_Meta <= 4)
+ {
+ a_Chunk->UnboundedRelSetBlock(a_RelX, a_RelY, a_RelZ, E_BLOCK_COBBLESTONE, 0);
+ return true;
+ }
+ }
+
+ return false;
+}
+
+
+
diff --git a/src/Simulator/FloodyFluidSimulator.h b/src/Simulator/FloodyFluidSimulator.h
index 5fd91b2b1..c0ccd422f 100644
--- a/src/Simulator/FloodyFluidSimulator.h
+++ b/src/Simulator/FloodyFluidSimulator.h
@@ -47,6 +47,9 @@ protected:
/** Checks if there are enough neighbors to create a source at the coords specified; turns into source and returns true if so. */
bool CheckNeighborsForSource(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ);
+ /** Check if block should harden (Water/Lava interaction) */
+ bool HardenBlock(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta);
+
/** Spread water to neighbors.
*
* May be overridden to provide more sophisticated algorithms.
diff --git a/src/Simulator/VanillaFluidSimulator.cpp b/src/Simulator/VanillaFluidSimulator.cpp
index 5308d162b..78aff9d68 100644
--- a/src/Simulator/VanillaFluidSimulator.cpp
+++ b/src/Simulator/VanillaFluidSimulator.cpp
@@ -86,7 +86,7 @@ int cVanillaFluidSimulator::CalculateFlowCost(cChunk * a_Chunk, int a_RelX, int
{
return Cost;
}
- if (!IsPassableForFluid(BlockType))
+ if (!IsPassableForFluid(BlockType) && !IsBlockLiquid(BlockType))
{
return Cost;
}
@@ -96,7 +96,7 @@ int cVanillaFluidSimulator::CalculateFlowCost(cChunk * a_Chunk, int a_RelX, int
{
return Cost;
}
- if (IsPassableForFluid(BlockType))
+ if (IsPassableForFluid(BlockType) || IsBlockLiquid(BlockType))
{
// Path found, exit
return a_Iteration;
--
cgit v1.2.3
From 8fdffbb48caa527b83b40baf88e841d1593e79b6 Mon Sep 17 00:00:00 2001
From: Howaner
Date: Fri, 7 Mar 2014 16:14:11 +0100
Subject: Add missing documentation files
---
MCServer/Plugins/APIDump/APIDesc.lua | 2 ++
MCServer/Plugins/APIDump/Classes/BlockEntities.lua | 14 ++++++++++++++
2 files changed, 16 insertions(+)
diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua
index 94cdd0063..9df9d0e77 100644
--- a/MCServer/Plugins/APIDump/APIDesc.lua
+++ b/MCServer/Plugins/APIDump/APIDesc.lua
@@ -2150,7 +2150,9 @@ end
DoWithDropSpenserAt = { Params = "X, Y, Z, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a dropper or a dispenser at the specified coords, calls the CallbackFunction with the {{cDropSpenserEntity}} parameter representing the dropper or dispenser. The CallbackFunction has the following signature: function Callback({{cDropSpenserEntity|DropSpenserEntity}}, [CallbackData])
Note that this can be used to access both dispensers and droppers in a similar way. The function returns false if there is neither dispenser nor dropper, or if there is, it returns the bool value that the callback has returned." },
DoWithDropperAt = { Params = "X, Y, Z, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a dropper at the specified coords, calls the CallbackFunction with the {{cDropperEntity}} parameter representing the dropper. The CallbackFunction has the following signature: function Callback({{cDropperEntity|DropperEntity}}, [CallbackData])
The function returns false if there is no dropper, or if there is, it returns the bool value that the callback has returned." },
DoWithEntityByID = { Params = "EntityID, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If an entity with the specified ID exists, calls the callback with the {{cEntity}} parameter representing the entity. The CallbackFunction has the following signature: function Callback({{cEntity|Entity}}, [CallbackData])
The function returns false if the entity was not found, and it returns the same bool value that the callback has returned if the entity was found." },
+ DoWithFlowerPotAt = { Params = "X, Y, Z, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a flower pot at the specified coords, calls the CallbackFunction with the {{cFlowerPotEntity}} parameter representing the flower pot. The CallbackFunction has the following signature: function Callback({{cFlowerPotEntity|FlowerPotEntity}}, [CallbackData])
The function returns false if there is no flower pot, or if there is, it returns the bool value that the callback has returned." },
DoWithFurnaceAt = { Params = "X, Y, Z, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a furnace at the specified coords, calls the CallbackFunction with the {{cFurnaceEntity}} parameter representing the furnace. The CallbackFunction has the following signature: function Callback({{cFurnaceEntity|FurnaceEntity}}, [CallbackData])
The function returns false if there is no furnace, or if there is, it returns the bool value that the callback has returned." },
+ DoWithModHeadAt = { Params = "X, Y, Z, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a mob head at the specified coords, calls the CallbackFunction with the {{cMobHeadEntity}} parameter representing the furnace. The CallbackFunction has the following signature: function Callback({{cMobHeadEntity|MobHeadEntity}}, [CallbackData])
The function returns false if there is no mob head, or if there is, it returns the bool value that the callback has returned." },
DoWithNoteBlockAt = { Params = "BlockX, BlockY, BlockZ, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a note block at the specified coords, calls the CallbackFunction with the {{cNoteEntity}} parameter representing the note block. The CallbackFunction has the following signature: function Callback({{cNoteEntity|NoteEntity}}, [CallbackData])
The function returns false if there is no note block, or if there is, it returns the bool value that the callback has returned." },
DoWithPlayer = { Params = "PlayerName, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a player of the specified name (exact match), calls the CallbackFunction with the {{cPlayer}} parameter representing the player. The CallbackFunction has the following signature: function Callback({{cPlayer|Player}}, [CallbackData])
The function returns false if the player was not found, or whatever bool value the callback returned if the player was found." },
FastSetBlock =
diff --git a/MCServer/Plugins/APIDump/Classes/BlockEntities.lua b/MCServer/Plugins/APIDump/Classes/BlockEntities.lua
index 61a8e8d22..3deb50ade 100644
--- a/MCServer/Plugins/APIDump/Classes/BlockEntities.lua
+++ b/MCServer/Plugins/APIDump/Classes/BlockEntities.lua
@@ -238,6 +238,20 @@ World:ForEachChestInChunk(Player:GetChunkX(), Player:GetChunkZ(),
},
Inherits = "cBlockEntity";
}, -- cSignEntity
+
+ cFlowerPotEntity =
+ {
+ Desc = [[
+ This class represents a flower pot entity in the world.
+ ]],
+ Functions =
+ {
+ IsItemInPot = { Params = "", Return = "bool", Notes = "Is a flower in the pot?" },
+ GetItem = { Params = "", Return = "cItem", Notes = "Returns the item in the flower pot." },
+ SetItem = { Params = "cItem", Return = "", Notes = "Set the item in the flower pot" },
+ },
+ Inherits = "cBlockEntity";
+ }, -- cFlowerPotEntity
}
--
cgit v1.2.3
From fd4eda7d248884a48b5d7c67d4c59ee3a9dbb149 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Fri, 7 Mar 2014 17:43:06 +0100
Subject: Fixed a typo.
---
src/Bindings/ManualBindings.cpp | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp
index f9d04ce90..0dcb336ef 100644
--- a/src/Bindings/ManualBindings.cpp
+++ b/src/Bindings/ManualBindings.cpp
@@ -2456,7 +2456,7 @@ static int tolua_cBlockArea_GetSize(lua_State * tolua_S)
static int tolua_cBlockArea_LoadFromSchematicFile(lua_State * tolua_S)
{
// function cBlockArea::LoadFromSchematicFile
- // Exported manually because function has been moved to SchematicFileSerilizer.cpp
+ // Exported manually because function has been moved to SchematicFileSerializer.cpp
cLuaState L(tolua_S);
if (
!L.CheckParamUserType(1, "cBlockArea") ||
@@ -2486,7 +2486,7 @@ static int tolua_cBlockArea_LoadFromSchematicFile(lua_State * tolua_S)
static int tolua_cBlockArea_LoadFromSchematicString(lua_State * tolua_S)
{
// function cBlockArea::LoadFromSchematicString
- // Exported manually because function has been moved to SchematicFileSerilizer.cpp
+ // Exported manually because function has been moved to SchematicFileSerializer.cpp
cLuaState L(tolua_S);
if (
!L.CheckParamUserType(1, "cBlockArea") ||
@@ -2517,7 +2517,7 @@ static int tolua_cBlockArea_LoadFromSchematicString(lua_State * tolua_S)
static int tolua_cBlockArea_SaveToSchematicFile(lua_State * tolua_S)
{
// function cBlockArea::SaveToSchematicFile
- // Exported manually because function has been moved to SchematicFileSerilizer.cpp
+ // Exported manually because function has been moved to SchematicFileSerializer.cpp
cLuaState L(tolua_S);
if (
!L.CheckParamUserType(1, "cBlockArea") ||
@@ -2546,7 +2546,7 @@ static int tolua_cBlockArea_SaveToSchematicFile(lua_State * tolua_S)
static int tolua_cBlockArea_SaveToSchematicString(lua_State * tolua_S)
{
// function cBlockArea::SaveToSchematicString
- // Exported manually because function has been moved to SchematicFileSerilizer.cpp
+ // Exported manually because function has been moved to SchematicFileSerializer.cpp
cLuaState L(tolua_S);
if (
!L.CheckParamUserType(1, "cBlockArea") ||
--
cgit v1.2.3
From eff054027face23320f55a01fe5884fe285204b6 Mon Sep 17 00:00:00 2001
From: Howaner
Date: Fri, 7 Mar 2014 17:51:43 +0100
Subject: Link cItem in the documentation
---
MCServer/Plugins/APIDump/APIDesc.lua | 2 +-
MCServer/Plugins/APIDump/Classes/BlockEntities.lua | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua
index 9df9d0e77..39f7cbcd7 100644
--- a/MCServer/Plugins/APIDump/APIDesc.lua
+++ b/MCServer/Plugins/APIDump/APIDesc.lua
@@ -2152,7 +2152,7 @@ end
DoWithEntityByID = { Params = "EntityID, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If an entity with the specified ID exists, calls the callback with the {{cEntity}} parameter representing the entity. The CallbackFunction has the following signature: function Callback({{cEntity|Entity}}, [CallbackData])
The function returns false if the entity was not found, and it returns the same bool value that the callback has returned if the entity was found." },
DoWithFlowerPotAt = { Params = "X, Y, Z, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a flower pot at the specified coords, calls the CallbackFunction with the {{cFlowerPotEntity}} parameter representing the flower pot. The CallbackFunction has the following signature: function Callback({{cFlowerPotEntity|FlowerPotEntity}}, [CallbackData])
The function returns false if there is no flower pot, or if there is, it returns the bool value that the callback has returned." },
DoWithFurnaceAt = { Params = "X, Y, Z, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a furnace at the specified coords, calls the CallbackFunction with the {{cFurnaceEntity}} parameter representing the furnace. The CallbackFunction has the following signature: function Callback({{cFurnaceEntity|FurnaceEntity}}, [CallbackData])
The function returns false if there is no furnace, or if there is, it returns the bool value that the callback has returned." },
- DoWithModHeadAt = { Params = "X, Y, Z, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a mob head at the specified coords, calls the CallbackFunction with the {{cMobHeadEntity}} parameter representing the furnace. The CallbackFunction has the following signature: function Callback({{cMobHeadEntity|MobHeadEntity}}, [CallbackData])
The function returns false if there is no mob head, or if there is, it returns the bool value that the callback has returned." },
+ DoWithMobHeadAt = { Params = "X, Y, Z, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a mob head at the specified coords, calls the CallbackFunction with the {{cMobHeadEntity}} parameter representing the furnace. The CallbackFunction has the following signature: function Callback({{cMobHeadEntity|MobHeadEntity}}, [CallbackData])
The function returns false if there is no mob head, or if there is, it returns the bool value that the callback has returned." },
DoWithNoteBlockAt = { Params = "BlockX, BlockY, BlockZ, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a note block at the specified coords, calls the CallbackFunction with the {{cNoteEntity}} parameter representing the note block. The CallbackFunction has the following signature: function Callback({{cNoteEntity|NoteEntity}}, [CallbackData])
The function returns false if there is no note block, or if there is, it returns the bool value that the callback has returned." },
DoWithPlayer = { Params = "PlayerName, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a player of the specified name (exact match), calls the CallbackFunction with the {{cPlayer}} parameter representing the player. The CallbackFunction has the following signature: function Callback({{cPlayer|Player}}, [CallbackData])
The function returns false if the player was not found, or whatever bool value the callback returned if the player was found." },
FastSetBlock =
diff --git a/MCServer/Plugins/APIDump/Classes/BlockEntities.lua b/MCServer/Plugins/APIDump/Classes/BlockEntities.lua
index 3deb50ade..de42f66df 100644
--- a/MCServer/Plugins/APIDump/Classes/BlockEntities.lua
+++ b/MCServer/Plugins/APIDump/Classes/BlockEntities.lua
@@ -247,8 +247,8 @@ World:ForEachChestInChunk(Player:GetChunkX(), Player:GetChunkZ(),
Functions =
{
IsItemInPot = { Params = "", Return = "bool", Notes = "Is a flower in the pot?" },
- GetItem = { Params = "", Return = "cItem", Notes = "Returns the item in the flower pot." },
- SetItem = { Params = "cItem", Return = "", Notes = "Set the item in the flower pot" },
+ GetItem = { Params = "", Return = "{{cItem|Item}}", Notes = "Returns the item in the flower pot." },
+ SetItem = { Params = "{{cItem|Item}}", Return = "", Notes = "Set the item in the flower pot" },
},
Inherits = "cBlockEntity";
}, -- cFlowerPotEntity
--
cgit v1.2.3
From fac56bb935de5a808b197ccc4a886f262d94dc99 Mon Sep 17 00:00:00 2001
From: worktycho
Date: Fri, 7 Mar 2014 16:55:45 +0000
Subject: Enabled -ffast-math
---
SetFlags.cmake | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/SetFlags.cmake b/SetFlags.cmake
index ded57e6d7..6e86ac0aa 100644
--- a/SetFlags.cmake
+++ b/SetFlags.cmake
@@ -1,5 +1,4 @@
-
macro (add_flags_lnk FLAGS)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${FLAGS}")
@@ -50,6 +49,9 @@ macro(set_flags)
else()
add_flags_cxx("-pthread")
endif()
+
+ #we support non-IEEE 754 fpus so can make no guarentees about error
+ add_flags_cxx("-ffast-math")
else()
# Let gcc / clang know that we're compiling a multi-threaded app:
@@ -62,6 +64,9 @@ macro(set_flags)
# We use a signed char (fixes #640 on RasPi)
add_flags_cxx("-fsigned-char")
+
+ #we support non-IEEE 754 fpus so can make no guarentees about error
+ add_flags_cxx("-ffast-math")
endif()
--
cgit v1.2.3
From 2a3d8d46ec5d269b220ed1fb711cb4d2bfa9dfeb Mon Sep 17 00:00:00 2001
From: worktycho
Date: Fri, 7 Mar 2014 17:04:38 +0000
Subject: Only use fast-math in exes
---
SetFlags.cmake | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/SetFlags.cmake b/SetFlags.cmake
index 6e86ac0aa..a5bd3a0a2 100644
--- a/SetFlags.cmake
+++ b/SetFlags.cmake
@@ -1,4 +1,3 @@
-
macro (add_flags_lnk FLAGS)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${FLAGS}")
@@ -49,9 +48,6 @@ macro(set_flags)
else()
add_flags_cxx("-pthread")
endif()
-
- #we support non-IEEE 754 fpus so can make no guarentees about error
- add_flags_cxx("-ffast-math")
else()
# Let gcc / clang know that we're compiling a multi-threaded app:
@@ -65,8 +61,6 @@ macro(set_flags)
# We use a signed char (fixes #640 on RasPi)
add_flags_cxx("-fsigned-char")
- #we support non-IEEE 754 fpus so can make no guarentees about error
- add_flags_cxx("-ffast-math")
endif()
@@ -189,6 +183,9 @@ macro(set_exe_flags)
string(REPLACE "-w" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
string(REPLACE "-w" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
add_flags_cxx("-Wall -Wextra")
+
+ #we support non-IEEE 754 fpus so can make no guarentees about error
+ add_flags_cxx("-ffast-math")
endif()
endmacro()
--
cgit v1.2.3
From 95ea0ef43dfbcf2240a0ece70d2829ce63ab0dd3 Mon Sep 17 00:00:00 2001
From: worktycho
Date: Fri, 7 Mar 2014 17:22:37 +0000
Subject: Fixed clang compile
---
SetFlags.cmake | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/SetFlags.cmake b/SetFlags.cmake
index a5bd3a0a2..6a8211fa2 100644
--- a/SetFlags.cmake
+++ b/SetFlags.cmake
@@ -184,8 +184,13 @@ macro(set_exe_flags)
string(REPLACE "-w" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
add_flags_cxx("-Wall -Wextra")
- #we support non-IEEE 754 fpus so can make no guarentees about error
+ # we support non-IEEE 754 fpus so can make no guarentees about error
add_flags_cxx("-ffast-math")
+
+ # clang does not provide the __extern_always_inline macro and a part of libm depends on this when using fast-math
+ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
+ add_flags_cxx("-D__extern_always_inline=inline")
+ endif()
endif()
endmacro()
--
cgit v1.2.3
From b480148116ea7099c9a6afda83f74a3d45815a83 Mon Sep 17 00:00:00 2001
From: Tycho
Date: Fri, 7 Mar 2014 10:26:07 -0800
Subject: Fixed warnings
---
SetFlags.cmake | 2 +-
src/Bindings/LuaState.cpp | 1 +
src/Items/ItemHandler.h | 3 +++
src/OSSupport/SocketThreads.h | 2 +-
4 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/SetFlags.cmake b/SetFlags.cmake
index 6a8211fa2..35831e7e9 100644
--- a/SetFlags.cmake
+++ b/SetFlags.cmake
@@ -182,7 +182,7 @@ macro(set_exe_flags)
string(REPLACE "-w" "" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
string(REPLACE "-w" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
string(REPLACE "-w" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
- add_flags_cxx("-Wall -Wextra")
+ add_flags_cxx("-Wall -Wextra -Werror -Wno-error=unused-parameter")
# we support non-IEEE 754 fpus so can make no guarentees about error
add_flags_cxx("-ffast-math")
diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp
index 1890dcfe5..aa6ee05b3 100644
--- a/src/Bindings/LuaState.cpp
+++ b/src/Bindings/LuaState.cpp
@@ -677,6 +677,7 @@ void cLuaState::Push(Vector3i * a_Vector)
void cLuaState::Push(void * a_Ptr)
{
+ UNUSED(a_Ptr);
ASSERT(IsValid());
// Investigate the cause of this - what is the callstack?
diff --git a/src/Items/ItemHandler.h b/src/Items/ItemHandler.h
index ef3f37a7a..5b6c239cc 100644
--- a/src/Items/ItemHandler.h
+++ b/src/Items/ItemHandler.h
@@ -21,6 +21,9 @@ class cItemHandler
public:
cItemHandler(int a_ItemType);
+ // Force virtual destructor
+ virtual ~cItemHandler() {}
+
/// Called when the player tries to use the item (right mouse button). Return false to make the item unusable. DEFAULT: False
virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Dir);
diff --git a/src/OSSupport/SocketThreads.h b/src/OSSupport/SocketThreads.h
index fcd2ce11f..b2eb5950f 100644
--- a/src/OSSupport/SocketThreads.h
+++ b/src/OSSupport/SocketThreads.h
@@ -103,7 +103,7 @@ private:
public:
cSocketThread(cSocketThreads * a_Parent);
- ~cSocketThread();
+ virtual ~cSocketThread();
// All these methods assume parent's m_CS is locked
bool HasEmptySlot(void) const {return m_NumSlots < MAX_SLOTS; }
--
cgit v1.2.3
From 7f389522ef1f40e847a4a7828ad55e50c0151b00 Mon Sep 17 00:00:00 2001
From: Tycho
Date: Fri, 7 Mar 2014 10:42:13 -0800
Subject: Fixed warnings
---
src/Blocks/BlockStairs.h | 8 ++++++++
src/Blocks/BlockVine.h | 16 +++++++++++++---
2 files changed, 21 insertions(+), 3 deletions(-)
diff --git a/src/Blocks/BlockStairs.h b/src/Blocks/BlockStairs.h
index c1887bc46..93035b3b1 100644
--- a/src/Blocks/BlockStairs.h
+++ b/src/Blocks/BlockStairs.h
@@ -25,6 +25,14 @@ public:
BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta
) override
{
+ UNUSED(a_ChunkInterface);
+ UNUSED(a_BlockX);
+ UNUSED(a_BlockY);
+ UNUSED(a_BlockZ);
+ UNUSED(a_CursorX);
+ UNUSED(a_CursorY);
+ UNUSED(a_CursorZ);
+ UNUSED(a_BlockMeta);
a_BlockType = m_BlockType;
a_BlockMeta = RotationToMetaData(a_Player->GetYaw());
switch (a_BlockFace)
diff --git a/src/Blocks/BlockVine.h b/src/Blocks/BlockVine.h
index d8c114284..0934a451b 100644
--- a/src/Blocks/BlockVine.h
+++ b/src/Blocks/BlockVine.h
@@ -24,6 +24,10 @@ 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;
@@ -162,11 +166,17 @@ public:
return false;
}
- virtual void OnUpdate(cWorld * a_World, int X, int Y, int Z)
+ virtual void OnUpdate(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cBlockPluginInterface & a_BlockPluginInterface, cChunk & a_Chunk, int a_RelX, int a_RelY, int a_RelZ)
{
- if (a_World->GetBlock(X, Y - 1, Z) == E_BLOCK_AIR)
+ UNUSED(a_ChunkInterface);
+ UNUSED(a_WorldInterface);
+ UNUSED(a_BlockPluginInterface);
+
+ BLOCKTYPE Block;
+ a_Chunk.UnboundedRelGetBlockType(a_RelX, a_RelY - 1, a_RelZ, Block);
+ if (Block == E_BLOCK_AIR)
{
- a_World->SetBlock(X, Y - 1, Z, E_BLOCK_VINES, a_World->GetBlockMeta(X, Y, Z));
+ a_Chunk.UnboundedRelSetBlock(a_RelX, a_RelY - 1, a_RelZ, E_BLOCK_VINES, a_Chunk.GetMeta(a_RelX, a_RelY, a_RelZ));
}
}
--
cgit v1.2.3
From d86fc1af0640675c707330e671d69b23e27d20c1 Mon Sep 17 00:00:00 2001
From: andrew
Date: Fri, 7 Mar 2014 20:49:40 +0200
Subject: Added some comments
---
src/Simulator/FloodyFluidSimulator.cpp | 2 ++
src/Simulator/FloodyFluidSimulator.h | 5 ++++-
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/src/Simulator/FloodyFluidSimulator.cpp b/src/Simulator/FloodyFluidSimulator.cpp
index 48655afb3..03e94e791 100644
--- a/src/Simulator/FloodyFluidSimulator.cpp
+++ b/src/Simulator/FloodyFluidSimulator.cpp
@@ -64,8 +64,10 @@ void cFloodyFluidSimulator::SimulateBlock(cChunk * a_Chunk, int a_RelX, int a_Re
return;
}
+ // When in contact with water, lava should harden
if (HardenBlock(a_Chunk, a_RelX, a_RelY, a_RelZ, MyBlock, MyMeta))
{
+ // Block was changed, bail out
return;
}
diff --git a/src/Simulator/FloodyFluidSimulator.h b/src/Simulator/FloodyFluidSimulator.h
index c0ccd422f..632de3bb2 100644
--- a/src/Simulator/FloodyFluidSimulator.h
+++ b/src/Simulator/FloodyFluidSimulator.h
@@ -47,7 +47,10 @@ protected:
/** Checks if there are enough neighbors to create a source at the coords specified; turns into source and returns true if so. */
bool CheckNeighborsForSource(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ);
- /** Check if block should harden (Water/Lava interaction) */
+ /** Checks if the specified block should harden (Water/Lava interaction) and if so, converts it to a suitable block.
+ *
+ * Returns whether the block was changed or not.
+ */
bool HardenBlock(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta);
/** Spread water to neighbors.
--
cgit v1.2.3
From d33d72f0dc9ef8969c6b57592fbce54165641591 Mon Sep 17 00:00:00 2001
From: Tycho
Date: Fri, 7 Mar 2014 11:04:25 -0800
Subject: Warnings
---
src/ByteBuffer.cpp | 10 +++++-----
src/ByteBuffer.h | 24 ++++++++++++------------
src/Protocol/Protocol.h | 2 +-
src/Protocol/Protocol125.cpp | 2 +-
src/Protocol/Protocol125.h | 21 +++++++++++++++++----
src/Protocol/Protocol132.cpp | 2 +-
src/Protocol/Protocol132.h | 2 +-
src/Protocol/Protocol17x.cpp | 2 +-
src/Protocol/Protocol17x.h | 2 +-
src/Protocol/ProtocolRecognizer.cpp | 2 +-
src/Protocol/ProtocolRecognizer.h | 2 +-
11 files changed, 42 insertions(+), 29 deletions(-)
diff --git a/src/ByteBuffer.cpp b/src/ByteBuffer.cpp
index d2d3beb97..32a367462 100644
--- a/src/ByteBuffer.cpp
+++ b/src/ByteBuffer.cpp
@@ -171,7 +171,7 @@ cByteBuffer::~cByteBuffer()
-bool cByteBuffer::Write(const char * a_Bytes, int a_Count)
+bool cByteBuffer::Write(const char * a_Bytes, size_t a_Count)
{
CHECK_THREAD;
CheckValid();
@@ -263,7 +263,7 @@ int cByteBuffer::GetReadableSpace(void) const
-bool cByteBuffer::CanReadBytes(int a_Count) const
+bool cByteBuffer::CanReadBytes(size_t a_Count) const
{
CHECK_THREAD;
CheckValid();
@@ -274,7 +274,7 @@ bool cByteBuffer::CanReadBytes(int a_Count) const
-bool cByteBuffer::CanWriteBytes(int a_Count) const
+bool cByteBuffer::CanWriteBytes(size_t a_Count) const
{
CHECK_THREAD;
CheckValid();
@@ -767,7 +767,7 @@ bool cByteBuffer::ReadUTF16String(AString & a_String, int a_NumChars)
-bool cByteBuffer::SkipRead(int a_Count)
+bool cByteBuffer::SkipRead(size_t a_Count)
{
CHECK_THREAD;
CheckValid();
@@ -860,7 +860,7 @@ void cByteBuffer::ReadAgain(AString & a_Out)
-void cByteBuffer::AdvanceReadPos(int a_Count)
+void cByteBuffer::AdvanceReadPos(size_t a_Count)
{
CHECK_THREAD;
CheckValid();
diff --git a/src/ByteBuffer.h b/src/ByteBuffer.h
index cbce119b1..5fdf48c28 100644
--- a/src/ByteBuffer.h
+++ b/src/ByteBuffer.h
@@ -31,7 +31,7 @@ public:
~cByteBuffer();
/// Writes the bytes specified to the ringbuffer. Returns true if successful, false if not
- bool Write(const char * a_Bytes, int a_Count);
+ bool Write(const char * a_Bytes, size_t a_Count);
/// Returns the number of bytes that can be successfully written to the ringbuffer
int GetFreeSpace(void) const;
@@ -46,10 +46,10 @@ public:
int GetDataStart(void) const { return m_DataStart; }
/// Returns true if the specified amount of bytes are available for reading
- bool CanReadBytes(int a_Count) const;
+ bool CanReadBytes(size_t a_Count) const;
/// Returns true if the specified amount of bytes are available for writing
- bool CanWriteBytes(int a_Count) const;
+ bool CanWriteBytes(size_t a_Count) const;
// Read the specified datatype and advance the read pointer; return true if successfully read:
bool ReadChar (char & a_Value);
@@ -92,19 +92,19 @@ public:
bool WriteLEInt (int a_Value);
/// Reads a_Count bytes into a_Buffer; returns true if successful
- bool ReadBuf(void * a_Buffer, int a_Count);
+ bool ReadBuf(void * a_Buffer, size_t a_Count);
/// Writes a_Count bytes into a_Buffer; returns true if successful
- bool WriteBuf(const void * a_Buffer, int a_Count);
+ bool WriteBuf(const void * a_Buffer, size_t a_Count);
/// Reads a_Count bytes into a_String; returns true if successful
- bool ReadString(AString & a_String, int a_Count);
+ bool ReadString(AString & a_String, size_t a_Count);
/// Reads 2 * a_NumChars bytes and interprets it as a UTF16-BE string, converting it into UTF8 string a_String
bool ReadUTF16String(AString & a_String, int a_NumChars);
/// Skips reading by a_Count bytes; returns false if not enough bytes in the ringbuffer
- bool SkipRead(int a_Count);
+ bool SkipRead(size_t a_Count);
/// Reads all available data into a_Data
void ReadAll(AString & a_Data);
@@ -126,18 +126,18 @@ public:
protected:
char * m_Buffer;
- int m_BufferSize; // Total size of the ringbuffer
+ size_t m_BufferSize; // Total size of the ringbuffer
#ifdef _DEBUG
volatile unsigned long m_ThreadID; // Thread that is currently accessing the object, checked via cSingleThreadAccessChecker
#endif // _DEBUG
- int m_DataStart; // Where the data starts in the ringbuffer
- int m_WritePos; // Where the data ends in the ringbuffer
- int m_ReadPos; // Where the next read will start in the ringbuffer
+ size_t m_DataStart; // Where the data starts in the ringbuffer
+ size_t m_WritePos; // Where the data ends in the ringbuffer
+ size_t m_ReadPos; // Where the next read will start in the ringbuffer
/// Advances the m_ReadPos by a_Count bytes
- void AdvanceReadPos(int a_Count);
+ void AdvanceReadPos(size_t a_Count);
} ;
diff --git a/src/Protocol/Protocol.h b/src/Protocol/Protocol.h
index b5560f7c1..d3383bf0d 100644
--- a/src/Protocol/Protocol.h
+++ b/src/Protocol/Protocol.h
@@ -52,7 +52,7 @@ public:
virtual ~cProtocol() {}
/// Called when client sends some data
- virtual void DataReceived(const char * a_Data, int a_Size) = 0;
+ virtual void DataReceived(const char * a_Data, size_t a_Size) = 0;
// Sending stuff to clients (alphabetically sorted):
virtual void SendAttachEntity (const cEntity & a_Entity, const cEntity * a_Vehicle) = 0;
diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp
index 3980350f5..e032e4050 100644
--- a/src/Protocol/Protocol125.cpp
+++ b/src/Protocol/Protocol125.cpp
@@ -1186,7 +1186,7 @@ void cProtocol125::SendData(const char * a_Data, int a_Size)
-void cProtocol125::DataReceived(const char * a_Data, int a_Size)
+void cProtocol125::DataReceived(const char * a_Data, size_t a_Size)
{
if (!m_ReceivedData.Write(a_Data, a_Size))
{
diff --git a/src/Protocol/Protocol125.h b/src/Protocol/Protocol125.h
index 1d1484a60..66f3227b0 100644
--- a/src/Protocol/Protocol125.h
+++ b/src/Protocol/Protocol125.h
@@ -24,7 +24,7 @@ public:
cProtocol125(cClientHandle * a_Client);
/// Called when client sends some data:
- virtual void DataReceived(const char * a_Data, int a_Size) override;
+ virtual void DataReceived(const char * a_Data, size_t a_Size) override;
/// Sending stuff to clients (alphabetically sorted):
virtual void SendAttachEntity (const cEntity & a_Entity, const cEntity * a_Vehicle) override;
@@ -57,9 +57,17 @@ public:
virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) override;
virtual void SendMapColumn (int a_ID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length) override;
virtual void SendMapDecorators (int a_ID, const cMapDecoratorList & a_Decorators) override;
- virtual void SendMapInfo (int a_ID, unsigned int a_Scale) override {} // This protocol doesn't support such message
+ virtual void SendMapInfo (int a_ID, unsigned int a_Scale) override
+ {
+ // This protocol doesn't support such message
+ UNUSED(a_ID);
+ UNUSED(a_Scale);
+ }
virtual void SendParticleEffect (const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmmount) override;
- virtual void SendPaintingSpawn (const cPainting & a_Painting) override {};
+ virtual void SendPaintingSpawn (const cPainting & a_Painting) override
+ {
+ UNUSED(a_Painting);
+ };
virtual void SendPickupSpawn (const cPickup & a_Pickup) override;
virtual void SendPlayerAbilities (void) override {} // This protocol doesn't support such message
virtual void SendEntityAnimation (const cEntity & a_Entity, char a_Animation) override;
@@ -73,7 +81,12 @@ public:
virtual void SendRespawn (void) override;
virtual void SendExperience (void) override;
virtual void SendExperienceOrb (const cExpOrb & a_ExpOrb) override;
- virtual void SendScoreboardObjective (const AString & a_Name, const AString & a_DisplayName, Byte a_Mode) override {} // This protocol doesn't support such message
+ virtual void SendScoreboardObjective (const AString & a_Name, const AString & a_DisplayName, Byte a_Mode) override
+ {
+ UNUSED(a_Name);
+ UNUSED(a_DisplayName);
+ UNUSED(a_Mode);
+ } // This protocol doesn't support such message
virtual void SendScoreUpdate (const AString & a_Objective, const AString & a_Player, cObjective::Score a_Score, Byte a_Mode) override {} // This protocol doesn't support such message
virtual void SendDisplayObjective (const AString & a_Objective, cScoreboard::eDisplaySlot a_Display) override {} // This protocol doesn't support such message
virtual void SendSoundEffect (const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch) override; // a_Src coords are Block * 8
diff --git a/src/Protocol/Protocol132.cpp b/src/Protocol/Protocol132.cpp
index 1f9222a69..8df550c7b 100644
--- a/src/Protocol/Protocol132.cpp
+++ b/src/Protocol/Protocol132.cpp
@@ -108,7 +108,7 @@ cProtocol132::~cProtocol132()
-void cProtocol132::DataReceived(const char * a_Data, int a_Size)
+void cProtocol132::DataReceived(const char * a_Data, size_t a_Size)
{
if (m_IsEncrypted)
{
diff --git a/src/Protocol/Protocol132.h b/src/Protocol/Protocol132.h
index 89f4636f5..0702fbf5a 100644
--- a/src/Protocol/Protocol132.h
+++ b/src/Protocol/Protocol132.h
@@ -40,7 +40,7 @@ public:
virtual ~cProtocol132();
/// Called when client sends some data:
- virtual void DataReceived(const char * a_Data, int a_Size) override;
+ virtual void DataReceived(const char * a_Data, size_t a_Size) override;
// Sending commands (alphabetically sorted):
virtual void SendBlockAction (int a_BlockX, int a_BlockY, int a_BlockZ, char a_Byte1, char a_Byte2, BLOCKTYPE a_BlockType) override;
diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp
index 18646254f..cb9e5b9b1 100644
--- a/src/Protocol/Protocol17x.cpp
+++ b/src/Protocol/Protocol17x.cpp
@@ -98,7 +98,7 @@ cProtocol172::cProtocol172(cClientHandle * a_Client, const AString & a_ServerAdd
-void cProtocol172::DataReceived(const char * a_Data, int a_Size)
+void cProtocol172::DataReceived(const char * a_Data, size_t a_Size)
{
if (m_IsEncrypted)
{
diff --git a/src/Protocol/Protocol17x.h b/src/Protocol/Protocol17x.h
index 113501568..41163009e 100644
--- a/src/Protocol/Protocol17x.h
+++ b/src/Protocol/Protocol17x.h
@@ -56,7 +56,7 @@ public:
cProtocol172(cClientHandle * a_Client, const AString & a_ServerAddress, UInt16 a_ServerPort, UInt32 a_State);
/** Called when client sends some data: */
- virtual void DataReceived(const char * a_Data, int a_Size) override;
+ virtual void DataReceived(const char * a_Data, size_t a_Size) override;
/** Sending stuff to clients (alphabetically sorted): */
virtual void SendAttachEntity (const cEntity & a_Entity, const cEntity * a_Vehicle) override;
diff --git a/src/Protocol/ProtocolRecognizer.cpp b/src/Protocol/ProtocolRecognizer.cpp
index 84b052146..3b9003e60 100644
--- a/src/Protocol/ProtocolRecognizer.cpp
+++ b/src/Protocol/ProtocolRecognizer.cpp
@@ -68,7 +68,7 @@ AString cProtocolRecognizer::GetVersionTextFromInt(int a_ProtocolVersion)
-void cProtocolRecognizer::DataReceived(const char * a_Data, int a_Size)
+void cProtocolRecognizer::DataReceived(const char * a_Data, size_t a_Size)
{
if (m_Protocol == NULL)
{
diff --git a/src/Protocol/ProtocolRecognizer.h b/src/Protocol/ProtocolRecognizer.h
index 6aaafedeb..d7fb8fad2 100644
--- a/src/Protocol/ProtocolRecognizer.h
+++ b/src/Protocol/ProtocolRecognizer.h
@@ -59,7 +59,7 @@ public:
static AString GetVersionTextFromInt(int a_ProtocolVersion);
/// Called when client sends some data:
- virtual void DataReceived(const char * a_Data, int a_Size) override;
+ virtual void DataReceived(const char * a_Data, size_t a_Size) override;
/// Sending stuff to clients (alphabetically sorted):
virtual void SendAttachEntity (const cEntity & a_Entity, const cEntity * a_Vehicle) override;
--
cgit v1.2.3
From 21e85b07456f12c029ab32c396285ad13063964f Mon Sep 17 00:00:00 2001
From: Tycho
Date: Fri, 7 Mar 2014 11:15:04 -0800
Subject: Warnings
---
src/Generating/MineShafts.cpp | 2 ++
src/Generating/Trees.cpp | 2 +-
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/Generating/MineShafts.cpp b/src/Generating/MineShafts.cpp
index d9acc57bb..28dc37567 100644
--- a/src/Generating/MineShafts.cpp
+++ b/src/Generating/MineShafts.cpp
@@ -69,6 +69,8 @@ public:
m_BoundingBox(a_BoundingBox)
{
}
+
+ virtual ~cMineShaft() {}
/// Returns true if this mineshaft intersects the specified cuboid
bool DoesIntersect(const cCuboid & a_Other)
diff --git a/src/Generating/Trees.cpp b/src/Generating/Trees.cpp
index a660285d1..4909587b1 100644
--- a/src/Generating/Trees.cpp
+++ b/src/Generating/Trees.cpp
@@ -595,7 +595,7 @@ void GetPineTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a_Noise
{
break;
}
- ASSERT(LayerSize < ARRAYCOUNT(BigOs));
+ ASSERT((size_t)LayerSize < ARRAYCOUNT(BigOs));
PushCoordBlocks(a_BlockX, h, a_BlockZ, a_OtherBlocks, BigOs[LayerSize].Coords, BigOs[LayerSize].Count, E_BLOCK_LEAVES, E_META_LEAVES_CONIFER);
h--;
}
--
cgit v1.2.3
From d51cab2d3bb579b663c1211dfc1e69039165c06f Mon Sep 17 00:00:00 2001
From: Tycho
Date: Fri, 7 Mar 2014 11:16:16 -0800
Subject: Turned on Werror
---
SetFlags.cmake | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/SetFlags.cmake b/SetFlags.cmake
index 35831e7e9..e6ba782fc 100644
--- a/SetFlags.cmake
+++ b/SetFlags.cmake
@@ -182,7 +182,7 @@ macro(set_exe_flags)
string(REPLACE "-w" "" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
string(REPLACE "-w" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
string(REPLACE "-w" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
- add_flags_cxx("-Wall -Wextra -Werror -Wno-error=unused-parameter")
+ add_flags_cxx("-Wall -Wextra -Werror -Wno-error=unused-parameter -Wno-error=switch")
# we support non-IEEE 754 fpus so can make no guarentees about error
add_flags_cxx("-ffast-math")
--
cgit v1.2.3
From 72697cfb4f7cfa8e82cba4960ac9e8c729c3b24d Mon Sep 17 00:00:00 2001
From: Tycho
Date: Fri, 7 Mar 2014 11:23:28 -0800
Subject: Added support to overide CMake build type with env vars
---
src/CMakeLists.txt | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 5029906aa..cafa519c3 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -9,6 +9,14 @@ include_directories (SYSTEM "${PROJECT_SOURCE_DIR}/../lib/polarssl/include")
set(FOLDERS OSSupport HTTPServer Items Blocks Protocol Generating)
set(FOLDERS ${FOLDERS} WorldStorage Mobs Entities Simulator UI BlockEntities)
+if(DEFINED ENV{MCSERVER_BUILD_TYPE})
+ message("Setting build type to $ENV{MCSERVER_BUILD_TYPE}")
+ set(CMAKE_BUILD_TYPE $ENV{MCSERVER_BUILD_TYPE})
+endif()
+
+if(DEFINED ENV{MCSERVER_FORCE32})
+ set(FORCE32 $ENV{MCSERVER_FORCE32})
+endif()
if (NOT MSVC)
--
cgit v1.2.3
From 53fe82eaf85dc3bcd2cfdc12ffb2266e10f91e79 Mon Sep 17 00:00:00 2001
From: Tycho
Date: Fri, 7 Mar 2014 11:26:36 -0800
Subject: Added travis support for multiple build types
---
.travis.yml | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/.travis.yml b/.travis.yml
index c6537cf47..a12ca55e0 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -3,7 +3,13 @@ compiler:
- gcc
- clang
# Build MCServer
-script: cmake . -DCMAKE_BUILD_TYPE=RELEASE -DBUILD_TOOLS=1 -DSELF_TEST=1 && make -j 2 && cd MCServer/ && (echo stop | ./MCServer)
+script: cmake . -DBUILD_TOOLS=1 -DSELF_TEST=1 && make -j 2 && cd MCServer/ && (echo stop | ./MCServer)
+
+env:
+ - MCSERVER_BUILD_TYPE=RELEASE
+ - MCSERVER_BUILD_TYPE=DEBUG
+ - MCSERVER_BUILD_TYPE=RELEASE MCSERVER_FORCE32=1
+ - MCSERVER_BUILD_TYPE=DEBUG MCSERVER_FORCE32=1
# Notification Settings
notifications:
--
cgit v1.2.3
From 6b153a5014612a998179f4637139061ed11da6db Mon Sep 17 00:00:00 2001
From: worktycho
Date: Fri, 7 Mar 2014 19:59:49 +0000
Subject: Move env code part 1
---
src/CMakeLists.txt | 10 ----------
1 file changed, 10 deletions(-)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index cafa519c3..c2de26664 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,4 +1,3 @@
-
cmake_minimum_required (VERSION 2.8.2)
project (MCServer)
@@ -9,15 +8,6 @@ include_directories (SYSTEM "${PROJECT_SOURCE_DIR}/../lib/polarssl/include")
set(FOLDERS OSSupport HTTPServer Items Blocks Protocol Generating)
set(FOLDERS ${FOLDERS} WorldStorage Mobs Entities Simulator UI BlockEntities)
-if(DEFINED ENV{MCSERVER_BUILD_TYPE})
- message("Setting build type to $ENV{MCSERVER_BUILD_TYPE}")
- set(CMAKE_BUILD_TYPE $ENV{MCSERVER_BUILD_TYPE})
-endif()
-
-if(DEFINED ENV{MCSERVER_FORCE32})
- set(FORCE32 $ENV{MCSERVER_FORCE32})
-endif()
-
if (NOT MSVC)
--
cgit v1.2.3
From c67e008a4e3c19a79f82af4d430e43e6ea0eabbf Mon Sep 17 00:00:00 2001
From: worktycho
Date: Fri, 7 Mar 2014 20:03:05 +0000
Subject: Fixed wrong path in debug mode
---
.travis.yml | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index a12ca55e0..14dad4df4 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -3,13 +3,13 @@ compiler:
- gcc
- clang
# Build MCServer
-script: cmake . -DBUILD_TOOLS=1 -DSELF_TEST=1 && make -j 2 && cd MCServer/ && (echo stop | ./MCServer)
+script: cmake . -DBUILD_TOOLS=1 -DSELF_TEST=1 && make -j 2 && cd MCServer/ && (echo stop | $MCSERVER_PATH)
env:
- - MCSERVER_BUILD_TYPE=RELEASE
- - MCSERVER_BUILD_TYPE=DEBUG
- - MCSERVER_BUILD_TYPE=RELEASE MCSERVER_FORCE32=1
- - MCSERVER_BUILD_TYPE=DEBUG MCSERVER_FORCE32=1
+ - MCSERVER_BUILD_TYPE=RELEASE MCSERVER_PATH=./MCServer
+ - MCSERVER_BUILD_TYPE=DEBUG MCSERVER_PATH=./MCServer_debug
+ - MCSERVER_BUILD_TYPE=RELEASE MCSERVER_FORCE32=1 MCSERVER_PATH=./MCServer
+ - MCSERVER_BUILD_TYPE=DEBUG MCSERVER_FORCE32=1 MCSERVER_PATH=./MCServer_debug
# Notification Settings
notifications:
--
cgit v1.2.3
From 0eea9eb99841ba379475a277af860d22ac156071 Mon Sep 17 00:00:00 2001
From: worktycho
Date: Fri, 7 Mar 2014 20:16:16 +0000
Subject: Move env code part 2
Only just noticed I committed this on the wrong branch.
---
CMakeLists.txt | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 05b6d879b..e7e8daf7d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -3,6 +3,15 @@ cmake_minimum_required (VERSION 2.6)
# Without this, the MSVC variable isn't defined for MSVC builds ( http://www.cmake.org/pipermail/cmake/2011-November/047130.html )
enable_language(CXX C)
+if(DEFINED ENV{MCSERVER_BUILD_TYPE})
+ message("Setting build type to $ENV{MCSERVER_BUILD_TYPE}")
+ set(CMAKE_BUILD_TYPE $ENV{MCSERVER_BUILD_TYPE})
+endif()
+
+if(DEFINED ENV{MCSERVER_FORCE32})
+ set(FORCE32 $ENV{MCSERVER_FORCE32})
+endif()
+
# This has to be done before any flags have been set up.
if(${BUILD_TOOLS})
add_subdirectory(Tools/MCADefrag/)
--
cgit v1.2.3
From ffdf5f2022cbeb568cb6ff28448aad98876334b1 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Fri, 7 Mar 2014 21:28:52 +0100
Subject: Fixed cBlockArea schematic string saving signature.
---
MCServer/Plugins/APIDump/APIDesc.lua | 2 +-
src/Bindings/ManualBindings.cpp | 10 +++++++---
src/WorldStorage/SchematicFileSerializer.cpp | 7 +++----
src/WorldStorage/SchematicFileSerializer.h | 4 ++--
4 files changed, 13 insertions(+), 10 deletions(-)
diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua
index 5f1b11a4c..1e572492b 100644
--- a/MCServer/Plugins/APIDump/APIDesc.lua
+++ b/MCServer/Plugins/APIDump/APIDesc.lua
@@ -162,7 +162,7 @@ g_APIDesc =
RotateCW = { Params = "", Return = "", Notes = "Rotates the block area around the Y axis, clockwise (north -> east). Modifies blocks' metas (if present) to match." },
RotateCWNoMeta = { Params = "", Return = "", Notes = "Rotates the block area around the Y axis, clockwise (north -> east). Doesn't modify blocks' metas." },
SaveToSchematicFile = { Params = "FileName", Return = "", Notes = "Saves the current contents to a schematic file. Returns true if successful." },
- SaveToSchematicString = { Params = "", Return = "string", Notes = "Saves the current contents to a string (in a .schematic file format). Returns the data if successful, empty string if failed." },
+ SaveToSchematicString = { Params = "", Return = "string", Notes = "Saves the current contents to a string (in a .schematic file format). Returns the data if successful, nil if failed." },
SetBlockLight = { Params = "BlockX, BlockY, BlockZ, BlockLight", Return = "", Notes = "Sets the blocklight at the specified absolute coords" },
SetBlockMeta = { Params = "BlockX, BlockY, BlockZ, BlockMeta", Return = "", Notes = "Sets the block meta at the specified absolute coords" },
SetBlockSkyLight = { Params = "BlockX, BlockY, BlockZ, SkyLight", Return = "", Notes = "Sets the skylight at the specified absolute coords" },
diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp
index 05dc9717e..a5247bbe6 100644
--- a/src/Bindings/ManualBindings.cpp
+++ b/src/Bindings/ManualBindings.cpp
@@ -2563,9 +2563,13 @@ static int tolua_cBlockArea_SaveToSchematicString(lua_State * tolua_S)
return 0;
}
- AString Data = cSchematicFileSerializer::SaveToSchematicString(*self);
- L.Push(Data);
- return 1;
+ AString Data;
+ if (cSchematicFileSerializer::SaveToSchematicString(*self, Data))
+ {
+ L.Push(Data);
+ return 1;
+ }
+ return 0;
}
diff --git a/src/WorldStorage/SchematicFileSerializer.cpp b/src/WorldStorage/SchematicFileSerializer.cpp
index a6ae8d8e0..b021aeb0c 100644
--- a/src/WorldStorage/SchematicFileSerializer.cpp
+++ b/src/WorldStorage/SchematicFileSerializer.cpp
@@ -103,7 +103,7 @@ bool cSchematicFileSerializer::SaveToSchematicFile(const cBlockArea & a_BlockAre
-AString cSchematicFileSerializer::SaveToSchematicString(const cBlockArea & a_BlockArea)
+bool cSchematicFileSerializer::SaveToSchematicString(const cBlockArea & a_BlockArea, AString & a_Out)
{
// Serialize into NBT data:
AString NBT = SaveToSchematicNBT(a_BlockArea);
@@ -114,14 +114,13 @@ AString cSchematicFileSerializer::SaveToSchematicString(const cBlockArea & a_Blo
}
// Gzip the data:
- AString Compressed;
- int res = CompressStringGZIP(NBT.data(), NBT.size(), Compressed);
+ int res = CompressStringGZIP(NBT.data(), NBT.size(), a_Out);
if (res != Z_OK)
{
LOG("%s: Cannot Gzip the area data NBT representation: %d", __FUNCTION__, res);
return false;
}
- return Compressed;
+ return true;
}
diff --git a/src/WorldStorage/SchematicFileSerializer.h b/src/WorldStorage/SchematicFileSerializer.h
index f6ce1c16c..05b6c74f4 100644
--- a/src/WorldStorage/SchematicFileSerializer.h
+++ b/src/WorldStorage/SchematicFileSerializer.h
@@ -36,8 +36,8 @@ public:
static bool SaveToSchematicFile(const cBlockArea & a_BlockArea, const AString & a_FileName);
/** Saves the area into a string containing the .schematic file data.
- Returns the data, or empty string if failed. */
- static AString SaveToSchematicString(const cBlockArea & a_BlockArea);
+ Returns true if successful, false on failure. The data is stored into a_Out. */
+ static bool SaveToSchematicString(const cBlockArea & a_BlockArea, AString & a_Out);
private:
/** Loads the area from a schematic file uncompressed and parsed into a NBT tree.
--
cgit v1.2.3
From f5e374be41ef3bde93e0faaa76208e3e0e15e9ea Mon Sep 17 00:00:00 2001
From: Howaner
Date: Sat, 8 Mar 2014 10:25:46 +0100
Subject: Add TNT Save/Load and add Netbeans projects to .gitignore
---
.gitignore | 1 +
src/Entities/TNTEntity.cpp | 27 +++++++++++++++++----------
src/Entities/TNTEntity.h | 23 ++++++++++++++++-------
src/WorldStorage/NBTChunkSerializer.cpp | 15 ++++++++++++++-
src/WorldStorage/NBTChunkSerializer.h | 2 ++
src/WorldStorage/WSSAnvil.cpp | 28 ++++++++++++++++++++++++++++
src/WorldStorage/WSSAnvil.h | 1 +
7 files changed, 79 insertions(+), 18 deletions(-)
diff --git a/.gitignore b/.gitignore
index c8ad93a80..c544f394d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
build/
+nbproject/
ipch/
Win32/
MCServer/MCServer
diff --git a/src/Entities/TNTEntity.cpp b/src/Entities/TNTEntity.cpp
index 339107b2e..4f361403c 100644
--- a/src/Entities/TNTEntity.cpp
+++ b/src/Entities/TNTEntity.cpp
@@ -10,8 +10,7 @@
cTNTEntity::cTNTEntity(double a_X, double a_Y, double a_Z, double a_FuseTimeInSec) :
super(etTNT, a_X, a_Y, a_Z, 0.98, 0.98),
- m_Counter(0),
- m_MaxFuseTime(a_FuseTimeInSec)
+ m_FuseTicks(a_FuseTimeInSec)
{
}
@@ -21,8 +20,7 @@ cTNTEntity::cTNTEntity(double a_X, double a_Y, double a_Z, double a_FuseTimeInSe
cTNTEntity::cTNTEntity(const Vector3d & a_Pos, double a_FuseTimeInSec) :
super(etTNT, a_Pos.x, a_Pos.y, a_Pos.z, 0.98, 0.98),
- m_Counter(0),
- m_MaxFuseTime(a_FuseTimeInSec)
+ m_FuseTicks(a_FuseTimeInSec)
{
}
@@ -42,18 +40,27 @@ void cTNTEntity::SpawnOn(cClientHandle & a_ClientHandle)
+void cTNTEntity::Explode(void)
+{
+ m_FuseTicks = 0;
+ Destroy(true);
+ LOGD("BOOM at {%f,%f,%f}", GetPosX(), GetPosY(), GetPosZ());
+ m_World->DoExplosionAt(4.0, GetPosX() + 0.49, GetPosY() + 0.49, GetPosZ() + 0.49, true, esPrimedTNT, this);
+}
+
+
+
+
+
void cTNTEntity::Tick(float a_Dt, cChunk & a_Chunk)
{
super::Tick(a_Dt, a_Chunk);
BroadcastMovementUpdate();
float delta_time = a_Dt / 1000; // Convert miliseconds to seconds
- m_Counter += delta_time;
- if (m_Counter > m_MaxFuseTime) // Check if we go KABOOOM
+ m_FuseTicks -= delta_time;
+ if (m_FuseTicks <= 0)
{
- Destroy(true);
- LOGD("BOOM at {%f,%f,%f}", GetPosX(), GetPosY(), GetPosZ());
- m_World->DoExplosionAt(4.0, GetPosX() + 0.49, GetPosY() + 0.49, GetPosZ() + 0.49, true, esPrimedTNT, this);
- return;
+ Explode();
}
}
diff --git a/src/Entities/TNTEntity.h b/src/Entities/TNTEntity.h
index d1fcae766..8f83f52d9 100644
--- a/src/Entities/TNTEntity.h
+++ b/src/Entities/TNTEntity.h
@@ -16,19 +16,28 @@ public:
// tolua_end
CLASS_PROTODEF(cTNTEntity);
- cTNTEntity(double a_X, double a_Y, double a_Z, double a_FuseTimeInSec);
- cTNTEntity(const Vector3d & a_Pos, double a_FuseTimeInSec);
+ cTNTEntity(double a_X, double a_Y, double a_Z, double a_FuseTimeInSec = 4);
+ cTNTEntity(const Vector3d & a_Pos, double a_FuseTimeInSec = 4);
// cEntity overrides:
virtual void SpawnOn(cClientHandle & a_ClientHandle) override;
virtual void Tick(float a_Dt, cChunk & a_Chunk) override;
-
- double GetCounterTime(void) const { return m_Counter; } // tolua_export
- double GetMaxFuseTime(void) const { return m_MaxFuseTime; } // tolua_export
+
+ // tolua_begin
+
+ /** Explode the tnt */
+ void Explode(void);
+
+ /** Returns the fuse ticks until the tnt will explode */
+ double GetFuseTicks(void) const { return m_FuseTicks; }
+
+ /** Set the fuse ticks until the tnt will explode */
+ void SetFuseTicks(double a_FuseTicks) { m_FuseTicks = a_FuseTicks; }
+
+ // tolua_end
protected:
- double m_Counter; ///< How much time has elapsed since the object was created, in seconds
- double m_MaxFuseTime; ///< How long the fuse is, in seconds
+ double m_FuseTicks; ///< How much time in seconds is left, while the tnt will explode
}; // tolua_export
diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp
index 6d0e29958..06b815333 100644
--- a/src/WorldStorage/NBTChunkSerializer.cpp
+++ b/src/WorldStorage/NBTChunkSerializer.cpp
@@ -28,6 +28,7 @@
#include "../Entities/Minecart.h"
#include "../Entities/Pickup.h"
#include "../Entities/ProjectileEntity.h"
+#include "../Entities/TNTEntity.h"
#include "../Mobs/Monster.h"
#include "../Mobs/Bat.h"
@@ -583,6 +584,18 @@ void cNBTChunkSerializer::AddProjectileEntity(cProjectileEntity * a_Projectile)
+void cNBTChunkSerializer::AddTNTEntity(cTNTEntity * a_TNT)
+{
+ m_Writer.BeginCompound("");
+ AddBasicEntity(a_TNT, "PrimedTnt");
+ m_Writer.AddByte("Fuse", ((unsigned char)a_TNT->GetFuseTicks()) * 10);
+ m_Writer.EndCompound();
+}
+
+
+
+
+
void cNBTChunkSerializer::AddMinecartChestContents(cMinecartWithChest * a_Minecart)
{
m_Writer.BeginList("Items", TAG_Compound);
@@ -662,7 +675,7 @@ void cNBTChunkSerializer::Entity(cEntity * a_Entity)
case cEntity::etMonster: AddMonsterEntity ((cMonster *) a_Entity); break;
case cEntity::etPickup: AddPickupEntity ((cPickup *) a_Entity); break;
case cEntity::etProjectile: AddProjectileEntity ((cProjectileEntity *)a_Entity); break;
- case cEntity::etTNT: /* TODO */ break;
+ case cEntity::etTNT: AddTNTEntity ((cTNTEntity *) a_Entity); break;
case cEntity::etExpOrb: /* TODO */ break;
case cEntity::etItemFrame: /* TODO */ break;
case cEntity::etPainting: /* TODO */ break;
diff --git a/src/WorldStorage/NBTChunkSerializer.h b/src/WorldStorage/NBTChunkSerializer.h
index 8a9e18413..3b486d2bc 100644
--- a/src/WorldStorage/NBTChunkSerializer.h
+++ b/src/WorldStorage/NBTChunkSerializer.h
@@ -41,6 +41,7 @@ class cMonster;
class cPickup;
class cItemGrid;
class cProjectileEntity;
+class cTNTEntity;
@@ -107,6 +108,7 @@ protected:
void AddMonsterEntity (cMonster * a_Monster);
void AddPickupEntity (cPickup * a_Pickup);
void AddProjectileEntity (cProjectileEntity * a_Projectile);
+ void AddTNTEntity (cTNTEntity * a_TNT);
void AddMinecartChestContents(cMinecartWithChest * a_Minecart);
diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp
index 680f2458f..fa0c4dbd9 100644
--- a/src/WorldStorage/WSSAnvil.cpp
+++ b/src/WorldStorage/WSSAnvil.cpp
@@ -36,6 +36,7 @@
#include "../Entities/Minecart.h"
#include "../Entities/Pickup.h"
#include "../Entities/ProjectileEntity.h"
+#include "../Entities/TNTEntity.h"
@@ -1231,6 +1232,10 @@ void cWSSAnvil::LoadEntityFromNBT(cEntityList & a_Entities, const cParsedNBT & a
{
LoadPigZombieFromNBT(a_Entities, a_NBT, a_EntityTagIdx);
}
+ else if (strncmp(a_IDTag, "PrimedTnt", a_IDTagLength) == 0)
+ {
+ LoadTNTFromNBT(a_Entities, a_NBT, a_EntityTagIdx);
+ }
// TODO: other entities
}
@@ -2167,6 +2172,29 @@ void cWSSAnvil::LoadPigZombieFromNBT(cEntityList & a_Entities, const cParsedNBT
+void cWSSAnvil::LoadTNTFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx)
+{
+ std::auto_ptr TNT(new cTNTEntity(0.0, 0.0, 0.0, 0));
+ if (!LoadEntityBaseFromNBT(*TNT.get(), a_NBT, a_TagIdx))
+ {
+ return;
+ }
+
+ // Load Fuse Ticks:
+ int FuseTicks = a_NBT.FindChildByName(a_TagIdx, "Fuse");
+ if (FuseTicks > 0)
+ {
+ int MojangFuseTicks = (int) a_NBT.GetByte(FuseTicks);
+ TNT->SetFuseTicks((double) MojangFuseTicks / 10);
+ }
+
+ a_Entities.push_back(TNT.release());
+}
+
+
+
+
+
bool cWSSAnvil::LoadEntityBaseFromNBT(cEntity & a_Entity, const cParsedNBT & a_NBT, int a_TagIdx)
{
double Pos[3];
diff --git a/src/WorldStorage/WSSAnvil.h b/src/WorldStorage/WSSAnvil.h
index b26345b13..fe93d16c3 100644
--- a/src/WorldStorage/WSSAnvil.h
+++ b/src/WorldStorage/WSSAnvil.h
@@ -192,6 +192,7 @@ protected:
void LoadWolfFromNBT (cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx);
void LoadZombieFromNBT (cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx);
void LoadPigZombieFromNBT (cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx);
+ void LoadTNTFromNBT (cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx);
/// Loads entity common data from the NBT compound; returns true if successful
bool LoadEntityBaseFromNBT(cEntity & a_Entity, const cParsedNBT & a_NBT, int a_TagIdx);
--
cgit v1.2.3
From baeff21a5b693a99057aa5a7dc218bf93630b35a Mon Sep 17 00:00:00 2001
From: Howaner
Date: Sat, 8 Mar 2014 10:29:57 +0100
Subject: Add new tnt documentation
---
MCServer/Plugins/APIDump/APIDesc.lua | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua
index 39f7cbcd7..5cea49cb1 100644
--- a/MCServer/Plugins/APIDump/APIDesc.lua
+++ b/MCServer/Plugins/APIDump/APIDesc.lua
@@ -2023,8 +2023,9 @@ end
Desc = "This class manages a TNT entity.",
Functions =
{
- GetCounterTime = { Return = "number", Notes = "Returns the time until the entity explodes." },
- GetMaxFuseTime = { Return = "number", Notes = "Returns how long the fuse was." },
+ Explode = { Return = "", Notes = "Explode the tnt." },
+ GetFuseTicks = { Return = "number", Notes = "Returns the fuse ticks (in seconds) until the tnt will explode." },
+ SetFuseTicks = { Return = "number", Notes = "Set the fuse ticks (in seconds) until the tnt will explode." },
},
Inherits = "cEntity",
},
--
cgit v1.2.3
From 6679641b9e5ddb833b32ab7163cabaa8003e769e Mon Sep 17 00:00:00 2001
From: andrew
Date: Sat, 8 Mar 2014 12:53:15 +0200
Subject: cBlockInfo-related changes from #723
---
src/BlockInfo.cpp | 9 +++++++++
src/Blocks/BlockHandler.cpp | 1 +
src/Items/ItemPickaxe.h | 22 +++++++++++-----------
3 files changed, 21 insertions(+), 11 deletions(-)
diff --git a/src/BlockInfo.cpp b/src/BlockInfo.cpp
index 399efcd9b..20336a07c 100644
--- a/src/BlockInfo.cpp
+++ b/src/BlockInfo.cpp
@@ -271,6 +271,11 @@ void cBlockInfo::Initialize(void)
ms_Info[E_BLOCK_VINES ].m_IsSnowable = false;
ms_Info[E_BLOCK_WALLSIGN ].m_IsSnowable = false;
ms_Info[E_BLOCK_WATER ].m_IsSnowable = false;
+ ms_Info[E_BLOCK_RAIL ].m_IsSnowable = false;
+ ms_Info[E_BLOCK_ACTIVATOR_RAIL ].m_IsSnowable = false;
+ ms_Info[E_BLOCK_POWERED_RAIL ].m_IsSnowable = false;
+ ms_Info[E_BLOCK_DETECTOR_RAIL ].m_IsSnowable = false;
+ ms_Info[E_BLOCK_COBWEB ].m_IsSnowable = false;
// Blocks that don't drop without a special tool:
@@ -309,6 +314,10 @@ void cBlockInfo::Initialize(void)
ms_Info[E_BLOCK_STONE_PRESSURE_PLATE].m_RequiresSpecialTool = true;
ms_Info[E_BLOCK_STONE_SLAB ].m_RequiresSpecialTool = true;
ms_Info[E_BLOCK_VINES ].m_RequiresSpecialTool = true;
+ ms_Info[E_BLOCK_FURNACE ].m_RequiresSpecialTool = true;
+ ms_Info[E_BLOCK_LIT_FURNACE ].m_RequiresSpecialTool = true;
+ ms_Info[E_BLOCK_ANVIL ].m_RequiresSpecialTool = true;
+ ms_Info[E_BLOCK_ENCHANTMENT_TABLE ].m_RequiresSpecialTool = true;
// Nonsolid blocks:
diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp
index c5165986c..aa97b2ca9 100644
--- a/src/Blocks/BlockHandler.cpp
+++ b/src/Blocks/BlockHandler.cpp
@@ -146,6 +146,7 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType)
case E_BLOCK_NETHER_BRICK_STAIRS: return new cBlockStairsHandler (a_BlockType);
case E_BLOCK_NETHER_PORTAL: return new cBlockPortalHandler (a_BlockType);
case E_BLOCK_NETHER_WART: return new cBlockNetherWartHandler (a_BlockType);
+ case E_BLOCK_NETHER_QUARTZ_ORE: return new cBlockOreHandler (a_BlockType);
case E_BLOCK_NEW_LEAVES: return new cBlockNewLeavesHandler (a_BlockType);
case E_BLOCK_NEW_LOG: return new cBlockSidewaysHandler (a_BlockType);
case E_BLOCK_NOTE_BLOCK: return new cBlockNoteHandler (a_BlockType);
diff --git a/src/Items/ItemPickaxe.h b/src/Items/ItemPickaxe.h
index bde7f0905..2a8e40daa 100644
--- a/src/Items/ItemPickaxe.h
+++ b/src/Items/ItemPickaxe.h
@@ -19,17 +19,13 @@ public:
{
switch(m_ItemType)
{
- case E_ITEM_WOODEN_PICKAXE:
- case E_ITEM_GOLD_PICKAXE:
- return 1;
- case E_ITEM_STONE_PICKAXE:
- return 2;
- case E_ITEM_IRON_PICKAXE:
- return 3;
- case E_ITEM_DIAMOND_PICKAXE:
- return 4;
- default:
- return 0;
+ case E_ITEM_WOODEN_PICKAXE: return 1;
+ case E_ITEM_GOLD_PICKAXE: return 1;
+ case E_ITEM_STONE_PICKAXE: return 2;
+ case E_ITEM_IRON_PICKAXE: return 3;
+ case E_ITEM_DIAMOND_PICKAXE: return 4;
+
+ default: return 0;
}
}
@@ -61,6 +57,10 @@ public:
return PickaxeLevel() >= 2;
}
+ case E_BLOCK_ANVIL:
+ case E_BLOCK_ENCHANTMENT_TABLE:
+ case E_BLOCK_FURNACE:
+ case E_BLOCK_LIT_FURNACE:
case E_BLOCK_COAL_ORE:
case E_BLOCK_STONE:
case E_BLOCK_COBBLESTONE:
--
cgit v1.2.3
From b37966fd214fb048a415a33291a85ee8c263691c Mon Sep 17 00:00:00 2001
From: Howaner
Date: Sat, 8 Mar 2014 12:24:33 +0100
Subject: Change TNT Fuse to ticks
---
src/BlockEntities/DispenserEntity.cpp | 2 +-
src/Entities/TNTEntity.cpp | 12 ++++++------
src/Entities/TNTEntity.h | 10 +++++-----
src/Items/ItemLighter.h | 4 ++--
src/Simulator/IncrementalRedstoneSimulator.cpp | 2 +-
src/World.cpp | 4 ++--
src/World.h | 2 +-
src/WorldStorage/NBTChunkSerializer.cpp | 2 +-
src/WorldStorage/WSSAnvil.cpp | 3 +--
9 files changed, 20 insertions(+), 21 deletions(-)
diff --git a/src/BlockEntities/DispenserEntity.cpp b/src/BlockEntities/DispenserEntity.cpp
index 374f3d6e3..cbfbb1b6a 100644
--- a/src/BlockEntities/DispenserEntity.cpp
+++ b/src/BlockEntities/DispenserEntity.cpp
@@ -116,7 +116,7 @@ void cDispenserEntity::DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum)
{
double TNTX = 0.5 + (DispX + DispChunk->GetPosX() * cChunkDef::Width);
double TNTZ = 0.5 + (DispZ + DispChunk->GetPosZ() * cChunkDef::Width);
- m_World->SpawnPrimedTNT(TNTX, DispY + 0.5, TNTZ, 4, 0); // 4 seconds fuse, no initial velocity
+ m_World->SpawnPrimedTNT(TNTX, DispY + 0.5, TNTZ, 80, 0); // 80 ticks fuse, no initial velocity
m_Contents.ChangeSlotCount(a_SlotNum, -1);
}
break;
diff --git a/src/Entities/TNTEntity.cpp b/src/Entities/TNTEntity.cpp
index 4f361403c..02f31f5bb 100644
--- a/src/Entities/TNTEntity.cpp
+++ b/src/Entities/TNTEntity.cpp
@@ -8,9 +8,9 @@
-cTNTEntity::cTNTEntity(double a_X, double a_Y, double a_Z, double a_FuseTimeInSec) :
+cTNTEntity::cTNTEntity(double a_X, double a_Y, double a_Z, int a_FuseTicks) :
super(etTNT, a_X, a_Y, a_Z, 0.98, 0.98),
- m_FuseTicks(a_FuseTimeInSec)
+ m_FuseTicks(a_FuseTicks)
{
}
@@ -18,9 +18,9 @@ cTNTEntity::cTNTEntity(double a_X, double a_Y, double a_Z, double a_FuseTimeInSe
-cTNTEntity::cTNTEntity(const Vector3d & a_Pos, double a_FuseTimeInSec) :
+cTNTEntity::cTNTEntity(const Vector3d & a_Pos, int a_FuseTicks) :
super(etTNT, a_Pos.x, a_Pos.y, a_Pos.z, 0.98, 0.98),
- m_FuseTicks(a_FuseTimeInSec)
+ m_FuseTicks(a_FuseTicks)
{
}
@@ -56,8 +56,8 @@ void cTNTEntity::Tick(float a_Dt, cChunk & a_Chunk)
{
super::Tick(a_Dt, a_Chunk);
BroadcastMovementUpdate();
- float delta_time = a_Dt / 1000; // Convert miliseconds to seconds
- m_FuseTicks -= delta_time;
+
+ m_FuseTicks -= 1;
if (m_FuseTicks <= 0)
{
Explode();
diff --git a/src/Entities/TNTEntity.h b/src/Entities/TNTEntity.h
index 8f83f52d9..116f5a8cb 100644
--- a/src/Entities/TNTEntity.h
+++ b/src/Entities/TNTEntity.h
@@ -16,8 +16,8 @@ public:
// tolua_end
CLASS_PROTODEF(cTNTEntity);
- cTNTEntity(double a_X, double a_Y, double a_Z, double a_FuseTimeInSec = 4);
- cTNTEntity(const Vector3d & a_Pos, double a_FuseTimeInSec = 4);
+ cTNTEntity(double a_X, double a_Y, double a_Z, int a_FuseTicks = 80);
+ cTNTEntity(const Vector3d & a_Pos, int a_FuseTicks = 80);
// cEntity overrides:
virtual void SpawnOn(cClientHandle & a_ClientHandle) override;
@@ -29,15 +29,15 @@ public:
void Explode(void);
/** Returns the fuse ticks until the tnt will explode */
- double GetFuseTicks(void) const { return m_FuseTicks; }
+ int GetFuseTicks(void) const { return m_FuseTicks; }
/** Set the fuse ticks until the tnt will explode */
- void SetFuseTicks(double a_FuseTicks) { m_FuseTicks = a_FuseTicks; }
+ void SetFuseTicks(int a_FuseTicks) { m_FuseTicks = a_FuseTicks; }
// tolua_end
protected:
- double m_FuseTicks; ///< How much time in seconds is left, while the tnt will explode
+ int m_FuseTicks; ///< How much ticks is left, while the tnt will explode
}; // tolua_export
diff --git a/src/Items/ItemLighter.h b/src/Items/ItemLighter.h
index cc7daeb08..18873e911 100644
--- a/src/Items/ItemLighter.h
+++ b/src/Items/ItemLighter.h
@@ -33,8 +33,8 @@ public:
case E_BLOCK_TNT:
{
// Activate the TNT:
- a_World->BroadcastSoundEffect("game.tnt.primed", a_BlockX * 8, a_BlockY * 8, a_BlockZ * 8, 0.5f, 0.6f);
- a_World->SpawnPrimedTNT(a_BlockX + 0.5, a_BlockY + 0.5, a_BlockZ + 0.5, 4); // 4 seconds to boom
+ a_World->BroadcastSoundEffect("game.tnt.primed", a_BlockX * 8, a_BlockY * 8, a_BlockZ * 8, 1.0f, 1.0f);
+ a_World->SpawnPrimedTNT(a_BlockX + 0.5, a_BlockY + 0.5, a_BlockZ + 0.5); // 80 ticks to boom
a_World->SetBlock(a_BlockX,a_BlockY,a_BlockZ, E_BLOCK_AIR, 0);
break;
}
diff --git a/src/Simulator/IncrementalRedstoneSimulator.cpp b/src/Simulator/IncrementalRedstoneSimulator.cpp
index f377b0aa7..ca2ef4b1a 100644
--- a/src/Simulator/IncrementalRedstoneSimulator.cpp
+++ b/src/Simulator/IncrementalRedstoneSimulator.cpp
@@ -838,7 +838,7 @@ void cIncrementalRedstoneSimulator::HandleTNT(int a_BlockX, int a_BlockY, int a_
if (AreCoordsPowered(a_BlockX, a_BlockY, a_BlockZ))
{
m_World.BroadcastSoundEffect("game.tnt.primed", a_BlockX * 8, a_BlockY * 8, a_BlockZ * 8, 0.5f, 0.6f);
- m_World.SpawnPrimedTNT(a_BlockX + 0.5, a_BlockY + 0.5, a_BlockZ + 0.5, 4); // 4 seconds to boom
+ m_World.SpawnPrimedTNT(a_BlockX + 0.5, a_BlockY + 0.5, a_BlockZ + 0.5); // 80 ticks to boom
m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0);
}
}
diff --git a/src/World.cpp b/src/World.cpp
index ecb278e85..ebc37f7b2 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -1725,10 +1725,10 @@ int cWorld::SpawnMinecart(double a_X, double a_Y, double a_Z, int a_MinecartType
-void cWorld::SpawnPrimedTNT(double a_X, double a_Y, double a_Z, double a_FuseTimeInSec, double a_InitialVelocityCoeff)
+void cWorld::SpawnPrimedTNT(double a_X, double a_Y, double a_Z, int a_FuseTicks, double a_InitialVelocityCoeff)
{
UNUSED(a_InitialVelocityCoeff);
- cTNTEntity * TNT = new cTNTEntity(a_X, a_Y, a_Z, a_FuseTimeInSec);
+ cTNTEntity * TNT = new cTNTEntity(a_X, a_Y, a_Z, a_FuseTicks);
TNT->Initialize(this);
// TODO: Add a bit of speed in horiz and vert axes, based on the a_InitialVelocityCoeff
}
diff --git a/src/World.h b/src/World.h
index e6c665785..517b6b4fa 100644
--- a/src/World.h
+++ b/src/World.h
@@ -445,7 +445,7 @@ public:
int SpawnExperienceOrb(double a_X, double a_Y, double a_Z, int a_Reward);
/** Spawns a new primed TNT entity at the specified block coords and specified fuse duration. Initial velocity is given based on the relative coefficient provided */
- void SpawnPrimedTNT(double a_X, double a_Y, double a_Z, double a_FuseTimeInSec, double a_InitialVelocityCoeff = 1);
+ void SpawnPrimedTNT(double a_X, double a_Y, double a_Z, int a_FuseTimeInSec = 80, double a_InitialVelocityCoeff = 1);
// tolua_end
diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp
index 06b815333..17cf838c3 100644
--- a/src/WorldStorage/NBTChunkSerializer.cpp
+++ b/src/WorldStorage/NBTChunkSerializer.cpp
@@ -588,7 +588,7 @@ void cNBTChunkSerializer::AddTNTEntity(cTNTEntity * a_TNT)
{
m_Writer.BeginCompound("");
AddBasicEntity(a_TNT, "PrimedTnt");
- m_Writer.AddByte("Fuse", ((unsigned char)a_TNT->GetFuseTicks()) * 10);
+ m_Writer.AddByte("Fuse", (unsigned char)a_TNT->GetFuseTicks());
m_Writer.EndCompound();
}
diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp
index fa0c4dbd9..b52b74932 100644
--- a/src/WorldStorage/WSSAnvil.cpp
+++ b/src/WorldStorage/WSSAnvil.cpp
@@ -2184,8 +2184,7 @@ void cWSSAnvil::LoadTNTFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NB
int FuseTicks = a_NBT.FindChildByName(a_TagIdx, "Fuse");
if (FuseTicks > 0)
{
- int MojangFuseTicks = (int) a_NBT.GetByte(FuseTicks);
- TNT->SetFuseTicks((double) MojangFuseTicks / 10);
+ TNT->SetFuseTicks((int) a_NBT.GetByte(FuseTicks));
}
a_Entities.push_back(TNT.release());
--
cgit v1.2.3
From 60091bcba3f5e533a5b2a749e40f52556297e867 Mon Sep 17 00:00:00 2001
From: Howaner
Date: Sat, 8 Mar 2014 12:31:20 +0100
Subject: Change tnt documentation to ticks
---
MCServer/Plugins/APIDump/APIDesc.lua | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua
index 6d8272a95..28dffc1b6 100644
--- a/MCServer/Plugins/APIDump/APIDesc.lua
+++ b/MCServer/Plugins/APIDump/APIDesc.lua
@@ -2026,8 +2026,8 @@ end
Functions =
{
Explode = { Return = "", Notes = "Explode the tnt." },
- GetFuseTicks = { Return = "number", Notes = "Returns the fuse ticks (in seconds) until the tnt will explode." },
- SetFuseTicks = { Return = "number", Notes = "Set the fuse ticks (in seconds) until the tnt will explode." },
+ GetFuseTicks = { Return = "number", Notes = "Returns the fuse ticks until the tnt will explode." },
+ SetFuseTicks = { Return = "number", Notes = "Set the fuse ticks until the tnt will explode." },
},
Inherits = "cEntity",
},
@@ -2262,7 +2262,7 @@ end
SpawnMob = { Params = "X, Y, Z, {{cMonster|MonsterType}}", Return = "EntityID", Notes = "Spawns the specified type of mob at the specified coords. Returns the EntityID of the creates entity, or -1 on failure. " },
SpawnFallingBlock = { Params = "X, Y, Z, BlockType, BlockMeta", Return = "EntityID", Notes = "Spawns an {{cFallingBlock|Falling Block}} entity at the specified coords with the given block type/meta" },
SpawnExperienceOrb = { Params = "X, Y, Z, Reward", Return = "EntityID", Notes = "Spawns an {{cExpOrb|experience orb}} at the specified coords, with the given reward" },
- SpawnPrimedTNT = { Params = "X, Y, Z, FuseTimeSecs, InitialVelocityCoeff", Return = "", Notes = "Spawns a {{cTNTEntity|primed TNT entity}} at the specified coords, with the given fuse time. The entity gets a random speed multiplied by the InitialVelocityCoeff, 1 being the default value." },
+ SpawnPrimedTNT = { Params = "X, Y, Z, FuseTicks, InitialVelocityCoeff", Return = "", Notes = "Spawns a {{cTNTEntity|primed TNT entity}} at the specified coords, with the given fuse ticks. The entity gets a random speed multiplied by the InitialVelocityCoeff, 1 being the default value." },
TryGetHeight = { Params = "BlockX, BlockZ", Return = "IsValid, Height", Notes = "Returns true and height of the highest non-air block if the chunk is loaded, or false otherwise." },
UpdateSign = { Params = "X, Y, Z, Line1, Line2, Line3, Line4, [{{cPlayer|Player}}]", Return = "", Notes = "Sets the sign text at the specified coords. The sign-updating hooks are called for the change. The Player parameter is used to indicate the player from whom the change has come, it may be nil. Same as SetSignLiens()" },
UseBlockEntity = { Params = "{{cPlayer|Player}}, BlockX, BlockY, BlockZ", Return = "", Notes = "Makes the specified Player use the block entity at the specified coords (open chest UI, etc.) If the cords are in an unloaded chunk or there's no block entity, ignores the call." },
--
cgit v1.2.3
From 16ebbca35b8fc91061f0141625c292a8096e3b6d Mon Sep 17 00:00:00 2001
From: worktycho
Date: Sat, 8 Mar 2014 14:23:00 +0000
Subject: Moved returns
---
src/Blocks/MetaRotater.h | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/Blocks/MetaRotater.h b/src/Blocks/MetaRotater.h
index 5493c87e2..d3664b6f1 100644
--- a/src/Blocks/MetaRotater.h
+++ b/src/Blocks/MetaRotater.h
@@ -1,4 +1,3 @@
-
// MetaRotater.h
// Provides a mixin for rotations and reflections
@@ -44,11 +43,12 @@ NIBBLETYPE cMetaRotater
NIBBLETYPE cMetaRotater::MetaRotateCCW(NIBBLETYPE a_Meta)
{
@@ -63,8 +63,8 @@ NIBBLETYPE cMetaRotater
Date: Sat, 8 Mar 2014 15:21:09 +0000
Subject: Disable -Werror on this branch
---
SetFlags.cmake | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/SetFlags.cmake b/SetFlags.cmake
index 35831e7e9..6a8211fa2 100644
--- a/SetFlags.cmake
+++ b/SetFlags.cmake
@@ -182,7 +182,7 @@ macro(set_exe_flags)
string(REPLACE "-w" "" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
string(REPLACE "-w" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
string(REPLACE "-w" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
- add_flags_cxx("-Wall -Wextra -Werror -Wno-error=unused-parameter")
+ add_flags_cxx("-Wall -Wextra")
# we support non-IEEE 754 fpus so can make no guarentees about error
add_flags_cxx("-ffast-math")
--
cgit v1.2.3
From 9b47366d0323f09c77b607da778191e79b65335b Mon Sep 17 00:00:00 2001
From: Tycho
Date: Sat, 8 Mar 2014 07:36:52 -0800
Subject: Actually Fixed ByteBuffer
---
src/ByteBuffer.cpp | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/ByteBuffer.cpp b/src/ByteBuffer.cpp
index 32a367462..8080c1bdc 100644
--- a/src/ByteBuffer.cpp
+++ b/src/ByteBuffer.cpp
@@ -650,7 +650,7 @@ bool cByteBuffer::WriteLEInt(int a_Value)
-bool cByteBuffer::ReadBuf(void * a_Buffer, int a_Count)
+bool cByteBuffer::ReadBuf(void * a_Buffer, size_t a_Count)
{
CHECK_THREAD;
CheckValid();
@@ -684,7 +684,7 @@ bool cByteBuffer::ReadBuf(void * a_Buffer, int a_Count)
-bool cByteBuffer::WriteBuf(const void * a_Buffer, int a_Count)
+bool cByteBuffer::WriteBuf(const void * a_Buffer, size_t a_Count)
{
CHECK_THREAD;
CheckValid();
@@ -714,7 +714,7 @@ bool cByteBuffer::WriteBuf(const void * a_Buffer, int a_Count)
-bool cByteBuffer::ReadString(AString & a_String, int a_Count)
+bool cByteBuffer::ReadString(AString & a_String, size_t a_Count)
{
CHECK_THREAD;
CheckValid();
--
cgit v1.2.3
From 307fad0f257c825c8d433a3e82f2989a8fddd3e0 Mon Sep 17 00:00:00 2001
From: Tycho
Date: Sat, 8 Mar 2014 08:33:38 -0800
Subject: Fixed issues with int vs size_t and a few other warnings
---
src/BlockInfo.cpp | 2 --
src/Blocks/BlockHandler.h | 2 ++
src/ByteBuffer.cpp | 20 ++++++++++----------
src/ByteBuffer.h | 6 +++---
src/ClientHandle.cpp | 4 ++--
src/Entities/Minecart.cpp | 4 ++--
src/Entities/Minecart.h | 4 ++--
src/Protocol/Protocol17x.cpp | 4 ++--
src/Root.cpp | 6 ++----
src/Simulator/DelayedFluidSimulator.cpp | 2 +-
10 files changed, 26 insertions(+), 28 deletions(-)
diff --git a/src/BlockInfo.cpp b/src/BlockInfo.cpp
index 20336a07c..d1ecfdf7e 100644
--- a/src/BlockInfo.cpp
+++ b/src/BlockInfo.cpp
@@ -42,8 +42,6 @@ cBlockInfo::~cBlockInfo()
cBlockInfo & cBlockInfo::Get(BLOCKTYPE a_Type)
{
- ASSERT(a_Type < 256);
-
return ms_Info[a_Type];
}
diff --git a/src/Blocks/BlockHandler.h b/src/Blocks/BlockHandler.h
index 50c2e2ad5..3a3efb3cc 100644
--- a/src/Blocks/BlockHandler.h
+++ b/src/Blocks/BlockHandler.h
@@ -23,6 +23,8 @@ class cBlockHandler
{
public:
cBlockHandler(BLOCKTYPE a_BlockType);
+
+ virtual ~cBlockHandler() {}
/// Called when the block gets ticked either by a random tick or by a queued tick.
/// Note that the coords are chunk-relative!
diff --git a/src/ByteBuffer.cpp b/src/ByteBuffer.cpp
index 8080c1bdc..bda1105f5 100644
--- a/src/ByteBuffer.cpp
+++ b/src/ByteBuffer.cpp
@@ -177,15 +177,15 @@ bool cByteBuffer::Write(const char * a_Bytes, size_t a_Count)
CheckValid();
// Store the current free space for a check after writing:
- int CurFreeSpace = GetFreeSpace();
- int CurReadableSpace = GetReadableSpace();
- int WrittenBytes = 0;
+ size_t CurFreeSpace = GetFreeSpace();
+ size_t CurReadableSpace = GetReadableSpace();
+ size_t WrittenBytes = 0;
if (CurFreeSpace < a_Count)
{
return false;
}
- int TillEnd = m_BufferSize - m_WritePos;
+ size_t TillEnd = m_BufferSize - m_WritePos;
if (TillEnd <= a_Count)
{
// Need to wrap around the ringbuffer end
@@ -216,7 +216,7 @@ bool cByteBuffer::Write(const char * a_Bytes, size_t a_Count)
-int cByteBuffer::GetFreeSpace(void) const
+size_t cByteBuffer::GetFreeSpace(void) const
{
CHECK_THREAD;
CheckValid();
@@ -234,7 +234,7 @@ int cByteBuffer::GetFreeSpace(void) const
/// Returns the number of bytes that are currently in the ringbuffer. Note GetReadableBytes()
-int cByteBuffer::GetUsedSpace(void) const
+size_t cByteBuffer::GetUsedSpace(void) const
{
CHECK_THREAD;
CheckValid();
@@ -246,7 +246,7 @@ int cByteBuffer::GetUsedSpace(void) const
/// Returns the number of bytes that are currently available for reading (may be less than UsedSpace due to some data having been read already)
-int cByteBuffer::GetReadableSpace(void) const
+size_t cByteBuffer::GetReadableSpace(void) const
{
CHECK_THREAD;
CheckValid();
@@ -657,7 +657,7 @@ bool cByteBuffer::ReadBuf(void * a_Buffer, size_t a_Count)
ASSERT(a_Count >= 0);
NEEDBYTES(a_Count);
char * Dst = (char *)a_Buffer; // So that we can do byte math
- int BytesToEndOfBuffer = m_BufferSize - m_ReadPos;
+ size_t BytesToEndOfBuffer = m_BufferSize - m_ReadPos;
ASSERT(BytesToEndOfBuffer >= 0); // Sanity check
if (BytesToEndOfBuffer <= a_Count)
{
@@ -691,7 +691,7 @@ bool cByteBuffer::WriteBuf(const void * a_Buffer, size_t a_Count)
ASSERT(a_Count >= 0);
PUTBYTES(a_Count);
char * Src = (char *)a_Buffer; // So that we can do byte math
- int BytesToEndOfBuffer = m_BufferSize - m_WritePos;
+ size_t BytesToEndOfBuffer = m_BufferSize - m_WritePos;
if (BytesToEndOfBuffer <= a_Count)
{
// Reading across the ringbuffer end, read the first part and adjust parameters:
@@ -722,7 +722,7 @@ bool cByteBuffer::ReadString(AString & a_String, size_t a_Count)
NEEDBYTES(a_Count);
a_String.clear();
a_String.reserve(a_Count);
- int BytesToEndOfBuffer = m_BufferSize - m_ReadPos;
+ size_t BytesToEndOfBuffer = m_BufferSize - m_ReadPos;
ASSERT(BytesToEndOfBuffer >= 0); // Sanity check
if (BytesToEndOfBuffer <= a_Count)
{
diff --git a/src/ByteBuffer.h b/src/ByteBuffer.h
index 5fdf48c28..ed2e10a55 100644
--- a/src/ByteBuffer.h
+++ b/src/ByteBuffer.h
@@ -34,13 +34,13 @@ public:
bool Write(const char * a_Bytes, size_t a_Count);
/// Returns the number of bytes that can be successfully written to the ringbuffer
- int GetFreeSpace(void) const;
+ size_t GetFreeSpace(void) const;
/// Returns the number of bytes that are currently in the ringbuffer. Note GetReadableBytes()
- int GetUsedSpace(void) const;
+ size_t GetUsedSpace(void) const;
/// Returns the number of bytes that are currently available for reading (may be less than UsedSpace due to some data having been read already)
- int GetReadableSpace(void) const;
+ size_t GetReadableSpace(void) const;
/// Returns the current data start index. For debugging purposes.
int GetDataStart(void) const { return m_DataStart; }
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index 870568cdf..53c859721 100644
--- a/src/ClientHandle.cpp
+++ b/src/ClientHandle.cpp
@@ -96,8 +96,8 @@ cClientHandle::cClientHandle(const cSocket * a_Socket, int a_ViewDistance) :
m_ShouldCheckDownloaded(false),
m_NumExplosionsThisTick(0),
m_UniqueID(0),
- m_Locale("en_GB"),
- m_HasSentPlayerChunk(false)
+ m_HasSentPlayerChunk(false),
+ m_Locale("en_GB")
{
m_Protocol = new cProtocolRecognizer(this);
diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp
index f52a7b6d9..7f38aa35a 100644
--- a/src/Entities/Minecart.cpp
+++ b/src/Entities/Minecart.cpp
@@ -1031,9 +1031,9 @@ cMinecartWithChest::cMinecartWithChest(double a_X, double a_Y, double a_Z) :
-void cMinecartWithChest::SetSlot(int a_Idx, const cItem & a_Item)
+void cMinecartWithChest::SetSlot(size_t a_Idx, const cItem & a_Item)
{
- ASSERT((a_Idx >= 0) && (a_Idx < ARRAYCOUNT(m_Items)));
+ ASSERT(a_Idx < ARRAYCOUNT(m_Items));
m_Items[a_Idx] = a_Item;
}
diff --git a/src/Entities/Minecart.h b/src/Entities/Minecart.h
index 073e78953..ebdb576e0 100644
--- a/src/Entities/Minecart.h
+++ b/src/Entities/Minecart.h
@@ -122,7 +122,7 @@ public:
const cItem & GetSlot(int a_Idx) const { return m_Items[a_Idx]; }
cItem & GetSlot(int a_Idx) { return m_Items[a_Idx]; }
- void SetSlot(int a_Idx, const cItem & a_Item);
+ void SetSlot(size_t a_Idx, const cItem & a_Item);
protected:
@@ -193,4 +193,4 @@ public:
CLASS_PROTODEF(cMinecartWithHopper);
cMinecartWithHopper(double a_X, double a_Y, double a_Z);
-} ;
\ No newline at end of file
+} ;
diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp
index cb9e5b9b1..8e0d33227 100644
--- a/src/Protocol/Protocol17x.cpp
+++ b/src/Protocol/Protocol17x.cpp
@@ -1244,7 +1244,7 @@ void cProtocol172::AddReceivedData(const char * a_Data, int a_Size)
if (m_ReceivedData.GetReadableSpace() > 0)
{
AString AllData;
- int OldReadableSpace = m_ReceivedData.GetReadableSpace();
+ size_t OldReadableSpace = m_ReceivedData.GetReadableSpace();
m_ReceivedData.ReadAll(AllData);
m_ReceivedData.ResetRead();
m_ReceivedData.SkipRead(m_ReceivedData.GetReadableSpace() - OldReadableSpace);
@@ -1366,7 +1366,7 @@ void cProtocol172::AddReceivedData(const char * a_Data, int a_Size)
if (g_ShouldLogCommIn && (m_ReceivedData.GetReadableSpace() > 0))
{
AString AllData;
- int OldReadableSpace = m_ReceivedData.GetReadableSpace();
+ size_t OldReadableSpace = m_ReceivedData.GetReadableSpace();
m_ReceivedData.ReadAll(AllData);
m_ReceivedData.ResetRead();
m_ReceivedData.SkipRead(m_ReceivedData.GetReadableSpace() - OldReadableSpace);
diff --git a/src/Root.cpp b/src/Root.cpp
index 78c94888d..69f18104e 100644
--- a/src/Root.cpp
+++ b/src/Root.cpp
@@ -593,7 +593,6 @@ bool cRoot::FindAndDoWithPlayer(const AString & a_PlayerName, cPlayerListCallbac
unsigned m_NameLength;
const AString m_PlayerName;
- cPlayerListCallback & m_Callback;
virtual bool Item (cPlayer * a_pPlayer)
{
unsigned int Rating = RateCompareString (m_PlayerName, a_pPlayer->GetName());
@@ -615,18 +614,17 @@ bool cRoot::FindAndDoWithPlayer(const AString & a_PlayerName, cPlayerListCallbac
}
public:
- cCallback (const AString & a_PlayerName, cPlayerListCallback & a_Callback) :
+ cCallback (const AString & a_PlayerName) :
m_BestRating(0),
m_NameLength(a_PlayerName.length()),
m_PlayerName(a_PlayerName),
- m_Callback(a_Callback),
m_BestMatch(NULL),
m_NumMatches(0)
{}
cPlayer * m_BestMatch;
unsigned m_NumMatches;
- } Callback (a_PlayerName, a_Callback);
+ } Callback (a_PlayerName);
ForEachPlayer( Callback );
if (Callback.m_NumMatches == 1)
diff --git a/src/Simulator/DelayedFluidSimulator.cpp b/src/Simulator/DelayedFluidSimulator.cpp
index 3d2170e44..bc5158d95 100644
--- a/src/Simulator/DelayedFluidSimulator.cpp
+++ b/src/Simulator/DelayedFluidSimulator.cpp
@@ -20,7 +20,7 @@
bool cDelayedFluidSimulatorChunkData::cSlot::Add(int a_RelX, int a_RelY, int a_RelZ)
{
ASSERT(a_RelZ >= 0);
- ASSERT(a_RelZ < ARRAYCOUNT(m_Blocks));
+ ASSERT(a_RelZ < static_cast(ARRAYCOUNT(m_Blocks)));
cCoordWithIntVector & Blocks = m_Blocks[a_RelZ];
int Index = cChunkDef::MakeIndexNoCheck(a_RelX, a_RelY, a_RelZ);
--
cgit v1.2.3
From 66970fe943ccc414c2f4fb722852f0461b8ddca2 Mon Sep 17 00:00:00 2001
From: Jan-Fabian Humann
Date: Sat, 8 Mar 2014 17:55:53 +0100
Subject: Split cClientHandle::HandleEntityAction() into three seperate
functions HandleEntityCrouch, HandleEntityLeaveBed and HandleEntitySprinting.
---
src/ClientHandle.cpp | 58 +++++++++++++++++++++++---------------------
src/ClientHandle.h | 4 ++-
src/Protocol/Protocol125.cpp | 23 +++++++++++++++++-
src/Protocol/Protocol16x.cpp | 23 +++++++++++++++++-
src/Protocol/Protocol17x.cpp | 22 ++++++++++++++++-
5 files changed, 98 insertions(+), 32 deletions(-)
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index 870568cdf..79fdc5e04 100644
--- a/src/ClientHandle.cpp
+++ b/src/ClientHandle.cpp
@@ -1453,7 +1453,7 @@ bool cClientHandle::HandleHandshake(const AString & a_Username)
-void cClientHandle::HandleEntityAction(int a_EntityID, char a_ActionID)
+void cClientHandle::HandleEntityCrouch(int a_EntityID, bool a_IsCrouching)
{
if (a_EntityID != m_Player->GetUniqueID())
{
@@ -1461,35 +1461,37 @@ void cClientHandle::HandleEntityAction(int a_EntityID, char a_ActionID)
return;
}
- switch (a_ActionID)
+ m_Player->SetCrouch(a_IsCrouching);
+}
+
+
+
+
+
+void cClientHandle::HandleEntityLeaveBed(int a_EntityID)
+{
+ if (a_EntityID != m_Player->GetUniqueID())
{
- case 1: // Crouch
- {
- m_Player->SetCrouch(true);
- break;
- }
- case 2: // Uncrouch
- {
- m_Player->SetCrouch(false);
- break;
- }
- case 3: // Leave bed
- {
- m_Player->GetWorld()->BroadcastEntityAnimation(*m_Player, 2);
- break;
- }
- case 4: // Start sprinting
- {
- m_Player->SetSprint(true);
- break;
- }
- case 5: // Stop sprinting
- {
- m_Player->SetSprint(false);
- SendPlayerMaxSpeed();
- break;
- }
+ // We should only receive entity actions from the entity that is performing the action
+ return;
}
+
+ m_Player->GetWorld()->BroadcastEntityAnimation(*m_Player, 2);
+}
+
+
+
+
+
+void cClientHandle::HandleEntitySprinting(int a_EntityID, bool a_IsSprinting)
+{
+ if (a_EntityID != m_Player->GetUniqueID())
+ {
+ // We should only receive entity actions from the entity that is performing the action
+ return;
+ }
+
+ m_Player->SetSprint(a_IsSprinting);
}
diff --git a/src/ClientHandle.h b/src/ClientHandle.h
index 194533402..035fadfe4 100644
--- a/src/ClientHandle.h
+++ b/src/ClientHandle.h
@@ -188,7 +188,9 @@ public:
void HandleChat (const AString & a_Message);
void HandleCreativeInventory(short a_SlotNum, const cItem & a_HeldItem);
void HandleDisconnect (const AString & a_Reason);
- void HandleEntityAction (int a_EntityID, char a_ActionID);
+ void HandleEntityCrouch (int a_EntityID, bool a_IsCrouching);
+ void HandleEntityLeaveBed (int a_EntityID);
+ void HandleEntitySprinting (int a_EntityID, bool a_IsSprinting);
/** Called when the protocol handshake has been received (for protocol versions that support it;
otherwise the first instant when a username is received).
diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp
index 3980350f5..556ed1d08 100644
--- a/src/Protocol/Protocol125.cpp
+++ b/src/Protocol/Protocol125.cpp
@@ -1375,7 +1375,28 @@ int cProtocol125::ParseEntityAction(void)
{
HANDLE_PACKET_READ(ReadBEInt, int, EntityID);
HANDLE_PACKET_READ(ReadChar, char, ActionID);
- m_Client->HandleEntityAction(EntityID, ActionID);
+
+ if (ActionID == 1) // Crouch
+ {
+ m_Client->HandleEntityCrouch(EntityID, true);
+ }
+ else if (ActionID == 2) // Uncrouch
+ {
+ m_Client->HandleEntityCrouch(EntityID, false);
+ }
+ else if (ActionID == 3) // Leave Bed
+ {
+ m_Client->HandleEntityLeaveBed(EntityID);
+ }
+ else if (ActionID == 4) // Start sprinting
+ {
+ m_Client->HandleEntitySprinting(EntityID, true);
+ }
+ else if (ActionID == 5) // Stop sprinting
+ {
+ m_Client->HandleEntitySprinting(EntityID, false);
+ }
+
return PARSE_OK;
}
diff --git a/src/Protocol/Protocol16x.cpp b/src/Protocol/Protocol16x.cpp
index cfa27b3c4..6a41a577f 100644
--- a/src/Protocol/Protocol16x.cpp
+++ b/src/Protocol/Protocol16x.cpp
@@ -184,7 +184,28 @@ int cProtocol161::ParseEntityAction(void)
HANDLE_PACKET_READ(ReadBEInt, int, EntityID);
HANDLE_PACKET_READ(ReadChar, char, ActionID);
HANDLE_PACKET_READ(ReadBEInt, int, UnknownHorseVal);
- m_Client->HandleEntityAction(EntityID, ActionID);
+
+ if (ActionID == 1) // Crouch
+ {
+ m_Client->HandleEntityCrouch(EntityID, true);
+ }
+ else if (ActionID == 2) // Uncrouch
+ {
+ m_Client->HandleEntityCrouch(EntityID, false);
+ }
+ else if (ActionID == 3) // Leave Bed
+ {
+ m_Client->HandleEntityLeaveBed(EntityID);
+ }
+ else if (ActionID == 4) // Start sprinting
+ {
+ m_Client->HandleEntitySprinting(EntityID, true);
+ }
+ else if (ActionID == 5) // Stop sprinting
+ {
+ m_Client->HandleEntitySprinting(EntityID, false);
+ }
+
return PARSE_OK;
}
diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp
index 18646254f..19998a483 100644
--- a/src/Protocol/Protocol17x.cpp
+++ b/src/Protocol/Protocol17x.cpp
@@ -1732,7 +1732,27 @@ void cProtocol172::HandlePacketEntityAction(cByteBuffer & a_ByteBuffer)
HANDLE_READ(a_ByteBuffer, ReadBEInt, int, PlayerID);
HANDLE_READ(a_ByteBuffer, ReadByte, Byte, Action);
HANDLE_READ(a_ByteBuffer, ReadBEInt, int, JumpBoost);
- m_Client->HandleEntityAction(PlayerID, Action);
+
+ if (Action == 1) // Crouch
+ {
+ m_Client->HandleEntityCrouch(PlayerID, true);
+ }
+ else if (Action == 2) // Uncrouch
+ {
+ m_Client->HandleEntityCrouch(PlayerID, false);
+ }
+ else if (Action == 3) // Leave Bed
+ {
+ m_Client->HandleEntityLeaveBed(PlayerID);
+ }
+ else if (Action == 4) // Start sprinting
+ {
+ m_Client->HandleEntitySprinting(PlayerID, true);
+ }
+ else if (Action == 5) // Stop sprinting
+ {
+ m_Client->HandleEntitySprinting(PlayerID, false);
+ }
}
--
cgit v1.2.3
From 72f9c8b06970cb351121ad1e02cccc268db8c56d Mon Sep 17 00:00:00 2001
From: Jan-Fabian Humann
Date: Sat, 8 Mar 2014 19:26:32 +0100
Subject: Changed if-else to switch-case
---
src/Protocol/Protocol125.cpp | 24 +++++++++++-------------
src/Protocol/Protocol16x.cpp | 24 +++++++++++-------------
src/Protocol/Protocol17x.cpp | 24 +++++++++++-------------
3 files changed, 33 insertions(+), 39 deletions(-)
diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp
index 556ed1d08..169ab0c85 100644
--- a/src/Protocol/Protocol125.cpp
+++ b/src/Protocol/Protocol125.cpp
@@ -1376,25 +1376,23 @@ int cProtocol125::ParseEntityAction(void)
HANDLE_PACKET_READ(ReadBEInt, int, EntityID);
HANDLE_PACKET_READ(ReadChar, char, ActionID);
- if (ActionID == 1) // Crouch
+ switch (ActionID)
{
+ case 1: // Crouch
m_Client->HandleEntityCrouch(EntityID, true);
- }
- else if (ActionID == 2) // Uncrouch
- {
+ break;
+ case 2: // Uncrouch
m_Client->HandleEntityCrouch(EntityID, false);
- }
- else if (ActionID == 3) // Leave Bed
- {
+ break;
+ case 3: // Leave Bed
m_Client->HandleEntityLeaveBed(EntityID);
- }
- else if (ActionID == 4) // Start sprinting
- {
+ break;
+ case 4: // Start sprinting
m_Client->HandleEntitySprinting(EntityID, true);
- }
- else if (ActionID == 5) // Stop sprinting
- {
+ break;
+ case 5: // Stop sprinting
m_Client->HandleEntitySprinting(EntityID, false);
+ break;
}
return PARSE_OK;
diff --git a/src/Protocol/Protocol16x.cpp b/src/Protocol/Protocol16x.cpp
index 6a41a577f..4b1b4f408 100644
--- a/src/Protocol/Protocol16x.cpp
+++ b/src/Protocol/Protocol16x.cpp
@@ -185,25 +185,23 @@ int cProtocol161::ParseEntityAction(void)
HANDLE_PACKET_READ(ReadChar, char, ActionID);
HANDLE_PACKET_READ(ReadBEInt, int, UnknownHorseVal);
- if (ActionID == 1) // Crouch
+ switch (ActionID)
{
+ case 1: // Crouch
m_Client->HandleEntityCrouch(EntityID, true);
- }
- else if (ActionID == 2) // Uncrouch
- {
+ break;
+ case 2: // Uncrouch
m_Client->HandleEntityCrouch(EntityID, false);
- }
- else if (ActionID == 3) // Leave Bed
- {
+ break;
+ case 3: // Leave Bed
m_Client->HandleEntityLeaveBed(EntityID);
- }
- else if (ActionID == 4) // Start sprinting
- {
+ break;
+ case 4: // Start sprinting
m_Client->HandleEntitySprinting(EntityID, true);
- }
- else if (ActionID == 5) // Stop sprinting
- {
+ break;
+ case 5: // Stop sprinting
m_Client->HandleEntitySprinting(EntityID, false);
+ break;
}
return PARSE_OK;
diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp
index 19998a483..b0ec72a7d 100644
--- a/src/Protocol/Protocol17x.cpp
+++ b/src/Protocol/Protocol17x.cpp
@@ -1733,25 +1733,23 @@ void cProtocol172::HandlePacketEntityAction(cByteBuffer & a_ByteBuffer)
HANDLE_READ(a_ByteBuffer, ReadByte, Byte, Action);
HANDLE_READ(a_ByteBuffer, ReadBEInt, int, JumpBoost);
- if (Action == 1) // Crouch
+ switch (Action)
{
+ case 1: // Crouch
m_Client->HandleEntityCrouch(PlayerID, true);
- }
- else if (Action == 2) // Uncrouch
- {
+ break;
+ case 2: // Unchrouch
m_Client->HandleEntityCrouch(PlayerID, false);
- }
- else if (Action == 3) // Leave Bed
- {
+ break;
+ case 3: // Leave Bed
m_Client->HandleEntityLeaveBed(PlayerID);
- }
- else if (Action == 4) // Start sprinting
- {
+ break;
+ case 4: // Start sprinting
m_Client->HandleEntitySprinting(PlayerID, true);
- }
- else if (Action == 5) // Stop sprinting
- {
+ break;
+ case 5: // Stop sprinting
m_Client->HandleEntitySprinting(PlayerID, false);
+ break;
}
}
--
cgit v1.2.3
From 27fa2b72ba629e8175d33dace463bd7b7035a6e0 Mon Sep 17 00:00:00 2001
From: Tycho
Date: Sat, 8 Mar 2014 11:05:37 -0800
Subject: Enabled self test of bytebuffer
---
src/ByteBuffer.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/ByteBuffer.cpp b/src/ByteBuffer.cpp
index bda1105f5..adb8e9294 100644
--- a/src/ByteBuffer.cpp
+++ b/src/ByteBuffer.cpp
@@ -44,7 +44,7 @@
-#if 0
+#ifdef SELF_TEST
/// Self-test of the VarInt-reading and writing code
class cByteBufferSelfTest
--
cgit v1.2.3
From a6ed75c1fbd7d3a38336e8649b59950837529b14 Mon Sep 17 00:00:00 2001
From: Tycho
Date: Sat, 8 Mar 2014 11:18:51 -0800
Subject: Added tons more asserts to bytebuffer
---
src/ByteBuffer.cpp | 24 +++++++++++++++++-------
1 file changed, 17 insertions(+), 7 deletions(-)
diff --git a/src/ByteBuffer.cpp b/src/ByteBuffer.cpp
index adb8e9294..67fe1012c 100644
--- a/src/ByteBuffer.cpp
+++ b/src/ByteBuffer.cpp
@@ -185,6 +185,7 @@ bool cByteBuffer::Write(const char * a_Bytes, size_t a_Count)
{
return false;
}
+ ASSERT(m_BufferSize >= m_WritePos);
size_t TillEnd = m_BufferSize - m_WritePos;
if (TillEnd <= a_Count)
{
@@ -223,9 +224,13 @@ size_t cByteBuffer::GetFreeSpace(void) const
if (m_WritePos >= m_DataStart)
{
// Wrap around the buffer end:
+ ASSERT(m_BufferSize >= m_WritePos);
+ ASSERT((m_BufferSize - m_WritePos + m_DataStart) >= 1);
return m_BufferSize - m_WritePos + m_DataStart - 1;
}
// Single free space partition:
+ ASSERT(m_BufferSize >= m_WritePos);
+ ASSERT(m_BufferSize - m_WritePos >= 1);
return m_DataStart - m_WritePos - 1;
}
@@ -238,6 +243,8 @@ size_t cByteBuffer::GetUsedSpace(void) const
{
CHECK_THREAD;
CheckValid();
+ ASSERT(m_BufferSize >= GetFreeSpace());
+ ASSERT((m_BufferSize - GetFreeSpace()) >= 1);
return m_BufferSize - GetFreeSpace() - 1;
}
@@ -253,9 +260,11 @@ size_t cByteBuffer::GetReadableSpace(void) const
if (m_ReadPos > m_WritePos)
{
// Wrap around the buffer end:
+ ASSERT(m_BufferSize >= m_ReadPos);
return m_BufferSize - m_ReadPos + m_WritePos;
}
// Single readable space partition:
+ ASSERT(m_WritePos >= m_ReadPos);
return m_WritePos - m_ReadPos ;
}
@@ -654,11 +663,10 @@ bool cByteBuffer::ReadBuf(void * a_Buffer, size_t a_Count)
{
CHECK_THREAD;
CheckValid();
- ASSERT(a_Count >= 0);
NEEDBYTES(a_Count);
char * Dst = (char *)a_Buffer; // So that we can do byte math
+ ASSERT(m_BufferSize >= m_ReadPos);
size_t BytesToEndOfBuffer = m_BufferSize - m_ReadPos;
- ASSERT(BytesToEndOfBuffer >= 0); // Sanity check
if (BytesToEndOfBuffer <= a_Count)
{
// Reading across the ringbuffer end, read the first part and adjust parameters:
@@ -688,9 +696,9 @@ bool cByteBuffer::WriteBuf(const void * a_Buffer, size_t a_Count)
{
CHECK_THREAD;
CheckValid();
- ASSERT(a_Count >= 0);
PUTBYTES(a_Count);
char * Src = (char *)a_Buffer; // So that we can do byte math
+ ASSERT(m_BufferSize >= m_ReadPos);
size_t BytesToEndOfBuffer = m_BufferSize - m_WritePos;
if (BytesToEndOfBuffer <= a_Count)
{
@@ -718,18 +726,18 @@ bool cByteBuffer::ReadString(AString & a_String, size_t a_Count)
{
CHECK_THREAD;
CheckValid();
- ASSERT(a_Count >= 0);
NEEDBYTES(a_Count);
a_String.clear();
a_String.reserve(a_Count);
+ ASSERT(m_BufferSize >= m_ReadPos);
size_t BytesToEndOfBuffer = m_BufferSize - m_ReadPos;
- ASSERT(BytesToEndOfBuffer >= 0); // Sanity check
if (BytesToEndOfBuffer <= a_Count)
{
// Reading across the ringbuffer end, read the first part and adjust parameters:
if (BytesToEndOfBuffer > 0)
{
a_String.assign(m_Buffer + m_ReadPos, BytesToEndOfBuffer);
+ ASSERT(a_Count >= BytesToEndOfBuffer);
a_Count -= BytesToEndOfBuffer;
}
m_ReadPos = 0;
@@ -771,7 +779,6 @@ bool cByteBuffer::SkipRead(size_t a_Count)
{
CHECK_THREAD;
CheckValid();
- ASSERT(a_Count >= 0);
if (!CanReadBytes(a_Count))
{
return false;
@@ -809,6 +816,7 @@ bool cByteBuffer::ReadToByteBuffer(cByteBuffer & a_Dst, size_t a_NumBytes)
size_t num = (a_NumBytes > sizeof(buf)) ? sizeof(buf) : a_NumBytes;
VERIFY(ReadBuf(buf, num));
VERIFY(a_Dst.Write(buf, num));
+ ASSERT(a_NumBytes >= num);
a_NumBytes -= num;
}
return true;
@@ -846,13 +854,15 @@ void cByteBuffer::ReadAgain(AString & a_Out)
// Used by ProtoProxy to repeat communication twice, once for parsing and the other time for the remote party
CHECK_THREAD;
CheckValid();
- int DataStart = m_DataStart;
+ size_t DataStart = m_DataStart;
if (m_ReadPos < m_DataStart)
{
// Across the ringbuffer end, read the first part and adjust next part's start:
+ ASSERT(m_BufferSize >= m_DataStart);
a_Out.append(m_Buffer + m_DataStart, m_BufferSize - m_DataStart);
DataStart = 0;
}
+ ASSERT(m_ReadPos >= DataStart);
a_Out.append(m_Buffer + DataStart, m_ReadPos - DataStart);
}
--
cgit v1.2.3
From 6b530bde75b33be5f88444cc583548a2e7292a97 Mon Sep 17 00:00:00 2001
From: Tycho
Date: Sat, 8 Mar 2014 11:53:37 -0800
Subject: Added static
---
src/ByteBuffer.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/ByteBuffer.cpp b/src/ByteBuffer.cpp
index 67fe1012c..a3b40e5ef 100644
--- a/src/ByteBuffer.cpp
+++ b/src/ByteBuffer.cpp
@@ -47,7 +47,7 @@
#ifdef SELF_TEST
/// Self-test of the VarInt-reading and writing code
-class cByteBufferSelfTest
+static class cByteBufferSelfTest
{
public:
cByteBufferSelfTest(void)
--
cgit v1.2.3
From 17f27d1750083dc0a3eb958d554184839d7f92f2 Mon Sep 17 00:00:00 2001
From: Mattes D
Date: Sat, 8 Mar 2014 21:14:59 +0100
Subject: Added switch case indent notice
---
CONTRIBUTING.md | 2 ++
1 file changed, 2 insertions(+)
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index a0a332f30..7ec7058ae 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -22,8 +22,10 @@ Code Stuff
- This helps prevent mistakes such as `if (a & 1 == 0)`
* White space is free, so use it freely
- "freely" as in "plentifully", not "arbitrarily"
+ * All `case` statements inside a `switch` need an extra indent.
* Each and every control statement deserves its braces. This helps maintainability later on when the file is edited, lines added or removed - the control logic doesn't break so easily.
- The only exception: a `switch` statement with all `case` statements being a single short statement is allowed to use the short brace-less form.
+ - These two rules really mean that indent is governed by braces
* Add an empty last line in all source files (GCC and GIT can complain otherwise)
* Use doxy-comments for functions in the header file, format as `/** Description */`
* Use spaces after the comment markers: `// Comment` instead of `//Comment`
--
cgit v1.2.3
From 8d2ebf8e19e1556d256f75678d2272bb6739030f Mon Sep 17 00:00:00 2001
From: Tiger Wang
Date: Thu, 6 Mar 2014 20:06:53 +0000
Subject: Slight plugin messaging changes
- Clients are not allowed to register duplicate channels
- Clients are not allowed to use channels that were not registered
---
src/ClientHandle.cpp | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index 870568cdf..c677862eb 100644
--- a/src/ClientHandle.cpp
+++ b/src/ClientHandle.cpp
@@ -555,12 +555,25 @@ void cClientHandle::HandlePluginMessage(const AString & a_Channel, const AString
}
else if (a_Channel == "REGISTER")
{
+ if (HasPluginChannel(a_Channel))
+ {
+ SendPluginMessage("UNREGISTER", a_Channel);
+ return; // Can't register again if already taken - kinda defeats the point of plugin messaging!
+ }
+
RegisterPluginChannels(BreakApartPluginChannels(a_Message));
}
else if (a_Channel == "UNREGISTER")
{
UnregisterPluginChannels(BreakApartPluginChannels(a_Message));
}
+ else if (!HasPluginChannel(a_Channel))
+ {
+ // Ignore if client sent something but didn't register the channel first
+ LOGD("Player %s sent a plugin message on channel \"%s\", but didn't REGISTER it first", GetUsername().c_str(), a_Channel.c_str());
+ SendPluginMessage("UNREGISTER", a_Channel);
+ return;
+ }
cPluginManager::Get()->CallHookPluginMessage(*this, a_Channel, a_Message);
}
--
cgit v1.2.3
From ff186f9735bd08727d6d010e6815c103b2e181e8 Mon Sep 17 00:00:00 2001
From: Tiger Wang
Date: Sun, 9 Mar 2014 01:23:55 +0000
Subject: TNT explodes when consumed by fire
Fixed FS#406
---
src/Simulator/FireSimulator.cpp | 25 +++++++++++++++++++------
1 file changed, 19 insertions(+), 6 deletions(-)
diff --git a/src/Simulator/FireSimulator.cpp b/src/Simulator/FireSimulator.cpp
index 4967c83f9..6079ea740 100644
--- a/src/Simulator/FireSimulator.cpp
+++ b/src/Simulator/FireSimulator.cpp
@@ -335,20 +335,33 @@ void cFireSimulator::RemoveFuelNeighbors(cChunk * a_Chunk, int a_RelX, int a_Rel
{
BLOCKTYPE BlockType;
NIBBLETYPE BlockMeta;
- if (!a_Chunk->UnboundedRelGetBlock(a_RelX + gNeighborCoords[i].x, a_RelY + gNeighborCoords[i].y, a_RelZ + gNeighborCoords[i].z, BlockType, BlockMeta))
+ int X = a_RelX + gNeighborCoords[i].x;
+ int Z = a_RelZ + gNeighborCoords[i].z;
+
+ cChunkPtr Neighbour = a_Chunk->GetRelNeighborChunkAdjustCoords(X, Z);
+ if (Neighbour == NULL)
{
- // Neighbor not accessible, ignore it
continue;
}
+ Neighbour->GetBlockTypeMeta(X, a_RelY + gCrossCoords[i].y, Z, BlockType, BlockMeta);
+
if (!IsFuel(BlockType))
{
continue;
}
+
+ if (BlockType == E_BLOCK_TNT)
+ {
+ int AbsX = X + Neighbour->GetPosX() * cChunkDef::Width;
+ int AbsZ = Z + Neighbour->GetPosZ() * cChunkDef::Width;
+
+ m_World.SpawnPrimedTNT(AbsX, a_RelY + gNeighborCoords[i].y, AbsZ, 0);
+ Neighbour->SetBlock(X, a_RelY + gNeighborCoords[i].y, Z, E_BLOCK_AIR, 0);
+ return;
+ }
+
bool ShouldReplaceFuel = (m_World.GetTickRandomNumber(MAX_CHANCE_REPLACE_FUEL) < m_ReplaceFuelChance);
- a_Chunk->UnboundedRelSetBlock(
- a_RelX + gNeighborCoords[i].x, a_RelY + gNeighborCoords[i].y, a_RelZ + gNeighborCoords[i].z,
- ShouldReplaceFuel ? E_BLOCK_FIRE : E_BLOCK_AIR, 0
- );
+ Neighbour->SetBlock(X, a_RelY + gNeighborCoords[i].y, Z, ShouldReplaceFuel ? E_BLOCK_FIRE : E_BLOCK_AIR, 0);
} // for i - Coords[]
}
--
cgit v1.2.3
From d872f2e41dfe141e1b04cdfb73c915b9bcdb55ea Mon Sep 17 00:00:00 2001
From: Tiger Wang
Date: Sun, 9 Mar 2014 01:49:32 +0000
Subject: Updated Core
---
MCServer/Plugins/Core | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/MCServer/Plugins/Core b/MCServer/Plugins/Core
index 3b416b07a..013a32a7f 160000
--- a/MCServer/Plugins/Core
+++ b/MCServer/Plugins/Core
@@ -1 +1 @@
-Subproject commit 3b416b07a339b3abcbc127070d56eea05b05373d
+Subproject commit 013a32a7fb3c8a6cfe0aef892d4c7394d4e1be59
--
cgit v1.2.3
From f74ee8fb51c015f678438cc1dccf23d1d3c2cf6a Mon Sep 17 00:00:00 2001
From: Jan-Fabian Humann
Date: Sun, 9 Mar 2014 10:55:06 +0100
Subject: Adjusted style of switch/case
---
src/Protocol/Protocol125.cpp | 20 +++++---------------
src/Protocol/Protocol16x.cpp | 20 +++++---------------
src/Protocol/Protocol17x.cpp | 20 +++++---------------
3 files changed, 15 insertions(+), 45 deletions(-)
diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp
index 169ab0c85..ca286bafb 100644
--- a/src/Protocol/Protocol125.cpp
+++ b/src/Protocol/Protocol125.cpp
@@ -1378,21 +1378,11 @@ int cProtocol125::ParseEntityAction(void)
switch (ActionID)
{
- case 1: // Crouch
- m_Client->HandleEntityCrouch(EntityID, true);
- break;
- case 2: // Uncrouch
- m_Client->HandleEntityCrouch(EntityID, false);
- break;
- case 3: // Leave Bed
- m_Client->HandleEntityLeaveBed(EntityID);
- break;
- case 4: // Start sprinting
- m_Client->HandleEntitySprinting(EntityID, true);
- break;
- case 5: // Stop sprinting
- m_Client->HandleEntitySprinting(EntityID, false);
- break;
+ case 1: m_Client->HandleEntityCrouch(EntityID, true); break; // Crouch
+ case 2: m_Client->HandleEntityCrouch(EntityID, false); break; // Uncrouch
+ case 3: m_Client->HandleEntityLeaveBed(EntityID); break; // Leave Bed
+ case 4: m_Client->HandleEntitySprinting(EntityID, true); break; // Start sprinting
+ case 5: m_Client->HandleEntitySprinting(EntityID, false); break; // Stop sprinting
}
return PARSE_OK;
diff --git a/src/Protocol/Protocol16x.cpp b/src/Protocol/Protocol16x.cpp
index 4b1b4f408..f6ec0a199 100644
--- a/src/Protocol/Protocol16x.cpp
+++ b/src/Protocol/Protocol16x.cpp
@@ -187,21 +187,11 @@ int cProtocol161::ParseEntityAction(void)
switch (ActionID)
{
- case 1: // Crouch
- m_Client->HandleEntityCrouch(EntityID, true);
- break;
- case 2: // Uncrouch
- m_Client->HandleEntityCrouch(EntityID, false);
- break;
- case 3: // Leave Bed
- m_Client->HandleEntityLeaveBed(EntityID);
- break;
- case 4: // Start sprinting
- m_Client->HandleEntitySprinting(EntityID, true);
- break;
- case 5: // Stop sprinting
- m_Client->HandleEntitySprinting(EntityID, false);
- break;
+ case 1: m_Client->HandleEntityCrouch(EntityID, true); break; // Crouch
+ case 2: m_Client->HandleEntityCrouch(EntityID, false); break; // Uncrouch
+ case 3: m_Client->HandleEntityLeaveBed(EntityID); break; // Leave Bed
+ case 4: m_Client->HandleEntitySprinting(EntityID, true); break; // Start sprinting
+ case 5: m_Client->HandleEntitySprinting(EntityID, false); break; // Stop sprinting
}
return PARSE_OK;
diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp
index b0ec72a7d..0bb9a1204 100644
--- a/src/Protocol/Protocol17x.cpp
+++ b/src/Protocol/Protocol17x.cpp
@@ -1735,21 +1735,11 @@ void cProtocol172::HandlePacketEntityAction(cByteBuffer & a_ByteBuffer)
switch (Action)
{
- case 1: // Crouch
- m_Client->HandleEntityCrouch(PlayerID, true);
- break;
- case 2: // Unchrouch
- m_Client->HandleEntityCrouch(PlayerID, false);
- break;
- case 3: // Leave Bed
- m_Client->HandleEntityLeaveBed(PlayerID);
- break;
- case 4: // Start sprinting
- m_Client->HandleEntitySprinting(PlayerID, true);
- break;
- case 5: // Stop sprinting
- m_Client->HandleEntitySprinting(PlayerID, false);
- break;
+ case 1: m_Client->HandleEntityCrouch(PlayerID, true); break; // Crouch
+ case 2: m_Client->HandleEntityCrouch(PlayerID, false); break; // Uncrouch
+ case 3: m_Client->HandleEntityLeaveBed(PlayerID); break; // Leave Bed
+ case 4: m_Client->HandleEntitySprinting(PlayerID, true); break; // Start sprinting
+ case 5: m_Client->HandleEntitySprinting(PlayerID, false); break; // Stop sprinting
}
}
--
cgit v1.2.3
From b4e3d0aa4e573200d1fffc3073e791c54d9eb20c Mon Sep 17 00:00:00 2001
From: Tycho
Date: Sun, 9 Mar 2014 04:37:36 -0700
Subject: Turned off Wunused-parameter
---
SetFlags.cmake | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/SetFlags.cmake b/SetFlags.cmake
index e6ba782fc..4e20c84ab 100644
--- a/SetFlags.cmake
+++ b/SetFlags.cmake
@@ -182,7 +182,7 @@ macro(set_exe_flags)
string(REPLACE "-w" "" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
string(REPLACE "-w" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
string(REPLACE "-w" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
- add_flags_cxx("-Wall -Wextra -Werror -Wno-error=unused-parameter -Wno-error=switch")
+ add_flags_cxx("-Wall -Wextra -Werror -Wno-unused-parameter -Wno-error=switch")
# we support non-IEEE 754 fpus so can make no guarentees about error
add_flags_cxx("-ffast-math")
--
cgit v1.2.3
From 14c2f620d181614cd87270f8811b162858b53a49 Mon Sep 17 00:00:00 2001
From: Tycho
Date: Sun, 9 Mar 2014 04:43:22 -0700
Subject: FIxed int in test
---
src/ByteBuffer.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/ByteBuffer.cpp b/src/ByteBuffer.cpp
index a3b40e5ef..96a135562 100644
--- a/src/ByteBuffer.cpp
+++ b/src/ByteBuffer.cpp
@@ -86,7 +86,7 @@ public:
cByteBuffer buf(3);
for (int i = 0; i < 1000; i++)
{
- int FreeSpace = buf.GetFreeSpace();
+ size_t FreeSpace = buf.GetFreeSpace();
assert(buf.GetReadableSpace() == 0);
assert(FreeSpace > 0);
assert(buf.Write("a", 1));
--
cgit v1.2.3
From 59d42ec5b2c666f1f50c9763dad13e97e2c6040f Mon Sep 17 00:00:00 2001
From: Tycho
Date: Sun, 9 Mar 2014 04:58:08 -0700
Subject: Enabled loads of clang warnings
---
SetFlags.cmake | 2 ++
1 file changed, 2 insertions(+)
diff --git a/SetFlags.cmake b/SetFlags.cmake
index 4e20c84ab..56d32b8fe 100644
--- a/SetFlags.cmake
+++ b/SetFlags.cmake
@@ -190,6 +190,8 @@ macro(set_exe_flags)
# clang does not provide the __extern_always_inline macro and a part of libm depends on this when using fast-math
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
add_flags_cxx("-D__extern_always_inline=inline")
+ add_flags_cxx("-Weverything -Wno-c++98-compat-pedantic -Wno-string-conversion")
+ add_flags_cxx("-Wno-extra-semi -Wno-error=switch-enum -Wno-documentation")
endif()
endif()
--
cgit v1.2.3
From 4cb0b82d1df560ad32c92eede91f466c75a87c87 Mon Sep 17 00:00:00 2001
From: Tycho
Date: Sun, 9 Mar 2014 05:05:37 -0700
Subject: Fixed some warnings
---
src/ChunkDef.h | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/src/ChunkDef.h b/src/ChunkDef.h
index 7be2fa2df..63431f211 100644
--- a/src/ChunkDef.h
+++ b/src/ChunkDef.h
@@ -65,8 +65,8 @@ public:
enum
{
// Chunk dimensions:
- Width = 16,
- Height = 256,
+ Width = 16U,
+ Height = 256U,
NumBlocks = Width * Height * Width,
/// If the data is collected into a single buffer, how large it needs to be:
@@ -132,7 +132,7 @@ public:
}
- inline static unsigned int MakeIndexNoCheck(int x, int y, int z)
+ inline static unsigned int MakeIndexNoCheck(unsigned int x, unsigned int y, unsigned int z)
{
#if AXIS_ORDER == AXIS_ORDER_XZY
// For some reason, NOT using the Horner schema is faster. Weird.
@@ -240,7 +240,7 @@ public:
{
if ((x < Width) && (x > -1) && (y < Height) && (y > -1) && (z < Width) && (z > -1))
{
- int Index = MakeIndexNoCheck(x, y, z);
+ unsigned int Index = MakeIndexNoCheck(x, y, z);
return (a_Buffer[Index / 2] >> ((Index & 1) * 4)) & 0x0f;
}
ASSERT(!"cChunkDef::GetNibble(): coords out of chunk range!");
@@ -256,7 +256,7 @@ public:
return;
}
a_Buffer[a_BlockIdx / 2] = (
- (a_Buffer[a_BlockIdx / 2] & (0xf0 >> ((a_BlockIdx & 1) * 4))) | // The untouched nibble
+ (a_Buffer[a_BlockIdx / 2] & (0xf0 >> (static_cast(a_BlockIdx & 1) * 4))) | // The untouched nibble
((a_Nibble & 0x0f) << ((a_BlockIdx & 1) * 4)) // The nibble being set
);
}
@@ -282,13 +282,13 @@ public:
}
- inline static char GetNibble(const NIBBLETYPE * a_Buffer, const Vector3i & a_BlockPos )
+ inline static NIBBLETYPE GetNibble(const NIBBLETYPE * a_Buffer, const Vector3i & a_BlockPos )
{
return GetNibble(a_Buffer, a_BlockPos.x, a_BlockPos.y, a_BlockPos.z );
}
- inline static void SetNibble(NIBBLETYPE * a_Buffer, const Vector3i & a_BlockPos, char a_Value )
+ inline static void SetNibble(NIBBLETYPE * a_Buffer, const Vector3i & a_BlockPos, NIBBLETYPE a_Value )
{
SetNibble( a_Buffer, a_BlockPos.x, a_BlockPos.y, a_BlockPos.z, a_Value );
}
@@ -306,6 +306,9 @@ The virtual methods are called in the same order as they're declared here.
class cChunkDataCallback abstract
{
public:
+
+ virtual ~cChunkDataCallback() {}
+
/** Called before any other callbacks to inform of the current coords
(only in processes where multiple chunks can be processed, such as cWorld::ForEachChunkInRect()).
If false is returned, the chunk is skipped.
--
cgit v1.2.3
From e2cbebe522c8d52dc68e513d7896c1f0d21d5b71 Mon Sep 17 00:00:00 2001
From: Tiger Wang
Date: Thu, 27 Feb 2014 23:33:46 +0000
Subject: Fix Linux compile
---
src/CraftingRecipes.cpp | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/CraftingRecipes.cpp b/src/CraftingRecipes.cpp
index 41de0da8c..5d9992fd3 100644
--- a/src/CraftingRecipes.cpp
+++ b/src/CraftingRecipes.cpp
@@ -806,6 +806,8 @@ cCraftingRecipes::cRecipe * cCraftingRecipes::MatchRecipe(const cItem * a_Crafti
}
case E_ITEM_DYE:
{
+ int GridID = (itr->x + a_OffsetX) + a_GridStride * (itr->y + a_OffsetY);
+
// Found a dye in ingredients...
for (cRecipeSlots::const_iterator itrnumerodos = Recipe->m_Ingredients.begin(); itrnumerodos != Recipe->m_Ingredients.end(); ++itrnumerodos)
{
@@ -821,7 +823,7 @@ cCraftingRecipes::cRecipe * cCraftingRecipes::MatchRecipe(const cItem * a_Crafti
// Yep, push back fade colour and exit the loop
// There is a potential for flexibility here - we can move the goto out of the loop, so we can add multiple dyes (∴ multiple fade colours)
// That will require lots of dye-adding to crafting.txt though - TODO, perchance?
- int GridID = (itrnumerotres->x + a_OffsetX) + a_GridStride * (itrnumerotres->y + a_OffsetY);
+ GridID = (itrnumerotres->x + a_OffsetX) + a_GridStride * (itrnumerotres->y + a_OffsetY);
Recipe->m_Result.m_FireworkItem.m_FadeColours.push_back(cFireworkItem::GetVanillaColourCodeFromDye(a_CraftingGrid[GridID].m_ItemDamage));
goto next;
}
@@ -830,7 +832,6 @@ cCraftingRecipes::cRecipe * cCraftingRecipes::MatchRecipe(const cItem * a_Crafti
}
// Just normal crafting of star, push back normal colours
- int GridID = (itr->x + a_OffsetX) + a_GridStride * (itr->y + a_OffsetY);
Recipe->m_Result.m_FireworkItem.m_Colours.push_back(cFireworkItem::GetVanillaColourCodeFromDye(a_CraftingGrid[GridID].m_ItemDamage));
next:
--
cgit v1.2.3
From c05a1db88d2a81b5aa93881c9791bcaadaad6304 Mon Sep 17 00:00:00 2001
From: Tiger Wang
Date: Sat, 1 Mar 2014 21:24:36 +0000
Subject: CheckBlockInteractionsRate() fixed & enabled
---
src/ClientHandle.cpp | 48 +++++++++++++++++++-----------------------------
src/ClientHandle.h | 4 +++-
src/Entities/Player.cpp | 25 -------------------------
src/Entities/Player.h | 11 +----------
4 files changed, 23 insertions(+), 65 deletions(-)
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index b08ceb5f6..ef33a313d 100644
--- a/src/ClientHandle.cpp
+++ b/src/ClientHandle.cpp
@@ -52,6 +52,9 @@
/** Maximum number of explosions to send this tick, server will start dropping if exceeded */
#define MAX_EXPLOSIONS_PER_TICK 20
+/** Maximum number of block change interactions a player can perform per tick - exceeding this causes a kick */
+#define MAX_BLOCK_CHANGE_INTERACTIONS 20
+
/** How many ticks before the socket is closed after the client is destroyed (#31) */
static const int TICKS_BEFORE_CLOSE = 20;
@@ -687,6 +690,14 @@ void cClientHandle::HandleLeftClick(int a_BlockX, int a_BlockY, int a_BlockZ, eB
a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_Status
);
+ m_NumBlockChangeInteractionsThisTick++;
+
+ if (!CheckBlockInteractionsRate())
+ {
+ Kick("Too many blocks were destroyed per unit time - hacked client?");
+ return;
+ }
+
cPluginManager * PlgMgr = cRoot::Get()->GetPluginManager();
if (PlgMgr->CallHookPlayerLeftClick(*m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_Status))
{
@@ -694,12 +705,6 @@ void cClientHandle::HandleLeftClick(int a_BlockX, int a_BlockY, int a_BlockZ, eB
m_Player->GetWorld()->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, m_Player);
return;
}
-
- if (!CheckBlockInteractionsRate())
- {
- // Too many interactions per second, simply ignore. Probably a hacked client, so don't even send bak the block
- return;
- }
switch (a_Status)
{
@@ -924,7 +929,7 @@ void cClientHandle::HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, e
if (PlgMgr->CallHookPlayerRightClick(*m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ))
{
// A plugin doesn't agree with the action, replace the block on the client and quit:
- if (a_BlockFace > -1)
+ if (a_BlockFace > BLOCK_FACE_NONE)
{
AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace);
m_Player->GetWorld()->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, m_Player);
@@ -934,7 +939,7 @@ void cClientHandle::HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, e
if (!CheckBlockInteractionsRate())
{
- LOGD("Too many block interactions, aborting placement");
+ Kick("Too many blocks were destroyed per unit time - hacked client?");
return;
}
@@ -1613,28 +1618,12 @@ bool cClientHandle::CheckBlockInteractionsRate(void)
{
ASSERT(m_Player != NULL);
ASSERT(m_Player->GetWorld() != NULL);
- /*
- // TODO: _X 2012_11_01: This needs a total re-thinking and rewriting
- int LastActionCnt = m_Player->GetLastBlockActionCnt();
- if ((m_Player->GetWorld()->GetTime() - m_Player->GetLastBlockActionTime()) < 0.1)
- {
- // Limit the number of block interactions per tick
- m_Player->SetLastBlockActionTime(); //Player tried to interact with a block. Reset last block interation time.
- m_Player->SetLastBlockActionCnt(LastActionCnt + 1);
- if (m_Player->GetLastBlockActionCnt() > MAXBLOCKCHANGEINTERACTIONS)
- {
- // Kick if more than MAXBLOCKCHANGEINTERACTIONS per tick
- LOGWARN("Player %s tried to interact with a block too quickly! (could indicate bot) Was Kicked.", m_Username.c_str());
- Kick("You're a baaaaaad boy!");
- return false;
- }
- }
- else
+
+ if (m_NumBlockChangeInteractionsThisTick > MAX_BLOCK_CHANGE_INTERACTIONS)
{
- m_Player->SetLastBlockActionCnt(0); // Reset count
- m_Player->SetLastBlockActionTime(); // Player tried to interact with a block. Reset last block interation time.
+ return false;
}
- */
+
return true;
}
@@ -1707,8 +1696,9 @@ void cClientHandle::Tick(float a_Dt)
}
}
- // Reset explosion counter:
+ // Reset explosion & block change counters:
m_NumExplosionsThisTick = 0;
+ m_NumBlockChangeInteractionsThisTick = 0;
}
diff --git a/src/ClientHandle.h b/src/ClientHandle.h
index 194533402..2382e81cf 100644
--- a/src/ClientHandle.h
+++ b/src/ClientHandle.h
@@ -46,7 +46,6 @@ class cClientHandle : // tolua_export
public cSocketThreads::cCallback
{ // tolua_export
public:
- static const int MAXBLOCKCHANGEINTERACTIONS = 20; // 5 didn't help, 10 still doesn't work in Creative, 20 seems to have done the trick
#if defined(ANDROID_NDK)
static const int DEFAULT_VIEW_DISTANCE = 4; // The default ViewDistance (used when no value is set in Settings.ini)
@@ -319,6 +318,9 @@ private:
/** Number of explosions sent this tick */
int m_NumExplosionsThisTick;
+
+ /** Number of place or break interactions this tick */
+ int m_NumBlockChangeInteractionsThisTick;
static int s_ClientCount;
int m_UniqueID;
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index f4039e548..2a62931ab 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -38,10 +38,7 @@ cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName)
, m_Inventory(*this)
, m_CurrentWindow(NULL)
, m_InventoryWindow(NULL)
- , m_TimeLastPickupCheck(0.f)
, m_Color('-')
- , m_LastBlockActionTime(0)
- , m_LastBlockActionCnt(0)
, m_GameMode(eGameMode_NotSet)
, m_IP("")
, m_ClientHandle(a_Client)
@@ -79,7 +76,6 @@ cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName)
m_LastPlayerListTime = t1.GetNowTime();
m_TimeLastTeleportPacket = 0;
- m_TimeLastPickupCheck = 0;
m_PlayerName = a_PlayerName;
m_bDirtyPosition = true; // So chunks are streamed to player at spawn
@@ -1055,27 +1051,6 @@ void cPlayer::CloseWindowIfID(char a_WindowID, bool a_CanRefuse)
-void cPlayer::SetLastBlockActionTime()
-{
- if (m_World != NULL)
- {
- m_LastBlockActionTime = m_World->GetWorldAge() / 20.0f;
- }
-}
-
-
-
-
-
-void cPlayer::SetLastBlockActionCnt( int a_LastBlockActionCnt )
-{
- m_LastBlockActionCnt = a_LastBlockActionCnt;
-}
-
-
-
-
-
void cPlayer::SetGameMode(eGameMode a_GameMode)
{
if ((a_GameMode < gmMin) || (a_GameMode >= gmMax))
diff --git a/src/Entities/Player.h b/src/Entities/Player.h
index a795bb9eb..f9404dfaf 100644
--- a/src/Entities/Player.h
+++ b/src/Entities/Player.h
@@ -50,7 +50,7 @@ public:
/// Returns the curently equipped weapon; empty item if none
virtual cItem GetEquippedWeapon(void) const override { return m_Inventory.GetEquippedItem(); }
- /// Returns the currently equipped helmet; empty item if nonte
+ /// Returns the currently equipped helmet; empty item if none
virtual cItem GetEquippedHelmet(void) const override { return m_Inventory.GetEquippedHelmet(); }
/// Returns the currently equipped chestplate; empty item if none
@@ -165,11 +165,6 @@ public:
// tolua_end
void SetIP(const AString & a_IP);
-
- float GetLastBlockActionTime() { return m_LastBlockActionTime; }
- int GetLastBlockActionCnt() { return m_LastBlockActionCnt; }
- void SetLastBlockActionCnt( int );
- void SetLastBlockActionTime();
// Sets the current gamemode, doesn't check validity, doesn't send update packets to client
void LoginSetGameMode(eGameMode a_GameMode);
@@ -416,12 +411,8 @@ protected:
cWindow * m_CurrentWindow;
cWindow * m_InventoryWindow;
- float m_TimeLastPickupCheck;
-
char m_Color;
- float m_LastBlockActionTime;
- int m_LastBlockActionCnt;
eGameMode m_GameMode;
AString m_IP;
--
cgit v1.2.3
From 217aaca699cf1fa85740da4d1f0b71d4b8d806d7 Mon Sep 17 00:00:00 2001
From: Tiger Wang
Date: Sat, 1 Mar 2014 21:25:01 +0000
Subject: Moved firework handler to separate function
* Also simplified and improved readability of code
---
src/CraftingRecipes.cpp | 93 ++++++++++++++++++++++++-------------------------
src/CraftingRecipes.h | 3 ++
2 files changed, 48 insertions(+), 48 deletions(-)
diff --git a/src/CraftingRecipes.cpp b/src/CraftingRecipes.cpp
index 5d9992fd3..868182394 100644
--- a/src/CraftingRecipes.cpp
+++ b/src/CraftingRecipes.cpp
@@ -763,13 +763,24 @@ cCraftingRecipes::cRecipe * cCraftingRecipes::MatchRecipe(const cItem * a_Crafti
}
Recipe->m_Ingredients.insert(Recipe->m_Ingredients.end(), MatchedSlots.begin(), MatchedSlots.end());
-
- // Henceforth is code to handle fireworks
// We use Recipe instead of a_Recipe because we want the wildcard ingredients' slot numbers as well, which was just added previously
+ HandleFireworks(a_CraftingGrid, Recipe.get(), a_GridStride, a_OffsetX, a_OffsetY);
+
+ return Recipe.release();
+}
+
+
+
+
+
+void cCraftingRecipes::HandleFireworks(const cItem * a_CraftingGrid, cCraftingRecipes::cRecipe * a_Recipe, int a_GridStride, int a_OffsetX, int a_OffsetY)
+{
+ // TODO: add support for more than one dye in the recipe
+ // A manual and temporary solution (listing everything) is in crafting.txt for fade colours, but a programmatic solutions needs to be done for everything else
- if (Recipe->m_Result.m_ItemType == E_ITEM_FIREWORK_ROCKET)
+ if (a_Recipe->m_Result.m_ItemType == E_ITEM_FIREWORK_ROCKET)
{
- for (cRecipeSlots::const_iterator itr = Recipe->m_Ingredients.begin(); itr != Recipe->m_Ingredients.end(); ++itr)
+ for (cRecipeSlots::const_iterator itr = a_Recipe->m_Ingredients.begin(); itr != a_Recipe->m_Ingredients.end(); ++itr)
{
switch (itr->m_Item.m_ItemType)
{
@@ -777,80 +788,66 @@ cCraftingRecipes::cRecipe * cCraftingRecipes::MatchRecipe(const cItem * a_Crafti
{
// Result was a rocket, found a star - copy star data to rocket data
int GridID = (itr->x + a_OffsetX) + a_GridStride * (itr->y + a_OffsetY);
- Recipe->m_Result.m_FireworkItem.CopyFrom(a_CraftingGrid[GridID].m_FireworkItem);
+ a_Recipe->m_Result.m_FireworkItem.CopyFrom(a_CraftingGrid[GridID].m_FireworkItem);
break;
}
case E_ITEM_GUNPOWDER:
{
// Gunpowder - increase flight time
- Recipe->m_Result.m_FireworkItem.m_FlightTimeInTicks += 20;
+ a_Recipe->m_Result.m_FireworkItem.m_FlightTimeInTicks += 20;
break;
}
case E_ITEM_PAPER: break;
- default: LOG("Unexpected item in firework rocket recipe, was the crafting file fireworks section changed?"); break;
+ default: LOG("Unexpected item in firework rocket a_Recipe, was the crafting file fireworks section changed?"); break;
}
}
}
- else if (Recipe->m_Result.m_ItemType == E_ITEM_FIREWORK_STAR)
+ else if (a_Recipe->m_Result.m_ItemType == E_ITEM_FIREWORK_STAR)
{
- for (cRecipeSlots::const_iterator itr = Recipe->m_Ingredients.begin(); itr != Recipe->m_Ingredients.end(); ++itr)
+ std::vector DyeColours;
+ bool FoundStar = false;
+
+ for (cRecipeSlots::const_iterator itr = a_Recipe->m_Ingredients.begin(); itr != a_Recipe->m_Ingredients.end(); ++itr)
{
switch (itr->m_Item.m_ItemType)
{
case E_ITEM_FIREWORK_STAR:
{
// Result was star, found another star - probably adding fade colours, but copy data over anyhow
+ FoundStar = true;
int GridID = (itr->x + a_OffsetX) + a_GridStride * (itr->y + a_OffsetY);
- Recipe->m_Result.m_FireworkItem.CopyFrom(a_CraftingGrid[GridID].m_FireworkItem);
+ a_Recipe->m_Result.m_FireworkItem.CopyFrom(a_CraftingGrid[GridID].m_FireworkItem);
break;
}
case E_ITEM_DYE:
{
int GridID = (itr->x + a_OffsetX) + a_GridStride * (itr->y + a_OffsetY);
-
- // Found a dye in ingredients...
- for (cRecipeSlots::const_iterator itrnumerodos = Recipe->m_Ingredients.begin(); itrnumerodos != Recipe->m_Ingredients.end(); ++itrnumerodos)
- {
- // Loop through ingredients. Can we find a star?
- if (itrnumerodos->m_Item.m_ItemType == E_ITEM_FIREWORK_STAR)
- {
- // Yes, this is definately adding fade colours, unless crafting.txt was changed :/
- for (cRecipeSlots::const_iterator itrnumerotres = Recipe->m_Ingredients.begin(); itrnumerotres != Recipe->m_Ingredients.end(); ++itrnumerotres)
- {
- // Loop again, can we find dye?
- if (itrnumerotres->m_Item.m_ItemType == E_ITEM_DYE)
- {
- // Yep, push back fade colour and exit the loop
- // There is a potential for flexibility here - we can move the goto out of the loop, so we can add multiple dyes (∴ multiple fade colours)
- // That will require lots of dye-adding to crafting.txt though - TODO, perchance?
- GridID = (itrnumerotres->x + a_OffsetX) + a_GridStride * (itrnumerotres->y + a_OffsetY);
- Recipe->m_Result.m_FireworkItem.m_FadeColours.push_back(cFireworkItem::GetVanillaColourCodeFromDye(a_CraftingGrid[GridID].m_ItemDamage));
- goto next;
- }
- }
- }
- }
-
- // Just normal crafting of star, push back normal colours
- Recipe->m_Result.m_FireworkItem.m_Colours.push_back(cFireworkItem::GetVanillaColourCodeFromDye(a_CraftingGrid[GridID].m_ItemDamage));
-
- next:
+ DyeColours.push_back(cFireworkItem::GetVanillaColourCodeFromDye(a_CraftingGrid[GridID].m_ItemDamage));
break;
}
case E_ITEM_GUNPOWDER: break;
- case E_ITEM_DIAMOND: Recipe->m_Result.m_FireworkItem.m_HasTrail = true; break;
- case E_ITEM_GLOWSTONE_DUST: Recipe->m_Result.m_FireworkItem.m_HasFlicker = true; break;
-
- case E_ITEM_FIRE_CHARGE: Recipe->m_Result.m_FireworkItem.m_Type = 1; break;
- case E_ITEM_GOLD_NUGGET: Recipe->m_Result.m_FireworkItem.m_Type = 2; break;
- case E_ITEM_FEATHER: Recipe->m_Result.m_FireworkItem.m_Type = 4; break;
- case E_ITEM_HEAD: Recipe->m_Result.m_FireworkItem.m_Type = 3; break;
- default: LOG("Unexpected item in firework star recipe, was the crafting file fireworks section changed?"); break; // ermahgerd BARD ardmins
+ case E_ITEM_DIAMOND: a_Recipe->m_Result.m_FireworkItem.m_HasTrail = true; break;
+ case E_ITEM_GLOWSTONE_DUST: a_Recipe->m_Result.m_FireworkItem.m_HasFlicker = true; break;
+
+ case E_ITEM_FIRE_CHARGE: a_Recipe->m_Result.m_FireworkItem.m_Type = 1; break;
+ case E_ITEM_GOLD_NUGGET: a_Recipe->m_Result.m_FireworkItem.m_Type = 2; break;
+ case E_ITEM_FEATHER: a_Recipe->m_Result.m_FireworkItem.m_Type = 4; break;
+ case E_ITEM_HEAD: a_Recipe->m_Result.m_FireworkItem.m_Type = 3; break;
+ default: LOG("Unexpected item in firework star a_Recipe, was the crafting file fireworks section changed?"); break; // ermahgerd BARD ardmins
}
}
- }
- return Recipe.release();
+ if (FoundStar && (!DyeColours.empty()))
+ {
+ // Found a star and a dye? Fade colours.
+ a_Recipe->m_Result.m_FireworkItem.m_FadeColours = DyeColours;
+ }
+ else if (!DyeColours.empty())
+ {
+ // Only dye? Normal colours.
+ a_Recipe->m_Result.m_FireworkItem.m_Colours = DyeColours;
+ }
+ }
}
diff --git a/src/CraftingRecipes.h b/src/CraftingRecipes.h
index 9d92cbfab..90e41eddc 100644
--- a/src/CraftingRecipes.h
+++ b/src/CraftingRecipes.h
@@ -165,6 +165,9 @@ protected:
/// Checks if the grid matches the specified recipe, offset by the specified offsets. Returns a matched cRecipe * if so, or NULL if not matching. Caller must delete the return value!
cRecipe * MatchRecipe(const cItem * a_CraftingGrid, int a_GridWidth, int a_GridHeight, int a_GridStride, const cRecipe * a_Recipe, int a_OffsetX, int a_OffsetY);
+
+ /** Searches for anything firework related, and does the data setting if appropriate */
+ void HandleFireworks(const cItem * a_CraftingGrid, cCraftingRecipes::cRecipe * a_Recipe, int a_GridStride, int a_OffsetX, int a_OffsetY);
} ;
--
cgit v1.2.3
From 8f134adb6dab3ad171f34a2e08a314e591380def Mon Sep 17 00:00:00 2001
From: Tiger Wang
Date: Sat, 1 Mar 2014 21:25:27 +0000
Subject: Improved formatting of username tabcomplete
---
src/World.cpp | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/src/World.cpp b/src/World.cpp
index ffb463169..8b791fa48 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -2929,18 +2929,18 @@ void cWorld::TabCompleteUserName(const AString & a_Text, AStringVector & a_Resul
cCSLock Lock(m_CSPlayers);
for (cPlayerList::iterator itr = m_Players.begin(), end = m_Players.end(); itr != end; ++itr)
{
- size_t LastSpace = a_Text.find_last_of(" "); //Find the position of the last space
+ size_t LastSpace = a_Text.find_last_of(" "); // Find the position of the last space
- std::string LastWord = a_Text.substr(LastSpace + 1, a_Text.length()); //Find the last word
- std::string PlayerName ((*itr)->GetName());
- std::size_t Found = PlayerName.find(LastWord); //Try to find last word in playername
+ AString LastWord = a_Text.substr(LastSpace + 1, a_Text.length()); // Find the last word
+ AString PlayerName ((*itr)->GetName());
+ size_t Found = PlayerName.find(LastWord); // Try to find last word in playername
- if (Found!=0)
+ if (Found == AString::npos)
{
- continue; //No match
+ continue; // No match
}
- a_Results.push_back((*itr)->GetName()); //Match!
+ a_Results.push_back(PlayerName); // Match!
}
}
--
cgit v1.2.3
From d5180ef2308f0de6c9a7a828e5914e8424b9b16f Mon Sep 17 00:00:00 2001
From: Tiger Wang
Date: Sat, 1 Mar 2014 21:25:46 +0000
Subject: Added extra dye rules to crafting.txt
---
MCServer/crafting.txt | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/MCServer/crafting.txt b/MCServer/crafting.txt
index bce0c5e9e..60cda0673 100644
--- a/MCServer/crafting.txt
+++ b/MCServer/crafting.txt
@@ -478,5 +478,12 @@ FireworkStar = Gunpowder, * | Dye ^-1, * | Goldnugget, * | Glowdust, * | Dia
FireworkStar = Gunpowder, * | Dye ^-1, * | Feather, * | Glowdust, * | Diamond, *
FireworkStar = Gunpowder, * | Dye ^-1, * | SkeletonHead ^-1, * | Glowdust, * | Diamond, *
-# Star colour-change
+# Star fade colour-change
FireworkStar = FireworkStar, * | Dye ^-1, *
+FireworkStar = FireworkStar, * | Dye ^-1, * | Dye ^-1, *
+FireworkStar = FireworkStar, * | Dye ^-1, * | Dye ^-1, * | Dye ^-1, *
+FireworkStar = FireworkStar, * | Dye ^-1, * | Dye ^-1, * | Dye ^-1, * | Dye ^-1, *
+FireworkStar = FireworkStar, * | Dye ^-1, * | Dye ^-1, * | Dye ^-1, * | Dye ^-1, * | Dye ^-1, *
+FireworkStar = FireworkStar, * | Dye ^-1, * | Dye ^-1, * | Dye ^-1, * | Dye ^-1, * | Dye ^-1, * | Dye ^-1, *
+FireworkStar = FireworkStar, * | Dye ^-1, * | Dye ^-1, * | Dye ^-1, * | Dye ^-1, * | Dye ^-1, * | Dye ^-1, * | Dye ^-1, *
+FireworkStar = FireworkStar, * | Dye ^-1, * | Dye ^-1, * | Dye ^-1, * | Dye ^-1, * | Dye ^-1, * | Dye ^-1, * | Dye ^-1, * | Dye ^-1, *
--
cgit v1.2.3
From 124fc8bc664f96158b4db28372da62896d1db211 Mon Sep 17 00:00:00 2001
From: Tiger Wang
Date: Sat, 1 Mar 2014 21:26:43 +0000
Subject: Demonstrated issues with GetDataLength()
---
src/WorldStorage/FireworksSerializer.cpp | 12 +++++++-----
src/WorldStorage/FireworksSerializer.h | 4 ++++
2 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/src/WorldStorage/FireworksSerializer.cpp b/src/WorldStorage/FireworksSerializer.cpp
index 7f5077912..34204ae8a 100644
--- a/src/WorldStorage/FireworksSerializer.cpp
+++ b/src/WorldStorage/FireworksSerializer.cpp
@@ -89,26 +89,28 @@ void cFireworkItem::ParseFromNBT(cFireworkItem & a_FireworkItem, const cParsedNB
if (ExplosionName == "Colors")
{
- if (a_NBT.GetDataLength(explosiontag) == 0)
+ int DataLength = a_NBT.GetDataLength(explosiontag);
+ if (DataLength == 0)
{
continue;
}
const int * ColourData = (const int *)(a_NBT.GetData(explosiontag));
- for (int i = 0; i < ARRAYCOUNT(ColourData); i++)
+ for (int i = 0; i < DataLength; i++)
{
a_FireworkItem.m_Colours.push_back(ntohl(ColourData[i]));
}
}
else if (ExplosionName == "FadeColors")
{
- if (a_NBT.GetDataLength(explosiontag) == 0)
+ int DataLength = a_NBT.GetDataLength(explosiontag);
+ if (DataLength == 0)
{
continue;
}
const int * FadeColourData = (const int *)(a_NBT.GetData(explosiontag));
- for (int i = 0; i < ARRAYCOUNT(FadeColourData); i++)
+ for (int i = 0; i < DataLength; i++)
{
a_FireworkItem.m_FadeColours.push_back(ntohl(FadeColourData[i]));
}
@@ -244,6 +246,6 @@ int cFireworkItem::GetVanillaColourCodeFromDye(short a_DyeMeta)
case E_META_DYE_MAGENTA: return 12801229;
case E_META_DYE_ORANGE: return 15435844;
case E_META_DYE_WHITE: return 15790320;
- default: ASSERT(!"Unhandled dye meta whilst trying to get colour code for fireworks!"); break;
+ default: ASSERT(!"Unhandled dye meta whilst trying to get colour code for fireworks!"); return 0;
}
}
diff --git a/src/WorldStorage/FireworksSerializer.h b/src/WorldStorage/FireworksSerializer.h
index 37fb6c883..5b87bafdb 100644
--- a/src/WorldStorage/FireworksSerializer.h
+++ b/src/WorldStorage/FireworksSerializer.h
@@ -64,15 +64,19 @@ 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);
+
/** 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);
/** Converts the firework's vector of colours into a string of values separated by a semicolon */
static AString ColoursToString(const cFireworkItem & a_FireworkItem);
+
/** Parses a string containing encoded firework colours and populates a FireworkItem with it */
static void ColoursFromString(const AString & a_String, cFireworkItem & a_FireworkItem);
+
/** Converts the firework's vector of fade colours into a string of values separated by a semicolon */
static AString FadeColoursToString(const cFireworkItem & a_FireworkItem);
+
/** Parses a string containing encoded firework fade colours and populates a FireworkItem with it */
static void FadeColoursFromString(const AString & a_String, cFireworkItem & a_FireworkItem);
--
cgit v1.2.3
From a2fb28dd082b85d714970f119a82cdba3583037a Mon Sep 17 00:00:00 2001
From: Tiger Wang
Date: Sun, 2 Mar 2014 16:28:51 +0000
Subject: Fixed data length issues
---
src/ClientHandle.cpp | 2 +-
src/WorldStorage/FireworksSerializer.cpp | 5 +++--
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index ef33a313d..9f08b43a5 100644
--- a/src/ClientHandle.cpp
+++ b/src/ClientHandle.cpp
@@ -939,7 +939,7 @@ void cClientHandle::HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, e
if (!CheckBlockInteractionsRate())
{
- Kick("Too many blocks were destroyed per unit time - hacked client?");
+ Kick("Too many blocks were placed/interacted with per unit time - hacked client?");
return;
}
diff --git a/src/WorldStorage/FireworksSerializer.cpp b/src/WorldStorage/FireworksSerializer.cpp
index 34204ae8a..464bf225d 100644
--- a/src/WorldStorage/FireworksSerializer.cpp
+++ b/src/WorldStorage/FireworksSerializer.cpp
@@ -89,7 +89,8 @@ void cFireworkItem::ParseFromNBT(cFireworkItem & a_FireworkItem, const cParsedNB
if (ExplosionName == "Colors")
{
- int DataLength = a_NBT.GetDataLength(explosiontag);
+ // Divide by four as data length returned in bytes
+ int DataLength = a_NBT.GetDataLength(explosiontag) / 4;
if (DataLength == 0)
{
continue;
@@ -103,7 +104,7 @@ void cFireworkItem::ParseFromNBT(cFireworkItem & a_FireworkItem, const cParsedNB
}
else if (ExplosionName == "FadeColors")
{
- int DataLength = a_NBT.GetDataLength(explosiontag);
+ int DataLength = a_NBT.GetDataLength(explosiontag) / 4;
if (DataLength == 0)
{
continue;
--
cgit v1.2.3
From 76bf7ad8132f2d36cf974d7a376ca7b911343eac Mon Sep 17 00:00:00 2001
From: Tiger Wang
Date: Sun, 2 Mar 2014 17:41:34 +0000
Subject: Hexified colours
---
src/WorldStorage/FireworksSerializer.cpp | 32 ++++++++++++++++----------------
1 file changed, 16 insertions(+), 16 deletions(-)
diff --git a/src/WorldStorage/FireworksSerializer.cpp b/src/WorldStorage/FireworksSerializer.cpp
index 464bf225d..0e0094e76 100644
--- a/src/WorldStorage/FireworksSerializer.cpp
+++ b/src/WorldStorage/FireworksSerializer.cpp
@@ -231,22 +231,22 @@ int cFireworkItem::GetVanillaColourCodeFromDye(short a_DyeMeta)
switch (a_DyeMeta)
{
- case E_META_DYE_BLACK: return 1973019;
- case E_META_DYE_RED: return 11743532;
- case E_META_DYE_GREEN: return 3887386;
- case E_META_DYE_BROWN: return 5320730;
- case E_META_DYE_BLUE: return 2437522;
- case E_META_DYE_PURPLE: return 8073150;
- case E_META_DYE_CYAN: return 2651799;
- case E_META_DYE_LIGHTGRAY: return 11250603;
- case E_META_DYE_GRAY: return 4408131;
- case E_META_DYE_PINK: return 14188952;
- case E_META_DYE_LIGHTGREEN: return 4312372;
- case E_META_DYE_YELLOW: return 14602026;
- case E_META_DYE_LIGHTBLUE: return 6719955;
- case E_META_DYE_MAGENTA: return 12801229;
- case E_META_DYE_ORANGE: return 15435844;
- case E_META_DYE_WHITE: return 15790320;
+ case E_META_DYE_BLACK: return 0x1E1B1B;
+ case E_META_DYE_RED: return 0xB3312C;
+ case E_META_DYE_GREEN: return 0x3B511A;
+ case E_META_DYE_BROWN: return 0x51301A;
+ case E_META_DYE_BLUE: return 0x253192;
+ case E_META_DYE_PURPLE: return 0x7B2FBE;
+ case E_META_DYE_CYAN: return 0x287697;
+ case E_META_DYE_LIGHTGRAY: return 0xABABAB;
+ case E_META_DYE_GRAY: return 0x434343;
+ case E_META_DYE_PINK: return 0xD88198;
+ case E_META_DYE_LIGHTGREEN: return 0x41CD34;
+ case E_META_DYE_YELLOW: return 0xDECF2A;
+ case E_META_DYE_LIGHTBLUE: return 0x6689D3;
+ case E_META_DYE_MAGENTA: return 0xC354CD;
+ case E_META_DYE_ORANGE: return 0xEB8844;
+ case E_META_DYE_WHITE: return 0xF0F0F0;
default: ASSERT(!"Unhandled dye meta whilst trying to get colour code for fireworks!"); return 0;
}
}
--
cgit v1.2.3
From e6305d29a53c9a0c5e607629d30fec70e01cccab Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Fri, 7 Mar 2014 18:37:18 +0100
Subject: Added the first skeleton code for PieceGenerator.
This is a WIP and won't work / isn't used at all.
---
src/Generating/PieceGenerator.cpp | 332 ++++++++++++++++++++++++++++++++++++++
src/Generating/PieceGenerator.h | 213 ++++++++++++++++++++++++
2 files changed, 545 insertions(+)
create mode 100644 src/Generating/PieceGenerator.cpp
create mode 100644 src/Generating/PieceGenerator.h
diff --git a/src/Generating/PieceGenerator.cpp b/src/Generating/PieceGenerator.cpp
new file mode 100644
index 000000000..04513666d
--- /dev/null
+++ b/src/Generating/PieceGenerator.cpp
@@ -0,0 +1,332 @@
+
+// PieceGenerator.cpp
+
+// Implements the cBFSPieceGenerator class and cDFSPieceGenerator class
+// representing base classes for generating structures composed of individual "pieces"
+
+#include "Globals.h"
+#include "PieceGenerator.h"
+
+
+
+
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// cPiece:
+
+cPiece::cConnector cPiece::RotateMoveConnector(const cConnector & a_Connector, int a_NumCCWRotations, int a_MoveX, int a_MoveY, int a_MoveZ) const
+{
+ cPiece::cConnector res(a_Connector);
+
+ // Rotate the res connector:
+ Vector3i Size = GetSize();
+ switch (a_NumCCWRotations)
+ {
+ case 0:
+ {
+ // No rotation needed
+ break;
+ }
+ case 1:
+ {
+ // 1 CCW rotation:
+ int NewX = Size.z - res.m_X;
+ int NewZ = res.m_Z;
+ res.m_X = NewX;
+ res.m_Z = NewZ;
+ res.m_Direction = RotateBlockFaceCCW(res.m_Direction);
+ break;
+ }
+ case 2:
+ {
+ // 2 rotations ( = axis flip):
+ res.m_X = Size.x - res.m_X;
+ res.m_Z = Size.z - res.m_Z;
+ res.m_Direction = MirrorBlockFaceY(res.m_Direction);
+ break;
+ }
+ case 3:
+ {
+ // 1 CW rotation:
+ int NewX = res.m_Z;
+ int NewZ = Size.x - res.m_X;
+ res.m_X = NewX;
+ res.m_Z = NewZ;
+ res.m_Direction = RotateBlockFaceCW(res.m_Direction);
+ break;
+ }
+ }
+
+ // Move the res connector:
+ res.m_X += a_MoveX;
+ res.m_Y += a_MoveY;
+ res.m_Z += a_MoveZ;
+
+ return res;
+}
+
+
+
+
+
+cCuboid cPiece::RotateHitBoxToConnector(
+ const cPiece::cConnector & a_MyConnector,
+ const cPiece::cConnector & a_ToConnector,
+ int a_NumCCWRotations
+) const
+{
+ cCuboid res = GetHitBox();
+ switch (a_NumCCWRotations)
+ {
+ case 0:
+ {
+ // No rotation, return the hitbox as-is
+ break;
+ }
+ case 1:
+ {
+ // 1 CCW rotation:
+ // TODO: res.p1.x =
+ break;
+ }
+ }
+ return res;
+}
+
+
+
+
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// cPlacedPiece:
+
+cPlacedPiece::cPlacedPiece(const cPlacedPiece * a_Parent, const cPiece & a_Piece, const Vector3i & a_Coords, int a_NumCCWRotations) :
+ m_Parent(a_Parent),
+ m_Piece(&a_Piece),
+ m_Coords(a_Coords),
+ m_NumCCWRotations(a_NumCCWRotations)
+{
+ m_Depth = (m_Parent == NULL) ? 0 : (m_Parent->GetDepth() + 1);
+}
+
+
+
+
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// cPieceGenerator:
+
+cPieceGenerator::cPieceGenerator(cPiecePool & a_PiecePool, int a_Seed) :
+ m_PiecePool(a_PiecePool),
+ m_Noise(a_Seed),
+ m_Seed(a_Seed)
+{
+}
+
+
+
+
+
+cPlacedPiece cPieceGenerator::PlaceStartingPiece(int a_BlockX, int a_BlockY, int a_BlockZ, cFreeConnectors & a_OutConnectors)
+{
+ m_PiecePool.Reset();
+ int rnd = m_Noise.IntNoise3DInt(a_BlockX, a_BlockY, a_BlockZ) / 7;
+
+ // Choose a random one of the starting pieces:
+ cPieces StartingPieces = m_PiecePool.GetStartingPieces();
+ cPiece * StartingPiece = StartingPieces[rnd % StartingPieces.size()];
+ rnd = rnd >> 16;
+
+ // Choose a random supported rotation:
+ int Rotations[4] = {0};
+ int NumRotations = 1;
+ for (int i = 1; i < ARRAYCOUNT(Rotations); i++)
+ {
+ if (StartingPiece->CanRotateCCW(i))
+ {
+ Rotations[NumRotations] = i;
+ NumRotations += 1;
+ }
+ }
+ int Rotation = Rotations[rnd % NumRotations];
+
+ cPlacedPiece res(NULL, *StartingPiece, Vector3i(a_BlockX, a_BlockY, a_BlockZ), Rotation);
+
+ // Place the piece's connectors into a_OutConnectors:
+ const cPiece::cConnectors & Conn = StartingPiece->GetConnectors();
+ for (cPiece::cConnectors::const_iterator itr = Conn.begin(), end = Conn.end(); itr != end; ++itr)
+ {
+ a_OutConnectors.push_back(
+ cFreeConnector(res, StartingPiece->RotateMoveConnector(*itr, Rotation, a_BlockX, a_BlockY, a_BlockZ))
+ );
+ }
+
+ return res;
+}
+
+
+
+
+
+bool cPieceGenerator::TryPlacePieceAtConnector(const cPlacedPiece & a_ParentPiece, const cPiece::cConnector & a_Connector, cPlacedPieces & a_OutPieces)
+{
+ // Translation of direction - direction -> number of CCW rotations needed:
+ // You need DirectionRotationTable[rot1][rot2] CCW turns to get from rot1 to rot2
+ static const int DirectionRotationTable[6][6] =
+ {
+ /* YM, YP, ZM, ZP, XM, XP
+ /* YM */ { 0, 0, 0, 0, 0, 0},
+ /* YP */ { 0, 0, 0, 0, 0, 0},
+ /* ZM */ { 0, 0, 0, 2, 1, 3},
+ /* ZP */ { 0, 0, 2, 0, 3, 1},
+ /* XM */ { 0, 0, 3, 1, 0, 2},
+ /* XP */ { 0, 0, 1, 3, 2, 0},
+ };
+
+ // Get a list of available connections:
+ const int * RotTable = DirectionRotationTable[a_Connector.m_Direction];
+ cConnections Connections;
+ cPieces AvailablePieces = m_PiecePool.GetPiecesWithConnector(a_Connector.m_Type);
+ Connections.reserve(AvailablePieces.size());
+ for (cPieces::iterator itrP = AvailablePieces.begin(), endP = AvailablePieces.end(); itrP != endP; ++itrP)
+ {
+ cPiece::cConnectors Connectors = (*itrP)->GetConnectors();
+ for (cPiece::cConnectors::iterator itrC = Connectors.begin(), endC = Connectors.end(); itrC != endC; ++itrC)
+ {
+ if (itrC->m_Type != a_Connector.m_Type)
+ {
+ continue;
+ }
+ // This is a same-type connector, find out how to rotate to it:
+ int NumCCWRotations = RotTable[itrC->m_Direction];
+ if (!(*itrP)->CanRotateCCW(NumCCWRotations))
+ {
+ // Doesn't support this rotation
+ continue;
+ }
+ if (!CheckConnection(a_Connector, **itrP, *itrC, NumCCWRotations, a_OutPieces))
+ {
+ // Doesn't fit in this rotation
+ continue;
+ }
+ Connections.push_back(cConnection(**itrP, *itrC, NumCCWRotations));
+ } // for itrC - Connectors[]
+ } // for itrP - AvailablePieces[]
+ if (Connections.empty())
+ {
+ // No available connections, bail out
+ return false;
+ }
+
+ // Choose a random connection from the list:
+ int rnd = m_Noise.IntNoise3DInt(a_Connector.m_X, a_Connector.m_Y, a_Connector.m_Z) / 7;
+ cConnection & Conn = Connections[rnd % Connections.size()];
+
+ // Place the piece:
+ cPiece::cConnector NewConnector = Conn.m_Piece->RotateMoveConnector(*(Conn.m_Connector), Conn.m_NumCCWRotations, 0, 0, 0);
+ Vector3i Coords = a_ParentPiece.GetCoords();
+ Coords.x -= NewConnector.m_X;
+ Coords.y -= NewConnector.m_Y;
+ Coords.z -= NewConnector.m_Z;
+ a_OutPieces.push_back(cPlacedPiece(&a_ParentPiece, *(Conn.m_Piece), Coords, Conn.m_NumCCWRotations));
+ return false;
+}
+
+
+
+
+
+bool cPieceGenerator::CheckConnection(
+ const cPiece::cConnector & a_ExistingConnector,
+ const cPiece & a_Piece,
+ const cPiece::cConnector & a_NewConnector,
+ int a_NumCCWRotations,
+ const cPlacedPieces & a_OutPieces
+)
+{
+ // For each placed piece, test the hitbox against the new piece:
+ cCuboid RotatedHitBox = a_Piece.RotateHitBoxToConnector(a_NewConnector, a_ExistingConnector, a_NumCCWRotations);
+ for (cPlacedPieces::const_iterator itr = a_OutPieces.begin(), end = a_OutPieces.end(); itr != end; ++itr)
+ {
+ if (itr->GetHitBox().DoesIntersect(RotatedHitBox))
+ {
+ return false;
+ }
+ }
+ return true;
+}
+
+
+
+
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// cPieceGenerator::cConnection:
+
+cPieceGenerator::cConnection::cConnection(cPiece & a_Piece, cPiece::cConnector & a_Connector, int a_NumCCWRotations) :
+ m_Piece(&a_Piece),
+ m_Connector(&a_Connector),
+ m_NumCCWRotations(a_NumCCWRotations)
+{
+}
+
+
+
+
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// cPieceGenerator::cFreeConnector:
+
+cPieceGenerator::cFreeConnector::cFreeConnector(cPlacedPiece & a_Piece, const cPiece::cConnector & a_Connector) :
+ m_Piece(&a_Piece),
+ m_Connector(a_Connector)
+{
+}
+
+
+
+
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// cBFSPieceGenerator:
+
+cBFSPieceGenerator::cBFSPieceGenerator(cPiecePool & a_PiecePool, int a_Seed) :
+ super(a_PiecePool, a_Seed)
+{
+}
+
+
+
+
+
+void cBFSPieceGenerator::PlacePieces(int a_BlockX, int a_BlockY, int a_BlockZ, cPlacedPieces & a_OutPieces)
+{
+ a_OutPieces.clear();
+ cFreeConnectors ConnectorPool;
+
+ // Place the starting piece:
+ a_OutPieces.push_back(PlaceStartingPiece(a_BlockX, a_BlockY, a_BlockZ, ConnectorPool));
+
+ // Place pieces at the available connectors:
+ /*
+ Instead of removing them one by one from the pool, we process them sequentially and take note of the last
+ processed one. To save on memory, once the number of processed connectors reaches a big number, a chunk
+ of the connectors is removed.
+ */
+ size_t NumProcessed = 0;
+ while (ConnectorPool.size() > NumProcessed)
+ {
+ cFreeConnector & Conn = ConnectorPool[NumProcessed];
+ TryPlacePieceAtConnector(*Conn.m_Piece, Conn.m_Connector, a_OutPieces);
+ NumProcessed++;
+ if (NumProcessed > 1000)
+ {
+ ConnectorPool.erase(ConnectorPool.begin(), ConnectorPool.begin() + NumProcessed);
+ NumProcessed = 0;
+ }
+ }
+}
+
+
+
+
diff --git a/src/Generating/PieceGenerator.h b/src/Generating/PieceGenerator.h
new file mode 100644
index 000000000..3bc71a0ab
--- /dev/null
+++ b/src/Generating/PieceGenerator.h
@@ -0,0 +1,213 @@
+
+// PieceGenerator.h
+
+// Declares the cBFSPieceGenerator class and cDFSPieceGenerator class
+// representing base classes for generating structures composed of individual "pieces"
+
+/*
+Each uses a slightly different approach to generating:
+ - DFS extends pieces one by one until it hits the configured depth (or can't connect another piece anymore),
+ then starts looking at adjacent connectors (like depth-first search).
+ - BFS keeps a pool of currently-open connectors, chooses one at random and tries to place a piece on it,
+ thus possibly extending the pool of open connectors (like breadth-first search).
+*/
+
+
+
+
+
+#pragma once
+
+#include "../Defines.h"
+#include "../Cuboid.h"
+#include "../Noise.h"
+
+
+
+
+
+/** Represents a single piece. Can have multiple connectors of different types where other pieces can connect. */
+class cPiece
+{
+public:
+ struct cConnector
+ {
+ int m_X;
+ int m_Y;
+ int m_Z;
+ int m_Type;
+ eBlockFace m_Direction;
+
+ cConnector(int a_X, int a_Y, int a_Z, int a_Type, eBlockFace m_Direction);
+ };
+
+ typedef std::vector cConnectors;
+
+ /** Returns all of the available connectors that the piece has.
+ Each connector has a (relative) position in the piece, and a type associated with it. */
+ virtual cConnectors GetConnectors(void) const = 0;
+
+ /** Returns the dimensions of this piece.
+ The dimensions cover the entire piece, there is no block that the piece generates outside of this size. */
+ virtual Vector3i GetSize(void) const = 0;
+
+ /** Returns the "hitbox" of this piece.
+ A hitbox is what is compared and must not intersect other pieces' hitboxes when generating. */
+ virtual cCuboid GetHitBox(void) const = 0;
+
+ /** Returns true if the piece can be rotated CCW the specific number of 90-degree turns. */
+ virtual bool CanRotateCCW(int a_NumRotations) const = 0;
+
+ /** Returns a copy of the connector that is rotated and then moved by the specified amounts. */
+ cConnector RotateMoveConnector(const cConnector & a_Connector, int a_NumCCWRotations, int a_MoveX, int a_MoveY, int a_MoveZ) const;
+
+ /** Returns the hitbox after the specified number of rotations and moved so that a_MyConnector is placed at a_ToConnector*/
+ cCuboid RotateHitBoxToConnector(const cConnector & a_MyConnector, const cConnector & a_ToConnector, int a_NumCCWRotations) const;
+};
+
+typedef std::vector cPieces;
+
+
+
+
+
+class cPiecePool
+{
+public:
+ /** Returns a list of pieces that contain the specified connector type.
+ The cPiece pointers returned are managed by the pool and the caller doesn't free them. */
+ virtual cPieces GetPiecesWithConnector(int a_ConnectorType) = 0;
+
+ /** Returns the pieces that should be used as the starting point.
+ Multiple starting points are supported, one of the returned piece will be chosen. */
+ virtual cPieces GetStartingPieces(void) = 0;
+
+ /** Called after a piece is placed, to notify the pool that it has been used.
+ The pool may adjust the pieces it will return the next time. */
+ virtual void PiecePlaced(const cPiece & a_Piece) = 0;
+
+ /** Called when the pool has finished the current structure and should reset any piece-counters it has
+ for a new structure. */
+ virtual void Reset(void) = 0;
+};
+
+
+
+
+
+/** Represents a single piece that has been placed to specific coords in the world. */
+class cPlacedPiece
+{
+public:
+ cPlacedPiece(const cPlacedPiece * a_Parent, const cPiece & a_Piece, const Vector3i & a_Coords, int a_NumCCWRotations);
+
+ const cPiece & GetPiece (void) const { return *m_Piece; }
+ const Vector3i & GetCoords (void) const { return m_Coords; }
+ const int GetNumCCWRotations(void) const { return m_NumCCWRotations; }
+ const cCuboid & GetHitBox (void) const { return m_HitBox; }
+ const int GetDepth (void) const { return m_Depth; }
+
+protected:
+ const cPlacedPiece * m_Parent;
+ const cPiece * m_Piece;
+ Vector3i m_Coords;
+ int m_NumCCWRotations;
+ cCuboid m_HitBox;
+ int m_Depth;
+};
+
+typedef std::vector cPlacedPieces;
+
+
+
+
+
+class cPieceGenerator
+{
+public:
+ cPieceGenerator(cPiecePool & a_PiecePool, int a_Seed);
+
+protected:
+ /** The type used for storing a connection from one piece to another, while building the piece tree. */
+ struct cConnection
+ {
+ cPiece * m_Piece; // The piece being connected
+ cPiece::cConnector * m_Connector; // The piece's connector being used
+ int m_NumCCWRotations; // Number of rotations necessary to match the two connectors
+
+ cConnection(cPiece & a_Piece, cPiece::cConnector & a_Connector, int a_NumCCWRotations);
+ };
+ typedef std::vector cConnections;
+
+ /** The type used for storing a pool of connectors that will be attempted to expand by another piece. */
+ struct cFreeConnector
+ {
+ cPlacedPiece * m_Piece;
+ cPiece::cConnector m_Connector;
+
+ cFreeConnector(cPlacedPiece & a_Piece, const cPiece::cConnector & a_Connector);
+ };
+ typedef std::vector cFreeConnectors;
+
+
+ cPiecePool & m_PiecePool;
+ cNoise m_Noise;
+ int m_Seed;
+
+
+ /** Selects a starting piece and places it, including the rotations.
+ Also puts the piece's connectors in a_OutConnectors. */
+ cPlacedPiece PlaceStartingPiece(int a_BlockX, int a_BlockY, int a_BlockZ, cFreeConnectors & a_OutConnectors);
+
+ /** Tries to place a new piece at the specified (placed) connector. Returns true if successful. */
+ bool TryPlacePieceAtConnector(
+ const cPlacedPiece & a_ParentPiece,
+ const cPiece::cConnector & a_Connector,
+ cPlacedPieces & a_OutPieces
+ );
+
+ /** Checks if the specified piece would fit with the already-placed pieces, using the specified connector
+ and number of CCW rotations.
+ Returns true if the piece fits, false if not. */
+ bool CheckConnection(
+ const cPiece::cConnector & a_ExistingConnector, // The existing connector
+ const cPiece & a_Piece, // The new piece
+ const cPiece::cConnector & a_NewConnector, // The connector of the new piece
+ int a_NumCCWRotations, // Number of rotations for the new piece to align the connector
+ const cPlacedPieces & a_OutPieces // All the already-placed pieces to check
+ );
+} ;
+
+
+
+
+
+class cBFSPieceGenerator :
+ public cPieceGenerator
+{
+ typedef cPieceGenerator super;
+
+public:
+ cBFSPieceGenerator(cPiecePool & a_PiecePool, int a_Seed);
+
+ /** Generates a placement for pieces at the specified coords. */
+ void PlacePieces(int a_BlockX, int a_BlockY, int a_BlockZ, cPlacedPieces & a_OutPieces);
+};
+
+
+
+
+
+class cDFSPieceGenerator :
+ public cPieceGenerator
+{
+public:
+ cDFSPieceGenerator(cPiecePool & a_PiecePool, int a_Seed);
+
+ /** Generates a placement for pieces at the specified coords. */
+ void PlacePieces(int a_BlockX, int a_BlockY, int a_BlockZ, cPlacedPieces & a_OutPieces);
+};
+
+
+
+
--
cgit v1.2.3
From 93f0de521a0e2abb9c35dfb06bd3d306c548bf1b Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Fri, 7 Mar 2014 21:43:15 +0100
Subject: Added Vector3i::Move().
---
src/Vector3i.cpp | 52 +++++++++++++++++++++++++++++++++++++++++++++++-----
src/Vector3i.h | 47 +++++++++++++++++++++++++++++++++++------------
2 files changed, 82 insertions(+), 17 deletions(-)
diff --git a/src/Vector3i.cpp b/src/Vector3i.cpp
index 4ce1e2cf3..2106aea6d 100644
--- a/src/Vector3i.cpp
+++ b/src/Vector3i.cpp
@@ -1,6 +1,11 @@
+// Vector3i.cpp
+
+// Implements the Vector3i class representing an int-based 3D vector
+
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
+#include "math.h"
#include "Vector3i.h"
#include "Vector3d.h"
@@ -8,9 +13,46 @@
-Vector3i::Vector3i( const Vector3d & v )
- : x( (int)v.x )
- , y( (int)v.y )
- , z( (int)v.z )
+Vector3i::Vector3i(const Vector3d & v) :
+ x((int)v.x),
+ y((int)v.y),
+ z((int)v.z)
+{
+}
+
+
+
+
+
+Vector3i::Vector3i(void) :
+ x(0),
+ y(0),
+ z(0)
+{
+}
+
+
+
+
+
+Vector3i::Vector3i(int a_x, int a_y, int a_z) :
+ x(a_x),
+ y(a_y),
+ z(a_z)
+{
+}
+
+
+
+
+
+void Vector3i::Move(int a_MoveX, int a_MoveY, int a_MoveZ)
{
-}
\ No newline at end of file
+ x += a_MoveX;
+ y += a_MoveY;
+ z += a_MoveZ;
+}
+
+
+
+
diff --git a/src/Vector3i.h b/src/Vector3i.h
index 7d726a7b3..39e138683 100644
--- a/src/Vector3i.h
+++ b/src/Vector3i.h
@@ -1,22 +1,45 @@
+
+// Vector3i.h
+
+// Declares the Vector3i class representing an int-based 3D vector
+
+
+
+
+
#pragma once
-#include
+
+
+
+// fwd:
class Vector3d;
-class Vector3i // tolua_export
-{ // tolua_export
-public: // tolua_export
- Vector3i( const Vector3d & v ); // tolua_export
- Vector3i() : x(0), y(0), z(0) {} // tolua_export
- Vector3i(int a_x, int a_y, int a_z) : x(a_x), y(a_y), z(a_z) {} // tolua_export
- inline void Set(int a_x, int a_y, int a_z) { x = a_x, y = a_y, z = a_z; } // tolua_export
- inline float Length() const { return sqrtf( (float)( x * x + y * y + z * z) ); } // tolua_export
- inline int SqrLength() const { return x * x + y * y + z * z; } // tolua_export
- inline bool Equals( const Vector3i & v ) const { return (x == v.x && y == v.y && z == v.z ); } // tolua_export
- inline bool Equals( const Vector3i * v ) const { return (x == v->x && y == v->y && z == v->z ); } // tolua_export
+
+
+// tolua_begin
+class Vector3i
+{
+public:
+ /** Creates an int vector based on the floor()-ed coords of a double vector. */
+ Vector3i(const Vector3d & v);
+
+ Vector3i(void);
+ Vector3i(int a_x, int a_y, int a_z);
+
+ inline void Set(int a_x, int a_y, int a_z) { x = a_x, y = a_y, z = a_z; }
+ inline float Length() const { return sqrtf( (float)( x * x + y * y + z * z) ); }
+ inline int SqrLength() const { return x * x + y * y + z * z; }
+
+ inline bool Equals( const Vector3i & v ) const { return (x == v.x && y == v.y && z == v.z ); }
+ inline bool Equals( const Vector3i * v ) const { return (x == v->x && y == v->y && z == v->z ); }
+
+ void Move(int a_MoveX, int a_MoveY, int a_MoveZ);
+
+ // tolua_end
void operator += ( const Vector3i& a_V ) { x += a_V.x; y += a_V.y; z += a_V.z; }
void operator += ( Vector3i* a_V ) { x += a_V->x; y += a_V->y; z += a_V->z; }
--
cgit v1.2.3
From 5be983e7752091adbf7262f3074b3062ea44ae73 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Sun, 9 Mar 2014 10:05:30 +0100
Subject: Added BlockFaceToString() translation function.
---
src/Defines.h | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/src/Defines.h b/src/Defines.h
index 6ab2274a4..d2fcce576 100644
--- a/src/Defines.h
+++ b/src/Defines.h
@@ -276,6 +276,26 @@ inline eBlockFace RotateBlockFaceCW(eBlockFace a_BlockFace)
+/** Returns the textual representation of the BlockFace constant. */
+inline AString BlockFaceToString(eBlockFace a_BlockFace)
+{
+ switch (a_BlockFace)
+ {
+ case BLOCK_FACE_XM: return "BLOCK_FACE_XM";
+ case BLOCK_FACE_XP: return "BLOCK_FACE_XP";
+ case BLOCK_FACE_YM: return "BLOCK_FACE_YM";
+ case BLOCK_FACE_YP: return "BLOCK_FACE_YP";
+ case BLOCK_FACE_ZM: return "BLOCK_FACE_ZM";
+ case BLOCK_FACE_ZP: return "BLOCK_FACE_ZP";
+ case BLOCK_FACE_NONE: return "BLOCK_FACE_NONE";
+ }
+ return Printf("Unknown BLOCK_FACE: %d", a_BlockFace);
+}
+
+
+
+
+
inline bool IsValidBlock(int a_BlockType)
{
if (
--
cgit v1.2.3
From b9190fc04e1463371cec773d069315a6743a56d5 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Sun, 9 Mar 2014 10:11:33 +0100
Subject: PieceGenerator can connect two connectors of the same type.
Also added extensive debugging output and a test.
---
src/Generating/PieceGenerator.cpp | 347 ++++++++++++++++++++++++++++++++------
src/Generating/PieceGenerator.h | 51 ++++--
2 files changed, 338 insertions(+), 60 deletions(-)
diff --git a/src/Generating/PieceGenerator.cpp b/src/Generating/PieceGenerator.cpp
index 04513666d..58ccaf2c2 100644
--- a/src/Generating/PieceGenerator.cpp
+++ b/src/Generating/PieceGenerator.cpp
@@ -11,9 +11,169 @@
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// Self-test:
+
+static class cPieceGeneratorSelfTest :
+ public cPiecePool
+{
+public:
+ cPieceGeneratorSelfTest(void)
+ {
+ // Prepare the internal state:
+ InitializePieces();
+
+ // Generate:
+ cBFSPieceGenerator Gen(*this, 0);
+ cPlacedPieces OutPieces;
+ Gen.PlacePieces(500, 50, 500, 3, OutPieces);
+
+ // Print out the pieces:
+ printf("OutPieces.size() = %u\n", OutPieces.size());
+ size_t idx = 0;
+ for (cPlacedPieces::const_iterator itr = OutPieces.begin(), end = OutPieces.end(); itr != end; ++itr, ++idx)
+ {
+ const Vector3i & Coords = (*itr)->GetCoords();
+ cCuboid Hitbox = (*itr)->GetHitBox();
+ Hitbox.Sort();
+ printf("%u: {%d, %d, %d}, rot %d, hitbox {%d, %d, %d} - {%d, %d, %d} (%d * %d * %d)\n", idx,
+ Coords.x, Coords.y, Coords.z,
+ (*itr)->GetNumCCWRotations(),
+ Hitbox.p1.x, Hitbox.p1.y, Hitbox.p1.z,
+ Hitbox.p2.x, Hitbox.p2.y, Hitbox.p2.z,
+ Hitbox.DifX() + 1, Hitbox.DifY() + 1, Hitbox.DifZ() + 1
+ );
+ } // itr - OutPieces[]
+ printf("Done.\n");
+
+ // Free the placed pieces properly:
+ Gen.FreePieces(OutPieces);
+ }
+
+ ~cPieceGeneratorSelfTest()
+ {
+ // Dealloc all the pieces:
+ for (cPieces::iterator itr = m_Pieces.begin(), end = m_Pieces.end(); itr != end; ++itr)
+ {
+ delete *itr;
+ }
+ m_Pieces.clear();
+ }
+
+protected:
+ class cTestPiece :
+ public cPiece
+ {
+ int m_Size;
+ public:
+ cTestPiece(int a_Size) :
+ m_Size(a_Size)
+ {
+ }
+
+ virtual cConnectors GetConnectors(void) const override
+ {
+ // Each piece has 4 connectors, one of each type, plus one extra, at the center of its walls:
+ cConnectors res;
+ res.push_back(cConnector(m_Size / 2, 1, 0, 0, BLOCK_FACE_ZM));
+ res.push_back(cConnector(m_Size / 2, 1, m_Size - 1, 1, BLOCK_FACE_ZP));
+ res.push_back(cConnector(0, 1, m_Size / 2, 2, BLOCK_FACE_XM));
+ res.push_back(cConnector(m_Size - 1, 1, m_Size / 2, m_Size % 3, BLOCK_FACE_XP));
+ return res;
+ }
+
+ virtual Vector3i GetSize(void) const override
+ {
+ return Vector3i(m_Size, 5, m_Size);
+ }
+
+ virtual cCuboid GetHitBox(void) const override
+ {
+ return cCuboid(0, 0, 0, m_Size - 1, 4, m_Size - 1);
+ }
+
+ virtual bool CanRotateCCW(int a_NumCCWRotations) const override
+ {
+ return true;
+ }
+ };
+
+ cPieces m_Pieces;
+
+ virtual cPieces GetPiecesWithConnector(int a_ConnectorType) override
+ {
+ // Each piece contains each connector
+ return m_Pieces;
+ }
+
+
+ virtual cPieces GetStartingPieces(void) override
+ {
+ return m_Pieces;
+ }
+
+
+ virtual void PiecePlaced(const cPiece & a_Piece) override
+ {
+ UNUSED(a_Piece);
+ }
+
+
+ virtual void Reset(void) override
+ {
+ }
+
+
+ void InitializePieces(void)
+ {
+ m_Pieces.push_back(new cTestPiece(5));
+ m_Pieces.push_back(new cTestPiece(7));
+ m_Pieces.push_back(new cTestPiece(9));
+ }
+} g_Test;
+
+
+
+
+
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cPiece:
+
+Vector3i cPiece::RotatePos(const Vector3i & a_Pos, int a_NumCCWRotations) const
+{
+ Vector3i Size = GetSize();
+ switch (a_NumCCWRotations)
+ {
+ case 0:
+ {
+ // No rotation needed
+ return a_Pos;
+ }
+ case 1:
+ {
+ // 1 CCW rotation:
+ return Vector3i(a_Pos.z, a_Pos.y, Size.x - a_Pos.x - 1);
+ }
+ case 2:
+ {
+ // 2 rotations ( = axis flip):
+ return Vector3i(Size.x - a_Pos.x - 1, a_Pos.y, Size.z - a_Pos.z - 1);
+ }
+ case 3:
+ {
+ // 1 CW rotation:
+ return Vector3i(Size.z - a_Pos.z - 1, a_Pos.y, a_Pos.x);
+ }
+ }
+ ASSERT(!"Unhandled rotation");
+ return a_Pos;
+}
+
+
+
+
+
cPiece::cConnector cPiece::RotateMoveConnector(const cConnector & a_Connector, int a_NumCCWRotations, int a_MoveX, int a_MoveY, int a_MoveZ) const
{
cPiece::cConnector res(a_Connector);
@@ -30,37 +190,28 @@ cPiece::cConnector cPiece::RotateMoveConnector(const cConnector & a_Connector, i
case 1:
{
// 1 CCW rotation:
- int NewX = Size.z - res.m_X;
- int NewZ = res.m_Z;
- res.m_X = NewX;
- res.m_Z = NewZ;
res.m_Direction = RotateBlockFaceCCW(res.m_Direction);
break;
}
case 2:
{
// 2 rotations ( = axis flip):
- res.m_X = Size.x - res.m_X;
- res.m_Z = Size.z - res.m_Z;
res.m_Direction = MirrorBlockFaceY(res.m_Direction);
break;
}
case 3:
{
// 1 CW rotation:
- int NewX = res.m_Z;
- int NewZ = Size.x - res.m_X;
- res.m_X = NewX;
- res.m_Z = NewZ;
res.m_Direction = RotateBlockFaceCW(res.m_Direction);
break;
}
}
+ res.m_Pos = RotatePos(a_Connector.m_Pos, a_NumCCWRotations);
// Move the res connector:
- res.m_X += a_MoveX;
- res.m_Y += a_MoveY;
- res.m_Z += a_MoveZ;
+ res.m_Pos.x += a_MoveX;
+ res.m_Pos.y += a_MoveY;
+ res.m_Pos.z += a_MoveZ;
return res;
}
@@ -71,25 +222,28 @@ cPiece::cConnector cPiece::RotateMoveConnector(const cConnector & a_Connector, i
cCuboid cPiece::RotateHitBoxToConnector(
const cPiece::cConnector & a_MyConnector,
- const cPiece::cConnector & a_ToConnector,
+ const Vector3i & a_ToConnectorPos,
int a_NumCCWRotations
) const
{
+ ASSERT(a_NumCCWRotations == (a_NumCCWRotations % 4));
+ Vector3i ConnPos = RotatePos(a_MyConnector.m_Pos, a_NumCCWRotations);
+ ConnPos = a_ToConnectorPos - ConnPos;
+ return RotateMoveHitBox(a_NumCCWRotations, ConnPos.x, ConnPos.y, ConnPos.z);
+}
+
+
+
+
+
+cCuboid cPiece::RotateMoveHitBox(int a_NumCCWRotations, int a_MoveX, int a_MoveY, int a_MoveZ) const
+{
+ ASSERT(a_NumCCWRotations == (a_NumCCWRotations % 4));
cCuboid res = GetHitBox();
- switch (a_NumCCWRotations)
- {
- case 0:
- {
- // No rotation, return the hitbox as-is
- break;
- }
- case 1:
- {
- // 1 CCW rotation:
- // TODO: res.p1.x =
- break;
- }
- }
+ res.p1 = RotatePos(res.p1, a_NumCCWRotations);
+ res.p2 = RotatePos(res.p2, a_NumCCWRotations);
+ res.p1.Move(a_MoveX, a_MoveY, a_MoveZ);
+ res.p2.Move(a_MoveX, a_MoveY, a_MoveZ);
return res;
}
@@ -97,6 +251,31 @@ cCuboid cPiece::RotateHitBoxToConnector(
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// cPiece::cConnector:
+
+cPiece::cConnector::cConnector(int a_X, int a_Y, int a_Z, int a_Type, eBlockFace a_Direction) :
+ m_Pos(a_X, a_Y, a_Z),
+ m_Type(a_Type),
+ m_Direction(a_Direction)
+{
+}
+
+
+
+
+
+cPiece::cConnector::cConnector(const Vector3i & a_Pos, int a_Type, eBlockFace a_Direction) :
+ m_Pos(a_Pos),
+ m_Type(a_Type),
+ m_Direction(a_Direction)
+{
+}
+
+
+
+
+
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cPlacedPiece:
@@ -107,6 +286,7 @@ cPlacedPiece::cPlacedPiece(const cPlacedPiece * a_Parent, const cPiece & a_Piece
m_NumCCWRotations(a_NumCCWRotations)
{
m_Depth = (m_Parent == NULL) ? 0 : (m_Parent->GetDepth() + 1);
+ m_HitBox = a_Piece.RotateMoveHitBox(a_NumCCWRotations, a_Coords.x, a_Coords.y, a_Coords.z);
}
@@ -127,7 +307,20 @@ cPieceGenerator::cPieceGenerator(cPiecePool & a_PiecePool, int a_Seed) :
-cPlacedPiece cPieceGenerator::PlaceStartingPiece(int a_BlockX, int a_BlockY, int a_BlockZ, cFreeConnectors & a_OutConnectors)
+void cPieceGenerator::FreePieces(cPlacedPieces & a_PlacedPieces)
+{
+ for (cPlacedPieces::iterator itr = a_PlacedPieces.begin(), end = a_PlacedPieces.end(); itr != end; ++itr)
+ {
+ delete *itr;
+ } // for itr - a_PlacedPieces[]
+ a_PlacedPieces.clear();
+}
+
+
+
+
+
+cPlacedPiece * cPieceGenerator::PlaceStartingPiece(int a_BlockX, int a_BlockY, int a_BlockZ, cFreeConnectors & a_OutConnectors)
{
m_PiecePool.Reset();
int rnd = m_Noise.IntNoise3DInt(a_BlockX, a_BlockY, a_BlockZ) / 7;
@@ -150,7 +343,7 @@ cPlacedPiece cPieceGenerator::PlaceStartingPiece(int a_BlockX, int a_BlockY, int
}
int Rotation = Rotations[rnd % NumRotations];
- cPlacedPiece res(NULL, *StartingPiece, Vector3i(a_BlockX, a_BlockY, a_BlockZ), Rotation);
+ cPlacedPiece * res = new cPlacedPiece(NULL, *StartingPiece, Vector3i(a_BlockX, a_BlockY, a_BlockZ), Rotation);
// Place the piece's connectors into a_OutConnectors:
const cPiece::cConnectors & Conn = StartingPiece->GetConnectors();
@@ -171,7 +364,7 @@ cPlacedPiece cPieceGenerator::PlaceStartingPiece(int a_BlockX, int a_BlockY, int
bool cPieceGenerator::TryPlacePieceAtConnector(const cPlacedPiece & a_ParentPiece, const cPiece::cConnector & a_Connector, cPlacedPieces & a_OutPieces)
{
// Translation of direction - direction -> number of CCW rotations needed:
- // You need DirectionRotationTable[rot1][rot2] CCW turns to get from rot1 to rot2
+ // You need DirectionRotationTable[rot1][rot2] CCW turns to connect rot1 to rot2 (they are opposite)
static const int DirectionRotationTable[6][6] =
{
/* YM, YP, ZM, ZP, XM, XP
@@ -188,6 +381,12 @@ bool cPieceGenerator::TryPlacePieceAtConnector(const cPlacedPiece & a_ParentPiec
cConnections Connections;
cPieces AvailablePieces = m_PiecePool.GetPiecesWithConnector(a_Connector.m_Type);
Connections.reserve(AvailablePieces.size());
+ Vector3i ConnPos = a_Connector.m_Pos; // The position at which the new connector should be placed - 1 block away from the connector
+ AddFaceDirection(ConnPos.x, ConnPos.y, ConnPos.z, a_Connector.m_Direction);
+
+ // DEBUG:
+ printf("Placing piece at pos {%d, %d, %d}, direction %s\n", ConnPos.x, ConnPos.y, ConnPos.z, BlockFaceToString(a_Connector.m_Direction).c_str());
+
for (cPieces::iterator itrP = AvailablePieces.begin(), endP = AvailablePieces.end(); itrP != endP; ++itrP)
{
cPiece::cConnectors Connectors = (*itrP)->GetConnectors();
@@ -204,7 +403,7 @@ bool cPieceGenerator::TryPlacePieceAtConnector(const cPlacedPiece & a_ParentPiec
// Doesn't support this rotation
continue;
}
- if (!CheckConnection(a_Connector, **itrP, *itrC, NumCCWRotations, a_OutPieces))
+ if (!CheckConnection(a_Connector, ConnPos, **itrP, *itrC, NumCCWRotations, a_OutPieces))
{
// Doesn't fit in this rotation
continue;
@@ -219,17 +418,23 @@ bool cPieceGenerator::TryPlacePieceAtConnector(const cPlacedPiece & a_ParentPiec
}
// Choose a random connection from the list:
- int rnd = m_Noise.IntNoise3DInt(a_Connector.m_X, a_Connector.m_Y, a_Connector.m_Z) / 7;
+ int rnd = m_Noise.IntNoise3DInt(a_Connector.m_Pos.x, a_Connector.m_Pos.y, a_Connector.m_Pos.z) / 7;
cConnection & Conn = Connections[rnd % Connections.size()];
// Place the piece:
- cPiece::cConnector NewConnector = Conn.m_Piece->RotateMoveConnector(*(Conn.m_Connector), Conn.m_NumCCWRotations, 0, 0, 0);
- Vector3i Coords = a_ParentPiece.GetCoords();
- Coords.x -= NewConnector.m_X;
- Coords.y -= NewConnector.m_Y;
- Coords.z -= NewConnector.m_Z;
- a_OutPieces.push_back(cPlacedPiece(&a_ParentPiece, *(Conn.m_Piece), Coords, Conn.m_NumCCWRotations));
- return false;
+ printf("Chosen connector at {%d, %d, %d}, direction %s, needs %d rotations\n",
+ Conn.m_Connector.m_Pos.x, Conn.m_Connector.m_Pos.y, Conn.m_Connector.m_Pos.z,
+ BlockFaceToString(Conn.m_Connector.m_Direction).c_str(),
+ Conn.m_NumCCWRotations
+ );
+ Vector3i NewPos = Conn.m_Piece->RotatePos(Conn.m_Connector.m_Pos, Conn.m_NumCCWRotations);
+ ConnPos -= NewPos;
+ a_OutPieces.push_back(new cPlacedPiece(&a_ParentPiece, *(Conn.m_Piece), ConnPos, Conn.m_NumCCWRotations));
+
+ // Add the new piece's connectors to the list of free connectors:
+ // TODO
+
+ return true;
}
@@ -238,6 +443,7 @@ bool cPieceGenerator::TryPlacePieceAtConnector(const cPlacedPiece & a_ParentPiec
bool cPieceGenerator::CheckConnection(
const cPiece::cConnector & a_ExistingConnector,
+ const Vector3i & a_ToPos,
const cPiece & a_Piece,
const cPiece::cConnector & a_NewConnector,
int a_NumCCWRotations,
@@ -245,10 +451,10 @@ bool cPieceGenerator::CheckConnection(
)
{
// For each placed piece, test the hitbox against the new piece:
- cCuboid RotatedHitBox = a_Piece.RotateHitBoxToConnector(a_NewConnector, a_ExistingConnector, a_NumCCWRotations);
+ cCuboid RotatedHitBox = a_Piece.RotateHitBoxToConnector(a_NewConnector, a_ToPos, a_NumCCWRotations);
for (cPlacedPieces::const_iterator itr = a_OutPieces.begin(), end = a_OutPieces.end(); itr != end; ++itr)
{
- if (itr->GetHitBox().DoesIntersect(RotatedHitBox))
+ if ((*itr)->GetHitBox().DoesIntersect(RotatedHitBox))
{
return false;
}
@@ -260,12 +466,32 @@ bool cPieceGenerator::CheckConnection(
+// DEBUG:
+void cPieceGenerator::DebugConnectorPool(const cPieceGenerator::cFreeConnectors & a_ConnectorPool, size_t a_NumProcessed)
+{
+ printf(" Connector pool: %u items\n", a_ConnectorPool.size() - a_NumProcessed);
+ size_t idx = 0;
+ for (cPieceGenerator::cFreeConnectors::const_iterator itr = a_ConnectorPool.begin() + a_NumProcessed, end = a_ConnectorPool.end(); itr != end; ++itr, ++idx)
+ {
+ printf(" %u: {%d, %d, %d}, type %d, direction %s\n",
+ idx,
+ itr->m_Connector.m_Pos.x, itr->m_Connector.m_Pos.y, itr->m_Connector.m_Pos.z,
+ itr->m_Connector.m_Type,
+ BlockFaceToString(itr->m_Connector.m_Direction).c_str()
+ );
+ } // for itr - a_ConnectorPool[]
+}
+
+
+
+
+
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cPieceGenerator::cConnection:
cPieceGenerator::cConnection::cConnection(cPiece & a_Piece, cPiece::cConnector & a_Connector, int a_NumCCWRotations) :
m_Piece(&a_Piece),
- m_Connector(&a_Connector),
+ m_Connector(a_Connector),
m_NumCCWRotations(a_NumCCWRotations)
{
}
@@ -277,8 +503,8 @@ cPieceGenerator::cConnection::cConnection(cPiece & a_Piece, cPiece::cConnector &
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cPieceGenerator::cFreeConnector:
-cPieceGenerator::cFreeConnector::cFreeConnector(cPlacedPiece & a_Piece, const cPiece::cConnector & a_Connector) :
- m_Piece(&a_Piece),
+cPieceGenerator::cFreeConnector::cFreeConnector(cPlacedPiece * a_Piece, const cPiece::cConnector & a_Connector) :
+ m_Piece(a_Piece),
m_Connector(a_Connector)
{
}
@@ -299,7 +525,7 @@ cBFSPieceGenerator::cBFSPieceGenerator(cPiecePool & a_PiecePool, int a_Seed) :
-void cBFSPieceGenerator::PlacePieces(int a_BlockX, int a_BlockY, int a_BlockZ, cPlacedPieces & a_OutPieces)
+void cBFSPieceGenerator::PlacePieces(int a_BlockX, int a_BlockY, int a_BlockZ, int a_MaxDepth, cPlacedPieces & a_OutPieces)
{
a_OutPieces.clear();
cFreeConnectors ConnectorPool;
@@ -307,6 +533,17 @@ void cBFSPieceGenerator::PlacePieces(int a_BlockX, int a_BlockY, int a_BlockZ, c
// Place the starting piece:
a_OutPieces.push_back(PlaceStartingPiece(a_BlockX, a_BlockY, a_BlockZ, ConnectorPool));
+ // DEBUG:
+ printf("Placed the starting piece at {%d, %d, %d}\n", a_BlockX, a_BlockY, a_BlockZ);
+ cCuboid Hitbox = a_OutPieces[0]->GetHitBox();
+ Hitbox.Sort();
+ printf(" Hitbox: {%d, %d, %d} - {%d, %d, %d} (%d * %d * %d)\n",
+ Hitbox.p1.x, Hitbox.p1.y, Hitbox.p1.z,
+ Hitbox.p2.x, Hitbox.p2.y, Hitbox.p2.z,
+ Hitbox.DifX() + 1, Hitbox.DifY() + 1, Hitbox.DifZ() + 1
+ );
+ DebugConnectorPool(ConnectorPool, 0);
+
// Place pieces at the available connectors:
/*
Instead of removing them one by one from the pool, we process them sequentially and take note of the last
@@ -317,7 +554,23 @@ void cBFSPieceGenerator::PlacePieces(int a_BlockX, int a_BlockY, int a_BlockZ, c
while (ConnectorPool.size() > NumProcessed)
{
cFreeConnector & Conn = ConnectorPool[NumProcessed];
- TryPlacePieceAtConnector(*Conn.m_Piece, Conn.m_Connector, a_OutPieces);
+ if (Conn.m_Piece->GetDepth() < a_MaxDepth)
+ {
+ if (TryPlacePieceAtConnector(*Conn.m_Piece, Conn.m_Connector, a_OutPieces))
+ {
+ const cPlacedPiece * NewPiece = a_OutPieces.back();
+ const Vector3i & Coords = NewPiece->GetCoords();
+ printf("Placed a new piece at {%d, %d, %d}, rotation %d\n", Coords.x, Coords.y, Coords.z, NewPiece->GetNumCCWRotations());
+ cCuboid Hitbox = NewPiece->GetHitBox();
+ Hitbox.Sort();
+ printf(" Hitbox: {%d, %d, %d} - {%d, %d, %d} (%d * %d * %d)\n",
+ Hitbox.p1.x, Hitbox.p1.y, Hitbox.p1.z,
+ Hitbox.p2.x, Hitbox.p2.y, Hitbox.p2.z,
+ Hitbox.DifX() + 1, Hitbox.DifY() + 1, Hitbox.DifZ() + 1
+ );
+ DebugConnectorPool(ConnectorPool, NumProcessed + 1);
+ }
+ }
NumProcessed++;
if (NumProcessed > 1000)
{
diff --git a/src/Generating/PieceGenerator.h b/src/Generating/PieceGenerator.h
index 3bc71a0ab..0e24510ae 100644
--- a/src/Generating/PieceGenerator.h
+++ b/src/Generating/PieceGenerator.h
@@ -32,13 +32,18 @@ class cPiece
public:
struct cConnector
{
- int m_X;
- int m_Y;
- int m_Z;
+ /** Position relative to the piece */
+ Vector3i m_Pos;
+
+ /** Type of the connector. Any arbitrary number; the generator connects only connectors of the same type. */
int m_Type;
+
+ /** Direction in which the connector is facing.
+ Will be matched by the opposite direction for the connecting connector. */
eBlockFace m_Direction;
- cConnector(int a_X, int a_Y, int a_Z, int a_Type, eBlockFace m_Direction);
+ cConnector(int a_X, int a_Y, int a_Z, int a_Type, eBlockFace a_Direction);
+ cConnector(const Vector3i & a_Pos, int a_Type, eBlockFace a_Direction);
};
typedef std::vector cConnectors;
@@ -58,11 +63,17 @@ public:
/** Returns true if the piece can be rotated CCW the specific number of 90-degree turns. */
virtual bool CanRotateCCW(int a_NumRotations) const = 0;
+ /** Returns a copy of the a_Pos after rotating the piece the specified number of CCW rotations. */
+ Vector3i RotatePos(const Vector3i & a_Pos, int a_NumCCWRotations) const;
+
/** Returns a copy of the connector that is rotated and then moved by the specified amounts. */
cConnector RotateMoveConnector(const cConnector & a_Connector, int a_NumCCWRotations, int a_MoveX, int a_MoveY, int a_MoveZ) const;
- /** Returns the hitbox after the specified number of rotations and moved so that a_MyConnector is placed at a_ToConnector*/
- cCuboid RotateHitBoxToConnector(const cConnector & a_MyConnector, const cConnector & a_ToConnector, int a_NumCCWRotations) const;
+ /** Returns the hitbox after the specified number of rotations and moved so that a_MyConnector is placed at a_ToConnectorPos. */
+ cCuboid RotateHitBoxToConnector(const cConnector & a_MyConnector, const Vector3i & a_ToConnectorPos, int a_NumCCWRotations) const;
+
+ /** Returns the hitbox after the specified number of CCW rotations and moved by the specified amounts. */
+ cCuboid RotateMoveHitBox(int a_NumCCWRotations, int a_MoveX, int a_MoveY, int a_MoveZ) const;
};
typedef std::vector cPieces;
@@ -116,7 +127,7 @@ protected:
int m_Depth;
};
-typedef std::vector cPlacedPieces;
+typedef std::vector cPlacedPieces;
@@ -127,12 +138,16 @@ class cPieceGenerator
public:
cPieceGenerator(cPiecePool & a_PiecePool, int a_Seed);
+ /** Cleans up all the memory used by the placed pieces.
+ Call this utility function instead of freeing the items on your own. */
+ void FreePieces(cPlacedPieces & a_PlacedPieces);
+
protected:
/** The type used for storing a connection from one piece to another, while building the piece tree. */
struct cConnection
{
cPiece * m_Piece; // The piece being connected
- cPiece::cConnector * m_Connector; // The piece's connector being used
+ cPiece::cConnector m_Connector; // The piece's connector being used (relative non-rotated coords)
int m_NumCCWRotations; // Number of rotations necessary to match the two connectors
cConnection(cPiece & a_Piece, cPiece::cConnector & a_Connector, int a_NumCCWRotations);
@@ -145,7 +160,7 @@ protected:
cPlacedPiece * m_Piece;
cPiece::cConnector m_Connector;
- cFreeConnector(cPlacedPiece & a_Piece, const cPiece::cConnector & a_Connector);
+ cFreeConnector(cPlacedPiece * a_Piece, const cPiece::cConnector & a_Connector);
};
typedef std::vector cFreeConnectors;
@@ -157,7 +172,7 @@ protected:
/** Selects a starting piece and places it, including the rotations.
Also puts the piece's connectors in a_OutConnectors. */
- cPlacedPiece PlaceStartingPiece(int a_BlockX, int a_BlockY, int a_BlockZ, cFreeConnectors & a_OutConnectors);
+ cPlacedPiece * PlaceStartingPiece(int a_BlockX, int a_BlockY, int a_BlockZ, cFreeConnectors & a_OutConnectors);
/** Tries to place a new piece at the specified (placed) connector. Returns true if successful. */
bool TryPlacePieceAtConnector(
@@ -168,14 +183,22 @@ protected:
/** Checks if the specified piece would fit with the already-placed pieces, using the specified connector
and number of CCW rotations.
+ a_ExistingConnector is in world-coords and is already rotated properly
+ a_ToPos is the world-coords position on which the new connector should be placed (1 block away from a_ExistingConnector, in its Direction)
+ a_NewConnector is in the original (non-rotated) coords.
Returns true if the piece fits, false if not. */
bool CheckConnection(
const cPiece::cConnector & a_ExistingConnector, // The existing connector
+ const Vector3i & a_ToPos, // The position on which the new connector should be placed
const cPiece & a_Piece, // The new piece
const cPiece::cConnector & a_NewConnector, // The connector of the new piece
int a_NumCCWRotations, // Number of rotations for the new piece to align the connector
const cPlacedPieces & a_OutPieces // All the already-placed pieces to check
);
+
+ /** DEBUG: Outputs all the connectors in the pool into stdout.
+ a_NumProcessed signals the number of connectors from the pool that should be considered processed (not listed). */
+ void DebugConnectorPool(const cPieceGenerator::cFreeConnectors & a_ConnectorPool, size_t a_NumProcessed);
} ;
@@ -190,8 +213,9 @@ class cBFSPieceGenerator :
public:
cBFSPieceGenerator(cPiecePool & a_PiecePool, int a_Seed);
- /** Generates a placement for pieces at the specified coords. */
- void PlacePieces(int a_BlockX, int a_BlockY, int a_BlockZ, cPlacedPieces & a_OutPieces);
+ /** Generates a placement for pieces at the specified coords.
+ Caller must free each individual cPlacedPiece in a_OutPieces. */
+ void PlacePieces(int a_BlockX, int a_BlockY, int a_BlockZ, int a_MaxDepth, cPlacedPieces & a_OutPieces);
};
@@ -204,7 +228,8 @@ class cDFSPieceGenerator :
public:
cDFSPieceGenerator(cPiecePool & a_PiecePool, int a_Seed);
- /** Generates a placement for pieces at the specified coords. */
+ /** Generates a placement for pieces at the specified coords.
+ Caller must free each individual cPlacedPiece in a_OutPieces. */
void PlacePieces(int a_BlockX, int a_BlockY, int a_BlockZ, cPlacedPieces & a_OutPieces);
};
--
cgit v1.2.3
From 77787fb719bf6437d4101f091b5b9acedea83dd3 Mon Sep 17 00:00:00 2001
From: Tiger Wang
Date: Sun, 9 Mar 2014 14:55:47 +0000
Subject: != FACE_NONE
---
src/ClientHandle.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index d268a4122..1bd55a461 100644
--- a/src/ClientHandle.cpp
+++ b/src/ClientHandle.cpp
@@ -949,7 +949,7 @@ void cClientHandle::HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, e
cBlockHandler * BlockHandler = cBlockInfo::GetHandler(BlockType);
BlockHandler->OnCancelRightClick(ChunkInterface, *World, m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace);
- if (a_BlockFace > BLOCK_FACE_NONE)
+ if (a_BlockFace != BLOCK_FACE_NONE)
{
AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace);
World->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, m_Player);
--
cgit v1.2.3
From b64e9fb7f52e4a2b75b49413fdc2194132885370 Mon Sep 17 00:00:00 2001
From: Tiger Wang
Date: Sun, 9 Mar 2014 00:17:23 +0000
Subject: Beds now work properly fixes #707
Also fixes FS392
Conflicts:
src/Blocks/WorldInterface.h
src/ClientHandle.cpp
---
src/Blocks/BlockBed.cpp | 73 +++++++++++++++++++++++++++++++++++++----
src/Blocks/BroadcastInterface.h | 5 +--
src/Blocks/WorldInterface.h | 8 ++++-
src/Entities/Player.h | 17 ++++++++--
src/World.h | 8 ++---
5 files changed, 94 insertions(+), 17 deletions(-)
diff --git a/src/Blocks/BlockBed.cpp b/src/Blocks/BlockBed.cpp
index 3dad4feba..ca3927827 100644
--- a/src/Blocks/BlockBed.cpp
+++ b/src/Blocks/BlockBed.cpp
@@ -51,6 +51,49 @@ void cBlockBedHandler::OnDestroyed(cChunkInterface & a_ChunkInterface, cWorldInt
+class cTimeFastForwardTester :
+ public cPlayerListCallback
+{
+ virtual bool Item(cPlayer * a_Player) override
+ {
+ if (!a_Player->IsInBed())
+ {
+ return true;
+ }
+
+ return false;
+ }
+};
+
+
+
+
+
+class cPlayerBedStateUnsetter :
+ public cPlayerListCallback
+{
+public:
+ cPlayerBedStateUnsetter(Vector3i a_Position, cWorldInterface & a_WorldInterface) :
+ m_Position(a_Position), m_WorldInterface(a_WorldInterface)
+ {
+ }
+
+ virtual bool Item(cPlayer * a_Player) override
+ {
+ a_Player->SetIsInBed(false);
+ m_WorldInterface.GetBroadcastManager().BroadcastEntityAnimation(*a_Player, 2);
+ return false;
+ }
+
+private:
+ Vector3i m_Position;
+ cWorldInterface & m_WorldInterface;
+};
+
+
+
+
+
void cBlockBedHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ)
{
if (a_WorldInterface.GetDimension() != dimOverworld)
@@ -69,6 +112,8 @@ void cBlockBedHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface
}
else
{
+ Vector3i PillowDirection(0, 0, 0);
+
if (Meta & 0x8)
{
// Is pillow
@@ -77,16 +122,30 @@ void cBlockBedHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface
else
{
// Is foot end
- Vector3i Direction = MetaDataToDirection( Meta & 0x7 );
- if (a_ChunkInterface.GetBlock(a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z) == E_BLOCK_BED) // Must always use pillow location for sleeping
+ VERIFY((Meta & 0x4) != 1); // Occupied flag should never be set, else our compilator (intended) is broken
+
+ PillowDirection = MetaDataToDirection(Meta & 0x7);
+ if (a_ChunkInterface.GetBlock(a_BlockX + PillowDirection.x, a_BlockY, a_BlockZ + PillowDirection.z) == E_BLOCK_BED) // Must always use pillow location for sleeping
{
- a_WorldInterface.GetBroadcastManager().BroadcastUseBed(*a_Player, a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z);
+ a_WorldInterface.GetBroadcastManager().BroadcastUseBed(*a_Player, a_BlockX + PillowDirection.x, a_BlockY, a_BlockZ + PillowDirection.z);
}
}
- a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, (Meta | (1 << 2)));
- }
-
- } else {
+
+ a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, Meta | 0x4); // Where 0x4 = occupied bit
+ a_Player->SetIsInBed(true);
+
+ cTimeFastForwardTester Tester;
+ if (a_WorldInterface.ForEachPlayer(Tester))
+ {
+ cPlayerBedStateUnsetter Unsetter(Vector3i(a_BlockX + PillowDirection.x, a_BlockY, a_BlockZ + PillowDirection.z), a_WorldInterface);
+ a_WorldInterface.ForEachPlayer(Unsetter);
+ a_WorldInterface.SetTimeOfDay(0);
+ a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, Meta & 0xB); // Where 0xB = 1011, and zero is to make sure 'occupied' bit is always unset
+ }
+ }
+ }
+ else
+ {
a_Player->SendMessageFailure("You can only sleep at night");
}
}
diff --git a/src/Blocks/BroadcastInterface.h b/src/Blocks/BroadcastInterface.h
index f6ccd580b..01966ffbd 100644
--- a/src/Blocks/BroadcastInterface.h
+++ b/src/Blocks/BroadcastInterface.h
@@ -5,6 +5,7 @@ class cBroadcastInterface
{
public:
- virtual void BroadcastUseBed(const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ ) = 0;
- virtual void BroadcastSoundEffect (const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch, const cClientHandle * a_Exclude = NULL) = 0;
+ virtual void BroadcastUseBed (const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ ) = 0;
+ virtual void BroadcastSoundEffect(const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch, const cClientHandle * a_Exclude = NULL) = 0;
+ virtual void BroadcastEntityAnimation(const cEntity & a_Entity, char a_Animation, const cClientHandle * a_Exclude = NULL) = 0;
};
diff --git a/src/Blocks/WorldInterface.h b/src/Blocks/WorldInterface.h
index e59b00eff..580339d32 100644
--- a/src/Blocks/WorldInterface.h
+++ b/src/Blocks/WorldInterface.h
@@ -27,7 +27,13 @@ public:
/** Spawns a mob of the specified type. Returns the mob's EntityID if recognized and spawned, <0 otherwise */
virtual int SpawnMob(double a_PosX, double a_PosY, double a_PosZ, cMonster::eType a_MonsterType) = 0;
-
+
/** Sends the block on those coords to the player */
virtual void SendBlockTo(int a_BlockX, int a_BlockY, int a_BlockZ, cPlayer * a_Player) = 0;
+
+ /** Calls the callback for each player in the list; returns true if all players processed, false if the callback aborted by returning true */
+ virtual bool ForEachPlayer(cItemCallback & a_Callback) = 0;
+
+ virtual void SetTimeOfDay(Int64 a_TimeOfDay) = 0;
+
};
diff --git a/src/Entities/Player.h b/src/Entities/Player.h
index a795bb9eb..83a553821 100644
--- a/src/Entities/Player.h
+++ b/src/Entities/Player.h
@@ -275,6 +275,9 @@ public:
/// Returns true if the player is currently flying.
bool IsFlying(void) const { return m_IsFlying; }
+ /** Returns if a player is sleeping in a bed */
+ bool IsInBed(void) const { return m_bIsInBed; }
+
/// returns true if the player has thrown out a floater.
bool IsFishing(void) const { return m_IsFishing; }
@@ -283,6 +286,9 @@ public:
int GetFloaterID(void) const { return m_FloaterID; }
// tolua_end
+
+ /** Sets a player's in-bed state; we can't be sure plugins will keep this value updated, so no exporting */
+ void SetIsInBed(bool a_Flag) { m_bIsInBed = a_Flag; }
/// Starts eating the currently equipped item. Resets the eating timer and sends the proper animation packet
void StartEating(void);
@@ -376,8 +382,8 @@ protected:
GroupList m_ResolvedGroups;
GroupList m_Groups;
- std::string m_PlayerName;
- std::string m_LoadedWorldName;
+ AString m_PlayerName;
+ AString m_LoadedWorldName;
/// Xp Level stuff
enum
@@ -465,7 +471,7 @@ protected:
int m_FloaterID;
- cTeam* m_Team;
+ cTeam * m_Team;
@@ -488,6 +494,11 @@ protected:
/// Adds food exhaustion based on the difference between Pos and LastPos, sprinting status and swimming (in water block)
void ApplyFoodExhaustionFromMovement();
+
+ /** Flag representing whether the player is currently in a bed
+ Set by a right click on unoccupied bed, unset by a time fast forward or teleport */
+ bool m_bIsInBed;
+
} ; // tolua_export
diff --git a/src/World.h b/src/World.h
index 0a0939dd1..738697c94 100644
--- a/src/World.h
+++ b/src/World.h
@@ -134,7 +134,7 @@ public:
m_WeatherInterval = a_WeatherInterval;
}
- void SetTimeOfDay(Int64 a_TimeOfDay)
+ virtual void SetTimeOfDay(Int64 a_TimeOfDay)
{
m_TimeOfDay = a_TimeOfDay;
m_TimeOfDaySecs = (double)a_TimeOfDay / 20.0;
@@ -204,7 +204,7 @@ public:
void BroadcastEntityRelMoveLook (const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ, const cClientHandle * a_Exclude = NULL);
void BroadcastEntityStatus (const cEntity & a_Entity, char a_Status, const cClientHandle * a_Exclude = NULL);
void BroadcastEntityVelocity (const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL);
- void BroadcastEntityAnimation (const cEntity & a_Entity, char a_Animation, const cClientHandle * a_Exclude = NULL);
+ virtual void BroadcastEntityAnimation(const cEntity & a_Entity, char a_Animation, const cClientHandle * a_Exclude = NULL);
void BroadcastParticleEffect (const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmmount, cClientHandle * a_Exclude = NULL); // tolua_export
void BroadcastPlayerListItem (const cPlayer & a_Player, bool a_IsOnline, const cClientHandle * a_Exclude = NULL);
void BroadcastRemoveEntityEffect (const cEntity & a_Entity, int a_EffectID, const cClientHandle * a_Exclude = NULL);
@@ -217,7 +217,7 @@ public:
void BroadcastTeleportEntity (const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL);
void BroadcastThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ, const cClientHandle * a_Exclude = NULL);
void BroadcastTimeUpdate (const cClientHandle * a_Exclude = NULL);
- virtual void BroadcastUseBed (const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ );
+ virtual void BroadcastUseBed (const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ );
void BroadcastWeather (eWeather a_Weather, const cClientHandle * a_Exclude = NULL);
virtual cBroadcastInterface & GetBroadcastManager()
@@ -274,7 +274,7 @@ public:
void RemovePlayer( cPlayer* a_Player );
/** Calls the callback for each player in the list; returns true if all players processed, false if the callback aborted by returning true */
- bool ForEachPlayer(cPlayerListCallback & a_Callback); // >> EXPORTED IN MANUALBINDINGS <<
+ virtual bool ForEachPlayer(cPlayerListCallback & a_Callback); // >> EXPORTED IN MANUALBINDINGS <<
/** Calls the callback for the player of the given name; returns true if the player was found and the callback called, false if player not found. Callback return ignored */
bool DoWithPlayer(const AString & a_PlayerName, cPlayerListCallback & a_Callback); // >> EXPORTED IN MANUALBINDINGS <<
--
cgit v1.2.3
From 888c3f1af7b817ab770703ce0638e0eef07d2d31 Mon Sep 17 00:00:00 2001
From: Tiger Wang
Date: Sun, 9 Mar 2014 15:53:03 +0000
Subject: Fixed VERIFY
---
src/Blocks/BlockBed.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/Blocks/BlockBed.cpp b/src/Blocks/BlockBed.cpp
index ca3927827..6a3c6a55b 100644
--- a/src/Blocks/BlockBed.cpp
+++ b/src/Blocks/BlockBed.cpp
@@ -122,7 +122,7 @@ void cBlockBedHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface
else
{
// Is foot end
- VERIFY((Meta & 0x4) != 1); // Occupied flag should never be set, else our compilator (intended) is broken
+ VERIFY((Meta & 0x4) != 0x4); // Occupied flag should never be set, else our compilator (intended) is broken
PillowDirection = MetaDataToDirection(Meta & 0x7);
if (a_ChunkInterface.GetBlock(a_BlockX + PillowDirection.x, a_BlockY, a_BlockZ + PillowDirection.z) == E_BLOCK_BED) // Must always use pillow location for sleeping
--
cgit v1.2.3
From c5436e1ae75928f08a411d29a0b28241c3f2b062 Mon Sep 17 00:00:00 2001
From: Tycho
Date: Sun, 9 Mar 2014 09:16:15 -0700
Subject: Lots more warnings
---
SetFlags.cmake | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/SetFlags.cmake b/SetFlags.cmake
index 56d32b8fe..ec2f6c556 100644
--- a/SetFlags.cmake
+++ b/SetFlags.cmake
@@ -192,6 +192,15 @@ macro(set_exe_flags)
add_flags_cxx("-D__extern_always_inline=inline")
add_flags_cxx("-Weverything -Wno-c++98-compat-pedantic -Wno-string-conversion")
add_flags_cxx("-Wno-extra-semi -Wno-error=switch-enum -Wno-documentation")
+ add_flags_cxx("-Wno-error=sign-conversion -Wno-error=conversion -Wno-error=padded")
+ add_flags_cxx("-Wno-error=deprecated -Wno-error=weak-vtables -Wno-error=float-equal")
+ add_flags_cxx("-Wno-error=missing-prototypes -Wno-error=non-virtual-dtor")
+ add_flags_cxx("-Wno-error=covered-switch-default -Wno-error=shadow")
+ add_flags_cxx("-Wno-error=exit-time-destructors -Wno-error=missing-variable-declarations")
+ add_flags_cxx("-Wno-error=cast-align -Wno-error=unused-macros")
+ add_flags_cxx("-Wno-error=global-constructors -Wno-implicit-fallthrough")
+ add_flags_cxx("-Wno-missing-noreturn -Wno-error=unreachable-code -Wno-error=undef")
+ add_flags_cxx("-Wno-error=format-nonliteral")
endif()
endif()
--
cgit v1.2.3
From f4201e0b825479c6ae8ff3165fc0b7fa949c0006 Mon Sep 17 00:00:00 2001
From: Tycho
Date: Sun, 9 Mar 2014 09:25:16 -0700
Subject: Fixed gcc error
---
src/WorldStorage/WSSCompact.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/WorldStorage/WSSCompact.cpp b/src/WorldStorage/WSSCompact.cpp
index 5e49e4909..4301e1733 100644
--- a/src/WorldStorage/WSSCompact.cpp
+++ b/src/WorldStorage/WSSCompact.cpp
@@ -39,7 +39,7 @@ struct cWSSCompact::sChunkHeader
/// The maximum number of PAK files that are cached
-const int MAX_PAK_FILES = 16;
+const int MAX_PAK_FILES = 16U;
/// The maximum number of unsaved chunks before the cPAKFile saves them to disk
const int MAX_DIRTY_CHUNKS = 16;
--
cgit v1.2.3
From e73caf30f09248a7e428a937226e0383e69ff6ce Mon Sep 17 00:00:00 2001
From: Tycho
Date: Sun, 9 Mar 2014 09:33:40 -0700
Subject: Fix gcc error attempt 2
---
src/WorldStorage/WSSCompact.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/WorldStorage/WSSCompact.cpp b/src/WorldStorage/WSSCompact.cpp
index 4301e1733..885099713 100644
--- a/src/WorldStorage/WSSCompact.cpp
+++ b/src/WorldStorage/WSSCompact.cpp
@@ -39,7 +39,7 @@ struct cWSSCompact::sChunkHeader
/// The maximum number of PAK files that are cached
-const int MAX_PAK_FILES = 16U;
+const int MAX_PAK_FILES = static_cast(16);
/// The maximum number of unsaved chunks before the cPAKFile saves them to disk
const int MAX_DIRTY_CHUNKS = 16;
--
cgit v1.2.3
From ebf163b77a030553c616d19179a9cd0f6de787a6 Mon Sep 17 00:00:00 2001
From: Tycho
Date: Sun, 9 Mar 2014 09:45:59 -0700
Subject: Unsigned types take 3
---
src/WorldStorage/WSSCompact.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/WorldStorage/WSSCompact.cpp b/src/WorldStorage/WSSCompact.cpp
index 885099713..663260aaa 100644
--- a/src/WorldStorage/WSSCompact.cpp
+++ b/src/WorldStorage/WSSCompact.cpp
@@ -39,7 +39,7 @@ struct cWSSCompact::sChunkHeader
/// The maximum number of PAK files that are cached
-const int MAX_PAK_FILES = static_cast(16);
+const int MAX_PAK_FILES = static_cast(16);
/// The maximum number of unsaved chunks before the cPAKFile saves them to disk
const int MAX_DIRTY_CHUNKS = 16;
--
cgit v1.2.3
From b8cd0b0897f42f0d294203cec68729f43ecb711d Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Sun, 9 Mar 2014 17:48:17 +0100
Subject: Hotfix for MSVC compilation.
---
src/Protocol/Protocol125.h | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/Protocol/Protocol125.h b/src/Protocol/Protocol125.h
index 66f3227b0..aca24c03a 100644
--- a/src/Protocol/Protocol125.h
+++ b/src/Protocol/Protocol125.h
@@ -11,6 +11,7 @@
#include "Protocol.h"
#include "../ByteBuffer.h"
+#include "../Entities/Painting.h"
--
cgit v1.2.3
From 167ef3b7a1a1ec23330552decfc7d005ccfc8caa Mon Sep 17 00:00:00 2001
From: Tycho
Date: Sun, 9 Mar 2014 09:52:49 -0700
Subject: Take 4
---
src/WorldStorage/WSSCompact.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/WorldStorage/WSSCompact.cpp b/src/WorldStorage/WSSCompact.cpp
index 663260aaa..6e39b44cc 100644
--- a/src/WorldStorage/WSSCompact.cpp
+++ b/src/WorldStorage/WSSCompact.cpp
@@ -39,7 +39,7 @@ struct cWSSCompact::sChunkHeader
/// The maximum number of PAK files that are cached
-const int MAX_PAK_FILES = static_cast(16);
+const int MAX_PAK_FILES = static_cast(16);
/// The maximum number of unsaved chunks before the cPAKFile saves them to disk
const int MAX_DIRTY_CHUNKS = 16;
--
cgit v1.2.3
From 5c4c147e487e9dc08cfacd156b1f60a485460b75 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Sun, 9 Mar 2014 17:58:01 +0100
Subject: Silenced useless MSVC warnings in cMetaRotater.
---
src/Blocks/MetaRotater.h | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/src/Blocks/MetaRotater.h b/src/Blocks/MetaRotater.h
index d3664b6f1..dde88e6db 100644
--- a/src/Blocks/MetaRotater.h
+++ b/src/Blocks/MetaRotater.h
@@ -4,6 +4,15 @@
#pragma once
+// MSVC generates warnings for the templated AssertIfNotMatched parameter conditions, so disable it:
+#ifdef _MSC_VER
+ #pragma warning(disable: 4127) // Conditional expression is constant
+#endif
+
+
+
+
+
/*
Provides a mixin for rotations and reflections following the standard pattern of apply mask then use case.
@@ -29,6 +38,9 @@ public:
};
+
+
+
template
NIBBLETYPE cMetaRotater::MetaRotateCW(NIBBLETYPE a_Meta)
{
@@ -49,6 +61,8 @@ NIBBLETYPE cMetaRotater
NIBBLETYPE cMetaRotater::MetaRotateCCW(NIBBLETYPE a_Meta)
{
@@ -69,6 +83,8 @@ NIBBLETYPE cMetaRotater
NIBBLETYPE cMetaRotater::MetaMirrorXY(NIBBLETYPE a_Meta)
{
@@ -85,6 +101,7 @@ NIBBLETYPE cMetaRotater
NIBBLETYPE cMetaRotater::MetaMirrorYZ(NIBBLETYPE a_Meta)
{
@@ -97,3 +114,7 @@ NIBBLETYPE cMetaRotater
Date: Sun, 9 Mar 2014 10:04:07 -0700
Subject: Take 5
---
src/WorldStorage/WSSCompact.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/WorldStorage/WSSCompact.cpp b/src/WorldStorage/WSSCompact.cpp
index 6e39b44cc..18d4452d9 100644
--- a/src/WorldStorage/WSSCompact.cpp
+++ b/src/WorldStorage/WSSCompact.cpp
@@ -39,7 +39,7 @@ struct cWSSCompact::sChunkHeader
/// The maximum number of PAK files that are cached
-const int MAX_PAK_FILES = static_cast(16);
+const int MAX_PAK_FILES = static_cast(16);
/// The maximum number of unsaved chunks before the cPAKFile saves them to disk
const int MAX_DIRTY_CHUNKS = 16;
--
cgit v1.2.3
From 430aba9f1dc5db8c3d1ec9f9552bb41f8a0b21b0 Mon Sep 17 00:00:00 2001
From: Tycho
Date: Sun, 9 Mar 2014 10:10:36 -0700
Subject: Its a const not a macro
---
src/WorldStorage/WSSCompact.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/WorldStorage/WSSCompact.cpp b/src/WorldStorage/WSSCompact.cpp
index 18d4452d9..95477838e 100644
--- a/src/WorldStorage/WSSCompact.cpp
+++ b/src/WorldStorage/WSSCompact.cpp
@@ -39,7 +39,7 @@ struct cWSSCompact::sChunkHeader
/// The maximum number of PAK files that are cached
-const int MAX_PAK_FILES = static_cast(16);
+const size_t MAX_PAK_FILES = 16;
/// The maximum number of unsaved chunks before the cPAKFile saves them to disk
const int MAX_DIRTY_CHUNKS = 16;
--
cgit v1.2.3
From 676dcfd1c74a36882b5b9bb75749e3bd86b75d9e Mon Sep 17 00:00:00 2001
From: Tycho
Date: Sun, 9 Mar 2014 10:32:56 -0700
Subject: Globals.h is now warnings free again. Also turned off Wpadded as it
is indicates potental performance issues rather than potential bugs
---
SetFlags.cmake | 2 +-
src/ChunkDef.h | 32 ++++++++++++++++++++++++--------
src/Globals.h | 2 --
3 files changed, 25 insertions(+), 11 deletions(-)
diff --git a/SetFlags.cmake b/SetFlags.cmake
index ec2f6c556..82472f333 100644
--- a/SetFlags.cmake
+++ b/SetFlags.cmake
@@ -192,7 +192,7 @@ macro(set_exe_flags)
add_flags_cxx("-D__extern_always_inline=inline")
add_flags_cxx("-Weverything -Wno-c++98-compat-pedantic -Wno-string-conversion")
add_flags_cxx("-Wno-extra-semi -Wno-error=switch-enum -Wno-documentation")
- add_flags_cxx("-Wno-error=sign-conversion -Wno-error=conversion -Wno-error=padded")
+ add_flags_cxx("-Wno-error=sign-conversion -Wno-error=conversion -Wno-padded")
add_flags_cxx("-Wno-error=deprecated -Wno-error=weak-vtables -Wno-error=float-equal")
add_flags_cxx("-Wno-error=missing-prototypes -Wno-error=non-virtual-dtor")
add_flags_cxx("-Wno-error=covered-switch-default -Wno-error=shadow")
diff --git a/src/ChunkDef.h b/src/ChunkDef.h
index 63431f211..a5059348c 100644
--- a/src/ChunkDef.h
+++ b/src/ChunkDef.h
@@ -124,7 +124,9 @@ public:
(z < Width) && (z > -1)
)
{
- return MakeIndexNoCheck(x, y, z);
+ return MakeIndexNoCheck(static_cast(x),
+ static_cast(y),
+ static_cast(z));
}
LOGERROR("cChunkDef::MakeIndex(): coords out of range: {%d, %d, %d}; returning fake index 0", x, y, z);
ASSERT(!"cChunkDef::MakeIndex(): coords out of chunk range!");
@@ -166,7 +168,9 @@ public:
ASSERT((a_X >= 0) && (a_X < Width));
ASSERT((a_Y >= 0) && (a_Y < Height));
ASSERT((a_Z >= 0) && (a_Z < Width));
- a_BlockTypes[MakeIndexNoCheck(a_X, a_Y, a_Z)] = a_Type;
+ a_BlockTypes[MakeIndexNoCheck(static_cast(a_X),
+ static_cast(a_Y),
+ static_cast(a_Z))] = a_Type;
}
@@ -182,7 +186,9 @@ public:
ASSERT((a_X >= 0) && (a_X < Width));
ASSERT((a_Y >= 0) && (a_Y < Height));
ASSERT((a_Z >= 0) && (a_Z < Width));
- return a_BlockTypes[MakeIndexNoCheck(a_X, a_Y, a_Z)];
+ return a_BlockTypes[MakeIndexNoCheck(static_cast(a_X),
+ static_cast(a_Y),
+ static_cast(a_Z))];
}
@@ -240,7 +246,9 @@ public:
{
if ((x < Width) && (x > -1) && (y < Height) && (y > -1) && (z < Width) && (z > -1))
{
- unsigned int Index = MakeIndexNoCheck(x, y, z);
+ unsigned int Index = MakeIndexNoCheck(static_cast(x),
+ static_cast(y),
+ static_cast(z));
return (a_Buffer[Index / 2] >> ((Index & 1) * 4)) & 0x0f;
}
ASSERT(!"cChunkDef::GetNibble(): coords out of chunk range!");
@@ -255,8 +263,8 @@ public:
ASSERT(!"cChunkDef::SetNibble(): index out of range!");
return;
}
- a_Buffer[a_BlockIdx / 2] = (
- (a_Buffer[a_BlockIdx / 2] & (0xf0 >> (static_cast(a_BlockIdx & 1) * 4))) | // The untouched nibble
+ a_Buffer[a_BlockIdx / 2] = static_cast(
+ (a_Buffer[a_BlockIdx / 2] & (0xf0 >> ((a_BlockIdx & 1) * 4))) | // The untouched nibble
((a_Nibble & 0x0f) << ((a_BlockIdx & 1) * 4)) // The nibble being set
);
}
@@ -274,8 +282,10 @@ public:
return;
}
- int Index = MakeIndexNoCheck(x, y, z);
- a_Buffer[Index / 2] = (
+ unsigned int Index = MakeIndexNoCheck(static_cast(x),
+ static_cast(y),
+ static_cast(z));
+ a_Buffer[Index / 2] = static_cast(
(a_Buffer[Index / 2] & (0xf0 >> ((Index & 1) * 4))) | // The untouched nibble
((a_Nibble & 0x0f) << ((Index & 1) * 4)) // The nibble being set
);
@@ -435,6 +445,9 @@ Used primarily for entity moving while both chunks are locked.
class cClientDiffCallback
{
public:
+
+ virtual ~cClientDiffCallback() {}
+
/// Called for clients that are in Chunk1 and not in Chunk2,
virtual void Removed(cClientHandle * a_Client) = 0;
@@ -495,6 +508,9 @@ typedef std::vector cChunkCoordsVector;
class cChunkCoordCallback
{
public:
+
+ virtual ~cChunkCoordCallback() {}
+
virtual void Call(int a_ChunkX, int a_ChunkZ) = 0;
} ;
diff --git a/src/Globals.h b/src/Globals.h
index 28805a83f..98611fc55 100644
--- a/src/Globals.h
+++ b/src/Globals.h
@@ -254,5 +254,3 @@ T Clamp(T a_Value, T a_Min, T a_Max)
#include "Entities/Effects.h"
-
-
--
cgit v1.2.3
From 713c59b60b6a096554eda7fabc7696b33a6fcb59 Mon Sep 17 00:00:00 2001
From: Tycho
Date: Sun, 9 Mar 2014 10:41:53 -0700
Subject: Treat enum missmatches as warnings for now as there is such a large
number of them.
---
SetFlags.cmake | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/SetFlags.cmake b/SetFlags.cmake
index 82472f333..e71bf315d 100644
--- a/SetFlags.cmake
+++ b/SetFlags.cmake
@@ -182,7 +182,7 @@ macro(set_exe_flags)
string(REPLACE "-w" "" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
string(REPLACE "-w" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
string(REPLACE "-w" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
- add_flags_cxx("-Wall -Wextra -Werror -Wno-unused-parameter -Wno-error=switch")
+ add_flags_cxx("-Wall -Wextra -Werror -Wno-unused-parameter -Wno-error=switch -Wno-error=enum-compare")
# we support non-IEEE 754 fpus so can make no guarentees about error
add_flags_cxx("-ffast-math")
--
cgit v1.2.3
From 617ad0b5f8e8d469ec017a0e83754f7401f64d00 Mon Sep 17 00:00:00 2001
From: Tycho
Date: Sun, 9 Mar 2014 10:46:39 -0700
Subject: Only enable -Werror in gcc because gcc doesn't let you suppress enum
missmatch warnings
---
SetFlags.cmake | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/SetFlags.cmake b/SetFlags.cmake
index e71bf315d..a9657fff1 100644
--- a/SetFlags.cmake
+++ b/SetFlags.cmake
@@ -182,7 +182,7 @@ macro(set_exe_flags)
string(REPLACE "-w" "" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
string(REPLACE "-w" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
string(REPLACE "-w" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
- add_flags_cxx("-Wall -Wextra -Werror -Wno-unused-parameter -Wno-error=switch -Wno-error=enum-compare")
+ add_flags_cxx("-Wall -Wextra -Wno-unused-parameter -Wno-error=switch")
# we support non-IEEE 754 fpus so can make no guarentees about error
add_flags_cxx("-ffast-math")
@@ -190,7 +190,7 @@ macro(set_exe_flags)
# clang does not provide the __extern_always_inline macro and a part of libm depends on this when using fast-math
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
add_flags_cxx("-D__extern_always_inline=inline")
- add_flags_cxx("-Weverything -Wno-c++98-compat-pedantic -Wno-string-conversion")
+ add_flags_cxx("-Werror -Weverything -Wno-c++98-compat-pedantic -Wno-string-conversion")
add_flags_cxx("-Wno-extra-semi -Wno-error=switch-enum -Wno-documentation")
add_flags_cxx("-Wno-error=sign-conversion -Wno-error=conversion -Wno-padded")
add_flags_cxx("-Wno-error=deprecated -Wno-error=weak-vtables -Wno-error=float-equal")
--
cgit v1.2.3
From 3aff0b44bcb751606339de6498713b3ef2ce0e33 Mon Sep 17 00:00:00 2001
From: Tiger Wang
Date: Sun, 9 Mar 2014 17:51:02 +0000
Subject: Fixed #778 - stack overflow.com
---
src/Entities/Floater.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/Entities/Floater.h b/src/Entities/Floater.h
index 865d6dc50..f3b51d77b 100644
--- a/src/Entities/Floater.h
+++ b/src/Entities/Floater.h
@@ -11,7 +11,7 @@
class cFloater :
public cEntity
{
- typedef cFloater super;
+ typedef cEntity super;
public:
//tolua_end
--
cgit v1.2.3
From e5fc3c63f2ab4bcc8d225f746afd07d01ad9d08c Mon Sep 17 00:00:00 2001
From: Tycho
Date: Sun, 9 Mar 2014 10:52:12 -0700
Subject: Fix IsThread destructor
---
src/OSSupport/IsThread.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/OSSupport/IsThread.h b/src/OSSupport/IsThread.h
index b8784ea33..42b8bfdda 100644
--- a/src/OSSupport/IsThread.h
+++ b/src/OSSupport/IsThread.h
@@ -34,7 +34,7 @@ protected:
public:
cIsThread(const AString & iThreadName);
- ~cIsThread();
+ virtual ~cIsThread();
/// Starts the thread; returns without waiting for the actual start
bool Start(void);
--
cgit v1.2.3
From 9825dbfd34c65580d795065d1a82e7697b9c5cbd Mon Sep 17 00:00:00 2001
From: Tycho
Date: Sun, 9 Mar 2014 11:21:42 -0700
Subject: Fixed Mesannine twister to use UInt32
---
MCServer/Plugins/Core | 2 +-
src/ByteBuffer.h | 2 +-
src/Defines.h | 2 +-
src/Map.h | 2 +-
src/MersenneTwister.h | 4 +++-
5 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/MCServer/Plugins/Core b/MCServer/Plugins/Core
index 013a32a7f..3b416b07a 160000
--- a/MCServer/Plugins/Core
+++ b/MCServer/Plugins/Core
@@ -1 +1 @@
-Subproject commit 013a32a7fb3c8a6cfe0aef892d4c7394d4e1be59
+Subproject commit 3b416b07a339b3abcbc127070d56eea05b05373d
diff --git a/src/ByteBuffer.h b/src/ByteBuffer.h
index ed2e10a55..1915467f3 100644
--- a/src/ByteBuffer.h
+++ b/src/ByteBuffer.h
@@ -43,7 +43,7 @@ public:
size_t GetReadableSpace(void) const;
/// Returns the current data start index. For debugging purposes.
- int GetDataStart(void) const { return m_DataStart; }
+ size_t GetDataStart(void) const { return m_DataStart; }
/// Returns true if the specified amount of bytes are available for reading
bool CanReadBytes(size_t a_Count) const;
diff --git a/src/Defines.h b/src/Defines.h
index 6ab2274a4..fd240c91a 100644
--- a/src/Defines.h
+++ b/src/Defines.h
@@ -469,7 +469,7 @@ inline void EulerToVector(double a_Pan, double a_Pitch, double & a_X, double & a
inline void VectorToEuler(double a_X, double a_Y, double a_Z, double & a_Pan, double & a_Pitch)
{
- if (a_X != 0)
+ if (fabs(a_X) < std::numeric_limits::epsilon() )
{
a_Pan = atan2(a_Z, a_X) * 180 / PI - 90;
}
diff --git a/src/Map.h b/src/Map.h
index a313d5431..ee7c537b1 100644
--- a/src/Map.h
+++ b/src/Map.h
@@ -64,7 +64,7 @@ public:
unsigned int GetPixelX(void) const { return m_PixelX; }
unsigned int GetPixelZ(void) const { return m_PixelZ; }
- int GetRot(void) const { return m_Rot; }
+ unsigned int GetRot(void) const { return m_Rot; }
eType GetType(void) const { return m_Type; }
diff --git a/src/MersenneTwister.h b/src/MersenneTwister.h
index f4c7b0699..07b6b1e5c 100644
--- a/src/MersenneTwister.h
+++ b/src/MersenneTwister.h
@@ -59,10 +59,12 @@
#include
#include
+#include "Globals.h"
+
class MTRand {
// Data
public:
- typedef long uint32; // unsigned integer type, at least 32 bits
+ typedef UInt32 uint32; // unsigned integer type, at least 32 bits
enum { N = 624 }; // length of state vector
enum { SAVE = N + 1 }; // length of array for save()
--
cgit v1.2.3
From 1fdeabcf78394d197a7ab5e0f9edca07abdedd0e Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Sun, 9 Mar 2014 19:30:38 +0100
Subject: cPieceGenerator: New connectors are added to the free pool.
---
src/Generating/PieceGenerator.cpp | 32 ++++++++++++++++++++++++++------
src/Generating/PieceGenerator.h | 7 ++++---
2 files changed, 30 insertions(+), 9 deletions(-)
diff --git a/src/Generating/PieceGenerator.cpp b/src/Generating/PieceGenerator.cpp
index 58ccaf2c2..c8e4ec71b 100644
--- a/src/Generating/PieceGenerator.cpp
+++ b/src/Generating/PieceGenerator.cpp
@@ -361,7 +361,12 @@ cPlacedPiece * cPieceGenerator::PlaceStartingPiece(int a_BlockX, int a_BlockY, i
-bool cPieceGenerator::TryPlacePieceAtConnector(const cPlacedPiece & a_ParentPiece, const cPiece::cConnector & a_Connector, cPlacedPieces & a_OutPieces)
+bool cPieceGenerator::TryPlacePieceAtConnector(
+ const cPlacedPiece & a_ParentPiece,
+ const cPiece::cConnector & a_Connector,
+ cPlacedPieces & a_OutPieces,
+ cPieceGenerator::cFreeConnectors & a_OutConnectors
+)
{
// Translation of direction - direction -> number of CCW rotations needed:
// You need DirectionRotationTable[rot1][rot2] CCW turns to connect rot1 to rot2 (they are opposite)
@@ -429,10 +434,24 @@ bool cPieceGenerator::TryPlacePieceAtConnector(const cPlacedPiece & a_ParentPiec
);
Vector3i NewPos = Conn.m_Piece->RotatePos(Conn.m_Connector.m_Pos, Conn.m_NumCCWRotations);
ConnPos -= NewPos;
- a_OutPieces.push_back(new cPlacedPiece(&a_ParentPiece, *(Conn.m_Piece), ConnPos, Conn.m_NumCCWRotations));
+ cPlacedPiece * PlacedPiece = new cPlacedPiece(&a_ParentPiece, *(Conn.m_Piece), ConnPos, Conn.m_NumCCWRotations);
+ a_OutPieces.push_back(PlacedPiece);
// Add the new piece's connectors to the list of free connectors:
- // TODO
+ cPiece::cConnectors Connectors = Conn.m_Piece->GetConnectors();
+
+ // DEBUG:
+ printf("Adding %u connectors to the pool\n", Connectors.size() - 1);
+
+ for (cPiece::cConnectors::const_iterator itr = Connectors.begin(), end = Connectors.end(); itr != end; ++itr)
+ {
+ if (itr->m_Pos.Equals(Conn.m_Connector.m_Pos))
+ {
+ // This is the connector through which we have been connected to the parent, don't add
+ continue;
+ }
+ a_OutConnectors.push_back(cFreeConnector(PlacedPiece, Conn.m_Piece->RotateMoveConnector(*itr, Conn.m_NumCCWRotations, ConnPos.x, ConnPos.y, ConnPos.z)));
+ }
return true;
}
@@ -473,11 +492,12 @@ void cPieceGenerator::DebugConnectorPool(const cPieceGenerator::cFreeConnectors
size_t idx = 0;
for (cPieceGenerator::cFreeConnectors::const_iterator itr = a_ConnectorPool.begin() + a_NumProcessed, end = a_ConnectorPool.end(); itr != end; ++itr, ++idx)
{
- printf(" %u: {%d, %d, %d}, type %d, direction %s\n",
+ printf(" %u: {%d, %d, %d}, type %d, direction %s, depth %d\n",
idx,
itr->m_Connector.m_Pos.x, itr->m_Connector.m_Pos.y, itr->m_Connector.m_Pos.z,
itr->m_Connector.m_Type,
- BlockFaceToString(itr->m_Connector.m_Direction).c_str()
+ BlockFaceToString(itr->m_Connector.m_Direction).c_str(),
+ itr->m_Piece->GetDepth()
);
} // for itr - a_ConnectorPool[]
}
@@ -556,7 +576,7 @@ void cBFSPieceGenerator::PlacePieces(int a_BlockX, int a_BlockY, int a_BlockZ, i
cFreeConnector & Conn = ConnectorPool[NumProcessed];
if (Conn.m_Piece->GetDepth() < a_MaxDepth)
{
- if (TryPlacePieceAtConnector(*Conn.m_Piece, Conn.m_Connector, a_OutPieces))
+ if (TryPlacePieceAtConnector(*Conn.m_Piece, Conn.m_Connector, a_OutPieces, ConnectorPool))
{
const cPlacedPiece * NewPiece = a_OutPieces.back();
const Vector3i & Coords = NewPiece->GetCoords();
diff --git a/src/Generating/PieceGenerator.h b/src/Generating/PieceGenerator.h
index 0e24510ae..310c21fdd 100644
--- a/src/Generating/PieceGenerator.h
+++ b/src/Generating/PieceGenerator.h
@@ -176,9 +176,10 @@ protected:
/** Tries to place a new piece at the specified (placed) connector. Returns true if successful. */
bool TryPlacePieceAtConnector(
- const cPlacedPiece & a_ParentPiece,
- const cPiece::cConnector & a_Connector,
- cPlacedPieces & a_OutPieces
+ const cPlacedPiece & a_ParentPiece, // The existing piece to a new piece should be placed
+ const cPiece::cConnector & a_Connector, // The existing connector (world-coords) to which a new piece should be placed
+ cPlacedPieces & a_OutPieces, // Already placed pieces, to be checked for intersections
+ cFreeConnectors & a_OutConnectors // List of free connectors to which the new connectors will be placed
);
/** Checks if the specified piece would fit with the already-placed pieces, using the specified connector
--
cgit v1.2.3
From 1bf99b5fd26d142106d7a097900ebfe8a6279ad4 Mon Sep 17 00:00:00 2001
From: Tycho
Date: Sun, 9 Mar 2014 11:47:22 -0700
Subject: Be more parinoid about int sizes
---
src/Defines.h | 3 ++-
src/Globals.h | 18 ++++++++++++++++--
src/MersenneTwister.h | 2 --
3 files changed, 18 insertions(+), 5 deletions(-)
diff --git a/src/Defines.h b/src/Defines.h
index fd240c91a..592b9434a 100644
--- a/src/Defines.h
+++ b/src/Defines.h
@@ -2,6 +2,7 @@
#pragma once
#include "ChatColor.h"
+#include
@@ -469,7 +470,7 @@ inline void EulerToVector(double a_Pan, double a_Pitch, double & a_X, double & a
inline void VectorToEuler(double a_X, double a_Y, double a_Z, double & a_Pan, double & a_Pitch)
{
- if (fabs(a_X) < std::numeric_limits::epsilon() )
+ if (fabs(a_X) < std::numeric_limits::epsilon())
{
a_Pan = atan2(a_Z, a_X) * 180 / PI - 90;
}
diff --git a/src/Globals.h b/src/Globals.h
index 98611fc55..b046e6db0 100644
--- a/src/Globals.h
+++ b/src/Globals.h
@@ -81,7 +81,7 @@
#endif
-
+#include
// Integral types with predefined sizes:
@@ -96,8 +96,22 @@ typedef unsigned short UInt16;
typedef unsigned char Byte;
+// If you get an error about specialization check the size of integral types
+template
+class SizeChecker;
+
+template
+class SizeChecker {
+ T v;
+};
+template class SizeChecker;
+template class SizeChecker;
+template class SizeChecker;
+template class SizeChecker;
+template class SizeChecker;
+template class SizeChecker;
// A macro to disallow the copy constructor and operator= functions
// This should be used in the private: declarations for any class that shouldn't allow copying itself
@@ -179,7 +193,7 @@ typedef unsigned char Byte;
#include
#include
#include
-
+#include
diff --git a/src/MersenneTwister.h b/src/MersenneTwister.h
index 07b6b1e5c..2c5440f17 100644
--- a/src/MersenneTwister.h
+++ b/src/MersenneTwister.h
@@ -59,8 +59,6 @@
#include
#include
-#include "Globals.h"
-
class MTRand {
// Data
public:
--
cgit v1.2.3
From 8889d3b73347a7cc094a0e233479e96f2bc25a49 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Sun, 9 Mar 2014 19:54:27 +0100
Subject: Added cCuboid::Engulf().
---
src/Cuboid.cpp | 34 ++++++++++++++++++++++++++++++++++
src/Cuboid.h | 3 +++
2 files changed, 37 insertions(+)
diff --git a/src/Cuboid.cpp b/src/Cuboid.cpp
index 782837b23..dc8df8500 100644
--- a/src/Cuboid.cpp
+++ b/src/Cuboid.cpp
@@ -197,3 +197,37 @@ bool cCuboid::IsSorted(void) const
+
+void cCuboid::Engulf(const Vector3i & a_Point)
+{
+ if (a_Point.x < p1.x)
+ {
+ p1.x = a_Point.x;
+ }
+ else if (a_Point.x > p2.x)
+ {
+ p2.x = a_Point.x;
+ }
+
+ if (a_Point.y < p1.y)
+ {
+ p1.y = a_Point.y;
+ }
+ else if (a_Point.y > p2.y)
+ {
+ p2.y = a_Point.y;
+ }
+
+ if (a_Point.z < p1.z)
+ {
+ p1.z = a_Point.z;
+ }
+ else if (a_Point.z > p2.z)
+ {
+ p2.z = a_Point.z;
+ }
+}
+
+
+
+
diff --git a/src/Cuboid.h b/src/Cuboid.h
index 51ccf799b..50a69b853 100644
--- a/src/Cuboid.h
+++ b/src/Cuboid.h
@@ -86,6 +86,9 @@ public:
/** Returns true if the coords are properly sorted (lesser in p1, greater in p2) */
bool IsSorted(void) const;
+
+ /** If needed, expands the cuboid so that it contains the specified point. Assumes sorted. Doesn't contract. */
+ void Engulf(const Vector3i & a_Point);
} ;
// tolua_end
--
cgit v1.2.3
From 2eaae82a2a6f22b684ea153267c8f06f18145753 Mon Sep 17 00:00:00 2001
From: worktycho
Date: Sun, 9 Mar 2014 18:57:43 +0000
Subject: Mentiod that we use some c++11 exstensions
Eg override, abstract, va_copy, long long.
---
CONTRIBUTING.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 7ec7058ae..0c36be8b7 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -1,7 +1,7 @@
Code Stuff
----------
- * We use C++03
+ * We use C++03 with some C++11 extensions (ask if you think that something would be useful)
* Use the provided wrappers for OS stuff:
- Threading is done by inheriting from `cIsThread`, thread synchronization through `cCriticalSection`, `cSemaphore` and `cEvent`, file access and filesystem operations through the `cFile` class, high-precision timers through `cTimer`, high-precision sleep through `cSleep`
* No magic numbers, use named constants:
--
cgit v1.2.3
From 81bf846e648bf757a67699c57f2a9e66f6850416 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Sun, 9 Mar 2014 21:58:12 +0100
Subject: ChunkDef: Replaced enums with static const ints.
This makes them easier to use in std::min et al.
---
src/ChunkDef.h | 16 ++++++----------
1 file changed, 6 insertions(+), 10 deletions(-)
diff --git a/src/ChunkDef.h b/src/ChunkDef.h
index 7be2fa2df..7876c58e7 100644
--- a/src/ChunkDef.h
+++ b/src/ChunkDef.h
@@ -62,16 +62,12 @@ typedef unsigned char HEIGHTTYPE;
class cChunkDef
{
public:
- enum
- {
- // Chunk dimensions:
- Width = 16,
- Height = 256,
- NumBlocks = Width * Height * Width,
-
- /// If the data is collected into a single buffer, how large it needs to be:
- BlockDataSize = cChunkDef::NumBlocks * 2 + (cChunkDef::NumBlocks / 2), // 2.5 * numblocks
- } ;
+ // Chunk dimensions:
+ static const int Width = 16;
+ static const int Height = 256;
+ static const int NumBlocks = Width * Height * Width;
+ /// If the data is collected into a single buffer, how large it needs to be:
+ static const int BlockDataSize = cChunkDef::NumBlocks * 2 + (cChunkDef::NumBlocks / 2); // 2.5 * numblocks
/// The type used for any heightmap operations and storage; idx = x + Width * z; Height points to the highest non-air block in the column
typedef HEIGHTTYPE HeightMap[Width * Width];
--
cgit v1.2.3
From dacb6cef1d6d2942f01d15186d8a12b30d39a385 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Sun, 9 Mar 2014 22:02:08 +0100
Subject: Hardened cCuboid with asserts for its assumptions.
---
src/Cuboid.cpp | 6 ++++++
src/Cuboid.h | 8 +++++---
2 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/src/Cuboid.cpp b/src/Cuboid.cpp
index dc8df8500..2400c64f3 100644
--- a/src/Cuboid.cpp
+++ b/src/Cuboid.cpp
@@ -72,6 +72,9 @@ int cCuboid::GetVolume(void) const
bool cCuboid::DoesIntersect(const cCuboid & a_Other) const
{
+ ASSERT(IsSorted());
+ ASSERT(a_Other.IsSorted());
+
// In order for cuboids to intersect, each of their coord intervals need to intersect
return (
DoIntervalsIntersect(p1.x, p2.x, a_Other.p1.x, a_Other.p2.x) &&
@@ -86,6 +89,9 @@ bool cCuboid::DoesIntersect(const cCuboid & a_Other) const
bool cCuboid::IsCompletelyInside(const cCuboid & a_Outer) const
{
+ ASSERT(IsSorted());
+ ASSERT(a_Outer.IsSorted());
+
return (
(p1.x >= a_Outer.p1.x) &&
(p2.x <= a_Outer.p2.x) &&
diff --git a/src/Cuboid.h b/src/Cuboid.h
index 50a69b853..b95517f69 100644
--- a/src/Cuboid.h
+++ b/src/Cuboid.h
@@ -34,7 +34,8 @@ public:
Works on unsorted cuboids, too. */
int GetVolume(void) const;
- /** Returns true if the cuboids have at least one voxel in common. Both coords are considered inclusive. */
+ /** Returns true if the cuboids have at least one voxel in common. Both coords are considered inclusive.
+ Assumes both cuboids are sorted. */
bool DoesIntersect(const cCuboid & a_Other) const;
bool IsInside(const Vector3i & v) const
@@ -64,7 +65,8 @@ public:
);
}
- /** Returns true if this cuboid is completely inside the specifie cuboid (in all 6 coords) */
+ /** Returns true if this cuboid is completely inside the specifie cuboid (in all 6 coords).
+ Assumes both cuboids are sorted. */
bool IsCompletelyInside(const cCuboid & a_Outer) const;
/** Moves the cuboid by the specified offsets in each direction */
@@ -72,7 +74,7 @@ public:
/** Expands the cuboid by the specified amount in each direction.
Works on unsorted cuboids as well.
- Note that this function doesn't check for underflows. */
+ Note that this function doesn't check for underflows when using negative amounts. */
void Expand(int a_SubMinX, int a_AddMaxX, int a_SubMinY, int a_AddMaxY, int a_SubMinZ, int a_AddMaxZ);
/** Clamps both X coords to the specified range. Works on unsorted cuboids, too. */
--
cgit v1.2.3
From 0e985293b50ec89a163f40222825b3c147135b9a Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Sun, 9 Mar 2014 22:04:29 +0100
Subject: A working POCPiece generator.
---
src/Generating/ComposableGenerator.cpp | 5 +
src/Generating/POCPieceGenerator.cpp | 265 +++++++++++++++++++++++++++++++++
src/Generating/POCPieceGenerator.h | 54 +++++++
src/Generating/PieceGenerator.cpp | 31 +++-
src/Generating/PieceGenerator.h | 10 +-
5 files changed, 359 insertions(+), 6 deletions(-)
create mode 100644 src/Generating/POCPieceGenerator.cpp
create mode 100644 src/Generating/POCPieceGenerator.h
diff --git a/src/Generating/ComposableGenerator.cpp b/src/Generating/ComposableGenerator.cpp
index e96e9a645..6c00b5905 100644
--- a/src/Generating/ComposableGenerator.cpp
+++ b/src/Generating/ComposableGenerator.cpp
@@ -22,6 +22,7 @@
#include "EndGen.h"
#include "MineShafts.h"
#include "Noise3DGenerator.h"
+#include "POCPieceGenerator.h"
#include "Ravines.h"
@@ -364,6 +365,10 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile)
{
m_FinishGens.push_back(new cStructGenOreNests(Seed));
}
+ else if (NoCaseCompare(*itr, "POCPieces") == 0)
+ {
+ m_FinishGens.push_back(new cPOCPieceGenerator(Seed));
+ }
else if (NoCaseCompare(*itr, "PreSimulator") == 0)
{
m_FinishGens.push_back(new cFinishGenPreSimulator);
diff --git a/src/Generating/POCPieceGenerator.cpp b/src/Generating/POCPieceGenerator.cpp
new file mode 100644
index 000000000..9edfcc64f
--- /dev/null
+++ b/src/Generating/POCPieceGenerator.cpp
@@ -0,0 +1,265 @@
+
+// POCPieceGenerator.cpp
+
+// Implements the cPOCPieceGenerator class representing a Proof-Of_Concept structure generator using the cPieceGenerator technique
+// The generator generates a maze of rooms at {0, 100, 0}
+
+#include "Globals.h"
+#include "POCPieceGenerator.h"
+#include "ChunkDesc.h"
+
+
+
+
+
+/** POC pieces are simple boxes that have connectors in the middle of their walls.
+Each wall has one connector, there are 3 connector types that get assigned semi-randomly.
+The piece also knows how to imprint itself in a cChunkDesc, each piece has a different color glass
+and each connector is uses a different color wool frame. */
+class cPOCPiece :
+ public cPiece
+{
+public:
+ cPOCPiece(int a_Size) :
+ m_Size(a_Size)
+ {
+ m_Connectors.push_back(cConnector(m_Size / 2, 1, 0, 0, BLOCK_FACE_ZM));
+ m_Connectors.push_back(cConnector(m_Size / 2, 1, m_Size - 1, 1, BLOCK_FACE_ZP));
+ m_Connectors.push_back(cConnector(0, 1, m_Size / 2, 2, BLOCK_FACE_XM));
+ m_Connectors.push_back(cConnector(m_Size - 1, 1, m_Size / 2, m_Size % 3, BLOCK_FACE_XP));
+ }
+
+
+ /** Imprints the piece in the specified chunk. Assumes they intersect. */
+ void ImprintInChunk(cChunkDesc & a_ChunkDesc, const Vector3i & a_Pos, int a_NumCCWRotations)
+ {
+ int BlockX = a_ChunkDesc.GetChunkX() * cChunkDef::Width;
+ int BlockZ = a_ChunkDesc.GetChunkZ() * cChunkDef::Width;
+ Vector3i Min = a_Pos;
+ Min.Move(-BlockX, 0, -BlockZ);
+ Vector3i Max = Min;
+ Max.Move(m_Size - 1, 2, m_Size - 1);
+ ASSERT(Min.x < cChunkDef::Width);
+ ASSERT(Min.z < cChunkDef::Width);
+ ASSERT(Max.x >= 0);
+ ASSERT(Max.z >= 0);
+ if (Min.x >= 0)
+ {
+ // Draw the XM wall:
+ a_ChunkDesc.FillRelCuboid(Min.x, Min.x, Min.y, Max.y, Min.z, Max.z, E_BLOCK_STAINED_GLASS, m_Size % 16);
+ }
+ if (Min.z >= 0)
+ {
+ // Draw the ZM wall:
+ a_ChunkDesc.FillRelCuboid(Min.x, Max.x, Min.y, Max.y, Min.z, Min.z, E_BLOCK_STAINED_GLASS, m_Size % 16);
+ }
+ if (Max.x < cChunkDef::Width)
+ {
+ // Draw the XP wall:
+ a_ChunkDesc.FillRelCuboid(Max.x, Max.x, Min.y, Max.y, Min.z, Max.z, E_BLOCK_STAINED_GLASS, m_Size % 16);
+ }
+ if (Max.z < cChunkDef::Width)
+ {
+ // Draw the ZP wall:
+ a_ChunkDesc.FillRelCuboid(Min.x, Max.x, Min.y, Max.y, Max.z, Max.z, E_BLOCK_STAINED_GLASS, m_Size % 16);
+ }
+
+ // Draw all the connectors:
+ for (cConnectors::const_iterator itr = m_Connectors.begin(), end = m_Connectors.end(); itr != end; ++itr)
+ {
+ cConnector Conn = cPiece::RotateMoveConnector(*itr, a_NumCCWRotations, a_Pos.x, a_Pos.y, a_Pos.z);
+ Conn.m_Pos.Move(-BlockX, 0, -BlockZ);
+ if (
+ (Conn.m_Pos.x >= 0) && (Conn.m_Pos.x < cChunkDef::Width) &&
+ (Conn.m_Pos.z >= 0) && (Conn.m_Pos.z < cChunkDef::Width)
+ )
+ {
+ a_ChunkDesc.SetBlockTypeMeta(Conn.m_Pos.x, Conn.m_Pos.y, Conn.m_Pos.z, E_BLOCK_WOOL, itr->m_Type % 16);
+ }
+
+ /*
+ // TODO: Frame the connectors
+ switch (itr->m_Direction)
+ {
+ case BLOCK_FACE_XM:
+ case BLOCK_FACE_XP:
+ {
+ // TODO
+ break;
+ }
+
+ case BLOCK_FACE_ZM:
+ case BLOCK_FACE_ZP:
+ {
+ // TODO
+ break;
+ }
+ }
+ */
+ } // for itr - m_Connectors[]
+ }
+
+protected:
+ int m_Size;
+ cConnectors m_Connectors;
+
+ // cPiece overrides:
+ virtual cConnectors GetConnectors(void) const override
+ {
+ return m_Connectors;
+ }
+
+ virtual Vector3i GetSize(void) const override
+ {
+ return Vector3i(m_Size, 3, m_Size);
+ }
+
+ virtual cCuboid GetHitBox(void) const override
+ {
+ return cCuboid(0, 0, 0, m_Size - 1, 2, m_Size - 1);
+ }
+
+ virtual bool CanRotateCCW(int a_NumRotations) const override
+ {
+ return true;
+ }
+};
+
+
+
+
+
+static void DebugPieces(const cPlacedPieces & a_Pieces)
+{
+ size_t idx = 0;
+ for (cPlacedPieces::const_iterator itr = a_Pieces.begin(), end = a_Pieces.end(); itr != end; ++itr, ++idx)
+ {
+ const cCuboid & HitBox = (*itr)->GetHitBox();
+ printf(" %u: %d rotations, {%d - %d, %d - %d}\n",
+ idx, (*itr)->GetNumCCWRotations(),
+ HitBox.p1.x, HitBox.p2.x, HitBox.p1.z, HitBox.p2.z
+ );
+ } // for itr - a_Pieces[]
+}
+
+
+
+
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// cPOCPieceGenerator:
+
+cPOCPieceGenerator::cPOCPieceGenerator(int a_Seed) :
+ m_Seed(a_Seed)
+{
+ // Prepare a vector of available pieces:
+ m_AvailPieces.push_back(new cPOCPiece(5));
+ m_AvailPieces.push_back(new cPOCPiece(7));
+ m_AvailPieces.push_back(new cPOCPiece(9));
+
+ // Generate the structure:
+ cBFSPieceGenerator Gen(*this, a_Seed);
+ Gen.PlacePieces(0, 50, 0, 6, m_Pieces);
+
+ // DebugPieces(m_Pieces);
+
+ // Get the smallest cuboid encompassing the entire generated structure:
+ cCuboid Bounds(0, 50, 0, 0, 50, 0);
+ for (cPlacedPieces::const_iterator itr = m_Pieces.begin(), end = m_Pieces.end(); itr != end; ++itr)
+ {
+ Vector3i MinCoords = (*itr)->GetCoords();
+ Bounds.Engulf(MinCoords);
+ Bounds.Engulf(MinCoords + (*itr)->GetPiece().GetSize());
+ } // for itr - m_Pieces[]
+ m_Bounds = Bounds;
+}
+
+
+
+
+
+cPOCPieceGenerator::~cPOCPieceGenerator()
+{
+ cPieceGenerator::FreePieces(m_Pieces);
+}
+
+
+
+
+
+void cPOCPieceGenerator::GenFinish(cChunkDesc & a_ChunkDesc)
+{
+ int BlockX = a_ChunkDesc.GetChunkX() * cChunkDef::Width;
+ int BlockZ = a_ChunkDesc.GetChunkZ() * cChunkDef::Width;
+ if (
+ (BlockX + 16 < m_Bounds.p1.x) || (BlockX > m_Bounds.p2.x) || // X coords out of bounds of the generated structure
+ (BlockZ + 16 < m_Bounds.p1.z) || (BlockZ > m_Bounds.p2.z) // Z coords out of bounds of the generated structure
+ )
+ {
+ return;
+ }
+
+ // Imprint each piece in the chunk:
+ for (cPlacedPieces::const_iterator itr = m_Pieces.begin(), end = m_Pieces.end(); itr != end; ++itr)
+ {
+ const Vector3i & Pos = (*itr)->GetCoords();
+ Vector3i Size = (*itr)->GetPiece().GetSize();
+ if (((*itr)->GetNumCCWRotations() % 2) == 1)
+ {
+ std::swap(Size.x, Size.z);
+ }
+ if (
+ (Pos.x >= BlockX + 16) || (Pos.x + Size.x - 1 < BlockX) ||
+ (Pos.z >= BlockZ + 16) || (Pos.z + Size.z - 1 < BlockZ)
+ )
+ {
+ // This piece doesn't intersect the chunk
+ continue;
+ }
+
+ ((cPOCPiece &)(*itr)->GetPiece()).ImprintInChunk(a_ChunkDesc, Pos, (*itr)->GetNumCCWRotations());
+ } // for itr - m_Pieces[]
+ a_ChunkDesc.UpdateHeightmap();
+}
+
+
+
+
+
+cPieces cPOCPieceGenerator::GetPiecesWithConnector(int a_ConnectorType)
+{
+ // Each piece has each connector
+ return m_AvailPieces;
+}
+
+
+
+
+
+cPieces cPOCPieceGenerator::GetStartingPieces(void)
+{
+ // Any piece can be a starting piece
+ return m_AvailPieces;
+}
+
+
+
+
+
+void cPOCPieceGenerator::PiecePlaced(const cPiece & a_Piece)
+{
+ UNUSED(a_Piece);
+}
+
+
+
+
+
+void cPOCPieceGenerator::Reset(void)
+{
+ // Nothing needed
+}
+
+
+
+
diff --git a/src/Generating/POCPieceGenerator.h b/src/Generating/POCPieceGenerator.h
new file mode 100644
index 000000000..de3114ce0
--- /dev/null
+++ b/src/Generating/POCPieceGenerator.h
@@ -0,0 +1,54 @@
+
+// POCPieceGenerator.h
+
+// Declares the cPOCPieceGenerator class representing a Proof-Of_Concept structure generator using the cPieceGenerator technique
+// The generator generates a maze of rooms at {0, 100, 0}
+
+
+
+
+
+#pragma once
+
+#include "PieceGenerator.h"
+#include "ComposableGenerator.h"
+
+
+
+
+
+class cPOCPieceGenerator :
+ public cFinishGen,
+ protected cPiecePool
+{
+public:
+ cPOCPieceGenerator(int a_Seed);
+ ~cPOCPieceGenerator();
+
+protected:
+ int m_Seed;
+
+ /** The pieces from which the generated structure is built. */
+ cPieces m_AvailPieces;
+
+ /** The placed pieces of the generated structure. */
+ cPlacedPieces m_Pieces;
+
+ /** Bounds of the complete structure, to save on processing outside chunks. */
+ cCuboid m_Bounds;
+
+
+ // cFinishGen overrides:
+ virtual void GenFinish(cChunkDesc & a_ChunkDesc) override;
+
+ // cPiecePool overrides:
+ virtual cPieces GetPiecesWithConnector(int a_ConnectorType) override;
+ virtual cPieces GetStartingPieces(void) override;
+ virtual void PiecePlaced(const cPiece & a_Piece) override;
+ virtual void Reset(void) override;
+} ;
+
+
+
+
+
diff --git a/src/Generating/PieceGenerator.cpp b/src/Generating/PieceGenerator.cpp
index c8e4ec71b..e3de5b951 100644
--- a/src/Generating/PieceGenerator.cpp
+++ b/src/Generating/PieceGenerator.cpp
@@ -11,6 +11,8 @@
+#ifdef SELF_TEST
+
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Self-test:
@@ -132,6 +134,8 @@ protected:
}
} g_Test;
+#endif // SELF_TEST
+
@@ -287,6 +291,7 @@ cPlacedPiece::cPlacedPiece(const cPlacedPiece * a_Parent, const cPiece & a_Piece
{
m_Depth = (m_Parent == NULL) ? 0 : (m_Parent->GetDepth() + 1);
m_HitBox = a_Piece.RotateMoveHitBox(a_NumCCWRotations, a_Coords.x, a_Coords.y, a_Coords.z);
+ m_HitBox.Sort();
}
@@ -375,10 +380,10 @@ bool cPieceGenerator::TryPlacePieceAtConnector(
/* YM, YP, ZM, ZP, XM, XP
/* YM */ { 0, 0, 0, 0, 0, 0},
/* YP */ { 0, 0, 0, 0, 0, 0},
- /* ZM */ { 0, 0, 0, 2, 1, 3},
- /* ZP */ { 0, 0, 2, 0, 3, 1},
- /* XM */ { 0, 0, 3, 1, 0, 2},
- /* XP */ { 0, 0, 1, 3, 2, 0},
+ /* ZM */ { 0, 0, 2, 0, 1, 3},
+ /* ZP */ { 0, 0, 0, 2, 3, 1},
+ /* XM */ { 0, 0, 3, 1, 2, 0},
+ /* XP */ { 0, 0, 1, 3, 0, 2},
};
// Get a list of available connections:
@@ -389,8 +394,10 @@ bool cPieceGenerator::TryPlacePieceAtConnector(
Vector3i ConnPos = a_Connector.m_Pos; // The position at which the new connector should be placed - 1 block away from the connector
AddFaceDirection(ConnPos.x, ConnPos.y, ConnPos.z, a_Connector.m_Direction);
+ /*
// DEBUG:
- printf("Placing piece at pos {%d, %d, %d}, direction %s\n", ConnPos.x, ConnPos.y, ConnPos.z, BlockFaceToString(a_Connector.m_Direction).c_str());
+ printf("Placing piece at connector pos {%d, %d, %d}, direction %s\n", ConnPos.x, ConnPos.y, ConnPos.z, BlockFaceToString(a_Connector.m_Direction).c_str());
+ //*/
for (cPieces::iterator itrP = AvailablePieces.begin(), endP = AvailablePieces.end(); itrP != endP; ++itrP)
{
@@ -427,11 +434,15 @@ bool cPieceGenerator::TryPlacePieceAtConnector(
cConnection & Conn = Connections[rnd % Connections.size()];
// Place the piece:
+ /*
+ // DEBUG
printf("Chosen connector at {%d, %d, %d}, direction %s, needs %d rotations\n",
Conn.m_Connector.m_Pos.x, Conn.m_Connector.m_Pos.y, Conn.m_Connector.m_Pos.z,
BlockFaceToString(Conn.m_Connector.m_Direction).c_str(),
Conn.m_NumCCWRotations
);
+ //*/
+
Vector3i NewPos = Conn.m_Piece->RotatePos(Conn.m_Connector.m_Pos, Conn.m_NumCCWRotations);
ConnPos -= NewPos;
cPlacedPiece * PlacedPiece = new cPlacedPiece(&a_ParentPiece, *(Conn.m_Piece), ConnPos, Conn.m_NumCCWRotations);
@@ -440,8 +451,10 @@ bool cPieceGenerator::TryPlacePieceAtConnector(
// Add the new piece's connectors to the list of free connectors:
cPiece::cConnectors Connectors = Conn.m_Piece->GetConnectors();
+ /*
// DEBUG:
printf("Adding %u connectors to the pool\n", Connectors.size() - 1);
+ //*/
for (cPiece::cConnectors::const_iterator itr = Connectors.begin(), end = Connectors.end(); itr != end; ++itr)
{
@@ -471,6 +484,7 @@ bool cPieceGenerator::CheckConnection(
{
// For each placed piece, test the hitbox against the new piece:
cCuboid RotatedHitBox = a_Piece.RotateHitBoxToConnector(a_NewConnector, a_ToPos, a_NumCCWRotations);
+ RotatedHitBox.Sort();
for (cPlacedPieces::const_iterator itr = a_OutPieces.begin(), end = a_OutPieces.end(); itr != end; ++itr)
{
if ((*itr)->GetHitBox().DoesIntersect(RotatedHitBox))
@@ -485,6 +499,7 @@ bool cPieceGenerator::CheckConnection(
+//*
// DEBUG:
void cPieceGenerator::DebugConnectorPool(const cPieceGenerator::cFreeConnectors & a_ConnectorPool, size_t a_NumProcessed)
{
@@ -501,6 +516,7 @@ void cPieceGenerator::DebugConnectorPool(const cPieceGenerator::cFreeConnectors
);
} // for itr - a_ConnectorPool[]
}
+//*/
@@ -553,6 +569,7 @@ void cBFSPieceGenerator::PlacePieces(int a_BlockX, int a_BlockY, int a_BlockZ, i
// Place the starting piece:
a_OutPieces.push_back(PlaceStartingPiece(a_BlockX, a_BlockY, a_BlockZ, ConnectorPool));
+ /*
// DEBUG:
printf("Placed the starting piece at {%d, %d, %d}\n", a_BlockX, a_BlockY, a_BlockZ);
cCuboid Hitbox = a_OutPieces[0]->GetHitBox();
@@ -563,6 +580,7 @@ void cBFSPieceGenerator::PlacePieces(int a_BlockX, int a_BlockY, int a_BlockZ, i
Hitbox.DifX() + 1, Hitbox.DifY() + 1, Hitbox.DifZ() + 1
);
DebugConnectorPool(ConnectorPool, 0);
+ //*/
// Place pieces at the available connectors:
/*
@@ -578,6 +596,8 @@ void cBFSPieceGenerator::PlacePieces(int a_BlockX, int a_BlockY, int a_BlockZ, i
{
if (TryPlacePieceAtConnector(*Conn.m_Piece, Conn.m_Connector, a_OutPieces, ConnectorPool))
{
+ /*
+ // DEBUG:
const cPlacedPiece * NewPiece = a_OutPieces.back();
const Vector3i & Coords = NewPiece->GetCoords();
printf("Placed a new piece at {%d, %d, %d}, rotation %d\n", Coords.x, Coords.y, Coords.z, NewPiece->GetNumCCWRotations());
@@ -589,6 +609,7 @@ void cBFSPieceGenerator::PlacePieces(int a_BlockX, int a_BlockY, int a_BlockZ, i
Hitbox.DifX() + 1, Hitbox.DifY() + 1, Hitbox.DifZ() + 1
);
DebugConnectorPool(ConnectorPool, NumProcessed + 1);
+ //*/
}
}
NumProcessed++;
diff --git a/src/Generating/PieceGenerator.h b/src/Generating/PieceGenerator.h
index 310c21fdd..9dd5bcfba 100644
--- a/src/Generating/PieceGenerator.h
+++ b/src/Generating/PieceGenerator.h
@@ -30,6 +30,9 @@ Each uses a slightly different approach to generating:
class cPiece
{
public:
+ // Force a virtual destructor in all descendants
+ virtual ~cPiece() {}
+
struct cConnector
{
/** Position relative to the piece */
@@ -82,9 +85,14 @@ typedef std::vector cPieces;
+/** This class is an interface that provides pieces for the generator. It can keep track of what pieces were
+placed and adjust the returned piece vectors. */
class cPiecePool
{
public:
+ // Force a virtual destructor in all descendants:
+ virtual ~cPiecePool() {}
+
/** Returns a list of pieces that contain the specified connector type.
The cPiece pointers returned are managed by the pool and the caller doesn't free them. */
virtual cPieces GetPiecesWithConnector(int a_ConnectorType) = 0;
@@ -140,7 +148,7 @@ public:
/** Cleans up all the memory used by the placed pieces.
Call this utility function instead of freeing the items on your own. */
- void FreePieces(cPlacedPieces & a_PlacedPieces);
+ static void FreePieces(cPlacedPieces & a_PlacedPieces);
protected:
/** The type used for storing a connection from one piece to another, while building the piece tree. */
--
cgit v1.2.3
From 0f412a0a022b75823561c2f78e5f0c9469b0d1b4 Mon Sep 17 00:00:00 2001
From: Tiger Wang
Date: Sun, 9 Mar 2014 21:48:18 +0000
Subject: Removed uneeded meta obtain
---
src/Simulator/FireSimulator.cpp | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/src/Simulator/FireSimulator.cpp b/src/Simulator/FireSimulator.cpp
index 6079ea740..31cc0b670 100644
--- a/src/Simulator/FireSimulator.cpp
+++ b/src/Simulator/FireSimulator.cpp
@@ -1,4 +1,3 @@
-
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "FireSimulator.h"
@@ -334,7 +333,6 @@ void cFireSimulator::RemoveFuelNeighbors(cChunk * a_Chunk, int a_RelX, int a_Rel
for (size_t i = 0; i < ARRAYCOUNT(gNeighborCoords); i++)
{
BLOCKTYPE BlockType;
- NIBBLETYPE BlockMeta;
int X = a_RelX + gNeighborCoords[i].x;
int Z = a_RelZ + gNeighborCoords[i].z;
@@ -343,7 +341,7 @@ void cFireSimulator::RemoveFuelNeighbors(cChunk * a_Chunk, int a_RelX, int a_Rel
{
continue;
}
- Neighbour->GetBlockTypeMeta(X, a_RelY + gCrossCoords[i].y, Z, BlockType, BlockMeta);
+ BlockType = Neighbour->GetBlockTypeMeta(X, a_RelY + gCrossCoords[i].y, Z);
if (!IsFuel(BlockType))
{
--
cgit v1.2.3
From 0b9763fc5a84ac171338484f653fdae2a2bc999a Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Mon, 10 Mar 2014 07:55:47 +0100
Subject: Fixed MSVC2008 compilation.
---
src/WorldStorage/FireworksSerializer.cpp | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/WorldStorage/FireworksSerializer.cpp b/src/WorldStorage/FireworksSerializer.cpp
index 0e0094e76..1f05b470d 100644
--- a/src/WorldStorage/FireworksSerializer.cpp
+++ b/src/WorldStorage/FireworksSerializer.cpp
@@ -20,8 +20,8 @@ void cFireworkItem::WriteToNBTCompound(const cFireworkItem & a_FireworkItem, cFa
a_Writer.AddByte("Flicker", a_FireworkItem.m_HasFlicker);
a_Writer.AddByte("Trail", a_FireworkItem.m_HasTrail);
a_Writer.AddByte("Type", a_FireworkItem.m_Type);
- a_Writer.AddIntArray("Colors", a_FireworkItem.m_Colours.data(), a_FireworkItem.m_Colours.size());
- a_Writer.AddIntArray("FadeColors", a_FireworkItem.m_FadeColours.data(), a_FireworkItem.m_FadeColours.size());
+ a_Writer.AddIntArray("Colors", &(a_FireworkItem.m_Colours[0]), a_FireworkItem.m_Colours.size());
+ a_Writer.AddIntArray("FadeColors", &(a_FireworkItem.m_FadeColours[0]), a_FireworkItem.m_FadeColours.size());
a_Writer.EndCompound();
a_Writer.EndList();
a_Writer.EndCompound();
@@ -35,11 +35,11 @@ void cFireworkItem::WriteToNBTCompound(const cFireworkItem & a_FireworkItem, cFa
a_Writer.AddByte("Type", a_FireworkItem.m_Type);
if (!a_FireworkItem.m_Colours.empty())
{
- a_Writer.AddIntArray("Colors", a_FireworkItem.m_Colours.data(), a_FireworkItem.m_Colours.size());
+ a_Writer.AddIntArray("Colors", &(a_FireworkItem.m_Colours[0]), a_FireworkItem.m_Colours.size());
}
if (!a_FireworkItem.m_FadeColours.empty())
{
- a_Writer.AddIntArray("FadeColors", a_FireworkItem.m_FadeColours.data(), a_FireworkItem.m_FadeColours.size());
+ a_Writer.AddIntArray("FadeColors", &(a_FireworkItem.m_FadeColours[0]), a_FireworkItem.m_FadeColours.size());
}
a_Writer.EndCompound();
break;
--
cgit v1.2.3
From 6c4807556141f49a3fa5ff63474e6b95e5fd5cbf Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Mon, 10 Mar 2014 08:38:40 +0100
Subject: POCPieces: Added height.
Now the pieces connect in different heights, too, creating a true 3D maze.
---
src/Generating/POCPieceGenerator.cpp | 37 +++++++++++++++++++-----------------
1 file changed, 20 insertions(+), 17 deletions(-)
diff --git a/src/Generating/POCPieceGenerator.cpp b/src/Generating/POCPieceGenerator.cpp
index 9edfcc64f..d7619b8ff 100644
--- a/src/Generating/POCPieceGenerator.cpp
+++ b/src/Generating/POCPieceGenerator.cpp
@@ -20,13 +20,14 @@ class cPOCPiece :
public cPiece
{
public:
- cPOCPiece(int a_Size) :
- m_Size(a_Size)
+ cPOCPiece(int a_SizeXZ, int a_Height) :
+ m_SizeXZ(a_SizeXZ),
+ m_Height(a_Height)
{
- m_Connectors.push_back(cConnector(m_Size / 2, 1, 0, 0, BLOCK_FACE_ZM));
- m_Connectors.push_back(cConnector(m_Size / 2, 1, m_Size - 1, 1, BLOCK_FACE_ZP));
- m_Connectors.push_back(cConnector(0, 1, m_Size / 2, 2, BLOCK_FACE_XM));
- m_Connectors.push_back(cConnector(m_Size - 1, 1, m_Size / 2, m_Size % 3, BLOCK_FACE_XP));
+ m_Connectors.push_back(cConnector(m_SizeXZ / 2, a_Height / 2, 0, 0, BLOCK_FACE_ZM));
+ m_Connectors.push_back(cConnector(m_SizeXZ / 2, a_Height / 2, m_SizeXZ - 1, 1, BLOCK_FACE_ZP));
+ m_Connectors.push_back(cConnector(0, a_Height / 2, m_SizeXZ / 2, 2, BLOCK_FACE_XM));
+ m_Connectors.push_back(cConnector(m_SizeXZ - 1, a_Height - 1, m_SizeXZ / 2, m_SizeXZ % 3, BLOCK_FACE_XP));
}
@@ -38,7 +39,7 @@ public:
Vector3i Min = a_Pos;
Min.Move(-BlockX, 0, -BlockZ);
Vector3i Max = Min;
- Max.Move(m_Size - 1, 2, m_Size - 1);
+ Max.Move(m_SizeXZ - 1, m_Height - 1, m_SizeXZ - 1);
ASSERT(Min.x < cChunkDef::Width);
ASSERT(Min.z < cChunkDef::Width);
ASSERT(Max.x >= 0);
@@ -46,22 +47,22 @@ public:
if (Min.x >= 0)
{
// Draw the XM wall:
- a_ChunkDesc.FillRelCuboid(Min.x, Min.x, Min.y, Max.y, Min.z, Max.z, E_BLOCK_STAINED_GLASS, m_Size % 16);
+ a_ChunkDesc.FillRelCuboid(Min.x, Min.x, Min.y, Max.y, Min.z, Max.z, E_BLOCK_STAINED_GLASS, m_SizeXZ % 16);
}
if (Min.z >= 0)
{
// Draw the ZM wall:
- a_ChunkDesc.FillRelCuboid(Min.x, Max.x, Min.y, Max.y, Min.z, Min.z, E_BLOCK_STAINED_GLASS, m_Size % 16);
+ a_ChunkDesc.FillRelCuboid(Min.x, Max.x, Min.y, Max.y, Min.z, Min.z, E_BLOCK_STAINED_GLASS, m_SizeXZ % 16);
}
if (Max.x < cChunkDef::Width)
{
// Draw the XP wall:
- a_ChunkDesc.FillRelCuboid(Max.x, Max.x, Min.y, Max.y, Min.z, Max.z, E_BLOCK_STAINED_GLASS, m_Size % 16);
+ a_ChunkDesc.FillRelCuboid(Max.x, Max.x, Min.y, Max.y, Min.z, Max.z, E_BLOCK_STAINED_GLASS, m_SizeXZ % 16);
}
if (Max.z < cChunkDef::Width)
{
// Draw the ZP wall:
- a_ChunkDesc.FillRelCuboid(Min.x, Max.x, Min.y, Max.y, Max.z, Max.z, E_BLOCK_STAINED_GLASS, m_Size % 16);
+ a_ChunkDesc.FillRelCuboid(Min.x, Max.x, Min.y, Max.y, Max.z, Max.z, E_BLOCK_STAINED_GLASS, m_SizeXZ % 16);
}
// Draw all the connectors:
@@ -100,7 +101,8 @@ public:
}
protected:
- int m_Size;
+ int m_SizeXZ;
+ int m_Height;
cConnectors m_Connectors;
// cPiece overrides:
@@ -111,12 +113,12 @@ protected:
virtual Vector3i GetSize(void) const override
{
- return Vector3i(m_Size, 3, m_Size);
+ return Vector3i(m_SizeXZ, m_Height, m_SizeXZ);
}
virtual cCuboid GetHitBox(void) const override
{
- return cCuboid(0, 0, 0, m_Size - 1, 2, m_Size - 1);
+ return cCuboid(0, 0, 0, m_SizeXZ - 1, m_Height - 1, m_SizeXZ - 1);
}
virtual bool CanRotateCCW(int a_NumRotations) const override
@@ -153,9 +155,10 @@ cPOCPieceGenerator::cPOCPieceGenerator(int a_Seed) :
m_Seed(a_Seed)
{
// Prepare a vector of available pieces:
- m_AvailPieces.push_back(new cPOCPiece(5));
- m_AvailPieces.push_back(new cPOCPiece(7));
- m_AvailPieces.push_back(new cPOCPiece(9));
+ m_AvailPieces.push_back(new cPOCPiece(5, 3));
+ m_AvailPieces.push_back(new cPOCPiece(7, 5));
+ m_AvailPieces.push_back(new cPOCPiece(9, 5));
+ m_AvailPieces.push_back(new cPOCPiece(5, 7));
// Generate the structure:
cBFSPieceGenerator Gen(*this, a_Seed);
--
cgit v1.2.3
From 0cce0478d846114f49c4b8fe201aee7a1bb06b22 Mon Sep 17 00:00:00 2001
From: STRWarrior
Date: Mon, 10 Mar 2014 17:07:46 +0100
Subject: This allows a blockarea to have an Offset.
---
src/BlockArea.cpp | 19 +++++++++++++++++++
src/BlockArea.h | 5 +++++
src/WorldStorage/SchematicFileSerializer.cpp | 23 +++++++++++++++++++++++
3 files changed, 47 insertions(+)
diff --git a/src/BlockArea.cpp b/src/BlockArea.cpp
index d07ef747a..986b2ee25 100644
--- a/src/BlockArea.cpp
+++ b/src/BlockArea.cpp
@@ -168,6 +168,7 @@ cBlockArea::cBlockArea(void) :
m_SizeX(0),
m_SizeY(0),
m_SizeZ(0),
+ m_Offset(0,0,0),
m_BlockTypes(NULL),
m_BlockMetas(NULL),
m_BlockLight(NULL),
@@ -254,6 +255,24 @@ void cBlockArea::Create(int a_SizeX, int a_SizeY, int a_SizeZ, int a_DataTypes)
+void cBlockArea::SetOffset(int a_OffsetX, int a_OffsetY, int a_OffsetZ)
+{
+ m_Offset.Set(a_OffsetX, a_OffsetY, a_OffsetZ);
+}
+
+
+
+
+
+void cBlockArea::SetOffset(Vector3i a_Offset)
+{
+ m_Offset.Set(a_Offset.x, a_Offset.y, a_Offset.z);
+}
+
+
+
+
+
void cBlockArea::SetOrigin(int a_OriginX, int a_OriginY, int a_OriginZ)
{
m_OriginX = a_OriginX;
diff --git a/src/BlockArea.h b/src/BlockArea.h
index 0703f195e..d89c9b372 100644
--- a/src/BlockArea.h
+++ b/src/BlockArea.h
@@ -209,6 +209,8 @@ public:
void SetBlockLight (int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_BlockLight);
void SetRelBlockSkyLight(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_BlockSkyLight);
void SetBlockSkyLight (int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_BlockSkyLight);
+ void SetOffset (int a_OffsetX, int a_OffsetY, int a_OffsetZ);
+ void SetOffset (Vector3i a_Offset);
// Getters:
BLOCKTYPE GetRelBlockType (int a_RelX, int a_RelY, int a_RelZ) const;
@@ -219,6 +221,7 @@ public:
NIBBLETYPE GetBlockLight (int a_BlockX, int a_BlockY, int a_BlockZ) const;
NIBBLETYPE GetRelBlockSkyLight(int a_RelX, int a_RelY, int a_RelZ) const;
NIBBLETYPE GetBlockSkyLight (int a_BlockX, int a_BlockY, int a_BlockZ) const;
+ Vector3i GetOffset (void) const {return m_Offset;}
void SetBlockTypeMeta (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta);
void SetRelBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta);
@@ -299,6 +302,8 @@ protected:
int m_SizeY;
int m_SizeZ;
+ Vector3i m_Offset;
+
BLOCKTYPE * m_BlockTypes;
NIBBLETYPE * m_BlockMetas; // Each meta is stored as a separate byte for faster access
NIBBLETYPE * m_BlockLight; // Each light value is stored as a separate byte for faster access
diff --git a/src/WorldStorage/SchematicFileSerializer.cpp b/src/WorldStorage/SchematicFileSerializer.cpp
index b021aeb0c..0aea931eb 100644
--- a/src/WorldStorage/SchematicFileSerializer.cpp
+++ b/src/WorldStorage/SchematicFileSerializer.cpp
@@ -177,6 +177,25 @@ bool cSchematicFileSerializer::LoadFromSchematicNBT(cBlockArea & a_BlockArea, cP
a_BlockArea.Clear();
a_BlockArea.SetSize(SizeX, SizeY, SizeZ, AreMetasPresent ? (cBlockArea::baTypes | cBlockArea::baMetas) : cBlockArea::baTypes);
+ int TOffsetX = a_NBT.FindChildByName(a_NBT.GetRoot(), "WEOffsetX");
+ int TOffsetY = a_NBT.FindChildByName(a_NBT.GetRoot(), "WEOffsetY");
+ int TOffsetZ = a_NBT.FindChildByName(a_NBT.GetRoot(), "WEOffsetZ");
+
+ if (
+ (TOffsetX < 0) || (TOffsetY < 0) || (TOffsetZ < 0) ||
+ (a_NBT.GetType(TOffsetX) != TAG_Int) ||
+ (a_NBT.GetType(TOffsetY) != TAG_Int) ||
+ (a_NBT.GetType(TOffsetZ) != TAG_Int)
+ )
+ {
+ // Not every schematic file has an offset, so we shoudn't give a warn message.
+ a_BlockArea.SetOffset(0, 0, 0);
+ }
+ else
+ {
+ a_BlockArea.SetOffset(a_NBT.GetInt(TOffsetX), a_NBT.GetInt(TOffsetY), a_NBT.GetInt(TOffsetZ));
+ }
+
// Copy the block types and metas:
int NumBytes = a_BlockArea.m_SizeX * a_BlockArea.m_SizeY * a_BlockArea.m_SizeZ;
if (a_NBT.GetDataLength(TBlockTypes) < NumBytes)
@@ -234,6 +253,10 @@ AString cSchematicFileSerializer::SaveToSchematicNBT(const cBlockArea & a_BlockA
Writer.AddByteArray("Data", Dummy.data(), Dummy.size());
}
+ Writer.AddInt("WEOffsetX", a_BlockArea.m_Offset.x);
+ Writer.AddInt("WEOffsetY", a_BlockArea.m_Offset.y);
+ Writer.AddInt("WEOffsetZ", a_BlockArea.m_Offset.z);
+
// TODO: Save entities and block entities
Writer.BeginList("Entities", TAG_Compound);
Writer.EndList();
--
cgit v1.2.3
From 30353cd2285d8d2e9ec38c1015c7d45dbdb82b39 Mon Sep 17 00:00:00 2001
From: Tycho
Date: Mon, 10 Mar 2014 10:24:44 -0700
Subject: Fixed MTRand warnings
---
src/MersenneTwister.h | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/MersenneTwister.h b/src/MersenneTwister.h
index 2c5440f17..759b8a1ae 100644
--- a/src/MersenneTwister.h
+++ b/src/MersenneTwister.h
@@ -72,7 +72,7 @@ protected:
uint32 state[N]; // internal state
uint32 *pNext; // next value to get from state
- int left; // number of values left before reload needed
+ uint32 left; // number of values left before reload needed
// Methods
public:
@@ -164,7 +164,7 @@ inline void MTRand::initialize( const uint32 seed )
// only MSBs of the state array. Modified 9 Jan 2002 by Makoto Matsumoto.
uint32 *s = state;
uint32 *r = state;
- int i = 1;
+ uint32 i = 1;
*s++ = seed & 0xffffffffUL;
for( ; i < N; ++i )
{
@@ -205,9 +205,9 @@ inline void MTRand::seed( uint32 *const bigSeed, const uint32 seedLength )
// in each element are discarded.
// Just call seed() if you want to get array from /dev/urandom
initialize(19650218UL);
- int i = 1;
+ uint32 i = 1;
uint32 j = 0;
- int k = ( (uint32)N > seedLength ? (uint32)N : seedLength );
+ uint32 k = ( (uint32)N > seedLength ? (uint32)N : seedLength );
for( ; k; --k )
{
state[i] =
--
cgit v1.2.3
From 8665233522da3454a77c4c40ace03d3a61150023 Mon Sep 17 00:00:00 2001
From: Tycho
Date: Mon, 10 Mar 2014 10:32:51 -0700
Subject: Fixed cast between types of different alignment in cSocket
---
src/OSSupport/Socket.cpp | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/OSSupport/Socket.cpp b/src/OSSupport/Socket.cpp
index 6afaceedf..c29e495c3 100644
--- a/src/OSSupport/Socket.cpp
+++ b/src/OSSupport/Socket.cpp
@@ -307,7 +307,8 @@ bool cSocket::ConnectIPv4(const AString & a_HostNameOrAddr, unsigned short a_Por
CloseSocket();
return false;
}
- addr = *((unsigned long*)hp->h_addr);
+ // Should be optimised to a single word copy
+ memcpy(&addr, hp->h_addr, hp->h_length);
}
sockaddr_in server;
--
cgit v1.2.3
From e2e7f2184f09562753be1a474c2d7e8273b1e83b Mon Sep 17 00:00:00 2001
From: Tycho
Date: Mon, 10 Mar 2014 10:38:21 -0700
Subject: Fixed cast to type with different alignment in BlockingTCPLink
---
src/OSSupport/BlockingTCPLink.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/OSSupport/BlockingTCPLink.cpp b/src/OSSupport/BlockingTCPLink.cpp
index e9c00d6d4..07f48b955 100644
--- a/src/OSSupport/BlockingTCPLink.cpp
+++ b/src/OSSupport/BlockingTCPLink.cpp
@@ -70,7 +70,7 @@ bool cBlockingTCPLink::Connect(const char * iAddress, unsigned int iPort)
}
}
- server.sin_addr.s_addr = *((unsigned long *)hp->h_addr);
+ memcpy(&server.sin_addr.s_addr,hp->h_addr, hp->h_length);
server.sin_family = AF_INET;
server.sin_port = htons( (unsigned short)iPort);
if (connect(m_Socket, (struct sockaddr *)&server, sizeof(server)))
--
cgit v1.2.3
From 7c974b27b1c334da3cd83769398fa9104a2e3253 Mon Sep 17 00:00:00 2001
From: Tycho
Date: Mon, 10 Mar 2014 10:42:52 -0700
Subject: Removed unused macro
---
src/Protocol/Protocol125.cpp | 13 -------------
1 file changed, 13 deletions(-)
diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp
index 50ebb6d43..69f4934d8 100644
--- a/src/Protocol/Protocol125.cpp
+++ b/src/Protocol/Protocol125.cpp
@@ -1269,19 +1269,6 @@ int cProtocol125::ParsePacket(unsigned char a_PacketType)
-#define HANDLE_PACKET_PARSE(Packet) \
- { \
- int res = Packet.Parse(m_ReceivedData); \
- if (res < 0) \
- { \
- return res; \
- } \
- }
-
-
-
-
-
int cProtocol125::ParseArmAnim(void)
{
HANDLE_PACKET_READ(ReadBEInt, int, EntityID);
--
cgit v1.2.3
From 8864e7d8ca63c972793234d3c65aa534fdec06ad Mon Sep 17 00:00:00 2001
From: Tycho
Date: Mon, 10 Mar 2014 11:13:07 -0700
Subject: Fixed alignment issues in Fireworks Serializer
---
src/WorldStorage/FireworksSerializer.cpp | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/src/WorldStorage/FireworksSerializer.cpp b/src/WorldStorage/FireworksSerializer.cpp
index 1f05b470d..bdd5952ad 100644
--- a/src/WorldStorage/FireworksSerializer.cpp
+++ b/src/WorldStorage/FireworksSerializer.cpp
@@ -90,16 +90,16 @@ void cFireworkItem::ParseFromNBT(cFireworkItem & a_FireworkItem, const cParsedNB
if (ExplosionName == "Colors")
{
// Divide by four as data length returned in bytes
- int DataLength = a_NBT.GetDataLength(explosiontag) / 4;
+ int DataLength = a_NBT.GetDataLength(explosiontag);
if (DataLength == 0)
{
continue;
}
- const int * ColourData = (const int *)(a_NBT.GetData(explosiontag));
- for (int i = 0; i < DataLength; i++)
+ const char * ColourData = (a_NBT.GetData(explosiontag));
+ for (int i = 0; i < DataLength; i += 4 /* Size of network int*/)
{
- a_FireworkItem.m_Colours.push_back(ntohl(ColourData[i]));
+ a_FireworkItem.m_Colours.push_back(GetBEInt(ColourData + i));
}
}
else if (ExplosionName == "FadeColors")
@@ -110,10 +110,10 @@ void cFireworkItem::ParseFromNBT(cFireworkItem & a_FireworkItem, const cParsedNB
continue;
}
- const int * FadeColourData = (const int *)(a_NBT.GetData(explosiontag));
- for (int i = 0; i < DataLength; i++)
+ const char * FadeColourData = (a_NBT.GetData(explosiontag));
+ for (int i = 0; i < DataLength; i += 4 /* Size of network int*/)
{
- a_FireworkItem.m_FadeColours.push_back(ntohl(FadeColourData[i]));
+ a_FireworkItem.m_FadeColours.push_back(GetBEInt(FadeColourData + i));
}
}
}
--
cgit v1.2.3
From cff66315137e90db1292fa01640aae2e2d23b862 Mon Sep 17 00:00:00 2001
From: Tycho
Date: Mon, 10 Mar 2014 11:14:34 -0700
Subject: Removed unused macro from WSSCompact
---
src/WorldStorage/WSSCompact.cpp | 1 -
1 file changed, 1 deletion(-)
diff --git a/src/WorldStorage/WSSCompact.cpp b/src/WorldStorage/WSSCompact.cpp
index 95477838e..1e84fb4ad 100644
--- a/src/WorldStorage/WSSCompact.cpp
+++ b/src/WorldStorage/WSSCompact.cpp
@@ -764,7 +764,6 @@ void cWSSCompact::cPAKFile::UpdateChunk2To3()
// Cannot use cChunk::MakeIndex because it might change again?????????
// For compatibility, use what we know is current
- #define MAKE_2_INDEX( x, y, z ) ( y + (z * 256) + (x * 256 * 16) )
#define MAKE_3_INDEX( x, y, z ) ( x + (z * 16) + (y * 16 * 16) )
unsigned int InChunkOffset = 0;
--
cgit v1.2.3
From b2733fad220243a631f9625cc84a50b70b6f43de Mon Sep 17 00:00:00 2001
From: Tiger Wang
Date: Mon, 10 Mar 2014 18:23:12 +0000
Subject: Fixed compile
---
src/Simulator/FireSimulator.cpp | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/Simulator/FireSimulator.cpp b/src/Simulator/FireSimulator.cpp
index 31cc0b670..26712e6e6 100644
--- a/src/Simulator/FireSimulator.cpp
+++ b/src/Simulator/FireSimulator.cpp
@@ -1,3 +1,4 @@
+
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "FireSimulator.h"
@@ -341,7 +342,7 @@ void cFireSimulator::RemoveFuelNeighbors(cChunk * a_Chunk, int a_RelX, int a_Rel
{
continue;
}
- BlockType = Neighbour->GetBlockTypeMeta(X, a_RelY + gCrossCoords[i].y, Z);
+ BlockType = Neighbour->GetBlock(X, a_RelY + gCrossCoords[i].y, Z);
if (!IsFuel(BlockType))
{
--
cgit v1.2.3
From 8947f802940213d371863710e1c3ac873b2dc4b9 Mon Sep 17 00:00:00 2001
From: Tycho
Date: Mon, 10 Mar 2014 11:24:12 -0700
Subject: Use string.reserve to avoid the need to do inplace byteswap
---
src/WorldStorage/FastNBT.cpp | 16 ++++++----------
1 file changed, 6 insertions(+), 10 deletions(-)
diff --git a/src/WorldStorage/FastNBT.cpp b/src/WorldStorage/FastNBT.cpp
index 8f80c3f75..f1f092e0b 100644
--- a/src/WorldStorage/FastNBT.cpp
+++ b/src/WorldStorage/FastNBT.cpp
@@ -506,22 +506,18 @@ void cFastNBTWriter::AddIntArray(const AString & a_Name, const int * a_Value, si
{
TagCommon(a_Name, TAG_IntArray);
Int32 len = htonl(a_NumElements);
+ size_t cap = m_Result.capacity();
+ size_t size = m_Result.length();
+ if ((cap - size) < (4 + a_NumElements * 4))
+ {
+ m_Result.reserve(size +4 + a_NumElements * 4);
+ }
m_Result.append((const char *)&len, 4);
-#if defined(ANDROID_NDK)
- // Android has alignment issues - cannot byteswap (htonl) an int that is not 32-bit-aligned, which happens in the regular version
for (size_t i = 0; i < a_NumElements; i++)
{
int Element = htonl(a_Value[i]);
m_Result.append((const char *)&Element, 4);
}
-#else
- int * Elements = (int *)(m_Result.data() + m_Result.size());
- m_Result.append(a_NumElements * 4, (char)0);
- for (size_t i = 0; i < a_NumElements; i++)
- {
- Elements[i] = htonl(a_Value[i]);
- }
-#endif
}
--
cgit v1.2.3
From 2eca30aebc9a4f7307c31a75ca23e19fa3f1a4a7 Mon Sep 17 00:00:00 2001
From: Tycho
Date: Mon, 10 Mar 2014 11:34:20 -0700
Subject: Removed Some unnessicary macros
---
src/ClientHandle.cpp | 13 -------------
src/LightingThread.cpp | 6 ------
src/WorldStorage/WSSAnvil.cpp | 4 ++--
3 files changed, 2 insertions(+), 21 deletions(-)
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index 94c9f5f71..df728e83b 100644
--- a/src/ClientHandle.cpp
+++ b/src/ClientHandle.cpp
@@ -36,19 +36,6 @@
-
-
-#define AddPistonDir(x, y, z, dir, amount) switch (dir) { case 0: (y)-=(amount); break; case 1: (y)+=(amount); break;\
- case 2: (z)-=(amount); break; case 3: (z)+=(amount); break;\
- case 4: (x)-=(amount); break; case 5: (x)+=(amount); break; }
-
-
-
-
-
-/** If the number of queued outgoing packets reaches this, the client will be kicked */
-#define MAX_OUTGOING_PACKETS 2000
-
/** Maximum number of explosions to send this tick, server will start dropping if exceeded */
#define MAX_EXPLOSIONS_PER_TICK 20
diff --git a/src/LightingThread.cpp b/src/LightingThread.cpp
index 44dadb8a9..302473d71 100644
--- a/src/LightingThread.cpp
+++ b/src/LightingThread.cpp
@@ -13,12 +13,6 @@
-/// If more than this many chunks are in the queue, a warning is printed to the log
-#define WARN_ON_QUEUE_SIZE 800
-
-
-
-
/// Chunk data callback that takes the chunk data and puts them into cLightingThread's m_BlockTypes[] / m_HeightMap[]:
class cReader :
diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp
index eb159f28d..070738164 100644
--- a/src/WorldStorage/WSSAnvil.cpp
+++ b/src/WorldStorage/WSSAnvil.cpp
@@ -507,10 +507,10 @@ cChunkDef::BiomeMap * cWSSAnvil::LoadBiomeMapFromNBT(cChunkDef::BiomeMap * a_Bio
// The biomes stored don't match in size
return NULL;
}
- const int * BiomeData = (const int *)(a_NBT.GetData(a_TagIdx));
+ const char * BiomeData = (a_NBT.GetData(a_TagIdx));
for (size_t i = 0; i < ARRAYCOUNT(*a_BiomeMap); i++)
{
- (*a_BiomeMap)[i] = (EMCSBiome)(ntohl(BiomeData[i]));
+ (*a_BiomeMap)[i] = (EMCSBiome)(GetBEInt(&BiomeData[i * 4]));
if ((*a_BiomeMap)[i] == 0xff)
{
// Unassigned biomes
--
cgit v1.2.3
From 462829e23d8d3404e58ffc64fd19cf39e9be218f Mon Sep 17 00:00:00 2001
From: Tiger Wang
Date: Mon, 10 Mar 2014 18:35:02 +0000
Subject: Shrapnel now configurable
---
src/ChunkMap.cpp | 2 +-
src/World.cpp | 3 +--
src/World.h | 6 ++++++
3 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp
index b13337b44..e750ad731 100644
--- a/src/ChunkMap.cpp
+++ b/src/ChunkMap.cpp
@@ -1832,7 +1832,7 @@ void cChunkMap::DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_
Handler->ConvertToPickups(Drops, area.GetBlockMeta(bx + x, by + y, bz + z)); // Stone becomes cobblestone, coal ore becomes coal, etc.
m_World->SpawnItemPickups(Drops, bx + x, by + y, bz + z);
}
- else if (m_World->GetTickRandomNumber(100) < 20) // 20% chance of flinging stuff around
+ else if (m_World->IsTNTShrapnelEnabled() && (m_World->GetTickRandomNumber(100) < 20)) // 20% chance of flinging stuff around
{
if (!cBlockInfo::FullyOccupiesVoxel(area.GetBlockType(bx + x, by + y, bz + z)))
{
diff --git a/src/World.cpp b/src/World.cpp
index d6b88f187..89d0cf454 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -250,8 +250,6 @@ cWorld::cWorld(const AString & a_WorldName) :
m_SkyDarkness(0),
m_Weather(eWeather_Sunny),
m_WeatherInterval(24000), // Guaranteed 1 day of sunshine at server start :)
- m_bCommandBlocksEnabled(false),
- m_bUseChatPrefixes(true),
m_Scoreboard(this),
m_MapManager(this),
m_GeneratorCallbacks(*this),
@@ -554,6 +552,7 @@ void cWorld::Start(void)
m_IsSugarcaneBonemealable = IniFile.GetValueSetB("Plants", "IsSugarcaneBonemealable", false);
m_IsDeepSnowEnabled = IniFile.GetValueSetB("Physics", "DeepSnow", true);
m_ShouldLavaSpawnFire = IniFile.GetValueSetB("Physics", "ShouldLavaSpawnFire", true);
+ m_bTNTSpawnsShrapnel = IniFile.GetValueSetB("Physics", "IsTNTShrapnelEnabled", true);
m_bCommandBlocksEnabled = IniFile.GetValueSetB("Mechanics", "CommandBlocksEnabled", false);
m_bEnabledPVP = IniFile.GetValueSetB("Mechanics", "PVPEnabled", true);
m_bUseChatPrefixes = IniFile.GetValueSetB("Mechanics", "UseChatPrefixes", true);
diff --git a/src/World.h b/src/World.h
index 4b74f7aba..d7d5b5059 100644
--- a/src/World.h
+++ b/src/World.h
@@ -590,6 +590,9 @@ public:
bool AreCommandBlocksEnabled(void) const { return m_bCommandBlocksEnabled; }
void SetCommandBlocksEnabled(bool a_Flag) { m_bCommandBlocksEnabled = a_Flag; }
+ bool IsTNTShrapnelEnabled(void) const { return m_bTNTSpawnsShrapnel; }
+ void SetTNTShrapnelEnabled(bool a_Flag) { m_bTNTSpawnsShrapnel = a_Flag; }
+
bool ShouldUseChatPrefixes(void) const { return m_bUseChatPrefixes; }
void SetShouldUseChatPrefixes(bool a_Flag) { m_bUseChatPrefixes = a_Flag; }
@@ -847,6 +850,9 @@ private:
/** Whether prefixes such as [INFO] are prepended to SendMessageXXX() / BroadcastChatXXX() functions */
bool m_bUseChatPrefixes;
+
+ /** Whether TNT explosions, done via cWorld::DoExplosionAt(), should project random affected blocks as FallingBlock entities */
+ bool m_bTNTSpawnsShrapnel;
cChunkGenerator m_Generator;
--
cgit v1.2.3
From b78c729880705c1bf28f266b087046c4eaed8317 Mon Sep 17 00:00:00 2001
From: Tycho
Date: Mon, 10 Mar 2014 11:56:23 -0700
Subject: Fixed Alignment issue in ByteBuffer
---
src/ByteBuffer.cpp | 2 +-
src/StringUtils.cpp | 7 ++-----
src/StringUtils.h | 2 +-
3 files changed, 4 insertions(+), 7 deletions(-)
diff --git a/src/ByteBuffer.cpp b/src/ByteBuffer.cpp
index 96a135562..a7553786e 100644
--- a/src/ByteBuffer.cpp
+++ b/src/ByteBuffer.cpp
@@ -767,7 +767,7 @@ bool cByteBuffer::ReadUTF16String(AString & a_String, int a_NumChars)
{
return false;
}
- RawBEToUTF8((short *)(RawData.data()), a_NumChars, a_String);
+ RawBEToUTF8((RawData.data()), a_NumChars, a_String);
return true;
}
diff --git a/src/StringUtils.cpp b/src/StringUtils.cpp
index 3fe75d611..3e047fb5c 100644
--- a/src/StringUtils.cpp
+++ b/src/StringUtils.cpp
@@ -288,13 +288,13 @@ void ReplaceString(AString & iHayStack, const AString & iNeedle, const AString &
// Converts a stream of BE shorts into UTF-8 string; returns a ref to a_UTF8
-AString & RawBEToUTF8(short * a_RawData, int a_NumShorts, AString & a_UTF8)
+AString & RawBEToUTF8(const char * a_RawData, int a_NumShorts, AString & a_UTF8)
{
a_UTF8.clear();
a_UTF8.reserve(3 * a_NumShorts / 2); // a quick guess of the resulting size
for (int i = 0; i < a_NumShorts; i++)
{
- int c = ntohs(*(a_RawData + i));
+ int c = GetBEShort(a_RawData + i*2);
if (c < 0x80)
{
a_UTF8.push_back((char)c);
@@ -364,10 +364,7 @@ Notice from the original file:
#define UNI_MAX_BMP 0x0000FFFF
#define UNI_MAX_UTF16 0x0010FFFF
-#define UNI_MAX_UTF32 0x7FFFFFFF
-#define UNI_MAX_LEGAL_UTF32 0x0010FFFF
#define UNI_SUR_HIGH_START 0xD800
-#define UNI_SUR_HIGH_END 0xDBFF
#define UNI_SUR_LOW_START 0xDC00
#define UNI_SUR_LOW_END 0xDFFF
diff --git a/src/StringUtils.h b/src/StringUtils.h
index dfbfc2a75..b64108409 100644
--- a/src/StringUtils.h
+++ b/src/StringUtils.h
@@ -58,7 +58,7 @@ extern unsigned int RateCompareString(const AString & s1, const AString & s2 );
extern void ReplaceString(AString & iHayStack, const AString & iNeedle, const AString & iReplaceWith); // tolua_export
/// Converts a stream of BE shorts into UTF-8 string; returns a ref to a_UTF8
-extern AString & RawBEToUTF8(short * a_RawData, int a_NumShorts, AString & a_UTF8);
+extern AString & RawBEToUTF8(const char * a_RawData, int a_NumShorts, AString & a_UTF8);
/// Converts a UTF-8 string into a UTF-16 BE string, packing that back into AString; return a ref to a_UTF16
extern AString & UTF8ToRawBEUTF16(const char * a_UTF8, size_t a_UTF8Length, AString & a_UTF16);
--
cgit v1.2.3
From 693734bd8307f3089368cb3aca662641f92f2e71 Mon Sep 17 00:00:00 2001
From: Tycho
Date: Mon, 10 Mar 2014 11:57:04 -0700
Subject: Enable error on cast-align and unused macros
---
SetFlags.cmake | 1 -
1 file changed, 1 deletion(-)
diff --git a/SetFlags.cmake b/SetFlags.cmake
index a9657fff1..d9308f603 100644
--- a/SetFlags.cmake
+++ b/SetFlags.cmake
@@ -197,7 +197,6 @@ macro(set_exe_flags)
add_flags_cxx("-Wno-error=missing-prototypes -Wno-error=non-virtual-dtor")
add_flags_cxx("-Wno-error=covered-switch-default -Wno-error=shadow")
add_flags_cxx("-Wno-error=exit-time-destructors -Wno-error=missing-variable-declarations")
- add_flags_cxx("-Wno-error=cast-align -Wno-error=unused-macros")
add_flags_cxx("-Wno-error=global-constructors -Wno-implicit-fallthrough")
add_flags_cxx("-Wno-missing-noreturn -Wno-error=unreachable-code -Wno-error=undef")
add_flags_cxx("-Wno-error=format-nonliteral")
--
cgit v1.2.3
From bc556e7f00ee28198b5ba3e46c1c06caab8fc37b Mon Sep 17 00:00:00 2001
From: Tycho
Date: Mon, 10 Mar 2014 12:21:18 -0700
Subject: Fixed Issues in ProtoProxy
---
Tools/ProtoProxy/Connection.cpp | 16 ++++++++--------
Tools/ProtoProxy/Connection.h | 2 +-
2 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/Tools/ProtoProxy/Connection.cpp b/Tools/ProtoProxy/Connection.cpp
index 91d2fc42f..be908f303 100644
--- a/Tools/ProtoProxy/Connection.cpp
+++ b/Tools/ProtoProxy/Connection.cpp
@@ -131,8 +131,6 @@
} \
}
-
-#define MAX_ENC_LEN 1024
@@ -473,14 +471,14 @@ bool cConnection::SendData(SOCKET a_Socket, cByteBuffer & a_Data, const char * a
-bool cConnection::SendEncryptedData(SOCKET a_Socket, cAESCFBEncryptor & a_Encryptor, const char * a_Data, int a_Size, const char * a_Peer)
+bool cConnection::SendEncryptedData(SOCKET a_Socket, cAESCFBEncryptor & a_Encryptor, const char * a_Data, size_t a_Size, const char * a_Peer)
{
DataLog(a_Data, a_Size, "Encrypting %d bytes to %s", a_Size, a_Peer);
const Byte * Data = (const Byte *)a_Data;
while (a_Size > 0)
{
Byte Buffer[64 KiB];
- int NumBytes = (a_Size > sizeof(Buffer)) ? sizeof(Buffer) : a_Size;
+ size_t NumBytes = (a_Size > sizeof(Buffer)) ? sizeof(Buffer) : a_Size;
a_Encryptor.ProcessData(Buffer, Data, NumBytes);
bool res = SendData(a_Socket, (const char *)Buffer, NumBytes, a_Peer);
if (!res)
@@ -2263,7 +2261,9 @@ bool cConnection::HandleServerSpawnObjectVehicle(void)
HANDLE_SERVER_PACKET_READ(ReadByte, Byte, Yaw);
HANDLE_SERVER_PACKET_READ(ReadBEInt, int, DataIndicator);
AString ExtraData;
- short VelocityX, VelocityY, VelocityZ;
+ short VelocityX = 0;
+ short VelocityY = 0;
+ short VelocityZ = 0;
if (DataIndicator != 0)
{
HANDLE_SERVER_PACKET_READ(ReadBEShort, short, SpeedX);
@@ -2697,7 +2697,7 @@ bool cConnection::ParseMetadata(cByteBuffer & a_Buffer, AString & a_Metadata)
a_Metadata.push_back(x);
while (x != 0x7f)
{
- int Index = ((unsigned)((unsigned char)x)) & 0x1f; // Lower 5 bits = index
+ //int Index = ((unsigned)((unsigned char)x)) & 0x1f; // Lower 5 bits = index
int Type = ((unsigned)((unsigned char)x)) >> 5; // Upper 3 bits = type
int Length = 0;
switch (Type)
@@ -2772,7 +2772,7 @@ void cConnection::LogMetadata(const AString & a_Metadata, size_t a_IndentCount)
{
int Index = ((unsigned)((unsigned char)a_Metadata[pos])) & 0x1f; // Lower 5 bits = index
int Type = ((unsigned)((unsigned char)a_Metadata[pos])) >> 5; // Upper 3 bits = type
- int Length = 0;
+ //int Length = 0;
switch (Type)
{
case 0:
@@ -2827,7 +2827,7 @@ void cConnection::LogMetadata(const AString & a_Metadata, size_t a_IndentCount)
ASSERT(!"Cannot parse item description from metadata");
return;
}
- int After = bb.GetReadableSpace();
+ //int After = bb.GetReadableSpace();
int BytesConsumed = BytesLeft - bb.GetReadableSpace();
Log("%sslot[%d] = %s (%d bytes)", Indent.c_str(), Index, ItemDesc.c_str(), BytesConsumed);
diff --git a/Tools/ProtoProxy/Connection.h b/Tools/ProtoProxy/Connection.h
index 5e4f8cd7b..70b759d0f 100644
--- a/Tools/ProtoProxy/Connection.h
+++ b/Tools/ProtoProxy/Connection.h
@@ -109,7 +109,7 @@ protected:
bool SendData(SOCKET a_Socket, cByteBuffer & a_Data, const char * a_Peer);
/// Sends data to the specfied socket, after encrypting it using a_Encryptor. If sending fails, prints a fail message using a_Peer and returns false
- bool SendEncryptedData(SOCKET a_Socket, cAESCFBEncryptor & a_Encryptor, const char * a_Data, int a_Size, const char * a_Peer);
+ bool SendEncryptedData(SOCKET a_Socket, cAESCFBEncryptor & a_Encryptor, const char * a_Data, size_t a_Size, const char * a_Peer);
/// Sends data to the specfied socket, after encrypting it using a_Encryptor. If sending fails, prints a fail message using a_Peer and returns false
bool SendEncryptedData(SOCKET a_Socket, cAESCFBEncryptor & a_Encryptor, cByteBuffer & a_Data, const char * a_Peer);
--
cgit v1.2.3
From bb28f0d1e3fa685791433220d0bf96bda6d4937e Mon Sep 17 00:00:00 2001
From: Tycho
Date: Mon, 10 Mar 2014 12:36:01 -0700
Subject: Fixed assert
---
src/ByteBuffer.cpp | 31 +++++++++++++++++--------------
1 file changed, 17 insertions(+), 14 deletions(-)
diff --git a/src/ByteBuffer.cpp b/src/ByteBuffer.cpp
index a7553786e..ae4e72737 100644
--- a/src/ByteBuffer.cpp
+++ b/src/ByteBuffer.cpp
@@ -46,6 +46,9 @@
#ifdef SELF_TEST
+#define assert_test(x) ( !!(x) || \
+ LOGERROR("Assertion failed: %s, file %s, line %i", #x, __FILE__, __LINE__ ), abort(1))
+
/// Self-test of the VarInt-reading and writing code
static class cByteBufferSelfTest
{
@@ -62,11 +65,11 @@ public:
cByteBuffer buf(50);
buf.Write("\x05\xac\x02\x00", 4);
UInt32 v1;
- assert(buf.ReadVarInt(v1) && (v1 == 5));
+ assert_test(buf.ReadVarInt(v1) && (v1 == 5));
UInt32 v2;
- assert(buf.ReadVarInt(v2) && (v2 == 300));
+ assert_test(buf.ReadVarInt(v2) && (v2 == 300));
UInt32 v3;
- assert(buf.ReadVarInt(v3) && (v3 == 0));
+ assert_test(buf.ReadVarInt(v3) && (v3 == 0));
}
void TestWrite(void)
@@ -77,8 +80,8 @@ public:
buf.WriteVarInt(0);
AString All;
buf.ReadAll(All);
- assert(All.size() == 4);
- assert(memcmp(All.data(), "\x05\xac\x02\x00", All.size()) == 0);
+ assert_test(All.size() == 4);
+ assert_test(memcmp(All.data(), "\x05\xac\x02\x00", All.size()) == 0);
}
void TestWrap(void)
@@ -87,17 +90,17 @@ public:
for (int i = 0; i < 1000; i++)
{
size_t FreeSpace = buf.GetFreeSpace();
- assert(buf.GetReadableSpace() == 0);
- assert(FreeSpace > 0);
- assert(buf.Write("a", 1));
- assert(buf.CanReadBytes(1));
- assert(buf.GetReadableSpace() == 1);
+ assert_test(buf.GetReadableSpace() == 0);
+ assert_test(FreeSpace > 0);
+ assert_test(buf.Write("a", 1));
+ assert_test(buf.CanReadBytes(1));
+ assert_test(buf.GetReadableSpace() == 1);
unsigned char v = 0;
- assert(buf.ReadByte(v));
- assert(v == 'a');
- assert(buf.GetReadableSpace() == 0);
+ assert_test(buf.ReadByte(v));
+ assert_test(v == 'a');
+ assert_test(buf.GetReadableSpace() == 0);
buf.CommitRead();
- assert(buf.GetFreeSpace() == FreeSpace); // We're back to normal
+ assert_test(buf.GetFreeSpace() == FreeSpace); // We're back to normal
}
}
--
cgit v1.2.3
From 4ed68916d8c0ac4b5384bbaf83088b52ca2d47d9 Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Mon, 10 Mar 2014 20:52:53 +0100
Subject: Revert "Fixed some warnings"
This reverts commit 4cb0b82d1df560ad32c92eede91f466c75a87c87.
---
src/ChunkDef.h | 17 +++++++----------
1 file changed, 7 insertions(+), 10 deletions(-)
diff --git a/src/ChunkDef.h b/src/ChunkDef.h
index 63431f211..7be2fa2df 100644
--- a/src/ChunkDef.h
+++ b/src/ChunkDef.h
@@ -65,8 +65,8 @@ public:
enum
{
// Chunk dimensions:
- Width = 16U,
- Height = 256U,
+ Width = 16,
+ Height = 256,
NumBlocks = Width * Height * Width,
/// If the data is collected into a single buffer, how large it needs to be:
@@ -132,7 +132,7 @@ public:
}
- inline static unsigned int MakeIndexNoCheck(unsigned int x, unsigned int y, unsigned int z)
+ inline static unsigned int MakeIndexNoCheck(int x, int y, int z)
{
#if AXIS_ORDER == AXIS_ORDER_XZY
// For some reason, NOT using the Horner schema is faster. Weird.
@@ -240,7 +240,7 @@ public:
{
if ((x < Width) && (x > -1) && (y < Height) && (y > -1) && (z < Width) && (z > -1))
{
- unsigned int Index = MakeIndexNoCheck(x, y, z);
+ int Index = MakeIndexNoCheck(x, y, z);
return (a_Buffer[Index / 2] >> ((Index & 1) * 4)) & 0x0f;
}
ASSERT(!"cChunkDef::GetNibble(): coords out of chunk range!");
@@ -256,7 +256,7 @@ public:
return;
}
a_Buffer[a_BlockIdx / 2] = (
- (a_Buffer[a_BlockIdx / 2] & (0xf0 >> (static_cast(a_BlockIdx & 1) * 4))) | // The untouched nibble
+ (a_Buffer[a_BlockIdx / 2] & (0xf0 >> ((a_BlockIdx & 1) * 4))) | // The untouched nibble
((a_Nibble & 0x0f) << ((a_BlockIdx & 1) * 4)) // The nibble being set
);
}
@@ -282,13 +282,13 @@ public:
}
- inline static NIBBLETYPE GetNibble(const NIBBLETYPE * a_Buffer, const Vector3i & a_BlockPos )
+ inline static char GetNibble(const NIBBLETYPE * a_Buffer, const Vector3i & a_BlockPos )
{
return GetNibble(a_Buffer, a_BlockPos.x, a_BlockPos.y, a_BlockPos.z );
}
- inline static void SetNibble(NIBBLETYPE * a_Buffer, const Vector3i & a_BlockPos, NIBBLETYPE a_Value )
+ inline static void SetNibble(NIBBLETYPE * a_Buffer, const Vector3i & a_BlockPos, char a_Value )
{
SetNibble( a_Buffer, a_BlockPos.x, a_BlockPos.y, a_BlockPos.z, a_Value );
}
@@ -306,9 +306,6 @@ The virtual methods are called in the same order as they're declared here.
class cChunkDataCallback abstract
{
public:
-
- virtual ~cChunkDataCallback() {}
-
/** Called before any other callbacks to inform of the current coords
(only in processes where multiple chunks can be processed, such as cWorld::ForEachChunkInRect()).
If false is returned, the chunk is skipped.
--
cgit v1.2.3
From e9e2852ce1d7b3cdbbcc115d63f1d4d0ab25457f Mon Sep 17 00:00:00 2001
From: Tycho
Date: Mon, 10 Mar 2014 13:12:43 -0700
Subject: Fixed test asserts
---
src/ByteBuffer.cpp | 3 ---
src/CompositeChat.cpp | 62 ++++++++++++++++++++++++-------------------------
src/CraftingRecipes.cpp | 2 ++
src/Globals.h | 7 +++---
4 files changed, 37 insertions(+), 37 deletions(-)
diff --git a/src/ByteBuffer.cpp b/src/ByteBuffer.cpp
index ae4e72737..9d97d8614 100644
--- a/src/ByteBuffer.cpp
+++ b/src/ByteBuffer.cpp
@@ -46,9 +46,6 @@
#ifdef SELF_TEST
-#define assert_test(x) ( !!(x) || \
- LOGERROR("Assertion failed: %s, file %s, line %i", #x, __FILE__, __LINE__ ), abort(1))
-
/// Self-test of the VarInt-reading and writing code
static class cByteBufferSelfTest
{
diff --git a/src/CompositeChat.cpp b/src/CompositeChat.cpp
index 3eec35657..19ed30d78 100644
--- a/src/CompositeChat.cpp
+++ b/src/CompositeChat.cpp
@@ -32,15 +32,15 @@ public:
cCompositeChat Msg;
Msg.ParseText("Testing @2color codes and http://links parser");
const cCompositeChat::cParts & Parts = Msg.GetParts();
- assert(Parts.size() == 4);
- assert(Parts[0]->m_PartType == cCompositeChat::ptText);
- assert(Parts[1]->m_PartType == cCompositeChat::ptText);
- assert(Parts[2]->m_PartType == cCompositeChat::ptUrl);
- assert(Parts[3]->m_PartType == cCompositeChat::ptText);
- assert(Parts[0]->m_Style == "");
- assert(Parts[1]->m_Style == "@2");
- assert(Parts[2]->m_Style == "@2");
- assert(Parts[3]->m_Style == "@2");
+ assert_test(Parts.size() == 4);
+ assert_test(Parts[0]->m_PartType == cCompositeChat::ptText);
+ assert_test(Parts[1]->m_PartType == cCompositeChat::ptText);
+ assert_test(Parts[2]->m_PartType == cCompositeChat::ptUrl);
+ assert_test(Parts[3]->m_PartType == cCompositeChat::ptText);
+ assert_test(Parts[0]->m_Style == "");
+ assert_test(Parts[1]->m_Style == "@2");
+ assert_test(Parts[2]->m_Style == "@2");
+ assert_test(Parts[3]->m_Style == "@2");
}
void TestParser2(void)
@@ -48,15 +48,15 @@ public:
cCompositeChat Msg;
Msg.ParseText("@3Advanced stuff: @5overriding color codes and http://links.with/@4color-in-them handling");
const cCompositeChat::cParts & Parts = Msg.GetParts();
- assert(Parts.size() == 4);
- assert(Parts[0]->m_PartType == cCompositeChat::ptText);
- assert(Parts[1]->m_PartType == cCompositeChat::ptText);
- assert(Parts[2]->m_PartType == cCompositeChat::ptUrl);
- assert(Parts[3]->m_PartType == cCompositeChat::ptText);
- assert(Parts[0]->m_Style == "@3");
- assert(Parts[1]->m_Style == "@5");
- assert(Parts[2]->m_Style == "@5");
- assert(Parts[3]->m_Style == "@5");
+ assert_test(Parts.size() == 4);
+ assert_test(Parts[0]->m_PartType == cCompositeChat::ptText);
+ assert_test(Parts[1]->m_PartType == cCompositeChat::ptText);
+ assert_test(Parts[2]->m_PartType == cCompositeChat::ptUrl);
+ assert_test(Parts[3]->m_PartType == cCompositeChat::ptText);
+ assert_test(Parts[0]->m_Style == "@3");
+ assert_test(Parts[1]->m_Style == "@5");
+ assert_test(Parts[2]->m_Style == "@5");
+ assert_test(Parts[3]->m_Style == "@5");
}
void TestParser3(void)
@@ -64,11 +64,11 @@ public:
cCompositeChat Msg;
Msg.ParseText("http://links.starting the text");
const cCompositeChat::cParts & Parts = Msg.GetParts();
- assert(Parts.size() == 2);
- assert(Parts[0]->m_PartType == cCompositeChat::ptUrl);
- assert(Parts[1]->m_PartType == cCompositeChat::ptText);
- assert(Parts[0]->m_Style == "");
- assert(Parts[1]->m_Style == "");
+ assert_test(Parts.size() == 2);
+ assert_test(Parts[0]->m_PartType == cCompositeChat::ptUrl);
+ assert_test(Parts[1]->m_PartType == cCompositeChat::ptText);
+ assert_test(Parts[0]->m_Style == "");
+ assert_test(Parts[1]->m_Style == "");
}
void TestParser4(void)
@@ -76,11 +76,11 @@ public:
cCompositeChat Msg;
Msg.ParseText("links finishing the text: http://some.server");
const cCompositeChat::cParts & Parts = Msg.GetParts();
- assert(Parts.size() == 2);
- assert(Parts[0]->m_PartType == cCompositeChat::ptText);
- assert(Parts[1]->m_PartType == cCompositeChat::ptUrl);
- assert(Parts[0]->m_Style == "");
- assert(Parts[1]->m_Style == "");
+ assert_test(Parts.size() == 2);
+ assert_test(Parts[0]->m_PartType == cCompositeChat::ptText);
+ assert_test(Parts[1]->m_PartType == cCompositeChat::ptUrl);
+ assert_test(Parts[0]->m_Style == "");
+ assert_test(Parts[1]->m_Style == "");
}
void TestParser5(void)
@@ -88,9 +88,9 @@ public:
cCompositeChat Msg;
Msg.ParseText("http://only.links");
const cCompositeChat::cParts & Parts = Msg.GetParts();
- assert(Parts.size() == 1);
- assert(Parts[0]->m_PartType == cCompositeChat::ptUrl);
- assert(Parts[0]->m_Style == "");
+ assert_test(Parts.size() == 1);
+ assert_test(Parts[0]->m_PartType == cCompositeChat::ptUrl);
+ assert_test(Parts[0]->m_Style == "");
}
} gTest;
diff --git a/src/CraftingRecipes.cpp b/src/CraftingRecipes.cpp
index 868182394..be9f45caa 100644
--- a/src/CraftingRecipes.cpp
+++ b/src/CraftingRecipes.cpp
@@ -192,7 +192,9 @@ void cCraftingGrid::Dump(void)
{
for (int y = 0; y < m_Height; y++) for (int x = 0; x < m_Width; x++)
{
+ #ifdef _DEBUG
int idx = x + m_Width * y;
+ #endif
LOGD("Slot (%d, %d): Type %d, health %d, count %d",
x, y, m_Items[idx].m_ItemType, m_Items[idx].m_ItemDamage, m_Items[idx].m_ItemCount
);
diff --git a/src/Globals.h b/src/Globals.h
index b046e6db0..2cd160677 100644
--- a/src/Globals.h
+++ b/src/Globals.h
@@ -234,9 +234,10 @@ template class SizeChecker;
// Pretty much the same as ASSERT() but stays in Release builds
#define VERIFY( x ) ( !!(x) || ( LOGERROR("Verification failed: %s, file %s, line %i", #x, __FILE__, __LINE__ ), exit(1), 0 ) )
-
-
-
+// Same as assert but in all Self test builds
+#ifdef SELF_TEST
+#define assert_test(x) ( !!(x) || (assert(0), exit(1), 0))
+#endif
/// A generic interface used mainly in ForEach() functions
template class cItemCallback
--
cgit v1.2.3
From 26d7ed661225ed092bd79c55e16134aef770ee3b Mon Sep 17 00:00:00 2001
From: madmaxoft
Date: Mon, 10 Mar 2014 21:16:13 +0100
Subject: Removed debugging output.
Kept it commented-out for later revisions, if needed.
---
src/Generating/POCPieceGenerator.cpp | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/Generating/POCPieceGenerator.cpp b/src/Generating/POCPieceGenerator.cpp
index d7619b8ff..9ed4b565e 100644
--- a/src/Generating/POCPieceGenerator.cpp
+++ b/src/Generating/POCPieceGenerator.cpp
@@ -2,7 +2,7 @@
// POCPieceGenerator.cpp
// Implements the cPOCPieceGenerator class representing a Proof-Of_Concept structure generator using the cPieceGenerator technique
-// The generator generates a maze of rooms at {0, 100, 0}
+// The generator generates a maze of rooms at {0, 50, 0}
#include "Globals.h"
#include "POCPieceGenerator.h"
@@ -131,6 +131,7 @@ protected:
+/*
static void DebugPieces(const cPlacedPieces & a_Pieces)
{
size_t idx = 0;
@@ -143,6 +144,7 @@ static void DebugPieces(const cPlacedPieces & a_Pieces)
);
} // for itr - a_Pieces[]
}
+//*/
--
cgit v1.2.3
From 98e15a34a416c31d4689836f4f38161f1270513c Mon Sep 17 00:00:00 2001
From: Tycho
Date: Mon, 10 Mar 2014 13:18:53 -0700
Subject: Fixed xofts issues
---
Tools/ProtoProxy/Connection.cpp | 2 +-
src/ChunkDef.h | 26 ++++++++------------------
src/StringUtils.cpp | 2 +-
src/WorldStorage/FastNBT.cpp | 2 +-
src/WorldStorage/FireworksSerializer.cpp | 4 ++++
5 files changed, 15 insertions(+), 21 deletions(-)
diff --git a/Tools/ProtoProxy/Connection.cpp b/Tools/ProtoProxy/Connection.cpp
index be908f303..73688d310 100644
--- a/Tools/ProtoProxy/Connection.cpp
+++ b/Tools/ProtoProxy/Connection.cpp
@@ -2697,7 +2697,7 @@ bool cConnection::ParseMetadata(cByteBuffer & a_Buffer, AString & a_Metadata)
a_Metadata.push_back(x);
while (x != 0x7f)
{
- //int Index = ((unsigned)((unsigned char)x)) & 0x1f; // Lower 5 bits = index
+ // int Index = ((unsigned)((unsigned char)x)) & 0x1f; // Lower 5 bits = index
int Type = ((unsigned)((unsigned char)x)) >> 5; // Upper 3 bits = type
int Length = 0;
switch (Type)
diff --git a/src/ChunkDef.h b/src/ChunkDef.h
index a5059348c..fcda64f5c 100644
--- a/src/ChunkDef.h
+++ b/src/ChunkDef.h
@@ -124,9 +124,7 @@ public:
(z < Width) && (z > -1)
)
{
- return MakeIndexNoCheck(static_cast(x),
- static_cast(y),
- static_cast(z));
+ return MakeIndexNoCheck(x, y, z);
}
LOGERROR("cChunkDef::MakeIndex(): coords out of range: {%d, %d, %d}; returning fake index 0", x, y, z);
ASSERT(!"cChunkDef::MakeIndex(): coords out of chunk range!");
@@ -134,13 +132,13 @@ public:
}
- inline static unsigned int MakeIndexNoCheck(unsigned int x, unsigned int y, unsigned int z)
+ inline static unsigned int MakeIndexNoCheck(int x, int y, int z)
{
#if AXIS_ORDER == AXIS_ORDER_XZY
// For some reason, NOT using the Horner schema is faster. Weird.
- return x + (z * cChunkDef::Width) + (y * cChunkDef::Width * cChunkDef::Width); // 1.2 is XZY
+ return static_cast(x + (z * cChunkDef::Width) + (y * cChunkDef::Width * cChunkDef::Width)); // 1.2 is XZY
#elif AXIS_ORDER == AXIS_ORDER_YZX
- return y + (z * cChunkDef::Width) + (x * cChunkDef::Height * cChunkDef::Width); // 1.1 is YZX
+ return static_cast(y + (z * cChunkDef::Width) + (x * cChunkDef::Height * cChunkDef::Width)); // 1.1 is YZX
#endif
}
@@ -168,9 +166,7 @@ public:
ASSERT((a_X >= 0) && (a_X < Width));
ASSERT((a_Y >= 0) && (a_Y < Height));
ASSERT((a_Z >= 0) && (a_Z < Width));
- a_BlockTypes[MakeIndexNoCheck(static_cast(a_X),
- static_cast(a_Y),
- static_cast(a_Z))] = a_Type;
+ a_BlockTypes[MakeIndexNoCheck(a_X, a_Y, a_Z)] = a_Type;
}
@@ -186,9 +182,7 @@ public:
ASSERT((a_X >= 0) && (a_X < Width));
ASSERT((a_Y >= 0) && (a_Y < Height));
ASSERT((a_Z >= 0) && (a_Z < Width));
- return a_BlockTypes[MakeIndexNoCheck(static_cast(a_X),
- static_cast(a_Y),
- static_cast(a_Z))];
+ return a_BlockTypes[MakeIndexNoCheck(a_X, a_Y, a_Z)];
}
@@ -246,9 +240,7 @@ public:
{
if ((x < Width) && (x > -1) && (y < Height) && (y > -1) && (z < Width) && (z > -1))
{
- unsigned int Index = MakeIndexNoCheck(static_cast(x),
- static_cast(y),
- static_cast(z));
+ unsigned int Index = MakeIndexNoCheck(x, y, z);
return (a_Buffer[Index / 2] >> ((Index & 1) * 4)) & 0x0f;
}
ASSERT(!"cChunkDef::GetNibble(): coords out of chunk range!");
@@ -282,9 +274,7 @@ public:
return;
}
- unsigned int Index = MakeIndexNoCheck(static_cast(x),
- static_cast(y),
- static_cast(z));
+ unsigned int Index = MakeIndexNoCheck(x, y, z);
a_Buffer[Index / 2] = static_cast