Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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);

		}
		
}

 

  • 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

  • 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?

  • 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.

 

image.png.d6fa96993c89675f0900057c36e744b0.png

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.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.