Jump to content

[1.8.9] Mana bar reset


JimiIT92

Recommended Posts

So sorry to reopen this thread, but i've noticed that when the player comes back from the End the bar glitches out (it's shown fully charge when instead the player has a different value). I've already checked if the value is passed correctly, and it is, so i don't know why it is shown full. I've added this function in the event handler to catch the "player return from End event"

@SubscribeEvent
public void onClonePlayer(PlayerEvent.Clone event) {
	ExtendedPlayer props = ExtendedPlayer.get(event.original);
	ExtendedPlayer.get(event.entityPlayer).copy(props);
	RPG.INSTANCE.sendTo(new ManaValue(props.getCurrentMana()), (EntityPlayerMP) event.entityPlayer);
}

 

I've tried sending a specific amount of mana in the message, but the bar is still full

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

Got this now

@SubscribeEvent
public void onClonePlayer(PlayerEvent.Clone event) {
	ExtendedPlayer props = ExtendedPlayer.get(event.original);
	ExtendedPlayer.get(event.entityPlayer).copy(props);
}

 

but still full bar until a new spell is casted

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

Didn't saw that edit :D Thanks, this works now :)

PS: if i want to do some sort of regen (like every 5 seconds add 1 mana point) how could i do? I've tried the playerTickEvent but it lags of course)

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

I think i'm going somewhere. Right now i got this tick handler

@SubscribeEvent
public void onTick(PlayerTickEvent event) {
	ExtendedPlayer props = ExtendedPlayer.get(event.player);
	props.elapseTick();
	if(props.shouldSend()) {
		RPG.INSTANCE.sendTo(new ManaValue(props.getCurrentMana()), (EntityPlayerMP) event.player);
	}
}

 

That every 5 seconds should update the mana value by one. However the game crashes when should send the packet, giving a cast Exception

[03:16:42] [Client thread/ERROR] [FML]: Exception caught during firing event net.minecraftforge.fml.common.gameevent.TickEvent$PlayerTickEvent@1b8354aa:
java.lang.ClassCastException: net.minecraft.client.entity.EntityPlayerSP cannot be cast to net.minecraft.entity.player.EntityPlayerMP
at com.rpg.events.EventHandler.onTick(EventHandler.java:60) ~[EventHandler.class:?]
at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_8_EventHandler_onTick_PlayerTickEvent.invoke(.dynamic) ~[?:?]
at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:49) ~[ASMEventHandler.class:?]
at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:140) [EventBus.class:?]
at net.minecraftforge.fml.common.FMLCommonHandler.onPlayerPostTick(FMLCommonHandler.java:357) [FMLCommonHandler.class:?]
at net.minecraft.entity.player.EntityPlayer.onUpdate(EntityPlayer.java:402) [EntityPlayer.class:?]
at net.minecraft.client.entity.EntityPlayerSP.onUpdate(EntityPlayerSP.java:163) [EntityPlayerSP.class:?]
at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:2011) [World.class:?]
at net.minecraft.world.World.updateEntity(World.java:1976) [World.class:?]
at net.minecraft.world.World.updateEntities(World.java:1805) [World.class:?]
at net.minecraft.client.Minecraft.runTick(Minecraft.java:2176) [Minecraft.class:?]
at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1080) [Minecraft.class:?]
at net.minecraft.client.Minecraft.run(Minecraft.java:380) [Minecraft.class:?]
at net.minecraft.client.main.Main.main(Main.java:116) [Main.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_92]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_92]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_92]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_92]
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?]
at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_92]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_92]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_92]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_92]
at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) [start/:?]
at GradleStart.main(GradleStart.java:26) [start/:?]

 

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

Mmmm, so i could just use one single method in the IEEP class that send the packet with the amount of mana and then call that or send the packet when i change the mana value directly into IEEP functions? For example the setCurrentMana

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

You effectively need two methods in your IEEP (possibly more, but these two are key):

 

addMana(amount)

subtractMana(amount)

 

You could even make them one method, but we'll assume that they perform different checks and might have to be separate.  However the general structure is the same:

 

addSubMana(int amount) {
    /* check if able, floor/ceiling to min/max if needed */
    theManaAmount += amount;
    sendPacketToClient(....);
}

 

Then in

private sendPacketToClient

you...send an update packet to the client informing them of their new mana amount.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Just as i was suspecting, centralized the functions to change mana (basically add or subtract) and then send packets inside them :) Allright, thanks for the tip on optimization :)

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.