Jump to content

Recommended Posts

Posted

So, I've been working with creating a custom entity and that's going fairly well. Unfortunately, I cannot find the necessary methods to spawn entities procedurally during world generation. All of the methods that Minecraft uses to register entities in vanilla are protected methods, so I can't use those. I also have struggled to find reputable source code to take a look at on GitHub for registering entities to world spawning for 1.15.2, as it seems to be very different from previous versions. Is it possible that someone could refer me to a repo that does it elegantly or just to the necessary methods I should use?

 

Thanks 

Posted

Take a look at the method getSpawns in the Biome class. You can use that to add your entity into the spawnlist for each biomes.

Posted
  On 4/23/2020 at 12:34 AM, Ilyemu said:

Take a look at the method getSpawns in the Biome class. You can use that to add your entity into the spawnlist for each biomes.

Expand  

Yes, like lIyemu said, you can use the getSpawns method for every biome. You can iterate through them all by using java stream.

 

You can then to .add and add your entity. Allow me to show you an example:

 

package <idk, whatever package name you want>;

import <wherever you keep static references to your entities>;
import net.minecraft.entity.EntityClassification;
import net.minecraft.world.biome.Biome.SpawnListEntry;
import net.minecraftforge.registries.ForgeRegistries;

public class ModEntitySpawn {

	public static void spawnMobs() {

		ForgeRegistries.BIOMES.getValues().stream()
          		//This is just some randsom filtering but do whatever you want her, or dont filter at all 
          		//if you want your entity to appear anywhere.
				.filter(biome -> biome.getRegistryName().toString().equals("minecraft:mushroom_fields")
						|| biome.getRegistryName().toString().equals("minecraft:mushroom_fields_field_shore"))
				
          		//this is the main dish
				.forEach(biome -> {
					biome.getSpawns(EntityClassification.<depends on what you want>)
                      		//min and max refer to number of entities in a group.
							.add(new SpawnListEntry(<static reference to your entity>, <weight>, <min>, <max>));
				});

	}

}

 

Then you have to register it in your event subscriber:

 

@SubscribeEvent
public static void onLoadSpawns (FMLCommonSetupEvent event) {
	ModEntitySpawn.spawnMobs();
}

 

 

I hope this is helpful! good luck!

  • Like 1
Posted
  On 4/23/2020 at 2:39 AM, chubel10 said:

 

 


		ForgeRegistries.BIOMES.getValues().stream()
          		//This is just some randsom filtering but do whatever you want her, or dont filter at all 
          		//if you want your entity to appear anywhere.
				.filter(biome -> biome.getRegistryName().toString().equals("minecraft:mushroom_fields")
						|| biome.getRegistryName().toString().equals("minecraft:mushroom_fields_field_shore"))
				

 

Expand  

Instead of doing checks via their registry name, maybe you can try using their registered biome instance, should avoid the problem of mismatch string in the future.

  • Like 1
  • 1 year later...
Posted

Been hopping around the forums lately and can't really get a concrete answer on how to make your custom entity spawn in a particular biome. The code I have registers the entity placement using EntitySpawnPlacementRegistry.register() and adds a new SpawnListEntry to all biomes, for testing purposes, and is then put in a FMLCommonSetupEvent event. However, when I launch the game, I see no entities spawn even though I have it to where it should spawn in all biomes. Below is the code that I have. Also please excuse any bad formatting :) All help is appreciated!

Note: The SpawnListEntry I used uses the same values that a Minecraft Sheep does besides the entity of course.

EventSpawnRocky.java

public class EventSpawnRocky 
{
    @SubscribeEvent
    public static void spawnRocky(FMLCommonSetupEvent event)
    {
        DeferredWorkQueue.runLater(new Runnable() {

            @Override
            public void run() {
                ForgeRegistries.BIOMES.getValues().stream()
                .forEach(
                        biome -> 
                        {
                            List<Biome.SpawnListEntry> creatures = biome.getSpawns(EntityClassification.CREATURE);
                            creatures.add(new SpawnListEntry(ModEntities.rocky, 12, 4, 4));
                        });
            }}
                );
    }
}

MainModClass - Things we care about in setup_common, which is a FMLCommonSetupEvent

		DeferredWorkQueue.runLater(new Runnable()
		{
			@Override
			public void run() 
			{
				EntitySpawnPlacementRegistry.register(ModEntities.rocky,
						EntitySpawnPlacementRegistry.PlacementType.ON_GROUND,
						Heightmap.Type.MOTION_BLOCKING_NO_LEAVES,
						EntityRocky::spawnConditions);
			}
		}); 

and

MinecraftForge.EVENT_BUS.register(EventSpawnRocky.class);

spawnConditions from EntityRocky.java - I have it returning true for now.

	public static boolean spawnConditions(EntityType<EntityRocky> rocky, IWorld world, SpawnReason reason, BlockPos blockPos, Random rand) 
	{
		return true;
	}
  • Guest locked this topic
Guest
This topic is now closed to further replies.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • wait, i just did that. why didn't it work? also it's the same. help me!!!!
    • Culprit has been located! It was Tough As Nails + (plus) which was among one of the mods *added* before re-entering, in an attempt to improve compatibility. It, for some reason or another, did not want to work!
    • "You can either try to load it with only the vanilla data pack ("safe mode"), or go back to the title screen and fix it manually." Hello! I encountered this error just now while attempting to re-enter my world for the first time. Notably, no mods were removed before encountering this error and, while being able to find this error elsewhere on the internet, in my scenario it is seemingly caused by a specific mod, of which I cannot isolate. Things I have tried: - Enter "Safe Mode" (fails) - Remove datapacks (no change) - Reverted to old save data (no change) Here is the server log: https://mclo.gs/9vJQEfN I use Modrinth mod loader so please let me know how to share my mod list, and if it is needed.
    • So, i'm hosting (or attempting to host) a port-forwarded modded server for 1.12.2. There's quite a few mods in this pack, but they all run and have no compatibility issues (besides something causing the game to crash if you go fullscreen, a problem ive given up trying to identify or fix). It can run on 6gb of ram or less, and works fine in singleplayer. All of my friends that want to join have the exact same mod/config/game setup as I do (I personally helped them set everything up). Just to be safe, we've all allocated 12 gigabytes of RAM to the installation, and I've also allocated 12GB to the server itself. I am able to join with no issue and it runs fine. However, when they try to join, it gets stuck in the 'logging in' screen before their game becomes unresponsive. When they close it, it gives them the exit code 805306369, which usually means not enough RAM, but this cant be the case. On my screen, in the server, it shows them joining, and then disconnecting, so I dont think its a port-forwarding issue. They can all run it just fine in singleplayer as well. The annoying bit about this particular issue is that it generates no crash log. Does anyone have any suggestions? Thanks! Here is my debug log, and his, starting from the same place. MINE: [132647] [Netty Client IO #5INFO] [FML] Attempting connection with missing mods [ctm, fusion] at SERVER 132653.817 [132653] [Client threadINFO] [minecraftGuiConnecting] Connecting to 0, 25565 132654.682 [132654] [Netty Client IO #9INFO] [STDOUT] [xaero.common.core.transformer.ClassNodeTransformertransform29] Transforming class brz net.minecraft.client.network.NetHandlerPlayClient 132654.684 [132654] [Netty Client IO #9INFO] [STDOUT] [xaero.map.core.transformer.ClassNodeTransformertransform29] Transforming class net.minecraft.client.network.NetHandlerPlayClient 132654.764 [132654] [Netty Client IO #9INFO] [FML] Server protocol version 2 132654.777 [132654] [Netty Client IO #9INFO] [FML] Attempting connection with missing mods [ctm, fusion] at SERVER 132656.193 [132656] [Client threadINFO] [FML] Injecting existing registry data into this client instance 132659.081 [132659] [Client threadINFO] [FML] Applying holder lookups 132659.082 [132659] [Client threadINFO] [FML] Holder lookups applied 132659.092 [132659] [Netty Client IO #9INFO] [FML] [Netty Client IO #9] Client side modded connection established HIS: [13:12:16] [Netty Client IO #0/INFO] [FML]: Attempting connection with missing mods [ctm, fusion] at SERVER 13:12:25.597 [13:12:25] [Client thread/INFO] [minecraft/GuiConnecting]: Connecting to (my IP address and the server port 25565) 13:12:26.805 [13:12:26] [Netty Client IO #1/INFO] [STDOUT]: [xaero.common.core.transformer.ClassNodeTransformer:transform:29]: Transforming class brz net.minecraft.client.network.NetHandlerPlayClient 13:12:26.808 [13:12:26] [Netty Client IO #1/INFO] [STDOUT]: [xaero.map.core.transformer.ClassNodeTransformer:transform:29]: Transforming class net.minecraft.client.network.NetHandlerPlayClient 13:12:26.936 [13:12:26] [Netty Client IO #1/INFO] [FML]: Server protocol version 2 13:12:27.114 [13:12:27] [Netty Client IO #1/INFO] [FML]: Attempting connection with missing mods [ctm, fusion] at SERVER 13:12:27.480 [13:12:27] [Client thread/INFO] [FML]: Injecting existing registry data into this client instance 13:12:30.669 [13:12:30] [Client thread/INFO] [FML]: Applying holder lookups 13:12:30.671 [13:12:30] [Client thread/INFO] [FML]: Holder lookups applied 13:13:04.700 Process crashed with exit code -805306369 P.S - Both mods "CTM" and "FUSION" are present in both our folders so idk what that's about.
    • Please read the FAQ (link is orange banner at top of page), and post logs as described there, to an external site such as https://mclo.gs  
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.