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.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Make a test without practical_plushies_mobs, practical_plushies_animals and dark-waters - looks like it is not working with sinytra connector
    • VIP Call Girlfriend in Abu Dhabi ☮➡+971557861567(㎓) Escorts In Abu Dhabi   VIP Call Girlfriend in Abu Dhabi ☮➡+971557861567(㎓) Escorts In Abu Dhabi   VIP Call Girlfriend in Abu Dhabi ☮➡+971557861567(㎓) Escorts In Abu Dhabi
    • Maybe your file codes are missing. Therefore it is crashing.
    • I've been trying to make a mod pack for the last day or so now and I haven't been able to launch it once even with all mods disabled. It keeps showing up with Exit Code 1. I gave the modpack to a friend to try and it didn't launch on their pc either due to the same exit code, so I'm not entirely certain what the problem is or how to check it in the logs. So far I've attempted: - Changing from forge version 43.3.0 to 43.3.5 - Downloading Java - Disabling mods (both entirely and individually) I have an NVIDIA GeForce GTX 1070 driver, and I haven't tried to uninstall or reinstall it yet because I'm not certain how to and would have to mess anything up further. I have the latest .txt file of the crash report here: [16:24:34] [main/WARN]: Failed to add PDH Counter: \Paging File(_Total)\% Usage, Error code: 0xC0000BB8 [16:24:34] [main/WARN]: Failed to add counter for PDH counter: \Paging File(_Total)\% Usage [16:24:34] [main/WARN]: Disabling further attempts to query Paging File. [16:24:36] [main/WARN]: COM exception: Invalid Query: SELECT PERCENTUSAGE FROM Win32_PerfRawData_PerfOS_PagingFile [16:24:39] [Datafixer Bootstrap/INFO]: 198 Datafixer optimizations took 149 milliseconds [16:24:40] [Render thread/INFO]: Environment: Environment[sessionHost=https://sessionserver.mojang.com, servicesHost=https://api.minecraftservices.com, name=PROD] [16:24:40] [Render thread/INFO]: Setting user: CatDoodlee [16:24:41] [Render thread/INFO]: Backend library: LWJGL version 3.3.2+13 [16:24:42] [Render thread/INFO]: Reloading ResourceManager: vanilla [16:24:42] [Worker-Main-11/INFO]: Found unifont_all_no_pua-15.1.04.hex, loading [16:24:44] [Render thread/WARN]: Missing sound for event: minecraft:item.goat_horn.play [16:24:44] [Render thread/WARN]: Missing sound for event: minecraft:entity.goat.screaming.horn_break [16:24:44] [Render thread/INFO]: OpenAL initialized on device OpenAL Soft on Speakers (Atrix Wired Elite Headset) [16:24:44] [Render thread/INFO]: Sound engine started [16:24:44] [Render thread/INFO]: Created: 1024x512x4 minecraft:textures/atlas/blocks.png-atlas [16:24:44] [Render thread/INFO]: Created: 256x256x4 minecraft:textures/atlas/signs.png-atlas [16:24:44] [Render thread/INFO]: Created: 512x512x4 minecraft:textures/atlas/shield_patterns.png-atlas [16:24:44] [Render thread/INFO]: Created: 512x512x4 minecraft:textures/atlas/banner_patterns.png-atlas [16:24:44] [Render thread/INFO]: Created: 1024x1024x4 minecraft:textures/atlas/armor_trims.png-atlas [16:24:44] [Render thread/INFO]: Created: 128x64x4 minecraft:textures/atlas/decorated_pot.png-atlas [16:24:44] [Render thread/INFO]: Created: 256x256x4 minecraft:textures/atlas/chest.png-atlas [16:24:44] [Render thread/INFO]: Created: 512x256x4 minecraft:textures/atlas/shulker_boxes.png-atlas [16:24:44] [Render thread/INFO]: Created: 512x256x4 minecraft:textures/atlas/beds.png-atlas [16:24:45] [Render thread/WARN]: Shader rendertype_entity_translucent_emissive could not find sampler named Sampler2 in the specified shader program. [16:24:45] [Render thread/INFO]: Created: 512x256x0 minecraft:textures/atlas/particles.png-atlas [16:24:45] [Render thread/INFO]: Created: 256x256x0 minecraft:textures/atlas/paintings.png-atlas [16:24:45] [Render thread/INFO]: Created: 128x128x0 minecraft:textures/atlas/mob_effects.png-atlas [16:24:45] [Render thread/INFO]: Created: 1024x512x0 minecraft:textures/atlas/gui.png-atlas [16:25:41] [Render thread/INFO]: Stopping! any form of help is greatly appreciated ❤️
  • Topics

×
×
  • Create New...

Important Information

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