2019-06-20 00:29:15 +02:00
|
|
|
package io.github.cottonmc.templates;
|
|
|
|
|
|
|
|
import io.github.cottonmc.templates.block.SlopeBlock;
|
2023-06-15 10:24:11 +02:00
|
|
|
import io.github.cottonmc.templates.model.SlopeUnbakedModel;
|
2019-06-20 08:40:56 +02:00
|
|
|
import io.github.cottonmc.templates.model.TemplateModelVariantProvider;
|
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-06-16 05:09:57 +02:00
|
|
|
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
|
|
|
|
import net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener;
|
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;
|
2019-06-20 00:29:15 +02:00
|
|
|
import net.minecraft.util.math.Direction;
|
|
|
|
|
|
|
|
public class TemplatesClient implements ClientModInitializer {
|
2019-06-20 08:40:56 +02:00
|
|
|
public static TemplateModelVariantProvider provider = new TemplateModelVariantProvider();
|
2023-06-15 07:59:48 +02:00
|
|
|
|
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-06-16 05:09:57 +02:00
|
|
|
ModelLoadingRegistry.INSTANCE.registerVariantProvider(rm -> provider);
|
2023-06-15 10:24:11 +02:00
|
|
|
BlockRenderLayerMap.INSTANCE.putBlock(Templates.SLOPE, RenderLayer.getCutout());
|
2023-06-16 05:09:57 +02:00
|
|
|
|
|
|
|
//ADDON DEVELOEPRS: do this!
|
|
|
|
provider.registerTemplateModels(
|
|
|
|
//block
|
|
|
|
Templates.SLOPE,
|
|
|
|
//the blockstate you'd like the item model to show
|
|
|
|
Templates.SLOPE.getDefaultState().with(SlopeBlock.FACING, Direction.SOUTH),
|
|
|
|
//Function<BlockState, UnbakedModel> that creates your model
|
|
|
|
SlopeUnbakedModel::new
|
|
|
|
);
|
2019-06-20 00:29:15 +02:00
|
|
|
}
|
|
|
|
}
|