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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • At result, change: "id": "minecraft:iron_ingot" to "item": "minecraft:iron_ingot"
    • Thank all of you so much you are fucking psychos for doing this thank you so much :)
    • i have this custome crossbow i made  it autoloads after the first shoot is nice and all    but i don't like how when aiming it begins missaligned a little to the right then it slowly trembles a few and aligning whit the crosshair   this is coze the bow animation id vertical and made this crosbow rotate 90degrees      public UseAnim getUseAnimation(ItemStack p_40678_) {         return UseAnim.BOW;     } why i dont use UseAnim.CROSSBOW  for a crossbow  you see  the vainilla crossbow from the CrossbowItem.class uses a tag to know if its pulling to load an arrow or to shoot  private static final String TAG_CHARGED = "Charged"; i copy this methods to mi crossbow and set to UseAnim.CROSSBOW  but dont seems to do nothing     public static boolean isCharged(ItemStack p_40933_) {       CompoundTag compoundtag = p_40933_.getTag();       return compoundtag != null && compoundtag.getBoolean("Charged");    }    public static void setCharged(ItemStack p_40885_, boolean p_40886_) {       CompoundTag compoundtag = p_40885_.getOrCreateTag();       compoundtag.putBoolean("Charged", p_40886_);    } inside LivingEntity.class there is this   .getUseItemRemainingTicks()  thats used to calculate the bow pulling but seems like theres no .setUseItemRemainingTicks()   hoping to be understandable          i need to override the way the pulling animation is calculated to set it to the max from the beginning just for the sake of aesthetics             
    • So I'm able to download modpacks from curse forge get the into the minecraft mod folder but once the upload starts on the launcher it get's to the end and just won't progress does any one know what the issue might be I've uninstalled and reinstalled everything but I keep having the same problem.
    • { "type": "minecraft:crafting_shaped", "pattern": [ "i i", " R ", "i i" ], "key": { "i": { "item": "minecraft:iron_ingot" }, "R": { "item": "minecraft:redstone" } }, "result": { "id": "minecraft:iron_ingot" } } I'm having a problem where I've created a simple crafting recipe that takes in redstone dust and 4 iron ingots and returns an iron ingot (just for testing purposes). I have the file in my resouces/data/(modid)/recipes directory. However, the recipe does not work and I get no output when actually using a crafting table. Any help would be useful.
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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