Jump to content

1.15 Entity fields not being properly set


Turtledove

Recommended Posts

I'm trying to implement a magic circle that would appear below the players' feet whenever they start casting a spell. 

 

So far it all worked fine. In my game logic, whenever I create the object by calling its "non-default" constructor (the one with extra parameters in addition to World) and spawn it in world, its called first (correctly, with all of its variables properly set). But then the "default" MagicCircle(World worldIn) is called somewhere and then the variables are all reset, causing remove() to be called. I've printed all the counters and variables responsible for controlling the magic circle, and they work fine, so I'm unsure where it could be.

 

public EntityMagicCircle(World worldIn) 
{
        super(ModEntities.Magic_Circle.getEntityType(), worldIn);
}

public EnergyBallEntity(World worldIn, LivingEntity caster, int ticksLifetime) 
{
        super(ModEntities.Magic_Circle.getEntityType(), worldIn);
        this.setPosition(caster.getPosX(), caster.getPosY(), caster.getPosZ());
        this.ticksLifetime = ticksLifetime;
        this.ticksAlive = 0;
}

@Override
public void tick() 
{
	if (ticksAlive < ticksLifetime)
        {
            ticksAlive++;
        }
        else
        {
            ticksAlive = 0;
            this.remove();
        }
}

 

Instead, ticksLifetime and ticksAlive are 0 for some reason, so the magic circle never appears. I'm not doing anything funny when creating the EntityMagicCircle object either. When I comment out this.remove(), the magic circle spawns correctly, so I've no idea how to start approaching this apart from what I've already tried.

Link to comment
Share on other sites

Because ticksAlive and ticksLifetime are being set to 0 and 0, I tried printing both outside of the condition in tick(), and it prints:

 

(0,0)    (0,100)    (0,0)     (1,100)    (0,0)    (2,100) ....etc.

 

So for some reason there are two instances being created, and it isn't letting me do anything.

Link to comment
Share on other sites

Just now, Turtledove said:

So for some reason there are two instances being created, and it isn't letting me do anything.

I assume there's one on the client and one on the server. The one on the client likely doesn't know what ticksLifeTime is because it is initialized in the constructor, but when it spawns on the client it doesn't use that constructor use the EntityDataManager field in the Entity class to store your lifetime and alive count.

  • Like 1

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

6 minutes ago, Animefan8888 said:

I assume there's one on the client and one on the server. The one on the client likely doesn't know what ticksLifeTime is because it is initialized in the constructor, but when it spawns on the client it doesn't use that constructor use the EntityDataManager field in the Entity class to store your lifetime and alive count.

Yup that was it. God damn I can't believe I forgot about the most basic shit, staying up all night was not a good idea... 

 

thanks though ?

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.