Commits
md_5 authored 52fd29c0dca
26 26 | import net.minecraft.server.DynamicOpsNBT; |
27 27 | import net.minecraft.server.IBlockData; |
28 28 | import net.minecraft.server.IRegistry; |
29 29 | import net.minecraft.server.Item; |
30 30 | import net.minecraft.server.LootDeserializationContext; |
31 31 | import net.minecraft.server.MinecraftKey; |
32 32 | import net.minecraft.server.MinecraftServer; |
33 33 | import net.minecraft.server.MojangsonParser; |
34 34 | import net.minecraft.server.NBTBase; |
35 35 | import net.minecraft.server.NBTTagCompound; |
36 + | import net.minecraft.server.NBTTagString; |
36 37 | import net.minecraft.server.SavedFile; |
37 38 | import net.minecraft.server.SharedConstants; |
38 39 | import org.bukkit.Bukkit; |
39 40 | import org.bukkit.Material; |
40 41 | import org.bukkit.NamespacedKey; |
41 42 | import org.bukkit.UnsafeValues; |
42 43 | import org.bukkit.advancement.Advancement; |
43 44 | import org.bukkit.block.data.BlockData; |
44 45 | import org.bukkit.craftbukkit.block.data.CraftBlockData; |
45 46 | import org.bukkit.craftbukkit.inventory.CraftItemStack; |
162 163 | return CraftLegacy.fromLegacy(material, itemPriority); |
163 164 | } |
164 165 | |
165 166 | |
166 167 | public BlockData fromLegacy(Material material, byte data) { |
167 168 | return CraftBlockData.fromData(getBlock(material, data)); |
168 169 | } |
169 170 | |
170 171 | |
171 172 | public Material getMaterial(String material, int version) { |
173 + | Preconditions.checkArgument(material != null, "material == null"); |
172 174 | Preconditions.checkArgument(version <= this.getDataVersion(), "Newer version! Server downgrades are not supported!"); |
173 175 | |
174 176 | // Fastpath up to date materials |
175 177 | if (version == this.getDataVersion()) { |
176 178 | return Material.getMaterial(material); |
177 179 | } |
178 180 | |
179 - | NBTTagCompound stack = new NBTTagCompound(); |
180 - | stack.setString("id", "minecraft:" + material.toLowerCase(Locale.ROOT)); |
181 + | Dynamic<NBTBase> name = new Dynamic<>(DynamicOpsNBT.a, NBTTagString.a("minecraft:" + material.toLowerCase(Locale.ROOT))); |
182 + | Dynamic<NBTBase> converted = DataConverterRegistry.a().update(DataConverterTypes.ITEM_NAME, name, version, this.getDataVersion()); |
181 183 | |
182 - | Dynamic<NBTBase> converted = DataConverterRegistry.a().update(DataConverterTypes.ITEM_STACK, new Dynamic<>(DynamicOpsNBT.a, stack), version, this.getDataVersion()); |
183 - | String newId = converted.get("id").asString(""); |
184 + | if (name.equals(converted)) { |
185 + | converted = DataConverterRegistry.a().update(DataConverterTypes.BLOCK_NAME, name, version, this.getDataVersion()); |
186 + | } |
184 187 | |
185 - | return Material.matchMaterial(newId); |
188 + | return Material.matchMaterial(converted.asString("")); |
186 189 | } |
187 190 | |
188 191 | /** |
189 192 | * This string should be changed if the NMS mappings do. |
190 193 | * |
191 194 | * It has no meaning and should only be used as an equality check. Plugins |
192 195 | * which are sensitive to the NMS mappings may read it and refuse to load if |
193 196 | * it cannot be found or is different to the expected value. |
194 197 | * |
195 198 | * Remember: NMS is not supported API and may break at any time for any |