Skip to content

Commit

Permalink
Fix multipart states not loading geometry at all
Browse files Browse the repository at this point in the history
  • Loading branch information
rtm516 committed Mar 3, 2024
1 parent ae9e25a commit 69fe944
Showing 1 changed file with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<BlockPackModule, ModelConversionData> {
Expand Down Expand Up @@ -280,7 +283,7 @@ private void onDefineCustomBlocks(PackEventContext<GeyserDefineCustomBlocksEvent
for (Property<?> 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));
Expand Down Expand Up @@ -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> 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?
Expand All @@ -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;
}

Expand Down Expand Up @@ -417,7 +428,7 @@ private static String getTextureName(@NotNull String modelName) {
private static MultiVariant matchState(@NotNull BlockState state, @NotNull Map<String, MultiVariant> variants) {
List<String> 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<String, MultiVariant> entry : variants.entrySet()) {
Expand Down

0 comments on commit 69fe944

Please sign in to comment.