Jump to content

[1.7.10] getFoodStats().setFoodLevel() in event... @SideOnly(value=CLIENT)


Recommended Posts

Posted

Hi guys!

I'm trying to increase the food level of a player by 2 (so a complete icon on the GUI) or 1 (only if his food level is 19). But when I'm playing on my server, it make it crashes... Maybe because, when I hovered the method

getFoodStats().setFoodLevel()

in Eclipse, I read

@SideOnly(value=CLIENT)

which means that this code can't be "use" (sorry, I don't know which word I can use) by the server. So how can I check it ?

Here's my code :

 

@SubscribeEvent
public void playerAttackMob(AttackEntityEvent event)
{	
	if(event.entityPlayer.getHeldItem() != null && event.entityPlayer.getHeldItem().getItem() instanceof SapphireSceptre)
	{
		System.out.println("Test - Sapphire sceptre in hand!");
		EntityLivingBase target = null;

		if(event.target instanceof EntityLiving)
		{
			target = (EntityLivingBase) event.target;
		}


		if(event.target instanceof IMob)
		{
			System.out.println("Hit a munter with sapphire sceptre");
			event.entityPlayer.setHealth(event.entityPlayer.getHealth() + 2);
			target.addPotionEffect(new PotionEffect(Potion.wither.id, 1200));
		}
		else if(event.target instanceof IAnimals)
		{
			System.out.println("Hit an animal with sapphire sceptre");
			if(event.entityPlayer.getFoodStats().getFoodLevel() == 20)
			{
				event.entityPlayer.getFoodStats().setFoodLevel(20);
			}
			else if(event.entityPlayer.getFoodStats().getFoodLevel() < 18)
			{
				event.entityPlayer.getFoodStats().setFoodLevel(event.entityPlayer.getFoodStats().getFoodLevel() + 2);
			}
			else if(event.entityPlayer.getFoodStats().getFoodLevel() == 19)
			{
				event.entityPlayer.getFoodStats().setFoodLevel(event.entityPlayer.getFoodStats().getFoodLevel() + 1);
			}
		}
		else if(event.target instanceof EntityPlayer)
		{
			System.out.println("Hit a player with sapphire sceptre");
			((EntityPlayer) event.target).setHealth(target.getHealth() + 6);
		}

	}
}

 

And here's the crash log:

 

[18:55:10] [server thread/INFO]: Starting minecraft server version 1.7.10
[18:55:10] [server console handler/ERROR]: Exception handling console input
java.io.IOException: Descripteur non valide
at java.io.FileInputStream.readBytes(Native Method) ~[?:1.8.0_25]
at java.io.FileInputStream.read(Unknown Source) ~[?:1.8.0_25]
at java.io.BufferedInputStream.read1(Unknown Source) ~[?:1.8.0_25]
at java.io.BufferedInputStream.read(Unknown Source) ~[?:1.8.0_25]
at sun.nio.cs.StreamDecoder.readBytes(Unknown Source) ~[?:1.8.0_25]
at sun.nio.cs.StreamDecoder.implRead(Unknown Source) ~[?:1.8.0_25]
at sun.nio.cs.StreamDecoder.read(Unknown Source) ~[?:1.8.0_25]
at java.io.InputStreamReader.read(Unknown Source) ~[?:1.8.0_25]
at java.io.BufferedReader.fill(Unknown Source) ~[?:1.8.0_25]
at java.io.BufferedReader.readLine(Unknown Source) ~[?:1.8.0_25]
at java.io.BufferedReader.readLine(Unknown Source) ~[?:1.8.0_25]
at net.minecraft.server.dedicated.DedicatedServer$2.run(DedicatedServer.java:97) [lv.class:?]
[18:55:14] [server thread/INFO]: Loading properties
[18:55:14] [server thread/INFO]: Default game type: SURVIVAL
[18:55:14] [server thread/INFO]: Generating keypair
[18:55:14] [server thread/INFO]: Starting Minecraft server on *:25565
[18:55:14] [server thread/WARN]: **** SERVER IS RUNNING IN OFFLINE/INSECURE MODE!
[18:55:14] [server thread/WARN]: The server will make no attempt to authenticate usernames. Beware.
[18:55:14] [server thread/WARN]: While this makes the game possible to play without internet access, it also opens up the ability for hackers to connect with any username they choose.
[18:55:14] [server thread/WARN]: To change this, set "online-mode" to "true" in the server.properties file.
[18:55:15] [server thread/INFO]: Preparing level "world"
[18:55:15] [server thread/INFO]: Preparing start region for level 0
[18:55:16] [server thread/INFO]: Done (1,154s)! For help, type "help" or "?"
[18:55:59] [server thread/INFO]: MrAlexan14[/127.0.0.1:51010] logged in with entity id 229 at (-217.42040031834762, 66.0, 183.91979448208335)
[18:55:59] [server thread/INFO]: MrAlexan14 joined the game
[18:56:08] [server thread/INFO]: [MrAlexan14: Object successfully summoned]
[18:56:10] [server thread/ERROR]: Encountered an unexpected exception
java.lang.NoSuchMethodError: net.minecraft.util.FoodStats.func_75114_a(I)V
at com.mralexan.sapphiremod.events.SapphireEventHandler.playerAttackMob(SapphireEventHandler.java:72) ~[sapphireEventHandler.class:?]
at cpw.mods.fml.common.eventhandler.ASMEventHandler_7_SapphireEventHandler_playerAttackMob_AttackEntityEvent.invoke(.dynamic) ~[?:?]
at cpw.mods.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:54) ~[ASMEventHandler.class:?]
at cpw.mods.fml.common.eventhandler.EventBus.post(EventBus.java:138) ~[EventBus.class:?]
at net.minecraft.entity.player.EntityPlayer.func_71059_n(EntityPlayer.java:1185) ~[yz.class:?]
at net.minecraft.network.NetHandlerPlayServer.func_147340_a(NetHandlerPlayServer.java:821) ~[nh.class:?]
at net.minecraft.network.play.client.C02PacketUseEntity.func_148833_a(SourceFile:55) ~[ja.class:?]
at net.minecraft.network.play.client.C02PacketUseEntity.func_148833_a(SourceFile:10) ~[ja.class:?]
at net.minecraft.network.NetworkManager.func_74428_b(NetworkManager.java:212) ~[ej.class:?]
at net.minecraft.network.NetworkSystem.func_151269_c(NetworkSystem.java:165) ~[nc.class:?]
at net.minecraft.server.MinecraftServer.func_71190_q(MinecraftServer.java:659) ~[MinecraftServer.class:?]
at net.minecraft.server.dedicated.DedicatedServer.func_71190_q(DedicatedServer.java:334) ~[lt.class:?]
at net.minecraft.server.MinecraftServer.func_71217_p(MinecraftServer.java:547) ~[MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:427) [MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:685) [li.class:?]
[18:56:10] [server thread/ERROR]: This crash report has been saved to: C:\Users\Alexandre\Documents\Minecraft forge server\.\crash-reports\crash-2015-01-29_18.56.10-server.txt
[18:56:10] [server thread/INFO]: Stopping server
[18:56:10] [server thread/INFO]: Saving players
[18:56:10] [server thread/INFO]: Saving worlds
[18:56:10] [server thread/INFO]: Saving chunks for level 'world'/Overworld
[18:56:10] [server thread/INFO]: Saving chunks for level 'world'/Nether
[18:56:10] [server thread/INFO]: Saving chunks for level 'world'/The End
[18:56:10] [server thread/INFO]: Saving chunks for level 'world'/Erebus

 

Posted

Yeah, when I was messing around with this, I had to use potion effects.  A half-shank worth is like 5 ticks worth of the Saturation effect.

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.

Posted

Sorry, but I'm not sure to understand your post...

So you think that the better is to use a PotionEffect ? Like HungerRegeneration ? Because if it's what you're saying, I don't find it (I find Potion.hunger.id but I think it do the contrary of what I want to do)...

Posted

Hunger is negative food.  That's why I said "Saturation."

 

Saturation Causes food meter to be replenished by 1 (Half Hunger.svg) per tick. 1 (Half Hunger.svg) is added with each additional level Referenced by “Potion of Saturation” by game, but potion not currently present unless using custom potion features

 

Red At level 20 it fills the hunger bar in a tick. If a "corrupt" potion is used, hunger bar is decreased; at most levels, player will take starvation damage.

 

And my mistake it was 1 half-shank per tick.

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.

Posted

It's a potion effect.  I don't know how I can be any more clear about this.

 

I opened up the list of potions and look at what I found:

public static final Potion field_76443_y = (new PotionHealth(23, false, 16262179)).setPotionName("potion.saturation");

 

It doesn't have a deobf field name, but it still says "potion.saturation"

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.

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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