ReFramed/src/main/java/io/github/cottonmc/templates/TemplatesClient.java

68 lines
3.0 KiB
Java
Raw Normal View History

2019-06-20 00:29:15 +02:00
package io.github.cottonmc.templates;
2023-07-04 07:00:41 +02:00
import io.github.cottonmc.templates.model.RetexturedJsonModelUnbakedModel;
import io.github.cottonmc.templates.model.RetexturedMeshUnbakedModel;
import io.github.cottonmc.templates.model.SlopeBaseMesh;
2019-06-20 00:29:15 +02:00
import net.fabricmc.api.ClientModInitializer;
2023-06-15 10:24:11 +02:00
import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap;
2019-06-20 00:29:15 +02:00
import net.fabricmc.fabric.api.client.model.ModelLoadingRegistry;
2023-07-02 12:26:19 +02:00
import net.fabricmc.fabric.api.renderer.v1.Renderer;
import net.fabricmc.fabric.api.renderer.v1.RendererAccess;
2023-06-16 05:09:57 +02:00
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
import net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener;
import net.minecraft.client.MinecraftClient;
2023-06-15 10:24:11 +02:00
import net.minecraft.client.render.RenderLayer;
2023-06-16 05:09:57 +02:00
import net.minecraft.resource.ResourceManager;
import net.minecraft.resource.ResourceType;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.ChunkSectionPos;
2023-07-02 12:26:19 +02:00
import org.jetbrains.annotations.NotNull;
import java.util.Objects;
2019-06-20 00:29:15 +02:00
public class TemplatesClient implements ClientModInitializer {
2023-07-03 10:45:18 +02:00
public static TemplatesModelProvider provider = new TemplatesModelProvider();
2023-06-15 07:59:48 +02:00
2023-07-02 12:26:19 +02:00
public static @NotNull Renderer getFabricRenderer() {
return Objects.requireNonNull(RendererAccess.INSTANCE.getRenderer(), "A Fabric Rendering API implementation is required to use Templates!");
}
2019-06-20 00:29:15 +02:00
@Override
public void onInitializeClient() {
Templates.chunkRerenderProxy = (world, pos) -> {
if(world == MinecraftClient.getInstance().world) {
MinecraftClient.getInstance().worldRenderer.scheduleBlockRender(
ChunkSectionPos.getSectionCoord(pos.getX()),
ChunkSectionPos.getSectionCoord(pos.getY()),
ChunkSectionPos.getSectionCoord(pos.getZ())
);
}
};
2023-06-16 05:09:57 +02:00
ResourceManagerHelper.get(ResourceType.CLIENT_RESOURCES).registerReloadListener(new SimpleSynchronousResourceReloadListener() {
@Override
public Identifier getFabricId() {
return Templates.id("dump-caches");
}
@Override
public void reload(ResourceManager resourceManager) {
provider.dumpCache();
}
});
2023-06-15 10:24:11 +02:00
2023-07-02 10:51:39 +02:00
ModelLoadingRegistry.INSTANCE.registerResourceProvider(rm -> provider); //block models
ModelLoadingRegistry.INSTANCE.registerVariantProvider(rm -> provider); //item models
2023-06-30 10:59:10 +02:00
2023-07-04 07:00:41 +02:00
BlockRenderLayerMap.INSTANCE.putBlocks(RenderLayer.getCutout(), Templates.SLOPE, Templates.SLAB);
2023-06-16 05:09:57 +02:00
2023-07-05 05:38:06 +02:00
provider.addTemplateModel(Templates.id("slope_special"), new RetexturedMeshUnbakedModel(Templates.id("block/slope_base"), SlopeBaseMesh::make));
2023-07-02 10:51:39 +02:00
provider.assignItemModel(Templates.id("slope_special"), Templates.SLOPE);
2023-07-04 07:00:41 +02:00
2023-07-05 05:38:06 +02:00
provider.addTemplateModel(Templates.id("cube_special"), new RetexturedJsonModelUnbakedModel(Templates.id("block/cube")));
provider.addTemplateModel(Templates.id("slab_bottom_special"), new RetexturedJsonModelUnbakedModel(Templates.id("block/slab_bottom")));
provider.addTemplateModel(Templates.id("slab_top_special"), new RetexturedJsonModelUnbakedModel(Templates.id("block/slab_top")));
2023-07-04 07:00:41 +02:00
provider.assignItemModel(Templates.id("slab_bottom_special"), Templates.SLAB);
2019-06-20 00:29:15 +02:00
}
}