add portal locations

This commit is contained in:
okx-code
2026-06-24 23:07:25 +01:00
parent d875a72598
commit c8fed34910
4 changed files with 63 additions and 1 deletions

View File

@@ -0,0 +1,48 @@
package net.civmc.zorweth.mechanics;
import java.util.List;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.EnderSignal;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntitySpawnEvent;
public final class EnderEyeListener implements Listener {
private final String worldName;
private final List<PortalPosition> portals;
public EnderEyeListener(final String worldName, final List<PortalPosition> portals) {
this.worldName = worldName;
this.portals = portals;
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onEnderEyeSpawn(final EntitySpawnEvent event) {
if (!(event.getEntity() instanceof EnderSignal eye)) {
return;
}
final World world = event.getEntity().getWorld();
if (!world.getName().equals(this.worldName)) {
return;
}
Location closestPortal = null;
double closestDistanceSquared = Double.MAX_VALUE;
for (final PortalPosition portal : this.portals) {
final Location location = new Location(world, portal.x(), world.getMinHeight(), portal.z());
final double distanceSquared = location.distanceSquared(eye.getLocation());
if (distanceSquared < closestDistanceSquared) {
closestPortal = location;
closestDistanceSquared = distanceSquared;
}
}
if (closestPortal != null) {
eye.setTargetLocation(closestPortal);
}
}
}

View File

@@ -29,6 +29,12 @@ public class OilMechanics {
oilPos.add(new OilVein((int) position.get("x"), (int) position.get("z"), (int) position.get("yield")));
}
List<PortalPosition> portals = new ArrayList<>();
List<Map<?, ?>> portalPositions = mechanics.getMapList("portals");
for (Map<?, ?> position : portalPositions) {
portals.add(new PortalPosition((int) position.get("x"), (int) position.get("z")));
}
this.oilPos = oilPos;
this.world = mechanicsWorld;
this.radius = mechanics.getInt("radius");
@@ -41,6 +47,9 @@ public class OilMechanics {
Bukkit.addRecipe(recipe);
}
plugin.getServer().getPluginManager().registerEvents(new SeismicScannerListener(recipes, this), plugin);
if (!portals.isEmpty()) {
plugin.getServer().getPluginManager().registerEvents(new EnderEyeListener(mechanicsWorld, portals), plugin);
}
Fuel.createCrudeOil();
Fuel.createRocketFuel();

View File

@@ -0,0 +1,5 @@
package net.civmc.zorweth.mechanics;
public record PortalPosition(int x, int z) {
}