generated from FabricMC/fabric-example-mod
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added
duration
and duration_on_use
fields to spawn_effect_cloud
…
… 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
1 parent
a040e49
commit f217048
Showing
2 changed files
with
55 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...ain/java/io/github/apace100/apoli/power/factory/action/entity/SpawnEffectCloudAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |