Overlay that appears briefly during potion effect

Started by Calazacks on

Topic category: Help with modding (Java Edition)

Last seen on 03:26, 17. Jul 2023
Joined Feb 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Overlay that appears briefly during potion effect

I am trying to make a potion effect that will randomly flash an image (an Overlay?) for about a second. ideally with 4-6 different images that just briefly appear at random while effected. i am not sure how to bind multiple overlays to a potion effect, nor how to make them go away after a short time. is there a procedure to make overlays appear?

Last seen on 04:35, 17. Jan 2021
Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I can help you code it if…
Sun, 06/07/2020 - 02:19

I can help you code it if you want unless you are able to do it in MCreator.

Last seen on 03:10, 19. Feb 2022
Joined Jun 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
hey can u tell me which…
Sun, 06/07/2020 - 02:23

hey can u tell me which method u need to override in the overlay's class to do this?

Last seen on 04:35, 17. Jan 2021
Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Override a method? Just…
Sun, 06/07/2020 - 03:02

Override a method? Just subscribe to RenderGameOverlayEvent.Pre, or maybe I am not understanding what you mean.

I took some time; wrote up and tested this code (you can condense it I am sure, my excuse is that I am a little tired and rushed lol).

    private int tick;
    private int overlayUp;
    private Random random = new Random();
    private int randomOverlay = 3;
    private boolean isOverlayUp = false;
    @SubscribeEvent
    public void renderOverlay(RenderGameOverlayEvent.Post event) {

        if (event.getType() == RenderGameOverlayEvent.ElementType.TEXT) {
            Minecraft mc = Minecraft.getInstance();
            mc.textureManager.bindTexture(notifs);
            AbstractClientPlayerEntity abstractClientPlayerEntity = mc.player;
            Collection<EffectInstance> effectsList = abstractClientPlayerEntity.getActivePotionEffects();
            Iterator iterator = effectsList.iterator();
            System.out.println(effectsList);
            while (iterator.hasNext())
            {
                EffectInstance effect = (EffectInstance) iterator.next();
                if (effect.getPotion() == Effects.SPEED)
                {
                    tick++;
                    if (tick >= (20 * 6))
                    {
                        tick = 0;
                        isOverlayUp = true;
                        randomOverlay = random.nextInt(3);
                    }
                    if (isOverlayUp) {
                        if (randomOverlay == 2) {
                            overlayUp++;
                            if (overlayUp >= 20) {
                                overlayUp = 0;
                                isOverlayUp = false;
                            }
                            mc.ingameGUI.blit(5, 8, 0, 0, 16, 16);
                        } else if (randomOverlay == 1) {
                            overlayUp++;
                            if (overlayUp >= 20) {
                                overlayUp = 0;
                                isOverlayUp = false;
                            }
                            mc.ingameGUI.blit(5, 20, 0, 16, 16, 16);
                        } else if (randomOverlay == 0) {
                            overlayUp++;
                            if (overlayUp >= 20) {
                                overlayUp = 0;
                                isOverlayUp = false;
                            }
                            mc.ingameGUI.blit(5, 10, 0, 32, 16, 16);
                        }
                    }
                }
            }

@Calazaks: Keep in mind, you should understand the blit parameters and can change the effects to whatever you want ;D.

 

 

Also, before I post this. This code is based on framerate which is very "bad". So to get a consistent "timer" for each player. Subscribe to ClientTickEvent and set NBT variables for the timers and such. If you need more of an explanation/code, I would be thrilled to help you with that. I guess that is it.

Last seen on 03:26, 17. Jul 2023
Joined Feb 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Many thanks for the response…
Sun, 06/07/2020 - 04:40

Many thanks for the response. Ill try this and see if it works

 

Last seen on 04:35, 17. Jan 2021
Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Great! If you need any help…
Sun, 06/07/2020 - 04:41

Great! If you need any help or get any errors, post code please!

Last seen on 03:26, 17. Jul 2023
Joined Feb 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
To further elaborate as to…
Sun, 06/07/2020 - 04:44

To further elaborate as to what i'm trying to make, i'm attempting to make a "Madness" potion effect that has a ton of random things that occur, and i think that strange images randomly appearing almost like a jumpscare would add a bit more appropriate "mental" themes

Last seen on 04:35, 17. Jan 2021
Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
 jumpscare would add a bit…
Sun, 06/07/2020 - 04:46

 jumpscare would add a bit more appropriate "mental" themes

Absolutely

 

To extend on my code, it is optimized for 3 images. However, you can append the integers to get more, again if you need help post code or just ask🤗🤗🤗

Last seen on 03:10, 19. Feb 2022
Joined Jun 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
is this Event called every…
Sun, 06/07/2020 - 04:54

is this Event called every player tick?

Last seen on 04:35, 17. Jan 2021
Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
TickEvent.ClientTickEvent
Sun, 06/07/2020 - 04:57

TickEvent.ClientTickEvent

Last seen on 03:10, 19. Feb 2022
Joined Jun 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
lmao I can't read lol
Sun, 06/07/2020 - 04:58

lmao I can't read lol