Jump to content

Help with entity Variables


BluMasc

Recommended Posts

I am trying to make mobs, that have a certain number of times they can do a task. I have completed the first one and it works fine, but the second one won't work.

Here is the code in the first one:
 

public void aiStep() {
        super.aiStep();
        if (!this.level.isClientSide) {
            int i = Mth.floor(this.getX());
            int j = Mth.floor(this.getY());
            int k = Mth.floor(this.getZ());
            BlockPos blockpos = new BlockPos(i, j, k);
            if (!net.minecraftforge.event.ForgeEventFactory.getMobGriefingEvent(this.level, this)) {
                return;
            }
            if(workTimes > 0) {

                BlockState blockstate = ModBlocks.SLIME_LAYER.get().defaultBlockState();

                for (int l = 0; l < 4; ++l) {
                    i = Mth.floor(this.getX() + (double) ((float) (l % 2 * 2 - 1) * 0.25F));
                    j = Mth.floor(this.getY());
                    k = Mth.floor(this.getZ() + (double) ((float) (l / 2 % 2 * 2 - 1) * 0.25F));
                    BlockPos blockpos1 = new BlockPos(i, j, k);
                    if (this.level.isEmptyBlock(blockpos1) && blockstate.canSurvive(this.level, blockpos1)) {
                        this.level.setBlockAndUpdate(blockpos1, blockstate);
                        this.level.gameEvent(GameEvent.BLOCK_PLACE, blockpos1, GameEvent.Context.of(this, blockstate));
                        this.workTimes--;
                    } else if (this.level.getBlockState(blockpos1).is(blockstate.getBlock())) {

                        if (this.jumping) {
                            int size = this.level.getBlockState(blockpos1).getValue(SlimeLayerBlock.LAYERS);
                            int newsize = size + (Math.round(random.nextInt(0, 18) / (10 + size)));
                            if (newsize>size) {
                                BlockState higherslime = this.level.getBlockState(blockpos1).setValue(SlimeLayerBlock.LAYERS, Math.min(newsize, 8));
                                this.level.setBlockAndUpdate(blockpos1, higherslime);
                                this.level.gameEvent(GameEvent.BLOCK_PLACE, blockpos1, GameEvent.Context.of(this, higherslime));
                                this.workTimes--;
                            }
                        }
                    }
                }
            }
        }

The variable is the "workTimes" one.

In the second mob, this code seem to never go into the if block:

 

protected ParticleOptions getParticleType() {
        if(workTimes > 0){return ParticleTypes.HEART;}
        return ParticleTypes.ITEM_SNOWBALL;
    }

I don't know why it is working in one mob but not the other.

Here is my full source code, if the code above isn't enough.

Link to comment
Share on other sites

The purpose of this forum is to answer questions about forge/minecraft.

It's not here to give you free code reviews. Or to let you proxy the work of debugging your mod to us.

 

Since the question looks like a trivial logic error, I will answer it.

But in future your question should be about forge or minecraft, NOT your code. Otherwise, expect to just have your question ignored as off topic.

 

Here you don't enter the loop that calls that method if spawnCustomParticles() returns false which is the default

https://github.com/BluMasc/slimed/blob/e785fd4324a1559e220cb2cc4b8f55d60038053b/src/main/java/de/blumasc/slimed/entity/BaseSlime.java#L130

Your "broken" mob doesn't override that method so it too will return false and not spawn particles.

https://github.com/BluMasc/slimed/blob/master/src/main/java/de/blumasc/slimed/entity/LovelySlime.java

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

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.