the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 84 lines 2.4 kB view raw
1#include "stdafx.h" 2#include "net.minecraft.world.level.h" 3#include "net.minecraft.world.level.tile.entity.h" 4#include "MusicTile.h" 5#include "SoundTypes.h" 6 7MusicTile::MusicTile(int id) : EntityTile(id, Material::wood) 8{ 9} 10 11void MusicTile::neighborChanged(Level *level, int x, int y, int z, int type) 12{ 13 app.DebugPrintf("-------- Neighbour changed type %d\n", type); 14 bool signal = level->hasNeighborSignal(x, y, z); 15 shared_ptr<MusicTileEntity> mte = dynamic_pointer_cast<MusicTileEntity>( level->getTileEntity(x, y, z) ); 16 app.DebugPrintf("-------- Signal is %s, tile is currently %s\n",signal?"TRUE":"FALSE", mte->on?"ON":"OFF"); 17 if (mte != NULL && mte->on != signal) 18 { 19 if (signal) 20 { 21 mte->playNote(level, x, y, z); 22 } 23 mte->on = signal; 24 } 25} 26 27// 4J-PB - Adding a TestUse for tooltip display 28bool MusicTile::TestUse() 29{ 30 return true; 31} 32 33bool MusicTile::use(Level *level, int x, int y, int z, shared_ptr<Player> player, int clickedFace, float clickX, float clickY, float clickZ, bool soundOnly/*=false*/) // 4J added soundOnly param 34{ 35 if (soundOnly) return false; 36 if (level->isClientSide) return true; 37 shared_ptr<MusicTileEntity> mte = dynamic_pointer_cast<MusicTileEntity>( level->getTileEntity(x, y, z) ); 38 if (mte != NULL ) 39 { 40 mte->tune(); 41 mte->playNote(level, x, y, z); 42 } 43 return true; 44} 45 46void MusicTile::attack(Level *level, int x, int y, int z, shared_ptr<Player> player) 47{ 48 if (level->isClientSide) return; 49 shared_ptr<MusicTileEntity> mte = dynamic_pointer_cast<MusicTileEntity>( level->getTileEntity(x, y, z) ); 50 if( mte != NULL ) mte->playNote(level, x, y, z); 51} 52 53shared_ptr<TileEntity> MusicTile::newTileEntity(Level *level) 54{ 55 return shared_ptr<MusicTileEntity>( new MusicTileEntity() ); 56} 57 58void MusicTile::triggerEvent(Level *level, int x, int y, int z, int i, int note) 59{ 60 float pitch = (float) pow(2, (note - 12) / 12.0); 61 62 int iSound; 63 switch(i) 64 { 65 case 1: 66 iSound=eSoundType_NOTE_BD; 67 break; 68 case 2: 69 iSound=eSoundType_NOTE_SNARE; 70 break; 71 case 3: 72 iSound=eSoundType_NOTE_HAT; 73 break; 74 case 4: 75 iSound=eSoundType_NOTE_BASSATTACK; 76 break; 77 default: 78 iSound=eSoundType_NOTE_HARP; 79 break; 80 } 81 app.DebugPrintf("MusicTile::triggerEvent - playSound - pitch = %f\n",pitch); 82 level->playSound(x + 0.5, y + 0.5, z + 0.5, iSound, 3, pitch); 83 level->addParticle(eParticleType_note, x + 0.5, y + 1.2, z + 0.5, note / 24.0, 0, 0); 84}