Jump to content
  • Home
  • Files
  • Docs
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.8] Entity renders two times?
Currently Supported: 1.16.X (Latest) and 1.15.X (LTS)
Sign in to follow this  
Followers 0
DaryBob

[1.8] Entity renders two times?

By DaryBob, November 14, 2015 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

DaryBob    3

DaryBob

DaryBob    3

  • Stone Miner
  • DaryBob
  • Members
  • 3
  • 70 posts
Posted November 14, 2015

Hi guy's, today I made a mob. If I spawn him, he has like two textures, very weird. I also wanted him to wear an armor and an item. I thought about it, and removed the armor code. But he still was there two times.. Could you please take a look into ma' code?

Thanks, Dary

 

EntityCreator.java

package netcrafter.mods.aoto.util;

import net.minecraft.client.renderer.entity.Render;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.entity.projectile.EntityEgg;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraftforge.fml.client.registry.RenderingRegistry;
import net.minecraftforge.fml.common.registry.EntityRegistry;
import netcrafter.mods.aoto.Main;

public class EntityCreator {

public static final void createEntity(Class entityClass, Render renderer, String name, EnumCreatureType type, boolean doesSpawn, int probability, int minSpawn, int maxSpawn, BiomeGenBase[] biomes, int solidColor, int spotColor, boolean hasSpawnEgg) {
	int id = EntityRegistry.findGlobalUniqueEntityId();

	EntityRegistry.registerGlobalEntityID(entityClass, name, id);
	EntityRegistry.registerModEntity(entityClass, name, id, Main.instance, 64, 1, true);
	RenderingRegistry.registerEntityRenderingHandler(entityClass, renderer);

	if(doesSpawn) { EntityRegistry.addSpawn(name, probability, minSpawn, maxSpawn, type, biomes); }		
	if(hasSpawnEgg) { EntityList.entityEggs.put(Integer.valueOf(id), new EntityList.EntityEggInfo(id, solidColor, spotColor)); }
}

public static final void createEntityItem(Class entityClass, Render renderer, String name) {
	int id = EntityRegistry.findGlobalUniqueEntityId();

	EntityRegistry.registerGlobalEntityID(entityClass, name, id);
	EntityRegistry.registerModEntity(entityClass, name, id, Main.instance, 64, 1, true);
	RenderingRegistry.registerEntityRenderingHandler(entityClass, renderer);

}


}

 

CommonProxy.java

package netcrafter.mods.aoto.proxy;

import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.entity.RenderSnowball;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.registry.GameRegistry;
import netcrafter.mods.aoto.Main;
import netcrafter.mods.aoto.crafting.AOTOCrafting;
import netcrafter.mods.aoto.entity.boss.EntityForestGuardian;
import netcrafter.mods.aoto.entity.boss.EntityKingSteve;
import netcrafter.mods.aoto.entity.mob.EntityTreeMinion;
import netcrafter.mods.aoto.entity.projectile.EntityTreeRoot;
import netcrafter.mods.aoto.init.AOTOBlocks;
import netcrafter.mods.aoto.init.AOTOItems;
import netcrafter.mods.aoto.render.entity.RenderForestGuardian;
import netcrafter.mods.aoto.render.entity.RenderKingSteve;
import netcrafter.mods.aoto.render.entity.RenderTreeMinion;
import netcrafter.mods.aoto.util.EntityCreator;
import netcrafter.mods.aoto.util.WorldGenRegister;
import netcrafter.mods.aoto.world.gen.feature.ForestGen;

public class CommonProxy {

    public void preInit(FMLPreInitializationEvent e) {
    	//Creating and registering items and blocks
	AOTOItems.createItems();
	AOTOBlocks.createBlocks();
    }

    public void init(FMLInitializationEvent e) {
    	//Register crafting recipes
        AOTOCrafting.initCrafting();
        
        //Create and register entities
        EntityCreator.createEntityItem(EntityTreeRoot.class, new RenderSnowball(Minecraft.getMinecraft().getRenderManager(), AOTOItems.tree_root, Minecraft.getMinecraft().getRenderItem()), "TreeRoot");
        EntityCreator.createEntity(EntityKingSteve.class, new RenderKingSteve(), "KingSteve", EnumCreatureType.MONSTER, false, 0, 0, 0, null, 0xF2FF00, 0x020B12, true);
        EntityCreator.createEntity(EntityForestGuardian.class, new RenderForestGuardian(), "ForestGuardian", EnumCreatureType.MONSTER, false, 0, 0, 0, null, 0xC219A3, 0x19C238, true);
        EntityCreator.createEntity(EntityTreeMinion.class, new RenderTreeMinion(), "TreeMinion", EnumCreatureType.MONSTER, false, 0, 0, 0, null, 0xA85236, 0x6E260E, true);
        
        //Register world generators
        WorldGenRegister.registerGenerators();
    }

    public void postInit(FMLPostInitializationEvent e) {

    }

public void registerRenders() {

}

}

 

EntityKingSteve.java

package netcrafter.mods.aoto.entity.boss;

import java.util.Random;

import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityCreature;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.EntityAIArrowAttack;
import net.minecraft.entity.ai.EntityAIAttackOnCollide;
import net.minecraft.entity.ai.EntityAIHurtByTarget;
import net.minecraft.entity.ai.EntityAILookIdle;
import net.minecraft.entity.ai.EntityAIMoveTowardsTarget;
import net.minecraft.entity.ai.EntityAINearestAttackableTarget;
import net.minecraft.entity.ai.EntityAISwimming;
import net.minecraft.entity.ai.EntityAIWander;
import net.minecraft.entity.ai.EntityAIWatchClosest;
import net.minecraft.entity.boss.IBossDisplayData;
import net.minecraft.entity.effect.EntityLightningBolt;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.item.EntityXPOrb;
import net.minecraft.entity.monster.EntityGuardian;
import net.minecraft.entity.monster.EntityMob;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockPos;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.MathHelper;
import net.minecraft.world.DifficultyInstance;
import net.minecraft.world.World;
import netcrafter.mods.aoto.Reference;
import netcrafter.mods.aoto.entity.mob.EntityTreeMinion;
import netcrafter.mods.aoto.entity.projectile.EntityTreeRoot;
import netcrafter.mods.aoto.init.AOTOItems;

public class EntityKingSteve extends EntityMob implements IBossDisplayData {

private int attackCounter = 0;
    private int deathTicks = 0;
    private int regenTime = 0;

public EntityKingSteve(World worldIn) {
	super(worldIn);
	this.setSize(1.5F, 7.0F);
	this.tasks.addTask(1, new EntityAIAttackOnCollide(this, EntityPlayer.class, 2.0D, true));
	this.tasks.addTask(2, new EntityAIMoveTowardsTarget(this, 1.0D, (float) 2.0D));
    this.tasks.addTask(3, new EntityAIWander(this, 1.0D));
    this.tasks.addTask(4, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F));
    this.tasks.addTask(5, new EntityAILookIdle(this));
    this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, false));
    this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityPlayer.class, true));
}
    
    @Override
    protected void applyEntityAttributes() {
        super.applyEntityAttributes();
        this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(360.0F);
        this.getEntityAttribute(SharedMonsterAttributes.followRange).setBaseValue(35.0D);
        this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.26D);
        this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(15.0D);
        this.getEntityAttribute(SharedMonsterAttributes.knockbackResistance).setBaseValue(2.0D);
    }
    
    protected void func_180481_a(DifficultyInstance p_180481_1_) {
        super.func_180481_a(p_180481_1_);
        this.setCurrentItemOrArmor(0, new ItemStack(AOTOItems.long_diamond_sword));
        this.setCurrentItemOrArmor(1, new ItemStack(AOTOItems.beard));
    }

@Override
    protected String getLivingSound() {
        return Reference.MOD_ID + ":mob.forestguardian.living";
    }

    @Override
    protected String getHurtSound() {
        return Reference.MOD_ID + ":mob.forestguardian.hurt";
    }

    @Override
    protected String getDeathSound() {
        return Reference.MOD_ID + ":mob.forestguardian.death";
    }
    
    /** Calls this method if the mob is dead */
    @SuppressWarnings("unchecked")
    @Override
    protected void onDeathUpdate() {
    	//Increments deathTicks every tick
    	++this.deathTicks;

    	//Creates a huge explosion if the value of deathTicks is between 180 and 200
        if (this.deathTicks >= 180 && this.deathTicks <= 200) {
            final float f = (this.rand.nextFloat() - 0.5F) * 1.5F;
            final float f1 = (this.rand.nextFloat() - 0.5F) * 2.0F;
            final float f2 = (this.rand.nextFloat() - 0.5F) * 1.5F;
            //Spawns the explosion into the world
            this.worldObj.spawnParticle(EnumParticleTypes.EXPLOSION_HUGE, this.posX + f, this.posY + 2.0D + f1, this.posZ + f2, 0.0D, 0.0D, 0.0D);
        }

        int i;
        int j;

        if (!this.worldObj.isRemote) {
        	
        	if (this.deathTicks > 150 && this.deathTicks % 5 == 0) {
                i = 30;

                while (i > 0) {
                    j = EntityXPOrb.getXPSplit(i);
                    i -= j;
                    //Spawns xp orbs while i is bigger than zero
                    this.worldObj.spawnEntityInWorld(new EntityXPOrb(this.worldObj, this.posX, this.posY, this.posZ, j));
                }
            }

        }

        //Rotates the mob
        this.moveEntity(0.0D, 0.10000000149011612D, 0.0D);
        this.renderYawOffset = this.rotationYaw += 20.0F;

        //Checks if the death ticks reached 200
        if (this.deathTicks == 200 && !this.worldObj.isRemote) {
            i = 20;

            while (i > 0) {
                j = EntityXPOrb.getXPSplit(i);
                i -= j;
                //Spawns xp orbs while i is bigger than 0
                this.worldObj.spawnEntityInWorld(new EntityXPOrb(this.worldObj, this.posX, this.posY, this.posZ, j));
            }

            //Drops an item
            this.entityDropItem(new ItemStack(AOTOItems.gem, 1, 1), 0.5F);
            
            //Spawns a lighting bolt into the world
            this.worldObj.addWeatherEffect(new EntityLightningBolt(worldObj, this.posX + 6, this.posY + 6, this.posZ));
            
            //Sets this mob dead
            super.setDead();
        }
    }

    @Override
    protected void dropFewItems(boolean par1, int par2) {
    	final ItemStack var2 = new ItemStack(AOTOItems.crown);
        EnchantmentHelper.addRandomEnchantment(this.rand, var2, 5);
        this.entityDropItem(var2, 0.0F);
    }
    
    @Override
    public EntityItem entityDropItem(ItemStack par1ItemStack, float par2) {
        final EntityItem entityitem = new EntityItem(this.worldObj, this.posX, this.posY + par2, this.posZ, par1ItemStack);
        entityitem.motionY = -2.0D;
        entityitem.setPickupDelay(60);
        if (this.captureDrops) {
            this.capturedDrops.add(entityitem);
        }else{
            this.worldObj.spawnEntityInWorld(entityitem);
        }
        return entityitem;
    }
    
    @Override
    public void onLivingUpdate() {
    	
    	if(regenTime++ > 10) {
    		regenTime = 0;
    		this.heal(4);
    	}   	
    	super.onLivingUpdate();
    }

}

 

RenderKingSteve.java

package netcrafter.mods.aoto.render.entity;

import net.minecraft.client.Minecraft;
import net.minecraft.client.model.ModelBiped;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.client.renderer.entity.RenderBiped;
import net.minecraft.client.renderer.entity.RenderLiving;
import net.minecraft.client.renderer.entity.layers.LayerBipedArmor;
import net.minecraft.client.renderer.entity.layers.LayerHeldItem;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.boss.BossStatus;
import net.minecraft.entity.boss.IBossDisplayData;
import net.minecraft.util.ResourceLocation;
import netcrafter.mods.aoto.Reference;
import netcrafter.mods.aoto.entity.boss.EntityKingSteve;
import netcrafter.mods.aoto.entity.mob.EntityTreeMinion;
import netcrafter.mods.aoto.model.ModelKingSteve;
import netcrafter.mods.aoto.model.ModelTreeMinion;

public class RenderKingSteve extends RenderBiped {

    public RenderKingSteve() {
    	
    	super(Minecraft.getMinecraft().getRenderManager(), new ModelKingSteve(), 0);
    	
	this.addLayer(new LayerHeldItem(this));
	LayerBipedArmor layerbipedarmor = new LayerBipedArmor(this) {
		protected void func_177177_a() {
			this.field_177186_d = new ModelBiped(1.0F);
			this.field_177189_c = new ModelBiped(0.5F);
		}
	};

        this.addLayer(layerbipedarmor);

    }

    @Override
    protected ResourceLocation getEntityTexture(Entity par1Entity) {
        return new ResourceLocation(Reference.MOD_ID, "textures/models/king_steve.png");
    }
    
private void renderEntity(EntityKingSteve entity, double x, double y, double z, float yaw, float partialTickTime) {
    super.doRender(entity, x, y, z, yaw, partialTickTime);
    }

    @Override
    public void doRender(EntityLiving par1EntityLiving, double par2, double par4, double par6, float par8, float par9) {
        BossStatus.setBossStatus((IBossDisplayData) par1EntityLiving, false);
        super.doRender(par1EntityLiving, par2, par4, par6, par8, par9);
    }
    
}

 

ModelKingSteve.java

package netcrafter.mods.aoto.model;

import net.minecraft.client.model.ModelBiped;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.entity.Entity;

public class ModelKingSteve extends ModelBiped {

    ModelRenderer head;
    ModelRenderer body;
    ModelRenderer rightarm;
    ModelRenderer leftarm;
    ModelRenderer rightleg;
    ModelRenderer leftleg;
  
  public ModelKingSteve() {
    textureWidth = 64;
    textureHeight = 32;
    
      head = new ModelRenderer(this, 0, 0);
      head.addBox(-4F, -8F, -4F, 8, 8, ;
      head.setRotationPoint(0F, 0F, 0F);
      head.setTextureSize(64, 32);
      head.mirror = true;
      setRotation(head, 0F, 0F, 0F);
      body = new ModelRenderer(this, 16, 16);
      body.addBox(-4F, 0F, -2F, 8, 12, 4);
      body.setRotationPoint(0F, 0F, 0F);
      body.setTextureSize(64, 32);
      body.mirror = true;
      setRotation(body, 0F, 0F, 0F);
      rightarm = new ModelRenderer(this, 40, 16);
      rightarm.addBox(-3F, -2F, -2F, 4, 12, 4);
      rightarm.setRotationPoint(-5F, 2F, 0F);
      rightarm.setTextureSize(64, 32);
      rightarm.mirror = true;
      setRotation(rightarm, 0F, 0F, 0F);
      leftarm = new ModelRenderer(this, 40, 16);
      leftarm.addBox(-1F, -2F, -2F, 4, 12, 4);
      leftarm.setRotationPoint(5F, 2F, 0F);
      leftarm.setTextureSize(64, 32);
      leftarm.mirror = true;
      setRotation(leftarm, 0F, 0F, 0F);
      rightleg = new ModelRenderer(this, 0, 16);
      rightleg.addBox(-2F, 0F, -2F, 4, 12, 4);
      rightleg.setRotationPoint(-2F, 12F, 0F);
      rightleg.setTextureSize(64, 32);
      rightleg.mirror = true;
      setRotation(rightleg, 0F, 0F, 0F);
      leftleg = new ModelRenderer(this, 0, 16);
      leftleg.addBox(-2F, 0F, -2F, 4, 12, 4);
      leftleg.setRotationPoint(2F, 12F, 0F);
      leftleg.setTextureSize(64, 32);
      leftleg.mirror = true;
      setRotation(leftleg, 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);
    body.render(f5);
    rightarm.render(f5);
    leftarm.render(f5);
    rightleg.render(f5);
    leftleg.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) {
    super.setRotationAngles(f, f1, f2, f3, f4, f5, entity);
  }

}

 

Well now, that I pasted the model, maybe it renders it two times, because it is already a modelbiped?

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    7623

diesieben07

diesieben07    7623

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7623
  • 55277 posts
Posted November 14, 2015

First of all:

Do not use findGlobalUniqueEntityId or registerGlobalEntityID. Do not use EntityList.entityEggs. All you need is registerModEntity.

Also do not call registerEntityRenderingHandler directly like that, you will crash servers.

  • Quote

Share this post


Link to post
Share on other sites

DaryBob    3

DaryBob

DaryBob    3

  • Stone Miner
  • DaryBob
  • Members
  • 3
  • 70 posts
Posted November 14, 2015

Ok, so you mean if(!world.isRemote)?

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    7623

diesieben07

diesieben07    7623

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7623
  • 55277 posts
Posted November 14, 2015

No, you register renderers in your client proxy.

  • Quote

Share this post


Link to post
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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

    • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 0
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • Maxi90909
      Forge 1.16.5 - 36.0.9 start up crash

      By Maxi90909 · Posted 43 minutes ago

      OK Thank you. I had 2 Random Patches datas in my mods folder.
    • matthyit
      my 1.16.5 modded game crashes after a while of playing

      By matthyit · Posted 43 minutes ago

      so i need to update java?
    • Luis_ST
      [1.16.5] Enchantments can Apply to all Tools

      By Luis_ST · Posted 47 minutes ago

      but eclipse say i have to set the cast currently i looked in the vanilla EnchantmentHelper at the method removeIncompatible and i creat this: List<Enchantment> enchantmentList = enchantments.keySet().stream().collect(Collectors.toList()); List<Integer> levelList = enchantments.values().stream().collect(Collectors.toList()); List<EnchantmentData> data = new ArrayList<EnchantmentData>(); for (int i = 0; i < enchantments.size(); i++) { data.add(new EnchantmentData(enchantmentList.get(i), levelList.get(i))); } for (int i = 0; i < data.size(); i++) { EnchantmentHelper.removeIncompatible(data, data.get(i)); }  
    • diesieben07
      [1.16.5] Enchantments can Apply to all Tools

      By diesieben07 · Posted 51 minutes ago

      Sure. Although you should not need that cast.   Actually. I looked again. No, that does not make sense. Why are you trying to cast the iterator.
    • Luis_ST
      [1.16.5] Enchantments can Apply to all Tools

      By Luis_ST · Posted 52 minutes ago

      than this while (enchantmentIterator.hasNext()) { Enchantment enchantment = (Enchantment) enchantmentIterator; if (!enchantment.isCompatibleWith(enchantmentIterator.next())) { enchantmentIterator.remove(); } }  
  • Topics

    • Maxi90909
      4
      Forge 1.16.5 - 36.0.9 start up crash

      By Maxi90909
      Started 2 hours ago

    • matthyit
      4
      my 1.16.5 modded game crashes after a while of playing

      By matthyit
      Started 3 hours ago

    • Luis_ST
      22
      [1.16.5] Enchantments can Apply to all Tools

      By Luis_ST
      Started Yesterday at 07:21 AM

    • Zockerbua
      1
      I need help

      By Zockerbua
      Started 1 hour ago

    • domi0908
      6
      fix hitbox red baby mobs version forge

      By domi0908
      Started Tuesday at 03:04 PM

  • Who's Online (See full list)

    • Heliarco
    • gtf7dvygiduivtd
    • ianiiaannn
    • Zockerbua
    • ZØMB
    • Leronus
    • domi0908
    • Luis_ST
    • matthyit
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.8] Entity renders two times?
  • Theme

Copyright © 2019 ForgeDevelopment LLC · Ads by Longitude Ads LLC Powered by Invision Community