Jump to content

[SOLVED][1.13.2] Custom Minecart Entity saved and rendered as a Vanilla Minecart


psoftware

Recommended Posts

Hi everyone,
I'm new to Forge mod programming and I'm trying to write a simple mod to implement a new type of minecart.
Actually, most of the work is done: I have defined a new item (ItemUnstoppableMinecart) and a new entity (EntityUnstoppableMinecart), extended from EntityMinecartEmpty class.
I am able to place the custom entity using the item, and all the overridden methods are correcly called.

However I'm having two issues which I think are related:
- I'm not able to associate a Render class to the custom entity, which is still rendered as a vanilla one
- Carts get saved as vanilla minecarts, so when the game is restarted (single player), they become vanilla carts

I checked the map saves using NBTExplorer, basically each custom cart gets saved with "id:minecraft:minecart".

All the source code is on GitHub:
https://github.com/psoftware/unstopping-minecarts

What am I missing? Can you help me?
Thank you very much

Edited by psoftware
Link to comment
Share on other sites

1. Although you've created your own new entity that extends the minecart, you did not write custom methods of reading and writing to NBT tags, which are called when the entity saves to/loads from disk. Therefore, when your entity is being saved to NBT, it uses the saving method from the vanilla minecart entity, which saves your "unstoppable minecart" as a "vanilla minecart".

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

Thank you for the reply.
I've already tried to find NBT write methods from EntityMinecraft and EntityMinecraftEmpty classes, but there are only two methods:
 

protected void readAdditional(NBTTagCompound compound) {
    if (compound.getBoolean("CustomDisplayTile")) {
      this.setDisplayTile(NBTUtil.readBlockState(compound.getCompound("DisplayState")));
      this.setDisplayTileOffset(compound.getInt("DisplayOffset"));
    }
}

protected void writeAdditional(NBTTagCompound compound) {
    if (this.hasDisplayTile()) {
      compound.setBoolean("CustomDisplayTile", true);
      compound.setTag("DisplayState", NBTUtil.writeBlockState(this.getDisplayTile()));
      compound.setInt("DisplayOffset", this.getDisplayTileOffset());
    }
}


None of them sets the id field. It seems that it is done by the Entity class through the writeUnlessRemoved() method:

public final String getEntityString() {
    EntityType<?> entitytype = this.getType();
    ResourceLocation resourcelocation = EntityType.getId(entitytype);
    return entitytype.isSerializable() && resourcelocation != null ? resourcelocation.toString() : null;
}

public boolean writeUnlessRemoved(NBTTagCompound compound) {
    String s = this.getEntityString();
    if (!this.removed && s != null) {
      compound.setString("id", s);
      this.writeWithoutTypeId(compound);
      return true;
    } else {
      return false;
    }
}


Now the question is: why getType() returns EntityMinecart instead of my class? Maybe I messed up something with the entity registration?
 

 

Link to comment
Share on other sites

Thank you, I managed to solve both the problems.
Now my rendering class is registered on FML CommonSetup event and cart is correctly rendered (but it was hard to find the event due to the forge 1.13 changes).

For the registering problem, actually there was a constructor but it wasn't public. However it was not the problem but you gave me a good hint: the main issue was that I was extending the wrong minecart class, I had to extend EntityMinecart instead of EntityMinecartEmpty. EntityMinecartEmpty was "hiding" the EntityType parameter passed to Entity class constructor, setting it to EntityType.MINECART.

I've pushed the working solution on git for those who need it.

Many thanks

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.



×
×
  • Create New...

Important Information

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