I can't damage items?

Started by AFranklin78000 on

Topic category: Troubleshooting, bugs, and solutions

Last seen on 00:37, 24. May 2018
Joined Jan 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I can't damage items?

I am trying to damage items upon right click but it's not working... Here is the code and the gradle log:

 

Code:

 

package mod.mcreator;

import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.common.util.EnumHelper;

import net.minecraft.world.World;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ActionResult;
import net.minecraft.server.MinecraftServer;
import net.minecraft.item.ItemSword;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Item;
import net.minecraft.init.Blocks;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.effect.EntityLightningBolt;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.client.Minecraft;

import java.util.Set;
import java.util.Random;
import java.util.HashMap;

public class mcreator_voidSword {

public mcreator_voidSword() {
}

public static Item block;
public static Object instance;

public void load(FMLInitializationEvent event) {
ItemStack stack = new ItemStack(block, 1);
if (event.getSide() == Side.CLIENT)
Minecraft.getMinecraft().getRenderItem().getItemModelMesher()
.register(block, 0, new ModelResourceLocation("testenvironmentmod:voidsword", "inventory"));

GameRegistry.addRecipe(stack,
new Object[]{"012", "345", "678", Character.valueOf('0'), mcreator_netherStarBlock.block, Character.valueOf('1'),
mcreator_voidBlock.block, Character.valueOf('2'), mcreator_netherStarBlock.block, Character.valueOf('3'),
mcreator_netherStarBlock.block, Character.valueOf('4'), mcreator_voidBlock.block, Character.valueOf('5'),
mcreator_netherStarBlock.block, Character.valueOf('6'), mcreator_netherStarBlock.block, Character.valueOf('7'),
Blocks.OBSIDIAN, Character.valueOf('8'), mcreator_netherStarBlock.block,});
}

public void generateNether(World world, Random random, int chunkX, int chunkZ) {
}

public void generateSurface(World world, Random random, int chunkX, int chunkZ) {
}

public int addFuel(ItemStack fuel) {
return 0;
}

public void serverLoad(FMLServerStartingEvent event) {
}

public void preInit(FMLPreInitializationEvent event) {
}

public void registerRenderers() {
}

static {
Item.ToolMaterial enumt = EnumHelper.addToolMaterial("VOIDSWORD", 1, 1000, 4F, 20, 2);
block = (Item) (new ItemSword(enumt) {
public Set<String> getToolClasses(ItemStack stack) {
HashMap<String, Integer> ret = new HashMap<String, Integer>();
ret.put("sword", 1);
return ret.keySet();
}

@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer entity, EnumHand hand) {
float var4 = 1.0F;
ActionResult<ItemStack> ar = super.onItemRightClick(world, entity, hand);
int i = (int) (entity.prevPosX + (entity.posX - entity.prevPosX) * (double) var4);
int j = (int) (entity.prevPosY + (entity.posY - entity.prevPosY) * (double) var4 + 1.62D);
int k = (int) (entity.prevPosZ + (entity.posZ - entity.prevPosZ) * (double) var4);

if (true) {
if (entity instanceof EntityPlayerMP) {
MinecraftServer minecraftserver = FMLCommonHandler.instance().getMinecraftServerInstance();
if (minecraftserver != null)
minecraftserver.getCommandManager().executeCommand((EntityPlayerMP) entity, "gamerule sendCommandFeedback false");
}
}

if (true) {
if (entity instanceof EntityPlayerMP) {
MinecraftServer minecraftserver = FMLCommonHandler.instance().getMinecraftServerInstance();
if (minecraftserver != null)
minecraftserver.getCommandManager().executeCommand((EntityPlayerMP) entity, "scoreboard players tag @a add Safe");
}
}

if (true) {
if (entity instanceof EntityPlayerMP) {
MinecraftServer minecraftserver = FMLCommonHandler.instance().getMinecraftServerInstance();
if (minecraftserver != null)
minecraftserver.getCommandManager().executeCommand((EntityPlayerMP) entity,
"scoreboard players tag @e[type=item] add Safe");
}
}

if (true) {
if (entity instanceof EntityPlayerMP) {
MinecraftServer minecraftserver = FMLCommonHandler.instance().getMinecraftServerInstance();
if (minecraftserver != null)
minecraftserver.getCommandManager().executeCommand((EntityPlayerMP) entity, "kill @e[tag=!Safe,r=10]");
}
}

if (true) {
world.spawnParticle(EnumParticleTypes.PORTAL, (double) i, (double) 1, (double) k, 2.0D, 2.0D, 2.0D);
}

if (true) {
itemstack.damageItem(1, entity);
}

return ar;
}

@Override
public void onCreated(ItemStack itemstack, World world, EntityPlayer entity) {
super.onCreated(itemstack, world, entity);
float var4 = 1.0F;
int i = (int) (entity.prevPosX + (entity.posX - entity.prevPosX) * (double) var4);
int j = (int) (entity.prevPosY + (entity.posY - entity.prevPosY) * (double) var4 + 1.62D);
int k = (int) (entity.prevPosZ + (entity.posZ - entity.prevPosZ) * (double) var4);

if (true) {
world.spawnEntity(new EntityLightningBolt(world, i, j, k, false));
}

}
}).setUnlocalizedName("VoidSword");
block.setRegistryName("VoidSword");
GameRegistry.register(block);
block.setCreativeTab(mcreator_voidTab.tab);

}

}

 

 

 

Gradle log:

 

 

warning: [options] bootstrap class path not set in conjunction with -source 1.6
C:\Pylo\MCreator175\forge\build\sources\main\java\mod\mcreator\mcreator_voidSword.java:126: error: cannot find symbol
itemstack.damageItem(1, entity);
^
symbol: variable itemstack
C:\Pylo\MCreator175\forge\build\sources\main\java\mod\mcreator\mcreator_voidPickaxe.java:107: error: cannot find symbol
itemstack.damageItem(1, entity);
^
symbol: variable itemstack
C:\Pylo\MCreator175\forge\build\sources\main\java\mod\mcreator\mcreator_voidBreaker.java:89: error: cannot find symbol
itemstack.damageItem(1, entity);
^
symbol: variable itemstack
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
3 errors
1 warning

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.


 

There are other tools I am trying to damage too as you can see but they all have the same problem...

Last seen on 04:01, 2. Jun 2019
Joined Nov 2014
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Let's say you had a sword
Thu, 03/30/2017 - 20:51

Let's say you had a sword that you wanted to have lose durabilty when every you hit,
You would do this:
Add a tool type, name it, add a texture, name it change the tool type to "Sword" Change the other stuff to your perfernce. we're gonna wanna change the number of uses to a high number for me i put 900 (Higher then diamond) then click next.
then do the rest as you would/want.

When ever you hit a mob or break a block you lose durabilty a.k.a the tool is taking damge.
This works with ANY tool.

Last seen on 00:37, 24. May 2018
Joined Jan 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
RE:Let's say you had a sword
Tue, 05/02/2017 - 18:59

@#1 That's not what I am trying to do. I want the tool to DAMAGE on RIGHT click. I found out how to make tools like that already I just want it to damage upon RIGHT click.

 

Last seen on 00:42, 9. Sep 2017
Joined Apr 2015
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
RE:RE:Let's say you had a sword
Wed, 08/16/2017 - 20:50

@#1.1 I am having the same problem also and I thought I would find the answer to it here but I guess no one has answered it yet. It's kind of weird that they put things into mcreator that don't even function properly. Please someone help us!

Last seen on 11:29, 6. Jun 2019
Joined Aug 2017
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
What type of damage are we
Wed, 08/16/2017 - 21:43

What type of damage are we talking, from what you said I think what you mean is when you right click you want it to damage the durability of the item, or are we talking damaging whatever you are targeted at? 

Last seen on 00:42, 9. Sep 2017
Joined Apr 2015
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
RE:What type of damage are we
Thu, 08/17/2017 - 17:08

@#2 We want to have the tool lose durability on right click. I know when I do right click in air->damage item, finish it and let the gradle run I get an error; here is my code for the sword i was working on:

 

  import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.common.registry.GameRegistry; import net.minecraftforge.fml.common.event.FMLServerStartingEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.common.util.EnumHelper;   import net.minecraft.world.World; import net.minecraft.util.EnumHand; import net.minecraft.util.ActionResult; import net.minecraft.item.ItemSword; import net.minecraft.item.ItemStack; import net.minecraft.item.Item; import net.minecraft.init.Items; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.client.renderer.block.model.ModelResourceLocation; import net.minecraft.client.Minecraft;   import java.util.Set; import java.util.Random; import java.util.HashMap;   public class mcreator_sugarObsidianSword {   public mcreator_sugarObsidianSword() { }   public static Item block; public static Object instance;   public void load(FMLInitializationEvent event) { ItemStack stack = new ItemStack(block, 1); if (event.getSide() == Side.CLIENT) Minecraft.getMinecraft().getRenderItem().getItemModelMesher() .register(block, 0, new ModelResourceLocation("testenvironmentmod:sugarobsidiansword", "inventory"));   GameRegistry.addRecipe(stack, new Object[]{"X1X", "X4X", "X7X", Character.valueOf('1'), mcreator_sugarObsidianAlloy.block, Character.valueOf('4'), mcreator_sugarObsidianAlloy.block, Character.valueOf('7'), Items.STICK,}); }   public void generateNether(World world, Random random, int chunkX, int chunkZ) { }   public void generateSurface(World world, Random random, int chunkX, int chunkZ) { }   public int addFuel(ItemStack fuel) { return 0; }   public void serverLoad(FMLServerStartingEvent event) { }   public void preInit(FMLPreInitializationEvent event) { }   public void registerRenderers() { }   static { Item.ToolMaterial enumt = EnumHelper.addToolMaterial("SUGAROBSIDIANSWORD", 1, 100, 1F, 5, 2); block = (Item) (new ItemSword(enumt) { public Set<String> getToolClasses(ItemStack stack) { HashMap<String, Integer> ret = new HashMap<String, Integer>(); ret.put("sword", 1); return ret.keySet(); }   @Override public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer entity, EnumHand hand) { float var4 = 1.0F; ActionResult<ItemStack> ar = super.onItemRightClick(world, entity, hand); int i = (int) (entity.prevPosX + (entity.posX - entity.prevPosX) * (double) var4); int j = (int) (entity.prevPosY + (entity.posY - entity.prevPosY) * (double) var4 + 1.62D); int k = (int) (entity.prevPosZ + (entity.posZ - entity.prevPosZ) * (double) var4);   if (true) { itemstack.damageItem(10, entity); }   return ar; } }).setUnlocalizedName("SugarObsidianSword"); block.setRegistryName("SugarObsidianSword"); GameRegistry.register(block); block.setCreativeTab(CreativeTabs.COMBAT);   }   }
Last seen on 12:58, 23. Sep 2019
Joined Aug 2014
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
RE:RE:What type of damage are we
Tue, 08/22/2017 - 17:39

@#2.1 The solution is to add "ItemStack itemstack," just before "World, world...." in the itemOnRightClick event but doing so, it give you "@Override" error.

Removing @Override won't let you get any error, but right click event won't work...

Need help please...

Last seen on 12:58, 23. Sep 2019
Joined Aug 2014
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
RE:RE:What type of damage are we
Thu, 08/24/2017 - 11:29

@#2.1 The solution is to use getHeldItemMainHand() instead of itemstack and the item will lose durability (thanks to Nuparu00)

Last seen on 00:42, 9. Sep 2017
Joined Apr 2015
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
So, I modified the bit of
Sat, 08/26/2017 - 23:09
So, I modified the bit of code like  you said but I still get the error message! I think we need to get the Pylo devs on these things also because the program isn't supposed to be about fixing errors all the time.   import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.common.registry.GameRegistry; import net.minecraftforge.fml.common.event.FMLServerStartingEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.common.util.EnumHelper;   import net.minecraft.world.World; import net.minecraft.util.EnumHand; import net.minecraft.util.ActionResult; import net.minecraft.item.ItemSword; import net.minecraft.item.ItemStack; import net.minecraft.item.Item; import net.minecraft.init.Items; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.client.renderer.block.model.ModelResourceLocation; import net.minecraft.client.Minecraft;   import java.util.Set; import java.util.Random; import java.util.HashMap;   public class mcreator_sugarObsidianSword {   public mcreator_sugarObsidianSword() { }   public static Item block; public static Object instance;   public void load(FMLInitializationEvent event) { ItemStack stack = new ItemStack(block, 1); if (event.getSide() == Side.CLIENT) Minecraft.getMinecraft().getRenderItem().getItemModelMesher() .register(block, 0, new ModelResourceLocation("testenvironmentmod:sugarobsidiansword", "inventory"));   GameRegistry.addRecipe(stack, new Object[]{"X1X", "X4X", "X7X", Character.valueOf('1'), mcreator_sugarObsidianAlloy.block, Character.valueOf('4'), mcreator_sugarObsidianAlloy.block, Character.valueOf('7'), Items.STICK,}); }   public void generateNether(World world, Random random, int chunkX, int chunkZ) { }   public void generateSurface(World world, Random random, int chunkX, int chunkZ) { }   public int addFuel(ItemStack fuel) { return 0; }   public void serverLoad(FMLServerStartingEvent event) { }   public void preInit(FMLPreInitializationEvent event) { }   public void registerRenderers() { }   static { Item.ToolMaterial enumt = EnumHelper.addToolMaterial("SUGAROBSIDIANSWORD", 1, 100, 1F, 5, 2); block = (Item) (new ItemSword(enumt) { public Set<String> getToolClasses(ItemStack stack) { HashMap<String, Integer> ret = new HashMap<String, Integer>(); ret.put("sword", 1); return ret.keySet(); }   @Override public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer entity, EnumHand hand) { float var4 = 1.0F; ActionResult<ItemStack> ar = super.onItemRightClick(world, entity, hand); int i = (int) (entity.prevPosX + (entity.posX - entity.prevPosX) * (double) var4); int j = (int) (entity.prevPosY + (entity.posY - entity.prevPosY) * (double) var4 + 1.62D); int k = (int) (entity.prevPosZ + (entity.posZ - entity.prevPosZ) * (double) var4);   if (true) { getHeldItemMainHand.damageItem(10, entity); }   return ar; } }).setUnlocalizedName("SugarObsidianSword"); block.setRegistryName("SugarObsidianSword"); GameRegistry.register(block); block.setCreativeTab(CreativeTabs.COMBAT);   }   }
Last seen on 17:17, 10. Jan 2024
Joined Aug 2013
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
getHeldItemMainHand()  is a
Sat, 08/26/2017 - 23:24

getHeldItemMainHand()  is a method, you have to keep the brackets. Also, it is method in EntityPlayer so you need to call it from the player instance (EntityPlayer.getHeldItemMainHand(), instead of EntityPlayer use your EntityPlayer instance, in your case - entity)

Last seen on 00:42, 9. Sep 2017
Joined Apr 2015
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
RE:getHeldItemMainHand()  is a
Wed, 08/30/2017 - 06:44

@#4

Is this correct? If so, it still doesn't work as it game up with another error message. Here's the code:   import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.common.registry.GameRegistry; import net.minecraftforge.fml.common.event.FMLServerStartingEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.common.util.EnumHelper;   import net.minecraft.world.World; import net.minecraft.util.EnumHand; import net.minecraft.util.ActionResult; import net.minecraft.item.ItemSword; import net.minecraft.item.ItemStack; import net.minecraft.item.Item; import net.minecraft.init.Items; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.client.renderer.block.model.ModelResourceLocation; import net.minecraft.client.Minecraft;   import java.util.Set; import java.util.Random; import java.util.HashMap;   public class mcreator_sugarObsidianSword {   public mcreator_sugarObsidianSword() { }   public static Item block; public static Object instance;   public void load(FMLInitializationEvent event) { ItemStack stack = new ItemStack(block, 1); if (event.getSide() == Side.CLIENT) Minecraft.getMinecraft().getRenderItem().getItemModelMesher() .register(block, 0, new ModelResourceLocation("testenvironmentmod:sugarobsidiansword", "inventory"));   GameRegistry.addRecipe(stack, new Object[]{"X1X", "X4X", "X7X", Character.valueOf('1'), mcreator_sugarObsidianAlloy.block, Character.valueOf('4'), mcreator_sugarObsidianAlloy.block, Character.valueOf('7'), Items.STICK,}); }   public void generateNether(World world, Random random, int chunkX, int chunkZ) { }   public void generateSurface(World world, Random random, int chunkX, int chunkZ) { }   public int addFuel(ItemStack fuel) { return 0; }   public void serverLoad(FMLServerStartingEvent event) { }   public void preInit(FMLPreInitializationEvent event) { }   public void registerRenderers() { }   static { Item.ToolMaterial enumt = EnumHelper.addToolMaterial("SUGAROBSIDIANSWORD", 1, 100, 4F, 5, 2); block = (Item) (new ItemSword(enumt) { public Set<String> getToolClasses(ItemStack stack) { HashMap<String, Integer> ret = new HashMap<String, Integer>(); ret.put("sword", 1); return ret.keySet(); }   @Override public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer entity, EnumHand hand) { float var4 = 1.0F; ActionResult<ItemStack> ar = super.onItemRightClick(world, entity, hand); int i = (int) (entity.prevPosX + (entity.posX - entity.prevPosX) * (double) var4); int j = (int) (entity.prevPosY + (entity.posY - entity.prevPosY) * (double) var4 + 1.62D); int k = (int) (entity.prevPosZ + (entity.posZ - entity.prevPosZ) * (double) var4);   if (true) { entity.getHeldItemMainHand().damageItem(10, entity); }   return ar; } }).setUnlocalizedName("SugarObsidianSword"); block.setRegistryName("SugarObsidianSword"); GameRegistry.register(block); block.setCreativeTab(CreativeTabs.COMBAT);   }   }
Last seen on 12:58, 23. Sep 2019
Joined Aug 2014
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
RE:RE:getHeldItemMainHand()  is a
Wed, 08/30/2017 - 16:33

@#4.1 Why you're not posting the error too, it would be faster for us D:

Btw, you have to set entity as instance of EntityPlayer

Last seen on 00:42, 9. Sep 2017
Joined Apr 2015
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
First of all, sorry for not
Wed, 09/06/2017 - 02:09

First of all, sorry for not posting the error log; didn't think about it. So here that is:

warning: [options] bootstrap class path not set in conjunction with -source 1.6  C:\Pylo\MCreator175\forge\build\sources\main\java\mod\mcreator\mcreator_sugarObsidi3anSword.java:82: error: cannot find symbol itemstack.damageItem(10, entity); ^   symbol: variable itemstack Note: C:\Pylo\MCreator175\forge\build\sources\main\java\mod\mcreator\mcreator_compactedLeaves.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. 1 error 1 warning   FAILURE: Build failed with an exception.   * What went wrong: Execution failed for task ':compileJava'. > Compilation failed; see the compiler error output for details.   * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.       I am not very familiar with code so I don't quite know what you mean by setting the instance as EntityPlayer but I am pretty sure the log will help you out.
Last seen on 00:42, 9. Sep 2017
Joined Apr 2015
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Oh, for some reason it was
Wed, 09/06/2017 - 02:11
Oh, for some reason it was cut off, here is the full log:   warning: [options] bootstrap class path not set in conjunction with -source 1.6 C:\Pylo\MCreator175\forge\build\sources\main\java\mod\mcreator\mcreator_sugarObsidianSword.java:82: error: cannot find symbol itemstack.damageItem(10, entity); ^   symbol: variable itemstack Note: C:\Pylo\MCreator175\forge\build\sources\main\java\mod\mcreator\mcreator_compactedLeaves.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. 1 error 1 warning   FAILURE: Build failed with an exception.   * What went wrong: Execution failed for task ':compileJava'. > Compilation failed; see the compiler error output for details.   * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Last seen on 00:42, 9. Sep 2017
Joined Apr 2015
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Hmm, the website cuts off the
Wed, 09/06/2017 - 02:19

Hmm, the website cuts off the part of text at the right-most side but here is the most important part of code after su at the top: sugarObsidianSword.java:82:    the other part is just the item name so it is not as important: compactedLeaves.java.

Hope this helps!