Jump to content

Custom Entity problems


TomEVoll

Recommended Posts

Following code only spawns a pig.

EntityRegistry.registerModEntity(RobotHelper.class, "robotHelper", 0, this, 64, 1, true);
EntityRegistry.registerEgg(RobotHelper.class, mainColor, subColor);

 

 

Following code spawns the entity but everytime i load the world from save the entity loads, stays there for 5 sec, then vanish, saving the map loading it again the entity again show up for 5 sec then vanish.

I'm overriding canDespawn and return false, i also tried setting enablePersistence() and forcing age to 0.

 

int i =EntityRegistry.instance().findGlobalUniqueEntityId();
EntityRegistry.registerGlobalEntityID(RobotHelper.class,"robotHelper",i);
        EntityRegistry.registerModEntity(RobotHelper.class, "robotHelper", i, this, 64, 1, true);
EntityRegistry.registerEgg(RobotHelper.class, mainColor, subColor);

 

 

Im sure im the one doing something wrong here, but im clueless at this point to why it is vanishing.

Link to comment
Share on other sites

public class RobotHelper extends EntityCreature {

private static final DataParameter<Integer> PROFESSION = EntityDataManager.<Integer>createKey(RobotHelper.class, DataSerializers.VARINT);
    private int randomTickDivider;
    private boolean isMating;
    private boolean isPlaying;
    Village villageObj;
   

    private int timeUntilReset;
    /** addDefaultEquipmentAndRecipies is called if this is true */
    private boolean needsInitilization;
   
    
    /** Last player to trade with this villager, used for aggressivity. */
   
    private int careerId;
    /** This is the EntityVillager's career level value */
    private int careerLevel;
    private boolean isLookingForHome;
    private boolean areAdditionalTasksSet;
    private InventoryBasic inventory;

    

   

public RobotHelper(World worldIn) {
	this(worldIn, 0);
}




 public RobotHelper(World worldIn, int professionId)
    {

        super(worldIn);
        System.out.println("Constructed :" + professionId);

        this.inventory = new InventoryBasic("Items", false, ;
        this.setProfession(professionId);
        this.setSize(0.6F, 1.95F);
        ((PathNavigateGround)this.getNavigator()).setBreakDoors(true);
        this.setCanPickUpLoot(true);
        this.setCustomNameTag("ROBOT");
        this.setAlwaysRenderNameTag(true);
        //this.persistenceRequired = true;
        this.enablePersistence();
        this.entityAge = 0;
    }

  protected void entityInit()
    {
        super.entityInit();
        this.dataWatcher.register(PROFESSION, Integer.valueOf(0));
        this.entityAge = 0;
        
    }



 @Override
public void onEntityUpdate() {
	// TODO Auto-generated method stub
	 this.entityAge = 0;

	super.onEntityUpdate();
}

    protected void initEntityAI()
    {
    	super.initEntityAI();
        this.tasks.addTask(0, new EntityAISwimming(this));
        this.tasks.addTask(1, new EntityAIAvoidEntity(this, EntityZombie.class, 8.0F, 0.6D, 0.6D));
        //this.tasks.addTask(1, new EntityAITradePlayer(this));
        //this.tasks.addTask(1, new EntityAILookAtTradePlayer(this));
        
        //this.tasks.addTask(2, new EntityAIMoveIndoors(this));
        //this.tasks.addTask(3, new EntityAIRestrictOpenDoor(this));
        //this.tasks.addTask(4, new EntityAIOpenDoor(this, true));
        //this.tasks.addTask(5, new EntityAIMoveTowardsRestriction(this, 0.6D));
        
        
        //this.tasks.addTask(6, new EntityAIVillagerMate(this));
        //this.tasks.addTask(7, new EntityAIFollowGolem(this));
        
        
        this.tasks.addTask(9, new EntityAIWatchClosest2(this, EntityPlayer.class, 3.0F, 1.0F));
        //this.tasks.addTask(9, new EntityAIVillagerInteract(this));
        //this.tasks.addTask(9, new EntityAIWander(this, 0.6D));
        //this.tasks.addTask(10, new EntityAIWatchClosest(this, EntityLiving.class, 8.0F));
    }

    private void setAdditionalAItasks()
    {
        if (!this.areAdditionalTasksSet)
        {
            this.areAdditionalTasksSet = true;

            if (this.isChild())
            {
               // this.tasks.addTask(8, new EntityAIPlay(this, 0.32D));
            }
            else if (this.getProfession() == 0)
            {
               // this.tasks.addTask(6, new EntityAIHarvestFarmland(this, 0.6D));
            }
        }
    }


    public void writeEntityToNBT(NBTTagCompound tagCompound)
    {
        super.writeEntityToNBT(tagCompound);
        tagCompound.setInteger("Profession", this.getProfession());
        tagCompound.setInteger("Career", this.careerId);
        tagCompound.setInteger("CareerLevel", this.careerLevel);

      
        NBTTagList nbttaglist = new NBTTagList();

        for (int i = 0; i < this.inventory.getSizeInventory(); ++i)
        {
            ItemStack itemstack = this.inventory.getStackInSlot(i);

            if (itemstack != null)
            {
                nbttaglist.appendTag(itemstack.writeToNBT(new NBTTagCompound()));
            }
        }

        tagCompound.setTag("Inventory", nbttaglist);
    }

    /**
     * (abstract) Protected helper method to read subclass entity data from NBT.
     */
    public void readEntityFromNBT(NBTTagCompound tagCompund)
    {
        super.readEntityFromNBT(tagCompund);
        this.setProfession(tagCompund.getInteger("Profession"));
        this.careerId = tagCompund.getInteger("Career");
        this.careerLevel = tagCompund.getInteger("CareerLevel");


        NBTTagList nbttaglist = tagCompund.getTagList("Inventory", 10);

        for (int i = 0; i < nbttaglist.tagCount(); ++i)
        {
            ItemStack itemstack = ItemStack.loadItemStackFromNBT(nbttaglist.getCompoundTagAt(i));

            if (itemstack != null)
            {
                this.inventory.func_174894_a(itemstack);
            }
        }

        this.setCanPickUpLoot(true);
        this.setAdditionalAItasks();
        this.isDead = false;
        this.entityAge = 0;
    }
    
  
    
    protected boolean canDespawn()
    {
        return false;
    }

    protected SoundEvent getAmbientSound()
    {
        return SoundEvents.entity_villager_ambient;
    }

    protected SoundEvent getHurtSound()
    {
        return SoundEvents.entity_villager_hurt;
    }

    protected SoundEvent getDeathSound()
    {
        return SoundEvents.entity_villager_death;
    }

    public void setProfession(int professionId)
    {
        this.dataWatcher.set(PROFESSION, Integer.valueOf(professionId));
    }

    public int getProfession()
    {
        return Math.max(((Integer)this.dataWatcher.get(PROFESSION)).intValue() % 5, 0);
    }

}

 

 

Nothing in there really just part of the villager class

Link to comment
Share on other sites

Following code only spawns a pig.

EntityRegistry.registerModEntity(RobotHelper.class, "robotHelper", 0, this, 64, 1, true);
EntityRegistry.registerEgg(RobotHelper.class, mainColor, subColor);

 

 

Following code spawns the entity but everytime i load the world from save the entity loads, stays there for 5 sec, then vanish, saving the map loading it again the entity again show up for 5 sec then vanish.

I'm overriding canDespawn and return false, i also tried setting enablePersistence() and forcing age to 0.

 

int i =EntityRegistry.instance().findGlobalUniqueEntityId();
EntityRegistry.registerGlobalEntityID(RobotHelper.class,"robotHelper",i);
        EntityRegistry.registerModEntity(RobotHelper.class, "robotHelper", i, this, 64, 1, true);
EntityRegistry.registerEgg(RobotHelper.class, mainColor, subColor);

 

 

Im sure im the one doing something wrong here, but im clueless at this point to why it is vanishing.

 

Same thing is happening to me. I have yet to figure out a solution.

Link to comment
Share on other sites

Should add everything works fine until u save and reload the map, if you stay in the game after spawning a entity it stays visible, only when loading the map it vanishes. but you can still get pushed around by it, and collide with it, pushing it into a chest made it become visible, might be random

Link to comment
Share on other sites

Stop using registerGlobalEntityID

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

im not using globalID,

 

Yes you are, its in your post:

int i =EntityRegistry.instance().findGlobalUniqueEntityId(); //GlobalID
EntityRegistry.registerGlobalEntityID(RobotHelper.class,"robotHelper",i); //GlobalID

 

egg dont work without it, but i spawn in the entity with a item, and do not register it using the globalID.

 

Yes they do, use the registerModEntity overloaded function that takes two color parameters.

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

I posted the old way and the new way, new way will only spawn pig, dont matter if you use the function that create the egg as well as register it, or register the egg manually.

 

I was just listing both as i believe i was doing it wrong since the new way was not working correctly, I now know that is caused by a current bug in forge that is being corrected, https://github.com/MinecraftForge/MinecraftForge/pull/2587

 

Main problem now seems to be any entity or modded entity at least will vanish when a map is reloaded, the entity is still alive, can take damage, and will collide with the player, but is not visible until some update is triggered, like in the video i posted i use ender pearls to teleport threw the entity making me coolide with it causing some damage and the entity is then visible.

 

 

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.