summaryrefslogtreecommitdiffstats
path: root/src/Items
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@outlook.com>2017-08-18 12:17:56 +0200
committerGitHub <noreply@github.com>2017-08-18 12:17:56 +0200
commit72d7027861a3b7e7e8bb5fdcbbc5a1a778fa7f82 (patch)
treec1c1a040332d4ba1f784be25c67c9800e85015eb /src/Items
parentSitting cats block enderchests from opening (#3906) (diff)
parentChanged entity ownership model to use smart pointers (diff)
downloadcuberite-72d7027861a3b7e7e8bb5fdcbbc5a1a778fa7f82.tar
cuberite-72d7027861a3b7e7e8bb5fdcbbc5a1a778fa7f82.tar.gz
cuberite-72d7027861a3b7e7e8bb5fdcbbc5a1a778fa7f82.tar.bz2
cuberite-72d7027861a3b7e7e8bb5fdcbbc5a1a778fa7f82.tar.lz
cuberite-72d7027861a3b7e7e8bb5fdcbbc5a1a778fa7f82.tar.xz
cuberite-72d7027861a3b7e7e8bb5fdcbbc5a1a778fa7f82.tar.zst
cuberite-72d7027861a3b7e7e8bb5fdcbbc5a1a778fa7f82.zip
Diffstat (limited to '')
-rw-r--r--src/Items/ItemBoat.h5
-rw-r--r--src/Items/ItemBow.h11
-rw-r--r--src/Items/ItemFishingRod.h9
-rw-r--r--src/Items/ItemItemFrame.h7
-rw-r--r--src/Items/ItemMinecart.h19
-rw-r--r--src/Items/ItemPainting.h7
6 files changed, 16 insertions, 42 deletions
diff --git a/src/Items/ItemBoat.h b/src/Items/ItemBoat.h
index bdfed8944..f39a35a88 100644
--- a/src/Items/ItemBoat.h
+++ b/src/Items/ItemBoat.h
@@ -95,11 +95,8 @@ public:
}
// Spawn block at water level
- cBoat * Boat = new cBoat(x + 0.5, y + 0.5, z + 0.5, cBoat::ItemToMaterial(a_Player->GetEquippedItem()));
- if (!Boat->Initialize(*a_World))
+ if (a_World->SpawnBoat(x + 0.5, y + 0.5, z + 0.5, cBoat::ItemToMaterial(a_Player->GetEquippedItem())) == cEntity::INVALID_ID)
{
- delete Boat;
- Boat = nullptr;
return false;
}
diff --git a/src/Items/ItemBow.h b/src/Items/ItemBow.h
index a2f646efc..7cbd1dc70 100644
--- a/src/Items/ItemBow.h
+++ b/src/Items/ItemBow.h
@@ -69,17 +69,12 @@ public:
}
// Create the arrow entity:
- cArrowEntity * Arrow = new cArrowEntity(*a_Player, Force * 2);
- if (Arrow == nullptr)
+ auto Arrow = cpp14::make_unique<cArrowEntity>(*a_Player, Force * 2);
+ auto ArrowPtr = Arrow.get();
+ if (!ArrowPtr->Initialize(std::move(Arrow), *a_Player->GetWorld()))
{
return;
}
- if (!Arrow->Initialize(*a_Player->GetWorld()))
- {
- delete Arrow;
- Arrow = nullptr;
- return;
- }
a_Player->GetWorld()->BroadcastSoundEffect(
"entity.arrow.shoot",
a_Player->GetPosX(),
diff --git a/src/Items/ItemFishingRod.h b/src/Items/ItemFishingRod.h
index a32368304..012f13a6c 100644
--- a/src/Items/ItemFishingRod.h
+++ b/src/Items/ItemFishingRod.h
@@ -251,14 +251,13 @@ public:
}
else
{
- cFloater * Floater = new cFloater(a_Player->GetPosX(), a_Player->GetStance(), a_Player->GetPosZ(), a_Player->GetLookVector() * 15, a_Player->GetUniqueID(), (Random.RandInt(100, 900) - static_cast<int>(a_Player->GetEquippedItem().m_Enchantments.GetLevel(cEnchantments::enchLure) * 100)));
- if (!Floater->Initialize(*a_World))
+ auto Floater = cpp14::make_unique<cFloater>(a_Player->GetPosX(), a_Player->GetStance(), a_Player->GetPosZ(), a_Player->GetLookVector() * 15, a_Player->GetUniqueID(), (Random.RandInt(100, 900) - static_cast<int>(a_Player->GetEquippedItem().m_Enchantments.GetLevel(cEnchantments::enchLure) * 100)));
+ auto FloaterPtr = Floater.get();
+ if (!FloaterPtr->Initialize(std::move(Floater), *a_World))
{
- delete Floater;
- Floater = nullptr;
return false;
}
- a_Player->SetIsFishing(true, Floater->GetUniqueID());
+ a_Player->SetIsFishing(true, FloaterPtr->GetUniqueID());
}
return true;
}
diff --git a/src/Items/ItemItemFrame.h b/src/Items/ItemItemFrame.h
index 77a5bf47c..dd3e1f5a8 100644
--- a/src/Items/ItemItemFrame.h
+++ b/src/Items/ItemItemFrame.h
@@ -38,11 +38,10 @@ public:
if (Block == E_BLOCK_AIR)
{
- cItemFrame * ItemFrame = new cItemFrame(a_BlockFace, a_BlockX, a_BlockY, a_BlockZ);
- if (!ItemFrame->Initialize(*a_World))
+ auto ItemFrame = cpp14::make_unique<cItemFrame>(a_BlockFace, a_BlockX, a_BlockY, a_BlockZ);
+ auto ItemFramePtr = ItemFrame.get();
+ if (!ItemFramePtr->Initialize(std::move(ItemFrame), *a_World))
{
- delete ItemFrame;
- ItemFrame = nullptr;
return false;
}
diff --git a/src/Items/ItemMinecart.h b/src/Items/ItemMinecart.h
index 623342d41..05f375f06 100644
--- a/src/Items/ItemMinecart.h
+++ b/src/Items/ItemMinecart.h
@@ -59,24 +59,9 @@ public:
double x = static_cast<double>(a_BlockX) + 0.5;
double y = static_cast<double>(a_BlockY) + 0.5;
double z = static_cast<double>(a_BlockZ) + 0.5;
- cMinecart * Minecart = nullptr;
- switch (m_ItemType)
- {
- case E_ITEM_MINECART: Minecart = new cRideableMinecart (x, y, z, cItem(), 1); break;
- case E_ITEM_CHEST_MINECART: Minecart = new cMinecartWithChest (x, y, z); break;
- case E_ITEM_FURNACE_MINECART: Minecart = new cMinecartWithFurnace (x, y, z); break;
- case E_ITEM_MINECART_WITH_TNT: Minecart = new cMinecartWithTNT (x, y, z); break;
- case E_ITEM_MINECART_WITH_HOPPER: Minecart = new cMinecartWithHopper (x, y, z); break;
- default:
- {
- ASSERT(!"Unhandled minecart item");
- return false;
- }
- } // switch (m_ItemType)
- if (!Minecart->Initialize(*a_World))
+
+ if (a_World->SpawnMinecart(x, y, z, m_ItemType) == cEntity::INVALID_ID)
{
- delete Minecart;
- Minecart = nullptr;
return false;
}
diff --git a/src/Items/ItemPainting.h b/src/Items/ItemPainting.h
index 3432583ca..8e5a1b5d2 100644
--- a/src/Items/ItemPainting.h
+++ b/src/Items/ItemPainting.h
@@ -70,11 +70,10 @@ public:
{ "BurningSkull" }
};
- cPainting * Painting = new cPainting(gPaintingTitlesList[a_World->GetTickRandomNumber(ARRAYCOUNT(gPaintingTitlesList) - 1)].Title, a_BlockFace, a_BlockX, a_BlockY, a_BlockZ);
- if (!Painting->Initialize(*a_World))
+ auto Painting = cpp14::make_unique<cPainting>(gPaintingTitlesList[a_World->GetTickRandomNumber(ARRAYCOUNT(gPaintingTitlesList) - 1)].Title, a_BlockFace, a_BlockX, a_BlockY, a_BlockZ);
+ auto PaintingPtr = Painting.get();
+ if (!PaintingPtr->Initialize(std::move(Painting), *a_World))
{
- delete Painting;
- Painting = nullptr;
return false;
}