-
-
Notifications
You must be signed in to change notification settings - Fork 89
/
item.go
118 lines (106 loc) · 4.39 KB
/
item.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
117
118
package protocol
import (
"github.com/sandertv/gophertunnel/minecraft/nbt"
)
// ItemInstance represents a unique instance of an item stack. These instances carry a specific network ID
// that is persistent for the stack.
type ItemInstance struct {
// StackNetworkID is the network ID of the item stack. If the stack is empty, 0 is always written for this
// field. If not, the field should be set to 1 if the server authoritative inventories are disabled in the
// StartGame packet, or to a unique stack ID if it is enabled.
StackNetworkID int32
// Stack is the actual item stack of the item instance.
Stack ItemStack
}
// ItemStack represents an item instance/stack over network. It has a network ID and a metadata value that
// define its type.
type ItemStack struct {
ItemType
// BlockRuntimeID ...
BlockRuntimeID int32
// Count is the count of items that the item stack holds.
Count uint16
// NBTData is a map that is serialised to its NBT representation when sent in a packet.
NBTData map[string]interface{}
// CanBePlacedOn is a list of block identifiers like 'minecraft:stone' which the item, if it is an item
// that can be placed, can be placed on top of.
CanBePlacedOn []string
// CanBreak is a list of block identifiers like 'minecraft:dirt' that the item is able to break.
CanBreak []string
// HasNetworkID ...
HasNetworkID bool
}
// ItemType represents a consistent combination of network ID and metadata value of an item. It cannot usually
// be changed unless a new item is obtained.
type ItemType struct {
// NetworkID is the numerical network ID of the item. This is sometimes a positive ID, and sometimes a
// negative ID, depending on what item it concerns.
NetworkID int32
// MetadataValue is the metadata value of the item. For some items, this is the damage value, whereas for
// other items it is simply an identifier of a variant of the item.
MetadataValue uint32
}
// RecipeIngredientItem represents an item that may be used as a recipe ingredient.
type RecipeIngredientItem struct {
// NetworkID is the numerical network ID of the item. This is sometimes a positive ID, and sometimes a
// negative ID, depending on what item it concerns.
NetworkID int32
// MetadataValue is the metadata value of the item. For some items, this is the damage value, whereas for
// other items it is simply an identifier of a variant of the item.
MetadataValue int32
// Count is the count of items that the recipe ingredient is required to have.
Count int32
}
// RecipeIngredient reads/writes a RecipeIngredientItem x using IO r.
func RecipeIngredient(r IO, x *RecipeIngredientItem) {
r.Varint32(&x.NetworkID)
if x.NetworkID == 0 {
return
}
r.Varint32(&x.MetadataValue)
r.Varint32(&x.Count)
}
// ItemEntry is an item sent in the StartGame item table. It holds a name and a legacy ID, which is used to
// point back to that name.
type ItemEntry struct {
// Name if the name of the item, which is a name like 'minecraft:stick'.
Name string
// RuntimeID is the ID that is used to identify the item over network. After sending all items in the
// StartGame packet, items will then be identified using these numerical IDs.
RuntimeID int16
// ComponentBased specifies if the item was created using components, meaning the item is a custom item.
ComponentBased bool
}
// Item reads/writes an ItemEntry x using IO r.
func Item(r IO, x *ItemEntry) {
r.String(&x.Name)
r.Int16(&x.RuntimeID)
r.Bool(&x.ComponentBased)
}
// ItemComponentEntry is sent in the ItemComponent item table. It holds a name and all of the components and
// properties associated to the item.
type ItemComponentEntry struct {
// Name is the name of the item, which is a name like 'minecraft:stick'.
Name string
// Data is a map containing the components and properties of the item.
Data map[string]interface{}
}
// ItemComponents reads/writes an ItemComponentEntry x using IO r.
func ItemComponents(r IO, x *ItemComponentEntry) {
r.String(&x.Name)
r.NBT(&x.Data, nbt.NetworkLittleEndian)
}
// MaterialReducerOutput is an output from a material reducer.
type MaterialReducerOutput struct {
// NetworkID is the network ID of the output.
NetworkID int32
// Count is the quantity of the output.
Count int32
}
// MaterialReducer is a craft in a material reducer block in education edition.
type MaterialReducer struct {
// InputItem is the starting item.
InputItem ItemType
// Outputs contain all outputting items.
Outputs []MaterialReducerOutput
}