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 :>
Nice tutorial :D
Thanks Gold :D
Finally xD
Good tutorial ^^
Neat, pinning the topic :)
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
oh wait nvm i misunderstood what you meant my bad
Thx guys :>>
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:
I double triple checked I pasted it correctly, but it looks exactly the same as your image does
any ideas? Much appreciated.
Hi. If anyone is encountering any build errors its because you need to add a few extra imports. Namely:
You can add these in manually or simply press CTRL W and MCreator should magically fix everything :)
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?
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
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
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).