blob: adb7819559e7c29394e934942f00d5284c33fed8 (
plain)
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
|
package org.bukkit.material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.Material;
/**
* Handles specific metadata for certain items or blocks
*/
public class MaterialData implements Cloneable {
private final int type;
private byte data = 0;
public MaterialData(final int type) {
this(type, (byte) 0);
}
public MaterialData(final Material type) {
this(type, (byte) 0);
}
public MaterialData(final int type, final byte data) {
this.type = type;
this.data = data;
}
public MaterialData(final Material type, final byte data) {
this(type.getId(), data);
}
/**
* Gets the raw data in this material
*
* @return Raw data
*/
public byte getData() {
return data;
}
/**
* Sets the raw data of this material
*
* @param data New raw data
*/
public void setData(byte data) {
this.data = data;
}
/**
* Gets the Material that this MaterialData represents
*
* @return Material represented by this MaterialData
*/
public Material getItemType() {
return Material.getMaterial(type);
}
/**
* Gets the Material Id that this MaterialData represents
*
* @return Material Id represented by this MaterialData
*/
public int getItemTypeId() {
return type;
}
/**
* Creates a new ItemStack based on this MaterialData
*
* @return New ItemStack containing a copy of this MaterialData
*/
public ItemStack toItemStack() {
return new ItemStack(type, 0, data);
}
/**
* Creates a new ItemStack based on this MaterialData
*
* @param amount The stack size of the new stack
* @return New ItemStack containing a copy of this MaterialData
*/
public ItemStack toItemStack(int amount) {
return new ItemStack(type, amount, data);
}
@Override
public String toString() {
return getItemType() + "(" + getData() + ")";
}
@Override
public int hashCode() {
return ((getItemTypeId() << 8) ^ getData());
}
@Override
public boolean equals(Object obj) {
if (obj != null && obj instanceof MaterialData) {
MaterialData md = (MaterialData) obj;
return (md.getItemTypeId() == getItemTypeId() && md.getData() == getData());
} else {
return false;
}
}
@Override
public MaterialData clone() {
try {
return (MaterialData) super.clone();
} catch (CloneNotSupportedException e) {
throw new Error(e);
}
}
}
|