2021-07-13 01:19:40 +00:00
|
|
|
/*
|
2022-01-01 19:03:05 +00:00
|
|
|
* Copyright (c) 2019-2022 GeyserMC. http://geysermc.org
|
2021-07-13 01:19:40 +00:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*
|
|
|
|
* @author GeyserMC
|
|
|
|
* @link https://github.com/GeyserMC/Geyser
|
|
|
|
*/
|
|
|
|
|
2021-11-20 21:34:30 +00:00
|
|
|
package org.geysermc.geyser.registry;
|
2021-07-13 01:19:40 +00:00
|
|
|
|
2021-11-18 03:02:38 +00:00
|
|
|
import com.github.steveice10.mc.protocol.data.game.entity.type.EntityType;
|
2021-11-14 17:06:07 +00:00
|
|
|
import com.github.steveice10.mc.protocol.data.game.level.block.BlockEntityType;
|
2022-05-26 23:57:45 +00:00
|
|
|
import com.github.steveice10.mc.protocol.data.game.level.event.LevelEvent;
|
2021-11-18 03:02:38 +00:00
|
|
|
import com.github.steveice10.mc.protocol.data.game.level.particle.ParticleType;
|
2021-07-13 01:19:40 +00:00
|
|
|
import com.github.steveice10.mc.protocol.data.game.recipe.RecipeType;
|
2021-11-20 23:29:46 +00:00
|
|
|
import com.github.steveice10.packetlib.packet.Packet;
|
2021-07-13 01:19:40 +00:00
|
|
|
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
|
|
|
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
2021-07-28 00:29:27 +00:00
|
|
|
import it.unimi.dsi.fastutil.objects.Object2IntMap;
|
2021-11-18 03:02:38 +00:00
|
|
|
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
2022-12-21 00:47:45 +00:00
|
|
|
import org.cloudburstmc.nbt.NbtMap;
|
|
|
|
import org.cloudburstmc.nbt.NbtMapBuilder;
|
|
|
|
import org.cloudburstmc.protocol.bedrock.data.inventory.crafting.PotionMixData;
|
2023-02-14 22:09:48 +00:00
|
|
|
import org.cloudburstmc.protocol.bedrock.data.inventory.crafting.recipe.RecipeData;
|
2022-10-30 00:23:21 +00:00
|
|
|
import org.cloudburstmc.protocol.bedrock.packet.BedrockPacket;
|
2023-06-17 01:39:53 +00:00
|
|
|
import org.geysermc.geyser.GeyserImpl;
|
|
|
|
import org.geysermc.geyser.api.pack.ResourcePack;
|
2021-11-20 21:34:30 +00:00
|
|
|
import org.geysermc.geyser.entity.EntityDefinition;
|
2021-11-20 23:29:46 +00:00
|
|
|
import org.geysermc.geyser.inventory.item.Enchantment.JavaEnchantment;
|
2022-02-21 21:11:51 +00:00
|
|
|
import org.geysermc.geyser.inventory.recipe.GeyserRecipe;
|
2022-12-29 20:10:40 +00:00
|
|
|
import org.geysermc.geyser.item.type.Item;
|
2021-11-20 21:34:30 +00:00
|
|
|
import org.geysermc.geyser.registry.loader.*;
|
|
|
|
import org.geysermc.geyser.registry.populator.ItemRegistryPopulator;
|
2022-02-02 01:15:31 +00:00
|
|
|
import org.geysermc.geyser.registry.populator.PacketRegistryPopulator;
|
2021-11-20 21:34:30 +00:00
|
|
|
import org.geysermc.geyser.registry.populator.RecipeRegistryPopulator;
|
2022-07-09 22:39:02 +00:00
|
|
|
import org.geysermc.geyser.registry.provider.ProviderSupplier;
|
2021-11-20 21:34:30 +00:00
|
|
|
import org.geysermc.geyser.registry.type.EnchantmentData;
|
|
|
|
import org.geysermc.geyser.registry.type.ItemMappings;
|
|
|
|
import org.geysermc.geyser.registry.type.ParticleMapping;
|
|
|
|
import org.geysermc.geyser.registry.type.SoundMapping;
|
2022-02-02 01:15:31 +00:00
|
|
|
import org.geysermc.geyser.translator.level.block.entity.BlockEntityTranslator;
|
|
|
|
import org.geysermc.geyser.translator.level.event.LevelEventTranslator;
|
|
|
|
import org.geysermc.geyser.translator.sound.SoundInteractionTranslator;
|
|
|
|
import org.geysermc.geyser.translator.sound.SoundTranslator;
|
2021-07-13 01:19:40 +00:00
|
|
|
|
2022-07-09 22:39:02 +00:00
|
|
|
import java.util.*;
|
2021-07-13 01:19:40 +00:00
|
|
|
|
2021-07-22 02:14:00 +00:00
|
|
|
/**
|
|
|
|
* Holds all the common registries in Geyser.
|
|
|
|
*/
|
2021-11-28 16:03:45 +00:00
|
|
|
public final class Registries {
|
2023-08-21 23:04:08 +00:00
|
|
|
/**
|
|
|
|
* A registry holding all the providers.
|
|
|
|
* This has to be initialized first to allow extensions to access providers during other registry events.
|
|
|
|
*/
|
|
|
|
public static final SimpleMappedRegistry<Class<?>, ProviderSupplier> PROVIDERS = SimpleMappedRegistry.create(new IdentityHashMap<>(), ProviderRegistryLoader::new);
|
|
|
|
|
2021-11-18 03:02:38 +00:00
|
|
|
/**
|
|
|
|
* A registry holding a CompoundTag of the known entity identifiers.
|
|
|
|
*/
|
|
|
|
public static final SimpleRegistry<NbtMap> BEDROCK_ENTITY_IDENTIFIERS = SimpleRegistry.create("bedrock/entity_identifiers.dat", RegistryLoaders.NBT);
|
|
|
|
|
2021-11-20 23:29:46 +00:00
|
|
|
/**
|
|
|
|
* A registry containing all the Bedrock packet translators.
|
|
|
|
*/
|
|
|
|
public static final PacketTranslatorRegistry<BedrockPacket> BEDROCK_PACKET_TRANSLATORS = PacketTranslatorRegistry.create();
|
|
|
|
|
2021-07-22 03:18:31 +00:00
|
|
|
/**
|
|
|
|
* A registry holding a CompoundTag of all the known biomes.
|
|
|
|
*/
|
2021-07-28 00:29:27 +00:00
|
|
|
public static final SimpleRegistry<NbtMap> BIOMES_NBT = SimpleRegistry.create("bedrock/biome_definitions.dat", RegistryLoaders.NBT);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A mapped registry which stores Java biome identifiers and their Bedrock biome identifier.
|
|
|
|
*/
|
|
|
|
public static final SimpleRegistry<Object2IntMap<String>> BIOME_IDENTIFIERS = SimpleRegistry.create("mappings/biomes.json", BiomeIdentifierRegistryLoader::new);
|
2021-07-13 01:19:40 +00:00
|
|
|
|
2021-07-22 03:18:31 +00:00
|
|
|
/**
|
|
|
|
* A mapped registry which stores a block entity identifier to its {@link BlockEntityTranslator}.
|
|
|
|
*/
|
2021-11-20 23:29:46 +00:00
|
|
|
public static final SimpleMappedRegistry<BlockEntityType, BlockEntityTranslator> BLOCK_ENTITIES = SimpleMappedRegistry.create("org.geysermc.geyser.translator.level.block.entity.BlockEntity", BlockEntityRegistryLoader::new);
|
2021-07-13 01:19:40 +00:00
|
|
|
|
2021-07-22 03:18:31 +00:00
|
|
|
/**
|
2023-02-14 22:09:48 +00:00
|
|
|
* A versioned registry which holds a {@link RecipeType} to a corresponding list of {@link RecipeData}.
|
2021-07-22 03:18:31 +00:00
|
|
|
*/
|
2023-02-14 22:09:48 +00:00
|
|
|
public static final VersionedRegistry<Map<RecipeType, List<RecipeData>>> CRAFTING_DATA = VersionedRegistry.create(RegistryLoaders.empty(Int2ObjectOpenHashMap::new));
|
2021-07-13 01:19:40 +00:00
|
|
|
|
2021-11-15 01:15:25 +00:00
|
|
|
/**
|
|
|
|
* A registry holding data of all the known enchantments.
|
|
|
|
*/
|
|
|
|
public static final SimpleMappedRegistry<JavaEnchantment, EnchantmentData> ENCHANTMENTS;
|
|
|
|
|
2021-07-22 03:18:31 +00:00
|
|
|
/**
|
2021-11-18 03:02:38 +00:00
|
|
|
* A map containing all entity types and their respective Geyser definitions
|
|
|
|
*/
|
|
|
|
public static final SimpleMappedRegistry<EntityType, EntityDefinition<?>> ENTITY_DEFINITIONS = SimpleMappedRegistry.create(RegistryLoaders.empty(() -> new EnumMap<>(EntityType.class)));
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A map containing all Java entity identifiers and their respective Geyser definitions
|
2021-07-22 03:18:31 +00:00
|
|
|
*/
|
2021-11-18 03:02:38 +00:00
|
|
|
public static final SimpleMappedRegistry<String, EntityDefinition<?>> JAVA_ENTITY_IDENTIFIERS = SimpleMappedRegistry.create(RegistryLoaders.empty(Object2ObjectOpenHashMap::new));
|
2021-07-13 01:19:40 +00:00
|
|
|
|
2021-11-20 23:29:46 +00:00
|
|
|
/**
|
|
|
|
* A registry containing all the Java packet translators.
|
|
|
|
*/
|
|
|
|
public static final PacketTranslatorRegistry<Packet> JAVA_PACKET_TRANSLATORS = PacketTranslatorRegistry.create();
|
|
|
|
|
2022-12-29 20:10:40 +00:00
|
|
|
public static final SimpleRegistry<List<Item>> JAVA_ITEMS = SimpleRegistry.create(RegistryLoaders.empty(ArrayList::new));
|
|
|
|
|
|
|
|
public static final SimpleMappedRegistry<String, Item> JAVA_ITEM_IDENTIFIERS = SimpleMappedRegistry.create(RegistryLoaders.empty(Object2ObjectOpenHashMap::new));
|
|
|
|
|
2021-07-22 03:18:31 +00:00
|
|
|
/**
|
|
|
|
* A versioned registry which holds {@link ItemMappings} for each version. These item mappings contain
|
|
|
|
* primarily Bedrock version-specific data.
|
|
|
|
*/
|
2021-07-13 01:19:40 +00:00
|
|
|
public static final VersionedRegistry<ItemMappings> ITEMS = VersionedRegistry.create(RegistryLoaders.empty(Int2ObjectOpenHashMap::new));
|
|
|
|
|
2021-07-22 03:18:31 +00:00
|
|
|
/**
|
|
|
|
* A mapped registry holding the {@link ParticleType} to a corresponding {@link ParticleMapping}, containing various pieces of
|
|
|
|
* data primarily for how Bedrock should handle the particle.
|
|
|
|
*/
|
2021-07-13 01:19:40 +00:00
|
|
|
public static final SimpleMappedRegistry<ParticleType, ParticleMapping> PARTICLES = SimpleMappedRegistry.create("mappings/particles.json", ParticleTypesRegistryLoader::new);
|
|
|
|
|
2021-07-22 03:18:31 +00:00
|
|
|
/**
|
|
|
|
* A registry holding all the potion mixes.
|
|
|
|
*/
|
2023-03-17 23:07:31 +00:00
|
|
|
public static final VersionedRegistry<Set<PotionMixData>> POTION_MIXES;
|
2021-07-13 01:19:40 +00:00
|
|
|
|
2021-07-22 03:18:31 +00:00
|
|
|
/**
|
2022-02-22 01:51:31 +00:00
|
|
|
* A versioned registry holding all the recipes, with the net ID being the key, and {@link GeyserRecipe} as the value.
|
2021-07-22 03:18:31 +00:00
|
|
|
*/
|
2022-02-21 21:11:51 +00:00
|
|
|
public static final VersionedRegistry<Int2ObjectMap<GeyserRecipe>> RECIPES = VersionedRegistry.create(RegistryLoaders.empty(Int2ObjectOpenHashMap::new));
|
2021-07-13 01:19:40 +00:00
|
|
|
|
2021-07-22 03:18:31 +00:00
|
|
|
/**
|
2022-10-30 00:23:21 +00:00
|
|
|
* A mapped registry holding the available records, with the ID of the record being the key, and the {@link org.cloudburstmc.protocol.bedrock.data.SoundEvent}
|
2021-07-22 03:18:31 +00:00
|
|
|
* as the value.
|
|
|
|
*/
|
2022-10-30 00:23:21 +00:00
|
|
|
public static final IntMappedRegistry<org.cloudburstmc.protocol.bedrock.data.SoundEvent> RECORDS = IntMappedRegistry.create(RegistryLoaders.empty(Int2ObjectOpenHashMap::new));
|
2021-07-13 01:19:40 +00:00
|
|
|
|
2023-06-17 01:39:53 +00:00
|
|
|
/**
|
|
|
|
* A mapped registry holding {@link ResourcePack}'s with the pack uuid as keys.
|
|
|
|
*/
|
|
|
|
public static final DeferredRegistry<Map<String, ResourcePack>> RESOURCE_PACKS = DeferredRegistry.create(GeyserImpl.getInstance().packDirectory(), SimpleMappedRegistry::create, RegistryLoaders.RESOURCE_PACKS);
|
|
|
|
|
2021-07-22 03:18:31 +00:00
|
|
|
/**
|
|
|
|
* A mapped registry holding sound identifiers to their corresponding {@link SoundMapping}.
|
|
|
|
*/
|
2021-07-13 01:19:40 +00:00
|
|
|
public static final SimpleMappedRegistry<String, SoundMapping> SOUNDS = SimpleMappedRegistry.create("mappings/sounds.json", SoundRegistryLoader::new);
|
|
|
|
|
2021-07-22 03:18:31 +00:00
|
|
|
/**
|
2022-05-26 23:57:45 +00:00
|
|
|
* A mapped registry holding {@link LevelEvent}s to their corresponding {@link LevelEventTranslator}.
|
2021-07-22 03:18:31 +00:00
|
|
|
*/
|
2022-05-26 23:57:45 +00:00
|
|
|
public static final SimpleMappedRegistry<LevelEvent, LevelEventTranslator> SOUND_LEVEL_EVENTS = SimpleMappedRegistry.create("mappings/effects.json", SoundEventsRegistryLoader::new);
|
2021-07-13 01:19:40 +00:00
|
|
|
|
2021-07-22 03:18:31 +00:00
|
|
|
/**
|
2021-11-20 23:29:46 +00:00
|
|
|
* A mapped registry holding {@link SoundTranslator}s to their corresponding {@link SoundInteractionTranslator}.
|
2021-07-22 03:18:31 +00:00
|
|
|
*/
|
2021-11-20 23:29:46 +00:00
|
|
|
public static final SimpleMappedRegistry<SoundTranslator, SoundInteractionTranslator<?>> SOUND_TRANSLATORS = SimpleMappedRegistry.create("org.geysermc.geyser.translator.sound.SoundTranslator", SoundTranslatorRegistryLoader::new);
|
2021-07-13 01:19:40 +00:00
|
|
|
|
|
|
|
public static void init() {
|
|
|
|
// no-op
|
|
|
|
}
|
|
|
|
|
|
|
|
static {
|
2021-11-20 23:29:46 +00:00
|
|
|
PacketRegistryPopulator.populate();
|
2021-07-13 01:19:40 +00:00
|
|
|
ItemRegistryPopulator.populate();
|
|
|
|
RecipeRegistryPopulator.populate();
|
|
|
|
|
|
|
|
// Create registries that require other registries to load first
|
2023-03-17 23:07:31 +00:00
|
|
|
POTION_MIXES = VersionedRegistry.create(PotionMixRegistryLoader::new);
|
2021-11-15 01:15:25 +00:00
|
|
|
ENCHANTMENTS = SimpleMappedRegistry.create("mappings/enchantments.json", EnchantmentRegistryLoader::new);
|
2022-09-21 16:27:16 +00:00
|
|
|
|
2022-12-09 18:39:24 +00:00
|
|
|
// Remove unneeded client generation data from NbtMapBuilder
|
2022-09-21 16:27:16 +00:00
|
|
|
NbtMapBuilder biomesNbt = NbtMap.builder();
|
|
|
|
for (Map.Entry<String, Object> entry : BIOMES_NBT.get().entrySet()) {
|
|
|
|
String key = entry.getKey();
|
|
|
|
NbtMapBuilder value = ((NbtMap) entry.getValue()).toBuilder();
|
2022-12-09 18:39:24 +00:00
|
|
|
value.remove("minecraft:consolidated_features");
|
|
|
|
value.remove("minecraft:multinoise_generation_rules");
|
|
|
|
value.remove("minecraft:surface_material_adjustments");
|
|
|
|
value.remove( "minecraft:surface_parameters");
|
2022-09-21 16:27:16 +00:00
|
|
|
biomesNbt.put(key, value.build());
|
|
|
|
}
|
|
|
|
BIOMES_NBT.set(biomesNbt.build());
|
2021-07-13 01:19:40 +00:00
|
|
|
}
|
2023-02-14 22:09:48 +00:00
|
|
|
}
|