1 package minecraft 2 3 import ( 4 "errors" 5 "strconv" 6 7 "vimagination.zapto.org/minecraft/nbt" 8 ) 9 10 var ( 11 // ErrOOB is an error returned when sanity checking section data 12 ErrOOB = errors.New("received out-of-bounds error") 13 // ErrNoLock is an error returns by path types to indicate that the lock on the 14 // minecraft level has been locked and needs reinstating to continue 15 ErrNoLock = errors.New("lost lock on files") 16 ) 17 18 // MissingTagError is an error type returned when an expected tag is not found 19 type MissingTagError struct { 20 TagName string 21 } 22 23 func (m MissingTagError) Error() string { 24 return "minecraft: missing " + strconv.Quote(m.TagName) + " tag" 25 } 26 27 // WrongTypeError is an error returned when a nbt tag has an unexpected type 28 type WrongTypeError struct { 29 TagName string 30 Expecting, Got nbt.TagID 31 } 32 33 func (w WrongTypeError) Error() string { 34 return "minecraft: tag " + strconv.Quote(w.TagName) + " is of incorrect type, expecting " + strconv.Quote(w.Expecting.String()) + ", got " + strconv.Quote(w.Got.String()) 35 } 36 37 // UnexpectedValue is an error returned from chunk loading during sanity 38 // checking 39 type UnexpectedValue struct { 40 TagName, Expecting, Got string 41 } 42 43 func (u UnexpectedValue) Error() string { 44 return "minecraft: tag " + strconv.Quote(u.TagName) + " was expecting " + strconv.Quote(u.Expecting) + ", but got " + strconv.Quote(u.Got) 45 } 46 47 // UnknownCompression is an error returned by path types when it encounters a 48 // compression scheme it is not prepared to handle or an unkown compression 49 // scheme 50 type UnknownCompression struct { 51 Code byte 52 } 53 54 func (u UnknownCompression) Error() string { 55 return "unknown compression code: " + strconv.FormatUint(uint64(u.Code), 10) 56 } 57 58 // ConflictError is an error return by SetChunk when trying to save a single 59 // chunk multiple times during the same save operation 60 type ConflictError struct { 61 X, Z int32 62 } 63 64 func (c ConflictError) Error() string { 65 return "already setting chunk " + strconv.FormatInt(int64(c.X), 10) + "," + strconv.FormatInt(int64(c.Z), 10) + ", recall SetChunk to set again" 66 } 67 68 // FilePathSetError is an error returned from SetChunk when some error is 69 // returned either from converting the nbt or saving it 70 type FilePathSetError struct { 71 X, Z int32 72 Err error 73 } 74 75 func (f FilePathSetError) Error() string { 76 return "chunk " + strconv.FormatInt(int64(f.X), 10) + "," + strconv.FormatInt(int64(f.Z), 10) + " had the following error: " + f.Err.Error() 77 } 78 79 // MultiError is an error type that contains multiple errors 80 type MultiError struct { 81 Errors []error 82 } 83 84 func (m MultiError) Error() string { 85 if len(m.Errors) == 1 { 86 return m.Errors[0].Error() 87 } 88 return "received " + strconv.FormatInt(int64(len(m.Errors)), 10) + " errors" 89 } 90