Skip to content

Commit

Permalink
Merge branch '1.20.2' into 1.20.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Sollace committed Jun 30, 2024
2 parents 6570248 + 33b01f4 commit b11a71e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ public String formatValue(float value) {

public abstract String formatValue(float value);

public MutableText getBase(Text attributeName, float value, float max, String comparison, Formatting color) {
return formatAttributeLine(Text.translatable(
"attribute.modifier." + comparison + ".0",
Text.translatable("item.unicopia.magic_staff.enchanted", formatValue(value), formatValue(max)),
attributeName
).formatted(color));
}

public MutableText getBase(Text attributeName, float value, String comparison, Formatting color) {
return formatAttributeLine(Text.translatable("attribute.modifier." + comparison + ".0", formatValue(value), attributeName).formatted(color));
}
Expand All @@ -41,7 +49,7 @@ public Text get(Text attributeName, float value) {
return getBase(attributeName, value, "equals", Formatting.LIGHT_PURPLE);
}

public Text getRelative(Text attributeName, float baseValue, float currentValue, boolean detrimental) {
public Text getRelative(float baseValue, float currentValue, boolean detrimental) {
float difference = currentValue - baseValue;
return Text.literal(" (" + (difference > 0 ? "+" : "-") + formatValue(this == PERCENTAGE ? difference / baseValue : difference) + ")").formatted((detrimental ? difference : -difference) < 0 ? Formatting.DARK_GREEN : Formatting.RED);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.function.Function;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import com.minelittlepony.unicopia.ability.magic.spell.effect.CustomisedSpellType;
import com.minelittlepony.unicopia.ability.magic.spell.trait.SpellTraits;
Expand Down Expand Up @@ -51,21 +52,37 @@ public static <T extends Number> SpellAttribute<T> create(SpellAttributeType id,
}

public static <T extends @NotNull Number> SpellAttribute<T> create(SpellAttributeType id, AttributeFormat baseFormat, AttributeFormat relativeFormat, Trait trait, BiFunction<SpellTraits, Float, @NotNull T> valueGetter, boolean detrimental) {
return new SpellAttribute<>(trait, valueGetter, (CustomisedSpellType<?> type, List<Text> tooltip) -> {
return createRanged(id, baseFormat, relativeFormat, trait, null, valueGetter, detrimental);
}

public static <T extends Number> SpellAttribute<T> createRanged(SpellAttributeType id, AttributeFormat baseFormat, AttributeFormat relativeFormat, Trait trait,
@Nullable SpellAttribute<T> maxValueGetter,
BiFunction<SpellTraits, Float, @NotNull T> valueGetter,
boolean detrimental) {
final BiFunction<SpellTraits, Float, @NotNull T> clampedValueGetter = maxValueGetter == null ? valueGetter : (traits, f) -> {
T t = valueGetter.apply(traits, f);
T max = maxValueGetter.get(traits);
return max.floatValue() > 0 && t.floatValue() > max.floatValue() ? max : t;
};
return new SpellAttribute<>(trait, clampedValueGetter, (CustomisedSpellType<?> type, List<Text> tooltip) -> {
float traitAmount = type.traits().get(trait);
float traitDifference = type.relativeTraits().get(trait);
float value = valueGetter.apply(type.traits(), traitAmount).floatValue();
float max = maxValueGetter == null ? 0 : maxValueGetter.get(type.traits()).floatValue();
float value = clampedValueGetter.apply(type.traits(), traitAmount).floatValue();

var b = baseFormat.getBase(id.name(), value, "equals", Formatting.LIGHT_PURPLE);
var b = max > 0
? baseFormat.getBase(id.name(), value, max, "equals", Formatting.LIGHT_PURPLE)
: baseFormat.getBase(id.name(), value, "equals", Formatting.LIGHT_PURPLE);
if (traitDifference != 0) {
tooltip.add(b.append(relativeFormat.getRelative(Text.empty(), valueGetter.apply(type.traits(), traitAmount - traitDifference).floatValue(), value, detrimental)));
tooltip.add(b.append(relativeFormat.getRelative(valueGetter.apply(type.traits(), traitAmount - traitDifference).floatValue(), value, detrimental)));
tooltip.add(AttributeFormat.formatTraitDifference(trait, traitDifference));
} else {
tooltip.add(b);
}
});
}


public static SpellAttribute<Boolean> createConditional(SpellAttributeType id, Trait trait, Float2ObjectFunction<Boolean> valueGetter) {
return createConditional(id, trait, (traits, value) -> valueGetter.get(value.floatValue()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import net.minecraft.nbt.NbtCompound;
import net.minecraft.predicate.entity.EntityPredicates;
import net.minecraft.util.hit.EntityHitResult;
import net.minecraft.util.math.MathHelper;

public class FireBoltSpell extends AbstractSpell implements HomingSpell,
ProjectileDelegate.ConfigurationListener, ProjectileDelegate.EntityHitListener {
Expand All @@ -40,10 +39,13 @@ public class FireBoltSpell extends AbstractSpell implements HomingSpell,
private static final SpellAttribute<Integer> PROJECTILE_COUNT = SpellAttribute.create(SpellAttributeType.PROJECTILE_COUNT, AttributeFormat.REGULAR, AttributeFormat.PERCENTAGE, Trait.EARTH, earth -> 11 + (int)earth * 3);
private static final SpellAttribute<Boolean> FOLLOWS_TARGET = SpellAttribute.createConditional(SpellAttributeType.FOLLOWS_TARGET, Trait.FOCUS, focus -> focus >= 50);
private static final SpellAttribute<Float> FOLLOW_RANGE = SpellAttribute.create(SpellAttributeType.FOLLOW_RANGE, AttributeFormat.REGULAR, AttributeFormat.PERCENTAGE, Trait.FOCUS, focus -> Math.max(0F, focus - 49));
private static final SpellAttribute<Float> MAX_EXPLOSION_STRENGTH = SpellAttribute.create(SpellAttributeType.EXPLOSION_STRENGTH, AttributeFormat.REGULAR, AttributeFormat.PERCENTAGE, Trait.FOCUS, focus -> focus >= 50 ? 10F : 1F);
private static final SpellAttribute<Float> EXPLOSION_STRENGTH = SpellAttribute.create(SpellAttributeType.EXPLOSION_STRENGTH, AttributeFormat.REGULAR, AttributeFormat.PERCENTAGE, Trait.POWER, (traits, focus) -> MathHelper.clamp(focus / 50, 0, MAX_EXPLOSION_STRENGTH.get(traits)));
private static final SpellAttribute<Float> EXPLOSION_STRENGTH = SpellAttribute.createRanged(SpellAttributeType.EXPLOSION_STRENGTH, AttributeFormat.REGULAR, AttributeFormat.PERCENTAGE, Trait.POWER,
SpellAttribute.create(SpellAttributeType.EXPLOSION_STRENGTH, AttributeFormat.REGULAR, AttributeFormat.PERCENTAGE, Trait.FOCUS, focus -> focus >= 50 ? 10F : 1F),
(traits, power) -> Math.max(power / 50F, 0F),
false
);

static final TooltipFactory TOOLTIP = TooltipFactory.of(MAX_EXPLOSION_STRENGTH, EXPLOSION_STRENGTH, VELOCITY, PROJECTILE_COUNT, FOLLOWS_TARGET, FOLLOW_RANGE.conditionally(FOLLOWS_TARGET::get));
static final TooltipFactory TOOLTIP = TooltipFactory.of(EXPLOSION_STRENGTH, VELOCITY, PROJECTILE_COUNT, FOLLOWS_TARGET, FOLLOW_RANGE.conditionally(FOLLOWS_TARGET::get));

private final EntityReference<Entity> target = new EntityReference<>();

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/minelittlepony/unicopia/item/UItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ EntityAttributes.GENERIC_KNOCKBACK_RESISTANCE, new EntityAttributeModifier(Blunt
.rarity(Rarity.UNCOMMON), 0), ItemGroups.TOOLS);
AmuletItem PEARL_NECKLACE = register("pearl_necklace", new AmuletItem(new FabricItemSettings()
.maxCount(1)
.maxDamage(4)
.maxDamage(16)
.rarity(Rarity.UNCOMMON), 0), ItemGroups.TOOLS);

GlassesItem SUNGLASSES = register("sunglasses", new GlassesItem(new FabricItemSettings().maxCount(1)), ItemGroups.COMBAT);
Expand Down

0 comments on commit b11a71e

Please sign in to comment.