diff --git a/origins/src/main/java/me/dueris/genesismc/factory/actions/types/BiEntityActions.java b/origins/src/main/java/me/dueris/genesismc/factory/actions/types/BiEntityActions.java index f0a17f16c..294bae531 100644 --- a/origins/src/main/java/me/dueris/genesismc/factory/actions/types/BiEntityActions.java +++ b/origins/src/main/java/me/dueris/genesismc/factory/actions/types/BiEntityActions.java @@ -7,7 +7,6 @@ import me.dueris.genesismc.event.AddToSetEvent; import me.dueris.genesismc.event.RemoveFromSetEvent; import me.dueris.genesismc.factory.data.types.Space; -import me.dueris.genesismc.factory.data.types.VectorGetter; import me.dueris.genesismc.registry.Registries; import me.dueris.genesismc.util.Util; import net.minecraft.util.Mth; @@ -92,6 +91,36 @@ private void register(BiEntityActions.ActionFactory factory) { GenesisMC.getPlugin().registry.retrieve(Registries.BIENTITY_ACTION).register(factory); } + public enum Reference { + + POSITION((actor, target) -> target.position().subtract(actor.position())), + ROTATION((actor, target) -> { + + float pitch = actor.getBukkitEntity().getPitch(); + float yaw = actor.getBukkitEntity().getYaw(); + + float i = 0.017453292F; + + float j = -Mth.sin(yaw * i) * Mth.cos(pitch * i); + float k = -Mth.sin(pitch * i); + float l = Mth.cos(yaw * i) * Mth.cos(pitch * i); + + return new Vec3(j, k, l); + + }); + + final BiFunction refFunction; + + Reference(BiFunction refFunction) { + this.refFunction = refFunction; + } + + public Vec3 apply(net.minecraft.world.entity.Entity actor, net.minecraft.world.entity.Entity target) { + return refFunction.apply(actor, target); + } + + } + public static class ActionFactory implements Registrable { NamespacedKey key; BiConsumer> test; @@ -127,33 +156,4 @@ public NamespacedKey getKey() { return key; } } - - public enum Reference { - - POSITION((actor, target) -> target.position().subtract(actor.position())), - ROTATION((actor, target) -> { - - float pitch = actor.getBukkitEntity().getPitch(); - float yaw = actor.getBukkitEntity().getYaw(); - - float i = 0.017453292F; - - float j = -Mth.sin(yaw * i) * Mth.cos(pitch * i); - float k = -Mth.sin(pitch * i); - float l = Mth.cos(yaw * i) * Mth.cos(pitch * i); - - return new Vec3(j, k, l); - - }); - - final BiFunction refFunction; - Reference(BiFunction refFunction) { - this.refFunction = refFunction; - } - - public Vec3 apply(net.minecraft.world.entity.Entity actor, net.minecraft.world.entity.Entity target) { - return refFunction.apply(actor, target); - } - - } } diff --git a/origins/src/main/java/me/dueris/genesismc/factory/powers/apoli/AttributeHandler.java b/origins/src/main/java/me/dueris/genesismc/factory/powers/apoli/AttributeHandler.java index 41f6d1a14..299b71608 100644 --- a/origins/src/main/java/me/dueris/genesismc/factory/powers/apoli/AttributeHandler.java +++ b/origins/src/main/java/me/dueris/genesismc/factory/powers/apoli/AttributeHandler.java @@ -55,11 +55,32 @@ protected void runAttributeModifyPower(PlayerEvent e) { if (!getPlayers().contains(p)) return; for (Modifier modifier : modifiers) { try { - Attribute attributeModifier = attribute == null ? DataConverter.resolveAttribute(modifier.handle.getString("attribute")) : DataConverter.resolveAttribute(attribute); - AttributeModifier m = DataConverter.convertToAttributeModifier(modifier); + String attrName = modifier.handle.getString("attribute"); + double nmsValue; + Attribute attributeModifier; + + switch (attrName.toLowerCase()) { + case "reach-entity-attributes:reach": + nmsValue = DataConverter.attributeToBlockReach(modifier.value()); + attributeModifier = Attribute.PLAYER_BLOCK_INTERACTION_RANGE; + break; + case "reach-entity-attributes:attack_range": + nmsValue = DataConverter.attributeToEntityReach(modifier.value()); + attributeModifier = Attribute.PLAYER_ENTITY_INTERACTION_RANGE; + break; + default: + attributeModifier = attribute == null ? + DataConverter.resolveAttribute(attrName) : + DataConverter.resolveAttribute(attribute); + nmsValue = modifier.value(); + } + + AttributeModifier attrModifier = new AttributeModifier("unnamed", nmsValue, DataConverter.convertToOperation(modifier)); + if (p.getAttribute(attributeModifier) != null) { - p.getAttribute(attributeModifier).addTransientModifier(m); + p.getAttribute(attributeModifier).addTransientModifier(attrModifier); } + AttributeExecuteEvent attributeExecuteEvent = new AttributeExecuteEvent(p, attributeModifier, this, e.isAsynchronous()); Bukkit.getServer().getPluginManager().callEvent(attributeExecuteEvent); } catch (Exception ev) { diff --git a/origins/src/main/java/me/dueris/genesismc/factory/powers/apoli/ClimbingPower.java b/origins/src/main/java/me/dueris/genesismc/factory/powers/apoli/ClimbingPower.java index 5c97d1c49..82d9977e9 100644 --- a/origins/src/main/java/me/dueris/genesismc/factory/powers/apoli/ClimbingPower.java +++ b/origins/src/main/java/me/dueris/genesismc/factory/powers/apoli/ClimbingPower.java @@ -5,12 +5,10 @@ import me.dueris.calio.data.factory.FactoryJsonObject; import me.dueris.genesismc.GenesisMC; import me.dueris.genesismc.factory.powers.holder.PowerType; -import org.bukkit.Location; import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.craftbukkit.entity.CraftPlayer; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; -import org.bukkit.event.player.PlayerToggleSneakEvent; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import org.bukkit.scheduler.BukkitRunnable; diff --git a/origins/src/main/java/me/dueris/genesismc/factory/powers/apoli/DamageOverTime.java b/origins/src/main/java/me/dueris/genesismc/factory/powers/apoli/DamageOverTime.java index 744491050..019f3c6cc 100644 --- a/origins/src/main/java/me/dueris/genesismc/factory/powers/apoli/DamageOverTime.java +++ b/origins/src/main/java/me/dueris/genesismc/factory/powers/apoli/DamageOverTime.java @@ -2,7 +2,6 @@ import me.dueris.calio.data.FactoryData; import me.dueris.calio.data.factory.FactoryJsonObject; -import me.dueris.calio.data.types.OptionalInstance; import me.dueris.calio.data.types.RequiredInstance; import me.dueris.genesismc.GenesisMC; import me.dueris.genesismc.factory.powers.holder.PowerType; @@ -17,9 +16,6 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.entity.PlayerDeathEvent; -import org.jetbrains.annotations.Nullable; - -import java.util.Objects; public class DamageOverTime extends PowerType { private final int interval; diff --git a/origins/src/main/java/me/dueris/genesismc/factory/powers/apoli/ModifyFallingPower.java b/origins/src/main/java/me/dueris/genesismc/factory/powers/apoli/ModifyFallingPower.java index 1f2a3805b..947b5d579 100644 --- a/origins/src/main/java/me/dueris/genesismc/factory/powers/apoli/ModifyFallingPower.java +++ b/origins/src/main/java/me/dueris/genesismc/factory/powers/apoli/ModifyFallingPower.java @@ -2,8 +2,6 @@ import me.dueris.calio.data.FactoryData; import me.dueris.calio.data.factory.FactoryJsonObject; -import me.dueris.calio.data.types.OptionalInstance; -import me.dueris.calio.data.types.RequiredInstance; import me.dueris.genesismc.GenesisMC; import me.dueris.genesismc.factory.powers.holder.PowerType; import org.bukkit.entity.Player; diff --git a/origins/src/main/java/me/dueris/genesismc/factory/powers/apoli/StartingEquipmentPower.java b/origins/src/main/java/me/dueris/genesismc/factory/powers/apoli/StartingEquipmentPower.java index 77864f550..49e85c1ee 100644 --- a/origins/src/main/java/me/dueris/genesismc/factory/powers/apoli/StartingEquipmentPower.java +++ b/origins/src/main/java/me/dueris/genesismc/factory/powers/apoli/StartingEquipmentPower.java @@ -38,7 +38,6 @@ public void runGive(PowerUpdateEvent e) { if (getPlayers().contains(e.getPlayer()) && e.isNew()) { if (isActive(e.getPlayer())) { runGiveItems(e.getPlayer()); - } else { } } } diff --git a/origins/src/main/java/me/dueris/genesismc/util/DataConverter.java b/origins/src/main/java/me/dueris/genesismc/util/DataConverter.java index f29d22543..a14f2d4bc 100644 --- a/origins/src/main/java/me/dueris/genesismc/util/DataConverter.java +++ b/origins/src/main/java/me/dueris/genesismc/util/DataConverter.java @@ -9,6 +9,10 @@ * Helps with old-version conversion of data during runtime */ public class DataConverter { + private static final double DEFAULT_ENTITY_ATTRIBUTE_VALUE = 3.0; + private static final double DEFAULT_BLOCK_ATTRIBUTE_VALUE = 3.5; + private static final double DEFAULT_REACH_DISTANCE = 5.0; + public static Attribute resolveAttribute(String string) { String att = fixNamespace(fixAttributeNamespace(string)); if (att.equalsIgnoreCase("reach-entity-attributes:reach")) return Attribute.PLAYER_BLOCK_INTERACTION_RANGE; @@ -43,4 +47,32 @@ public static AttributeModifier.Operation convertToOperation(Modifier modifier) public static AttributeModifier convertToAttributeModifier(Modifier modifier) { return new AttributeModifier(modifier.handle.getStringOrDefault("name", "modifier"), modifier.value(), convertToOperation(modifier)); } + + public static double attributeToEntityReach(double attributeValue) { + if (attributeValue < 0) { + throw new IllegalArgumentException("Attribute value must be non-negative."); + } + return (attributeValue / DEFAULT_ENTITY_ATTRIBUTE_VALUE) * DEFAULT_REACH_DISTANCE; + } + + public static double entityReachToAttribute(double reachDistance) { + if (reachDistance < 0) { + throw new IllegalArgumentException("Reach distance must be non-negative."); + } + return (reachDistance / DEFAULT_REACH_DISTANCE) * DEFAULT_ENTITY_ATTRIBUTE_VALUE; + } + + public static double attributeToBlockReach(double attributeValue) { + if (attributeValue < 0) { + throw new IllegalArgumentException("Attribute value must be non-negative."); + } + return (attributeValue / DEFAULT_BLOCK_ATTRIBUTE_VALUE) * DEFAULT_REACH_DISTANCE; + } + + public static double blockReachToAttribute(double reachDistance) { + if (reachDistance < 0) { + throw new IllegalArgumentException("Reach distance must be non-negative."); + } + return (reachDistance / DEFAULT_REACH_DISTANCE) * DEFAULT_BLOCK_ATTRIBUTE_VALUE; + } } diff --git a/origins/src/main/java/me/dueris/genesismc/util/ItemStackPowerHolder.java b/origins/src/main/java/me/dueris/genesismc/util/ItemStackPowerHolder.java index c6626ab0f..72a113efd 100644 --- a/origins/src/main/java/me/dueris/genesismc/util/ItemStackPowerHolder.java +++ b/origins/src/main/java/me/dueris/genesismc/util/ItemStackPowerHolder.java @@ -7,9 +7,7 @@ import org.bukkit.Bukkit; import org.bukkit.NamespacedKey; import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerChatEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.persistence.PersistentDataContainer; @@ -17,8 +15,6 @@ import org.bukkit.scheduler.BukkitRunnable; import java.util.*; -import java.util.function.BiConsumer; -import java.util.function.Consumer; public class ItemStackPowerHolder implements Listener { private static final NamespacedKey key = GenesisMC.apoliIdentifier("stored_powers"); @@ -59,15 +55,20 @@ public static int getPowerCount(ItemStack stack) { return getPowers(stack).size(); } + public static List getPowers(ItemStack stack) { + return getTags(stack).stream().map(CraftApoli::getPowerFromTag).toList(); + } + + private static void saveTags(PersistentDataContainer container, List tags) { + String serializedTags = String.join(",", tags); + container.set(key, PersistentDataType.STRING, serializedTags); + } + public void addPlayerToTagCheck(Player player, String tag) { playersWithTags.computeIfAbsent(tag, k -> new HashSet<>()).add(player); updatePlayerTagStatus(player, tag); } - public static List getPowers(ItemStack stack) { - return getTags(stack).stream().map(CraftApoli::getPowerFromTag).toList(); - } - public void removePlayerFromTagCheck(Player player, String tag) { Set players = playersWithTags.get(tag); if (players != null) { @@ -75,11 +76,6 @@ public void removePlayerFromTagCheck(Player player, String tag) { } } - private static void saveTags(PersistentDataContainer container, List tags) { - String serializedTags = String.join(",", tags); - container.set(key, PersistentDataType.STRING, serializedTags); - } - /** * Run this when updating powers on the ItemStack */ @@ -121,7 +117,7 @@ public void run() { } private boolean checkEquippedItems(Player player, String tag) { - ItemStack[] equipment = new ItemStack[] { + ItemStack[] equipment = new ItemStack[]{ player.getInventory().getItemInMainHand(), player.getInventory().getItemInOffHand(), player.getInventory().getHelmet(), diff --git a/origins/src/main/java/me/dueris/genesismc/util/Util.java b/origins/src/main/java/me/dueris/genesismc/util/Util.java index 8692a0e44..1bd24f278 100644 --- a/origins/src/main/java/me/dueris/genesismc/util/Util.java +++ b/origins/src/main/java/me/dueris/genesismc/util/Util.java @@ -826,13 +826,12 @@ private static int getPos(JsonReader jsonReader) { throw new IllegalStateException("Couldn't read position of JsonReader", var2); } } - - @SuppressWarnings("unchecked") + public static T parseJson(com.mojang.brigadier.StringReader stringReader, Codec codec) { JsonReader jsonReader = new JsonReader(new java.io.StringReader(stringReader.getRemaining())); jsonReader.setLenient(true); - Object var4; + T var4; try { JsonElement jsonElement = Streams.parse(jsonReader); var4 = getOrThrow(codec.parse(JsonOps.INSTANCE, jsonElement), JsonParseException::new); @@ -842,7 +841,7 @@ public static T parseJson(com.mojang.brigadier.StringReader stringReader, Co stringReader.setCursor(stringReader.getCursor() + getPos(jsonReader)); } - return (T) var4; + return var4; } public static T getOrThrow(DataResult result, Function exceptionGetter) throws E { diff --git a/origins/src/main/java/me/dueris/genesismc/util/entity/PowerUtils.java b/origins/src/main/java/me/dueris/genesismc/util/entity/PowerUtils.java index 472f499ed..8610d54b9 100644 --- a/origins/src/main/java/me/dueris/genesismc/util/entity/PowerUtils.java +++ b/origins/src/main/java/me/dueris/genesismc/util/entity/PowerUtils.java @@ -1,6 +1,5 @@ package me.dueris.genesismc.util.entity; -import me.dueris.genesismc.GenesisMC; import me.dueris.genesismc.factory.CraftApoli; import me.dueris.genesismc.factory.powers.holder.PowerType; import me.dueris.genesismc.registry.registries.Layer; diff --git a/origins/src/main/resources/paper-plugin.yml b/origins/src/main/resources/paper-plugin.yml index 19b3fa9eb..f4826b695 100644 --- a/origins/src/main/resources/paper-plugin.yml +++ b/origins/src/main/resources/paper-plugin.yml @@ -5,9 +5,9 @@ name: "GenesisMC" version: 'mc1.20-1.0.0' main: "me.dueris.genesismc.GenesisMC" api-version: "1.20" -authors: [ Dueris, Tye ] +authors: [ Dueris ] folia-supported: false -description: "Bringing the life and fun of the Origins mod to PaperMC" +description: "A port of the Origins mod to PaperMC servers with Custom Origins support" website: "https://ko-fi.com/dueris" dependencies: server: