Topic category: Help with Minecraft modding (Java Edition)
Okay, so using the tutorial at https://mcreator.net/forum/35866/how-get-tabula-models-work-mcreator-mi… , I was able to port Minecraft's skeleton model into Mcreator. However, since with custom models, even humanoids, armor can't render, I decided to try my hand at coding in rendered in amor and equipment. I managed to get it partially working, with it successfully reading the code without crashing and attempting to render in my armor, however, the result had the armor rendered in be basically anything that isn't a true block (like water, other mobs, etc) taking its place. Here is the code that I used:
package net.mcreator.minespansion;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.common.registry.EntityRegistry;
import net.minecraftforge.fml.common.registry.EntityEntryBuilder;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.client.registry.RenderingRegistry;
import net.minecraftforge.common.DungeonHooks;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.World;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.DamageSource;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Item;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.init.Items;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.passive.EntityWolf;
import net.minecraft.entity.monster.EntityMob;
import net.minecraft.entity.ai.EntityAIWander;
import net.minecraft.entity.ai.EntityAISwimming;
import net.minecraft.entity.ai.EntityAINearestAttackableTarget;
import net.minecraft.entity.ai.EntityAILookIdle;
import net.minecraft.entity.ai.EntityAIHurtByTarget;
import net.minecraft.entity.ai.EntityAIAvoidEntity;
import net.minecraft.entity.ai.EntityAIAttackMelee;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.entity.EnumCreatureAttribute;
import net.minecraft.entity.Entity;
import net.minecraft.client.renderer.entity.RenderLiving;
import net.minecraft.client.model.ModelSkeleton;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.client.model.ModelBase;
import java.util.Iterator;
import java.util.ArrayList;
import net.minecraft.client.renderer.entity.RenderBiped;
import net.minecraft.client.model.ModelBiped;
public class MCreatorRevenant extends minespansion.ModElement {
public static final int ENTITYID = 4;
public static final int ENTITYID_RANGED = 5;
public MCreatorRevenant(minespansion instance) {
super(instance);
instance.entities.add(() -> EntityEntryBuilder.create().entity(EntityCustom.class)
.id(new ResourceLocation("minespansion", "revenant"), ENTITYID).name("revenant").tracker(64, 1, true).egg(-3222081, -11974327)
.build());
}
@Override
public void init(FMLInitializationEvent event) {
Biome[] spawnBiomes = allbiomes(Biome.REGISTRY);
EntityRegistry.addSpawn(EntityCustom.class, 75, 2, 6, EnumCreatureType.MONSTER, spawnBiomes);
DungeonHooks.addDungeonMob(new ResourceLocation("minespansion:revenant"), 180);
}
private Biome[] allbiomes(net.minecraft.util.registry.RegistryNamespaced<ResourceLocation, Biome> in) {
Iterator<Biome> itr = in.iterator();
ArrayList<Biome> ls = new ArrayList<Biome>();
while (itr.hasNext())
ls.add(itr.next());
return ls.toArray(new Biome[ls.size()]);
}
@SideOnly(Side.CLIENT)
@Override
public void preInit(FMLPreInitializationEvent event) {
RenderingRegistry.registerEntityRenderingHandler(EntityCustom.class, renderManager -> {
RenderLiving customRender = new RenderLiving(renderManager, new ModelSkeleton(), 0.5f) {
protected ResourceLocation getEntityTexture(Entity entity) {
return new ResourceLocation("minespansion:textures/revenant.png");
}
};
customRender.addLayer(new net.minecraft.client.renderer.entity.layers.LayerHeldItem(customRender));
customRender.addLayer(new net.minecraft.client.renderer.entity.layers.LayerBipedArmor(customRender) {
protected void initArmor() {
this.modelLeggings = new ModelBiped();
this.modelArmor = new ModelBiped();
}
});
return customRender;
});
}
public static class EntityCustom extends EntityMob {
public EntityCustom(World world) {
super(world);
setSize(0.6f, 1.8f);
experienceValue = 8;
this.isImmuneToFire = false;
setNoAI(!true);
this.tasks.addTask(1, new EntityAIAvoidEntity(this, EntityWolf.class, (float) 6, 1, 1.2));
this.targetTasks.addTask(2, new EntityAIHurtByTarget(this, true));
this.tasks.addTask(3, new EntityAIAttackMelee(this, 1.2, false));
this.targetTasks.addTask(4, new EntityAINearestAttackableTarget(this, EntityPlayer.class, false, true));
this.tasks.addTask(5, new EntityAIWander(this, 1));
this.tasks.addTask(6, new EntityAILookIdle(this));
this.tasks.addTask(7, new EntityAISwimming(this));
this.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, new ItemStack(MCreatorIronNaginata.block, (int) (1)));
this.setItemStackToSlot(EntityEquipmentSlot.OFFHAND, new ItemStack(Items.SHIELD, (int) (1)));
this.setItemStackToSlot(EntityEquipmentSlot.HEAD, new ItemStack(MCreatorRevenantArmor.helmet, (int) (1)));
this.setItemStackToSlot(EntityEquipmentSlot.CHEST, new ItemStack(MCreatorRevenantArmor.body, (int) (1)));
this.setItemStackToSlot(EntityEquipmentSlot.LEGS, new ItemStack(MCreatorRevenantArmor.legs, (int) (1)));
this.setItemStackToSlot(EntityEquipmentSlot.FEET, new ItemStack(MCreatorRevenantArmor.boots, (int) (1)));
}
@Override
public EnumCreatureAttribute getCreatureAttribute() {
return EnumCreatureAttribute.UNDEAD;
}
@Override
protected Item getDropItem() {
return null;
}
@Override
public net.minecraft.util.SoundEvent getAmbientSound() {
return (net.minecraft.util.SoundEvent) net.minecraft.util.SoundEvent.REGISTRY.getObject(new ResourceLocation("entity.skeleton.ambient"));
}
@Override
public net.minecraft.util.SoundEvent getHurtSound(DamageSource ds) {
return (net.minecraft.util.SoundEvent) net.minecraft.util.SoundEvent.REGISTRY.getObject(new ResourceLocation("entity.skeleton.hurt"));
}
@Override
public net.minecraft.util.SoundEvent getDeathSound() {
return (net.minecraft.util.SoundEvent) net.minecraft.util.SoundEvent.REGISTRY.getObject(new ResourceLocation("entity.skeleton.death"));
}
@Override
protected float getSoundVolume() {
return 1.0F;
}
@Override
public boolean attackEntityFrom(DamageSource source, float amount) {
if (source.getImmediateSource() instanceof EntityArrow)
return false;
if (source == DamageSource.DROWN)
return false;
return super.attackEntityFrom(source, amount);
}
@Override
protected void applyEntityAttributes() {
super.applyEntityAttributes();
if (this.getEntityAttribute(SharedMonsterAttributes.ARMOR) != null)
this.getEntityAttribute(SharedMonsterAttributes.ARMOR).setBaseValue(0D);
if (this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED) != null)
this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.3D);
if (this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH) != null)
this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(32D);
if (this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE) != null)
this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).setBaseValue(6D);
}
}
/**
* ModelSkeleton - Either Mojang or a mod author Created using Tabula 7.0.1
*/
public static class ModelSkeleton extends ModelBase {
public ModelRenderer field_178723_h;
public ModelRenderer field_178721_j;
public ModelRenderer field_78116_c;
public ModelRenderer field_78115_e;
public ModelRenderer field_178724_i;
public ModelRenderer field_178722_k;
public ModelRenderer field_178720_f;
public ModelSkeleton() {
this.textureWidth = 64;
this.textureHeight = 32;
this.field_78116_c = new ModelRenderer(this, 0, 0);
this.field_78116_c.setRotationPoint(0.0F, 0.0F, 0.0F);
this.field_78116_c.addBox(-4.0F, -8.0F, -4.0F, 8, 8, 8, 0.0F);
this.field_178722_k = new ModelRenderer(this, 0, 16);
this.field_178722_k.mirror = true;
this.field_178722_k.setRotationPoint(2.0F, 12.0F, 0.10000000149011612F);
this.field_178722_k.addBox(-1.0F, 0.0F, -1.0F, 2, 12, 2, 0.0F);
this.field_178723_h = new ModelRenderer(this, 40, 16);
this.field_178723_h.setRotationPoint(-5.0F, 2.0F, 0.0F);
this.field_178723_h.addBox(-1.0F, -2.0F, -1.0F, 2, 12, 2, 0.0F);
this.setRotateAngle(field_178723_h, 0.0F, 0.0F, 0.10000000149011613F);
this.field_78115_e = new ModelRenderer(this, 16, 16);
this.field_78115_e.setRotationPoint(0.0F, 0.0F, 0.0F);
this.field_78115_e.addBox(-4.0F, 0.0F, -2.0F, 8, 12, 4, 0.0F);
this.field_178721_j = new ModelRenderer(this, 0, 16);
this.field_178721_j.setRotationPoint(-2.0F, 12.0F, 0.10000000149011612F);
this.field_178721_j.addBox(-1.0F, 0.0F, -1.0F, 2, 12, 2, 0.0F);
this.field_178724_i = new ModelRenderer(this, 40, 16);
this.field_178724_i.mirror = true;
this.field_178724_i.setRotationPoint(5.0F, 2.0F, 0.0F);
this.field_178724_i.addBox(-1.0F, -2.0F, -1.0F, 2, 12, 2, 0.0F);
this.setRotateAngle(field_178724_i, 0.0F, 0.0F, -0.10000000149011613F);
this.field_178720_f = new ModelRenderer(this, 32, 0);
this.field_178720_f.setRotationPoint(0.0F, 0.0F, 0.0F);
this.field_178720_f.addBox(-4.0F, -8.0F, -4.0F, 8, 8, 8, 0.5F);
}
@Override
public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5) {
this.field_78116_c.render(f5);
this.field_178722_k.render(f5);
this.field_178723_h.render(f5);
this.field_78115_e.render(f5);
this.field_178721_j.render(f5);
this.field_178724_i.render(f5);
this.field_178720_f.render(f5);
}
/**
* This is a helper function from Tabula to set the rotation of model
* parts
*/
public void setRotateAngle(ModelRenderer modelRenderer, float x, float y, float z) {
modelRenderer.rotateAngleX = x;
modelRenderer.rotateAngleY = y;
modelRenderer.rotateAngleZ = z;
}
public void setRotationAngles(float f, float f1, float f2, float f3, float f4, float f5, Entity e) {
super.setRotationAngles(f, f1, f2, f3, f4, f5, e);
this.field_78116_c.rotateAngleY = f3 / (180F / (float) Math.PI);
this.field_78116_c.rotateAngleX = f4 / (180F / (float) Math.PI);
this.field_178721_j.rotateAngleX = MathHelper.cos(f * 1.0F) * -1.0F * f1;
this.field_178722_k.rotateAngleX = MathHelper.cos(f * 1.0F) * 1.0F * f1;
this.field_178724_i.rotateAngleX = MathHelper.cos(f * 0.6662F + (float) Math.PI) * 2.0F * f1 * 0.5F;
this.field_178723_h.rotateAngleX = MathHelper.cos(f * 0.6662F) * 2.0F * f1 * 0.5F;
}
}
}
What adjustments do I need to make in order to make it render properly, if at all possible?
bump
Is it rendered like this? https://mcreator.net/tracker/issue/51905
No, it looks more like this: https://youtu.be/gFcWfzcI2jE
I am not sure why this is happening, you will need to tweak with a code a bit probably to find a solution.