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 60077e5 commit 9775c9d
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,11 @@ public static FactoryHolder initilize(Pair<JsonObject, NamespacedKey> pair, Acce
CraftCalio.INSTANCE.getLogger().severe(
"An unhandled exception was thrown when attempting to create new Registerable!");
CraftCalio.INSTANCE.getLogger().severe(
"Registry: {a} | Associated Namespace: {b} | Throwable: {c}"
"Registry: {a} | Associated Namespace: {b} | Type: {c} | Throwable: {d}"
.replace("{a}", accessorKey.getOfType().getSimpleName())
.replace("{b}", key.asString())
.replace("{c}", throwable.getMessage() == null ? "Null Message" : throwable.getMessage()) + stacktrace[0]
.replace("{c}", accessorKey.usesTypeDefiner() ? pair.getFirst().get("type").getAsString() : "No Type")
.replace("{d}", throwable.getMessage() == null ? "Null Message" : throwable.getMessage()) + stacktrace[0]
);
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private static boolean testMetaAction(FactoryJsonObject action, String[] extras)
}

public static void executeBiEntity(Entity actor, Entity target, FactoryJsonObject action) {
if (!action.isPresent("type") || action.isEmpty()) return;
if (!action.isPresent("type") || action.isEmpty() || target == actor) return;
String type = action.getString("type");
Pair<Entity, Entity> entityPair = new Pair<>() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,54 @@
import me.dueris.genesismc.GenesisMC;
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;
import net.minecraft.world.damagesource.DamageType;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.phys.Vec3;
import org.apache.commons.lang3.function.TriConsumer;
import org.bukkit.NamespacedKey;
import org.bukkit.craftbukkit.entity.CraftEntity;
import org.bukkit.craftbukkit.entity.CraftLivingEntity;
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
import org.bukkit.entity.*;
import org.bukkit.util.Vector;
import org.joml.Vector3f;

import java.util.function.BiConsumer;
import java.util.function.BiFunction;

public class BiEntityActions {

public void register() {
register(new ActionFactory(GenesisMC.apoliIdentifier("add_velocity"), (action, entityPair) -> {
boolean set = action.isPresent("set") && action.getBoolean("set");
Vector vector = VectorGetter.getVector(action);
net.minecraft.world.entity.Entity actor = entityPair.left().getHandle();
net.minecraft.world.entity.Entity target = entityPair.right().getHandle();

if (set) entityPair.right().setVelocity(vector);
else entityPair.right().setVelocity(entityPair.right().getVelocity().add(vector));
if ((actor == null || target == null) || (target instanceof Player && (!action.getBooleanOrDefault("server", true)))) {
return;
}
float xVal = action.getNumberOrDefault("x", 0.0F).getFloat();
float yVal = action.getNumberOrDefault("y", 0.0F).getFloat();
float zVal = action.getNumberOrDefault("z", 0.0F).getFloat();

Vector3f vec = new Vector3f(xVal, yVal, zVal);
TriConsumer<Float, Float, Float> method = action.getBooleanOrDefault("set", false) ? (x, y, z) -> {
target.getBukkitEntity().setVelocity(new Vector(x, y, z));
} : (x, y, z) -> {
target.getBukkitEntity().setVelocity(target.getBukkitEntity().getVelocity().add(new Vector(x, y, z)));
};

Reference reference = action.getEnumValueOrDefault("reference", Reference.class, Reference.POSITION);
Vec3 refVec = reference.apply(actor, target);

Space.transformVectorToBase(refVec, vec, actor.getBukkitEntity().getYaw(), true); // vector normalized by method
method.accept(vec.x, vec.y, vec.z);

target.hurtMarked = true;
}));
register(new ActionFactory(GenesisMC.apoliIdentifier("remove_from_entity_set"), (action, entityPair) -> {
RemoveFromSetEvent ev = new RemoveFromSetEvent(entityPair.right(), action.getString("set"));
Expand Down Expand Up @@ -101,4 +127,33 @@ 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 @@ -171,7 +171,23 @@ public void register() {
if (entity instanceof Player p) {
PowerType powerContainer = GenesisMC.getPlugin().registry.retrieve(Registries.CRAFT_POWER).get(action.getNamespacedKey("power"));
if (powerContainer != null) {
RaycastUtils.executeNMSCommand(((CraftEntity) p).getHandle(), CraftLocation.toVec3D(p.getLocation()), "power remove {name} {identifier}".replace("{name}", p.getName()).replace("{identifier}", action.getString("action")));
RaycastUtils.executeNMSCommand(((CraftEntity) p).getHandle(), CraftLocation.toVec3D(p.getLocation()), "power remove {name} {identifier}".replace("{name}", p.getName()).replace("{identifier}", action.getString("power")));
}
}
}));
register(new ActionFactory(GenesisMC.apoliIdentifier("grant_power"), (action, entity) -> {
if (entity instanceof Player p) {
PowerType powerContainer = GenesisMC.getPlugin().registry.retrieve(Registries.CRAFT_POWER).get(action.getNamespacedKey("power"));
if (powerContainer != null) {
RaycastUtils.executeNMSCommand(((CraftEntity) p).getHandle(), CraftLocation.toVec3D(p.getLocation()), "power grant {name} {identifier}".replace("{name}", p.getName()).replace("{identifier}", action.getString("power")));
}
}
}));
register(new ActionFactory(GenesisMC.apoliIdentifier("revoke_power"), (action, entity) -> {
if (entity instanceof Player p) {
PowerType powerContainer = GenesisMC.getPlugin().registry.retrieve(Registries.CRAFT_POWER).get(action.getNamespacedKey("power"));
if (powerContainer != null) {
RaycastUtils.executeNMSCommand(((CraftEntity) p).getHandle(), CraftLocation.toVec3D(p.getLocation()), "power revoke {name} {identifier}".replace("{name}", p.getName()).replace("{identifier}", action.getString("power")));
}
}
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ public class DamageOverTime extends PowerType {
private final float damageEasy;
private final String damageType;

public DamageOverTime(String name, String description, boolean hidden, FactoryJsonObject condition, int loading_priority, int interval, float damage, @Nullable float damageEasy, String damageType) {
public DamageOverTime(String name, String description, boolean hidden, FactoryJsonObject condition, int loading_priority, int interval, float damage, float damageEasy, String damageType) {
super(name, description, hidden, condition, loading_priority);
this.interval = interval;
this.damage = damage;
this.damageEasy = Objects.isNull(damageEasy) ? damage : damageEasy;
this.damageEasy = damageEasy == -1F ? damage : damageEasy;
this.damageType = damageType;
}

public static FactoryData registerComponents(FactoryData data) {
return PowerType.registerComponents(data).ofNamespace(GenesisMC.apoliIdentifier("damage_over_time"))
.add("interval", int.class, 20)
.add("damage", float.class, new RequiredInstance())
.add("damage_easy", float.class, new OptionalInstance())
.add("damage_easy", float.class, -1F)
.add("damage_type", String.class, "apoli:damage_over_time");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public ModifyFallingPower(String name, String description, boolean hidden, Facto

public static FactoryData registerComponents(FactoryData data) {
return PowerType.registerComponents(data).ofNamespace(GenesisMC.apoliIdentifier("modify_falling"))
.add("velocity", float.class, new OptionalInstance())
.add("velocity", float.class, 0F)
.add("take_fall_damage", boolean.class, true);
}

Expand All @@ -40,7 +40,7 @@ public void runE(PlayerMoveEvent e) {
@NotNull Vector velocityVal = p.getVelocity();
if (isActive(p)) {
if (velocityVal.getY() > 0D) return;
if (velocity != null) {
if (velocity != null && velocity != 0F) {
if (velocity < 0.08) {
// This way is a lot smoother and also updates the client preventing weird glitches
p.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_FALLING, 5, 1, false, false, false));
Expand Down

0 comments on commit 9775c9d

Please sign in to comment.