Topic category: User side tutorials
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
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
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:
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
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:
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;
now, press ctrl+w again and save your entity code.
Now, we'll edit the rendering
we'll go where the entity's texture is selected, and then we'll edit that part
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:
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
create a local variable in the procedure with the same name registered in the entity code
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:
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
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:
That's it, thanks for reading this far, I hope I helped you :>
Is this confirmed to be working in 1.17 version, Im getting build errors?
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
Could you make a video showcasing this in more detail, and a clear walkthrough?
Does this work for blocks?
@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 ^^
Where can I find Set Local: Variant? I can't find it anywhere, and i've looked.
is it posible to do the same but with the glow texture?
> 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?
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
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:
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?
And another question:
why include "zoi" in the naming, like
"zoi_ruby_1
zoi_ruby_2
etc.."
?
Thank you :)
Wait, how i can add it to Vanilla mobs, like a cow, pig and chicken? Now mine.