Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ org.jetbrains.dokka.experimental.gradle.pluginMode=V2Enabled
javaVersion=25
mcVersion=26.1.2
group=dev.slne.surf.api
version=3.17.2
version=3.18.0
relocationPrefix=dev.slne.surf.api.libs
snapshot=false
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,36 @@ class V1_21_11SurfPaperNmsLootTableBridgeImpl : SurfPaperNmsLootTableBridge {
return lootTable.getRandomItems(lootParams, nmsEntity.lootTableSeed)
.mapTo(mutableObjectListOf()) { it.toBukkit() }
}

override fun rollLootTable(
entity: LivingEntity,
damageSource: DamageSource,
causedByPlayer: Boolean
): Collection<ItemStack> {
val nmsEntity = entity.toNms()
val lootTableKey = nmsEntity.lootTable.getOrNull() ?: return emptyObjectList()
val lootTable = MinecraftServer.getServer().reloadableRegistries().getLootTable(lootTableKey)
val nmsDamageSource = damageSource.toNms()

val paramBuilder = LootParams.Builder(nmsEntity.level() as ServerLevel)
.withParameter(LootContextParams.THIS_ENTITY, nmsEntity)
.withParameter(LootContextParams.ORIGIN, nmsEntity.position())
.withParameter(LootContextParams.DAMAGE_SOURCE, nmsDamageSource)
.withOptionalParameter(LootContextParams.ATTACKING_ENTITY, nmsDamageSource.entity)
.withOptionalParameter(
LootContextParams.DIRECT_ATTACKING_ENTITY,
nmsDamageSource.directEntity
)

val lastHurtByPlayer = nmsEntity.getLastHurtByPlayer()
if (causedByPlayer && lastHurtByPlayer != null) {
paramBuilder.withParameter(LootContextParams.LAST_DAMAGE_PLAYER, lastHurtByPlayer)
.withLuck(lastHurtByPlayer.luck)
}

val lootParams = paramBuilder.create(LootContextParamSets.ENTITY)

return lootTable.getRandomItems(lootParams, nmsEntity.lootTableSeed)
.mapTo(mutableObjectListOf()) { it.toBukkit() }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,36 @@ class V26_1SurfPaperNmsLootTableBridgeImpl : SurfPaperNmsLootTableBridge {
return lootTable.getRandomItems(lootParams, nmsEntity.lootTableSeed)
.mapTo(mutableObjectListOf()) { it.toBukkit() }
}

override fun rollLootTable(
entity: LivingEntity,
damageSource: DamageSource,
causedByPlayer: Boolean
): Collection<ItemStack> {
val nmsEntity = entity.toNms()
val lootTableKey = nmsEntity.lootTable.getOrNull() ?: return emptyObjectList()
val lootTable = MinecraftServer.getServer().reloadableRegistries().getLootTable(lootTableKey)
val nmsDamageSource = damageSource.toNms()

val paramBuilder = LootParams.Builder(nmsEntity.level() as ServerLevel)
.withParameter(LootContextParams.THIS_ENTITY, nmsEntity)
.withParameter(LootContextParams.ORIGIN, nmsEntity.position())
.withParameter(LootContextParams.DAMAGE_SOURCE, nmsDamageSource)
.withOptionalParameter(LootContextParams.ATTACKING_ENTITY, nmsDamageSource.entity)
.withOptionalParameter(
LootContextParams.DIRECT_ATTACKING_ENTITY,
nmsDamageSource.directEntity
)

val lastHurtByPlayer = nmsEntity.getLastHurtByPlayer()
if (causedByPlayer && lastHurtByPlayer != null) {
paramBuilder.withParameter(LootContextParams.LAST_DAMAGE_PLAYER, lastHurtByPlayer)
.withLuck(lastHurtByPlayer.luck)
}

val lootParams = paramBuilder.create(LootContextParamSets.ENTITY)

return lootTable.getRandomItems(lootParams, nmsEntity.lootTableSeed)
.mapTo(mutableObjectListOf()) { it.toBukkit() }
}
}
2 changes: 2 additions & 0 deletions surf-api-paper/surf-api-paper/api/surf-api-paper.api
Original file line number Diff line number Diff line change
Expand Up @@ -1703,11 +1703,13 @@ public final class dev/slne/surf/api/paper/nms/bridges/SurfPaperNmsItemBridge$Co
public abstract interface class dev/slne/surf/api/paper/nms/bridges/SurfPaperNmsLootTableBridge {
public static final field Companion Ldev/slne/surf/api/paper/nms/bridges/SurfPaperNmsLootTableBridge$Companion;
public abstract fun getDifferentLootTable (Lorg/bukkit/entity/LivingEntity;Lorg/bukkit/damage/DamageSource;Lorg/bukkit/entity/EntityType;Z)Ljava/util/Collection;
public abstract fun rollLootTable (Lorg/bukkit/entity/LivingEntity;Lorg/bukkit/damage/DamageSource;Z)Ljava/util/Collection;
}

public final class dev/slne/surf/api/paper/nms/bridges/SurfPaperNmsLootTableBridge$Companion : dev/slne/surf/api/paper/nms/bridges/SurfPaperNmsLootTableBridge {
public fun getDifferentLootTable (Lorg/bukkit/entity/LivingEntity;Lorg/bukkit/damage/DamageSource;Lorg/bukkit/entity/EntityType;Z)Ljava/util/Collection;
public final fun getINSTANCE ()Ldev/slne/surf/api/paper/nms/bridges/SurfPaperNmsLootTableBridge;
public fun rollLootTable (Lorg/bukkit/entity/LivingEntity;Lorg/bukkit/damage/DamageSource;Z)Ljava/util/Collection;
}

public abstract interface class dev/slne/surf/api/paper/nms/bridges/SurfPaperNmsNbtBridge {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ interface SurfPaperNmsLootTableBridge {
causedByPlayer: Boolean,
): Collection<ItemStack>

fun rollLootTable(
entity: LivingEntity,
damageSource: DamageSource,
causedByPlayer: Boolean,
): Collection<ItemStack>

companion object : SurfPaperNmsLootTableBridge by bridge {
val INSTANCE get() = bridge
}
Expand Down