Your message is being sent twice because Item#onItemUse is called on both the client and the server. Check which side the method is being called on using the world.isRemote field: it's true on the client and false on the server.
Never use the Minecraft class outside of client-only classes like GUIs, otherwise your code will crash on dedicated servers (because it's a client-only class). Send the chat message to the EntityPlayer argument of the method rather than sending it to the client player (from Minecraft#thePlayer).
Rollback Post to RevisionRollBack
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Please help me ...
when i right click item, instead only 1 action, 2 action coming.
example
action: send message Hello World
Output:
1. Hello World
2. Hello World
2 action instead 1
Please help me fix again...
Code
package com.jvbtwentyone.trymod.items;
import java.util.List;
import com.jvbtwentyone.trymod.GlobalVariables;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.BlockPos;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class ItemTry extends Item
{
@Override
public boolean onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ)
{
if(!playerIn.isSneaking())
{
if(stack.getTagCompound() == null)
{
stack.setTagCompound(new NBTTagCompound());
}
if(true){
GlobalVariables.Usecount = GlobalVariables.Usecount + 1;
NBTTagCompound nbt = new NBTTagCompound();
nbt.setInteger("dim", playerIn.dimension);
nbt.setInteger("posX", pos.getX());
nbt.setInteger("posY", pos.getY());
nbt.setInteger("posZ", pos.getZ());
stack.getTagCompound().setTag("Trys", nbt);
stack.setStackDisplayName(EnumChatFormatting.AQUA + "Trys Item");
Minecraft.getMinecraft().thePlayer.sendChatMessage("======Your position======");
Minecraft.getMinecraft().thePlayer.sendChatMessage("Dim " + playerIn.dimension + " X:" + pos.getX() + " Y:" + pos.getY() + " Z:" + pos.getZ());
Minecraft.getMinecraft().thePlayer.sendChatMessage("/time set day");
}
}
return false;
}
@Override
public ItemStack onItemRightClick(ItemStack stack, World worldIn, EntityPlayer playerIn)
{
if(playerIn.isSneaking())
{
if(stack.getTagCompound() != null)
{
stack.getTagCompound().removeTag("Trys");
stack.clearCustomName();
GlobalVariables.Usecount = 0;
}
}
return stack;
}
@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, EntityPlayer playerIn, List tooltip, boolean advanced)
{
if(stack.getTagCompound() != null)
{
if(stack.getTagCompound().hasKey("Trys"))
{
NBTTagCompound nbt = (NBTTagCompound) stack.getTagCompound().getTag("Trys");
int dim = nbt.getInteger("dim");
int posX = nbt.getInteger("posX");
int posY = nbt.getInteger("posY");
int posZ = nbt.getInteger("posZ");
tooltip.add("Dim " + dim + " X:" + posX + " Y:" + posY + " Z:" + posZ);
tooltip.add("Usecount:" + GlobalVariables.Usecount);
}
}
}
@Override
@SideOnly(Side.CLIENT)
public boolean hasEffect(ItemStack stack)
{
if(stack.getTagCompound() != null)
{
return stack.getTagCompound().hasKey("Trys");
}
return false;
}
}
Please support my mod. I'm first time modder in here
Your message is being sent twice because Item#onItemUse is called on both the client and the server. Check which side the method is being called on using the world.isRemote field: it's true on the client and false on the server.
Never use the Minecraft class outside of client-only classes like GUIs, otherwise your code will crash on dedicated servers (because it's a client-only class). Send the chat message to the EntityPlayer argument of the method rather than sending it to the client player (from Minecraft#thePlayer).
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
And this GlobalVariables.Usecount = GlobalVariables.Usecount + 1; Result in game is 2 how to fix it please help me....
There's no world.isRemote in my codes.
Please support my mod. I'm first time modder in here
Both methods onItemUse and onItemRightClick should give you a world parameter.
I checked your code an you have called them worldIn ...
So you can create a if statement to check if worldIn.isRemote (That should be possible in 1.7.10 and 1.8 aswell)
TechMage66
You are also making a pointless check: if(true) is completely unnecessary, the else part will never be called
If I helped you, please click the green up arrow.
Where should i put this in my code part? Eclipse said rename in file...
Please support my mod. I'm first time modder in here
Ok i fixed it now, thanks for helpers :), but i can't use the item anymore i used it only one time please help...
Please support my mod. I'm first time modder in here
Need more help please...
Please support my mod. I'm first time modder in here
Post your code on Gist or Pastebin.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.