Skip to content

Commit

Permalink
Support giving players non-card items like potions, keys, and coins
Browse files Browse the repository at this point in the history
  • Loading branch information
4Ply committed Sep 15, 2024
1 parent da25d81 commit c8bcdd6
Show file tree
Hide file tree
Showing 27 changed files with 234 additions and 1,670 deletions.
2 changes: 0 additions & 2 deletions .openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ src/main/kotlin/org/trackedout/client/apis/ClaimApi.kt
src/main/kotlin/org/trackedout/client/apis/EventsApi.kt
src/main/kotlin/org/trackedout/client/apis/InventoryApi.kt
src/main/kotlin/org/trackedout/client/apis/ScoreApi.kt
src/main/kotlin/org/trackedout/client/apis/StateApi.kt
src/main/kotlin/org/trackedout/client/apis/StatusApi.kt
src/main/kotlin/org/trackedout/client/apis/TasksApi.kt
src/main/kotlin/org/trackedout/client/infrastructure/ApiAbstractions.kt
Expand Down Expand Up @@ -32,7 +31,6 @@ src/main/kotlin/org/trackedout/client/models/InventoryCardsGet200Response.kt
src/main/kotlin/org/trackedout/client/models/Item.kt
src/main/kotlin/org/trackedout/client/models/Score.kt
src/main/kotlin/org/trackedout/client/models/ScoresGet200Response.kt
src/main/kotlin/org/trackedout/client/models/StateGet200Response.kt
src/main/kotlin/org/trackedout/client/models/StatusSection.kt
src/main/kotlin/org/trackedout/client/models/StatusSectionLinesInner.kt
src/main/kotlin/org/trackedout/client/models/StorageItemsGet200Response.kt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,33 +71,57 @@ class AddDeckToPlayerInventoryAction(
shulkerNbt.putString("owner", playerName)
shulkerNbt.putUuid("owner-id", player.uuid)

val cardCount = cards.groupingBy { it.name!! }.eachCount()
val cardCount = cards
.filter { Cards.findCard(it.name!!) != null }
.groupingBy { it.name!! }.eachCount()
var cardIndex = 0
player.debug("Your shulker should contain ${cards.size} cards:")
cardCount.forEach { (cardName, count) ->
player.debug("- ${count}x $cardName")
logger.info("$playerName's shulker should contain ${count}x $cardName")

val card = Cards.findCard(cardName)
if (card == null) {
player.sendMessage("Unknown card '${cardName}', Agronet will not add it to your deck", Formatting.RED)
logger.error("Unknown card '${cardName}', Agronet cannot add it to $playerName's deck")
} else {
val cardData = createCard(cardIndex++, card, count)
shulkerItems.add(cardData)

eventsApi.eventsPost(
Event(
name = "card-exists-on-join-${cardName.replace("_", "-")}",
player = playerName,
x = 0.0,
y = 0.0,
z = 0.0,
count = count,
)
val card = Cards.findCard(cardName)!!
val cardData = createCard(cardIndex++, card, count)
shulkerItems.add(cardData)

eventsApi.eventsPost(
Event(
name = "card-exists-on-join-${cardName.replace("_", "-")}",
player = playerName,
x = 0.0,
y = 0.0,
z = 0.0,
count = count,
)
}
)
}

cards
.filter { Cards.findCard(it.name!!) == null }
.forEach { item ->
val itemName = item.name!!
if (dungeonItemsForGiveCommand.containsKey(itemName)) {
logger.info("Giving $playerName 1x$itemName (and deleting it from item storage)")
inventoryApi.inventoryDeleteCardPost(item)
eventsApi.eventsPost(
Event(
name = "item-deleted-$itemName",
player = playerName,
x = 0.0,
y = 0.0,
z = 0.0,
count = 1,
)
)

val item = dungeonItemsForGiveCommand[itemName]!!
player.giveItemStack(item.copy())
} else {
player.sendMessage("Unknown card '${itemName}', Agronet will not add it to your deck", Formatting.RED)
logger.error("Unknown card '${itemName}', Agronet cannot add it to $playerName's deck")
}
}

shulkerNbt.put(BlockItem.BLOCK_ENTITY_TAG_KEY, blockCompound)

val shulkerBox = ItemStack(Items.CYAN_SHULKER_BOX)
Expand Down
153 changes: 153 additions & 0 deletions src/main/kotlin/org/trackedout/actions/DungeonItems.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
package org.trackedout.actions

import net.minecraft.item.ItemStack
import net.minecraft.item.Items
import net.minecraft.nbt.StringNbtReader

val dungeonItemsForGiveCommand = mapOf(

"SLOWNESS_POTION" to ItemStack(Items.SPLASH_POTION).also {
it.nbt = StringNbtReader.parse(
"""
{ "Potion": "minecraft:strong_slowness" }
""".trimIndent()
)
},

"CAVES_OF_CARNAGE_KEY" to ItemStack(Items.IRON_NUGGET).also {
it.nbt = StringNbtReader.parse(
"""
{
"tracked": 1b,
"CustomModelData": 201,
"display": {
"Name": "{\"text\":\"❄☠ The Caves of Carnage Key ☠❄\"}"
}
}
""".trimIndent()
)
},

"BLACK_MINES_KEY" to ItemStack(Items.IRON_NUGGET).also {
it.nbt = StringNbtReader.parse(
"""
{
"tracked": 1b,
"CustomModelData": 203,
"display": {
"Name": "{\"text\":\"❄☠ The Black Mines Key ☠❄\"}"
}
}
""".trimIndent()
)
},

"BURNING_DARK_KEY" to ItemStack(Items.IRON_NUGGET).also {
it.nbt = StringNbtReader.parse(
"""
{
"tracked": 1b,
"CustomModelData": 209,
"display": {
"Name": "{\"text\":\"❄☠ The Burning Dark Key ☠❄\"}"
}
}
""".trimIndent()
)
},

"COIN" to ItemStack(Items.IRON_NUGGET).also {
it.nbt = StringNbtReader.parse(
"""
{
"tracked": 1b,
"CustomModelData": 1,
"display": {
"Name": "{\"text\":\"❄☠ Decked Out Coin ☠❄\"}"
}
}
""".trimIndent()
)
},

"CROWN" to ItemStack(Items.IRON_NUGGET).also {
it.nbt = StringNbtReader.parse(
"""
{
"tracked": 1b,
"CustomModelData": 2,
"display": {
"Name": "{\"text\":\"❄☠ Decked Out Crown ☠❄\"}"
}
}
""".trimIndent()
)
},

"RUSTY_REPAIR_KIT" to ItemStack(Items.IRON_INGOT).also {
it.nbt = StringNbtReader.parse(
"""
{
"display": {
"Name": "[{\"text\":\"❄☠ Rusty Repair Kit ☠❄\"}]"
},
"CustomModelData": 2
}
""".trimIndent()
)
}

)

/*
{ "Potion": "minecraft:strong_slowness" }
{
"tracked": 1b,
"CustomModelData": 201,
"display": {
"Name": "{\"text\":\"❄☠ The Caves of Carnage Key ☠❄\"}"
}
}
{
"tracked": 1b,
"CustomModelData": 203,
"display": {
"Name": "{\"text\":\"❄☠ The Black Mines Key ☠❄\"}"
}
}
{
"tracked": 1b,
"CustomModelData": 209,
"display": {
"Name": "{\"text\":\"❄☠ The Burning Dark Key ☠❄\"}"
}
}
{
"tracked": 1b,
"CustomModelData": 1,
"display": {
"Name": "{\"text\":\"❄☠ Decked Out Coin ☠❄\"}"
}
}
{
"tracked": 1b,
"CustomModelData": 2,
"display": {
"Name": "{\"text\":\"❄☠ Decked Out Crown ☠❄\"}"
}
}
{
"display": {
"Name": "[{\"text\":\"❄☠ Rusty Repair Kit ☠❄\"}]"
},
"CustomModelData": 2
}
*/
Loading

0 comments on commit c8bcdd6

Please sign in to comment.