mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-24 05:47:59 +01:00
Finish the light spell
This commit is contained in:
parent
00758b0c15
commit
75dfb85092
4 changed files with 55 additions and 19 deletions
|
@ -24,36 +24,42 @@ public class LightSpell extends AbstractSpell {
|
|||
.with(Trait.ORDER, 25)
|
||||
.build();
|
||||
|
||||
private int age;
|
||||
private int duration;
|
||||
|
||||
private List<EntityReference<FairyEntity>> lights;
|
||||
private final List<EntityReference<FairyEntity>> 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<FairyEntity>());
|
||||
}
|
||||
}
|
||||
|
||||
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<FairyEntity>());
|
||||
}
|
||||
}
|
||||
|
||||
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<FairyEntity> light = new EntityReference<>();
|
||||
light.fromNBT((NbtCompound)nbt);
|
||||
lights.add(light);
|
||||
});
|
||||
} else {
|
||||
lights = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -27,6 +27,10 @@ public class EntityReference<T extends Entity> implements NbtSerialisable {
|
|||
uuid = entity.getUuid();
|
||||
clientId = entity.getId();
|
||||
pos = Optional.of(entity.getPos());
|
||||
} else {
|
||||
uuid = null;
|
||||
clientId = 0;
|
||||
pos = Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue