From 52ec9f42965e992f32191709fd4887b889a6835b Mon Sep 17 00:00:00 2001 From: Slotterleet <62336673+Slotterleet@users.noreply.github.com> Date: Sun, 7 May 2023 03:49:40 +0200 Subject: [PATCH] A couple of features for better planet modding (#8558) * Planet item whitelist * allowLaunchToNumbered for planets * Update core/src/mindustry/type/Planet.java * Update core/src/mindustry/type/Planet.java --------- Co-authored-by: Anuken --- core/src/mindustry/content/Planets.java | 3 +++ .../mindustry/maps/generators/PlanetGenerator.java | 2 +- .../maps/planet/ErekirPlanetGenerator.java | 6 ------ core/src/mindustry/type/Planet.java | 14 +++++++++++++- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/core/src/mindustry/content/Planets.java b/core/src/mindustry/content/Planets.java index c1c82bbde5..c5e4531e55 100644 --- a/core/src/mindustry/content/Planets.java +++ b/core/src/mindustry/content/Planets.java @@ -68,6 +68,9 @@ public class Planets{ hiddenItems.addAll(Items.serpuloItems).removeAll(Items.erekirItems); enemyBuildSpeedMultiplier = 0.4f; + //TODO disallowed for now + allowLaunchToNumbered = false; + //TODO SHOULD there be lighting? updateLighting = false; diff --git a/core/src/mindustry/maps/generators/PlanetGenerator.java b/core/src/mindustry/maps/generators/PlanetGenerator.java index 18ea8a35eb..710e63b0dd 100644 --- a/core/src/mindustry/maps/generators/PlanetGenerator.java +++ b/core/src/mindustry/maps/generators/PlanetGenerator.java @@ -55,7 +55,7 @@ public abstract class PlanetGenerator extends BasicGenerator implements HexMeshe /** @return whether to allow landing on the specified procedural sector */ public boolean allowLanding(Sector sector){ - return sector.hasBase() || sector.near().contains(Sector::hasBase); + return sector.planet.allowLaunchToNumbered && (sector.hasBase() || sector.near().contains(Sector::hasBase)); } public void addWeather(Sector sector, Rules rules){ diff --git a/core/src/mindustry/maps/planet/ErekirPlanetGenerator.java b/core/src/mindustry/maps/planet/ErekirPlanetGenerator.java index a6ee5d7d9a..b79f744fdd 100644 --- a/core/src/mindustry/maps/planet/ErekirPlanetGenerator.java +++ b/core/src/mindustry/maps/planet/ErekirPlanetGenerator.java @@ -62,12 +62,6 @@ public class ErekirPlanetGenerator extends PlanetGenerator{ return 2000 * 1.07f * 6f / 5f; } - @Override - public boolean allowLanding(Sector sector){ - //TODO disallowed for now - return false; - } - float rawHeight(Vec3 position){ return Simplex.noise3d(seed, octaves, persistence, 1f/heightScl, 10f + position.x, 10f + position.y, 10f + position.z); } diff --git a/core/src/mindustry/type/Planet.java b/core/src/mindustry/type/Planet.java index 4d05c58f55..ee7a9bcd42 100644 --- a/core/src/mindustry/type/Planet.java +++ b/core/src/mindustry/type/Planet.java @@ -13,6 +13,7 @@ import mindustry.content.*; import mindustry.content.TechTree.*; import mindustry.ctype.*; import mindustry.game.*; +import mindustry.game.EventType.ContentInitEvent; import mindustry.graphics.*; import mindustry.graphics.g3d.*; import mindustry.graphics.g3d.PlanetGrid.*; @@ -114,6 +115,8 @@ public class Planet extends UnlockableContent{ public boolean prebuildBase = true; /** If true, waves are created on sector loss. TODO remove. */ public boolean allowWaves = false; + /** If false, players are unable to land on this planet's numbered sectors. */ + public boolean allowLaunchToNumbered = true; /** Icon as displayed in the planet selection dialog. This is a string, as drawables are null at load time. */ public String icon = "planet"; /** Default core block for launching. */ @@ -130,8 +133,10 @@ public class Planet extends UnlockableContent{ public @Nullable TechNode techTree; /** TODO remove? Planets that can be launched to from this one. Made mutual in init(). */ public Seq launchCandidates = new Seq<>(); - /** Items not available on this planet. */ + /** Items not available on this planet. Left out for backwards compatibility. */ public Seq hiddenItems = new Seq<>(); + /** The only items available on this planet, if defined. */ + public Seq itemWhitelist = new Seq<>(); /** Content (usually planet-specific) that is unlocked upon landing here. */ public Seq unlockedOnLand = new Seq<>(); /** Loads the mesh. Clientside only. Defaults to a boring sphere mesh. */ @@ -159,6 +164,13 @@ public class Planet extends UnlockableContent{ parent.updateTotalRadius(); } + //if an item whitelist exists, add everything else not in that whitelist to hidden items + Events.on(ContentInitEvent.class, e -> { + if(itemWhitelist.size > 0){ + hiddenItems.addAll(content.items().select(i -> !itemWhitelist.contains(i))); + } + }); + //calculate solar system for(solarSystem = this; solarSystem.parent != null; solarSystem = solarSystem.parent); }