Jump to content

[1.5.2]Random Textures for Mobs[SOLVED]


DoorCloser

Recommended Posts

Hey guys. I was wondered about if i could set random textures to mob. So its like Villager. I tried to mess up with it. I added some Strings and what i get:

public void setProfession(int par1)
    {
        this.dataWatcher.updateObject(160, Integer.valueOf(par1));
    }
public int getProfession()
    {
        return this.dataWatcher.getWatchableObjectInt(160);
    }
@SideOnly(Side.CLIENT)
public String getTexture()
{
        switch (this.getProfession())
        {
            case 0:
                return "/mob/HL/Mesa/Scientist_1.png";
            case 1:
                return "/mob/HL/Mesa/Scientist_2.png";
            case 2:
                return "/mob/HL/Mesa/Scientist_3.png";
            case 3:
                return "/mob/HL/Mesa/Scientist_4.png";
            default:
                return "/mob/HL/Mesa/Scientist_4.png";
        }
    }

 

For that to work villager didnt need anything speciefied. But when i go to Minecraft, i cant see my mob and there is alot of errors in console.

 

 

2014-01-20 17:38:59 [iNFO] [sTDERR] java.lang.NullPointerException

2014-01-20 17:38:59 [iNFO] [sTDERR] at net.minecraft.entity.DataWatcher.getWatchableObjectInt(DataWatcher.java:93)

2014-01-20 17:38:59 [iNFO] [sTDERR] at halflifemod.entity.monster.EntityScientist.getProfession(EntityScientist.java:69)

2014-01-20 17:38:59 [iNFO] [sTDERR] at halflifemod.entity.monster.EntityScientist.getTexture(EntityScientist.java:122)

2014-01-20 18:15:36 [iNFO] [sTDERR] java.lang.ClassCastException

2014-01-20 18:15:36 [iNFO] [sTDERR] java.lang.ClassCastException

 

 

 

Any guesses what i could try to do?

Link to comment
Share on other sites

It was set on 16 in Villager. Which i can use?

Learn to read the code you are using please:

Quote from DataWatcher.java:

 

throw new IllegalArgumentException("Data value id is too big with " + par1 + "! (Max is " + 31 + ")");

 

And even some of those are already used:

 

Now like I said earlier, the datawatcher can only allow 32 objects in it. here are some of the most important values: Entity: uses value 0, 1 meaning there is 30 more free id's (if you were to extend Entity directly). EntityLivingBase: uses 6, 7, 8, 9 (as well as all others from entity) meaning every single of your mobs has 26 id's free! EntityAnimal: uses 12 (as well as every other from before) for age. 25 free for your passive mobs. EntityPlayer: uses 16, 17, 18 as well as EntityLivingBase so you still have 23 free id's.

From http://www.minecraftforge.net/wiki/Datawatcher

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

It was set on 16 in Villager. Which i can use?

Learn to read the code you are using please:

Quote from DataWatcher.java:

 

throw new IllegalArgumentException("Data value id is too big with " + par1 + "! (Max is " + 31 + ")");

 

And even some of those are already used:

 

Now like I said earlier, the datawatcher can only allow 32 objects in it. here are some of the most important values: Entity: uses value 0, 1 meaning there is 30 more free id's (if you were to extend Entity directly). EntityLivingBase: uses 6, 7, 8, 9 (as well as all others from entity) meaning every single of your mobs has 26 id's free! EntityAnimal: uses 12 (as well as every other from before) for age. 25 free for your passive mobs. EntityPlayer: uses 16, 17, 18 as well as EntityLivingBase so you still have 23 free id's.

From http://www.minecraftforge.net/wiki/Datawatcher

 

Still nothing works. I tried out other ID's. Again it spawns an empty space instead of Mob. So that means something with render. Because entity is still ok. So i can beat it and do other stuff, but its like invisible. And console getting alot of errors.

 

 

2014-01-20 21:27:11 [iNFO] [sTDERR] java.lang.NullPointerException

2014-01-20 21:27:11 [iNFO] [sTDERR] at net.minecraft.entity.DataWatcher.getWatchableObjectInt(DataWatcher.java:93)

2014-01-20 21:27:11 [iNFO] [sTDERR] at halflifemod.entity.monster.EntityScientist.getProfession(EntityScientist.java:95)

2014-01-20 21:27:11 [iNFO] [sTDERR] at halflifemod.entity.monster.EntityScientist.getTexture(EntityScientist.java:109)

2014-01-20 21:27:11 [iNFO] [sTDERR] at net.minecraft.client.renderer.entity.RenderLiving.func_98190_a(RenderLiving.java:291)

2014-01-20 21:27:11 [iNFO] [sTDERR] at net.minecraft.client.renderer.entity.RenderLiving.renderModel(RenderLiving.java:263)

2014-01-20 21:27:11 [iNFO] [sTDERR] at net.minecraft.client.renderer.entity.RenderLiving.doRenderLiving(RenderLiving.java:124)

2014-01-20 21:27:11 [iNFO] [sTDERR] at net.minecraft.client.renderer.entity.RenderBiped.doRenderLiving(RenderBiped.java:159)

2014-01-20 21:27:11 [iNFO] [sTDERR] at net.minecraft.client.renderer.entity.RenderBiped.doRender(RenderBiped.java:305)

2014-01-20 21:27:11 [iNFO] [sTDERR] at net.minecraft.client.renderer.entity.RenderManager.renderEntityWithPosYaw(RenderManager.java:310)

2014-01-20 21:27:11 [iNFO] [sTDERR] at net.minecraft.client.renderer.entity.RenderManager.renderEntity(RenderManager.java:279)

2014-01-20 21:27:11 [iNFO] [sTDERR] at net.minecraft.client.renderer.RenderGlobal.renderEntities(RenderGlobal.java:508)

2014-01-20 21:27:11 [iNFO] [sTDERR] at net.minecraft.client.renderer.EntityRenderer.renderWorld(EntityRenderer.java:1150)

2014-01-20 21:27:11 [iNFO] [sTDERR] at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:991)

2014-01-20 21:27:11 [iNFO] [sTDERR] at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:871)

2014-01-20 21:27:11 [iNFO] [sTDERR] at net.minecraft.client.Minecraft.run(Minecraft.java:760)

2014-01-20 21:27:11 [iNFO] [sTDERR] at java.lang.Thread.run(Unknown Source)

 

 

Link to comment
Share on other sites

You are supposed to set the initial value in entityInit().

 

Ok, so they not causing lags and errors right now, but skins not randomizing too

Here is the code

 

 

package halflifemod.entity.monster;

 

import cpw.mods.fml.common.registry.VillagerRegistry;

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

 

import java.util.Collections;

import java.util.HashMap;

import java.util.Iterator;

import java.util.Map;

import java.util.Random;

 

import doorcloser.modding.HalflifeRegistry;

import net.minecraft.block.Block;

import net.minecraft.enchantment.Enchantment;

import net.minecraft.enchantment.EnchantmentData;

import net.minecraft.enchantment.EnchantmentHelper;

import net.minecraft.entity.Entity;

import net.minecraft.entity.EntityAgeable;

import net.minecraft.entity.EntityLiving;

import net.minecraft.entity.IMerchant;

import net.minecraft.entity.INpc;

import net.minecraft.entity.ai.EntityAIAvoidEntity;

import net.minecraft.entity.ai.EntityAIFollowGolem;

import net.minecraft.entity.ai.EntityAILookAtTradePlayer;

import net.minecraft.entity.ai.EntityAIMoveIndoors;

import net.minecraft.entity.ai.EntityAIMoveTwardsRestriction;

import net.minecraft.entity.ai.EntityAIOpenDoor;

import net.minecraft.entity.ai.EntityAIPanic;

import net.minecraft.entity.ai.EntityAIPlay;

import net.minecraft.entity.ai.EntityAIRestrictOpenDoor;

import net.minecraft.entity.ai.EntityAISwimming;

import net.minecraft.entity.ai.EntityAITradePlayer;

import net.minecraft.entity.ai.EntityAIVillagerMate;

import net.minecraft.entity.ai.EntityAIWander;

import net.minecraft.entity.ai.EntityAIWatchClosest;

import net.minecraft.entity.ai.EntityAIWatchClosest2;

import net.minecraft.entity.monster.EntityMob;

import net.minecraft.entity.monster.EntityZombie;

import net.minecraft.entity.monster.IMob;

import net.minecraft.entity.passive.EntityVillager;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.item.Item;

import net.minecraft.item.ItemStack;

import net.minecraft.nbt.NBTTagCompound;

import net.minecraft.potion.Potion;

import net.minecraft.potion.PotionEffect;

import net.minecraft.util.ChunkCoordinates;

import net.minecraft.util.DamageSource;

import net.minecraft.util.MathHelper;

import net.minecraft.util.Tuple;

import net.minecraft.village.MerchantRecipe;

import net.minecraft.village.MerchantRecipeList;

import net.minecraft.village.Village;

import net.minecraft.world.World;

 

public class EntityScientist extends EntityMob implements INpc {

 

private int randomTickDivider;

 

public EntityScientist(World par1World) {

this(par1World, 0);

}

 

public EntityScientist(World par1World, int par2) {

super(par1World);

this.randomTickDivider = 0;

 

this.setProfession(par2);

this.texture = "/mob/HL/Mesa/Scientist.png";

this.moveSpeed = 0.5F;

this.setSize(0.6F, 1.8F);

this.getNavigator().setBreakDoors(true);

this.getNavigator().setAvoidsWater(true);

this.tasks.addTask(0, new EntityAISwimming(this));

this.tasks.addTask(1, new EntityAIAvoidEntity(this, EntityZombie.class,8.0F, 0.3F, 0.35F));

this.tasks.addTask(2, new EntityAIPanic(this, 0.38F));

this.tasks.addTask(3, new EntityAIMoveIndoors(this));

this.tasks.addTask(4, new EntityAIRestrictOpenDoor(this));

this.tasks.addTask(5, new EntityAIOpenDoor(this, true));

this.tasks.addTask(6, new EntityAIMoveTwardsRestriction(this, 0.3F));

 

this.tasks.addTask(9, new EntityAIWatchClosest2(this,EntityPlayer.class, 3.0F, 1.0F));

this.tasks.addTask(9, new EntityAIWander(this, 0.3F));

this.tasks.addTask(10, new EntityAIWatchClosest(this,EntityLiving.class, 8.0F));

}

 

 

 

/**

* Returns true if the newer Entity AI code should be run

*/

public boolean isAIEnabled() {

return true;

}

 

 

 

protected void entityInit() {

super.entityInit();

this.dataWatcher.addObject(17, Integer.valueOf(0));

}

 

public int getMaxHealth() {

return 20;

}

 

/**

* (abstract) Protected helper method to write subclass entity data to NBT.

*/

public void writeEntityToNBT(NBTTagCompound par1NBTTagCompound) {

super.writeEntityToNBT(par1NBTTagCompound);

par1NBTTagCompound.setInteger("Profession", this.getProfession());

}

 

/**

* (abstract) Protected helper method to read subclass entity data from NBT.

*/

public void readEntityFromNBT(NBTTagCompound par1NBTTagCompound) {

super.readEntityFromNBT(par1NBTTagCompound);

this.setProfession(par1NBTTagCompound.getInteger("Profession"));

}

 

@SideOnly(Side.CLIENT)

public String getTexture() {

switch (this.getProfession()) {

case 0:

return "/mob/HL/Mesa/Scientist1.png";

case 1:

return "/mob/HL/Mesa/Scientist2.png";

case 2:

return "/mob/HL/Mesa/Scientist3.png";

default:

return VillagerRegistry.getVillagerSkin(this.getProfession(),super.getTexture());

}

}

 

/**

* Determines if an entity can be despawned, used on idle far away entities

*/

protected boolean canDespawn() {

return false;

}

 

/**

* Returns the sound this mob makes while it's alive.

*/

protected String getLivingSound() {

return null;

}

 

/**

* Returns the sound this mob makes when it is hurt.

*/

protected String getHurtSound() {

return "scientist.sci_pain";

 

}

 

protected float getSoundVolume() {

return 0.5F;

}

 

/**

* Returns the sound this mob makes on death.

*/

protected String getDeathSound() {

return "scientist.sci_die";

}

 

public void setProfession(int par1) {

this.dataWatcher.updateObject(17, Integer.valueOf(par1));

}

 

public int getProfession() {

return this.dataWatcher.getWatchableObjectInt(17);

}

 

 

 

}

 

 

 

It takes only "case 0" skin and putting it in on model. Whats the matter with this?

Link to comment
Share on other sites

Code flow.

entityInit() obviously get's called after the constructor. Now understand what that means for your setProfession() call in the constructor.

 

I forgot to say. My mob is rendering and everything is fine, all goes without lags, errors and stuff. But it doesnt randomizes skins. So it only reads texture upon case 0, but i need it to randomly choose from case 0 to case 2. Its like the Villager, so when i spawn villager, his texture randomizing. I've taken code from villager, so it suppose to work but its not. Here is the code.  What can i do?

@SideOnly(Side.CLIENT)
public String getTexture() {
	switch (this.getProfession()) {
	case 0:
		return "/mob/HL/Mesa/Scientist1.png";
	case 1:
		return "/mob/HL/Mesa/Scientist2.png";
	case 2:
		return "/mob/HL/Mesa/Scientist3.png";
	default:
		return VillagerRegistry.getVillagerSkin(this.getProfession(),super.getTexture());
	}
}

Link to comment
Share on other sites

So i have to put setProfession after constructor, or entityInit in constructor. I tried both variants and it doesnt help.

You have to make it so that setProfession gets called after you set the initial value (which you do in entityInit currently).

 

NVM. I fixed it out. I've just copied all stuff from Villager and removed not needed by "removing" method and everything is now fine! Thanks guys. Here is the files, so you can see the changes:

 

 

package halflifemod.entity.monster;

 

import cpw.mods.fml.common.registry.VillagerRegistry;

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

 

import java.util.Collections;

import java.util.HashMap;

import java.util.Iterator;

import java.util.Map;

import java.util.Random;

 

import doorcloser.modding.ScientistRegistry;

import net.minecraft.block.Block;

import net.minecraft.entity.Entity;

import net.minecraft.entity.EntityLiving;

import net.minecraft.entity.INpc;

import net.minecraft.entity.ai.EntityAIAvoidEntity;

import net.minecraft.entity.ai.EntityAILookAtTradePlayer;

import net.minecraft.entity.ai.EntityAIMoveIndoors;

import net.minecraft.entity.ai.EntityAIMoveTwardsRestriction;

import net.minecraft.entity.ai.EntityAIOpenDoor;

import net.minecraft.entity.ai.EntityAIPanic;

import net.minecraft.entity.ai.EntityAIPlay;

import net.minecraft.entity.ai.EntityAIRestrictOpenDoor;

import net.minecraft.entity.ai.EntityAISwimming;

 

import net.minecraft.entity.ai.EntityAIWander;

import net.minecraft.entity.ai.EntityAIWatchClosest;

import net.minecraft.entity.ai.EntityAIWatchClosest2;

import net.minecraft.entity.monster.EntityMob;

import net.minecraft.entity.monster.EntityZombie;

import net.minecraft.entity.monster.IMob;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.item.Item;

 

import net.minecraft.nbt.NBTTagCompound;

import net.minecraft.world.World;

 

 

public class EntityScientist extends EntityMob implements INpc

{

  public EntityScientist(World par1World)

    {

        this(par1World, 0);

    }

 

    public EntityScientist(World par1World, int par2)

    {

        super(par1World);

     

        this.setProfession(par2);

        this.texture = "/mob/HL/Mesa/Scientist.png";

        this.moveSpeed = 0.5F;

        this.setSize(0.6F, 1.8F);

        this.getNavigator().setBreakDoors(true);

        this.getNavigator().setAvoidsWater(true);

        this.tasks.addTask(0, new EntityAISwimming(this));

        this.tasks.addTask(1, new EntityAIAvoidEntity(this, EntityZombie.class, 8.0F, 0.3F, 0.35F));

        this.tasks.addTask(2, new EntityAIPanic(this, 0.38F));

        this.tasks.addTask(3, new EntityAIMoveIndoors(this));

        this.tasks.addTask(4, new EntityAIRestrictOpenDoor(this));

        this.tasks.addTask(5, new EntityAIOpenDoor(this, true));

        this.tasks.addTask(6, new EntityAIMoveTwardsRestriction(this, 0.3F));

     

        this.tasks.addTask(7, new EntityAIWatchClosest2(this, EntityPlayer.class, 3.0F, 1.0F));

        this.tasks.addTask(7, new EntityAIWatchClosest2(this, EntityScientist.class, 5.0F, 0.02F));

        this.tasks.addTask(8, new EntityAIWander(this, 0.3F));

        this.tasks.addTask(9, new EntityAIWatchClosest(this, EntityLiving.class, 8.0F));

    }

 

    /**

    * Returns true if the newer Entity AI code should be run

    */

    public boolean isAIEnabled()

    {

        return true;

    }

 

   

 

    protected void entityInit()

    {

        super.entityInit();

        this.dataWatcher.addObject(16, Integer.valueOf(0));

    }

 

    public int getMaxHealth()

    {

        return 20;

    }

 

    /**

    * (abstract) Protected helper method to write subclass entity data to NBT.

    */

    public void writeEntityToNBT(NBTTagCompound par1NBTTagCompound)

    {

        super.writeEntityToNBT(par1NBTTagCompound);

        par1NBTTagCompound.setInteger("Profession", this.getProfession());   

    }

 

    /**

    * (abstract) Protected helper method to read subclass entity data from NBT.

    */

    public void readEntityFromNBT(NBTTagCompound par1NBTTagCompound)

    {

        super.readEntityFromNBT(par1NBTTagCompound);

        this.setProfession(par1NBTTagCompound.getInteger("Profession"));

    }

 

    @SideOnly(Side.CLIENT)

 

    /**

    * Returns the texture's file path as a String.

    */

    public String getTexture()

    {

        switch (this.getProfession())

        {

            case 0:

                return "/mob/HL/Mesa/Scientist1.png";

            case 1:

                return "/mob/HL/Mesa/Scientist2.png";

            case 2:

                return "/mob/HL/Mesa/Scientist3.png";

            default:

                return VillagerRegistry.getVillagerSkin(this.getProfession(), super.getTexture());

        }

    }

 

    /**

    * Determines if an entity can be despawned, used on idle far away entities

    */

    protected boolean canDespawn()

    {

        return false;

    }

 

    /**

    * Returns the sound this mob makes while it's alive.

    */

    protected String getLivingSound()

    {

        return null;

    }

 

    /**

    * Returns the sound this mob makes when it is hurt.

    */

    protected String getHurtSound()

    {

        return "scientist.sci_pain";

    }

 

    /**

    * Returns the sound this mob makes on death.

    */

    protected String getDeathSound()

    {

        return "scientist.sci_die";

    }

 

    public void setProfession(int par1)

    {

        this.dataWatcher.updateObject(16, Integer.valueOf(par1));

    }

 

    public int getProfession()

    {

        return this.dataWatcher.getWatchableObjectInt(16);

    }

 

    private void textureRandomize(int par1)

    {

      switch (this.getProfession())

        {

            case 0:

            break;

            case 1:

            break;

            case 2:

               

        }}

 

    public void initCreature()

    {

        ScientistRegistry.applyRandomTexture(this, worldObj.rand);

    }

    protected float getSoundVolume() {

return 0.5F;

}

 

}

 

 

 

 

package doorcloser.modding;

 

import halflifemod.entity.monster.EntityScientist;

import java.util.ArrayList;

import java.util.List;

import java.util.Map;

import java.util.Random;

import com.google.common.collect.Lists;

import com.google.common.collect.Maps;

 

public class ScientistRegistry

{

    private static final ScientistRegistry INSTANCE = new ScientistRegistry();

 

   

    private Map<Integer, String> newScientists = Maps.newHashMap();

    private List<Integer> newScientistIds = Lists.newArrayList();

 

 

   

    public static ScientistRegistry instance()

    {

        return INSTANCE;

    }

 

    public static void applyRandomTexture(EntityScientist entityScientist, Random rand)

    {

        int extra = instance().newScientistIds.size();

        int trade = rand.nextInt(5 + extra);

        entityScientist.setProfession(trade < 5 ? trade : instance().newScientistIds.get(trade - 5));

    }

}

 

 

 

So, how you can see i only needed to set a registry file and add this string to my EntityFile:

public void initCreature()
    {
        ScientistRegistry.applyRandomTexture(this, worldObj.rand);
    }

 

 

 

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.

Announcements



×
×
  • Create New...

Important Information

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