From 9849ca32a2ebd13ad7e5e2e1b69a2239af4a6bd7 Mon Sep 17 00:00:00 2001 From: Tnze Date: Fri, 25 Nov 2022 11:22:47 +0800 Subject: [PATCH] check current DimensionType to avoid panic. --- bot/world/chunks.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/bot/world/chunks.go b/bot/world/chunks.go index 6baaab5..0bd1420 100644 --- a/bot/world/chunks.go +++ b/bot/world/chunks.go @@ -1,6 +1,8 @@ package world import ( + "errors" + "github.com/Tnze/go-mc/bot" "github.com/Tnze/go-mc/bot/basic" "github.com/Tnze/go-mc/data/packetid" @@ -40,6 +42,9 @@ func (w *World) onPlayerSpawn(pk.Packet) error { func (w *World) handleLevelChunkWithLightPacket(packet pk.Packet) error { var pos level.ChunkPos currentDimType := w.p.WorldInfo.RegistryCodec.DimensionType.Find(w.p.DimensionType) + if currentDimType == nil { + return errors.New("dimension type " + w.p.DimensionType + " not found") + } chunk := level.EmptyChunk(int(currentDimType.Height) / 16) if err := packet.Scan(&pos, chunk); err != nil { return err