commit
81446b0f80
@ -452,7 +452,6 @@ void cBlockInfo::Initialize(cBlockInfoArray & a_Info)
|
|||||||
a_Info[E_BLOCK_AIR ].m_IsSolid = false;
|
a_Info[E_BLOCK_AIR ].m_IsSolid = false;
|
||||||
a_Info[E_BLOCK_BIG_FLOWER ].m_IsSolid = false;
|
a_Info[E_BLOCK_BIG_FLOWER ].m_IsSolid = false;
|
||||||
a_Info[E_BLOCK_BROWN_MUSHROOM ].m_IsSolid = false;
|
a_Info[E_BLOCK_BROWN_MUSHROOM ].m_IsSolid = false;
|
||||||
a_Info[E_BLOCK_CAKE ].m_IsSolid = false;
|
|
||||||
a_Info[E_BLOCK_CARROTS ].m_IsSolid = false;
|
a_Info[E_BLOCK_CARROTS ].m_IsSolid = false;
|
||||||
a_Info[E_BLOCK_COBWEB ].m_IsSolid = false;
|
a_Info[E_BLOCK_COBWEB ].m_IsSolid = false;
|
||||||
a_Info[E_BLOCK_CROPS ].m_IsSolid = false;
|
a_Info[E_BLOCK_CROPS ].m_IsSolid = false;
|
||||||
|
96
src/Blocks/BlockCocoaPod.h
Normal file
96
src/Blocks/BlockCocoaPod.h
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "BlockHandler.h"
|
||||||
|
#include "../FastRandom.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class cBlockCocoaPodHandler :
|
||||||
|
public cBlockHandler
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
cBlockCocoaPodHandler(BLOCKTYPE a_BlockType)
|
||||||
|
: cBlockHandler(a_BlockType)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override
|
||||||
|
{
|
||||||
|
eBlockFace BlockFace = MetaToBlockFace(a_Chunk.GetMeta(a_RelX, a_RelY, a_RelZ));
|
||||||
|
AddFaceDirection(a_RelX, a_RelY, a_RelZ, BlockFace, true);
|
||||||
|
|
||||||
|
BLOCKTYPE BlockType;
|
||||||
|
NIBBLETYPE BlockMeta;
|
||||||
|
a_Chunk.UnboundedRelGetBlock(a_RelX, a_RelY, a_RelZ, BlockType, BlockMeta);
|
||||||
|
|
||||||
|
return ((BlockType == E_BLOCK_LOG) && ((BlockMeta & 0x3) == E_META_LOG_JUNGLE));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
virtual void OnUpdate(cChunkInterface & cChunkInterface, cWorldInterface & a_WorldInterface, cBlockPluginInterface & a_PluginInterface, cChunk & a_Chunk, int a_RelX, int a_RelY, int a_RelZ) override
|
||||||
|
{
|
||||||
|
cFastRandom Random;
|
||||||
|
|
||||||
|
if (Random.NextInt(5) == 0)
|
||||||
|
{
|
||||||
|
NIBBLETYPE Meta = a_Chunk.GetMeta(a_RelX, a_RelY, a_RelZ);
|
||||||
|
NIBBLETYPE TypeMeta = Meta & 0x03;
|
||||||
|
int GrowState = Meta >> 2;
|
||||||
|
|
||||||
|
if (GrowState < 2)
|
||||||
|
{
|
||||||
|
++GrowState;
|
||||||
|
a_Chunk.SetMeta(a_RelX, a_RelY, a_RelZ, (NIBBLETYPE) (GrowState << 2 | TypeMeta));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
|
||||||
|
{
|
||||||
|
int GrowState = a_BlockMeta >> 2;
|
||||||
|
a_Pickups.Add(E_ITEM_DYE, ((GrowState >= 2) ? 3 : 1), E_META_DYE_BROWN);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static eBlockFace MetaToBlockFace(NIBBLETYPE a_Meta)
|
||||||
|
{
|
||||||
|
switch (a_Meta & 0x3)
|
||||||
|
{
|
||||||
|
case 0: return BLOCK_FACE_ZM;
|
||||||
|
case 1: return BLOCK_FACE_XP;
|
||||||
|
case 2: return BLOCK_FACE_ZP;
|
||||||
|
case 3: return BLOCK_FACE_XM;
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
ASSERT(!"Bad meta");
|
||||||
|
return BLOCK_FACE_NONE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static NIBBLETYPE BlockFaceToMeta(eBlockFace a_BlockFace)
|
||||||
|
{
|
||||||
|
switch (a_BlockFace)
|
||||||
|
{
|
||||||
|
case BLOCK_FACE_ZM: return 0;
|
||||||
|
case BLOCK_FACE_XM: return 3;
|
||||||
|
case BLOCK_FACE_XP: return 1;
|
||||||
|
case BLOCK_FACE_ZP: return 2;
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
ASSERT(!"Unknown face");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} ;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
|||||||
#include "BlockChest.h"
|
#include "BlockChest.h"
|
||||||
#include "BlockCloth.h"
|
#include "BlockCloth.h"
|
||||||
#include "BlockCobWeb.h"
|
#include "BlockCobWeb.h"
|
||||||
|
#include "BlockCocoaPod.h"
|
||||||
#include "BlockCommandBlock.h"
|
#include "BlockCommandBlock.h"
|
||||||
#include "BlockComparator.h"
|
#include "BlockComparator.h"
|
||||||
#include "BlockCrops.h"
|
#include "BlockCrops.h"
|
||||||
@ -198,6 +199,7 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType)
|
|||||||
case E_BLOCK_CAULDRON: return new cBlockCauldronHandler (a_BlockType);
|
case E_BLOCK_CAULDRON: return new cBlockCauldronHandler (a_BlockType);
|
||||||
case E_BLOCK_CHEST: return new cBlockChestHandler (a_BlockType);
|
case E_BLOCK_CHEST: return new cBlockChestHandler (a_BlockType);
|
||||||
case E_BLOCK_COAL_ORE: return new cBlockOreHandler (a_BlockType);
|
case E_BLOCK_COAL_ORE: return new cBlockOreHandler (a_BlockType);
|
||||||
|
case E_BLOCK_COCOA_POD: return new cBlockCocoaPodHandler (a_BlockType);
|
||||||
case E_BLOCK_COMMAND_BLOCK: return new cBlockCommandBlockHandler (a_BlockType);
|
case E_BLOCK_COMMAND_BLOCK: return new cBlockCommandBlockHandler (a_BlockType);
|
||||||
case E_BLOCK_ACTIVE_COMPARATOR: return new cBlockComparatorHandler (a_BlockType);
|
case E_BLOCK_ACTIVE_COMPARATOR: return new cBlockComparatorHandler (a_BlockType);
|
||||||
case E_BLOCK_COBBLESTONE: return new cBlockStoneHandler (a_BlockType);
|
case E_BLOCK_COBBLESTONE: return new cBlockStoneHandler (a_BlockType);
|
||||||
|
@ -24,6 +24,7 @@ SET (HDRS
|
|||||||
BlockChest.h
|
BlockChest.h
|
||||||
BlockCloth.h
|
BlockCloth.h
|
||||||
BlockCobWeb.h
|
BlockCobWeb.h
|
||||||
|
BlockCocoaPod.h
|
||||||
BlockCommandBlock.h
|
BlockCommandBlock.h
|
||||||
BlockComparator.h
|
BlockComparator.h
|
||||||
BlockCrops.h
|
BlockCrops.h
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include "ItemHandler.h"
|
#include "ItemHandler.h"
|
||||||
#include "../World.h"
|
#include "../World.h"
|
||||||
#include "../Entities/Player.h"
|
#include "../Entities/Player.h"
|
||||||
|
#include "../Blocks/BlockCocoaPod.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -16,10 +17,9 @@ public:
|
|||||||
cItemDyeHandler(int a_ItemType)
|
cItemDyeHandler(int a_ItemType)
|
||||||
: cItemHandler(a_ItemType)
|
: cItemHandler(a_ItemType)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Dir) override
|
virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace) override
|
||||||
{
|
{
|
||||||
// Handle growing the plants:
|
// Handle growing the plants:
|
||||||
if (a_Item.m_ItemDamage == E_META_DYE_WHITE)
|
if (a_Item.m_ItemDamage == E_META_DYE_WHITE)
|
||||||
@ -34,8 +34,50 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if ((a_Item.m_ItemDamage == E_META_DYE_BROWN) && (a_BlockFace >= BLOCK_FACE_ZM) && (a_BlockFace <= BLOCK_FACE_XP))
|
||||||
|
{
|
||||||
|
BLOCKTYPE BlockType;
|
||||||
|
NIBBLETYPE BlockMeta;
|
||||||
|
a_World->GetBlockTypeMeta(a_BlockX, a_BlockY, a_BlockZ, BlockType, BlockMeta);
|
||||||
|
|
||||||
|
// Check if the block that the player clicked is a jungle log.
|
||||||
|
if ((BlockType != E_BLOCK_LOG) || ((BlockMeta & 0x3) != E_META_LOG_JUNGLE))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the location from the new cocoa pod.
|
||||||
|
AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, false);
|
||||||
|
BlockMeta = cBlockCocoaPodHandler::BlockFaceToMeta(a_BlockFace);
|
||||||
|
|
||||||
|
if (a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ) != E_BLOCK_AIR)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check plugins
|
||||||
|
if (cRoot::Get()->GetPluginManager()->CallHookPlayerPlacingBlock(*a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, 0, 0, 0, E_BLOCK_COCOA_POD, BlockMeta))
|
||||||
|
{
|
||||||
|
a_World->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, a_Player);
|
||||||
|
a_Player->GetInventory().SendEquippedSlot();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set block and broadcast place sound
|
||||||
|
a_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_COCOA_POD, BlockMeta);
|
||||||
|
a_World->BroadcastSoundEffect("dig.stone", a_BlockX + 0.5, a_BlockY + 0.5, a_BlockZ + 0.5, 1.0f, 0.8f);
|
||||||
|
|
||||||
|
// Remove one cocoa pod from the inventory
|
||||||
|
if (!a_Player->IsGameModeCreative())
|
||||||
|
{
|
||||||
|
a_Player->GetInventory().RemoveOneEquippedItem();
|
||||||
|
}
|
||||||
|
cRoot::Get()->GetPluginManager()->CallHookPlayerPlacedBlock(*a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, 0, 0, 0, E_BLOCK_COCOA_POD, BlockMeta);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
|
||||||
|
@ -1520,7 +1520,21 @@ bool cWorld::GrowRipePlant(int a_BlockX, int a_BlockY, int a_BlockZ, bool a_IsBy
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case E_BLOCK_COCOA_POD:
|
||||||
|
{
|
||||||
|
NIBBLETYPE TypeMeta = BlockMeta & 0x03;
|
||||||
|
int GrowState = BlockMeta >> 2;
|
||||||
|
|
||||||
|
if (GrowState < 2)
|
||||||
|
{
|
||||||
|
GrowState++;
|
||||||
|
FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, BlockType, (NIBBLETYPE) (GrowState << 2 | TypeMeta));
|
||||||
|
BroadcastSoundParticleEffect(2005, a_BlockX, a_BlockY, a_BlockZ, 0);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
case E_BLOCK_CROPS:
|
case E_BLOCK_CROPS:
|
||||||
{
|
{
|
||||||
if (a_IsByBonemeal && !m_IsCropsBonemealable)
|
if (a_IsByBonemeal && !m_IsCropsBonemealable)
|
||||||
|
Loading…
Reference in New Issue
Block a user