mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-03 16:36:00 +00:00
Sync!
This commit is contained in:
parent
6cfa593eee
commit
805523d069
@ -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;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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,14 +125,40 @@ 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;
|
||||
}
|
||||
|
||||
|
||||
@ -123,6 +166,11 @@ public class EngineMobHandlerSVC extends IrisEngineService implements IrisMobDat
|
||||
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;
|
||||
|
@ -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();
|
||||
|
@ -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() {
|
||||
|
||||
}
|
||||
}
|
@ -59,11 +59,16 @@ import net.bytebuddy.implementation.bytecode.member.MethodInvocation;
|
||||
import net.bytebuddy.matcher.ElementMatchers;
|
||||
import net.minecraft.core.IdMapper;
|
||||
import net.minecraft.core.MappedRegistry;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.resources.RegistryOps;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.progress.ChunkProgressListener;
|
||||
import net.minecraft.util.GsonHelper;
|
||||
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.Level;
|
||||
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.entity.Dolphin;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityCategory;
|
||||
import org.bukkit.entity.Mob;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
import org.bukkit.generator.BiomeProvider;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
@ -230,13 +237,13 @@ public class NMSBinding implements INMSBinding {
|
||||
}
|
||||
|
||||
@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 instanceof CollectionTag<?> collection) {
|
||||
KList<Object> list = new KList<>();
|
||||
|
||||
for (Object i : collection) {
|
||||
if (i instanceof net.minecraft.nbt.Tag t)
|
||||
if (i instanceof Tag t)
|
||||
list.add(convertFromTag(t, depth + 1, maxDepth));
|
||||
else list.add(i);
|
||||
}
|
||||
@ -303,7 +310,7 @@ public class NMSBinding implements INMSBinding {
|
||||
return tag;
|
||||
}
|
||||
if (object instanceof List<?> list) {
|
||||
var tag = new net.minecraft.nbt.ListTag();
|
||||
var tag = new ListTag();
|
||||
for (var i : list) {
|
||||
tag.add(convertToTag(i, depth + 1, maxDepth));
|
||||
}
|
||||
@ -855,6 +862,20 @@ public class NMSBinding implements INMSBinding {
|
||||
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
|
||||
public KList<String> getStructureKeys() {
|
||||
KList<String> keys = new KList<>();
|
||||
@ -965,12 +986,12 @@ public class NMSBinding implements INMSBinding {
|
||||
|
||||
new ByteBuddy()
|
||||
.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()
|
||||
.load(CraftServer.class.getClassLoader(), ClassReloadingStrategy.fromInstalledAgent());
|
||||
new ByteBuddy()
|
||||
.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,
|
||||
List.class, boolean.class, RandomSequences.class, World.Environment.class, ChunkGenerator.class, BiomeProvider.class))))
|
||||
.make()
|
||||
|
Loading…
x
Reference in New Issue
Block a user