Jump to content

Mob Transformation on LivingTickEvent


Chydog376

Recommended Posts

Hello,

I am trying to make a drowned transform into a custom mod I made (called Hot Drowned) when it goes through a magma bubble column. I already have the mob fully working in game, but the code for the transformation is giving me trouble. Since I can't edit the drowned code, I tried to make it check on Living Tick Event for a drowned that is doing the ticking and check its position from there in relation to a magma block but its not working. My code is below, thank you in advance.

    @SubscribeEvent(priority = EventPriority.HIGHEST)
    public void entityJoinWorld(LivingEvent.LivingTickEvent event, ServerLevel pServerLevel) {
        System.out.println("Entity Ticked");
        Entity entity = event.getEntity();
        if (entity.isAlive() && entity instanceof Drowned) {
            Drowned drowned = (Drowned) entity;
            BlockPos bPos = BlockPos.of(drowned.blockPosition().get(Direction.Axis.Y));
            BlockState bPosBlock = pServerLevel.getBlockState(bPos);
            int dHieght = bPos.getY();
            if (bPosBlock == Blocks.WATER.defaultBlockState() || bPosBlock == Blocks.MAGMA_BLOCK.defaultBlockState()){
                if (bPosBlock == Blocks.MAGMA_BLOCK.defaultBlockState()){
                    ModEntities.HOT_DROWN.get().spawn(pServerLevel, BlockPos.of(drowned.blockPosition().get(Direction.Axis.Y)), NATURAL);
                }else {
                    for (int x = dHieght + 64; x > 0; x--) {
                        bPos = BlockPos.of(bPos.below().get(Direction.Axis.Y));
                        bPosBlock = pServerLevel.getBlockState(bPos);
                        System.out.println(bPosBlock);
                        if (bPosBlock == Blocks.MAGMA_BLOCK.defaultBlockState()) {
                            ModEntities.HOT_DROWN.get().spawn(pServerLevel, BlockPos.of(drowned.blockPosition().get(Direction.Axis.Y)), NATURAL);
                        } else {
                            return;
                        }
                    }
                }
            }
            }
        }
    }

 

Link to comment
Share on other sites

Is the code inside the event event gets called? I believe that event listeners needs to be public static and the Level parameter should be retrieved from the event itself (not sure if you can provide it as a listener parameter, I don't think so tbh)

Don't blame me if i always ask for your help. I just want to learn to be better :)

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.