Skip to content

Commit

Permalink
Make api register methods return instance and add fields to all defau…
Browse files Browse the repository at this point in the history
…lt modules
  • Loading branch information
MattiDragon committed Jul 9, 2023
1 parent b1f0c30 commit 53b6693
Show file tree
Hide file tree
Showing 17 changed files with 464 additions and 306 deletions.
84 changes: 60 additions & 24 deletions src/main/java/wraith/fabricaeexnihilo/api/FENRegistries.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,133 +26,156 @@ public interface FENRegistries {
/**
* Register a new type of barrel. It will be registered under {@code fabricaeexnihilo:<name>_barrel}. You will have
* to manually provide all assets. The model {@code fabricaeexnihilo:block/barrel} can be extended for convenience.
* If another api module has already registered a barrel with the same name, it will be returned instead.
* The created block will not be registered with minecraft until after all api modules have run.
*
* @param name The name of the barrel.
* @param isFireproof Whether it should be fireproof.
* @param settings Block settings for the barrel.
*/
//TODO: enchantability option
void registerBarrel(String name, boolean isFireproof, AbstractBlock.Settings settings);
Block registerBarrel(String name, boolean isFireproof, AbstractBlock.Settings settings);

/**
* Register a new type of crucible. It will be registered under {@code fabricaeexnihilo:<name>_crucible}. You will
* have to manually provide all assets. The model {@code fabricaeexnihilo:block/crucible} can be extended for
* convenience.
* convenience. If another has api module already registered a crucible with the same name, it will be returned instead.
* The created block will not be registered with minecraft until after all api modules have run.
*
* @param name The name of the crucible.
* @param isFireproof Whether it should be fireproof.
* @param settings Block settings for the crucible.
*/
//TODO: enchantability option
void registerCrucible(String name, boolean isFireproof, AbstractBlock.Settings settings);
Block registerCrucible(String name, boolean isFireproof, AbstractBlock.Settings settings);

/**
* Register a new crushed block. It will be registered under {@code fabricaeexnihilo:crushed_<name>}. You will have
* to manually provide all assets.
* If another api module has already registered a crushed block with the same name, it will be returned instead.
* The created block will not be registered with minecraft until after all api modules have run.
*
* @param name The base name of the crushed block.
* @param settings Block settings for the crushed block.
*/
void registerCrushedBlock(String name, AbstractBlock.Settings settings);
Block registerCrushedBlock(String name, AbstractBlock.Settings settings);

/**
* Register a new type of infested leaves. It will be registered under
* {@code fabricaeexnihilo:infested_<name>_leaves}. You will have to manually provide all assets, but you can reuse
* the standard leaves model. The tint index of 0 is provided as white.
* If another api module has already registered an infested leaves block with the same name, it will be returned instead.
* The created block will not be registered with minecraft until after all api modules have run.
*
* @param name The name of the wood type.
* @param source The source of the transformation. Used in code.
* @param settings Block settings for the leaves
*/
void registerInfestedLeaves(String name, Identifier source, AbstractBlock.Settings settings);
Block registerInfestedLeaves(String name, Identifier source, AbstractBlock.Settings settings);

/**
* Register a new type of sieve. It will be registered under {@code fabricaeexnihilo:<name>_sieve}. You will have to
* manually provide all assets. The model {@code fabricaeexnihilo:block/sieve} can be extended for convenience.
* If another api module has already registered a sieve with the same name, it will be returned instead.
* The created block will not be registered with minecraft until after all api modules have run.
*
* @param name The name of the sieve.
* @param isFireproof Whether it should be fireproof.
* @param settings Block settings for the sieve.
*/
//TODO: enchantability option
void registerSieve(String name, boolean isFireproof, AbstractBlock.Settings settings);
Block registerSieve(String name, boolean isFireproof, AbstractBlock.Settings settings);

/**
* Register a new type of strainer. It will be registered under {@code fabricaeexnihilo:<name>_strainer}. You will
* have to manually provide all assets. The model {@code fabricaeexnihilo:block/strainer} can be extended for
* convenience.
* If another api module has already registered a strainer with the same name, it will be returned instead.
* The created block will not be registered with minecraft until after all api modules have run.
*
* @param name The name of the strainer.
* @param isFireproof Whether it should be fireproof.
* @param settings Block settings for the strainer.
*/
void registerStrainer(String name, boolean isFireproof, AbstractBlock.Settings settings);
Block registerStrainer(String name, boolean isFireproof, AbstractBlock.Settings settings);

/**
* Register a new type of mesh piece. It will be registered under {@code fabricaeexnihilo:<name>_mesh}. You will
* have to manually provide all assets. The model {@code fabricaeexnihilo:item/mesh} can be directly extended.
* (tint index 1 will be tinted based on {@code color}).
* If another api module has already registered a mesh with the same name, it will be returned instead.
* The created item will not be registered with minecraft until after all api modules have run.
*
* @param name The name of the mesh.
* @param color The color it will be tinted.
* @param enchantability The enchantability of the mesh. You can use vanilla tool materials as a reference.
* @param settings Item settings for the mesh.
*/
void registerMesh(String name, Color color, int enchantability, Item.Settings settings);
Item registerMesh(String name, Color color, int enchantability, Item.Settings settings);

/**
* Register a new type of ore piece. It will be registered under {@code fabricaeexnihilo:<name>_piece}. You will
* have to manually provide all assets. (layer1 will be tinted based on {@code color}).
* If another api module has already registered an ore piece with the same name, it will be returned instead.
* The created item will not be registered with minecraft until after all api modules have run.
*
* @param name The name of the ore.
* @param settings Item settings for the piece.
*/
void registerOrePiece(String name, Item.Settings settings);
Item registerOrePiece(String name, Item.Settings settings);

/**
* Register a new type of seed that creates normal plants. It will be registered under
* {@code fabricaeexnihilo:<name>_seeds}. You will have to manually provide all assets.
* If another api module has already registered a seed with the same name, it will be returned instead.
* The created item will not be registered with minecraft until after all api modules have run.
*
* @param name The name of the seeds.
* @param plants A lazy that resolves to the possible results.
* @see #registerSeed(String, Identifier...)
*/
void registerSeed(String name, Lazy<Block[]> plants);
Item registerSeed(String name, Lazy<Block[]> plants);

/**
* Register a new type of seed that creates normal plants. It will be registered under
* {@code fabricaeexnihilo:<name>_seeds}. You will have to manually provide all assets.
* If another api module has already registered a seed with the same name, it will be returned instead.
* The created item will not be registered with minecraft until after all api modules have run.
*
* @param name The name of the seeds.
* @param plants Ids that resolve to possible results.
* @see #registerSeed(String, Identifier...)
*/
default void registerSeed(String name, Identifier... plants) {
registerSeed(name, new Lazy<>(() -> Arrays.stream(plants)
default Item registerSeed(String name, Identifier... plants) {
return registerSeed(name, new Lazy<>(() -> Arrays.stream(plants)
.map(Registries.BLOCK::get)
.toArray(Block[]::new)));
}

/**
* Register a new type of seed that creates tall plants. It will be registered under
* {@code fabricaeexnihilo:<name>_seeds}. You will have to manually provide all assets.
* If another api module has already registered a seed with the same name, it will be returned instead.
* The created item will not be registered with minecraft until after all api modules have run.
*
* @param name The name of the seeds.
* @param plants A lazy that resolves to the possible results.
* @see #registerTallPlantSeed(String, Identifier...)
*/
void registerTallPlantSeed(String name, Lazy<TallPlantBlock[]> plants);
Item registerTallPlantSeed(String name, Lazy<TallPlantBlock[]> plants);

/**
* Register a new type of seed that creates tall plants. It will be registered under
* {@code fabricaeexnihilo:<name>_seeds}. You will have to manually provide all assets.
* If another api module has already registered a seed with the same name, it will be returned instead.
* The created item will not be registered with minecraft until after all api modules have run.
*
* @param name The name of the seeds.
* @param plants Ids that resolve to possible results.
* @see #registerTallPlantSeed(String, Identifier...)
*/
default void registerTallPlantSeed(String name, Identifier... plants) {
registerTallPlantSeed(name, new Lazy<>(() -> Arrays.stream(plants)
default Item registerTallPlantSeed(String name, Identifier... plants) {
return registerTallPlantSeed(name, new Lazy<>(() -> Arrays.stream(plants)
.map(Registries.BLOCK::get)
.map(block -> (TallPlantBlock) block)
.toArray(TallPlantBlock[]::new)));
Expand All @@ -161,45 +184,47 @@ default void registerTallPlantSeed(String name, Identifier... plants) {
/**
* Register a new type of seed that transforms one block into another. It will be registered under
* {@code fabricaeexnihilo:<name>_seeds}. You will have to manually provide all assets.
* If another api module has already registered a seed with the same name, it will be returned instead.
* The created item will not be registered with minecraft until after all api modules have run.
*
* @param name The name of the seeds.
* @param from A lazy that resolves to the source block.
* @param to A lazy that resolves to the result block.
* @see #registerTransformingSeed(String, Identifier, Identifier)
*/
void registerTransformingSeed(String name, Lazy<Block> from, Lazy<Block> to);
Item registerTransformingSeed(String name, Lazy<Block> from, Lazy<Block> to);

/**
* Register a new type of seed that transforms one block into another. It will be registered under
* {@code fabricaeexnihilo:<name>_seeds}. You will have to manually provide all assets.
* If another api module has already registered a seed with the same name, it will be returned instead.
* The created item will not be registered with minecraft until after all api modules have run.
*
* @param name The name of the seeds.
* @param from An id that points to the source block.
* @param to An id that points to the result block.
* @see #registerTransformingSeed(String, Lazy, Lazy)
*/
default void registerTransformingSeed(String name, Identifier from, Identifier to) {
registerTransformingSeed(name, new Lazy<>(() -> Registries.BLOCK.get(from)), new Lazy<>(() -> Registries.BLOCK.get(to)));
default Item registerTransformingSeed(String name, Identifier from, Identifier to) {
return registerTransformingSeed(name, new Lazy<>(() -> Registries.BLOCK.get(from)), new Lazy<>(() -> Registries.BLOCK.get(to)));
}

/**
* Registers a new type of wood block by calling all the relevant methods. You will need an additional call to
* {@link #registerInfestedLeaves} and {@link #registerSeed} to register the corresponding leaves and seed
* respectively.
* If another api module has already registered a seed with the same name, it will be returned instead.
* The created item will not be registered with minecraft until after all api modules have run.
*
* @param name The name of the wood type. Will be directly passed into the called methods.
* @param fireproof Whether the wood is fireproof or not. Will be directly passed into the called methods.
* @see #registerBarrel
* @see #registerCrucible
* @see #registerSieve
* @see #registerStrainer
* @return An object with methods to access all the return values of the called methods.
*/
default void registerWood(String name, boolean fireproof, AbstractBlock.Settings settings) {
registerSieve(name, fireproof, settings);
registerStrainer(name, fireproof, settings);
registerBarrel(name, fireproof, settings);
registerCrucible(name, fireproof, settings);
}
WoodenBlockBundle registerWood(String name, boolean fireproof, AbstractBlock.Settings settings);

/**
* Provides default item settings that all FEN items are based on.
Expand Down Expand Up @@ -230,4 +255,15 @@ default void registerWood(String name, boolean fireproof, AbstractBlock.Settings
* Provides infested leaves block settings that all infested leaves are based on.
*/
FabricBlockSettings infestedLeavesBlockSettings();

/**
* A container for blocks of a wood type. Used as return value of {@link #registerWood}
*/
@ApiStatus.NonExtendable
interface WoodenBlockBundle {
Block sieve();
Block strainer();
Block barrel();
Block crucible();
}
}

0 comments on commit 53b6693

Please sign in to comment.