From 4df23d19b7be2f274974e3dfe91e716e6296f11c Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Sat, 29 Sep 2012 13:59:32 +0000 Subject: Unified folder name-casing git-svn-id: http://mc-server.googlecode.com/svn/trunk@902 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/Blocks/BlockBed.h | 123 +++++++++ source/Blocks/BlockCactus.h | 64 +++++ source/Blocks/BlockChest.h | 26 ++ source/Blocks/BlockCloth.h | 23 ++ source/Blocks/BlockCrops.h | 64 +++++ source/Blocks/BlockDirt.h | 72 +++++ source/Blocks/BlockDispenser.h | 22 ++ source/Blocks/BlockDoor.cpp | 74 ++++++ source/Blocks/BlockDoor.h | 31 +++ source/Blocks/BlockEntity.h | 31 +++ source/Blocks/BlockFire.h | 33 +++ source/Blocks/BlockFlower.h | 38 +++ source/Blocks/BlockFluid.h | 20 ++ source/Blocks/BlockFurnace.h | 27 ++ source/Blocks/BlockGlowstone.h | 22 ++ source/Blocks/BlockGravel.h | 18 ++ source/Blocks/BlockHandler.cpp | 448 ++++++++++++++++++++++++++++++++ source/Blocks/BlockHandler.h | 90 +++++++ source/Blocks/BlockIce.h | 26 ++ source/Blocks/BlockLadder.h | 40 +++ source/Blocks/BlockLeaves.h | 167 ++++++++++++ source/Blocks/BlockMelon.h | 29 +++ source/Blocks/BlockMushroom.h | 47 ++++ source/Blocks/BlockNote.h | 13 + source/Blocks/BlockOre.h | 58 +++++ source/Blocks/BlockPiston.cpp | 51 ++++ source/Blocks/BlockPiston.h | 15 ++ source/Blocks/BlockRedstone.cpp | 41 +++ source/Blocks/BlockRedstone.h | 33 +++ source/Blocks/BlockRedstoneRepeater.cpp | 39 +++ source/Blocks/BlockRedstoneRepeater.h | 52 ++++ source/Blocks/BlockRedstoneTorch.h | 28 ++ source/Blocks/BlockSand.h | 18 ++ source/Blocks/BlockSapling.h | 56 ++++ source/Blocks/BlockSign.h | 47 ++++ source/Blocks/BlockSlab.h | 51 ++++ source/Blocks/BlockSnow.h | 44 ++++ source/Blocks/BlockStairs.h | 22 ++ source/Blocks/BlockStems.h | 46 ++++ source/Blocks/BlockStone.h | 18 ++ source/Blocks/BlockSugarcane.h | 71 +++++ source/Blocks/BlockTallGrass.h | 41 +++ source/Blocks/BlockTorch.h | 166 ++++++++++++ source/Blocks/BlockVine.h | 35 +++ source/Blocks/BlockWood.h | 22 ++ source/Blocks/BlockWorkbench.h | 36 +++ source/Chunk.cpp | 2 +- source/ClientHandle.cpp | 4 +- source/FluidSimulator.cpp | 2 +- source/Inventory.cpp | 2 +- source/Items/ItemBed.h | 25 ++ source/Items/ItemBucket.h | 94 +++++++ source/Items/ItemCloth.h | 23 ++ source/Items/ItemDoor.h | 26 ++ source/Items/ItemDye.h | 35 +++ source/Items/ItemFood.h | 56 ++++ source/Items/ItemHandler.cpp | 422 ++++++++++++++++++++++++++++++ source/Items/ItemHandler.h | 83 ++++++ source/Items/ItemHoe.h | 31 +++ source/Items/ItemLeaves.h | 27 ++ source/Items/ItemLighter.h | 27 ++ source/Items/ItemPickaxe.h | 75 ++++++ source/Items/ItemRedstoneDust.h | 36 +++ source/Items/ItemRedstoneRepeater.h | 36 +++ source/Items/ItemSapling.h | 28 ++ source/Items/ItemSeeds.h | 59 +++++ source/Items/ItemShears.h | 42 +++ source/Items/ItemShovel.h | 41 +++ source/Items/ItemSign.h | 26 ++ source/Items/ItemSlab.h | 45 ++++ source/Items/ItemSugarcane.h | 39 +++ source/Items/ItemSword.h | 21 ++ source/Items/ItemWood.h | 22 ++ source/Piston.cpp | 2 +- source/Root.cpp | 4 +- source/UI/Window.cpp | 2 +- source/World.cpp | 2 +- source/blocks/BlockBed.h | 123 --------- source/blocks/BlockCactus.h | 64 ----- source/blocks/BlockChest.h | 26 -- source/blocks/BlockCloth.h | 23 -- source/blocks/BlockCrops.h | 64 ----- source/blocks/BlockDirt.h | 72 ----- source/blocks/BlockDispenser.h | 22 -- source/blocks/BlockDoor.cpp | 74 ------ source/blocks/BlockDoor.h | 31 --- source/blocks/BlockEntity.h | 31 --- source/blocks/BlockFire.h | 33 --- source/blocks/BlockFlower.h | 38 --- source/blocks/BlockFluid.h | 20 -- source/blocks/BlockFurnace.h | 27 -- source/blocks/BlockGlowstone.h | 22 -- source/blocks/BlockGravel.h | 18 -- source/blocks/BlockHandler.cpp | 448 -------------------------------- source/blocks/BlockHandler.h | 90 ------- source/blocks/BlockIce.h | 26 -- source/blocks/BlockLadder.h | 40 --- source/blocks/BlockLeaves.h | 167 ------------ source/blocks/BlockMelon.h | 29 --- source/blocks/BlockMushroom.h | 47 ---- source/blocks/BlockNote.h | 13 - source/blocks/BlockOre.h | 58 ----- source/blocks/BlockPiston.cpp | 51 ---- source/blocks/BlockPiston.h | 15 -- source/blocks/BlockRedstone.cpp | 41 --- source/blocks/BlockRedstone.h | 33 --- source/blocks/BlockRedstoneRepeater.cpp | 39 --- source/blocks/BlockRedstoneRepeater.h | 52 ---- source/blocks/BlockRedstoneTorch.h | 28 -- source/blocks/BlockSand.h | 18 -- source/blocks/BlockSapling.h | 56 ---- source/blocks/BlockSign.h | 47 ---- source/blocks/BlockSlab.h | 51 ---- source/blocks/BlockSnow.h | 44 ---- source/blocks/BlockStairs.h | 22 -- source/blocks/BlockStems.h | 46 ---- source/blocks/BlockStone.h | 18 -- source/blocks/BlockSugarcane.h | 71 ----- source/blocks/BlockTallGrass.h | 41 --- source/blocks/BlockTorch.h | 166 ------------ source/blocks/BlockVine.h | 35 --- source/blocks/BlockWood.h | 22 -- source/blocks/BlockWorkbench.h | 36 --- source/items/ItemBed.h | 25 -- source/items/ItemBucket.h | 94 ------- source/items/ItemCloth.h | 23 -- source/items/ItemDoor.h | 26 -- source/items/ItemDye.h | 35 --- source/items/ItemFood.h | 56 ---- source/items/ItemHandler.cpp | 422 ------------------------------ source/items/ItemHandler.h | 83 ------ source/items/ItemHoe.h | 31 --- source/items/ItemLeaves.h | 27 -- source/items/ItemLighter.h | 27 -- source/items/ItemPickaxe.h | 75 ------ source/items/ItemRedstoneDust.h | 36 --- source/items/ItemRedstoneRepeater.h | 36 --- source/items/ItemSapling.h | 28 -- source/items/ItemSeeds.h | 59 ----- source/items/ItemShears.h | 42 --- source/items/ItemShovel.h | 41 --- source/items/ItemSign.h | 26 -- source/items/ItemSlab.h | 45 ---- source/items/ItemSugarcane.h | 39 --- source/items/ItemSword.h | 21 -- source/items/ItemWood.h | 22 -- 146 files changed, 3867 insertions(+), 3867 deletions(-) create mode 100644 source/Blocks/BlockBed.h create mode 100644 source/Blocks/BlockCactus.h create mode 100644 source/Blocks/BlockChest.h create mode 100644 source/Blocks/BlockCloth.h create mode 100644 source/Blocks/BlockCrops.h create mode 100644 source/Blocks/BlockDirt.h create mode 100644 source/Blocks/BlockDispenser.h create mode 100644 source/Blocks/BlockDoor.cpp create mode 100644 source/Blocks/BlockDoor.h create mode 100644 source/Blocks/BlockEntity.h create mode 100644 source/Blocks/BlockFire.h create mode 100644 source/Blocks/BlockFlower.h create mode 100644 source/Blocks/BlockFluid.h create mode 100644 source/Blocks/BlockFurnace.h create mode 100644 source/Blocks/BlockGlowstone.h create mode 100644 source/Blocks/BlockGravel.h create mode 100644 source/Blocks/BlockHandler.cpp create mode 100644 source/Blocks/BlockHandler.h create mode 100644 source/Blocks/BlockIce.h create mode 100644 source/Blocks/BlockLadder.h create mode 100644 source/Blocks/BlockLeaves.h create mode 100644 source/Blocks/BlockMelon.h create mode 100644 source/Blocks/BlockMushroom.h create mode 100644 source/Blocks/BlockNote.h create mode 100644 source/Blocks/BlockOre.h create mode 100644 source/Blocks/BlockPiston.cpp create mode 100644 source/Blocks/BlockPiston.h create mode 100644 source/Blocks/BlockRedstone.cpp create mode 100644 source/Blocks/BlockRedstone.h create mode 100644 source/Blocks/BlockRedstoneRepeater.cpp create mode 100644 source/Blocks/BlockRedstoneRepeater.h create mode 100644 source/Blocks/BlockRedstoneTorch.h create mode 100644 source/Blocks/BlockSand.h create mode 100644 source/Blocks/BlockSapling.h create mode 100644 source/Blocks/BlockSign.h create mode 100644 source/Blocks/BlockSlab.h create mode 100644 source/Blocks/BlockSnow.h create mode 100644 source/Blocks/BlockStairs.h create mode 100644 source/Blocks/BlockStems.h create mode 100644 source/Blocks/BlockStone.h create mode 100644 source/Blocks/BlockSugarcane.h create mode 100644 source/Blocks/BlockTallGrass.h create mode 100644 source/Blocks/BlockTorch.h create mode 100644 source/Blocks/BlockVine.h create mode 100644 source/Blocks/BlockWood.h create mode 100644 source/Blocks/BlockWorkbench.h create mode 100644 source/Items/ItemBed.h create mode 100644 source/Items/ItemBucket.h create mode 100644 source/Items/ItemCloth.h create mode 100644 source/Items/ItemDoor.h create mode 100644 source/Items/ItemDye.h create mode 100644 source/Items/ItemFood.h create mode 100644 source/Items/ItemHandler.cpp create mode 100644 source/Items/ItemHandler.h create mode 100644 source/Items/ItemHoe.h create mode 100644 source/Items/ItemLeaves.h create mode 100644 source/Items/ItemLighter.h create mode 100644 source/Items/ItemPickaxe.h create mode 100644 source/Items/ItemRedstoneDust.h create mode 100644 source/Items/ItemRedstoneRepeater.h create mode 100644 source/Items/ItemSapling.h create mode 100644 source/Items/ItemSeeds.h create mode 100644 source/Items/ItemShears.h create mode 100644 source/Items/ItemShovel.h create mode 100644 source/Items/ItemSign.h create mode 100644 source/Items/ItemSlab.h create mode 100644 source/Items/ItemSugarcane.h create mode 100644 source/Items/ItemSword.h create mode 100644 source/Items/ItemWood.h delete mode 100644 source/blocks/BlockBed.h delete mode 100644 source/blocks/BlockCactus.h delete mode 100644 source/blocks/BlockChest.h delete mode 100644 source/blocks/BlockCloth.h delete mode 100644 source/blocks/BlockCrops.h delete mode 100644 source/blocks/BlockDirt.h delete mode 100644 source/blocks/BlockDispenser.h delete mode 100644 source/blocks/BlockDoor.cpp delete mode 100644 source/blocks/BlockDoor.h delete mode 100644 source/blocks/BlockEntity.h delete mode 100644 source/blocks/BlockFire.h delete mode 100644 source/blocks/BlockFlower.h delete mode 100644 source/blocks/BlockFluid.h delete mode 100644 source/blocks/BlockFurnace.h delete mode 100644 source/blocks/BlockGlowstone.h delete mode 100644 source/blocks/BlockGravel.h delete mode 100644 source/blocks/BlockHandler.cpp delete mode 100644 source/blocks/BlockHandler.h delete mode 100644 source/blocks/BlockIce.h delete mode 100644 source/blocks/BlockLadder.h delete mode 100644 source/blocks/BlockLeaves.h delete mode 100644 source/blocks/BlockMelon.h delete mode 100644 source/blocks/BlockMushroom.h delete mode 100644 source/blocks/BlockNote.h delete mode 100644 source/blocks/BlockOre.h delete mode 100644 source/blocks/BlockPiston.cpp delete mode 100644 source/blocks/BlockPiston.h delete mode 100644 source/blocks/BlockRedstone.cpp delete mode 100644 source/blocks/BlockRedstone.h delete mode 100644 source/blocks/BlockRedstoneRepeater.cpp delete mode 100644 source/blocks/BlockRedstoneRepeater.h delete mode 100644 source/blocks/BlockRedstoneTorch.h delete mode 100644 source/blocks/BlockSand.h delete mode 100644 source/blocks/BlockSapling.h delete mode 100644 source/blocks/BlockSign.h delete mode 100644 source/blocks/BlockSlab.h delete mode 100644 source/blocks/BlockSnow.h delete mode 100644 source/blocks/BlockStairs.h delete mode 100644 source/blocks/BlockStems.h delete mode 100644 source/blocks/BlockStone.h delete mode 100644 source/blocks/BlockSugarcane.h delete mode 100644 source/blocks/BlockTallGrass.h delete mode 100644 source/blocks/BlockTorch.h delete mode 100644 source/blocks/BlockVine.h delete mode 100644 source/blocks/BlockWood.h delete mode 100644 source/blocks/BlockWorkbench.h delete mode 100644 source/items/ItemBed.h delete mode 100644 source/items/ItemBucket.h delete mode 100644 source/items/ItemCloth.h delete mode 100644 source/items/ItemDoor.h delete mode 100644 source/items/ItemDye.h delete mode 100644 source/items/ItemFood.h delete mode 100644 source/items/ItemHandler.cpp delete mode 100644 source/items/ItemHandler.h delete mode 100644 source/items/ItemHoe.h delete mode 100644 source/items/ItemLeaves.h delete mode 100644 source/items/ItemLighter.h delete mode 100644 source/items/ItemPickaxe.h delete mode 100644 source/items/ItemRedstoneDust.h delete mode 100644 source/items/ItemRedstoneRepeater.h delete mode 100644 source/items/ItemSapling.h delete mode 100644 source/items/ItemSeeds.h delete mode 100644 source/items/ItemShears.h delete mode 100644 source/items/ItemShovel.h delete mode 100644 source/items/ItemSign.h delete mode 100644 source/items/ItemSlab.h delete mode 100644 source/items/ItemSugarcane.h delete mode 100644 source/items/ItemSword.h delete mode 100644 source/items/ItemWood.h (limited to 'source') diff --git a/source/Blocks/BlockBed.h b/source/Blocks/BlockBed.h new file mode 100644 index 000000000..cbef5bb4d --- /dev/null +++ b/source/Blocks/BlockBed.h @@ -0,0 +1,123 @@ +#pragma once +#include "BlockHandler.h" +#include "../World.h" +#include "../Sign.h" +#include "../Player.h" + +class cBlockBedHandler : public cBlockHandler +{ +public: + cBlockBedHandler(BLOCKTYPE a_BlockID) + : cBlockHandler(a_BlockID) + { + + } + + + + + + virtual void PlaceBlock(cWorld *a_World, cPlayer *a_Player, NIBBLETYPE a_BlockMeta, int a_X, int a_Y, int a_Z, char a_Dir) override + { + if( a_Dir != 1 ) // Can only be placed on the floor + return; + + NIBBLETYPE Meta = RotationToMetaData( a_Player->GetRotation() ); + Vector3i Direction = MetaDataToDirection( Meta ); + + if (a_World->GetBlock(a_X+Direction.x, a_Y, a_Z+Direction.z) != E_BLOCK_AIR) + { + return; + } + + a_World->SetBlock(a_X, a_Y, a_Z, E_BLOCK_BED, Meta); + a_World->SetBlock(a_X + Direction.x, a_Y, a_Z + Direction.z, E_BLOCK_BED, Meta | 0x8); + + OnPlacedByPlayer(a_World, a_Player, a_X, a_Y, a_Z, a_Dir); + } + + + + + + virtual void OnDestroyed(cWorld *a_World, int a_X, int a_Y, int a_Z) override + { + char OldMeta = a_World->GetBlockMeta(a_X, a_Y, a_Z); + + Vector3i ThisPos( a_X, a_Y, a_Z ); + Vector3i Direction = MetaDataToDirection( OldMeta & 0x7 ); + if (OldMeta & 0x8) + { + // Was pillow + if (a_World->GetBlock(ThisPos - Direction) == E_BLOCK_BED) + { + a_World->FastSetBlock(ThisPos - Direction, E_BLOCK_AIR, 0); + } + } + else + { + // Was foot end + if (a_World->GetBlock(ThisPos + Direction) == E_BLOCK_BED) + { + a_World->FastSetBlock(ThisPos + Direction, E_BLOCK_AIR, 0); + } + } + } + + + + + + virtual int GetDropID() override + { + return E_ITEM_BED; + } + + virtual NIBBLETYPE GetDropMeta(NIBBLETYPE a_BlockMeta) override + { + return 0; + } + + + + + + virtual bool AllowBlockOnTop() override + { + return false; + } + + + + + + static NIBBLETYPE RotationToMetaData( float a_Rotation ) + { + a_Rotation += 180 + (180/4); // So its not aligned with axis + if( a_Rotation > 360.f ) a_Rotation -= 360.f; + + a_Rotation = (a_Rotation/360) * 4; + + return ((char)a_Rotation+2) % 4; + } + + + + + + static Vector3i MetaDataToDirection( NIBBLETYPE a_MetaData ) + { + switch( a_MetaData ) + { + case 0: // south +z + return Vector3i(0, 0, 1); + case 1: // west -x + return Vector3i(-1, 0, 0); + case 2: // north -z + return Vector3i(0, 0, -1); + case 3: // east +x + return Vector3i(1, 0, 0); + }; + return Vector3i(); + } +}; diff --git a/source/Blocks/BlockCactus.h b/source/Blocks/BlockCactus.h new file mode 100644 index 000000000..964646299 --- /dev/null +++ b/source/Blocks/BlockCactus.h @@ -0,0 +1,64 @@ + +#pragma once +#include "BlockHandler.h" + + + + + +class cBlockCactusHandler : + public cBlockHandler +{ +public: + cBlockCactusHandler(BLOCKTYPE a_BlockID) + : cBlockHandler(a_BlockID) + { + } + + + virtual NIBBLETYPE GetDropMeta(NIBBLETYPE a_BlockMeta) override + { + return 0; + } + + + virtual bool CanBeAt(cWorld * a_World, int a_X, int a_Y, int a_Z) override + { + BLOCKTYPE Surface = a_World->GetBlock(a_X, a_Y - 1, a_Z); + if ((Surface != E_BLOCK_SAND) && (Surface != E_BLOCK_CACTUS)) + { + // Cactus can only be placed on sand and itself + return false; + } + + // Check surroundings. Cacti may ONLY be surrounded by air + if ( + (a_World->GetBlock(a_X - 1, a_Y, a_Z) != E_BLOCK_AIR) || + (a_World->GetBlock(a_X + 1, a_Y, a_Z) != E_BLOCK_AIR) || + (a_World->GetBlock(a_X, a_Y, a_Z - 1) != E_BLOCK_AIR) || + (a_World->GetBlock(a_X, a_Y, a_Z + 1) != E_BLOCK_AIR) + ) + { + return false; + } + + return true; + } + + + virtual bool CanBePlacedOnSide() override + { + return false; + } + + + virtual AString GetStepSound(void) override + { + return "step.cloth"; + } + +}; + + + + diff --git a/source/Blocks/BlockChest.h b/source/Blocks/BlockChest.h new file mode 100644 index 000000000..db67fe1c8 --- /dev/null +++ b/source/Blocks/BlockChest.h @@ -0,0 +1,26 @@ +#pragma once +#include "BlockEntity.h" +#include "../World.h" +#include "../Piston.h" +#include "../Player.h" + +class cBlockChestHandler : public cBlockEntityHandler +{ +public: + cBlockChestHandler(BLOCKTYPE a_BlockID) + : cBlockEntityHandler(a_BlockID) + { + } + + virtual void PlaceBlock(cWorld *a_World, cPlayer *a_Player, NIBBLETYPE a_BlockMeta, int a_X, int a_Y, int a_Z, char a_Dir) override + { + a_World->SetBlock(a_X, a_Y, a_Z, m_BlockID, cPiston::RotationPitchToMetaData(a_Player->GetRotation(), 0)); + OnPlacedByPlayer(a_World, a_Player, a_X, a_Y, a_Z, a_Dir); + } + + virtual AString GetStepSound(void) override + { + return "step.wood"; + } + +}; diff --git a/source/Blocks/BlockCloth.h b/source/Blocks/BlockCloth.h new file mode 100644 index 000000000..452ad2237 --- /dev/null +++ b/source/Blocks/BlockCloth.h @@ -0,0 +1,23 @@ +#pragma once +#include "BlockHandler.h" + + +class cBlockClothHandler : public cBlockHandler +{ +public: + cBlockClothHandler(BLOCKTYPE a_BlockID) + : cBlockHandler(a_BlockID) + { + } + + virtual NIBBLETYPE GetDropMeta(NIBBLETYPE a_BlockMeta) override + { + return a_BlockMeta; + } + + virtual AString GetStepSound(void) override + { + return "step.cloth"; + } + +}; diff --git a/source/Blocks/BlockCrops.h b/source/Blocks/BlockCrops.h new file mode 100644 index 000000000..b30139e79 --- /dev/null +++ b/source/Blocks/BlockCrops.h @@ -0,0 +1,64 @@ +#pragma once +#include "BlockHandler.h" +#include "../MersenneTwister.h" +#include "../World.h" + +class cBlockCropsHandler : public cBlockHandler +{ +public: + cBlockCropsHandler(BLOCKTYPE a_BlockID) + : cBlockHandler(a_BlockID) + { + } + + virtual bool NeedsRandomTicks() override + { + return true; + } + + virtual bool AllowBlockOnTop() override + { + return false; + } + + virtual int GetDropID() override + { + return E_ITEM_EMPTY; + } + + virtual void OnDestroyed(cWorld *a_World, int a_X, int a_Y, int a_Z) override + { + MTRand rand; + NIBBLETYPE Meta = a_World->GetBlockMeta(a_X, a_Y, a_Z); + + cItems Drops; + + if(Meta & 0x7) //Is Wheat + { + Drops.push_back(cItem(E_ITEM_WHEAT, 1, 0)); + } + if(rand.randInt(3) == 0) + { //Drop an second seed + Drops.push_back(cItem(E_ITEM_SEEDS, 1, 0)); + } + Drops.push_back(cItem(E_ITEM_SEEDS, 1, 0)); + a_World->SpawnItemPickups(Drops, a_X, a_Y, a_Z); + } + + void OnUpdate(cWorld *a_World, int a_X, int a_Y, int a_Z) override + { + + //TODO: Handle Growing here + } + + virtual bool CanBeAt(cWorld *a_World, int a_X, int a_Y, int a_Z) override + { + return a_World->GetBlock(a_X, a_Y - 1, a_Z) == E_BLOCK_FARMLAND; + } + + virtual AString GetStepSound(void) override + { + return "step.grass"; + } + +}; diff --git a/source/Blocks/BlockDirt.h b/source/Blocks/BlockDirt.h new file mode 100644 index 000000000..5a2487f1b --- /dev/null +++ b/source/Blocks/BlockDirt.h @@ -0,0 +1,72 @@ +#pragma once +#include "BlockHandler.h" +#include "../MersenneTwister.h" +#include "../World.h" + +class cBlockDirtHandler : public cBlockHandler +{ +public: + cBlockDirtHandler(BLOCKTYPE a_BlockID) + : cBlockHandler(a_BlockID) + { + } + + + virtual bool NeedsRandomTicks() override + { + return m_BlockID == E_BLOCK_GRASS; + } + + virtual int GetDropID() override + { + return E_BLOCK_DIRT; + } + + + void OnUpdate(cWorld *a_World, int a_X, int a_Y, int a_Z) override + { + if (m_BlockID != E_BLOCK_GRASS) + { + return; + } + + // Grass becomes dirt if there is something on top of it: + BLOCKTYPE Above = a_World->GetBlock(a_X, a_Y + 1, a_Z); + if (!g_BlockTransparent[Above] && !g_BlockOneHitDig[Above]) + { + a_World->FastSetBlock(a_X, a_Y, a_Z, E_BLOCK_DIRT, 0); + return; + } + + // Grass spreads to adjacent blocks: + MTRand rand; + for (int i = 0; i < 2; i++) // Pick two blocks to grow to + { + int OfsX = rand.randInt(2) - 1; // [-1 .. 1] + int OfsY = rand.randInt(4) - 3; // [-3 .. 1] + int OfsZ = rand.randInt(2) - 1; // [-1 .. 1] + + BLOCKTYPE DestBlock; + NIBBLETYPE DestMeta; + a_World->GetBlockTypeMeta(a_X + OfsX, a_Y + OfsY, a_Z + OfsZ, DestBlock, DestMeta); + if(DestBlock != E_BLOCK_DIRT) + { + continue; + } + + BLOCKTYPE AboveDest; + NIBBLETYPE AboveMeta; + a_World->GetBlockTypeMeta(a_X + OfsX, a_Y + OfsY + 1, a_Z + OfsZ, AboveDest, AboveMeta); + if (g_BlockOneHitDig[AboveDest] || g_BlockTransparent[AboveDest]) + { + a_World->FastSetBlock(a_X + OfsX, a_Y + OfsY, a_Z + OfsZ, E_BLOCK_GRASS, 0); + } + } // for i - repeat twice + } + + virtual AString GetStepSound(void) override + { + return "step.gravel"; + } + +}; diff --git a/source/Blocks/BlockDispenser.h b/source/Blocks/BlockDispenser.h new file mode 100644 index 000000000..eee75a39a --- /dev/null +++ b/source/Blocks/BlockDispenser.h @@ -0,0 +1,22 @@ +#pragma once +#include "BlockEntity.h" +#include "../World.h" +#include "../Piston.h" +#include "../Player.h" + +class cBlockDispenserHandler : public cBlockEntityHandler +{ +public: + cBlockDispenserHandler(BLOCKTYPE a_BlockID) + : cBlockEntityHandler(a_BlockID) + { + } + + virtual void PlaceBlock(cWorld *a_World, cPlayer *a_Player, NIBBLETYPE a_BlockMeta, int a_X, int a_Y, int a_Z, char a_Dir) override + { + a_World->SetBlock(a_X, a_Y, a_Z, m_BlockID, cPiston::RotationPitchToMetaData(a_Player->GetRotation(), 0)); + OnPlacedByPlayer(a_World, a_Player, a_X, a_Y, a_Z, a_Dir); + } + + +}; \ No newline at end of file diff --git a/source/Blocks/BlockDoor.cpp b/source/Blocks/BlockDoor.cpp new file mode 100644 index 000000000..deed8a256 --- /dev/null +++ b/source/Blocks/BlockDoor.cpp @@ -0,0 +1,74 @@ +#include "Globals.h" +#include "BlockDoor.h" +#include "../Item.h" +#include "../World.h" +#include "../Doors.h" +#include "../Player.h" + + +cBlockDoorHandler::cBlockDoorHandler(BLOCKTYPE a_BlockID) + : cBlockHandler(a_BlockID) +{ +} + +void cBlockDoorHandler::OnPlaced(cWorld *a_World, int a_X, int a_Y, int a_Z, int a_Dir) +{ + +} + +void cBlockDoorHandler::OnDestroyed(cWorld *a_World, int a_X, int a_Y, int a_Z) +{ + char OldMeta = a_World->GetBlockMeta(a_X, a_Y, a_Z); + + if (OldMeta & 8) + { + // Was upper part of door + if (cDoors::IsDoor(a_World->GetBlock(a_X, a_Y - 1, a_Z))) + { + a_World->FastSetBlock(a_X, a_Y - 1, a_Z, E_BLOCK_AIR, 0); + } + } + else + { + // Was lower part + if (cDoors::IsDoor(a_World->GetBlock(a_X, a_Y + 1, a_Z))) + { + a_World->FastSetBlock(a_X, a_Y + 1, a_Z, E_BLOCK_AIR, 0); + } + } +} + +void cBlockDoorHandler::OnDigging(cWorld *a_World, cPlayer *a_Player, int a_X, int a_Y, int a_Z) +{ + cDoors::ChangeDoor(a_World, a_X, a_Y, a_Z); +} + +void cBlockDoorHandler::OnUse(cWorld *a_World, cPlayer *a_Player, int a_X, int a_Y, int a_Z) +{ + cDoors::ChangeDoor(a_World, a_X, a_Y, a_Z); +} + +char cBlockDoorHandler::GetDropCount() +{ + return 1; +} + +void cBlockDoorHandler::PlaceBlock(cWorld *a_World, cPlayer *a_Player, NIBBLETYPE a_BlockMeta, int a_X, int a_Y, int a_Z, char a_Dir) +{ + if (a_World->GetBlock(a_X, a_Y + 1, a_Z) == E_BLOCK_AIR) + { + a_BlockMeta = cDoors::RotationToMetaData(a_Player->GetRotation()); + a_World->SetBlock(a_X, a_Y + 1, a_Z, m_BlockID, a_BlockMeta + 8); + a_World->SetBlock(a_X, a_Y, a_Z, m_BlockID, a_BlockMeta); + OnPlacedByPlayer(a_World, a_Player, a_X, a_Y, a_Z, a_Dir); + } +} + +AString cBlockDoorHandler::GetStepSound(void) +{ + if (m_BlockID == E_BLOCK_WOODEN_DOOR) + return "step.wood"; + + else + return "step.stone"; +} diff --git a/source/Blocks/BlockDoor.h b/source/Blocks/BlockDoor.h new file mode 100644 index 000000000..3316f50a4 --- /dev/null +++ b/source/Blocks/BlockDoor.h @@ -0,0 +1,31 @@ +#pragma once +#include "BlockHandler.h" + + +class cBlockDoorHandler : public cBlockHandler +{ +public: + cBlockDoorHandler(BLOCKTYPE a_BlockID); + virtual void OnPlaced(cWorld *a_World, int a_X, int a_Y, int a_Z, int a_Dir) override; + virtual void OnDestroyed(cWorld *a_World, int a_X, int a_Y, int a_Z) override; + virtual void OnDigging(cWorld *a_World, cPlayer *a_Player, int a_X, int a_Y, int a_Z) override; + virtual void OnUse(cWorld *a_World, cPlayer *a_Player, int a_X, int a_Y, int a_Z) override; + virtual AString GetStepSound(void) override; + virtual char GetDropCount() override; + virtual bool IsUseable() override + { + return true; + } + + virtual void PlaceBlock(cWorld *a_World, cPlayer *a_Player, NIBBLETYPE a_BlockMeta, int a_X, int a_Y, int a_Z, char a_Dir) override; + + virtual int GetDropID() override + { + return (m_BlockID == E_BLOCK_WOODEN_DOOR) ? E_ITEM_WOODEN_DOOR : E_ITEM_IRON_DOOR; + } + + virtual bool CanBePlacedOnSide() override + { + return false; + } +}; \ No newline at end of file diff --git a/source/Blocks/BlockEntity.h b/source/Blocks/BlockEntity.h new file mode 100644 index 000000000..caf6ee342 --- /dev/null +++ b/source/Blocks/BlockEntity.h @@ -0,0 +1,31 @@ + +#pragma once + +#include "BlockHandler.h" + + + + + +class cBlockEntityHandler : public cBlockHandler +{ +public: + cBlockEntityHandler(BLOCKTYPE a_BlockID) + : cBlockHandler(a_BlockID) + { + } + + virtual void OnUse(cWorld * a_World, cPlayer *a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) override + { + a_World->UseBlockEntity(a_Player, a_BlockX, a_BlockY, a_BlockZ); + } + + virtual bool IsUseable() override + { + return true; + } +}; + + + + diff --git a/source/Blocks/BlockFire.h b/source/Blocks/BlockFire.h new file mode 100644 index 000000000..1fecf9a14 --- /dev/null +++ b/source/Blocks/BlockFire.h @@ -0,0 +1,33 @@ +#pragma once +#include "BlockHandler.h" + + +class cBlockFireHandler : public cBlockHandler +{ +public: + cBlockFireHandler(BLOCKTYPE a_BlockID) + : cBlockHandler(a_BlockID) + { + } + + virtual void OnDigging(cWorld *a_World, cPlayer *a_Player, int a_X, int a_Y, int a_Z) override + { + a_World->DigBlock(a_X, a_Y, a_Z); + } + + virtual char GetDropCount() override + { + return -1; + } + + virtual bool IsClickedThrough() override + { + return true; + } + + virtual AString GetStepSound(void) override + { + return "step.wood"; + } + +}; diff --git a/source/Blocks/BlockFlower.h b/source/Blocks/BlockFlower.h new file mode 100644 index 000000000..35a55fcac --- /dev/null +++ b/source/Blocks/BlockFlower.h @@ -0,0 +1,38 @@ +#pragma once +#include "BlockHandler.h" + + +class cBlockFlowerHandler : public cBlockHandler +{ +public: + cBlockFlowerHandler(BLOCKTYPE a_BlockID) + : cBlockHandler(a_BlockID) + { + } + + virtual NIBBLETYPE GetDropMeta(NIBBLETYPE a_BlockMeta) override + { + return 0; + } + + virtual bool CanBeAt(cWorld *a_World, int a_X, int a_Y, int a_Z) override + { + return IsBlockTypeOfDirt(a_World->GetBlock(a_X, a_Y - 1, a_Z)); + } + + virtual bool AllowBlockOnTop() override + { + return false; + } + + virtual bool CanBePlacedOnSide() override + { + return false; + } + + virtual AString GetStepSound(void) override + { + return "step.grass"; + } + +}; diff --git a/source/Blocks/BlockFluid.h b/source/Blocks/BlockFluid.h new file mode 100644 index 000000000..c5ac660b0 --- /dev/null +++ b/source/Blocks/BlockFluid.h @@ -0,0 +1,20 @@ +#pragma once +#include "BlockHandler.h" + + +class cBlockFluidHandler : public cBlockHandler +{ +public: + cBlockFluidHandler(BLOCKTYPE a_BlockID) + : cBlockHandler(a_BlockID) + { + + } + + virtual bool IgnoreBuildCollision() override + { + return true; + } + + +}; \ No newline at end of file diff --git a/source/Blocks/BlockFurnace.h b/source/Blocks/BlockFurnace.h new file mode 100644 index 000000000..4157b5049 --- /dev/null +++ b/source/Blocks/BlockFurnace.h @@ -0,0 +1,27 @@ +#pragma once +#include "BlockEntity.h" +#include "../World.h" +#include "../Piston.h" +#include "../Player.h" + +class cBlockFurnaceHandler : public cBlockEntityHandler +{ +public: + cBlockFurnaceHandler(BLOCKTYPE a_BlockID) + : cBlockEntityHandler(a_BlockID) + { + } + + virtual int GetDropID() override + { + return E_ITEM_FURNACE; + } + + virtual void PlaceBlock(cWorld *a_World, cPlayer *a_Player, NIBBLETYPE a_BlockMeta, int a_X, int a_Y, int a_Z, char a_Dir) override + { + a_World->SetBlock(a_X, a_Y, a_Z, m_BlockID, cPiston::RotationPitchToMetaData(a_Player->GetRotation(), 0)); + OnPlacedByPlayer(a_World, a_Player, a_X, a_Y, a_Z, a_Dir); + } + + +}; \ No newline at end of file diff --git a/source/Blocks/BlockGlowstone.h b/source/Blocks/BlockGlowstone.h new file mode 100644 index 000000000..0b906e2fe --- /dev/null +++ b/source/Blocks/BlockGlowstone.h @@ -0,0 +1,22 @@ +#pragma once +#include "BlockHandler.h" + + +class cBlockGlowstoneHandler : public cBlockHandler +{ +public: + cBlockGlowstoneHandler(BLOCKTYPE a_BlockID) + : cBlockHandler(a_BlockID) + { + } + + virtual NIBBLETYPE GetDropMeta(NIBBLETYPE a_BlockMeta) override + { + return 0; + } + + virtual int GetDropID() override + { + return E_ITEM_GLOWSTONE_DUST; + } +}; \ No newline at end of file diff --git a/source/Blocks/BlockGravel.h b/source/Blocks/BlockGravel.h new file mode 100644 index 000000000..da47db9bb --- /dev/null +++ b/source/Blocks/BlockGravel.h @@ -0,0 +1,18 @@ +#pragma once +#include "BlockHandler.h" + + +class cBlockGravelHandler : public cBlockHandler +{ +public: + cBlockGravelHandler(BLOCKTYPE a_BlockID) + : cBlockHandler(a_BlockID) + { + } + + virtual AString GetStepSound(void) override + { + return "step.gravel"; + } + +}; diff --git a/source/Blocks/BlockHandler.cpp b/source/Blocks/BlockHandler.cpp new file mode 100644 index 000000000..e6b384a23 --- /dev/null +++ b/source/Blocks/BlockHandler.cpp @@ -0,0 +1,448 @@ +#include "Globals.h" +#include "BlockHandler.h" +#include "../Item.h" +#include "../World.h" +#include "BlockSand.h" +#include "BlockGravel.h" +#include "BlockDoor.h" +#include "BlockFire.h" +#include "BlockRedstone.h" +#include "BlockRedstoneTorch.h" +#include "BlockRedstoneRepeater.h" +#include "BlockPiston.h" +#include "BlockWorkbench.h" +#include "BlockEntity.h" +#include "BlockVine.h" +#include "BlockTallGrass.h" +#include "BlockSnow.h" +#include "BlockCloth.h" +#include "BlockSlab.h" +#include "BlockDirt.h" +#include "BlockTorch.h" +#include "BlockWood.h" +#include "BlockLeaves.h" +#include "BlockSapling.h" +#include "BlockFluid.h" +#include "BlockChest.h" +#include "BlockFurnace.h" +#include "BlockDispenser.h" +#include "BlockStairs.h" +#include "BlockLadder.h" +#include "BlockSign.h" +#include "BlockCrops.h" +#include "BlockSugarcane.h" +#include "BlockFlower.h" +#include "BlockMushroom.h" +#include "BlockCactus.h" +#include "BlockStems.h" +#include "BlockGlowstone.h" +#include "BlockStone.h" +#include "BlockMelon.h" +#include "BlockIce.h" +#include "BlockOre.h" +#include "BlockNote.h" +#include "BlockBed.h" + + + + + +bool cBlockHandler::m_HandlerInitialized = false; +cBlockHandler *cBlockHandler::m_BlockHandler[256]; + + + + + +cBlockHandler *cBlockHandler::GetBlockHandler(BLOCKTYPE a_BlockID) +{ + if (!m_HandlerInitialized) + { + //We have to initialize + memset(m_BlockHandler, 0, sizeof(m_BlockHandler)); + m_HandlerInitialized = true; + } + if (m_BlockHandler[a_BlockID] != NULL) + { + return m_BlockHandler[a_BlockID]; + } + + return m_BlockHandler[a_BlockID] = CreateBlockHandler(a_BlockID); +} + + + + + +cBlockHandler *cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockID) +{ + switch(a_BlockID) + { + case E_BLOCK_SAND: + return new cBlockSandHandler(a_BlockID); + case E_BLOCK_GRAVEL: + return new cBlockGravelHandler(a_BlockID); + case E_BLOCK_WOODEN_DOOR: + case E_BLOCK_IRON_DOOR: + return new cBlockDoorHandler(a_BlockID); + case E_BLOCK_FIRE: + return new cBlockFireHandler(a_BlockID); + case E_BLOCK_REDSTONE_TORCH_ON: + case E_BLOCK_REDSTONE_TORCH_OFF: + return new cBlockRedstoneTorchHandler(a_BlockID); + case E_BLOCK_REDSTONE_WIRE: + return new cBlockRedstoneHandler(a_BlockID); + case E_BLOCK_PISTON: + case E_BLOCK_STICKY_PISTON: + return new cBlockPistonHandler(a_BlockID); + case E_BLOCK_REDSTONE_REPEATER_ON: + case E_BLOCK_REDSTONE_REPEATER_OFF: + return new cBlockRedstoneRepeaterHandler(a_BlockID); + case E_BLOCK_WORKBENCH: + return new cBlockWorkbenchHandler(a_BlockID); + case E_BLOCK_SNOW: + return new cBlockSnowHandler(a_BlockID); + case E_BLOCK_TALL_GRASS: + return new cBlockTallGrassHandler(a_BlockID); + case E_BLOCK_VINES: + return new cBlockVineHandler(a_BlockID); + case ::E_BLOCK_WOOL: + return new cBlockClothHandler(a_BlockID); + case E_BLOCK_WOODEN_SLAB: + case E_BLOCK_STONE_SLAB: + case E_BLOCK_DOUBLE_WOODEN_SLAB: + case E_BLOCK_DOUBLE_STONE_SLAB: + return new cBlockSlabHandler(a_BlockID); + case E_BLOCK_LOG: + case E_BLOCK_PLANKS: + return new cBlockWoodHandler(a_BlockID); + case E_BLOCK_TORCH: + return new cBlockTorchHandler(a_BlockID); + case E_BLOCK_DIRT: + case E_BLOCK_GRASS: + return new cBlockDirtHandler(a_BlockID); + case E_BLOCK_LEAVES: + return new cBlockLeavesHandler(a_BlockID); + case E_BLOCK_SAPLING: + return new cBlockSaplingHandler(a_BlockID); + case E_BLOCK_WATER: + case E_BLOCK_STATIONARY_WATER: + case E_BLOCK_STATIONARY_LAVA: + case E_BLOCK_LAVA: + return new cBlockFluidHandler(a_BlockID); + case E_BLOCK_DISPENSER: + return new cBlockDispenserHandler(a_BlockID); + case E_BLOCK_FURNACE: + case E_BLOCK_LIT_FURNACE: + return new cBlockFurnaceHandler(a_BlockID); + case E_BLOCK_CHEST: + return new cBlockChestHandler(a_BlockID); + case E_BLOCK_ICE: + return new cBlockIceHandler(a_BlockID); + case E_BLOCK_LADDER: + return new cBlockLadderHandler(a_BlockID); + case E_BLOCK_COBBLESTONE_STAIRS: + case E_BLOCK_BRICK_STAIRS: + case E_BLOCK_STONE_BRICK_STAIRS: + case E_BLOCK_NETHER_BRICK_STAIRS: + case E_BLOCK_WOODEN_STAIRS: + return new cBlockStairsHandler(a_BlockID); + case E_BLOCK_SIGN_POST: + case E_BLOCK_WALLSIGN: + return new cBlockSignHandler(a_BlockID); + case E_BLOCK_CROPS: + return new cBlockCropsHandler(a_BlockID); + case E_BLOCK_SUGARCANE: + return new cBlockSugarcaneHandler(a_BlockID); + case E_BLOCK_YELLOW_FLOWER: + case E_BLOCK_RED_ROSE: + return new cBlockFlowerHandler(a_BlockID); + case E_BLOCK_BROWN_MUSHROOM: + case E_BLOCK_RED_MUSHROOM: + return new cBlockMushroomHandler(a_BlockID); + case E_BLOCK_CACTUS: + return new cBlockCactusHandler(a_BlockID); + case E_BLOCK_MELON_STEM: + case E_BLOCK_PUMPKIN_STEM: + return new cBlockStemsHandler(a_BlockID); + case E_BLOCK_GLOWSTONE: + return new cBlockGlowstoneHandler(a_BlockID); + case E_BLOCK_DIAMOND_ORE: + case E_BLOCK_GOLD_ORE: + case E_BLOCK_REDSTONE_ORE: + case E_BLOCK_REDSTONE_ORE_GLOWING: + case E_BLOCK_EMERALD_ORE: + case E_BLOCK_IRON_ORE: + case E_BLOCK_LAPIS_ORE: + case E_BLOCK_COAL_ORE: + return new cBlockOreHandler(a_BlockID); + case E_BLOCK_STONE: + case E_BLOCK_COBBLESTONE: + return new cBlockStoneHandler(a_BlockID); + case E_BLOCK_MELON: + return new cBlockMelonHandler(a_BlockID); + case E_BLOCK_NOTE_BLOCK: + return new cBlockNoteHandler(a_BlockID); + case E_BLOCK_BED: + return new cBlockBedHandler(a_BlockID); + default: + return new cBlockHandler(a_BlockID); + break; + } +} + + + + + +void cBlockHandler::Deinit() +{ + for(int i = 0; i < 256; i++) + { + delete m_BlockHandler[i]; + } + m_HandlerInitialized = false; +} + + + + + +cBlockHandler::cBlockHandler(BLOCKTYPE a_BlockID) +{ + m_BlockID = a_BlockID; +} + + + + + +void cBlockHandler::OnUpdate(cWorld *a_World, int a_X, int a_Y, int a_Z) +{ +} + + + + + +void cBlockHandler::OnPlacedByPlayer(cWorld *a_World, cPlayer * a_Player, int a_X, int a_Y, int a_Z, int a_Dir) +{ +} + + + + + +void cBlockHandler::OnDestroyedByPlayer(cWorld *a_World, cPlayer * a_Player, int a_X, int a_Y, int a_Z) +{ +} + + + + + +void cBlockHandler::OnPlaced(cWorld *a_World, int a_X, int a_Y, int a_Z, int a_Dir) +{ + //Notify the neighbors + NeighborChanged(a_World, a_X - 1, a_Y, a_Z); + NeighborChanged(a_World, a_X + 1, a_Y, a_Z); + NeighborChanged(a_World, a_X, a_Y - 1, a_Z); + NeighborChanged(a_World, a_X, a_Y + 1, a_Z); + NeighborChanged(a_World, a_X, a_Y, a_Z - 1); + NeighborChanged(a_World, a_X, a_Y, a_Z + 1); +} + + + + + +void cBlockHandler::OnDestroyed(cWorld *a_World, int a_X, int a_Y, int a_Z) +{ + //Notify the neighbors + NeighborChanged(a_World, a_X - 1, a_Y, a_Z); + NeighborChanged(a_World, a_X + 1, a_Y, a_Z); + NeighborChanged(a_World, a_X, a_Y - 1, a_Z); + NeighborChanged(a_World, a_X, a_Y + 1, a_Z); + NeighborChanged(a_World, a_X, a_Y, a_Z - 1); + NeighborChanged(a_World, a_X, a_Y, a_Z + 1); +} + + + + + +void cBlockHandler::NeighborChanged(cWorld *a_World, int a_X, int a_Y, int a_Z) +{ + GetBlockHandler(a_World->GetBlock(a_X, a_Y, a_Z))->OnNeighborChanged(a_World, a_X, a_Y, a_Z); +} + + + + + +void cBlockHandler::OnNeighborChanged(cWorld *a_World, int a_X, int a_Y, int a_Z) +{ +} + + + + + +void cBlockHandler::OnDigging(cWorld *a_World, cPlayer *a_Player, int a_X, int a_Y, int a_Z) +{ +} + + + + + +void cBlockHandler::OnUse(cWorld *a_World, cPlayer *a_Player, int a_X, int a_Y, int a_Z) +{ +} + + + + + +void cBlockHandler::PlaceBlock(cWorld *a_World, cPlayer *a_Player, NIBBLETYPE a_BlockMeta, int a_X, int a_Y, int a_Z, char a_Dir) +{ + a_World->SetBlock(a_X, a_Y, a_Z, m_BlockID, a_BlockMeta); + OnPlacedByPlayer(a_World, a_Player, a_X, a_Y, a_Z, a_Dir); +} + + + + + +char cBlockHandler::GetDropCount() +{ + return 1; +} + + + + + +int cBlockHandler::GetDropID() +{ + return m_BlockID; +} + + + + + +NIBBLETYPE cBlockHandler::GetDropMeta(NIBBLETYPE a_BlockMeta) +{ + return a_BlockMeta; //This keeps most textures. The few other blocks have to override this +} + + + + + +void cBlockHandler::DropBlock(cWorld *a_World, int a_X, int a_Y, int a_Z) +{ + cItems Drops; + NIBBLETYPE Meta = a_World->GetBlockMeta(a_X, a_Y, a_Z); + char DropCount = GetDropCount(); + short DropItem = (short)GetDropID(); + if (DropCount > 0 && (DropItem != E_ITEM_EMPTY)) + { + Drops.push_back(cItem(DropItem, DropCount, GetDropMeta(Meta))); + a_World->SpawnItemPickups(Drops, a_X, a_Y, a_Z); + } +} + + + + + +AString cBlockHandler::GetStepSound() { + return "step.stone"; +} + + + + + +bool cBlockHandler::CanBePlacedAt(cWorld *a_World, int a_X, int a_Y, int a_Z, char a_Dir) +{ + return CanBeAt(a_World, a_X, a_Y, a_Z); +} + + + + + +bool cBlockHandler::CanBeAt(cWorld *a_World, int a_X, int a_Y, int a_Z) +{ + return true; +} + + + + + +bool cBlockHandler::IsUseable() +{ + return false; +} + + + + + +bool cBlockHandler::IsClickedThrough() +{ + return false; +} + + + + + +bool cBlockHandler::IgnoreBuildCollision() +{ + return m_BlockID == E_BLOCK_AIR; +} + + + + + +bool cBlockHandler::NeedsRandomTicks() +{ + return false; +} + + + + + +bool cBlockHandler::AllowBlockOnTop() +{ + return true; +} + + + + + +bool cBlockHandler::CanBePlacedOnSide() +{ + return true; +} + + + + + +bool cBlockHandler::DropOnUnsuitable() +{ + return true; +} + + + + diff --git a/source/Blocks/BlockHandler.h b/source/Blocks/BlockHandler.h new file mode 100644 index 000000000..859870c4a --- /dev/null +++ b/source/Blocks/BlockHandler.h @@ -0,0 +1,90 @@ +#pragma once +#include "../Defines.h" + +class cWorld; +class cPlayer; + + + +class cBlockHandler +{ +public: + cBlockHandler(BLOCKTYPE a_BlockID); + + // Called when the block gets ticked either by a random tick or by a queued tick + virtual void OnUpdate(cWorld *a_World, int a_X, int a_Y, int a_Z); + + // Will be called by cBlockHandler::PlaceBlock after the player has placed a new block + virtual void OnPlacedByPlayer(cWorld *a_World, cPlayer * a_Player, int a_X, int a_Y, int a_Z, int a_Dir); + // Will be called before the player has destroyed a block + virtual void OnDestroyedByPlayer(cWorld *a_World, cPlayer * a_Player, int a_X, int a_Y, int a_Z); + // Will be called when a new block was placed. Will be called before OnPlacedByPlayer + virtual void OnPlaced(cWorld *a_World, int a_X, int a_Y, int a_Z, int a_Dir); + // Will be called before a block gets destroyed / replaced with air + virtual void OnDestroyed(cWorld *a_World, int a_X, int a_Y, int a_Z); + // Will be called when a direct neighbor of this block has been changed (The position is the own position, not the neighbor position) + virtual void OnNeighborChanged(cWorld *a_World, int a_X, int a_Y, int a_Z); + // Notifies all neighbors of the give block about a change + static void NeighborChanged(cWorld *a_World, int a_X, int a_Y, int a_Z); + // Will be called while the player diggs the block. + virtual void OnDigging(cWorld *a_World, cPlayer *a_Player, int a_X, int a_Y, int a_Z); + // Will be called if the user right clicks the block and the block is useable + virtual void OnUse(cWorld *a_World, cPlayer *a_Player, int a_X, int a_Y, int a_Z); + // This function handles the real block placement for the give block by a player and also calls the OnPlacedByPlayer function + virtual void PlaceBlock(cWorld *a_World, cPlayer *a_Player, NIBBLETYPE a_BlockMeta, int a_X, int a_Y, int a_Z, char a_Dir); + + // Indicates how much items are dropped DEFAULT: 1 + virtual char GetDropCount(); + // Indicates the id dropped by this block DEFAULT: BlockID + virtual int GetDropID(); + // Indicates the Drop Meta data based on the block meta DEFAULT: BlockMeta + virtual NIBBLETYPE GetDropMeta(NIBBLETYPE a_BlockMeta); + // This function handles the dropping of a block based on the Drop id, drop count and drop meta. This will not destroy the block + virtual void DropBlock(cWorld *a_World, int a_X, int a_Y, int a_Z); + /// Returns step sound name of block + virtual AString GetStepSound(); + + // Indicates whether this block needs random ticks DEFAULT: False + virtual bool NeedsRandomTicks(); + + /// Checks if the block can stay at the specified coords in the world + virtual bool CanBeAt(cWorld *a_World, int a_BlockX, int a_BlockY, int a_BlockZ); + + /// Checks if the block can be placed at this point. Default: CanBeAt(...) NOTE: This call doesn't actually place the block + virtual bool CanBePlacedAt(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir); + + /// Called when the player tries to place a block on top of this block (Only if he aims directly on this block); return false to disallow + virtual bool AllowBlockOnTop(void); + + /// Called to check whether this block supports a rclk action. If it returns true, OnUse() is called + virtual bool IsUseable(void); + + // Indicates whether the client will click through this block. For example digging a fire will hit the block below the fire so fire is clicked through + virtual bool IsClickedThrough(void); + + // Checks if the player can build "inside" this block. For example blocks placed "on" snow will be placed at the same position. So: Snow ignores Build collision + virtual bool IgnoreBuildCollision(void); + + /// Indicates this block can be placed on the side of other blocks. Default: true + virtual bool CanBePlacedOnSide(); + + /// Does this block drop if it gets destroyed by an unsuitable situation? Default: true + virtual bool DropOnUnsuitable(); + + + // Static function to get the blockhandler for an specific block id + static cBlockHandler * GetBlockHandler(BLOCKTYPE a_BlockID); + + // Deletes all initialised block handlers + static void Deinit(); + +protected: + BLOCKTYPE m_BlockID; + // Creates a new blockhandler for the given block id. For internal use only, use GetBlockHandler instead. + static cBlockHandler *CreateBlockHandler(BLOCKTYPE a_BlockID); + static cBlockHandler *m_BlockHandler[256]; + static bool m_HandlerInitialized; //used to detect if the blockhandlers are initialized +}; + +// Shortcut to get the blockhandler for a specific block +inline cBlockHandler *BlockHandler(BLOCKTYPE a_BlockID) { return cBlockHandler::GetBlockHandler(a_BlockID); } \ No newline at end of file diff --git a/source/Blocks/BlockIce.h b/source/Blocks/BlockIce.h new file mode 100644 index 000000000..cc5cc8920 --- /dev/null +++ b/source/Blocks/BlockIce.h @@ -0,0 +1,26 @@ +#pragma once +#include "BlockHandler.h" +#include "../MersenneTwister.h" +#include "../World.h" + +class cBlockIceHandler : public cBlockHandler +{ +public: + cBlockIceHandler(BLOCKTYPE a_BlockID) + : cBlockHandler(a_BlockID) + { + } + + virtual int GetDropID() override + { + return E_ITEM_EMPTY; + } + + virtual void OnDestroyed(cWorld *a_World, int a_X, int a_Y, int a_Z) override + { + a_World->FastSetBlock(a_X, a_Y, a_Z, E_BLOCK_STATIONARY_WATER, 8); + //This is called later than the real destroying of this ice block + } + + +}; \ No newline at end of file diff --git a/source/Blocks/BlockLadder.h b/source/Blocks/BlockLadder.h new file mode 100644 index 000000000..ee48df848 --- /dev/null +++ b/source/Blocks/BlockLadder.h @@ -0,0 +1,40 @@ +#pragma once +#include "BlockHandler.h" +#include "../World.h" +#include "../Ladder.h" + +class cBlockLadderHandler : public cBlockHandler +{ +public: + cBlockLadderHandler(BLOCKTYPE a_BlockID) + : cBlockHandler(a_BlockID) + { + + } + + virtual void PlaceBlock(cWorld *a_World, cPlayer *a_Player, NIBBLETYPE a_BlockMeta, int a_X, int a_Y, int a_Z, char a_Dir) override + { + a_World->SetBlock(a_X, a_Y, a_Z, m_BlockID, cLadder::DirectionToMetaData(a_Dir)); + OnPlacedByPlayer(a_World, a_Player, a_X, a_Y, a_Z, a_Dir); + } + + virtual bool CanBePlacedAt(cWorld *a_World, int a_X, int a_Y, int a_Z, char a_Dir) override + { + AddDirection( a_X, a_Y, a_Z, a_Dir, true ); + return a_World->GetBlock( a_X, a_Y, a_Z ) != E_BLOCK_AIR; + } + + + virtual bool CanBeAt(cWorld *a_World, int a_X, int a_Y, int a_Z) override + { + char Dir = cLadder::MetaDataToDirection(a_World->GetBlockMeta( a_X, a_Y, a_Z)); + return CanBePlacedAt(a_World, a_X, a_Y, a_Z, Dir); + } + + + virtual AString GetStepSound(void) override + { + return "step.wood"; + } + +}; diff --git a/source/Blocks/BlockLeaves.h b/source/Blocks/BlockLeaves.h new file mode 100644 index 000000000..65c47f8de --- /dev/null +++ b/source/Blocks/BlockLeaves.h @@ -0,0 +1,167 @@ +#pragma once +#include "BlockHandler.h" +#include "../MersenneTwister.h" +#include "../World.h" +#include "../BlockArea.h" + + + +// Leaves can be this many blocks that away (inclusive) from the log not to decay +#define LEAVES_CHECK_DISTANCE 6 + +#define PROCESS_NEIGHBOR(x,y,z) \ + switch (a_Area.GetBlockType(x, y, z)) \ + { \ + case E_BLOCK_LEAVES: a_Area.SetBlockType(x, y, z, (BLOCKTYPE)(E_BLOCK_SPONGE + i + 1)); break; \ + case E_BLOCK_LOG: return true; \ + } + +bool HasNearLog(cBlockArea &a_Area, int a_BlockX, int a_BlockY, int a_BlockZ); + + + +class cBlockLeavesHandler : public cBlockHandler +{ +public: + cBlockLeavesHandler(BLOCKTYPE a_BlockID) + : cBlockHandler(a_BlockID) + { + } + + virtual int GetDropID() override + { + MTRand rand; + + if(rand.randInt(5) == 0) + { + return E_ITEM_SAPLING; + } + + return E_ITEM_EMPTY; + } + + void OnDestroyed(cWorld *a_World, int a_X, int a_Y, int a_Z) override + { + cBlockHandler::OnDestroyed(a_World, a_X, a_Y, a_Z); + + //0.5% chance of dropping an apple + NIBBLETYPE Meta = a_World->GetBlockMeta(a_X, a_Y, a_Z); + //check if Oak (0x1 and 0x2 bit not set) + MTRand rand; + if(!(Meta & 3) && rand.randInt(200) == 100) + { + cItems Drops; + Drops.push_back(cItem(E_ITEM_RED_APPLE, 1, 0)); + a_World->SpawnItemPickups(Drops, a_X, a_Y, a_Z); + } + } + + virtual void OnNeighborChanged(cWorld *a_World, int a_X, int a_Y, int a_Z) override + { + NIBBLETYPE Meta = a_World->GetBlockMeta(a_X, a_Y, a_Z); + a_World->SetBlockMeta(a_X, a_Y, a_Z, Meta & 0x7); //Unset 0x8 bit so it gets checked for decay + } + + virtual bool NeedsRandomTicks() override + { + return true; + } + + virtual void OnUpdate(cWorld *a_World, int a_X, int a_Y, int a_Z) override + { + NIBBLETYPE Meta = a_World->GetBlockMeta(a_X, a_Y, a_Z); + if ((Meta & 0x04) != 0) + { + // Player-placed leaves, don't decay + return; + } + + if (Meta & 0x8) + { + // These leaves have been checked for decay lately and nothing around them changed + return; + } + + // Get the data around the leaves: + cBlockArea Area; + if (!Area.Read( + a_World, + a_X - LEAVES_CHECK_DISTANCE, a_X + LEAVES_CHECK_DISTANCE, + a_Y - LEAVES_CHECK_DISTANCE, a_Y + LEAVES_CHECK_DISTANCE, + a_Z - LEAVES_CHECK_DISTANCE, a_Z + LEAVES_CHECK_DISTANCE, + cBlockArea::baTypes) + ) + { + // Cannot check leaves, a chunk is missing too close + return; + } + + if (HasNearLog(Area, a_X, a_Y, a_Z)) + { + // Wood found, the leaves stay; mark them as checked: + a_World->SetBlockMeta(a_X, a_Y, a_Z, Meta | 0x8); + return; + } + // Decay the leaves: + DropBlock(a_World, a_X, a_Y, a_Z); + + a_World->DigBlock(a_X, a_Y, a_Z); + + } + + virtual AString GetStepSound(void) override + { + return "step.grass"; + } +}; + + +bool HasNearLog(cBlockArea &a_Area, int a_BlockX, int a_BlockY, int a_BlockZ) +{ + // Filter the blocks into a {leaves, log, other (air)} set: + BLOCKTYPE * Types = a_Area.GetBlockTypes(); + for (int i = a_Area.GetBlockCount() - 1; i > 0; i--) + { + switch (Types[i]) + { + case E_BLOCK_LEAVES: + case E_BLOCK_LOG: + { + break; + } + default: + { + Types[i] = E_BLOCK_AIR; + break; + } + } + } // for i - Types[] + + // Perform a breadth-first search to see if there's a log connected within 4 blocks of the leaves block: + // Simply replace all reachable leaves blocks with a sponge block plus iteration (in the Area) and see if we can reach a log in 4 iterations + a_Area.SetBlockType(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_SPONGE); + for (int i = 0; i < LEAVES_CHECK_DISTANCE; i++) + { + for (int y = a_BlockY - i; y <= a_BlockY + i; y++) + { + for (int z = a_BlockZ - i; z <= a_BlockZ + i; z++) + { + for (int x = a_BlockX - i; x <= a_BlockX + i; x++) + { + if (a_Area.GetBlockType(x, y, z) != E_BLOCK_SPONGE + i) + { + continue; + } + PROCESS_NEIGHBOR(x - 1, y, z); + PROCESS_NEIGHBOR(x + 1, y, z); + PROCESS_NEIGHBOR(x, y, z - 1); + PROCESS_NEIGHBOR(x, y, z + 1); + PROCESS_NEIGHBOR(x, y + 1, z); + PROCESS_NEIGHBOR(x, y - 1, z); + } // for x + } // for z + } // for y + } // for i - BFS iterations + return false; +} + diff --git a/source/Blocks/BlockMelon.h b/source/Blocks/BlockMelon.h new file mode 100644 index 000000000..87fb7e1e8 --- /dev/null +++ b/source/Blocks/BlockMelon.h @@ -0,0 +1,29 @@ +#pragma once +#include "BlockHandler.h" + + +class cBlockMelonHandler : public cBlockHandler +{ +public: + cBlockMelonHandler(BLOCKTYPE a_BlockID) + : cBlockHandler(a_BlockID) + { + } + + + virtual int GetDropID() override + { + return E_ITEM_MELON_SLICE; + } + + virtual char GetDropCount() override + { + MTRand r1; + return (char)(3 + r1.randInt(4)); + } + + virtual AString GetStepSound(void) override + { + return "step.wood"; + } +}; diff --git a/source/Blocks/BlockMushroom.h b/source/Blocks/BlockMushroom.h new file mode 100644 index 000000000..c4119bad0 --- /dev/null +++ b/source/Blocks/BlockMushroom.h @@ -0,0 +1,47 @@ +#pragma once +#include "BlockHandler.h" + + +class cBlockMushroomHandler : public cBlockHandler +{ +public: + cBlockMushroomHandler(BLOCKTYPE a_BlockID) + : cBlockHandler(a_BlockID) + { + } + + virtual NIBBLETYPE GetDropMeta(NIBBLETYPE a_BlockMeta) override + { + return 0; + } + + virtual bool CanBeAt(cWorld *a_World, int a_X, int a_Y, int a_Z) override + { + switch (a_World->GetBlock(a_X, a_Y - 1, a_Z)) + { + case E_BLOCK_GLASS: + case E_BLOCK_CACTUS: + case E_BLOCK_ICE: + case E_BLOCK_LEAVES: + case E_BLOCK_AIR: + return false; + } + return true; + } + + virtual bool AllowBlockOnTop() override + { + return false; + } + + + virtual bool CanBePlacedOnSide() override + { + return false; + } + + virtual AString GetStepSound(void) override + { + return "step.grass"; + } +}; diff --git a/source/Blocks/BlockNote.h b/source/Blocks/BlockNote.h new file mode 100644 index 000000000..896a5d03b --- /dev/null +++ b/source/Blocks/BlockNote.h @@ -0,0 +1,13 @@ +#pragma once +#include "BlockHandler.h" +#include "BlockEntity.h" + +class cBlockNoteHandler : public cBlockEntityHandler +{ +public: + cBlockNoteHandler(BLOCKTYPE a_BlockID) + : cBlockEntityHandler(a_BlockID) + { + } + +}; diff --git a/source/Blocks/BlockOre.h b/source/Blocks/BlockOre.h new file mode 100644 index 000000000..556a215ce --- /dev/null +++ b/source/Blocks/BlockOre.h @@ -0,0 +1,58 @@ +#pragma once +#include "BlockHandler.h" +#include "../MersenneTwister.h" +#include "../World.h" + +class cBlockOreHandler : public cBlockHandler +{ +public: + cBlockOreHandler(BLOCKTYPE a_BlockID) + : cBlockHandler(a_BlockID) + { + } + + virtual char GetDropCount() override + { + MTRand r1; + switch(m_BlockID) + { + case E_BLOCK_LAPIS_ORE: + return 4 + (char)r1.randInt(4); + case E_BLOCK_REDSTONE_ORE: + case E_BLOCK_REDSTONE_ORE_GLOWING: + return 4 + (char)r1.randInt(1); + default: + return 1; + } + } + + virtual NIBBLETYPE GetDropMeta(NIBBLETYPE a_Meta) override + { + switch(m_BlockID) + { + case E_BLOCK_LAPIS_ORE: + return 4; + default: + return 0; + } + } + + virtual int GetDropID() override + { + switch(m_BlockID) + { + case E_BLOCK_DIAMOND_ORE: + return E_ITEM_DIAMOND; + case E_BLOCK_REDSTONE_ORE: + case E_BLOCK_REDSTONE_ORE_GLOWING: + return E_ITEM_REDSTONE_DUST; + case E_BLOCK_EMERALD_ORE: + return E_ITEM_EMERALD; + case E_BLOCK_LAPIS_ORE: + return E_ITEM_DYE; + case E_BLOCK_COAL_ORE: + return E_ITEM_COAL; + } + return m_BlockID; + } +}; \ No newline at end of file diff --git a/source/Blocks/BlockPiston.cpp b/source/Blocks/BlockPiston.cpp new file mode 100644 index 000000000..a4ed13d88 --- /dev/null +++ b/source/Blocks/BlockPiston.cpp @@ -0,0 +1,51 @@ +#include "Globals.h" +#include "BlockPiston.h" +#include "../Item.h" +#include "../World.h" +#include "../Redstone.h" +#include "../Player.h" +#include "../Piston.h" + + + +#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; } + + + + +cBlockPistonHandler::cBlockPistonHandler(BLOCKTYPE a_BlockID) + : cBlockHandler(a_BlockID) +{ +} + +void cBlockPistonHandler::OnPlaced(cWorld *a_World, int a_X, int a_Y, int a_Z, int a_Dir) +{ + +} + +void cBlockPistonHandler::OnDestroyed(cWorld *a_World, int a_X, int a_Y, int a_Z) +{ + char OldMeta = a_World->GetBlockMeta(a_X, a_Y, a_Z); + + int newX = a_X; + int newY = a_Y; + int newZ = a_Z; + AddPistonDir(newX, newY, newZ, OldMeta & ~(8), 1); + + if (a_World->GetBlock(newX, newY, newZ) == E_BLOCK_PISTON_EXTENSION) + { + a_World->SetBlock(newX, newY, newZ, E_BLOCK_AIR, 0); + } +} + +void cBlockPistonHandler::PlaceBlock(cWorld *a_World, cPlayer *a_Player, NIBBLETYPE a_BlockMeta, int a_X, int a_Y, int a_Z, char a_Dir) +{ + + a_World->SetBlock(a_X, a_Y, a_Z, m_BlockID, cPiston::RotationPitchToMetaData(a_Player->GetRotation(), a_Player->GetPitch())); + OnPlacedByPlayer(a_World, a_Player, a_X, a_Y, a_Z, a_Dir); + + cRedstone Redstone(a_World); + Redstone.ChangeRedstone(a_X, a_Y, a_Z, false); +} \ No newline at end of file diff --git a/source/Blocks/BlockPiston.h b/source/Blocks/BlockPiston.h new file mode 100644 index 000000000..dbce9bae5 --- /dev/null +++ b/source/Blocks/BlockPiston.h @@ -0,0 +1,15 @@ +#pragma once +#include "BlockHandler.h" + + +class cBlockPistonHandler : public cBlockHandler +{ +public: + cBlockPistonHandler(BLOCKTYPE a_BlockID); + virtual void OnPlaced(cWorld *a_World, int a_X, int a_Y, int a_Z, int a_Dir) override; + virtual void OnDestroyed(cWorld *a_World, int a_X, int a_Y, int a_Z) override; + + + virtual void PlaceBlock(cWorld *a_World, cPlayer *a_Player, NIBBLETYPE a_BlockMeta, int a_X, int a_Y, int a_Z, char a_Dir) override; + +}; \ No newline at end of file diff --git a/source/Blocks/BlockRedstone.cpp b/source/Blocks/BlockRedstone.cpp new file mode 100644 index 000000000..7653436f4 --- /dev/null +++ b/source/Blocks/BlockRedstone.cpp @@ -0,0 +1,41 @@ +#include "Globals.h" +#include "BlockRedstone.h" +#include "../Item.h" +#include "../World.h" +#include "../Redstone.h" +#include "../Torch.h" + +cBlockRedstoneHandler::cBlockRedstoneHandler(BLOCKTYPE a_BlockID) + : cBlockHandler(a_BlockID) +{ +} + +void cBlockRedstoneHandler::OnPlaced(cWorld *a_World, int a_X, int a_Y, int a_Z, int a_Dir) +{ + cRedstone Redstone(a_World); + bool Added = false; + if(a_World->GetBlock(a_X, a_Y, a_Z) == E_BLOCK_REDSTONE_TORCH_ON) + Added = true; + + Redstone.ChangeRedstone(a_X, a_Y, a_Z, Added); +} + +void cBlockRedstoneHandler::OnDestroyed(cWorld *a_World, int a_X, int a_Y, int a_Z) +{ + cRedstone Redstone(a_World); + Redstone.ChangeRedstone(a_X, a_Y, a_Z, false); +} + +void cBlockRedstoneHandler::PlaceBlock(cWorld *a_World, cPlayer *a_Player, NIBBLETYPE a_BlockMeta, int a_X, int a_Y, int a_Z, char a_Dir) +{ + switch(m_BlockID) + { + case E_BLOCK_REDSTONE_TORCH_ON: + case E_BLOCK_REDSTONE_TORCH_OFF: + a_BlockMeta = cTorch::DirectionToMetaData(a_Dir); + break; + + } + a_World->SetBlock(a_X, a_Y, a_Z, m_BlockID, a_BlockMeta); + OnPlacedByPlayer(a_World, a_Player, a_X, a_Y, a_Z, a_Dir); +} \ No newline at end of file diff --git a/source/Blocks/BlockRedstone.h b/source/Blocks/BlockRedstone.h new file mode 100644 index 000000000..9b83b1b29 --- /dev/null +++ b/source/Blocks/BlockRedstone.h @@ -0,0 +1,33 @@ +#pragma once +#include "BlockHandler.h" +#include "../World.h" + +class cBlockRedstoneHandler : public cBlockHandler +{ +public: + cBlockRedstoneHandler(BLOCKTYPE a_BlockID); + virtual void OnPlaced(cWorld *a_World, int a_X, int a_Y, int a_Z, int a_Dir) override; + virtual void OnDestroyed(cWorld *a_World, int a_X, int a_Y, int a_Z) override; + + virtual void PlaceBlock(cWorld *a_World, cPlayer *a_Player, NIBBLETYPE a_BlockMeta, int a_X, int a_Y, int a_Z, char a_Dir) override; + + virtual bool AllowBlockOnTop() override + { + return false; + } + + virtual bool CanBeAt(cWorld *a_World, int a_X, int a_Y, int a_Z) override + { + return a_World->GetBlock(a_X, a_Y - 1, a_Z) != E_BLOCK_AIR; + } + + virtual int GetDropID() override + { + return E_ITEM_REDSTONE_DUST; + } + + virtual bool CanBePlacedOnSide() override + { + return false; + } +}; \ No newline at end of file diff --git a/source/Blocks/BlockRedstoneRepeater.cpp b/source/Blocks/BlockRedstoneRepeater.cpp new file mode 100644 index 000000000..861f6e221 --- /dev/null +++ b/source/Blocks/BlockRedstoneRepeater.cpp @@ -0,0 +1,39 @@ +#include "Globals.h" +#include "BlockRedstoneRepeater.h" +#include "../Item.h" +#include "../World.h" +#include "../Redstone.h" +#include "../Player.h" + +cBlockRedstoneRepeaterHandler::cBlockRedstoneRepeaterHandler(BLOCKTYPE a_BlockID) + : cBlockHandler(a_BlockID) +{ +} + +void cBlockRedstoneRepeaterHandler::OnPlaced(cWorld *a_World, int a_X, int a_Y, int a_Z, int a_Dir) +{ + cRedstone Redstone(a_World); + Redstone.ChangeRedstone(a_X, a_Y, a_Z, false); +} + +void cBlockRedstoneRepeaterHandler::OnDestroyed(cWorld *a_World, int a_X, int a_Y, int a_Z) +{ + cRedstone Redstone(a_World); + Redstone.ChangeRedstone(a_X, a_Y, a_Z, false); +} + +void cBlockRedstoneRepeaterHandler::OnUse(cWorld *a_World, cPlayer *a_Player, int a_X, int a_Y, int a_Z) +{ + a_World->FastSetBlock(a_X, a_Y, a_Z, m_BlockID, ((a_World->GetBlockMeta(a_X, a_Y, a_Z) + 0x04) & 0x0f)); +} + +void cBlockRedstoneRepeaterHandler::OnDigging(cWorld *a_World, cPlayer *a_Player, int a_X, int a_Y, int a_Z) +{ + OnUse(a_World, a_Player, a_X, a_Y, a_Z); +} + +void cBlockRedstoneRepeaterHandler::PlaceBlock(cWorld *a_World, cPlayer *a_Player, NIBBLETYPE a_BlockMeta, int a_X, int a_Y, int a_Z, char a_Dir) +{ + a_World->SetBlock(a_X, a_Y, a_Z, m_BlockID, cRedstone::RepeaterRotationToMetaData(a_Player->GetRotation())); + OnPlacedByPlayer(a_World, a_Player, a_X, a_Y, a_Z, a_Dir); +} \ No newline at end of file diff --git a/source/Blocks/BlockRedstoneRepeater.h b/source/Blocks/BlockRedstoneRepeater.h new file mode 100644 index 000000000..a928f554f --- /dev/null +++ b/source/Blocks/BlockRedstoneRepeater.h @@ -0,0 +1,52 @@ +#pragma once +#include "BlockHandler.h" +#include "../World.h" + +class cBlockRedstoneRepeaterHandler : public cBlockHandler +{ +public: + cBlockRedstoneRepeaterHandler(BLOCKTYPE a_BlockID); + virtual void OnPlaced(cWorld *a_World, int a_X, int a_Y, int a_Z, int a_Dir) override; + virtual void OnDestroyed(cWorld *a_World, int a_X, int a_Y, int a_Z) override; + + virtual void OnDigging(cWorld *a_World, cPlayer *a_Player, int a_X, int a_Y, int a_Z) override; + virtual void OnUse(cWorld *a_World, cPlayer *a_Player, int a_X, int a_Y, int a_Z) override; + + virtual NIBBLETYPE GetDropMeta(NIBBLETYPE a_BlockMeta) override + { + return 0; + } + + virtual int GetDropID() override + { + return E_ITEM_REDSTONE_REPEATER; + } + + virtual bool IsUseable() override + { + return true; + } + + virtual void PlaceBlock(cWorld *a_World, cPlayer *a_Player, NIBBLETYPE a_BlockMeta, int a_X, int a_Y, int a_Z, char a_Dir) override; + + virtual bool AllowBlockOnTop() override + { + return false; + } + + virtual bool CanBeAt(cWorld *a_World, int a_X, int a_Y, int a_Z) override + { + return a_World->GetBlock(a_X, a_Y - 1, a_Z) != E_BLOCK_AIR; + } + + + virtual bool CanBePlacedOnSide() override + { + return false; + } + + virtual AString GetStepSound(void) override + { + return "step.wood"; + } +}; diff --git a/source/Blocks/BlockRedstoneTorch.h b/source/Blocks/BlockRedstoneTorch.h new file mode 100644 index 000000000..eeb2afc5c --- /dev/null +++ b/source/Blocks/BlockRedstoneTorch.h @@ -0,0 +1,28 @@ + +#pragma once +#include "BlockRedstone.h" +#include "BlockTorch.h" +#include "../Torch.h" + + + + + +class cBlockRedstoneTorchHandler : public cBlockTorchHandler +{ +public: + cBlockRedstoneTorchHandler(BLOCKTYPE a_BlockID) + : cBlockTorchHandler(a_BlockID) + { + } + + virtual int GetDropID(void) override + { + return E_ITEM_REDSTONE_TORCH_ON; + } + + virtual AString GetStepSound(void) override + { + return "step.wood"; + } +}; diff --git a/source/Blocks/BlockSand.h b/source/Blocks/BlockSand.h new file mode 100644 index 000000000..69fda5ec6 --- /dev/null +++ b/source/Blocks/BlockSand.h @@ -0,0 +1,18 @@ +#pragma once +#include "BlockHandler.h" + + +class cBlockSandHandler : public cBlockHandler +{ +public: + cBlockSandHandler(BLOCKTYPE a_BlockID) + : cBlockHandler(a_BlockID) + { + } + + virtual AString GetStepSound(void) override + { + return "step.sand"; + } + +}; diff --git a/source/Blocks/BlockSapling.h b/source/Blocks/BlockSapling.h new file mode 100644 index 000000000..c9862349a --- /dev/null +++ b/source/Blocks/BlockSapling.h @@ -0,0 +1,56 @@ +#pragma once +#include "BlockHandler.h" +#include "../World.h" + +class cBlockSaplingHandler : public cBlockHandler +{ +public: + cBlockSaplingHandler(BLOCKTYPE a_BlockID) + : cBlockHandler(a_BlockID) + { + } + + virtual bool NeedsRandomTicks() override + { + return true; + } + + virtual NIBBLETYPE GetDropMeta(NIBBLETYPE a_BlockMeta) override + { + return a_BlockMeta & 3; //Only the first 2 bits contain the display information the others are for growing + } + + virtual bool CanBeAt(cWorld *a_World, int a_X, int a_Y, int a_Z) override + { + return IsBlockTypeOfDirt(a_World->GetBlock(a_X, a_Y - 1, a_Z)); + } + + virtual bool AllowBlockOnTop() override + { + return false; + } + + void OnUpdate(cWorld *a_World, int a_X, int a_Y, int a_Z) override + { + NIBBLETYPE Meta = a_World->GetBlockMeta(a_X, a_Y, a_Z); + + if ((Meta & 0x08) != 0) + { + a_World->GrowTree(a_X, a_Y, a_Z); + } + else + { + a_World->SetBlockMeta(a_X, a_Y, a_Z, Meta | 0x08); + } + } + + virtual bool CanBePlacedOnSide() override + { + return false; + } + + virtual AString GetStepSound(void) override + { + return "step.grass"; + } +}; diff --git a/source/Blocks/BlockSign.h b/source/Blocks/BlockSign.h new file mode 100644 index 000000000..dd82605b3 --- /dev/null +++ b/source/Blocks/BlockSign.h @@ -0,0 +1,47 @@ +#pragma once +#include "BlockHandler.h" +#include "../World.h" +#include "../Sign.h" +#include "../Player.h" + +class cBlockSignHandler : public cBlockHandler +{ +public: + cBlockSignHandler(BLOCKTYPE a_BlockID) + : cBlockHandler(a_BlockID) + { + + } + + virtual void PlaceBlock(cWorld *a_World, cPlayer *a_Player, NIBBLETYPE a_BlockMeta, int a_X, int a_Y, int a_Z, char a_Dir) override + { + BLOCKTYPE Block; + NIBBLETYPE Meta; + if(a_Dir == 1) + { + Meta = cSign::RotationToMetaData(a_Player->GetRotation()); + Block = E_BLOCK_SIGN_POST; + }else{ + Meta = cSign::DirectionToMetaData(a_Dir); + Block = E_BLOCK_WALLSIGN; + } + + a_World->SetBlock(a_X, a_Y, a_Z, Block, Meta); + OnPlacedByPlayer(a_World, a_Player, a_X, a_Y, a_Z, a_Dir); + } + + virtual int GetDropID() override + { + return E_ITEM_SIGN; + } + + virtual bool AllowBlockOnTop() override + { + return false; + } + + virtual AString GetStepSound(void) override + { + return "step.wood"; + } +}; diff --git a/source/Blocks/BlockSlab.h b/source/Blocks/BlockSlab.h new file mode 100644 index 000000000..ad9970d67 --- /dev/null +++ b/source/Blocks/BlockSlab.h @@ -0,0 +1,51 @@ +#pragma once +#include "BlockHandler.h" + + +class cBlockSlabHandler : public cBlockHandler +{ +public: + cBlockSlabHandler(BLOCKTYPE a_BlockID) + : cBlockHandler(a_BlockID) + { + } + + virtual NIBBLETYPE GetDropMeta(NIBBLETYPE a_BlockMeta) override + { + return a_BlockMeta; + } + + virtual char GetDropCount() override + { + if(m_BlockID == E_BLOCK_DOUBLE_STONE_SLAB + || m_BlockID == E_BLOCK_DOUBLE_WOODEN_SLAB) + return 2; + return 1; + } + + + virtual void PlaceBlock(cWorld *a_World, cPlayer *a_Player, NIBBLETYPE a_BlockMeta, int a_X, int a_Y, int a_Z, char a_Dir) override + { + a_World->SetBlock(a_X, a_Y, a_Z, m_BlockID, DirectionToMetaData( a_Dir, a_BlockMeta )); + OnPlacedByPlayer(a_World, a_Player, a_X, a_Y, a_Z, a_Dir); + } + + static char DirectionToMetaData( char a_Direction, NIBBLETYPE Meta ) + { + char result = Meta; + if( a_Direction == 0) + { + result |= 0x8; + } + return result; + } + + virtual AString GetStepSound(void) override + { + if (m_BlockID == E_BLOCK_WOODEN_SLAB || m_BlockID ==E_BLOCK_DOUBLE_WOODEN_SLAB) + return "step.wood"; + + else + return "step.stone"; + } +}; diff --git a/source/Blocks/BlockSnow.h b/source/Blocks/BlockSnow.h new file mode 100644 index 000000000..c8e6b4c1c --- /dev/null +++ b/source/Blocks/BlockSnow.h @@ -0,0 +1,44 @@ +#pragma once +#include "BlockHandler.h" + + +class cBlockSnowHandler : public cBlockHandler +{ +public: + cBlockSnowHandler(BLOCKTYPE a_BlockID) + : cBlockHandler(a_BlockID) + { + } + + virtual bool IgnoreBuildCollision() override + { + return true; + } + + virtual int GetDropID() override + { + return E_ITEM_SNOWBALL; + } + + virtual char GetDropCount() override + { + return 4; + } + + + virtual bool CanBeAt(cWorld *a_World, int a_X, int a_Y, int a_Z) override + { + return a_World->GetBlock(a_X, a_Y - 1, a_Z) != E_BLOCK_AIR; + } + + virtual bool DropOnUnsuitable() override + { + return false; + } + + virtual AString GetStepSound(void) override + { + return "step.cloth"; + } + +}; diff --git a/source/Blocks/BlockStairs.h b/source/Blocks/BlockStairs.h new file mode 100644 index 000000000..4d0007bc5 --- /dev/null +++ b/source/Blocks/BlockStairs.h @@ -0,0 +1,22 @@ +#pragma once +#include "BlockHandler.h" +#include "../Stairs.h" + +class cBlockStairsHandler : public cBlockHandler +{ +public: + cBlockStairsHandler(BLOCKTYPE a_BlockID) + : cBlockHandler(a_BlockID) + { + + } + + + virtual void PlaceBlock(cWorld *a_World, cPlayer *a_Player, NIBBLETYPE a_BlockMeta, int a_X, int a_Y, int a_Z, char a_Dir) override + { + a_World->SetBlock(a_X, a_Y, a_Z, m_BlockID, cStairs::RotationToMetaData(a_Player->GetRotation(), a_Dir)); + OnPlacedByPlayer(a_World, a_Player, a_X, a_Y, a_Z, a_Dir); + } + + //TODO: step sound +}; diff --git a/source/Blocks/BlockStems.h b/source/Blocks/BlockStems.h new file mode 100644 index 000000000..be4519a52 --- /dev/null +++ b/source/Blocks/BlockStems.h @@ -0,0 +1,46 @@ +#pragma once +#include "BlockHandler.h" +#include "../MersenneTwister.h" +#include "../World.h" + +class cBlockStemsHandler : public cBlockHandler +{ +public: + cBlockStemsHandler(BLOCKTYPE a_BlockID) + : cBlockHandler(a_BlockID) + { + } + + virtual bool NeedsRandomTicks() override + { + return true; + } + + virtual NIBBLETYPE GetDropMeta(NIBBLETYPE a_BlockMeta) override + { + return 0; + } + + virtual int GetDropID() override + { + if(m_BlockID == E_BLOCK_MELON_STEM) + return E_ITEM_MELON_SEEDS; + return E_ITEM_PUMPKIN_SEEDS; + } + + void OnUpdate(cWorld *a_World, int a_X, int a_Y, int a_Z) override + { + //TODO: Handle Growing here + } + + virtual bool CanBeAt(cWorld *a_World, int a_X, int a_Y, int a_Z) override + { + return a_World->GetBlock(a_X, a_Y - 1, a_Z) == E_BLOCK_FARMLAND; + } + + virtual AString GetStepSound(void) override + { + return "step.wood"; + } + +}; diff --git a/source/Blocks/BlockStone.h b/source/Blocks/BlockStone.h new file mode 100644 index 000000000..8b645bf1e --- /dev/null +++ b/source/Blocks/BlockStone.h @@ -0,0 +1,18 @@ +#pragma once +#include "BlockHandler.h" +#include "../MersenneTwister.h" +#include "../World.h" + +class cBlockStoneHandler : public cBlockHandler +{ +public: + cBlockStoneHandler(BLOCKTYPE a_BlockID) + : cBlockHandler(a_BlockID) + { + } + + virtual int GetDropID() override + { + return E_ITEM_COBBLESTONE; + } +}; \ No newline at end of file diff --git a/source/Blocks/BlockSugarcane.h b/source/Blocks/BlockSugarcane.h new file mode 100644 index 000000000..1d477b42b --- /dev/null +++ b/source/Blocks/BlockSugarcane.h @@ -0,0 +1,71 @@ + +#pragma once +#include "BlockHandler.h" + + + + + +class cBlockSugarcaneHandler : + public cBlockHandler +{ +public: + cBlockSugarcaneHandler(BLOCKTYPE a_BlockID) + : cBlockHandler(a_BlockID) + { + } + + + virtual bool NeedsRandomTicks() override + { + return true; + } + + + virtual int GetDropID() override + { + return E_ITEM_SUGARCANE; + } + + + virtual bool CanBeAt(cWorld * a_World, int a_X, int a_Y, int a_Z) override + { + switch (a_World->GetBlock(a_X, a_Y - 1, a_Z)) + { + case E_BLOCK_DIRT: + case E_BLOCK_GRASS: + case E_BLOCK_FARMLAND: + case E_BLOCK_SAND: + { + return a_World->IsBlockDirectlyWatered(a_X, a_Y - 1, a_Z); + } + case E_BLOCK_SUGARCANE: + { + return true; + } + } + return false; + } + + + void OnUpdate(cWorld * a_World, int a_X, int a_Y, int a_Z) override + { + //TODO: Handle Growing here + } + + + virtual bool CanBePlacedOnSide() override + { + return false; + } + + virtual AString GetStepSound(void) override + { + return "step.grass"; + } + +}; + + + + diff --git a/source/Blocks/BlockTallGrass.h b/source/Blocks/BlockTallGrass.h new file mode 100644 index 000000000..f5bb1b373 --- /dev/null +++ b/source/Blocks/BlockTallGrass.h @@ -0,0 +1,41 @@ +#pragma once +#include "BlockHandler.h" + + +class cBlockTallGrassHandler : public cBlockHandler +{ +public: + cBlockTallGrassHandler(BLOCKTYPE a_BlockID) + : cBlockHandler(a_BlockID) + { + } + + virtual bool IgnoreBuildCollision() override + { + return true; + } + + virtual int GetDropID() override + { + return E_ITEM_SEEDS; + } + + virtual char GetDropCount() override + { + MTRand r1; + if(r1.randInt(10) == 5) + return 1; + return 0; + } + + virtual bool CanBeAt(cWorld *a_World, int a_X, int a_Y, int a_Z) override + { + return a_World->GetBlock(a_X, a_Y - 1, a_Z) != E_BLOCK_AIR; + } + + virtual AString GetStepSound(void) override + { + return "step.grass"; + } + +}; diff --git a/source/Blocks/BlockTorch.h b/source/Blocks/BlockTorch.h new file mode 100644 index 000000000..450b5ecab --- /dev/null +++ b/source/Blocks/BlockTorch.h @@ -0,0 +1,166 @@ + +#pragma once +#include "BlockHandler.h" +#include "../Torch.h" +#include "../World.h" + + + + + +class cBlockTorchHandler : public cBlockHandler +{ +public: + cBlockTorchHandler(BLOCKTYPE a_BlockID) + : cBlockHandler(a_BlockID) + { + } + + + virtual void PlaceBlock(cWorld * a_World, cPlayer * a_Player, NIBBLETYPE a_BlockMeta, int a_X, int a_Y, int a_Z, char a_Dir) override + { + if(!TorchCanBePlacedAt(a_World, a_X, a_Y, a_Z, a_Dir)) + { + a_Dir = FindSuitableDirection(a_World, a_X, a_Y, a_Z); + + if(a_Dir == BLOCK_FACE_BOTTOM) + return; + } + + a_World->SetBlock(a_X, a_Y, a_Z, m_BlockID, cTorch::DirectionToMetaData(a_Dir)); + OnPlacedByPlayer(a_World, a_Player, a_X, a_Y, a_Z, a_Dir); + } + + + virtual bool AllowBlockOnTop(void) override + { + return false; + } + + + static bool CanBePlacedOn(BLOCKTYPE a_BlockType, char a_Direction) + { + switch (a_BlockType) + { + case E_BLOCK_STONE: + case E_BLOCK_GRASS: + case E_BLOCK_DIRT: + case E_BLOCK_COBBLESTONE: + case E_BLOCK_PLANKS: + case E_BLOCK_BEDROCK: + case E_BLOCK_SAND: + case E_BLOCK_GRAVEL: + case E_BLOCK_GOLD_ORE: + case E_BLOCK_IRON_ORE: + case E_BLOCK_COAL_ORE: + case E_BLOCK_LOG: + case E_BLOCK_SPONGE: + case E_BLOCK_LAPIS_ORE: + case E_BLOCK_LAPIS_BLOCK: + case E_BLOCK_SANDSTONE: + case E_BLOCK_WOOL: + case E_BLOCK_GOLD_BLOCK: + case E_BLOCK_IRON_BLOCK: + case E_BLOCK_DOUBLE_STONE_SLAB: + case E_BLOCK_BRICK: + case E_BLOCK_BOOKCASE: + case E_BLOCK_MOSSY_COBBLESTONE: + case E_BLOCK_OBSIDIAN: + case E_BLOCK_MOB_SPAWNER: + case E_BLOCK_DIAMOND_ORE: + case E_BLOCK_DIAMOND_BLOCK: + case E_BLOCK_CRAFTING_TABLE: + case E_BLOCK_REDSTONE_ORE: + case E_BLOCK_REDSTONE_ORE_GLOWING: + case E_BLOCK_SNOW_BLOCK: + case E_BLOCK_CLAY: + case E_BLOCK_JUKEBOX: + case E_BLOCK_PUMPKIN: + case E_BLOCK_NETHERRACK: + case E_BLOCK_SOULSAND: + case E_BLOCK_JACK_O_LANTERN: + case E_BLOCK_LOCKED_CHEST: + case E_BLOCK_STONE_BRICKS: + case E_BLOCK_MELON: + case E_BLOCK_MYCELIUM: + case E_BLOCK_NETHER_BRICK: + case E_BLOCK_END_STONE: + case E_BLOCK_REDSTONE_LAMP_OFF: + case E_BLOCK_REDSTONE_LAMP_ON: + case E_BLOCK_DOUBLE_WOODEN_SLAB: + case E_BLOCK_EMERALD_ORE: + case E_BLOCK_ENDER_CHEST: + case E_BLOCK_EMERALD_BLOCK: + { + return true; + } + + case E_BLOCK_GLASS: + case E_BLOCK_FENCE: + case E_BLOCK_NETHER_BRICK_FENCE: + { + return (a_Direction == 0x1); // allow only direction "standing on floor" + } + + default: + { + return false; + } + } + } + + + static bool TorchCanBePlacedAt(cWorld * a_World, int a_X, int a_Y, int a_Z, char a_Dir) + { + // TODO: If placing a torch from below, check all 4 XZ neighbors, place it on that neighbor instead + // How to propagate that change up? + // Simon: The easiest way is to calculate the position two times, shouldnīt cost much cpu power :) + + if(a_Dir == BLOCK_FACE_BOTTOM) + return false; + + AddDirection( a_X, a_Y, a_Z, a_Dir, true ); + + return CanBePlacedOn(a_World->GetBlock( a_X, a_Y, a_Z ), a_Dir); + } + + // Finds a suitable Direction for the Torch. Returns BLOCK_FACE_BOTTOM on failure + static char FindSuitableDirection(cWorld * a_World, int a_X, int a_Y, int a_Z) + { + for(int i = 1; i <= 5; i++) + { + if(TorchCanBePlacedAt(a_World, a_X, a_Y, a_Z, i)) + return i; + } + return BLOCK_FACE_BOTTOM; + } + + virtual bool CanBePlacedAt(cWorld * a_World, int a_X, int a_Y, int a_Z, char a_Dir) override + { + if(TorchCanBePlacedAt(a_World, a_X, a_Y, a_Z, a_Dir)) + return true; + + return FindSuitableDirection(a_World, a_X, a_Y, a_Z) != BLOCK_FACE_BOTTOM; + } + + + virtual bool CanBeAt(cWorld * a_World, int a_X, int a_Y, int a_Z) override + { + char Dir = cTorch::MetaDataToDirection(a_World->GetBlockMeta( a_X, a_Y, a_Z)); + return TorchCanBePlacedAt(a_World, a_X, a_Y, a_Z, Dir); + } + + virtual NIBBLETYPE GetDropMeta(NIBBLETYPE a_BlockMeta) override + { + return 0; + } + + virtual AString GetStepSound(void) override + { + return "step.wood"; + } +}; + + + + diff --git a/source/Blocks/BlockVine.h b/source/Blocks/BlockVine.h new file mode 100644 index 000000000..56317219a --- /dev/null +++ b/source/Blocks/BlockVine.h @@ -0,0 +1,35 @@ +#pragma once +#include "BlockHandler.h" +#include "../Vine.h" + +class cBlockVineHandler : public cBlockHandler +{ +public: + cBlockVineHandler(BLOCKTYPE a_BlockID) + : cBlockHandler(a_BlockID) + { + } + + virtual bool IgnoreBuildCollision() override + { + return true; + } + + virtual void PlaceBlock(cWorld *a_World, cPlayer *a_Player, NIBBLETYPE a_BlockMeta, int a_X, int a_Y, int a_Z, char a_Dir) override + { + a_World->SetBlock(a_X, a_Y, a_Z, m_BlockID, cVine::DirectionToMetaData(a_Dir)); + OnPlacedByPlayer(a_World, a_Player, a_X, a_Y, a_Z, a_Dir); + } + + + virtual bool AllowBlockOnTop() override + { + return false; + } + + virtual AString GetStepSound(void) override + { + return "step.grass"; + } + +}; diff --git a/source/Blocks/BlockWood.h b/source/Blocks/BlockWood.h new file mode 100644 index 000000000..d71d5d71c --- /dev/null +++ b/source/Blocks/BlockWood.h @@ -0,0 +1,22 @@ +#pragma once +#include "BlockHandler.h" + + +class cBlockWoodHandler : public cBlockHandler +{ +public: + cBlockWoodHandler(BLOCKTYPE a_BlockID) + : cBlockHandler(a_BlockID) + { + } + NIBBLETYPE GetDropMeta(NIBBLETYPE a_BlockMeta) override + { + return a_BlockMeta; + } + + virtual AString GetStepSound(void) override + { + return "step.wood"; + } + +}; diff --git a/source/Blocks/BlockWorkbench.h b/source/Blocks/BlockWorkbench.h new file mode 100644 index 000000000..c1c004dc5 --- /dev/null +++ b/source/Blocks/BlockWorkbench.h @@ -0,0 +1,36 @@ +#pragma once +#include "BlockHandler.h" +#include "../UI/Window.h" +#include "../Player.h" + + + + + +class cBlockWorkbenchHandler: + public cBlockHandler +{ +public: + cBlockWorkbenchHandler(BLOCKTYPE a_BlockID) + : cBlockHandler(a_BlockID) + { + } + + virtual void OnUse(cWorld * a_World, cPlayer *a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) override + { + cWindow * Window = new cCraftingWindow(a_BlockX, a_BlockY, a_BlockZ); + a_Player->OpenWindow(Window); + } + + virtual bool IsUseable() override + { + return true; + } + + virtual AString GetStepSound(void) override + { + return "step.wood"; + } + + +}; \ No newline at end of file diff --git a/source/Chunk.cpp b/source/Chunk.cpp index cb4e5511f..e7a828c66 100644 --- a/source/Chunk.cpp +++ b/source/Chunk.cpp @@ -29,7 +29,7 @@ #include "Player.h" #include "BlockArea.h" #include "PluginManager.h" -#include "blocks/BlockHandler.h" +#include "Blocks/BlockHandler.h" #include diff --git a/source/ClientHandle.cpp b/source/ClientHandle.cpp index e32e03f16..1585a08b0 100644 --- a/source/ClientHandle.cpp +++ b/source/ClientHandle.cpp @@ -23,8 +23,8 @@ #include "ChatColor.h" #include "OSSupport/Socket.h" #include "OSSupport/Timer.h" -#include "items/ItemHandler.h" -#include "blocks/BlockHandler.h" +#include "Items/ItemHandler.h" +#include "Blocks/BlockHandler.h" #include "Tracer.h" #include "Vector3f.h" diff --git a/source/FluidSimulator.cpp b/source/FluidSimulator.cpp index 804db9d36..d8007b9bf 100644 --- a/source/FluidSimulator.cpp +++ b/source/FluidSimulator.cpp @@ -9,7 +9,7 @@ #include "BlockID.h" #include "Defines.h" #include "Item.h" -#include "blocks/BlockHandler.h" +#include "Blocks/BlockHandler.h" diff --git a/source/Inventory.cpp b/source/Inventory.cpp index 1ad349fb5..c35a6c5d0 100644 --- a/source/Inventory.cpp +++ b/source/Inventory.cpp @@ -10,7 +10,7 @@ #include -#include "items/ItemHandler.h" +#include "Items/ItemHandler.h" diff --git a/source/Items/ItemBed.h b/source/Items/ItemBed.h new file mode 100644 index 000000000..b49df65a3 --- /dev/null +++ b/source/Items/ItemBed.h @@ -0,0 +1,25 @@ + +#pragma once + +#include "ItemHandler.h" +#include "../World.h" + +class cItemBedHandler : public cItemHandler +{ +public: + cItemBedHandler(int a_ItemID) + : cItemHandler(a_ItemID) + { + + } + + virtual bool IsPlaceable() override + { + return true; + } + + virtual BLOCKTYPE GetBlockType() override + { + return E_BLOCK_BED; + } +}; \ No newline at end of file diff --git a/source/Items/ItemBucket.h b/source/Items/ItemBucket.h new file mode 100644 index 000000000..736112960 --- /dev/null +++ b/source/Items/ItemBucket.h @@ -0,0 +1,94 @@ + +#pragma once + +#include "ItemHandler.h" +#include "../World.h" + +class cItemBucketHandler : public cItemHandler +{ +public: + cItemBucketHandler(int a_ItemID) + : cItemHandler(a_ItemID) + { + + } + + virtual bool OnItemUse(cWorld *a_World, cPlayer *a_Player, cItem *a_Item, int a_X, int a_Y, int a_Z, char a_Dir) override + { + switch(m_ItemID) + { + case E_ITEM_BUCKET: + { + if (a_Dir >= 0) + { + AddDirection(a_X, a_Y, a_Z, a_Dir); + } + BLOCKTYPE ClickedBlock = a_World->GetBlock(a_X, a_Y, a_Z); + LOG("Bucket Clicked BlockID: %d", ClickedBlock); + ENUM_ITEM_ID NewItem = E_ITEM_EMPTY; + switch (ClickedBlock) + { + 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; + } + } + cItem Item(a_Item->m_ItemID, 1); + if ( + (NewItem != E_ITEM_EMPTY) && + ( + ((a_Player->GetGameMode() == 1) || + a_Player->GetInventory().RemoveItem(Item)) + ) + ) + { + // Give New Bucket + cItem Item(NewItem, 1); + a_Player->GetInventory().AddItem(Item); + // Remove water / lava block + a_Player->GetWorld()->SetBlock(a_X, a_Y, a_Z, E_BLOCK_AIR, 0); + return true; + } + break; + } + + case E_ITEM_WATER_BUCKET: + case E_ITEM_LAVA_BUCKET: + { + BLOCKTYPE NewBlock = (m_ItemID == E_ITEM_LAVA_BUCKET) ? E_BLOCK_LAVA : E_BLOCK_WATER; + if (a_Dir >= 0) + { + AddDirection(a_X, a_Y, a_Z, a_Dir); + } + if(a_World->GetBlock(a_X, a_Y, a_Z) == E_BLOCK_AIR) + { + cItem Item(a_Item->m_ItemID, 1); + if ((a_Player->GetGameMode() == 1) || (a_Player->GetInventory().RemoveItem(Item))) + { + a_World->SetBlock(a_X, a_Y, a_Z, NewBlock, 0); + + if (a_Player->GetGameMode() == 1) + { + break; //No new Bucket for creative players + } + cItem Item(E_ITEM_BUCKET, 1); + a_Player->GetInventory().AddItem(Item); + return true; + } + } + } + break; + } + + return false; + } + +}; \ No newline at end of file diff --git a/source/Items/ItemCloth.h b/source/Items/ItemCloth.h new file mode 100644 index 000000000..5de064397 --- /dev/null +++ b/source/Items/ItemCloth.h @@ -0,0 +1,23 @@ + +#pragma once + +#include "ItemHandler.h" + + + + + +class cItemClothHandler : + public cItemHandler +{ +public: + cItemClothHandler(int a_ItemID) + : cItemHandler(a_ItemID) + { + + } +} ; + + + + diff --git a/source/Items/ItemDoor.h b/source/Items/ItemDoor.h new file mode 100644 index 000000000..6e841333f --- /dev/null +++ b/source/Items/ItemDoor.h @@ -0,0 +1,26 @@ + +#pragma once + +#include "ItemHandler.h" +#include "../World.h" + +class cItemDoorHandler : public cItemHandler +{ +public: + cItemDoorHandler(int a_ItemID) + : cItemHandler(a_ItemID) + { + + } + + virtual bool IsPlaceable() override + { + return true; + } + + virtual BLOCKTYPE GetBlockType() override + { + return (m_ItemID == E_ITEM_WOODEN_DOOR) ? E_BLOCK_WOODEN_DOOR : E_BLOCK_IRON_DOOR; + } + +}; \ No newline at end of file diff --git a/source/Items/ItemDye.h b/source/Items/ItemDye.h new file mode 100644 index 000000000..5b21a501c --- /dev/null +++ b/source/Items/ItemDye.h @@ -0,0 +1,35 @@ + +#pragma once + +#include "ItemHandler.h" +#include "../World.h" +#include "../Player.h" + +class cItemDyeHandler : public cItemHandler +{ +public: + cItemDyeHandler(int a_ItemID) + : cItemHandler(a_ItemID) + { + + } + + virtual bool OnItemUse(cWorld *a_World, cPlayer *a_Player, cItem *a_Item, int a_X, int a_Y, int a_Z, char a_Dir) override + { + // TODO: Handle coloring the sheep, too (OnItemUseOnEntity maybe) + // Handle growing the plants: + if (a_Item->m_ItemHealth == E_META_DYE_WHITE) + { + if(a_World->GrowPlant(a_X, a_Y, a_Z, true)) + { + if (a_Player->GetGameMode() == eGameMode_Survival) + { + cItem Item(a_Item->m_ItemID, 1, a_Item->m_ItemHealth); + a_Player->GetInventory().RemoveItem(Item); + return true; + } + } + } + return false; + } +}; \ No newline at end of file diff --git a/source/Items/ItemFood.h b/source/Items/ItemFood.h new file mode 100644 index 000000000..6e5a27d5d --- /dev/null +++ b/source/Items/ItemFood.h @@ -0,0 +1,56 @@ + +#pragma once + +#include "ItemHandler.h" + + +class cItemFoodHandler : public cItemHandler +{ +public: + cItemFoodHandler(int a_ItemID) + : cItemHandler(a_ItemID) + { + } + + virtual bool IsFood() override + { + return true; + } + + virtual FoodInfo GetFoodInfo() override + { + switch(m_ItemID) + { + case E_ITEM_BREAD: + return FoodInfo(5, 6.f); + case E_ITEM_COOKIE: + return FoodInfo(2, 0.4f); + case E_ITEM_MELON_SLICE: + return FoodInfo(2, 1.2f); + case E_ITEM_RAW_CHICKEN: + return FoodInfo(2, 1.2f, 30); + case E_ITEM_COOKED_CHICKEN: + return FoodInfo(6, 7.2f); + case E_ITEM_RAW_BEEF: + case E_ITEM_RAW_MEAT: + return FoodInfo(3, 1.8f); + case E_ITEM_STEAK: + case E_ITEM_COOKED_MEAT: + return FoodInfo(8, 12.8f); + case E_ITEM_RAW_FISH: + return FoodInfo(2, 1.2f); + case E_ITEM_COOKED_FISH: + return FoodInfo(5, 6.f); + case E_ITEM_RED_APPLE: + return FoodInfo(4, 2.4f); + case E_ITEM_GOLDEN_APPLE: + return FoodInfo(4, 9.6f); + case E_ITEM_ROTTEN_FLESH: + return FoodInfo(4, 0.8f, 80); + case E_ITEM_SPIDER_EYE: + return FoodInfo(2, 3.2f, 100); + } + return FoodInfo(0, 0.f); + } + +}; \ No newline at end of file diff --git a/source/Items/ItemHandler.cpp b/source/Items/ItemHandler.cpp new file mode 100644 index 000000000..49ed865e7 --- /dev/null +++ b/source/Items/ItemHandler.cpp @@ -0,0 +1,422 @@ + +#include "Globals.h" +#include "ItemHandler.h" +#include "../Item.h" +#include "../World.h" +#include "../Player.h" + +//Handler +#include "ItemCloth.h" +#include "ItemHoe.h" +#include "ItemSlab.h" +#include "ItemWood.h" +#include "ItemShears.h" +#include "ItemLeaves.h" +#include "ItemSapling.h" +#include "ItemBucket.h" +#include "ItemLighter.h" +#include "ItemRedstoneDust.h" +#include "ItemRedstoneRepeater.h" +#include "ItemSeeds.h" +#include "ItemDye.h" +#include "ItemSugarcane.h" +#include "ItemPickaxe.h" +#include "ItemShovel.h" +#include "ItemSword.h" +#include "ItemDoor.h" +#include "ItemFood.h" +#include "ItemSign.h" +#include "ItemBed.h" + +#include "../Blocks/BlockHandler.h" + + + + + +bool cItemHandler::m_HandlerInitialized = false; +cItemHandler * cItemHandler::m_ItemHandler[2266]; + + + + + +cItemHandler *cItemHandler::GetItemHandler(int a_ItemID) +{ + if(a_ItemID < 0) a_ItemID = 0; + + if(!m_HandlerInitialized) + { //We have to initialize + memset(m_ItemHandler, 0, sizeof(m_ItemHandler)); + m_HandlerInitialized = true; + } + if(m_ItemHandler[a_ItemID]) + return m_ItemHandler[a_ItemID]; + m_ItemHandler[a_ItemID] = CreateItemHandler(a_ItemID); + return m_ItemHandler[a_ItemID]; +} + + + + + +cItemHandler *cItemHandler::CreateItemHandler(int a_ItemID) +{ + switch(a_ItemID) + { + default: return new cItemHandler(a_ItemID); + + // Single item per handler: + case E_ITEM_SHEARS: return new cItemShearsHandler(a_ItemID); + case E_ITEM_LEAVES: return new cItemLeavesHandler(a_ItemID); + case E_ITEM_SAPLING: return new cItemSaplingHandler(a_ItemID); + case E_ITEM_DYE: return new cItemDyeHandler(a_ItemID); + case E_ITEM_SUGARCANE: return new cItemSugarcaneHandler(a_ItemID); + case E_ITEM_FLINT_AND_STEEL: return new cItemLighterHandler(a_ItemID); + case E_ITEM_REDSTONE_DUST: return new cItemRedstoneDustHandler(a_ItemID); + case E_ITEM_REDSTONE_REPEATER: return new cItemRedstoneRepeaterHandler(a_ItemID); + case E_ITEM_WOOL: return new cItemClothHandler(a_ItemID); + + case E_ITEM_WOODEN_HOE: + case E_ITEM_STONE_HOE: + case E_ITEM_IRON_HOE: + case E_ITEM_GOLD_HOE: + case E_ITEM_DIAMOND_HOE: + { + return new cItemHoeHandler(a_ItemID); + } + + case E_ITEM_WOODEN_PICKAXE: + case E_ITEM_STONE_PICKAXE: + case E_ITEM_IRON_PICKAXE: + case E_ITEM_GOLD_PICKAXE: + case E_ITEM_DIAMOND_PICKAXE: + { + return new cItemPickaxeHandler(a_ItemID); + } + + case E_ITEM_WOODEN_SHOVEL: + case E_ITEM_STONE_SHOVEL: + case E_ITEM_IRON_SHOVEL: + case E_ITEM_GOLD_SHOVEL: + case E_ITEM_DIAMOND_SHOVEL: + { + return new cItemShovelHandler(a_ItemID); + } + + case E_ITEM_WOODEN_SWORD: + case E_ITEM_STONE_SWORD: + case E_ITEM_IRON_SWORD: + case E_ITEM_GOLD_SWORD: + case E_ITEM_DIAMOND_SWORD: + { + return new cItemSwordHandler(a_ItemID); + } + + case E_ITEM_STONE_SLAB: + case E_ITEM_WOODEN_SLAB: + { + return new cItemSlabHandler(a_ItemID); + } + + case E_ITEM_LOG: + case E_ITEM_PLANKS: + { + return new cItemWoodHandler(a_ItemID); + } + + case E_ITEM_BUCKET: + case E_ITEM_WATER_BUCKET: + case E_ITEM_LAVA_BUCKET: + { + return new cItemBucketHandler(a_ItemID); + } + + case E_ITEM_PUMPKIN_SEEDS: + case E_ITEM_MELON_SEEDS: + case E_ITEM_SEEDS: + { + return new cItemSeedsHandler(a_ItemID); + } + + case E_ITEM_IRON_DOOR: + case E_ITEM_WOODEN_DOOR: + { + return new cItemDoorHandler(a_ItemID); + } + + // Food: + case E_ITEM_BREAD: + case E_ITEM_COOKIE: + case E_ITEM_MELON_SLICE: + case E_ITEM_RAW_CHICKEN: + case E_ITEM_COOKED_CHICKEN: + case E_ITEM_RAW_BEEF: + case E_ITEM_RAW_MEAT: + case E_ITEM_STEAK: + case E_ITEM_COOKED_MEAT: + case E_ITEM_RAW_FISH: + case E_ITEM_COOKED_FISH: + case E_ITEM_RED_APPLE: + case E_ITEM_GOLDEN_APPLE: + case E_ITEM_ROTTEN_FLESH: + case E_ITEM_SPIDER_EYE: + { + return new cItemFoodHandler(a_ItemID); + } + + case E_ITEM_SIGN: + return new cItemSignHandler(a_ItemID); + + case E_ITEM_BED: + return new cItemBedHandler(a_ItemID); + } +} + + + + + +void cItemHandler::Deinit() +{ + for(int i = 0; i < 2266; i++) + { + delete m_ItemHandler[i]; + } + m_HandlerInitialized = false; +} + + + + + +cItemHandler::cItemHandler(int a_ItemID) +{ + m_ItemID = a_ItemID; +} + + + + + +bool cItemHandler::OnItemUse(cWorld *a_World, cPlayer *a_Player, cItem *a_Item, int a_X, int a_Y, int a_Z, char a_Dir) +{ + return false; +} + + + + + +bool cItemHandler::OnDiggingBlock(cWorld *a_World, cPlayer *a_Player, cItem *a_Item, int a_X, int a_Y, int a_Z, char a_Dir) +{ + return false; +} + + + + + +void cItemHandler::OnBlockDestroyed(cWorld *a_World, cPlayer *a_Player, cItem *a_Item, int a_X, int a_Y, int a_Z) +{ + char Block = a_World->GetBlock(a_X, a_Y, a_Z); + cBlockHandler *Handler = cBlockHandler::GetBlockHandler(Block); + + if(a_Player->GetGameMode() == eGameMode_Survival) + { + if(!BlockRequiresSpecialTool(Block) || CanHarvestBlock(Block)) + { + Handler->DropBlock(a_World, a_X, a_Y, a_Z); + } + } + + a_Player->UseEquippedItem(); +} + + + + + +void cItemHandler::OnFoodEaten(cWorld *a_World, cPlayer *a_Player, cItem *a_Item) +{ + +} + + + + + +char cItemHandler::GetMaxStackSize(void) +{ + if (m_ItemID < 256) + { + // All blocks can stack up to 64 + return 64; + } + + switch (m_ItemID) + { + case E_ITEM_APPLE: return 64; + case E_ITEM_ARROW: return 64; + case E_ITEM_BLAZE_POWDER: return 64; + case E_ITEM_BLAZE_ROD: return 64; + case E_ITEM_BONE: return 64; + case E_ITEM_BOOK: return 64; + case E_ITEM_BOWL: return 64; + case E_ITEM_BREAD: return 64; + case E_ITEM_BROWN_MUSHROOM: return 64; + case E_ITEM_BUCKET: return 1; // TODO: change this to 16 when turning compatibility to 1.3 + case E_ITEM_COAL: return 64; + case E_ITEM_COOKED_CHICKEN: return 64; + case E_ITEM_COOKED_FISH: return 64; + case E_ITEM_COOKED_PORKCHOP: return 64; + case E_ITEM_DIAMOND: return 64; + case E_ITEM_FEATHER: return 64; + case E_ITEM_FLINT: return 64; + case E_ITEM_GOLD: return 64; + case E_ITEM_GUNPOWDER: return 64; + case E_ITEM_IRON: return 64; + case E_ITEM_RAW_PORKCHOP: return 64; + case E_ITEM_SEEDS: return 64; + case E_ITEM_STICK: return 64; + case E_ITEM_STRING: return 64; + case E_ITEM_WHEAT: return 64; + } + // By default items don't stack: + return 1; +} + + + + + +bool cItemHandler::IsTool() +{ + return + (m_ItemID >= 256 && m_ItemID <= 259) + || (m_ItemID == 261) + || (m_ItemID >= 267 && m_ItemID <= 279) + || (m_ItemID >= 283 && m_ItemID <= 286) + || (m_ItemID >= 290 && m_ItemID <= 294) + || (m_ItemID >= 256 && m_ItemID <= 259) + || (m_ItemID == 325) + || (m_ItemID == 346); +} + + + + + +bool cItemHandler::IsFood() +{ + return + (m_ItemID == 260) + || (m_ItemID == 282) + || (m_ItemID == 297) + || (m_ItemID >= 319 && m_ItemID <= 320) + || (m_ItemID == 335) + || (m_ItemID >= 349 && m_ItemID <= 350) + || (m_ItemID == 357) + || (m_ItemID == 360) + || (m_ItemID >= 363 && m_ItemID <= 366); +} + + + + + +bool cItemHandler::IsPlaceable() +{ + return m_ItemID >= 1 && m_ItemID <= 136; +} + + + + + +bool cItemHandler::CanHarvestBlock(BLOCKTYPE a_BlockID) +{ + return false; +} + + + + + +BLOCKTYPE cItemHandler::GetBlockType() +{ + ASSERT(m_ItemID < 256); // Items with IDs above 255 should all be handled by specific handlers + + #ifdef _DEBUG + if (m_ItemID > 256) + { + LOGERROR("Item %d has no valid block!", m_ItemID); + } + #endif // _DEBUG + + return (BLOCKTYPE) m_ItemID; +} + + + + + +NIBBLETYPE cItemHandler::GetBlockMeta(short a_ItemDamage) +{ + return (NIBBLETYPE)a_ItemDamage & 0x0f; // This keeps most textures. The few other items have to override this +} + + + + + +void cItemHandler::PlaceBlock(cWorld *a_World, cPlayer *a_Player, cItem *a_Item, int a_X, int a_Y, int a_Z, char a_Dir) +{ + BLOCKTYPE Block = GetBlockType(); + cBlockHandler *Handler = cBlockHandler::GetBlockHandler(Block); + Handler->PlaceBlock(a_World, a_Player, GetBlockMeta(a_Item->m_ItemHealth), a_X, a_Y, a_Z, a_Dir); + if(a_Player->GetGameMode() == eGameMode_Survival) + { + cItem Item(a_Item->m_ItemID, 1); + a_Player->GetInventory().RemoveItem(Item); + } +} + + + + + +bool cItemHandler::EatItem(cPlayer *a_Player, cItem *a_Item) +{ + FoodInfo Info = GetFoodInfo(); + + if(Info.FoodLevel > 0 || Info.Saturation > 0.f) + { + bool Success = a_Player->Feed(Info.FoodLevel, Info.Saturation); + if(Success && Info.PoisionChance > 0) + { + MTRand r1; + if((r1.randInt(100) - Info.PoisionChance) <= 0) + { //Unlucky guy :D + //TODO: Make player ill + } + } + + return Success; + } + + return false; +} + + + + + +cItemHandler::FoodInfo cItemHandler::GetFoodInfo() +{ + return FoodInfo(0, 0.f); +} + + + + diff --git a/source/Items/ItemHandler.h b/source/Items/ItemHandler.h new file mode 100644 index 000000000..67935ecb4 --- /dev/null +++ b/source/Items/ItemHandler.h @@ -0,0 +1,83 @@ + +#pragma once +#include "../Defines.h" + + + + + +// fwd: +class cWorld; +class cPlayer; + + + + + +class cItemHandler +{ +public: + cItemHandler(int a_ItemID); + // Called when the player tries to use the item. Return false to make the item unusable. DEFAULT: False + virtual bool OnItemUse(cWorld *a_World, cPlayer *a_Player, cItem *a_Item, int a_X, int a_Y, int a_Z, char a_Dir); //eg for fishing or hoes + // Called while the player diggs a block using this item + virtual bool OnDiggingBlock(cWorld * a_World, cPlayer * a_Player, cItem * a_HeldItem, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace); + // Called when the player destroys a block using this item. This also calls the drop function for the destroyed block + virtual void OnBlockDestroyed(cWorld *a_World, cPlayer *a_Player, cItem *a_Item, int a_X, int a_Y, int a_Z); + // Called after the player has eaten this item. + virtual void OnFoodEaten(cWorld *a_World, cPlayer *a_Player, cItem *a_Item); + + /// Returns the maximum stack size for a given item + virtual char GetMaxStackSize(void); + + struct FoodInfo + { + FoodInfo(short a_FoodLevel, float a_Saturation, char a_PoisionChance = 0) + { + FoodLevel = a_FoodLevel; + Saturation = a_Saturation; + PoisionChance = a_PoisionChance; + } + short FoodLevel; + float Saturation; + char PoisionChance; //0 - 100 + }; + + // Returns the FoodInfo for this item. (FoodRecovery, Saturation and PoisionChance) + virtual FoodInfo GetFoodInfo(); + + // Lets the player eat a selected item. Returns true if the player ate the item + virtual bool EatItem(cPlayer *a_Player, cItem *a_Item); + + // Places the current block and removes the item from the player inventory + virtual void PlaceBlock(cWorld *a_World, cPlayer *a_Player, cItem *a_Item, int a_X, int a_Y, int a_Z, char a_Dir); + + // Indicates if this item is a tool + virtual bool IsTool(); + // Indicates if this item is food + virtual bool IsFood(); + //Blocks simply get placed + virtual bool IsPlaceable(); + + // Returns the block type on placement + virtual BLOCKTYPE GetBlockType(); + //Returns the block meta on placement + virtual NIBBLETYPE GetBlockMeta(short a_ItemDamage); + // Returns whether this tool/item can harvest a specific block (e.g. wooden pickaxe can harvest stone, but wood canīt) DEFAULT: False + virtual bool CanHarvestBlock(BLOCKTYPE a_BlockID); + + static cItemHandler *GetItemHandler(int a_ItemID); + + static void Deinit(); + + +protected: + int m_ItemID; + static cItemHandler *CreateItemHandler(int m_ItemID); + + static cItemHandler *m_ItemHandler[2266]; + static bool m_HandlerInitialized; //used to detect if the itemhandlers are initialized +}; + +//Short function +inline cItemHandler *ItemHandler(int a_ItemID) { return cItemHandler::GetItemHandler(a_ItemID); } \ No newline at end of file diff --git a/source/Items/ItemHoe.h b/source/Items/ItemHoe.h new file mode 100644 index 000000000..e7ea9135c --- /dev/null +++ b/source/Items/ItemHoe.h @@ -0,0 +1,31 @@ + +#pragma once + +#include "ItemHandler.h" +#include "../World.h" +#include "../Player.h" + +class cItemHoeHandler : public cItemHandler +{ +public: + cItemHoeHandler(int a_ItemID) + : cItemHandler(a_ItemID) + { + + } + + virtual bool OnItemUse(cWorld *a_World, cPlayer *a_Player, cItem *a_Item, int a_X, int a_Y, int a_Z, char a_Dir) override + { + BLOCKTYPE Block = a_World->GetBlock(a_X, a_Y, a_Z); + + if(Block == E_BLOCK_DIRT || Block == E_BLOCK_GRASS) + { + a_World->FastSetBlock(a_X, a_Y, a_Z, E_BLOCK_FARMLAND, 0); + + a_Player->UseEquippedItem(); + return true; + + } + return false; + } +}; \ No newline at end of file diff --git a/source/Items/ItemLeaves.h b/source/Items/ItemLeaves.h new file mode 100644 index 000000000..f96adb0b8 --- /dev/null +++ b/source/Items/ItemLeaves.h @@ -0,0 +1,27 @@ + +#pragma once + +#include "ItemHandler.h" + + + + + +class cItemLeavesHandler : + public cItemHandler +{ +public: + cItemLeavesHandler(int a_ItemID) + : cItemHandler(a_ItemID) + { + } + + virtual NIBBLETYPE GetBlockMeta(short a_ItemDamage) override + { + return (NIBBLETYPE)(a_ItemDamage & 0x0f) | 0x4; //0x4 bit set means this is a player-placed leaves block, not to be decayed + } +} ; + + + + diff --git a/source/Items/ItemLighter.h b/source/Items/ItemLighter.h new file mode 100644 index 000000000..92279aafa --- /dev/null +++ b/source/Items/ItemLighter.h @@ -0,0 +1,27 @@ +#pragma once + +#include "ItemHandler.h" +#include "../World.h" +#include "../Player.h" + +class cItemLighterHandler : public cItemHandler +{ +public: + cItemLighterHandler(int a_ItemID) + : cItemHandler(a_ItemID) + { + + } + + virtual bool OnItemUse(cWorld *a_World, cPlayer *a_Player, cItem *a_Item, int a_X, int a_Y, int a_Z, char a_Dir) override + { + a_Player->UseEquippedItem(); + + AddDirection(a_X, a_Y, a_Z, a_Dir); + + a_World->SetBlock(a_X, a_Y, a_Z, E_BLOCK_FIRE, 0); //0 -> new fire TODO: Make Firesimulator use this + + return false; + } + +}; \ No newline at end of file diff --git a/source/Items/ItemPickaxe.h b/source/Items/ItemPickaxe.h new file mode 100644 index 000000000..158aca44f --- /dev/null +++ b/source/Items/ItemPickaxe.h @@ -0,0 +1,75 @@ + +#pragma once + +#include "ItemHandler.h" +#include "../World.h" +#include "../Player.h" + +class cItemPickaxeHandler : public cItemHandler +{ +public: + cItemPickaxeHandler(int a_ItemID) + : cItemHandler(a_ItemID) + { + + } + + char PickaxeLevel() + { + switch(m_ItemID) + { + 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; + } + } + + virtual bool CanHarvestBlock(BLOCKTYPE a_BlockID) override + { + switch(a_BlockID) + { + case E_BLOCK_OBSIDIAN: + return PickaxeLevel() >= 4; + case E_BLOCK_DIAMOND_BLOCK: + case E_BLOCK_DIAMOND_ORE: + case E_BLOCK_GOLD_BLOCK: + case E_BLOCK_GOLD_ORE: + case E_BLOCK_REDSTONE_ORE: + case E_BLOCK_REDSTONE_ORE_GLOWING: + case E_BLOCK_EMERALD_ORE: + return PickaxeLevel() >= 3; + case E_BLOCK_IRON_BLOCK: + case E_BLOCK_IRON_ORE: + case E_BLOCK_LAPIS_ORE: + case E_BLOCK_LAPIS_BLOCK: + return PickaxeLevel() >= 2; + case E_BLOCK_COAL_ORE: + case E_BLOCK_STONE: + case E_BLOCK_COBBLESTONE: + case E_BLOCK_END_STONE: + case E_BLOCK_MOSSY_COBBLESTONE: + case E_BLOCK_SANDSTONE_STAIRS: + case E_BLOCK_SANDSTONE: + case E_BLOCK_STONE_BRICKS: + case E_BLOCK_NETHER_BRICK: + case E_BLOCK_NETHERRACK: + case E_BLOCK_STONE_SLAB: + case E_BLOCK_DOUBLE_STONE_SLAB: + case E_BLOCK_STONE_PRESSURE_PLATE: + case E_BLOCK_BRICK: + case E_BLOCK_COBBLESTONE_STAIRS: + case E_BLOCK_STONE_BRICK_STAIRS: + case E_BLOCK_NETHER_BRICK_STAIRS: + return PickaxeLevel() >= 1; + } + return false; + } +}; \ No newline at end of file diff --git a/source/Items/ItemRedstoneDust.h b/source/Items/ItemRedstoneDust.h new file mode 100644 index 000000000..1ce316d9e --- /dev/null +++ b/source/Items/ItemRedstoneDust.h @@ -0,0 +1,36 @@ + +#pragma once + +#include "ItemHandler.h" + + + + + +class cItemRedstoneDustHandler : public cItemHandler +{ +public: + cItemRedstoneDustHandler(int a_ItemID) + : cItemHandler(a_ItemID) + { + } + + virtual bool IsPlaceable() override + { + return true; + } + + virtual BLOCKTYPE GetBlockType() override + { + return E_BLOCK_REDSTONE_WIRE; + } + + virtual NIBBLETYPE GetBlockMeta(short a_ItemDamage) override + { + return 0; + } +} ; + + + + diff --git a/source/Items/ItemRedstoneRepeater.h b/source/Items/ItemRedstoneRepeater.h new file mode 100644 index 000000000..c31c2af53 --- /dev/null +++ b/source/Items/ItemRedstoneRepeater.h @@ -0,0 +1,36 @@ + +#pragma once + +#include "ItemHandler.h" + + + + + +class cItemRedstoneRepeaterHandler : public cItemHandler +{ +public: + cItemRedstoneRepeaterHandler(int a_ItemID) + : cItemHandler(a_ItemID) + { + } + + virtual bool IsPlaceable() override + { + return true; + } + + virtual BLOCKTYPE GetBlockType() override + { + return ::E_BLOCK_REDSTONE_REPEATER_OFF; + } + + virtual NIBBLETYPE GetBlockMeta(short a_ItemMeta) override + { + return 0; + } +} ; + + + + diff --git a/source/Items/ItemSapling.h b/source/Items/ItemSapling.h new file mode 100644 index 000000000..b0c223f29 --- /dev/null +++ b/source/Items/ItemSapling.h @@ -0,0 +1,28 @@ + +#pragma once + +#include "ItemHandler.h" + + + + + +class cItemSaplingHandler : public cItemHandler +{ +public: + cItemSaplingHandler(int a_ItemID) + : cItemHandler(a_ItemID) + { + + } + + virtual NIBBLETYPE GetBlockMeta(short a_ItemDamage) override + { + // Only the lowest 3 bits are important + return (NIBBLETYPE)(a_ItemDamage & 0x07); + } +} ; + + + + diff --git a/source/Items/ItemSeeds.h b/source/Items/ItemSeeds.h new file mode 100644 index 000000000..3eb9d6e86 --- /dev/null +++ b/source/Items/ItemSeeds.h @@ -0,0 +1,59 @@ + +#pragma once + +#include "ItemHandler.h" +#include "../World.h" + + + + + +class cItemSeedsHandler : + public cItemHandler +{ +public: + cItemSeedsHandler(int a_ItemID) + : cItemHandler(a_ItemID) + { + + } + + virtual bool IsPlaceable() override + { + return true; + } + + virtual BLOCKTYPE GetBlockType() override + { + switch(m_ItemID) + { + case E_ITEM_SEEDS: return E_BLOCK_CROPS; + case E_ITEM_MELON_SEEDS: return E_BLOCK_MELON_STEM; + case E_ITEM_PUMPKIN_SEEDS: return E_BLOCK_PUMPKIN_STEM; + default: return E_BLOCK_AIR; + } + } + + virtual NIBBLETYPE GetBlockMeta(short a_ItemDamage) override + { + return 0; //Not grown yet + } + + virtual void PlaceBlock(cWorld *a_World, cPlayer *a_Player, cItem *a_Item, int a_X, int a_Y, int a_Z, char a_Dir) override + { + int X = a_X, + Y = a_Y, + Z = a_Z; + + AddDirection(X, Y, Z, a_Dir, true); + + if(a_World->GetBlock(X, Y, Z) != E_BLOCK_FARMLAND) + return; + + return cItemHandler::PlaceBlock(a_World, a_Player, a_Item, a_X, a_Y, a_Z, a_Dir); + } +} ; + + + + diff --git a/source/Items/ItemShears.h b/source/Items/ItemShears.h new file mode 100644 index 000000000..2f3476735 --- /dev/null +++ b/source/Items/ItemShears.h @@ -0,0 +1,42 @@ + +#pragma once + +#include "ItemHandler.h" +#include "../World.h" +#include "../Player.h" + +class cItemShearsHandler : public cItemHandler +{ +public: + cItemShearsHandler(int a_ItemID) + : cItemHandler(a_ItemID) + { + + } + virtual bool IsTool() override + { + return true; + } + virtual bool OnDiggingBlock(cWorld *a_World, cPlayer *a_Player, cItem *a_Item, int a_X, int a_Y, int a_Z, char a_Dir) override + { + BLOCKTYPE Block = a_World->GetBlock(a_X, a_Y, a_Z); + if(Block == E_BLOCK_LEAVES) + { + cItems Drops; + Drops.push_back(cItem(E_ITEM_LEAVES, 1, a_World->GetBlockMeta(a_X, a_Y, a_Z))); + a_World->SpawnItemPickups(Drops, a_X, a_Y, a_Z); + + a_World->SetBlock(a_X, a_Y, a_Z, E_BLOCK_AIR, 0); + a_Player->UseEquippedItem(); + return true; + } + return false; + } + + + virtual bool CanHarvestBlock(BLOCKTYPE a_BlockID) override + { + return a_BlockID == E_BLOCK_COBWEB + || a_BlockID == E_BLOCK_VINES; + } +}; \ No newline at end of file diff --git a/source/Items/ItemShovel.h b/source/Items/ItemShovel.h new file mode 100644 index 000000000..f5a65795a --- /dev/null +++ b/source/Items/ItemShovel.h @@ -0,0 +1,41 @@ + +#pragma once + +#include "ItemHandler.h" +#include "../World.h" +#include "../Player.h" + +#include "../Blocks/BlockHandler.h" + + + + + +class cItemShovelHandler : public cItemHandler +{ +public: + cItemShovelHandler(int a_ItemID) + : cItemHandler(a_ItemID) + { + + } + + virtual bool OnDiggingBlock(cWorld *a_World, cPlayer *a_Player, cItem *a_Item, int a_X, int a_Y, int a_Z, char a_Dir) override + { + BLOCKTYPE Block = a_World->GetBlock(a_X, a_Y, a_Z); + if(Block == E_BLOCK_SNOW) + { + BlockHandler(Block)->DropBlock(a_World, a_X, a_Y, a_Z); + + a_World->SetBlock(a_X, a_Y, a_Z, E_BLOCK_AIR, 0); + a_Player->UseEquippedItem(); + return true; + } + return false; + } + + virtual bool CanHarvestBlock(BLOCKTYPE a_BlockID) override + { + return a_BlockID == E_BLOCK_SNOW; + } +}; \ No newline at end of file diff --git a/source/Items/ItemSign.h b/source/Items/ItemSign.h new file mode 100644 index 000000000..a0c6aaa9c --- /dev/null +++ b/source/Items/ItemSign.h @@ -0,0 +1,26 @@ + +#pragma once + +#include "ItemHandler.h" +#include "../World.h" + +class cItemSignHandler : public cItemHandler +{ +public: + cItemSignHandler(int a_ItemID) + : cItemHandler(a_ItemID) + { + + } + + virtual bool IsPlaceable() override + { + return true; + } + + virtual BLOCKTYPE GetBlockType() override + { + return E_BLOCK_SIGN_POST; + } + +}; \ No newline at end of file diff --git a/source/Items/ItemSlab.h b/source/Items/ItemSlab.h new file mode 100644 index 000000000..0bab038a2 --- /dev/null +++ b/source/Items/ItemSlab.h @@ -0,0 +1,45 @@ + +#pragma once + +#include "ItemHandler.h" +#include "../World.h" + + + + + +class cItemSlabHandler : public cItemHandler +{ +public: + cItemSlabHandler(int a_ItemID) + : cItemHandler(a_ItemID) + { + + } + + virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, cItem * a_Item, int a_X, int a_Y, int a_Z, char a_Dir) override + { + BLOCKTYPE Block; + NIBBLETYPE Meta; + a_World->GetBlockTypeMeta(a_X, a_Y, a_Z, Block, Meta); + + if ( + (a_Dir == 0 || a_Dir == 1) // Only when clicking on top or on bottom of the block + && (Block == E_BLOCK_WOODEN_SLAB || Block == E_BLOCK_STONE_SLAB) // It is a slab + && (Block == a_Item->m_ItemID) // Same slab + && ((Meta & 0x7) == (a_Item->m_ItemHealth & 0x7))) // Same Texture + { + cItem Item(a_Item->m_ItemID, 1); + if (a_Player->GetInventory().RemoveItem(Item)) + { + a_World->SetBlock(a_X, a_Y, a_Z, Block - 1, Meta); //Block - 1 simple hack to save one if statement + return true; + } + } + return false; + } +} ; + + + + diff --git a/source/Items/ItemSugarcane.h b/source/Items/ItemSugarcane.h new file mode 100644 index 000000000..4fdf43428 --- /dev/null +++ b/source/Items/ItemSugarcane.h @@ -0,0 +1,39 @@ + +#pragma once + +#include "ItemHandler.h" +#include "../World.h" + + + + + +class cItemSugarcaneHandler : + public cItemHandler +{ +public: + cItemSugarcaneHandler(int a_ItemID) + : cItemHandler(a_ItemID) + { + + } + + virtual bool IsPlaceable() override + { + return true; + } + + virtual BLOCKTYPE GetBlockType() override + { + return E_BLOCK_SUGARCANE; + } + + virtual NIBBLETYPE GetBlockMeta(short a_ItemDamage) override + { + return 0; //Not grown yet + } +} ; + + + + diff --git a/source/Items/ItemSword.h b/source/Items/ItemSword.h new file mode 100644 index 000000000..eb4aa0ef9 --- /dev/null +++ b/source/Items/ItemSword.h @@ -0,0 +1,21 @@ + +#pragma once + +#include "ItemHandler.h" +#include "../World.h" +#include "../Player.h" + +class cItemSwordHandler : public cItemHandler +{ +public: + cItemSwordHandler(int a_ItemID) + : cItemHandler(a_ItemID) + { + + } + + virtual bool CanHarvestBlock(BLOCKTYPE a_BlockID) override + { + return a_BlockID == E_BLOCK_COBWEB; + } +}; \ No newline at end of file diff --git a/source/Items/ItemWood.h b/source/Items/ItemWood.h new file mode 100644 index 000000000..d6f66d1c5 --- /dev/null +++ b/source/Items/ItemWood.h @@ -0,0 +1,22 @@ + +#pragma once + +#include "ItemHandler.h" + + + + + +class cItemWoodHandler : + public cItemHandler +{ +public: + cItemWoodHandler(int a_ItemID) + : cItemHandler(a_ItemID) + { + } +} ; + + + + diff --git a/source/Piston.cpp b/source/Piston.cpp index a4c014729..750d76bb0 100644 --- a/source/Piston.cpp +++ b/source/Piston.cpp @@ -11,7 +11,7 @@ #include "World.h" #include "BlockID.h" #include "Server.h" -#include "blocks/BlockHandler.h" +#include "Blocks/BlockHandler.h" extern bool g_BlockPistonBreakable[]; diff --git a/source/Root.cpp b/source/Root.cpp index 2a6afc0e7..1b7f90d60 100644 --- a/source/Root.cpp +++ b/source/Root.cpp @@ -12,8 +12,8 @@ #include "MonsterConfig.h" #include "Redstone.h" #include "Player.h" -#include "blocks/BlockHandler.h" -#include "items/ItemHandler.h" +#include "Blocks/BlockHandler.h" +#include "Items/ItemHandler.h" #include "Chunk.h" #ifdef USE_SQUIRREL diff --git a/source/UI/Window.cpp b/source/UI/Window.cpp index b3d72570c..ad9ce67c7 100644 --- a/source/UI/Window.cpp +++ b/source/UI/Window.cpp @@ -8,7 +8,7 @@ #include "../Pickup.h" #include "../Inventory.h" #include "WindowOwner.h" -#include "../items/ItemHandler.h" +#include "../Items/ItemHandler.h" #include "SlotArea.h" #include "../ChestEntity.h" diff --git a/source/World.cpp b/source/World.cpp index 184cff869..03438b227 100644 --- a/source/World.cpp +++ b/source/World.cpp @@ -43,7 +43,7 @@ #include "Tracer.h" #include "Generating/Trees.h" #include "PluginManager.h" -#include "blocks/BlockHandler.h" +#include "Blocks/BlockHandler.h" #include "Vector3d.h" #include "tolua++.h" diff --git a/source/blocks/BlockBed.h b/source/blocks/BlockBed.h deleted file mode 100644 index cbef5bb4d..000000000 --- a/source/blocks/BlockBed.h +++ /dev/null @@ -1,123 +0,0 @@ -#pragma once -#include "BlockHandler.h" -#include "../World.h" -#include "../Sign.h" -#include "../Player.h" - -class cBlockBedHandler : public cBlockHandler -{ -public: - cBlockBedHandler(BLOCKTYPE a_BlockID) - : cBlockHandler(a_BlockID) - { - - } - - - - - - virtual void PlaceBlock(cWorld *a_World, cPlayer *a_Player, NIBBLETYPE a_BlockMeta, int a_X, int a_Y, int a_Z, char a_Dir) override - { - if( a_Dir != 1 ) // Can only be placed on the floor - return; - - NIBBLETYPE Meta = RotationToMetaData( a_Player->GetRotation() ); - Vector3i Direction = MetaDataToDirection( Meta ); - - if (a_World->GetBlock(a_X+Direction.x, a_Y, a_Z+Direction.z) != E_BLOCK_AIR) - { - return; - } - - a_World->SetBlock(a_X, a_Y, a_Z, E_BLOCK_BED, Meta); - a_World->SetBlock(a_X + Direction.x, a_Y, a_Z + Direction.z, E_BLOCK_BED, Meta | 0x8); - - OnPlacedByPlayer(a_World, a_Player, a_X, a_Y, a_Z, a_Dir); - } - - - - - - virtual void OnDestroyed(cWorld *a_World, int a_X, int a_Y, int a_Z) override - { - char OldMeta = a_World->GetBlockMeta(a_X, a_Y, a_Z); - - Vector3i ThisPos( a_X, a_Y, a_Z ); - Vector3i Direction = MetaDataToDirection( OldMeta & 0x7 ); - if (OldMeta & 0x8) - { - // Was pillow - if (a_World->GetBlock(ThisPos - Direction) == E_BLOCK_BED) - { - a_World->FastSetBlock(ThisPos - Direction, E_BLOCK_AIR, 0); - } - } - else - { - // Was foot end - if (a_World->GetBlock(ThisPos + Direction) == E_BLOCK_BED) - { - a_World->FastSetBlock(ThisPos + Direction, E_BLOCK_AIR, 0); - } - } - } - - - - - - virtual int GetDropID() override - { - return E_ITEM_BED; - } - - virtual NIBBLETYPE GetDropMeta(NIBBLETYPE a_BlockMeta) override - { - return 0; - } - - - - - - virtual bool AllowBlockOnTop() override - { - return false; - } - - - - - - static NIBBLETYPE RotationToMetaData( float a_Rotation ) - { - a_Rotation += 180 + (180/4); // So its not aligned with axis - if( a_Rotation > 360.f ) a_Rotation -= 360.f; - - a_Rotation = (a_Rotation/360) * 4; - - return ((char)a_Rotation+2) % 4; - } - - - - - - static Vector3i MetaDataToDirection( NIBBLETYPE a_MetaData ) - { - switch( a_MetaData ) - { - case 0: // south +z - return Vector3i(0, 0, 1); - case 1: // west -x - return Vector3i(-1, 0, 0); - case 2: // north -z - return Vector3i(0, 0, -1); - case 3: // east +x - return Vector3i(1, 0, 0); - }; - return Vector3i(); - } -}; diff --git a/source/blocks/BlockCactus.h b/source/blocks/BlockCactus.h deleted file mode 100644 index 964646299..000000000 --- a/source/blocks/BlockCactus.h +++ /dev/null @@ -1,64 +0,0 @@ - -#pragma once -#include "BlockHandler.h" - - - - - -class cBlockCactusHandler : - public cBlockHandler -{ -public: - cBlockCactusHandler(BLOCKTYPE a_BlockID) - : cBlockHandler(a_BlockID) - { - } - - - virtual NIBBLETYPE GetDropMeta(NIBBLETYPE a_BlockMeta) override - { - return 0; - } - - - virtual bool CanBeAt(cWorld * a_World, int a_X, int a_Y, int a_Z) override - { - BLOCKTYPE Surface = a_World->GetBlock(a_X, a_Y - 1, a_Z); - if ((Surface != E_BLOCK_SAND) && (Surface != E_BLOCK_CACTUS)) - { - // Cactus can only be placed on sand and itself - return false; - } - - // Check surroundings. Cacti may ONLY be surrounded by air - if ( - (a_World->GetBlock(a_X - 1, a_Y, a_Z) != E_BLOCK_AIR) || - (a_World->GetBlock(a_X + 1, a_Y, a_Z) != E_BLOCK_AIR) || - (a_World->GetBlock(a_X, a_Y, a_Z - 1) != E_BLOCK_AIR) || - (a_World->GetBlock(a_X, a_Y, a_Z + 1) != E_BLOCK_AIR) - ) - { - return false; - } - - return true; - } - - - virtual bool CanBePlacedOnSide() override - { - return false; - } - - - virtual AString GetStepSound(void) override - { - return "step.cloth"; - } - -}; - - - - diff --git a/source/blocks/BlockChest.h b/source/blocks/BlockChest.h deleted file mode 100644 index db67fe1c8..000000000 --- a/source/blocks/BlockChest.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once -#include "BlockEntity.h" -#include "../World.h" -#include "../Piston.h" -#include "../Player.h" - -class cBlockChestHandler : public cBlockEntityHandler -{ -public: - cBlockChestHandler(BLOCKTYPE a_BlockID) - : cBlockEntityHandler(a_BlockID) - { - } - - virtual void PlaceBlock(cWorld *a_World, cPlayer *a_Player, NIBBLETYPE a_BlockMeta, int a_X, int a_Y, int a_Z, char a_Dir) override - { - a_World->SetBlock(a_X, a_Y, a_Z, m_BlockID, cPiston::RotationPitchToMetaData(a_Player->GetRotation(), 0)); - OnPlacedByPlayer(a_World, a_Player, a_X, a_Y, a_Z, a_Dir); - } - - virtual AString GetStepSound(void) override - { - return "step.wood"; - } - -}; diff --git a/source/blocks/BlockCloth.h b/source/blocks/BlockCloth.h deleted file mode 100644 index 452ad2237..000000000 --- a/source/blocks/BlockCloth.h +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once -#include "BlockHandler.h" - - -class cBlockClothHandler : public cBlockHandler -{ -public: - cBlockClothHandler(BLOCKTYPE a_BlockID) - : cBlockHandler(a_BlockID) - { - } - - virtual NIBBLETYPE GetDropMeta(NIBBLETYPE a_BlockMeta) override - { - return a_BlockMeta; - } - - virtual AString GetStepSound(void) override - { - return "step.cloth"; - } - -}; diff --git a/source/blocks/BlockCrops.h b/source/blocks/BlockCrops.h deleted file mode 100644 index b30139e79..000000000 --- a/source/blocks/BlockCrops.h +++ /dev/null @@ -1,64 +0,0 @@ -#pragma once -#include "BlockHandler.h" -#include "../MersenneTwister.h" -#include "../World.h" - -class cBlockCropsHandler : public cBlockHandler -{ -public: - cBlockCropsHandler(BLOCKTYPE a_BlockID) - : cBlockHandler(a_BlockID) - { - } - - virtual bool NeedsRandomTicks() override - { - return true; - } - - virtual bool AllowBlockOnTop() override - { - return false; - } - - virtual int GetDropID() override - { - return E_ITEM_EMPTY; - } - - virtual void OnDestroyed(cWorld *a_World, int a_X, int a_Y, int a_Z) override - { - MTRand rand; - NIBBLETYPE Meta = a_World->GetBlockMeta(a_X, a_Y, a_Z); - - cItems Drops; - - if(Meta & 0x7) //Is Wheat - { - Drops.push_back(cItem(E_ITEM_WHEAT, 1, 0)); - } - if(rand.randInt(3) == 0) - { //Drop an second seed - Drops.push_back(cItem(E_ITEM_SEEDS, 1, 0)); - } - Drops.push_back(cItem(E_ITEM_SEEDS, 1, 0)); - a_World->SpawnItemPickups(Drops, a_X, a_Y, a_Z); - } - - void OnUpdate(cWorld *a_World, int a_X, int a_Y, int a_Z) override - { - - //TODO: Handle Growing here - } - - virtual bool CanBeAt(cWorld *a_World, int a_X, int a_Y, int a_Z) override - { - return a_World->GetBlock(a_X, a_Y - 1, a_Z) == E_BLOCK_FARMLAND; - } - - virtual AString GetStepSound(void) override - { - return "step.grass"; - } - -}; diff --git a/source/blocks/BlockDirt.h b/source/blocks/BlockDirt.h deleted file mode 100644 index 5a2487f1b..000000000 --- a/source/blocks/BlockDirt.h +++ /dev/null @@ -1,72 +0,0 @@ -#pragma once -#include "BlockHandler.h" -#include "../MersenneTwister.h" -#include "../World.h" - -class cBlockDirtHandler : public cBlockHandler -{ -public: - cBlockDirtHandler(BLOCKTYPE a_BlockID) - : cBlockHandler(a_BlockID) - { - } - - - virtual bool NeedsRandomTicks() override - { - return m_BlockID == E_BLOCK_GRASS; - } - - virtual int GetDropID() override - { - return E_BLOCK_DIRT; - } - - - void OnUpdate(cWorld *a_World, int a_X, int a_Y, int a_Z) override - { - if (m_BlockID != E_BLOCK_GRASS) - { - return; - } - - // Grass becomes dirt if there is something on top of it: - BLOCKTYPE Above = a_World->GetBlock(a_X, a_Y + 1, a_Z); - if (!g_BlockTransparent[Above] && !g_BlockOneHitDig[Above]) - { - a_World->FastSetBlock(a_X, a_Y, a_Z, E_BLOCK_DIRT, 0); - return; - } - - // Grass spreads to adjacent blocks: - MTRand rand; - for (int i = 0; i < 2; i++) // Pick two blocks to grow to - { - int OfsX = rand.randInt(2) - 1; // [-1 .. 1] - int OfsY = rand.randInt(4) - 3; // [-3 .. 1] - int OfsZ = rand.randInt(2) - 1; // [-1 .. 1] - - BLOCKTYPE DestBlock; - NIBBLETYPE DestMeta; - a_World->GetBlockTypeMeta(a_X + OfsX, a_Y + OfsY, a_Z + OfsZ, DestBlock, DestMeta); - if(DestBlock != E_BLOCK_DIRT) - { - continue; - } - - BLOCKTYPE AboveDest; - NIBBLETYPE AboveMeta; - a_World->GetBlockTypeMeta(a_X + OfsX, a_Y + OfsY + 1, a_Z + OfsZ, AboveDest, AboveMeta); - if (g_BlockOneHitDig[AboveDest] || g_BlockTransparent[AboveDest]) - { - a_World->FastSetBlock(a_X + OfsX, a_Y + OfsY, a_Z + OfsZ, E_BLOCK_GRASS, 0); - } - } // for i - repeat twice - } - - virtual AString GetStepSound(void) override - { - return "step.gravel"; - } - -}; diff --git a/source/blocks/BlockDispenser.h b/source/blocks/BlockDispenser.h deleted file mode 100644 index eee75a39a..000000000 --- a/source/blocks/BlockDispenser.h +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once -#include "BlockEntity.h" -#include "../World.h" -#include "../Piston.h" -#include "../Player.h" - -class cBlockDispenserHandler : public cBlockEntityHandler -{ -public: - cBlockDispenserHandler(BLOCKTYPE a_BlockID) - : cBlockEntityHandler(a_BlockID) - { - } - - virtual void PlaceBlock(cWorld *a_World, cPlayer *a_Player, NIBBLETYPE a_BlockMeta, int a_X, int a_Y, int a_Z, char a_Dir) override - { - a_World->SetBlock(a_X, a_Y, a_Z, m_BlockID, cPiston::RotationPitchToMetaData(a_Player->GetRotation(), 0)); - OnPlacedByPlayer(a_World, a_Player, a_X, a_Y, a_Z, a_Dir); - } - - -}; \ No newline at end of file diff --git a/source/blocks/BlockDoor.cpp b/source/blocks/BlockDoor.cpp deleted file mode 100644 index deed8a256..000000000 --- a/source/blocks/BlockDoor.cpp +++ /dev/null @@ -1,74 +0,0 @@ -#include "Globals.h" -#include "BlockDoor.h" -#include "../Item.h" -#include "../World.h" -#include "../Doors.h" -#include "../Player.h" - - -cBlockDoorHandler::cBlockDoorHandler(BLOCKTYPE a_BlockID) - : cBlockHandler(a_BlockID) -{ -} - -void cBlockDoorHandler::OnPlaced(cWorld *a_World, int a_X, int a_Y, int a_Z, int a_Dir) -{ - -} - -void cBlockDoorHandler::OnDestroyed(cWorld *a_World, int a_X, int a_Y, int a_Z) -{ - char OldMeta = a_World->GetBlockMeta(a_X, a_Y, a_Z); - - if (OldMeta & 8) - { - // Was upper part of door - if (cDoors::IsDoor(a_World->GetBlock(a_X, a_Y - 1, a_Z))) - { - a_World->FastSetBlock(a_X, a_Y - 1, a_Z, E_BLOCK_AIR, 0); - } - } - else - { - // Was lower part - if (cDoors::IsDoor(a_World->GetBlock(a_X, a_Y + 1, a_Z))) - { - a_World->FastSetBlock(a_X, a_Y + 1, a_Z, E_BLOCK_AIR, 0); - } - } -} - -void cBlockDoorHandler::OnDigging(cWorld *a_World, cPlayer *a_Player, int a_X, int a_Y, int a_Z) -{ - cDoors::ChangeDoor(a_World, a_X, a_Y, a_Z); -} - -void cBlockDoorHandler::OnUse(cWorld *a_World, cPlayer *a_Player, int a_X, int a_Y, int a_Z) -{ - cDoors::ChangeDoor(a_World, a_X, a_Y, a_Z); -} - -char cBlockDoorHandler::GetDropCount() -{ - return 1; -} - -void cBlockDoorHandler::PlaceBlock(cWorld *a_World, cPlayer *a_Player, NIBBLETYPE a_BlockMeta, int a_X, int a_Y, int a_Z, char a_Dir) -{ - if (a_World->GetBlock(a_X, a_Y + 1, a_Z) == E_BLOCK_AIR) - { - a_BlockMeta = cDoors::RotationToMetaData(a_Player->GetRotation()); - a_World->SetBlock(a_X, a_Y + 1, a_Z, m_BlockID, a_BlockMeta + 8); - a_World->SetBlock(a_X, a_Y, a_Z, m_BlockID, a_BlockMeta); - OnPlacedByPlayer(a_World, a_Player, a_X, a_Y, a_Z, a_Dir); - } -} - -AString cBlockDoorHandler::GetStepSound(void) -{ - if (m_BlockID == E_BLOCK_WOODEN_DOOR) - return "step.wood"; - - else - return "step.stone"; -} diff --git a/source/blocks/BlockDoor.h b/source/blocks/BlockDoor.h deleted file mode 100644 index 3316f50a4..000000000 --- a/source/blocks/BlockDoor.h +++ /dev/null @@ -1,31 +0,0 @@ -#pragma once -#include "BlockHandler.h" - - -class cBlockDoorHandler : public cBlockHandler -{ -public: - cBlockDoorHandler(BLOCKTYPE a_BlockID); - virtual void OnPlaced(cWorld *a_World, int a_X, int a_Y, int a_Z, int a_Dir) override; - virtual void OnDestroyed(cWorld *a_World, int a_X, int a_Y, int a_Z) override; - virtual void OnDigging(cWorld *a_World, cPlayer *a_Player, int a_X, int a_Y, int a_Z) override; - virtual void OnUse(cWorld *a_World, cPlayer *a_Player, int a_X, int a_Y, int a_Z) override; - virtual AString GetStepSound(void) override; - virtual char GetDropCount() override; - virtual bool IsUseable() override - { - return true; - } - - virtual void PlaceBlock(cWorld *a_World, cPlayer *a_Player, NIBBLETYPE a_BlockMeta, int a_X, int a_Y, int a_Z, char a_Dir) override; - - virtual int GetDropID() override - { - return (m_BlockID == E_BLOCK_WOODEN_DOOR) ? E_ITEM_WOODEN_DOOR : E_ITEM_IRON_DOOR; - } - - virtual bool CanBePlacedOnSide() override - { - return false; - } -}; \ No newline at end of file diff --git a/source/blocks/BlockEntity.h b/source/blocks/BlockEntity.h deleted file mode 100644 index caf6ee342..000000000 --- a/source/blocks/BlockEntity.h +++ /dev/null @@ -1,31 +0,0 @@ - -#pragma once - -#include "BlockHandler.h" - - - - - -class cBlockEntityHandler : public cBlockHandler -{ -public: - cBlockEntityHandler(BLOCKTYPE a_BlockID) - : cBlockHandler(a_BlockID) - { - } - - virtual void OnUse(cWorld * a_World, cPlayer *a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) override - { - a_World->UseBlockEntity(a_Player, a_BlockX, a_BlockY, a_BlockZ); - } - - virtual bool IsUseable() override - { - return true; - } -}; - - - - diff --git a/source/blocks/BlockFire.h b/source/blocks/BlockFire.h deleted file mode 100644 index 1fecf9a14..000000000 --- a/source/blocks/BlockFire.h +++ /dev/null @@ -1,33 +0,0 @@ -#pragma once -#include "BlockHandler.h" - - -class cBlockFireHandler : public cBlockHandler -{ -public: - cBlockFireHandler(BLOCKTYPE a_BlockID) - : cBlockHandler(a_BlockID) - { - } - - virtual void OnDigging(cWorld *a_World, cPlayer *a_Player, int a_X, int a_Y, int a_Z) override - { - a_World->DigBlock(a_X, a_Y, a_Z); - } - - virtual char GetDropCount() override - { - return -1; - } - - virtual bool IsClickedThrough() override - { - return true; - } - - virtual AString GetStepSound(void) override - { - return "step.wood"; - } - -}; diff --git a/source/blocks/BlockFlower.h b/source/blocks/BlockFlower.h deleted file mode 100644 index 35a55fcac..000000000 --- a/source/blocks/BlockFlower.h +++ /dev/null @@ -1,38 +0,0 @@ -#pragma once -#include "BlockHandler.h" - - -class cBlockFlowerHandler : public cBlockHandler -{ -public: - cBlockFlowerHandler(BLOCKTYPE a_BlockID) - : cBlockHandler(a_BlockID) - { - } - - virtual NIBBLETYPE GetDropMeta(NIBBLETYPE a_BlockMeta) override - { - return 0; - } - - virtual bool CanBeAt(cWorld *a_World, int a_X, int a_Y, int a_Z) override - { - return IsBlockTypeOfDirt(a_World->GetBlock(a_X, a_Y - 1, a_Z)); - } - - virtual bool AllowBlockOnTop() override - { - return false; - } - - virtual bool CanBePlacedOnSide() override - { - return false; - } - - virtual AString GetStepSound(void) override - { - return "step.grass"; - } - -}; diff --git a/source/blocks/BlockFluid.h b/source/blocks/BlockFluid.h deleted file mode 100644 index c5ac660b0..000000000 --- a/source/blocks/BlockFluid.h +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once -#include "BlockHandler.h" - - -class cBlockFluidHandler : public cBlockHandler -{ -public: - cBlockFluidHandler(BLOCKTYPE a_BlockID) - : cBlockHandler(a_BlockID) - { - - } - - virtual bool IgnoreBuildCollision() override - { - return true; - } - - -}; \ No newline at end of file diff --git a/source/blocks/BlockFurnace.h b/source/blocks/BlockFurnace.h deleted file mode 100644 index 4157b5049..000000000 --- a/source/blocks/BlockFurnace.h +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once -#include "BlockEntity.h" -#include "../World.h" -#include "../Piston.h" -#include "../Player.h" - -class cBlockFurnaceHandler : public cBlockEntityHandler -{ -public: - cBlockFurnaceHandler(BLOCKTYPE a_BlockID) - : cBlockEntityHandler(a_BlockID) - { - } - - virtual int GetDropID() override - { - return E_ITEM_FURNACE; - } - - virtual void PlaceBlock(cWorld *a_World, cPlayer *a_Player, NIBBLETYPE a_BlockMeta, int a_X, int a_Y, int a_Z, char a_Dir) override - { - a_World->SetBlock(a_X, a_Y, a_Z, m_BlockID, cPiston::RotationPitchToMetaData(a_Player->GetRotation(), 0)); - OnPlacedByPlayer(a_World, a_Player, a_X, a_Y, a_Z, a_Dir); - } - - -}; \ No newline at end of file diff --git a/source/blocks/BlockGlowstone.h b/source/blocks/BlockGlowstone.h deleted file mode 100644 index 0b906e2fe..000000000 --- a/source/blocks/BlockGlowstone.h +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once -#include "BlockHandler.h" - - -class cBlockGlowstoneHandler : public cBlockHandler -{ -public: - cBlockGlowstoneHandler(BLOCKTYPE a_BlockID) - : cBlockHandler(a_BlockID) - { - } - - virtual NIBBLETYPE GetDropMeta(NIBBLETYPE a_BlockMeta) override - { - return 0; - } - - virtual int GetDropID() override - { - return E_ITEM_GLOWSTONE_DUST; - } -}; \ No newline at end of file diff --git a/source/blocks/BlockGravel.h b/source/blocks/BlockGravel.h deleted file mode 100644 index da47db9bb..000000000 --- a/source/blocks/BlockGravel.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once -#include "BlockHandler.h" - - -class cBlockGravelHandler : public cBlockHandler -{ -public: - cBlockGravelHandler(BLOCKTYPE a_BlockID) - : cBlockHandler(a_BlockID) - { - } - - virtual AString GetStepSound(void) override - { - return "step.gravel"; - } - -}; diff --git a/source/blocks/BlockHandler.cpp b/source/blocks/BlockHandler.cpp deleted file mode 100644 index e6b384a23..000000000 --- a/source/blocks/BlockHandler.cpp +++ /dev/null @@ -1,448 +0,0 @@ -#include "Globals.h" -#include "BlockHandler.h" -#include "../Item.h" -#include "../World.h" -#include "BlockSand.h" -#include "BlockGravel.h" -#include "BlockDoor.h" -#include "BlockFire.h" -#include "BlockRedstone.h" -#include "BlockRedstoneTorch.h" -#include "BlockRedstoneRepeater.h" -#include "BlockPiston.h" -#include "BlockWorkbench.h" -#include "BlockEntity.h" -#include "BlockVine.h" -#include "BlockTallGrass.h" -#include "BlockSnow.h" -#include "BlockCloth.h" -#include "BlockSlab.h" -#include "BlockDirt.h" -#include "BlockTorch.h" -#include "BlockWood.h" -#include "BlockLeaves.h" -#include "BlockSapling.h" -#include "BlockFluid.h" -#include "BlockChest.h" -#include "BlockFurnace.h" -#include "BlockDispenser.h" -#include "BlockStairs.h" -#include "BlockLadder.h" -#include "BlockSign.h" -#include "BlockCrops.h" -#include "BlockSugarcane.h" -#include "BlockFlower.h" -#include "BlockMushroom.h" -#include "BlockCactus.h" -#include "BlockStems.h" -#include "BlockGlowstone.h" -#include "BlockStone.h" -#include "BlockMelon.h" -#include "BlockIce.h" -#include "BlockOre.h" -#include "BlockNote.h" -#include "BlockBed.h" - - - - - -bool cBlockHandler::m_HandlerInitialized = false; -cBlockHandler *cBlockHandler::m_BlockHandler[256]; - - - - - -cBlockHandler *cBlockHandler::GetBlockHandler(BLOCKTYPE a_BlockID) -{ - if (!m_HandlerInitialized) - { - //We have to initialize - memset(m_BlockHandler, 0, sizeof(m_BlockHandler)); - m_HandlerInitialized = true; - } - if (m_BlockHandler[a_BlockID] != NULL) - { - return m_BlockHandler[a_BlockID]; - } - - return m_BlockHandler[a_BlockID] = CreateBlockHandler(a_BlockID); -} - - - - - -cBlockHandler *cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockID) -{ - switch(a_BlockID) - { - case E_BLOCK_SAND: - return new cBlockSandHandler(a_BlockID); - case E_BLOCK_GRAVEL: - return new cBlockGravelHandler(a_BlockID); - case E_BLOCK_WOODEN_DOOR: - case E_BLOCK_IRON_DOOR: - return new cBlockDoorHandler(a_BlockID); - case E_BLOCK_FIRE: - return new cBlockFireHandler(a_BlockID); - case E_BLOCK_REDSTONE_TORCH_ON: - case E_BLOCK_REDSTONE_TORCH_OFF: - return new cBlockRedstoneTorchHandler(a_BlockID); - case E_BLOCK_REDSTONE_WIRE: - return new cBlockRedstoneHandler(a_BlockID); - case E_BLOCK_PISTON: - case E_BLOCK_STICKY_PISTON: - return new cBlockPistonHandler(a_BlockID); - case E_BLOCK_REDSTONE_REPEATER_ON: - case E_BLOCK_REDSTONE_REPEATER_OFF: - return new cBlockRedstoneRepeaterHandler(a_BlockID); - case E_BLOCK_WORKBENCH: - return new cBlockWorkbenchHandler(a_BlockID); - case E_BLOCK_SNOW: - return new cBlockSnowHandler(a_BlockID); - case E_BLOCK_TALL_GRASS: - return new cBlockTallGrassHandler(a_BlockID); - case E_BLOCK_VINES: - return new cBlockVineHandler(a_BlockID); - case ::E_BLOCK_WOOL: - return new cBlockClothHandler(a_BlockID); - case E_BLOCK_WOODEN_SLAB: - case E_BLOCK_STONE_SLAB: - case E_BLOCK_DOUBLE_WOODEN_SLAB: - case E_BLOCK_DOUBLE_STONE_SLAB: - return new cBlockSlabHandler(a_BlockID); - case E_BLOCK_LOG: - case E_BLOCK_PLANKS: - return new cBlockWoodHandler(a_BlockID); - case E_BLOCK_TORCH: - return new cBlockTorchHandler(a_BlockID); - case E_BLOCK_DIRT: - case E_BLOCK_GRASS: - return new cBlockDirtHandler(a_BlockID); - case E_BLOCK_LEAVES: - return new cBlockLeavesHandler(a_BlockID); - case E_BLOCK_SAPLING: - return new cBlockSaplingHandler(a_BlockID); - case E_BLOCK_WATER: - case E_BLOCK_STATIONARY_WATER: - case E_BLOCK_STATIONARY_LAVA: - case E_BLOCK_LAVA: - return new cBlockFluidHandler(a_BlockID); - case E_BLOCK_DISPENSER: - return new cBlockDispenserHandler(a_BlockID); - case E_BLOCK_FURNACE: - case E_BLOCK_LIT_FURNACE: - return new cBlockFurnaceHandler(a_BlockID); - case E_BLOCK_CHEST: - return new cBlockChestHandler(a_BlockID); - case E_BLOCK_ICE: - return new cBlockIceHandler(a_BlockID); - case E_BLOCK_LADDER: - return new cBlockLadderHandler(a_BlockID); - case E_BLOCK_COBBLESTONE_STAIRS: - case E_BLOCK_BRICK_STAIRS: - case E_BLOCK_STONE_BRICK_STAIRS: - case E_BLOCK_NETHER_BRICK_STAIRS: - case E_BLOCK_WOODEN_STAIRS: - return new cBlockStairsHandler(a_BlockID); - case E_BLOCK_SIGN_POST: - case E_BLOCK_WALLSIGN: - return new cBlockSignHandler(a_BlockID); - case E_BLOCK_CROPS: - return new cBlockCropsHandler(a_BlockID); - case E_BLOCK_SUGARCANE: - return new cBlockSugarcaneHandler(a_BlockID); - case E_BLOCK_YELLOW_FLOWER: - case E_BLOCK_RED_ROSE: - return new cBlockFlowerHandler(a_BlockID); - case E_BLOCK_BROWN_MUSHROOM: - case E_BLOCK_RED_MUSHROOM: - return new cBlockMushroomHandler(a_BlockID); - case E_BLOCK_CACTUS: - return new cBlockCactusHandler(a_BlockID); - case E_BLOCK_MELON_STEM: - case E_BLOCK_PUMPKIN_STEM: - return new cBlockStemsHandler(a_BlockID); - case E_BLOCK_GLOWSTONE: - return new cBlockGlowstoneHandler(a_BlockID); - case E_BLOCK_DIAMOND_ORE: - case E_BLOCK_GOLD_ORE: - case E_BLOCK_REDSTONE_ORE: - case E_BLOCK_REDSTONE_ORE_GLOWING: - case E_BLOCK_EMERALD_ORE: - case E_BLOCK_IRON_ORE: - case E_BLOCK_LAPIS_ORE: - case E_BLOCK_COAL_ORE: - return new cBlockOreHandler(a_BlockID); - case E_BLOCK_STONE: - case E_BLOCK_COBBLESTONE: - return new cBlockStoneHandler(a_BlockID); - case E_BLOCK_MELON: - return new cBlockMelonHandler(a_BlockID); - case E_BLOCK_NOTE_BLOCK: - return new cBlockNoteHandler(a_BlockID); - case E_BLOCK_BED: - return new cBlockBedHandler(a_BlockID); - default: - return new cBlockHandler(a_BlockID); - break; - } -} - - - - - -void cBlockHandler::Deinit() -{ - for(int i = 0; i < 256; i++) - { - delete m_BlockHandler[i]; - } - m_HandlerInitialized = false; -} - - - - - -cBlockHandler::cBlockHandler(BLOCKTYPE a_BlockID) -{ - m_BlockID = a_BlockID; -} - - - - - -void cBlockHandler::OnUpdate(cWorld *a_World, int a_X, int a_Y, int a_Z) -{ -} - - - - - -void cBlockHandler::OnPlacedByPlayer(cWorld *a_World, cPlayer * a_Player, int a_X, int a_Y, int a_Z, int a_Dir) -{ -} - - - - - -void cBlockHandler::OnDestroyedByPlayer(cWorld *a_World, cPlayer * a_Player, int a_X, int a_Y, int a_Z) -{ -} - - - - - -void cBlockHandler::OnPlaced(cWorld *a_World, int a_X, int a_Y, int a_Z, int a_Dir) -{ - //Notify the neighbors - NeighborChanged(a_World, a_X - 1, a_Y, a_Z); - NeighborChanged(a_World, a_X + 1, a_Y, a_Z); - NeighborChanged(a_World, a_X, a_Y - 1, a_Z); - NeighborChanged(a_World, a_X, a_Y + 1, a_Z); - NeighborChanged(a_World, a_X, a_Y, a_Z - 1); - NeighborChanged(a_World, a_X, a_Y, a_Z + 1); -} - - - - - -void cBlockHandler::OnDestroyed(cWorld *a_World, int a_X, int a_Y, int a_Z) -{ - //Notify the neighbors - NeighborChanged(a_World, a_X - 1, a_Y, a_Z); - NeighborChanged(a_World, a_X + 1, a_Y, a_Z); - NeighborChanged(a_World, a_X, a_Y - 1, a_Z); - NeighborChanged(a_World, a_X, a_Y + 1, a_Z); - NeighborChanged(a_World, a_X, a_Y, a_Z - 1); - NeighborChanged(a_World, a_X, a_Y, a_Z + 1); -} - - - - - -void cBlockHandler::NeighborChanged(cWorld *a_World, int a_X, int a_Y, int a_Z) -{ - GetBlockHandler(a_World->GetBlock(a_X, a_Y, a_Z))->OnNeighborChanged(a_World, a_X, a_Y, a_Z); -} - - - - - -void cBlockHandler::OnNeighborChanged(cWorld *a_World, int a_X, int a_Y, int a_Z) -{ -} - - - - - -void cBlockHandler::OnDigging(cWorld *a_World, cPlayer *a_Player, int a_X, int a_Y, int a_Z) -{ -} - - - - - -void cBlockHandler::OnUse(cWorld *a_World, cPlayer *a_Player, int a_X, int a_Y, int a_Z) -{ -} - - - - - -void cBlockHandler::PlaceBlock(cWorld *a_World, cPlayer *a_Player, NIBBLETYPE a_BlockMeta, int a_X, int a_Y, int a_Z, char a_Dir) -{ - a_World->SetBlock(a_X, a_Y, a_Z, m_BlockID, a_BlockMeta); - OnPlacedByPlayer(a_World, a_Player, a_X, a_Y, a_Z, a_Dir); -} - - - - - -char cBlockHandler::GetDropCount() -{ - return 1; -} - - - - - -int cBlockHandler::GetDropID() -{ - return m_BlockID; -} - - - - - -NIBBLETYPE cBlockHandler::GetDropMeta(NIBBLETYPE a_BlockMeta) -{ - return a_BlockMeta; //This keeps most textures. The few other blocks have to override this -} - - - - - -void cBlockHandler::DropBlock(cWorld *a_World, int a_X, int a_Y, int a_Z) -{ - cItems Drops; - NIBBLETYPE Meta = a_World->GetBlockMeta(a_X, a_Y, a_Z); - char DropCount = GetDropCount(); - short DropItem = (short)GetDropID(); - if (DropCount > 0 && (DropItem != E_ITEM_EMPTY)) - { - Drops.push_back(cItem(DropItem, DropCount, GetDropMeta(Meta))); - a_World->SpawnItemPickups(Drops, a_X, a_Y, a_Z); - } -} - - - - - -AString cBlockHandler::GetStepSound() { - return "step.stone"; -} - - - - - -bool cBlockHandler::CanBePlacedAt(cWorld *a_World, int a_X, int a_Y, int a_Z, char a_Dir) -{ - return CanBeAt(a_World, a_X, a_Y, a_Z); -} - - - - - -bool cBlockHandler::CanBeAt(cWorld *a_World, int a_X, int a_Y, int a_Z) -{ - return true; -} - - - - - -bool cBlockHandler::IsUseable() -{ - return false; -} - - - - - -bool cBlockHandler::IsClickedThrough() -{ - return false; -} - - - - - -bool cBlockHandler::IgnoreBuildCollision() -{ - return m_BlockID == E_BLOCK_AIR; -} - - - - - -bool cBlockHandler::NeedsRandomTicks() -{ - return false; -} - - - - - -bool cBlockHandler::AllowBlockOnTop() -{ - return true; -} - - - - - -bool cBlockHandler::CanBePlacedOnSide() -{ - return true; -} - - - - - -bool cBlockHandler::DropOnUnsuitable() -{ - return true; -} - - - - diff --git a/source/blocks/BlockHandler.h b/source/blocks/BlockHandler.h deleted file mode 100644 index 859870c4a..000000000 --- a/source/blocks/BlockHandler.h +++ /dev/null @@ -1,90 +0,0 @@ -#pragma once -#include "../Defines.h" - -class cWorld; -class cPlayer; - - - -class cBlockHandler -{ -public: - cBlockHandler(BLOCKTYPE a_BlockID); - - // Called when the block gets ticked either by a random tick or by a queued tick - virtual void OnUpdate(cWorld *a_World, int a_X, int a_Y, int a_Z); - - // Will be called by cBlockHandler::PlaceBlock after the player has placed a new block - virtual void OnPlacedByPlayer(cWorld *a_World, cPlayer * a_Player, int a_X, int a_Y, int a_Z, int a_Dir); - // Will be called before the player has destroyed a block - virtual void OnDestroyedByPlayer(cWorld *a_World, cPlayer * a_Player, int a_X, int a_Y, int a_Z); - // Will be called when a new block was placed. Will be called before OnPlacedByPlayer - virtual void OnPlaced(cWorld *a_World, int a_X, int a_Y, int a_Z, int a_Dir); - // Will be called before a block gets destroyed / replaced with air - virtual void OnDestroyed(cWorld *a_World, int a_X, int a_Y, int a_Z); - // Will be called when a direct neighbor of this block has been changed (The position is the own position, not the neighbor position) - virtual void OnNeighborChanged(cWorld *a_World, int a_X, int a_Y, int a_Z); - // Notifies all neighbors of the give block about a change - static void NeighborChanged(cWorld *a_World, int a_X, int a_Y, int a_Z); - // Will be called while the player diggs the block. - virtual void OnDigging(cWorld *a_World, cPlayer *a_Player, int a_X, int a_Y, int a_Z); - // Will be called if the user right clicks the block and the block is useable - virtual void OnUse(cWorld *a_World, cPlayer *a_Player, int a_X, int a_Y, int a_Z); - // This function handles the real block placement for the give block by a player and also calls the OnPlacedByPlayer function - virtual void PlaceBlock(cWorld *a_World, cPlayer *a_Player, NIBBLETYPE a_BlockMeta, int a_X, int a_Y, int a_Z, char a_Dir); - - // Indicates how much items are dropped DEFAULT: 1 - virtual char GetDropCount(); - // Indicates the id dropped by this block DEFAULT: BlockID - virtual int GetDropID(); - // Indicates the Drop Meta data based on the block meta DEFAULT: BlockMeta - virtual NIBBLETYPE GetDropMeta(NIBBLETYPE a_BlockMeta); - // This function handles the dropping of a block based on the Drop id, drop count and drop meta. This will not destroy the block - virtual void DropBlock(cWorld *a_World, int a_X, int a_Y, int a_Z); - /// Returns step sound name of block - virtual AString GetStepSound(); - - // Indicates whether this block needs random ticks DEFAULT: False - virtual bool NeedsRandomTicks(); - - /// Checks if the block can stay at the specified coords in the world - virtual bool CanBeAt(cWorld *a_World, int a_BlockX, int a_BlockY, int a_BlockZ); - - /// Checks if the block can be placed at this point. Default: CanBeAt(...) NOTE: This call doesn't actually place the block - virtual bool CanBePlacedAt(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir); - - /// Called when the player tries to place a block on top of this block (Only if he aims directly on this block); return false to disallow - virtual bool AllowBlockOnTop(void); - - /// Called to check whether this block supports a rclk action. If it returns true, OnUse() is called - virtual bool IsUseable(void); - - // Indicates whether the client will click through this block. For example digging a fire will hit the block below the fire so fire is clicked through - virtual bool IsClickedThrough(void); - - // Checks if the player can build "inside" this block. For example blocks placed "on" snow will be placed at the same position. So: Snow ignores Build collision - virtual bool IgnoreBuildCollision(void); - - /// Indicates this block can be placed on the side of other blocks. Default: true - virtual bool CanBePlacedOnSide(); - - /// Does this block drop if it gets destroyed by an unsuitable situation? Default: true - virtual bool DropOnUnsuitable(); - - - // Static function to get the blockhandler for an specific block id - static cBlockHandler * GetBlockHandler(BLOCKTYPE a_BlockID); - - // Deletes all initialised block handlers - static void Deinit(); - -protected: - BLOCKTYPE m_BlockID; - // Creates a new blockhandler for the given block id. For internal use only, use GetBlockHandler instead. - static cBlockHandler *CreateBlockHandler(BLOCKTYPE a_BlockID); - static cBlockHandler *m_BlockHandler[256]; - static bool m_HandlerInitialized; //used to detect if the blockhandlers are initialized -}; - -// Shortcut to get the blockhandler for a specific block -inline cBlockHandler *BlockHandler(BLOCKTYPE a_BlockID) { return cBlockHandler::GetBlockHandler(a_BlockID); } \ No newline at end of file diff --git a/source/blocks/BlockIce.h b/source/blocks/BlockIce.h deleted file mode 100644 index cc5cc8920..000000000 --- a/source/blocks/BlockIce.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once -#include "BlockHandler.h" -#include "../MersenneTwister.h" -#include "../World.h" - -class cBlockIceHandler : public cBlockHandler -{ -public: - cBlockIceHandler(BLOCKTYPE a_BlockID) - : cBlockHandler(a_BlockID) - { - } - - virtual int GetDropID() override - { - return E_ITEM_EMPTY; - } - - virtual void OnDestroyed(cWorld *a_World, int a_X, int a_Y, int a_Z) override - { - a_World->FastSetBlock(a_X, a_Y, a_Z, E_BLOCK_STATIONARY_WATER, 8); - //This is called later than the real destroying of this ice block - } - - -}; \ No newline at end of file diff --git a/source/blocks/BlockLadder.h b/source/blocks/BlockLadder.h deleted file mode 100644 index ee48df848..000000000 --- a/source/blocks/BlockLadder.h +++ /dev/null @@ -1,40 +0,0 @@ -#pragma once -#include "BlockHandler.h" -#include "../World.h" -#include "../Ladder.h" - -class cBlockLadderHandler : public cBlockHandler -{ -public: - cBlockLadderHandler(BLOCKTYPE a_BlockID) - : cBlockHandler(a_BlockID) - { - - } - - virtual void PlaceBlock(cWorld *a_World, cPlayer *a_Player, NIBBLETYPE a_BlockMeta, int a_X, int a_Y, int a_Z, char a_Dir) override - { - a_World->SetBlock(a_X, a_Y, a_Z, m_BlockID, cLadder::DirectionToMetaData(a_Dir)); - OnPlacedByPlayer(a_World, a_Player, a_X, a_Y, a_Z, a_Dir); - } - - virtual bool CanBePlacedAt(cWorld *a_World, int a_X, int a_Y, int a_Z, char a_Dir) override - { - AddDirection( a_X, a_Y, a_Z, a_Dir, true ); - return a_World->GetBlock( a_X, a_Y, a_Z ) != E_BLOCK_AIR; - } - - - virtual bool CanBeAt(cWorld *a_World, int a_X, int a_Y, int a_Z) override - { - char Dir = cLadder::MetaDataToDirection(a_World->GetBlockMeta( a_X, a_Y, a_Z)); - return CanBePlacedAt(a_World, a_X, a_Y, a_Z, Dir); - } - - - virtual AString GetStepSound(void) override - { - return "step.wood"; - } - -}; diff --git a/source/blocks/BlockLeaves.h b/source/blocks/BlockLeaves.h deleted file mode 100644 index 65c47f8de..000000000 --- a/source/blocks/BlockLeaves.h +++ /dev/null @@ -1,167 +0,0 @@ -#pragma once -#include "BlockHandler.h" -#include "../MersenneTwister.h" -#include "../World.h" -#include "../BlockArea.h" - - - -// Leaves can be this many blocks that away (inclusive) from the log not to decay -#define LEAVES_CHECK_DISTANCE 6 - -#define PROCESS_NEIGHBOR(x,y,z) \ - switch (a_Area.GetBlockType(x, y, z)) \ - { \ - case E_BLOCK_LEAVES: a_Area.SetBlockType(x, y, z, (BLOCKTYPE)(E_BLOCK_SPONGE + i + 1)); break; \ - case E_BLOCK_LOG: return true; \ - } - -bool HasNearLog(cBlockArea &a_Area, int a_BlockX, int a_BlockY, int a_BlockZ); - - - -class cBlockLeavesHandler : public cBlockHandler -{ -public: - cBlockLeavesHandler(BLOCKTYPE a_BlockID) - : cBlockHandler(a_BlockID) - { - } - - virtual int GetDropID() override - { - MTRand rand; - - if(rand.randInt(5) == 0) - { - return E_ITEM_SAPLING; - } - - return E_ITEM_EMPTY; - } - - void OnDestroyed(cWorld *a_World, int a_X, int a_Y, int a_Z) override - { - cBlockHandler::OnDestroyed(a_World, a_X, a_Y, a_Z); - - //0.5% chance of dropping an apple - NIBBLETYPE Meta = a_World->GetBlockMeta(a_X, a_Y, a_Z); - //check if Oak (0x1 and 0x2 bit not set) - MTRand rand; - if(!(Meta & 3) && rand.randInt(200) == 100) - { - cItems Drops; - Drops.push_back(cItem(E_ITEM_RED_APPLE, 1, 0)); - a_World->SpawnItemPickups(Drops, a_X, a_Y, a_Z); - } - } - - virtual void OnNeighborChanged(cWorld *a_World, int a_X, int a_Y, int a_Z) override - { - NIBBLETYPE Meta = a_World->GetBlockMeta(a_X, a_Y, a_Z); - a_World->SetBlockMeta(a_X, a_Y, a_Z, Meta & 0x7); //Unset 0x8 bit so it gets checked for decay - } - - virtual bool NeedsRandomTicks() override - { - return true; - } - - virtual void OnUpdate(cWorld *a_World, int a_X, int a_Y, int a_Z) override - { - NIBBLETYPE Meta = a_World->GetBlockMeta(a_X, a_Y, a_Z); - if ((Meta & 0x04) != 0) - { - // Player-placed leaves, don't decay - return; - } - - if (Meta & 0x8) - { - // These leaves have been checked for decay lately and nothing around them changed - return; - } - - // Get the data around the leaves: - cBlockArea Area; - if (!Area.Read( - a_World, - a_X - LEAVES_CHECK_DISTANCE, a_X + LEAVES_CHECK_DISTANCE, - a_Y - LEAVES_CHECK_DISTANCE, a_Y + LEAVES_CHECK_DISTANCE, - a_Z - LEAVES_CHECK_DISTANCE, a_Z + LEAVES_CHECK_DISTANCE, - cBlockArea::baTypes) - ) - { - // Cannot check leaves, a chunk is missing too close - return; - } - - if (HasNearLog(Area, a_X, a_Y, a_Z)) - { - // Wood found, the leaves stay; mark them as checked: - a_World->SetBlockMeta(a_X, a_Y, a_Z, Meta | 0x8); - return; - } - // Decay the leaves: - DropBlock(a_World, a_X, a_Y, a_Z); - - a_World->DigBlock(a_X, a_Y, a_Z); - - } - - virtual AString GetStepSound(void) override - { - return "step.grass"; - } -}; - - -bool HasNearLog(cBlockArea &a_Area, int a_BlockX, int a_BlockY, int a_BlockZ) -{ - // Filter the blocks into a {leaves, log, other (air)} set: - BLOCKTYPE * Types = a_Area.GetBlockTypes(); - for (int i = a_Area.GetBlockCount() - 1; i > 0; i--) - { - switch (Types[i]) - { - case E_BLOCK_LEAVES: - case E_BLOCK_LOG: - { - break; - } - default: - { - Types[i] = E_BLOCK_AIR; - break; - } - } - } // for i - Types[] - - // Perform a breadth-first search to see if there's a log connected within 4 blocks of the leaves block: - // Simply replace all reachable leaves blocks with a sponge block plus iteration (in the Area) and see if we can reach a log in 4 iterations - a_Area.SetBlockType(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_SPONGE); - for (int i = 0; i < LEAVES_CHECK_DISTANCE; i++) - { - for (int y = a_BlockY - i; y <= a_BlockY + i; y++) - { - for (int z = a_BlockZ - i; z <= a_BlockZ + i; z++) - { - for (int x = a_BlockX - i; x <= a_BlockX + i; x++) - { - if (a_Area.GetBlockType(x, y, z) != E_BLOCK_SPONGE + i) - { - continue; - } - PROCESS_NEIGHBOR(x - 1, y, z); - PROCESS_NEIGHBOR(x + 1, y, z); - PROCESS_NEIGHBOR(x, y, z - 1); - PROCESS_NEIGHBOR(x, y, z + 1); - PROCESS_NEIGHBOR(x, y + 1, z); - PROCESS_NEIGHBOR(x, y - 1, z); - } // for x - } // for z - } // for y - } // for i - BFS iterations - return false; -} - diff --git a/source/blocks/BlockMelon.h b/source/blocks/BlockMelon.h deleted file mode 100644 index 87fb7e1e8..000000000 --- a/source/blocks/BlockMelon.h +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once -#include "BlockHandler.h" - - -class cBlockMelonHandler : public cBlockHandler -{ -public: - cBlockMelonHandler(BLOCKTYPE a_BlockID) - : cBlockHandler(a_BlockID) - { - } - - - virtual int GetDropID() override - { - return E_ITEM_MELON_SLICE; - } - - virtual char GetDropCount() override - { - MTRand r1; - return (char)(3 + r1.randInt(4)); - } - - virtual AString GetStepSound(void) override - { - return "step.wood"; - } -}; diff --git a/source/blocks/BlockMushroom.h b/source/blocks/BlockMushroom.h deleted file mode 100644 index c4119bad0..000000000 --- a/source/blocks/BlockMushroom.h +++ /dev/null @@ -1,47 +0,0 @@ -#pragma once -#include "BlockHandler.h" - - -class cBlockMushroomHandler : public cBlockHandler -{ -public: - cBlockMushroomHandler(BLOCKTYPE a_BlockID) - : cBlockHandler(a_BlockID) - { - } - - virtual NIBBLETYPE GetDropMeta(NIBBLETYPE a_BlockMeta) override - { - return 0; - } - - virtual bool CanBeAt(cWorld *a_World, int a_X, int a_Y, int a_Z) override - { - switch (a_World->GetBlock(a_X, a_Y - 1, a_Z)) - { - case E_BLOCK_GLASS: - case E_BLOCK_CACTUS: - case E_BLOCK_ICE: - case E_BLOCK_LEAVES: - case E_BLOCK_AIR: - return false; - } - return true; - } - - virtual bool AllowBlockOnTop() override - { - return false; - } - - - virtual bool CanBePlacedOnSide() override - { - return false; - } - - virtual AString GetStepSound(void) override - { - return "step.grass"; - } -}; diff --git a/source/blocks/BlockNote.h b/source/blocks/BlockNote.h deleted file mode 100644 index 896a5d03b..000000000 --- a/source/blocks/BlockNote.h +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once -#include "BlockHandler.h" -#include "BlockEntity.h" - -class cBlockNoteHandler : public cBlockEntityHandler -{ -public: - cBlockNoteHandler(BLOCKTYPE a_BlockID) - : cBlockEntityHandler(a_BlockID) - { - } - -}; diff --git a/source/blocks/BlockOre.h b/source/blocks/BlockOre.h deleted file mode 100644 index 556a215ce..000000000 --- a/source/blocks/BlockOre.h +++ /dev/null @@ -1,58 +0,0 @@ -#pragma once -#include "BlockHandler.h" -#include "../MersenneTwister.h" -#include "../World.h" - -class cBlockOreHandler : public cBlockHandler -{ -public: - cBlockOreHandler(BLOCKTYPE a_BlockID) - : cBlockHandler(a_BlockID) - { - } - - virtual char GetDropCount() override - { - MTRand r1; - switch(m_BlockID) - { - case E_BLOCK_LAPIS_ORE: - return 4 + (char)r1.randInt(4); - case E_BLOCK_REDSTONE_ORE: - case E_BLOCK_REDSTONE_ORE_GLOWING: - return 4 + (char)r1.randInt(1); - default: - return 1; - } - } - - virtual NIBBLETYPE GetDropMeta(NIBBLETYPE a_Meta) override - { - switch(m_BlockID) - { - case E_BLOCK_LAPIS_ORE: - return 4; - default: - return 0; - } - } - - virtual int GetDropID() override - { - switch(m_BlockID) - { - case E_BLOCK_DIAMOND_ORE: - return E_ITEM_DIAMOND; - case E_BLOCK_REDSTONE_ORE: - case E_BLOCK_REDSTONE_ORE_GLOWING: - return E_ITEM_REDSTONE_DUST; - case E_BLOCK_EMERALD_ORE: - return E_ITEM_EMERALD; - case E_BLOCK_LAPIS_ORE: - return E_ITEM_DYE; - case E_BLOCK_COAL_ORE: - return E_ITEM_COAL; - } - return m_BlockID; - } -}; \ No newline at end of file diff --git a/source/blocks/BlockPiston.cpp b/source/blocks/BlockPiston.cpp deleted file mode 100644 index a4ed13d88..000000000 --- a/source/blocks/BlockPiston.cpp +++ /dev/null @@ -1,51 +0,0 @@ -#include "Globals.h" -#include "BlockPiston.h" -#include "../Item.h" -#include "../World.h" -#include "../Redstone.h" -#include "../Player.h" -#include "../Piston.h" - - - -#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; } - - - - -cBlockPistonHandler::cBlockPistonHandler(BLOCKTYPE a_BlockID) - : cBlockHandler(a_BlockID) -{ -} - -void cBlockPistonHandler::OnPlaced(cWorld *a_World, int a_X, int a_Y, int a_Z, int a_Dir) -{ - -} - -void cBlockPistonHandler::OnDestroyed(cWorld *a_World, int a_X, int a_Y, int a_Z) -{ - char OldMeta = a_World->GetBlockMeta(a_X, a_Y, a_Z); - - int newX = a_X; - int newY = a_Y; - int newZ = a_Z; - AddPistonDir(newX, newY, newZ, OldMeta & ~(8), 1); - - if (a_World->GetBlock(newX, newY, newZ) == E_BLOCK_PISTON_EXTENSION) - { - a_World->SetBlock(newX, newY, newZ, E_BLOCK_AIR, 0); - } -} - -void cBlockPistonHandler::PlaceBlock(cWorld *a_World, cPlayer *a_Player, NIBBLETYPE a_BlockMeta, int a_X, int a_Y, int a_Z, char a_Dir) -{ - - a_World->SetBlock(a_X, a_Y, a_Z, m_BlockID, cPiston::RotationPitchToMetaData(a_Player->GetRotation(), a_Player->GetPitch())); - OnPlacedByPlayer(a_World, a_Player, a_X, a_Y, a_Z, a_Dir); - - cRedstone Redstone(a_World); - Redstone.ChangeRedstone(a_X, a_Y, a_Z, false); -} \ No newline at end of file diff --git a/source/blocks/BlockPiston.h b/source/blocks/BlockPiston.h deleted file mode 100644 index dbce9bae5..000000000 --- a/source/blocks/BlockPiston.h +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once -#include "BlockHandler.h" - - -class cBlockPistonHandler : public cBlockHandler -{ -public: - cBlockPistonHandler(BLOCKTYPE a_BlockID); - virtual void OnPlaced(cWorld *a_World, int a_X, int a_Y, int a_Z, int a_Dir) override; - virtual void OnDestroyed(cWorld *a_World, int a_X, int a_Y, int a_Z) override; - - - virtual void PlaceBlock(cWorld *a_World, cPlayer *a_Player, NIBBLETYPE a_BlockMeta, int a_X, int a_Y, int a_Z, char a_Dir) override; - -}; \ No newline at end of file diff --git a/source/blocks/BlockRedstone.cpp b/source/blocks/BlockRedstone.cpp deleted file mode 100644 index 7653436f4..000000000 --- a/source/blocks/BlockRedstone.cpp +++ /dev/null @@ -1,41 +0,0 @@ -#include "Globals.h" -#include "BlockRedstone.h" -#include "../Item.h" -#include "../World.h" -#include "../Redstone.h" -#include "../Torch.h" - -cBlockRedstoneHandler::cBlockRedstoneHandler(BLOCKTYPE a_BlockID) - : cBlockHandler(a_BlockID) -{ -} - -void cBlockRedstoneHandler::OnPlaced(cWorld *a_World, int a_X, int a_Y, int a_Z, int a_Dir) -{ - cRedstone Redstone(a_World); - bool Added = false; - if(a_World->GetBlock(a_X, a_Y, a_Z) == E_BLOCK_REDSTONE_TORCH_ON) - Added = true; - - Redstone.ChangeRedstone(a_X, a_Y, a_Z, Added); -} - -void cBlockRedstoneHandler::OnDestroyed(cWorld *a_World, int a_X, int a_Y, int a_Z) -{ - cRedstone Redstone(a_World); - Redstone.ChangeRedstone(a_X, a_Y, a_Z, false); -} - -void cBlockRedstoneHandler::PlaceBlock(cWorld *a_World, cPlayer *a_Player, NIBBLETYPE a_BlockMeta, int a_X, int a_Y, int a_Z, char a_Dir) -{ - switch(m_BlockID) - { - case E_BLOCK_REDSTONE_TORCH_ON: - case E_BLOCK_REDSTONE_TORCH_OFF: - a_BlockMeta = cTorch::DirectionToMetaData(a_Dir); - break; - - } - a_World->SetBlock(a_X, a_Y, a_Z, m_BlockID, a_BlockMeta); - OnPlacedByPlayer(a_World, a_Player, a_X, a_Y, a_Z, a_Dir); -} \ No newline at end of file diff --git a/source/blocks/BlockRedstone.h b/source/blocks/BlockRedstone.h deleted file mode 100644 index 9b83b1b29..000000000 --- a/source/blocks/BlockRedstone.h +++ /dev/null @@ -1,33 +0,0 @@ -#pragma once -#include "BlockHandler.h" -#include "../World.h" - -class cBlockRedstoneHandler : public cBlockHandler -{ -public: - cBlockRedstoneHandler(BLOCKTYPE a_BlockID); - virtual void OnPlaced(cWorld *a_World, int a_X, int a_Y, int a_Z, int a_Dir) override; - virtual void OnDestroyed(cWorld *a_World, int a_X, int a_Y, int a_Z) override; - - virtual void PlaceBlock(cWorld *a_World, cPlayer *a_Player, NIBBLETYPE a_BlockMeta, int a_X, int a_Y, int a_Z, char a_Dir) override; - - virtual bool AllowBlockOnTop() override - { - return false; - } - - virtual bool CanBeAt(cWorld *a_World, int a_X, int a_Y, int a_Z) override - { - return a_World->GetBlock(a_X, a_Y - 1, a_Z) != E_BLOCK_AIR; - } - - virtual int GetDropID() override - { - return E_ITEM_REDSTONE_DUST; - } - - virtual bool CanBePlacedOnSide() override - { - return false; - } -}; \ No newline at end of file diff --git a/source/blocks/BlockRedstoneRepeater.cpp b/source/blocks/BlockRedstoneRepeater.cpp deleted file mode 100644 index 861f6e221..000000000 --- a/source/blocks/BlockRedstoneRepeater.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include "Globals.h" -#include "BlockRedstoneRepeater.h" -#include "../Item.h" -#include "../World.h" -#include "../Redstone.h" -#include "../Player.h" - -cBlockRedstoneRepeaterHandler::cBlockRedstoneRepeaterHandler(BLOCKTYPE a_BlockID) - : cBlockHandler(a_BlockID) -{ -} - -void cBlockRedstoneRepeaterHandler::OnPlaced(cWorld *a_World, int a_X, int a_Y, int a_Z, int a_Dir) -{ - cRedstone Redstone(a_World); - Redstone.ChangeRedstone(a_X, a_Y, a_Z, false); -} - -void cBlockRedstoneRepeaterHandler::OnDestroyed(cWorld *a_World, int a_X, int a_Y, int a_Z) -{ - cRedstone Redstone(a_World); - Redstone.ChangeRedstone(a_X, a_Y, a_Z, false); -} - -void cBlockRedstoneRepeaterHandler::OnUse(cWorld *a_World, cPlayer *a_Player, int a_X, int a_Y, int a_Z) -{ - a_World->FastSetBlock(a_X, a_Y, a_Z, m_BlockID, ((a_World->GetBlockMeta(a_X, a_Y, a_Z) + 0x04) & 0x0f)); -} - -void cBlockRedstoneRepeaterHandler::OnDigging(cWorld *a_World, cPlayer *a_Player, int a_X, int a_Y, int a_Z) -{ - OnUse(a_World, a_Player, a_X, a_Y, a_Z); -} - -void cBlockRedstoneRepeaterHandler::PlaceBlock(cWorld *a_World, cPlayer *a_Player, NIBBLETYPE a_BlockMeta, int a_X, int a_Y, int a_Z, char a_Dir) -{ - a_World->SetBlock(a_X, a_Y, a_Z, m_BlockID, cRedstone::RepeaterRotationToMetaData(a_Player->GetRotation())); - OnPlacedByPlayer(a_World, a_Player, a_X, a_Y, a_Z, a_Dir); -} \ No newline at end of file diff --git a/source/blocks/BlockRedstoneRepeater.h b/source/blocks/BlockRedstoneRepeater.h deleted file mode 100644 index a928f554f..000000000 --- a/source/blocks/BlockRedstoneRepeater.h +++ /dev/null @@ -1,52 +0,0 @@ -#pragma once -#include "BlockHandler.h" -#include "../World.h" - -class cBlockRedstoneRepeaterHandler : public cBlockHandler -{ -public: - cBlockRedstoneRepeaterHandler(BLOCKTYPE a_BlockID); - virtual void OnPlaced(cWorld *a_World, int a_X, int a_Y, int a_Z, int a_Dir) override; - virtual void OnDestroyed(cWorld *a_World, int a_X, int a_Y, int a_Z) override; - - virtual void OnDigging(cWorld *a_World, cPlayer *a_Player, int a_X, int a_Y, int a_Z) override; - virtual void OnUse(cWorld *a_World, cPlayer *a_Player, int a_X, int a_Y, int a_Z) override; - - virtual NIBBLETYPE GetDropMeta(NIBBLETYPE a_BlockMeta) override - { - return 0; - } - - virtual int GetDropID() override - { - return E_ITEM_REDSTONE_REPEATER; - } - - virtual bool IsUseable() override - { - return true; - } - - virtual void PlaceBlock(cWorld *a_World, cPlayer *a_Player, NIBBLETYPE a_BlockMeta, int a_X, int a_Y, int a_Z, char a_Dir) override; - - virtual bool AllowBlockOnTop() override - { - return false; - } - - virtual bool CanBeAt(cWorld *a_World, int a_X, int a_Y, int a_Z) override - { - return a_World->GetBlock(a_X, a_Y - 1, a_Z) != E_BLOCK_AIR; - } - - - virtual bool CanBePlacedOnSide() override - { - return false; - } - - virtual AString GetStepSound(void) override - { - return "step.wood"; - } -}; diff --git a/source/blocks/BlockRedstoneTorch.h b/source/blocks/BlockRedstoneTorch.h deleted file mode 100644 index eeb2afc5c..000000000 --- a/source/blocks/BlockRedstoneTorch.h +++ /dev/null @@ -1,28 +0,0 @@ - -#pragma once -#include "BlockRedstone.h" -#include "BlockTorch.h" -#include "../Torch.h" - - - - - -class cBlockRedstoneTorchHandler : public cBlockTorchHandler -{ -public: - cBlockRedstoneTorchHandler(BLOCKTYPE a_BlockID) - : cBlockTorchHandler(a_BlockID) - { - } - - virtual int GetDropID(void) override - { - return E_ITEM_REDSTONE_TORCH_ON; - } - - virtual AString GetStepSound(void) override - { - return "step.wood"; - } -}; diff --git a/source/blocks/BlockSand.h b/source/blocks/BlockSand.h deleted file mode 100644 index 69fda5ec6..000000000 --- a/source/blocks/BlockSand.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once -#include "BlockHandler.h" - - -class cBlockSandHandler : public cBlockHandler -{ -public: - cBlockSandHandler(BLOCKTYPE a_BlockID) - : cBlockHandler(a_BlockID) - { - } - - virtual AString GetStepSound(void) override - { - return "step.sand"; - } - -}; diff --git a/source/blocks/BlockSapling.h b/source/blocks/BlockSapling.h deleted file mode 100644 index c9862349a..000000000 --- a/source/blocks/BlockSapling.h +++ /dev/null @@ -1,56 +0,0 @@ -#pragma once -#include "BlockHandler.h" -#include "../World.h" - -class cBlockSaplingHandler : public cBlockHandler -{ -public: - cBlockSaplingHandler(BLOCKTYPE a_BlockID) - : cBlockHandler(a_BlockID) - { - } - - virtual bool NeedsRandomTicks() override - { - return true; - } - - virtual NIBBLETYPE GetDropMeta(NIBBLETYPE a_BlockMeta) override - { - return a_BlockMeta & 3; //Only the first 2 bits contain the display information the others are for growing - } - - virtual bool CanBeAt(cWorld *a_World, int a_X, int a_Y, int a_Z) override - { - return IsBlockTypeOfDirt(a_World->GetBlock(a_X, a_Y - 1, a_Z)); - } - - virtual bool AllowBlockOnTop() override - { - return false; - } - - void OnUpdate(cWorld *a_World, int a_X, int a_Y, int a_Z) override - { - NIBBLETYPE Meta = a_World->GetBlockMeta(a_X, a_Y, a_Z); - - if ((Meta & 0x08) != 0) - { - a_World->GrowTree(a_X, a_Y, a_Z); - } - else - { - a_World->SetBlockMeta(a_X, a_Y, a_Z, Meta | 0x08); - } - } - - virtual bool CanBePlacedOnSide() override - { - return false; - } - - virtual AString GetStepSound(void) override - { - return "step.grass"; - } -}; diff --git a/source/blocks/BlockSign.h b/source/blocks/BlockSign.h deleted file mode 100644 index dd82605b3..000000000 --- a/source/blocks/BlockSign.h +++ /dev/null @@ -1,47 +0,0 @@ -#pragma once -#include "BlockHandler.h" -#include "../World.h" -#include "../Sign.h" -#include "../Player.h" - -class cBlockSignHandler : public cBlockHandler -{ -public: - cBlockSignHandler(BLOCKTYPE a_BlockID) - : cBlockHandler(a_BlockID) - { - - } - - virtual void PlaceBlock(cWorld *a_World, cPlayer *a_Player, NIBBLETYPE a_BlockMeta, int a_X, int a_Y, int a_Z, char a_Dir) override - { - BLOCKTYPE Block; - NIBBLETYPE Meta; - if(a_Dir == 1) - { - Meta = cSign::RotationToMetaData(a_Player->GetRotation()); - Block = E_BLOCK_SIGN_POST; - }else{ - Meta = cSign::DirectionToMetaData(a_Dir); - Block = E_BLOCK_WALLSIGN; - } - - a_World->SetBlock(a_X, a_Y, a_Z, Block, Meta); - OnPlacedByPlayer(a_World, a_Player, a_X, a_Y, a_Z, a_Dir); - } - - virtual int GetDropID() override - { - return E_ITEM_SIGN; - } - - virtual bool AllowBlockOnTop() override - { - return false; - } - - virtual AString GetStepSound(void) override - { - return "step.wood"; - } -}; diff --git a/source/blocks/BlockSlab.h b/source/blocks/BlockSlab.h deleted file mode 100644 index ad9970d67..000000000 --- a/source/blocks/BlockSlab.h +++ /dev/null @@ -1,51 +0,0 @@ -#pragma once -#include "BlockHandler.h" - - -class cBlockSlabHandler : public cBlockHandler -{ -public: - cBlockSlabHandler(BLOCKTYPE a_BlockID) - : cBlockHandler(a_BlockID) - { - } - - virtual NIBBLETYPE GetDropMeta(NIBBLETYPE a_BlockMeta) override - { - return a_BlockMeta; - } - - virtual char GetDropCount() override - { - if(m_BlockID == E_BLOCK_DOUBLE_STONE_SLAB - || m_BlockID == E_BLOCK_DOUBLE_WOODEN_SLAB) - return 2; - return 1; - } - - - virtual void PlaceBlock(cWorld *a_World, cPlayer *a_Player, NIBBLETYPE a_BlockMeta, int a_X, int a_Y, int a_Z, char a_Dir) override - { - a_World->SetBlock(a_X, a_Y, a_Z, m_BlockID, DirectionToMetaData( a_Dir, a_BlockMeta )); - OnPlacedByPlayer(a_World, a_Player, a_X, a_Y, a_Z, a_Dir); - } - - static char DirectionToMetaData( char a_Direction, NIBBLETYPE Meta ) - { - char result = Meta; - if( a_Direction == 0) - { - result |= 0x8; - } - return result; - } - - virtual AString GetStepSound(void) override - { - if (m_BlockID == E_BLOCK_WOODEN_SLAB || m_BlockID ==E_BLOCK_DOUBLE_WOODEN_SLAB) - return "step.wood"; - - else - return "step.stone"; - } -}; diff --git a/source/blocks/BlockSnow.h b/source/blocks/BlockSnow.h deleted file mode 100644 index c8e6b4c1c..000000000 --- a/source/blocks/BlockSnow.h +++ /dev/null @@ -1,44 +0,0 @@ -#pragma once -#include "BlockHandler.h" - - -class cBlockSnowHandler : public cBlockHandler -{ -public: - cBlockSnowHandler(BLOCKTYPE a_BlockID) - : cBlockHandler(a_BlockID) - { - } - - virtual bool IgnoreBuildCollision() override - { - return true; - } - - virtual int GetDropID() override - { - return E_ITEM_SNOWBALL; - } - - virtual char GetDropCount() override - { - return 4; - } - - - virtual bool CanBeAt(cWorld *a_World, int a_X, int a_Y, int a_Z) override - { - return a_World->GetBlock(a_X, a_Y - 1, a_Z) != E_BLOCK_AIR; - } - - virtual bool DropOnUnsuitable() override - { - return false; - } - - virtual AString GetStepSound(void) override - { - return "step.cloth"; - } - -}; diff --git a/source/blocks/BlockStairs.h b/source/blocks/BlockStairs.h deleted file mode 100644 index 4d0007bc5..000000000 --- a/source/blocks/BlockStairs.h +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once -#include "BlockHandler.h" -#include "../Stairs.h" - -class cBlockStairsHandler : public cBlockHandler -{ -public: - cBlockStairsHandler(BLOCKTYPE a_BlockID) - : cBlockHandler(a_BlockID) - { - - } - - - virtual void PlaceBlock(cWorld *a_World, cPlayer *a_Player, NIBBLETYPE a_BlockMeta, int a_X, int a_Y, int a_Z, char a_Dir) override - { - a_World->SetBlock(a_X, a_Y, a_Z, m_BlockID, cStairs::RotationToMetaData(a_Player->GetRotation(), a_Dir)); - OnPlacedByPlayer(a_World, a_Player, a_X, a_Y, a_Z, a_Dir); - } - - //TODO: step sound -}; diff --git a/source/blocks/BlockStems.h b/source/blocks/BlockStems.h deleted file mode 100644 index be4519a52..000000000 --- a/source/blocks/BlockStems.h +++ /dev/null @@ -1,46 +0,0 @@ -#pragma once -#include "BlockHandler.h" -#include "../MersenneTwister.h" -#include "../World.h" - -class cBlockStemsHandler : public cBlockHandler -{ -public: - cBlockStemsHandler(BLOCKTYPE a_BlockID) - : cBlockHandler(a_BlockID) - { - } - - virtual bool NeedsRandomTicks() override - { - return true; - } - - virtual NIBBLETYPE GetDropMeta(NIBBLETYPE a_BlockMeta) override - { - return 0; - } - - virtual int GetDropID() override - { - if(m_BlockID == E_BLOCK_MELON_STEM) - return E_ITEM_MELON_SEEDS; - return E_ITEM_PUMPKIN_SEEDS; - } - - void OnUpdate(cWorld *a_World, int a_X, int a_Y, int a_Z) override - { - //TODO: Handle Growing here - } - - virtual bool CanBeAt(cWorld *a_World, int a_X, int a_Y, int a_Z) override - { - return a_World->GetBlock(a_X, a_Y - 1, a_Z) == E_BLOCK_FARMLAND; - } - - virtual AString GetStepSound(void) override - { - return "step.wood"; - } - -}; diff --git a/source/blocks/BlockStone.h b/source/blocks/BlockStone.h deleted file mode 100644 index 8b645bf1e..000000000 --- a/source/blocks/BlockStone.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once -#include "BlockHandler.h" -#include "../MersenneTwister.h" -#include "../World.h" - -class cBlockStoneHandler : public cBlockHandler -{ -public: - cBlockStoneHandler(BLOCKTYPE a_BlockID) - : cBlockHandler(a_BlockID) - { - } - - virtual int GetDropID() override - { - return E_ITEM_COBBLESTONE; - } -}; \ No newline at end of file diff --git a/source/blocks/BlockSugarcane.h b/source/blocks/BlockSugarcane.h deleted file mode 100644 index 1d477b42b..000000000 --- a/source/blocks/BlockSugarcane.h +++ /dev/null @@ -1,71 +0,0 @@ - -#pragma once -#include "BlockHandler.h" - - - - - -class cBlockSugarcaneHandler : - public cBlockHandler -{ -public: - cBlockSugarcaneHandler(BLOCKTYPE a_BlockID) - : cBlockHandler(a_BlockID) - { - } - - - virtual bool NeedsRandomTicks() override - { - return true; - } - - - virtual int GetDropID() override - { - return E_ITEM_SUGARCANE; - } - - - virtual bool CanBeAt(cWorld * a_World, int a_X, int a_Y, int a_Z) override - { - switch (a_World->GetBlock(a_X, a_Y - 1, a_Z)) - { - case E_BLOCK_DIRT: - case E_BLOCK_GRASS: - case E_BLOCK_FARMLAND: - case E_BLOCK_SAND: - { - return a_World->IsBlockDirectlyWatered(a_X, a_Y - 1, a_Z); - } - case E_BLOCK_SUGARCANE: - { - return true; - } - } - return false; - } - - - void OnUpdate(cWorld * a_World, int a_X, int a_Y, int a_Z) override - { - //TODO: Handle Growing here - } - - - virtual bool CanBePlacedOnSide() override - { - return false; - } - - virtual AString GetStepSound(void) override - { - return "step.grass"; - } - -}; - - - - diff --git a/source/blocks/BlockTallGrass.h b/source/blocks/BlockTallGrass.h deleted file mode 100644 index f5bb1b373..000000000 --- a/source/blocks/BlockTallGrass.h +++ /dev/null @@ -1,41 +0,0 @@ -#pragma once -#include "BlockHandler.h" - - -class cBlockTallGrassHandler : public cBlockHandler -{ -public: - cBlockTallGrassHandler(BLOCKTYPE a_BlockID) - : cBlockHandler(a_BlockID) - { - } - - virtual bool IgnoreBuildCollision() override - { - return true; - } - - virtual int GetDropID() override - { - return E_ITEM_SEEDS; - } - - virtual char GetDropCount() override - { - MTRand r1; - if(r1.randInt(10) == 5) - return 1; - return 0; - } - - virtual bool CanBeAt(cWorld *a_World, int a_X, int a_Y, int a_Z) override - { - return a_World->GetBlock(a_X, a_Y - 1, a_Z) != E_BLOCK_AIR; - } - - virtual AString GetStepSound(void) override - { - return "step.grass"; - } - -}; diff --git a/source/blocks/BlockTorch.h b/source/blocks/BlockTorch.h deleted file mode 100644 index 450b5ecab..000000000 --- a/source/blocks/BlockTorch.h +++ /dev/null @@ -1,166 +0,0 @@ - -#pragma once -#include "BlockHandler.h" -#include "../Torch.h" -#include "../World.h" - - - - - -class cBlockTorchHandler : public cBlockHandler -{ -public: - cBlockTorchHandler(BLOCKTYPE a_BlockID) - : cBlockHandler(a_BlockID) - { - } - - - virtual void PlaceBlock(cWorld * a_World, cPlayer * a_Player, NIBBLETYPE a_BlockMeta, int a_X, int a_Y, int a_Z, char a_Dir) override - { - if(!TorchCanBePlacedAt(a_World, a_X, a_Y, a_Z, a_Dir)) - { - a_Dir = FindSuitableDirection(a_World, a_X, a_Y, a_Z); - - if(a_Dir == BLOCK_FACE_BOTTOM) - return; - } - - a_World->SetBlock(a_X, a_Y, a_Z, m_BlockID, cTorch::DirectionToMetaData(a_Dir)); - OnPlacedByPlayer(a_World, a_Player, a_X, a_Y, a_Z, a_Dir); - } - - - virtual bool AllowBlockOnTop(void) override - { - return false; - } - - - static bool CanBePlacedOn(BLOCKTYPE a_BlockType, char a_Direction) - { - switch (a_BlockType) - { - case E_BLOCK_STONE: - case E_BLOCK_GRASS: - case E_BLOCK_DIRT: - case E_BLOCK_COBBLESTONE: - case E_BLOCK_PLANKS: - case E_BLOCK_BEDROCK: - case E_BLOCK_SAND: - case E_BLOCK_GRAVEL: - case E_BLOCK_GOLD_ORE: - case E_BLOCK_IRON_ORE: - case E_BLOCK_COAL_ORE: - case E_BLOCK_LOG: - case E_BLOCK_SPONGE: - case E_BLOCK_LAPIS_ORE: - case E_BLOCK_LAPIS_BLOCK: - case E_BLOCK_SANDSTONE: - case E_BLOCK_WOOL: - case E_BLOCK_GOLD_BLOCK: - case E_BLOCK_IRON_BLOCK: - case E_BLOCK_DOUBLE_STONE_SLAB: - case E_BLOCK_BRICK: - case E_BLOCK_BOOKCASE: - case E_BLOCK_MOSSY_COBBLESTONE: - case E_BLOCK_OBSIDIAN: - case E_BLOCK_MOB_SPAWNER: - case E_BLOCK_DIAMOND_ORE: - case E_BLOCK_DIAMOND_BLOCK: - case E_BLOCK_CRAFTING_TABLE: - case E_BLOCK_REDSTONE_ORE: - case E_BLOCK_REDSTONE_ORE_GLOWING: - case E_BLOCK_SNOW_BLOCK: - case E_BLOCK_CLAY: - case E_BLOCK_JUKEBOX: - case E_BLOCK_PUMPKIN: - case E_BLOCK_NETHERRACK: - case E_BLOCK_SOULSAND: - case E_BLOCK_JACK_O_LANTERN: - case E_BLOCK_LOCKED_CHEST: - case E_BLOCK_STONE_BRICKS: - case E_BLOCK_MELON: - case E_BLOCK_MYCELIUM: - case E_BLOCK_NETHER_BRICK: - case E_BLOCK_END_STONE: - case E_BLOCK_REDSTONE_LAMP_OFF: - case E_BLOCK_REDSTONE_LAMP_ON: - case E_BLOCK_DOUBLE_WOODEN_SLAB: - case E_BLOCK_EMERALD_ORE: - case E_BLOCK_ENDER_CHEST: - case E_BLOCK_EMERALD_BLOCK: - { - return true; - } - - case E_BLOCK_GLASS: - case E_BLOCK_FENCE: - case E_BLOCK_NETHER_BRICK_FENCE: - { - return (a_Direction == 0x1); // allow only direction "standing on floor" - } - - default: - { - return false; - } - } - } - - - static bool TorchCanBePlacedAt(cWorld * a_World, int a_X, int a_Y, int a_Z, char a_Dir) - { - // TODO: If placing a torch from below, check all 4 XZ neighbors, place it on that neighbor instead - // How to propagate that change up? - // Simon: The easiest way is to calculate the position two times, shouldnīt cost much cpu power :) - - if(a_Dir == BLOCK_FACE_BOTTOM) - return false; - - AddDirection( a_X, a_Y, a_Z, a_Dir, true ); - - return CanBePlacedOn(a_World->GetBlock( a_X, a_Y, a_Z ), a_Dir); - } - - // Finds a suitable Direction for the Torch. Returns BLOCK_FACE_BOTTOM on failure - static char FindSuitableDirection(cWorld * a_World, int a_X, int a_Y, int a_Z) - { - for(int i = 1; i <= 5; i++) - { - if(TorchCanBePlacedAt(a_World, a_X, a_Y, a_Z, i)) - return i; - } - return BLOCK_FACE_BOTTOM; - } - - virtual bool CanBePlacedAt(cWorld * a_World, int a_X, int a_Y, int a_Z, char a_Dir) override - { - if(TorchCanBePlacedAt(a_World, a_X, a_Y, a_Z, a_Dir)) - return true; - - return FindSuitableDirection(a_World, a_X, a_Y, a_Z) != BLOCK_FACE_BOTTOM; - } - - - virtual bool CanBeAt(cWorld * a_World, int a_X, int a_Y, int a_Z) override - { - char Dir = cTorch::MetaDataToDirection(a_World->GetBlockMeta( a_X, a_Y, a_Z)); - return TorchCanBePlacedAt(a_World, a_X, a_Y, a_Z, Dir); - } - - virtual NIBBLETYPE GetDropMeta(NIBBLETYPE a_BlockMeta) override - { - return 0; - } - - virtual AString GetStepSound(void) override - { - return "step.wood"; - } -}; - - - - diff --git a/source/blocks/BlockVine.h b/source/blocks/BlockVine.h deleted file mode 100644 index 56317219a..000000000 --- a/source/blocks/BlockVine.h +++ /dev/null @@ -1,35 +0,0 @@ -#pragma once -#include "BlockHandler.h" -#include "../Vine.h" - -class cBlockVineHandler : public cBlockHandler -{ -public: - cBlockVineHandler(BLOCKTYPE a_BlockID) - : cBlockHandler(a_BlockID) - { - } - - virtual bool IgnoreBuildCollision() override - { - return true; - } - - virtual void PlaceBlock(cWorld *a_World, cPlayer *a_Player, NIBBLETYPE a_BlockMeta, int a_X, int a_Y, int a_Z, char a_Dir) override - { - a_World->SetBlock(a_X, a_Y, a_Z, m_BlockID, cVine::DirectionToMetaData(a_Dir)); - OnPlacedByPlayer(a_World, a_Player, a_X, a_Y, a_Z, a_Dir); - } - - - virtual bool AllowBlockOnTop() override - { - return false; - } - - virtual AString GetStepSound(void) override - { - return "step.grass"; - } - -}; diff --git a/source/blocks/BlockWood.h b/source/blocks/BlockWood.h deleted file mode 100644 index d71d5d71c..000000000 --- a/source/blocks/BlockWood.h +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once -#include "BlockHandler.h" - - -class cBlockWoodHandler : public cBlockHandler -{ -public: - cBlockWoodHandler(BLOCKTYPE a_BlockID) - : cBlockHandler(a_BlockID) - { - } - NIBBLETYPE GetDropMeta(NIBBLETYPE a_BlockMeta) override - { - return a_BlockMeta; - } - - virtual AString GetStepSound(void) override - { - return "step.wood"; - } - -}; diff --git a/source/blocks/BlockWorkbench.h b/source/blocks/BlockWorkbench.h deleted file mode 100644 index c1c004dc5..000000000 --- a/source/blocks/BlockWorkbench.h +++ /dev/null @@ -1,36 +0,0 @@ -#pragma once -#include "BlockHandler.h" -#include "../UI/Window.h" -#include "../Player.h" - - - - - -class cBlockWorkbenchHandler: - public cBlockHandler -{ -public: - cBlockWorkbenchHandler(BLOCKTYPE a_BlockID) - : cBlockHandler(a_BlockID) - { - } - - virtual void OnUse(cWorld * a_World, cPlayer *a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) override - { - cWindow * Window = new cCraftingWindow(a_BlockX, a_BlockY, a_BlockZ); - a_Player->OpenWindow(Window); - } - - virtual bool IsUseable() override - { - return true; - } - - virtual AString GetStepSound(void) override - { - return "step.wood"; - } - - -}; \ No newline at end of file diff --git a/source/items/ItemBed.h b/source/items/ItemBed.h deleted file mode 100644 index b49df65a3..000000000 --- a/source/items/ItemBed.h +++ /dev/null @@ -1,25 +0,0 @@ - -#pragma once - -#include "ItemHandler.h" -#include "../World.h" - -class cItemBedHandler : public cItemHandler -{ -public: - cItemBedHandler(int a_ItemID) - : cItemHandler(a_ItemID) - { - - } - - virtual bool IsPlaceable() override - { - return true; - } - - virtual BLOCKTYPE GetBlockType() override - { - return E_BLOCK_BED; - } -}; \ No newline at end of file diff --git a/source/items/ItemBucket.h b/source/items/ItemBucket.h deleted file mode 100644 index 736112960..000000000 --- a/source/items/ItemBucket.h +++ /dev/null @@ -1,94 +0,0 @@ - -#pragma once - -#include "ItemHandler.h" -#include "../World.h" - -class cItemBucketHandler : public cItemHandler -{ -public: - cItemBucketHandler(int a_ItemID) - : cItemHandler(a_ItemID) - { - - } - - virtual bool OnItemUse(cWorld *a_World, cPlayer *a_Player, cItem *a_Item, int a_X, int a_Y, int a_Z, char a_Dir) override - { - switch(m_ItemID) - { - case E_ITEM_BUCKET: - { - if (a_Dir >= 0) - { - AddDirection(a_X, a_Y, a_Z, a_Dir); - } - BLOCKTYPE ClickedBlock = a_World->GetBlock(a_X, a_Y, a_Z); - LOG("Bucket Clicked BlockID: %d", ClickedBlock); - ENUM_ITEM_ID NewItem = E_ITEM_EMPTY; - switch (ClickedBlock) - { - 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; - } - } - cItem Item(a_Item->m_ItemID, 1); - if ( - (NewItem != E_ITEM_EMPTY) && - ( - ((a_Player->GetGameMode() == 1) || - a_Player->GetInventory().RemoveItem(Item)) - ) - ) - { - // Give New Bucket - cItem Item(NewItem, 1); - a_Player->GetInventory().AddItem(Item); - // Remove water / lava block - a_Player->GetWorld()->SetBlock(a_X, a_Y, a_Z, E_BLOCK_AIR, 0); - return true; - } - break; - } - - case E_ITEM_WATER_BUCKET: - case E_ITEM_LAVA_BUCKET: - { - BLOCKTYPE NewBlock = (m_ItemID == E_ITEM_LAVA_BUCKET) ? E_BLOCK_LAVA : E_BLOCK_WATER; - if (a_Dir >= 0) - { - AddDirection(a_X, a_Y, a_Z, a_Dir); - } - if(a_World->GetBlock(a_X, a_Y, a_Z) == E_BLOCK_AIR) - { - cItem Item(a_Item->m_ItemID, 1); - if ((a_Player->GetGameMode() == 1) || (a_Player->GetInventory().RemoveItem(Item))) - { - a_World->SetBlock(a_X, a_Y, a_Z, NewBlock, 0); - - if (a_Player->GetGameMode() == 1) - { - break; //No new Bucket for creative players - } - cItem Item(E_ITEM_BUCKET, 1); - a_Player->GetInventory().AddItem(Item); - return true; - } - } - } - break; - } - - return false; - } - -}; \ No newline at end of file diff --git a/source/items/ItemCloth.h b/source/items/ItemCloth.h deleted file mode 100644 index 5de064397..000000000 --- a/source/items/ItemCloth.h +++ /dev/null @@ -1,23 +0,0 @@ - -#pragma once - -#include "ItemHandler.h" - - - - - -class cItemClothHandler : - public cItemHandler -{ -public: - cItemClothHandler(int a_ItemID) - : cItemHandler(a_ItemID) - { - - } -} ; - - - - diff --git a/source/items/ItemDoor.h b/source/items/ItemDoor.h deleted file mode 100644 index 6e841333f..000000000 --- a/source/items/ItemDoor.h +++ /dev/null @@ -1,26 +0,0 @@ - -#pragma once - -#include "ItemHandler.h" -#include "../World.h" - -class cItemDoorHandler : public cItemHandler -{ -public: - cItemDoorHandler(int a_ItemID) - : cItemHandler(a_ItemID) - { - - } - - virtual bool IsPlaceable() override - { - return true; - } - - virtual BLOCKTYPE GetBlockType() override - { - return (m_ItemID == E_ITEM_WOODEN_DOOR) ? E_BLOCK_WOODEN_DOOR : E_BLOCK_IRON_DOOR; - } - -}; \ No newline at end of file diff --git a/source/items/ItemDye.h b/source/items/ItemDye.h deleted file mode 100644 index 5b21a501c..000000000 --- a/source/items/ItemDye.h +++ /dev/null @@ -1,35 +0,0 @@ - -#pragma once - -#include "ItemHandler.h" -#include "../World.h" -#include "../Player.h" - -class cItemDyeHandler : public cItemHandler -{ -public: - cItemDyeHandler(int a_ItemID) - : cItemHandler(a_ItemID) - { - - } - - virtual bool OnItemUse(cWorld *a_World, cPlayer *a_Player, cItem *a_Item, int a_X, int a_Y, int a_Z, char a_Dir) override - { - // TODO: Handle coloring the sheep, too (OnItemUseOnEntity maybe) - // Handle growing the plants: - if (a_Item->m_ItemHealth == E_META_DYE_WHITE) - { - if(a_World->GrowPlant(a_X, a_Y, a_Z, true)) - { - if (a_Player->GetGameMode() == eGameMode_Survival) - { - cItem Item(a_Item->m_ItemID, 1, a_Item->m_ItemHealth); - a_Player->GetInventory().RemoveItem(Item); - return true; - } - } - } - return false; - } -}; \ No newline at end of file diff --git a/source/items/ItemFood.h b/source/items/ItemFood.h deleted file mode 100644 index 6e5a27d5d..000000000 --- a/source/items/ItemFood.h +++ /dev/null @@ -1,56 +0,0 @@ - -#pragma once - -#include "ItemHandler.h" - - -class cItemFoodHandler : public cItemHandler -{ -public: - cItemFoodHandler(int a_ItemID) - : cItemHandler(a_ItemID) - { - } - - virtual bool IsFood() override - { - return true; - } - - virtual FoodInfo GetFoodInfo() override - { - switch(m_ItemID) - { - case E_ITEM_BREAD: - return FoodInfo(5, 6.f); - case E_ITEM_COOKIE: - return FoodInfo(2, 0.4f); - case E_ITEM_MELON_SLICE: - return FoodInfo(2, 1.2f); - case E_ITEM_RAW_CHICKEN: - return FoodInfo(2, 1.2f, 30); - case E_ITEM_COOKED_CHICKEN: - return FoodInfo(6, 7.2f); - case E_ITEM_RAW_BEEF: - case E_ITEM_RAW_MEAT: - return FoodInfo(3, 1.8f); - case E_ITEM_STEAK: - case E_ITEM_COOKED_MEAT: - return FoodInfo(8, 12.8f); - case E_ITEM_RAW_FISH: - return FoodInfo(2, 1.2f); - case E_ITEM_COOKED_FISH: - return FoodInfo(5, 6.f); - case E_ITEM_RED_APPLE: - return FoodInfo(4, 2.4f); - case E_ITEM_GOLDEN_APPLE: - return FoodInfo(4, 9.6f); - case E_ITEM_ROTTEN_FLESH: - return FoodInfo(4, 0.8f, 80); - case E_ITEM_SPIDER_EYE: - return FoodInfo(2, 3.2f, 100); - } - return FoodInfo(0, 0.f); - } - -}; \ No newline at end of file diff --git a/source/items/ItemHandler.cpp b/source/items/ItemHandler.cpp deleted file mode 100644 index 63d4f4258..000000000 --- a/source/items/ItemHandler.cpp +++ /dev/null @@ -1,422 +0,0 @@ - -#include "Globals.h" -#include "ItemHandler.h" -#include "../Item.h" -#include "../World.h" -#include "../Player.h" - -//Handler -#include "ItemCloth.h" -#include "ItemHoe.h" -#include "ItemSlab.h" -#include "ItemWood.h" -#include "ItemShears.h" -#include "ItemLeaves.h" -#include "ItemSapling.h" -#include "ItemBucket.h" -#include "ItemLighter.h" -#include "ItemRedstoneDust.h" -#include "ItemRedstoneRepeater.h" -#include "ItemSeeds.h" -#include "ItemDye.h" -#include "ItemSugarcane.h" -#include "ItemPickaxe.h" -#include "ItemShovel.h" -#include "ItemSword.h" -#include "ItemDoor.h" -#include "ItemFood.h" -#include "ItemSign.h" -#include "ItemBed.h" - -#include "../blocks/BlockHandler.h" - - - - - -bool cItemHandler::m_HandlerInitialized = false; -cItemHandler * cItemHandler::m_ItemHandler[2266]; - - - - - -cItemHandler *cItemHandler::GetItemHandler(int a_ItemID) -{ - if(a_ItemID < 0) a_ItemID = 0; - - if(!m_HandlerInitialized) - { //We have to initialize - memset(m_ItemHandler, 0, sizeof(m_ItemHandler)); - m_HandlerInitialized = true; - } - if(m_ItemHandler[a_ItemID]) - return m_ItemHandler[a_ItemID]; - m_ItemHandler[a_ItemID] = CreateItemHandler(a_ItemID); - return m_ItemHandler[a_ItemID]; -} - - - - - -cItemHandler *cItemHandler::CreateItemHandler(int a_ItemID) -{ - switch(a_ItemID) - { - default: return new cItemHandler(a_ItemID); - - // Single item per handler: - case E_ITEM_SHEARS: return new cItemShearsHandler(a_ItemID); - case E_ITEM_LEAVES: return new cItemLeavesHandler(a_ItemID); - case E_ITEM_SAPLING: return new cItemSaplingHandler(a_ItemID); - case E_ITEM_DYE: return new cItemDyeHandler(a_ItemID); - case E_ITEM_SUGARCANE: return new cItemSugarcaneHandler(a_ItemID); - case E_ITEM_FLINT_AND_STEEL: return new cItemLighterHandler(a_ItemID); - case E_ITEM_REDSTONE_DUST: return new cItemRedstoneDustHandler(a_ItemID); - case E_ITEM_REDSTONE_REPEATER: return new cItemRedstoneRepeaterHandler(a_ItemID); - case E_ITEM_WOOL: return new cItemClothHandler(a_ItemID); - - case E_ITEM_WOODEN_HOE: - case E_ITEM_STONE_HOE: - case E_ITEM_IRON_HOE: - case E_ITEM_GOLD_HOE: - case E_ITEM_DIAMOND_HOE: - { - return new cItemHoeHandler(a_ItemID); - } - - case E_ITEM_WOODEN_PICKAXE: - case E_ITEM_STONE_PICKAXE: - case E_ITEM_IRON_PICKAXE: - case E_ITEM_GOLD_PICKAXE: - case E_ITEM_DIAMOND_PICKAXE: - { - return new cItemPickaxeHandler(a_ItemID); - } - - case E_ITEM_WOODEN_SHOVEL: - case E_ITEM_STONE_SHOVEL: - case E_ITEM_IRON_SHOVEL: - case E_ITEM_GOLD_SHOVEL: - case E_ITEM_DIAMOND_SHOVEL: - { - return new cItemShovelHandler(a_ItemID); - } - - case E_ITEM_WOODEN_SWORD: - case E_ITEM_STONE_SWORD: - case E_ITEM_IRON_SWORD: - case E_ITEM_GOLD_SWORD: - case E_ITEM_DIAMOND_SWORD: - { - return new cItemSwordHandler(a_ItemID); - } - - case E_ITEM_STONE_SLAB: - case E_ITEM_WOODEN_SLAB: - { - return new cItemSlabHandler(a_ItemID); - } - - case E_ITEM_LOG: - case E_ITEM_PLANKS: - { - return new cItemWoodHandler(a_ItemID); - } - - case E_ITEM_BUCKET: - case E_ITEM_WATER_BUCKET: - case E_ITEM_LAVA_BUCKET: - { - return new cItemBucketHandler(a_ItemID); - } - - case E_ITEM_PUMPKIN_SEEDS: - case E_ITEM_MELON_SEEDS: - case E_ITEM_SEEDS: - { - return new cItemSeedsHandler(a_ItemID); - } - - case E_ITEM_IRON_DOOR: - case E_ITEM_WOODEN_DOOR: - { - return new cItemDoorHandler(a_ItemID); - } - - // Food: - case E_ITEM_BREAD: - case E_ITEM_COOKIE: - case E_ITEM_MELON_SLICE: - case E_ITEM_RAW_CHICKEN: - case E_ITEM_COOKED_CHICKEN: - case E_ITEM_RAW_BEEF: - case E_ITEM_RAW_MEAT: - case E_ITEM_STEAK: - case E_ITEM_COOKED_MEAT: - case E_ITEM_RAW_FISH: - case E_ITEM_COOKED_FISH: - case E_ITEM_RED_APPLE: - case E_ITEM_GOLDEN_APPLE: - case E_ITEM_ROTTEN_FLESH: - case E_ITEM_SPIDER_EYE: - { - return new cItemFoodHandler(a_ItemID); - } - - case E_ITEM_SIGN: - return new cItemSignHandler(a_ItemID); - - case E_ITEM_BED: - return new cItemBedHandler(a_ItemID); - } -} - - - - - -void cItemHandler::Deinit() -{ - for(int i = 0; i < 2266; i++) - { - delete m_ItemHandler[i]; - } - m_HandlerInitialized = false; -} - - - - - -cItemHandler::cItemHandler(int a_ItemID) -{ - m_ItemID = a_ItemID; -} - - - - - -bool cItemHandler::OnItemUse(cWorld *a_World, cPlayer *a_Player, cItem *a_Item, int a_X, int a_Y, int a_Z, char a_Dir) -{ - return false; -} - - - - - -bool cItemHandler::OnDiggingBlock(cWorld *a_World, cPlayer *a_Player, cItem *a_Item, int a_X, int a_Y, int a_Z, char a_Dir) -{ - return false; -} - - - - - -void cItemHandler::OnBlockDestroyed(cWorld *a_World, cPlayer *a_Player, cItem *a_Item, int a_X, int a_Y, int a_Z) -{ - char Block = a_World->GetBlock(a_X, a_Y, a_Z); - cBlockHandler *Handler = cBlockHandler::GetBlockHandler(Block); - - if(a_Player->GetGameMode() == eGameMode_Survival) - { - if(!BlockRequiresSpecialTool(Block) || CanHarvestBlock(Block)) - { - Handler->DropBlock(a_World, a_X, a_Y, a_Z); - } - } - - a_Player->UseEquippedItem(); -} - - - - - -void cItemHandler::OnFoodEaten(cWorld *a_World, cPlayer *a_Player, cItem *a_Item) -{ - -} - - - - - -char cItemHandler::GetMaxStackSize(void) -{ - if (m_ItemID < 256) - { - // All blocks can stack up to 64 - return 64; - } - - switch (m_ItemID) - { - case E_ITEM_APPLE: return 64; - case E_ITEM_ARROW: return 64; - case E_ITEM_BLAZE_POWDER: return 64; - case E_ITEM_BLAZE_ROD: return 64; - case E_ITEM_BONE: return 64; - case E_ITEM_BOOK: return 64; - case E_ITEM_BOWL: return 64; - case E_ITEM_BREAD: return 64; - case E_ITEM_BROWN_MUSHROOM: return 64; - case E_ITEM_BUCKET: return 1; // TODO: change this to 16 when turning compatibility to 1.3 - case E_ITEM_COAL: return 64; - case E_ITEM_COOKED_CHICKEN: return 64; - case E_ITEM_COOKED_FISH: return 64; - case E_ITEM_COOKED_PORKCHOP: return 64; - case E_ITEM_DIAMOND: return 64; - case E_ITEM_FEATHER: return 64; - case E_ITEM_FLINT: return 64; - case E_ITEM_GOLD: return 64; - case E_ITEM_GUNPOWDER: return 64; - case E_ITEM_IRON: return 64; - case E_ITEM_RAW_PORKCHOP: return 64; - case E_ITEM_SEEDS: return 64; - case E_ITEM_STICK: return 64; - case E_ITEM_STRING: return 64; - case E_ITEM_WHEAT: return 64; - } - // By default items don't stack: - return 1; -} - - - - - -bool cItemHandler::IsTool() -{ - return - (m_ItemID >= 256 && m_ItemID <= 259) - || (m_ItemID == 261) - || (m_ItemID >= 267 && m_ItemID <= 279) - || (m_ItemID >= 283 && m_ItemID <= 286) - || (m_ItemID >= 290 && m_ItemID <= 294) - || (m_ItemID >= 256 && m_ItemID <= 259) - || (m_ItemID == 325) - || (m_ItemID == 346); -} - - - - - -bool cItemHandler::IsFood() -{ - return - (m_ItemID == 260) - || (m_ItemID == 282) - || (m_ItemID == 297) - || (m_ItemID >= 319 && m_ItemID <= 320) - || (m_ItemID == 335) - || (m_ItemID >= 349 && m_ItemID <= 350) - || (m_ItemID == 357) - || (m_ItemID == 360) - || (m_ItemID >= 363 && m_ItemID <= 366); -} - - - - - -bool cItemHandler::IsPlaceable() -{ - return m_ItemID >= 1 && m_ItemID <= 136; -} - - - - - -bool cItemHandler::CanHarvestBlock(BLOCKTYPE a_BlockID) -{ - return false; -} - - - - - -BLOCKTYPE cItemHandler::GetBlockType() -{ - ASSERT(m_ItemID < 256); // Items with IDs above 255 should all be handled by specific handlers - - #ifdef _DEBUG - if (m_ItemID > 256) - { - LOGERROR("Item %d has no valid block!", m_ItemID); - } - #endif // _DEBUG - - return (BLOCKTYPE) m_ItemID; -} - - - - - -NIBBLETYPE cItemHandler::GetBlockMeta(short a_ItemDamage) -{ - return (NIBBLETYPE)a_ItemDamage & 0x0f; // This keeps most textures. The few other items have to override this -} - - - - - -void cItemHandler::PlaceBlock(cWorld *a_World, cPlayer *a_Player, cItem *a_Item, int a_X, int a_Y, int a_Z, char a_Dir) -{ - BLOCKTYPE Block = GetBlockType(); - cBlockHandler *Handler = cBlockHandler::GetBlockHandler(Block); - Handler->PlaceBlock(a_World, a_Player, GetBlockMeta(a_Item->m_ItemHealth), a_X, a_Y, a_Z, a_Dir); - if(a_Player->GetGameMode() == eGameMode_Survival) - { - cItem Item(a_Item->m_ItemID, 1); - a_Player->GetInventory().RemoveItem(Item); - } -} - - - - - -bool cItemHandler::EatItem(cPlayer *a_Player, cItem *a_Item) -{ - FoodInfo Info = GetFoodInfo(); - - if(Info.FoodLevel > 0 || Info.Saturation > 0.f) - { - bool Success = a_Player->Feed(Info.FoodLevel, Info.Saturation); - if(Success && Info.PoisionChance > 0) - { - MTRand r1; - if((r1.randInt(100) - Info.PoisionChance) <= 0) - { //Unlucky guy :D - //TODO: Make player ill - } - } - - return Success; - } - - return false; -} - - - - - -cItemHandler::FoodInfo cItemHandler::GetFoodInfo() -{ - return FoodInfo(0, 0.f); -} - - - - diff --git a/source/items/ItemHandler.h b/source/items/ItemHandler.h deleted file mode 100644 index 67935ecb4..000000000 --- a/source/items/ItemHandler.h +++ /dev/null @@ -1,83 +0,0 @@ - -#pragma once -#include "../Defines.h" - - - - - -// fwd: -class cWorld; -class cPlayer; - - - - - -class cItemHandler -{ -public: - cItemHandler(int a_ItemID); - // Called when the player tries to use the item. Return false to make the item unusable. DEFAULT: False - virtual bool OnItemUse(cWorld *a_World, cPlayer *a_Player, cItem *a_Item, int a_X, int a_Y, int a_Z, char a_Dir); //eg for fishing or hoes - // Called while the player diggs a block using this item - virtual bool OnDiggingBlock(cWorld * a_World, cPlayer * a_Player, cItem * a_HeldItem, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace); - // Called when the player destroys a block using this item. This also calls the drop function for the destroyed block - virtual void OnBlockDestroyed(cWorld *a_World, cPlayer *a_Player, cItem *a_Item, int a_X, int a_Y, int a_Z); - // Called after the player has eaten this item. - virtual void OnFoodEaten(cWorld *a_World, cPlayer *a_Player, cItem *a_Item); - - /// Returns the maximum stack size for a given item - virtual char GetMaxStackSize(void); - - struct FoodInfo - { - FoodInfo(short a_FoodLevel, float a_Saturation, char a_PoisionChance = 0) - { - FoodLevel = a_FoodLevel; - Saturation = a_Saturation; - PoisionChance = a_PoisionChance; - } - short FoodLevel; - float Saturation; - char PoisionChance; //0 - 100 - }; - - // Returns the FoodInfo for this item. (FoodRecovery, Saturation and PoisionChance) - virtual FoodInfo GetFoodInfo(); - - // Lets the player eat a selected item. Returns true if the player ate the item - virtual bool EatItem(cPlayer *a_Player, cItem *a_Item); - - // Places the current block and removes the item from the player inventory - virtual void PlaceBlock(cWorld *a_World, cPlayer *a_Player, cItem *a_Item, int a_X, int a_Y, int a_Z, char a_Dir); - - // Indicates if this item is a tool - virtual bool IsTool(); - // Indicates if this item is food - virtual bool IsFood(); - //Blocks simply get placed - virtual bool IsPlaceable(); - - // Returns the block type on placement - virtual BLOCKTYPE GetBlockType(); - //Returns the block meta on placement - virtual NIBBLETYPE GetBlockMeta(short a_ItemDamage); - // Returns whether this tool/item can harvest a specific block (e.g. wooden pickaxe can harvest stone, but wood canīt) DEFAULT: False - virtual bool CanHarvestBlock(BLOCKTYPE a_BlockID); - - static cItemHandler *GetItemHandler(int a_ItemID); - - static void Deinit(); - - -protected: - int m_ItemID; - static cItemHandler *CreateItemHandler(int m_ItemID); - - static cItemHandler *m_ItemHandler[2266]; - static bool m_HandlerInitialized; //used to detect if the itemhandlers are initialized -}; - -//Short function -inline cItemHandler *ItemHandler(int a_ItemID) { return cItemHandler::GetItemHandler(a_ItemID); } \ No newline at end of file diff --git a/source/items/ItemHoe.h b/source/items/ItemHoe.h deleted file mode 100644 index e7ea9135c..000000000 --- a/source/items/ItemHoe.h +++ /dev/null @@ -1,31 +0,0 @@ - -#pragma once - -#include "ItemHandler.h" -#include "../World.h" -#include "../Player.h" - -class cItemHoeHandler : public cItemHandler -{ -public: - cItemHoeHandler(int a_ItemID) - : cItemHandler(a_ItemID) - { - - } - - virtual bool OnItemUse(cWorld *a_World, cPlayer *a_Player, cItem *a_Item, int a_X, int a_Y, int a_Z, char a_Dir) override - { - BLOCKTYPE Block = a_World->GetBlock(a_X, a_Y, a_Z); - - if(Block == E_BLOCK_DIRT || Block == E_BLOCK_GRASS) - { - a_World->FastSetBlock(a_X, a_Y, a_Z, E_BLOCK_FARMLAND, 0); - - a_Player->UseEquippedItem(); - return true; - - } - return false; - } -}; \ No newline at end of file diff --git a/source/items/ItemLeaves.h b/source/items/ItemLeaves.h deleted file mode 100644 index f96adb0b8..000000000 --- a/source/items/ItemLeaves.h +++ /dev/null @@ -1,27 +0,0 @@ - -#pragma once - -#include "ItemHandler.h" - - - - - -class cItemLeavesHandler : - public cItemHandler -{ -public: - cItemLeavesHandler(int a_ItemID) - : cItemHandler(a_ItemID) - { - } - - virtual NIBBLETYPE GetBlockMeta(short a_ItemDamage) override - { - return (NIBBLETYPE)(a_ItemDamage & 0x0f) | 0x4; //0x4 bit set means this is a player-placed leaves block, not to be decayed - } -} ; - - - - diff --git a/source/items/ItemLighter.h b/source/items/ItemLighter.h deleted file mode 100644 index 92279aafa..000000000 --- a/source/items/ItemLighter.h +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once - -#include "ItemHandler.h" -#include "../World.h" -#include "../Player.h" - -class cItemLighterHandler : public cItemHandler -{ -public: - cItemLighterHandler(int a_ItemID) - : cItemHandler(a_ItemID) - { - - } - - virtual bool OnItemUse(cWorld *a_World, cPlayer *a_Player, cItem *a_Item, int a_X, int a_Y, int a_Z, char a_Dir) override - { - a_Player->UseEquippedItem(); - - AddDirection(a_X, a_Y, a_Z, a_Dir); - - a_World->SetBlock(a_X, a_Y, a_Z, E_BLOCK_FIRE, 0); //0 -> new fire TODO: Make Firesimulator use this - - return false; - } - -}; \ No newline at end of file diff --git a/source/items/ItemPickaxe.h b/source/items/ItemPickaxe.h deleted file mode 100644 index 158aca44f..000000000 --- a/source/items/ItemPickaxe.h +++ /dev/null @@ -1,75 +0,0 @@ - -#pragma once - -#include "ItemHandler.h" -#include "../World.h" -#include "../Player.h" - -class cItemPickaxeHandler : public cItemHandler -{ -public: - cItemPickaxeHandler(int a_ItemID) - : cItemHandler(a_ItemID) - { - - } - - char PickaxeLevel() - { - switch(m_ItemID) - { - 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; - } - } - - virtual bool CanHarvestBlock(BLOCKTYPE a_BlockID) override - { - switch(a_BlockID) - { - case E_BLOCK_OBSIDIAN: - return PickaxeLevel() >= 4; - case E_BLOCK_DIAMOND_BLOCK: - case E_BLOCK_DIAMOND_ORE: - case E_BLOCK_GOLD_BLOCK: - case E_BLOCK_GOLD_ORE: - case E_BLOCK_REDSTONE_ORE: - case E_BLOCK_REDSTONE_ORE_GLOWING: - case E_BLOCK_EMERALD_ORE: - return PickaxeLevel() >= 3; - case E_BLOCK_IRON_BLOCK: - case E_BLOCK_IRON_ORE: - case E_BLOCK_LAPIS_ORE: - case E_BLOCK_LAPIS_BLOCK: - return PickaxeLevel() >= 2; - case E_BLOCK_COAL_ORE: - case E_BLOCK_STONE: - case E_BLOCK_COBBLESTONE: - case E_BLOCK_END_STONE: - case E_BLOCK_MOSSY_COBBLESTONE: - case E_BLOCK_SANDSTONE_STAIRS: - case E_BLOCK_SANDSTONE: - case E_BLOCK_STONE_BRICKS: - case E_BLOCK_NETHER_BRICK: - case E_BLOCK_NETHERRACK: - case E_BLOCK_STONE_SLAB: - case E_BLOCK_DOUBLE_STONE_SLAB: - case E_BLOCK_STONE_PRESSURE_PLATE: - case E_BLOCK_BRICK: - case E_BLOCK_COBBLESTONE_STAIRS: - case E_BLOCK_STONE_BRICK_STAIRS: - case E_BLOCK_NETHER_BRICK_STAIRS: - return PickaxeLevel() >= 1; - } - return false; - } -}; \ No newline at end of file diff --git a/source/items/ItemRedstoneDust.h b/source/items/ItemRedstoneDust.h deleted file mode 100644 index 1ce316d9e..000000000 --- a/source/items/ItemRedstoneDust.h +++ /dev/null @@ -1,36 +0,0 @@ - -#pragma once - -#include "ItemHandler.h" - - - - - -class cItemRedstoneDustHandler : public cItemHandler -{ -public: - cItemRedstoneDustHandler(int a_ItemID) - : cItemHandler(a_ItemID) - { - } - - virtual bool IsPlaceable() override - { - return true; - } - - virtual BLOCKTYPE GetBlockType() override - { - return E_BLOCK_REDSTONE_WIRE; - } - - virtual NIBBLETYPE GetBlockMeta(short a_ItemDamage) override - { - return 0; - } -} ; - - - - diff --git a/source/items/ItemRedstoneRepeater.h b/source/items/ItemRedstoneRepeater.h deleted file mode 100644 index c31c2af53..000000000 --- a/source/items/ItemRedstoneRepeater.h +++ /dev/null @@ -1,36 +0,0 @@ - -#pragma once - -#include "ItemHandler.h" - - - - - -class cItemRedstoneRepeaterHandler : public cItemHandler -{ -public: - cItemRedstoneRepeaterHandler(int a_ItemID) - : cItemHandler(a_ItemID) - { - } - - virtual bool IsPlaceable() override - { - return true; - } - - virtual BLOCKTYPE GetBlockType() override - { - return ::E_BLOCK_REDSTONE_REPEATER_OFF; - } - - virtual NIBBLETYPE GetBlockMeta(short a_ItemMeta) override - { - return 0; - } -} ; - - - - diff --git a/source/items/ItemSapling.h b/source/items/ItemSapling.h deleted file mode 100644 index b0c223f29..000000000 --- a/source/items/ItemSapling.h +++ /dev/null @@ -1,28 +0,0 @@ - -#pragma once - -#include "ItemHandler.h" - - - - - -class cItemSaplingHandler : public cItemHandler -{ -public: - cItemSaplingHandler(int a_ItemID) - : cItemHandler(a_ItemID) - { - - } - - virtual NIBBLETYPE GetBlockMeta(short a_ItemDamage) override - { - // Only the lowest 3 bits are important - return (NIBBLETYPE)(a_ItemDamage & 0x07); - } -} ; - - - - diff --git a/source/items/ItemSeeds.h b/source/items/ItemSeeds.h deleted file mode 100644 index 3eb9d6e86..000000000 --- a/source/items/ItemSeeds.h +++ /dev/null @@ -1,59 +0,0 @@ - -#pragma once - -#include "ItemHandler.h" -#include "../World.h" - - - - - -class cItemSeedsHandler : - public cItemHandler -{ -public: - cItemSeedsHandler(int a_ItemID) - : cItemHandler(a_ItemID) - { - - } - - virtual bool IsPlaceable() override - { - return true; - } - - virtual BLOCKTYPE GetBlockType() override - { - switch(m_ItemID) - { - case E_ITEM_SEEDS: return E_BLOCK_CROPS; - case E_ITEM_MELON_SEEDS: return E_BLOCK_MELON_STEM; - case E_ITEM_PUMPKIN_SEEDS: return E_BLOCK_PUMPKIN_STEM; - default: return E_BLOCK_AIR; - } - } - - virtual NIBBLETYPE GetBlockMeta(short a_ItemDamage) override - { - return 0; //Not grown yet - } - - virtual void PlaceBlock(cWorld *a_World, cPlayer *a_Player, cItem *a_Item, int a_X, int a_Y, int a_Z, char a_Dir) override - { - int X = a_X, - Y = a_Y, - Z = a_Z; - - AddDirection(X, Y, Z, a_Dir, true); - - if(a_World->GetBlock(X, Y, Z) != E_BLOCK_FARMLAND) - return; - - return cItemHandler::PlaceBlock(a_World, a_Player, a_Item, a_X, a_Y, a_Z, a_Dir); - } -} ; - - - - diff --git a/source/items/ItemShears.h b/source/items/ItemShears.h deleted file mode 100644 index 2f3476735..000000000 --- a/source/items/ItemShears.h +++ /dev/null @@ -1,42 +0,0 @@ - -#pragma once - -#include "ItemHandler.h" -#include "../World.h" -#include "../Player.h" - -class cItemShearsHandler : public cItemHandler -{ -public: - cItemShearsHandler(int a_ItemID) - : cItemHandler(a_ItemID) - { - - } - virtual bool IsTool() override - { - return true; - } - virtual bool OnDiggingBlock(cWorld *a_World, cPlayer *a_Player, cItem *a_Item, int a_X, int a_Y, int a_Z, char a_Dir) override - { - BLOCKTYPE Block = a_World->GetBlock(a_X, a_Y, a_Z); - if(Block == E_BLOCK_LEAVES) - { - cItems Drops; - Drops.push_back(cItem(E_ITEM_LEAVES, 1, a_World->GetBlockMeta(a_X, a_Y, a_Z))); - a_World->SpawnItemPickups(Drops, a_X, a_Y, a_Z); - - a_World->SetBlock(a_X, a_Y, a_Z, E_BLOCK_AIR, 0); - a_Player->UseEquippedItem(); - return true; - } - return false; - } - - - virtual bool CanHarvestBlock(BLOCKTYPE a_BlockID) override - { - return a_BlockID == E_BLOCK_COBWEB - || a_BlockID == E_BLOCK_VINES; - } -}; \ No newline at end of file diff --git a/source/items/ItemShovel.h b/source/items/ItemShovel.h deleted file mode 100644 index 24928efb8..000000000 --- a/source/items/ItemShovel.h +++ /dev/null @@ -1,41 +0,0 @@ - -#pragma once - -#include "ItemHandler.h" -#include "../World.h" -#include "../Player.h" - -#include "../blocks/BlockHandler.h" - - - - - -class cItemShovelHandler : public cItemHandler -{ -public: - cItemShovelHandler(int a_ItemID) - : cItemHandler(a_ItemID) - { - - } - - virtual bool OnDiggingBlock(cWorld *a_World, cPlayer *a_Player, cItem *a_Item, int a_X, int a_Y, int a_Z, char a_Dir) override - { - BLOCKTYPE Block = a_World->GetBlock(a_X, a_Y, a_Z); - if(Block == E_BLOCK_SNOW) - { - BlockHandler(Block)->DropBlock(a_World, a_X, a_Y, a_Z); - - a_World->SetBlock(a_X, a_Y, a_Z, E_BLOCK_AIR, 0); - a_Player->UseEquippedItem(); - return true; - } - return false; - } - - virtual bool CanHarvestBlock(BLOCKTYPE a_BlockID) override - { - return a_BlockID == E_BLOCK_SNOW; - } -}; \ No newline at end of file diff --git a/source/items/ItemSign.h b/source/items/ItemSign.h deleted file mode 100644 index a0c6aaa9c..000000000 --- a/source/items/ItemSign.h +++ /dev/null @@ -1,26 +0,0 @@ - -#pragma once - -#include "ItemHandler.h" -#include "../World.h" - -class cItemSignHandler : public cItemHandler -{ -public: - cItemSignHandler(int a_ItemID) - : cItemHandler(a_ItemID) - { - - } - - virtual bool IsPlaceable() override - { - return true; - } - - virtual BLOCKTYPE GetBlockType() override - { - return E_BLOCK_SIGN_POST; - } - -}; \ No newline at end of file diff --git a/source/items/ItemSlab.h b/source/items/ItemSlab.h deleted file mode 100644 index 0bab038a2..000000000 --- a/source/items/ItemSlab.h +++ /dev/null @@ -1,45 +0,0 @@ - -#pragma once - -#include "ItemHandler.h" -#include "../World.h" - - - - - -class cItemSlabHandler : public cItemHandler -{ -public: - cItemSlabHandler(int a_ItemID) - : cItemHandler(a_ItemID) - { - - } - - virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, cItem * a_Item, int a_X, int a_Y, int a_Z, char a_Dir) override - { - BLOCKTYPE Block; - NIBBLETYPE Meta; - a_World->GetBlockTypeMeta(a_X, a_Y, a_Z, Block, Meta); - - if ( - (a_Dir == 0 || a_Dir == 1) // Only when clicking on top or on bottom of the block - && (Block == E_BLOCK_WOODEN_SLAB || Block == E_BLOCK_STONE_SLAB) // It is a slab - && (Block == a_Item->m_ItemID) // Same slab - && ((Meta & 0x7) == (a_Item->m_ItemHealth & 0x7))) // Same Texture - { - cItem Item(a_Item->m_ItemID, 1); - if (a_Player->GetInventory().RemoveItem(Item)) - { - a_World->SetBlock(a_X, a_Y, a_Z, Block - 1, Meta); //Block - 1 simple hack to save one if statement - return true; - } - } - return false; - } -} ; - - - - diff --git a/source/items/ItemSugarcane.h b/source/items/ItemSugarcane.h deleted file mode 100644 index 4fdf43428..000000000 --- a/source/items/ItemSugarcane.h +++ /dev/null @@ -1,39 +0,0 @@ - -#pragma once - -#include "ItemHandler.h" -#include "../World.h" - - - - - -class cItemSugarcaneHandler : - public cItemHandler -{ -public: - cItemSugarcaneHandler(int a_ItemID) - : cItemHandler(a_ItemID) - { - - } - - virtual bool IsPlaceable() override - { - return true; - } - - virtual BLOCKTYPE GetBlockType() override - { - return E_BLOCK_SUGARCANE; - } - - virtual NIBBLETYPE GetBlockMeta(short a_ItemDamage) override - { - return 0; //Not grown yet - } -} ; - - - - diff --git a/source/items/ItemSword.h b/source/items/ItemSword.h deleted file mode 100644 index eb4aa0ef9..000000000 --- a/source/items/ItemSword.h +++ /dev/null @@ -1,21 +0,0 @@ - -#pragma once - -#include "ItemHandler.h" -#include "../World.h" -#include "../Player.h" - -class cItemSwordHandler : public cItemHandler -{ -public: - cItemSwordHandler(int a_ItemID) - : cItemHandler(a_ItemID) - { - - } - - virtual bool CanHarvestBlock(BLOCKTYPE a_BlockID) override - { - return a_BlockID == E_BLOCK_COBWEB; - } -}; \ No newline at end of file diff --git a/source/items/ItemWood.h b/source/items/ItemWood.h deleted file mode 100644 index d6f66d1c5..000000000 --- a/source/items/ItemWood.h +++ /dev/null @@ -1,22 +0,0 @@ - -#pragma once - -#include "ItemHandler.h" - - - - - -class cItemWoodHandler : - public cItemHandler -{ -public: - cItemWoodHandler(int a_ItemID) - : cItemHandler(a_ItemID) - { - } -} ; - - - - -- cgit v1.2.3