From d019160939402d96df3fd37dd64b8c203b4b624b Mon Sep 17 00:00:00 2001 From: Joshua Castle <26531652+Kas-tle@users.noreply.github.com> Date: Thu, 5 Jan 2023 22:28:32 -0800 Subject: [PATCH] add registerBlockItemOverride event + refactor --- .../event/lifecycle/GeyserDefineCustomBlocksEvent.java | 9 +++++++++ .../geyser/registry/mappings/MappingsConfigReader.java | 2 +- .../registry/mappings/util}/CustomBlockMapping.java | 4 +++- .../registry/mappings/versions/MappingsReader.java | 2 +- .../registry/mappings/versions/MappingsReader_v1.java | 4 ++-- .../registry/populator/CustomBlockRegistryPopulator.java | 8 ++++++++ 6 files changed, 24 insertions(+), 5 deletions(-) rename {api/geyser/src/main/java/org/geysermc/geyser/api/block/custom => core/src/main/java/org/geysermc/geyser/registry/mappings/util}/CustomBlockMapping.java (90%) diff --git a/api/geyser/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineCustomBlocksEvent.java b/api/geyser/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineCustomBlocksEvent.java index bc8db82b8..c821c593a 100644 --- a/api/geyser/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineCustomBlocksEvent.java +++ b/api/geyser/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineCustomBlocksEvent.java @@ -54,4 +54,13 @@ public abstract class GeyserDefineCustomBlocksEvent implements Event { * @param customBlockState the custom block state with which to override java state identifier */ public abstract void registerBlockStateOverride(@NonNull String javaIdentifier, @NonNull CustomBlockState customBlockState); + + /** + * Registers the given {@link CustomBlockData} as an override for the + * given java item identifier + * + * @param javaIdentifier the java item identifier to override + * @param customBlockData the custom block data with which to override java item identifier + */ + public abstract void registerBlockItemOverride(@NonNull String javaIdentifier, @NonNull CustomBlockData customBlockData); } diff --git a/core/src/main/java/org/geysermc/geyser/registry/mappings/MappingsConfigReader.java b/core/src/main/java/org/geysermc/geyser/registry/mappings/MappingsConfigReader.java index 3eb195517..039412957 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/mappings/MappingsConfigReader.java +++ b/core/src/main/java/org/geysermc/geyser/registry/mappings/MappingsConfigReader.java @@ -29,8 +29,8 @@ import com.fasterxml.jackson.databind.JsonNode; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import org.geysermc.geyser.GeyserImpl; -import org.geysermc.geyser.api.block.custom.CustomBlockMapping; import org.geysermc.geyser.api.item.custom.CustomItemData; +import org.geysermc.geyser.registry.mappings.util.CustomBlockMapping; import org.geysermc.geyser.registry.mappings.versions.MappingsReader; import org.geysermc.geyser.registry.mappings.versions.MappingsReader_v1; diff --git a/api/geyser/src/main/java/org/geysermc/geyser/api/block/custom/CustomBlockMapping.java b/core/src/main/java/org/geysermc/geyser/registry/mappings/util/CustomBlockMapping.java similarity index 90% rename from api/geyser/src/main/java/org/geysermc/geyser/api/block/custom/CustomBlockMapping.java rename to core/src/main/java/org/geysermc/geyser/registry/mappings/util/CustomBlockMapping.java index ccd5e8ad8..a4a525317 100644 --- a/api/geyser/src/main/java/org/geysermc/geyser/api/block/custom/CustomBlockMapping.java +++ b/core/src/main/java/org/geysermc/geyser/registry/mappings/util/CustomBlockMapping.java @@ -23,11 +23,13 @@ * @link https://github.com/GeyserMC/Geyser */ -package org.geysermc.geyser.api.block.custom; +package org.geysermc.geyser.registry.mappings.util; import java.util.Map; import org.checkerframework.checker.nullness.qual.NonNull; +import org.geysermc.geyser.api.block.custom.CustomBlockData; +import org.geysermc.geyser.api.block.custom.CustomBlockState; /** * This class is used to store a custom block mappings, which contain all of the diff --git a/core/src/main/java/org/geysermc/geyser/registry/mappings/versions/MappingsReader.java b/core/src/main/java/org/geysermc/geyser/registry/mappings/versions/MappingsReader.java index a49e9fcc6..d94f78251 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/mappings/versions/MappingsReader.java +++ b/core/src/main/java/org/geysermc/geyser/registry/mappings/versions/MappingsReader.java @@ -27,10 +27,10 @@ package org.geysermc.geyser.registry.mappings.versions; import com.fasterxml.jackson.databind.JsonNode; -import org.geysermc.geyser.api.block.custom.CustomBlockMapping; import org.geysermc.geyser.api.item.custom.CustomItemData; import org.geysermc.geyser.api.item.custom.CustomRenderOffsets; import org.geysermc.geyser.item.exception.InvalidCustomMappingsFileException; +import org.geysermc.geyser.registry.mappings.util.CustomBlockMapping; import java.nio.file.Path; import java.util.function.BiConsumer; diff --git a/core/src/main/java/org/geysermc/geyser/registry/mappings/versions/MappingsReader_v1.java b/core/src/main/java/org/geysermc/geyser/registry/mappings/versions/MappingsReader_v1.java index 99aa08902..f72ef5986 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/mappings/versions/MappingsReader_v1.java +++ b/core/src/main/java/org/geysermc/geyser/registry/mappings/versions/MappingsReader_v1.java @@ -31,7 +31,6 @@ import com.google.common.base.CharMatcher; import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.api.block.custom.CustomBlockData; -import org.geysermc.geyser.api.block.custom.CustomBlockMapping; import org.geysermc.geyser.api.block.custom.CustomBlockPermutation; import org.geysermc.geyser.api.block.custom.CustomBlockState; import org.geysermc.geyser.api.block.custom.component.BoxComponent; @@ -47,6 +46,7 @@ import org.geysermc.geyser.level.block.GeyserCustomBlockData.CustomBlockDataBuil import org.geysermc.geyser.level.physics.BoundingBox; import org.geysermc.geyser.registry.BlockRegistries; import org.geysermc.geyser.registry.mappings.util.BlockPropertyTypeMaps; +import org.geysermc.geyser.registry.mappings.util.CustomBlockMapping; import org.geysermc.geyser.registry.type.BlockMapping; import org.geysermc.geyser.util.BlockUtils; @@ -480,7 +480,7 @@ public class MappingsReader_v1 extends MappingsReader { return pairs; } - public float clamp(float value, float min, float max) { + private float clamp(float value, float min, float max) { return Math.max(min, Math.min(max, value)); } diff --git a/core/src/main/java/org/geysermc/geyser/registry/populator/CustomBlockRegistryPopulator.java b/core/src/main/java/org/geysermc/geyser/registry/populator/CustomBlockRegistryPopulator.java index f3a75415c..3ff0ac58e 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/populator/CustomBlockRegistryPopulator.java +++ b/core/src/main/java/org/geysermc/geyser/registry/populator/CustomBlockRegistryPopulator.java @@ -72,6 +72,14 @@ public class CustomBlockRegistryPopulator { javaIdentifier + " Old override: " + oldBlockState.name() + " New override: " + customBlockState.name()); } } + + @Override + public void registerBlockItemOverride(@NonNull String javaIdentifier, @NonNull CustomBlockData customBlockData) { + if (!customBlocks.contains(customBlockData)) { + throw new IllegalArgumentException("Custom block is unregistered. Name: " + customBlockData.name()); + } + customBlockItemOverrides.put(javaIdentifier, customBlockData); + } }); for (CustomSkull customSkull : BlockRegistries.CUSTOM_SKULLS.get().values()) {