Skip to content

Commit

Permalink
cleanup and document some API classes
Browse files Browse the repository at this point in the history
  • Loading branch information
IchHabeHunger54 committed Jun 13, 2024
1 parent cc60ba6 commit 851f19e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,35 @@
import java.util.ServiceLoader;
import java.util.function.Supplier;

/**
* The main accessor class for Bibliocraft's API. Use this to get references to the singleton instances of {@link BibliocraftWoodTypeRegistry} and {@link BibliocraftDatagenHelper}.
*/
@ApiStatus.NonExtendable
public interface BibliocraftApi {
String MOD_ID = "bibliocraft";

/**
* @return The only instance of {@link BibliocraftDatagenHelper}.
*/
static BibliocraftDatagenHelper getDatagenHelper() {
return InstanceHolder.DATAGEN_HELPER.get();
}

/**
* @return The only instance of {@link BibliocraftWoodTypeRegistry}.
*/
static BibliocraftWoodTypeRegistry getWoodTypeRegistry() {
return InstanceHolder.WOOD_TYPE_REGISTRY.get();
}

/**
* The internal class used to hold the instances. DO NOT ACCESS YOURSELF!
*/
@ApiStatus.Internal
final class InstanceHolder {
private InstanceHolder() {}

private static final Lazy<BibliocraftDatagenHelper> DATAGEN_HELPER = Lazy.concurrentOf(fromServiceLoader(BibliocraftDatagenHelper.class));
private static final Lazy<BibliocraftWoodTypeRegistry> WOOD_TYPE_REGISTRY = Lazy.concurrentOf(fromServiceLoader(BibliocraftWoodTypeRegistry.class));
private InstanceHolder() {}

private static <T> Supplier<T> fromServiceLoader(Class<T> clazz) {
return () -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@

import java.util.function.Supplier;

/**
* Holds all information Bibliocraft needs about a wood type.
*
* @param id The id of the wood type.
* @param woodType The corresponding vanilla {@link WoodType}.
* @param properties A supplier for the wood type's {@link BlockBehaviour.Properties}.
* @param texture The location of the wood type's plank texture. Used in datagen.
* @param family The corresponding {@link BlockFamily}. Used in datagen.
*/
public record BibliocraftWoodType(
ResourceLocation id,
WoodType woodType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
* Make sure to put this call behind a {@code ModList.isLoaded("bibliocraft")} check, and in a separate class, to prevent accidental classloading (like you would with client classes).
*/
public interface BibliocraftWoodTypeRegistry {

/**
* @param id The id of the wood type to get.
* @return The wood type with the given id. May return null if no wood type with the given id exists.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
import java.util.Map;
import java.util.function.Supplier;

/**
* Register your own {@link BibliocraftWoodType}s here.
*
* This event is not cancelable. This event is fired on the {@link net.neoforged.fml.common.Mod.EventBusSubscriber.Bus.MOD}.
*/
@SuppressWarnings({"JavadocBlankLines", "JavadocReference"})
public class RegisterBibliocraftWoodTypesEvent extends Event implements IModBusEvent {
private final Map<ResourceLocation, BibliocraftWoodType> woodTypes;

Expand Down

0 comments on commit 851f19e

Please sign in to comment.