Skip to content

Commit

Permalink
Merge branch '1.20.1/dev' into 1.20.1/fabric
Browse files Browse the repository at this point in the history
  • Loading branch information
bibi-reden committed Aug 13, 2024
2 parents b107804 + 2f7137c commit 938893c
Show file tree
Hide file tree
Showing 34 changed files with 371 additions and 343 deletions.
17 changes: 14 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
## Additions 🍎
- Added the ability to customize the color of the label (default is still gold).

## Changes 🌽
- 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`).
- The UI has gone through a breaking change. recent alpha builds of WizardEX will not work with this version, though `alpha.3` will.
- Switching to the beta channel as most components of the mod are stable.
- Required changes before release is the UI and re-adjusting the config for the last time.
- Rebalanced knockback resistance to a proper 1% gain and displayed it properly.
- Added author & contributor information according to who assisted in the development of the project's codebase.
- Fixed `lifesteal` attribute not applying to attacker(s).
- Fixed refund issues on the screen.

## Later Objectives ⚡
- Fixing tooltips
- Adjusting more attributes
3 changes: 3 additions & 0 deletions crowdin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
files:
- source: /src/main/resources/assets/playerex/lang/en_us.json
translation: /src/main/resources/assets/playerex/lang/%locale_with_underscore%.json
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.14
mod_version=4.0.0+1.20.1-beta.1
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.10-fabric
data_attributes_version=2.0.0+1.20.1-beta.13-fabric

# owo
owo_version=0.11.2+1.20
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ abstract class EntityRendererMixin<T extends Entity> {
if (playerex$shouldRenderLevel() && entity instanceof Player livingEntity) {
Optional<Double> maybeLevel = DataAttributesAPI.getValue(PlayerEXAttributes.LEVEL, livingEntity);
if (maybeLevel.isPresent()) {
text = text.copy().append(" ").append(Component.translatable("playerex.ui.nameplate.level", maybeLevel.get().intValue()).withStyle((style) -> style.withColor(0xFFAA00)));
text = text.copy().append(" ").append(
Component.translatable("playerex.ui.nameplate.level", maybeLevel.get().intValue())
.withStyle((style) -> style.withColor(PlayerEX.CONFIG.getVisualSettings().getNameplateColor().rgb()))
);
}
}
return text;
Expand Down
43 changes: 14 additions & 29 deletions src/client/java/com/bibireden/playerex/mixin/ItemStackMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.bibireden.playerex.PlayerEX;
import com.bibireden.playerex.config.PlayerEXConfigModel;
import com.google.common.collect.Multimap;
import com.llamalad7.mixinextras.sugar.Local;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
Expand Down Expand Up @@ -78,25 +79,17 @@ abstract class ItemStackMixin {
private double playerex$modifyAdditionAttributeKnockback(double original) { return original / 10.0; }

// todo: not sure about the implementation(s) here...
@Inject(method = "getTooltipLines", at = @At(value = "INVOKE", target = "Ljava/util/List;add(Ljava/lang/Object;)Z", ordinal = 7, shift = At.Shift.AFTER), locals = LocalCapture.CAPTURE_FAILHARD)
@Inject(method = "getTooltipLines", at = @At(value = "INVOKE", target = "Ljava/util/List;add(Ljava/lang/Object;)Z", ordinal = 7, shift = At.Shift.AFTER))
private void playerex$insertModifierEqualsTooltip(
Player player, TooltipFlag context,
CallbackInfoReturnable<List<Component>> info,
List<Component> list,
MutableComponent arg3,
int arg4,
EquipmentSlot[] arg5,
int arg6,
int arg7,
EquipmentSlot arg8,
Multimap<?, ?> arg9,
Iterator<?> arg10,
Map.Entry<Attribute, AttributeModifier> entry,
AttributeModifier entityAttributeModifier,
double arg13, double e
@Local List<Component> list,
@Local Map.Entry<Attribute, AttributeModifier> entry,
@Local AttributeModifier modifier,
@Local(ordinal = 1) double e
) {
list.set(list.size() - 1, Component.literal(" ")
.append(Component.translatable("attribute.modifier.equals." + entityAttributeModifier.getOperation().toValue(), playerex$value(e, entry, entityAttributeModifier), Component.translatable(entry.getKey().getDescriptionId())))
.append(Component.translatable("attribute.modifier.equals." + modifier.getOperation().toValue(), playerex$value(e, entry, modifier), Component.translatable(entry.getKey().getDescriptionId())))
.withStyle(ChatFormatting.DARK_GREEN)
);
}
Expand All @@ -122,27 +115,19 @@ abstract class ItemStackMixin {
);
}

@Inject(method = "getTooltipLines", at = @At(value = "INVOKE", target = "Ljava/util/List;add(Ljava/lang/Object;)Z", ordinal = 9, shift = At.Shift.AFTER), locals = LocalCapture.CAPTURE_FAILHARD)
@Inject(method = "getTooltipLines", at = @At(value = "INVOKE", target = "Ljava/util/List;add(Ljava/lang/Object;)Z", ordinal = 9, shift = At.Shift.AFTER))
private void playerex$insertModifierTakeTooltip(
Player player, TooltipFlag context,
CallbackInfoReturnable<List<Component>> info,
List<Component> list,
MutableComponent arg3,
int arg4,
EquipmentSlot[] arg5,
int arg6,
int arg7,
EquipmentSlot arg8,
Multimap<?, ?> arg9,
Iterator<?> arg10,
Map.Entry<Attribute, AttributeModifier> entry,
AttributeModifier entityAttributeModifier,
double arg13, double e
@Local List<Component> list,
@Local Map.Entry<Attribute, AttributeModifier> entry,
@Local AttributeModifier modifier,
@Local(ordinal = 1) double e
) {
list.set(
list.size() - 1,
Component.translatable("attribute.modifier.take." + entityAttributeModifier.getOperation().toValue(),
playerex$value(e, entry, entityAttributeModifier),
Component.translatable("attribute.modifier.take." + modifier.getOperation().toValue(),
playerex$value(e, entry, modifier),
Component.translatable(entry.getKey().getDescriptionId())).withStyle(ChatFormatting.RED)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ abstract class LocalPlayerMixin {
@Shadow @Final protected Minecraft minecraft;

@Inject(method = "setExperienceValues", at = @At("TAIL"))
private void setExperience(CallbackInfo ci) {
private void playerex$setExperienceValues(CallbackInfo ci) {
if (minecraft.screen instanceof PlayerEXScreen screen) screen.onExperienceUpdated();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,20 @@ public final class PlayerEXMenuRegistry {
* which will be applied to the {@link PlayerEXScreen} as a page.
*/
public static void register(ResourceLocation id, @NotNull Class<? extends MenuComponent> menu) {
ENTRIES.add(new Pair<>(id, menu));
ENTRIES.sort((a, b) -> {
var order = PRIORITY_ORDER.getOrDefault(a.getFirst().getNamespace(), Integer.MAX_VALUE);
var order2 = PRIORITY_ORDER.getOrDefault(b.getFirst().getNamespace(), Integer.MAX_VALUE);
return order.compareTo(order2);
});
Pair<ResourceLocation, Class<? extends MenuComponent>> pair = new Pair<>(id, menu);
Integer insertingPriority = PRIORITY_ORDER.get(pair.getFirst().toString());

if (!ENTRIES.isEmpty()) {
for (int i = 0, size = ENTRIES.size(); i < size; i++) {
Pair<ResourceLocation, Class<? extends MenuComponent>> entry = ENTRIES.get(i);
Integer priority = PRIORITY_ORDER.get(entry.getFirst().toString());
if (priority > insertingPriority) {
ENTRIES.add(i, pair);
return;
}
}
}
ENTRIES.add(pair);
}

@NotNull
Expand Down
28 changes: 18 additions & 10 deletions src/client/kotlin/com/bibireden/playerex/ui/PlayerEXScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.bibireden.playerex.ui

import com.bibireden.playerex.PlayerEXClient
import com.bibireden.playerex.components.player.IPlayerDataComponent
import com.bibireden.playerex.ext.data
import com.bibireden.playerex.ext.component
import com.bibireden.playerex.ext.level
import com.bibireden.playerex.networking.NetworkingChannels
import com.bibireden.playerex.networking.NetworkingPackets
Expand All @@ -11,6 +11,7 @@ import com.bibireden.playerex.registry.PlayerEXMenuRegistry
import com.bibireden.playerex.ui.components.MenuComponent
import com.bibireden.playerex.ui.components.MenuComponent.OnLevelUpdated
import com.bibireden.playerex.ui.components.buttons.AttributeButtonComponent
import com.bibireden.playerex.ui.helper.InputHelper
import com.bibireden.playerex.ui.util.Colors
import com.bibireden.playerex.util.PlayerEXUtil
import io.wispforest.owo.ui.base.BaseUIModelScreen
Expand Down Expand Up @@ -40,7 +41,9 @@ class PlayerEXScreen : BaseUIModelScreen<FlowLayout>(FlowLayout::class.java, Dat
private val content by lazy { uiAdapter.rootComponent.childById(FlowLayout::class, "content")!! }
private val footer by lazy { uiAdapter.rootComponent.childById(FlowLayout::class, "footer")!! }

private val currentLevel by lazy { uiAdapter.rootComponent.childById(LabelComponent::class, "level:current")!! }
private val levelAmount by lazy { uiAdapter.rootComponent.childById(TextBoxComponent::class, "level:amount")!! }
private val levelButton by lazy { uiAdapter.rootComponent.childById(ButtonComponent::class, "level:button")!! }

private val onLevelUpdatedEvents = OnLevelUpdated.stream
private val onLevelUpdated: EventSource<OnLevelUpdated> = onLevelUpdatedEvents.source()
Expand All @@ -51,7 +54,7 @@ class PlayerEXScreen : BaseUIModelScreen<FlowLayout>(FlowLayout::class.java, Dat
fun onLevelUpdated(level: Int) {
val root = this.uiAdapter.rootComponent

root.childById(LabelComponent::class, "level:current")?.apply {
currentLevel.apply {
text(Component.translatable("playerex.ui.current_level", player.level.toInt(), PlayerEXUtil.getRequiredXpForNextLevel(player)))
}

Expand All @@ -77,10 +80,13 @@ class PlayerEXScreen : BaseUIModelScreen<FlowLayout>(FlowLayout::class.java, Dat
private fun updatePointsAvailable() {
this.uiAdapter.rootComponent.childById(LabelComponent::class, "points_available")?.apply {
text(Component.translatable("playerex.ui.main.skill_points_header").append(": [").append(
Component.literal("${player.data.skillPoints}").withStyle {
it.withColor(when (player.data.skillPoints) {
0 -> Colors.GRAY else -> Colors.SATURATED_BLUE
})
Component.literal("${player.component.skillPoints}").withStyle {
it.withColor(
when (player.component.skillPoints) {
0 -> Colors.GRAY
else -> Colors.SATURATED_BLUE
}
)
}).append("]")
)
}
Expand All @@ -100,7 +106,7 @@ class PlayerEXScreen : BaseUIModelScreen<FlowLayout>(FlowLayout::class.java, Dat
val amount = levelAmount.value.toIntOrNull() ?: return
val result = player.level + amount

this.uiAdapter.rootComponent.childById(ButtonComponent::class, "level:button")!!
levelButton
.active(player.experienceLevel >= PlayerEXUtil.getRequiredXpForLevel(player, result))
.tooltip(Component.translatable("playerex.ui.level_button", PlayerEXUtil.getRequiredXpForLevel(player, result), amount, player.experienceLevel))
}
Expand All @@ -112,7 +118,7 @@ class PlayerEXScreen : BaseUIModelScreen<FlowLayout>(FlowLayout::class.java, Dat
result = Mth.clamp((player.experienceLevel.toDouble() / required) * 100, 0.0, 100.0)
}
footer.childById(BoxComponent::class, "progress")!!
.horizontalSizing().animate(1000, Easing.CUBIC, Sizing.fill(result.toInt())).forwards()
.horizontalSizing().animate(250, Easing.CUBIC, Sizing.fill(result.toInt())).forwards()
}

override fun build(rootComponent: FlowLayout) {
Expand All @@ -121,6 +127,8 @@ class PlayerEXScreen : BaseUIModelScreen<FlowLayout>(FlowLayout::class.java, Dat
val levelUpButton = rootComponent.childById(ButtonComponent::class, "level:button")!!

updateLevelUpButton()

levelAmount.setFilter(InputHelper::isUIntInput)
levelAmount.onChanged().subscribe { updateLevelUpButton() }

val previousPage = rootComponent.childById(ButtonComponent::class, "previous")!!
Expand All @@ -130,7 +138,7 @@ class PlayerEXScreen : BaseUIModelScreen<FlowLayout>(FlowLayout::class.java, Dat

PlayerEXMenuRegistry.get().forEach { (_, clazz) ->
val instance = clazz.getDeclaredConstructor().newInstance()
instance.init(minecraft!!, this, player.data)
instance.init(minecraft!!, this, player.component)
instance.build(content)
pages.add(instance)
}
Expand Down Expand Up @@ -179,7 +187,7 @@ class PlayerEXScreen : BaseUIModelScreen<FlowLayout>(FlowLayout::class.java, Dat
return super.keyPressed(keyCode, scanCode, modifiers)
}

enum class AttributeButtonComponentType {
enum class ButtonType {
Add,
Remove;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import com.bibireden.data_attributes.api.attribute.StackingBehavior
import com.bibireden.data_attributes.api.attribute.StackingFormula
import com.bibireden.playerex.components.player.IPlayerDataComponent
import com.bibireden.playerex.ext.id
import com.bibireden.playerex.ui.PlayerEXScreen.AttributeButtonComponentType
import com.bibireden.playerex.ui.PlayerEXScreen.ButtonType
import com.bibireden.playerex.ui.components.buttons.AttributeButtonComponent
import com.bibireden.playerex.ui.components.labels.AttributeLabelComponent
import com.bibireden.playerex.ui.util.Colors
Expand Down Expand Up @@ -65,18 +65,16 @@ class AttributeComponent(private val attribute: Attribute, private val player: P
.id("${attribute.id}:label")
)

child(AttributeButtonComponent(attribute, player, component, AttributeButtonComponentType.Remove))
child(AttributeButtonComponent(attribute, player, component, ButtonType.Remove))
child(
AttributeLabelComponent(attribute, player).also { label = it }
.horizontalSizing(Sizing.fill(34))
)
child(AttributeButtonComponent(attribute, player, component, AttributeButtonComponentType.Add))
child(AttributeButtonComponent(attribute, player, component, ButtonType.Add))

horizontalAlignment(HorizontalAlignment.RIGHT)
verticalAlignment(VerticalAlignment.CENTER)

verticalAlignment(VerticalAlignment.CENTER)

refresh()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,27 @@ import io.wispforest.owo.ui.component.Components
import io.wispforest.owo.ui.container.Containers
import io.wispforest.owo.ui.container.FlowLayout
import io.wispforest.owo.ui.core.Sizing
import net.minecraft.world.entity.ai.attributes.Attribute
import net.minecraft.world.entity.player.Player
import net.minecraft.network.chat.Component
import kotlin.jvm.optionals.getOrNull

private fun transform(array: List<Pair<EntityAttributeSupplier, FormattingPredicate>>): List<Pair<Attribute, FormattingPredicate>> {
val filtered = mutableListOf<Pair<Attribute, FormattingPredicate>>()
for ((attribute, pred) in array) {
if (attribute.get().isPresent) filtered.add(Pair(attribute.get().get(), pred))
}
return filtered
}

class AttributeListComponent(translationKey: String, private val player: Player, private val gimmie: List<Pair<EntityAttributeSupplier, FormattingPredicate>>) : FlowLayout(Sizing.fill(25), Sizing.content(), Algorithm.VERTICAL) {
class AttributeListComponent(translationKey: String, private val player: Player, val attributes: List<EntityAttributeSupplier>) : FlowLayout(Sizing.fill(25), Sizing.content(), Algorithm.VERTICAL) {
val entriesSection: FlowLayout

init {
child(
Components.label(Component.translatable(translationKey))
.horizontalSizing(Sizing.fill(100))
)
child(Components.label(Component.translatable(translationKey)).horizontalSizing(Sizing.fill(100)))
child(Components.box(Sizing.fill(100), Sizing.fixed(2)))
entriesSection = Containers.verticalFlow(Sizing.fill(100), Sizing.content())
.apply {
gap(4)
}.also(::child)
.apply { gap(4) }.also(::child)

gap(4)
refresh()
}

fun refresh() {
entriesSection.children().filterIsInstance<AttributeListEntryComponent>().forEach(::removeChild)
entriesSection.children(transform(gimmie).map {
Containers.horizontalScroll(Sizing.fill(100), Sizing.content(), AttributeListEntryComponent(it.first, player, it.second)).scrollbarThiccness(2)
entriesSection.children(attributes.mapNotNull { it.get().getOrNull() }.map {
Containers.horizontalScroll(Sizing.fill(100), Sizing.content(), AttributeListEntryComponent(it, player)).scrollbarThiccness(2)
})
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.bibireden.playerex.ui.components

import com.bibireden.data_attributes.api.DataAttributesAPI
import com.bibireden.playerex.ext.id
import com.bibireden.playerex.ui.util.Colors
import io.wispforest.owo.ui.component.LabelComponent
import io.wispforest.owo.ui.core.HorizontalAlignment
Expand All @@ -11,11 +12,9 @@ import net.minecraft.network.chat.Component

typealias FormattingPredicate = (Double) -> String

class AttributeListEntryComponent(
val attribute: Attribute,
val player: Player,
private val formattingPredicate: FormattingPredicate
) : LabelComponent(Component.empty()) {
class AttributeListEntryComponent(val attribute: Attribute, val player: Player) : LabelComponent(Component.empty()) {
private val BASE_VALUE_FACTOR_IDS = setOf("ranged_weapon:haste")

init {
horizontalTextAlignment(HorizontalAlignment.CENTER)
verticalTextAlignment(VerticalAlignment.CENTER)
Expand All @@ -24,13 +23,17 @@ class AttributeListEntryComponent(
}

fun refresh() {
val formattedValue = if (attribute.id.toString() in BASE_VALUE_FACTOR_IDS) {
// this is literally to handle an edge case.
val value = DataAttributesAPI.getValue(attribute, player).orElse(0.0)
attribute.`data_attributes$format`().function(attribute.defaultValue, attribute.defaultValue * 2, value)
}
else DataAttributesAPI.getFormattedValue(attribute, player)

text(
Component.translatable(attribute.descriptionId)
.append(": ")
.append(Component.literal(
DataAttributesAPI.getValue(attribute, player).map { formattingPredicate(it) }
.orElse("N/A")).withStyle { it.withColor(Colors.GOLD) }
)
.append(Component.literal(formattedValue).withStyle { it.withColor(Colors.GOLD) })
)
}
}
Loading

0 comments on commit 938893c

Please sign in to comment.