Jukebox improvements (#4537)
* Add jukebox block handler Co-authored-by: peterbell10 <peterbell10@live.co.uk>
This commit is contained in:
parent
605cf774f9
commit
f5d24746d6
@ -1,6 +1,9 @@
|
|||||||
|
|
||||||
|
// JukeboxEntity.cpp
|
||||||
|
|
||||||
|
// Implements the cJukeboxEntity class representing a single jukebox in the world
|
||||||
|
|
||||||
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
||||||
|
|
||||||
#include "JukeboxEntity.h"
|
#include "JukeboxEntity.h"
|
||||||
#include "../World.h"
|
#include "../World.h"
|
||||||
#include "../EffectID.h"
|
#include "../EffectID.h"
|
||||||
@ -23,6 +26,21 @@ cJukeboxEntity::cJukeboxEntity(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Ve
|
|||||||
|
|
||||||
cJukeboxEntity::~cJukeboxEntity()
|
cJukeboxEntity::~cJukeboxEntity()
|
||||||
{
|
{
|
||||||
|
if (m_World && IsPlayingRecord())
|
||||||
|
{
|
||||||
|
// Stop playing music when destroyed by any means
|
||||||
|
m_World->BroadcastSoundParticleEffect(EffectID::SFX_RANDOM_PLAY_MUSIC_DISC, GetPos(), 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void cJukeboxEntity::Destroy(void)
|
||||||
|
{
|
||||||
|
ASSERT(m_World != nullptr);
|
||||||
|
EjectRecord();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -50,7 +68,7 @@ bool cJukeboxEntity::UsedBy(cPlayer * a_Player)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
const cItem & HeldItem = a_Player->GetEquippedItem();
|
const cItem & HeldItem = a_Player->GetEquippedItem();
|
||||||
if (PlayRecord(HeldItem.m_ItemType))
|
if (PlayRecord(HeldItem.m_ItemType) && !a_Player->IsGameModeCreative())
|
||||||
{
|
{
|
||||||
a_Player->GetInventory().RemoveOneEquippedItem();
|
a_Player->GetInventory().RemoveOneEquippedItem();
|
||||||
return true;
|
return true;
|
||||||
@ -96,9 +114,9 @@ bool cJukeboxEntity::EjectRecord(void)
|
|||||||
cItems Drops;
|
cItems Drops;
|
||||||
Drops.push_back(cItem(static_cast<short>(m_Record), 1, 0));
|
Drops.push_back(cItem(static_cast<short>(m_Record), 1, 0));
|
||||||
m_Record = 0;
|
m_Record = 0;
|
||||||
m_World->SpawnItemPickups(Drops, Vector3d(0.5, 1, 0.5) + m_Pos, 8);
|
m_World->SpawnItemPickups(Drops, Vector3d(0.5, 0.5, 0.5) + m_Pos, 10);
|
||||||
m_World->BroadcastSoundParticleEffect(EffectID::SFX_RANDOM_PLAY_MUSIC_DISC, GetPos(), 0);
|
|
||||||
m_World->SetBlockMeta(m_Pos, E_META_JUKEBOX_OFF);
|
m_World->SetBlockMeta(m_Pos, E_META_JUKEBOX_OFF);
|
||||||
|
m_World->BroadcastSoundParticleEffect(EffectID::SFX_RANDOM_PLAY_MUSIC_DISC, GetPos(), 0);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,6 +46,7 @@ public: // tolua_export
|
|||||||
// tolua_end
|
// tolua_end
|
||||||
|
|
||||||
// cBlockEntity overrides:
|
// cBlockEntity overrides:
|
||||||
|
virtual void Destroy(void) override;
|
||||||
virtual void CopyFrom(const cBlockEntity & a_Src) override;
|
virtual void CopyFrom(const cBlockEntity & a_Src) override;
|
||||||
virtual bool UsedBy(cPlayer * a_Player) override;
|
virtual bool UsedBy(cPlayer * a_Player) override;
|
||||||
virtual void SendTo(cClientHandle &) override {}
|
virtual void SendTo(cClientHandle &) override {}
|
||||||
|
@ -45,6 +45,7 @@
|
|||||||
#include "BlockMobHead.h"
|
#include "BlockMobHead.h"
|
||||||
#include "BlockHopper.h"
|
#include "BlockHopper.h"
|
||||||
#include "BlockIce.h"
|
#include "BlockIce.h"
|
||||||
|
#include "BlockJukebox.h"
|
||||||
#include "BlockLadder.h"
|
#include "BlockLadder.h"
|
||||||
#include "BlockLeaves.h"
|
#include "BlockLeaves.h"
|
||||||
#include "BlockLilypad.h"
|
#include "BlockLilypad.h"
|
||||||
@ -259,7 +260,7 @@ static cBlockHandler * CreateBlockHandler(BLOCKTYPE a_BlockType)
|
|||||||
case E_BLOCK_IRON_ORE: return new cBlockOreHandler (a_BlockType);
|
case E_BLOCK_IRON_ORE: return new cBlockOreHandler (a_BlockType);
|
||||||
case E_BLOCK_IRON_TRAPDOOR: return new cBlockTrapdoorHandler (a_BlockType);
|
case E_BLOCK_IRON_TRAPDOOR: return new cBlockTrapdoorHandler (a_BlockType);
|
||||||
case E_BLOCK_JACK_O_LANTERN: return new cBlockPumpkinHandler (a_BlockType);
|
case E_BLOCK_JACK_O_LANTERN: return new cBlockPumpkinHandler (a_BlockType);
|
||||||
case E_BLOCK_JUKEBOX: return new cBlockEntityHandler (a_BlockType);
|
case E_BLOCK_JUKEBOX: return new cBlockJukeboxHandler (a_BlockType);
|
||||||
case E_BLOCK_JUNGLE_DOOR: return new cBlockDoorHandler (a_BlockType);
|
case E_BLOCK_JUNGLE_DOOR: return new cBlockDoorHandler (a_BlockType);
|
||||||
case E_BLOCK_JUNGLE_FENCE: return new cBlockFenceHandler (a_BlockType);
|
case E_BLOCK_JUNGLE_FENCE: return new cBlockFenceHandler (a_BlockType);
|
||||||
case E_BLOCK_JUNGLE_FENCE_GATE: return new cBlockFenceGateHandler (a_BlockType);
|
case E_BLOCK_JUNGLE_FENCE_GATE: return new cBlockFenceGateHandler (a_BlockType);
|
||||||
|
36
src/Blocks/BlockJukebox.h
Normal file
36
src/Blocks/BlockJukebox.h
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "BlockEntity.h"
|
||||||
|
#include "Mixins.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class cBlockJukeboxHandler :
|
||||||
|
public cClearMetaOnDrop<cBlockEntityHandler>
|
||||||
|
{
|
||||||
|
using super = cClearMetaOnDrop<cBlockEntityHandler>;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
cBlockJukeboxHandler(BLOCKTYPE a_BlockType):
|
||||||
|
super(a_BlockType)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) override
|
||||||
|
{
|
||||||
|
UNUSED(a_Meta);
|
||||||
|
return 6;
|
||||||
|
}
|
||||||
|
} ;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user