From 9af1f8d2fc0dd929ae3896e45817c4676b7f28d0 Mon Sep 17 00:00:00 2001 From: dueris Date: Thu, 1 Aug 2024 19:35:05 -0700 Subject: [PATCH] Finish actions! --- .../me/dueris/originspaper/Bootstrap.java | 3 +- .../originspaper/command/OriginCommand.java | 10 +- .../originspaper/command/PowerCommand.java | 6 +- .../originspaper/factory/CraftApoli.java | 6 +- .../factory/action/types/EntityActions.java | 67 ++++++ .../types/entity/AddVelocityAction.java | 44 ++++ .../action/types/entity/AddXpAction.java | 30 +++ .../types/entity/ApplyEffectAction.java | 34 +++ .../types/entity/AreaOfEffectAction.java | 56 +++++ .../types/entity/BlockActionAtAction.java | 23 ++ .../types/entity/ChangeResourceAction.java | 28 +++ .../types/entity/ClearEffectAction.java | 28 +++ .../types/entity/CraftingTableAction.java | 32 +++ .../action/types/entity/DamageAction.java | 65 +++++ .../action/types/entity/DismountAction.java | 16 ++ .../types/entity/DropInventoryAction.java | 42 ++++ .../action/types/entity/EmitGameEvent.java | 18 ++ .../action/types/entity/EnderChestAction.java | 41 ++++ .../types/entity/EquippedItemAction.java | 44 ++++ .../types/entity/ExecuteCommandAction.java | 47 ++++ .../action/types/entity/ExhaustAction.java | 23 ++ .../action/types/entity/ExplodeAction.java | 65 +++++ .../action/types/entity/ExtinguishAction.java | 16 ++ .../action/types/entity/FeedAction.java | 25 ++ .../types/entity/FireProjectileAction.java | 114 +++++++++ .../action/types/entity/GainAirAction.java | 24 ++ .../action/types/entity/GiveAction.java | 87 +++++++ .../types/entity/GrantAdvancementAction.java | 28 +++ .../action/types/entity/HealAction.java | 24 ++ .../types/entity/ModifyDeathTicksAction.java | 27 +++ .../types/entity/ModifyInventoryAction.java | 45 ++++ .../types/entity/ModifyResourceAction.java | 26 ++ .../action/types/entity/ModifyStatAction.java | 42 ++++ .../action/types/entity/PassengerAction.java | 45 ++++ .../action/types/entity/PlaySoundAction.java | 30 +++ .../types/entity/RandomTeleportAction.java | 166 +++++++++++++ .../action/types/entity/RaycastAction.java | 226 ++++++++++++++++++ .../types/entity/RemoveAdvancementAction.java | 28 +++ .../types/entity/ReplaceInventoryAction.java | 41 ++++ .../action/types/entity/RidingAction.java | 58 +++++ .../action/types/entity/SelectorAction.java | 64 +++++ .../types/entity/SetFallDistanceAction.java | 18 ++ .../action/types/entity/SetOnFireAction.java | 18 ++ .../types/entity/SetResourceAction.java | 27 +++ .../action/types/entity/ShowToastAction.java | 78 ++++++ .../types/entity/SpawnEffectCloudAction.java | 47 ++++ .../types/entity/SpawnEntityAction.java | 59 +++++ .../types/entity/SpawnParticlesAction.java | 64 +++++ .../action/types/entity/SwingHandAction.java | 28 +++ .../action/types/entity/ToggleAction.java | 23 ++ .../types/entity/TriggerCooldownAction.java | 37 +++ .../origins/SlimelingSizeChangers.java | 4 +- .../util/entity/PlayerManager.java | 4 +- .../util/entity/PowerHolderComponent.java | 2 +- 54 files changed, 2238 insertions(+), 15 deletions(-) create mode 100644 origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/AddVelocityAction.java create mode 100644 origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/AddXpAction.java create mode 100644 origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/ApplyEffectAction.java create mode 100644 origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/AreaOfEffectAction.java create mode 100644 origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/BlockActionAtAction.java create mode 100644 origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/ChangeResourceAction.java create mode 100644 origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/ClearEffectAction.java create mode 100644 origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/CraftingTableAction.java create mode 100644 origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/DamageAction.java create mode 100644 origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/DismountAction.java create mode 100644 origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/DropInventoryAction.java create mode 100644 origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/EmitGameEvent.java create mode 100644 origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/EnderChestAction.java create mode 100644 origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/EquippedItemAction.java create mode 100644 origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/ExecuteCommandAction.java create mode 100644 origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/ExhaustAction.java create mode 100644 origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/ExplodeAction.java create mode 100644 origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/ExtinguishAction.java create mode 100644 origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/FeedAction.java create mode 100644 origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/FireProjectileAction.java create mode 100644 origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/GainAirAction.java create mode 100644 origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/GiveAction.java create mode 100644 origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/GrantAdvancementAction.java create mode 100644 origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/HealAction.java create mode 100644 origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/ModifyDeathTicksAction.java create mode 100644 origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/ModifyInventoryAction.java create mode 100644 origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/ModifyResourceAction.java create mode 100644 origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/ModifyStatAction.java create mode 100644 origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/PassengerAction.java create mode 100644 origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/PlaySoundAction.java create mode 100644 origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/RandomTeleportAction.java create mode 100644 origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/RaycastAction.java create mode 100644 origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/RemoveAdvancementAction.java create mode 100644 origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/ReplaceInventoryAction.java create mode 100644 origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/RidingAction.java create mode 100644 origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/SelectorAction.java create mode 100644 origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/SetFallDistanceAction.java create mode 100644 origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/SetOnFireAction.java create mode 100644 origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/SetResourceAction.java create mode 100644 origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/ShowToastAction.java create mode 100644 origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/SpawnEffectCloudAction.java create mode 100644 origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/SpawnEntityAction.java create mode 100644 origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/SpawnParticlesAction.java create mode 100644 origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/SwingHandAction.java create mode 100644 origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/ToggleAction.java create mode 100644 origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/TriggerCooldownAction.java diff --git a/origins/src/main/java/me/dueris/originspaper/Bootstrap.java b/origins/src/main/java/me/dueris/originspaper/Bootstrap.java index 12c7920e1..4708e15f8 100644 --- a/origins/src/main/java/me/dueris/originspaper/Bootstrap.java +++ b/origins/src/main/java/me/dueris/originspaper/Bootstrap.java @@ -160,7 +160,8 @@ public void bootstrap(@Nullable BootstrapContext bootContext) { new Tuple<>("apoli:custom_data", "apoli:nbt"), new Tuple<>("apoli:is_equippable", "apoli:equippable"), new Tuple<>("apoli:fireproof", "apoli:fire_resistant"), - new Tuple<>("apoli:merge_nbt", "apoli:merge_custom_data") + new Tuple<>("apoli:merge_nbt", "apoli:merge_custom_data"), + new Tuple<>("apoli:revoke_power", "apoli:remove_power") ) ); CalioParser.REMAPPER.set(remapper); diff --git a/origins/src/main/java/me/dueris/originspaper/command/OriginCommand.java b/origins/src/main/java/me/dueris/originspaper/command/OriginCommand.java index 133ea0fd4..a750d6080 100644 --- a/origins/src/main/java/me/dueris/originspaper/command/OriginCommand.java +++ b/origins/src/main/java/me/dueris/originspaper/command/OriginCommand.java @@ -83,7 +83,7 @@ public static void register(@NotNull CommandDispatcher dispa Commands.argument("origin", ResourceLocationArgument.id()) .suggests( (context, builder) -> { - OriginLayer layer = CraftApoli.getLayerFromTag( + OriginLayer layer = CraftApoli.getLayer( CraftNamespacedKey.fromMinecraft(ResourceLocationArgument.getId(context, "layer")).asString() ); ORIGINS.stream() @@ -106,7 +106,7 @@ public static void register(@NotNull CommandDispatcher dispa .executes( context -> { Collection targets = EntityArgument.getPlayers(context, "targets"); - OriginLayer layer = CraftApoli.getLayerFromTag( + OriginLayer layer = CraftApoli.getLayer( CraftNamespacedKey.fromMinecraft(ResourceLocationArgument.getId(context, "layer")).asString() ); Origin origin = CraftApoli.getOrigin( @@ -259,7 +259,7 @@ public static void register(@NotNull CommandDispatcher dispa .executes( context -> { Collection targets = EntityArgument.getPlayers(context, "targets"); - OriginLayer layer = CraftApoli.getLayerFromTag( + OriginLayer layer = CraftApoli.getLayer( CraftNamespacedKey.fromMinecraft(ResourceLocationArgument.getId(context, "layer")).asString() ); targets.forEach( @@ -318,7 +318,7 @@ public static void register(@NotNull CommandDispatcher dispa ) .executes(context -> { Collection targets = EntityArgument.getPlayers(context, "targets"); - OriginLayer layer = CraftApoli.getLayerFromTag( + OriginLayer layer = CraftApoli.getLayer( CraftNamespacedKey.fromMinecraft(ResourceLocationArgument.getId(context, "layer")).asString() ); RandomOriginPage randomOriginPage = new RandomOriginPage(); @@ -383,7 +383,7 @@ public static void register(@NotNull CommandDispatcher dispa ) .executes(context -> { Collection targets = EntityArgument.getPlayers(context, "targets"); - OriginLayer layer = CraftApoli.getLayerFromTag( + OriginLayer layer = CraftApoli.getLayer( CraftNamespacedKey.fromMinecraft(ResourceLocationArgument.getId(context, "layer")).asString() ); targets.forEach(player -> { diff --git a/origins/src/main/java/me/dueris/originspaper/command/PowerCommand.java b/origins/src/main/java/me/dueris/originspaper/command/PowerCommand.java index 4e01c554e..04a852dbf 100644 --- a/origins/src/main/java/me/dueris/originspaper/command/PowerCommand.java +++ b/origins/src/main/java/me/dueris/originspaper/command/PowerCommand.java @@ -123,7 +123,7 @@ public static void register(CommandDispatcher dispatcher) { context.getSource().getBukkitSender(), power, player.getBukkitEntity(), - CraftApoli.getLayerFromTag("apoli:command"), + CraftApoli.getLayer("apoli:command"), context.getSource().isSilent() ); } catch (IllegalAccessException | @@ -158,7 +158,7 @@ public static void register(CommandDispatcher dispatcher) { context.getSource().getBukkitSender(), power, player.getBukkitEntity(), - CraftApoli.getLayerFromTag( + CraftApoli.getLayer( CraftNamespacedKey.fromMinecraft(ResourceLocationArgument.getId(context, "layer")) .asString() ), @@ -379,7 +379,7 @@ private static void addRemoveArg(LiteralArgumentBuilder main context.getSource().getBukkitSender(), OriginsPaper.getPlugin().registry.retrieve(Registries.CRAFT_POWER).get(arg), p.getBukkitEntity(), - CraftApoli.getLayerFromTag(layer), + CraftApoli.getLayer(layer), context.getSource().isSilent() ); } catch (IllegalAccessException | diff --git a/origins/src/main/java/me/dueris/originspaper/factory/CraftApoli.java b/origins/src/main/java/me/dueris/originspaper/factory/CraftApoli.java index c960a78cc..f6464676a 100644 --- a/origins/src/main/java/me/dueris/originspaper/factory/CraftApoli.java +++ b/origins/src/main/java/me/dueris/originspaper/factory/CraftApoli.java @@ -62,7 +62,11 @@ public static Origin getOrigin(String originTag) { return emptyOrigin(); } - public static OriginLayer getLayerFromTag(String layerTag) { + public static OriginLayer getLayer(ResourceLocation layerTag) { + return getLayer(layerTag.toString()); + } + + public static OriginLayer getLayer(String layerTag) { for (OriginLayer l : layerRegistrar.values()) { if (l.getTag().equals(layerTag)) { return l; diff --git a/origins/src/main/java/me/dueris/originspaper/factory/action/types/EntityActions.java b/origins/src/main/java/me/dueris/originspaper/factory/action/types/EntityActions.java index 191201d51..77bdf766e 100644 --- a/origins/src/main/java/me/dueris/originspaper/factory/action/types/EntityActions.java +++ b/origins/src/main/java/me/dueris/originspaper/factory/action/types/EntityActions.java @@ -1,13 +1,22 @@ package me.dueris.originspaper.factory.action.types; import io.github.dueris.calio.SerializableDataTypes; +import io.github.dueris.calio.parser.InstanceDefiner; import me.dueris.originspaper.OriginsPaper; +import me.dueris.originspaper.factory.CraftApoli; import me.dueris.originspaper.factory.action.ActionFactory; import me.dueris.originspaper.factory.action.Actions; import me.dueris.originspaper.factory.action.meta.*; import me.dueris.originspaper.factory.data.ApoliDataTypes; import me.dueris.originspaper.registry.Registries; +import me.dueris.originspaper.registry.registries.OriginLayer; +import me.dueris.originspaper.registry.registries.PowerType; +import me.dueris.originspaper.util.entity.PowerHolderComponent; +import me.dueris.originspaper.util.entity.PowerUtils; +import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.Entity; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; public class EntityActions { @@ -25,6 +34,64 @@ public static void registerAll() { register(NothingAction.getFactory()); register(SideAction.getFactory(ApoliDataTypes.ENTITY_ACTION, entity -> !entity.level().isClientSide)); + register(new ActionFactory<>(OriginsPaper.apoliIdentifier("grant_power"), + InstanceDefiner.instanceDefiner() + .add("power", SerializableDataTypes.IDENTIFIER) + .add("source", SerializableDataTypes.IDENTIFIER), + (data, entity) -> { + if (entity.getBukkitEntity() instanceof Player p) { + PowerType powerContainer = OriginsPaper.getPlugin().registry.retrieve(Registries.CRAFT_POWER).get(data.getId("power")); + if (powerContainer == null) { + OriginsPaper.getPlugin().getLogger().severe("Searched PowerType was null when attempting to revoke a power: {}".replace("{}", data.getId("power").toString())); + return; + } + OriginLayer layer = CraftApoli.getLayer(data.getId("source")); + try { + PowerUtils.removePower(Bukkit.getConsoleSender(), powerContainer, p, layer, false); + } catch (InstantiationException | IllegalAccessException e) { + throw new RuntimeException(e); + } + } + })); + register(new ActionFactory<>(OriginsPaper.apoliIdentifier("remove_power"), + InstanceDefiner.instanceDefiner() + .add("power", SerializableDataTypes.IDENTIFIER) + .add("source", SerializableDataTypes.IDENTIFIER), + (data, entity) -> { + if (entity.getBukkitEntity() instanceof Player p) { + PowerType powerContainer = OriginsPaper.getPlugin().registry.retrieve(Registries.CRAFT_POWER).get(data.getId("power")); + if (powerContainer == null) { + OriginsPaper.getPlugin().getLogger().severe("Searched PowerType was null when attempting to apply a new power: {}".replace("{}", data.getId("power").toString())); + return; + } + OriginLayer layer = CraftApoli.getLayer(data.getId("source")); + try { + PowerUtils.grantPower(Bukkit.getConsoleSender(), powerContainer, p, layer, false); + } catch (InstantiationException | IllegalAccessException e) { + throw new RuntimeException(e); + } + } + })); + register(new ActionFactory<>(OriginsPaper.apoliIdentifier("revoke_all_powers"), + InstanceDefiner.instanceDefiner() + .add("source", SerializableDataTypes.IDENTIFIER), + (data, entity) -> { + if (entity instanceof Player p) { + for (ResourceLocation powerKey : PowerHolderComponent.getPowers(p).stream().map(PowerType::key).toList()) { + PowerType powerContainer = OriginsPaper.getPlugin().registry.retrieve(Registries.CRAFT_POWER).get(powerKey); + if (powerContainer == null) { + OriginsPaper.getPlugin().getLogger().severe("Searched PowerType was null when attempting to revoke a power: {}".replace("{}", powerKey.toString())); + return; + } + OriginLayer layer = CraftApoli.getLayer(data.getId("source")); + try { + PowerUtils.removePower(Bukkit.getConsoleSender(), powerContainer, p, layer, false); + } catch (InstantiationException | IllegalAccessException e) { + throw new RuntimeException(e); + } + } + } + })); Actions.registerPackage(EntityActions::register, "me.dueris.originspaper.factory.action.types.entity"); } diff --git a/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/AddVelocityAction.java b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/AddVelocityAction.java new file mode 100644 index 000000000..c0b3d8638 --- /dev/null +++ b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/AddVelocityAction.java @@ -0,0 +1,44 @@ +package me.dueris.originspaper.factory.action.types.entity; + +import io.github.dueris.calio.SerializableDataTypes; +import io.github.dueris.calio.parser.InstanceDefiner; +import me.dueris.originspaper.OriginsPaper; +import me.dueris.originspaper.factory.action.ActionFactory; +import me.dueris.originspaper.factory.data.ApoliDataTypes; +import me.dueris.originspaper.factory.data.types.Space; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.player.Player; +import org.apache.logging.log4j.util.TriConsumer; +import org.jetbrains.annotations.NotNull; +import org.joml.Vector3f; + +public class AddVelocityAction { + + public static @NotNull ActionFactory getFactory() { + return new ActionFactory<>(OriginsPaper.apoliIdentifier("add_velocity"), + InstanceDefiner.instanceDefiner() + .add("x", SerializableDataTypes.FLOAT, 0F) + .add("y", SerializableDataTypes.FLOAT, 0F) + .add("z", SerializableDataTypes.FLOAT, 0F) + .add("space", ApoliDataTypes.SPACE, Space.WORLD) + .add("client", SerializableDataTypes.BOOLEAN, true) + .add("server", SerializableDataTypes.BOOLEAN, true) + .add("set", SerializableDataTypes.BOOLEAN, false), + (data, entity) -> { + if (entity instanceof Player + && (entity.level().isClientSide ? + !data.getBoolean("client") : !data.getBoolean("server"))) + return; + Space space = data.get("space"); + Vector3f vec = new Vector3f(data.getFloat("x"), data.getFloat("y"), data.getFloat("z")); + TriConsumer method = entity::push; + if (data.getBoolean("set")) { + method = entity::setDeltaMovement; + } + space.toGlobal(vec, entity); + method.accept(vec.x, vec.y, vec.z); + entity.hurtMarked = true; + } + ); + } +} diff --git a/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/AddXpAction.java b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/AddXpAction.java new file mode 100644 index 000000000..c83fb0a84 --- /dev/null +++ b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/AddXpAction.java @@ -0,0 +1,30 @@ +package me.dueris.originspaper.factory.action.types.entity; + +import io.github.dueris.calio.SerializableDataTypes; +import io.github.dueris.calio.parser.InstanceDefiner; +import me.dueris.originspaper.OriginsPaper; +import me.dueris.originspaper.factory.action.ActionFactory; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.player.Player; +import org.jetbrains.annotations.NotNull; + +public class AddXpAction { + + public static @NotNull ActionFactory getFactory() { + return new ActionFactory<>(OriginsPaper.apoliIdentifier("add_xp"), + InstanceDefiner.instanceDefiner() + .add("points", SerializableDataTypes.INT, 0) + .add("levels", SerializableDataTypes.INT, 0), + (data, entity) -> { + if (entity instanceof Player) { + int points = data.getInt("points"); + int levels = data.getInt("levels"); + if (points > 0) { + ((Player) entity).giveExperiencePoints(points); + } + ((Player) entity).giveExperienceLevels(levels); + } + } + ); + } +} diff --git a/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/ApplyEffectAction.java b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/ApplyEffectAction.java new file mode 100644 index 000000000..9b23f6549 --- /dev/null +++ b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/ApplyEffectAction.java @@ -0,0 +1,34 @@ +package me.dueris.originspaper.factory.action.types.entity; + +import io.github.dueris.calio.SerializableDataTypes; +import io.github.dueris.calio.parser.InstanceDefiner; +import me.dueris.originspaper.OriginsPaper; +import me.dueris.originspaper.factory.action.ActionFactory; +import net.minecraft.world.effect.MobEffectInstance; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.LivingEntity; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +public class ApplyEffectAction { + + public static @NotNull ActionFactory getFactory() { + return new ActionFactory<>(OriginsPaper.apoliIdentifier("apply_effect"), + InstanceDefiner.instanceDefiner() + .add("effect", SerializableDataTypes.STATUS_EFFECT_INSTANCE, null) + .add("effects", SerializableDataTypes.list(SerializableDataTypes.STATUS_EFFECT_INSTANCE), null), + (data, entity) -> { + if (entity instanceof LivingEntity le && !entity.level().isClientSide) { + if (data.isPresent("effect")) { + MobEffectInstance effect = data.get("effect"); + le.addEffect(new MobEffectInstance(effect)); + } + if (data.isPresent("effects")) { + ((List) data.get("effects")).forEach(e -> le.addEffect(new MobEffectInstance(e))); + } + } + } + ); + } +} diff --git a/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/AreaOfEffectAction.java b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/AreaOfEffectAction.java new file mode 100644 index 000000000..d162d6ad0 --- /dev/null +++ b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/AreaOfEffectAction.java @@ -0,0 +1,56 @@ +package me.dueris.originspaper.factory.action.types.entity; + +import io.github.dueris.calio.SerializableDataTypes; +import io.github.dueris.calio.parser.InstanceDefiner; +import io.github.dueris.calio.parser.reader.DeserializedFactoryJson; +import me.dueris.originspaper.OriginsPaper; +import me.dueris.originspaper.factory.action.ActionFactory; +import me.dueris.originspaper.factory.data.ApoliDataTypes; +import me.dueris.originspaper.factory.data.types.Shape; +import net.minecraft.util.Tuple; +import net.minecraft.world.entity.Entity; +import org.jetbrains.annotations.NotNull; + +import java.util.function.Consumer; +import java.util.function.Predicate; + +public class AreaOfEffectAction { + + public static void action(@NotNull DeserializedFactoryJson data, @NotNull Entity entity) { + + Consumer> biEntityAction = data.get("bientity_action"); + Predicate> biEntityCondition = data.get("bientity_condition"); + Shape shape = data.get("shape"); + + boolean includeActor = data.get("include_actor"); + double radius = data.get("radius"); + + for (Entity target : Shape.getEntities(shape, entity.level(), entity.getPosition(1.0f), radius)) { + + if (target == entity && !includeActor) { + continue; + } + + Tuple actorAndTarget = new Tuple<>(entity, target); + if (biEntityCondition == null || biEntityCondition.test(actorAndTarget)) { + biEntityAction.accept(actorAndTarget); + } + + } + + } + + public static @NotNull ActionFactory getFactory() { + return new ActionFactory<>( + OriginsPaper.apoliIdentifier("area_of_effect"), + InstanceDefiner.instanceDefiner() + .add("radius", SerializableDataTypes.DOUBLE, 16D) + .add("shape", SerializableDataTypes.enumValue(Shape.class), Shape.CUBE) + .add("bientity_action", ApoliDataTypes.BIENTITY_ACTION) + .add("bientity_condition", ApoliDataTypes.BIENTITY_CONDITION, null) + .add("include_target", SerializableDataTypes.BOOLEAN, false) + .add("include_actor", SerializableDataTypes.BOOLEAN, false), + AreaOfEffectAction::action + ); + } +} diff --git a/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/BlockActionAtAction.java b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/BlockActionAtAction.java new file mode 100644 index 000000000..bb489c0b0 --- /dev/null +++ b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/BlockActionAtAction.java @@ -0,0 +1,23 @@ +package me.dueris.originspaper.factory.action.types.entity; + +import io.github.dueris.calio.parser.InstanceDefiner; +import me.dueris.originspaper.OriginsPaper; +import me.dueris.originspaper.factory.action.ActionFactory; +import me.dueris.originspaper.factory.data.ApoliDataTypes; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.level.Level; +import org.apache.commons.lang3.tuple.Triple; +import org.jetbrains.annotations.NotNull; + +public class BlockActionAtAction { + + public static @NotNull ActionFactory getFactory() { + return new ActionFactory<>(OriginsPaper.apoliIdentifier("block_action_at"), + InstanceDefiner.instanceDefiner() + .add("block_action", ApoliDataTypes.BLOCK_ACTION), + (data, entity) -> ((ActionFactory>) data.get("block_action")).accept( + Triple.of(entity.level(), entity.blockPosition(), Direction.UP))); + } +} diff --git a/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/ChangeResourceAction.java b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/ChangeResourceAction.java new file mode 100644 index 000000000..9b0bacae7 --- /dev/null +++ b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/ChangeResourceAction.java @@ -0,0 +1,28 @@ +package me.dueris.originspaper.factory.action.types.entity; + +import io.github.dueris.calio.SerializableDataTypes; +import io.github.dueris.calio.parser.InstanceDefiner; +import me.dueris.originspaper.OriginsPaper; +import me.dueris.originspaper.factory.action.ActionFactory; +import me.dueris.originspaper.factory.data.ApoliDataTypes; +import me.dueris.originspaper.factory.data.types.ResourceOperation; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.player.Player; +import org.jetbrains.annotations.NotNull; + +public class ChangeResourceAction { + + public static @NotNull ActionFactory getFactory() { + return new ActionFactory<>(OriginsPaper.apoliIdentifier("change_resource"), + InstanceDefiner.instanceDefiner() + .add("resource", SerializableDataTypes.IDENTIFIER) + .add("change", SerializableDataTypes.INT) + .add("operation", ApoliDataTypes.RESOURCE_OPERATION, ResourceOperation.ADD), + (data, entity) -> { + if (entity instanceof Player player) { + // TODO + } + } + ); + } +} diff --git a/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/ClearEffectAction.java b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/ClearEffectAction.java new file mode 100644 index 000000000..7e8912dfa --- /dev/null +++ b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/ClearEffectAction.java @@ -0,0 +1,28 @@ +package me.dueris.originspaper.factory.action.types.entity; + +import io.github.dueris.calio.SerializableDataTypes; +import io.github.dueris.calio.parser.InstanceDefiner; +import me.dueris.originspaper.OriginsPaper; +import me.dueris.originspaper.factory.action.ActionFactory; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.LivingEntity; +import org.jetbrains.annotations.NotNull; + +public class ClearEffectAction { + + public static @NotNull ActionFactory getFactory() { + return new ActionFactory<>(OriginsPaper.apoliIdentifier("clear_effect"), + InstanceDefiner.instanceDefiner() + .add("effect", SerializableDataTypes.STATUS_EFFECT_ENTRY, null), + (data, entity) -> { + if (entity instanceof LivingEntity le) { + if (data.isPresent("effect")) { + le.removeEffect(data.get("effect")); + } else { + le.removeAllEffects(); + } + } + } + ); + } +} diff --git a/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/CraftingTableAction.java b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/CraftingTableAction.java new file mode 100644 index 000000000..ebc19de99 --- /dev/null +++ b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/CraftingTableAction.java @@ -0,0 +1,32 @@ +package me.dueris.originspaper.factory.action.types.entity; + +import io.github.dueris.calio.parser.InstanceDefiner; +import io.github.dueris.calio.parser.reader.DeserializedFactoryJson; +import me.dueris.originspaper.OriginsPaper; +import me.dueris.originspaper.factory.action.ActionFactory; +import net.minecraft.stats.Stats; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.player.Player; +import org.jetbrains.annotations.NotNull; + +public class CraftingTableAction { + + public static void action(DeserializedFactoryJson data, Entity entity) { + + if (!(entity instanceof Player playerEntity)) { + return; + } + + playerEntity.getBukkitEntity().openWorkbench(null, true); + playerEntity.awardStat(Stats.INTERACT_WITH_CRAFTING_TABLE); + + } + + public static @NotNull ActionFactory getFactory() { + return new ActionFactory<>( + OriginsPaper.apoliIdentifier("crafting_table"), + InstanceDefiner.instanceDefiner(), + CraftingTableAction::action + ); + } +} diff --git a/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/DamageAction.java b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/DamageAction.java new file mode 100644 index 000000000..79c1ac289 --- /dev/null +++ b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/DamageAction.java @@ -0,0 +1,65 @@ +package me.dueris.originspaper.factory.action.types.entity; + +import io.github.dueris.calio.SerializableDataTypes; +import io.github.dueris.calio.parser.InstanceDefiner; +import io.github.dueris.calio.parser.reader.DeserializedFactoryJson; +import me.dueris.originspaper.OriginsPaper; +import me.dueris.originspaper.factory.action.ActionFactory; +import me.dueris.originspaper.factory.data.types.modifier.Modifier; +import me.dueris.originspaper.factory.data.types.modifier.ModifierUtil; +import me.dueris.originspaper.util.Util; +import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.LivingEntity; +import org.jetbrains.annotations.NotNull; + +import java.util.LinkedList; +import java.util.List; + +public class DamageAction { + + public static void action(@NotNull DeserializedFactoryJson data, Entity entity) { + + Float damageAmount = data.get("amount"); + List modifiers = new LinkedList<>(); + + data.ifPresent("modifier", modifiers::add); + data.>ifPresent("modifiers", modifiers::addAll); + + if (!modifiers.isEmpty() && entity instanceof LivingEntity livingEntity) { + damageAmount = (float) ModifierUtil.applyModifiers(livingEntity, modifiers, livingEntity.getMaxHealth()); + } + + if (damageAmount == null) { + return; + } + + try { + DamageSource source; + if (data.isPresent("damage_type")) { + source = Util.getDamageSource(Util.DAMAGE_REGISTRY.get(data.getId("damage_type"))); + } else { + source = entity.level().damageSources().generic(); + } + if (data.isPresent("source") && !data.isPresent("damage_type")) { + OriginsPaper.getPlugin().getLogger().warning("A \"source\" field was provided in the bientity_action \"apoli:damage\", please use the \"damage_type\" field instead."); + } + entity.hurt(source, damageAmount); + } catch (Throwable t) { + OriginsPaper.getPlugin().getLog4JLogger().error("Error trying to deal damage via the `damage` entity action: {}", t.getMessage()); + } + + } + + public static @NotNull ActionFactory getFactory() { + return new ActionFactory<>( + OriginsPaper.apoliIdentifier("damage"), + InstanceDefiner.instanceDefiner() + .add("amount", SerializableDataTypes.FLOAT, null) + .add("damage_type", SerializableDataTypes.DAMAGE_TYPE, null) + .add("modifier", Modifier.DATA_TYPE, null) + .add("modifiers", Modifier.LIST_TYPE, null), + DamageAction::action + ); + } +} diff --git a/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/DismountAction.java b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/DismountAction.java new file mode 100644 index 000000000..5d0c09fc8 --- /dev/null +++ b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/DismountAction.java @@ -0,0 +1,16 @@ +package me.dueris.originspaper.factory.action.types.entity; + +import io.github.dueris.calio.parser.InstanceDefiner; +import me.dueris.originspaper.OriginsPaper; +import me.dueris.originspaper.factory.action.ActionFactory; +import net.minecraft.world.entity.Entity; +import org.jetbrains.annotations.NotNull; + +public class DismountAction { + + public static @NotNull ActionFactory getFactory() { + return new ActionFactory<>(OriginsPaper.apoliIdentifier("dismount"), + InstanceDefiner.instanceDefiner(), + (data, entity) -> entity.stopRiding()); + } +} diff --git a/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/DropInventoryAction.java b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/DropInventoryAction.java new file mode 100644 index 000000000..6a73a62a1 --- /dev/null +++ b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/DropInventoryAction.java @@ -0,0 +1,42 @@ +package me.dueris.originspaper.factory.action.types.entity; + +import io.github.dueris.calio.SerializableDataTypes; +import io.github.dueris.calio.parser.InstanceDefiner; +import io.github.dueris.calio.parser.reader.DeserializedFactoryJson; +import me.dueris.originspaper.OriginsPaper; +import me.dueris.originspaper.factory.action.ActionFactory; +import me.dueris.originspaper.factory.data.ApoliDataTypes; +import me.dueris.originspaper.factory.data.types.InventoryType; +import net.minecraft.world.entity.Entity; +import org.jetbrains.annotations.NotNull; + +import static me.dueris.originspaper.util.Util.dropInventory; + +public class DropInventoryAction { + + public static void action(@NotNull DeserializedFactoryJson data, Entity entity) { + + InventoryType inventoryType = data.get("inventory_type"); + + switch (inventoryType) { + case INVENTORY -> dropInventory(data, entity); + } + + } + + public static @NotNull ActionFactory getFactory() { + return new ActionFactory<>(OriginsPaper.apoliIdentifier("drop_inventory"), + InstanceDefiner.instanceDefiner() + .add("inventory_type", ApoliDataTypes.INVENTORY_TYPE, InventoryType.INVENTORY) + .add("entity_action", ApoliDataTypes.ENTITY_ACTION, null) + .add("item_action", ApoliDataTypes.ITEM_ACTION, null) + .add("item_condition", ApoliDataTypes.ITEM_CONDITION, null) + .add("slots", SerializableDataTypes.list(ApoliDataTypes.ITEM_SLOT), null) + .add("slot", ApoliDataTypes.ITEM_SLOT, null) + .add("throw_randomly", SerializableDataTypes.BOOLEAN, false) + .add("retain_ownership", SerializableDataTypes.BOOLEAN, true) + .add("amount", SerializableDataTypes.INT, 0), + DropInventoryAction::action + ); + } +} diff --git a/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/EmitGameEvent.java b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/EmitGameEvent.java new file mode 100644 index 000000000..2db878531 --- /dev/null +++ b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/EmitGameEvent.java @@ -0,0 +1,18 @@ +package me.dueris.originspaper.factory.action.types.entity; + +import io.github.dueris.calio.SerializableDataTypes; +import io.github.dueris.calio.parser.InstanceDefiner; +import me.dueris.originspaper.OriginsPaper; +import me.dueris.originspaper.factory.action.ActionFactory; +import net.minecraft.world.entity.Entity; +import org.jetbrains.annotations.NotNull; + +public class EmitGameEvent { + + public static @NotNull ActionFactory getFactory() { + return new ActionFactory<>(OriginsPaper.apoliIdentifier("emit_game_event"), + InstanceDefiner.instanceDefiner() + .add("event", SerializableDataTypes.GAME_EVENT), + (data, entity) -> entity.gameEvent(data.get("event"))); + } +} diff --git a/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/EnderChestAction.java b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/EnderChestAction.java new file mode 100644 index 000000000..9f3080104 --- /dev/null +++ b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/EnderChestAction.java @@ -0,0 +1,41 @@ +package me.dueris.originspaper.factory.action.types.entity; + +import io.github.dueris.calio.parser.InstanceDefiner; +import io.github.dueris.calio.parser.reader.DeserializedFactoryJson; +import me.dueris.originspaper.OriginsPaper; +import me.dueris.originspaper.factory.action.ActionFactory; +import net.minecraft.network.chat.Component; +import net.minecraft.stats.Stats; +import net.minecraft.world.SimpleMenuProvider; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.ChestMenu; +import net.minecraft.world.inventory.PlayerEnderChestContainer; +import org.jetbrains.annotations.NotNull; + +public class EnderChestAction { + + private static final Component TITLE = Component.translatable("container.enderchest"); + + public static void action(DeserializedFactoryJson data, Entity entity) { + if (!(entity instanceof Player player)) return; + + PlayerEnderChestContainer enderChestContainer = player.getEnderChestInventory(); + + player.openMenu( + new SimpleMenuProvider((i, inventory, _player) -> + ChestMenu.threeRows(i, inventory, enderChestContainer), + TITLE + ) + ); + + player.awardStat(Stats.OPEN_ENDERCHEST); + } + + public static @NotNull ActionFactory getFactory() { + return new ActionFactory<>(OriginsPaper.apoliIdentifier("ender_chest"), + InstanceDefiner.instanceDefiner(), + EnderChestAction::action + ); + } +} diff --git a/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/EquippedItemAction.java b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/EquippedItemAction.java new file mode 100644 index 000000000..0c80b3fdd --- /dev/null +++ b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/EquippedItemAction.java @@ -0,0 +1,44 @@ +package me.dueris.originspaper.factory.action.types.entity; + +import io.github.dueris.calio.SerializableDataTypes; +import io.github.dueris.calio.parser.InstanceDefiner; +import io.github.dueris.calio.parser.reader.DeserializedFactoryJson; +import me.dueris.originspaper.OriginsPaper; +import me.dueris.originspaper.factory.action.ActionFactory; +import me.dueris.originspaper.factory.data.ApoliDataTypes; +import net.minecraft.util.Tuple; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EquipmentSlot; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.SlotAccess; +import net.minecraft.world.level.Level; +import org.jetbrains.annotations.NotNull; + +import java.util.function.Consumer; + +public class EquippedItemAction { + + public static void action(DeserializedFactoryJson data, Entity entity) { + + if (!(entity instanceof LivingEntity livingEntity)) { + return; + } + + EquipmentSlot slot = data.get("equipment_slot"); + Consumer> itemAction = data.get("action"); + + SlotAccess stackReference = SlotAccess.forEquipmentSlot(livingEntity, slot); + itemAction.accept(new Tuple<>(entity.level(), stackReference)); + + } + + public static @NotNull ActionFactory getFactory() { + return new ActionFactory<>( + OriginsPaper.apoliIdentifier("equipped_item_action"), + InstanceDefiner.instanceDefiner() + .add("equipment_slot", SerializableDataTypes.EQUIPMENT_SLOT) + .add("action", ApoliDataTypes.ITEM_ACTION), + EquippedItemAction::action + ); + } +} diff --git a/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/ExecuteCommandAction.java b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/ExecuteCommandAction.java new file mode 100644 index 000000000..a3044b0cc --- /dev/null +++ b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/ExecuteCommandAction.java @@ -0,0 +1,47 @@ +package me.dueris.originspaper.factory.action.types.entity; + +import io.github.dueris.calio.SerializableDataTypes; +import io.github.dueris.calio.parser.InstanceDefiner; +import me.dueris.originspaper.OriginsPaper; +import me.dueris.originspaper.factory.action.ActionFactory; +import net.minecraft.commands.CommandSource; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.entity.Entity; +import org.jetbrains.annotations.NotNull; + +public class ExecuteCommandAction { + + public static @NotNull ActionFactory getFactory() { + return new ActionFactory<>(OriginsPaper.apoliIdentifier("execute_command"), + InstanceDefiner.instanceDefiner() + .add("command", SerializableDataTypes.STRING), + (data, entity) -> { + MinecraftServer server = entity.level().getServer(); + if (server != null) { + boolean validOutput = !(entity instanceof ServerPlayer) || ((ServerPlayer) entity).connection != null; + CommandSourceStack source = new CommandSourceStack( + OriginsPaper.showCommandOutput && validOutput ? entity : CommandSource.NULL, + entity.position(), + entity.getRotationVector(), + entity.level() instanceof ServerLevel ? (ServerLevel) entity.level() : null, + 4, + entity.getName().getString(), + entity.getDisplayName(), + entity.level().getServer(), + entity); + String cmd = data.getString("command"); + // Fix the command to support our pehuki implementation + if (cmd.contains("scale")) { + if (cmd.contains("@s")) { + cmd = cmd.replace(" @s", ""); + } + } + server.getCommands().performPrefixedCommand(source, cmd); + } + } + ); + } +} diff --git a/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/ExhaustAction.java b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/ExhaustAction.java new file mode 100644 index 000000000..b17e71b93 --- /dev/null +++ b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/ExhaustAction.java @@ -0,0 +1,23 @@ +package me.dueris.originspaper.factory.action.types.entity; + +import io.github.dueris.calio.SerializableDataTypes; +import io.github.dueris.calio.parser.InstanceDefiner; +import me.dueris.originspaper.OriginsPaper; +import me.dueris.originspaper.factory.action.ActionFactory; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.player.Player; +import org.jetbrains.annotations.NotNull; + +public class ExhaustAction { + + public static @NotNull ActionFactory getFactory() { + return new ActionFactory<>(OriginsPaper.apoliIdentifier("exhaust"), + InstanceDefiner.instanceDefiner() + .add("amount", SerializableDataTypes.FLOAT), + (data, entity) -> { + if (entity instanceof Player) + ((Player) entity).getFoodData().addExhaustion(data.getFloat("amount")); + } + ); + } +} diff --git a/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/ExplodeAction.java b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/ExplodeAction.java new file mode 100644 index 000000000..717beab6d --- /dev/null +++ b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/ExplodeAction.java @@ -0,0 +1,65 @@ +package me.dueris.originspaper.factory.action.types.entity; + +import io.github.dueris.calio.SerializableDataTypes; +import io.github.dueris.calio.parser.InstanceDefiner; +import io.github.dueris.calio.parser.reader.DeserializedFactoryJson; +import me.dueris.originspaper.OriginsPaper; +import me.dueris.originspaper.factory.action.ActionFactory; +import me.dueris.originspaper.factory.data.ApoliDataTypes; +import me.dueris.originspaper.factory.data.types.ExplosionMask; +import net.minecraft.core.particles.ParticleTypes; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.level.Explosion; +import net.minecraft.world.level.ExplosionDamageCalculator; +import net.minecraft.world.level.Level; +import net.minecraft.world.phys.Vec3; +import org.jetbrains.annotations.NotNull; + +public class ExplodeAction { + + public static void action(DeserializedFactoryJson data, @NotNull Entity entity) { + + Level level = entity.level(); + if (level.isClientSide) { + return; + } + + float explosionPower = data.get("power"); + boolean create_fire = data.getBoolean("create_fire"); + + Vec3 location = entity.position(); + + Explosion explosion = new Explosion( + level, + null, + level.damageSources().generic(), + new ExplosionDamageCalculator(), + location.x, + location.y, + location.z, + explosionPower, + create_fire, + data.get("destruction_type"), + ParticleTypes.EXPLOSION, + ParticleTypes.EXPLOSION_EMITTER, + SoundEvents.GENERIC_EXPLODE + ); + ExplosionMask.getExplosionMask(explosion, level).apply(true, data.get("indestructible"), data.get("destructible"), true); + + } + + public static @NotNull ActionFactory getFactory() { + return new ActionFactory<>( + OriginsPaper.apoliIdentifier("explode"), + InstanceDefiner.instanceDefiner() + .add("power", SerializableDataTypes.FLOAT) + .add("destruction_type", ApoliDataTypes.BACKWARDS_COMPATIBLE_DESTRUCTION_TYPE, Explosion.BlockInteraction.DESTROY) + .add("indestructible", ApoliDataTypes.BLOCK_CONDITION, null) + .add("indestructible_resistance", SerializableDataTypes.FLOAT, 10.0f) + .add("destructible", ApoliDataTypes.BLOCK_CONDITION, null) + .add("create_fire", SerializableDataTypes.BOOLEAN, false), + ExplodeAction::action + ); + } +} diff --git a/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/ExtinguishAction.java b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/ExtinguishAction.java new file mode 100644 index 000000000..63eb3d539 --- /dev/null +++ b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/ExtinguishAction.java @@ -0,0 +1,16 @@ +package me.dueris.originspaper.factory.action.types.entity; + +import io.github.dueris.calio.parser.InstanceDefiner; +import me.dueris.originspaper.OriginsPaper; +import me.dueris.originspaper.factory.action.ActionFactory; +import net.minecraft.world.entity.Entity; +import org.jetbrains.annotations.NotNull; + +public class ExtinguishAction { + + public static @NotNull ActionFactory getFactory() { + return new ActionFactory<>(OriginsPaper.identifier("extinguish"), + InstanceDefiner.instanceDefiner(), + (data, entity) -> entity.clearFire()); + } +} diff --git a/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/FeedAction.java b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/FeedAction.java new file mode 100644 index 000000000..f1ffeec11 --- /dev/null +++ b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/FeedAction.java @@ -0,0 +1,25 @@ +package me.dueris.originspaper.factory.action.types.entity; + +import io.github.dueris.calio.SerializableDataTypes; +import io.github.dueris.calio.parser.InstanceDefiner; +import me.dueris.originspaper.OriginsPaper; +import me.dueris.originspaper.factory.action.ActionFactory; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.player.Player; +import org.jetbrains.annotations.NotNull; + +public class FeedAction { + + public static @NotNull ActionFactory getFactory() { + return new ActionFactory<>(OriginsPaper.apoliIdentifier("feed"), + InstanceDefiner.instanceDefiner() + .add("food", SerializableDataTypes.INT) + .add("saturation", SerializableDataTypes.FLOAT), + (data, entity) -> { + if (entity instanceof Player) { + ((Player) entity).getFoodData().eat(data.getInt("food"), data.getFloat("saturation")); + } + } + ); + } +} diff --git a/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/FireProjectileAction.java b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/FireProjectileAction.java new file mode 100644 index 000000000..5342371bc --- /dev/null +++ b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/FireProjectileAction.java @@ -0,0 +1,114 @@ +package me.dueris.originspaper.factory.action.types.entity; + +import io.github.dueris.calio.SerializableDataTypes; +import io.github.dueris.calio.parser.InstanceDefiner; +import io.github.dueris.calio.parser.reader.DeserializedFactoryJson; +import me.dueris.originspaper.OriginsPaper; +import me.dueris.originspaper.factory.action.ActionFactory; +import me.dueris.originspaper.factory.data.ApoliDataTypes; +import me.dueris.originspaper.util.Util; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.util.Mth; +import net.minecraft.util.RandomSource; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.projectile.AbstractHurtingProjectile; +import net.minecraft.world.entity.projectile.Projectile; +import net.minecraft.world.phys.Vec3; +import org.jetbrains.annotations.NotNull; + +import java.util.function.Consumer; + +public class FireProjectileAction { + + public static void action(DeserializedFactoryJson data, @NotNull Entity entity) { + + if (!(entity.level() instanceof ServerLevel serverWorld)) { + return; + } + + EntityType entityType = data.get("entity_type"); + CompoundTag entityNbt = data.get("tag"); + RandomSource random = serverWorld.getRandom(); + + Vec3 rotationVector = entity.getLookAngle(); + Vec3 velocity = entity.getDeltaMovement(); + Vec3 verticalOffset = entity + .position() + .add(0, entity.getEyeHeight(entity.getPose()), 0); + + float divergence = data.get("divergence"); + float speed = data.get("speed"); + float pitch = entity.getXRot(); + float yaw = entity.getYRot(); + + int count = data.get("count"); + for (int i = 0; i < count; i++) { + + Entity entityToSpawn = Util + .getEntityWithPassengers(serverWorld, entityType, entityNbt, verticalOffset, yaw, pitch) + .orElse(null); + + if (entityToSpawn == null) { + return; + } + + if (entityToSpawn instanceof Projectile projectileToSpawn) { + + if (projectileToSpawn instanceof AbstractHurtingProjectile explosiveProjectileToSpawn) { + explosiveProjectileToSpawn.accelerationPower = speed; + } + + projectileToSpawn.setOwner(entity); + projectileToSpawn.shootFromRotation(entity, pitch, yaw, 0F, speed, divergence); + + } else { + + float j = 0.017453292F; + double k = 0.007499999832361937D; + + float l = -Mth.sin(yaw * j) * Mth.cos(pitch * j); + float m = -Mth.sin(pitch * j); + float n = Mth.cos(yaw * j) * Mth.cos(pitch * j); + + Vec3 entityToSpawnVelocity = new Vec3(l, m, n) + .normalize() + .add(random.nextGaussian() * k * divergence, random.nextGaussian() * k * divergence, random.nextGaussian() * k * divergence) + .scale(speed); + + entityToSpawn.setDeltaMovement(entityToSpawnVelocity); + entityToSpawn.push(velocity.x, entity.onGround() ? 0.0D : velocity.y, velocity.z); + + } + + if (!entityNbt.isEmpty()) { + + CompoundTag mergedNbt = entityToSpawn.saveWithoutId(new CompoundTag()); + mergedNbt.merge(entityNbt); + + entityToSpawn.load(mergedNbt); + + } + + serverWorld.tryAddFreshEntityWithPassengers(entityToSpawn); + data.>ifPresent("projectile_action", projectileAction -> projectileAction.accept(entityToSpawn)); + + } + + } + + public static @NotNull ActionFactory getFactory() { + return new ActionFactory<>( + OriginsPaper.apoliIdentifier("fire_projectile"), + InstanceDefiner.instanceDefiner() + .add("entity_type", SerializableDataTypes.ENTITY_TYPE) + .add("divergence", SerializableDataTypes.FLOAT, 1F) + .add("speed", SerializableDataTypes.FLOAT, 1.5F) + .add("count", SerializableDataTypes.INT, 1) + .add("tag", SerializableDataTypes.NBT, new CompoundTag()) + .add("projectile_action", ApoliDataTypes.ENTITY_ACTION, null), + FireProjectileAction::action + ); + } +} diff --git a/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/GainAirAction.java b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/GainAirAction.java new file mode 100644 index 000000000..9ad3f7100 --- /dev/null +++ b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/GainAirAction.java @@ -0,0 +1,24 @@ +package me.dueris.originspaper.factory.action.types.entity; + +import io.github.dueris.calio.SerializableDataTypes; +import io.github.dueris.calio.parser.InstanceDefiner; +import me.dueris.originspaper.OriginsPaper; +import me.dueris.originspaper.factory.action.ActionFactory; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.LivingEntity; +import org.jetbrains.annotations.NotNull; + +public class GainAirAction { + + public static @NotNull ActionFactory getFactory() { + return new ActionFactory<>(OriginsPaper.identifier("gain_air"), + InstanceDefiner.instanceDefiner() + .add("value", SerializableDataTypes.INT), + (data, entity) -> { + if (entity instanceof LivingEntity le) { + le.setAirSupply(Math.min(le.getAirSupply() + data.getInt("value"), le.getMaxAirSupply())); + } + } + ); + } +} diff --git a/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/GiveAction.java b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/GiveAction.java new file mode 100644 index 000000000..4cd217189 --- /dev/null +++ b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/GiveAction.java @@ -0,0 +1,87 @@ +package me.dueris.originspaper.factory.action.types.entity; + +import io.github.dueris.calio.SerializableDataTypes; +import io.github.dueris.calio.parser.InstanceDefiner; +import io.github.dueris.calio.parser.reader.DeserializedFactoryJson; +import me.dueris.originspaper.OriginsPaper; +import me.dueris.originspaper.factory.action.ActionFactory; +import me.dueris.originspaper.factory.data.ApoliDataTypes; +import me.dueris.originspaper.util.Util; +import net.minecraft.util.Tuple; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EquipmentSlot; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.SlotAccess; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; +import org.jetbrains.annotations.NotNull; + +import java.util.function.Consumer; + +public class GiveAction { + + public static void action(DeserializedFactoryJson data, @NotNull Entity entity) { + + if (entity.level().isClientSide) { + return; + } + + ItemStack stack = data.get("stack").copy(); + if (stack.isEmpty()) { + return; + } + + SlotAccess stackReference = Util.createStackReference(stack); + if (data.isPresent("item_action")) { + Consumer> itemAction = data.get("item_action"); + itemAction.accept(new Tuple<>(entity.level(), stackReference)); + } + + stack = stackReference.get(); + + tryPreferredSlot: + if (data.isPresent("preferred_slot") && entity instanceof LivingEntity livingEntity) { + + EquipmentSlot preferredSlot = data.get("preferred_slot"); + ItemStack stackInSlot = livingEntity.getItemBySlot(preferredSlot); + + if (stackInSlot.isEmpty()) { + livingEntity.setItemSlot(preferredSlot, stack); + return; + } + + if (!ItemStack.matches(stackInSlot, stack) || stackInSlot.getCount() >= stackInSlot.getMaxStackSize()) { + break tryPreferredSlot; + } + + int itemsToGive = Math.min(stackInSlot.getMaxStackSize() - stackInSlot.getCount(), stack.getCount()); + + stackInSlot.grow(itemsToGive); + stack.shrink(itemsToGive); + + if (stack.isEmpty()) { + return; + } + + } + + if (entity instanceof Player playerEntity) { + playerEntity.getInventory().placeItemBackInInventory(stack); + } else { + Util.throwItem(entity, stack, false, false); + } + + } + + public static @NotNull ActionFactory getFactory() { + return new ActionFactory<>( + OriginsPaper.apoliIdentifier("give"), + InstanceDefiner.instanceDefiner() + .add("stack", SerializableDataTypes.ITEM_STACK) + .add("item_action", ApoliDataTypes.ITEM_ACTION, null) + .add("preferred_slot", SerializableDataTypes.EQUIPMENT_SLOT, null), + GiveAction::action + ); + } +} diff --git a/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/GrantAdvancementAction.java b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/GrantAdvancementAction.java new file mode 100644 index 000000000..5ad38f236 --- /dev/null +++ b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/GrantAdvancementAction.java @@ -0,0 +1,28 @@ +package me.dueris.originspaper.factory.action.types.entity; + +import io.github.dueris.calio.SerializableDataTypes; +import io.github.dueris.calio.parser.InstanceDefiner; +import io.github.dueris.calio.parser.reader.DeserializedFactoryJson; +import me.dueris.originspaper.OriginsPaper; +import me.dueris.originspaper.factory.action.ActionFactory; +import net.minecraft.world.entity.Entity; +import org.bukkit.Bukkit; +import org.jetbrains.annotations.NotNull; + +public class GrantAdvancementAction { + + public static void action(@NotNull DeserializedFactoryJson data, @NotNull Entity entity) { + Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "advancement grant $1 only $2" + .replace("$1", entity.getName().getString()) + .replace("$2", data.getString("advancement"))); + } + + public static @NotNull ActionFactory getFactory() { + return new ActionFactory<>( + OriginsPaper.apoliIdentifier("grant_advancement"), + InstanceDefiner.instanceDefiner() + .add("advancement", SerializableDataTypes.IDENTIFIER, null), + GrantAdvancementAction::action + ); + } +} diff --git a/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/HealAction.java b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/HealAction.java new file mode 100644 index 000000000..1e562a9dc --- /dev/null +++ b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/HealAction.java @@ -0,0 +1,24 @@ +package me.dueris.originspaper.factory.action.types.entity; + +import io.github.dueris.calio.SerializableDataTypes; +import io.github.dueris.calio.parser.InstanceDefiner; +import me.dueris.originspaper.OriginsPaper; +import me.dueris.originspaper.factory.action.ActionFactory; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.LivingEntity; +import org.jetbrains.annotations.NotNull; + +public class HealAction { + + public static @NotNull ActionFactory getFactory() { + return new ActionFactory<>(OriginsPaper.apoliIdentifier("heal"), + InstanceDefiner.instanceDefiner() + .add("amount", SerializableDataTypes.FLOAT), + (data, entity) -> { + if (entity instanceof LivingEntity) { + ((LivingEntity) entity).heal(data.getFloat("amount")); + } + } + ); + } +} diff --git a/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/ModifyDeathTicksAction.java b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/ModifyDeathTicksAction.java new file mode 100644 index 000000000..bd74cafb8 --- /dev/null +++ b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/ModifyDeathTicksAction.java @@ -0,0 +1,27 @@ +package me.dueris.originspaper.factory.action.types.entity; + +import io.github.dueris.calio.parser.InstanceDefiner; +import io.github.dueris.calio.parser.reader.DeserializedFactoryJson; +import me.dueris.originspaper.OriginsPaper; +import me.dueris.originspaper.factory.action.ActionFactory; +import me.dueris.originspaper.factory.data.types.modifier.Modifier; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.LivingEntity; +import org.jetbrains.annotations.NotNull; + +public class ModifyDeathTicksAction { + + public static void action(DeserializedFactoryJson data, Entity entity) { + if (entity instanceof LivingEntity living) { + living.deathTime = (int) data.get("modifier").apply(entity, living.deathTime); + } + } + + public static @NotNull ActionFactory getFactory() { + return new ActionFactory<>(OriginsPaper.apoliIdentifier("modify_death_ticks"), + InstanceDefiner.instanceDefiner() + .add("modifier", Modifier.DATA_TYPE), + ModifyDeathTicksAction::action + ); + } +} diff --git a/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/ModifyInventoryAction.java b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/ModifyInventoryAction.java new file mode 100644 index 000000000..87f5282c5 --- /dev/null +++ b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/ModifyInventoryAction.java @@ -0,0 +1,45 @@ +package me.dueris.originspaper.factory.action.types.entity; + +import io.github.dueris.calio.SerializableDataTypes; +import io.github.dueris.calio.parser.InstanceDefiner; +import io.github.dueris.calio.parser.reader.DeserializedFactoryJson; +import me.dueris.originspaper.OriginsPaper; +import me.dueris.originspaper.factory.action.ActionFactory; +import me.dueris.originspaper.factory.data.ApoliDataTypes; +import me.dueris.originspaper.factory.data.types.InventoryType; +import me.dueris.originspaper.util.Util; +import net.minecraft.world.entity.Entity; +import org.jetbrains.annotations.NotNull; + +import static me.dueris.originspaper.util.Util.modifyInventory; + +public class ModifyInventoryAction { + + public static void action(@NotNull DeserializedFactoryJson data, Entity entity) { + + InventoryType inventoryType = data.get("inventory_type"); + Util.ProcessMode processMode = data.get("process_mode"); + int limit = data.getInt("limit"); + + switch (inventoryType) { + case INVENTORY: + modifyInventory(data, entity, processMode.getProcessor(), limit); + break; + } + } + + public static @NotNull ActionFactory getFactory() { + return new ActionFactory<>(OriginsPaper.apoliIdentifier("modify_inventory"), + InstanceDefiner.instanceDefiner() + .add("inventory_type", ApoliDataTypes.INVENTORY_TYPE, InventoryType.INVENTORY) + .add("process_mode", ApoliDataTypes.PROCESS_MODE, Util.ProcessMode.STACKS) + .add("entity_action", ApoliDataTypes.ENTITY_ACTION, null) + .add("item_action", ApoliDataTypes.ITEM_ACTION) + .add("item_condition", ApoliDataTypes.ITEM_CONDITION, null) + .add("slots", SerializableDataTypes.list(ApoliDataTypes.ITEM_SLOT), null) + .add("slot", ApoliDataTypes.ITEM_SLOT, null) + .add("limit", SerializableDataTypes.INT, 0), + ModifyInventoryAction::action + ); + } +} diff --git a/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/ModifyResourceAction.java b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/ModifyResourceAction.java new file mode 100644 index 000000000..c3d149b4e --- /dev/null +++ b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/ModifyResourceAction.java @@ -0,0 +1,26 @@ +package me.dueris.originspaper.factory.action.types.entity; + +import io.github.dueris.calio.SerializableDataTypes; +import io.github.dueris.calio.parser.InstanceDefiner; +import io.github.dueris.calio.parser.reader.DeserializedFactoryJson; +import me.dueris.originspaper.OriginsPaper; +import me.dueris.originspaper.factory.action.ActionFactory; +import me.dueris.originspaper.factory.data.types.modifier.Modifier; +import net.minecraft.world.entity.Entity; +import org.jetbrains.annotations.NotNull; + +public class ModifyResourceAction { + + public static void action(DeserializedFactoryJson data, Entity entity) { + // TODO + } + + public static @NotNull ActionFactory getFactory() { + return new ActionFactory<>(OriginsPaper.apoliIdentifier("modify_resource"), + InstanceDefiner.instanceDefiner() + .add("modifier", Modifier.DATA_TYPE) + .add("resource", SerializableDataTypes.IDENTIFIER), + ModifyResourceAction::action + ); + } +} diff --git a/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/ModifyStatAction.java b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/ModifyStatAction.java new file mode 100644 index 000000000..f802a5711 --- /dev/null +++ b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/ModifyStatAction.java @@ -0,0 +1,42 @@ +package me.dueris.originspaper.factory.action.types.entity; + +import io.github.dueris.calio.SerializableDataTypes; +import io.github.dueris.calio.parser.InstanceDefiner; +import io.github.dueris.calio.parser.reader.DeserializedFactoryJson; +import me.dueris.originspaper.OriginsPaper; +import me.dueris.originspaper.factory.action.ActionFactory; +import me.dueris.originspaper.factory.data.types.modifier.Modifier; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.stats.ServerStatsCounter; +import net.minecraft.stats.Stat; +import net.minecraft.world.entity.Entity; +import org.jetbrains.annotations.NotNull; + +public class ModifyStatAction { + + public static void action(DeserializedFactoryJson data, Entity entity) { + if (!(entity instanceof ServerPlayer serverPlayerEntity)) return; + + Stat stat = data.get("stat"); + ServerStatsCounter serverStatHandler = serverPlayerEntity.getStats(); + + int newValue; + int originalValue = serverStatHandler.getValue(stat); + + serverPlayerEntity.resetStat(stat); + + Modifier modifier = data.get("modifier"); + newValue = (int) modifier.apply(entity, originalValue); + + serverPlayerEntity.awardStat(stat, newValue); + } + + public static @NotNull ActionFactory getFactory() { + return new ActionFactory<>(OriginsPaper.apoliIdentifier("modify_stat"), + InstanceDefiner.instanceDefiner() + .add("stat", SerializableDataTypes.STAT) + .add("modifier", Modifier.DATA_TYPE), + ModifyStatAction::action + ); + } +} diff --git a/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/PassengerAction.java b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/PassengerAction.java new file mode 100644 index 000000000..fb2b07b6a --- /dev/null +++ b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/PassengerAction.java @@ -0,0 +1,45 @@ +package me.dueris.originspaper.factory.action.types.entity; + +import io.github.dueris.calio.SerializableDataTypes; +import io.github.dueris.calio.parser.InstanceDefiner; +import me.dueris.originspaper.OriginsPaper; +import me.dueris.originspaper.factory.action.ActionFactory; +import me.dueris.originspaper.factory.data.ApoliDataTypes; +import net.minecraft.util.Tuple; +import net.minecraft.world.entity.Entity; +import org.jetbrains.annotations.NotNull; + +import java.util.function.Consumer; +import java.util.function.Predicate; + +public class PassengerAction { + + public static @NotNull ActionFactory getFactory() { + return new ActionFactory<>(OriginsPaper.apoliIdentifier("passenger_action"), + InstanceDefiner.instanceDefiner() + .add("action", ApoliDataTypes.ENTITY_ACTION, null) + .add("bientity_action", ApoliDataTypes.BIENTITY_ACTION, null) + .add("bientity_condition", ApoliDataTypes.BIENTITY_CONDITION, null) + .add("recursive", SerializableDataTypes.BOOLEAN, false), + (data, entity) -> { + Consumer entityAction = data.get("action"); + Consumer> bientityAction = data.get("bientity_action"); + Predicate> cond = data.get("bientity_condition"); + if (!entity.isVehicle() || (entityAction == null && bientityAction == null)) { + return; + } + Iterable passengers = data.getBoolean("recursive") ? entity.getIndirectPassengers() : entity.getPassengers(); + for (Entity passenger : passengers) { + if (cond == null || cond.test(new Tuple<>(passenger, entity))) { + if (entityAction != null) { + entityAction.accept(passenger); + } + if (bientityAction != null) { + bientityAction.accept(new Tuple<>(passenger, entity)); + } + } + } + } + ); + } +} diff --git a/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/PlaySoundAction.java b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/PlaySoundAction.java new file mode 100644 index 000000000..e44b1b5c5 --- /dev/null +++ b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/PlaySoundAction.java @@ -0,0 +1,30 @@ +package me.dueris.originspaper.factory.action.types.entity; + +import io.github.dueris.calio.SerializableDataTypes; +import io.github.dueris.calio.parser.InstanceDefiner; +import io.github.dueris.calio.parser.reader.DeserializedFactoryJson; +import me.dueris.originspaper.OriginsPaper; +import me.dueris.originspaper.factory.action.ActionFactory; +import net.minecraft.sounds.SoundSource; +import net.minecraft.world.entity.Entity; +import org.jetbrains.annotations.NotNull; + +public class PlaySoundAction { + + public static void action(@NotNull DeserializedFactoryJson data, @NotNull Entity entity) { + SoundSource category = data.isPresent("category") ? data.get("category") : entity.getSoundSource(); + entity.level().playSound(null, entity.blockPosition(), data.get("sound"), category, data.getFloat("volume"), data.getFloat("pitch")); + } + + public static @NotNull ActionFactory getFactory() { + return new ActionFactory<>( + OriginsPaper.apoliIdentifier("play_sound"), + InstanceDefiner.instanceDefiner() + .add("sound", SerializableDataTypes.SOUND_EVENT) + .add("category", SerializableDataTypes.enumValue(SoundSource.class), null) + .add("volume", SerializableDataTypes.FLOAT, 1.0f) + .add("pitch", SerializableDataTypes.FLOAT, 1.0f), + PlaySoundAction::action + ); + } +} diff --git a/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/RandomTeleportAction.java b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/RandomTeleportAction.java new file mode 100644 index 000000000..8c7e0d2ed --- /dev/null +++ b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/RandomTeleportAction.java @@ -0,0 +1,166 @@ +package me.dueris.originspaper.factory.action.types.entity; + +import io.github.dueris.calio.SerializableDataTypes; +import io.github.dueris.calio.parser.InstanceDefiner; +import io.github.dueris.calio.parser.reader.DeserializedFactoryJson; +import me.dueris.originspaper.OriginsPaper; +import me.dueris.originspaper.factory.action.ActionFactory; +import me.dueris.originspaper.factory.data.ApoliDataTypes; +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.TicketType; +import net.minecraft.util.Mth; +import net.minecraft.util.RandomSource; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.PathfinderMob; +import net.minecraft.world.level.ChunkPos; +import net.minecraft.world.level.block.state.pattern.BlockInWorld; +import net.minecraft.world.level.levelgen.Heightmap; +import net.minecraft.world.phys.Vec3; +import org.jetbrains.annotations.NotNull; + +import java.util.function.Consumer; +import java.util.function.Predicate; + +public class RandomTeleportAction { + + public static void action(DeserializedFactoryJson data, @NotNull Entity entity) { + + if (!(entity.level() instanceof ServerLevel serverWorld)) { + return; + } + + Predicate landingBlockCondition = data.isPresent("landing_block_condition") ? data.get("landing_block_condition") + : cachedBlockPosition -> cachedBlockPosition.getState().blocksMotion(); + Predicate landingCondition = data.isPresent("landing_condition") ? data.get("landing_condition") + : _entity -> serverWorld.noCollision(_entity) && !serverWorld.containsAnyLiquid(_entity.getBoundingBox()); + + Heightmap.Types heightmap = data.get("heightmap"); + RandomSource random = RandomSource.create(); + Vec3 landingOffset = data.get("landing_offset"); + + boolean loadedChunksOnly = data.getBoolean("loaded_chunks_only"); + boolean succeeded = false; + + int attempts = data.isPresent("attempts") ? (int) ((data.getDouble("area_width") * 2) + (data.getDouble("area_height") * 2)) : 1; + + double areaWidth = data.getDouble("area_width") * 2; + double areaHeight = data.getDouble("area_height") * 2; + double x, y, z; + + for (int i = 0; i < attempts; i++) { + + x = entity.getX() + (random.nextDouble() - 0.5) * areaWidth; + y = Mth.clamp(entity.getY() + (random.nextInt(Math.max((int) areaHeight, 1)) - (areaHeight / 2)), serverWorld.getMinBuildHeight(), serverWorld.getMinBuildHeight() + (serverWorld.getLogicalHeight() - 1)); + z = entity.getZ() + (random.nextDouble() - 0.5) * areaWidth; + + if (attemptToTeleport(entity, serverWorld, x, y, z, landingOffset.x(), landingOffset.y(), landingOffset.z(), areaHeight, loadedChunksOnly, heightmap, landingBlockCondition, landingCondition)) { + + data.>ifPresent("success_action", successAction -> successAction.accept(entity)); + entity.resetFallDistance(); + + succeeded = true; + break; + + } + + } + + if (!succeeded) { + data.>ifPresent("fail_action", failAction -> failAction.accept(entity)); + } + + } + + private static boolean attemptToTeleport(Entity entity, ServerLevel serverWorld, double destX, double destY, double destZ, double offsetX, double offsetY, double offsetZ, double areaHeight, boolean loadedChunksOnly, Heightmap.Types heightmap, Predicate landingBlockCondition, Predicate landingCondition) { + + BlockPos.MutableBlockPos blockPos = BlockPos.containing(destX, destY, destZ).mutable(); + boolean foundSurface = false; + + if (heightmap != null) { + + blockPos.set(serverWorld.getHeightmapPos(heightmap, blockPos).below()); + + if (landingBlockCondition.test(new BlockInWorld(serverWorld, blockPos, true))) { + blockPos.set(blockPos.above()); + foundSurface = true; + } + + } else { + + for (double decrements = 0; decrements < areaHeight / 2; ++decrements) { + + blockPos.set(blockPos.below()); + + if (landingBlockCondition.test(new BlockInWorld(serverWorld, blockPos, true))) { + + blockPos.set(blockPos.above()); + foundSurface = true; + + break; + + } + + } + + } + + destX = offsetX == 0 ? destX : Mth.floor(destX) + offsetX; + destY = blockPos.getY() + offsetY; + destZ = offsetZ == 0 ? destZ : Mth.floor(destZ) + offsetZ; + + blockPos.set(destX, destY, destZ); + + if (!foundSurface) { + return false; + } + + double prevX = entity.getX(); + double prevY = entity.getY(); + double prevZ = entity.getZ(); + + ChunkPos chunkPos = new ChunkPos(blockPos); + if (!serverWorld.hasChunk(chunkPos.x, chunkPos.z)) { + + if (loadedChunksOnly) { + return false; + } + + serverWorld.getChunkSource().addRegionTicket(TicketType.POST_TELEPORT, chunkPos, 0, entity.getId()); + serverWorld.getChunk(chunkPos.x, chunkPos.z); + + } + + entity.teleportTo(destX, destY, destZ); + + if (!landingCondition.test(entity)) { + entity.teleportTo(prevX, prevY, prevZ); + return false; + } + + if (entity instanceof PathfinderMob pathAwareEntity) { + pathAwareEntity.getNavigation().stop(); + } + + return true; + + } + + public static @NotNull ActionFactory getFactory() { + return new ActionFactory<>( + OriginsPaper.apoliIdentifier("random_teleport"), + InstanceDefiner.instanceDefiner() + .add("area_width", SerializableDataTypes.DOUBLE, 8.0) + .add("area_height", SerializableDataTypes.DOUBLE, 8.0) + .add("heightmap", SerializableDataTypes.enumValue(Heightmap.Types.class), null) + .add("attempts", SerializableDataTypes.INT, 0) + .add("landing_block_condition", ApoliDataTypes.BLOCK_CONDITION, null) + .add("landing_condition", ApoliDataTypes.ENTITY_CONDITION, null) + .add("landing_offset", SerializableDataTypes.VECTOR, Vec3.ZERO) + .add("loaded_chunks_only", SerializableDataTypes.BOOLEAN, true) + .add("success_action", ApoliDataTypes.ENTITY_ACTION, null) + .add("fail_action", ApoliDataTypes.ENTITY_ACTION, null), + RandomTeleportAction::action + ); + } +} diff --git a/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/RaycastAction.java b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/RaycastAction.java new file mode 100644 index 000000000..b0c6d3df7 --- /dev/null +++ b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/RaycastAction.java @@ -0,0 +1,226 @@ +package me.dueris.originspaper.factory.action.types.entity; + +import io.github.dueris.calio.SerializableDataTypes; +import io.github.dueris.calio.parser.InstanceDefiner; +import io.github.dueris.calio.parser.reader.DeserializedFactoryJson; +import me.dueris.originspaper.OriginsPaper; +import me.dueris.originspaper.factory.action.ActionFactory; +import me.dueris.originspaper.factory.condition.ConditionFactory; +import me.dueris.originspaper.factory.data.ApoliDataTypes; +import me.dueris.originspaper.factory.data.types.Space; +import net.minecraft.commands.CommandSource; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.util.Tuple; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.ai.attributes.Attributes; +import net.minecraft.world.entity.projectile.ProjectileUtil; +import net.minecraft.world.level.ClipContext; +import net.minecraft.world.level.Level; +import net.minecraft.world.phys.*; +import org.apache.commons.lang3.tuple.Triple; +import org.jetbrains.annotations.NotNull; +import org.joml.Vector3f; + +import java.util.function.Consumer; + +public class RaycastAction { + + public static void action(@NotNull DeserializedFactoryJson data, @NotNull Entity entity) { + + Vec3 origin = new Vec3(entity.getX(), entity.getEyeY(), entity.getZ()); + Vec3 direction = entity.getViewVector(1); + if (data.isPresent("direction")) { + direction = data.get("direction"); + Space space = data.get("space"); + Vector3f vector3f = new Vector3f((float) direction.x(), (float) direction.y(), (float) direction.z()).normalize(); + space.toGlobal(vector3f, entity); + direction = new Vec3(vector3f); + } + Vec3 target = origin.add(direction.scale(getBlockReach(data, entity))); + + data.>ifPresent("before_action", action -> action.accept(entity)); + + HitResult hitResult = null; + if (data.getBoolean("entity")) { + double distance = getEntityReach(data, entity); + target = origin.add(direction.scale(distance)); + hitResult = performEntityRaycast(entity, origin, target, data.get("bientity_condition")); + } + if (data.getBoolean("block")) { + double distance = getBlockReach(data, entity); + target = origin.add(direction.scale(distance)); + BlockHitResult blockHit = performBlockRaycast(entity, origin, target, data.get("shape_type"), data.get("fluid_handling")); + if (blockHit.getType() != HitResult.Type.MISS) { + if (hitResult == null || hitResult.getType() == HitResult.Type.MISS) { + hitResult = blockHit; + } else { + if (hitResult.distanceTo(entity) > blockHit.distanceTo(entity)) { + hitResult = blockHit; + } + } + } + } + if (hitResult != null && hitResult.getType() != HitResult.Type.MISS) { + if (data.isPresent("command_at_hit")) { + Vec3 offsetDirection = direction; + double offset = 0; + Vec3 hitPos = hitResult.getLocation(); + if (data.isPresent("command_hit_offset")) { + offset = data.getDouble("command_hit_offset"); + } else { + if (hitResult instanceof BlockHitResult bhr) { + if (bhr.getDirection() == Direction.DOWN) { + offset = entity.getBbHeight(); + } else if (bhr.getDirection() == Direction.UP) { + offset = 0; + } else { + offset = entity.getBbWidth() / 2; + offsetDirection = new Vec3( + bhr.getDirection().getStepX(), + bhr.getDirection().getStepY(), + bhr.getDirection().getStepZ() + ).scale(-1); + } + } + offset += 0.05; + } + Vec3 at = hitPos.subtract(offsetDirection.scale(offset)); + executeCommandAtHit(entity, at, data.getString("command_at_hit")); + } + if (data.isPresent("command_along_ray")) { + executeStepCommands(entity, origin, hitResult.getLocation(), data.getString("command_along_ray"), data.getDouble("command_step")); + } + if (data.isPresent("block_action") && hitResult instanceof BlockHitResult bhr) { + ActionFactory> blockAction = data.get("block_action"); + Triple blockActionContext = Triple.of(entity.level(), bhr.getBlockPos(), bhr.getDirection()); + blockAction.accept(blockActionContext); + } + if (data.isPresent("bientity_action") && hitResult instanceof EntityHitResult ehr) { + ActionFactory> bientityAction = data.get("bientity_action"); + Tuple bientityActionContext = new Tuple<>(entity, ehr.getEntity()); + bientityAction.accept(bientityActionContext); + } + data.>ifPresent("hit_action", action -> action.accept(entity)); + } else { + if (data.isPresent("command_along_ray") && !data.getBoolean("command_along_ray_only_on_hit")) { + executeStepCommands(entity, origin, target, data.getString("command_along_ray"), data.getDouble("command_step")); + } + data.>ifPresent("miss_action", action -> action.accept(entity)); + } + } + + private static double getEntityReach(@NotNull DeserializedFactoryJson data, Entity entity) { + + if (!data.isPresent("entity_distance") && !data.isPresent("distance")) { + return entity instanceof LivingEntity livingEntity && livingEntity.getAttributes().hasAttribute(Attributes.ENTITY_INTERACTION_RANGE) + ? livingEntity.getAttributeValue(Attributes.ENTITY_INTERACTION_RANGE) + : 3; + } else { + return data.isPresent("entity_distance") + ? data.getDouble("entity_distance") + : data.getDouble("distance"); + } + + } + + private static double getBlockReach(@NotNull DeserializedFactoryJson data, Entity entity) { + + if (!data.isPresent("block_distance") && !data.isPresent("distance")) { + return entity instanceof LivingEntity livingEntity && livingEntity.getAttributes().hasAttribute(Attributes.BLOCK_INTERACTION_RANGE) + ? livingEntity.getAttributeValue(Attributes.BLOCK_INTERACTION_RANGE) + : 4.5; + } else { + return data.isPresent("block_distance") + ? data.getDouble("block_distance") + : data.getDouble("distance"); + } + + } + + private static void executeStepCommands(@NotNull Entity entity, Vec3 origin, Vec3 target, String command, double step) { + MinecraftServer server = entity.level().getServer(); + if (server != null) { + Vec3 direction = target.subtract(origin).normalize(); + double length = origin.distanceTo(target); + for (double current = 0; current < length; current += step) { + boolean validOutput = !(entity instanceof ServerPlayer) || ((ServerPlayer) entity).connection != null; + CommandSourceStack source = new CommandSourceStack( + OriginsPaper.showCommandOutput && validOutput ? entity : CommandSource.NULL, + origin.add(direction.scale(current)), + entity.getRotationVector(), + entity.level() instanceof ServerLevel ? (ServerLevel) entity.level() : null, + 4, + entity.getName().getString(), + entity.getDisplayName(), + entity.level().getServer(), + entity); + server.getCommands().performPrefixedCommand(source, command); + } + } + } + + private static void executeCommandAtHit(@NotNull Entity entity, Vec3 hitPosition, String command) { + MinecraftServer server = entity.level().getServer(); + if (server != null) { + boolean validOutput = !(entity instanceof ServerPlayer) || ((ServerPlayer) entity).connection != null; + CommandSourceStack source = new CommandSourceStack( + OriginsPaper.showCommandOutput && validOutput ? entity : CommandSource.NULL, + hitPosition, + entity.getRotationVector(), + entity.level() instanceof ServerLevel ? (ServerLevel) entity.level() : null, + 4, + entity.getName().getString(), + entity.getDisplayName(), + entity.level().getServer(), + entity); + server.getCommands().performPrefixedCommand(source, command); + } + } + + private static @NotNull BlockHitResult performBlockRaycast(Entity source, Vec3 origin, Vec3 target, ClipContext.Block shapeType, ClipContext.Fluid fluidHandling) { + ClipContext context = new ClipContext(origin, target, shapeType, fluidHandling, source); + return source.level().clip(context); + } + + private static EntityHitResult performEntityRaycast(@NotNull Entity source, Vec3 origin, @NotNull Vec3 target, ConditionFactory> biEntityCondition) { + Vec3 ray = target.subtract(origin); + AABB box = source.getBoundingBox().expandTowards(ray).inflate(1.0D, 1.0D, 1.0D); + EntityHitResult entityHitResult = ProjectileUtil.getEntityHitResult(source, origin, target, box, (entityx) -> { + return !entityx.isSpectator() && (biEntityCondition == null || biEntityCondition.test(new Tuple<>(source, entityx))); + }, ray.lengthSqr()); + return entityHitResult; + } + + public static @NotNull ActionFactory getFactory() { + return new ActionFactory<>(OriginsPaper.apoliIdentifier("raycast"), + InstanceDefiner.instanceDefiner() + .add("distance", SerializableDataTypes.DOUBLE, null) + .add("block_distance", SerializableDataTypes.DOUBLE, null) + .add("entity_distance", SerializableDataTypes.DOUBLE, null) + .add("direction", SerializableDataTypes.VECTOR, null) + .add("space", ApoliDataTypes.SPACE, Space.WORLD) + .add("block", SerializableDataTypes.BOOLEAN, true) + .add("entity", SerializableDataTypes.BOOLEAN, true) + .add("shape_type", SerializableDataTypes.enumValue(ClipContext.Block.class), ClipContext.Block.OUTLINE) + .add("fluid_handling", SerializableDataTypes.enumValue(ClipContext.Fluid.class), ClipContext.Fluid.ANY) + .add("block_action", ApoliDataTypes.BLOCK_ACTION, null) + .add("bientity_condition", ApoliDataTypes.BIENTITY_CONDITION, null) + .add("bientity_action", ApoliDataTypes.BIENTITY_ACTION, null) + .add("command_at_hit", SerializableDataTypes.STRING, null) + .add("command_hit_offset", SerializableDataTypes.DOUBLE, null) + .add("command_along_ray", SerializableDataTypes.STRING, null) + .add("command_step", SerializableDataTypes.DOUBLE, 1.0) + .add("command_along_ray_only_on_hit", SerializableDataTypes.BOOLEAN, false) + .add("before_action", ApoliDataTypes.ENTITY_ACTION, null) + .add("hit_action", ApoliDataTypes.ENTITY_ACTION, null) + .add("miss_action", ApoliDataTypes.ENTITY_ACTION, null), + RaycastAction::action + ); + } +} diff --git a/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/RemoveAdvancementAction.java b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/RemoveAdvancementAction.java new file mode 100644 index 000000000..aa1152b1d --- /dev/null +++ b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/RemoveAdvancementAction.java @@ -0,0 +1,28 @@ +package me.dueris.originspaper.factory.action.types.entity; + +import io.github.dueris.calio.SerializableDataTypes; +import io.github.dueris.calio.parser.InstanceDefiner; +import io.github.dueris.calio.parser.reader.DeserializedFactoryJson; +import me.dueris.originspaper.OriginsPaper; +import me.dueris.originspaper.factory.action.ActionFactory; +import net.minecraft.world.entity.Entity; +import org.bukkit.Bukkit; +import org.jetbrains.annotations.NotNull; + +public class RemoveAdvancementAction { + + public static void action(@NotNull DeserializedFactoryJson data, @NotNull Entity entity) { + Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "advancement revoke $1 only $2" + .replace("$1", entity.getName().getString()) + .replace("$2", data.getString("advancement"))); + } + + public static @NotNull ActionFactory getFactory() { + return new ActionFactory<>( + OriginsPaper.apoliIdentifier("revoke_advancement"), + InstanceDefiner.instanceDefiner() + .add("advancement", SerializableDataTypes.IDENTIFIER, null), + RemoveAdvancementAction::action + ); + } +} diff --git a/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/ReplaceInventoryAction.java b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/ReplaceInventoryAction.java new file mode 100644 index 000000000..5cb54ce08 --- /dev/null +++ b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/ReplaceInventoryAction.java @@ -0,0 +1,41 @@ +package me.dueris.originspaper.factory.action.types.entity; + +import io.github.dueris.calio.SerializableDataTypes; +import io.github.dueris.calio.parser.InstanceDefiner; +import io.github.dueris.calio.parser.reader.DeserializedFactoryJson; +import me.dueris.originspaper.OriginsPaper; +import me.dueris.originspaper.factory.action.ActionFactory; +import me.dueris.originspaper.factory.data.ApoliDataTypes; +import me.dueris.originspaper.factory.data.types.InventoryType; +import net.minecraft.world.entity.Entity; +import org.jetbrains.annotations.NotNull; + +import static me.dueris.originspaper.util.Util.replaceInventory; + +public class ReplaceInventoryAction { + + public static void action(@NotNull DeserializedFactoryJson data, Entity entity) { + + InventoryType inventoryType = data.get("inventory_type"); + + switch (inventoryType) { + case INVENTORY -> replaceInventory(data, entity); + } + + } + + public static @NotNull ActionFactory getFactory() { + return new ActionFactory<>(OriginsPaper.apoliIdentifier("replace_inventory"), + InstanceDefiner.instanceDefiner() + .add("inventory_type", ApoliDataTypes.INVENTORY_TYPE, InventoryType.INVENTORY) + .add("entity_action", ApoliDataTypes.ENTITY_ACTION, null) + .add("item_action", ApoliDataTypes.ITEM_ACTION, null) + .add("item_condition", ApoliDataTypes.ITEM_CONDITION, null) + .add("slots", SerializableDataTypes.list(ApoliDataTypes.ITEM_SLOT), null) + .add("slot", ApoliDataTypes.ITEM_SLOT, null) + .add("stack", SerializableDataTypes.ITEM_STACK) + .add("merge_nbt", SerializableDataTypes.BOOLEAN, false), + ReplaceInventoryAction::action + ); + } +} diff --git a/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/RidingAction.java b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/RidingAction.java new file mode 100644 index 000000000..84816ab22 --- /dev/null +++ b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/RidingAction.java @@ -0,0 +1,58 @@ +package me.dueris.originspaper.factory.action.types.entity; + +import io.github.dueris.calio.SerializableDataTypes; +import io.github.dueris.calio.parser.InstanceDefiner; +import me.dueris.originspaper.OriginsPaper; +import me.dueris.originspaper.factory.action.ActionFactory; +import me.dueris.originspaper.factory.data.ApoliDataTypes; +import net.minecraft.util.Tuple; +import net.minecraft.world.entity.Entity; +import org.jetbrains.annotations.NotNull; + +import java.util.function.Consumer; +import java.util.function.Predicate; + +public class RidingAction { + + public static @NotNull ActionFactory getFactory() { + return new ActionFactory<>(OriginsPaper.apoliIdentifier("riding_action"), + InstanceDefiner.instanceDefiner() + .add("action", ApoliDataTypes.ENTITY_ACTION, null) + .add("bientity_action", ApoliDataTypes.BIENTITY_ACTION, null) + .add("bientity_condition", ApoliDataTypes.BIENTITY_CONDITION, null) + .add("recursive", SerializableDataTypes.BOOLEAN, false), + (data, entity) -> { + Consumer entityAction = data.get("action"); + Consumer> bientityAction = data.get("bientity_action"); + Predicate> cond = data.get("bientity_condition"); + if (!entity.isPassenger() || (entityAction == null && bientityAction == null)) { + return; + } + if (data.getBoolean("recursive")) { + Entity vehicle = entity.getVehicle(); + while (vehicle != null) { + if (cond == null || cond.test(new Tuple<>(entity, vehicle))) { + if (entityAction != null) { + entityAction.accept(vehicle); + } + if (bientityAction != null) { + bientityAction.accept(new Tuple<>(entity, vehicle)); + } + } + vehicle = vehicle.getVehicle(); + } + } else { + Entity vehicle = entity.getVehicle(); + if (cond == null || cond.test(new Tuple<>(entity, vehicle))) { + if (entityAction != null) { + entityAction.accept(vehicle); + } + if (bientityAction != null) { + bientityAction.accept(new Tuple<>(entity, vehicle)); + } + } + } + } + ); + } +} diff --git a/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/SelectorAction.java b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/SelectorAction.java new file mode 100644 index 000000000..ffdc938a8 --- /dev/null +++ b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/SelectorAction.java @@ -0,0 +1,64 @@ +package me.dueris.originspaper.factory.action.types.entity; + +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import io.github.dueris.calio.parser.InstanceDefiner; +import io.github.dueris.calio.parser.reader.DeserializedFactoryJson; +import io.github.dueris.calio.util.ArgumentWrapper; +import me.dueris.originspaper.OriginsPaper; +import me.dueris.originspaper.factory.action.ActionFactory; +import me.dueris.originspaper.factory.data.ApoliDataTypes; +import net.minecraft.commands.CommandSource; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.arguments.selector.EntitySelector; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.util.Tuple; +import net.minecraft.world.entity.Entity; +import org.jetbrains.annotations.NotNull; + +import java.util.function.Consumer; +import java.util.function.Predicate; + +public class SelectorAction { + + public static void action(DeserializedFactoryJson data, @NotNull Entity entity) { + + MinecraftServer server = entity.level().getServer(); + if (server == null) return; + + EntitySelector selector = data.>get("selector").get(); + Predicate> biEntityCondition = data.get("bientity_condition"); + Consumer> biEntityAction = data.get("bientity_action"); + + CommandSourceStack source = new CommandSourceStack( + CommandSource.NULL, + entity.position(), + entity.getRotationVector(), + (ServerLevel) entity.level(), + 2, + entity.getScoreboardName(), + entity.getName(), + server, + entity + ); + + try { + selector.findEntities(source) + .stream() + .filter(e -> biEntityCondition == null || biEntityCondition.test(new Tuple<>(entity, e))) + .forEach(e -> biEntityAction.accept(new Tuple<>(entity, e))); + } catch (CommandSyntaxException ignored) {} + + } + + public static @NotNull ActionFactory getFactory() { + return new ActionFactory<>( + OriginsPaper.apoliIdentifier("selector_action"), + InstanceDefiner.instanceDefiner() + .add("selector", ApoliDataTypes.ENTITIES_SELECTOR) + .add("bientity_action", ApoliDataTypes.BIENTITY_ACTION) + .add("bientity_condition", ApoliDataTypes.BIENTITY_CONDITION, null), + SelectorAction::action + ); + } +} diff --git a/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/SetFallDistanceAction.java b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/SetFallDistanceAction.java new file mode 100644 index 000000000..26d8baa6a --- /dev/null +++ b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/SetFallDistanceAction.java @@ -0,0 +1,18 @@ +package me.dueris.originspaper.factory.action.types.entity; + +import io.github.dueris.calio.SerializableDataTypes; +import io.github.dueris.calio.parser.InstanceDefiner; +import me.dueris.originspaper.OriginsPaper; +import me.dueris.originspaper.factory.action.ActionFactory; +import net.minecraft.world.entity.Entity; +import org.jetbrains.annotations.NotNull; + +public class SetFallDistanceAction { + + public static @NotNull ActionFactory getFactory() { + return new ActionFactory<>(OriginsPaper.identifier("set_fall_distance"), + InstanceDefiner.instanceDefiner() + .add("fall_distance", SerializableDataTypes.FLOAT), + (data, entity) -> entity.fallDistance = data.getFloat("fall_distance")); + } +} diff --git a/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/SetOnFireAction.java b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/SetOnFireAction.java new file mode 100644 index 000000000..db9f3d2fe --- /dev/null +++ b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/SetOnFireAction.java @@ -0,0 +1,18 @@ +package me.dueris.originspaper.factory.action.types.entity; + +import io.github.dueris.calio.SerializableDataTypes; +import io.github.dueris.calio.parser.InstanceDefiner; +import me.dueris.originspaper.OriginsPaper; +import me.dueris.originspaper.factory.action.ActionFactory; +import net.minecraft.world.entity.Entity; +import org.jetbrains.annotations.NotNull; + +public class SetOnFireAction { + + public static @NotNull ActionFactory getFactory() { + return new ActionFactory<>(OriginsPaper.apoliIdentifier("set_on_fire"), + InstanceDefiner.instanceDefiner() + .add("duration", SerializableDataTypes.INT), + (data, entity) -> entity.igniteForSeconds(data.getInt("duration"))); + } +} diff --git a/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/SetResourceAction.java b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/SetResourceAction.java new file mode 100644 index 000000000..0e9b90811 --- /dev/null +++ b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/SetResourceAction.java @@ -0,0 +1,27 @@ +package me.dueris.originspaper.factory.action.types.entity; + +import io.github.dueris.calio.SerializableDataTypes; +import io.github.dueris.calio.parser.InstanceDefiner; +import me.dueris.originspaper.OriginsPaper; +import me.dueris.originspaper.factory.action.ActionFactory; +import net.minecraft.world.entity.Entity; +import org.jetbrains.annotations.NotNull; + +public class SetResourceAction { + + public static @NotNull ActionFactory getFactory() { + return new ActionFactory<>(OriginsPaper.apoliIdentifier("set_resource"), + InstanceDefiner.instanceDefiner() + .add("resource", SerializableDataTypes.IDENTIFIER) + .add("value", SerializableDataTypes.INT), + (data, entity) -> { + // TODO +// Optional resourceBar = Resource.getDisplayedBar(entity, data.getString("resource")); +// resourceBar.ifPresent((bar) -> { +// int val = data.getNumber("value").getInt(); +// bar.change(val, "set"); +// }); + } + ); + } +} diff --git a/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/ShowToastAction.java b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/ShowToastAction.java new file mode 100644 index 000000000..5c181499a --- /dev/null +++ b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/ShowToastAction.java @@ -0,0 +1,78 @@ +package me.dueris.originspaper.factory.action.types.entity; + +import io.github.dueris.calio.SerializableDataTypes; +import io.github.dueris.calio.parser.InstanceDefiner; +import io.github.dueris.calio.parser.reader.DeserializedFactoryJson; +import me.dueris.originspaper.OriginsPaper; +import me.dueris.originspaper.factory.action.ActionFactory; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.item.ItemStack; +import org.bukkit.Bukkit; +import org.bukkit.advancement.Advancement; +import org.bukkit.craftbukkit.entity.CraftPlayer; +import org.bukkit.craftbukkit.util.CraftNamespacedKey; +import org.bukkit.scheduler.BukkitRunnable; +import org.jetbrains.annotations.NotNull; + +public class ShowToastAction { + + public static void action(DeserializedFactoryJson data, @NotNull Entity entity) { + + if (!entity.level().isClientSide) { + String title = data.getString("title"); + String description = data.getString("description"); + ItemStack icon = data.get("icon"); + + if (entity.getBukkitEntity() instanceof CraftPlayer player) { + String advancement = "{\n" + + " \"criteria\": {\n" + + " \"trigger\": {\n" + + " \"trigger\": \"minecraft:impossible\"\n" + + " }\n" + + " },\n" + + " \"display\": {\n" + + " \"icon\": {\n" + + " \"id\": \"" + icon.getBukkitStack().getType().getKey().asString() + "\"\n" + + " },\n" + + " \"title\": {\n" + + " \"text\": \"" + title + "\"\n" + + " },\n" + + " \"description\": {\n" + + " \"text\": \"" + description + "\"\n" + + " },\n" + + " \"background\": \"minecraft:textures/gui/advancements/backgrounds/adventure.png\",\n" + + " \"frame\": \"task\",\n" + + " \"announce_to_chat\": false,\n" + + " \"show_toast\": true,\n" + + " \"hidden\": true\n" + + " }\n" + + " }"; + Advancement possible = Bukkit.getAdvancement(CraftNamespacedKey.fromMinecraft(OriginsPaper.apoliIdentifier(title.replace(" ", "_").toLowerCase()))); + Advancement a = possible == null ? + Bukkit.getUnsafe().loadAdvancement(possible.getKey(), advancement) : possible; + // Advancement is loaded now + player.getAdvancementProgress(a).awardCriteria("trigger"); + new BukkitRunnable() { + @Override + public void run() { + player.getAdvancementProgress(a).revokeCriteria("trigger"); + } + }.runTaskLater(OriginsPaper.getPlugin(), 5); + } + } + + } + + public static @NotNull ActionFactory getFactory() { + return new ActionFactory<>( + OriginsPaper.apoliIdentifier("show_toast"), + InstanceDefiner.instanceDefiner() + .add("title", SerializableDataTypes.TEXT) + .add("description", SerializableDataTypes.TEXT) + .add("texture", SerializableDataTypes.IDENTIFIER, OriginsPaper.apoliIdentifier("toast/custom")) + .add("icon", SerializableDataTypes.ITEM_STACK, ItemStack.EMPTY) + .add("duration", SerializableDataTypes.POSITIVE_INT, 5000), + ShowToastAction::action + ); + } +} diff --git a/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/SpawnEffectCloudAction.java b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/SpawnEffectCloudAction.java new file mode 100644 index 000000000..6deef6d80 --- /dev/null +++ b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/SpawnEffectCloudAction.java @@ -0,0 +1,47 @@ +package me.dueris.originspaper.factory.action.types.entity; + +import io.github.dueris.calio.SerializableDataTypes; +import io.github.dueris.calio.parser.InstanceDefiner; +import io.github.dueris.calio.parser.reader.DeserializedFactoryJson; +import me.dueris.originspaper.OriginsPaper; +import me.dueris.originspaper.factory.action.ActionFactory; +import net.minecraft.world.entity.AreaEffectCloud; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.item.alchemy.PotionContents; +import org.jetbrains.annotations.NotNull; + +public class SpawnEffectCloudAction { + + public static void action(DeserializedFactoryJson data, @NotNull Entity entity) { + + AreaEffectCloud aec = new AreaEffectCloud(entity.level(), entity.getX(), entity.getY(), entity.getZ()); + if (entity instanceof LivingEntity livingEntity) { + aec.setOwner(livingEntity); + } + + aec.setRadius(data.getFloat("radius")); + aec.setRadiusOnUse(data.getFloat("radius_on_use")); + aec.setDuration(data.getInt("duration")); + aec.setDurationOnUse(data.getInt("duration_on_use")); + aec.setWaitTime(data.getInt("wait_time")); + aec.setPotionContents(data.get("effect_component")); + + entity.level().addFreshEntity(aec); + + } + + public static @NotNull ActionFactory getFactory() { + return new ActionFactory<>( + OriginsPaper.apoliIdentifier("spawn_effect_cloud"), + InstanceDefiner.instanceDefiner() + .add("radius", SerializableDataTypes.FLOAT, 3.0F) + .add("radius_on_use", SerializableDataTypes.FLOAT, -0.5F) + .add("duration", SerializableDataTypes.INT, 600) + .add("duration_on_use", SerializableDataTypes.INT, 0) + .add("wait_time", SerializableDataTypes.INT, 10) + .add("effect_component", SerializableDataTypes.POTION_CONTENTS_COMPONENT, PotionContents.EMPTY), + SpawnEffectCloudAction::action + ); + } +} diff --git a/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/SpawnEntityAction.java b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/SpawnEntityAction.java new file mode 100644 index 000000000..7e43bc3da --- /dev/null +++ b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/SpawnEntityAction.java @@ -0,0 +1,59 @@ +package me.dueris.originspaper.factory.action.types.entity; + +import io.github.dueris.calio.SerializableDataTypes; +import io.github.dueris.calio.parser.InstanceDefiner; +import io.github.dueris.calio.parser.reader.DeserializedFactoryJson; +import me.dueris.originspaper.OriginsPaper; +import me.dueris.originspaper.factory.action.ActionFactory; +import me.dueris.originspaper.factory.data.ApoliDataTypes; +import me.dueris.originspaper.util.Util; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.util.Tuple; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityType; +import org.jetbrains.annotations.NotNull; + +import java.util.Optional; +import java.util.function.Consumer; + +public class SpawnEntityAction { + + public static void action(DeserializedFactoryJson data, @NotNull Entity entity) { + + if (entity.level().isClientSide) return; + + ServerLevel serverWorld = (ServerLevel) entity.level(); + EntityType entityType = data.get("entity_type"); + CompoundTag entityNbt = data.get("tag"); + + Optional opt$entityToSpawn = Util.getEntityWithPassengers( + serverWorld, + entityType, + entityNbt, + entity.position(), + entity.getYRot(), + entity.getXRot() + ); + + if (opt$entityToSpawn.isEmpty()) return; + Entity entityToSpawn = opt$entityToSpawn.get(); + + serverWorld.tryAddFreshEntityWithPassengers(entityToSpawn); + data.>ifPresent("entity_action", entityAction -> entityAction.accept(entityToSpawn)); + data.>>ifPresent("bientity_action", biEntityAction -> biEntityAction.accept(new Tuple<>(entity, entityToSpawn))); + + } + + public static @NotNull ActionFactory getFactory() { + return new ActionFactory<>( + OriginsPaper.apoliIdentifier("spawn_entity"), + InstanceDefiner.instanceDefiner() + .add("entity_type", SerializableDataTypes.ENTITY_TYPE) + .add("tag", SerializableDataTypes.NBT, null) + .add("entity_action", ApoliDataTypes.ENTITY_ACTION, null) + .add("bientity_action", ApoliDataTypes.BIENTITY_ACTION, null), + SpawnEntityAction::action + ); + } +} diff --git a/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/SpawnParticlesAction.java b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/SpawnParticlesAction.java new file mode 100644 index 000000000..e7221862f --- /dev/null +++ b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/SpawnParticlesAction.java @@ -0,0 +1,64 @@ +package me.dueris.originspaper.factory.action.types.entity; + +import io.github.dueris.calio.SerializableDataTypes; +import io.github.dueris.calio.parser.InstanceDefiner; +import io.github.dueris.calio.parser.reader.DeserializedFactoryJson; +import me.dueris.originspaper.OriginsPaper; +import me.dueris.originspaper.factory.action.ActionFactory; +import me.dueris.originspaper.factory.data.ApoliDataTypes; +import net.minecraft.core.particles.ParticleOptions; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.util.Tuple; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.phys.Vec3; +import org.jetbrains.annotations.NotNull; + +import java.util.function.Predicate; + +public class SpawnParticlesAction { + + public static void action(DeserializedFactoryJson data, @NotNull Entity entity) { + + if (!(entity.level() instanceof ServerLevel serverWorld)) { + return; + } + + Vec3 delta = data + .get("spread") + .multiply(entity.getBbWidth(), entity.getEyeHeight(entity.getPose()), entity.getBbWidth()); + Vec3 pos = entity + .position() + .add(data.getDouble("offset_x"), data.getDouble("offset_y"), data.getDouble("offset_z")); + + Predicate> biEntityCondition = data.get("bientity_condition"); + ParticleOptions particleEffect = data.get("particle"); + + boolean force = data.getBoolean("force"); + float speed = data.getFloat("speed"); + int count = Math.max(0, data.getInt("count")); + + for (ServerPlayer player : serverWorld.players()) { + if (biEntityCondition == null || biEntityCondition.test(new Tuple<>(entity, player))) { + serverWorld.sendParticles(player, particleEffect, force, pos.x(), pos.y(), pos.z(), count, delta.x(), delta.y(), delta.z(), speed); + } + } + + } + + public static @NotNull ActionFactory getFactory() { + return new ActionFactory<>(OriginsPaper.apoliIdentifier("spawn_particles"), + InstanceDefiner.instanceDefiner() + .add("particle", SerializableDataTypes.PARTICLE_EFFECT_OR_TYPE) + .add("bientity_condition", ApoliDataTypes.BIENTITY_CONDITION, null) + .add("count", SerializableDataTypes.INT, 1) + .add("speed", SerializableDataTypes.FLOAT, 0.0F) + .add("force", SerializableDataTypes.BOOLEAN, false) + .add("spread", SerializableDataTypes.VECTOR, new Vec3(0.5, 0.5, 0.5)) + .add("offset_x", SerializableDataTypes.DOUBLE, 0.0D) + .add("offset_y", SerializableDataTypes.DOUBLE, 0.5D) + .add("offset_z", SerializableDataTypes.DOUBLE, 0.0D), + SpawnParticlesAction::action + ); + } +} diff --git a/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/SwingHandAction.java b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/SwingHandAction.java new file mode 100644 index 000000000..9be71fc2c --- /dev/null +++ b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/SwingHandAction.java @@ -0,0 +1,28 @@ +package me.dueris.originspaper.factory.action.types.entity; + +import io.github.dueris.calio.SerializableDataTypes; +import io.github.dueris.calio.parser.InstanceDefiner; +import io.github.dueris.calio.parser.reader.DeserializedFactoryJson; +import me.dueris.originspaper.OriginsPaper; +import me.dueris.originspaper.factory.action.ActionFactory; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.LivingEntity; +import org.jetbrains.annotations.NotNull; + +public class SwingHandAction { + + public static void action(DeserializedFactoryJson data, Entity entity) { + if (entity instanceof LivingEntity living) { + living.swing(data.get("hand"), true); + } + } + + public static @NotNull ActionFactory getFactory() { + return new ActionFactory<>(OriginsPaper.apoliIdentifier("swing_hand"), + InstanceDefiner.instanceDefiner() + .add("hand", SerializableDataTypes.HAND, InteractionHand.MAIN_HAND), + SwingHandAction::action + ); + } +} diff --git a/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/ToggleAction.java b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/ToggleAction.java new file mode 100644 index 000000000..54dd16a47 --- /dev/null +++ b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/ToggleAction.java @@ -0,0 +1,23 @@ +package me.dueris.originspaper.factory.action.types.entity; + +import io.github.dueris.calio.SerializableDataTypes; +import io.github.dueris.calio.parser.InstanceDefiner; +import me.dueris.originspaper.OriginsPaper; +import me.dueris.originspaper.factory.action.ActionFactory; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.LivingEntity; +import org.jetbrains.annotations.NotNull; + +public class ToggleAction { + + public static @NotNull ActionFactory getFactory() { + return new ActionFactory<>(OriginsPaper.apoliIdentifier("toggle"), + InstanceDefiner.instanceDefiner() + .add("power", SerializableDataTypes.IDENTIFIER), + (data, entity) -> { + if (entity instanceof LivingEntity) { + } + } + ); + } +} diff --git a/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/TriggerCooldownAction.java b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/TriggerCooldownAction.java new file mode 100644 index 000000000..6fea61884 --- /dev/null +++ b/origins/src/main/java/me/dueris/originspaper/factory/action/types/entity/TriggerCooldownAction.java @@ -0,0 +1,37 @@ +package me.dueris.originspaper.factory.action.types.entity; + +import io.github.dueris.calio.SerializableDataTypes; +import io.github.dueris.calio.parser.InstanceDefiner; +import me.dueris.originspaper.OriginsPaper; +import me.dueris.originspaper.factory.action.ActionFactory; +import me.dueris.originspaper.registry.registries.PowerType; +import me.dueris.originspaper.util.entity.PowerHolderComponent; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.player.Player; +import org.jetbrains.annotations.NotNull; + +import java.util.Arrays; + +public class TriggerCooldownAction { + + public static @NotNull ActionFactory getFactory() { + return new ActionFactory<>(OriginsPaper.identifier("trigger_cooldown"), + InstanceDefiner.instanceDefiner() + .add("power", SerializableDataTypes.IDENTIFIER), + (data, entity) -> { + if (entity instanceof Player player) { + Arrays.stream(new String[]{"apoli:action_on_hit", "apoli:action_when_damage_taken", "apoli:action_when_hit", + "apoli:action_self", "apoli:attacker_action_when_hit", "apoli:self_action_on_hit", + "apoli:self_action_on_kill", "apoli:self_action_when_hit", "apoli:target_action_on_hit", "apoli:cooldown"}).forEach(type -> { + for (PowerType powerContainer : PowerHolderComponent.getPowers((org.bukkit.entity.Player) player.getBukkitEntity(), type)) { + // TODO +// if (powerContainer instanceof CooldownPower cooldownPower) { +// Cooldown.addCooldown(player, cooldownPower.getCooldown(), cooldownPower); +// } + } + }); + } + } + ); + } +} diff --git a/origins/src/main/java/me/dueris/originspaper/factory/powers/provider/origins/SlimelingSizeChangers.java b/origins/src/main/java/me/dueris/originspaper/factory/powers/provider/origins/SlimelingSizeChangers.java index 61de8981b..ba05c235c 100644 --- a/origins/src/main/java/me/dueris/originspaper/factory/powers/provider/origins/SlimelingSizeChangers.java +++ b/origins/src/main/java/me/dueris/originspaper/factory/powers/provider/origins/SlimelingSizeChangers.java @@ -69,7 +69,7 @@ public void powerGrant(@NotNull PowerUpdateEvent e) { @Override public void run() { try { - PowerUtils.removePower(Bukkit.getConsoleSender(), e.getPower(), p, CraftApoli.getLayerFromTag("origins:origin"), false); + PowerUtils.removePower(Bukkit.getConsoleSender(), e.getPower(), p, CraftApoli.getLayer("origins:origin"), false); } catch (InstantiationException | IllegalAccessException ex) { throw new RuntimeException(ex); } @@ -108,7 +108,7 @@ public void powerGrant(@NotNull PowerUpdateEvent e) { @Override public void run() { try { - PowerUtils.removePower(Bukkit.getConsoleSender(), e.getPower(), p, CraftApoli.getLayerFromTag("origins:origin"), false); + PowerUtils.removePower(Bukkit.getConsoleSender(), e.getPower(), p, CraftApoli.getLayer("origins:origin"), false); } catch (InstantiationException | IllegalAccessException ex) { throw new RuntimeException(ex); } diff --git a/origins/src/main/java/me/dueris/originspaper/util/entity/PlayerManager.java b/origins/src/main/java/me/dueris/originspaper/util/entity/PlayerManager.java index be9bec28a..5ccfab585 100644 --- a/origins/src/main/java/me/dueris/originspaper/util/entity/PlayerManager.java +++ b/origins/src/main/java/me/dueris/originspaper/util/entity/PlayerManager.java @@ -132,9 +132,9 @@ public void run() { } }).runTaskLater(OriginsPaper.getPlugin(), OriginConfiguration.getConfiguration().getInt("choosing_delay")); if (!p.getPersistentDataContainer().has(identifier("updated")) - && !PowerHolderComponent.getOrigin(p, CraftApoli.getLayerFromTag("origins:origin")).equals(CraftApoli.emptyOrigin())) { + && !PowerHolderComponent.getOrigin(p, CraftApoli.getLayer("origins:origin")).equals(CraftApoli.emptyOrigin())) { PowerHolderComponent.setOrigin( - p, CraftApoli.getLayerFromTag("origins:origin"), PowerHolderComponent.getOrigin(p, CraftApoli.getLayerFromTag("origins:origin")) + p, CraftApoli.getLayer("origins:origin"), PowerHolderComponent.getOrigin(p, CraftApoli.getLayer("origins:origin")) ); p.getPersistentDataContainer().set(identifier("updated"), PersistentDataType.BOOLEAN, true); } diff --git a/origins/src/main/java/me/dueris/originspaper/util/entity/PowerHolderComponent.java b/origins/src/main/java/me/dueris/originspaper/util/entity/PowerHolderComponent.java index 19168fd5c..2e8603258 100644 --- a/origins/src/main/java/me/dueris/originspaper/util/entity/PowerHolderComponent.java +++ b/origins/src/main/java/me/dueris/originspaper/util/entity/PowerHolderComponent.java @@ -90,7 +90,7 @@ public static void setupPowers(Player p) { for (String layer : layers) { String[] layerData = layer.split("\\|"); - OriginLayer layerContainer = CraftApoli.getLayerFromTag(layerData[0]); + OriginLayer layerContainer = CraftApoli.getLayer(layerData[0]); ConcurrentLinkedQueue powers = new ConcurrentLinkedQueue<>(); for (String dataPiece : layerData) {