Skip to content

Commit

Permalink
Added ItemGroup methods to RecipeBuilder + javadocs
Browse files Browse the repository at this point in the history
  • Loading branch information
UselessBullets committed May 8, 2024
1 parent c0e499d commit 5776a9c
Show file tree
Hide file tree
Showing 11 changed files with 470 additions and 20 deletions.
31 changes: 30 additions & 1 deletion src/main/java/turniplabs/halplibe/helper/BlockBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public BlockBuilder setBlockColor(Function<Block, BlockColor> blockColorSupplier
* Example code:
* <pre>{@code
* public static final Block customFlower = new BlockBuilder(MOD_ID)
* .setBlockModel(BlockModelCrossedSquares::new))
* .setBlockModel(block -> new BlockModelCrossedSquares<>(block)))
* .build(new BlockFlower("custom.flower", 4002);
* }</pre>
*/
Expand All @@ -272,6 +272,17 @@ public BlockBuilder setBlockModel(@NotNull Function<Block, BlockModel<?>> blockM
blockBuilder.blockModelSupplier = blockModelSupplier;
return blockBuilder;
}

/**
* Sets the item form of the block's visible model.<br>
* Example code:
* <pre>{@code
* public static final Block customFlower = new BlockBuilder(MOD_ID)
* .setItemModel(block -> new ItemModelBlock(block, MOD_ID)))
* .build(new BlockFlower("custom.flower", 4002);
* }</pre>
*/
@SuppressWarnings({"unused"})
public BlockBuilder setItemModel(@NotNull Function<ItemBlock, ItemModel> itemModelSupplier) {
BlockBuilder blockBuilder = this.clone();
blockBuilder.customItemModelSupplier = itemModelSupplier;
Expand All @@ -294,6 +305,9 @@ public BlockBuilder setItemBlock(BlockLambda<ItemBlock> customItemBlock) {
return blockBuilder;
}

/**
* Overrides all previous tags with the ones provided
*/
@SafeVarargs
@SuppressWarnings({"unused"})
public final BlockBuilder setTags(Tag<Block>... tags) {
Expand All @@ -302,6 +316,9 @@ public final BlockBuilder setTags(Tag<Block>... tags) {
return blockBuilder;
}

/**
* Adds provided tags to previously specified tags
*/
@SafeVarargs
@SuppressWarnings({"unused"})
public final BlockBuilder addTags(Tag<Block>... tags) {
Expand All @@ -310,6 +327,11 @@ public final BlockBuilder addTags(Tag<Block>... tags) {
return blockBuilder;
}

/**
* Applies the builder configuration to the supplied block.
* @param block Input block object
* @return Returns the input block after builder settings are applied to it.
*/
@SuppressWarnings({"unused"})
public <T extends Block> T build(T block) {
if (hardness != null) {
Expand Down Expand Up @@ -459,6 +481,10 @@ public static void reserveRuns(String modId, Toml runs, int neededIds, Consumer<
public static class Assignment{
public static boolean blockDispatcherInitialized = false;
public static final Map<Block, Function<Block, BlockModel<?>>> queuedBlockModels = new LinkedHashMap<>();

/**
* Queues a BlockModel assignment until the game is ready to do so
*/
public static void queueBlockModel(@NotNull Block block, Function<Block, BlockModel<?>> blockModelSupplier){
if (!HalpLibe.isClient) return;
if (blockModelSupplier == null) return;
Expand All @@ -471,6 +497,9 @@ public static void queueBlockModel(@NotNull Block block, Function<Block, BlockMo
}
public static boolean blockColorDispatcherInitialized = false;
public static final Map<Block, Function<Block, BlockColor>> queuedBlockColors = new LinkedHashMap<>();
/**
* Queues a BlockColor assignment until the game is ready to do so
*/
public static void queueBlockColor(@NotNull Block block, Function<Block, BlockColor> blockColorSupplier){
if (!HalpLibe.isClient) return;
if (blockColorSupplier == null) return;
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/turniplabs/halplibe/helper/EntityHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public static void createSpecialTileEntity(Class<? extends TileEntity> clazz, St
public static class Assignment {
public static boolean entityRendererDispatcherInitialized = false;
public static final Map<Class<? extends Entity> , Supplier<EntityRenderer<?>>> queuedEntityRenderer = new LinkedHashMap<>();
/**
* Queues aa EntityRenderer assignment until the game is ready to do so
*/
public static void queueEntityRenderer(@NotNull Class<? extends Entity> clazz, @NotNull Supplier<EntityRenderer<?>> rendererSupplier){
if (!HalpLibe.isClient) return;
if (rendererSupplier == null) return;
Expand All @@ -50,6 +53,9 @@ public static void queueEntityRenderer(@NotNull Class<? extends Entity> clazz, @
}
public static boolean tileEntityRendererDispatcherInitialized = false;
public static final Map<Class<? extends TileEntity> , Supplier<TileEntityRenderer<?>>> queuedTileEntityRenderer = new LinkedHashMap<>();
/**
* Queues a TileEntityRenderer assignment until the game is ready to do so
*/
public static void queueTileEntityRenderer(@NotNull Class<? extends TileEntity> clazz, @NotNull Supplier<TileEntityRenderer<?>> rendererSupplier){
if (!HalpLibe.isClient) return;
if (rendererSupplier == null) return;
Expand Down
53 changes: 52 additions & 1 deletion src/main/java/turniplabs/halplibe/helper/ItemBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -47,31 +46,69 @@ public ItemBuilder clone() {
throw new AssertionError();
}
}

/**
* Sets the ItemModel to be assigned to the {@link Item} built.
* @param modelSupplier Provides the {@link Item} built in {@link #build(Item)} to a lambda that returns an {@link ItemModel}
* @return @return Copy of {@link ItemBuilder}
*/
@SuppressWarnings({"unused"})
public ItemBuilder setItemModel(Function<Item, ItemModel> modelSupplier){
ItemBuilder builder = this.clone();
builder.customItemModelSupplier = modelSupplier;
return builder;
}
/**
* Sets the key to the built {@link Item}, for example if you set the key "gem.sapphire" the actual key ingame will be "item.<modid>.gem.sapphire"
* @param key Override translation key for the {@link Item}
* @return @return Copy of {@link ItemBuilder}
*/
@SuppressWarnings({"unused"})
public ItemBuilder setKey(String key){
ItemBuilder builder = this.clone();
builder.overrideKey = key;
return builder;
}
/**
* Sets stack size for the built {@link Item}, will override any class default stacksizes
* @param stackSize Stack size of the {@link Item}
* @return @return Copy of {@link ItemBuilder}
*/
@SuppressWarnings({"unused"})
public ItemBuilder setStackSize(int stackSize){
ItemBuilder builder = this.clone();
builder.stackSize = stackSize;
return builder;
}

/**
* Sets max durability for the built {@link Item}, will override any class default max damage values.
* Probably only really affects tool classes.
* @param maxDamage Max durability of the {@link Item}
* @return @return Copy of {@link ItemBuilder}
*/
@SuppressWarnings({"unused"})
public ItemBuilder setMaxDamage(int maxDamage){
ItemBuilder builder = this.clone();
builder.maxDamage = maxDamage;
return builder;
}
/**
* Sets the container item for the built item. For example {@code Item.bucketMilk} uses the container item {@code Item.bucket}
* @param itemSupplier Supplies the {@link Item} to set as the container item
* @return @return Copy of {@link ItemBuilder}
*/
@SuppressWarnings({"unused"})
public ItemBuilder setContainerItem(Supplier<Item> itemSupplier){
ItemBuilder builder = this.clone();
builder.containerItemSupplier = itemSupplier;
return builder;
}

/**
* Overrides all previous tags with the ones provided
* @return @return Copy of {@link ItemBuilder}
*/
@SafeVarargs
@SuppressWarnings({"unused"})
public final ItemBuilder setTags(Tag<Item>... tags) {
Expand All @@ -80,6 +117,10 @@ public final ItemBuilder setTags(Tag<Item>... tags) {
return itemBuilder;
}

/**
* Adds provided tags to previously specified tags
* @return @return Copy of {@link ItemBuilder}
*/
@SafeVarargs
@SuppressWarnings({"unused"})
public final ItemBuilder addTags(Tag<Item>... tags) {
Expand All @@ -88,6 +129,12 @@ public final ItemBuilder addTags(Tag<Item>... tags) {
return itemBuilder;
}

/**
* Applies the builder configuration to the supplied item.
* @param item Input item object
* @return Returns the input item after builder settings are applied to it.
*/
@SuppressWarnings("unused")
public <T extends Item> T build(T item){
List<String> tokens;

Expand Down Expand Up @@ -124,6 +171,10 @@ public <T extends Item> T build(T item){
public static class Assignment{
public static boolean itemDispatcherInitialized = false;
public static final Map<Item, Function<Item, ItemModel>> queuedItemModels = new LinkedHashMap<>();
/**
* Queues a ItemModel assignment until the game is ready to do so
*/
@SuppressWarnings("unchecked")
public static <T extends Item> void queueItemModel(@NotNull T item, @NotNull Function<T, ItemModel> itemModelSupplier){
if (!HalpLibe.isClient) return;
if (itemDispatcherInitialized){
Expand Down
Loading

0 comments on commit 5776a9c

Please sign in to comment.