[Tutorial] Creating texture variations for entities (Custom Code) [1.16.5/1.15.2]

Started by tetch_wolf on Sat, 10/02/2021 - 23:59

Topic category: User side tutorials

Last seen on 16:14, 25. Nov 2021
Joined Mar 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
[Tutorial] Creating texture variations for entities (Custom Code) [1.16.5/1.15.2]
Sun, 10/03/2021 - 07:44 (edited)

Before we start the tutorial, some warnings:

-This tutorial was made for 1.16.5 and 1.15.2, so it may not work on older generators like 1.12.2

-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 variable

Code

 

 

 

Let's record the following variable:
 

public static final DataParameter<Integer> VARIANT = EntityDataManager.createKey(CustomEntity.class, DataSerializers.VARINT); 

In the end, the code should look like this:

code

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

 

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

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

code

 

two spaces after the last "{"

so paste the following code:

public void setVariant(int varIn) {
			this.dataManager.set(VARIANT, varIn);
		}

		public int getVariant() {
			return this.dataManager.get(VARIANT);
		}

		protected void registerData() {
			super.registerData();
			this.dataManager.register(VARIANT, 0);
		}

		public void writeAdditional(CompoundNBT compound) {
			super.writeAdditional(compound);
			compound.putInt("Variant", this.getVariant());
		}

		public void readAdditional(CompoundNBT compound) {
			super.readAdditional(compound);
			this.setVariant(compound.getInt("Variant"));
		}

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

now, save your entity code, and we'll edit the rendering

render

if you are on 1.15, the render code will be together with the entity's java file

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

texture selector

Then replace 

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

with:

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

in my case, it looked like this:

look like this

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

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

procedure

 

 first code snippet:

((YourEntityEntity.CustomEntity) entity).getVariant()

second code snippet:

((YourEntityEntity.CustomEntity) entity).setVariant((int)Variant);

the number [30] 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:entity
 

(Yes XD, I know it's not the same entity as the tutorial, but it's an entity that contains the same code presented in the tutorial)

 

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

Edited by tetch_wolf on Sun, 10/03/2021 - 07:44
Last seen on 16:14, 25. Nov 2021
Joined Mar 2019
Points:

User statistics:

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

Thanks Gold :D

Last seen on 04:52, 28. Nov 2021
Joined Jun 2017
Points:

User statistics:

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

Finally xD

Last seen on 07:32, 30. Nov 2021
Joined Sep 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Good tutorial ^^
Sun, 10/03/2021 - 07:15

Good tutorial ^^

Last seen on 12:01, 30. Nov 2021
Joined Sep 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • 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 12:01, 30. Nov 2021
Joined Sep 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • 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:14, 25. Nov 2021
Joined Mar 2019
Points:

User statistics:

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

Thx guys :>>

Last seen on 17:25, 21. Nov 2021
Joined Jan 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • 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 01:38, 5. Nov 2021
Joined Jul 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • 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 17:13, 29. Nov 2021
Joined Mar 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • 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 21:05, 29. Nov 2021
Joined Mar 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • 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 17:25, 21. Nov 2021
Joined Jan 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • 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