Jump to content

Recommended Posts

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.

Posted

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.

Posted

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

×   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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Please post complete logs as described in the FAQ (https://forums.minecraftforge.net/topic/125488-rules-and-frequently-asked-questions-faq/), it will contain more information that may help figure out what your problem is.  
    • These are the Forge forums, you'd probably be better off asking in a fabric forum, if they have one.
    • I've just created a server for my friends and I to play on, running 1.21.4 with Fabric. I've given them an instance that includes all the client side mods they'll need, but I've just now come across a problem, built into the nature of MacOS, that a specific client side mod fixes. If possible I want to use this mod as a server side mod, so my friends wont have to go through the hassle of adding it themselves. The mod in question is MacOS Input Fixes. The latest version (1.21.3) does work on 1.21.4. If this can be turned into a server side mod, what would I need to do to change its functionality? What programs would I need to install and learn?
    • when i start my save i have this error message  [Server thread/WARN]:Could not find value 'formations:template_editor' in registry 'minecraft:item' for @RegistryEntryAcceptor! What can i do ??
    • Great news! That actually fixed it! I am forever grateful for your help man, you seriously saved me. Here is exactly what I did in case others have the same issue: Create new world (using the re-create world function didn't work for me.) Use the same seed from original world, make sure my game settings are all the same like difficulty, gamemode, etc. Load in to world. Exit world. Go to save folder, copy level.dat, level.dat_old, and session.lock Go to original broken world's save folder, delete those three files and paste in the ones I copied. Load into original world. I relogged a few times just to check the error wouldn't return. Seems now to be working just fine! I'll be making sure to make more frequent backups and if this problem ever occurs again, I'll try out your solution once more. Thank you again TileEntity!
  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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