Updates to biomes

This commit is contained in:
Daniel Mills
2020-11-17 22:25:06 -05:00
parent 6e47e4bcd2
commit 8dee20295e
5 changed files with 191 additions and 0 deletions

View File

@@ -10,6 +10,7 @@ import com.volmit.iris.scaffold.parallax.ParallaxAccess;
import com.volmit.iris.scaffold.parallel.MultiBurst;
import com.volmit.iris.util.*;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Biome;
@@ -342,6 +343,8 @@ public interface Engine extends DataProvider, Fallible, GeneratorAccess, LootPro
return getHeight() + getMinHeight();
}
public EngineEffects getEffects();
public EngineCompound getCompound();
public default boolean isStudio()
@@ -353,4 +356,19 @@ public interface Engine extends DataProvider, Fallible, GeneratorAccess, LootPro
{
MultiBurst.burst.lazy(() -> getParallax().cleanup());
}
default IrisBiome getBiome(Location l)
{
return getBiome(l.getBlockX(), l.getBlockY(), l.getBlockZ());
}
default IrisRegion getRegion(Location l)
{
return getRegion(l.getBlockX(), l.getBlockZ());
}
default boolean contains(Location l)
{
return l.getBlockY() >= getMinHeight() && l.getBlockY() <= getMaxHeight();
}
}

View File

@@ -0,0 +1,7 @@
package com.volmit.iris.scaffold.engine;
public interface EngineEffects extends EngineComponent {
public void updatePlayerMap();
public void tickRandomPlayer();
}

View File

@@ -0,0 +1,72 @@
package com.volmit.iris.scaffold.engine;
import com.volmit.iris.object.IrisBiome;
import com.volmit.iris.object.IrisEffect;
import com.volmit.iris.object.IrisRegion;
import com.volmit.iris.util.J;
import com.volmit.iris.util.M;
import lombok.Data;
import org.bukkit.Location;
import org.bukkit.entity.Player;
@Data
public class EnginePlayer {
private final Engine engine;
private final Player player;
private IrisBiome biome;
private IrisRegion region;
private Location lastLocation;
private long lastSample;
public EnginePlayer(Engine engine, Player player)
{
this.engine = engine;
this.player = player;
lastLocation = player.getLocation().clone();
lastSample = -1;
sample();
}
public void tick()
{
sample();
J.s(() -> {
if(region != null)
{
for(IrisEffect j : region.getEffects())
{
j.apply(player, getEngine());
}
}
if(biome != null)
{
for(IrisEffect j : biome.getEffects())
{
j.apply(player, getEngine());
}
}
});
}
public long ticksSinceLastSample()
{
return M.ms() - lastSample;
}
public void sample() {
if(ticksSinceLastSample() > 55 && player.getLocation().distanceSquared(lastLocation) > 9 * 9)
{
lastLocation = player.getLocation().clone();
lastSample = M.ms();
sampleBiomeRegion();
}
}
private void sampleBiomeRegion() {
Location l = player.getLocation();
biome = engine.getBiome(l);
region = engine.getRegion(l);
}
}