Jump to content

Recommended Posts

Posted

So I was following a tutorial to add a potion effect when holding item, my code is:

@Override

public void onUpdate(ItemStack stack, World world, Entity entity, int par4, boolean par5){

System.out.println("First update is Successfull");

super.onUpdate(stack, world, entity, par4, par5);

System.out.println("Update Successfull");

{

EntityPlayer player = (EntityPlayer) entity;

ItemStack equipped = player.getCurrentEquippedItem();

System.out.println("Found held item");

if(player.getCurrentEquippedItem().equals(stack)){

System.out.println("Found Item Successfully");

player.addPotionEffect(new PotionEffect(Potion.moveSpeed.id, 5, 3));

System.out.println("Added Potion Effect Successfully");

}

}

}

 

I have all of the System.out.println to see where my code was getting stuck and it is getting stuck on the first line. This code works for many people but not me. I am using the most recent version of Eclipse, Forge 1.7.10 and jre1.8.0_45.

Posted

-The extra braces are to close of the ones I opened.

-What can I remove?

-So this mod would not work in single player?

-Then what would I put instead of entity?

Posted

My full code for that item is:

 

package com.farline.item;

 

 

import com.farline.creativetabs.MCreativeTabs;

 

import com.farline.lib.RefStrings;

 

 

import net.minecraft.creativetab.CreativeTabs;

import net.minecraft.entity.Entity;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.item.Item;

import net.minecraft.item.ItemStack;

import net.minecraft.potion.Potion;

import net.minecraft.potion.PotionEffect;

import net.minecraft.world.World;

import net.minecraftforge.common.util.EnumHelper;

import cpw.mods.fml.common.registry.GameRegistry;

 

public class SpeedStick extends Item{

 

public SpeedStick() {

this.setFull3D();

}

 

public static void main(String[] args){

 

}

 

public static void mainRegistry(){

initializeItem();

registerItem();

}

 

public static Item sStick;

 

public static void initializeItem(){

sStick = new Item().setUnlocalizedName("sStick").setMaxStackSize(1).setCreativeTab(MCreativeTabs.tabItems).setTextureName(RefStrings.MODID + ":SpeedStick");

 

}

 

public static void registerItem(){

GameRegistry.registerItem(sStick, sStick.getUnlocalizedName());

System.out.println("Added Item Successfully");

}

 

@Override

public void onUpdate(ItemStack stack, World world, Entity entity, int par4, boolean par5){

System.out.println("First update is Successfull");

super.onUpdate(stack, world, entity, par4, par5);

System.out.println("Update Successfull");

{

EntityPlayer player = (EntityPlayer) entity;

ItemStack equipped = player.getCurrentEquippedItem();

System.out.println("Found held item");

if(player.getCurrentEquippedItem().equals(stack)){

System.out.println("Found Item Successfully");

player.addPotionEffect(new PotionEffect(Potion.moveSpeed.id, 5, 3));

System.out.println("Added Potion Effect Successfully");

}

}

}

 

}

 

If that helps at all.

Posted

New code:

 

@Override

public void onUpdate(ItemStack stack, World world, Entity entity, int par4, boolean par5){

System.out.println("First update is Successfull");

super.onUpdate(stack, world, entity, par4, par5);

System.out.println("Update Successfull");

 

EntityPlayer player = (EntityPlayer) entity;

ItemStack equipped = player.getCurrentEquippedItem();

System.out.println("Found held item");

System.out.println("Found Item Successfully");

player.addPotionEffect(new PotionEffect(Potion.moveSpeed.id, 5, 3));

System.out.println("Added Potion Effect Successfully");

}

Posted

world.isRemote - client

!world.isRemote - server

 

Everything that is "logic" part of game should always happen on server (spawning, updates, changing values, etc.)

 

entity instanceof EntityPlayer - if true you know that it is player, before that you can't touch player methods.

  Quote

1.7.10 is no longer supported by forge, you are on your own.

Posted

I have never touched this part of mods before, so can someone please help me out and insert what everyone is telling me to insert into the proper place, because i don't know where to put it.

Posted

I have tryed

if(!world.isRemote && entity instanceof EntityPlayer){

player.addPotionEffect(new PotionEffect(Potion.moveSpeed.id, 5, 3));

}

NO luck though

Posted

The println messages are not apearing. The first line:

public void onUpdate(ItemStack stack, World world, Entity entity, int par4, boolean par5){

println message isnt even apearing

Guest
This topic is now closed to further replies.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • My name is Richie Leo, and I’m sharing this message with a heart full of gratitude and hope. Several months ago, I was a victim of a devastating online scam that cost me a staggering $873,463. I was devastated, confused, and had nearly given up on ever recovering my money — until I came across Wizard George Cyber Service. Through their exceptional cyber recovery expertise and deep investigative skills, Wizard George and his team were able to trace, track, and recover the full amount that was stolen from me. Their professionalism, speed, and transparency truly amazed me. If you’re reading this and you’ve been scammed — whether it’s crypto, investment fraud, or any kind of online theft — don’t give up. I strongly recommend reaching out to Wizard George Cyber Service. 📧 Em: wizardgeorgecyberservice(AT) g m a l L. C o M
    • Alright, here is the log file https://mclo.gs/5eCwafV
    • Please read the FAQ (https://forums.minecraftforge.net/topic/125488-rules-and-frequently-asked-questions-faq/) and post log files as described there, using a site such as https://mclo.gs/ and post the link here.  
    • I tried updating the mods in my modpack which caused incompatibilities so i have tried to revert them back to their older versions i was using before. In the logs it doesnt show me any clear incompatibilities except for tfmg & entity texture features, but when i try to remove those it still doesn't work. I have tried removing the forge-client.toml file which was a suggestion i found on  a few other posts. This is the log file i get. [inline log removed] Any help would be appreciated. Thanks in advance
    • I don't use KubeJS, never even heard of it. But after doing what "Ugdhar" suggested earlier in this post with the "config/Mekanism/generator-storage.toml", I tried going into an individual save's serverconfig folder, and just deleting everything except the parcool folder (I have that mod installed.) Then, a bit of loading and temporary freezing later, seems to have worked. Even when quitting to menu and loading back in, or also when quitting to menu, exiting to desktop, and re-launching MC, choose a save and loading it.
  • Topics

  • Who's Online (See full list)

    • There are no registered users currently online
×
×
  • Create New...

Important Information

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