From 7175b9e435a54cff33914d21384625a445cc5cf0 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 20 Aug 2016 13:34:29 +0100 Subject: test --- src/Items/ItemBoat.h | 3 +-- src/Items/ItemBow.h | 11 +++-------- src/Items/ItemFishingRod.h | 4 ++-- src/Items/ItemItemFrame.h | 6 ++---- src/Items/ItemMinecart.h | 17 ++--------------- src/Items/ItemPainting.h | 4 ++-- 6 files changed, 12 insertions(+), 33 deletions(-) (limited to 'src/Items') diff --git a/src/Items/ItemBoat.h b/src/Items/ItemBoat.h index de16c70dc..ad6934916 100644 --- a/src/Items/ItemBoat.h +++ b/src/Items/ItemBoat.h @@ -92,8 +92,7 @@ public: } // Spawn block at water level - cBoat * Boat = new cBoat(x + 0.5, y + 0.5, z + 0.5); - Boat->Initialize(*a_World); + a_World->SpawnBoat(x + 0.5, y + 0.5, z + 0.5); return true; } diff --git a/src/Items/ItemBow.h b/src/Items/ItemBow.h index fc0ee8434..0d4bdd46e 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 ArrowPtr = cpp14::make_unique(*a_Player, Force * 2); + auto Arrow = ArrowPtr.get(); + if (!Arrow->Initialize(std::move(ArrowPtr), *a_Player->GetWorld())) { return; } - if (!Arrow->Initialize(*a_Player->GetWorld())) - { - delete Arrow; - Arrow = nullptr; - return; - } a_Player->GetWorld()->BroadcastSoundEffect( "random.bow", a_Player->GetPosX(), diff --git a/src/Items/ItemFishingRod.h b/src/Items/ItemFishingRod.h index 3a2ef0275..e44eb09bb 100644 --- a/src/Items/ItemFishingRod.h +++ b/src/Items/ItemFishingRod.h @@ -244,9 +244,9 @@ public: } else { - cFloater * Floater = new cFloater(a_Player->GetPosX(), a_Player->GetStance(), a_Player->GetPosZ(), a_Player->GetLookVector() * 15, a_Player->GetUniqueID(), static_cast(100 + static_cast(a_World->GetTickRandomNumber(800)) - (a_Player->GetEquippedItem().m_Enchantments.GetLevel(cEnchantments::enchLure) * 100))); - Floater->Initialize(*a_World); + auto Floater = cpp14::make_unique(a_Player->GetPosX(), a_Player->GetStance(), a_Player->GetPosZ(), a_Player->GetLookVector() * 15, a_Player->GetUniqueID(), static_cast(100 + static_cast(a_World->GetTickRandomNumber(800)) - (a_Player->GetEquippedItem().m_Enchantments.GetLevel(cEnchantments::enchLure) * 100))); a_Player->SetIsFishing(true, Floater->GetUniqueID()); + Floater->Initialize(std::move(Floater), *a_World); } return true; } diff --git a/src/Items/ItemItemFrame.h b/src/Items/ItemItemFrame.h index 77a5bf47c..a670d6cac 100644 --- a/src/Items/ItemItemFrame.h +++ b/src/Items/ItemItemFrame.h @@ -38,11 +38,9 @@ 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(a_BlockFace, a_BlockX, a_BlockY, a_BlockZ); + if (!ItemFrame->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 6344c0178..d7ea18719 100644 --- a/src/Items/ItemMinecart.h +++ b/src/Items/ItemMinecart.h @@ -59,21 +59,8 @@ public: double x = static_cast(a_BlockX) + 0.5; double y = static_cast(a_BlockY) + 0.5; double z = static_cast(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) - Minecart->Initialize(*a_World); + + a_World->SpawnMinecart(x, y, z, m_ItemType); if (!a_Player->IsGameModeCreative()) { diff --git a/src/Items/ItemPainting.h b/src/Items/ItemPainting.h index dd35931dd..60a231d2b 100644 --- a/src/Items/ItemPainting.h +++ b/src/Items/ItemPainting.h @@ -70,8 +70,8 @@ public: { "BurningSkull" } }; - cPainting * Painting = new cPainting(gPaintingTitlesList[a_World->GetTickRandomNumber(ARRAYCOUNT(gPaintingTitlesList) - 1)].Title, a_BlockFace, a_BlockX, a_BlockY, a_BlockZ); - Painting->Initialize(*a_World); + auto Painting = cpp14::make_unique(gPaintingTitlesList[a_World->GetTickRandomNumber(ARRAYCOUNT(gPaintingTitlesList) - 1)].Title, a_BlockFace, a_BlockX, a_BlockY, a_BlockZ); + Painting->Initialize(std::move(Painting), *a_World); if (!a_Player->IsGameModeCreative()) { -- cgit v1.2.3