From 75dfb850924278d13c3bcbcd6f6e6f1a0e9c4e5e Mon Sep 17 00:00:00 2001 From: Sollace Date: Mon, 27 Dec 2021 23:14:46 +0200 Subject: [PATCH] Finish the light spell --- .../magic/spell/effect/LightSpell.java | 40 +++++++++++-------- .../unicopia/client/render/RenderLayers.java | 2 +- .../unicopia/entity/EntityReference.java | 4 ++ .../unicopia/entity/FairyEntity.java | 28 ++++++++++++- 4 files changed, 55 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/LightSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/LightSpell.java index 5ee80336..6bbdd725 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/LightSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/LightSpell.java @@ -24,36 +24,42 @@ public class LightSpell extends AbstractSpell { .with(Trait.ORDER, 25) .build(); + private int age; private int duration; - private List> lights; + private final List> lights = new ArrayList<>(); protected LightSpell(SpellType type, SpellTraits traits) { super(type, traits); - duration = (int)(traits.get(Trait.FOCUS, 0, 160) * 19); + duration = 120 + (int)(traits.get(Trait.FOCUS, 0, 160) * 19); } @Override public boolean tick(Caster caster, Situation situation) { - if (duration-- <= 0) { + age++; + + if (age % 20 == 0) { + duration--; + } + + if (duration <= 0) { return false; } - if (lights == null) { - int size = 2 + caster.getWorld().random.nextInt(2) + (int)(getTraits().get(Trait.LIFE, 10, 20) - 10)/10; - lights = new ArrayList<>(size); - for (int i = 0; i < size; i++) { - lights.set(i, new EntityReference()); - } - } - if (!caster.isClient()) { + if (lights.isEmpty()) { + int size = 2 + caster.getWorld().random.nextInt(2) + (int)(getTraits().get(Trait.LIFE, 10, 20) - 10)/10; + while (lights.size() < size) { + lights.add(new EntityReference()); + } + } + lights.forEach(ref -> { if (!ref.isPresent(caster.getWorld())) { FairyEntity entity = UEntities.TWITTERMITE.create(caster.getWorld()); entity.setPosition(ref.getPosition().orElseGet(() -> { - return caster.getMaster().getPos().add(VecHelper.supply(() -> caster.getWorld().random.nextInt(2) - 1)); + return caster.getMaster().getPos().add(VecHelper.supply(() -> caster.getWorld().random.nextInt(3) - 1)); })); entity.setMaster(caster.getMaster()); entity.world.spawnEntity(entity); @@ -70,7 +76,9 @@ public class LightSpell extends AbstractSpell { @Override public void toNBT(NbtCompound compound) { super.toNBT(compound); - if (lights != null) { + compound.putInt("age", age); + compound.putInt("duration", duration); + if (!lights.isEmpty()) { NbtList list = new NbtList(); lights.forEach(light -> { list.add(light.toNBT()); @@ -82,15 +90,15 @@ public class LightSpell extends AbstractSpell { @Override public void fromNBT(NbtCompound compound) { super.fromNBT(compound); + age = compound.getInt("age"); + duration = compound.getInt("duration"); + lights.clear(); if (compound.contains("lights", NbtElement.LIST_TYPE)) { - lights = new ArrayList<>(); compound.getList("lights", NbtElement.COMPOUND_TYPE).forEach(nbt -> { EntityReference light = new EntityReference<>(); light.fromNBT((NbtCompound)nbt); lights.add(light); }); - } else { - lights = null; } } } diff --git a/src/main/java/com/minelittlepony/unicopia/client/render/RenderLayers.java b/src/main/java/com/minelittlepony/unicopia/client/render/RenderLayers.java index f5968948..93a80670 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/render/RenderLayers.java +++ b/src/main/java/com/minelittlepony/unicopia/client/render/RenderLayers.java @@ -26,7 +26,7 @@ public final class RenderLayers extends RenderLayer { .shader(COLOR_SHADER) .transparency(TRANSLUCENT_TRANSPARENCY) .target(TRANSLUCENT_TARGET) - .texturing(solid(120, 120, 0, 0.6F)) + .texturing(solid(0.8F, 0.9F, 1, 0.6F)) .build(false)); public static RenderLayer getMagicGlow() { diff --git a/src/main/java/com/minelittlepony/unicopia/entity/EntityReference.java b/src/main/java/com/minelittlepony/unicopia/entity/EntityReference.java index 3c6c367b..0648ac06 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/EntityReference.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/EntityReference.java @@ -27,6 +27,10 @@ public class EntityReference implements NbtSerialisable { uuid = entity.getUuid(); clientId = entity.getId(); pos = Optional.of(entity.getPos()); + } else { + uuid = null; + clientId = 0; + pos = Optional.empty(); } } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/FairyEntity.java b/src/main/java/com/minelittlepony/unicopia/entity/FairyEntity.java index 49391568..cbbd81af 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/FairyEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/FairyEntity.java @@ -119,6 +119,11 @@ public class FairyEntity extends PathAwareEntity implements LightEmittingEntity, return false; } + @Override + public boolean isPushedByFluids() { + return false; + } + public boolean isStaying() { return stayingPos.isPresent(); } @@ -172,14 +177,33 @@ public class FairyEntity extends PathAwareEntity implements LightEmittingEntity, @Override protected ActionResult interactMob(PlayerEntity player, Hand hand) { - if (hand == Hand.MAIN_HAND && isStaying() && player == getMaster()) { - stayingPos = Optional.empty(); + if (hand == Hand.MAIN_HAND) { + + if (isStaying()) { + stayingPos = Optional.empty(); + if (player != getMaster()) { + assignment.set(player); + } + } else { + assignment.set(null); + setStaying(getBlockPos()); + } + + playSound(SoundEvents.ENTITY_BAT_AMBIENT, getSoundVolume() / 3, getSoundPitch() * 3); + return ActionResult.SUCCESS; } return ActionResult.PASS; } + @Override + public boolean handleAttack(Entity attacker) { + attacker.damage(DamageSource.LIGHTNING_BOLT, (float)getAttackDistanceScalingFactor(attacker) * 3); + + return false; + } + @Override public void onRemoved() { super.onRemoved();