From 324fa55bf0c72f61ce8b5dfc3df7770d61a8e25f Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Mon, 16 Dec 2013 18:01:33 +0100 Subject: You can spawn boats on water. --- src/Items/ItemBoat.h | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) (limited to 'src/Items') diff --git a/src/Items/ItemBoat.h b/src/Items/ItemBoat.h index 6e3395f1d..c50171c0c 100644 --- a/src/Items/ItemBoat.h +++ b/src/Items/ItemBoat.h @@ -10,6 +10,7 @@ #pragma once #include "../Entities/Boat.h" +#include "../LineBlockTracer.h" @@ -30,23 +31,47 @@ public: virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir) override { - if (a_Dir < 0) + if (a_Dir > 0) { return false; } + + class cCallbacks : + public cBlockTracer::cCallbacks + { + public: + Vector3d Pos; + virtual bool OnNextBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, char a_EntryFace) override + { + if (a_BlockType != E_BLOCK_AIR) + { + Pos = Vector3d(a_BlockX, a_BlockY, a_BlockZ); + return true; + } + return false; + } + } Callbacks; - double x = (double)a_BlockX + 0.5; - double y = (double)a_BlockY + 0.5; - double z = (double)a_BlockZ + 0.5; + cLineBlockTracer Tracer(*a_World, Callbacks); + Vector3d Start(a_Player->GetEyePosition() + a_Player->GetLookVector()); + Vector3d End(a_Player->GetEyePosition() + a_Player->GetLookVector() * 5); - cBoat * Boat = NULL; + Tracer.Trace(Start.x, Start.y, Start.z, End.x, End.y, End.z); + + double x = Callbacks.Pos.x; + double y = Callbacks.Pos.y; + double z = Callbacks.Pos.z; + + if (x == 0 && y == 0 && z == 0) + { + return false; + } - Boat = new cBoat (x, y, z); + cBoat * Boat = new cBoat(x, y + 1, z); Boat->Initialize(a_World); return true; } - } ; -- cgit v1.2.3 From 6b21dc6d11673f612d3ca6f3f4ced8809d61ef47 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Mon, 16 Dec 2013 20:53:43 +0100 Subject: Using suggestions for Boat placing. --- src/Items/ItemBoat.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Items') diff --git a/src/Items/ItemBoat.h b/src/Items/ItemBoat.h index c50171c0c..0326b13b8 100644 --- a/src/Items/ItemBoat.h +++ b/src/Items/ItemBoat.h @@ -62,7 +62,7 @@ public: double y = Callbacks.Pos.y; double z = Callbacks.Pos.z; - if (x == 0 && y == 0 && z == 0) + if ((x == 0) && (y == 0) && (z == 0)) { return false; } -- cgit v1.2.3 From 59165dcba5df9fc30f4a9795b550364eb89e9c2b Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Mon, 16 Dec 2013 21:50:57 +0100 Subject: Boats spawn on top of a block. not between 4 blocks. --- src/Items/ItemBoat.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Items') diff --git a/src/Items/ItemBoat.h b/src/Items/ItemBoat.h index 0326b13b8..79c8e9589 100644 --- a/src/Items/ItemBoat.h +++ b/src/Items/ItemBoat.h @@ -67,7 +67,7 @@ public: return false; } - cBoat * Boat = new cBoat(x, y + 1, z); + cBoat * Boat = new cBoat(x + 0.5, y + 1, z + 0.5); Boat->Initialize(a_World); return true; -- cgit v1.2.3 From d28142ff719ac79977d00fa2f337fecd173ea88d Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Tue, 17 Dec 2013 17:33:48 +0100 Subject: Made buckets work when the player does not 'look' at a block. This fixes #265 --- src/Items/ItemBucket.h | 85 +++++++++++++++++++++++++++++++------------------- 1 file changed, 53 insertions(+), 32 deletions(-) (limited to 'src/Items') diff --git a/src/Items/ItemBucket.h b/src/Items/ItemBucket.h index fa3d48da1..87f23b554 100644 --- a/src/Items/ItemBucket.h +++ b/src/Items/ItemBucket.h @@ -5,6 +5,7 @@ #include "../World.h" #include "../Simulator/FluidSimulator.h" #include "../Blocks/BlockHandler.h" +#include "../LineBlockTracer.h" @@ -39,45 +40,34 @@ public: bool ScoopUpFluid(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace) { - if (a_BlockFace < 0) + if (a_BlockFace > 0) { return false; } - AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace); - BLOCKTYPE ClickedBlock; - NIBBLETYPE ClickedMeta; - a_World->GetBlockTypeMeta(a_BlockX, a_BlockY, a_BlockZ, ClickedBlock, ClickedMeta); - LOGD("Bucket Clicked BlockType %d, meta %d", ClickedBlock, ClickedMeta); - if (ClickedMeta != 0) + + Vector3i BlockPos; + GetBlockFromTrace(a_World, a_Player, BlockPos); + + if (a_World->GetBlockMeta(BlockPos.x, BlockPos.y, BlockPos.z) != 0) { // Not a source block return false; } - - if (a_Player->GetGameMode() == gmCreative) + + BLOCKTYPE Block = a_World->GetBlock(BlockPos.x, BlockPos.y, BlockPos.z); + ENUM_ITEM_ID NewItem; + + if (IsBlockWater(Block)) { - // In creative mode don't modify the inventory, just remove the fluid: - a_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0); - return true; + NewItem = E_ITEM_WATER_BUCKET; } - - ENUM_ITEM_ID NewItem = E_ITEM_EMPTY; - switch (ClickedBlock) + else if (IsBlockLava(Block)) { - case E_BLOCK_WATER: - case E_BLOCK_STATIONARY_WATER: - { - NewItem = E_ITEM_WATER_BUCKET; - break; - } - case E_BLOCK_LAVA: - case E_BLOCK_STATIONARY_LAVA: - { - NewItem = E_ITEM_LAVA_BUCKET; - break; - } - - default: return false; + NewItem = E_ITEM_LAVA_BUCKET; + } + else + { + return false; } // Remove the bucket from the inventory @@ -89,11 +79,10 @@ public: } // Give new bucket, filled with fluid: - cItem Item(NewItem, 1); - a_Player->GetInventory().AddItem(Item, true, true); + a_Player->GetInventory().AddItem(cItem(NewItem), true, true); // Remove water / lava block - a_Player->GetWorld()->SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0); + a_Player->GetWorld()->SetBlock(BlockPos.x, BlockPos.y, BlockPos.z, E_BLOCK_AIR, 0); return true; } @@ -157,4 +146,36 @@ public: return true; } + bool GetBlockFromTrace(cWorld * a_World, cPlayer * a_Player, Vector3i & BlockPos) + { + class cCallbacks : + public cBlockTracer::cCallbacks + { + public: + Vector3d Pos; + virtual bool OnNextBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, char a_EntryFace) override + { + if (a_BlockMeta != 0) // Even if it was a water block it would not be a source. + { + return false; + } + if ((IsBlockWater(a_BlockType)) || (IsBlockLava(a_BlockType))) + { + Pos = Vector3d(a_BlockX, a_BlockY, a_BlockZ); + return true; + } + return false; + } + } Callbacks; + + cLineBlockTracer Tracer(*a_World, Callbacks); + Vector3d Start(a_Player->GetEyePosition() + a_Player->GetLookVector()); + Vector3d End(a_Player->GetEyePosition() + a_Player->GetLookVector() * 5); + + Tracer.Trace(Start.x, Start.y, Start.z, End.x, End.y, End.z); + + BlockPos.Set((int) Callbacks.Pos.x, (int) Callbacks.Pos.y, (int) Callbacks.Pos.z); + return true; + } + }; -- cgit v1.2.3 From f1a1d6fa5c64a88d9b72d70e70c085ce75830933 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Tue, 17 Dec 2013 19:42:06 +0100 Subject: Using Recommendations. --- src/Items/ItemBucket.h | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) (limited to 'src/Items') diff --git a/src/Items/ItemBucket.h b/src/Items/ItemBucket.h index 87f23b554..4cddd64d8 100644 --- a/src/Items/ItemBucket.h +++ b/src/Items/ItemBucket.h @@ -46,7 +46,10 @@ public: } Vector3i BlockPos; - GetBlockFromTrace(a_World, a_Player, BlockPos); + if (!GetBlockFromTrace(a_World, a_Player, BlockPos)) + { + return false; // Nothing in range. + } if (a_World->GetBlockMeta(BlockPos.x, BlockPos.y, BlockPos.z) != 0) { @@ -70,16 +73,18 @@ public: return false; } - // Remove the bucket from the inventory - if (!a_Player->GetInventory().RemoveOneEquippedItem()) + // Give new bucket, filled with fluid when the gamemode is not creative: + if (!a_Player->IsGameModeCreative()) { - LOG("Clicked with an empty bucket, but cannot remove one from the inventory? WTF?"); - ASSERT(!"Inventory bucket mismatch"); - return true; + // Remove the bucket from the inventory + if (!a_Player->GetInventory().RemoveOneEquippedItem()) + { + LOG("Clicked with an empty bucket, but cannot remove one from the inventory? WTF?"); + ASSERT(!"Inventory bucket mismatch"); + return true; + } + a_Player->GetInventory().AddItem(cItem(NewItem), true, true); } - - // Give new bucket, filled with fluid: - a_Player->GetInventory().AddItem(cItem(NewItem), true, true); // Remove water / lava block a_Player->GetWorld()->SetBlock(BlockPos.x, BlockPos.y, BlockPos.z, E_BLOCK_AIR, 0); @@ -153,14 +158,16 @@ public: { public: Vector3d Pos; + bool HitFluid; virtual bool OnNextBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, char a_EntryFace) override { if (a_BlockMeta != 0) // Even if it was a water block it would not be a source. { return false; } - if ((IsBlockWater(a_BlockType)) || (IsBlockLava(a_BlockType))) + if (IsBlockWater(a_BlockType) || IsBlockLava(a_BlockType)) { + HitFluid = true; Pos = Vector3d(a_BlockX, a_BlockY, a_BlockZ); return true; } @@ -174,6 +181,12 @@ public: Tracer.Trace(Start.x, Start.y, Start.z, End.x, End.y, End.z); + if (!Callbacks.HitFluid) + { + return false; + } + + BlockPos.Set((int) Callbacks.Pos.x, (int) Callbacks.Pos.y, (int) Callbacks.Pos.z); return true; } -- cgit v1.2.3 From a1bfc8911846ccd9e4aaf36ee7759ab73d5d9844 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Tue, 17 Dec 2013 20:02:44 +0100 Subject: Renamed Pos to m_Pos. --- src/Items/ItemBucket.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/Items') diff --git a/src/Items/ItemBucket.h b/src/Items/ItemBucket.h index 4cddd64d8..4f55db7f8 100644 --- a/src/Items/ItemBucket.h +++ b/src/Items/ItemBucket.h @@ -157,7 +157,7 @@ public: public cBlockTracer::cCallbacks { public: - Vector3d Pos; + Vector3i m_Pos; bool HitFluid; virtual bool OnNextBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, char a_EntryFace) override { @@ -168,7 +168,7 @@ public: if (IsBlockWater(a_BlockType) || IsBlockLava(a_BlockType)) { HitFluid = true; - Pos = Vector3d(a_BlockX, a_BlockY, a_BlockZ); + m_Pos = Vector3d(a_BlockX, a_BlockY, a_BlockZ); return true; } return false; @@ -187,7 +187,7 @@ public: } - BlockPos.Set((int) Callbacks.Pos.x, (int) Callbacks.Pos.y, (int) Callbacks.Pos.z); + BlockPos.Set(Callbacks.m_Pos.x, Callbacks.m_Pos.y, Callbacks.m_Pos.z); return true; } -- cgit v1.2.3 From a74fdd902350d76aaad65cfc892dc0abbb59e792 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Tue, 17 Dec 2013 20:04:39 +0100 Subject: Forgot to change one Vector3d to Vector3i. --- src/Items/ItemBucket.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Items') diff --git a/src/Items/ItemBucket.h b/src/Items/ItemBucket.h index 4f55db7f8..9d1fc276b 100644 --- a/src/Items/ItemBucket.h +++ b/src/Items/ItemBucket.h @@ -168,7 +168,7 @@ public: if (IsBlockWater(a_BlockType) || IsBlockLava(a_BlockType)) { HitFluid = true; - m_Pos = Vector3d(a_BlockX, a_BlockY, a_BlockZ); + m_Pos = Vector3i(a_BlockX, a_BlockY, a_BlockZ); return true; } return false; -- cgit v1.2.3 From a4f4ba534ee288c61a579986474296d3910f91e3 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 17 Dec 2013 20:06:48 +0100 Subject: Fixed naming and initialization. --- src/Items/ItemBucket.h | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src/Items') diff --git a/src/Items/ItemBucket.h b/src/Items/ItemBucket.h index 9d1fc276b..c9a632580 100644 --- a/src/Items/ItemBucket.h +++ b/src/Items/ItemBucket.h @@ -151,6 +151,7 @@ public: return true; } + bool GetBlockFromTrace(cWorld * a_World, cPlayer * a_Player, Vector3i & BlockPos) { class cCallbacks : @@ -158,7 +159,14 @@ public: { public: Vector3i m_Pos; - bool HitFluid; + bool m_HasHitFluid; + + + cCallbacks(void) : + m_HasHitFluid(false) + { + } + virtual bool OnNextBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, char a_EntryFace) override { if (a_BlockMeta != 0) // Even if it was a water block it would not be a source. @@ -167,8 +175,8 @@ public: } if (IsBlockWater(a_BlockType) || IsBlockLava(a_BlockType)) { - HitFluid = true; - m_Pos = Vector3i(a_BlockX, a_BlockY, a_BlockZ); + m_HasHitFluid = true; + m_Pos.Set(a_BlockX, a_BlockY, a_BlockZ); return true; } return false; @@ -181,7 +189,7 @@ public: Tracer.Trace(Start.x, Start.y, Start.z, End.x, End.y, End.z); - if (!Callbacks.HitFluid) + if (!Callbacks.m_HasHitFluid) { return false; } -- cgit v1.2.3 From ffca4f94c180f6241eaf3b0f394cbc28bfb8483d Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Wed, 18 Dec 2013 18:33:18 +0100 Subject: Implented Nether Wart. --- src/Items/ItemHandler.cpp | 2 ++ src/Items/ItemNetherWart.h | 54 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 src/Items/ItemNetherWart.h (limited to 'src/Items') diff --git a/src/Items/ItemHandler.cpp b/src/Items/ItemHandler.cpp index 92ba94999..23b9a86d4 100644 --- a/src/Items/ItemHandler.cpp +++ b/src/Items/ItemHandler.cpp @@ -23,6 +23,7 @@ #include "ItemLeaves.h" #include "ItemLighter.h" #include "ItemMinecart.h" +#include "ItemNetherWart.h" #include "ItemPickaxe.h" #include "ItemThrowable.h" #include "ItemRedstoneDust.h" @@ -101,6 +102,7 @@ cItemHandler *cItemHandler::CreateItemHandler(int a_ItemType) case E_ITEM_FIREWORK_ROCKET: return new cItemFireworkHandler(); case E_ITEM_FLINT_AND_STEEL: return new cItemLighterHandler(a_ItemType); case E_ITEM_FLOWER_POT: return new cItemFlowerPotHandler(a_ItemType); + case E_ITEM_NETHER_WART: return new cItemNetherWartHandler(a_ItemType); case E_ITEM_REDSTONE_DUST: return new cItemRedstoneDustHandler(a_ItemType); case E_ITEM_REDSTONE_REPEATER: return new cItemRedstoneRepeaterHandler(a_ItemType); case E_ITEM_SHEARS: return new cItemShearsHandler(a_ItemType); diff --git a/src/Items/ItemNetherWart.h b/src/Items/ItemNetherWart.h new file mode 100644 index 000000000..aa4a44340 --- /dev/null +++ b/src/Items/ItemNetherWart.h @@ -0,0 +1,54 @@ + +#pragma once + +#include "ItemHandler.h" +#include "../World.h" + + + + + +class cItemNetherWartHandler : + public cItemHandler +{ +public: + cItemNetherWartHandler(int a_ItemType) : + cItemHandler(a_ItemType) + { + + } + + virtual bool IsPlaceable(void) override + { + return true; + } + + virtual bool GetPlacementBlockTypeMeta( + cWorld * a_World, cPlayer * a_Player, + int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, + int a_CursorX, int a_CursorY, int a_CursorZ, + BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta + ) override + { + if (a_BlockFace != BLOCK_FACE_TOP) + { + // Only allow planting nether wart from the top side of the block + return false; + } + + // Only allow placement on farmland + int X = a_BlockX; + int Y = a_BlockY; + int Z = a_BlockZ; + AddFaceDirection(X, Y, Z, a_BlockFace, true); + if (a_World->GetBlock(X, Y, Z) != E_BLOCK_SOULSAND) + { + return false; + } + + a_BlockMeta = 0; + a_BlockType = E_BLOCK_NETHER_WART; + + return true; + } +} ; \ No newline at end of file -- cgit v1.2.3