mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-24 13:57: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)
|
.with(Trait.ORDER, 25)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
private int age;
|
||||||
private int duration;
|
private int duration;
|
||||||
|
|
||||||
private List<EntityReference<FairyEntity>> lights;
|
private final List<EntityReference<FairyEntity>> lights = new ArrayList<>();
|
||||||
|
|
||||||
protected LightSpell(SpellType<?> type, SpellTraits traits) {
|
protected LightSpell(SpellType<?> type, SpellTraits traits) {
|
||||||
super(type, traits);
|
super(type, traits);
|
||||||
duration = (int)(traits.get(Trait.FOCUS, 0, 160) * 19);
|
duration = 120 + (int)(traits.get(Trait.FOCUS, 0, 160) * 19);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean tick(Caster<?> caster, Situation situation) {
|
public boolean tick(Caster<?> caster, Situation situation) {
|
||||||
|
|
||||||
if (duration-- <= 0) {
|
age++;
|
||||||
|
|
||||||
|
if (age % 20 == 0) {
|
||||||
|
duration--;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (duration <= 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lights == null) {
|
if (!caster.isClient()) {
|
||||||
|
if (lights.isEmpty()) {
|
||||||
int size = 2 + caster.getWorld().random.nextInt(2) + (int)(getTraits().get(Trait.LIFE, 10, 20) - 10)/10;
|
int size = 2 + caster.getWorld().random.nextInt(2) + (int)(getTraits().get(Trait.LIFE, 10, 20) - 10)/10;
|
||||||
lights = new ArrayList<>(size);
|
while (lights.size() < size) {
|
||||||
for (int i = 0; i < size; i++) {
|
lights.add(new EntityReference<FairyEntity>());
|
||||||
lights.set(i, new EntityReference<FairyEntity>());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!caster.isClient()) {
|
|
||||||
lights.forEach(ref -> {
|
lights.forEach(ref -> {
|
||||||
if (!ref.isPresent(caster.getWorld())) {
|
if (!ref.isPresent(caster.getWorld())) {
|
||||||
FairyEntity entity = UEntities.TWITTERMITE.create(caster.getWorld());
|
FairyEntity entity = UEntities.TWITTERMITE.create(caster.getWorld());
|
||||||
entity.setPosition(ref.getPosition().orElseGet(() -> {
|
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.setMaster(caster.getMaster());
|
||||||
entity.world.spawnEntity(entity);
|
entity.world.spawnEntity(entity);
|
||||||
|
@ -70,7 +76,9 @@ public class LightSpell extends AbstractSpell {
|
||||||
@Override
|
@Override
|
||||||
public void toNBT(NbtCompound compound) {
|
public void toNBT(NbtCompound compound) {
|
||||||
super.toNBT(compound);
|
super.toNBT(compound);
|
||||||
if (lights != null) {
|
compound.putInt("age", age);
|
||||||
|
compound.putInt("duration", duration);
|
||||||
|
if (!lights.isEmpty()) {
|
||||||
NbtList list = new NbtList();
|
NbtList list = new NbtList();
|
||||||
lights.forEach(light -> {
|
lights.forEach(light -> {
|
||||||
list.add(light.toNBT());
|
list.add(light.toNBT());
|
||||||
|
@ -82,15 +90,15 @@ public class LightSpell extends AbstractSpell {
|
||||||
@Override
|
@Override
|
||||||
public void fromNBT(NbtCompound compound) {
|
public void fromNBT(NbtCompound compound) {
|
||||||
super.fromNBT(compound);
|
super.fromNBT(compound);
|
||||||
|
age = compound.getInt("age");
|
||||||
|
duration = compound.getInt("duration");
|
||||||
|
lights.clear();
|
||||||
if (compound.contains("lights", NbtElement.LIST_TYPE)) {
|
if (compound.contains("lights", NbtElement.LIST_TYPE)) {
|
||||||
lights = new ArrayList<>();
|
|
||||||
compound.getList("lights", NbtElement.COMPOUND_TYPE).forEach(nbt -> {
|
compound.getList("lights", NbtElement.COMPOUND_TYPE).forEach(nbt -> {
|
||||||
EntityReference<FairyEntity> light = new EntityReference<>();
|
EntityReference<FairyEntity> light = new EntityReference<>();
|
||||||
light.fromNBT((NbtCompound)nbt);
|
light.fromNBT((NbtCompound)nbt);
|
||||||
lights.add(light);
|
lights.add(light);
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
lights = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ public final class RenderLayers extends RenderLayer {
|
||||||
.shader(COLOR_SHADER)
|
.shader(COLOR_SHADER)
|
||||||
.transparency(TRANSLUCENT_TRANSPARENCY)
|
.transparency(TRANSLUCENT_TRANSPARENCY)
|
||||||
.target(TRANSLUCENT_TARGET)
|
.target(TRANSLUCENT_TARGET)
|
||||||
.texturing(solid(120, 120, 0, 0.6F))
|
.texturing(solid(0.8F, 0.9F, 1, 0.6F))
|
||||||
.build(false));
|
.build(false));
|
||||||
|
|
||||||
public static RenderLayer getMagicGlow() {
|
public static RenderLayer getMagicGlow() {
|
||||||
|
|
|
@ -27,6 +27,10 @@ public class EntityReference<T extends Entity> implements NbtSerialisable {
|
||||||
uuid = entity.getUuid();
|
uuid = entity.getUuid();
|
||||||
clientId = entity.getId();
|
clientId = entity.getId();
|
||||||
pos = Optional.of(entity.getPos());
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isPushedByFluids() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isStaying() {
|
public boolean isStaying() {
|
||||||
return stayingPos.isPresent();
|
return stayingPos.isPresent();
|
||||||
}
|
}
|
||||||
|
@ -172,14 +177,33 @@ public class FairyEntity extends PathAwareEntity implements LightEmittingEntity,
|
||||||
@Override
|
@Override
|
||||||
protected ActionResult interactMob(PlayerEntity player, Hand hand) {
|
protected ActionResult interactMob(PlayerEntity player, Hand hand) {
|
||||||
|
|
||||||
if (hand == Hand.MAIN_HAND && isStaying() && player == getMaster()) {
|
if (hand == Hand.MAIN_HAND) {
|
||||||
|
|
||||||
|
if (isStaying()) {
|
||||||
stayingPos = Optional.empty();
|
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.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ActionResult.PASS;
|
return ActionResult.PASS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean handleAttack(Entity attacker) {
|
||||||
|
attacker.damage(DamageSource.LIGHTNING_BOLT, (float)getAttackDistanceScalingFactor(attacker) * 3);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRemoved() {
|
public void onRemoved() {
|
||||||
super.onRemoved();
|
super.onRemoved();
|
||||||
|
|
Loading…
Reference in a new issue