From 69fe944abde10847358df5718ccc986085898b2b Mon Sep 17 00:00:00 2001 From: rtm516 Date: Sun, 3 Mar 2024 17:19:38 +0000 Subject: [PATCH] Fix multipart states not loading geometry at all --- .../hydraulic/block/BlockPackModule.java | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/shared/src/main/java/org/geysermc/hydraulic/block/BlockPackModule.java b/shared/src/main/java/org/geysermc/hydraulic/block/BlockPackModule.java index 3e1be50..3099b97 100644 --- a/shared/src/main/java/org/geysermc/hydraulic/block/BlockPackModule.java +++ b/shared/src/main/java/org/geysermc/hydraulic/block/BlockPackModule.java @@ -51,7 +51,9 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import team.unnamed.creative.ResourcePack; +import team.unnamed.creative.blockstate.Condition; import team.unnamed.creative.blockstate.MultiVariant; +import team.unnamed.creative.blockstate.Selector; import team.unnamed.creative.blockstate.Variant; import team.unnamed.creative.model.Model; import team.unnamed.creative.model.ModelTexture; @@ -62,6 +64,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Optional; @AutoService(PackModule.class) public class BlockPackModule extends ConvertablePackModule { @@ -280,7 +283,7 @@ private void onDefineCustomBlocks(PackEventContext property : state.getProperties()) { String propValue = state.getValue(property).toString(); if (property instanceof EnumProperty) { - propValue = "'" + propValue + "'"; + propValue = "'" + propValue.toLowerCase() + "'"; } conditions.add(String.format(STATE_CONDITION, property.getName(), propValue)); @@ -369,6 +372,17 @@ private ModelDefinition getModel(@NotNull ModInfo mod, @NotNull ResourceLocation multiVariant = packState.variants().get(""); } + // Get the default multipart variant if we have no match + // TODO: Multipart states, this is temporary as we dont parse the condition yet + if (multiVariant == null) { + Optional selector = packState.multipart().stream().filter(multipart -> multipart.condition() == Condition.NONE).findFirst(); + if (selector.isPresent()) { + multiVariant = selector.get().variant(); + } + + // LOGGER.warn("Missing multipart state conversion for block {} {}", blockLocation, state); + } + // We have a match! Now we need to find the model if (multiVariant != null && !multiVariant.variants().isEmpty()) { // TODO: Handle multiple variants? @@ -383,9 +397,6 @@ private ModelDefinition getModel(@NotNull ModInfo mod, @NotNull ResourceLocation } } - // TODO: Multipart states - // LOGGER.warn("Missing multipart state conversion for block {} {}", blockLocation, state); - return null; } @@ -417,7 +428,7 @@ private static String getTextureName(@NotNull String modelName) { private static MultiVariant matchState(@NotNull BlockState state, @NotNull Map variants) { List properties = new ArrayList<>(); for (Property property : state.getProperties()) { - properties.add(property.getName() + "=" + state.getValue(property)); + properties.add(property.getName() + "=" + state.getValue(property).toString().toLowerCase()); } for (Map.Entry entry : variants.entrySet()) {