Jump to content

[Forge 1.19] How to make my entities spawn naturally


Loris Accordino

Recommended Posts

Hello. I state that I am new to this forum, so I apologize for any errors in the title, description or guidelines or anything else.
I'm new to Java too.
I have a problem with a mod in Forge 1.19.

I have to make my entity (Raccoon) naturally spawn in any minecraft world with the mod applied.

I followed a tutorial and it worked in 1.18.2, but in 1.19, with the same code, it doesn't work, but it doesn't throw an exception, but it doesn't spawn the Raccoon in my world at all.

(I don't put the Raccoon code because I understand that it works and, I believe, that you shouldn't change that part)

The TutorialMod.java code (Forget the imports that have nothing to do with it, moreover the interested part is in the void clientSetup😞

package com.loris.tutorialmod;

import com.loris.tutorialmod.entity.ModEntityTypes;
import com.loris.tutorialmod.entity.client.RaccoonRenderer;
import com.loris.tutorialmod.entity.custom.RaccoonEntity;
import com.loris.tutorialmod.fluids.ModFluidTypes;
import com.loris.tutorialmod.init.BlockInit;
import com.loris.tutorialmod.init.ConfiguredFeatureInit;
import com.loris.tutorialmod.init.FluidInit;
import com.loris.tutorialmod.init.ItemInit;
import com.loris.tutorialmod.init.PlacedFeatureInit;
import com.loris.tutorialmod.init.SoundInit;

import net.minecraft.client.renderer.entity.EntityRenderers;
import net.minecraft.world.entity.SpawnPlacements;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.levelgen.Heightmap;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import software.bernie.example.registry.EntityRegistry;
import software.bernie.geckolib3.GeckoLib;

@Mod("tutorialmod")
public class TutorialMod {
	
	public static final String MOD_ID = "tutorialmod";
	
	public static final CreativeModeTab ANIMALS = new CreativeModeTab("animals") {
		@Override
		@OnlyIn(Dist.CLIENT)
		public ItemStack makeIcon() {
			return new ItemStack(ItemInit.RACCOON_SPAWN_EGG.get());
		}
	};
	
	
	@SuppressWarnings("removal")
	public TutorialMod() {
		IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus();
        
        GeckoLib.initialize();     
        ModEntityTypes.register(bus);
        EntityRegistry.ENTITIES.register(bus);     
        
		bus.addListener(this::clientSetup);
		
		MinecraftForge.EVENT_BUS.register(this);
	}
	
	private void clientSetup(final FMLClientSetupEvent event) {	
        EntityRenderers.register(ModEntityTypes.RACCOON.get(), RaccoonRenderer::new);
        
        SpawnPlacements.register(ModEntityTypes.RACCOON.get(),
                SpawnPlacements.Type.ON_GROUND,
                Heightmap.Types.MOTION_BLOCKING_NO_LEAVES,
                RaccoonEntity::checkAnimalSpawnRules);
    }
}

Any help is appreciated :)

Link to comment
Share on other sites

Hello. I tried to add what the link was asking for and I added the json file, but it doesn't work, on the contrary: it deletes every mob in my world.

These are the various files:

BiomeInit:

package com.loris.tutorialmod.init;

import com.loris.tutorialmod.ExampleBiomeModifier;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;

import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.levelgen.placement.PlacedFeature;
import net.minecraftforge.common.world.BiomeModifier;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;

public class BiomeInit {
	static DeferredRegister<Codec<? extends BiomeModifier>> BIOME_MODIFIER_SERIALIZERS =
		    DeferredRegister.create(ForgeRegistries.Keys.BIOME_MODIFIER_SERIALIZERS, "tutorialmod");

		  public static RegistryObject<Codec<ExampleBiomeModifier>> EXAMPLE_CODEC = BIOME_MODIFIER_SERIALIZERS.register("example", () ->
		    RecordCodecBuilder.create(builder -> builder.group(
		        // declare fields
		        Biome.LIST_CODEC.fieldOf("biomes").forGetter(ExampleBiomeModifier::biomes),
		        PlacedFeature.CODEC.fieldOf("feature").forGetter(ExampleBiomeModifier::feature)
		      // declare constructor
		      ).apply(builder, ExampleBiomeModifier::new)));
}

 

ExampleBiomeModifier:

package com.loris.tutorialmod;

import com.loris.tutorialmod.init.BiomeInit;
import com.mojang.serialization.Codec;

import net.minecraft.core.Holder;
import net.minecraft.core.HolderSet;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.levelgen.placement.PlacedFeature;
import net.minecraftforge.common.world.BiomeModifier;
import net.minecraftforge.common.world.ModifiableBiomeInfo.BiomeInfo.Builder;

public record ExampleBiomeModifier(HolderSet<Biome> biomes, Holder<PlacedFeature> feature) implements BiomeModifier
{
  public void modify(Holder<Biome> biome, Phase phase, Builder builder)
  {
    // add a feature to all specified biomes
    if (phase == Phase.ADD && biomes.contains(biome)) {
      
    }
  }

@Override
public Codec<? extends BiomeModifier> codec() {
	// TODO Auto-generated method stub
	return BiomeInit.EXAMPLE_CODEC.get();
}

@Override
public boolean equals(Object obj) {
	// TODO Auto-generated method stub
	return false;
}

@Override
public int hashCode() {
	// TODO Auto-generated method stub
	return 0;
}

@Override
public String toString() {
	// TODO Auto-generated method stub
	return null;
}
}

 

biome_modifier_serializers.json (I'm not sure it should be called that, is that the problem?):

{
  "type": "forge:add_spawns",
  "biomes": "#tutorialmod:is_overworld",
  "spawners":
  {
    "type": "tutorialmod:raccoon", // Type of mob to spawn
    "weight": 100, // int, spawn weighting
    "minCount": 1, // int, minimum pack size
    "maxCount": 4 // int, maximum pack size
  }
}


Could you help me? :)

Link to comment
Share on other sites

It looks like you are just copy/pasting code without understanding what it does.

Don't do this. Try to work out what you are doing at each step. Otherwise you will never get to the point where you can fix problems for yourself.

 

You have created and tried to registered your own biome modifier - but you don't show where you are BIOME_MODIFIER_SERIALIZERS.register() to the mod event bus?

 

You are not even using that modifier anyway, instead you are using the forge:addspawns biome modifier.

 

The name of the biome modifier json only has to be meaningful to you, but its location is important.

https://forge.gemwire.uk/wiki/Biome_Modifiers#Biome_Modifier_JSONs

 

Quote

"biomes": "#tutorialmod:is_overworld",

Unless you have created a biome tag with this name, I think you want #minecraft:is_overworld 

 

You probably have an error message about this in your run/logs/debug.log

Always check your log to look for errors before asking why things don't work.

You can always post the log here if you can't work out what an error means. But do try to figure it out for yourself first.

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.

Announcements



×
×
  • Create New...

Important Information

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