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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hi, I want to make a client-only mod, everything is ok, but when I use shaders, none of the textures rendered in RenderLevelStageEvent nor the crow entity model are rendered, I want them to be visible, because it's a horror themed mod Here is how i render the crow model in the CrowEntityRenderer<CrowEntity>, by the time i use this method, i know is not the right method but i don't think this is the cause of the problem, the renderType i'm using is entityCutout @Override public void render(CrowEntity p_entity, float entityYaw, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) { super.render(p_entity, entityYaw, partialTick, poseStack, bufferSource, packedLight); ClientEventHandler.getClient().crow.renderToBuffer(poseStack, bufferSource.getBuffer(ClientEventHandler.getClient().crow .renderType(TEXTURE)), packedLight, OverlayTexture.NO_OVERLAY, Utils.rgb(255, 255, 255)); } Here renderLevelStage @Override public void renderWorld(RenderLevelStageEvent e) { horrorEvents.draw(e); } Here is how i render every event public void draw(RenderLevelStageEvent e) { for (HorrorEvent event : currentHorrorEvents) { event.tick(e.getPartialTick()); event.draw(e); } } Here is how i render the crow model on the event @Override public void draw(RenderLevelStageEvent e) { if(e.getStage() == RenderLevelStageEvent.Stage.AFTER_ENTITIES) { float arcProgress = getArcProgress(0.25f); int alpha = (int) Mth.lerp(arcProgress, 0, 255); int packedLight = LevelRenderer.getLightColor(Minecraft.getInstance().level, blockPos); VertexConsumer builder = ClientEventHandler.bufferSource.getBuffer(crow); Crow<CreepyBirdHorrorEvent> model = ClientEventHandler .getClient().crow; model.setupAnim(this); RenderHelper.renderModelInWorld(model, position, offset, e.getCamera(), e.getPoseStack(), builder, packedLight, OverlayTexture.NO_OVERLAY, alpha); builder = ClientEventHandler.bufferSource.getBuffer(eyes); RenderHelper.renderModelInWorld(model, position, offset, e.getCamera(), e.getPoseStack(), builder, 15728880, OverlayTexture.NO_OVERLAY, alpha); } } How i render the model public static void renderModelInWorld(Model model, Vector3f pos, Vector3f offset, Camera camera, PoseStack matrix, VertexConsumer builder, int light, int overlay, int alpha) { matrix.pushPose(); Vec3 cameraPos = camera.getPosition(); double finalX = pos.x - cameraPos.x + offset.x; double finalY = pos.y - cameraPos.y + offset.y; double finalZ = pos.z - cameraPos.z + offset.z; matrix.pushPose(); matrix.translate(finalX, finalY, finalZ); matrix.mulPose(Axis.XP.rotationDegrees(180f)); model.renderToBuffer(matrix, builder, light, overlay, Utils .rgba(255, 255, 255, alpha)); matrix.popPose(); matrix.popPose(); } Thanks in advance
    • Here's the link: https://mclo.gs/7L5FibL Here's the link: https://mclo.gs/7L5FibL
    • Also the mod "Connector Extras" modifies Reach-entity-attributes and can cause fatal errors when combined with ValkrienSkies mod. Disable this mod and continue to use Syntra without it.
    • Hi everyone. I was trying modify the vanilla loot of the "short_grass" block, I would like it drops seeds and vegetal fiber (new item of my mod), but I don't found any guide or tutorial on internet. Somebody can help me?
    • On 1.20.1 use ValkrienSkies mod version 2.3.0 Beta 1. I had the same issues as you and it turns out the newer beta versions have tons of unresolved incompatibilities. If you change the version you will not be required to change the versions of eureka or any other additions unless prompted at startup. This will resolve Reach-entity-attributes error sound related error and cowardly errors.
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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