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

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.

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.

  • Author

Sorry,

I didnt know a forum about forge/minecraft wasnt about coding a mod for forge/minecraft. Wont happen again.

 

PS: Thats not the error. Particles do spwan, just not the right ones.

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.