@@ -177,6 +177,8 @@ protected override void OnUpdateFrame(FrameEventArgs e)
177177 Camera . position . Y += delta * 6f ;
178178 else if ( keyboardState . IsKeyDown ( Key . ShiftLeft ) )
179179 Camera . position . Y -= delta * 6f ;
180+
181+ Camera . UpdateView ( Width , Height ) ;
180182 }
181183
182184 if ( GUI . Scene == 1 && wantToSave ) {
@@ -202,7 +204,8 @@ protected override void OnUpdateFrame(FrameEventArgs e)
202204 if ( keyboardState . IsKeyDown ( Key . Escape ) )
203205 UnlockMouse ( ) ;
204206
205- outline . Update ( ) ;
207+ //if (!outline.Raycast)
208+ outline . Update ( ) ;
206209
207210 GUI . Update ( delta ) ;
208211
@@ -220,7 +223,6 @@ protected override void OnRenderFrame(FrameEventArgs e)
220223 colShader . UploadMat4 ( "uView" , ref Camera . viewMatrix ) ;
221224
222225 shader . Bind ( ) ;
223- Camera . UpdateView ( Width , Height ) ;
224226 shader . UploadMat4 ( "uProjection" , ref Camera . projMatrix ) ;
225227 shader . UploadMat4 ( "uView" , ref Camera . viewMatrix ) ;
226228 if ( GUI . Scene > 0 )
@@ -244,9 +246,30 @@ protected override void OnRenderFrame(FrameEventArgs e)
244246 GL . DepthMask ( true ) ;
245247
246248 SwapBuffers ( ) ;
249+
250+ LateUpdate ( ) ;
251+ }
252+
253+ private void LateUpdate ( )
254+ {
255+ if ( wantToTakeInput ) {
256+ string input = BlockToPlace . TakeInput ( ) ;
257+ if ( input != string . Empty ) {
258+ if ( ! World . WillCreateValidTextures ( input , 0 ) ) {
259+ Console . ForegroundColor = ConsoleColor . Red ;
260+ Console . WriteLine ( $ "\" { input } \" isn't valid block") ;
261+ Console . ResetColor ( ) ;
262+ }
263+ else
264+ World . BlockToPlace = input ;
265+ }
266+ GUI . SetScene ( 0 ) ;
267+ wantToTakeInput = false ;
268+ }
247269 }
248270
249271 bool wantToSave = false ;
272+ bool wantToTakeInput = false ;
250273 protected override void OnKeyDown ( KeyboardKeyEventArgs e )
251274 {
252275 if ( e . Key == Key . P ) {
@@ -259,23 +282,15 @@ protected override void OnKeyDown(KeyboardKeyEventArgs e)
259282 Console . WriteLine ( "Couldn't get block index or sub chunk" ) ;
260283 }
261284 else if ( e . Key == Key . E ) {
262- string input = BlockToPlace . TakeInput ( ) ;
263- if ( input != string . Empty ) {
264- if ( ! World . WillCreateValidTextures ( input , 0 ) ) {
265- Console . ForegroundColor = ConsoleColor . Red ;
266- Console . WriteLine ( $ "\" { input } \" isn't valid block") ;
267- Console . ResetColor ( ) ;
268- }
269- else
270- World . BlockToPlace = input ;
271- }
285+ GUI . SetScene ( 3 ) ;
286+ wantToTakeInput = true ;
272287 }
273288 else if ( e . Key == Key . S && ( e . Modifiers & KeyModifiers . Control ) == KeyModifiers . Control ) // save
274- {
275289 wantToSave = true ;
276- }
277290 else if ( e . Key == Key . C )
278291 World . ShowChunkOutlines = ! World . ShowChunkOutlines ;
292+ else if ( e . Key == Key . M )
293+ outline . Raycast = ! outline . Raycast ;
279294 else
280295 keyboardState = e . Keyboard ;
281296
@@ -297,10 +312,12 @@ protected override void OnMouseDown(MouseButtonEventArgs e)
297312 GUI . OnMouseDown ( e . Button , e . Position ) ;
298313
299314 if ( GUI . Scene == 1 ) {
315+ if ( outline . Raycast )
316+ outline . Update ( ) ;
300317 if ( e . Button == MouseButton . Left )
301- World . SetBlock ( ( Vector3i ) outline . Position , "air" ) ;
318+ World . SetBlock ( ( Vector3i ) outline . raycastResult . HitPos , "air" ) ;
302319 if ( e . Button == MouseButton . Right )
303- World . SetBlock ( ( Vector3i ) outline . Position , World . BlockToPlace ) ;
320+ World . SetBlock ( ( Vector3i ) outline . raycastResult . LastPos , World . BlockToPlace ) ;
304321 }
305322 }
306323 protected override void OnMouseUp ( MouseButtonEventArgs e )
0 commit comments