|
31 | 31 | import java.util.HashSet; |
32 | 32 | import java.util.Iterator; |
33 | 33 | import java.util.List; |
34 | | -import java.util.Locale; |
35 | 34 | import java.util.Map; |
36 | 35 | import java.util.Optional; |
37 | 36 | import java.util.Set; |
|
91 | 90 | import com.mojang.logging.LogUtils; |
92 | 91 | import com.mojang.serialization.Codec; |
93 | 92 | import com.mojang.serialization.DataResult; |
94 | | -import com.mojang.serialization.DynamicOps; |
95 | 93 |
|
96 | 94 | import dev.jorel.commandapi.CommandAPI; |
97 | 95 | import dev.jorel.commandapi.CommandAPIHandler; |
|
138 | 136 | import net.minecraft.commands.arguments.ScoreboardSlotArgument; |
139 | 137 | import net.minecraft.commands.arguments.blocks.BlockPredicateArgument; |
140 | 138 | import net.minecraft.commands.arguments.blocks.BlockStateArgument; |
141 | | -import net.minecraft.commands.arguments.blocks.BlockStateParser; |
142 | 139 | import net.minecraft.commands.arguments.coordinates.BlockPosArgument; |
143 | 140 | import net.minecraft.commands.arguments.coordinates.ColumnPosArgument; |
144 | 141 | import net.minecraft.commands.arguments.coordinates.Vec2Argument; |
|
153 | 150 | import net.minecraft.commands.functions.InstantiatedFunction; |
154 | 151 | import net.minecraft.commands.synchronization.ArgumentUtils; |
155 | 152 | import net.minecraft.core.BlockPos; |
| 153 | +import net.minecraft.core.component.DataComponentMap; |
| 154 | +import net.minecraft.core.component.PatchedDataComponentMap; |
156 | 155 | import net.minecraft.core.particles.BlockParticleOption; |
157 | 156 | import net.minecraft.core.particles.DustColorTransitionOptions; |
158 | 157 | import net.minecraft.core.particles.DustParticleOptions; |
|
166 | 165 | import net.minecraft.core.registries.Registries; |
167 | 166 | import net.minecraft.nbt.CompoundTag; |
168 | 167 | import net.minecraft.nbt.NbtOps; |
169 | | -import net.minecraft.nbt.Tag; |
170 | 168 | import net.minecraft.network.chat.Component.Serializer; |
171 | 169 | import net.minecraft.resources.ResourceLocation; |
172 | 170 | import net.minecraft.server.MinecraftServer; |
@@ -300,59 +298,30 @@ public String[] compatibleVersions() { |
300 | 298 | }; |
301 | 299 |
|
302 | 300 | private static String serializeNMSItemStack(ItemStack is) { |
303 | | - String result = new ItemInput(is.getItemHolder(), is.getComponents()).serialize(COMMAND_BUILD_CONTEXT); |
304 | | - System.out.println("Converted is: " + result); |
305 | | - return result; |
| 301 | + final DataComponentMap patchedMap = PatchedDataComponentMap.fromPatch(PatchedDataComponentMap.EMPTY, is.getComponentsPatch()); |
| 302 | + return new ItemInput(is.getItemHolder(), patchedMap).serialize(COMMAND_BUILD_CONTEXT); |
306 | 303 | } |
307 | 304 |
|
308 | 305 | @Differs(from = "1.20.4", by = "Everything") |
309 | 306 | @Override |
310 | 307 | public final String convert(org.bukkit.inventory.ItemStack is) { |
311 | | - ItemStack itemStack = CraftItemStack.asNMSCopy(is); |
312 | | - |
313 | | - System.out.println(is.getType() + "Patch:"); |
314 | | - System.out.println(itemStack.getComponentsPatch()); |
315 | | - |
316 | | - // TODO: We need to figure out how to get this component patch |
317 | | - // which contains the "minimal set of components" into a form |
318 | | - // of standard components, which is then serializable. |
319 | | - |
320 | | - System.out.println("Serialized:"); |
321 | | - System.out.println(serializeNMSItemStack(CraftItemStack.asNMSCopy(is))); |
322 | 308 | return serializeNMSItemStack(CraftItemStack.asNMSCopy(is)); |
323 | 309 | } |
324 | 310 |
|
| 311 | + @SuppressWarnings({ "rawtypes", "unchecked" }) |
325 | 312 | @Differs(from = "1.20.4", by = "Everything") |
326 | 313 | @Override |
327 | 314 | public final String convert(ParticleData<?> particle) { |
328 | | - System.out.println("Unpacking " + particle.particle().getKey()); |
329 | 315 | final ParticleOptions particleOptions = CraftParticle.createParticleParam(particle.particle(), particle.data()); |
330 | 316 | final ResourceLocation particleKey = BuiltInRegistries.PARTICLE_TYPE.getKey(particleOptions.getType()); |
331 | | - // /particle dust{scale:2,color:[1,2,2]} |
332 | | - Codec codec = particleOptions.getType().codec().codec(); |
333 | | - DataResult result = codec.encodeStart(NbtOps.INSTANCE, particleOptions); |
334 | | - Object o = result.result().get(); |
335 | | - System.out.println("UNPACKED to " + o); |
336 | | - System.out.println(o.getClass().getName()); |
337 | | - |
338 | | -// .encodeStart(NbtOps.INSTANCE, particleOptions); |
339 | | -// |
340 | | -// |
341 | | -// // From RecipeManager#fromJson which isn't accessible |
342 | | -// final Recipe recipe = Recipe.CODEC.parse(JsonOps.INSTANCE, p.second()).getOrThrow(JsonParseException::new); |
343 | | -// return new RecipeHolder(new ResourceLocation(p.first()), recipe); |
344 | | - |
345 | | -// particleOptions.getType().codec().decoder().; |
346 | | - |
347 | | - |
348 | | - final String dataString; |
349 | | - |
350 | | - if (o.toString().equals("{}")) { |
351 | | - dataString = ""; |
352 | | - } else { |
353 | | - dataString = o.toString(); |
354 | | - } |
355 | 317 |
|
| 318 | + // /particle dust{scale:2,color:[1,2,2]} |
| 319 | + // Use the particle option's codec to convert the data into NBT. If we have any tags, add them |
| 320 | + // to the end, otherwise leave it as it is (e.g. `/particle crit` as opposed to `/particle crit{}`) |
| 321 | + final Codec codec = particleOptions.getType().codec().codec(); |
| 322 | + final DataResult<CompoundTag> result = codec.encodeStart(NbtOps.INSTANCE, particleOptions); |
| 323 | + final CompoundTag particleOptionsTag = result.result().get(); |
| 324 | + final String dataString = particleOptionsTag.getAllKeys().isEmpty() ? "" : particleOptionsTag.getAsString(); |
356 | 325 | return particleKey.toString() + dataString; |
357 | 326 | } |
358 | 327 |
|
|
0 commit comments