Skip to content

Commit

Permalink
#76 Add CompostableUtils feature
Browse files Browse the repository at this point in the history
This update introduces the CompostableUtils class into the growthcraft.core.utils package. The class includes methods for registering an item as compostable with specific or custom compostability values, and retrieving the compostable value associated with a given key. This helps facilitate compostable items management in the Growthcraft mod for Minecraft.
  • Loading branch information
Alatyami committed Feb 10, 2024
1 parent a4349ec commit 90d2636
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions src/main/java/growthcraft/core/utils/CompostableUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package growthcraft.core.utils;

import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.ComposterBlock;

public class CompostableUtils {

/**
* Registers an item as compostable with a specific compostability value.
*
* @param item the item to register as compostable
* @param compostable the compostability value of the item
*/
public static void registerCompostable(Item item, COMPOSTABLE compostable) {
ComposterBlock.COMPOSTABLES.put(item, compostable.getValue());
}

/**
* Registers an item as compostable with a custom compostability value.
*
* @param item the item to register as compostable
* @param compostable the custom compostability value of the item (between 0.0 and 1.0)
*/
public static void registerCompostableCustom(Item item, float compostable) {
ComposterBlock.COMPOSTABLES.put(item, compostable);
}

/**
* Retrieves the compostable value associated with the given key.
*
* @param key the key to look up the compostable value for
* @return the compostable value associated with the given key, or NORMAL if no matching key is found
*/
public static COMPOSTABLE getCompostableByString(String key) {
switch (key) {
case "lowest":
return COMPOSTABLE.LOWEST;
case "low":
return COMPOSTABLE.LOW;
case "high":
return COMPOSTABLE.HIGH;
case "highest":
return COMPOSTABLE.HIGHEST;
default:
return COMPOSTABLE.NORMAL;
}
}

public enum COMPOSTABLE {
LOWEST(0.3F),
LOW(0.5F),
NORMAL(0.65F),
HIGH(0.85F),
HIGHEST(1.0F);

private final float value;

COMPOSTABLE(float value) {
this.value = value;
}

public float getValue() {
return value;
}
}

}

0 comments on commit 90d2636

Please sign in to comment.