9
0
mirror of https://github.com/VolmitSoftware/Iris.git synced 2025-12-28 11:39:07 +00:00
This commit is contained in:
RePixelatedMC
2024-08-22 16:07:02 +02:00
parent 6cfa593eee
commit 805523d069
7 changed files with 141 additions and 41 deletions

View File

@@ -43,6 +43,7 @@ public class IrisSettings {
private IrisSettingsStudio studio = new IrisSettingsStudio();
private IrisSettingsPerformance performance = new IrisSettingsPerformance();
private IrisWorldDump worldDump = new IrisWorldDump();
private IrisWorldSettings irisWorldSettings = new IrisWorldSettings();
public static int getThreadCount(int c) {
return switch (c) {
@@ -199,4 +200,12 @@ public class IrisSettings {
public static class IrisWorldDump {
public int mcaCacheSize = 3;
}
// todo: Goal:Have these as the default world settings and when put in bukkit.yml it will again overwrite that world from these.
@Data
public static class IrisWorldSettings {
public boolean dynamicEntityAdjustments;
}
}

View File

@@ -19,6 +19,7 @@
package com.volmit.iris.core.commands;
import com.volmit.iris.Iris;
import com.volmit.iris.core.IrisSettings;
import com.volmit.iris.core.loader.IrisData;
import com.volmit.iris.core.tools.IrisPackBenchmarking;
import com.volmit.iris.core.tools.IrisToolbelt;
@@ -130,15 +131,9 @@ public class CommandDeveloper implements DecreeExecutor {
}
@Decree(description = "test")
public void devtest() {
public void test() {
try {
for (File mcafile : new File("rrtrender1/region").listFiles()) {
MCAFile mca = MCAUtil.read(mcafile);
int c = 0;
}
} catch (Exception e) {
e.printStackTrace();
}

View File

@@ -115,6 +115,11 @@ public interface INMSBinding {
Vector3d getBoundingbox(org.bukkit.entity.EntityType entity);
default String getMobCategory(EntityType entityType) {
// todo: Update to other versions!
return null;
}
Entity spawnEntity(Location location, EntityType type, CreatureSpawnEvent.SpawnReason reason);
Color getBiomeColor(Location location, BiomeColor type);

View File

@@ -1,29 +1,50 @@
package com.volmit.iris.engine.service;
import com.google.common.util.concurrent.AtomicDouble;
import com.volmit.iris.Iris;
import com.volmit.iris.core.nms.INMS;
import com.volmit.iris.engine.framework.Engine;
import com.volmit.iris.engine.object.IrisEngineService;
import com.volmit.iris.util.format.Form;
import com.volmit.iris.util.math.M;
import com.volmit.iris.util.mobs.IrisMobDataHandler;
import com.volmit.iris.util.mobs.IrisMobPiece;
import com.volmit.iris.util.scheduling.Looper;
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
import io.lumine.mythic.bukkit.adapters.BukkitEntity;
import it.unimi.dsi.fastutil.Hash;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.EntityType;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerChangedWorldEvent;
import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.CountDownLatch;
import java.util.function.Supplier;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
public class EngineMobHandlerSVC extends IrisEngineService implements IrisMobDataHandler {
private int id;
public double energy;
private Supplier<IrisMobPiece> supplier;
private HashMap<Types, Integer> bukkitLimits;
private Function<EntityType, Types> entityType;
private ConcurrentLinkedQueue<IrisMobPiece> pieces;
public enum Types {
monsters,
animals,
water_animals,
water_ambient,
water_underground_creature,
axolotls,
ambient
}
public EngineMobHandlerSVC(Engine engine) {
super(engine);
@@ -34,7 +55,9 @@ public class EngineMobHandlerSVC extends IrisEngineService implements IrisMobDat
this.id = engine.getCacheID();
this.pieces = new ConcurrentLinkedQueue<>();
this.supplier = null;
this.entityType = (entityType) -> Types.valueOf(INMS.get().getMobCategory(entityType));
this.bukkitLimits = new HashMap<>();
//new Ticker();
}
@@ -42,23 +65,12 @@ public class EngineMobHandlerSVC extends IrisEngineService implements IrisMobDat
@Override
public void onDisable(boolean hotload) {
}
public Ticker tick() {
return new EngineMobHandlerSVC.Ticker(() -> {
return null;
});
}
private class Ticker extends Looper {
private final CountDownLatch exit = new CountDownLatch(1);
private Ticker(Supplier<IrisMobPiece> supplier) {
private Ticker() {
setPriority(Thread.NORM_PRIORITY);
start();
Iris.debug("Started Mob Engine for: " + engine.getName());
@@ -76,10 +88,15 @@ public class EngineMobHandlerSVC extends IrisEngineService implements IrisMobDat
stopwatch.begin();
fixEnergy();
Predicate<IrisMobPiece> shouldExecutePredicate = IrisMobPiece::shouldTick;
Consumer<IrisMobPiece> executeMethod = IrisMobPiece::tick;
pieces.stream()
.filter(shouldExecutePredicate)
.forEach(executeMethod);
stopwatch.end();
Iris.info("Took: " + Form.f(stopwatch.getMilliseconds()));
double millis = stopwatch.getMilliseconds();
int size = pieces.size();
wait = size == 0 ? 50L : (long) Math.max(50d / size - millis, 0);
@@ -108,21 +125,52 @@ public class EngineMobHandlerSVC extends IrisEngineService implements IrisMobDat
}
if (event.getFrom().equals(world)) {
// pieces.removeIf(piece -> {
// if (piece.getOwner().equals(player.getUniqueId())) {
// piece.close();
// return true;
// }
// return false;
// });
pieces.removeIf(piece -> {
if (piece.getOwner().equals(player.getUniqueId())) {
piece.close();
return true;
}
return false;
});
}
}
private HashMap<Types, Integer> getBukkitLimits() {
HashMap<Types, Integer> temp = new HashMap<>();
FileConfiguration fc = new YamlConfiguration();
try {
fc.load(new File("bukkit.yml"));
ConfigurationSection section = fc.getConfigurationSection("spawn-limits");
if (section == null) {
throw new NoSuchFieldException("spawn-limits not found!");
}
for (String s : section.getKeys(false)) {
try {
ConfigurationSection entry = section.getConfigurationSection(s);
} catch (Exception e) {
e.printStackTrace();
}
}
} catch (Exception e) {
Iris.reportError(e);
}
return null;
}
private void fixEnergy() {
energy = M.clip(energy, 1D, engine.getDimension().getEnergy().evaluate(null, engine.getData(), energy));
}
@Override
public Function<EntityType, Types> getMobType() {
return entityType;
}
@Override
public Engine getEngine() {
return engine;

View File

@@ -2,9 +2,15 @@ package com.volmit.iris.util.mobs;
import com.google.common.util.concurrent.AtomicDouble;
import com.volmit.iris.engine.framework.Engine;
import com.volmit.iris.engine.service.EngineMobHandlerSVC;
import org.bukkit.entity.EntityType;
import java.util.function.Function;
public interface IrisMobDataHandler {
Function<EntityType, EngineMobHandlerSVC.Types> getMobType();
Engine getEngine();
double getEnergy();

View File

@@ -14,23 +14,39 @@ public class IrisMobPiece {
@Getter
private final Player player;
private IrisMobDataHandler dataHandler;
public long lastRanPlayer;
private long lastRanPlayer;
public IrisMobPiece(Player player, IrisMobDataHandler dh) {
this.player = player;
this.dataHandler = dh;
}
/**
* Predict if it should tick the player or if it should skip it for this round.
* @return true = should tick
*/
public boolean shouldTick() {
return true;
}
/**
* Ticks the current player
*/
public void tick() {
lastRanPlayer = M.ms();
// Use the engine instance as needed, but without a direct reference
// For example: engine.getDimension().getEnergy().evaluate(...)
}
public UUID getOwner() {
return player.getUniqueId();
}
public void close() {
}
}