From d8072da61f8a098ea30f579034ad976cf86408f3 Mon Sep 17 00:00:00 2001 From: Howaner Date: Wed, 28 May 2014 15:54:43 +0200 Subject: Fix skull bugs. --- src/Blocks/BlockMobHead.h | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) (limited to 'src/Blocks') diff --git a/src/Blocks/BlockMobHead.h b/src/Blocks/BlockMobHead.h index b7629b07c..248f20d49 100644 --- a/src/Blocks/BlockMobHead.h +++ b/src/Blocks/BlockMobHead.h @@ -19,7 +19,46 @@ public: virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override { - a_Pickups.push_back(cItem(E_ITEM_HEAD, 1, 0)); + // The drops spawns in OnDestroyed + } + + virtual void OnDestroyedByPlayer(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) override + { + if (a_Player->IsGameModeCreative()) + { + // No drops in creative mode + return; + } + + class cCallback : public cMobHeadCallback + { + virtual bool Item(cMobHeadEntity * a_MobHeadEntity) + { + cItems Pickups; + Pickups.Add(E_ITEM_HEAD, 1, (short) a_MobHeadEntity->GetType()); + MTRand r1; + + // Mid-block position first + double MicroX, MicroY, MicroZ; + MicroX = a_MobHeadEntity->GetPosX() + 0.5; + MicroY = a_MobHeadEntity->GetPosY() + 0.5; + MicroZ = a_MobHeadEntity->GetPosZ() + 0.5; + + // Add random offset second + MicroX += r1.rand(1) - 0.5; + MicroZ += r1.rand(1) - 0.5; + + a_MobHeadEntity->GetWorld()->SpawnItemPickups(Pickups, MicroX, MicroY, MicroZ); + return false; + } + + public: + cCallback() {} + }; + cCallback Callback; + + cWorld * World = (cWorld *) &a_WorldInterface; + World->DoWithMobHeadAt(a_BlockX, a_BlockY, a_BlockZ, Callback); } bool TrySpawnWither(cChunkInterface & a_ChunkInterface, cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ) @@ -170,7 +209,7 @@ public: a_MobHeadEntity->SetType(static_cast(m_OldBlockMeta)); a_MobHeadEntity->SetRotation(static_cast(Rotation)); - a_MobHeadEntity->GetWorld()->BroadcastBlockEntity(a_MobHeadEntity->GetPosX(), a_MobHeadEntity->GetPosY(), a_MobHeadEntity->GetPosZ(), m_Player->GetClientHandle()); + a_MobHeadEntity->GetWorld()->BroadcastBlockEntity(a_MobHeadEntity->GetPosX(), a_MobHeadEntity->GetPosY(), a_MobHeadEntity->GetPosZ()); return false; } -- cgit v1.2.3 From 421588d25dd4e2e293d48daece27444bfbc318bf Mon Sep 17 00:00:00 2001 From: Howaner Date: Wed, 28 May 2014 16:59:51 +0200 Subject: Fix fire break. --- src/Blocks/BlockFire.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/Blocks') diff --git a/src/Blocks/BlockFire.h b/src/Blocks/BlockFire.h index f9f32eb50..147e4b53e 100644 --- a/src/Blocks/BlockFire.h +++ b/src/Blocks/BlockFire.h @@ -36,8 +36,8 @@ public: - Loop through boundary variables, and fill with portal blocks based on Dir with meta from Dir */ - a_BlockY--; // Because we want the block below the fire - FindAndSetPortalFrame(a_BlockX, a_BlockY, a_BlockZ, a_ChunkInterface, a_WorldInterface); + // a_BlockY - 1: Because we want the block below the fire + FindAndSetPortalFrame(a_BlockX, a_BlockY - 1, a_BlockZ, a_ChunkInterface, a_WorldInterface); } virtual void OnDigging(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) override -- cgit v1.2.3 From 9f645b2c75aa8dbfbab439e4afdf17a321072a88 Mon Sep 17 00:00:00 2001 From: Howaner Date: Wed, 28 May 2014 17:05:13 +0200 Subject: Fix hay place sound. --- src/Blocks/BlockHandler.cpp | 3 ++- src/Blocks/BlockHayBale.h | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 src/Blocks/BlockHayBale.h (limited to 'src/Blocks') diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp index 304e35e84..bae396ea8 100644 --- a/src/Blocks/BlockHandler.cpp +++ b/src/Blocks/BlockHandler.cpp @@ -38,6 +38,7 @@ #include "BlockGlass.h" #include "BlockGlowstone.h" #include "BlockGravel.h" +#include "BlockHayBale.h" #include "BlockMobHead.h" #include "BlockHopper.h" #include "BlockIce.h" @@ -132,7 +133,7 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType) case E_BLOCK_GLASS: return new cBlockGlassHandler (a_BlockType); case E_BLOCK_GRASS: return new cBlockDirtHandler (a_BlockType); case E_BLOCK_GRAVEL: return new cBlockGravelHandler (a_BlockType); - case E_BLOCK_HAY_BALE: return new cBlockSidewaysHandler (a_BlockType); + case E_BLOCK_HAY_BALE: return new cBlockHayBaleHandler (a_BlockType); case E_BLOCK_HEAD: return new cBlockMobHeadHandler (a_BlockType); case E_BLOCK_HOPPER: return new cBlockHopperHandler (a_BlockType); case E_BLOCK_ICE: return new cBlockIceHandler (a_BlockType); diff --git a/src/Blocks/BlockHayBale.h b/src/Blocks/BlockHayBale.h new file mode 100644 index 000000000..5b646e264 --- /dev/null +++ b/src/Blocks/BlockHayBale.h @@ -0,0 +1,29 @@ + +#pragma once + +#include "BlockHandler.h" +#include "BlockSideways.h" + + + + + +class cBlockHayBaleHandler : + public cBlockSidewaysHandler +{ +public: + cBlockHayBaleHandler(BLOCKTYPE a_BlockType) + : cBlockSidewaysHandler(a_BlockType) + { + } + + + virtual const char * GetStepSound(void) override + { + return "step.grass"; + } +} ; + + + + -- cgit v1.2.3 From 142fa83124fc3b766916ac79fb037fea91a19a1e Mon Sep 17 00:00:00 2001 From: Howaner Date: Wed, 28 May 2014 19:32:20 +0200 Subject: Code improvements --- src/Blocks/BlockMobHead.h | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'src/Blocks') diff --git a/src/Blocks/BlockMobHead.h b/src/Blocks/BlockMobHead.h index 248f20d49..fe4099835 100644 --- a/src/Blocks/BlockMobHead.h +++ b/src/Blocks/BlockMobHead.h @@ -19,7 +19,7 @@ public: virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override { - // The drops spawns in OnDestroyed + // The drop spawn is in OnDestroyed method } virtual void OnDestroyedByPlayer(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) override @@ -51,11 +51,7 @@ public: a_MobHeadEntity->GetWorld()->SpawnItemPickups(Pickups, MicroX, MicroY, MicroZ); return false; } - - public: - cCallback() {} - }; - cCallback Callback; + } Callback; cWorld * World = (cWorld *) &a_WorldInterface; World->DoWithMobHeadAt(a_BlockX, a_BlockY, a_BlockZ, Callback); -- cgit v1.2.3 From 84c83e0deb8c46be5bd4a25ef00515d48cf296a9 Mon Sep 17 00:00:00 2001 From: Tycho Date: Mon, 16 Jun 2014 15:03:07 +0100 Subject: Fix a few warnings --- src/Blocks/BlockDoor.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/Blocks') diff --git a/src/Blocks/BlockDoor.h b/src/Blocks/BlockDoor.h index bc59051c3..049c4a334 100644 --- a/src/Blocks/BlockDoor.h +++ b/src/Blocks/BlockDoor.h @@ -156,10 +156,10 @@ public: if (a_BlockX > 0) { NIBBLETYPE DownMeta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY - 1, a_BlockZ); - return (DownMeta & 0x07) | 0x08 | (Meta << 4); + return (NIBBLETYPE) ((DownMeta & 0x07) | 0x08 | (Meta << 4)); } // This is the top part of the door at the bottommost layer of the world, there's no bottom: - return 0x08 | (Meta << 4); + return (NIBBLETYPE) (0x08 | (Meta << 4)); } else { @@ -167,7 +167,7 @@ public: if (a_BlockY < cChunkDef::Height - 1) { NIBBLETYPE UpMeta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY + 1, a_BlockZ); - return Meta | (UpMeta << 4); + return (NIBBLETYPE) (Meta | (UpMeta << 4)); } // This is the bottom part of the door at the topmost layer of the world, there's no top: return Meta; -- cgit v1.2.3 From 7c4b8306aaf02e2aaa8acc70432f6f9636076f3e Mon Sep 17 00:00:00 2001 From: Howaner Date: Mon, 16 Jun 2014 23:05:29 +0200 Subject: Glass shouldn't drop. --- src/Blocks/BlockHandler.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/Blocks') diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp index 304e35e84..4440e39a9 100644 --- a/src/Blocks/BlockHandler.cpp +++ b/src/Blocks/BlockHandler.cpp @@ -130,6 +130,7 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType) case E_BLOCK_GLOWSTONE: return new cBlockGlowstoneHandler (a_BlockType); case E_BLOCK_GOLD_ORE: return new cBlockOreHandler (a_BlockType); case E_BLOCK_GLASS: return new cBlockGlassHandler (a_BlockType); + case E_BLOCK_GLASS_PANE: return new cBlockGlassHandler (a_BlockType); case E_BLOCK_GRASS: return new cBlockDirtHandler (a_BlockType); case E_BLOCK_GRAVEL: return new cBlockGravelHandler (a_BlockType); case E_BLOCK_HAY_BALE: return new cBlockSidewaysHandler (a_BlockType); @@ -186,6 +187,8 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType) case E_BLOCK_SIGN_POST: return new cBlockSignHandler (a_BlockType); case E_BLOCK_SNOW: return new cBlockSnowHandler (a_BlockType); case E_BLOCK_SPRUCE_WOOD_STAIRS: return new cBlockStairsHandler (a_BlockType); + case E_BLOCK_STAINED_GLASS: return new cBlockGlassHandler (a_BlockType); + case E_BLOCK_STAINED_GLASS_PANE: return new cBlockGlassHandler (a_BlockType); case E_BLOCK_STATIONARY_LAVA: return new cBlockLavaHandler (a_BlockType); case E_BLOCK_STATIONARY_WATER: return new cBlockFluidHandler (a_BlockType); case E_BLOCK_STICKY_PISTON: return new cBlockPistonHandler (a_BlockType); -- cgit v1.2.3 From 9dea609194e27d282480ca56be99f0becec8d899 Mon Sep 17 00:00:00 2001 From: Howaner Date: Mon, 16 Jun 2014 23:35:30 +0200 Subject: Fix doubleslab meta. --- src/Blocks/BlockSlab.h | 1 + 1 file changed, 1 insertion(+) (limited to 'src/Blocks') diff --git a/src/Blocks/BlockSlab.h b/src/Blocks/BlockSlab.h index 80841b094..f3f2366fd 100644 --- a/src/Blocks/BlockSlab.h +++ b/src/Blocks/BlockSlab.h @@ -80,6 +80,7 @@ public: if (IsAnySlabType(a_ChunkInterface.GetBlock(a_BlockX, a_BlockY, a_BlockZ))) { a_BlockType = GetDoubleSlabType(m_BlockType); + a_BlockMeta = a_BlockMeta & 0x7; } return true; -- cgit v1.2.3 From 43ff96f66494dd1719d7bdb1d0f0c3957e5f61b7 Mon Sep 17 00:00:00 2001 From: Howaner Date: Tue, 17 Jun 2014 00:40:35 +0200 Subject: Add pressure plate handler --- src/Blocks/BlockHandler.cpp | 5 +++++ src/Blocks/BlockPressurePlate.h | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 src/Blocks/BlockPressurePlate.h (limited to 'src/Blocks') diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp index 304e35e84..521de5684 100644 --- a/src/Blocks/BlockHandler.cpp +++ b/src/Blocks/BlockHandler.cpp @@ -56,6 +56,7 @@ #include "BlockPlanks.h" #include "BlockPortal.h" #include "BlockPumpkin.h" +#include "BlockPressurePlate.h" #include "BlockQuartz.h" #include "BlockRail.h" #include "BlockRedstone.h" @@ -134,6 +135,7 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType) case E_BLOCK_GRAVEL: return new cBlockGravelHandler (a_BlockType); case E_BLOCK_HAY_BALE: return new cBlockSidewaysHandler (a_BlockType); case E_BLOCK_HEAD: return new cBlockMobHeadHandler (a_BlockType); + case E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE: return new cBlockPressurePlateHandler(a_BlockType); case E_BLOCK_HOPPER: return new cBlockHopperHandler (a_BlockType); case E_BLOCK_ICE: return new cBlockIceHandler (a_BlockType); case E_BLOCK_INACTIVE_COMPARATOR: return new cBlockComparatorHandler (a_BlockType); @@ -149,6 +151,7 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType) case E_BLOCK_LEAVES: return new cBlockLeavesHandler (a_BlockType); case E_BLOCK_LILY_PAD: return new cBlockLilypadHandler (a_BlockType); case E_BLOCK_LIT_FURNACE: return new cBlockFurnaceHandler (a_BlockType); + case E_BLOCK_LIGHT_WEIGHTED_PRESSURE_PLATE: return new cBlockPressurePlateHandler(a_BlockType); case E_BLOCK_LOG: return new cBlockSidewaysHandler (a_BlockType); case E_BLOCK_MELON: return new cBlockMelonHandler (a_BlockType); case E_BLOCK_MELON_STEM: return new cBlockStemsHandler (a_BlockType); @@ -192,6 +195,7 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType) case E_BLOCK_STONE: return new cBlockStoneHandler (a_BlockType); case E_BLOCK_STONE_BRICK_STAIRS: return new cBlockStairsHandler (a_BlockType); case E_BLOCK_STONE_BUTTON: return new cBlockButtonHandler (a_BlockType); + case E_BLOCK_STONE_PRESSURE_PLATE: return new cBlockPressurePlateHandler (a_BlockType); case E_BLOCK_STONE_SLAB: return new cBlockSlabHandler (a_BlockType); case E_BLOCK_SUGARCANE: return new cBlockSugarcaneHandler (a_BlockType); case E_BLOCK_TALL_GRASS: return new cBlockTallGrassHandler (a_BlockType); @@ -203,6 +207,7 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType) case E_BLOCK_WATER: return new cBlockFluidHandler (a_BlockType); case E_BLOCK_WOODEN_BUTTON: return new cBlockButtonHandler (a_BlockType); case E_BLOCK_WOODEN_DOOR: return new cBlockDoorHandler (a_BlockType); + case E_BLOCK_WOODEN_PRESSURE_PLATE: return new cBlockPressurePlateHandler (a_BlockType); case E_BLOCK_WOODEN_SLAB: return new cBlockSlabHandler (a_BlockType); case E_BLOCK_WOODEN_STAIRS: return new cBlockStairsHandler (a_BlockType); case E_BLOCK_WOOL: return new cBlockClothHandler (a_BlockType); diff --git a/src/Blocks/BlockPressurePlate.h b/src/Blocks/BlockPressurePlate.h new file mode 100644 index 000000000..2e6754cdb --- /dev/null +++ b/src/Blocks/BlockPressurePlate.h @@ -0,0 +1,34 @@ + +#pragma once + +#include "BlockHandler.h" + + + + +class cBlockPressurePlateHandler : + public cBlockHandler +{ +public: + cBlockPressurePlateHandler(BLOCKTYPE a_BlockType) + : cBlockHandler(a_BlockType) + { + } + + virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override + { + // Reset meta to 0 + a_Pickups.push_back(cItem(m_BlockType, 1, 0)); + } + + virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override + { + if (a_RelY <= 0) + { + return false; + } + BLOCKTYPE BlockBelow = a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ); + + return (BlockBelow == E_BLOCK_FENCE_GATE || BlockBelow == E_BLOCK_FENCE || cBlockInfo::IsSolid(BlockBelow)); + } +}; \ No newline at end of file -- cgit v1.2.3 From 1316d2d24d2760f191a873e35959aee209b70f87 Mon Sep 17 00:00:00 2001 From: Howaner Date: Tue, 17 Jun 2014 00:41:31 +0200 Subject: Add end lines to BlockPressurePlate.h --- src/Blocks/BlockPressurePlate.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/Blocks') diff --git a/src/Blocks/BlockPressurePlate.h b/src/Blocks/BlockPressurePlate.h index 2e6754cdb..01d5e8174 100644 --- a/src/Blocks/BlockPressurePlate.h +++ b/src/Blocks/BlockPressurePlate.h @@ -31,4 +31,8 @@ public: return (BlockBelow == E_BLOCK_FENCE_GATE || BlockBelow == E_BLOCK_FENCE || cBlockInfo::IsSolid(BlockBelow)); } -}; \ No newline at end of file +} ; + + + + -- cgit v1.2.3 From a89524d5330ffbdbaea1d38421dabe8d8f62999e Mon Sep 17 00:00:00 2001 From: Howaner Date: Tue, 17 Jun 2014 01:15:38 +0200 Subject: Add DoWithBlockEntityAt() to WorldInterface.h --- src/Blocks/BlockMobHead.h | 89 ++++++++++++++++++++++++++------------------- src/Blocks/WorldInterface.h | 9 +++++ 2 files changed, 61 insertions(+), 37 deletions(-) (limited to 'src/Blocks') diff --git a/src/Blocks/BlockMobHead.h b/src/Blocks/BlockMobHead.h index fe4099835..34a92c150 100644 --- a/src/Blocks/BlockMobHead.h +++ b/src/Blocks/BlockMobHead.h @@ -30,48 +30,58 @@ public: return; } - class cCallback : public cMobHeadCallback + class cCallback : public cBlockEntityCallback { - virtual bool Item(cMobHeadEntity * a_MobHeadEntity) + virtual bool Item(cBlockEntity * a_BlockEntity) { + cMobHeadEntity * MobHeadEntity = static_cast(a_BlockEntity); + if (MobHeadEntity == NULL) + { + return false; + } + cItems Pickups; - Pickups.Add(E_ITEM_HEAD, 1, (short) a_MobHeadEntity->GetType()); + Pickups.Add(E_ITEM_HEAD, 1, (short) MobHeadEntity->GetType()); MTRand r1; // Mid-block position first double MicroX, MicroY, MicroZ; - MicroX = a_MobHeadEntity->GetPosX() + 0.5; - MicroY = a_MobHeadEntity->GetPosY() + 0.5; - MicroZ = a_MobHeadEntity->GetPosZ() + 0.5; + MicroX = MobHeadEntity->GetPosX() + 0.5; + MicroY = MobHeadEntity->GetPosY() + 0.5; + MicroZ = MobHeadEntity->GetPosZ() + 0.5; // Add random offset second MicroX += r1.rand(1) - 0.5; MicroZ += r1.rand(1) - 0.5; - a_MobHeadEntity->GetWorld()->SpawnItemPickups(Pickups, MicroX, MicroY, MicroZ); + MobHeadEntity->GetWorld()->SpawnItemPickups(Pickups, MicroX, MicroY, MicroZ); return false; } } Callback; - cWorld * World = (cWorld *) &a_WorldInterface; - World->DoWithMobHeadAt(a_BlockX, a_BlockY, a_BlockZ, Callback); + a_WorldInterface.DoWithBlockEntityAt(a_BlockX, a_BlockY, a_BlockZ, Callback); } - bool TrySpawnWither(cChunkInterface & a_ChunkInterface, cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ) + bool TrySpawnWither(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ) { if (a_BlockY < 2) { return false; } - class cCallback : public cMobHeadCallback + class cCallback : public cBlockEntityCallback { bool m_IsWither; - virtual bool Item (cMobHeadEntity * a_MobHeadEntity) + virtual bool Item (cBlockEntity * a_BlockEntity) { - m_IsWither = (a_MobHeadEntity->GetType() == SKULL_TYPE_WITHER); + cMobHeadEntity * MobHeadEntity = static_cast(a_BlockEntity); + if (MobHeadEntity == NULL) + { + return false; + } + m_IsWither = (MobHeadEntity->GetType() == SKULL_TYPE_WITHER); return false; } @@ -105,7 +115,7 @@ public: } PlayerCallback(Vector3f(a_BlockX, a_BlockY, a_BlockZ)); - a_World->DoWithMobHeadAt(a_BlockX, a_BlockY, a_BlockZ, CallbackA); + a_WorldInterface.DoWithBlockEntityAt(a_BlockX, a_BlockY, a_BlockZ, CallbackA); if (!CallbackA.IsWither()) { @@ -122,8 +132,8 @@ public: return false; } - a_World->DoWithMobHeadAt(a_BlockX - 1, a_BlockY, a_BlockZ, CallbackA); - a_World->DoWithMobHeadAt(a_BlockX + 1, a_BlockY, a_BlockZ, CallbackB); + a_WorldInterface.DoWithBlockEntityAt(a_BlockX - 1, a_BlockY, a_BlockZ, CallbackA); + a_WorldInterface.DoWithBlockEntityAt(a_BlockX + 1, a_BlockY, a_BlockZ, CallbackB); BLOCKTYPE Block1 = a_ChunkInterface.GetBlock(a_BlockX - 1, a_BlockY - 1, a_BlockZ); BLOCKTYPE Block2 = a_ChunkInterface.GetBlock(a_BlockX + 1, a_BlockY - 1, a_BlockZ); @@ -136,15 +146,15 @@ public: a_ChunkInterface.FastSetBlock(a_BlockX, a_BlockY - 2, a_BlockZ, E_BLOCK_AIR, 0); // Block entities - a_World->SetBlock(a_BlockX + 1, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0); - a_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0); - a_World->SetBlock(a_BlockX - 1, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0); + a_ChunkInterface.SetBlock(a_WorldInterface, a_BlockX + 1, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0); + a_ChunkInterface.SetBlock(a_WorldInterface, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0); + a_ChunkInterface.SetBlock(a_WorldInterface, a_BlockX - 1, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0); // Spawn the wither: - a_World->SpawnMob(a_BlockX + 0.5, a_BlockY - 2, a_BlockZ + 0.5, cMonster::mtWither); + a_WorldInterface.SpawnMob(a_BlockX + 0.5, a_BlockY - 2, a_BlockZ + 0.5, cMonster::mtWither); // Award Achievement - a_World->ForEachPlayer(PlayerCallback); + a_WorldInterface.ForEachPlayer(PlayerCallback); return true; } @@ -152,8 +162,8 @@ public: CallbackA.Reset(); CallbackB.Reset(); - a_World->DoWithMobHeadAt(a_BlockX, a_BlockY, a_BlockZ - 1, CallbackA); - a_World->DoWithMobHeadAt(a_BlockX, a_BlockY, a_BlockZ + 1, CallbackB); + a_WorldInterface.DoWithBlockEntityAt(a_BlockX, a_BlockY, a_BlockZ - 1, CallbackA); + a_WorldInterface.DoWithBlockEntityAt(a_BlockX, a_BlockY, a_BlockZ + 1, CallbackB); Block1 = a_ChunkInterface.GetBlock(a_BlockX, a_BlockY - 1, a_BlockZ - 1); Block2 = a_ChunkInterface.GetBlock(a_BlockX, a_BlockY - 1, a_BlockZ + 1); @@ -166,15 +176,15 @@ public: a_ChunkInterface.FastSetBlock(a_BlockX, a_BlockY - 2, a_BlockZ, E_BLOCK_AIR, 0); // Block entities - a_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ + 1, E_BLOCK_AIR, 0); - a_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0); - a_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ - 1, E_BLOCK_AIR, 0); + a_ChunkInterface.SetBlock(a_WorldInterface, a_BlockX, a_BlockY, a_BlockZ + 1, E_BLOCK_AIR, 0); + a_ChunkInterface.SetBlock(a_WorldInterface, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0); + a_ChunkInterface.SetBlock(a_WorldInterface, a_BlockX, a_BlockY, a_BlockZ - 1, E_BLOCK_AIR, 0); // Spawn the wither: - a_World->SpawnMob(a_BlockX + 0.5, a_BlockY - 2, a_BlockZ + 0.5, cMonster::mtWither); + a_WorldInterface.SpawnMob(a_BlockX + 0.5, a_BlockY - 2, a_BlockZ + 0.5, cMonster::mtWither); // Award Achievement - a_World->ForEachPlayer(PlayerCallback); + a_WorldInterface.ForEachPlayer(PlayerCallback); return true; } @@ -189,23 +199,29 @@ public: BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta ) override { - class cCallback : public cMobHeadCallback + class cCallback : public cBlockEntityCallback { cPlayer * m_Player; NIBBLETYPE m_OldBlockMeta; NIBBLETYPE m_NewBlockMeta; - virtual bool Item (cMobHeadEntity * a_MobHeadEntity) + virtual bool Item (cBlockEntity * a_BlockEntity) { + cMobHeadEntity * MobHeadEntity = static_cast(a_BlockEntity); + if (MobHeadEntity == NULL) + { + return false; + } + int Rotation = 0; if (m_NewBlockMeta == 1) { Rotation = (int) floor(m_Player->GetYaw() * 16.0F / 360.0F + 0.5) & 0xF; } - - a_MobHeadEntity->SetType(static_cast(m_OldBlockMeta)); - a_MobHeadEntity->SetRotation(static_cast(Rotation)); - a_MobHeadEntity->GetWorld()->BroadcastBlockEntity(a_MobHeadEntity->GetPosX(), a_MobHeadEntity->GetPosY(), a_MobHeadEntity->GetPosZ()); + + MobHeadEntity->SetType(static_cast(m_OldBlockMeta)); + MobHeadEntity->SetRotation(static_cast(Rotation)); + MobHeadEntity->GetWorld()->BroadcastBlockEntity(MobHeadEntity->GetPosX(), MobHeadEntity->GetPosY(), MobHeadEntity->GetPosZ()); return false; } @@ -219,8 +235,7 @@ public: cCallback Callback(a_Player, a_BlockMeta, static_cast(a_BlockFace)); a_BlockMeta = (NIBBLETYPE)a_BlockFace; - cWorld * World = (cWorld *) &a_WorldInterface; - World->DoWithMobHeadAt(a_BlockX, a_BlockY, a_BlockZ, Callback); + a_WorldInterface.DoWithBlockEntityAt(a_BlockX, a_BlockY, a_BlockZ, Callback); a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, a_BlockMeta); if (a_BlockMeta == SKULL_TYPE_WITHER) @@ -235,7 +250,7 @@ public: }; for (size_t i = 0; i < ARRAYCOUNT(Coords); ++i) { - if (TrySpawnWither(a_ChunkInterface, World, a_BlockX + Coords[i].x, a_BlockY, a_BlockZ + Coords[i].z)) + if (TrySpawnWither(a_ChunkInterface, a_WorldInterface, a_BlockX + Coords[i].x, a_BlockY, a_BlockZ + Coords[i].z)) { break; } diff --git a/src/Blocks/WorldInterface.h b/src/Blocks/WorldInterface.h index bfbb053d9..650a216c0 100644 --- a/src/Blocks/WorldInterface.h +++ b/src/Blocks/WorldInterface.h @@ -6,6 +6,12 @@ class cItems; +typedef cItemCallback cBlockEntityCallback; + + + + + class cWorldInterface { public: @@ -29,6 +35,9 @@ public: /** Spawns a mob of the specified type. Returns the mob's EntityID if recognized and spawned, <0 otherwise */ virtual int SpawnMob(double a_PosX, double a_PosY, double a_PosZ, cMonster::eType a_MonsterType) = 0; + /** Calls the callback for the block entity at the specified coords; returns false if there's no block entity at those coords, true if found */ + virtual bool DoWithBlockEntityAt(int a_BlockX, int a_BlockY, int a_BlockZ, cBlockEntityCallback & a_Callback) = 0; + /** Sends the block on those coords to the player */ virtual void SendBlockTo(int a_BlockX, int a_BlockY, int a_BlockZ, cPlayer * a_Player) = 0; -- cgit v1.2.3 From a4d4621fbe6dbab3e2202f17e8f0b384120041e0 Mon Sep 17 00:00:00 2001 From: Howaner Date: Tue, 17 Jun 2014 12:47:18 +0200 Subject: Add parenthesis --- src/Blocks/BlockPressurePlate.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/Blocks') diff --git a/src/Blocks/BlockPressurePlate.h b/src/Blocks/BlockPressurePlate.h index 01d5e8174..adec36eb6 100644 --- a/src/Blocks/BlockPressurePlate.h +++ b/src/Blocks/BlockPressurePlate.h @@ -27,9 +27,9 @@ public: { return false; } - BLOCKTYPE BlockBelow = a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ); - return (BlockBelow == E_BLOCK_FENCE_GATE || BlockBelow == E_BLOCK_FENCE || cBlockInfo::IsSolid(BlockBelow)); + BLOCKTYPE BlockBelow = a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ); + return ((BlockBelow == E_BLOCK_FENCE_GATE) || (BlockBelow == E_BLOCK_FENCE) || cBlockInfo::IsSolid(BlockBelow)); } } ; -- cgit v1.2.3 From 8e927e6e2bfb461b26a3413cbde829f98fbcaa28 Mon Sep 17 00:00:00 2001 From: Howaner Date: Tue, 17 Jun 2014 14:45:29 +0200 Subject: Check block type from cBlockEntity --- src/Blocks/BlockMobHead.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/Blocks') diff --git a/src/Blocks/BlockMobHead.h b/src/Blocks/BlockMobHead.h index 34a92c150..68996aa3f 100644 --- a/src/Blocks/BlockMobHead.h +++ b/src/Blocks/BlockMobHead.h @@ -34,11 +34,11 @@ public: { virtual bool Item(cBlockEntity * a_BlockEntity) { - cMobHeadEntity * MobHeadEntity = static_cast(a_BlockEntity); - if (MobHeadEntity == NULL) + if (a_BlockEntity->GetBlockType() != E_BLOCK_HEAD) { return false; } + cMobHeadEntity * MobHeadEntity = static_cast(a_BlockEntity); cItems Pickups; Pickups.Add(E_ITEM_HEAD, 1, (short) MobHeadEntity->GetType()); @@ -73,13 +73,13 @@ public: { bool m_IsWither; - virtual bool Item (cBlockEntity * a_BlockEntity) + virtual bool Item(cBlockEntity * a_BlockEntity) { - cMobHeadEntity * MobHeadEntity = static_cast(a_BlockEntity); - if (MobHeadEntity == NULL) + if (a_BlockEntity->GetBlockType() != E_BLOCK_HEAD) { return false; } + cMobHeadEntity * MobHeadEntity = static_cast(a_BlockEntity); m_IsWither = (MobHeadEntity->GetType() == SKULL_TYPE_WITHER); return false; @@ -205,13 +205,13 @@ public: NIBBLETYPE m_OldBlockMeta; NIBBLETYPE m_NewBlockMeta; - virtual bool Item (cBlockEntity * a_BlockEntity) + virtual bool Item(cBlockEntity * a_BlockEntity) { - cMobHeadEntity * MobHeadEntity = static_cast(a_BlockEntity); - if (MobHeadEntity == NULL) + if (a_BlockEntity->GetBlockType() != E_BLOCK_HEAD) { return false; } + cMobHeadEntity * MobHeadEntity = static_cast(a_BlockEntity); int Rotation = 0; if (m_NewBlockMeta == 1) -- cgit v1.2.3