Fire duration for living entities

This commit is contained in:
jglrxavpok 2020-05-05 17:59:57 +02:00
parent 365c3edbdf
commit ca3295cc16
3 changed files with 31 additions and 0 deletions

View File

@ -5,6 +5,7 @@ import net.minestom.server.entity.EntityCreature;
import net.minestom.server.entity.Player;
import net.minestom.server.instance.Instance;
import net.minestom.server.utils.MathUtils;
import net.minestom.server.utils.time.TimeUnit;
public class SimpleCommand implements CommandProcessor {
@Override
@ -20,6 +21,7 @@ public class SimpleCommand implements CommandProcessor {
@Override
public boolean process(Player player, String command, String[] args) {
player.sendMessage("Everyone come at you!");
player.setFireForDuration(1000, TimeUnit.MILLISECOND);
Instance instance = player.getInstance();
@ -29,6 +31,7 @@ public class SimpleCommand implements CommandProcessor {
creature.setPathTo(player.getPosition());
}
/*StorageManager storageManager = MinecraftServer.getStorageManager();
StorageFolder storageFolder = storageManager.getFolder("player_data");

View File

@ -13,6 +13,7 @@ import net.minestom.server.network.packet.server.play.CollectItemPacket;
import net.minestom.server.network.packet.server.play.EntityAnimationPacket;
import net.minestom.server.network.packet.server.play.EntityPropertiesPacket;
import net.minestom.server.utils.Position;
import net.minestom.server.utils.time.TimeUnit;
import java.util.Set;
import java.util.function.Consumer;
@ -32,6 +33,7 @@ public abstract class LivingEntity extends Entity {
private boolean isHandActive;
private boolean offHand;
private boolean riptideSpinAttack;
private long fireExtinguishTime;
public LivingEntity(int entityType, Position spawnPosition) {
super(entityType, spawnPosition);
@ -45,6 +47,12 @@ public abstract class LivingEntity extends Entity {
@Override
public void update() {
if(isOnFire()) {
if(System.currentTimeMillis() > fireExtinguishTime) {
setOnFire(false);
}
}
// Items picking
if (canPickupItem) {
Chunk chunk = instance.getChunkAt(getPosition()); // TODO check surrounding chunks
@ -105,6 +113,25 @@ public abstract class LivingEntity extends Entity {
callEvent(DeathEvent.class, deathEvent);
}
/**
* Sets fire to this entity for a given duration
* @param duration duration in ticks of the effect
*/
public void setFireForDuration(int duration) {
setOnFire(true);
setFireForDuration(duration, TimeUnit.TICK);
}
/**
* Sets fire to this entity for a given duration
* @param duration duration of the effet
* @param unit unit used to express the duration
*/
public void setFireForDuration(int duration, TimeUnit unit) {
setOnFire(true);
fireExtinguishTime = System.currentTimeMillis()+unit.toMilliseconds(duration);
}
/**
* @param type the damage type
* @param value the amount of damage

View File

@ -12,6 +12,7 @@ public class DamageType {
public static final DamageType VOID = new DamageType("attack.outOfWorld");
public static final DamageType GRAVITY = new DamageType("attack.fall");
public static final DamageType ON_FIRE = new DamageType("attack.onFire");
private final String identifier;
public DamageType(String identifier) {