2323
2424#endregion
2525
26+ using MiNET . Items ;
27+ using MiNET . Particles ;
28+ using MiNET . Utils . Vectors ;
29+ using MiNET . Worlds ;
30+ using System ;
31+ using System . Linq ;
32+ using System . Numerics ;
33+
2634namespace MiNET . Blocks
2735{
2836 public partial class Jukebox : Block
2937 {
38+ private static int [ ] discIds = { 500 , 501 , 502 , 503 , 504 , 505 , 506 , 507 , 508 , 509 , 510 , 511 } ;
39+ private static Item disc { get ; set ; }
40+ private static bool playing { get ; set ; } = false ;
3041 public Jukebox ( ) : base ( 84 )
3142 {
3243 BlastResistance = 30 ;
3344 Hardness = 2f ;
3445 }
46+
47+ public override void BreakBlock ( Level level , BlockFace face , bool silent = false )
48+ {
49+ if ( level . BlockWithTicks . TryGetValue ( Coordinates , out long value ) )
50+ {
51+ level . CancelBlockTick ( this ) ;
52+ }
53+ if ( playing )
54+ {
55+ level . BroadcastSound ( Coordinates , LevelSoundEventType . RecordNull ) ;
56+ level . DropItem ( Coordinates , disc ) ;
57+ }
58+ base . BreakBlock ( level , face ) ;
59+ }
60+
61+ public override void OnTick ( Level level , bool isRandom )
62+ {
63+ if ( isRandom ) { return ; }
64+ LegacyParticle particle = new NoteParticle ( level ) { Position = new Vector3 ( Coordinates . X + 0.5f , Coordinates . Y + 1 , Coordinates . Z + 0.5f ) } ;
65+ particle . Spawn ( ) ;
66+ if ( playing )
67+ {
68+ level . ScheduleBlockTick ( this , 20 ) ;
69+ }
70+ }
71+
72+ public override bool Interact ( Level level , Player player , BlockCoordinates blockCoordinates , BlockFace face , Vector3 faceCoord )
73+ {
74+ if ( playing == true )
75+ {
76+ level . BroadcastSound ( blockCoordinates , LevelSoundEventType . RecordNull ) ;
77+ level . DropItem ( blockCoordinates , disc ) ;
78+ playing = false ;
79+ level . CancelBlockTick ( this ) ;
80+ }
81+ else
82+ {
83+ var itemInHand = player . Inventory . GetItemInHand ( ) ;
84+ if ( ! discIds . Contains ( itemInHand . Id ) ) { return true ; }
85+ disc = itemInHand ;
86+ player . Inventory . SetInventorySlot ( player . Inventory . InHandSlot , new ItemAir ( ) ) ;
87+ switch ( itemInHand . Id )
88+ {
89+ case 500 :
90+ level . BroadcastSound ( blockCoordinates , LevelSoundEventType . Record13 ) ;
91+ break ;
92+ case 501 :
93+ level . BroadcastSound ( blockCoordinates , LevelSoundEventType . RecordCat ) ;
94+ break ;
95+ case 502 :
96+ level . BroadcastSound ( blockCoordinates , LevelSoundEventType . RecordBlocks ) ;
97+ break ;
98+ case 503 :
99+ level . BroadcastSound ( blockCoordinates , LevelSoundEventType . RecordChirp ) ;
100+ break ;
101+ case 504 :
102+ level . BroadcastSound ( blockCoordinates , LevelSoundEventType . RecordFar ) ;
103+ break ;
104+ case 505 :
105+ level . BroadcastSound ( blockCoordinates , LevelSoundEventType . RecordMall ) ;
106+ break ;
107+ case 506 :
108+ level . BroadcastSound ( blockCoordinates , LevelSoundEventType . RecordMellohi ) ;
109+ break ;
110+ case 507 :
111+ level . BroadcastSound ( blockCoordinates , LevelSoundEventType . RecordStal ) ;
112+ break ;
113+ case 508 :
114+ level . BroadcastSound ( blockCoordinates , LevelSoundEventType . RecordStrad ) ;
115+ break ;
116+ case 509 :
117+ level . BroadcastSound ( blockCoordinates , LevelSoundEventType . RecordWard ) ;
118+ break ;
119+ case 510 :
120+ level . BroadcastSound ( blockCoordinates , LevelSoundEventType . Record11 ) ;
121+ break ;
122+ case 511 :
123+ level . BroadcastSound ( blockCoordinates , LevelSoundEventType . RecordWait ) ;
124+ break ;
125+ default :
126+ return true ;
127+ }
128+ playing = true ;
129+ level . ScheduleBlockTick ( this , 20 ) ;
130+ }
131+ return true ;
132+ }
35133 }
36134}
0 commit comments