This commit is contained in:
Daniel Mills
2021-07-31 22:32:14 -04:00
parent 9a11021560
commit 6b97acdb50
12 changed files with 204 additions and 97 deletions

View File

@@ -32,9 +32,11 @@ import lombok.experimental.Accessors;
import org.bukkit.Location;
import org.bukkit.Particle;
import org.bukkit.Sound;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.util.Vector;
@Accessors(chain = true)
@NoArgsConstructor
@@ -254,4 +256,40 @@ public class IrisEffect {
true, false, false)));
}
}
public void apply(Entity p) {
if (!canTick()) {
return;
}
if (RNG.r.nextInt(chance) != 0) {
return;
}
if (sound != null) {
Location part = p.getLocation().clone().add(RNG.r.i(-soundDistance, soundDistance), RNG.r.i(-soundDistance, soundDistance), RNG.r.i(-soundDistance, soundDistance));
J.s(() -> p.getWorld().playSound(part, getSound(), (float) volume, (float) RNG.r.d(minPitch, maxPitch)));
}
if (particleEffect != null) {
Location part = p.getLocation().clone().add(0, 0.25, 0).add(new Vector(1,1,1).multiply(RNG.r.d())).subtract(new Vector(1,1,1).multiply(RNG.r.d()));
part.add(RNG.r.d(), 0, RNG.r.d());
if (extra != 0) {
J.s(() -> p.getWorld().spawnParticle(particleEffect, part.getX(), part.getY() + RNG.r.i(particleOffset),
part.getZ(),
particleCount,
randomAltX ? RNG.r.d(-particleAltX, particleAltX) : particleAltX,
randomAltY ? RNG.r.d(-particleAltY, particleAltY) : particleAltY,
randomAltZ ? RNG.r.d(-particleAltZ, particleAltZ) : particleAltZ,
extra));
} else {
J.s(() -> p.getWorld().spawnParticle(particleEffect, part.getX(), part.getY() + RNG.r.i(particleOffset), part.getZ(),
particleCount,
randomAltX ? RNG.r.d(-particleAltX, particleAltX) : particleAltX,
randomAltY ? RNG.r.d(-particleAltY, particleAltY) : particleAltY,
randomAltZ ? RNG.r.d(-particleAltZ, particleAltZ) : particleAltZ));
}
}
}
}

View File

@@ -129,6 +129,9 @@ public class IrisEntity extends IrisRegistrant {
@Desc("If specified, this entity will be leashed by this entity. I.e. THIS ENTITY Leashed by SPECIFIED. This has no effect on EnderDragons, Withers, Players, or Bats.Non-living entities excluding leashes will not persist as leashholders.")
private IrisEntity leashHolder = null;
@Desc("If specified, this entity will spawn with an effect")
private IrisEffect spawnEffect = null;
@Desc("The main gene for a panda if the entity type is a panda")
private Gene pandaMainGene = Gene.NORMAL;
@@ -150,7 +153,6 @@ public class IrisEntity extends IrisRegistrant {
e.setGravity(isGravity());
e.setInvulnerable(isInvulnerable());
e.setSilent(isSilent());
e.setPersistent(true);
int gg = 0;
for (IrisEntity i : passengers) {
@@ -257,6 +259,11 @@ public class IrisEntity extends IrisRegistrant {
m.setAware(isAware());
}
if(spawnEffect != null)
{
spawnEffect.apply(e);
}
return e;
}

View File

@@ -27,6 +27,7 @@ import com.volmit.iris.engine.object.annotations.MinNumber;
import com.volmit.iris.engine.object.annotations.RegistryListEntity;
import com.volmit.iris.engine.object.annotations.Required;
import com.volmit.iris.engine.object.common.IRare;
import com.volmit.iris.util.format.C;
import com.volmit.iris.util.math.RNG;
import com.volmit.iris.util.scheduling.J;
import lombok.AllArgsConstructor;
@@ -60,6 +61,7 @@ public class IrisEntitySpawn implements IRare {
@Desc("The max of this entity to spawn")
private int maxSpawns = 1;
private transient IrisSpawner referenceSpawner;
private final transient AtomicCache<RNG> rng = new AtomicCache<>();
private final transient AtomicCache<IrisEntity> ent = new AtomicCache<>();
@@ -99,8 +101,13 @@ public class IrisEntitySpawn implements IRare {
private Entity spawn100(Engine g, Location at) {
try {
Location l = at.clone().add(0.5, 1, 0.5);
Iris.debug(" Spawned " + "Entity<" + getEntity() + "> at " + l.getBlockX() + "," + l.getBlockY() + "," + l.getBlockZ());
return getRealEntity(g).spawn(g, l, rng.aquire(() -> new RNG(g.getTarget().getWorld().seed() + 4)));
Entity e = getRealEntity(g).spawn(g, l, rng.aquire(() -> new RNG(g.getTarget().getWorld().seed() + 4)));
if(e != null)
{
Iris.debug("Spawned " + C.DARK_AQUA + "Entity<" + getEntity() + "> " + C.GREEN + e.getType() + C.LIGHT_PURPLE + " @ " + C.GRAY + e.getLocation().getX() + ", " + e.getLocation().getY() + ", " + e.getLocation().getZ());
}
return e;
} catch (Throwable e) {
Iris.reportError(e);
Iris.error(" Failed to retrieve real entity @ " + at);

View File

@@ -43,7 +43,7 @@ public class IrisRate {
public long getInterval()
{
long t = per.getMilliseconds() / amount;
long t = per.getMilliseconds() / (amount == 0 ? 1 : amount);
return Math.abs(t <= 0 ? 1 : t);
}

View File

@@ -18,7 +18,9 @@
package com.volmit.iris.engine.object;
import com.volmit.iris.Iris;
import com.volmit.iris.engine.object.annotations.Desc;
import com.volmit.iris.util.math.CDou;
import lombok.Data;
import org.bukkit.World;
@@ -33,24 +35,19 @@ public class IrisTimeBlock {
public boolean isWithin(World world)
{
return isWithin(world.getTime() / 1000D);
return isWithin(((world.getTime() / 1000D)+6)%24);
}
public boolean isWithin(double hour)
{
if(startHour == endHour)
{
if(endHour == -1)
{
return false;
}
return true;
return endHour != -1;
}
if(startHour > endHour)
{
return !(hour >= startHour && hour <= endHour);
return hour >= startHour || hour <= endHour;
}
return hour >= startHour && hour <= endHour;

View File

@@ -41,8 +41,8 @@ public enum IrisWeather {
return switch(this)
{
case NONE -> world.isClearWeather();
case DOWNFALL -> world.hasStorm() && world.isThundering();
case DOWNFALL_WITH_THUNDER -> world.hasStorm();
case DOWNFALL -> world.hasStorm();
case DOWNFALL_WITH_THUNDER -> world.hasStorm() && world.isThundering();
case ANY -> true;
};
}

View File

@@ -18,10 +18,11 @@
package com.volmit.iris.engine.object.engine;
import com.volmit.iris.util.collection.KList;
import lombok.Data;
@Data
public class IrisEngineData
{
private KList<IrisEngineSpawnerCooldown> spawnerCooldowns = new KList<>();
}