generated from VulpixelMC/MDK-1.21-ModDevGradle
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(day 2): load programmer art in memory
- Loading branch information
Showing
1 changed file
with
73 additions
and
0 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
src/main/java/gay/sylv/legacy_landscape/client/ClientLegacyLandscape.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package gay.sylv.legacy_landscape.client; | ||
|
||
import com.mojang.logging.LogUtils; | ||
import gay.sylv.legacy_landscape.LegacyLandscape; | ||
import net.minecraft.Util; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.color.block.BlockColors; | ||
import net.minecraft.client.model.geom.EntityModelSet; | ||
import net.minecraft.client.renderer.texture.TextureManager; | ||
import net.minecraft.client.resources.FoliageColorReloadListener; | ||
import net.minecraft.client.resources.GrassColorReloadListener; | ||
import net.minecraft.client.resources.SplashManager; | ||
import net.minecraft.client.resources.model.ModelManager; | ||
import net.minecraft.server.packs.PackResources; | ||
import net.minecraft.server.packs.PackType; | ||
import net.minecraft.server.packs.resources.ReloadableResourceManager; | ||
import net.minecraft.server.packs.resources.ResourceManagerReloadListener; | ||
import net.minecraft.util.Unit; | ||
import net.neoforged.api.distmarker.Dist; | ||
import net.neoforged.api.distmarker.OnlyIn; | ||
import net.neoforged.bus.api.SubscribeEvent; | ||
import net.neoforged.fml.common.EventBusSubscriber; | ||
import net.neoforged.neoforge.client.event.RegisterClientReloadListenersEvent; | ||
import org.slf4j.Logger; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.stream.Collectors; | ||
|
||
@OnlyIn(Dist.CLIENT) | ||
@EventBusSubscriber( | ||
modid = LegacyLandscape.MOD_ID, | ||
bus = EventBusSubscriber.Bus.MOD | ||
) | ||
public final class ClientLegacyLandscape { | ||
private static final Logger LOGGER = LogUtils.getLogger(); | ||
|
||
private static PackResources programmerArt; | ||
private static ReloadableResourceManager resourceManager; | ||
private static TextureManager textureManager; | ||
private static SplashManager splashManager; | ||
private static BlockColors blockColors; | ||
private static ModelManager modelManager; | ||
private static EntityModelSet entityModels; | ||
|
||
@SubscribeEvent | ||
private static void registerReloadListeners(RegisterClientReloadListenersEvent event) { | ||
event.registerReloadListener((ResourceManagerReloadListener) resourceManager1 -> { | ||
Minecraft client = Minecraft.getInstance(); | ||
try (PackResources programmerArtResources = Objects.requireNonNull(client.getResourcePackRepository().getPack("programmer_art")).open()) { | ||
programmerArt = programmerArtResources; | ||
resourceManager = new ReloadableResourceManager(PackType.CLIENT_RESOURCES); | ||
textureManager = new TextureManager(resourceManager); | ||
resourceManager.registerReloadListener(textureManager); | ||
splashManager = new SplashManager(Minecraft.getInstance().getUser()); | ||
resourceManager.registerReloadListener(splashManager); | ||
resourceManager.registerReloadListener(new GrassColorReloadListener()); | ||
resourceManager.registerReloadListener(new FoliageColorReloadListener()); | ||
blockColors = BlockColors.createDefault(); | ||
modelManager = new ModelManager(textureManager, blockColors, 0); | ||
resourceManager.registerReloadListener(modelManager); | ||
entityModels = new EntityModelSet(); | ||
resourceManager.registerReloadListener(entityModels); | ||
} | ||
|
||
List<PackResources> fullResourcesList = client.getResourceManager().listPacks().collect(Collectors.toCollection(ArrayList::new)); | ||
fullResourcesList.add(programmerArt); | ||
resourceManager.createReload(Util.backgroundExecutor(), client, CompletableFuture.completedFuture(Unit.INSTANCE), fullResourcesList).done().thenRun(() -> LOGGER.info("Loaded programmer art resources")); | ||
}); | ||
} | ||
} |