mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-23 21:38:00 +01:00
Merge branch '1.20.2' into 1.20.4
This commit is contained in:
commit
b11a71e403
4 changed files with 37 additions and 10 deletions
|
@ -33,6 +33,14 @@ public enum AttributeFormat {
|
||||||
|
|
||||||
public abstract 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) {
|
public MutableText getBase(Text attributeName, float value, String comparison, Formatting color) {
|
||||||
return formatAttributeLine(Text.translatable("attribute.modifier." + comparison + ".0", formatValue(value), attributeName).formatted(color));
|
return formatAttributeLine(Text.translatable("attribute.modifier." + comparison + ".0", formatValue(value), attributeName).formatted(color));
|
||||||
}
|
}
|
||||||
|
@ -41,7 +49,7 @@ public enum AttributeFormat {
|
||||||
return getBase(attributeName, value, "equals", Formatting.LIGHT_PURPLE);
|
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;
|
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);
|
return Text.literal(" (" + (difference > 0 ? "+" : "-") + formatValue(this == PERCENTAGE ? difference / baseValue : difference) + ")").formatted((detrimental ? difference : -difference) < 0 ? Formatting.DARK_GREEN : Formatting.RED);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import java.util.function.BiFunction;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
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.effect.CustomisedSpellType;
|
||||||
import com.minelittlepony.unicopia.ability.magic.spell.trait.SpellTraits;
|
import com.minelittlepony.unicopia.ability.magic.spell.trait.SpellTraits;
|
||||||
|
@ -51,14 +52,29 @@ public record SpellAttribute<T> (
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
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 traitAmount = type.traits().get(trait);
|
||||||
float traitDifference = type.relativeTraits().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) {
|
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));
|
tooltip.add(AttributeFormat.formatTraitDifference(trait, traitDifference));
|
||||||
} else {
|
} else {
|
||||||
tooltip.add(b);
|
tooltip.add(b);
|
||||||
|
@ -66,6 +82,7 @@ public record SpellAttribute<T> (
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static SpellAttribute<Boolean> createConditional(SpellAttributeType id, Trait trait, Float2ObjectFunction<Boolean> valueGetter) {
|
public static SpellAttribute<Boolean> createConditional(SpellAttributeType id, Trait trait, Float2ObjectFunction<Boolean> valueGetter) {
|
||||||
return createConditional(id, trait, (traits, value) -> valueGetter.get(value.floatValue()));
|
return createConditional(id, trait, (traits, value) -> valueGetter.get(value.floatValue()));
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,6 @@ import net.minecraft.item.Items;
|
||||||
import net.minecraft.nbt.NbtCompound;
|
import net.minecraft.nbt.NbtCompound;
|
||||||
import net.minecraft.predicate.entity.EntityPredicates;
|
import net.minecraft.predicate.entity.EntityPredicates;
|
||||||
import net.minecraft.util.hit.EntityHitResult;
|
import net.minecraft.util.hit.EntityHitResult;
|
||||||
import net.minecraft.util.math.MathHelper;
|
|
||||||
|
|
||||||
public class FireBoltSpell extends AbstractSpell implements HomingSpell,
|
public class FireBoltSpell extends AbstractSpell implements HomingSpell,
|
||||||
ProjectileDelegate.ConfigurationListener, ProjectileDelegate.EntityHitListener {
|
ProjectileDelegate.ConfigurationListener, ProjectileDelegate.EntityHitListener {
|
||||||
|
@ -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<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<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> 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.createRanged(SpellAttributeType.EXPLOSION_STRENGTH, AttributeFormat.REGULAR, AttributeFormat.PERCENTAGE, Trait.POWER,
|
||||||
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)));
|
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<>();
|
private final EntityReference<Entity> target = new EntityReference<>();
|
||||||
|
|
||||||
|
|
|
@ -220,7 +220,7 @@ public interface UItems {
|
||||||
.rarity(Rarity.UNCOMMON), 0), ItemGroups.TOOLS);
|
.rarity(Rarity.UNCOMMON), 0), ItemGroups.TOOLS);
|
||||||
AmuletItem PEARL_NECKLACE = register("pearl_necklace", new AmuletItem(new FabricItemSettings()
|
AmuletItem PEARL_NECKLACE = register("pearl_necklace", new AmuletItem(new FabricItemSettings()
|
||||||
.maxCount(1)
|
.maxCount(1)
|
||||||
.maxDamage(4)
|
.maxDamage(16)
|
||||||
.rarity(Rarity.UNCOMMON), 0), ItemGroups.TOOLS);
|
.rarity(Rarity.UNCOMMON), 0), ItemGroups.TOOLS);
|
||||||
|
|
||||||
GlassesItem SUNGLASSES = register("sunglasses", new GlassesItem(new FabricItemSettings().maxCount(1)), ItemGroups.COMBAT);
|
GlassesItem SUNGLASSES = register("sunglasses", new GlassesItem(new FabricItemSettings().maxCount(1)), ItemGroups.COMBAT);
|
||||||
|
|
Loading…
Reference in a new issue