[Tutorial] Creating texture variations for entities (Custom Code) [1.17,1.18, 1.19.2]

Started by tetch_wolf on

Topic category: User side tutorials

Last seen on 19:16, 19. Apr 2024
Joined Mar 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
[Tutorial] Creating texture variations for entities (Custom Code) [1.17,1.18, 1.19.2]
Fri, 01/13/2023 - 00:29 (edited)

Before we start the tutorial, some warnings:

-This tutorial was made for versions between 1.17 and 1.19.2, so it not work on older generators like 1.12.2, 1.15 or 1.16

-This tutorial doesn't work with layers because mcreator doesn't support the use of variables in the layer method

-A big thank you to my friend Nate (NatePlays95#4509) for helping me with this tutorial, without him I wouldn't have been able to.


Hello!

What's up? I hope well

If you are here, it means that you want to create texture variations for your entities, but without having to create other entities with other textures.

in this detailed tutorial, you'll learn how to create texture variations to how to use them in procedures

 

Let's go!

Part 1: Creating texture variations

First of all and most obviously, lock your entity code

Lock the Code

 

 

 

 

Lock the Code

 

Now, we'll enter our entity code (not the render) and start injecting our magic mix

We will go where our entity is extended (monster entity, creature entity, tameable entity, etc.), and we will register a data entrie

Code

 

 

 

Let's record the following data entrie:
 

public static final EntityDataAccessor<Integer> VariantData = SynchedEntityData.defineId(CustomEntityEntity.class, EntityDataSerializers.INT);

In the end, the code should look like this:

code

you can register different entries with different names, but in this case, we use the name "VariantData"

 

after that, we will go to some instance of the entity, and we will finish registering our entrie

in my case, I decided to register at the end of the code

code

two spaces after the last "{"

so paste the following code:

	
@Override
	protected void defineSynchedData() {
		super.defineSynchedData();
		this.entityData.define(VariantData, 0);
	}

	public void setVariantData(int varIn) {
		this.entityData.set(VariantData, varIn);
	}

	public int getVariantData() {
		return this.entityData.get(VariantData);
	}

	public void addAdditionalSaveData(CompoundTag compound) {
		super.addAdditionalSaveData(compound);
		compound.putInt("VariantData", this.getVariantData());
	}

	public void readAdditionalSaveData(CompoundTag compound) {
		super.readAdditionalSaveData(compound);
		this.setVariantData(compound.getInt("VariantData"));
	}

Okay, we finished registering our variable, an addendum, to register other variables, it is necessary another method, I will bring it in a future part 2 of this tutorial

In the end, the code should look like this:

code

Click ctrl+w to organize the imports, and then go to import

import net.minecraft.server.commands.data.EntityDataAccessor;

and replace it with

import net.minecraft.network.syncher.EntityDataAccessor;

wrong import

right import

now, press ctrl+w again and save your entity code.

 

 Now, we'll edit the rendering

render

we'll go where the entity's texture is selected, and then we'll edit that part

ResourceLocation

Then replace 

return new ResourceLocation("yourmodid:textures/your_texture.png")

with:

[YourEntityName]Entity _variant = (YourEntityNameEntity) entity;
                        return new ResourceLocation("modid:textures/yourentitytexture_" + String.valueOf(_variant.getVariantData()) + ".png");

in my case, it looked like this:

New Resource Location

save your entity's code, and now we'll create a procedure to select the entity's texture

Create a procedure assigned to the "On Initial Entity Spawn" trigger

trigger

create a local variable in the procedure with the same name registered in the entity code

Procedure

 

 first code snippet:

((YourEntityEntity) entity).getVariantData()

second code snippet:

((YourEntityEntity) entity).setVariantData((int)VariantData);

the number [60] in the procedure represents the amount of texture variations that the entity has

Save the procedure, and now we go to the final part of the tutorial

rename your textures so they look like this:

textures

zoi_ruby_1
zoi_ruby_2
etc..

thus, if the generated id is 2, the selected texture will be "zoi_ruby_2.png"

basically, this part of the procedure is responsible for generating an id, and each id is a texture

procedure

also

zoi_ruby_0= base texture

texture 0 will never be selected, so make 1 equal to 0

Let's test it in the game:
 Ruby

That's it, thanks for reading this far, I hope I helped you :>

Edited by tetch_wolf on Fri, 01/13/2023 - 00:29
Last seen on 23:44, 30. Jul 2023
Joined Dec 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Is this confirmed to be…
Tue, 02/08/2022 - 02:49

Is this confirmed to be working in 1.17 version, Im getting build errors?

Last seen on 23:44, 30. Jul 2023
Joined Dec 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
These are the errors I'm…
Tue, 02/08/2022 - 04:02

These are the errors I'm recieving back, I think it has to do with the local variable but im not sure. If anyone could help it would be much appreciated. 

> Task :compileJava FAILED
C:\Users\james\MCreatorWorkspaces\dreadful_dead\src\main\java\net\mcreator\fab\procedures\DireWolfVariantProcedure.java:37: error: ')' expected if (entity instanceof DireWolfEntity) {if ((((DireWolfEntity.CustomEntity) entity).getVariant());==0)) {Variant = Math.ceil(3*Math.random());((DireWolfEntity.CustomEntity) entity).setVariant((int)Variant);
^
C:\Users\james\MCreatorWorkspaces\dreadful_dead\src\main\java\net\mcreator\fab\procedures\DireWolfVariantProcedure.java:37: error: illegal start of expression if (entity instanceof DireWolfEntity) {if ((((DireWolfEntity.CustomEntity) entity).getVariant());==0)) {Variant = Math.ceil(3*Math.random());((DireWolfEntity.CustomEntity) entity).setVariant((int)Variant);
^
C:\Users\james\MCreatorWorkspaces\dreadful_dead\src\main\java\net\mcreator\fab\procedures\DireWolfVariantProcedure.java:37: error: ';' expected if (entity instanceof DireWolfEntity) {if ((((DireWolfEntity.CustomEntity) entity).getVariant());==0)) {Variant = Math.ceil(3*Math.random());((DireWolfEntity.CustomEntity) entity).setVariant((int)Variant);
^
3 errors
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 1s
1 actionable task: 1 executed

BUILD FAILED
Task completed in 4 seconds

 

Last seen on 15:55, 26. Jul 2022
Joined Feb 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Could you make a video…
Thu, 03/31/2022 - 19:28

Could you make a video showcasing this in more detail, and a clear walkthrough?

Last seen on 23:20, 19. Apr 2024
Joined Jul 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Does this work for blocks?
Mon, 04/04/2022 - 07:32

Does this work for blocks?

@Ali107 - Blocks use…
Mon, 04/04/2022 - 12:52

@Ali107 - Blocks use Blockstates, so it's kinda different thing to work on.

As for tutorial - big thank you for creator, this may be extremely helpful for my mod I'm working on right now ^^

Last seen on 02:44, 12. Apr 2022
Joined Apr 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Where can I find Set Local:…
Wed, 04/06/2022 - 03:42

Where can I find Set Local: Variant? I can't find it anywhere, and i've looked.

Last seen on 05:22, 5. Jun 2023
Joined Oct 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
is it posible to do the same…
Wed, 04/13/2022 - 21:01

is it posible to do the same but with the glow texture?

Last seen on 17:39, 15. Jan 2024
Joined Feb 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
> Task :compileJava C:\Users…
Sat, 04/16/2022 - 04:58

> Task :compileJava
C:\Users\Juani\MCreatorWorkspaces\165\src\main\java\net\mcreator\uwu\procedures\GoldfishtexturesProcedure.java:49: error: cannot find symbol ((GoldfishEntity.CustomEntity) entity).setVariant((int) Variant);
^
symbol: variable Variant
location: class net.mcreator.uwu.procedures.GoldfishtexturesProcedure
1 error
> Task :compileJava FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 3m 1s
1 actionable task: 1 executed

BUILD FAILED
Task completed in 3 minutes and 10 seconds

I have this error, can someone help me?

Last seen on 03:42, 14. Aug 2022
Joined Aug 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I need help:Executing Gradle…
Sun, 08/07/2022 - 04:08

I need help:
Executing Gradle task: build
Build info: MCreator 2022.1.20510, forge-1.16.5, 64-bit, 8079 MB, Windows 10, JVM 17.0.1, JAVA_HOME: C:\Program Files\Pylo\MCreator\jdk, started on: 2022-08-06-22:59:12

> Task :compileJava
C:\Users\SANTIAGO DAVID\MCreatorWorkspaces\hogwarts_school\src\main\java\net\mcreator\hogwartsschool\entity\IntegranteGryffindorEntity.java:93: error: cannot find symbol public static final DataParameter<Integer> VARIANT = EntityDataManager.createKey(CustomEntity.class, DataSerializers.VARIANT);
^
symbol: variable VARIANT
location: class net.minecraft.network.datasync.DataSerializers
1 error
> Task :compileJava FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 12s
1 actionable task: 1 executed

BUILD FAILED
Task completed in 20 seconds

Last seen on 21:43, 19. Apr 2024
Joined Jul 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Hey, thank you so so much…
Tue, 08/22/2023 - 12:28

Hey, thank you so so much for this tutorial!

I just got this to run on a workspace running MCreator 2022.3 with the earliest iteration of Nerdy's Geckolib plugin for 1.19.2.

I don't know if anyone has tried this since, but in the entity code I had to delete/put in "**/" brackets the section for adding data for the custom inventory like this:


/**
@Override
public void addAdditionalSaveData(CompoundTag compound) {
super.addAdditionalSaveData(compound);
compound.put("InventoryCustom", inventory.serializeNBT());
}

@Override
public void readAdditionalSaveData(CompoundTag compound) {
super.readAdditionalSaveData(compound);
Tag inventoryCustom = compound.get("InventoryCustom");
if (inventoryCustom instanceof CompoundTag inventoryTag)
inventory.deserializeNBT(inventoryTag);
}
**/

otherwise I would get an error complaining that "addAdditionalSaveData" and "readAdditionalSaveData" (which is added for "VariantData")  was already in use.

Will disabling this section about the inventory break anything? My entity has a fuel system that still works, so the custom inventory was not affected by this.

 

 

Also: I still get broken purple textures... double checked the texture's directories but it didn't change anything.

Should I mark this down as finnicky because of the GecoLib plugin and wait until something similar is introduced in an official MCreator build?

 

 

 

 

Last seen on 21:43, 19. Apr 2024
Joined Jul 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
And another question: why…
Tue, 08/22/2023 - 12:33

And another question:

why include "zoi" in the naming, like

"zoi_ruby_1
zoi_ruby_2
etc.."

?

Thank you :)