Jump to content

[1.15.1] How to make a custom entity?


DragonITA

Recommended Posts

Hi, sorry for this late reply! I dont know exactly how to Java syntax work if a error was found. Lua Syntax will stop the script (here it is the .class or the .java) if a error was found then the code dont continue and i muss rerun the script in eclipse. This take some time. Ok, why i say this? I say this then i have a Problem with my custom BlockItem. I want first resolve this Problem and then show the code.

P.S.: I need a little bit of time to refind the code.

Edit: Resolved

Edited by DragonITA
P.S.

New in Modding? == Still learning!

Link to comment
Share on other sites

3 hours ago, DragonITA said:

Hi, sorry for this late reply! I dont know exactly how to Java syntax work if a error was found. Lua Syntax will stop the script (here it is the .class or the .java) if a error was found then the code dont continue and i muss rerun the script in eclipse. This take some time. Ok, why i say this? I say this then i have a Problem with my custom BlockItem. I want first resolve this Problem and then show the code.

P.S.: I need a little bit of time to refind the code.

Java is a static language. It has to compile before running. There must be no syntax errors.

However, it sounds like you are struggling with basic Java syntax. Please learn Java before making a mod, as not knowing Java will cause unnecessary confusions.

  • Like 1

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

Link to comment
Share on other sites

Thanks, i am trying to learn Java. I know a little bit the Heritage of the Java syntax. Here is on how i actualy make my entity (i have tried to find the Init Folder in the Vanilla Code to see hoz i should register my entities, but i cant find it. So I tried to watch a video of HarryTalks with version 1.14.4 to go further. But I get an error, have tried to solve it with my current knowledge, but I can't get it right.) Here is my current Code:

 

package mod.dragonita.fantasymod.entities;

import mod.dragonita.fantasymod.init.FantasyModEntities;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.goal.LookAtGoal;
import net.minecraft.entity.ai.goal.LookRandomlyGoal;
import net.minecraft.entity.ai.goal.PanicGoal;
import net.minecraft.entity.ai.goal.WaterAvoidingRandomWalkingGoal;
import net.minecraft.entity.passive.horse.HorseEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.world.World;

public class UnicornEntity extends HorseEntity{
	
	@SuppressWarnings("unchecked")
	public UnicornEntity(EntityType<? extends HorseEntity> type, World worldIn) {
		super((EntityType<? extends HorseEntity>) FantasyModEntities.UNICORN_ENTITY, worldIn);
	}

	protected void registerGoals()
	{
		this.goalSelector.addGoal(1, new PanicGoal(this, 1.2D));
		this.goalSelector.addGoal(6, new WaterAvoidingRandomWalkingGoal(this, 0.7D));
		this.goalSelector.addGoal(7, new LookAtGoal(this, PlayerEntity.class, 6.0F));
		this.goalSelector.addGoal(8, new LookRandomlyGoal(this));
	}
	
	protected void registerAttributes()
	{
		super.registerAttributes();
		this.getAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(10.0d);
		this.getAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(5.0d);
	}
}

 

package mod.dragonita.fantasymod.init;

import mod.dragonita.fantasymod.Main;
import mod.dragonita.fantasymod.entities.UnicornEntity;
import net.minecraft.entity.EntityClassification;
import net.minecraft.entity.EntityType;
import net.minecraft.item.Item;
import net.minecraft.item.SpawnEggItem;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.Biomes;
import net.minecraft.world.biome.Biome.SpawnListEntry;
import net.minecraftforge.event.RegistryEvent;

public class FantasyModEntities {
	
	public static EntityType<?> UNICORN_ENTITY = EntityType.Builder.create(UnicornEntity::new, EntityClassification.CREATURE).build(Main.MODID + ":unicorn_entity").setRegistryName(new ResourceLocation(Main.MODID, "unicorn_entity"));
	
	public static void registerEntitySpawnEggs(final RegistryEvent.Register<Item> event)
	{
		event.getRegistry().registerAll
		(
			ModItems.UNICORN_ENTITY_EGG = registerEntitySpawnEgg(UNICORN_ENTITY, 0xf0f0f0, 0xdf51f5, "unicorn_entity_egg")	
		);
	}
	
	public static void registerEntityWorldSpawns()
	{
		registerEntityWorldSpawn(UNICORN_ENTITY, Biomes.PLAINS, Biomes.JUNGLE, Biomes.BEACH);
	}
	
	public static Item registerEntitySpawnEgg(EntityType<?> type, int color1, int color2, String name)
	{
		SpawnEggItem item = new SpawnEggItem(type, color1, color2, new Item.Properties().group(ModItemGroups.RAINBOW_MOD_GROUP));
		item.setRegistryName(new ResourceLocation(Main.MODID, name));
		return item;
	}
	
	public static void registerEntityWorldSpawn(EntityType<?> entity, Biome... biomes)
	{
		for(Biome biome : biomes)
		{
			if(biome != null)
			{
				biome.getSpawns(entity.getClassification()).add(new SpawnListEntry(entity, 20, 1, 10));
			}
		}
	}
}

 

 

package mod.dragonita.fantasymod.client.renders;

import mod.dragonita.fantasymod.client.models.UnicornEntityModel;
import mod.dragonita.fantasymod.entities.UnicornEntity;
import net.minecraft.client.renderer.entity.EntityRenderer;
import net.minecraft.client.renderer.entity.EntityRendererManager;
import net.minecraft.client.renderer.entity.LivingRenderer;
import net.minecraft.entity.passive.horse.AbstractHorseEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.fml.client.registry.IRenderFactory;

@OnlyIn(Dist.CLIENT)
public class UnicornEntityRender extends LivingRenderer<AbstractHorseEntity, UnicornEntityModel>
{
	public UnicornEntityRender(EntityRendererManager manager)
	{
		super(manager, new UnicornEntityModel(0f), 0f);
	}

	public static final ResourceLocation unicorn = new ResourceLocation("fantasymod:textures/entity/unicorn_entity.png");
	
	public static class RenderFactory implements IRenderFactory<UnicornEntity>
	{

		@Override
		public EntityRenderer<? super UnicornEntity> createRenderFor(EntityRendererManager manager)
		{
			return new UnicornEntityRender(manager);
		}
		
	}

	@Override
	public ResourceLocation getEntityTexture(AbstractHorseEntity entity) {
		return unicorn;
	}
}

 

package mod.dragonita.fantasymod.client.models;

import net.minecraft.client.renderer.entity.model.HorseModel;
import net.minecraft.entity.passive.horse.AbstractHorseEntity;

public class UnicornEntityModel extends HorseModel<AbstractHorseEntity>
{

	public UnicornEntityModel(float p_i51065_1_) {
		super(p_i51065_1_);
	}

}

 

Im have troubles here:

package mod.dragonita.fantasymod.client.renders;

import mod.dragonita.fantasymod.entities.UnicornEntity;
import mod.dragonita.fantasymod.init.FantasyModEntities;
import mod.dragonita.fantasymod.init.ModEntities;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.passive.horse.HorseEntity;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.fml.client.registry.RenderingRegistry;

@OnlyIn(Dist.CLIENT)
public class FantasyRenderRegistry
{
	@SuppressWarnings("unchecked")
	public static void registryEntityRenders()
	{
		RenderingRegistry.registerEntityRenderingHandler((EntityType<? extends HorseEntity>) FantasyModEntities.UNICORN_ENTITY, new UnicornEntityRender.RenderFactory()); //Here i have my errors message
	}
}

I am getting the following error message: 

The method registerEntityRenderingHandler(EntityType<T>, IRenderFactory<? super T>) in the type RenderingRegistry is not applicable for the arguments (EntityType<capture#2-of ? extends HorseEntity>, UnicornEntityRender.RenderFactory)

I already say thank you for all your help.

New in Modding? == Still learning!

Link to comment
Share on other sites

4 hours ago, diesieben07 said:

Do not create registry entries in a static initializer. Use the DeferredRegister class.

I am new in Java and Modding. What is a registry entrie?

4 hours ago, diesieben07 said:

Do not use @OnlyIn.

Why?

4 hours ago, diesieben07 said:

The error message says that the arguments you are trying to pass to registerEntityRenderingHandler are not valid. Check the method parameters and their types and make sure your arguments match.

I arleady made this, but i am new and i dont find what i made wrong. Its want a entity type and i have arleady write my entity type, but it have still continue to send me this error message. I tried, but it dont work.

New in Modding? == Still learning!

Link to comment
Share on other sites

6 hours ago, DragonITA said:

I am new in Java and Modding. What is a registry entrie?

Any implementation of IForgeRegistry (blocks, items, etc). These should be created during the appropiate registry event.

 

6 hours ago, DragonITA said:

I arleady made this, but i am new and i dont find what i made wrong. Its want a entity type and i have arleady write my entity type, but it have still continue to send me this error message. I tried, but it dont work.

This is basic Java syntax. If you are struggling with this then you need to learn Java before making a mod. This is not a Java forum.

Edited by DavidM
  • Like 1

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

Link to comment
Share on other sites

On 1/5/2020 at 1:50 AM, DavidM said:

This is basic Java syntax. If you are struggling with this then you need to learn Java before making a mod. This is not a Java forum.

Ok, thanks. What is a EntityType? Is this my Entity or something else? Auf jedenfalls arbeite ich gerade um dieses Problem lösen können.

 

On 1/4/2020 at 2:38 PM, diesieben07 said:

Use the DeferredRegister class.

Should i replace the RenderingRegistry with the DeferredRegister?

 

Ok, I know that I'm annoying you with my questions, and I also tried to look at some vanilla code, but all I need is this: In which folder is the Entity RenderRegistry? I'm looking for a solution to my problem right now, and as it is written in the tips from @DavidM: The best way to learn is to look at the vanilla code. So I've been thinking and want to look at a classic code. I'm just now noticing how many things I have to work on, so I want to finish this topic first and then improve myself, because it must be really annoying to try to help someone who doesn't know anything.

 

 

Thanks for reading it.

Edited by DragonITA
I switched Tom with DavidM, no idea why I wrote Tom.

New in Modding? == Still learning!

Link to comment
Share on other sites

7 minutes ago, diesieben07 said:

EntityType is just that: A type of entity, such as "creeper" or "zombie".

It simply is the Type of my Entity, my Entity in others word. Can i use my Entity like a EntityType?

Edit: I was so stupid, the solution was before my eyes for the whole time. I already made an EntityType, just had to import it.

Edited by DragonITA
I found a solution to my first problem.

New in Modding? == Still learning!

Link to comment
Share on other sites

@diesieben07, i'm sorry, I was just checking to make sure. 

Ok, so if I understood and read well then I should implement the IForgeRegistryEntry in a class. The (hopefully last) question: Where should I implement it, in which class? I don't want to take any risk, but if I have read it then I have to implement it in my entity class. Am I right?

New in Modding? == Still learning!

Link to comment
Share on other sites

On 1/4/2020 at 2:38 PM, diesieben07 said:

The error message says that the arguments you are trying to pass to registerEntityRenderingHandler are not valid. Check the method parameters and their types and make sure your arguments match.

I resolved it.

New in Modding? == Still learning!

Link to comment
Share on other sites

33 minutes ago, diesieben07 said:

You would know this if you had read the (already linked) documentation:

On 1/5/2020 at 1:54 PM, diesieben07 said:

I read it, only dont have see the difference between client physical side and client logical side.

this is what my IDE shows me (Tried to look at a vanilla code):

@net.minecraftforge.api.distmarker.OnlyIn(value=net.minecraftforge.api.distmarker.Dist.CLIENT)

I know it's exactly the same. But I don't understand that, even with the link you've already given. I just find it hard to understand that, and except for these four differences I don't understand at all. Why do you say I can't do it this way, but the vanilla code does exactly that? Could you explain it to me (And yes, I repeat, I read the link and still don't understand it)?

New in Modding? == Still learning!

Link to comment
Share on other sites

 

2 minutes ago, diesieben07 said:

However the code is not identical of course, some things (like GUIs or world rendering) only exist on the client. These things are marked by forge using @OnlyIn to signify "I only found this in distribution X".

(Similarly some things may only exist in the dedicated server distribution, but is going to be a much, much shorter list that is largely irrelevant for modding).

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

21 minutes ago, diesieben07 said:

A more modern name for physical side is "distribution".

 

This is the physical client (client distribution):
image.png.0820c9f02aa62ed957151d303e846c1c.png

When you start a single-player world it starts a logical client and a logical server (the integrated server). The distribution remains client, even for the integrated server. You don't suddenly have a dedicated server running.

When you connect to a server it starts a logical client.

 

This is the physical server (server distribution):

image.png.83f15c573a349cbf20abd8690109f69b.png

It only contains one logical side: The server. The distribution is always server.

 

Well, it definitely exists.

 

@OnlyIn is a forge thing. Vanilla does not have this.

During setup, forge merges the minecraft client jar and the server jar together (the two distributions, see the images above if you don't know the difference) to create one codebase.

However the code is not identical of course, some things (like GUIs or world rendering) only exist on the client. These things are marked by forge using @OnlyIn to signify "I only found this in distribution X".

Wow, thanks for that answer. Now I understand everything except for one point: Why can't I use @OnlyIn and what should I replace it with (the docs is really outdated soon and I don't know what to use now. Strange, when I pressed ctrl + spacebar in the IDE, then normal white comes up with a whole bunch of variables/functions I can use, but I haven't seen any FMLEnvironment.Dist)? If it is, then how should I use it? Usually my IDE tells me, but I don't see anything.

New in Modding? == Still learning!

Link to comment
Share on other sites

  • 3 weeks later...
On 1/8/2020 at 4:45 PM, DragonITA said:

I resolved it.

Can you please show your solution or tell me the name of the official java-class, that calls "registerEntityRenderingHandler" to register entity renderers?

I don´t know how to find this file, if i don´t know it´s name..

Edited by Drachenbauer
  • Like 1
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

    • I'm using Modrinth as a launcher for a forge modpack on 1.20.1, and can't diagnose the issue on the crash log myself. Have tried repairing the Minecraft instillation as well as removing a few mods that have been problematic for me in the past to no avail. Crash log is below, if any further information is necessary let me know. Thank you! https://paste.ee/p/k6xnS
    • Hey folks. I am working on a custom "Mecha" entity (extended from LivingEntity) that the player builds up from blocks that should get modular stats depending on the used blocks. e.g. depending on what will be used for the legs, the entity will have a different jump strength. However, something unexpected is happening when trying to override a few of LivingEntity's functions and using my new own "Mecha" specific fields: instead of their actual instance-specific value, the default value is used (0f for a float, null for an object...) This is especially strange as when executing with the same entity from a point in the code specific to the mecha entity, the correct value is used. Here are some code snippets to better illustrate what I mean: /* The main Mecha class, cut down for brevity */ public class Mecha extends LivingEntity { protected float jumpMultiplier; //somewhere later during the code when spawning the entity, jumpMultiplier is set to something like 1.5f //changing the access to public didn't help @Override //Overridden from LivingEntity, this function is only used in the jumpFromGround() function, used in the aiStep() function, used in the LivingEntity tick() function protected float getJumpPower() { //something is wrong with this function //for some reason I can't correctly access the fields and methods from the instanciated entity when I am in one of those overridden protected functions. this is very annoying LogUtils.getLogger().info(String.valueOf(this.jumpMultiplier))) //will print 0f return this.jumpMultiplier * super.getJumpPower(); } //The code above does not operate properly. Written as is, the entity will not jump, and adding debug logs shows that when executing the code, the value of this.jumpMultiplier is 0f //in contrast, it will be the correct value when done here: @Override public void tick() { super.tick(); //inherited LivingEntity logic //Custom logic LogUtils.getLogger().info(String.valueOf(this.jumpMultiplier))) //will print 1.5f } } My actual code is slightly different, as the jumpMuliplier is stored in another object (so I am calling "this.legModule.getJumpPower()" instead of the float), but even using a simple float exactly like in the code above didn't help. When running my usual code, the object I try to use is found to be null instead, leading to a crash from a nullPointerException. Here is the stacktrace of said crash: The full code can be viewed here. I have found a workaround in the case of jump strength, but have already found the same problem for another parameter I want to do, and I do not understand why the code is behaving as such, and I would very much like to be able to override those methods as intended - they seemed to work just fine like that for vanilla mobs... Any clues as to what may be happening here?
    • Please delete post. Had not noticed the newest edition for 1.20.6 which resolves the issue.
    • https://paste.ee/p/GTgAV Here's my debug log, I'm on 1.18.2 with forge 40.2.4 and I just want to get it to work!! I cant find any mod names in the error part and I would like some help from the pros!! I have 203 mods at the moment.
  • Topics

×
×
  • Create New...

Important Information

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