Jump to content

[1.7.10]How to add enchants to a weapon as default


2FastAssassin

Recommended Posts

I have looked every where and cant find any tutorial on how to make it so a weapon has an enchant as default eg fire sword have fire aspect as default. please help

Link to comment
Share on other sites

Add this to sword class:

@Override

public void onUpdate(ItemStack stack, World worldIn, Entity entityIn,

int itemSlot, boolean isSelected) {

// TODO Auto-generated method stub

stack.addEnchantment(ench, level);

super.onUpdate(stack, worldIn, entityIn, itemSlot, isSelected);

}

Sorry for my English

Link to comment
Share on other sites

I did this and when ever I have the sword the game crashes(I did have some of the code from potion effect but I got rid of the potion effect while doing this)

 

Code for my sword:

package wearethewarriorsmod.item;

 

import net.minecraft.enchantment.Enchantment;

import net.minecraft.entity.Entity;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.item.Item;

import net.minecraft.item.ItemStack;

import net.minecraft.item.ItemSword;

import net.minecraft.potion.Potion;

import net.minecraft.potion.PotionEffect;

import net.minecraft.world.World;

 

public class ItemDragonsword extends ItemSword {

 

public ItemDragonsword(ToolMaterial material) {

super(material);

}

public void onUpdate(ItemStack stack, World world, Entity entity, int par4, boolean par5){

super.onUpdate(stack, world, entity, par4, par5);

{

int itemSlot, boolean isSelected) {

          stack.addEnchantment(Enchantment.fireAspect, 2);

          super.onUpdate(stack, world, entity, itemSlot, isSelected);

}

}

 

}

}

 

Link to comment
Share on other sites

---- Minecraft Crash Report ----

// This doesn't make any sense!

 

Time: 2/04/15 11:22 PM

Description: Ticking entity

 

java.lang.Error: Unresolved compilation problems:

Syntax error on token ",", ; expected

Syntax error on token ")", ; expected

 

at wearethewarriorsmod.item.ItemDragonsword.onUpdate(ItemDragonsword.java:21)

at net.minecraft.item.ItemStack.updateAnimation(ItemStack.java:476)

at net.minecraft.entity.player.InventoryPlayer.decrementAnimations(InventoryPlayer.java:347)

at net.minecraft.entity.player.EntityPlayer.onLivingUpdate(EntityPlayer.java:610)

at net.minecraft.client.entity.EntityPlayerSP.onLivingUpdate(EntityPlayerSP.java:299)

at net.minecraft.entity.EntityLivingBase.onUpdate(EntityLivingBase.java:1816)

at net.minecraft.entity.player.EntityPlayer.onUpdate(EntityPlayer.java:327)

at net.minecraft.client.entity.EntityClientPlayerMP.onUpdate(EntityClientPlayerMP.java:96)

at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:2298)

at net.minecraft.world.World.updateEntity(World.java:2258)

at net.minecraft.world.World.updateEntities(World.java:2108)

at net.minecraft.client.Minecraft.runTick(Minecraft.java:2086)

at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1028)

at net.minecraft.client.Minecraft.run(Minecraft.java:951)

at net.minecraft.client.main.Main.main(Main.java:164)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:483)

at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)

at net.minecraft.launchwrapper.Launch.main(Launch.java:28)

at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source)

at GradleStart.main(Unknown Source)

 

 

A detailed walkthrough of the error, its code path and all known details is as follows:

---------------------------------------------------------------------------------------

 

-- Head --

Stacktrace:

at wearethewarriorsmod.item.ItemDragonsword.onUpdate(ItemDragonsword.java:21)

at net.minecraft.item.ItemStack.updateAnimation(ItemStack.java:476)

at net.minecraft.entity.player.InventoryPlayer.decrementAnimations(InventoryPlayer.java:347)

at net.minecraft.entity.player.EntityPlayer.onLivingUpdate(EntityPlayer.java:610)

at net.minecraft.client.entity.EntityPlayerSP.onLivingUpdate(EntityPlayerSP.java:299)

at net.minecraft.entity.EntityLivingBase.onUpdate(EntityLivingBase.java:1816)

at net.minecraft.entity.player.EntityPlayer.onUpdate(EntityPlayer.java:327)

at net.minecraft.client.entity.EntityClientPlayerMP.onUpdate(EntityClientPlayerMP.java:96)

at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:2298)

at net.minecraft.world.World.updateEntity(World.java:2258)

 

-- Entity being ticked --

Details:

Entity Type: null (net.minecraft.client.entity.EntityClientPlayerMP)

Entity ID: 240

Entity Name: Player941

Entity's Exact location: -381.73, 97.86, 323.81

Entity's Block location: World: (-382,97,323), Chunk: (at 2,6,3 in -24,20; contains blocks -384,0,320 to -369,255,335), Region: (-1,0; contains chunks -32,0 to -1,31, blocks -512,0,0 to -1,255,511)

Entity's Momentum: 0.00, 0.00, 0.00

Stacktrace:

at net.minecraft.world.World.updateEntities(World.java:2108)

 

-- Affected level --

Details:

Level name: MpServer

All players: 1 total; [EntityClientPlayerMP['Player941'/240, l='MpServer', x=-381.73, y=97.86, z=323.81]]

Chunk stats: MultiplayerChunkCache: 0, 0

Level seed: 0

Level generator: ID 00 - default, ver 1. Features enabled: false

Level generator options:

Level spawn location: World: (-124,64,240), Chunk: (at 4,4,0 in -8,15; contains blocks -128,0,240 to -113,255,255), Region: (-1,0; contains chunks -32,0 to -1,31, blocks -512,0,0 to -1,255,511)

Level time: 25018 game time, 25018 day time

Level dimension: 0

Level storage version: 0x00000 - Unknown?

Level weather: Rain time: 0 (now: false), thunder time: 0 (now: false)

Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: false

Forced entities: 20 total; [EntityXPOrb['Experience Orb'/256, l='MpServer', x=-377.25, y=88.13, z=308.25], EntityXPOrb['Experience Orb'/257, l='MpServer', x=-376.13, y=83.13, z=310.88], EntityZombie['Zombie'/258, l='MpServer', x=-359.56, y=25.00, z=324.53], EntityCreeper['Creeper'/259, l='MpServer', x=-354.50, y=24.00, z=328.66], EntityCreeper['Creeper'/260, l='MpServer', x=-358.72, y=25.00, z=325.66], EntitySkeleton['Skeleton'/261, l='MpServer', x=-361.44, y=24.00, z=324.72], EntityZombie['Zombie'/263, l='MpServer', x=-356.47, y=24.00, z=335.66], EntityItem['item.item.rottenFlesh'/264, l='MpServer', x=-360.41, y=56.13, z=325.28], EntityClientPlayerMP['Player941'/240, l='MpServer', x=-381.73, y=97.86, z=323.81], EntityZombie['Zombie'/245, l='MpServer', x=-392.41, y=34.00, z=326.94], EntityZombie['Zombie'/246, l='MpServer', x=-393.31, y=34.00, z=324.50], EntityZombie['Zombie'/247, l='MpServer', x=-395.53, y=34.00, z=324.00], EntitySkeleton['Skeleton'/248, l='MpServer', x=-393.88, y=34.00, z=323.47], EntitySkeleton['Skeleton'/249, l='MpServer', x=-393.50, y=34.22, z=329.50], EntityItem['item.tile.stonebrick'/250, l='MpServer', x=-396.38, y=78.13, z=323.41], EntityItem['item.tile.stonebrick'/251, l='MpServer', x=-391.34, y=93.13, z=322.88], EntityItem['item.tile.dirt.default'/252, l='MpServer', x=-394.88, y=95.13, z=326.88], EntityItem['item.tile.dirt.default'/253, l='MpServer', x=-393.13, y=96.13, z=327.88], EntityXPOrb['Experience Orb'/254, l='MpServer', x=-374.50, y=67.13, z=313.94], EntityItem['item.item.rottenFlesh'/255, l='MpServer', x=-377.13, y=88.13, z=309.00]]

Retry entities: 0 total; []

Server brand: fml,forge

Server type: Integrated singleplayer server

Stacktrace:

at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:415)

at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2555)

at net.minecraft.client.Minecraft.run(Minecraft.java:973)

at net.minecraft.client.main.Main.main(Main.java:164)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:483)

at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)

at net.minecraft.launchwrapper.Launch.main(Launch.java:28)

at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source)

at GradleStart.main(Unknown Source)

 

-- System Details --

Details:

Minecraft Version: 1.7.10

Operating System: Windows 7 (x86) version 6.1

Java Version: 1.8.0_25, Oracle Corporation

Java VM Version: Java HotSpot Client VM (mixed mode), Oracle Corporation

Memory: 819846952 bytes (781 MB) / 1046937600 bytes (998 MB) up to 1046937600 bytes (998 MB)

JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M

AABB Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used

IntCache: cache: 0, tcache: 0, allocated: 13, tallocated: 95

FML: MCP v9.05 FML v7.10.85.1291 Minecraft Forge 10.13.2.1291 4 mods loaded, 4 mods active

mcp{9.05} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available

FML{7.10.85.1291} [Forge Mod Loader] (forgeSrc-1.7.10-10.13.2.1291.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available

Forge{10.13.2.1291} [Minecraft Forge] (forgeSrc-1.7.10-10.13.2.1291.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available

watwm{1.0} [We Are The Warriors Mod] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available

Launched Version: 1.7.10

LWJGL: 2.9.1

OpenGL: ATI Radeon 3000 Graphics GL version 3.3.10750 Compatibility Profile Context, ATI Technologies Inc.

GL Caps: Using GL 1.3 multitexturing.

Using framebuffer objects because OpenGL 3.0 is supported and separate blending is supported.

Anisotropic filtering is supported and maximum anisotropy is 16.

Shaders are available because OpenGL 2.1 is supported.

 

Is Modded: Definitely; Client brand changed to 'fml,forge'

Type: Client (map_client.txt)

Resource Packs: []

Current Language: English (US)

Profiler Position: N/A (disabled)

Vec3 Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used

Anisotropic Filtering: Off (1)

Link to comment
Share on other sites

Try this:

package wearethewarriorsmod.item;

import net.minecraft.enchantment.Enchantment;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemSword;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.world.World;

public class ItemDragonsword extends ItemSword {

   public ItemDragonsword(ToolMaterial material) {
      super(material);
   }
   public void onUpdate(ItemStack stack, World world, Entity entity, int par4, boolean par5){
      super.onUpdate(stack, world, entity, par4, par5);
      
            if(itemstack.isItemEnchanted() == false) {
                 stack.addEnchantment(Enchantment.fireAspect, 2);
                 super.onUpdate(stack, world, entity, itemSlot, isSelected);
         }
      

   }
}

Sorry for my English

Link to comment
Share on other sites

Well, you should understand basic java to do this. The code is totally wrong.

Learn basic java, please.

To laci200270: Do not just provide copy-paste code.. It is far from how learning works.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Link to comment
Share on other sites

Well, you should understand basic java to do this. The code is totally wrong.

Learn basic java, please.

To laci200270: Do not just provide copy-paste code.. It is far from how learning works.

OK I just reworked the code because totally  wrong.

Next time I only say what is the error?(I just only want to help)

Sorry for my English

Link to comment
Share on other sites

Oh, I'm not saying to you when 'The code is totally wrong'.  :/

It seems that OP doesn't know basic java. So it would be more helpful to tell him/her 'Learn Basic Java', I think.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Link to comment
Share on other sites

  • 1 year later...

Although this thread is suuuper dead, in case anyone needs the working code, here it is:

 

public void onUpdate(ItemStack stack, World world, Entity entity, int i, boolean bool) {
	super.onUpdate(stack, world, entity, i, bool);

	if(stack.isItemEnchanted() == false) {
		stack.addEnchantment(MainRegistry.customEnchantment, 2);
                                                        // Or, Enchantments.whateverEnchantmentYouWant
		super.onUpdate(stack, world, entity, i, bool);
	}
}

 

Basically, the variables on the second super.onUpdate method were incorrect. Just match the variables of the super with the onUpdate method and everything should work.

 

Also, take a look at where my code says:

    (MainRegistry.customEnchantment, 2);

 

This line is swappable and will change. If you're doing in game enchantments, then do:

     (Enchantments.nameOfEnchantment, idOfTheEnchantment);

 

The code I have is for custom enchantments, for which you call your main modding class.

Creator and Developer of the SkyrimCraft mod!

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

    • I was trying to load some mods for 1.19.4 and yes all of them are right and i think some are interfering with each other and I don't know which ones to remove
    • Minecraft has crashed! net.fabricmc.loader.impl.FormattedException: java.lang.RuntimeException: Mixin transformation of net.minecraft.class_310 failed     at net.fabricmc.loader.impl.FormattedException.ofLocalized(FormattedException.java:63)     at net.fabricmc.loader.impl.game.minecraft.MinecraftGameProvider.launch(MinecraftGameProvider.java:472)     at net.fabricmc.loader.impl.launch.knot.Knot.launch(Knot.java:74)     at net.fabricmc.loader.impl.launch.knot.KnotClient.main(KnotClient.java:23) Caused by: java.lang.RuntimeException: Mixin transformation of net.minecraft.class_310 failed     at net.fabricmc.loader.impl.launch.knot.KnotClassDelegate.getPostMixinClassByteArray(KnotClassDelegate.java:427)     at net.fabricmc.loader.impl.launch.knot.KnotClassDelegate.tryLoadClass(KnotClassDelegate.java:323)     at net.fabricmc.loader.impl.launch.knot.KnotClassDelegate.loadClass(KnotClassDelegate.java:218)     at net.fabricmc.loader.impl.launch.knot.KnotClassLoader.loadClass(KnotClassLoader.java:119)     at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525)     at net.minecraft.client.main.Main.main(Main.java:207)     at net.fabricmc.loader.impl.game.minecraft.MinecraftGameProvider.launch(MinecraftGameProvider.java:470)     ... 2 more Caused by: org.spongepowered.asm.mixin.transformer.throwables.MixinTransformerError: An unexpected critical error was encountered     at org.spongepowered.asm.mixin.transformer.MixinProcessor.applyMixins(MixinProcessor.java:392)     at org.spongepowered.asm.mixin.transformer.MixinTransformer.transformClass(MixinTransformer.java:234)     at org.spongepowered.asm.mixin.transformer.MixinTransformer.transformClassBytes(MixinTransformer.java:202)     at meteordevelopment.meteorclient.asm.Asm$Transformer.transformClassBytes(Asm.java:102)     at net.fabricmc.loader.impl.launch.knot.KnotClassDelegate.getPostMixinClassByteArray(KnotClassDelegate.java:422)     ... 8 more Caused by: org.spongepowered.asm.mixin.injection.throwables.InjectionError: Critical injection failure: Redirector breakBlockCheck(Lnet/minecraft/class_746;)Z in reaper.mixins.json:MinecraftClientMixin from mod reaper failed injection check, (0/1) succeeded. Scanned 1 target(s). Using refmap reaper-refmap.json     at org.spongepowered.asm.mixin.injection.struct.InjectionInfo.postInject(InjectionInfo.java:468)     at org.spongepowered.asm.mixin.transformer.MixinTargetContext.applyInjections(MixinTargetContext.java:1384)     at org.spongepowered.asm.mixin.transformer.MixinApplicatorStandard.applyInjections(MixinApplicatorStandard.java:1062)     at org.spongepowered.asm.mixin.transformer.MixinApplicatorStandard.applyMixin(MixinApplicatorStandard.java:402)     at org.spongepowered.asm.mixin.transformer.MixinApplicatorStandard.apply(MixinApplicatorStandard.java:327)     at org.spongepowered.asm.mixin.transformer.TargetClassContext.apply(TargetClassContext.java:422)     at org.spongepowered.asm.mixin.transformer.TargetClassContext.applyMixins(TargetClassContext.java:403)     at org.spongepowered.asm.mixin.transformer.MixinProcessor.applyMixins(MixinProcessor.java:363)     ... 12 more  
    • Did some digging on that specific error and found a reddit post. Someone replied that they fixed it by closing Overwolf, so I went into task manager and closed Overwolf before loading up the game. This seems to have fixed it! I guess the error has something to do with Overwolf then. 
    • I'm struggling so hard to find a way to allow players to use my config file to modify where structures are being created. I have checked for events in the documentation but none of them seem to be of use for this. Why pointing Biome is not enough? Well Certain mods like Lost cities use vanilla generation, causing many structures to spawn in, completely disrupting the dimension generation. Is there a way to control dimensional spawning of structures? Please Im still trying very hard to find how to do this.
    • I'm new to modpack making, but familiar with file management and mod development. I cannot locate which mod is causing the crash. If it's more than one, Im not sure how to locate it. Any clues as to whats causing this? I have read through different possible causes but every thing is different, and none of the solves issues are the solution to my problem. This problem started occurring after adding about 5 mods, but once I removed them, the problem continued. It worked fine before.   Here is the crash report.
  • Topics

×
×
  • Create New...

Important Information

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