-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from AtriusX/dev/custom-key-recipe
- Loading branch information
Showing
10 changed files
with
84 additions
and
32 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
31 changes: 20 additions & 11 deletions
31
src/main/kotlin/xyz/atrius/waystones/data/crafting/CompassRecipe.kt
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 |
---|---|---|
@@ -1,19 +1,28 @@ | ||
package xyz.atrius.waystones.data.crafting | ||
|
||
import org.bukkit.Material | ||
import xyz.atrius.waystones.utility.defaultWarpKey | ||
import xyz.atrius.waystones.utility.toKey | ||
import xyz.atrius.waystones.configuration | ||
import xyz.atrius.waystones.utility.* | ||
|
||
object CompassRecipe : CraftingRecipe("is_warp_key".toKey(), defaultWarpKey()) { | ||
|
||
override val recipe = """ | ||
| * | ||
|*x* | ||
| * | ||
""".trimMargin() | ||
private val keyRecipe = configuration.keyRecipe() | ||
|
||
override val items = hashMapOf( | ||
'*' to Material.IRON_INGOT, | ||
'x' to Material.REDSTONE_BLOCK | ||
) | ||
override val recipe = run { | ||
// Pull recipe from config and determine grid size (list can be size 1, 4, or 9) | ||
val size = sqrt(keyRecipe.size) | ||
keyRecipe | ||
// Map each item to it's hash char | ||
.map(String::hashChar) | ||
// Chunk the list by its square size | ||
.chunked(size) | ||
// Glue each list into a string and join each by a newline | ||
.joinToString("\n", transform = List<Char>::glue) | ||
} | ||
|
||
override val items = hashMapOf<Char, Material>().apply { | ||
// For each item in the recipe, map it's material to it's hashcode | ||
for (item in keyRecipe.toHashSet()) | ||
this[item.hashChar()] = Material.valueOf(item) | ||
} | ||
} |
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,11 @@ | ||
package xyz.atrius.waystones.utility | ||
|
||
import kotlin.math.sqrt as ktSqrt | ||
|
||
// Helper function since kotlin doesn't have a native fixed-point square root | ||
fun sqrt(value: Int): Int = | ||
ktSqrt(value.toFloat()).toInt() | ||
|
||
// Calculates the character representation of an object based on its hashcode | ||
fun Any.hashChar(): Char = | ||
hashCode().toChar() |
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