Skip to content

Commit

Permalink
Force singleton init, fix patch, adjust for new DA
Browse files Browse the repository at this point in the history
  • Loading branch information
bibi-reden committed Aug 9, 2024
1 parent bcccffc commit b107804
Show file tree
Hide file tree
Showing 9 changed files with 348 additions and 188 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
## Changes 🌽
- Update FLK
- Fixed **Fire Resistance** not calculating correctly.
- Using the latest data-attributes with a supplied "stock" data-pack.
- You can clear your config if you wish to use stock, or keep your config with all the entries.
- Applied a patch for missing id's, which is an edge-case (will be labeled `unresolved:id`).
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ parchment_version=1.20.1:2023.09.03
quilt_mappings_version=23

# Mod Properties
mod_version=4.0.0+1.20.1-alpha.13
mod_version=4.0.0+1.20.1-alpha.14
maven_group=com.bibireden.playerex
archives_base_name=playerex-directors-cut

Expand All @@ -31,7 +31,7 @@ ranged_weapon_api_version=1.1.2+1.20.1

# in-house
opc_version=2.0.0+1.20.1-beta.4-fabric
data_attributes_version=2.0.0+1.20.1-beta.9-fabric
data_attributes_version=2.0.0+1.20.1-beta.10-fabric

# owo
owo_version=0.11.2+1.20
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class AttributeComponent(private val attribute: Attribute, private val player: P
val label: AttributeLabelComponent

fun refresh() {
val entries = DataAttributesAPI.clientManager.data.functions[attribute.id]
val entries = DataAttributesAPI.clientManager.functions[attribute.id]
if (!entries.isNullOrEmpty()) {
label.tooltip(
Component.translatable("playerex.ui.main.modified_attributes").also { text ->
Expand Down
18 changes: 7 additions & 11 deletions src/main/kotlin/com/bibireden/playerex/PlayerEX.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ package com.bibireden.playerex
import com.bibireden.data_attributes.api.DataAttributesAPI
import com.bibireden.data_attributes.api.attribute.EntityAttributeSupplier
import com.bibireden.data_attributes.api.event.EntityAttributeModifiedEvents
import com.bibireden.data_attributes.api.factory.DefaultAttributeFactory
import com.bibireden.opc.api.OfflinePlayerCacheAPI
import com.bibireden.playerex.api.PlayerEXAPI
import com.bibireden.playerex.api.PlayerEXCachedKeys
import com.bibireden.playerex.api.PlayerEXCachedKeys.Level
import com.bibireden.playerex.api.attribute.DefaultAttributeImpl
import com.bibireden.playerex.api.attribute.PlayerEXAttributes
import com.bibireden.playerex.api.attribute.TradeSkillAttributes
import com.bibireden.playerex.api.event.LivingEntityEvents
import com.bibireden.playerex.api.event.PlayerEXSoundEvents
import com.bibireden.playerex.api.event.PlayerEntityEvents
Expand All @@ -22,9 +21,6 @@ import com.bibireden.playerex.networking.registerServerbound
import com.bibireden.playerex.networking.types.UpdatePacketType
import de.dafuqs.additionalentityattributes.AdditionalEntityAttributes
import eu.pb4.placeholders.api.Placeholders
import io.wispforest.endec.Endec
import io.wispforest.endec.impl.BuiltInEndecs
import io.wispforest.endec.impl.RecordEndec
import net.fabricmc.api.ModInitializer
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback
import net.fabricmc.fabric.api.entity.event.v1.ServerPlayerEvents
Expand All @@ -33,18 +29,22 @@ import net.minecraft.core.Registry
import net.minecraft.core.registries.BuiltInRegistries
import net.minecraft.resources.ResourceLocation
import net.minecraft.world.entity.ai.attributes.Attributes
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import kotlin.jvm.optionals.getOrElse

object PlayerEX : ModInitializer {
const val MOD_ID: String = "playerex"

@JvmField
val LOGGER = LoggerFactory.getLogger(MOD_ID)
val LOGGER: Logger = LoggerFactory.getLogger(MOD_ID)

@JvmField
val CONFIG = PlayerEXConfig.createAndLoad()

// this is literally here to initialize the singletons...
val PRIMARY_ATTRIBUTE_IDS = PlayerEXAttributes.PRIMARY_ATTRIBUTE_IDS
val TRADE_SKILL_IDS = TradeSkillAttributes.IDS

fun id(path: String) = ResourceLocation.tryBuild(MOD_ID, path)!!

private val gimmick = listOf(
Expand Down Expand Up @@ -89,10 +89,6 @@ object PlayerEX : ModInitializer {
Registry.register(BuiltInRegistries.SOUND_EVENT, PlayerEXSoundEvents.SPEND_SOUND.location, PlayerEXSoundEvents.SPEND_SOUND)
Registry.register(BuiltInRegistries.SOUND_EVENT, PlayerEXSoundEvents.REFUND_SOUND.location, PlayerEXSoundEvents.REFUND_SOUND)

DefaultAttributeFactory.registerOverrides(DefaultAttributeImpl.OVERRIDES)
DefaultAttributeFactory.registerFunctions(DefaultAttributeImpl.FUNCTIONS)
DefaultAttributeFactory.registerEntityTypes(DefaultAttributeImpl.ENTITY_TYPES)

EntityAttributeModifiedEvents.MODIFIED.register { attribute, entity, _, _, _ ->
if (entity?.level() == null) return@register // no entity & no world, skip

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,11 @@ import net.minecraft.resources.ResourceLocation
import net.minecraft.world.entity.ai.attributes.Attribute


/**
* Expects the [Attribute] to be registered by the time it is invoked.
*
* Returns an unresolved [ResourceLocation] if invalid.
* Do not use this in static initialization.
* */
val Attribute.id: ResourceLocation
get() = BuiltInRegistries.ATTRIBUTE.getKey(this)!!
get() = BuiltInRegistries.ATTRIBUTE.getKey(this) ?: ResourceLocation.tryBuild("unresolved", "id")!!
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"entries": {
"minecraft:player": {
"playerex:level": 0.0,
"playerex:constitution": 0.0,
"playerex:strength": 0.0,
"playerex:dexterity": 0.0,
"playerex:intelligence": 0.0,
"playerex:luckiness": 0.0,
"playerex:evasion": 0.0,
"playerex:lifesteal": 0.0,
"playerex:focus": 0.0,
"playerex:health_regeneration": 0.0,
"playerex:heal_amplification": 0.0,
"playerex:melee_crit_damage": 0.0,
"playerex:melee_crit_chance": 0.0,
"playerex:ranged_crit_damage": 0.0,
"playerex:ranged_crit_chance": 0.0,
"playerex:fire_resistance": 0.0,
"playerex:freeze_resistance": 0.0,
"playerex:lightning_resistance": 0.0,
"playerex:poison_resistance": 0.0,
"playerex:wither_resistance": 0.0,
"playerex:breaking_speed": 1.0,
"playerex:enchanting": 0.0,
"playerex:logging": 0.0,
"playerex:alchemy": 0.0,
"playerex:fishing": 0.0,
"playerex:mining": 0.0,
"playerex:smithing": 0.0,
"playerex:farming": 0.0
}
}
}
Loading

0 comments on commit b107804

Please sign in to comment.