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
|
|
|
|
2023-08-21 23:04:08 +00:00
|
|
|
import it.unimi.dsi.fastutil.Pair;
|
|
|
|
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
2021-07-13 01:19:40 +00:00
|
|
|
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
2023-04-07 01:47:37 +00:00
|
|
|
import it.unimi.dsi.fastutil.objects.Object2IntMap;
|
|
|
|
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
|
2021-07-13 01:19:40 +00:00
|
|
|
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
2023-08-21 23:04:08 +00:00
|
|
|
import org.geysermc.geyser.api.block.custom.CustomBlockData;
|
|
|
|
import org.geysermc.geyser.api.block.custom.CustomBlockState;
|
|
|
|
import org.geysermc.geyser.api.block.custom.nonvanilla.JavaBlockState;
|
|
|
|
import org.geysermc.geyser.registry.loader.CollisionRegistryLoader;
|
2021-11-20 21:34:30 +00:00
|
|
|
import org.geysermc.geyser.registry.loader.RegistryLoaders;
|
|
|
|
import org.geysermc.geyser.registry.populator.BlockRegistryPopulator;
|
2023-08-21 23:04:08 +00:00
|
|
|
import org.geysermc.geyser.registry.populator.CustomBlockRegistryPopulator;
|
|
|
|
import org.geysermc.geyser.registry.populator.CustomSkullRegistryPopulator;
|
2021-11-20 21:34:30 +00:00
|
|
|
import org.geysermc.geyser.registry.type.BlockMapping;
|
|
|
|
import org.geysermc.geyser.registry.type.BlockMappings;
|
2023-08-21 23:04:08 +00:00
|
|
|
import org.geysermc.geyser.registry.type.CustomSkull;
|
|
|
|
import org.geysermc.geyser.translator.collision.BlockCollision;
|
2023-04-07 01:47:37 +00:00
|
|
|
|
|
|
|
import java.util.BitSet;
|
2021-07-13 01:19:40 +00:00
|
|
|
|
2023-08-21 23:04:08 +00:00
|
|
|
import java.util.Set;
|
|
|
|
|
2021-07-22 02:14:00 +00:00
|
|
|
/**
|
|
|
|
* Holds all the block registries in Geyser.
|
|
|
|
*/
|
2021-07-13 01:19:40 +00:00
|
|
|
public class BlockRegistries {
|
2021-07-22 03:18:31 +00:00
|
|
|
/**
|
|
|
|
* A versioned registry which holds {@link BlockMappings} for each version. These block mappings contain
|
|
|
|
* primarily Bedrock version-specific data.
|
|
|
|
*/
|
2021-07-13 01:19:40 +00:00
|
|
|
public static final VersionedRegistry<BlockMappings> BLOCKS = VersionedRegistry.create(RegistryLoaders.empty(Int2ObjectOpenHashMap::new));
|
|
|
|
|
2021-07-22 03:18:31 +00:00
|
|
|
/**
|
|
|
|
* A mapped registry which stores Java to Bedrock block identifiers.
|
|
|
|
*/
|
2021-07-13 01:19:40 +00:00
|
|
|
public static final SimpleMappedRegistry<String, String> JAVA_TO_BEDROCK_IDENTIFIERS = SimpleMappedRegistry.create(RegistryLoaders.empty(Object2ObjectOpenHashMap::new));
|
|
|
|
|
2021-07-22 03:18:31 +00:00
|
|
|
/**
|
2021-09-04 17:36:09 +00:00
|
|
|
* A registry which stores Java IDs to {@link BlockMapping}, containing miscellaneous information about
|
2021-07-22 03:18:31 +00:00
|
|
|
* blocks and their behavior in many cases.
|
|
|
|
*/
|
2023-04-07 01:47:37 +00:00
|
|
|
public static final ArrayRegistry<BlockMapping> JAVA_BLOCKS = ArrayRegistry.create(RegistryLoaders.uninitialized());
|
2021-07-13 01:19:40 +00:00
|
|
|
|
2023-08-21 23:04:08 +00:00
|
|
|
/**
|
|
|
|
* A mapped registry containing which holds block IDs to its {@link BlockCollision}.
|
|
|
|
*/
|
|
|
|
public static final IntMappedRegistry<BlockCollision> COLLISIONS;
|
|
|
|
|
2021-07-22 03:18:31 +00:00
|
|
|
/**
|
2023-04-07 01:47:37 +00:00
|
|
|
* A mapped registry containing the Java identifiers to IDs.
|
2021-07-22 03:18:31 +00:00
|
|
|
*/
|
2023-04-07 01:47:37 +00:00
|
|
|
public static final MappedRegistry<String, Integer, Object2IntMap<String>> JAVA_IDENTIFIER_TO_ID = MappedRegistry.create(RegistryLoaders.empty(Object2IntOpenHashMap::new));
|
2021-07-13 01:19:40 +00:00
|
|
|
|
2021-12-08 01:05:44 +00:00
|
|
|
/**
|
|
|
|
* A registry which stores unique Java IDs to its clean identifier
|
|
|
|
* This is used in the statistics form.
|
|
|
|
*/
|
2023-04-07 01:47:37 +00:00
|
|
|
public static final ArrayRegistry<String> CLEAN_JAVA_IDENTIFIERS = ArrayRegistry.create(RegistryLoaders.uninitialized());
|
2021-12-08 01:05:44 +00:00
|
|
|
|
2021-07-22 03:18:31 +00:00
|
|
|
/**
|
|
|
|
* A registry containing all the waterlogged blockstates.
|
|
|
|
*/
|
2023-04-07 01:47:37 +00:00
|
|
|
public static final SimpleRegistry<BitSet> WATERLOGGED = SimpleRegistry.create(RegistryLoaders.empty(BitSet::new));
|
2021-07-13 01:19:40 +00:00
|
|
|
|
2022-06-24 20:48:28 +00:00
|
|
|
/**
|
|
|
|
* A registry containing all blockstates which are always interactive.
|
|
|
|
*/
|
2023-04-07 01:47:37 +00:00
|
|
|
public static final SimpleRegistry<BitSet> INTERACTIVE = SimpleRegistry.create(RegistryLoaders.uninitialized());
|
2022-06-24 20:48:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A registry containing all blockstates which are interactive if the player has the may build permission.
|
|
|
|
*/
|
2023-04-07 01:47:37 +00:00
|
|
|
public static final SimpleRegistry<BitSet> INTERACTIVE_MAY_BUILD = SimpleRegistry.create(RegistryLoaders.uninitialized());
|
2022-06-24 20:48:28 +00:00
|
|
|
|
2023-08-21 23:04:08 +00:00
|
|
|
/**
|
|
|
|
* A registry containing all the custom blocks.
|
|
|
|
*/
|
|
|
|
public static final ArrayRegistry<CustomBlockData> CUSTOM_BLOCKS = ArrayRegistry.create(RegistryLoaders.empty(() -> new CustomBlockData[] {}));
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A registry which stores Java Ids and the custom block state it should be replaced with.
|
|
|
|
*/
|
|
|
|
public static final MappedRegistry<Integer, CustomBlockState, Int2ObjectMap<CustomBlockState>> CUSTOM_BLOCK_STATE_OVERRIDES = MappedRegistry.create(RegistryLoaders.empty(Int2ObjectOpenHashMap::new));
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A registry which stores non vanilla java blockstates and the custom block state it should be replaced with.
|
|
|
|
*/
|
|
|
|
public static final SimpleMappedRegistry<JavaBlockState, CustomBlockState> NON_VANILLA_BLOCK_STATE_OVERRIDES = SimpleMappedRegistry.create(RegistryLoaders.empty(Object2ObjectOpenHashMap::new));
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A registry which stores clean Java Ids and the custom block it should be replaced with in the context of items.
|
|
|
|
*/
|
|
|
|
public static final SimpleMappedRegistry<String, CustomBlockData> CUSTOM_BLOCK_ITEM_OVERRIDES = SimpleMappedRegistry.create(RegistryLoaders.empty(Object2ObjectOpenHashMap::new));
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A registry which stores Custom Block Data for extended collision boxes and the Java IDs of blocks that will have said extended collision boxes placed above them.
|
|
|
|
*/
|
|
|
|
public static final SimpleMappedRegistry<CustomBlockData, Set<Integer>> EXTENDED_COLLISION_BOXES = SimpleMappedRegistry.create(RegistryLoaders.empty(Object2ObjectOpenHashMap::new));
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A registry which stores skin texture hashes to custom skull blocks.
|
|
|
|
*/
|
|
|
|
public static final SimpleMappedRegistry<String, CustomSkull> CUSTOM_SKULLS = SimpleMappedRegistry.create(RegistryLoaders.empty(Object2ObjectOpenHashMap::new));
|
|
|
|
|
2021-07-13 01:19:40 +00:00
|
|
|
static {
|
2023-08-21 23:04:08 +00:00
|
|
|
CustomSkullRegistryPopulator.populate();
|
|
|
|
BlockRegistryPopulator.populate(BlockRegistryPopulator.Stage.PRE_INIT);
|
|
|
|
CustomBlockRegistryPopulator.populate(CustomBlockRegistryPopulator.Stage.DEFINITION);
|
|
|
|
CustomBlockRegistryPopulator.populate(CustomBlockRegistryPopulator.Stage.NON_VANILLA_REGISTRATION);
|
|
|
|
BlockRegistryPopulator.populate(BlockRegistryPopulator.Stage.INIT_JAVA);
|
|
|
|
COLLISIONS = IntMappedRegistry.create(Pair.of("org.geysermc.geyser.translator.collision.CollisionRemapper", "mappings/collision.json"), CollisionRegistryLoader::new);
|
|
|
|
CustomBlockRegistryPopulator.populate(CustomBlockRegistryPopulator.Stage.VANILLA_REGISTRATION);
|
|
|
|
CustomBlockRegistryPopulator.populate(CustomBlockRegistryPopulator.Stage.CUSTOM_REGISTRATION);
|
|
|
|
BlockRegistryPopulator.populate(BlockRegistryPopulator.Stage.INIT_BEDROCK);
|
|
|
|
BlockRegistryPopulator.populate(BlockRegistryPopulator.Stage.POST_INIT);
|
2021-07-13 01:19:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void init() {
|
|
|
|
// no-op
|
|
|
|
}
|
2023-08-21 23:04:08 +00:00
|
|
|
|
2021-07-13 01:19:40 +00:00
|
|
|
}
|