Jump to content

[1.7.10]Custom Mob Head Turning Animation Problem


MrProg

Recommended Posts

So I have a mob, and when its head turns the ears don't go with it and instead kind of stay in place. The nose follows the head so I don't get why the ears don't.

 

Here is the code for the rotation:

public void setRotationAngles(float f, float f1, float f2, float f3, float f4, float f5, Entity entity)
  {
  this.head.rotateAngleX = f4 / (180F / (float)Math.PI);
          this.head.rotateAngleY = f3 / (180F / (float)Math.PI);
  
  this.nose.rotateAngleX = this.head.rotateAngleX;
  this.nose.rotateAngleY = this.head.rotateAngleY;
  
  this.ear.rotateAngleX = this.head.rotateAngleX;
  this.ear.rotateAngleY = this.head.rotateAngleY;
  
  this.ear2.rotateAngleX = this.head.rotateAngleX;
  this.ear2.rotateAngleY = this.head.rotateAngleY;

 

I also all have my model pieces in the same positions just with different offsets.

 

Here's a normal picture when it's facing me:

FBM53zr.png

 

Here's a picture when it turns its head:

MifUHci.png

 

Don't mind the hat I haven't tried fixing that yet.

Link to comment
Share on other sites

If you want them to move together they need to have the same rotation point.  You didn't post the code where you set the rotation points, but I suspect you don't have them the same.

 

Alternatively you can make the parts "child" parts to the head and then you only have to turn the head, using the addChild() method for the renderer parts.  However, in that case the rotation points will be relative and probably have to be adjusted depending on how you set up your model pieces.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

I do have the rotations points all the same. Here is the whole model class for any more reference:

package wintercraft.render.models;

import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.entity.Entity;
import net.minecraft.util.MathHelper;

public class ModelElf extends ModelBase
{
  //fields
    ModelRenderer head;
    ModelRenderer nose;
    ModelRenderer ear;
    ModelRenderer ear2;
    ModelRenderer chest;
    ModelRenderer pants;
    ModelRenderer rightarm;
    ModelRenderer leftarm;
    ModelRenderer rightleg;
    ModelRenderer rightshoe;
    ModelRenderer leftleg;
    ModelRenderer leftshoe;
    ModelRenderer hatbrim;
    ModelRenderer hat1;
    ModelRenderer hat2;
    ModelRenderer hat3;
    ModelRenderer hat4;
    ModelRenderer hat5;
    ModelRenderer hat6;
    ModelRenderer hatpoof;
  
  public ModelElf()
  {
    textureWidth = 64;
    textureHeight = 128;
    
      head = new ModelRenderer(this, 0, 53);
      head.addBox(-4F, -8F, -4F, 6, 6, 6);
      head.setRotationPoint(1F, 6F, 0F);
      head.setTextureSize(64, 128);
      head.mirror = true;
      setRotation(head, 0F, 0F, 0F);
      nose = new ModelRenderer(this, 50, 29);
      nose.addBox(-1.5F, -5F, -6F, 1, 1, 3);
      nose.setRotationPoint(1F, 6F, 0F);
      nose.setTextureSize(64, 128);
      nose.mirror = true;
      setRotation(nose, 0F, 0F, 0F);
      ear2 = new ModelRenderer(this, 56, 0);
      ear2.addBox(-0.4F, -9F, -2.8F, 1, 4, 1);
      ear2.setRotationPoint(1F, 6F, 0F);
      ear2.setTextureSize(64, 128);
      ear2.mirror = true;
      setRotation(ear2, -0.3141593F, 0F, 0.2617994F);
      ear = new ModelRenderer(this, 56, 0);
      ear.addBox(-2.6F, -9.5F, -2.8F, 1, 4, 1);
      ear.setRotationPoint(1F, 6F, 0F);
      ear.setTextureSize(64, 128);
      ear.mirror = true;
      setRotation(ear, -0.3141593F, 0F, -0.2617994F);
      chest = new ModelRenderer(this, 19, 41);
      chest.addBox(0F, 0F, 0F, 7, 7, 4);
      chest.setRotationPoint(-3.5F, 4F, -2.5F);
      chest.setTextureSize(64, 128);
      chest.mirror = true;
      setRotation(chest, 0F, 0F, 0F);
      pants = new ModelRenderer(this, 15, 16);
      pants.addBox(-4F, 0F, -2F, 8, 5, 4);
      pants.setRotationPoint(0F, 11F, -0.5F);
      pants.setTextureSize(64, 128);
      pants.mirror = true;
      setRotation(pants, 0F, 0F, 0F);
      rightarm = new ModelRenderer(this, 40, 16);
      rightarm.addBox(-3F, -2F, -2F, 3, 9, 3);
      rightarm.setRotationPoint(-3.5F, 6F, 0F);
      rightarm.setTextureSize(64, 128);
      rightarm.mirror = true;
      setRotation(rightarm, 0F, 0F, 0.1396263F);
      leftarm = new ModelRenderer(this, 40, 16);
      leftarm.addBox(-1F, -2F, -2F, 3, 9, 3);
      leftarm.setRotationPoint(4.5F, 6F, 0F);
      leftarm.setTextureSize(64, 128);
      leftarm.mirror = true;
      setRotation(leftarm, 0F, 0F, -0.1396263F);
      rightleg = new ModelRenderer(this, 0, 16);
      rightleg.addBox(-2F, 0F, -2F, 3, 9, 3);
      rightleg.setRotationPoint(-1.7F, 15F, 0F);
      rightleg.setTextureSize(64, 128);
      rightleg.mirror = true;
      setRotation(rightleg, 0F, 0F, 0F);
      rightshoe = new ModelRenderer(this, 0, 29);
      rightshoe.addBox(-2.466667F, 6F, -4.4F, 4, 3, 6);
      rightshoe.setRotationPoint(2.7F, 15F, 0F);
      rightshoe.setTextureSize(64, 128);
      rightshoe.mirror = true;
      setRotation(rightshoe, 0F, 0F, 0F);
      leftleg = new ModelRenderer(this, 0, 16);
      leftleg.addBox(-2F, 0F, -2F, 3, 9, 3);
      leftleg.setRotationPoint(2.7F, 15F, 0F);
      leftleg.setTextureSize(64, 128);
      leftleg.mirror = true;
      setRotation(leftleg, 0F, 0F, 0F);
      leftshoe = new ModelRenderer(this, 0, 29);
      leftshoe.addBox(-7F, 6F, -4.4F, 4, 3, 6);
      leftshoe.setRotationPoint(2.7F, 15F, 0F);
      leftshoe.setTextureSize(64, 128);
      leftshoe.mirror = true;
      setRotation(leftshoe, 0F, 0F, 0F);
      hatbrim = new ModelRenderer(this, 25, 2);
      hatbrim.addBox(0F, 0F, 0F, 7, 1, ;
      hatbrim.setRotationPoint(-3.5F, -2.8F, -5F);
      hatbrim.setTextureSize(64, 128);
      hatbrim.mirror = true;
      setRotation(hatbrim, -0.122173F, 0F, 0F);
      hat1 = new ModelRenderer(this, 0, 0);
      hat1.addBox(0F, 0F, 0F, 6, 3, 6);
      hat1.setRotationPoint(-3F, -5F, -3.5F);
      hat1.setTextureSize(64, 128);
      hat1.mirror = true;
      setRotation(hat1, -0.1745329F, 0F, 0F);
      hat2 = new ModelRenderer(this, 0, 0);
      hat2.addBox(0F, 0F, 0F, 5, 3, 5);
      hat2.setRotationPoint(-2.5F, -6.8F, -2.1F);
      hat2.setTextureSize(64, 128);
      hat2.mirror = true;
      setRotation(hat2, -0.5410521F, 0F, 0F);
      hat3 = new ModelRenderer(this, 0, 0);
      hat3.addBox(0F, 0F, 0F, 4, 3, 4);
      hat3.setRotationPoint(-2F, -7.666667F, -0.5F);
      hat3.setTextureSize(64, 128);
      hat3.mirror = true;
      setRotation(hat3, -0.6981317F, 0F, 0F);
      hat4 = new ModelRenderer(this, 0, 0);
      hat4.addBox(0F, 0F, 0F, 3, 2, 3);
      hat4.setRotationPoint(-1.5F, -8.5F, 1.5F);
      hat4.setTextureSize(64, 128);
      hat4.mirror = true;
      setRotation(hat4, -0.9948377F, 0F, 0F);
      hat5 = new ModelRenderer(this, 0, 0);
      hat5.addBox(0F, 0F, 0F, 2, 3, 2);
      hat5.setRotationPoint(-1F, -9F, 3.4F);
      hat5.setTextureSize(64, 128);
      hat5.mirror = true;
      setRotation(hat5, -1.012291F, 0F, 0F);
      hat6 = new ModelRenderer(this, 0, 0);
      hat6.addBox(0F, 0F, 0F, 1, 2, 1);
      hat6.setRotationPoint(-0.5F, -9F, 5F);
      hat6.setTextureSize(64, 128);
      hat6.mirror = true;
      setRotation(hat6, -1.27409F, 0F, 0F);
      hatpoof = new ModelRenderer(this, 0, 39);
      hatpoof.addBox(0F, 0F, 0F, 2, 2, 2);
      hatpoof.setRotationPoint(-1F, -9.5F, 4.6F);
      hatpoof.setTextureSize(64, 128);
      hatpoof.mirror = true;
      setRotation(hatpoof, 0F, 0F, 0F);
  }
  
  public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5)
  {
    super.render(entity, f, f1, f2, f3, f4, f5);
    setRotationAngles(f, f1, f2, f3, f4, f5,entity);
    head.render(f5);
    nose.render(f5);
    ear.render(f5);
    ear2.render(f5);
    chest.render(f5);
    pants.render(f5);
    rightarm.render(f5);
    leftarm.render(f5);
    rightleg.render(f5);
    rightshoe.render(f5);
    leftleg.render(f5);
    leftshoe.render(f5);
    hatbrim.render(f5);
    hat1.render(f5);
    hat2.render(f5);
    hat3.render(f5);
    hat4.render(f5);
    hat5.render(f5);
    hat6.render(f5);
    hatpoof.render(f5);
  }
  
  private void setRotation(ModelRenderer model, float x, float y, float z)
  {
    model.rotateAngleX = x;
    model.rotateAngleY = y;
    model.rotateAngleZ = z;
  }
  
  public void setRotationAngles(float f, float f1, float f2, float f3, float f4, float f5, Entity entity)
  {
  
  this.head.rotateAngleX = f4 / (180F / (float)Math.PI);
      this.head.rotateAngleY = f3 / (180F / (float)Math.PI);
  
  this.nose.rotateAngleX = this.head.rotateAngleX;
  this.nose.rotateAngleY = this.head.rotateAngleY;
  
  this.ear.rotateAngleX = this.head.rotateAngleX;
  this.ear.rotateAngleY = this.head.rotateAngleY;
  
  this.ear2.rotateAngleX = this.head.rotateAngleX;
  this.ear2.rotateAngleY = this.head.rotateAngleY;
  
  this.leftleg.rotateAngleX = MathHelper.cos(f * 0.6662F) * 2.0F * f1 * 0.5f;
  this.leftleg.rotateAngleY = 0.0f;
  
  this.rightleg.rotateAngleX = MathHelper.cos(f * 0.6662F + (float)Math.PI) * 1.4f * f1;
  this.rightleg.rotateAngleY = 0.0f;
  
  this.leftshoe.rotateAngleX = this.leftleg.rotateAngleX;
  this.leftshoe.rotateAngleY = this.leftleg.rotateAngleY;
  
  this.rightshoe.rotateAngleX = this.rightleg.rotateAngleX;
  this.rightshoe.rotateAngleY = this.rightleg.rotateAngleY;
  
  this.leftarm.rotateAngleX = MathHelper.cos(f * 0.6662F) * 2.0F * f1 * 0.5f;
  this.leftarm.rotateAngleZ = 0.0f;
  
  this.rightarm.rotateAngleX = MathHelper.cos(f * 0.6663F + (float)Math.PI) * 1.4f * f1;
  this.rightarm.rotateAngleZ = 0.0f;
  }

}

Link to comment
Share on other sites

That is weird because it looks pretty straight-forward and I can't see any obvious problem.

 

The one thing I'm slightly suspicious about though is that you didn't center the rotation point in the head.  Your head box is 6 x 6 x 6 and so the offset should probably be -3 in the X and Z dimensions not -4. 

 

The problem a lot of people encounter with models is that they use offsets to erroneously compensate for bad rotation point alignment.  Basically you can make a model look like all the pieces are connected with the offsets but that can break down when rotating if the rotation points weren't set up properly first.

 

Anyway, what happens if you add 1 to the X and Z offsets (the first and third parameter of the addBox() methods for the head and everything attached to it (ears, nose, hat)?

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

Sorry for such a long wait but I tried that and still have the same problem where the nose works fine but the ears still don't act correctly.

 

Here is the changed code if needed:

head = new ModelRenderer(this, 0, 53);
      head.addBox(-3F, -8F, -3F, 6, 6, 6);
      head.setRotationPoint(0F, 6F, 0F);
      head.setTextureSize(64, 128);
      head.mirror = true;
      setRotation(head, 0F, 0F, 0F);
      nose = new ModelRenderer(this, 50, 29);
      nose.addBox(-0.5F, -5F, -5F, 1, 1, 3);
      nose.setRotationPoint(0F, 6F, 0F);
      nose.setTextureSize(64, 128);
      nose.mirror = true;
      setRotation(nose, 0F, 0F, 0F);
      ear2 = new ModelRenderer(this, 56, 0);
      ear2.addBox(0.4F, -9F, -1.8F, 1, 4, 1);
      ear2.setRotationPoint(0F, 6F, 0F);
      ear2.setTextureSize(64, 128);
      ear2.mirror = true;
      setRotation(ear2, -0.3141593F, 0F, 0.2617994F);
      ear = new ModelRenderer(this, 56, 0);
      ear.addBox(-1.6F, -9.5F, -1.8F, 1, 4, 1);
      ear.setRotationPoint(0F, 6F, 0F);
      ear.setTextureSize(64, 128);
      ear.mirror = true;
      setRotation(ear, -0.3141593F, 0F, -0.2617994F);

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • KILAT77 : Waspada Situs Scam dengan Withdraw Yang Tidak Dibayar Di era digital saat ini, banyak orang yang mencari keberuntungan melalui situs perjudian online. Namun, dibalik gemerlap janji-janji manis kemenangan, ada bahaya yang mengintai. Salah satu situs yang patut diwaspadai adalah KILAT77. Situs ini mendapat reputasi buruk karena banyak laporan dari pengguna yang mengklaim bahwa mereka tidak bisa menarik dana kemenangan mereka. Dalam artikel ini, kita akan membahas mengapa ROTER88 dianggap sebagai situs scam dan bagaimana Anda bisa melindungi diri dari penipuan serupa. Pengalaman Pengguna: Penarikan Tidak Dibayar Beberapa pengguna telah melaporkan pengalaman buruk mereka dengan KILAT77. Mereka mengaku bahwa setelah memenangkan sejumlah uang dan mencoba menariknya, proses penarikan mereka ditolak tanpa alasan yang jelas. Bahkan, beberapa pengguna melaporkan bahwa akun mereka tiba-tiba diblokir setelah mencoba melakukan penarikan, sehingga mereka kehilangan akses ke dana mereka sama sekali.
    • It is a dupe mod issue Remove Rubidium - you are already using Embeddium which is a fork of Rubidium
    • I made a block entity in forge 1.20.1, I want to prevent hopper from taking input slot item, i tried to override the extractItem method, it prevented hopper from taking input slot item, but the player also unable to take/change the item in input slot unless the slot is empty. public class FluidSeparatorBlockEntity extends BlockEntity implements MenuProvider { private static final int INPUT_SLOT = 0; private final CustomItemHandler itemHandler = new CustomItemHandler(3){ @Override protected void onContentsChanged(int slot) { setChanged(); } @Override public boolean isItemValid(int slot, @NotNull ItemStack stack) { return slot == INPUT_SLOT; } @Override public @NotNull ItemStack extractItem(int slot, int amount, boolean simulate) { if (slot == INPUT_SLOT) { return ItemStack.EMPTY; } return super.extractItem(slot, amount, simulate); } }; private LazyOptional<IItemHandler> lazyItemHandler = LazyOptional.empty(); protected final ContainerData data; private int progress = 0; private int maxProgress = 78; public FluidSeparatorBlockEntity(BlockPos pPos, BlockState pBlockState) { super(ModBlockEntities.FLUID_SEPARATOR_BE.get(), pPos, pBlockState); this.data = new ContainerData() { @Override public int get(int pIndex) { return switch (pIndex) { case 0 -> FluidSeparatorBlockEntity.this.progress; case 1, 2 -> FluidSeparatorBlockEntity.this.maxProgress; default -> 0; }; } @Override public void set(int pIndex, int pValue) { switch (pIndex) { case 0 -> FluidSeparatorBlockEntity.this.progress = pValue; case 1, 2 -> FluidSeparatorBlockEntity.this.maxProgress = pValue; } } @Override public int getCount() { return 3; } }; } @Override public @NotNull <T> LazyOptional<T> getCapability(@NotNull Capability<T> cap, @Nullable Direction side) { if(cap == ForgeCapabilities.ITEM_HANDLER) { return lazyItemHandler.cast(); } return super.getCapability(cap, side); } @Override public void onLoad() { super.onLoad(); lazyItemHandler = LazyOptional.of(() -> itemHandler); } @Override public void invalidateCaps() { super.invalidateCaps(); lazyItemHandler.invalidate(); } public void drops() { SimpleContainer inventory = new SimpleContainer(itemHandler.getSlots()); for(int i = 0; i < itemHandler.getSlots(); i++) { inventory.setItem(i, itemHandler.getStackInSlot(i)); } Containers.dropContents(this.level, this.worldPosition, inventory); } @Override public Component getDisplayName() { return Component.translatable("block.chemmaster.fluid_separator"); } @Nullable @Override public AbstractContainerMenu createMenu(int pContainerId, Inventory pPlayerInventory, Player pPlayer) { return new FluidSeparatorMenu(pContainerId, pPlayerInventory, this, this.data); } @Override protected void saveAdditional(CompoundTag pTag) { pTag.put("inventory", itemHandler.serializeNBT()); pTag.putInt("fluid_separator.progress", progress); super.saveAdditional(pTag); } @Override public void load(CompoundTag pTag) { super.load(pTag); itemHandler.deserializeNBT(pTag.getCompound("inventory")); progress = pTag.getInt("fluid_separator.progress"); } public void tick(Level pLevel, BlockPos pPos, BlockState pState) { ItemStack inputStack = this.itemHandler.getStackInSlot(INPUT_SLOT); if (inputStack.getCount() < 2) { resetProgress(); return; } if(hasRecipe()) { increaseCraftingProgress(); setChanged(pLevel, pPos, pState); if(hasProgressFinished()) { craftItem(); resetProgress(); } } else { resetProgress(); } } private void resetProgress() { progress = 0; } private void craftItem() { Optional<FluidSeparatingRecipe> recipe = getCurrentRecipe(); if (recipe.isPresent()) { List<ItemStack> results = recipe.get().getOutputs(); ItemStack inputStack = this.itemHandler.getStackInSlot(INPUT_SLOT); if (inputStack.getCount() < 2) { // If there are not enough items, do not proceed with crafting return; } // Extract the input item from the input slot this.itemHandler.internalExtractItem(INPUT_SLOT, 2, false); // Loop through each result item and find suitable output slots for (ItemStack result : results) { int outputSlot = findSuitableOutputSlot(result); if (outputSlot != -1) { this.itemHandler.setStackInSlot(outputSlot, new ItemStack(result.getItem(), this.itemHandler.getStackInSlot(outputSlot).getCount() + result.getCount())); } else { // Handle the case where no suitable output slot is found // This can be logging an error, throwing an exception, or any other handling logic System.err.println("No suitable output slot found for item: " + result); } } } } private int findSuitableOutputSlot(ItemStack result) { // Implement logic to find a suitable output slot for the given result // Return the slot index or -1 if no suitable slot is found for (int i = 0; i < this.itemHandler.getSlots(); i++) { // Ensure we do not place the output item in the input slot if (i == INPUT_SLOT) { continue; } ItemStack stackInSlot = this.itemHandler.getStackInSlot(i); if (stackInSlot.isEmpty() || (stackInSlot.getItem() == result.getItem() && stackInSlot.getCount() + result.getCount() <= stackInSlot.getMaxStackSize())) { return i; } } return -1; } private boolean hasRecipe() { Optional<FluidSeparatingRecipe> recipe = getCurrentRecipe(); if (recipe.isEmpty()) { return false; } List<ItemStack> results = recipe.get().getOutputs(); for (ItemStack result : results) { if (!canInsertAmountIntoOutputSlot(result) || !canInsertItemIntoOutputSlot(result.getItem())) { return false; } } return true; } private Optional<FluidSeparatingRecipe> getCurrentRecipe(){ SimpleContainer inventory = new SimpleContainer(this.itemHandler.getSlots()); for (int i = 0; i < itemHandler.getSlots(); i++) { inventory.setItem(i, this.itemHandler.getStackInSlot(i)); } return this.level.getRecipeManager().getRecipeFor(FluidSeparatingRecipe.Type.INSTANCE, inventory, level); } private boolean canInsertAmountIntoOutputSlot(ItemStack result) { for (int i = 1; i < this.itemHandler.getSlots(); i++) { ItemStack stackInSlot = this.itemHandler.getStackInSlot(i); if (stackInSlot.isEmpty() || (stackInSlot.getItem() == result.getItem() && stackInSlot.getCount() + result.getCount() <= stackInSlot.getMaxStackSize())) { return true; } } return false; } private boolean canInsertItemIntoOutputSlot(Item item) { for (int i = 1; i < this.itemHandler.getSlots(); i++) { ItemStack stackInSlot = this.itemHandler.getStackInSlot(i); if (stackInSlot.isEmpty() || stackInSlot.getItem() == item) { return true; } } return false; } private boolean hasProgressFinished() { return progress >= maxProgress; } private void increaseCraftingProgress() { progress++; } }  
    • No dice. Unfortunately this fix didn't work, thank you though.
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.