Skip to content

Commit

Permalink
[ref] use xor for switching, remove shadow of id
Browse files Browse the repository at this point in the history
  • Loading branch information
bibi-reden committed Sep 26, 2024
1 parent 5d58900 commit a02a3e0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ class AttributeOverrideProviderV2(val option: Option<Map<Identifier, AttributeOv
.apply {
setEditableColor(0xf2e1c0)
setTextPredicate { str ->
val id = Identifier.tryParse(str) ?: return@setTextPredicate true
if (backing.containsKey(id)) {
val predId = Identifier.tryParse(str) ?: return@setTextPredicate true
if (backing.containsKey(predId)) {
setEditableColor(0xe54d48)
}
else if (Registries.ATTRIBUTE[id] == null) {
else if (!Registries.ATTRIBUTE.containsId(predId)) {
setEditableColor(0xf2e1c0)
}
else {
Expand All @@ -118,8 +118,8 @@ class AttributeOverrideProviderV2(val option: Option<Map<Identifier, AttributeOv
// ensured that this exists and is possible to swap
this.backing.remove(id)
this.backing[newId] = override.copy(
min = newAttribute.`data_attributes$min_fallback`() ?: override.min_fallback,
max = newAttribute.`data_attributes$max_fallback`() ?: override.max_fallback,
min = newAttribute.`data_attributes$min_fallback`(),
max = newAttribute.`data_attributes$max_fallback`(),
smoothness = 1.0,
formula = StackingFormula.Flat,
format = AttributeFormat.Whole
Expand Down Expand Up @@ -218,10 +218,7 @@ class AttributeOverrideProviderV2(val option: Option<Map<Identifier, AttributeOv
)
hf.child(
Components.button(Text.translatable("text.config.data_attributes.enum.stackingFormula.${override.formula.name.lowercase()}")) {
override.formula = when (override.formula) {
StackingFormula.Flat -> StackingFormula.Diminished
StackingFormula.Diminished -> StackingFormula.Flat
}
override.formula = StackingFormula.entries[override.formula.ordinal xor 1]
it.message = Text.translatable("text.config.data_attributes.enum.stackingFormula.${override.formula.name.lowercase()}")
replaceEntry(id, override.copy(formula = override.formula))
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/assets/data_attributes/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

"text.config.data_attributes.data_entry.edit": [
{"text": "", "color": "#efb13f"},
{"text": "Edit ID", "color": "white"}
{"text": "Edit", "color": "white"}
],

"text.config.data_attributes.data_entry.remove": [
Expand Down

0 comments on commit a02a3e0

Please sign in to comment.