Scrimbles Posted February 28, 2020 Share Posted February 28, 2020 (edited) I need to do a check if a world has caves enabled, to either add something in the worldgenmain.lua or not, I was wondering if theres an easy statement to the effect of "if TheWorld.hascaves then..." etc. Thankus Edited March 2, 2020 by Ogrecakes 1 Link to comment https://forums.kleientertainment.com/forums/topic/116087-is-there-an-easy-if-statement-to-check-if-a-world-has-caves-enabled-edit-the-answer-is-yes-solution-inside/ Share on other sites More sharing options...
Ultroman Posted February 29, 2020 Share Posted February 29, 2020 (edited) UPDATE: Doesn't work. This is probably not the most optimal way, but do this after the whole world is done generating: use FindEntity to search for "cave_entrance" entities, and if you don't find any, then there are no caves. But if you can put caves on and set sinkholes to "None" and somehow still go into the caves, that would be an edge-case my solution doesn't handle. Otherwise, it should work fine. You'd also have to use this check somewhere: if TheWorld.worldprefab == "cave" then Edited February 29, 2020 by Ultroman 2 Link to comment https://forums.kleientertainment.com/forums/topic/116087-is-there-an-easy-if-statement-to-check-if-a-world-has-caves-enabled-edit-the-answer-is-yes-solution-inside/#findComment-1311799 Share on other sites More sharing options...
Desblat Posted February 29, 2020 Share Posted February 29, 2020 I feel like there must be a world tag for that. I just put that into mod config. Also I make crafting reciped that don't strickly require caves. Btw you should keep in mind that some people use cave content on surface mods. 1 Link to comment https://forums.kleientertainment.com/forums/topic/116087-is-there-an-easy-if-statement-to-check-if-a-world-has-caves-enabled-edit-the-answer-is-yes-solution-inside/#findComment-1311849 Share on other sites More sharing options...
Hornete Posted February 29, 2020 Share Posted February 29, 2020 6 hours ago, Ultroman said: This is probably not the most optimal way, but do this after the whole world is done generating: use FindEntity to search for "cave_entrance" entities, There may be a problem with that, I'm pretty sure the cave entrance entities ALWAYS exist. The reason for this is if a player wants to add caves to a non caves world it makes the process a little easier. They're invisible in non caves world but they do exist iirc Link to comment https://forums.kleientertainment.com/forums/topic/116087-is-there-an-easy-if-statement-to-check-if-a-world-has-caves-enabled-edit-the-answer-is-yes-solution-inside/#findComment-1311855 Share on other sites More sharing options...
Ultroman Posted February 29, 2020 Share Posted February 29, 2020 3 hours ago, Hornete said: There may be a problem with that, I'm pretty sure the cave entrance entities ALWAYS exist. The reason for this is if a player wants to add caves to a non caves world it makes the process a little easier. They're invisible in non caves world but they do exist iirc Ah, well there goes that solution. I searched the game code for an hour, and didn't find anything. Just a lot of ways to see if your CURRENT world is a cave, which is pretty useless. 1 Link to comment https://forums.kleientertainment.com/forums/topic/116087-is-there-an-easy-if-statement-to-check-if-a-world-has-caves-enabled-edit-the-answer-is-yes-solution-inside/#findComment-1311883 Share on other sites More sharing options...
CarlZalph Posted February 29, 2020 Share Posted February 29, 2020 (edited) On 2/29/2020 at 7:20 AM, Hornete said: There may be a problem with that, I'm pretty sure the cave entrance entities ALWAYS exist. The reason for this is if a player wants to add caves to a non caves world it makes the process a little easier. They're invisible in non caves world but they do exist iirc This is correct, and the code they use to detect it is: if not TheWorld.ismastersim then return inst end if TheNet:GetServerIsClientHosted() and not (TheShard:IsMaster() or TheShard:IsSecondary()) then --On non-sharded servers we'll make these vanish for now, but still generate them So by logic, I would surmise that being able to detect if the world does have shards (caves/etc), then invert that to become: if TheWorld.ismastersim and not (TheNet:GetServerIsClientHosted() and not (TheShard:IsMaster() or TheShard:IsSecondary())) then -- Shards are on end Edited December 24, 2020 by CarlZalph IsSlave changed to IsSecondary during some update. 4 Link to comment https://forums.kleientertainment.com/forums/topic/116087-is-there-an-easy-if-statement-to-check-if-a-world-has-caves-enabled-edit-the-answer-is-yes-solution-inside/#findComment-1311886 Share on other sites More sharing options...
Scrimbles Posted March 1, 2020 Author Share Posted March 1, 2020 (edited) 13 hours ago, CarlZalph said: This is correct, and the code they use to detect it is: if not TheWorld.ismastersim then return inst end if TheNet:GetServerIsClientHosted() and not (TheShard:IsMaster() or TheShard:IsSlave()) then --On non-sharded servers we'll make these vanish for now, but still generate them So by logic, I would surmise that being able to detect if the world does have shards (caves/etc), then invert that to become: if TheWorld.ismastersim and not (TheNet:GetServerIsClientHosted() and not (TheShard:IsMaster() or TheShard:IsSlave())) then -- Shards are on end This definitely works for fully generated and active server, tested it with both caved/caveless and a print("") for each and it worked. Unfortunately, when used in modworldgenmain, TheWorld comes up as nil, same with TheNet and TheShard. Doing ~= nil checks for any of them doesn't do anything, and adding GLOBAL. before them still comes up as nil. Perhaps world generation is done before the server is put online, in which case I think I might be out of luck for this solution Edited March 1, 2020 by Ogrecakes 1 Link to comment https://forums.kleientertainment.com/forums/topic/116087-is-there-an-easy-if-statement-to-check-if-a-world-has-caves-enabled-edit-the-answer-is-yes-solution-inside/#findComment-1312080 Share on other sites More sharing options...
CarlZalph Posted March 1, 2020 Share Posted March 1, 2020 10 hours ago, Ogrecakes said: This definitely works for fully generated and active server, tested it with both caved/caveless and a print("") for each and it worked. Unfortunately, when used in modworldgenmain, TheWorld comes up as nil, same with TheNet and TheShard. Doing ~= nil checks for any of them doesn't do anything, and adding GLOBAL. before them still comes up as nil. Perhaps world generation is done before the server is put online, in which case I think I might be out of luck for this solution Mmm, unfortunate. What's the end goal for this check? Perhaps there may be a different approach to what you're wanting done instead of lurking in modworldgenmain. Link to comment https://forums.kleientertainment.com/forums/topic/116087-is-there-an-easy-if-statement-to-check-if-a-world-has-caves-enabled-edit-the-answer-is-yes-solution-inside/#findComment-1312187 Share on other sites More sharing options...
Scrimbles Posted March 1, 2020 Author Share Posted March 1, 2020 1 hour ago, CarlZalph said: Mmm, unfortunate. What's the end goal for this check? Perhaps there may be a different approach to what you're wanting done instead of lurking in modworldgenmain. The mod involves spawning in a set piece for players who are on a server without caves. It attaches a timer to the toadstool for a whole set of events, but I want to make sure that the toadstool can be put in caveless worlds too. Currently its just a toggleable setting in the mod menu, and that works fine, but it would be much more ideal for it to be automatic. I will probably look into the server retrofitting for when the oasis was added to the game, or maybe find a way to detect the swamp (where the setpiece spawns) and just spawn in the required prefab randomly after the world starts. 1 Link to comment https://forums.kleientertainment.com/forums/topic/116087-is-there-an-easy-if-statement-to-check-if-a-world-has-caves-enabled-edit-the-answer-is-yes-solution-inside/#findComment-1312209 Share on other sites More sharing options...
Fluxistence Posted October 10, 2021 Share Posted October 10, 2021 Update: TheShard:IsSlave() has been replaced with TheShard:IsSecondary(). Link to comment https://forums.kleientertainment.com/forums/topic/116087-is-there-an-easy-if-statement-to-check-if-a-world-has-caves-enabled-edit-the-answer-is-yes-solution-inside/#findComment-1503378 Share on other sites More sharing options...
Lyraedan Posted January 30, 2023 Share Posted January 30, 2023 On 2/29/2020 at 4:10 PM, Ultroman said: Ah, well there goes that solution. I searched the game code for an hour, and didn't find anything. Just a lot of ways to see if your CURRENT world is a cave, which is pretty useless. I have encountered a situation where I need to check if the CURRENT world the player is in is a cave. You wouldn't happen to remember this? Link to comment https://forums.kleientertainment.com/forums/topic/116087-is-there-an-easy-if-statement-to-check-if-a-world-has-caves-enabled-edit-the-answer-is-yes-solution-inside/#findComment-1619629 Share on other sites More sharing options...
Merkyrrie Posted February 1, 2023 Share Posted February 1, 2023 On 1/30/2023 at 5:17 PM, Lyraedan said: I have encountered a situation where I need to check if the CURRENT world the player is in is a cave. You wouldn't happen to remember this? In case you still need it, TheWorld:HasTag("cave") 1 Link to comment https://forums.kleientertainment.com/forums/topic/116087-is-there-an-easy-if-statement-to-check-if-a-world-has-caves-enabled-edit-the-answer-is-yes-solution-inside/#findComment-1619852 Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now