ItemPotionFix .java

net.minecraft.util.datafix.fixes.ItemPotionFix (class): members: POTIONS, SPLASH, DEFAULT, makeRule. strings: "minecraft:long_fire_resistance", "Damage".

net.minecraft.util.datafix.fixesclass192 linescommonextends DataFix6.9 KB

API Surface (1)

TypeRewriteRule makeRule()

Fields & Constants (3)

SPLASH
POTIONS
DEFAULT

String literals (39)

"minecraft:water"
"minecraft:regeneration"
"minecraft:swiftness"
"minecraft:fire_resistance"
"minecraft:poison"
"minecraft:healing"
"minecraft:night_vision"
"minecraft:weakness"
"minecraft:strength"
"minecraft:slowness"
"minecraft:leaping"
"minecraft:harming"
"minecraft:water_breathing"
"minecraft:invisibility"
"minecraft:awkward"
"minecraft:thick"
"minecraft:strong_regeneration"
"minecraft:strong_swiftness"
"minecraft:strong_poison"
"minecraft:strong_healing"
"minecraft:strong_strength"
"minecraft:strong_leaping"
"minecraft:strong_harming"
"minecraft:mundane"

Code Graph: Dependencies (1)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

ItemPotionFix.java192 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.util.datafix.fixes;
2
3
import com.mojang.datafixers.DSL;
4
import com.mojang.datafixers.DataFix;
5
import com.mojang.datafixers.DataFixUtils;
6
import com.mojang.datafixers.OpticFinder;
7
import com.mojang.datafixers.TypeRewriteRule;
8
import com.mojang.datafixers.Typed;
9
import com.mojang.datafixers.schemas.Schema;
10
import com.mojang.datafixers.types.Type;
11
import com.mojang.datafixers.util.Pair;
12
import com.mojang.serialization.Dynamic;
13
import java.util.Objects;
14
import java.util.Optional;
15
import net.minecraft.util.datafix.schemas.NamespacedSchema;
16
import org.jspecify.annotations.Nullable;
17
18
public class ItemPotionFix extends DataFix {
19
	private static final int SPLASH = 16384;
20
	private static final @Nullable String[] POTIONS = DataFixUtils.make(new String[128], map -> {
21
		map[0] = "minecraft:water";
22
		map[1] = "minecraft:regeneration";
23
		map[2] = "minecraft:swiftness";
24
		map[3] = "minecraft:fire_resistance";
25
		map[4] = "minecraft:poison";
26
		map[5] = "minecraft:healing";
27
		map[6] = "minecraft:night_vision";
28
		map[7] = null;
29
		map[8] = "minecraft:weakness";
30
		map[9] = "minecraft:strength";
31
		map[10] = "minecraft:slowness";
32
		map[11] = "minecraft:leaping";
33
		map[12] = "minecraft:harming";
34
		map[13] = "minecraft:water_breathing";
35
		map[14] = "minecraft:invisibility";
36
		map[15] = null;
37
		map[16] = "minecraft:awkward";
38
		map[17] = "minecraft:regeneration";
39
		map[18] = "minecraft:swiftness";
40
		map[19] = "minecraft:fire_resistance";
41
		map[20] = "minecraft:poison";
42
		map[21] = "minecraft:healing";
43
		map[22] = "minecraft:night_vision";
44
		map[23] = null;
45
		map[24] = "minecraft:weakness";
46
		map[25] = "minecraft:strength";
47
		map[26] = "minecraft:slowness";
48
		map[27] = "minecraft:leaping";
49
		map[28] = "minecraft:harming";
50
		map[29] = "minecraft:water_breathing";
51
		map[30] = "minecraft:invisibility";
52
		map[31] = null;
53
		map[32] = "minecraft:thick";
54
		map[33] = "minecraft:strong_regeneration";
55
		map[34] = "minecraft:strong_swiftness";
56
		map[35] = "minecraft:fire_resistance";
57
		map[36] = "minecraft:strong_poison";
58
		map[37] = "minecraft:strong_healing";
59
		map[38] = "minecraft:night_vision";
60
		map[39] = null;
61
		map[40] = "minecraft:weakness";
62
		map[41] = "minecraft:strong_strength";
63
		map[42] = "minecraft:slowness";
64
		map[43] = "minecraft:strong_leaping";
65
		map[44] = "minecraft:strong_harming";
66
		map[45] = "minecraft:water_breathing";
67
		map[46] = "minecraft:invisibility";
68
		map[47] = null;
69
		map[48] = null;
70
		map[49] = "minecraft:strong_regeneration";
71
		map[50] = "minecraft:strong_swiftness";
72
		map[51] = "minecraft:fire_resistance";
73
		map[52] = "minecraft:strong_poison";
74
		map[53] = "minecraft:strong_healing";
75
		map[54] = "minecraft:night_vision";
76
		map[55] = null;
77
		map[56] = "minecraft:weakness";
78
		map[57] = "minecraft:strong_strength";
79
		map[58] = "minecraft:slowness";
80
		map[59] = "minecraft:strong_leaping";
81
		map[60] = "minecraft:strong_harming";
82
		map[61] = "minecraft:water_breathing";
83
		map[62] = "minecraft:invisibility";
84
		map[63] = null;
85
		map[64] = "minecraft:mundane";
86
		map[65] = "minecraft:long_regeneration";
87
		map[66] = "minecraft:long_swiftness";
88
		map[67] = "minecraft:long_fire_resistance";
89
		map[68] = "minecraft:long_poison";
90
		map[69] = "minecraft:healing";
91
		map[70] = "minecraft:long_night_vision";
92
		map[71] = null;
93
		map[72] = "minecraft:long_weakness";
94
		map[73] = "minecraft:long_strength";
95
		map[74] = "minecraft:long_slowness";
96
		map[75] = "minecraft:long_leaping";
97
		map[76] = "minecraft:harming";
98
		map[77] = "minecraft:long_water_breathing";
99
		map[78] = "minecraft:long_invisibility";
100
		map[79] = null;
101
		map[80] = "minecraft:awkward";
102
		map[81] = "minecraft:long_regeneration";
103
		map[82] = "minecraft:long_swiftness";
104
		map[83] = "minecraft:long_fire_resistance";
105
		map[84] = "minecraft:long_poison";
106
		map[85] = "minecraft:healing";
107
		map[86] = "minecraft:long_night_vision";
108
		map[87] = null;
109
		map[88] = "minecraft:long_weakness";
110
		map[89] = "minecraft:long_strength";
111
		map[90] = "minecraft:long_slowness";
112
		map[91] = "minecraft:long_leaping";
113
		map[92] = "minecraft:harming";
114
		map[93] = "minecraft:long_water_breathing";
115
		map[94] = "minecraft:long_invisibility";
116
		map[95] = null;
117
		map[96] = "minecraft:thick";
118
		map[97] = "minecraft:regeneration";
119
		map[98] = "minecraft:swiftness";
120
		map[99] = "minecraft:long_fire_resistance";
121
		map[100] = "minecraft:poison";
122
		map[101] = "minecraft:strong_healing";
123
		map[102] = "minecraft:long_night_vision";
124
		map[103] = null;
125
		map[104] = "minecraft:long_weakness";
126
		map[105] = "minecraft:strength";
127
		map[106] = "minecraft:long_slowness";
128
		map[107] = "minecraft:leaping";
129
		map[108] = "minecraft:strong_harming";
130
		map[109] = "minecraft:long_water_breathing";
131
		map[110] = "minecraft:long_invisibility";
132
		map[111] = null;
133
		map[112] = null;
134
		map[113] = "minecraft:regeneration";
135
		map[114] = "minecraft:swiftness";
136
		map[115] = "minecraft:long_fire_resistance";
137
		map[116] = "minecraft:poison";
138
		map[117] = "minecraft:strong_healing";
139
		map[118] = "minecraft:long_night_vision";
140
		map[119] = null;
141
		map[120] = "minecraft:long_weakness";
142
		map[121] = "minecraft:strength";
143
		map[122] = "minecraft:long_slowness";
144
		map[123] = "minecraft:leaping";
145
		map[124] = "minecraft:strong_harming";
146
		map[125] = "minecraft:long_water_breathing";
147
		map[126] = "minecraft:long_invisibility";
148
		map[127] = null;
149
	});
150
	public static final String DEFAULT = "minecraft:water";
151
152
	public ItemPotionFix(final Schema outputSchema, final boolean changesType) {
153
		super(outputSchema, changesType);
154
	}
155
156
	@Override
157
	public TypeRewriteRule makeRule() {
158
		Type<?> itemStackType = this.getInputSchema().getType(References.ITEM_STACK);
159
		OpticFinder<Pair<String, String>> idFinder = DSL.fieldFinder("id", DSL.named(References.ITEM_NAME.typeName(), NamespacedSchema.namespacedString()));
160
		OpticFinder<?> tagFinder = itemStackType.findField("tag");
161
		return this.fixTypeEverywhereTyped("ItemPotionFix", itemStackType, input -> {
162
			Optional<Pair<String, String>> id = input.getOptional(idFinder);
163
			if (id.isPresent() && Objects.equals(id.get().getSecond(), "minecraft:potion")) {
164
				Dynamic<?> rest = input.get(DSL.remainderFinder());
165
				Optional<? extends Typed<?>> tag = input.getOptionalTyped(tagFinder);
166
				short damage = rest.get("Damage").asShort((short)0);
167
				if (tag.isPresent()) {
168
					Typed<?> output = input;
169
					Dynamic<?> tagRest = tag.get().get(DSL.remainderFinder());
170
					Optional<String> potion = tagRest.get("Potion").asString().result();
171
					if (potion.isEmpty()) {
172
						String potionName = POTIONS[damage & 127];
173
						Typed<?> newTag = tag.get().set(DSL.remainderFinder(), tagRest.set("Potion", tagRest.createString(potionName == null ? "minecraft:water" : potionName)));
174
						output = output.set(tagFinder, newTag);
175
						if ((damage & 16384) == 16384) {
176
							output = output.set(idFinder, Pair.of(References.ITEM_NAME.typeName(), "minecraft:splash_potion"));
177
						}
178
					}
179
180
					if (damage != 0) {
181
						rest = rest.set("Damage", rest.createShort((short)0));
182
					}
183
184
					return output.set(DSL.remainderFinder(), rest);
185
				}
186
			}
187
188
			return input;
189
		});
190
	}
191
}
192

Decompiled Minecraft 26.3 source of ItemPotionFix (net/minecraft/util/datafix/fixes/ItemPotionFix.java) with Mojang official mappings, stored verbatim on the site.