Skip to content

Commit

Permalink
Fixed the previous commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
TheOnlyTails committed Mar 28, 2021
1 parent 82146da commit 0127e9e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 22 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ kffVersion=1.10.0
# https://maven.apache.org/guides/mini/guide-naming-conventions.html
package=com.theonlytails
artifact=loottables
modVersion=0.1.2
modVersion=0.1.3
# Misc
author=TheOnlyTails
# Config
Expand Down
10 changes: 5 additions & 5 deletions src/main/kotlin/com/theonlytails/loottables/LootEntries.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fun LootPool.Builder.itemEntry(
@LootTablesDsl
fun LootPool.Builder.itemEntry(
item: IItemProvider,
body: StandaloneLootEntry.Builder<*>.() -> StandaloneLootEntry.Builder<*>,
body: StandaloneLootEntry.Builder<*>.() -> LootEntry.Builder<*>,
): LootPool.Builder = add(ItemLootEntry.lootTableItem(item).body())

@LootTablesDsl
Expand All @@ -27,7 +27,7 @@ fun LootPool.Builder.tagEntry(
@LootTablesDsl
fun LootPool.Builder.tagEntry(
tag: ITag<Item>,
body: StandaloneLootEntry.Builder<*>.() -> StandaloneLootEntry.Builder<*>,
body: StandaloneLootEntry.Builder<*>.() -> LootEntry.Builder<*>,
): LootPool.Builder = add(TagLootEntry.expandTag(tag).body())

@LootTablesDsl
Expand All @@ -38,7 +38,7 @@ fun LootPool.Builder.tableEntry(
@LootTablesDsl
fun LootPool.Builder.tableEntry(
lootTable: ResourceLocation,
body: StandaloneLootEntry.Builder<*>.() -> StandaloneLootEntry.Builder<*>,
body: StandaloneLootEntry.Builder<*>.() -> LootEntry.Builder<*>,
): LootPool.Builder = add(TableLootEntry.lootTableReference(lootTable).body())

@LootTablesDsl
Expand All @@ -49,7 +49,7 @@ fun LootPool.Builder.dynamicEntry(
@LootTablesDsl
fun LootPool.Builder.dynamicEntry(
id: ResourceLocation,
body: StandaloneLootEntry.Builder<*>.() -> StandaloneLootEntry.Builder<*>,
body: StandaloneLootEntry.Builder<*>.() -> LootEntry.Builder<*>,
): LootPool.Builder = add(DynamicLootEntry.dynamicEntry(id).body())

@LootTablesDsl
Expand All @@ -75,5 +75,5 @@ fun LootEntry.Builder<*>.condition(getCondition: () -> ILootCondition.IBuilder):
`when`(getCondition())

@LootTablesDsl
fun StandaloneLootEntry.Builder<*>.function(getFunction: () -> ILootFunction.IBuilder): LootEntry.Builder<*> =
fun StandaloneLootEntry.Builder<*>.function(getFunction: () -> ILootFunction.IBuilder): StandaloneLootEntry.Builder<*> =
apply(getFunction())
30 changes: 14 additions & 16 deletions src/test/kotlin/LootTablesTest.kt
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
import com.google.gson.Gson
import com.theonlytails.loottables.*
import io.kotest.core.spec.style.StringSpec
import net.minecraft.block.Blocks
import net.minecraft.block.SlabBlock
import net.minecraft.loot.LootParameterSets.BLOCK
import net.minecraft.state.properties.SlabType
import net.minecraft.loot.LootSerializers
import net.minecraft.loot.functions.CopyName

val gson: Gson = LootSerializers.createLootTableSerializer()
.disableHtmlEscaping()
.setPrettyPrinting()
.create()

class LootTablesTest : StringSpec({
"drop slabs" {
lootTable(BLOCK) {
"loot entries with functions" {
println(gson.toJson(lootTable(BLOCK) {
pool {
itemEntry(Blocks.ACACIA_SLAB)

condition { survivesExplosion() }
function {
setCount(constantRange(2)) {
condition {
blockStateProperty(Blocks.ACACIA_SLAB).setProperties(
stateProperties { hasProperty(SlabBlock.TYPE, SlabType.DOUBLE) }
)
}
}
itemEntry(Blocks.CHEST) {
function { copyName(CopyName.Source.BLOCK_ENTITY) }
}
condition { survivesExplosion() }
}
}
}))
}
}
)

0 comments on commit 0127e9e

Please sign in to comment.