-
-
Notifications
You must be signed in to change notification settings - Fork 95
/
crafting_data.go
116 lines (110 loc) · 4.02 KB
/
crafting_data.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package packet
import (
"fmt"
"github.com/sandertv/gophertunnel/minecraft/protocol"
)
// CraftingData is sent by the server to let the client know all crafting data that the server maintains. This
// includes shapeless crafting, crafting table recipes, furnace recipes etc. Each crafting station's recipes
// are included in it.
type CraftingData struct {
// Recipes is a list of all recipes available on the server. It includes among others shapeless, shaped
// and furnace recipes. The client will only be able to craft these recipes.
Recipes []protocol.Recipe
// PotionRecipes is a list of all potion mixing recipes which may be used in the brewing stand.
PotionRecipes []protocol.PotionRecipe
// PotionContainerChangeRecipes is a list of all recipes to convert a potion from one type to another,
// such as from a drinkable potion to a splash potion, or from a splash potion to a lingering potion.
PotionContainerChangeRecipes []protocol.PotionContainerChangeRecipe
// ClearRecipes indicates if all recipes currently active on the client should be cleaned. Doing this
// means that the client will have no recipes active by itself: Any CraftingData packets previously sent
// will also be discarded, and only the recipes in this CraftingData packet will be used.
ClearRecipes bool
}
// ID ...
func (*CraftingData) ID() uint32 {
return IDCraftingData
}
// Marshal ...
func (pk *CraftingData) Marshal(w *protocol.Writer) {
l, potRecipesLen, containerRecipesLen := uint32(len(pk.Recipes)), uint32(len(pk.PotionRecipes)), uint32(len(pk.PotionContainerChangeRecipes))
w.Varuint32(&l)
for _, recipe := range pk.Recipes {
var c int32
switch recipe.(type) {
case *protocol.ShapelessRecipe:
c = protocol.RecipeShapeless
case *protocol.ShapedRecipe:
c = protocol.RecipeShaped
case *protocol.FurnaceRecipe:
c = protocol.RecipeFurnace
case *protocol.FurnaceDataRecipe:
c = protocol.RecipeFurnaceData
case *protocol.MultiRecipe:
c = protocol.RecipeMulti
case *protocol.ShulkerBoxRecipe:
c = protocol.RecipeShulkerBox
case *protocol.ShapelessChemistryRecipe:
c = protocol.RecipeShapelessChemistry
case *protocol.ShapedChemistryRecipe:
c = protocol.RecipeShapedChemistry
default:
w.UnknownEnumOption(fmt.Sprintf("%T", recipe), "crafting recipe type")
}
w.Varint32(&c)
recipe.Marshal(w)
}
w.Varuint32(&potRecipesLen)
for _, mix := range pk.PotionRecipes {
protocol.PotRecipe(w, &mix)
}
w.Varuint32(&containerRecipesLen)
for _, mix := range pk.PotionContainerChangeRecipes {
protocol.PotContainerChangeRecipe(w, &mix)
}
w.Bool(&pk.ClearRecipes)
}
// Unmarshal ...
func (pk *CraftingData) Unmarshal(r *protocol.Reader) {
var length uint32
r.Varuint32(&length)
pk.Recipes = make([]protocol.Recipe, length)
for i := uint32(0); i < length; i++ {
var recipeType int32
r.Varint32(&recipeType)
var recipe protocol.Recipe
switch recipeType {
case protocol.RecipeShapeless:
recipe = &protocol.ShapelessRecipe{}
case protocol.RecipeShaped:
recipe = &protocol.ShapedRecipe{}
case protocol.RecipeFurnace:
recipe = &protocol.FurnaceRecipe{}
case protocol.RecipeFurnaceData:
recipe = &protocol.FurnaceDataRecipe{}
case protocol.RecipeMulti:
recipe = &protocol.MultiRecipe{}
case protocol.RecipeShulkerBox:
recipe = &protocol.ShulkerBoxRecipe{}
case protocol.RecipeShapelessChemistry:
recipe = &protocol.ShapelessChemistryRecipe{}
case protocol.RecipeShapedChemistry:
recipe = &protocol.ShapedChemistryRecipe{}
default:
r.UnknownEnumOption(recipeType, "crafting data recipe type")
}
//goland:noinspection GoNilness
recipe.Unmarshal(r)
pk.Recipes[i] = recipe
}
r.Varuint32(&length)
pk.PotionRecipes = make([]protocol.PotionRecipe, length)
for i := uint32(0); i < length; i++ {
protocol.PotRecipe(r, &pk.PotionRecipes[i])
}
r.Varuint32(&length)
pk.PotionContainerChangeRecipes = make([]protocol.PotionContainerChangeRecipe, length)
for i := uint32(0); i < length; i++ {
protocol.PotContainerChangeRecipe(r, &pk.PotionContainerChangeRecipes[i])
}
r.Bool(&pk.ClearRecipes)
}