Posted April 26, 20205 yr So I created a Zelda heart container like item, it works and stuff, The issue is when dying. When I die, the health resets. I sorta have a lead on how to fix it. I know about the PlayerRespawnEvent and have gotten it to work, can't find out how to just keep it at the value I have it at. Would If statements work? If so, then I don't know how to get the if statement to work with the attribute modifier value if that's even possible. Sorry if my explaining is bad. Any help? UPDATE: Got it to work with if statements, just a bit wonky UPDATE 2: Yeah, I'm starting to figure it out. it's confusion on how to set up the if statement. Right now it is.. @SubscribeEvent public void defaultHealth(PlayerLoggedInEvent event) { PlayerEntity player = event.getPlayer(); if(player.getMaxHealth() == 20) player.getAttribute(SharedMonsterAttributes.MAX_HEALTH).applyModifier(new AttributeModifier("MaxHealth", -14f, AttributeModifier.Operation.ADDITION)); } @SubscribeEvent public void keepHealth(PlayerRespawnEvent event) { PlayerEntity player = event.getPlayer(); if(player.getMaxHealth() == 20) player.getAttribute(SharedMonsterAttributes.MAX_HEALTH).applyModifier(new AttributeModifier("MaxHealth", -14f, AttributeModifier.Operation.ADDITION)); } I know I need to have the if statement have two variables for both cause right now it'll reset back to normal if it's at 20 when you log back in, and when you die and respawn it'll reset it no matter what. The PlayerRespawnEvent is my biggest issue rn. Edited April 27, 20205 yr by Babelincoln1809
April 27, 20205 yr Author 22 minutes ago, poopoodice said: I believe player clone event might be the thing you are looking for. PlayerCloneEvent doesn't appear to be a thing Wait found it Edited April 27, 20205 yr by Babelincoln1809
April 27, 20205 yr Author @poopoodice So far, I can't get it to clone the original player on respawn.
April 27, 20205 yr 13 minutes ago, Babelincoln1809 said: @poopoodice So far, I can't get it to clone the original player on respawn. the game will clone the player. in "player clone" event you are to copy your data from old (dead) player to new instance. before that, you need to solve persistance problem - ie. store the value. you dot that covered already?
April 27, 20205 yr Author 2 minutes ago, MFMods said: the game will clone the player. in "player clone" event you are to copy your data from old (dead) player to new instance. before that, you need to solve persistance problem - ie. store the value. you dot that covered already? I do not think I've stored the value. I'm really only totally lost on this respawn part. So far I have.. @SubscribeEvent public void keepHealth(PlayerEvent.Clone event) { PlayerEntity clone = event.getOriginal(); }
April 27, 20205 yr ok. you found the clone event. inside you write new-player-instance.value1 <- old-player-instance.value1 new-player-instance.value2 <- old-player-instance.value2 now persistence... if you just ask how do i store 1 integer on a player/cow/pickaxe, people here will say "learn capabilities. use capabilities. love capabilities." (https://mcforge.readthedocs.io/en/latest/datastorage/capabilities/) i do not quite agree... yes, the capability system allows you to store several values as a nice structured record. yes the system allows modA to nicely and properly access the data some modB has stored. but sometimes you just need one integer or one string and you can not imagine other mods wanting to interact. so you may elect not to make two interfaces and three more classes to keep that one value. and it's fine. entities and item stacks still have a nbt compound where you can keep your value across game shutdown/load. but in your case you can just read modifiers from the old player instance and apply onto a new player instance. no need to duplicate data.
April 27, 20205 yr Author 6 minutes ago, MFMods said: ok. you found the clone event. inside you write new-player-instance.value1 <- old-player-instance.value1 new-player-instance.value2 <- old-player-instance.value2 Writing that down inside the method just gave me errors
April 27, 20205 yr Author 7 minutes ago, diesieben07 said: Well, that was pseudocode, obviously. Do you know Java? Yeah, I understand the basics/essentials. I've been learning it for a year and half right now and when coding Minecraft I get really ambitious and sometimes try to do stuff I don't understand/learn fully learned yet. I do a lot of trail and error with Minecraft, and use the reference libraries a lot. I do tend to overthink, which isn't good lol.
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.