From 08e08000a645b143cd2629e57edd02c4f3bf0b90 Mon Sep 17 00:00:00 2001 From: Edgaru089 Date: Fri, 25 Feb 2022 21:15:44 +0800 Subject: [PATCH] break/place only when not paused --- internal/game/logic.go | 48 ++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/internal/game/logic.go b/internal/game/logic.go index 0a81f68..5b400bf 100644 --- a/internal/game/logic.go +++ b/internal/game/logic.go @@ -273,32 +273,34 @@ func (g *Game) Update(win *glfw.Window, delta time.Duration) { render.Framewire.PushBox(r.GrowEven(itype.Vec3d{0.03125, 0.03125, 0.03125}).Offset(bc.ToFloat64()).ToFloat32(), color.White) } - // Break/Place block - if win.GetMouseButton(glfw.MouseButtonLeft) == glfw.Press && g.runtime-time.Duration(g.player.DatasetI("LastBreak")) >= PlayerBreakCooldown { - // Break - g.world.Break(bc) - g.player.SetDatasetI("LastBreak", int64(g.runtime)) - } else if win.GetMouseButton(glfw.MouseButtonRight) == glfw.Press && g.runtime-time.Duration(g.player.DatasetI("LastPlace")) >= PlayerBreakCooldown { - // Place - // Check hitbox - tobehit := world.GetBlockBehaviour(placeId[placei]).Appearance(bc.Add(itype.DirectionVeci[dir]), 0, nil, g.world).Hitbox - if len(tobehit) == 0 { - tobehit = []itype.Boxd{{OffX: 0, OffY: 0, OffZ: 0, SizeX: 1, SizeY: 1, SizeZ: 1}} - } - canplace := true - outer: - for _, pb := range g.player.WorldHitbox() { - for _, b := range tobehit { - if ok, _ := b.Offset(bc.Add(itype.DirectionVeci[dir]).ToFloat64()).Intersect(pb); ok { - canplace = false - break outer + if !g.paused { + // Break/Place block + if win.GetMouseButton(glfw.MouseButtonLeft) == glfw.Press && g.runtime-time.Duration(g.player.DatasetI("LastBreak")) >= PlayerBreakCooldown { + // Break + g.world.Break(bc) + g.player.SetDatasetI("LastBreak", int64(g.runtime)) + } else if win.GetMouseButton(glfw.MouseButtonRight) == glfw.Press && g.runtime-time.Duration(g.player.DatasetI("LastPlace")) >= PlayerBreakCooldown { + // Place + // Check hitbox + tobehit := world.GetBlockBehaviour(placeId[placei]).Appearance(bc.Add(itype.DirectionVeci[dir]), 0, nil, g.world).Hitbox + if len(tobehit) == 0 { + tobehit = []itype.Boxd{{OffX: 0, OffY: 0, OffZ: 0, SizeX: 1, SizeY: 1, SizeZ: 1}} + } + canplace := true + outer: + for _, pb := range g.player.WorldHitbox() { + for _, b := range tobehit { + if ok, _ := b.Offset(bc.Add(itype.DirectionVeci[dir]).ToFloat64()).Intersect(pb); ok { + canplace = false + break outer + } } } - } - if canplace { - g.world.SetBlock(bc.Add(itype.DirectionVeci[dir]), placeId[placei], 0, nil) - g.player.SetDatasetI("LastPlace", int64(g.runtime)) + if canplace { + g.world.SetBlock(bc.Add(itype.DirectionVeci[dir]), placeId[placei], 0, nil) + g.player.SetDatasetI("LastPlace", int64(g.runtime)) + } } } }