Posted May 25, 20205 yr 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() { super.registerAttributes(); this.getAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(1D); this.getAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.26F); } }
May 25, 20205 yr Author 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
May 25, 20205 yr Author 2 hours ago, diesieben07 said: You have to put your entity type instance there. Missile m1 = new Missile(ModEntityTypes.MISSILE_ENTITY.get(), this.world); This doesn't give me an error in eclipse, but crashes the game. What do I put there?
May 25, 20205 yr Author 2 minutes ago, diesieben07 said: Show the crash.... https://pastebin.com/uh6LSbhy https://pastebin.com/99JDmpeK First is crash, second is the class file which attempts to spawn the entity
May 25, 20205 yr Author 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!
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.