|
8 | 8 | import com.comphenix.protocol.reflect.accessors.FieldAccessor;
|
9 | 9 | import com.comphenix.protocol.utility.MinecraftReflectionTestUtil;
|
10 | 10 |
|
| 11 | +import com.google.common.base.Preconditions; |
11 | 12 | import com.google.common.util.concurrent.MoreExecutors;
|
12 | 13 | import net.minecraft.SharedConstants;
|
13 | 14 | import net.minecraft.commands.CommandDispatcher;
|
14 | 15 | import net.minecraft.core.IRegistry;
|
15 | 16 | import net.minecraft.core.IRegistryCustom;
|
16 | 17 | import net.minecraft.core.LayeredRegistryAccess;
|
| 18 | +import net.minecraft.core.registries.BuiltInRegistries; |
| 19 | +import net.minecraft.core.registries.Registries; |
| 20 | +import net.minecraft.resources.MinecraftKey; |
17 | 21 | import net.minecraft.resources.RegistryDataLoader;
|
18 | 22 | import net.minecraft.server.DataPackResources;
|
19 | 23 | import net.minecraft.server.DispenserRegistry;
|
|
26 | 30 | import net.minecraft.server.packs.repository.ResourcePackRepository;
|
27 | 31 | import net.minecraft.server.packs.repository.ResourcePackSourceVanilla;
|
28 | 32 | import net.minecraft.server.packs.resources.ResourceManager;
|
| 33 | +import net.minecraft.tags.TagKey; |
| 34 | +import net.minecraft.world.entity.EntityTypes; |
29 | 35 | import net.minecraft.world.flag.FeatureFlags;
|
| 36 | +import net.minecraft.world.item.Item; |
30 | 37 | import net.minecraft.world.item.enchantment.Enchantments;
|
| 38 | +import net.minecraft.world.level.block.Block; |
| 39 | +import net.minecraft.world.level.material.FluidType; |
31 | 40 | import org.apache.logging.log4j.LogManager;
|
32 | 41 | import org.bukkit.Bukkit;
|
33 | 42 | import org.bukkit.Keyed;
|
|
38 | 47 | import org.bukkit.craftbukkit.v1_21_R1.CraftServer;
|
39 | 48 | import org.bukkit.craftbukkit.v1_21_R1.CraftWorld;
|
40 | 49 | import org.bukkit.craftbukkit.v1_21_R1.inventory.CraftItemFactory;
|
| 50 | +import org.bukkit.craftbukkit.v1_21_R1.tag.CraftBlockTag; |
| 51 | +import org.bukkit.craftbukkit.v1_21_R1.tag.CraftEntityTag; |
| 52 | +import org.bukkit.craftbukkit.v1_21_R1.tag.CraftFluidTag; |
| 53 | +import org.bukkit.craftbukkit.v1_21_R1.tag.CraftItemTag; |
41 | 54 | import org.bukkit.craftbukkit.v1_21_R1.util.CraftMagicNumbers;
|
| 55 | +import org.bukkit.craftbukkit.v1_21_R1.util.CraftNamespacedKey; |
42 | 56 | import org.bukkit.craftbukkit.v1_21_R1.util.Versioning;
|
43 | 57 | import org.spigotmc.SpigotWorldConfig;
|
44 | 58 |
|
@@ -151,6 +165,46 @@ private void initialize() {
|
151 | 165 | return CraftRegistry.createRegistry(registryType, registryCustom);
|
152 | 166 | });
|
153 | 167 |
|
| 168 | + when(mockedServer.getTag(any(), any(), any())).then(mock -> { |
| 169 | + String registry = mock.getArgument(0); |
| 170 | + Class<?> clazz = mock.getArgument(2); |
| 171 | + MinecraftKey key = CraftNamespacedKey.toMinecraft(mock.getArgument(1)); |
| 172 | + |
| 173 | + switch (registry) { |
| 174 | + case org.bukkit.Tag.REGISTRY_BLOCKS -> { |
| 175 | + Preconditions.checkArgument(clazz == org.bukkit.Material.class, "Block namespace must have block type"); |
| 176 | + TagKey<Block> blockTagKey = TagKey.a(Registries.f, key); |
| 177 | + if (BuiltInRegistries.e.b(blockTagKey).isPresent()) { |
| 178 | + return new CraftBlockTag(BuiltInRegistries.e, blockTagKey); |
| 179 | + } |
| 180 | + } |
| 181 | + case org.bukkit.Tag.REGISTRY_ITEMS -> { |
| 182 | + Preconditions.checkArgument(clazz == org.bukkit.Material.class, "Item namespace must have item type"); |
| 183 | + TagKey<Item> itemTagKey = TagKey.a(Registries.K, key); |
| 184 | + if (BuiltInRegistries.g.b(itemTagKey).isPresent()) { |
| 185 | + return new CraftItemTag(BuiltInRegistries.g, itemTagKey); |
| 186 | + } |
| 187 | + } |
| 188 | + case org.bukkit.Tag.REGISTRY_FLUIDS -> { |
| 189 | + Preconditions.checkArgument(clazz == org.bukkit.Fluid.class, "Fluid namespace must have fluid type"); |
| 190 | + TagKey<FluidType> fluidTagKey = TagKey.a(Registries.D, key); |
| 191 | + if (BuiltInRegistries.c.b(fluidTagKey).isPresent()) { |
| 192 | + return new CraftFluidTag(BuiltInRegistries.c, fluidTagKey); |
| 193 | + } |
| 194 | + } |
| 195 | + case org.bukkit.Tag.REGISTRY_ENTITY_TYPES -> { |
| 196 | + Preconditions.checkArgument(clazz == org.bukkit.entity.EntityType.class, "Entity type namespace must have entity type"); |
| 197 | + TagKey<EntityTypes<?>> entityTagKey = TagKey.a(Registries.z, key); |
| 198 | + if (BuiltInRegistries.f.b(entityTagKey).isPresent()) { |
| 199 | + return new CraftEntityTag(BuiltInRegistries.f, entityTagKey); |
| 200 | + } |
| 201 | + } |
| 202 | + default -> throw new IllegalArgumentException(); |
| 203 | + } |
| 204 | + |
| 205 | + return null; |
| 206 | + }); |
| 207 | + |
154 | 208 | WorldServer nmsWorld = mock(WorldServer.class);
|
155 | 209 | SpigotWorldConfig mockWorldConfig = mock(SpigotWorldConfig.class);
|
156 | 210 |
|
|
0 commit comments