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 IrisSettingsStudio studio = new IrisSettingsStudio();
private IrisSettingsPerformance performance = new IrisSettingsPerformance(); private IrisSettingsPerformance performance = new IrisSettingsPerformance();
private IrisWorldDump worldDump = new IrisWorldDump(); private IrisWorldDump worldDump = new IrisWorldDump();
private IrisWorldSettings irisWorldSettings = new IrisWorldSettings();
public static int getThreadCount(int c) { public static int getThreadCount(int c) {
return switch (c) { return switch (c) {
@ -199,4 +200,12 @@ public class IrisSettings {
public static class IrisWorldDump { public static class IrisWorldDump {
public int mcaCacheSize = 3; 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; package com.volmit.iris.core.commands;
import com.volmit.iris.Iris; import com.volmit.iris.Iris;
import com.volmit.iris.core.IrisSettings;
import com.volmit.iris.core.loader.IrisData; import com.volmit.iris.core.loader.IrisData;
import com.volmit.iris.core.tools.IrisPackBenchmarking; import com.volmit.iris.core.tools.IrisPackBenchmarking;
import com.volmit.iris.core.tools.IrisToolbelt; import com.volmit.iris.core.tools.IrisToolbelt;
@ -130,15 +131,9 @@ public class CommandDeveloper implements DecreeExecutor {
} }
@Decree(description = "test") @Decree(description = "test")
public void devtest() { public void test() {
try { try {
for (File mcafile : new File("rrtrender1/region").listFiles()) {
MCAFile mca = MCAUtil.read(mcafile);
int c = 0;
}
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -115,6 +115,11 @@ public interface INMSBinding {
Vector3d getBoundingbox(org.bukkit.entity.EntityType entity); 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); Entity spawnEntity(Location location, EntityType type, CreatureSpawnEvent.SpawnReason reason);
Color getBiomeColor(Location location, BiomeColor type); Color getBiomeColor(Location location, BiomeColor type);

View File

@ -1,29 +1,50 @@
package com.volmit.iris.engine.service; package com.volmit.iris.engine.service;
import com.google.common.util.concurrent.AtomicDouble;
import com.volmit.iris.Iris; import com.volmit.iris.Iris;
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.format.Form;
import com.volmit.iris.util.math.M; import com.volmit.iris.util.math.M;
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.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.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerChangedWorldEvent; 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.ConcurrentLinkedQueue;
import java.util.concurrent.CountDownLatch; 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 { public class EngineMobHandlerSVC extends IrisEngineService implements IrisMobDataHandler {
private int id; private int id;
public double energy; public double energy;
private Supplier<IrisMobPiece> supplier; private HashMap<Types, Integer> bukkitLimits;
private Function<EntityType, Types> entityType;
private ConcurrentLinkedQueue<IrisMobPiece> pieces; private ConcurrentLinkedQueue<IrisMobPiece> pieces;
public enum Types {
monsters,
animals,
water_animals,
water_ambient,
water_underground_creature,
axolotls,
ambient
}
public EngineMobHandlerSVC(Engine engine) { public EngineMobHandlerSVC(Engine engine) {
super(engine); super(engine);
@ -34,7 +55,9 @@ public class EngineMobHandlerSVC extends IrisEngineService implements IrisMobDat
this.id = engine.getCacheID(); this.id = engine.getCacheID();
this.pieces = new ConcurrentLinkedQueue<>(); this.pieces = new ConcurrentLinkedQueue<>();
this.supplier = null; this.entityType = (entityType) -> Types.valueOf(INMS.get().getMobCategory(entityType));
this.bukkitLimits = new HashMap<>();
//new Ticker(); //new Ticker();
} }
@ -42,23 +65,12 @@ public class EngineMobHandlerSVC extends IrisEngineService implements IrisMobDat
@Override @Override
public void onDisable(boolean hotload) { public void onDisable(boolean hotload) {
}
public Ticker tick() {
return new EngineMobHandlerSVC.Ticker(() -> {
return null;
});
} }
private class Ticker extends Looper { private class Ticker extends Looper {
private final CountDownLatch exit = new CountDownLatch(1); private final CountDownLatch exit = new CountDownLatch(1);
private Ticker(Supplier<IrisMobPiece> supplier) { private Ticker() {
setPriority(Thread.NORM_PRIORITY); setPriority(Thread.NORM_PRIORITY);
start(); start();
Iris.debug("Started Mob Engine for: " + engine.getName()); Iris.debug("Started Mob Engine for: " + engine.getName());
@ -76,10 +88,15 @@ public class EngineMobHandlerSVC extends IrisEngineService implements IrisMobDat
stopwatch.begin(); stopwatch.begin();
fixEnergy(); fixEnergy();
Predicate<IrisMobPiece> shouldExecutePredicate = IrisMobPiece::shouldTick;
Consumer<IrisMobPiece> executeMethod = IrisMobPiece::tick;
pieces.stream()
.filter(shouldExecutePredicate)
.forEach(executeMethod);
stopwatch.end(); stopwatch.end();
Iris.info("Took: " + Form.f(stopwatch.getMilliseconds()));
double millis = stopwatch.getMilliseconds(); double millis = stopwatch.getMilliseconds();
int size = pieces.size(); int size = pieces.size();
wait = size == 0 ? 50L : (long) Math.max(50d / size - millis, 0); wait = size == 0 ? 50L : (long) Math.max(50d / size - millis, 0);
@ -108,14 +125,40 @@ public class EngineMobHandlerSVC extends IrisEngineService implements IrisMobDat
} }
if (event.getFrom().equals(world)) { if (event.getFrom().equals(world)) {
// pieces.removeIf(piece -> { pieces.removeIf(piece -> {
// if (piece.getOwner().equals(player.getUniqueId())) { if (piece.getOwner().equals(player.getUniqueId())) {
// piece.close(); piece.close();
// return true; return true;
// }
// return false;
// });
} }
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;
} }
@ -123,6 +166,11 @@ public class EngineMobHandlerSVC extends IrisEngineService implements IrisMobDat
energy = M.clip(energy, 1D, engine.getDimension().getEnergy().evaluate(null, engine.getData(), energy)); energy = M.clip(energy, 1D, engine.getDimension().getEnergy().evaluate(null, engine.getData(), energy));
} }
@Override
public Function<EntityType, Types> getMobType() {
return entityType;
}
@Override @Override
public Engine getEngine() { public Engine getEngine() {
return engine; return engine;

View File

@ -2,9 +2,15 @@ package com.volmit.iris.util.mobs;
import com.google.common.util.concurrent.AtomicDouble; import com.google.common.util.concurrent.AtomicDouble;
import com.volmit.iris.engine.framework.Engine; 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 { public interface IrisMobDataHandler {
Function<EntityType, EngineMobHandlerSVC.Types> getMobType();
Engine getEngine(); Engine getEngine();
double getEnergy(); double getEnergy();

View File

@ -14,23 +14,39 @@ public class IrisMobPiece {
@Getter @Getter
private final Player player; private final Player player;
private IrisMobDataHandler dataHandler; private IrisMobDataHandler dataHandler;
public long lastRanPlayer; private long lastRanPlayer;
public IrisMobPiece(Player player, IrisMobDataHandler dh) { public IrisMobPiece(Player player, IrisMobDataHandler dh) {
this.player = player; this.player = player;
this.dataHandler = dh; 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() { public void tick() {
lastRanPlayer = M.ms(); lastRanPlayer = M.ms();
// Use the engine instance as needed, but without a direct reference
// For example: engine.getDimension().getEnergy().evaluate(...)
} }
public UUID getOwner() { public UUID getOwner() {
return player.getUniqueId(); return player.getUniqueId();
} }
public void close() {
}
} }

View File

@ -59,11 +59,16 @@ import net.bytebuddy.implementation.bytecode.member.MethodInvocation;
import net.bytebuddy.matcher.ElementMatchers; import net.bytebuddy.matcher.ElementMatchers;
import net.minecraft.core.IdMapper; import net.minecraft.core.IdMapper;
import net.minecraft.core.MappedRegistry; import net.minecraft.core.MappedRegistry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.RegistryOps; import net.minecraft.resources.RegistryOps;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.progress.ChunkProgressListener; import net.minecraft.server.level.progress.ChunkProgressListener;
import net.minecraft.util.GsonHelper; import net.minecraft.util.GsonHelper;
import net.minecraft.world.RandomSequences; import net.minecraft.world.RandomSequences;
import net.minecraft.world.entity.MobCategory;
import net.minecraft.world.entity.MobSpawnType;
import net.minecraft.world.entity.MobType;
import net.minecraft.world.entity.ai.behavior.TryLaySpawnOnWaterNearLand;
import net.minecraft.world.level.ChunkPos; import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelHeightAccessor; import net.minecraft.world.level.LevelHeightAccessor;
@ -98,6 +103,8 @@ import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_20_R3.util.CraftNamespacedKey; import org.bukkit.craftbukkit.v1_20_R3.util.CraftNamespacedKey;
import org.bukkit.entity.Dolphin; import org.bukkit.entity.Dolphin;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityCategory;
import org.bukkit.entity.Mob;
import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.generator.BiomeProvider; import org.bukkit.generator.BiomeProvider;
import org.bukkit.generator.ChunkGenerator; import org.bukkit.generator.ChunkGenerator;
@ -230,13 +237,13 @@ public class NMSBinding implements INMSBinding {
} }
@Contract(value = "null, _, _ -> null", pure = true) @Contract(value = "null, _, _ -> null", pure = true)
private Object convertFromTag(net.minecraft.nbt.Tag tag, int depth, int maxDepth) { private Object convertFromTag(Tag tag, int depth, int maxDepth) {
if (tag == null || depth > maxDepth) return null; if (tag == null || depth > maxDepth) return null;
if (tag instanceof CollectionTag<?> collection) { if (tag instanceof CollectionTag<?> collection) {
KList<Object> list = new KList<>(); KList<Object> list = new KList<>();
for (Object i : collection) { for (Object i : collection) {
if (i instanceof net.minecraft.nbt.Tag t) if (i instanceof Tag t)
list.add(convertFromTag(t, depth + 1, maxDepth)); list.add(convertFromTag(t, depth + 1, maxDepth));
else list.add(i); else list.add(i);
} }
@ -303,7 +310,7 @@ public class NMSBinding implements INMSBinding {
return tag; return tag;
} }
if (object instanceof List<?> list) { if (object instanceof List<?> list) {
var tag = new net.minecraft.nbt.ListTag(); var tag = new ListTag();
for (var i : list) { for (var i : list) {
tag.add(convertToTag(i, depth + 1, maxDepth)); tag.add(convertToTag(i, depth + 1, maxDepth));
} }
@ -855,6 +862,20 @@ public class NMSBinding implements INMSBinding {
return new Color(rgba, true); return new Color(rgba, true);
} }
@Override
public String getMobCategory(org.bukkit.entity.EntityType bukkitEntity) {
var test = registry().registry(Registries.ENTITY_TYPE).orElse(null);
for (EntityType entity : test) {
MobCategory category = entity.getCategory();
var name = entity.getDescriptionId().replaceAll("entity.minecraft.", "");
var bukkit = bukkitEntity.name();
if(name.equalsIgnoreCase(bukkit)) {
return category.getName();
}
}
return null;
}
@Override @Override
public KList<String> getStructureKeys() { public KList<String> getStructureKeys() {
KList<String> keys = new KList<>(); KList<String> keys = new KList<>();
@ -965,12 +986,12 @@ public class NMSBinding implements INMSBinding {
new ByteBuddy() new ByteBuddy()
.redefine(CraftServer.class) .redefine(CraftServer.class)
.visit(Advice.to(CraftServerAdvice.class).on(ElementMatchers.isMethod().and(ElementMatchers.takesArguments(WorldCreator.class)))) .visit(Advice.to(CraftServerAdvice.class).on(ElementMatchers.isMethod().and(takesArguments(WorldCreator.class))))
.make() .make()
.load(CraftServer.class.getClassLoader(), ClassReloadingStrategy.fromInstalledAgent()); .load(CraftServer.class.getClassLoader(), ClassReloadingStrategy.fromInstalledAgent());
new ByteBuddy() new ByteBuddy()
.redefine(ServerLevel.class) .redefine(ServerLevel.class)
.visit(Advice.to(ServerLevelAdvice.class).on(ElementMatchers.isConstructor().and(ElementMatchers.takesArguments(MinecraftServer.class, Executor.class, LevelStorageSource.LevelStorageAccess.class, .visit(Advice.to(ServerLevelAdvice.class).on(ElementMatchers.isConstructor().and(takesArguments(MinecraftServer.class, Executor.class, LevelStorageSource.LevelStorageAccess.class,
PrimaryLevelData.class, ResourceKey.class, LevelStem.class, ChunkProgressListener.class, boolean.class, long.class, PrimaryLevelData.class, ResourceKey.class, LevelStem.class, ChunkProgressListener.class, boolean.class, long.class,
List.class, boolean.class, RandomSequences.class, World.Environment.class, ChunkGenerator.class, BiomeProvider.class)))) List.class, boolean.class, RandomSequences.class, World.Environment.class, ChunkGenerator.class, BiomeProvider.class))))
.make() .make()