diff --git a/CHANGELOG.md b/CHANGELOG.md index 0123095..dc6e406 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +remorphed 4.2 +================ + +- add config option for loading menu asynchronously + remorphed 4.1 ================ diff --git a/common/src/main/java/tocraft/remorphed/config/RemorphedConfig.java b/common/src/main/java/tocraft/remorphed/config/RemorphedConfig.java index 2092847..deb6a3a 100644 --- a/common/src/main/java/tocraft/remorphed/config/RemorphedConfig.java +++ b/common/src/main/java/tocraft/remorphed/config/RemorphedConfig.java @@ -1,6 +1,7 @@ package tocraft.remorphed.config; import tocraft.craftedcore.config.Config; +import tocraft.craftedcore.config.annotions.Comment; import tocraft.craftedcore.config.annotions.Synchronize; import tocraft.remorphed.Remorphed; @@ -23,6 +24,8 @@ public class RemorphedConfig implements Config { put("minecraft:wither", 2); } }; + @Comment("Whether the entities that should be rendered can be loaded asynchronously") + public boolean loadMenuAsynchronous = true; @Override public String getName() { diff --git a/common/src/main/java/tocraft/remorphed/screen/RemorphedScreen.java b/common/src/main/java/tocraft/remorphed/screen/RemorphedScreen.java index 70c8c3c..ed142d0 100644 --- a/common/src/main/java/tocraft/remorphed/screen/RemorphedScreen.java +++ b/common/src/main/java/tocraft/remorphed/screen/RemorphedScreen.java @@ -78,21 +78,65 @@ public void init() { addRenderableWidget(specialShapeButton); } - CompletableFuture.runAsync(() -> { - populateUnlockedRenderEntities(minecraft.player); - ShapeType currentShape = ShapeType.from(PlayerShape.getCurrentShape(minecraft.player)); + if (Remorphed.CONFIG.loadMenuAsynchronous) { + CompletableFuture.runAsync(this::instantiate); + } else { + instantiate(); + } + } + + private void instantiate() { + populateUnlockedRenderEntities(minecraft.player); + ShapeType currentShape = ShapeType.from(PlayerShape.getCurrentShape(minecraft.player)); + + // handle favorites + unlockedShapes.sort((first, second) -> { + if (Objects.equals(first, currentShape)) { + return -1; + } else if (Objects.equals(second, currentShape)) { + return 1; + } else { + boolean firstIsFav = PlayerMorph.getFavoriteShapes(minecraft.player).contains(first); + boolean secondIsFav = PlayerMorph.getFavoriteShapes(minecraft.player).contains(second); + if (firstIsFav == secondIsFav) { + return 0; + } + else if (firstIsFav) { + return -1; + } + else { + return 1; + } + } + }); + + // filter unlocked + if (!Remorphed.displayVariantsInMenu) { + List> newUnlocked = new ArrayList<>(); + for (ShapeType shapeType : unlockedShapes) { + if (shapeType.equals(currentShape) || !newUnlocked.stream().map(ShapeType::getEntityType).toList().contains(shapeType.getEntityType())) { + newUnlocked.add(shapeType); + } + } + + unlockedShapes.clear(); + unlockedShapes.addAll(newUnlocked); + } - // handle favorites - unlockedShapes.sort((first, second) -> { - if (Objects.equals(first, currentShape)) { + if (Remorphed.foundSkinShifter) { + populateUnlockedRenderPlayers(minecraft.player); + UUID currentSkin = SkinShifter.getCurrentSkin(minecraft.player); + + unlockedSkins.sort((first, second) -> { + if (Objects.equals(first.id(), currentSkin) && currentShape != null) { return -1; - } else if (Objects.equals(second, currentShape)) { + } else if (Objects.equals(second.id(), currentSkin) && currentShape != null) { return 1; } else { - boolean firstIsFav = PlayerMorph.getFavoriteShapes(minecraft.player).contains(first); - boolean secondIsFav = PlayerMorph.getFavoriteShapes(minecraft.player).contains(second); + boolean firstIsFav = PlayerMorph.getFavoriteSkinIds(minecraft.player).contains(first.id()); + boolean secondIsFav = PlayerMorph.getFavoriteSkinIds(minecraft.player).contains(second.id()); if (firstIsFav == secondIsFav) { - return 0; + return first.name().compareTo(second.name()); } else if (firstIsFav) { return -1; @@ -102,70 +146,32 @@ else if (firstIsFav) { } } }); + } - // filter unlocked - if (!Remorphed.displayVariantsInMenu) { - List> newUnlocked = new ArrayList<>(); - for (ShapeType shapeType : unlockedShapes) { - if (shapeType.equals(currentShape) || !newUnlocked.stream().map(ShapeType::getEntityType).toList().contains(shapeType.getEntityType())) { - newUnlocked.add(shapeType); - } - } - - unlockedShapes.clear(); - unlockedShapes.addAll(newUnlocked); - } - - if (Remorphed.foundSkinShifter) { - populateUnlockedRenderPlayers(minecraft.player); - UUID currentSkin = SkinShifter.getCurrentSkin(minecraft.player); - - unlockedSkins.sort((first, second) -> { - if (Objects.equals(first.id(), currentSkin) && currentShape != null) { - return -1; - } else if (Objects.equals(second.id(), currentSkin) && currentShape != null) { - return 1; - } else { - boolean firstIsFav = PlayerMorph.getFavoriteSkinIds(minecraft.player).contains(first.id()); - boolean secondIsFav = PlayerMorph.getFavoriteSkinIds(minecraft.player).contains(second.id()); - if (firstIsFav == secondIsFav) { - return first.name().compareTo(second.name()); - } - else if (firstIsFav) { - return -1; - } - else { - return 1; - } - } - }); - } - - populateShapeWidgets(unlockedShapes, unlockedSkins); + populateShapeWidgets(unlockedShapes, unlockedSkins); - // implement search handler - searchBar.setResponder(text -> { - setFocused(searchBar); + // implement search handler + searchBar.setResponder(text -> { + setFocused(searchBar); - // Only re-filter if the text contents changed - if (!lastSearchContents.equals(text)) { - ((ScreenAccessor) this).getSelectables().removeIf(button -> button instanceof EntityWidget); - children().removeIf(button -> button instanceof EntityWidget); + // Only re-filter if the text contents changed + if (!lastSearchContents.equals(text)) { + ((ScreenAccessor) this).getSelectables().removeIf(button -> button instanceof EntityWidget); + children().removeIf(button -> button instanceof EntityWidget); - List> filteredShapes = unlockedShapes - .stream() - .filter(type -> text.isEmpty() || ShapeType.createTooltipText(renderEntities.get(type)).getString().toUpperCase().contains(text.toUpperCase()) || EntityType.getKey(type.getEntityType()).toString().toUpperCase().contains(text.toUpperCase())) - .toList(); - List filteredSkins = unlockedSkins - .stream() - .filter(skin -> text.isEmpty() || skin.name().toUpperCase().contains(text.toUpperCase()) || skin.id().toString().contains(text.toUpperCase())) - .toList(); + List> filteredShapes = unlockedShapes + .stream() + .filter(type -> text.isEmpty() || ShapeType.createTooltipText(renderEntities.get(type)).getString().toUpperCase().contains(text.toUpperCase()) || EntityType.getKey(type.getEntityType()).toString().toUpperCase().contains(text.toUpperCase())) + .toList(); + List filteredSkins = unlockedSkins + .stream() + .filter(skin -> text.isEmpty() || skin.name().toUpperCase().contains(text.toUpperCase()) || skin.id().toString().contains(text.toUpperCase())) + .toList(); - populateShapeWidgets(filteredShapes, filteredSkins); - } + populateShapeWidgets(filteredShapes, filteredSkins); + } - lastSearchContents = text; - }); + lastSearchContents = text; }); } diff --git a/gradle.properties b/gradle.properties index f38aaca..e5aaa9f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,13 +2,13 @@ org.gradle.jvmargs=-Xmx4G # Base Versions archives_base_name=remorphed artifact_type=release -mod_version=4.1 +mod_version=4.2 maven_group=dev.tocraft # Loader Versions fabric_loader=0.15.11 # Dependency Versions -craftedcore_version=5.3 -woodwalkers_version=5 +craftedcore_version=5.5 +woodwalkers_version=5.2 skinshifter_version=1.1 # Upload data curseforge_id=950721