Skip to content

Commit

Permalink
Added duration and duration_on_use fields to spawn_effect_cloud
Browse files Browse the repository at this point in the history
… entity action type (#225)

* Add `duration` and `duration_on_use` fields to `spawn_effect_cloud`.

* Optimized imports in `EntityActions`

---------

Co-authored-by: eggohito <66972816+eggohito@users.noreply.github.com>
  • Loading branch information
MerchantPug and eggohito authored Jun 28, 2024
1 parent a040e49 commit f217048
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@
import io.github.apace100.calio.data.SerializableData;
import io.github.apace100.calio.data.SerializableDataTypes;
import io.github.apace100.calio.util.IdentifierAlias;
import net.minecraft.entity.AreaEffectCloudEntity;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.potion.PotionUtil;
import net.minecraft.registry.Registry;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.command.CommandOutput;
Expand All @@ -32,7 +30,6 @@
import org.apache.logging.log4j.util.TriConsumer;
import org.joml.Vector3f;

import java.util.LinkedList;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Predicate;
Expand Down Expand Up @@ -130,33 +127,6 @@ public static void register() {
.add("block_action", ApoliDataTypes.BLOCK_ACTION),
(data, entity) -> ((ActionFactory<Triple<World, BlockPos, Direction>>.Instance)data.get("block_action")).accept(
Triple.of(entity.getWorld(), entity.getBlockPos(), Direction.UP))));
register(new ActionFactory<>(Apoli.identifier("spawn_effect_cloud"), new SerializableData()
.add("radius", SerializableDataTypes.FLOAT, 3.0F)
.add("radius_on_use", SerializableDataTypes.FLOAT, -0.5F)
.add("wait_time", SerializableDataTypes.INT, 10)
.add("effect", SerializableDataTypes.STATUS_EFFECT_INSTANCE, null)
.add("effects", SerializableDataTypes.STATUS_EFFECT_INSTANCES, null),
(data, entity) -> {
AreaEffectCloudEntity areaEffectCloudEntity = new AreaEffectCloudEntity(entity.getWorld(), entity.getX(), entity.getY(), entity.getZ());
if (entity instanceof LivingEntity) {
areaEffectCloudEntity.setOwner((LivingEntity)entity);
}
areaEffectCloudEntity.setRadius(data.getFloat("radius"));
areaEffectCloudEntity.setRadiusOnUse(data.getFloat("radius_on_use"));
areaEffectCloudEntity.setWaitTime(data.getInt("wait_time"));
areaEffectCloudEntity.setRadiusGrowth(-areaEffectCloudEntity.getRadius() / (float)areaEffectCloudEntity.getDuration());
List<StatusEffectInstance> effects = new LinkedList<>();
if(data.isPresent("effect")) {
effects.add(data.get("effect"));
}
if(data.isPresent("effects")) {
effects.addAll(data.get("effects"));
}
areaEffectCloudEntity.setColor(PotionUtil.getColor(effects));
effects.forEach(areaEffectCloudEntity::addEffect);

entity.getWorld().spawnEntity(areaEffectCloudEntity);
}));
register(new ActionFactory<>(Apoli.identifier("extinguish"), new SerializableData(),
(data, entity) -> entity.extinguish()));
register(new ActionFactory<>(Apoli.identifier("execute_command"), new SerializableData()
Expand Down Expand Up @@ -376,6 +346,7 @@ public static void register() {
register(ActionOnEntitySetAction.getFactory());
register(RandomTeleportAction.getFactory());
register(ShowToastAction.getFactory());
register(SpawnEffectCloudAction.getFactory());
}

private static void register(ActionFactory<Entity> actionFactory) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package io.github.apace100.apoli.power.factory.action.entity;

import io.github.apace100.apoli.Apoli;
import io.github.apace100.apoli.power.factory.action.ActionFactory;
import io.github.apace100.calio.data.SerializableData;
import io.github.apace100.calio.data.SerializableDataTypes;
import net.minecraft.entity.AreaEffectCloudEntity;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.potion.PotionUtil;

import java.util.LinkedList;
import java.util.List;

public class SpawnEffectCloudAction {

public static void action(SerializableData.Instance data, Entity entity) {
AreaEffectCloudEntity areaEffectCloudEntity = new AreaEffectCloudEntity(entity.getWorld(), entity.getX(), entity.getY(), entity.getZ());
if (entity instanceof LivingEntity) {
areaEffectCloudEntity.setOwner((LivingEntity) entity);
}
areaEffectCloudEntity.setDuration(data.getInt("duration"));
areaEffectCloudEntity.setDurationOnUse(data.getInt("duration_on_use"));
areaEffectCloudEntity.setRadius(data.getFloat("radius"));
areaEffectCloudEntity.setRadiusOnUse(data.getFloat("radius_on_use"));
areaEffectCloudEntity.setWaitTime(data.getInt("wait_time"));
areaEffectCloudEntity.setRadiusGrowth(-areaEffectCloudEntity.getRadius() / (float) areaEffectCloudEntity.getDuration());
List<StatusEffectInstance> effects = new LinkedList<>();
if (data.isPresent("effect")) {
effects.add(data.get("effect"));
}
if (data.isPresent("effects")) {
effects.addAll(data.get("effects"));
}
areaEffectCloudEntity.setColor(PotionUtil.getColor(effects));
effects.forEach(areaEffectCloudEntity::addEffect);

entity.getWorld().spawnEntity(areaEffectCloudEntity);
}

public static ActionFactory<Entity> getFactory() {
return new ActionFactory<>(Apoli.identifier("spawn_effect_cloud"), new SerializableData()
.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", SerializableDataTypes.STATUS_EFFECT_INSTANCE, null)
.add("effects", SerializableDataTypes.STATUS_EFFECT_INSTANCES, null),
SpawnEffectCloudAction::action);
}

}

0 comments on commit f217048

Please sign in to comment.