Jump to content

Spawning an entity


Recommended Posts

So I'm still sorta lost on how to spawn an entity. I'm pretty sure i can use world.addentity to spawn it, but first I guess I need to make it using something like this:

Missile m1 = new Missile(???, world);

My question is what do I put instead of the three question marks? I tried putting null, and it just crashed my game when it should have started. Here is my missile class.

package com.sonniccub.racismmod.entities;

import java.util.Random;

import com.sonniccub.racismmod.racismmod;
import com.sonniccub.racismmod.init.ModEntityTypes;

import net.minecraft.entity.EntityType;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.monster.MonsterEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.world.Explosion;
import net.minecraft.world.World;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus;
import net.minecraftforge.event.entity.living.LivingHurtEvent;

@Mod.EventBusSubscriber(modid = racismmod.MOD_ID, bus = Bus.FORGE)
public class Missile extends MonsterEntity {

	public Missile(EntityType<? extends MonsterEntity> type, World worldIn) {
		super(type, worldIn);
		protected void registerAttributes() {



Link to comment
Share on other sites

Just now, diesieben07 said:

You need to register a custom entity type. Its a registry entry, just like blocks or items.

package com.sonniccub.racismmod.init;

import com.sonniccub.racismmod.racismmod;
import com.sonniccub.racismmod.entities.Cop;
import com.sonniccub.racismmod.entities.Missile;

import net.minecraft.entity.EntityClassification;
import net.minecraft.entity.EntityType;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.RegistryObject;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;

public class ModEntityTypes {
	public static final DeferredRegister<EntityType<?>> ENTITY_TYPES = new DeferredRegister<>(ForgeRegistries.ENTITIES, racismmod.MOD_ID); 
	public static final RegistryObject<EntityType<Cop>> COP_ENTITY = ENTITY_TYPES.register("cop", 
			() -> EntityType.Builder.<Cop>create(Cop::new, EntityClassification.MONSTER)
			.size(1f, 2f)
			.build(new ResourceLocation(racismmod.MOD_ID, "cop").toString()));
	public static final RegistryObject<EntityType<Missile>> MISSILE_ENTITY = ENTITY_TYPES.register("missile", 
			() -> EntityType.Builder.<Missile>create(Missile::new, EntityClassification.MONSTER)
			.size(1f, 1f)
			.build(new ResourceLocation(racismmod.MOD_ID, "missile").toString()));

Is this what you mean? I can /summon it into the game, but I just don't know what to put there, everything I've tried gives me an error

Link to comment
Share on other sites

43 minutes ago, diesieben07 said:

You never assign anything to the world field, therefor it is null.

Please either get a decent IDE that will warn you about this (see below) or if that is already the case, please adhere to the warnings your IDE gives you.



Ok it seems to be working better now. Still something I need to mess with, but it actually works now. Thank you!

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.

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.


  • Create New...

Important Information

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