Skip to content

Commit

Permalink
feat: create constants for duplicated keys
Browse files Browse the repository at this point in the history
  • Loading branch information
iGabyTM committed Mar 17, 2024
1 parent 0e5aa89 commit 1406aee
Showing 1 changed file with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,35 +83,40 @@ class CrateReloadedImplementation : ItemSerializer() {

}

const val EFFECT: String = " effect:"
const val POWER: String = " power:"
const val DURATION: String = " duration:"
const val SPLASH: String = " splash:"

private fun StringBuilder.appendPotion(potion: Potion) {
if (potion.type.effectType == null) {
return
}

this.append(" effect:").append(potion.type.effectType?.name)
.append(" power:").append(potion.level)
.append(" duration:").append(potion.effects.first().duration)
.append(" splash:").append(potion.isSplash)
this.append(EFFECT).append(potion.type.effectType?.name)
.append(POWER).append(potion.level)
.append(DURATION).append(potion.effects.first().duration.ticksToSeconds())
.append(SPLASH).append(potion.isSplash)
}

private fun StringBuilder.appendPotion(potionMeta: PotionMeta, splash: Boolean) {
val basePotionData = potionMeta.basePotionData

if (basePotionData.type.effectType != null) {
append(" effect:").append(basePotionData.type.effectType?.name)
append(" power:").append(if (basePotionData.isUpgraded) 2 else 1)
append(EFFECT).append(basePotionData.type.effectType?.name)
append(POWER).append(if (basePotionData.isUpgraded) 2 else 1)
}

if (potionMeta.hasCustomEffects()) {
potionMeta.customEffects.forEach { customEffect ->
append(" effect:").append(customEffect.type.name)
customEffect.amplifier.ifNotZero { append(" power:").append(it) }
append(" duration:").append(customEffect.duration.ticksToSeconds()) // The time is in ticks and CR uses seconds
append(EFFECT).append(customEffect.type.name)
customEffect.amplifier.ifNotZero { power -> append(POWER).append(power) }
append(DURATION).append(customEffect.duration.ticksToSeconds())
}
}

if (splash) {
append(" splash:true")
append(SPLASH).append(true)
}
}

Expand Down

0 comments on commit 1406aee

Please sign in to comment.