Skip to content

Commit

Permalink
MORE FIXES!
Browse files Browse the repository at this point in the history
  • Loading branch information
Dueris committed May 24, 2024
1 parent 321e2dd commit 1e53f9f
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<net.minecraft.world.entity.Entity, net.minecraft.world.entity.Entity, Vec3> refFunction;

Reference(BiFunction<net.minecraft.world.entity.Entity, net.minecraft.world.entity.Entity, Vec3> 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<FactoryJsonObject, Pair<CraftEntity, CraftEntity>> test;
Expand Down Expand Up @@ -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<net.minecraft.world.entity.Entity, net.minecraft.world.entity.Entity, Vec3> refFunction;
Reference(BiFunction<net.minecraft.world.entity.Entity, net.minecraft.world.entity.Entity, Vec3> refFunction) {
this.refFunction = refFunction;
}

public Vec3 apply(net.minecraft.world.entity.Entity actor, net.minecraft.world.entity.Entity target) {
return refFunction.apply(actor, target);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public void runGive(PowerUpdateEvent e) {
if (getPlayers().contains(e.getPlayer()) && e.isNew()) {
if (isActive(e.getPlayer())) {
runGiveItems(e.getPlayer());
} else {
}
}
}
Expand Down
32 changes: 32 additions & 0 deletions origins/src/main/java/me/dueris/genesismc/util/DataConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,14 @@
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;
import org.bukkit.persistence.PersistentDataType;
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");
Expand Down Expand Up @@ -59,27 +55,27 @@ public static int getPowerCount(ItemStack stack) {
return getPowers(stack).size();
}

public static List<PowerType> getPowers(ItemStack stack) {
return getTags(stack).stream().map(CraftApoli::getPowerFromTag).toList();
}

private static void saveTags(PersistentDataContainer container, List<String> 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<PowerType> getPowers(ItemStack stack) {
return getTags(stack).stream().map(CraftApoli::getPowerFromTag).toList();
}

public void removePlayerFromTagCheck(Player player, String tag) {
Set<Player> players = playersWithTags.get(tag);
if (players != null) {
players.remove(player);
}
}

private static void saveTags(PersistentDataContainer container, List<String> tags) {
String serializedTags = String.join(",", tags);
container.set(key, PersistentDataType.STRING, serializedTags);
}

/**
* Run this when updating powers on the ItemStack
*/
Expand Down Expand Up @@ -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(),
Expand Down
7 changes: 3 additions & 4 deletions origins/src/main/java/me/dueris/genesismc/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -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> T parseJson(com.mojang.brigadier.StringReader stringReader, Codec<T> 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);
Expand All @@ -842,7 +841,7 @@ public static <T> T parseJson(com.mojang.brigadier.StringReader stringReader, Co
stringReader.setCursor(stringReader.getCursor() + getPos(jsonReader));
}

return (T) var4;
return var4;
}

public static <T, E extends Throwable> T getOrThrow(DataResult<T> result, Function<String, E> exceptionGetter) throws E {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
4 changes: 2 additions & 2 deletions origins/src/main/resources/paper-plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 1e53f9f

Please sign in to comment.