break/place only when not paused

This commit is contained in:
Edgaru089 2022-02-25 21:15:44 +08:00
parent 1e74665abc
commit 08e08000a6

View File

@ -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))
}
}
}
}