mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-06-19 23:31:27 +00:00
- Removed VanillaHeight.
- Removed useless code - okey I really need to sync now
This commit is contained in:
@@ -833,7 +833,7 @@ public class Iris extends VolmitPlugin implements Listener {
|
|||||||
throw new IllegalStateException("Unable to register dimension " + dim.getName());
|
throw new IllegalStateException("Unable to register dimension " + dim.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
return new BukkitChunkGenerator(w, false, ff, dim.getLoadKey(), false);
|
return new BukkitChunkGenerator(w, false, ff, dim.getLoadKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void splash() {
|
public void splash() {
|
||||||
|
|||||||
@@ -72,7 +72,6 @@ public class CommandIris implements DecreeExecutor {
|
|||||||
VolmitSender sender = Iris.getSender();
|
VolmitSender sender = Iris.getSender();
|
||||||
private CommandStudio studio;
|
private CommandStudio studio;
|
||||||
private CommandPregen pregen;
|
private CommandPregen pregen;
|
||||||
private CommandLazyPregen lazyPregen;
|
|
||||||
private CommandSettings settings;
|
private CommandSettings settings;
|
||||||
private CommandObject object;
|
private CommandObject object;
|
||||||
private CommandJigsaw jigsaw;
|
private CommandJigsaw jigsaw;
|
||||||
@@ -133,7 +132,6 @@ public class CommandIris implements DecreeExecutor {
|
|||||||
.seed(seed)
|
.seed(seed)
|
||||||
.sender(sender())
|
.sender(sender())
|
||||||
.studio(false)
|
.studio(false)
|
||||||
.smartVanillaHeight(vanillaheight)
|
|
||||||
.headlessRadius(headlessRadius)
|
.headlessRadius(headlessRadius)
|
||||||
.create();
|
.create();
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
@@ -647,6 +645,6 @@ public class CommandIris implements DecreeExecutor {
|
|||||||
ff.mkdirs();
|
ff.mkdirs();
|
||||||
service(StudioSVC.class).installIntoWorld(sender, dim.getLoadKey(), ff.getParentFile());
|
service(StudioSVC.class).installIntoWorld(sender, dim.getLoadKey(), ff.getParentFile());
|
||||||
}
|
}
|
||||||
return new BukkitChunkGenerator(w, false, ff, dim.getLoadKey(), false);
|
return new BukkitChunkGenerator(w, false, ff, dim.getLoadKey());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ import com.volmit.iris.util.math.M;
|
|||||||
import com.volmit.iris.util.math.Position2;
|
import com.volmit.iris.util.math.Position2;
|
||||||
import com.volmit.iris.util.scheduling.ChronoLatch;
|
import com.volmit.iris.util.scheduling.ChronoLatch;
|
||||||
import com.volmit.iris.util.scheduling.J;
|
import com.volmit.iris.util.scheduling.J;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
@@ -93,6 +95,7 @@ public class PregeneratorJob implements PregenListener {
|
|||||||
J.a(this.pregenerator::start, 20);
|
J.a(this.pregenerator::start, 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static boolean shutdownInstance() {
|
public static boolean shutdownInstance() {
|
||||||
if (instance == null) {
|
if (instance == null) {
|
||||||
return false;
|
return false;
|
||||||
@@ -234,11 +237,6 @@ public class PregeneratorJob implements PregenListener {
|
|||||||
draw(x, z, COLOR_GENERATING);
|
draw(x, z, COLOR_GENERATING);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onServerShutdown() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onChunkGenerated(int x, int z) {
|
public void onChunkGenerated(int x, int z) {
|
||||||
if (engine != null) {
|
if (engine != null) {
|
||||||
|
|||||||
@@ -15,11 +15,6 @@ public final class EmptyListener implements PregenListener {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onServerShutdown() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onChunkGenerated(int x, int z) {
|
public void onChunkGenerated(int x, int z) {
|
||||||
|
|
||||||
|
|||||||
@@ -40,6 +40,8 @@ import com.volmit.iris.util.scheduling.ChronoLatch;
|
|||||||
import com.volmit.iris.util.scheduling.J;
|
import com.volmit.iris.util.scheduling.J;
|
||||||
import com.volmit.iris.util.scheduling.Looper;
|
import com.volmit.iris.util.scheduling.Looper;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
@@ -351,11 +353,6 @@ public class IrisPregenerator {
|
|||||||
listener.onChunkGenerating(x, z);
|
listener.onChunkGenerating(x, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onServerShutdown() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onChunkGenerated(int x, int z) {
|
public void onChunkGenerated(int x, int z) {
|
||||||
listener.onChunkGenerated(x, z);
|
listener.onChunkGenerated(x, z);
|
||||||
|
|||||||
@@ -23,8 +23,6 @@ public interface PregenListener {
|
|||||||
|
|
||||||
void onChunkGenerating(int x, int z);
|
void onChunkGenerating(int x, int z);
|
||||||
|
|
||||||
void onServerShutdown();
|
|
||||||
|
|
||||||
void onChunkGenerated(int x, int z);
|
void onChunkGenerated(int x, int z);
|
||||||
|
|
||||||
void onRegionGenerated(int x, int z);
|
void onRegionGenerated(int x, int z);
|
||||||
|
|||||||
@@ -82,7 +82,6 @@ public class IrisCreator {
|
|||||||
* Benchmark mode
|
* Benchmark mode
|
||||||
*/
|
*/
|
||||||
private boolean benchmark = false;
|
private boolean benchmark = false;
|
||||||
private boolean smartVanillaHeight = false;
|
|
||||||
/**
|
/**
|
||||||
* Radius of chunks to pregenerate in the headless mode
|
* Radius of chunks to pregenerate in the headless mode
|
||||||
* if set to -1, headless mode is disabled
|
* if set to -1, headless mode is disabled
|
||||||
@@ -144,7 +143,6 @@ public class IrisCreator {
|
|||||||
.name(name)
|
.name(name)
|
||||||
.seed(seed)
|
.seed(seed)
|
||||||
.studio(studio)
|
.studio(studio)
|
||||||
.smartVanillaHeight(smartVanillaHeight)
|
|
||||||
.create();
|
.create();
|
||||||
PlatformChunkGenerator access = (PlatformChunkGenerator) wc.generator();
|
PlatformChunkGenerator access = (PlatformChunkGenerator) wc.generator();
|
||||||
if (access == null) {
|
if (access == null) {
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ public class IrisWorldCreator {
|
|||||||
private String name;
|
private String name;
|
||||||
private boolean studio = false;
|
private boolean studio = false;
|
||||||
private String dimensionName = null;
|
private String dimensionName = null;
|
||||||
private boolean smartVanillaHeight = false;
|
|
||||||
private long seed = 1337;
|
private long seed = 1337;
|
||||||
|
|
||||||
public IrisWorldCreator() {
|
public IrisWorldCreator() {
|
||||||
@@ -66,11 +65,6 @@ public class IrisWorldCreator {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IrisWorldCreator smartVanillaHeight(boolean smartVanillaHeight) {
|
|
||||||
this.smartVanillaHeight = smartVanillaHeight;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public WorldCreator create() {
|
public WorldCreator create() {
|
||||||
IrisDimension dim = IrisData.loadAnyDimension(dimensionName);
|
IrisDimension dim = IrisData.loadAnyDimension(dimensionName);
|
||||||
|
|
||||||
@@ -84,7 +78,7 @@ public class IrisWorldCreator {
|
|||||||
.build();
|
.build();
|
||||||
ChunkGenerator g = new BukkitChunkGenerator(w, studio, studio
|
ChunkGenerator g = new BukkitChunkGenerator(w, studio, studio
|
||||||
? dim.getLoader().getDataFolder() :
|
? dim.getLoader().getDataFolder() :
|
||||||
new File(w.worldFolder(), "iris/pack"), dimensionName, smartVanillaHeight);
|
new File(w.worldFolder(), "iris/pack"), dimensionName);
|
||||||
|
|
||||||
if (!INMS.get().registerDimension(name, dim)) {
|
if (!INMS.get().registerDimension(name, dim)) {
|
||||||
throw new IllegalStateException("Unable to register dimension " + dim.getName());
|
throw new IllegalStateException("Unable to register dimension " + dim.getName());
|
||||||
|
|||||||
@@ -287,7 +287,8 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void fixEnergy() {
|
private void fixEnergy() {
|
||||||
energy = M.clip(energy, 1D, getDimension().getEnergy().evaluate(null, getData(), energy));
|
//energy = M.clip(energy, 1D, getDimension().getEnergy().evaluateMax(null, getData(), energy));
|
||||||
|
energy = 1000; // Temp fix to prevent crash
|
||||||
}
|
}
|
||||||
|
|
||||||
private void spawnIn(Chunk c, boolean initial) {
|
private void spawnIn(Chunk c, boolean initial) {
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import org.bukkit.*;
|
|||||||
import org.bukkit.entity.EnderSignal;
|
import org.bukkit.entity.EnderSignal;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.block.Action;
|
import org.bukkit.event.block.Action;
|
||||||
import org.bukkit.event.block.BlockBreakEvent;
|
import org.bukkit.event.block.BlockBreakEvent;
|
||||||
|
|||||||
@@ -47,18 +47,31 @@ public class IrisEnergy {
|
|||||||
@MaxNumber(10000)
|
@MaxNumber(10000)
|
||||||
// @Desc("This is the maximum energy you can have in a dimension")
|
// @Desc("This is the maximum energy you can have in a dimension")
|
||||||
// private double maximumEnergy = 1000;
|
// private double maximumEnergy = 1000;
|
||||||
@Desc("The expression. For your energy scaling, Inherited variables are me ( maximum energy ), ce ( current energy ). Avoid using those variable names. ")
|
@Desc("The expression. For your energy scaling, Inherited variables are ce ( current energy ). Avoid using those variable names. ")
|
||||||
private String expression = null;
|
private String expressionMax = null;
|
||||||
|
@Desc("The expression. For your energy scaling, Inherited variables are ce ( current energy ). Avoid using those variable names. ")
|
||||||
|
private String expressionCur = null;
|
||||||
@ArrayType(type = IrisEnergyExpressionLoad.class, min = 1)
|
@ArrayType(type = IrisEnergyExpressionLoad.class, min = 1)
|
||||||
@Desc("Variables to use in this expression")
|
@Desc("Variables to use in this expression")
|
||||||
private KList<IrisEnergyExpressionLoad> variables = new KList<>();
|
private KList<IrisEnergyExpressionLoad> variables = new KList<>();
|
||||||
|
|
||||||
private static final Parser parser = new Parser();
|
private static final Parser parser = new Parser();
|
||||||
private transient AtomicCache<Expression> expressionCache = new AtomicCache<>();
|
private transient AtomicCache<Expression> expressionMaxCache = new AtomicCache<>();
|
||||||
|
private transient AtomicCache<Expression> expressionCurCache = new AtomicCache<>();
|
||||||
|
|
||||||
private Expression expression() {
|
private Expression getExpression(String type) {
|
||||||
return expressionCache.aquire(() -> {
|
switch (type) {
|
||||||
Scope scope = new Scope(); // Create variable scope. This scope can hold both constants and invocation variables.
|
case "max":
|
||||||
|
return expressionMaxCache.aquire(() -> parseExpression(expressionMax, "1000"));
|
||||||
|
case "cur":
|
||||||
|
return expressionCurCache.aquire(() -> parseExpression(expressionCur, "1000"));
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException("Unknown expression type: " + type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Expression parseExpression(String expression, String defaultValue) {
|
||||||
|
Scope scope = new Scope();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
for (IrisEnergyExpressionLoad i : variables) {
|
for (IrisEnergyExpressionLoad i : variables) {
|
||||||
@@ -73,19 +86,20 @@ public class IrisEnergy {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (expression != null) {
|
if (expression != null) {
|
||||||
return parser.parse(getExpression(), scope);
|
return parser.parse(expression, scope);
|
||||||
}
|
}
|
||||||
return parser.parse("1000", scope);
|
return parser.parse(defaultValue, scope);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
Iris.error("Script load error in Energy Expression");
|
Iris.error("Script load error in Energy Expression");
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public double evaluate(RNG rng, IrisData data, Double ce) {
|
public double evaluateMax(String type, RNG rng, IrisData data, Double ce) {
|
||||||
|
Expression expression = getExpression(type);
|
||||||
|
|
||||||
double[] g = new double[3 + getVariables().size()];
|
double[] g = new double[3 + getVariables().size()];
|
||||||
int m = 0;
|
int m = 0;
|
||||||
for (IrisEnergyExpressionLoad i : getVariables()) {
|
for (IrisEnergyExpressionLoad i : getVariables()) {
|
||||||
@@ -95,7 +109,7 @@ public class IrisEnergy {
|
|||||||
g[m++] = ce;
|
g[m++] = ce;
|
||||||
g[m] = -1;
|
g[m] = -1;
|
||||||
|
|
||||||
return expression().evaluate(g);
|
return expression.evaluate(g);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,7 +88,6 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun
|
|||||||
private final boolean studio;
|
private final boolean studio;
|
||||||
private final AtomicInteger a = new AtomicInteger(0);
|
private final AtomicInteger a = new AtomicInteger(0);
|
||||||
private final CompletableFuture<Integer> spawnChunks = new CompletableFuture<>();
|
private final CompletableFuture<Integer> spawnChunks = new CompletableFuture<>();
|
||||||
private final boolean smartVanillaHeight;
|
|
||||||
private Engine engine;
|
private Engine engine;
|
||||||
private Looper hotloader;
|
private Looper hotloader;
|
||||||
private StudioMode lastMode;
|
private StudioMode lastMode;
|
||||||
@@ -98,7 +97,7 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun
|
|||||||
|
|
||||||
private boolean initialized = false;
|
private boolean initialized = false;
|
||||||
|
|
||||||
public BukkitChunkGenerator(IrisWorld world, boolean studio, File dataLocation, String dimensionKey, boolean smartVanillaHeight) {
|
public BukkitChunkGenerator(IrisWorld world, boolean studio, File dataLocation, String dimensionKey) {
|
||||||
setup = new AtomicBoolean(false);
|
setup = new AtomicBoolean(false);
|
||||||
studioGenerator = null;
|
studioGenerator = null;
|
||||||
dummyBiomeProvider = new DummyBiomeProvider();
|
dummyBiomeProvider = new DummyBiomeProvider();
|
||||||
@@ -110,7 +109,6 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun
|
|||||||
this.dataLocation = dataLocation;
|
this.dataLocation = dataLocation;
|
||||||
this.dimensionKey = dimensionKey;
|
this.dimensionKey = dimensionKey;
|
||||||
this.folder = new ReactiveFolder(dataLocation, (_a, _b, _c) -> hotload());
|
this.folder = new ReactiveFolder(dataLocation, (_a, _b, _c) -> hotload());
|
||||||
this.smartVanillaHeight = smartVanillaHeight;
|
|
||||||
Bukkit.getServer().getPluginManager().registerEvents(this, Iris.instance);
|
Bukkit.getServer().getPluginManager().registerEvents(this, Iris.instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,14 +186,6 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun
|
|||||||
throw new RuntimeException("Missing Dimension: " + dimensionKey);
|
throw new RuntimeException("Missing Dimension: " + dimensionKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (smartVanillaHeight) {
|
|
||||||
dimension.setSmartVanillaHeight(true);
|
|
||||||
try (FileWriter writer = new FileWriter(data.getDimensionLoader().fileFor(dimension))) {
|
|
||||||
writer.write(data.getGson().toJson(dimension));
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
lastMode = StudioMode.NORMAL;
|
lastMode = StudioMode.NORMAL;
|
||||||
engine = new IrisEngine(new EngineTarget(world, dimension, data), studio);
|
engine = new IrisEngine(new EngineTarget(world, dimension, data), studio);
|
||||||
|
|||||||
@@ -4,12 +4,13 @@ import com.volmit.iris.Iris;
|
|||||||
import com.volmit.iris.core.nms.INMS;
|
import com.volmit.iris.core.nms.INMS;
|
||||||
import com.volmit.iris.engine.framework.Engine;
|
import com.volmit.iris.engine.framework.Engine;
|
||||||
import com.volmit.iris.engine.object.IrisEngineService;
|
import com.volmit.iris.engine.object.IrisEngineService;
|
||||||
|
import com.volmit.iris.util.data.KCache;
|
||||||
import com.volmit.iris.util.format.Form;
|
import com.volmit.iris.util.format.Form;
|
||||||
|
import com.volmit.iris.util.mobs.HistoryManager;
|
||||||
import com.volmit.iris.util.mobs.IrisMobDataHandler;
|
import com.volmit.iris.util.mobs.IrisMobDataHandler;
|
||||||
import com.volmit.iris.util.mobs.IrisMobPiece;
|
import com.volmit.iris.util.mobs.IrisMobPiece;
|
||||||
import com.volmit.iris.util.scheduling.Looper;
|
import com.volmit.iris.util.scheduling.Looper;
|
||||||
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
|
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
|
||||||
import io.lumine.mythic.bukkit.utils.lib.jooq.impl.QOM;
|
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
@@ -18,6 +19,7 @@ import org.bukkit.event.EventHandler;
|
|||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
||||||
|
|
||||||
|
import javax.xml.crypto.Data;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
@@ -29,9 +31,12 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
public class EngineMobHandlerSVC extends IrisEngineService implements IrisMobDataHandler {
|
public class EngineMobHandlerSVC extends IrisEngineService implements IrisMobDataHandler {
|
||||||
|
|
||||||
|
private HistoryManager<DataType, Integer, Long> history;
|
||||||
|
|
||||||
private int id;
|
private int id;
|
||||||
public double energyMax;
|
public int energyMax;
|
||||||
public double energy;
|
public int energy;
|
||||||
|
private long irritation = 0;
|
||||||
private HashSet<Chunk> loadedChunks;
|
private HashSet<Chunk> loadedChunks;
|
||||||
private HashMap<Types, Integer> bukkitLimits;
|
private HashMap<Types, Integer> bukkitLimits;
|
||||||
private Function<EntityType, Types> entityType;
|
private Function<EntityType, Types> entityType;
|
||||||
@@ -45,6 +50,7 @@ public class EngineMobHandlerSVC extends IrisEngineService implements IrisMobDat
|
|||||||
public void onEnable(boolean hotload) {
|
public void onEnable(boolean hotload) {
|
||||||
|
|
||||||
this.id = engine.getCacheID();
|
this.id = engine.getCacheID();
|
||||||
|
this.history = new HistoryManager<>(Long.MAX_VALUE);
|
||||||
this.pieces = new ConcurrentLinkedQueue<>();
|
this.pieces = new ConcurrentLinkedQueue<>();
|
||||||
this.entityType = (entityType) -> Types.valueOf(INMS.get().getMobCategory(entityType));
|
this.entityType = (entityType) -> Types.valueOf(INMS.get().getMobCategory(entityType));
|
||||||
this.loadedChunks = new HashSet<>();
|
this.loadedChunks = new HashSet<>();
|
||||||
@@ -71,6 +77,7 @@ public class EngineMobHandlerSVC extends IrisEngineService implements IrisMobDat
|
|||||||
protected long loop() {
|
protected long loop() {
|
||||||
long wait = -1;
|
long wait = -1;
|
||||||
try {
|
try {
|
||||||
|
irritation++;
|
||||||
if (engine.isClosed() || engine.getCacheID() != id) {
|
if (engine.isClosed() || engine.getCacheID() != id) {
|
||||||
interrupt();
|
interrupt();
|
||||||
}
|
}
|
||||||
@@ -81,7 +88,7 @@ public class EngineMobHandlerSVC extends IrisEngineService implements IrisMobDat
|
|||||||
loadedChunks = Arrays.stream(getEngine().getWorld().realWorld().getLoadedChunks())
|
loadedChunks = Arrays.stream(getEngine().getWorld().realWorld().getLoadedChunks())
|
||||||
.collect(Collectors.toCollection(HashSet::new));
|
.collect(Collectors.toCollection(HashSet::new));
|
||||||
|
|
||||||
fixEnergy();
|
updateMaxEnergy();
|
||||||
|
|
||||||
Predicate<IrisMobPiece> shouldTick = IrisMobPiece::shouldTick;
|
Predicate<IrisMobPiece> shouldTick = IrisMobPiece::shouldTick;
|
||||||
Function<IrisMobPiece, List<Integer>> tickCosts = piece -> piece.getTickCosts(1);
|
Function<IrisMobPiece, List<Integer>> tickCosts = piece -> piece.getTickCosts(1);
|
||||||
@@ -92,12 +99,14 @@ public class EngineMobHandlerSVC extends IrisEngineService implements IrisMobDat
|
|||||||
tickCosts
|
tickCosts
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
||||||
Consumer<IrisMobPiece> tick = piece -> piece.tick(42);
|
Consumer<IrisMobPiece> tick = piece -> piece.tick(42);
|
||||||
|
|
||||||
pieces.stream()
|
pieces.stream()
|
||||||
.filter(shouldTick)
|
.filter(shouldTick)
|
||||||
.forEach(tick);
|
.forEach(tick);
|
||||||
|
|
||||||
|
|
||||||
stopwatch.end();
|
stopwatch.end();
|
||||||
Iris.info("Took: " + Form.f(stopwatch.getMilliseconds()));
|
Iris.info("Took: " + Form.f(stopwatch.getMilliseconds()));
|
||||||
double millis = stopwatch.getMilliseconds();
|
double millis = stopwatch.getMilliseconds();
|
||||||
@@ -111,7 +120,11 @@ public class EngineMobHandlerSVC extends IrisEngineService implements IrisMobDat
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assignEnergyToPieces(LinkedHashMap<IrisMobPiece, List<Integer>> map) {
|
/**
|
||||||
|
* @param map Data to do calculations with
|
||||||
|
* @return returns the energy distribution for each piece
|
||||||
|
*/
|
||||||
|
private LinkedHashMap<IrisMobPiece, Integer> assignEnergyToPieces(LinkedHashMap<IrisMobPiece, List<Integer>> map) {
|
||||||
Supplier<LinkedHashMap<IrisMobPiece, List<Integer>>> sortedMapSupplier = new Supplier<>() {
|
Supplier<LinkedHashMap<IrisMobPiece, List<Integer>>> sortedMapSupplier = new Supplier<>() {
|
||||||
private LinkedHashMap<IrisMobPiece, List<Integer>> cachedMap;
|
private LinkedHashMap<IrisMobPiece, List<Integer>> cachedMap;
|
||||||
|
|
||||||
@@ -134,13 +147,21 @@ public class EngineMobHandlerSVC extends IrisEngineService implements IrisMobDat
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Function<Integer,Integer> viewHistory = (history) -> map.values().stream()
|
// Might need caching?
|
||||||
|
Function<Integer, Integer> viewHistory = (history) ->
|
||||||
|
map.values().stream()
|
||||||
.mapToInt(list -> list.isEmpty() ? 0 : list.get(history))
|
.mapToInt(list -> list.isEmpty() ? 0 : list.get(history))
|
||||||
.sum();
|
.sum();
|
||||||
|
|
||||||
|
|
||||||
|
int i = calculateNewEnergy();
|
||||||
|
|
||||||
|
|
||||||
|
return null;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.NORMAL)
|
@EventHandler(priority = EventPriority.NORMAL)
|
||||||
public void on(PlayerChangedWorldEvent event) {
|
public void on(PlayerChangedWorldEvent event) {
|
||||||
if (!engine.getWorld().tryGetRealWorld()) {
|
if (!engine.getWorld().tryGetRealWorld()) {
|
||||||
@@ -177,8 +198,19 @@ public class EngineMobHandlerSVC extends IrisEngineService implements IrisMobDat
|
|||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fixEnergy() {
|
private void updateMaxEnergy() {
|
||||||
energyMax = engine.getDimension().getEnergy().evaluate(null, engine.getData(), energy);
|
var e = (int) engine.getDimension().getEnergy().evaluateMax("max", null, engine.getData(), (double) energy);
|
||||||
|
history.addEntry(DataType.ENERGY_MAX, e, irritation);
|
||||||
|
energyMax = e;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int calculateNewEnergy() {
|
||||||
|
return (int) engine.getDimension().getEnergy().evaluateMax("cur",null, engine.getData(), (double) energy);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getIrritation() {
|
||||||
|
return irritation;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -203,7 +235,7 @@ public class EngineMobHandlerSVC extends IrisEngineService implements IrisMobDat
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getEnergy() {
|
public double getEnergy() {
|
||||||
fixEnergy();
|
updateMaxEnergy();
|
||||||
return energy;
|
return energy;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package com.volmit.iris.util.mobs;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.Deque;
|
||||||
|
import java.util.concurrent.ConcurrentLinkedDeque;
|
||||||
|
|
||||||
|
public class HistoryManager<K, V, I> {
|
||||||
|
private final Deque<HistoryEntry<K, V, I>> history = new ConcurrentLinkedDeque<>();
|
||||||
|
private final long maxSize;
|
||||||
|
|
||||||
|
public HistoryManager(long maxSize) {
|
||||||
|
this.maxSize = maxSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addEntry(K key, V value, I irritation) {
|
||||||
|
history.addFirst(new HistoryEntry<>(key, value, irritation));
|
||||||
|
if (history.size() > maxSize) {
|
||||||
|
history.removeLast();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public HistoryEntry<K, V, I> getEntry(int index) {
|
||||||
|
return history.stream().skip(index).findFirst().orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public I get3rd() {
|
||||||
|
return history.stream()
|
||||||
|
.skip(2)
|
||||||
|
.findFirst()
|
||||||
|
.map(HistoryEntry::getExtra)
|
||||||
|
.orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class HistoryEntry<K, V, I> {
|
||||||
|
private final K key;
|
||||||
|
private final V value;
|
||||||
|
private final I extra;
|
||||||
|
|
||||||
|
public HistoryEntry(K key, V value, I extra) {
|
||||||
|
this.key = key;
|
||||||
|
this.value = value;
|
||||||
|
this.extra = extra;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -24,6 +24,14 @@ public interface IrisMobDataHandler {
|
|||||||
ambient
|
ambient
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum DataType {
|
||||||
|
ENERGY_MAX,
|
||||||
|
ENERGY_CONSUMPTION
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
long getIrritation();
|
||||||
|
|
||||||
Function<EntityType, Types> getMobType();
|
Function<EntityType, Types> getMobType();
|
||||||
|
|
||||||
Engine getEngine();
|
Engine getEngine();
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ public class IrisMobPiece {
|
|||||||
/**
|
/**
|
||||||
* Returns the estimated Energy cost to run this tick.
|
* Returns the estimated Energy cost to run this tick.
|
||||||
* Handy for if you are on a resource limit and need to prioritize who gets ticked and who not and what to expect.
|
* Handy for if you are on a resource limit and need to prioritize who gets ticked and who not and what to expect.
|
||||||
* @param predict > The Prediction size on how far it should predict
|
* @param predict > The Prediction size on how far it should predict, return 0 if shouldTick return false on the Irritation.
|
||||||
* @return The Predictions it made.
|
* @return The Predictions it made.
|
||||||
*/
|
*/
|
||||||
public List<Integer> getTickCosts(int predict) {
|
public List<Integer> getTickCosts(int predict) {
|
||||||
|
|||||||
Reference in New Issue
Block a user