Jump to content

Register Entities in Forge 1.14


DevTech

Recommended Posts

 

Hey, I'm trying to register an entity but the builder is painting it in red can someone help me?

EntityTypes Class:

package de.krokoyt.element.entity;

import de.krokoyt.element.Element.RegistryEvents;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityClassification;
import net.minecraft.entity.EntityType;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus;
import net.minecraftforge.registries.IForgeRegistry; 

@EventBusSubscriber(bus = Bus.MOD)
public class EntityTypes{ 
      
    public static EntityType<?> vampireball;
    
    @SubscribeEvent
    public static void register(RegistryEvent.Register<EntityType<?>> e) {
        IForgeRegistry<EntityType<?>> registry = e.getRegistry();
        vampireball = EntityType.Builder.create(Vampire::new, EntityClassification.CREATURE).build(""); 
        
        vampireball.setRegistryName("element", "vampire");
        registry.register(vampireball);
    }

}

 

Entity class:

package de.krokoyt.element.entity;

import de.krokoyt.element.Element;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.item.EnderPearlEntity;
import net.minecraft.entity.projectile.ProjectileItemEntity;
import net.minecraft.entity.projectile.ThrowableEntity;
import net.minecraft.item.Item;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

public class Vampire extends ThrowableEntity{

    
    
    protected Vampire(EntityType<? extends ThrowableEntity> type, World world) {
        super(type, world);
    }

    protected Vampire(EntityType<? extends ThrowableEntity> type, LivingEntity livingEntityIn, World worldIn) {
        super(type, livingEntityIn, worldIn);
        // TODO Auto-generated constructor stub
    }

    @Override
    protected void onImpact(RayTraceResult result) {
        
        remove();
    }

    @Override
    protected void registerData() {
        
        
    }

    

}


 

Link to comment
Share on other sites

okay i have fixxed it but i have a another error when i summon the entity then say the game "Unable to summon entity"

Entity Class:

package de.krokoyt.element.entity;

import javax.annotation.Nonnull;

import de.krokoyt.element.Element;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.item.EnderPearlEntity;
import net.minecraft.entity.projectile.ProjectileItemEntity;
import net.minecraft.entity.projectile.ThrowableEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.network.IPacket;
import net.minecraft.util.DamageSource;
import net.minecraft.util.math.EntityRayTraceResult;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.fml.network.FMLPlayMessages;
import net.minecraftforge.fml.network.NetworkHooks;

public class Vampire 
     extends ProjectileItemEntity{

    private LivingEntity thrower;
    
    public Vampire(EntityType<? extends ProjectileItemEntity> type, World world) {super(type, world);}

    
    public Vampire(double x, double y, double z, World world) {
        super(Element.RegistryEvents.vampireentity, x, y, z, world);
       
      }
     
     public Vampire(World worldIn, LivingEntity throwerIn) {
          super(Element.RegistryEvents.vampireentity, throwerIn, worldIn);
          this.thrower = throwerIn;
       }
     
     public Vampire(FMLPlayMessages.SpawnEntity packet, World worldIn) {
         super(Element.RegistryEvents.vampireentity, worldIn);
     }

 
//    protected Vampire(EntityType<? extends ThrowableEntity> type, LivingEntity livingEntityIn, World worldIn) {
//        super(type, livingEntityIn, worldIn);
//        // TODO Auto-generated constructor stub
//    }
    
      
      @Nonnull
        protected Item func_213885_i() {
            // TODO Auto-generated method stub
            return Element.RegistryEvents.vampireball;
        }


    @Override
    protected void onImpact(RayTraceResult result) {
        if(!this.getEntity().world.isRemote) {
            if(result.getType() != null) {
                if(result.getType() == result.getType().ENTITY) {
                    Entity entity = ((EntityRayTraceResult)result).getEntity();
                    entity.attackEntityFrom(DamageSource.causeThornsDamage(this), 1F);
                    //SPAWN HEAL BALL
                }
            }
        }
        remove();
    }

    @Override
    protected void registerData() {
        
        
    }
    
    @Override
    public IPacket<?> createSpawnPacket() {
        // TODO Auto-generated method stub
        return NetworkHooks.getEntitySpawningPacket(this);
    }
    

    

    

}

 


Main class:

package de.krokoyt.element;

import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.entity.SpriteRenderer;
import net.minecraft.entity.EntityClassification;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.IProjectile;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.InterModComms;
import net.minecraftforge.fml.client.registry.RenderingRegistry;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.event.lifecycle.InterModEnqueueEvent;
import net.minecraftforge.fml.event.lifecycle.InterModProcessEvent;
import net.minecraftforge.fml.event.server.FMLServerStartingEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.IForgeRegistry;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import de.krokoyt.element.entity.Vampire;
import de.krokoyt.element.items.ElectricStaff;
import de.krokoyt.element.items.FireStaff;
import de.krokoyt.element.items.HealthStaff;
import de.krokoyt.element.items.Healthball;
import de.krokoyt.element.items.ItemBase;
import de.krokoyt.element.items.Vamireball;

import java.util.stream.Collectors;

import javax.annotation.Nonnull;

// The value here should match an entry in the META-INF/mods.toml file
@Mod("element")
public class Element
{
    // Directly reference a log4j logger.
    private static final Logger LOGGER = LogManager.getLogger();

    private final CommonProxy proxy = DistExecutor.runForDist(() -> ClientProxy::new, () -> CommonProxy::new);
    
    public Element() {
        // Register the setup method for modloading
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
        // Register the enqueueIMC method for modloading
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::enqueueIMC);
        // Register the processIMC method for modloading
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::processIMC);
        // Register the doClientStuff method for modloading
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff);

        // Register ourselves for server and other game events we are interested in
        MinecraftForge.EVENT_BUS.register(this);
    }

    private void setup(final FMLCommonSetupEvent event)
    {
        // some preinit code
        LOGGER.info("HELLO FROM PREINIT");
        LOGGER.info("DIRT BLOCK >> {}", Blocks.DIRT.getRegistryName());
    }

    private void doClientStuff(final FMLClientSetupEvent event) {
        // do something that can only be done on the client
        RenderingRegistry.registerEntityRenderingHandler(Vampire.class, render -> new SpriteRenderer(render, Minecraft.getInstance().getItemRenderer()));
        LOGGER.info("Got game settings {}", event.getMinecraftSupplier().get().gameSettings);
    }

    private void enqueueIMC(final InterModEnqueueEvent event)
    {
        // some example code to dispatch IMC to another mod
        InterModComms.sendTo("examplemod", "helloworld", () -> { LOGGER.info("Hello world from the MDK"); return "Hello world";});
    }

    private void processIMC(final InterModProcessEvent event)
    {
        // some example code to receive and process InterModComms from other mods
        LOGGER.info("Got IMC {}", event.getIMCStream().
                map(m->m.getMessageSupplier().get()).
                collect(Collectors.toList()));
    }
    // You can use SubscribeEvent and let the Event Bus discover methods to call
    @SubscribeEvent
    public void onServerStarting(FMLServerStartingEvent event) {
        // do something when the server starts
        LOGGER.info("HELLO from server starting");
    }

    // You can use EventBusSubscriber to automatically subscribe events on the contained class (this is subscribing to the MOD
    // Event bus for receiving Registry Events)
    @Mod.EventBusSubscriber(bus=Mod.EventBusSubscriber.Bus.MOD)
    public static class RegistryEvents {
        
        public static ItemGroup tab = new CreativeTab();
        
        public static Item DarkStaff = new de.krokoyt.element.items.DarkStaff();
        public static Item ElectricStaff = new ElectricStaff();
        public static Item FireStaff = new FireStaff();
        public static Item HealStaff = new HealthStaff();
        
        public static final Item staff = new ItemBase("staff", 64, tab);
        public static final Item magicessense = new ItemBase("magicessence", 64, tab);
        
        public static final Item dark = new ItemBase("darkessense", 64, tab);
        public static final Item electrik = new ItemBase("electrikessense", 64, tab);
        public static final Item fire = new ItemBase("fireessense", 64, tab);
        public static final Item ice = new ItemBase("iceessense", 64, tab);
        public static final Item life = new ItemBase("lifeessense", 64, tab);
        public static final Item poison = new ItemBase("poisonessense", 64, tab);
        public static final Item water = new ItemBase("wateressense", 64, tab);
        public static final Item wind = new ItemBase("windessense", 64, tab);
         
        public static final Item vampireball = new Vamireball();
        public static final Item healthball = new Healthball();
        
        public static final SoundEvent MAGIC = (SoundEvent)(new SoundEvent(new ResourceLocation("element", "magic"))).setRegistryName("magic");
       
        @SubscribeEvent
        public static void registerSoundEvents(RegistryEvent.Register<SoundEvent> event) { event.getRegistry().register(MAGIC); }
        
        public static EntityType<Vampire> vampireentity = EntityType.Builder.<Vampire>create(Vampire::new, EntityClassification.MISC).setShouldReceiveVelocityUpdates(true).setCustomClientFactory(Vampire::new).setUpdateInterval(1).setTrackingRange(187).size(0.6F, 0.6F).build("element:vampire");

        
        @SubscribeEvent
        public static void registerEntity(RegistryEvent.Register<EntityType<?>> e) {
            IForgeRegistry<EntityType<?>> registry = e.getRegistry();

            
            vampireentity.setRegistryName("element", "vampire");
            registry.register(vampireentity);
        }
        
        @SubscribeEvent
        public static void onBlocksRegistry(final RegistryEvent.Register<Block> blockRegistryEvent) {
            // register a new block here
            LOGGER.info("HELLO from Register Block");
        }
        
        @SubscribeEvent
        public static void onItemRegistry(final RegistryEvent.Register<Item> e) {
            e.getRegistry().register(DarkStaff);
            e.getRegistry().register(ElectricStaff);
            e.getRegistry().register(FireStaff);
            e.getRegistry().register(HealStaff);
            e.getRegistry().register(staff);
            e.getRegistry().register(magicessense);
            
            e.getRegistry().register(dark);
            e.getRegistry().register(electrik);
            e.getRegistry().register(fire);
            e.getRegistry().register(ice);
            e.getRegistry().register(life);
            e.getRegistry().register(poison);
            e.getRegistry().register(water);
            e.getRegistry().register(wind);
            
            e.getRegistry().register(vampireball);
            e.getRegistry().register(healthball);
        }
    }
}

 

Edited by DevTech
Codes
Link to comment
Share on other sites

The Debug say:

 

[12:06:59] [Server thread/WARN] [minecraft/EntityType]: Exception loading entity:
net.minecraft.crash.ReportedException: Loading entity NBT
        at net.minecraft.entity.Entity.read(Entity.java:1678) ~[forge-1.14.4-28.1.1_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {pl:accesstransformer:B}
        at net.minecraft.entity.EntityType.lambda$loadEntityUnchecked$1(EntityType.java:428) ~[forge-1.14.4-28.1.1_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {}
        at net.minecraft.util.Util.acceptOrElse(Util.java:247) ~[forge-1.14.4-28.1.1_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {}
        at net.minecraft.entity.EntityType.loadEntityUnchecked(EntityType.java:425) ~[forge-1.14.4-28.1.1_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {}
        at net.minecraft.entity.EntityType.loadEntity(EntityType.java:473) ~[forge-1.14.4-28.1.1_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {}
        at net.minecraft.entity.EntityType.func_220335_a(EntityType.java:455) ~[forge-1.14.4-28.1.1_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {}
        at net.minecraft.command.impl.SummonCommand.summonEntity(SummonCommand.java:50) ~[forge-1.14.4-28.1.1_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {}
        at net.minecraft.command.impl.SummonCommand.lambda$register$1(SummonCommand.java:32) ~[forge-1.14.4-28.1.1_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {}
        at com.mojang.brigadier.CommandDispatcher.execute(CommandDispatcher.java:262) ~[brigadier-1.0.17.jar:?] {}
        at net.minecraft.command.Commands.handleCommand(Commands.java:199) ~[?:?] {}
        at net.minecraft.network.play.ServerPlayNetHandler.handleSlashCommand(ServerPlayNetHandler.java:1019) ~[?:?] {}
        at net.minecraft.network.play.ServerPlayNetHandler.processChatMessage(ServerPlayNetHandler.java:999) ~[?:?] {}
        at net.minecraft.network.play.client.CChatMessagePacket.processPacket(CChatMessagePacket.java:37) ~[?:?] {}
        at net.minecraft.network.play.client.CChatMessagePacket.processPacket(CChatMessagePacket.java:8) ~[?:?] {}
        at net.minecraft.network.PacketThreadUtil.lambda$checkThreadAndEnqueue$0(PacketThreadUtil.java:19) ~[?:?] {}
        at net.minecraft.util.concurrent.TickDelayedTask.run(TickDelayedTask.java:20) [?:?] {}
        at net.minecraft.util.concurrent.ThreadTaskExecutor.run(ThreadTaskExecutor.java:140) [?:?] {pl:accesstransformer:B}
        at net.minecraft.util.concurrent.RecursiveEventLoop.run(RecursiveEventLoop.java:22) [?:?] {}
        at net.minecraft.util.concurrent.ThreadTaskExecutor.driveOne(ThreadTaskExecutor.java:110) [?:?] {pl:accesstransformer:B}
        at net.minecraft.server.MinecraftServer.func_213205_aW(MinecraftServer.java:726) [?:?] {pl:accesstransformer:B}
        at net.minecraft.server.MinecraftServer.driveOne(MinecraftServer.java:720) [?:?] {pl:accesstransformer:B}
        at net.minecraft.util.concurrent.ThreadTaskExecutor.driveUntil(ThreadTaskExecutor.java:123) [?:?] {pl:accesstransformer:B}
        at net.minecraft.server.MinecraftServer.runScheduledTasks(MinecraftServer.java:706) [?:?] {pl:accesstransformer:B}
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:650) [?:?] {pl:accesstransformer:B}
        at java.lang.Thread.run(Thread.java:748) [?:1.8.0_221] {}
Caused by: java.lang.NullPointerException
        at net.minecraft.network.datasync.EntityDataManager.set(EntityDataManager.java:123) ~[forge-1.14.4-28.1.1_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {}
        at net.minecraft.entity.projectile.ProjectileItemEntity.func_213884_b(ProjectileItemEntity.java:38) ~[forge-1.14.4-28.1.1_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {pl:runtimedistcleaner:A}
        at net.minecraft.entity.projectile.ProjectileItemEntity.readAdditional(ProjectileItemEntity.java:76) ~[forge-1.14.4-28.1.1_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {pl:runtimedistcleaner:A}
        at net.minecraft.entity.Entity.read(Entity.java:1663) ~[forge-1.14.4-28.1.1_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {pl:accesstransformer:B}
        ... 24 more
[12:06:59] [Client thread/INFO] [minecraft/NewChatGui]: [CHAT] Unable to summon entity

 

Vampire Entity class:

 

package de.krokoyt.element.entity;

import javax.annotation.Nonnull;

import de.krokoyt.element.Element;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.item.EnderPearlEntity;
import net.minecraft.entity.projectile.ProjectileItemEntity;
import net.minecraft.entity.projectile.ThrowableEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.network.IPacket;
import net.minecraft.util.DamageSource;
import net.minecraft.util.math.EntityRayTraceResult;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.fml.network.FMLPlayMessages;
import net.minecraftforge.fml.network.NetworkHooks;

public class Vampire 
 	extends ProjectileItemEntity{

	private LivingEntity thrower;
	
	public Vampire(EntityType<? extends ProjectileItemEntity> type, World world) {super(type, world);}

	
	public Vampire(double x, double y, double z, World world) {
	    super((EntityType<? extends ProjectileItemEntity>) Element.RegistryEvents.vampireentity, x, y, z, world);
	   
	  }
	 
	 public Vampire(World worldIn, LivingEntity throwerIn) {
	      super((EntityType<? extends ProjectileItemEntity>) Element.RegistryEvents.vampireentity, throwerIn, worldIn);
	      this.thrower = throwerIn;
	   }
	 
	 public Vampire(FMLPlayMessages.SpawnEntity packet, World worldIn) {
		 super((EntityType<? extends ProjectileItemEntity>) Element.RegistryEvents.vampireentity, worldIn);
	 }

 
//	protected Vampire(EntityType<? extends ThrowableEntity> type, LivingEntity livingEntityIn, World worldIn) {
//		super(type, livingEntityIn, worldIn);
//		// TODO Auto-generated constructor stub
//	}
	
	  
	  @Nonnull
		protected Item func_213885_i() {
			// TODO Auto-generated method stub
			return Element.RegistryEvents.vampireball;
		}


	@Override
	protected void onImpact(RayTraceResult result) {
		if(!this.getEntity().world.isRemote) {
			if(result.getType() != null) {
				if(result.getType() == result.getType().ENTITY) {
					Entity entity = ((EntityRayTraceResult)result).getEntity();
					entity.attackEntityFrom(DamageSource.causeThornsDamage(this), 1F);
					//SPAWN HEAL BALL
				}
			}
		}
		remove();
	}

	@Override
	protected void registerData() {
		
		
	}
	
	@Override
	public IPacket<?> createSpawnPacket() {
		// TODO Auto-generated method stub
		return NetworkHooks.getEntitySpawningPacket(this);
	}
	

	

	

}

 

Edited by DevTech
Code
Link to comment
Share on other sites

    @SubscribeEvent
        public static void registerModels(FMLClientSetupEvent event) { 
            RenderingRegistry.registerEntityRenderingHandler(Vampire.class, render -> new SpriteRenderer(render, Minecraft.getInstance().getItemRenderer())); 
            RenderingRegistry.registerEntityRenderingHandler(Heal.class, render -> new SpriteRenderer(render, Minecraft.getInstance().getItemRenderer())); 
            RenderingRegistry.registerEntityRenderingHandler(Bubble.class, render -> new SpriteRenderer(render, Minecraft.getInstance().getItemRenderer())); 
            }

Here render i all entitys

 

Edited by DevTech
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.