Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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.

  • Author

Walking around in the room after they vanish i realized im bumping in to them and suddenly 1 became visible, it seems this is a server->client sync issue

  • Author

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

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.

  • Author

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

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.

  • Author

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

 

This should show what i mean by vanishing..

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.

  • Author

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.

 

 

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.