OS | IDE | Forge | JDK | Lang |
---|---|---|---|---|
Windows10 1809 17763.593 | IntelliJ IDEA 2019 | 1.14.3-27.0.15 | 1.8.0_202 | Java |
When I made it compatible with 1.13.2 to 1.14.2, the render of my own Entity was not displayed and I stumbled, so I summarized it. I hope it will be helpful. Entity registration is the same as 1.13.2. → [Forge] How to register your own Entity and Entity Render in 1.13.2 The source code will be explained based on the TorchBowMod of my own mod as before.
The symptom is that the render and entity are linked on the client side as shown below, but they are not displayed.
RenderResist
RenderingRegistry.registerEntityRenderingHandler(EntityTorch.class, RenderTorch::new);
In 1.13.2 this was displayed properly.
First of all, I suspected that the Entity registration was not successful. However, since the processing such as collision detection performed by Entity was working normally, it seems that Entity registration is normal.
After doing various searches, I found the cause and countermeasures.
First of all, when registering an Entity with EntityType, until now,
TORCH_ENTITY = EntityType.Builder.<EntityTorch>create(EntityTorch::new, EntityClassification.MISC)
Like, I passed the instance directly to the create method, but in 1.14.2 I had to pass the instance with the newly added setCustomClientFactory
instead of this instance.
First, modify the EntityType mentioned earlier.
TORCH_ENTITY = EntityType.Builder.<EntityTorch>create(EntityClassification.MISC)
.setCustomClientFactory(EntityTorch::new)//Add this line
It is like this.
It may be abbreviated in the lambda expression and it may be difficult to understand, but with this alone, an error will occur if the Entity does not have a constructor that meets the expected value of <net.minecraftforge.fml.network.FMLPlayMessages.SpawnEntity, World>
. I will.
An easy-to-understand lambda expression inside setCustomClientFactory
? It looks like this.
.setCustomClientFactory((FMLPlayMessages.SpawnEntity spawnEntity, World world) -> new EntityTorch(spawnEntity,world))
Creating a constructor
public EntityTorch(FMLPlayMessages.SpawnEntity packet, World worldIn) {
super(TORCH_ENTITY, worldIn);
}
I think you should pass your own Entity Type with super like this. Perhaps.
And in addition to adding a constructor to the Entity class, it seems that you need to override createSpawnPacket
.
@Override
public IPacket<?> createSpawnPacket() {
return NetworkHooks.getEntitySpawningPacket(this);
}
It feels like it's overriding like this and returning its own spawn packet. For the time being, the render is displayed like this.
If you are suffering from the same phenomenon because you have stumbled upon this specification change, please refer to it. Also, if you have any mistakes, please leave an edit request or comment.