Jump to content

Recommended Posts

Posted

Hello!

 

I tried to add an effect when i wear my armor so i try some line of codes:

 

@Override
	public void onArmorTick(World world, EntityPlayer player, ItemStack item)
	{
		if(player.inventory.armorItemInSlot(0) != null &&
			player.inventory.armorItemInSlot(1) != null && 
			player.inventory.armorItemInSlot(2) != null &&
			player.inventory.armorItemInSlot(3) != null)
		{
			if(player.inventory.armorItemInSlot(0).getItem() == ModItems.WULFENITE_BOOTS &&
				player.inventory.armorItemInSlot(1).getItem() == ModItems.WULFENITE_LEGGINGS && 
				player.inventory.armorItemInSlot(2).getItem() == ModItems.WULFENITE_CHESTPLATE &&
				player.inventory.armorItemInSlot(3).getItem() == ModItems.WULFENITE_HELMET)
			{
				player.addPotionEffect(new PotionEffect(Potion.getPotionById(16), 20, 0));
			}
		}
	}

 

Or

 

	@Override
	public void onArmorTick(World world, EntityPlayer player, ItemStack itemStack) {
		
		if (player.inventory.armorItemInSlot(3) != null && player.inventory.armorItemInSlot(3).getItem() == ModItems.WULFENITE_HELMET
				    	        && player.inventory.armorItemInSlot(2) != null && player.inventory.armorItemInSlot(2).getItem() == ModItems.WULFENITE_CHESTPLATE
				    	        && player.inventory.armorItemInSlot(1) != null && player.inventory.armorItemInSlot(1).getItem() == ModItems.WULFENITE_LEGGINGS
				   	        && player.inventory.armorItemInSlot(0) != null && player.inventory.armorItemInSlot(0).getItem() == ModItems.WULFENITE_BOOTS) {
			player.addPotionEffect(new PotionEffect(MobEffects.WATER_BREATHING, 40, 4, false, false));
		}
	}

 

They work perfectly in Solo,

but when i join my SpongeForge server 1.12.2 with my mod, and i wear my armor i get disconnect with the message "Internal Server Error"

In the console, there's this error:

 

net.minecraft.util.ReportedException: Ticking player
at net.minecraft.entity.player.EntityPlayerMP.func_71127_g(EntityPlayerMP.java:459) ~[oq.class:?]
at net.minecraft.network.NetHandlerPlayServer.redirect$onPlayerTick$zjb000(NetHandlerPlayServer.java:2056) ~[pa.class:?]
at net.minecraft.network.NetHandlerPlayServer.func_73660_a(NetHandlerPlayServer.java:173) ~[pa.class:?]
at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher$1.func_73660_a(NetworkDispatcher.java:209) ~[NetworkDispatcher$1.class:?]
at net.minecraft.network.NetworkManager.func_74428_b(NetworkManager.java:285) ~[gw.class:?]
at net.minecraft.network.NetworkSystem.func_151269_c(NetworkSystem.java:180) [oz.class:?]
at net.minecraft.server.MinecraftServer.func_71190_q(MinecraftServer.java:790) [MinecraftServer.class:?]
at net.minecraft.server.dedicated.DedicatedServer.func_71190_q(DedicatedServer.java:397) [nz.class:?]
at net.minecraft.server.MinecraftServer.func_71217_p(MinecraftServer.java:668) [MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:526) [MinecraftServer.class:?]
at java.lang.Thread.run(Thread.java:748) [?:1.8.0_212]
Caused by: java.lang.NoSuchMethodError: net.minecraft.entity.player.InventoryPlayer.func_70440_f(I)Lnet/minecraft/item/ItemStack;
at fr.mrsawz.sawzmod.items.armor.ArmorBase.onArmorTick(ArmorBase.java:71) ~[ArmorBase.class:?]
at net.minecraft.entity.player.InventoryPlayer.func_70429_k(InventoryPlayer.java:371) ~[aec.class:?]
at net.minecraft.entity.player.EntityPlayer.func_70636_d(EntityPlayer.java:511) ~[aed.class:?]
at net.minecraft.entity.EntityLivingBase.func_70071_h_(EntityLivingBase.java:2179) ~[vp.class:?]
at net.minecraft.entity.player.EntityPlayer.func_70071_h_(EntityPlayer.java:234) ~[aed.class:?]
at net.minecraft.entity.player.EntityPlayerMP.func_71127_g(EntityPlayerMP.java:382) ~[oq.class:?]
... 10 more
[11:08:16]: [NetHandlerPlayServer] MrSawZ lost connection: Internal server error

 

I don't know why and i didn't found any pieces of information on the internet.

Can you help me, please? :( 

 

Posted

I do this but it doesn't work 

	public void onArmorTick(World world, EntityLivingBase entitylivingbase, ItemStack itemStack) {

	ItemStack helmet = entitylivingbase.getItemStackFromSlot(EntityEquipmentSlot.HEAD);
			if(helmet.getItem() == ModItems.WULFENITE_HELMET) {
				entitylivingbase.addPotionEffect(new PotionEffect(Potion.getPotionById(16), 20, 0));
			}
	}	

 

I tried to search on the internet, but i only found a little piece of code 

I didn't know how i can do this, i have no more idea

Posted
7 minutes ago, diesieben07 said:
  • Do not use hardcoded numeric IDs. Numeric IDs can and will change. Use the constants in the MobEffects class.
  • Define "does not work".

Ok so i change :

entitylivingbase.addPotionEffect(new PotionEffect(Potion.getPotionById(16), 20, 0));

with this

entitylivingbase.addPotionEffect(new PotionEffect(MobEffects.NIGHT_VISION, 5, 1));

 

 

there is no error in my code but when i put my "Wulfenite Helmet" I have no effects given to me

I think the helmet check on the "EntityEquipmentSlot.HEAD" doesn't work

	public void onArmorTick(World world, EntityLivingBase entitylivingbase, ItemStack itemStack) {

	ItemStack helmet = entitylivingbase.getItemStackFromSlot(EntityEquipmentSlot.HEAD);
			if(helmet.getItem() == ModItems.WULFENITE_HELMET) {
				entitylivingbase.addPotionEffect(new PotionEffect(MobEffects.NIGHT_VISION, 5, 1));
			}
	}	

 

Posted

Ok, so i found the solution after some test,

i leave the code here if someone wants him

		if(itemStack.getItem().equals(ModItems.WULFENITE_HELMET) 
			&& !player.inventory.armorInventory.get(1).isEmpty() 
			&& !player.inventory.armorInventory.get(2).isEmpty() 
			&& !player.inventory.armorInventory.get(0).isEmpty()) // CHECK IF FULL ARMOR PUT ON THE PLAYER	{

			if(player.inventory.armorInventory.get(1).getItem().equals(ModItems.WULFENITE_LEGGINGS) 
				&& player.inventory.armorInventory.get(2).getItem().equals(ModItems.WULFENITE_CHESTPLATE) 
				&& player.inventory.armorInventory.get(0).getItem().equals(ModItems.WULFENITE_BOOTS)) // CHECK IF BOOTS LEGGINGS AND CHESTPLATE IS YOURS	{

			player.addPotionEffect(new PotionEffect(MobEffects.FIRE_RESISTANCE, 20, 0));
			}
		}

 

 

Posted
Quote

if(itemStack.getItem().equals(ModItems.WULFENITE_HELMET) 
			&& !player.inventory.armorInventory.get(1).isEmpty() 
			&& !player.inventory.armorInventory.get(2).isEmpty() 
			&& !player.inventory.armorInventory.get(0).isEmpty())

This "if" check is pointless (the check for non-empty armor part) since you've wrote another "if" checking if the armor is your armor.

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

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.