|
30 | 30 | import org.bukkit.command.CommandSender; |
31 | 31 | import org.bukkit.command.SimpleCommandMap; |
32 | 32 | import org.bukkit.craftbukkit.v1_20_R4.CraftParticle; |
| 33 | +import org.bukkit.craftbukkit.v1_20_R4.CraftRegistry; |
33 | 34 | import org.bukkit.craftbukkit.v1_20_R4.CraftWorld; |
34 | 35 | import org.bukkit.craftbukkit.v1_20_R4.entity.CraftPlayer; |
35 | 36 | import org.bukkit.craftbukkit.v1_20_R4.inventory.CraftItemFactory; |
| 37 | +import org.bukkit.craftbukkit.v1_20_R4.util.CraftNamespacedKey; |
36 | 38 | import org.bukkit.enchantments.Enchantment; |
37 | 39 | import org.bukkit.entity.Player; |
38 | 40 | import org.bukkit.help.HelpTopic; |
|
41 | 43 | import org.bukkit.scoreboard.Team; |
42 | 44 | import org.jetbrains.annotations.NotNull; |
43 | 45 | import org.jetbrains.annotations.Nullable; |
| 46 | +import org.mockito.MockedStatic; |
44 | 47 | import org.mockito.Mockito; |
45 | 48 |
|
46 | 49 | import com.google.gson.JsonParseException; |
|
67 | 70 | import net.minecraft.commands.functions.CommandFunction; |
68 | 71 | import net.minecraft.core.BlockPos; |
69 | 72 | import net.minecraft.core.HolderLookup; |
| 73 | +import net.minecraft.core.Registry; |
| 74 | +import net.minecraft.core.RegistryAccess; |
| 75 | +import net.minecraft.core.particles.ParticleType; |
70 | 76 | import net.minecraft.core.registries.BuiltInRegistries; |
| 77 | +import net.minecraft.core.registries.Registries; |
71 | 78 | import net.minecraft.network.chat.Component; |
72 | 79 | import net.minecraft.network.chat.numbers.BlankFormat; |
73 | 80 | import net.minecraft.resources.ResourceKey; |
@@ -160,6 +167,24 @@ public MockNMS(CommandAPIBukkit<?> baseNMS) { |
160 | 167 | } |
161 | 168 | return null; |
162 | 169 | }); |
| 170 | + |
| 171 | + // CraftBukkit's registry is shared across all instances of a test (or all tests?) |
| 172 | + if (CraftRegistry.getMinecraftRegistry() == null) { |
| 173 | + RegistryAccess registry = Mockito.mock(RegistryAccess.class); |
| 174 | + Mockito.when(registry.registry(any())).thenAnswer(args -> { |
| 175 | + ResourceKey key = args.getArgument(0); |
| 176 | + System.out.println("Trying to access registry: " + key.registry()); |
| 177 | + Thread.currentThread().dumpStack(); |
| 178 | + return Optional.ofNullable(null); |
| 179 | + }); |
| 180 | + Mockito.when(registry.registryOrThrow(any())).thenAnswer(args -> { |
| 181 | + ResourceKey key = args.getArgument(0); |
| 182 | + System.out.println("Trying to access registry: " + key.registry()); |
| 183 | + Thread.currentThread().dumpStack(); |
| 184 | + return null; |
| 185 | + }); |
| 186 | + CraftRegistry.setMinecraftRegistry(registry); |
| 187 | + } |
163 | 188 | } |
164 | 189 |
|
165 | 190 | /************************* |
@@ -412,11 +437,13 @@ public String getBukkitPotionEffectTypeName(PotionEffectType potionEffectType) { |
412 | 437 |
|
413 | 438 | @Override |
414 | 439 | public String getNMSParticleNameFromBukkit(Particle particle) { |
| 440 | + // CraftRegistry.setMinecraftRegistry(this.<MinecraftServer>getMinecraftServer().getServer().registryAccess()); |
415 | 441 | // Didn't want to do it like this, but it's way easier than going via the |
416 | 442 | // registry to do all sorts of nonsense with lookups. If you ever want to |
417 | 443 | // change your mind, here's how to access it via the registry. This doesn't |
418 | 444 | // scale well for pre 1.19 versions though! |
419 | 445 | // BuiltInRegistries.PARTICLE_TYPE.getKey(CraftParticle.toNMS(particle).getType()).toString(); |
| 446 | + particle.getKey(); |
420 | 447 | return BuiltInRegistries.PARTICLE_TYPE.getKey(CraftParticle.bukkitToMinecraft(particle)).toString(); |
421 | 448 | // return particle.getKey().toString(); |
422 | 449 | } |
|
0 commit comments