-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
1 changed file
with
67 additions
and
0 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
src/main/java/growthcraft/core/utils/CompostableUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
|
||
} |