Jump to content

Recommended Posts

Posted

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);
		}
	}
}

 

Posted

1.

  On 5/9/2020 at 10:26 PM, TheRedstoneWiz said:

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

Expand  

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.

  On 5/9/2020 at 10:26 PM, 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));"

Expand  

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).

Posted
  On 5/9/2020 at 10:26 PM, 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"

Expand  

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.

Posted
  On 5/9/2020 at 10:26 PM, TheRedstoneWiz said:

I was following Harry talks tutorial to weapons and tools

Expand  

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).

 

  On 5/9/2020 at 10:26 PM, TheRedstoneWiz said:

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

Expand  

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:

  Reveal hidden contents

 

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Recovering stolen Bitcoin can feel like an insurmountable challenge, especially after falling victim to scams that promise high returns with little investment. My journey began with excitement when I first learned about Bitcoin mining pools. The idea of earning substantial profits from a modest investment was enticing. I was encouraged to invest $5,200, and soon found myself caught in a web of endless demands for more money to access my funds. As time went on, I paid out hundreds of thousands of dollars, believing that each payment would finally unlock my investments. However, the requests never ceased, and I soon realized I was trapped in a scam. The weight of losing $826,000 worth of Bitcoin was unbearable, and I felt utterly helpless. I reached out to authorities, but their responses were disheartening, leaving me feeling even more isolated in my struggle. In my desperation, I even went to pray, seeking guidance and hope in what felt like a hopeless situation. I poured my heart out, asking for a sign or a way to recover my lost funds. It was during this time of reflection that I began searching for solutions online, hoping to find a way to recover my investments. That’s when I stumbled upon RAPID DIGITAL RECOVERY. At first, I was cynical after all, I had already been deceived so many times. However, I decided to reach out and share my story. The team at RAPID DIGITAL RECOVERY was understanding and compassionate, assuring me they had the expertise to help me recover my stolen Bitcoin. Within hours of providing them with the necessary information, I began to see progress. They guided me through the recovery process, keeping me informed every step of the way. It was surreal to watch as they worked diligently to trace my funds and navigate the complexities of the blockchain. To my astonishment, I received confirmation that my Bitcoin had been successfully recovered. The relief and joy I felt were indescribable. I had almost given up hope, but RAPID DIGITAL RECOVERY proved to be the lifeline I desperately needed. If you find yourself in a similar situation, I urge you to seek help from Reputable team at RAPID DIGITAL RECOVERY.  
    • https://mclo.gs/9Byd16j Hi, I've had my BetterMC world for a couple days now (1.19.2 vers & Fabric loader) but recently whenever I try to open the profile the minecraft launcher crashes and provides this error code. I've checked both this forum and google and haven't found any similar problems or solution to my problem. I'm not the best at reading crash logs but I gathered that there's an issue with fabric possibly, so I re-downloaded the same one on the modpack, then the latest version for 1.19.2 fabric and the issue still occurred. What can I do now?
    • it works now but idk why lmao. i removed terrablender and it didnt work. i then left it for a couple of days and, when i came back, updated the mods that needed updating because "what's the worst that could happen". i then tried launching it and now it works. i genuenly have no clue what i did to make it work, othen than updating the mods. so, thanks for your help
    • Add the crash-report or latest.log (logs-folder) with sites like https://mclo.gs/ and paste the link to it here  
  • Topics

×
×
  • Create New...

Important Information

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