diff --git a/core/src/mindustry/content/Planets.java b/core/src/mindustry/content/Planets.java index c5e4531e55..7eec1f10b0 100644 --- a/core/src/mindustry/content/Planets.java +++ b/core/src/mindustry/content/Planets.java @@ -65,7 +65,6 @@ public class Planets{ clearSectorOnLose = true; defaultCore = Blocks.coreBastion; iconColor = Color.valueOf("ff9266"); - hiddenItems.addAll(Items.serpuloItems).removeAll(Items.erekirItems); enemyBuildSpeedMultiplier = 0.4f; //TODO disallowed for now @@ -152,7 +151,6 @@ public class Planets{ startSector = 15; alwaysUnlocked = true; landCloudColor = Pal.spore.cpy().a(0.5f); - hiddenItems.addAll(Items.erekirItems).removeAll(Items.serpuloItems); }}; verilus = makeAsteroid("verlius", sun, Blocks.stoneWall, Blocks.iceWall, 0.5f, 12, 2f, gen -> { diff --git a/core/src/mindustry/core/Logic.java b/core/src/mindustry/core/Logic.java index 59f9b3cdcd..be096bf715 100644 --- a/core/src/mindustry/core/Logic.java +++ b/core/src/mindustry/core/Logic.java @@ -143,7 +143,6 @@ public class Logic implements ApplicationListener{ //set up hidden items state.rules.hiddenBuildItems.clear(); - state.rules.hiddenBuildItems.addAll(state.rules.sector.planet.hiddenItems); } //save settings diff --git a/core/src/mindustry/core/World.java b/core/src/mindustry/core/World.java index 92e3e46a8c..cac92019f6 100644 --- a/core/src/mindustry/core/World.java +++ b/core/src/mindustry/core/World.java @@ -322,7 +322,6 @@ public class World{ state.rules.env = sector.planet.defaultEnv; state.rules.planet = sector.planet; state.rules.hiddenBuildItems.clear(); - state.rules.hiddenBuildItems.addAll(sector.planet.hiddenItems); sector.planet.applyRules(state.rules); sector.info.resources = content.toSeq(); sector.info.resources.sort(Structs.comps(Structs.comparing(Content::getContentType), Structs.comparingInt(c -> c.id))); diff --git a/core/src/mindustry/ctype/UnlockableContent.java b/core/src/mindustry/ctype/UnlockableContent.java index e727e933fe..4b7157b05d 100644 --- a/core/src/mindustry/ctype/UnlockableContent.java +++ b/core/src/mindustry/ctype/UnlockableContent.java @@ -102,6 +102,10 @@ public abstract class UnlockableContent extends MappableContent{ uiIcon = Core.atlas.find(getContentType().name() + "-" + name + "-ui", fullIcon); } + public boolean isOnPlanet(@Nullable Planet planet){ + return planet == null || shownPlanets.isEmpty() || shownPlanets.contains(planet); + } + public int getLogicId(){ return logicVars.lookupLogicId(this); } diff --git a/core/src/mindustry/game/Rules.java b/core/src/mindustry/game/Rules.java index bd405c793e..c87e3311c0 100644 --- a/core/src/mindustry/game/Rules.java +++ b/core/src/mindustry/game/Rules.java @@ -153,8 +153,11 @@ public class Rules{ public ObjectSet revealedBlocks = new ObjectSet<>(); /** Unlocked content names. Only used in multiplayer when the campaign is enabled. */ public ObjectSet researched = new ObjectSet<>(); - /** Block containing these items as requirements are hidden. */ - public ObjectSet hiddenBuildItems = Items.erekirOnlyItems.asSet(); + /** + * Block containing these items as requirements are hidden. + * @deprecated May be removed in the near future. + * */ + public @Deprecated ObjectSet hiddenBuildItems = Items.erekirOnlyItems.asSet(); /** In-map objective executor. */ public MapObjectives objectives = new MapObjectives(); /** Flags set by objectives. Used in world processors. */ diff --git a/core/src/mindustry/maps/generators/BaseGenerator.java b/core/src/mindustry/maps/generators/BaseGenerator.java index 9671a83a42..71ccc7810c 100644 --- a/core/src/mindustry/maps/generators/BaseGenerator.java +++ b/core/src/mindustry/maps/generators/BaseGenerator.java @@ -34,7 +34,7 @@ public class BaseGenerator{ Seq wallsSmall = content.blocks().select(b -> b instanceof Wall && b.isVanilla() && b.size == size && !b.insulated && b.buildVisibility == BuildVisibility.shown && !(b instanceof Door) - && !(Structs.contains(b.requirements, i -> state.rules.hiddenBuildItems.contains(i.item)))); + && b.isOnPlanet(state.getPlanet())); wallsSmall.sort(b -> b.buildCost); return wallsSmall.getFrac(difficulty * 0.91f); } diff --git a/core/src/mindustry/service/GameService.java b/core/src/mindustry/service/GameService.java index ce008a3c88..fd4eb01a61 100644 --- a/core/src/mindustry/service/GameService.java +++ b/core/src/mindustry/service/GameService.java @@ -81,12 +81,12 @@ public class GameService{ } private void registerEvents(){ - allTransportSerpulo = content.blocks().select(b -> b.category == Category.distribution && b.isVisibleOn(Planets.serpulo) && b.isVanilla() && b.buildVisibility == BuildVisibility.shown).toArray(Block.class); - allTransportErekir = content.blocks().select(b -> b.category == Category.distribution && b.isVisibleOn(Planets.erekir) && b.isVanilla() && b.buildVisibility == BuildVisibility.shown).toArray(Block.class); + allTransportSerpulo = content.blocks().select(b -> b.category == Category.distribution && b.isOnPlanet(Planets.serpulo) && b.isVanilla() && b.buildVisibility == BuildVisibility.shown).toArray(Block.class); + allTransportErekir = content.blocks().select(b -> b.category == Category.distribution && b.isOnPlanet(Planets.erekir) && b.isVanilla() && b.buildVisibility == BuildVisibility.shown).toArray(Block.class); //cores are ignored since they're upgrades and can be skipped - allSerpuloBlocks = content.blocks().select(b -> b.synthetic() && b.isVisibleOn(Planets.serpulo) && b.isVanilla() && !(b instanceof CoreBlock) && b.buildVisibility == BuildVisibility.shown).toArray(Block.class); - allErekirBlocks = content.blocks().select(b -> b.synthetic() && b.isVisibleOn(Planets.erekir) && b.isVanilla() && !(b instanceof CoreBlock) && b.buildVisibility == BuildVisibility.shown).toArray(Block.class); + allSerpuloBlocks = content.blocks().select(b -> b.synthetic() && b.isOnPlanet(Planets.serpulo) && b.isVanilla() && !(b instanceof CoreBlock) && b.buildVisibility == BuildVisibility.shown).toArray(Block.class); + allErekirBlocks = content.blocks().select(b -> b.synthetic() && b.isOnPlanet(Planets.erekir) && b.isVanilla() && !(b instanceof CoreBlock) && b.buildVisibility == BuildVisibility.shown).toArray(Block.class); unitsBuilt = Core.settings.getJson("units-built" , ObjectSet.class, String.class, ObjectSet::new); blocksBuilt = Core.settings.getJson("blocks-built" , ObjectSet.class, String.class, ObjectSet::new); diff --git a/core/src/mindustry/type/Item.java b/core/src/mindustry/type/Item.java index 1c59b0d07a..3ba4dc9de5 100644 --- a/core/src/mindustry/type/Item.java +++ b/core/src/mindustry/type/Item.java @@ -47,8 +47,6 @@ public class Item extends UnlockableContent implements Senseable{ /** If true, this material is used by buildings. If false, this material will be incinerated in certain cores. */ public boolean buildable = true; public boolean hidden = false; - /** For mods. Adds this item to the listed planets' hidden items Seq. */ - public @Nullable Planet[] hiddenOnPlanets; public Item(String name, Color color){ super(name); @@ -60,14 +58,9 @@ public class Item extends UnlockableContent implements Senseable{ } @Override - public void init(){ - super.init(); - - if(hiddenOnPlanets != null){ - for(Planet planet : hiddenOnPlanets){ - planet.hiddenItems.add(this); - } - } + public boolean isOnPlanet(Planet planet){ + //hidden items should not appear on any planet's resource selection screen + return super.isOnPlanet(planet) && !hidden; } @Override diff --git a/core/src/mindustry/type/Planet.java b/core/src/mindustry/type/Planet.java index 72e901d51e..66309f71ac 100644 --- a/core/src/mindustry/type/Planet.java +++ b/core/src/mindustry/type/Planet.java @@ -15,7 +15,6 @@ import mindustry.content.*; import mindustry.content.TechTree.*; import mindustry.ctype.*; import mindustry.game.*; -import mindustry.game.EventType.ContentInitEvent; import mindustry.gen.*; import mindustry.graphics.*; import mindustry.graphics.g3d.*; @@ -146,10 +145,6 @@ 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. Left out for backwards compatibility. */ - public Seq hiddenItems = new Seq<>(); - /** The only items available on this planet, if defined. */ - public Seq itemWhitelist = new Seq<>(); /** If true, all content in this planet's tech tree will be assigned this planet in their shownPlanets. */ public boolean autoAssignPlanet = true; /** Content (usually planet-specific) that is unlocked upon landing here. */ @@ -181,13 +176,6 @@ 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); } @@ -219,7 +207,6 @@ public class Planet extends UnlockableContent{ rules.env = defaultEnv; rules.planet = this; rules.hiddenBuildItems.clear(); - rules.hiddenBuildItems.addAll(hiddenItems); } public @Nullable Sector getLastSector(){ @@ -340,12 +327,9 @@ public class Planet extends UnlockableContent{ techTree = TechTree.roots.find(n -> n.planet == this); } - if(techTree != null){ + if(techTree != null && autoAssignPlanet){ techTree.addDatabaseTab(this); - - if(autoAssignPlanet){ - techTree.addPlanet(this); - } + techTree.addPlanet(this); } for(Sector sector : sectors){ diff --git a/core/src/mindustry/ui/dialogs/CustomRulesDialog.java b/core/src/mindustry/ui/dialogs/CustomRulesDialog.java index a277593dd3..a906d45509 100644 --- a/core/src/mindustry/ui/dialogs/CustomRulesDialog.java +++ b/core/src/mindustry/ui/dialogs/CustomRulesDialog.java @@ -229,19 +229,8 @@ public class CustomRulesDialog extends BaseDialog{ } number("@rules.dropzoneradius", false, f -> rules.dropZoneRadius = f * tilesize, () -> rules.dropZoneRadius / tilesize, () -> rules.waves); - category("resourcesbuilding"); - check("@rules.infiniteresources", b -> { - rules.infiniteResources = b; - - //reset to serpulo if any env was enabled - if(!b && rules.hiddenBuildItems.isEmpty()){ - rules.env = Planets.serpulo.defaultEnv; - rules.hiddenBuildItems.clear(); - rules.hiddenBuildItems.addAll(Planets.serpulo.hiddenItems); - setup(); - } - }, () -> rules.infiniteResources); + check("@rules.infiniteresources", b -> rules.infiniteResources = b, () -> rules.infiniteResources); check("@rules.onlydepositcore", b -> rules.onlyDepositCore = b, () -> rules.onlyDepositCore); check("@rules.derelictrepair", b -> rules.derelictRepair = b, () -> rules.derelictRepair); check("@rules.reactorexplosions", b -> rules.reactorExplosions = b, () -> rules.reactorExplosions); diff --git a/core/src/mindustry/ui/dialogs/LaunchLoadoutDialog.java b/core/src/mindustry/ui/dialogs/LaunchLoadoutDialog.java index 61d3358233..86ca0c8e16 100644 --- a/core/src/mindustry/ui/dialogs/LaunchLoadoutDialog.java +++ b/core/src/mindustry/ui/dialogs/LaunchLoadoutDialog.java @@ -48,7 +48,7 @@ public class LaunchLoadoutDialog extends BaseDialog{ ItemSeq launch = universe.getLaunchResources(); if(sector.planet.allowLaunchLoadout){ for(var item : content.items()){ - if(sector.planet.hiddenItems.contains(item)){ + if(!item.isOnPlanet(sector.planet)){ launch.set(item, 0); } } @@ -72,7 +72,7 @@ public class LaunchLoadoutDialog extends BaseDialog{ if(destination.preset != null){ var rules = destination.preset.generator.map.rules(); for(var stack : rules.loadout){ - if(!sector.planet.hiddenItems.contains(stack.item)){ + if(stack.item.isOnPlanet(sector.planet)){ resources.add(stack.item, stack.amount); } } @@ -136,7 +136,7 @@ public class LaunchLoadoutDialog extends BaseDialog{ ItemSeq realItems = sitems.copy(); selected.requirements().each(realItems::remove); - loadout.show(lastCapacity, realItems, out, i -> i.unlocked() && !sector.planet.hiddenItems.contains(i), out::clear, () -> {}, () -> { + loadout.show(lastCapacity, realItems, out, i -> i.unlocked() && i.isOnPlanet(sector.planet), out::clear, () -> {}, () -> { universe.updateLaunchResources(new ItemSeq(out)); update.run(); rebuildItems.run(); @@ -172,7 +172,7 @@ public class LaunchLoadoutDialog extends BaseDialog{ Cons handler = s -> { if(s.tiles.contains(tile -> !tile.block.supportsEnv(sector.planet.defaultEnv) || //make sure block can be built here. - (!sector.planet.hiddenItems.isEmpty() && Structs.contains(tile.block.requirements, stack -> sector.planet.hiddenItems.contains(stack.item))))){ + tile.block.isOnPlanet(sector.planet))){ return; } diff --git a/core/src/mindustry/world/Block.java b/core/src/mindustry/world/Block.java index 7b2f60c399..9c21acd8f8 100644 --- a/core/src/mindustry/world/Block.java +++ b/core/src/mindustry/world/Block.java @@ -899,10 +899,6 @@ public class Block extends UnlockableContent implements Senseable{ return !isHidden() && (state.rules.editor || (!state.rules.hideBannedBlocks || !state.rules.isBanned(this))); } - public boolean isVisibleOn(Planet planet){ - return !Structs.contains(requirements, i -> planet.hiddenItems.contains(i.item)) && (shownPlanets.isEmpty() || shownPlanets.contains(planet)); - } - public boolean isPlaceable(){ return isVisible() && (!state.rules.isBanned(this) || state.rules.editor) && supportsEnv(state.rules.env); }