2019-06-20 00:29:15 +02:00
|
|
|
package io.github.cottonmc.templates;
|
|
|
|
|
2023-07-09 06:43:55 +02:00
|
|
|
import io.github.cottonmc.templates.model.UnbakedAutoRetexturedModel;
|
|
|
|
import io.github.cottonmc.templates.model.UnbakedJsonRetexturedModel;
|
|
|
|
import io.github.cottonmc.templates.model.UnbakedMeshRetexturedModel;
|
2023-07-04 02:02:52 +02:00
|
|
|
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;
|
2023-07-08 10:10:44 +02:00
|
|
|
import net.minecraft.block.Block;
|
2023-06-16 04:50:41 +02:00
|
|
|
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;
|
2023-06-16 04:50:41 +02:00
|
|
|
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() {
|
2023-06-16 04:50:41 +02:00
|
|
|
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-08 10:10:44 +02:00
|
|
|
BlockRenderLayerMap.INSTANCE.putBlocks(RenderLayer.getCutout(), Templates.BLOCKS.toArray(new Block[0]));
|
2023-07-04 07:00:41 +02:00
|
|
|
|
2023-07-09 06:43:55 +02:00
|
|
|
//vanilla style models (using "auto" method)
|
|
|
|
provider.addTemplateModel(Templates.id("button_special"), new UnbakedAutoRetexturedModel(new Identifier("block/button")));
|
|
|
|
provider.addTemplateModel(Templates.id("button_pressed_special"), new UnbakedAutoRetexturedModel(new Identifier("block/button_pressed")));
|
2023-07-09 07:06:10 +02:00
|
|
|
provider.addTemplateModel(Templates.id("one_candle_special"), new UnbakedAutoRetexturedModel(new Identifier("block/template_candle")));
|
|
|
|
provider.addTemplateModel(Templates.id("two_candles_special"), new UnbakedAutoRetexturedModel(new Identifier("block/template_two_candles")));
|
|
|
|
provider.addTemplateModel(Templates.id("three_candles_special"), new UnbakedAutoRetexturedModel(new Identifier("block/template_three_candles")));
|
|
|
|
provider.addTemplateModel(Templates.id("four_candles_special"), new UnbakedAutoRetexturedModel(new Identifier("block/template_four_candles")));
|
2023-07-09 06:43:55 +02:00
|
|
|
provider.addTemplateModel(Templates.id("carpet_special"), new UnbakedAutoRetexturedModel(new Identifier("block/carpet")));
|
|
|
|
provider.addTemplateModel(Templates.id("cube_special"), new UnbakedAutoRetexturedModel(new Identifier("block/cube")));
|
|
|
|
provider.addTemplateModel(Templates.id("fence_post_special"), new UnbakedAutoRetexturedModel(new Identifier("block/fence_post")));
|
|
|
|
provider.addTemplateModel(Templates.id("fence_side_special"), new UnbakedAutoRetexturedModel(new Identifier("block/fence_side")));
|
|
|
|
provider.addTemplateModel(Templates.id("fence_gate_special"), new UnbakedAutoRetexturedModel(new Identifier("block/template_fence_gate")));
|
|
|
|
provider.addTemplateModel(Templates.id("fence_gate_open_special"), new UnbakedAutoRetexturedModel(new Identifier("block/template_fence_gate_open")));
|
|
|
|
provider.addTemplateModel(Templates.id("fence_gate_wall_special"), new UnbakedAutoRetexturedModel(new Identifier("block/template_fence_gate_wall")));
|
|
|
|
provider.addTemplateModel(Templates.id("fence_gate_wall_open_special"), new UnbakedAutoRetexturedModel(new Identifier("block/template_fence_gate_wall_open")));
|
2023-07-10 05:27:49 +02:00
|
|
|
provider.addTemplateModel(Templates.id("glass_pane_post_special"), new UnbakedAutoRetexturedModel(new Identifier("block/glass_pane_post")));
|
|
|
|
provider.addTemplateModel(Templates.id("glass_pane_side_special"), new UnbakedAutoRetexturedModel(new Identifier("block/glass_pane_side")));
|
|
|
|
provider.addTemplateModel(Templates.id("glass_pane_side_alt_special"), new UnbakedAutoRetexturedModel(new Identifier("block/glass_pane_side_alt")));
|
|
|
|
provider.addTemplateModel(Templates.id("glass_pane_noside_special"), new UnbakedAutoRetexturedModel(new Identifier("block/glass_pane_noside")));
|
|
|
|
provider.addTemplateModel(Templates.id("glass_pane_noside_alt_special"), new UnbakedAutoRetexturedModel(new Identifier("block/glass_pane_noside_alt")));
|
2023-07-09 06:43:55 +02:00
|
|
|
provider.addTemplateModel(Templates.id("pressure_plate_up_special"), new UnbakedAutoRetexturedModel(new Identifier("block/pressure_plate_up")));
|
|
|
|
provider.addTemplateModel(Templates.id("pressure_plate_down_special"), new UnbakedAutoRetexturedModel(new Identifier("block/pressure_plate_down")));
|
|
|
|
provider.addTemplateModel(Templates.id("slab_bottom_special"), new UnbakedAutoRetexturedModel(new Identifier("block/slab")));
|
|
|
|
provider.addTemplateModel(Templates.id("slab_top_special"), new UnbakedAutoRetexturedModel(new Identifier("block/slab_top")));
|
2023-07-09 07:18:52 +02:00
|
|
|
provider.addTemplateModel(Templates.id("stairs_special"), new UnbakedAutoRetexturedModel(new Identifier("block/stairs")));
|
|
|
|
provider.addTemplateModel(Templates.id("inner_stairs_special"), new UnbakedAutoRetexturedModel(new Identifier("block/inner_stairs")));
|
|
|
|
provider.addTemplateModel(Templates.id("outer_stairs_special"), new UnbakedAutoRetexturedModel(new Identifier("block/outer_stairs")));
|
2023-07-10 05:27:49 +02:00
|
|
|
provider.addTemplateModel(Templates.id("trapdoor_bottom_special"), new UnbakedAutoRetexturedModel(new Identifier("block/template_trapdoor_bottom")));
|
|
|
|
provider.addTemplateModel(Templates.id("trapdoor_top_special"), new UnbakedAutoRetexturedModel(new Identifier("block/template_trapdoor_top")));
|
2023-07-09 06:43:55 +02:00
|
|
|
provider.addTemplateModel(Templates.id("wall_post_special"), new UnbakedAutoRetexturedModel(new Identifier("block/template_wall_post")));
|
|
|
|
provider.addTemplateModel(Templates.id("wall_side_special"), new UnbakedAutoRetexturedModel(new Identifier("block/template_wall_side")));
|
|
|
|
provider.addTemplateModel(Templates.id("wall_side_tall_special"), new UnbakedAutoRetexturedModel(new Identifier("block/template_wall_side_tall")));
|
2023-07-06 05:57:19 +02:00
|
|
|
|
2023-07-09 06:43:55 +02:00
|
|
|
//vanilla style models (using "special-sprite replacement" method)
|
|
|
|
provider.addTemplateModel(Templates.id("lever_special"), new UnbakedJsonRetexturedModel(Templates.id("block/lever")));
|
2023-07-11 09:11:22 +02:00
|
|
|
provider.addTemplateModel(Templates.id("trapdoor_open_special"), new UnbakedJsonRetexturedModel(Templates.id("block/trapdoor_open")));
|
2023-07-09 06:43:55 +02:00
|
|
|
provider.addTemplateModel(Templates.id("lever_on_special"), new UnbakedJsonRetexturedModel(Templates.id("block/lever_on")));
|
2023-07-08 10:10:44 +02:00
|
|
|
|
2023-07-09 06:43:55 +02:00
|
|
|
//mesh models
|
2023-07-10 02:41:37 +02:00
|
|
|
provider.addTemplateModel(Templates.id("slope_special"), new UnbakedMeshRetexturedModel(Templates.id("block/slope_base"), SlopeBaseMesh::makeUpright));
|
|
|
|
provider.addTemplateModel(Templates.id("slope_side_special"), new UnbakedMeshRetexturedModel(Templates.id("block/slope_base"), SlopeBaseMesh::makeSide));
|
2023-07-08 10:10:44 +02:00
|
|
|
|
2023-07-09 06:43:55 +02:00
|
|
|
//item only models
|
|
|
|
provider.addTemplateModel(Templates.id("button_inventory_special"), new UnbakedAutoRetexturedModel(new Identifier("block/button_inventory")));
|
|
|
|
provider.addTemplateModel(Templates.id("fence_inventory_special"), new UnbakedAutoRetexturedModel(new Identifier("block/fence_inventory")));
|
|
|
|
provider.addTemplateModel(Templates.id("fence_post_inventory_special"), new UnbakedAutoRetexturedModel(Templates.id("block/fence_post_inventory")));
|
|
|
|
provider.addTemplateModel(Templates.id("wall_inventory_special"), new UnbakedAutoRetexturedModel(new Identifier("block/wall_inventory")));
|
|
|
|
|
|
|
|
//item model assignments (in lieu of models/item/___.json)
|
|
|
|
provider.assignItemModel(Templates.id("button_inventory_special"), Templates.BUTTON);
|
2023-07-09 07:06:10 +02:00
|
|
|
provider.assignItemModel(Templates.id("one_candle_special"), Templates.CANDLE); //TODO vanilla uses its own item model
|
2023-07-08 10:10:44 +02:00
|
|
|
provider.assignItemModel(Templates.id("carpet_special"), Templates.CARPET);
|
2023-07-06 05:57:19 +02:00
|
|
|
provider.assignItemModel(Templates.id("cube_special"), Templates.CUBE);
|
2023-07-06 06:45:12 +02:00
|
|
|
provider.assignItemModel(Templates.id("fence_inventory_special"), Templates.FENCE);
|
2023-07-08 10:10:44 +02:00
|
|
|
provider.assignItemModel(Templates.id("fence_gate_special"), Templates.FENCE_GATE);
|
|
|
|
provider.assignItemModel(Templates.id("lever_special"), Templates.LEVER); //TODO vanilla uses its own item model
|
2023-07-10 05:27:49 +02:00
|
|
|
//provider.assignItemModel(Templates.id("glass_pane_side_special"), Templates.PANE); //Done with a regular json model actually
|
2023-07-09 06:43:55 +02:00
|
|
|
provider.assignItemModel(Templates.id("fence_post_inventory_special"), Templates.POST);
|
2023-07-08 10:10:44 +02:00
|
|
|
provider.assignItemModel(Templates.id("pressure_plate_up_special"), Templates.PRESSURE_PLATE);
|
2023-07-06 05:57:19 +02:00
|
|
|
provider.assignItemModel(Templates.id("slope_special"), Templates.SLOPE);
|
2023-07-04 07:00:41 +02:00
|
|
|
provider.assignItemModel(Templates.id("slab_bottom_special"), Templates.SLAB);
|
2023-07-09 07:18:52 +02:00
|
|
|
provider.assignItemModel(Templates.id("stairs_special"), Templates.STAIRS);
|
2023-07-10 05:27:49 +02:00
|
|
|
provider.assignItemModel(Templates.id("trapdoor_bottom_special"), Templates.TRAPDOOR);
|
2023-07-06 06:45:12 +02:00
|
|
|
provider.assignItemModel(Templates.id("wall_inventory_special"), Templates.WALL);
|
2019-06-20 00:29:15 +02:00
|
|
|
}
|
|
|
|
}
|