Villager_31441 Posted July 10, 2018 Posted July 10, 2018 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? Quote
Animefan8888 Posted July 10, 2018 Posted July 10, 2018 Please post the actual code you have. And I believe your issue is that other entities never sync their PotionEffects to the client. Quote 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.
Villager_31441 Posted July 10, 2018 Author Posted July 10, 2018 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? Quote
Animefan8888 Posted July 10, 2018 Posted July 10, 2018 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() Quote 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.
Villager_31441 Posted July 10, 2018 Author Posted July 10, 2018 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. Quote
Animefan8888 Posted July 10, 2018 Posted July 10, 2018 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. 1 Quote 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.
Villager_31441 Posted July 10, 2018 Author Posted July 10, 2018 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! Quote
V0idWa1k3r Posted July 10, 2018 Posted July 10, 2018 4 minutes ago, Villager_31441 said: what would be a good way to refer to "minecraft:levitation" in code MobEffects.LEVITATION 1 Quote
Villager_31441 Posted July 10, 2018 Author Posted July 10, 2018 1 minute ago, V0idWa1k3r said: MobEffects.LEVITATION Ah. Thanks a lot. Quote
Villager_31441 Posted July 11, 2018 Author Posted July 11, 2018 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. Quote
Villager_31441 Posted July 12, 2018 Author Posted July 12, 2018 (edited) 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 July 12, 2018 by Villager_31441 Quote
Villager_31441 Posted July 12, 2018 Author Posted July 12, 2018 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? Quote
Villager_31441 Posted July 12, 2018 Author Posted July 12, 2018 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! Quote
Villager_31441 Posted July 13, 2018 Author Posted July 13, 2018 (edited) 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 July 13, 2018 by Villager_31441 Quote
Recommended Posts
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.