-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
76a7fc2
commit e36ce7d
Showing
37 changed files
with
300 additions
and
206 deletions.
There are no files selected for viewing
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
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
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
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
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,61 @@ | ||
package forestry.api.core; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
import net.minecraft.util.RandomSource; | ||
import net.minecraft.world.item.Item; | ||
import net.minecraft.world.item.ItemStack; | ||
|
||
import it.unimi.dsi.fastutil.Hash; | ||
|
||
/** | ||
* Represents some item that has a set chance of being produced. | ||
* | ||
* @see Product The default implementation used in the majority of cases. | ||
*/ | ||
public interface IProduct { | ||
/** | ||
* A hashing strategy used for FastUtil custom hash collections. | ||
* Currently, Forestry uses this to remove common products between species from the product list of a hybrid bee. | ||
*/ | ||
Hash.Strategy<IProduct> ITEM_ONLY_STRATEGY = new Hash.Strategy<>() { | ||
@Override | ||
public int hashCode(@Nullable IProduct o) { | ||
return o == null ? 0 : o.item().hashCode(); | ||
} | ||
|
||
@Override | ||
public boolean equals(@Nullable IProduct a, @Nullable IProduct b) { | ||
return (a == null || b == null) ? a == b : a.item() == b.item(); | ||
} | ||
}; | ||
|
||
// todo should this be replaced with is(ItemStack) and getIconStack() methods instead? | ||
/** | ||
* Gets the item this product contains. In the case of a dynamic product, return an item that might | ||
* be used to display it in a screen or for equality purposes in {@link #ITEM_ONLY_STRATEGY}. | ||
* | ||
* @return The item this product represents. | ||
*/ | ||
Item item(); | ||
|
||
/** | ||
* @return The set chance of this product being produced. | ||
*/ | ||
float chance(); | ||
|
||
/** | ||
* @return A new stack of this product. If your product is dynamic, return a "default" nonempty stack. | ||
*/ | ||
ItemStack createStack(); | ||
|
||
/** | ||
* Used to produce a random variant of this product. | ||
* | ||
* @param random The random source. If no randomness is desired, call {@link #createStack} instead. | ||
* @return A new stack of this product with potentially random properties. | ||
*/ | ||
default ItemStack createRandomStack(RandomSource random) { | ||
return createStack(); | ||
} | ||
} |
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
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
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
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
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
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
Oops, something went wrong.