/
MaterialBlockType.java
173 lines (150 loc) · 6.35 KB
/
MaterialBlockType.java
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
package com.denizenscript.denizen.objects.properties.material;
import com.denizenscript.denizen.nms.NMSHandler;
import com.denizenscript.denizen.nms.NMSVersion;
import com.denizenscript.denizen.objects.MaterialTag;
import com.denizenscript.denizen.utilities.MultiVersionHelper1_17;
import com.denizenscript.denizencore.objects.Mechanism;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.objects.properties.Property;
import com.denizenscript.denizencore.objects.properties.PropertyParser;
import com.denizenscript.denizencore.utilities.CoreUtilities;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.type.*;
public class MaterialBlockType implements Property {
public static boolean describes(ObjectTag material) {
if (!(material instanceof MaterialTag)) {
return false;
}
MaterialTag mat = (MaterialTag) material;
if (!mat.hasModernData()) {
return false;
}
BlockData data = mat.getModernData();
return data instanceof Slab
|| data instanceof TechnicalPiston
|| data instanceof Campfire
|| (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_17) && (data instanceof PointedDripstone
|| data instanceof CaveVinesPlant));
}
public static MaterialBlockType getFrom(ObjectTag _material) {
if (!describes(_material)) {
return null;
}
else {
return new MaterialBlockType((MaterialTag) _material);
}
}
public static final String[] handledMechs = new String[] {
"type", "slab_type"
};
private MaterialBlockType(MaterialTag _material) {
material = _material;
}
public MaterialTag material;
public static void registerTags() {
// <--[tag]
// @attribute <MaterialTag.type>
// @returns ElementTag
// @mechanism MaterialTag.type
// @group properties
// @description
// Returns the current type of the block.
// For slabs, output is TOP, BOTTOM, or DOUBLE.
// For piston_heads, output is NORMAL or STICKY.
// For campfires, output is NORMAL or SIGNAL.
// For pointed dripstone, output is BASE, FRUSTUM, MIDDLE, TIP, or TIP_MERGE.
// For cave vines, output is NORMAL or BERRIES.
// -->
PropertyParser.<MaterialBlockType, ElementTag>registerStaticTag(ElementTag.class, "type", (attribute, material) -> {
return new ElementTag(material.getPropertyString());
}, "slab_type");
}
public boolean isSlab() {
return material.getModernData() instanceof Slab;
}
public boolean isPistonHead() {
return material.getModernData() instanceof TechnicalPiston;
}
public boolean isCampfire() {
return material.getModernData() instanceof Campfire;
}
public boolean isDripstone() {
return NMSHandler.getVersion().isAtLeast(NMSVersion.v1_17) && material.getModernData() instanceof PointedDripstone;
}
public boolean isCaveVines() {
return NMSHandler.getVersion().isAtLeast(NMSVersion.v1_17) && material.getModernData() instanceof CaveVinesPlant;
}
public Slab getSlab() {
return (Slab) material.getModernData();
}
public TechnicalPiston getPistonHead() {
return (TechnicalPiston) material.getModernData();
}
public Campfire getCampfire() {
return (Campfire) material.getModernData();
}
/*public PointedDripstone getDripstone() { // TODO: 1.17
return (PointedDripstone) material.getModernData();
}
public CaveVinesPlant getCaveVines() {
return (CaveVinesPlant) material.getModernData();
}*/
@Override
public String getPropertyString() {
if (isSlab()) {
return getSlab().getType().name();
}
else if (isCampfire()) {
return getCampfire().isSignalFire() ? "SIGNAL" : "NORMAL";
}
else if (isPistonHead()) {
return getPistonHead().getType().name();
}
else if (isDripstone()) {
return ((PointedDripstone) material.getModernData()).getThickness().name(); // TODO: 1.17
}
else if (isCaveVines()) {
return ((CaveVinesPlant) material.getModernData()).isBerries() ? "BERRIES" : "NORMAL"; // TODO: 1.17
}
return null; // Unreachable.
}
@Override
public String getPropertyId() {
return "type";
}
@Override
public void adjust(Mechanism mechanism) {
// <--[mechanism]
// @object MaterialTag
// @name type
// @input ElementTag
// @description
// Sets the current type of the block.
// For slabs, input is TOP, BOTTOM, or DOUBLE.
// For piston_heads, input is NORMAL or STICKY.
// For campfires, input is NORMAL or SIGNAL.
// For pointed dripstone, input is BASE, FRUSTUM, MIDDLE, TIP, or TIP_MERGE.
// For cave vines, input is NORMAL or BERRIES.
// @tags
// <MaterialTag.type>
// -->
if (mechanism.matches("type") || (mechanism.matches("slab_type"))) {
if (isSlab() && mechanism.requireEnum(false, Slab.Type.values())) {
getSlab().setType(Slab.Type.valueOf(mechanism.getValue().asString().toUpperCase()));
}
else if (isCampfire()) {
getCampfire().setSignalFire(CoreUtilities.equalsIgnoreCase(mechanism.getValue().asString(), "signal"));
}
else if (isPistonHead() && mechanism.requireEnum(false, TechnicalPiston.Type.values())) {
getPistonHead().setType(TechnicalPiston.Type.valueOf(mechanism.getValue().asString().toUpperCase()));
}
else if (isDripstone()) {
MultiVersionHelper1_17.materialBlockTypeRunMech(mechanism, this);
}
else if (isCaveVines()) {
((CaveVinesPlant) material.getModernData()).setBerries(CoreUtilities.equalsIgnoreCase(mechanism.getValue().asString(), "berries")); // TODO: 1.17
}
}
}
}