[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 16:58, 28. Mar 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 16:58, 28. Mar 2024
Joined Mar 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Thanks Gold :D
Sun, 10/03/2021 - 01:26

Thanks Gold :D

Last seen on 09:48, 26. Sep 2022
Joined Jun 2017
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Finally xD
Sun, 10/03/2021 - 03:47

Finally xD

Last seen on 21:52, 28. Dec 2022
Joined Sep 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
i know its just me probably…
Sun, 10/03/2021 - 12:41

i know its just me probably being stupid, but what am i supposed to name the procedure? I dont understand what you mean by the name registered in the code

Last seen on 21:52, 28. Dec 2022
Joined Sep 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
oh wait nvm i misunderstood …
Sun, 10/03/2021 - 12:50

oh wait nvm i misunderstood  what you meant my bad

 

Last seen on 16:58, 28. Mar 2024
Joined Mar 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Thx guys :>>
Sun, 10/03/2021 - 20:12

Thx guys :>>

Last seen on 01:15, 25. Jul 2022
Joined Jan 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
You are a lifesaver if I can…
Sun, 10/17/2021 - 17:52

You are a lifesaver if I can get this to work

Followed through the whole tutorial, everything looks good, but I'm getting this error in regards to the first custom code line in the entity file:
 

> Task :compileJava FAILED 
D:\MocRepo\src\main\java\net\mcreator\mocreatures\entity\CrabBlueEntity.java:84: error: cannot find symbol 
      public static final DataParameter<Integer> VARIANT = EntityDataManager.createKey(CustomEntity.class, DataSerializers.VARINT); 
                          ^ 
  symbol:   class DataParameter 
  location: class CustomEntity 
D:\MocRepo\src\main\java\net\mcreator\mocreatures\entity\CrabBlueEntity.java:84: error: cannot find symbol 
      public static final DataParameter<Integer> VARIANT = EntityDataManager.createKey(CustomEntity.class, DataSerializers.VARINT); 
                                                                                                           ^ 
  symbol:   variable DataSerializers 
  location: class CustomEntity 
D:\MocRepo\src\main\java\net\mcreator\mocreatures\entity\CrabBlueEntity.java:84: error: cannot find symbol 
      public static final DataParameter<Integer> VARIANT = EntityDataManager.createKey(CustomEntity.class, DataSerializers.VARINT); 
                                                           ^ 
  symbol:   variable EntityDataManager 
  location: class CustomEntity 
3 errors

I double triple checked I pasted it correctly, but it looks exactly the same as your image does

 

public static class CustomEntity extends TameableEntity {
		public static final DataParameter<Integer> VARIANT = EntityDataManager.createKey(CustomEntity.class, DataSerializers.VARINT);
		public CustomEntity(FMLPlayMessages.SpawnEntity packet, World world) {
			this(entity, world);
		}

 

any ideas? Much appreciated.

Last seen on 09:35, 12. May 2022
Joined Jul 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Hi. If anyone is…
Fri, 10/22/2021 - 09:06

Hi. If anyone is encountering any build errors its because you need to add a few extra imports. Namely:

import net.minecraft.network.datasync.EntityDataManager;

import net.minecraft.network.datasync.DataSerializers;

import net.minecraft.network.datasync.DataParameter;

import net.minecraft.nbt.CompoundNBT;

You can add these in manually or simply press CTRL W and MCreator should magically fix everything :)

Last seen on 18:15, 24. Dec 2021
Joined Mar 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I need help Executing Gradle…
Fri, 10/22/2021 - 18:26

I need help

Executing Gradle task: build
Build info: MCreator 2021.2.36710, forge-1.16.5, 64-bit, 4093 MB, Windows 10, JVM 11.0.11, JAVA_HOME: C:\Users\Admin\Desktop\Folders\Programms\MCreator20212\jdk
> Task :compileJava
C:\Users\Admin\MCreatorWorkspaces\minecraftian_galaxy\src\main\java\net\mcreator\minecraftiangalaxy\procedures\GranopuSelectTexProcedure.java:47: error: cannot find symbol ((GranopuEntity.CustomEntity) entity).setVariant((int) Variant);
^
symbol: variable Variant
location: class net.mcreator.minecraftiangalaxy.procedures.GranopuSelectTexProcedure
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
Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
See https://docs.gradle.org/7.1.1/userguide/command_line_interface.html#sec…
BUILD FAILED in 21s
1 actionable task: 1 executed
BUILD FAILED
Task completed in 26 seconds

How fix it?

Last seen on 16:35, 13. Jul 2023
Joined Mar 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
a question, when you finish…
Sat, 10/23/2021 - 19:53

a question, when you finish implementing the code to the entity or when you finish configuring the entity (excuse the redundancy) do you have to block the code? I don't know if I made myself understood

Last seen on 01:15, 25. Jul 2022
Joined Jan 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Oh duh thank you! Put in the…
Sun, 10/24/2021 - 16:25

Oh duh thank you! Put in the imports and its working great. This is gonna help me optimize a ton, thank you both so much <3

Last seen on 16:33, 5. Jan 2023
Joined Nov 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Coding tutorials like this…
Fri, 12/17/2021 - 14:17

Coding tutorials like this one could be ideas to get added into mcreator itself, if this guy could find a way to make variants of the same mob (changing texture) to the game, then it should be added in mcreator (like, an option to add variants of the entity).