Jump to content

Help with entity Variables


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() {
        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)) {
            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));
                    } 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));

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


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



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


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.

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.

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.


  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • That's what's so odd. Because I shift-clicked to get the file path & it literally is the same exact thing: (copy + pasted from folder) "C:\Program Files\Java\jdk-17\bin\javaw.exe"
    • updated a few mods and now my pack won't load https://paste.ee/p/0sUrp
    • I have installed Forge 1000 times and in different versions, but every time I enter a server or world, it loads the entire square and then it says ''Saving world''. After that, Minecraft closes and the launcher opens with a window displaying error code ''-1''. I don't even have any mods installed, it doesn't let me join any world or server. I contacted Minecraft support, and they told me to talk to you. I hope you can help me with this issue, I'm waiting for your response.
    • I'm trying to make a Event that is fired if a Player is swimming. Here is the Event Class: public class PlayerSwimEvent extends PlayerEvent { public PlayerSwimEvent(Player player) { super(player); } } Here is the Hooks (similar to ForgeHooks Class) that has Methods for the Events: public class EventHooks { public static void onPlayerSwim(Player player) { MinecraftForge.EVENT_BUS.post(new PlayerSwimEvent(player)); } } And here is the Mixin Class: @Mixin(value = Player.class) public class MixinPlayerSwimEvent { @Inject(method = "isSwimming", at = @At("HEAD")) public boolean isSwimming(CallbackInfoReturnable<Boolean> cir) { Player player = null; if (!player.getAbilities().flying && !player.isSpectator()) { EventHooks.onPlayerSwim(player); } return cir.getReturnValue(); } } My Issue is now that I don't get it to work because of the missing Parameter Player. Can someone help with this?
    • Official Website: https://informalhouse.com/r31p [Tap To Order Now] Perma Health Keto Gummies Canada if you're looking for a feature upgrade that will aid in your weight loss. It's among the most well-known weight loss supplements that are currently available, and many people have reported that it has assisted them in losing weight and maintaining their current physical appearance because it is believed to have a number of health benefits when taken over an extended period of time. Order Now:- https://groups.google.com/g/perma-health-keto-gummies-canada-quebec-try/c/4Um2uvnP-9g https://groups.google.com/g/active-keto-capsules-reviews-australia-public/c/kDDPgO8i8N4 https://gamma.app/public/Active-Keto-Capsules-Australia-weight-loss--l3anbew5k3vo5xl https://gamma.app/public/Perma-Health-Keto-Gummies-Canada-Quebec-Buy-5lhwh920bh1hzfd https://medium.com/@jon2023lee/perma-health-keto-gummies-canada-quebec-healthy-weight-loss-88a1bf673d72 https://medium.com/@jon2023lee/active-keto-capsules-australia-increased-energy-d80bc3aa5fc6 https://groups.google.com/g/chemistbuy--warehouse-keto-gummies-australia/c/L9ehZw7QxvA https://groups.google.com/g/mozilla.dev.platform/c/DUplSCW14Ds https://groups.google.com/g/mozilla.dev.platform/c/mxfTITHqHQU https://groups.google.com/g/active-keto-capsules-reviews-australia/c/xIM5sHObvSA https://www.facebook.com/ChemistWarehouseKetoGummiesAustraliasale https://www.facebook.com/ActiveketocapsulesreviewsAustralia https://gamma.app/public/Chemist-Warehouse-Keto-Gummies-Australia-Do-whatever-it-takes-not-5hixkohxcxt89to?mode=doc https://gamma.app/public/Active-keto-capsules-reviews-Australia-Crazy-Deals-Todays-best-of-iksqml7nl380vmp?mode=doc   
  • Topics

  • Create New...

Important Information

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