mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-02 07:56:48 +00:00
implement custom conditions for mythic mobs (#1204)
This commit is contained in:
parent
37be7ca847
commit
851ac18f0d
@ -18,20 +18,33 @@
|
|||||||
|
|
||||||
package com.volmit.iris.core.link;
|
package com.volmit.iris.core.link;
|
||||||
|
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
|
import com.volmit.iris.Iris;
|
||||||
|
import com.volmit.iris.core.tools.IrisToolbelt;
|
||||||
|
import io.lumine.mythic.api.adapters.AbstractLocation;
|
||||||
|
import io.lumine.mythic.api.config.MythicLineConfig;
|
||||||
|
import io.lumine.mythic.api.skills.conditions.ILocationCondition;
|
||||||
import io.lumine.mythic.bukkit.MythicBukkit;
|
import io.lumine.mythic.bukkit.MythicBukkit;
|
||||||
|
import io.lumine.mythic.bukkit.adapters.BukkitWorld;
|
||||||
|
import io.lumine.mythic.bukkit.events.MythicConditionLoadEvent;
|
||||||
|
import io.lumine.mythic.core.skills.SkillCondition;
|
||||||
|
import io.lumine.mythic.core.utils.annotations.MythicCondition;
|
||||||
|
import io.lumine.mythic.core.utils.annotations.MythicField;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.util.Collection;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class MythicMobsLink {
|
public class MythicMobsLink {
|
||||||
|
|
||||||
public MythicMobsLink() {
|
public MythicMobsLink() {
|
||||||
|
if (getPlugin() == null) return;
|
||||||
|
Iris.instance.registerListener(new ConditionListener());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isEnabled() {
|
public boolean isEnabled() {
|
||||||
@ -49,12 +62,70 @@ public class MythicMobsLink {
|
|||||||
* @param location The location
|
* @param location The location
|
||||||
* @return The mob, or null if it can't be spawned
|
* @return The mob, or null if it can't be spawned
|
||||||
*/
|
*/
|
||||||
public @Nullable
|
public @Nullable Entity spawnMob(String mob, Location location) {
|
||||||
Entity spawnMob(String mob, Location location) {
|
|
||||||
return isEnabled() ? MythicBukkit.inst().getMobManager().spawnMob(mob, location).getEntity().getBukkitEntity() : null;
|
return isEnabled() ? MythicBukkit.inst().getMobManager().spawnMob(mob, location).getEntity().getBukkitEntity() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<String> getMythicMobTypes() {
|
public Collection<String> getMythicMobTypes() {
|
||||||
return isEnabled() ? MythicBukkit.inst().getMobManager().getMobNames() : List.of();
|
return isEnabled() ? MythicBukkit.inst().getMobManager().getMobNames() : List.of();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class ConditionListener implements Listener {
|
||||||
|
@EventHandler
|
||||||
|
public void on(MythicConditionLoadEvent event) {
|
||||||
|
switch (event.getConditionName()) {
|
||||||
|
case "irisbiome" -> event.register(new IrisBiomeCondition(event.getConditionName(), event.getConfig()));
|
||||||
|
case "irisregion" -> event.register(new IrisRegionCondition(event.getConditionName(), event.getConfig()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@MythicCondition(author = "CrazyDev22", name = "irisbiome", description = "Tests if the target is within the given list of biomes")
|
||||||
|
public static class IrisBiomeCondition extends SkillCondition implements ILocationCondition {
|
||||||
|
@MythicField(name = "biome", aliases = {"b"}, description = "A list of biomes to check")
|
||||||
|
private Set<String> biomes = Sets.newConcurrentHashSet();
|
||||||
|
@MythicField(name = "surface", aliases = {"s"}, description = "If the biome check should only be performed on the surface")
|
||||||
|
private boolean surface;
|
||||||
|
|
||||||
|
public IrisBiomeCondition(String line, MythicLineConfig mlc) {
|
||||||
|
super(line);
|
||||||
|
String b = mlc.getString(new String[]{"biome", "b"}, "");
|
||||||
|
biomes.addAll(Arrays.asList(b.split(",")));
|
||||||
|
surface = mlc.getBoolean(new String[]{"surface", "s"}, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean check(AbstractLocation target) {
|
||||||
|
var access = IrisToolbelt.access(((BukkitWorld) target.getWorld()).getBukkitWorld());
|
||||||
|
if (access == null) return false;
|
||||||
|
var engine = access.getEngine();
|
||||||
|
if (engine == null) return false;
|
||||||
|
var biome = surface ?
|
||||||
|
engine.getSurfaceBiome(target.getBlockX(), target.getBlockZ()) :
|
||||||
|
engine.getBiomeOrMantle(target.getBlockX(), target.getBlockY() - engine.getMinHeight(), target.getBlockZ());
|
||||||
|
return biomes.contains(biome.getLoadKey());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@MythicCondition(author = "CrazyDev22", name = "irisbiome", description = "Tests if the target is within the given list of biomes")
|
||||||
|
public static class IrisRegionCondition extends SkillCondition implements ILocationCondition {
|
||||||
|
@MythicField(name = "region", aliases = {"r"}, description = "A list of regions to check")
|
||||||
|
private Set<String> regions = Sets.newConcurrentHashSet();
|
||||||
|
|
||||||
|
public IrisRegionCondition(String line, MythicLineConfig mlc) {
|
||||||
|
super(line);
|
||||||
|
String b = mlc.getString(new String[]{"region", "r"}, "");
|
||||||
|
regions.addAll(Arrays.asList(b.split(",")));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean check(AbstractLocation target) {
|
||||||
|
var access = IrisToolbelt.access(((BukkitWorld) target.getWorld()).getBukkitWorld());
|
||||||
|
if (access == null) return false;
|
||||||
|
var engine = access.getEngine();
|
||||||
|
if (engine == null) return false;
|
||||||
|
var region = engine.getRegion(target.getBlockX(), target.getBlockZ());
|
||||||
|
return regions.contains(region.getLoadKey());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,7 +96,6 @@ public class IrisEngine implements Engine {
|
|||||||
private EngineExecutionEnvironment execution;
|
private EngineExecutionEnvironment execution;
|
||||||
private EngineWorldManager worldManager;
|
private EngineWorldManager worldManager;
|
||||||
private volatile int parallelism;
|
private volatile int parallelism;
|
||||||
private volatile int minHeight;
|
|
||||||
private boolean failing;
|
private boolean failing;
|
||||||
private boolean closed;
|
private boolean closed;
|
||||||
private int cacheId;
|
private int cacheId;
|
||||||
@ -129,7 +128,6 @@ public class IrisEngine implements Engine {
|
|||||||
getData().setEngine(this);
|
getData().setEngine(this);
|
||||||
getData().loadPrefetch(this);
|
getData().loadPrefetch(this);
|
||||||
Iris.info("Initializing Engine: " + target.getWorld().name() + "/" + target.getDimension().getLoadKey() + " (" + target.getDimension().getDimensionHeight() + " height) Seed: " + getSeedManager().getSeed());
|
Iris.info("Initializing Engine: " + target.getWorld().name() + "/" + target.getDimension().getLoadKey() + " (" + target.getDimension().getDimensionHeight() + " height) Seed: " + getSeedManager().getSeed());
|
||||||
minHeight = 0;
|
|
||||||
failing = false;
|
failing = false;
|
||||||
closed = false;
|
closed = false;
|
||||||
art = J.ar(this::tickRandomPlayer, 0);
|
art = J.ar(this::tickRandomPlayer, 0);
|
||||||
@ -475,7 +473,7 @@ public class IrisEngine implements Engine {
|
|||||||
getEngineData().getStatistics().generatedChunk();
|
getEngineData().getStatistics().generatedChunk();
|
||||||
try {
|
try {
|
||||||
PrecisionStopwatch p = PrecisionStopwatch.start();
|
PrecisionStopwatch p = PrecisionStopwatch.start();
|
||||||
Hunk<BlockData> blocks = vblocks.listen((xx, y, zz, t) -> catchBlockUpdates(x + xx, y + getMinHeight(), z + zz, t));
|
Hunk<BlockData> blocks = vblocks.listen((xx, y, zz, t) -> catchBlockUpdates(x + xx, y, z + zz, t));
|
||||||
|
|
||||||
if (getDimension().isDebugChunkCrossSections() && ((x >> 4) % getDimension().getDebugCrossSectionsMod() == 0 || (z >> 4) % getDimension().getDebugCrossSectionsMod() == 0)) {
|
if (getDimension().isDebugChunkCrossSections() && ((x >> 4) % getDimension().getDebugCrossSectionsMod() == 0 || (z >> 4) % getDimension().getDebugCrossSectionsMod() == 0)) {
|
||||||
for (int i = 0; i < 16; i++) {
|
for (int i = 0; i < 16; i++) {
|
||||||
|
@ -140,7 +140,9 @@ public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdat
|
|||||||
return getTarget().getWorld().minHeight();
|
return getTarget().getWorld().minHeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
void setMinHeight(int min);
|
default void setMinHeight(int min) {
|
||||||
|
getTarget().getWorld().minHeight(min);
|
||||||
|
}
|
||||||
|
|
||||||
@BlockCoordinates
|
@BlockCoordinates
|
||||||
default void generate(int x, int z, TerrainChunk tc, boolean multicore) throws WrongEngineBroException {
|
default void generate(int x, int z, TerrainChunk tc, boolean multicore) throws WrongEngineBroException {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user