This repository has been archived by the owner on May 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent LootyItems in vanilla recipes (#49)
* prevent LootyItems from being used in vanilla recipes * changes * Refactor so each system class is in its own file * Slightly clean up indentation * Don't check for SetItem component now that we explicitly deny using a component * Only prevent usage in vanilla recipes --------- Co-authored-by: Danielle Voznyy <[email protected]>
- Loading branch information
Showing
6 changed files
with
71 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
group=com.mineinabyss | ||
version=0.10 | ||
idofrontVersion=0.18.11 | ||
idofrontVersion=0.18.14 |
12 changes: 12 additions & 0 deletions
12
src/main/kotlin/com/mineinabyss/looty/features/recipes/DenyInVanillaRecipe.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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.mineinabyss.looty.features.recipes | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
/** | ||
* A component to indicate that an ItemStack should not be allowed in vanilla crafting recipes. | ||
* Meaning if a GearyItem has a base-material of PAPER and this component, it cannot be used to craft books. | ||
*/ | ||
@Serializable | ||
@SerialName("looty:deny_in_vanilla_recipes") | ||
class DenyInVanillaRecipes |
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
30 changes: 30 additions & 0 deletions
30
src/main/kotlin/com/mineinabyss/looty/features/recipes/RecipeCraftingSystem.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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.mineinabyss.looty.features.recipes | ||
|
||
import com.mineinabyss.geary.papermc.datastore.decodePrefabs | ||
import org.bukkit.Keyed | ||
import org.bukkit.event.EventHandler | ||
import org.bukkit.event.EventPriority | ||
import org.bukkit.event.Listener | ||
import org.bukkit.event.inventory.PrepareItemCraftEvent | ||
|
||
class RecipeCraftingSystem : Listener { | ||
/** | ||
* Prevents custom items being usable in vanilla recipes based on their material, | ||
* when they have a [DenyInVanillaRecipes] component, by setting result to null. | ||
*/ | ||
@EventHandler(priority = EventPriority.HIGHEST) | ||
fun PrepareItemCraftEvent.onCraftWithCustomItem() { | ||
// Ensure this only cancels vanilla recipes | ||
if (recipe == null || (recipe as? Keyed)?.key()?.namespace() != "minecraft") return | ||
|
||
if (inventory.matrix.any { | ||
it?.itemMeta?.persistentDataContainer | ||
?.decodePrefabs() | ||
?.firstOrNull() | ||
?.toEntityOrNull() | ||
?.has<DenyInVanillaRecipes>() == true | ||
}) { | ||
inventory.result = null | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/kotlin/com/mineinabyss/looty/features/recipes/RecipeDiscoverySystem.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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.mineinabyss.looty.features.recipes | ||
|
||
import org.bukkit.NamespacedKey | ||
import org.bukkit.event.EventHandler | ||
import org.bukkit.event.Listener | ||
import org.bukkit.event.player.PlayerJoinEvent | ||
|
||
class RecipeDiscoverySystem( | ||
val discoveredRecipes: List<NamespacedKey> | ||
) : Listener { | ||
@EventHandler | ||
fun PlayerJoinEvent.showRecipesOnJoin() { | ||
player.discoverRecipes(discoveredRecipes) | ||
} | ||
} |