Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Spawning Custom Mobs at Night (or whenever)


Draco18s
 Share

Recommended Posts

How would I go about registering a mob to be spawned under certain conditions (typically at night, but for the mob I have in mind, I probably want them to spawn during the day)?

 

Right now I have them showing up on chunk generation (because that I know where it occurs) but I'm not sure how to go about spawning mobs over time and maintaining a reasonable count (given that individually my mob is fairly tough, spawning one in a chunk that already has one--or in an adjacent chunk--might be a little unfair on the player).

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Forge Events is how I'd do it

 

Not needed.

 

What you do, is that when you call the EntityRegistry.addSpawn(); method, you sawn as a EnumCreatureType.CREATURE (I think thats what it is, I know it's EnumCreatureType though) for spawning during the day, and EnumCreatureType.MONSTER (once again, same issue as before) for during the night. Then there is EnumCreatureType.WATER. If that isn't self explanatory then I don't know what is :/

 

But yeah, the EntityRegistry.addSpawn(); is where you can register if it spawns or not and such.

 

As for the spawning only one in a chunk, there is a method in the Entity class that sets that I think.

 

And for the adjacent chunks.... Well, have fun with that :D

I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes.

 

I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there xD

Link to comment
Share on other sites

What you do, is that when you call the EntityRegistry.addSpawn(); method, you sawn as a EnumCreatureType.CREATURE (I think thats what it is, I know it's EnumCreatureType though) for spawning during the day, and EnumCreatureType.MONSTER (once again, same issue as before) for during the night. Then there is EnumCreatureType.WATER. If that isn't self explanatory then I don't know what is :/

 

But yeah, the EntityRegistry.addSpawn(); is where you can register if it spawns or not and such.

 

As for the spawning only one in a chunk, there is a method in the Entity class that sets that I think.

 

Awesome, thanks!

 

And yeah, there's a function in the entity class that says how many can spawn per chunk.  Couldn't figure out how it was used (because I was lacking the EntityRegistry part) but I did at least alter the numbers to what I'd like.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

MORE ADVANCED TRICKIER QUESTION ASK:

 

What if I want to limit these mob spawns to additional dimensions and only additional dimensions (i.e. not vanilla) and not during the night (i.e. I don't care about light level)?

 

Conditions:

 

1) Arbitrary light level: daytime spawning should be valid--night may never actually occur, day may never actually occur, but mobs should still spawn.

2) Specific dimensions of unknown dimension ID: which dimensions are not known at mod registration time because the dimensions don't exist yet.

3) If the player leaves a valid dimension and enters a non-valid dimension, mob spawning should be disabled (and vice versa).1

4) Biome is irrelevant (some modifiers yes--such as mob A not spawning where it is cold, mob B not spawning where it is hot, etc.2--but not "oh mob B only spawns in Jungles" like ocelots).

 

Example:

Spawn the mob when "Jungles in Dimension with Non-Vanilla Property Y."  Not "Jungles" nor "Dimension N."

 

1Through another mod's API I have a class that has two functions--onChunkPopulate and tick--that get called for each chunk in a valid dimension (the first one being chunk creation the second being chunk update) and access to a few events for when the player changes dimension via this mod's methods,3 though I am unsure if I can determine from the world object if it is a valid spawning dimension or not: I do not appear to have access to the custom WorldSavedData class that would hold those properties.  At the moment I am using this class to manually spawn mobs by checking each chunk as it ticks for existing mobs and distance from the nearest player, although this is imperfect.

2Due to additional biome mods, like Biomes o' Plenty, I want my mob to spawn even in those biomes.  I know there's a BiomeEvent...event and I could catch and store the additional IDs based on various parameters that I chose, but that's not the issue.  It's figuring out when and where to register the spawning and then invalidate it!

3And there are other mods that permit dimensional travel that I do not (necessarily) have access to!  IC2's teleporter, vanilla nether portal, end portal, twilight forest portal...

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

MORE ADVANCED TRICKIER QUESTION ASK:

 

What if I want to limit these mob spawns to additional dimensions and only additional dimensions (i.e. not vanilla) and not during the night (i.e. I don't care about light level)?

 

Conditions:

 

1) Arbitrary light level: daytime spawning should be valid--night may never actually occur, day may never actually occur, but mobs should still spawn.

2) Specific dimensions of unknown dimension ID: which dimensions are not known at mod registration time because the dimensions don't exist yet.

3) If the player leaves a valid dimension and enters a non-valid dimension, mob spawning should be disabled (and vice versa).1

4) Biome is irrelevant (some modifiers yes--such as mob A not spawning where it is cold, mob B not spawning where it is hot, etc.2--but not "oh mob B only spawns in Jungles" like ocelots).

 

Example:

Spawn the mob when "Jungles in Dimension with Non-Vanilla Property Y."  Not "Jungles" nor "Dimension N."

 

1Through another mod's API I have a class that has two functions--onChunkPopulate and tick--that get called for each chunk in a valid dimension (the first one being chunk creation the second being chunk update) and access to a few events for when the player changes dimension via this mod's methods,3 though I am unsure if I can determine from the world object if it is a valid spawning dimension or not: I do not appear to have access to the custom WorldSavedData class that would hold those properties.  At the moment I am using this class to manually spawn mobs by checking each chunk as it ticks for existing mobs and distance from the nearest player, although this is imperfect.

2Due to additional biome mods, like Biomes o' Plenty, I want my mob to spawn even in those biomes.  I know there's a BiomeEvent...event and I could catch and store the additional IDs based on various parameters that I chose, but that's not the issue.  It's figuring out when and where to register the spawning and then invalidate it!

3And there are other mods that permit dimensional travel that I do not (necessarily) have access to!  IC2's teleporter, vanilla nether portal, end portal, twilight forest portal...

 

Ahh.... I see some of your problems... I think. I am not quite getting some of these problems :/ So If you could try explaining them in a bit more detailed way?? Then I might be able to read it the way you want it to be read.

I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes.

 

I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there xD

Link to comment
Share on other sites

Ahh.... I see some of your problems... I think. I am not quite getting some of these problems :/ So If you could try explaining them in a bit more detailed way?? Then I might be able to read it the way you want it to be read.

 

I'm working with the Mystcraft API.

 

Part of that API is a world generator interface, it's effectively the same as a vanilla IWorldGenerator, but Mystcraft controls when it is used (and there are often multiple per dimension).  Each one of these files is the implementation of a single effect.  An effect can range from "add these blocks to the world" to "cause potion effects on mobs at random."

 

I want to spawn custom mobs as part of one of these effects.  Mystcraft does not currently do any kind of mob spawn control.  So I am currently doing AABB checks over a wide area (easily 65x65x128) every 80 or so ticks, and counting how many mobs of a given type are found, and if below a certain threshold, spawn more.

 

I would much rather hand control over to Minecraft's spawning system, but I have no way of knowing when to invalidate the spawning rules.  I only know when the player is in the dimension them dimension is loaded.  I do not have access to the load or unload events (at least, not in any more detail than the Forge events) nor do I have access to the list of effects a given dimension has (specifically: XCompWiz doesn't want symbols to be aware of each other: observable properties are fine ("what is the average terrain height?" "what is the sea level?") but not the specific symbols used to get there ("Flat terrain" "nether terrain" etc.).

 

So a number of things can be inferred from looking at these aggregate properties, but outside of the IWorldGenerator class, I have no way of knowing if an active dimension has the property I desire (nor does the spawn registry limit dimensions!  Imagine multiplayer where I could enable/disable the spawning based on the property I don't have access to: one player goes to the valid dimension and the player in the overworld sees my mobs spawn at night!  This is not desirable!).

 

So, I need to spawn my mobs...

1) Any time, day or night

2) Specific, but unknown, dimension ID or IDs

3) No biome restrictions

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

So, I need to spawn my mobs...

1) Any time, day or night

 

Thats fairly easy. Just call the EntityRegistry.addSpawn(); twice, once with the mob as EnumCreatureType.CREATURE, and the other as EnumCreatureType.MONSTER. That will spawn it as a monster (night) and creature (day).

 

2) Specific, but unknown, dimension ID or IDs

 

Couldn't this be achieved by checking if the player is in the dimension needed? (or do you need the dimension ID still?)

If this is possible, then you could spawn it in a dimension specific biome. (I assume that the dimension biomes do not spawn in the overworld, and only in the dimension?)

 

3) No biome restrictions

 

I believe that cannot be achieved with vanilla code...

I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes.

 

I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there xD

Link to comment
Share on other sites

2) Specific, but unknown, dimension ID or IDs

 

Couldn't this be achieved by checking if the player is in the dimension needed? (or do you need the dimension ID still?)

If this is possible, then you could spawn it in a dimension specific biome. (I assume that the dimension biomes do not spawn in the overworld, and only in the dimension?)

 

The problem arises when trying to determine what dimension number that is.  Followed by what object is doing the checking assuming I knew?  The mob itself?

And your assumption is wrong. :P  Mystcraft says "what biomes would you like?" and gives you a list.  All vanilla biomes are valid (and so are all mod biomes).  I can, in fact, make a world that checkerboards between Sky and Hell.

 

3) No biome restrictions

 

I believe that cannot be achieved with vanilla code...

 

Other than calling addSpawn for all biomes...which means I need an event listener to listen for mod biomes...

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Other than calling addSpawn for all biomes...which means I need an event listener to listen for mod biomes...

 

I think that using the biomeList (the list of all the biomes that are available, including modded ones), you could check to see what ID's are used, and then (somehow as there is no method that I can find that returns the name of the biome) get the name of the biome. Then, using that getName() method or whatever you are using to get it, print out the ID of the biome, and the name of the corresponding ID. After obtaining that information, you could then read through and find the biomes you needed....

 

And if you are just wanting to spawn a mob in one biome only, its like this:

EntityRegistry.addSpawn(EntityToSpawn.class, weightedProb, min, max, typeOfCreature, BiomeGenBase.nameOfBiome);

 

or, for a modded biome:

EntityRegistry.addSpawn(EntityToSpawn.class, weightedProb, min, max, typeOfCreature, WhereYourBiomeVariablesAreKept.nameOfBiome);

I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes.

 

I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there xD

Link to comment
Share on other sites

Other than calling addSpawn for all biomes...which means I need an event listener to listen for mod biomes...

 

I think that using the biomeList (the list of all the biomes that are available, including modded ones), you could check to see what ID's are used, and then (somehow as there is no method that I can find that returns the name of the biome) get the name of the biome. Then, using that getName() method or whatever you are using to get it, print out the ID of the biome, and the name of the corresponding ID. After obtaining that information, you could then read through and find the biomes you needed....

 

Something like that.

 

Less of an issue than restriction dimension.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

I am still not getting what you mean by restricting dimension. Do you mean restricting it so that the mob can only exist inside that dimension?

I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes.

 

I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there xD

Link to comment
Share on other sites

Do you mean restricting it so that the mob can only exist inside that dimension?

 

Yes.

 

The mob should be able to change dimensions if forced (via teleportation effects, such as nether portals) but should not spawn there.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

You could probably do a check like that inside the actual entity. Basically, you have a method that will set the entity to dead if it is not in a dimension. Then you use the good 'ole spawn method to spawn it in the biome you want. Then it can only exist in that dimension... Another way would be to look through gast code. They can only exist in the nether right? Or is it just the hell biome????

I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes.

 

I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there xD

Link to comment
Share on other sites

You could probably do a check like that inside the actual entity. Basically, you have a method that will set the entity to dead if it is not in a dimension. Then you use the good 'ole spawn method to spawn it in the biome you want. Then it can only exist in that dimension...

 

Meaning I'd have to store a list of valid dimension IDs.  Grumble grumble.  Rather than being able to look at empirical world properties.

 

Another way would be to look through gast code. They can only exist in the nether right? Or is it just the hell biome????

 

Hell biome.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Quote

Another way would be to look through gast code. They can only exist in the nether right? Or is it just the hell biome?

 

Hell biome.

 

Damn..... Well then. This will be fun :/

I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes.

 

I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there xD

Link to comment
Share on other sites

Damn..... Well then. This will be fun :/

 

I think you mean ‼Fun‼. ;)

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • In 1.16, LootModifierManager#deserializeModifier read: private IGlobalLootModifier deserializeModifier(ResourceLocation location, JsonElement element) { if (!element.isJsonObject()) return null; JsonObject object = element.getAsJsonObject(); ILootCondition[] lootConditions = GSON_INSTANCE.fromJson(object.get("conditions"), ILootCondition[].class); // For backward compatibility with the initial implementation, fall back to using the location as the type. // TODO: Remove fallback in 1.16 ResourceLocation serializer = location; if (object.has("type")) { serializer = new ResourceLocation(JSONUtils.getAsString(object, "type")); } return ForgeRegistries.LOOT_MODIFIER_SERIALIZERS.getValue(serializer).read(location, object, lootConditions); } Note the if(object.has(type")){} block, which is lacking from the 1.18 version of the class: private IGlobalLootModifier deserializeModifier(ResourceLocation location, JsonElement element) { if (!element.isJsonObject()) return null; JsonObject object = element.getAsJsonObject(); LootItemCondition[] lootConditions = GSON_INSTANCE.fromJson(object.get("conditions"), LootItemCondition[].class); ResourceLocation serializer = new ResourceLocation(GsonHelper.getAsString(object, "type")); return ForgeRegistries.LOOT_MODIFIER_SERIALIZERS.getValue(serializer).read(location, object, lootConditions); } So, the "value" tag is required now for loot modifiers... fine. I added this to my loot modifer json files when I kept getting NullPointerExceptions. But when I use a valid "value" tag I get: [15:27:02] [Render thread/ERROR]: Couldn't parse loot modifier examplemod:add_structure_loot java.lang.NullPointerException: Cannot invoke "net.minecraftforge.common.loot.GlobalLootModifierSerializer.read(net.minecraft.resources.ResourceLocation, com.google.gson.JsonObject, net.minecraft.world.level.storage.loot.predicates.LootItemCondition[])" because the return value of "net.minecraftforge.registries.IForgeRegistry.getValue(net.minecraft.resources.ResourceLocation)" is null at net.minecraftforge.common.loot.LootModifierManager.deserializeModifier(LootModifierManager.java:133) ~[forge-1.18-38.0.14_mapped_official_1.18-recomp.jar%2376%2382!:?] at net.minecraftforge.common.loot.LootModifierManager.lambda$apply$0(LootModifierManager.java:115) ~[forge-1.18-38.0.14_mapped_official_1.18-recomp.jar%2376%2382!:?] at java.util.ArrayList.forEach(ArrayList.java:1511) ~[?:?] at net.minecraftforge.common.loot.LootModifierManager.apply(LootModifierManager.java:113) ~[forge-1.18-38.0.14_mapped_official_1.18-recomp.jar%2376%2382!:?] at net.minecraftforge.common.loot.LootModifierManager.apply(LootModifierManager.java:54) ~[forge-1.18-38.0.14_mapped_official_1.18-recomp.jar%2376%2382!:?] My json file is: { "type": "chest", "conditions": [ { "condition": "forge:loot_table_id", "loot_table_id": "examplemod:chests/modstructure" } ] } I tried printing the contents of ForgeRegistries.LOOT_MODIFIER_SERIALIZERS to know which keys I can use, but got: [15:26:13] [modloading-worker-0/INFO]: Printing LOOT_MODIFER_SERIALIZERS [15:26:13] [modloading-worker-0/INFO]: Printed LOOT_MODIFER_SERIALIZERS Is this a bug, given 1.18 is new, or am I not using these classes right?
    • https://forge.gemwire.uk/wiki/Capabilities#Attaching_a_Capability do the same thing but with LevelChunk
    • Yeah never figured that one out. Going to look into that a little deeper now.
    • So I just need to attach my code (I posted above) to chunks?
    • Capabilities all work the same regardless of their attached type (except ItemStack ones which are a little special).
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.