Jump to content

Checking for potion effects on mobs


Villager_31441

Recommended Posts

Hello there.

I just started with creating mods for Minecraft.

I am trying to check for all entities that have a specific potion effect and change some stuff in how they are rendered.

The code works absolutely fine with players but not for mobs at all. I found out that it is this piece of code.

@SubscribeEvent
public void onRenderLiving(RenderLivingEvent.Pre event) {
  LivingEntityBase = event.entity;
  Potion levitation = Potion.getPotionById(25);
  if(levitation != null && player.getActivePotionEffect(levitation) != null) {
    // do stuff
  }
}

The code in the if-statement is never executed for any entities other than players.

I also tried iterating through .getActivePotionEffects() but it never finds any effect at all. Logging revealed that the entites will be passed to the function though. So it must be due to .getPotionEffect() always returning false on mobs.

 

Am I using the API wrong? And if so, how would you check whether a mob has a potion effect?

Link to comment
Share on other sites

Please post the actual code you have. And I believe your issue is that other entities never sync their PotionEffects to the client.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

4 minutes ago, Animefan8888 said:

I believe your issue is that other entities never sync their PotionEffects to the client.

I thought about that as well. The client should know about the effects on the player character but not necessarily any other entity.

How would I go about retrieving that information from the server? Especially with the check happening every tick.

Do I have to send a message to the client using SimplImpl whenever a mob in its maximum view distance receives or runs out of a potion effect?

Link to comment
Share on other sites

5 minutes ago, Villager_31441 said:

I thought about that as well. The client should know about the effects on the player character but not necessarily any other entity.

How would I go about retrieving that information from the server? Especially with the check happening every tick.

Do I have to send a message to the client using SimplImpl whenever a mob in its maximum view distance receives or runs out of a potion effect?

Are you specifically targeting the levitation potion effect? If so you could just retrieve it with Entity#hasNoGravity()

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

5 minutes ago, Animefan8888 said:

Are you specifically targeting the levitation potion effect? If so you could just retrieve it with Entity#hasNoGravity()

I am. Thanks. Just tried that out. It doesn't work for the mobs nor the player. It did detect a newly summoned Zombie Pigman with {NoGravity:1} NBT data though. So I suppose it does just that and nothing beyond.

Link to comment
Share on other sites

12 minutes ago, Villager_31441 said:

I am. Thanks. Just tried that out. It doesn't work for the mobs nor the player. It did detect a newly summoned Zombie Pigman with {NoGravity:1} NBT data though. So I suppose it does just that and nothing beyond.

Oops, my bad, that is only used for flying mobs it turns out. Specifically used for flying. It turns out you might have to subscribe to PlayerEvent.StartTracking and "tag" the entity and "untag" the entity in PlayerEvent.StopTracking. And then in a tick event check if they have the potion effect and send the packet and mark that so you don't continuously send the packet. And then check if they don't have the effect and send another packet letting the client know. Honestly, you might even want to skip the Tracking section because it might work better.

  • Like 1

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

16 minutes ago, diesieben07 said:

Also Problematic code, issue 8.

Yeah. I figured the id is bad practice. Makes it hard to read, too. I've seen a bunch of code examples using something like Potion.jump_boost ect. but IntelliJ tells me that no attributes of that sort exist. So what would be a good way to refer to "minecraft:levitation" in code?

 

21 minutes ago, Animefan8888 said:

in a tick event check if they have the potion effect and send the packet and mark that so you don't continuously send the packet. And then check if they don't have the effect and send another packet letting the client know.

Ugh, I was really hoping for an easier way.

I am just trying to create a very simple mod that flips the player/mob model around when someone hits the ceiling under the levitation effect. Maybe I can just detect upward movement instead of the effect? But then I wouldn't know how to differentiate between floating and jumping against a block. So I guess I will have to learn how to efficiently do the networking stuff.

Thank you for your help thus far!

Link to comment
Share on other sites

On 7/10/2018 at 3:39 PM, Animefan8888 said:

It turns out you might have to subscribe to PlayerEvent.StartTracking and "tag" the entity and "untag" the entity in PlayerEvent.StopTracking. And then in a tick event check if they have the potion effect and send the packet and mark that so you don't continuously send the packet. And then check if they don't have the effect and send another packet letting the client know. Honestly, you might even want to skip the Tracking section because it might work better.

Is this page about Extended Entity Properties what your are talking about? It says that the system is deprecated but the favored Capability system doesn't sound at all like it would solve my problem.

I am also having a very hard time understanding what is going on in these code snippets. Do you know of any more detailed explanations than the docs? I consider them very confusing.

Link to comment
Share on other sites

So, I followed this guide on PlanetMinecraft about the capability system.

What is still unclear to me:

  • Is the guide still up to date or has a lot changed since then?
  • What is that resource location in the capability handler pointing at?
  • My IDE warns me that CapabilityManager.INSTANCE.register() is deprecated but it still appears in the official documentation. What is the new way of registering your capabilities?

And I also cannot find anything about the mentioned tracking events. What are the respective functions called and how do I use them?

EntityLivingBase#potionsNeedUpdate also doesn't appear to be a thing.

Edited by Villager_31441
Link to comment
Share on other sites

Thanks a lot.

 

13 minutes ago, diesieben07 said:

There are two overloads for this method. One is deprecated, one is not. 

Ah, I see. The new API requires a factory of type Callable instead of the class.

 

16 minutes ago, diesieben07 said:

If an entity enters this radius, this event is fired. This is an opportunity for mods to send additional data attached to the entity to the client that is now tracking this entity.

So I send the state of all entities (or at least those with a positive state - as in they have levitation) to the respective client once they are being tracked.

What would I do when the state of a currently tracked entity changes? I have to send it to all tracking clients. But is there a simple way to find out who that is or do I have to store which client tracks which entities myself?

When I do notify the clients would I simply send a message via SimplImpl? Can I apply the state directly to the entity so that I can find out about it via entity.whatever() or do I have to find my own solution, e.g. store all the IDs of entities with a positive state in an ArrayList and then check if the entity is in there?

Link to comment
Share on other sites

1 minute ago, diesieben07 said:

This is where capabilities come into play. You can use them to store this additional state on the entity.

Ah, now I got it. So I detect the state on the server and store them with a capability, send updates to the client and store them with the exact same capability. It's starting to make sense now.

 

Thank you so much for your help and quick responses!

Link to comment
Share on other sites

I am now sending a message to the clients when a mob changes its status. But how can I assign the status to the entity on the client? I have tried sending the entity UUID alongside the message but it appears the client only uses a numerical non-persistent identifier. Is there another way to find the correct entity?

Edited by Villager_31441
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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • DAFTAR DAN LOGIN DISINI   Hantogel atau handogel adalah bentuk pengumpulan duka uang yang populer di dunia judi online, khususnya dalam permainan slot gacor. Banyak situs judi online yang menawarkan handogel slot gacor, dan sebagai pemain, penting untuk mengetahui cara memilih dan mengakses situs tersebut dengan aman dan amanah. Dalam artikel ini, kami akan membahas cara memilih situs slot gacor online yang berkualitas dan tahu cara mengakses handogelnya.
    • DAFTAR & LOGIN SIRITOGEL Siritogel adalah kumpulan kata yang mungkin baru saja dikenal oleh masyarakat, namun dengan perkembangan teknologi dan banyaknya informasi yang tersedia di internet, kalau kita siritogel (mencari informasi dengan cara yang cermat dan rinci) tentang situs slot gacor online, maka kita akan menemukan banyak hal yang menarik dan membahayakan sama sekali. Dalam artikel ini, kita akan mencoba menjelaskan apa itu situs slot gacor online dan bagaimana cara mengatasi dampaknya yang negatif.
    • This honestly might just work for you @SubscribeEvent public static void onScreenRender(ScreenEvent.Render.Post event) { final var player = Minecraft.getInstance().player; final var options = Minecraft.getInstance().options; if(!hasMyEffect(player)) return; // TODO: You provide hasMyEffect float f = Mth.lerp(event.getPartialTick(), player.oSpinningEffectIntensity, player.spinningEffectIntensity); float f1 = ((Double)options.screenEffectScale().get()).floatValue(); if(f <= 0F || f1 >= 1F) return; float p_282656_ = f * (1.0F - f1); final var p_282460_ = event.getGuiGraphics(); int i = p_282460_.guiWidth(); int j = p_282460_.guiHeight(); p_282460_.pose().pushPose(); float f5 = Mth.lerp(p_282656_, 2.0F, 1.0F); p_282460_.pose().translate((float)i / 2.0F, (float)j / 2.0F, 0.0F); p_282460_.pose().scale(f5, f5, f5); p_282460_.pose().translate((float)(-i) / 2.0F, (float)(-j) / 2.0F, 0.0F); float f4 = 0.2F * p_282656_; float f2 = 0.4F * p_282656_; float f3 = 0.2F * p_282656_; RenderSystem.disableDepthTest(); RenderSystem.depthMask(false); RenderSystem.enableBlend(); RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ONE, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ONE); p_282460_.setColor(f4, f2, f3, 1.0F); p_282460_.blit(new ResourceLocation("textures/misc/nausea.png"), 0, 0, -90, 0.0F, 0.0F, i, j, i, j); p_282460_.setColor(1.0F, 1.0F, 1.0F, 1.0F); RenderSystem.defaultBlendFunc(); RenderSystem.disableBlend(); RenderSystem.depthMask(true); RenderSystem.enableDepthTest(); p_282460_.pose().popPose(); }   Note: Most of this is directly copied from GameRenderer as you pointed out you found. The only thing you'll have to likely do is update the `oSpinningEffectIntensity` + `spinningEffectIntensity` variables on the player when your effect is applied. Which values should be there? Not 100% sure, might be a game of guess and check, but `handleNetherPortalClient` in LocalPlayer has some hard coded you might be able to start with.
    • Dalam dunia perjudian online yang berkembang pesat, mencari platform yang dapat memberikan kemenangan maksimal dan hasil terbaik adalah impian setiap penjudi. OLXTOTO, dengan bangga, mempersembahkan dirinya sebagai jawaban atas pencarian itu. Sebagai platform terbesar untuk kemenangan maksimal dan hasil optimal, OLXTOTO telah menciptakan gelombang besar di komunitas perjudian online. Satu dari banyak keunggulan yang dimiliki OLXTOTO adalah koleksi permainan yang luas dan beragam. Dari togel hingga slot online, dari live casino hingga permainan kartu klasik, OLXTOTO memiliki sesuatu untuk setiap pemain. Dibangun dengan teknologi terkini dan dikembangkan oleh para ahli industri, setiap permainan di platform ini dirancang untuk memberikan pengalaman yang tak tertandingi bagi para penjudi. Namun, keunggulan OLXTOTO tidak hanya terletak pada variasi permainan yang mereka tawarkan. Mereka juga menonjol karena komitmen mereka terhadap keamanan dan keadilan. Dengan sistem keamanan tingkat tinggi dan proses audit yang ketat, OLXTOTO memastikan bahwa setiap putaran permainan berjalan dengan adil dan transparan. Para pemain dapat merasa aman dan yakin bahwa pengalaman berjudi mereka di OLXTOTO tidak akan terganggu oleh masalah keamanan atau keadilan. Tak hanya itu, OLXTOTO juga terkenal karena layanan pelanggan yang luar biasa. Tim dukungan mereka selalu siap sedia untuk membantu para pemain dengan segala pertanyaan atau masalah yang mereka hadapi. Dengan respon cepat dan solusi yang efisien, OLXTOTO memastikan bahwa pengalaman berjudi para pemain tetap mulus dan menyenangkan. Dengan semua fitur dan keunggulan yang ditawarkannya, tidak mengherankan bahwa OLXTOTO telah menjadi pilihan utama bagi jutaan penjudi online di seluruh dunia. Jika Anda mencari platform yang dapat memberikan kemenangan maksimal dan hasil optimal, tidak perlu mencari lebih jauh dari OLXTOTO. Bergabunglah dengan OLXTOTO hari ini dan mulailah petualangan Anda menuju kemenangan besar dan hasil terbaik!
    • Selamat datang di OLXTOTO, situs slot gacor terpanas yang sedang booming di industri perjudian online. Jika Anda mencari pengalaman bermain yang luar biasa, maka OLXTOTO adalah tempat yang tepat untuk Anda. Dapatkan sensasi tidak biasa dengan variasi slot online terlengkap dan peluang memenangkan jackpot slot maxwin yang sering. Di sini, Anda akan merasakan keseruan yang luar biasa dalam bermain judi slot. DAFTAR OLXTOTO DISINI LOGIN OLXTOTO DISINI AKUN PRO OLXTOTO DISINI   Jackpot Slot Maxwin Sering Untuk Peluang Besar Di OLXTOTO, kami tidak hanya memberikan hadiah slot biasa, tapi juga memberikan kesempatan kepada pemain untuk memenangkan jackpot slot maxwin yang sering. Dengan demikian, Anda dapat meraih keberuntungan besar dan memenangkan ribuan rupiah sebagai hadiah jackpot slot maxwin kami. Jackpot slot maxwin merupakan peluang besar bagi para pemain judi slot untuk meraih keuntungan yang lebih besar. Dalam permainan kami, Anda tidak harus terpaku pada kemenangan biasa saja. Kami hadir dengan jackpot slot maxwin yang sering, sehingga Anda memiliki peluang yang lebih besar untuk meraih kemenangan besar dengan hadiah yang menggiurkan. Dalam permainan judi slot, pengalaman bermain bukan hanya tentang keseruan dan hiburan semata. Kami memahami bahwa para pemain juga menginginkan kesempatan untuk meraih keberuntungan besar. Oleh karena itu, OLXTOTO hadir dengan jackpot slot maxwin yang sering untuk memberikan peluang besar kepada para pemain kami. Peluang Besar Menang Jackpot Slot Maxwin Peluang menang jackpot slot maxwin di OLXTOTO sangatlah besar. Anda tidak perlu khawatir tentang batasan atau pembatasan dalam meraih jackpot tersebut. Kami ingin memberikan kesempatan kepada semua pemain kami untuk merasakan sensasi menang dalam jumlah yang luar biasa. Jackpot slot maxwin kami dibuka untuk semua pemain judi slot di OLXTOTO. Anda memiliki peluang yang sama dengan pemain lainnya untuk memenangkan hadiah jackpot yang besar. Kami percaya bahwa semua orang memiliki kesempatan untuk meraih keberuntungan besar, dan itulah mengapa kami menyediakan jackpot slot maxwin yang sering untuk memenuhi harapan dan keinginan Anda.   Kesimpulan OLXTOTO adalah situs slot gacor terbaik yang memberikan pengalaman bermain judi slot online yang tak terlupakan. Dengan variasi slot online terlengkap dan peluang memenangkan jackpot slot maxwin yang sering, OLXTOTO menjadi pilihan terbaik bagi para pemain yang mencari kesenangan dan kemenangan besar dalam perjudian online. Di samping itu, OLXTOTO juga menawarkan layanan pelanggan yang ramah dan responsif, siap membantu setiap pemain dalam mengatasi masalah teknis atau pertanyaan seputar perjudian online. Kami menjaga integritas game dan memberikan lingkungan bermain yang adil serta menjalankan kebijakan perlindungan pelanggan yang cermat. Bergabunglah dengan OLXTOTO sekarang dan nikmati pengalaman bermain slot online yang luar biasa. Jadilah bagian dari komunitas perjudian yang mengagumkan ini dan raih kesempatan untuk meraih kemenangan besar. Dapatkan akses mudah dan praktis ke situs OLXTOTO dan rasakan sensasi bermain judi slot yang tak terlupakan.  
  • Topics

×
×
  • Create New...

Important Information

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