Skip to content

Commit

Permalink
api design, the third (also some more documentation)
Browse files Browse the repository at this point in the history
  • Loading branch information
IchHabeHunger54 committed Feb 2, 2024
1 parent a7cdab7 commit 6dd1300
Show file tree
Hide file tree
Showing 39 changed files with 399 additions and 309 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
package com.github.minecraftschurlimods.bibliocraft;

import com.github.minecraftschurlimods.bibliocraft.api.BibliocraftWoodTypeRegistry;
import net.minecraft.data.BlockFamilies;
import net.minecraft.data.BlockFamily;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.properties.WoodType;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.fml.common.Mod;

Expand All @@ -8,5 +16,23 @@ public final class Bibliocraft {
public static final String MOD_ID = "bibliocraft";

public Bibliocraft(IEventBus modBus) {
registerVanilla("oak", WoodType.OAK, Blocks.OAK_PLANKS, BlockFamilies.OAK_PLANKS);
registerVanilla("spruce", WoodType.SPRUCE, Blocks.SPRUCE_PLANKS, BlockFamilies.SPRUCE_PLANKS);
registerVanilla("birch", WoodType.BIRCH, Blocks.BIRCH_PLANKS, BlockFamilies.BIRCH_PLANKS);
registerVanilla("jungle", WoodType.JUNGLE, Blocks.JUNGLE_PLANKS, BlockFamilies.JUNGLE_PLANKS);
registerVanilla("acacia", WoodType.ACACIA, Blocks.ACACIA_PLANKS, BlockFamilies.ACACIA_PLANKS);
registerVanilla("dark_oak", WoodType.DARK_OAK, Blocks.DARK_OAK_PLANKS, BlockFamilies.DARK_OAK_PLANKS);
registerVanilla("crimson", WoodType.CRIMSON, Blocks.CRIMSON_PLANKS, BlockFamilies.CRIMSON_PLANKS);
registerVanilla("warped", WoodType.WARPED, Blocks.WARPED_PLANKS, BlockFamilies.WARPED_PLANKS);
registerVanilla("mangrove", WoodType.MANGROVE, Blocks.MANGROVE_PLANKS, BlockFamilies.MANGROVE_PLANKS);
registerVanilla("bamboo", WoodType.BAMBOO, Blocks.BAMBOO_PLANKS, BlockFamilies.BAMBOO_PLANKS);
registerVanilla("cherry", WoodType.CHERRY, Blocks.CHERRY_PLANKS, BlockFamilies.CHERRY_PLANKS);
}

/**
* Private helper for registering the vanilla variants.
*/
private static void registerVanilla(String name, WoodType woodType, Block planks, BlockFamily family) {
BibliocraftWoodTypeRegistry.get().register(new ResourceLocation(name), woodType, () -> BlockBehaviour.Properties.ofFullCopy(planks), new ResourceLocation("block/" + name + "_planks"), family);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.github.minecraftschurlimods.bibliocraft;

import com.github.minecraftschurlimods.bibliocraft.api.BibliocraftWoodType;
import com.github.minecraftschurlimods.bibliocraft.apiimpl.BibliocraftWoodTypeRegistryImpl;
import com.github.minecraftschurlimods.bibliocraft.init.BCEntities;
import com.github.minecraftschurlimods.bibliocraft.init.BCRegistries;
import net.minecraft.world.entity.LivingEntity;
Expand All @@ -18,7 +18,7 @@ public static final class ModBus {
@SubscribeEvent
private static void constructMod(FMLConstructModEvent event) {
event.enqueueWork(() -> {
BibliocraftWoodType.postRegister();
BibliocraftWoodTypeRegistryImpl.get().postRegister();
BCRegistries.init(Objects.requireNonNull(ModList.get().getModContainerById(Bibliocraft.MOD_ID).orElseThrow().getEventBus()));
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.github.minecraftschurlimods.bibliocraft.api;

import com.github.minecraftschurlimods.bibliocraft.apiimpl.BibliocraftDatagenAPIImpl;
import com.github.minecraftschurlimods.bibliocraft.apiimpl.BibliocraftDatagenHelperImpl;
import net.minecraft.data.loot.BlockLootSubProvider;
import net.minecraft.data.recipes.RecipeOutput;
import net.minecraft.data.tags.IntrinsicHolderTagsProvider;
Expand All @@ -24,34 +24,93 @@
* Then, call whatever methods you need from the respective providers. Always pass in your mod's corresponding data provider.
*/
@SuppressWarnings("JavadocReference")
public interface BibliocraftDatagenAPI {
static BibliocraftDatagenAPIImpl get() {
return BibliocraftDatagenAPIImpl.get();
}

public interface BibliocraftDatagenHelper {
/**
* Marks a {@link BibliocraftWoodType} as to-be-datagenned. This method is thread-safe.
*
* @param woodType The {@link BibliocraftWoodType} to mark.
*/
void addWoodTypeToGenerate(BibliocraftWoodType woodType);

/**
* @return An unmodifiable list of all {@link BibliocraftWoodType}s to datagen.
*/
List<BibliocraftWoodType> getWoodTypesToGenerate();

/**
* Generates the English (en_us) translation files for Bibliocraft blocks with a {@link BibliocraftWoodType}.
*
* @param provider The {@link LanguageProvider} to use.
* @param woodType The {@link BibliocraftWoodType} to generate the translations for.
*/
void generateEnglishTranslationsFor(LanguageProvider provider, BibliocraftWoodType woodType);

/**
* Generates the blockstates and block model files for Bibliocraft blocks with a {@link BibliocraftWoodType}.
*
* @param provider The {@link BlockStateProvider} to use.
* @param woodType The {@link BibliocraftWoodType} to generate the blockstates and block models for.
*/
void generateBlockStatesFor(BlockStateProvider provider, BibliocraftWoodType woodType);

/**
* Generates the item model files for Bibliocraft blocks with a {@link BibliocraftWoodType}.
*
* @param provider The {@link ItemModelProvider} to use.
* @param woodType The {@link BibliocraftWoodType} to generate the item models for.
*/
void generateItemModelsFor(ItemModelProvider provider, BibliocraftWoodType woodType);

/**
* Generates the block tag files for Bibliocraft blocks with a {@link BibliocraftWoodType}.
*
* @param tagAccessor A reference to your mod's {@link BlockTagsProvider#tag(TagKey)} method, as it is protected for some reason.
* @param woodType The {@link BibliocraftWoodType} to generate the block tags for.
*/
void generateBlockTagsFor(Function<TagKey<Block>, IntrinsicHolderTagsProvider.IntrinsicTagAppender<Block>> tagAccessor, BibliocraftWoodType woodType);

/**
* Generates the item tag files for Bibliocraft blocks with a {@link BibliocraftWoodType}.
*
* @param tagAccessor A reference to your mod's {@link ItemTagsProvider#tag(TagKey)} method, as it is protected for some reason.
* @param woodType The {@link BibliocraftWoodType} to generate the item tags for.
*/
void generateItemTagsFor(Function<TagKey<Item>, IntrinsicHolderTagsProvider.IntrinsicTagAppender<Item>> tagAccessor, BibliocraftWoodType woodType);

/**
* Generates the loot table files for Bibliocraft blocks with a {@link BibliocraftWoodType}.
*
* @param lootTableAdder A reference to your mod's {@link BlockLootSubProvider#add(Block, LootTable.Builder)} method, as it is protected for some reason.
* @param woodType The {@link BibliocraftWoodType} to generate the loot tables for.
*/
void generateLootTablesFor(BiConsumer<Block, LootTable.Builder> lootTableAdder, BibliocraftWoodType woodType);

/**
* Generates the recipe files for Bibliocraft blocks with a {@link BibliocraftWoodType}.
*
* @param output The {@link RecipeOutput} to use.
* @param woodType The {@link BibliocraftWoodType} to generate the recipes for.
*/
void generateRecipesFor(RecipeOutput output, BibliocraftWoodType woodType);

/**
* @return The only instance of this class.
*/
static BibliocraftDatagenHelper get() {
return BibliocraftDatagenHelperImpl.get();
}

/**
* Marks all {@link BibliocraftWoodType}s from the given mod as to-be-datagenned. This method is thread-safe.
*
* @param modid The id of the mod to mark the {@link BibliocraftWoodType}s of.
*/
default void addWoodTypesToGenerateByModid(String modid) {
BibliocraftWoodType.getAll().stream()
.filter(e -> e.id.getNamespace().equals(modid))
BibliocraftWoodTypeRegistry.get().getAll().stream()
.filter(e -> e.getNamespace().equals(modid))
.forEach(this::addWoodTypeToGenerate);
}

/**
* @return An unmodifiable list of all {@link BibliocraftWoodType}s to datagen.
*/
List<BibliocraftWoodType> getWoodTypesToGenerate();

/**
* Generates the English (en_us) translation files for Bibliocraft blocks with your mod's wood type(s).
*
Expand All @@ -61,14 +120,6 @@ default void generateEnglishTranslations(LanguageProvider provider) {
getWoodTypesToGenerate().forEach(woodType -> generateEnglishTranslationsFor(provider, woodType));
}

/**
* Generates the English (en_us) translation files for Bibliocraft blocks with a {@link BibliocraftWoodType}.
*
* @param provider The {@link LanguageProvider} to use.
* @param woodType The {@link BibliocraftWoodType} to generate the translations for.
*/
void generateEnglishTranslationsFor(LanguageProvider provider, BibliocraftWoodType woodType);

/**
* Generates the blockstates and block model files for Bibliocraft blocks with your mod's wood type(s).
*
Expand All @@ -78,14 +129,6 @@ default void generateBlockStates(BlockStateProvider provider) {
getWoodTypesToGenerate().forEach(woodType -> generateBlockStatesFor(provider, woodType));
}

/**
* Generates the blockstates and block model files for Bibliocraft blocks with a {@link BibliocraftWoodType}.
*
* @param provider The {@link BlockStateProvider} to use.
* @param woodType The {@link BibliocraftWoodType} to generate the blockstates and block models for.
*/
void generateBlockStatesFor(BlockStateProvider provider, BibliocraftWoodType woodType);

/**
* Generates the item model files for Bibliocraft items with your mod's wood type(s).
*
Expand All @@ -95,14 +138,6 @@ default void generateItemModels(ItemModelProvider provider) {
getWoodTypesToGenerate().forEach(woodType -> generateItemModelsFor(provider, woodType));
}

/**
* Generates the item model files for Bibliocraft blocks with a {@link BibliocraftWoodType}.
*
* @param provider The {@link ItemModelProvider} to use.
* @param woodType The {@link BibliocraftWoodType} to generate the item models for.
*/
void generateItemModelsFor(ItemModelProvider provider, BibliocraftWoodType woodType);

/**
* Generates the block tag files for Bibliocraft blocks with your mod's wood type(s).
*
Expand All @@ -112,14 +147,6 @@ default void generateBlockTags(Function<TagKey<Block>, IntrinsicHolderTagsProvid
getWoodTypesToGenerate().forEach(woodType -> generateBlockTagsFor(tagAccessor, woodType));
}

/**
* Generates the block tag files for Bibliocraft blocks with a {@link BibliocraftWoodType}.
*
* @param tagAccessor A reference to your mod's {@link BlockTagsProvider#tag(TagKey)} method, as it is protected for some reason.
* @param woodType The {@link BibliocraftWoodType} to generate the block tags for.
*/
void generateBlockTagsFor(Function<TagKey<Block>, IntrinsicHolderTagsProvider.IntrinsicTagAppender<Block>> tagAccessor, BibliocraftWoodType woodType);

/**
* Generates the item tag files for Bibliocraft blocks with your mod's wood type(s).
*
Expand All @@ -129,14 +156,6 @@ default void generateItemTags(Function<TagKey<Item>, IntrinsicHolderTagsProvider
getWoodTypesToGenerate().forEach(woodType -> generateItemTagsFor(tagAccessor, woodType));
}

/**
* Generates the item tag files for Bibliocraft blocks with a {@link BibliocraftWoodType}.
*
* @param tagAccessor A reference to your mod's {@link ItemTagsProvider#tag(TagKey)} method, as it is protected for some reason.
* @param woodType The {@link BibliocraftWoodType} to generate the item tags for.
*/
void generateItemTagsFor(Function<TagKey<Item>, IntrinsicHolderTagsProvider.IntrinsicTagAppender<Item>> tagAccessor, BibliocraftWoodType woodType);

/**
* Generates the loot table files for Bibliocraft blocks with your mod's wood type(s).
*
Expand All @@ -146,14 +165,6 @@ default void generateLootTables(BiConsumer<Block, LootTable.Builder> lootTableAd
getWoodTypesToGenerate().forEach(woodType -> generateLootTablesFor(lootTableAdder, woodType));
}

/**
* Generates the loot table files for Bibliocraft blocks with a {@link BibliocraftWoodType}.
*
* @param lootTableAdder A reference to your mod's {@link BlockLootSubProvider#add(Block, LootTable.Builder)} method, as it is protected for some reason.
* @param woodType The {@link BibliocraftWoodType} to generate the loot tables for.
*/
void generateLootTablesFor(BiConsumer<Block, LootTable.Builder> lootTableAdder, BibliocraftWoodType woodType);

/**
* Generates the recipe files for Bibliocraft blocks with your mod's wood type(s).
*
Expand All @@ -162,12 +173,4 @@ default void generateLootTables(BiConsumer<Block, LootTable.Builder> lootTableAd
default void generateRecipes(RecipeOutput output) {
getWoodTypesToGenerate().forEach(woodType -> generateRecipesFor(output, woodType));
}

/**
* Generates the recipe files for Bibliocraft blocks with a {@link BibliocraftWoodType}.
*
* @param output The {@link RecipeOutput} to use.
* @param woodType The {@link BibliocraftWoodType} to generate the recipes for.
*/
void generateRecipesFor(RecipeOutput output, BibliocraftWoodType woodType);
}
Loading

0 comments on commit 6dd1300

Please sign in to comment.