Jump to content

error when adding katana sword (1.14.4)


TheRedstoneWiz

Recommended Posts

I was following Harry talks tutorial to weapons and tools, and while following, i encountered an error when making the SwordItem on this line:

 

 

"ItemList.wooden_katana = new SwordItem(ToolMaterialList.katana_wooden_material, -1.0f, 6.0f, new Item.Properties().group(ItemGroup.MISC)).setRegistryName(location(wooden_katana));"

 

 

At the end of this line, where it says "wooden_katana", it gives the following error:

 

"wooden_katana cannot be resolved to a variable"

 

even though i set the variable in the class "ToolMaterialList".

 

The second error on the line is shown in the typical red underlines from "new SwordItem" to "ItemGroup.Misc))" which says:

 

"The constructor SwordItem(ToolMaterialList, float, float, Item.Properties) is undefined"

 

How do I fix these errors?

 

ToolMaterialList.java

 

package redstonewiz.asianweaponry.lists;

import net.minecraft.item.IItemTier;
import net.minecraft.item.Item;
import net.minecraft.item.crafting.Ingredient;

public enum ToolMaterialList implements IItemTier 
{
	katana_diamond_material(3.0F, 0.0F, 2000, 3, 14, ItemList.katana_diamond_material),
	katana_iron_material(2.5F, 0.0F, 2000, 3, 14, ItemList.katana_diamond_material),
	katana_gold_material(1F, 0.0F, 2000, 3, 14, ItemList.katana_diamond_material),
	katana_stone_material(2.0F, 0.0F, 2000, 3, 14, ItemList.katana_diamond_material),
	katana_wooden_material(1.0F, 0.0F, 2000, 3, 14, ItemList.katana_diamond_material);
	
	private float attackDamage, efficiency;
	private int durability, HarvestLevel, enchantibility;
	private Item repairMaterial;
	
	private ToolMaterialList(float attackDamage, float efficiency, int durability, int HarvestLevel, int enchantibility, Item repairMaterial) 
	{
		// TODO Auto-generated constructor stub
		this.attackDamage = attackDamage;
		this.efficiency = efficiency;
		this.durability = durability;
		this.HarvestLevel = HarvestLevel;
		this.enchantibility = enchantibility;
		this.repairMaterial = repairMaterial;
	}

	@Override
	public int getMaxUses() {
		// TODO Auto-generated method stub
		return this.durability;
	}

	@Override
	public float getEfficiency() {
		// TODO Auto-generated method stub
		return this.efficiency;
	}

	@Override
	public float getAttackDamage() {
		// TODO Auto-generated method stub
		return this.attackDamage;
	}

	@Override
	public int getHarvestLevel() {
		// TODO Auto-generated method stub
		return this.HarvestLevel;
	}

	@Override
	public int getEnchantability() {
		// TODO Auto-generated method stub
		return this.enchantibility;
	}

	@Override
	public Ingredient getRepairMaterial() {
		// TODO Auto-generated method stub
		return Ingredient.fromItems(this.repairMaterial);
	}
}

 

ItemList.java

 

package redstonewiz.asianweaponry.lists;

import net.minecraft.item.Item;
import net.minecraft.item.SwordItem;

public class ItemList 
{
	public static Item bluesteel_ingot;
	
	public static Item katana_diamond_material;
	
	public static SwordItem diamond_katana;
	public static SwordItem iron_katana;
	public static SwordItem golden_katana;
	public static SwordItem stone_katana;
	public static SwordItem wooden_katana;
}

 

AsianWeaponryMod.java (my main)

 

package redstonewiz.asianweaponry;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.SwordItem;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import redstonewiz.asianweaponry.items.ItemCustomKatana;
import redstonewiz.asianweaponry.lists.ItemList;
import redstonewiz.asianweaponry.lists.ToolMaterialList;

@Mod("asianweaponrymod")
public class AsianWeaponryMod 
{
	
	public static AsianWeaponryMod instance;
	public static final String modid = "asianweaponrymod";
	private static final Logger logger = LogManager.getLogger(modid);
	
	public AsianWeaponryMod() 
	{
		
		instance = this;
		
		FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
		FMLJavaModLoadingContext.get().getModEventBus().addListener(this::clientRegistries);
		// TODO Auto-generated constructor stub
		MinecraftForge.EVENT_BUS.register(this);
	}
	
	private void setup(final FMLCommonSetupEvent event)
	{
		logger.info("Setup method registered");
	}
	
	private void clientRegistries(final FMLCommonSetupEvent event)
	{
		logger.info("clientRegistries method registered");
	}
	
	@Mod.EventBusSubscriber(bus=Mod.EventBusSubscriber.Bus.MOD)
	public static class RegistryEvents
	{
		@SubscribeEvent
		public static void registerItems(final RegistryEvent.Register<Item> event)
		{
			event.getRegistry().registerAll
			(
					ItemList.wooden_katana = new SwordItem(ToolMaterialList.katana_wooden_material, -1.0f, 6.0f, new Item.Properties().group(ItemGroup.MISC)).setRegistryName(location(wooden_katana));

			logger.info("Items registered.");
		}
		
		private static ResourceLocation location(String name) 
		{
			return new ResourceLocation(modid, name);
		}
	}
}

 

Link to comment
Share on other sites

1.

25 minutes ago, TheRedstoneWiz said:

"The constructor SwordItem(ToolMaterialList, float, float, Item.Properties) is undefined"

Attackdamage is an int, but you have it as a float. If you're using an IDE it should be able to tell you what each constructor expects. (Actually followed a similar tutorial and had the same mistake),

 

2.

26 minutes ago, TheRedstoneWiz said:

"ItemList.wooden_katana = new SwordItem(ToolMaterialList.katana_wooden_material, -1.0f, 6.0f, new Item.Properties().group(ItemGroup.MISC)).setRegistryName(location(wooden_katana));"

Don't use static initializers for registration, the new preferred method is deferred registration. Check out the docs, but basically you create a deferred registry and use the register method of that object (takes the item name as a string and a supplier (i.e. a function that returns a new instance of that object).

Link to comment
Share on other sites

1 hour ago, TheRedstoneWiz said:

At the end of this line, where it says "wooden_katana", it gives the following error:

"wooden_katana cannot be resolved to a variable"

Yes. Because it wooden_katana as a variable name doesn't exist. The method accepts a string, pass it a string.

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.

Link to comment
Share on other sites

4 hours ago, TheRedstoneWiz said:

I was following Harry talks tutorial to weapons and tools

It is recommended to not follow such tutorials on YouTube, as their quality is subpar, as well as producing code that does not follow established conventions (including problematic code).

 

4 hours ago, TheRedstoneWiz said:

even though i set the variable in the class "ToolMaterialList".

It is not in the same class as the current one, so you need to reference the class first. This should be basic Java.

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.

 

 

Link to comment
Share on other sites

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.