mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-08-27 04:37:47 +00:00
Fix Iris entity spawn delegation
This commit is contained in:
@@ -295,7 +295,7 @@ public class IrisSettings {
|
||||
public boolean studio = true;
|
||||
public boolean openVSCode = true;
|
||||
public boolean disableTimeAndWeather = true;
|
||||
public boolean enableEntitySpawning = false;
|
||||
public boolean entitySpawning = true;
|
||||
public boolean autoStartDefaultStudio = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -295,7 +295,7 @@ public class IrisProject {
|
||||
}
|
||||
|
||||
if (sender.isPlayer() && sender.player() != null) {
|
||||
J.runEntity(sender.player(), () -> sender.player().setGameMode(GameMode.SPECTATOR));
|
||||
J.runEntity(sender.player(), () -> sender.player().setGameMode(GameMode.CREATIVE));
|
||||
}
|
||||
activeProvider = IrisToolbelt.access(result.world());
|
||||
maintenanceWorld = result.world();
|
||||
|
||||
@@ -82,6 +82,7 @@ public final class WorldRuntimeControlService {
|
||||
|
||||
IrisServices.get(art.arcane.iris.core.link.MultiverseCoreLink.class).removeFromConfig(world);
|
||||
setIntGameRule(world, 0, "SPAWN_CHUNK_RADIUS", "spawnChunkRadius");
|
||||
enableStudioEntitySpawning(world);
|
||||
if (!IrisSettings.get().getStudio().isDisableTimeAndWeather()) {
|
||||
return true;
|
||||
}
|
||||
@@ -100,17 +101,12 @@ public final class WorldRuntimeControlService {
|
||||
applyStudioWorldRules(world);
|
||||
|
||||
setBooleanGameRule(world, false, "DO_FIRE_TICK", "doFireTick");
|
||||
setBooleanGameRule(world, false, "DO_MOB_SPAWNING", "doMobSpawning");
|
||||
setBooleanGameRule(world, false, "DO_MOB_LOOT", "doMobLoot");
|
||||
setBooleanGameRule(world, false, "DO_TRADER_SPAWNING", "doTraderSpawning");
|
||||
setBooleanGameRule(world, false, "DO_PATROL_SPAWNING", "doPatrolSpawning");
|
||||
setBooleanGameRule(world, false, "DO_INSOMNIA", "doInsomnia");
|
||||
setBooleanGameRule(world, true, "DO_IMMEDIATE_RESPAWN", "doImmediateRespawn");
|
||||
setBooleanGameRule(world, false, "FALL_DAMAGE", "fallDamage");
|
||||
setBooleanGameRule(world, false, "FIRE_DAMAGE", "fireDamage");
|
||||
setBooleanGameRule(world, false, "DROWNING_DAMAGE", "drowningDamage");
|
||||
setBooleanGameRule(world, false, "FREEZE_DAMAGE", "freezeDamage");
|
||||
setBooleanGameRule(world, false, "DO_WARDEN_SPAWNING", "doWardenSpawning");
|
||||
setBooleanGameRule(world, false, "MOB_GRIEFING", "mobGriefing");
|
||||
setBooleanGameRule(world, false, "DO_TILE_DROPS", "doTileDrops");
|
||||
setBooleanGameRule(world, true, "KEEP_INVENTORY", "keepInventory");
|
||||
@@ -121,6 +117,14 @@ public final class WorldRuntimeControlService {
|
||||
return true;
|
||||
}
|
||||
|
||||
static void enableStudioEntitySpawning(World world) {
|
||||
setBooleanGameRule(world, true, "DO_MOB_SPAWNING", "doMobSpawning");
|
||||
setBooleanGameRule(world, true, "DO_TRADER_SPAWNING", "doTraderSpawning");
|
||||
setBooleanGameRule(world, true, "DO_PATROL_SPAWNING", "doPatrolSpawning");
|
||||
setBooleanGameRule(world, true, "DO_INSOMNIA", "doInsomnia");
|
||||
setBooleanGameRule(world, true, "DO_WARDEN_SPAWNING", "doWardenSpawning");
|
||||
}
|
||||
|
||||
public boolean applyNoonTimeLock(World world) {
|
||||
if (world == null) {
|
||||
return false;
|
||||
|
||||
@@ -40,8 +40,6 @@ import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
import org.bukkit.event.entity.EntitySpawnEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.world.WorldUnloadEvent;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
@@ -129,26 +127,6 @@ public class ObjectStudioSaveService implements IrisService {
|
||||
unregister(event.getWorld());
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onCreatureSpawn(CreatureSpawnEvent event) {
|
||||
if (!studios.containsKey(event.getLocation().getWorld().getUID())) return;
|
||||
CreatureSpawnEvent.SpawnReason reason = event.getSpawnReason();
|
||||
if (reason == CreatureSpawnEvent.SpawnReason.CUSTOM
|
||||
|| reason == CreatureSpawnEvent.SpawnReason.COMMAND
|
||||
|| reason == CreatureSpawnEvent.SpawnReason.SPAWNER_EGG) {
|
||||
return;
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onEntitySpawn(EntitySpawnEvent event) {
|
||||
if (event instanceof CreatureSpawnEvent) return;
|
||||
if (!studios.containsKey(event.getLocation().getWorld().getUID())) return;
|
||||
if (event.getEntity() instanceof org.bukkit.entity.Player) return;
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if (event.getHand() != EquipmentSlot.HAND) return;
|
||||
|
||||
@@ -979,7 +979,7 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
|
||||
return true;
|
||||
}
|
||||
|
||||
return IrisSettings.get().getStudio().isEnableEntitySpawning();
|
||||
return IrisSettings.get().getStudio().isEntitySpawning();
|
||||
}
|
||||
|
||||
private KList<IrisEntitySpawn> spawnRandomly(List<IrisEntitySpawn> types) {
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
package art.arcane.iris.core.runtime;
|
||||
|
||||
import art.arcane.iris.core.IrisSettings;
|
||||
import art.arcane.iris.core.service.ObjectStudioSaveService;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class StudioEntitySpawningTest {
|
||||
@Test
|
||||
public void studioEntitySpawningDefaultsToEnabled() {
|
||||
assertTrue(new IrisSettings.IrisSettingsStudio().isEntitySpawning());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void studioWorldRulesEnableVanillaMobSpawning() throws IOException {
|
||||
String source = Files.readString(Path.of(
|
||||
"src/main/java/art/arcane/iris/core/runtime/WorldRuntimeControlService.java"));
|
||||
int helperStart = source.indexOf("static void enableStudioEntitySpawning");
|
||||
int helperEnd = source.indexOf("public boolean applyNoonTimeLock", helperStart);
|
||||
String helper = source.substring(helperStart, helperEnd);
|
||||
|
||||
assertTrue(source.contains("enableStudioEntitySpawning(world);"));
|
||||
assertTrue(helper.contains("setBooleanGameRule(world, true, \"DO_MOB_SPAWNING\""));
|
||||
assertTrue(helper.contains("setBooleanGameRule(world, true, \"DO_TRADER_SPAWNING\""));
|
||||
assertTrue(helper.contains("setBooleanGameRule(world, true, \"DO_PATROL_SPAWNING\""));
|
||||
assertTrue(helper.contains("setBooleanGameRule(world, true, \"DO_INSOMNIA\""));
|
||||
assertTrue(helper.contains("setBooleanGameRule(world, true, \"DO_WARDEN_SPAWNING\""));
|
||||
assertFalse(helper.contains("setBooleanGameRule(world, false, \"DO_MOB_SPAWNING\""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generalStudioUsesAPlayerModeEligibleForNaturalSpawning() throws IOException {
|
||||
String source = Files.readString(Path.of(
|
||||
"src/main/java/art/arcane/iris/core/project/IrisProject.java"));
|
||||
|
||||
assertFalse(source.contains("GameMode.SPECTATOR"));
|
||||
assertTrue(source.contains("GameMode.CREATIVE"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void objectStudioDoesNotCancelEntitySpawns() {
|
||||
boolean hasSpawnCanceller = Arrays.stream(ObjectStudioSaveService.class.getDeclaredMethods())
|
||||
.anyMatch(method -> method.getName().equals("onCreatureSpawn")
|
||||
|| method.getName().equals("onEntitySpawn"));
|
||||
|
||||
assertFalse(hasSpawnCanceller);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user