Jump to content

[SOLVED] [1.12.2] Can't add new enchantment type


Jiro7

Recommended Posts

So I'm trying to make a mod that adds enchantments to shields. I haven't added any effects to them yet, but I wanted to test if I could get them to show up in a shield when putting it inside an enchanting table, but they don't. I created a new EnumEnchantmentType called SHIELDS but it doesn't seem to work, I can't get the enchantments ingame. I know this is the case because I created a Test enchantment that, instead of being Shield enchantment type, is "Breakable" enchantment type (which is a vanilla enchantment type) and it's the only one that works. 

 

The error:

 

[13:32:03] [Server thread/WARN] [minecraft/CommandHandler]: Couldn't process command: enchant @p shieldenchants:shieldboost
java.lang.NullPointerException: null
    at net.minecraft.item.Item.canApplyAtEnchantingTable(Item.java:1167) ~[Item.class:?]
    at net.minecraft.enchantment.Enchantment.canApplyAtEnchantingTable(Enchantment.java:226) ~[Enchantment.class:?]
    at net.minecraft.enchantment.Enchantment.canApply(Enchantment.java:190) ~[Enchantment.class:?]
    at net.minecraft.command.CommandEnchant.execute(CommandEnchant.java:76) ~[CommandEnchant.class:?]
    at net.minecraft.command.CommandHandler.tryExecute(CommandHandler.java:126) [CommandHandler.class:?]
    at net.minecraft.command.CommandHandler.executeCommand(CommandHandler.java:98) [CommandHandler.class:?]
    at net.minecraft.network.NetHandlerPlayServer.handleSlashCommand(NetHandlerPlayServer.java:1003) [NetHandlerPlayServer.class:?]
    at net.minecraft.network.NetHandlerPlayServer.processChatMessage(NetHandlerPlayServer.java:979) [NetHandlerPlayServer.class:?]
    at net.minecraft.network.play.client.CPacketChatMessage.processPacket(CPacketChatMessage.java:47) [CPacketChatMessage.class:?]
    at net.minecraft.network.play.client.CPacketChatMessage.processPacket(CPacketChatMessage.java:8) [CPacketChatMessage.class:?]
    at net.minecraft.network.PacketThreadUtil$1.run(PacketThreadUtil.java:21) [PacketThreadUtil$1.class:?]
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_191]
    at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_191]
    at net.minecraft.util.Util.runTask(Util.java:53) [Util.class:?]
    at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:798) [MinecraftServer.class:?]
    at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:743) [MinecraftServer.class:?]
    at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:192) [IntegratedServer.class:?]
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:592) [MinecraftServer.class:?]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_191]
[13:32:03] [main/INFO] [minecraft/GuiNewChat]: [CHAT] An unknown error occurred while attempting to perform this command

 

This is the code:

 

The ModEnchantments class:

 

package jiro.shieldenchantments.init;

import jiro.shieldenchantments.enchantment.EnchantmentAbsorb;
import jiro.shieldenchantments.enchantment.EnchantmentBerserk;
import jiro.shieldenchantments.enchantment.EnchantmentDeflection;
import jiro.shieldenchantments.enchantment.EnchantmentGuard;
import jiro.shieldenchantments.enchantment.EnchantmentHeavyweight;
import jiro.shieldenchantments.enchantment.EnchantmentShieldBoost;
import jiro.shieldenchantments.enchantment.EnchantmentSlimy;
import jiro.shieldenchantments.enchantment.EnchantmentTest;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnumEnchantmentType;
import net.minecraft.item.ItemShield;
import net.minecraftforge.common.util.EnumHelper;
import net.minecraftforge.event.RegistryEvent.Register;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import jiro.shieldenchantments.util.Reference;

@Mod.EventBusSubscriber(modid = Reference.MOD_ID)
public class ModEnchantments {
	
	public static final Enchantment HEAVYWEIGHT = new EnchantmentHeavyweight();
	public static final Enchantment BERSERK = new EnchantmentBerserk();
	public static final Enchantment GUARD = new EnchantmentGuard();
	public static final Enchantment DEFLECTION = new EnchantmentDeflection();
	public static final Enchantment ABSORB = new EnchantmentAbsorb();
	public static final Enchantment SHIELD_BOOST = new EnchantmentShieldBoost();
	public static final Enchantment SLIMY = new EnchantmentSlimy();
	public static final Enchantment TEST = new EnchantmentTest();
	
	public static final EnumEnchantmentType SHIELDS = EnumHelper.addEnchantmentType("shields", (item)->(item instanceof ItemShield));

	@SubscribeEvent
	public static void registerEnchantments(Register<Enchantment> event) {
		event.getRegistry().registerAll(HEAVYWEIGHT, BERSERK, GUARD, DEFLECTION, ABSORB, SHIELD_BOOST, SLIMY, TEST);
	}
	
}

 

One of the new enchantments class (they are all the same):

 

package jiro.shieldenchantments.enchantment;

import jiro.shieldenchantments.init.ModEnchantments;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.Enchantment.Rarity;
import net.minecraft.inventory.EntityEquipmentSlot;

public class EnchantmentSlimy extends Enchantment {
	
	public EnchantmentSlimy(){
		super(Rarity.COMMON, ModEnchantments.SHIELDS, new EntityEquipmentSlot[] {EntityEquipmentSlot.MAINHAND, EntityEquipmentSlot.OFFHAND});
		this.setRegistryName("slimy");
		this.setName("slimy");
	}
	
	@Override
	public int getMaxLevel() {
		return 4;
	}

}

 

The Main class:

 

package jiro.shieldenchantments;

import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.Mod.Instance;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import jiro.shieldenchantments.proxy.CommonProxy;
import jiro.shieldenchantments.util.Reference;

@Mod(modid = Reference.MOD_ID, name = Reference.NAME, version = Reference.VERSION)
public class Main {

	@Instance
	public static Main instance;
	
	@SidedProxy(clientSide = Reference.CLIENT_PROXY_CLASS, serverSide = Reference.COMMON_PROXY_CLASS)
	public static CommonProxy proxy;
	
	@EventHandler
	public static void PreInit(FMLPreInitializationEvent event){
		
	}
	
	@EventHandler
	public static void init(FMLInitializationEvent event){
		
	}
	
	@EventHandler
	public static void PostInit(FMLPostInitializationEvent event){
		
	}
}

 

What am I doing wrong? 

Edited by Jiro7
Problem solved!
Link to comment
Share on other sites

Managed to fix this by simply putting

 

public static final EnumEnchantmentType SHIELDS = EnumHelper.addEnchantmentType("shields", (item)->(item instanceof ItemShield));

 

before

 

public static final Enchantment HEAVYWEIGHT = new EnchantmentHeavyweight();
	public static final Enchantment BERSERK = new EnchantmentBerserk();
	public static final Enchantment GUARD = new EnchantmentGuard();
	public static final Enchantment DEFLECTION = new EnchantmentDeflection();
	public static final Enchantment ABSORB = new EnchantmentAbsorb();
	public static final Enchantment SHIELD_BOOST = new EnchantmentShieldBoost();
	public static final Enchantment SLIMY = new EnchantmentSlimy();
	public static final Enchantment TEST = new EnchantmentTest();

 

Hope it helps others in the same situation!

Link to comment
Share on other sites

You should prefix your enum with your modid

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

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

    • why when I launch the forge version of minecraft in full screen and turn on screen recording, only the first static image of the launch is recorded and the gameplay itself is not recorded
    • As a software developer from Sakha Republic, Russia. and like many in my field, I am quite tech-savvy. However, I recently became a victim of a cryptocurrency scam that cost me more than 10 million in my currency. The experience was not only financially devastating but also emotionally draining. I reported the crime to the authorities, hoping for a swift resolution, but I was frustrated and lacked results. It felt like I was in a maze with no exit. Feeling stuck and desperate, I turned to fellow developers for advice. One of them recommended a company called Muyern Trust Hacker. Initially, I was hesitant; I had heard mixed reviews about recovery services and I was concerned about falling victim to another scam. However, after speaking with their team, I was impressed by their professionalism and the clarity of their recovery methods. The team at Muyern Trust Hacker was dedicated and responsive, providing regular updates on their progress. It was refreshing to work with professionals who genuinely cared about my situation and were committed to helping me recover my lost funds. To my astonishment, they managed to recover most of my lost funds. The experience taught me valuable lessons about the risks of cryptocurrency investments and the importance of vigilance in the digital space.
    • Hello! I am the leader of this rp community for a Minecraft rp server and I would like to lend out an invitation to you all to join! We are on a rp server meaning we are going to do some rp and have characters, lore, stories and more! If you want to join just click the discord link below and I’ll help guide you through the process in joining the server and joining us on the server which should be easy. (NOTE: server requires you have to be 16 years old or older) (Java only!) Discord: https://discord.gg/V9uxjKQ7dB
    • these are the errors at startup [06nov2024 19:13:37.566] [main/INFO] [cpw.mods.modlauncher.Launcher/MODLAUNCHER]: ModLauncher running: args [--launchTarget, forgeserver, --fml.forgeVersion, 47.3.11, --fml.mcVersion, 1.20.1, --fml.forgeGroup, net.minecraftforge, --fml.mcpVersion, 20230612.114412] [06nov2024 19:13:37.570] [main/INFO] [cpw.mods.modlauncher.Launcher/MODLAUNCHER]: ModLauncher 10.0.9+10.0.9+main.dcd20f30 starting: java version 23.0.1 by Oracle Corporation; OS Windows 11 arch amd64 version 10.0 [06nov2024 19:13:39.173] [main/INFO] [net.minecraftforge.fml.loading.ImmediateWindowHandler/]: ImmediateWindowProvider not loading because launch target is forgeserver [06nov2024 19:13:39.178] [main/INFO] [mixin-transmog/]: Mixin Transmogrifier is definitely up to no good... [06nov2024 19:13:39.398] [main/INFO] [mixin-transmog/]: Redefining 5 mixin classes [06nov2024 19:13:39.412] [main/INFO] [mixin-transmog/]: crimes against java were committed [06nov2024 19:13:39.413] [main/INFO] [com.teampotato.redirector.Redirector/]: Redirector CoreMod initialized successfully! [06nov2024 19:13:39.424] [main/INFO] [mixin-transmog/]: Original mixin transformation service successfully crobbed by mixin-transmogrifier! [06nov2024 19:13:39.453] [main/INFO] [mixin/]: SpongePowered MIXIN Subsystem Version=0.8.5 Source=union:/C:/Users/zappi/OneDrive/Desktop/server%20forge/mods/Connector-1.0.0-beta.18+1.20.1-full.jar%23386%23390!/ Service=ModLauncher Env=SERVER [06nov2024 19:13:40.424] [main/WARN] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Mod file C:\Users\zappi\OneDrive\Desktop\server forge\libraries\net\minecraftforge\fmlcore\1.20.1-47.3.11\fmlcore-1.20.1-47.3.11.jar is missing mods.toml file [06nov2024 19:13:40.427] [main/WARN] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Mod file C:\Users\zappi\OneDrive\Desktop\server forge\libraries\net\minecraftforge\javafmllanguage\1.20.1-47.3.11\javafmllanguage-1.20.1-47.3.11.jar is missing mods.toml file [06nov2024 19:13:40.430] [main/WARN] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Mod file C:\Users\zappi\OneDrive\Desktop\server forge\libraries\net\minecraftforge\lowcodelanguage\1.20.1-47.3.11\lowcodelanguage-1.20.1-47.3.11.jar is missing mods.toml file [06nov2024 19:13:40.433] [main/WARN] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Mod file C:\Users\zappi\OneDrive\Desktop\server forge\libraries\net\minecraftforge\mclanguage\1.20.1-47.3.11\mclanguage-1.20.1-47.3.11.jar is missing mods.toml file [06nov2024 19:13:41.061] [main/WARN] [net.minecraftforge.jarjar.selection.JarSelector/]: Attempted to select two dependency jars from JarJar which have the same identification: Mod File:  and Mod File: . Using Mod File:  [06nov2024 19:13:41.062] [main/WARN] [net.minecraftforge.jarjar.selection.JarSelector/]: Attempted to select two dependency jars from JarJar which have the same identification: Mod File:  and Mod File: . Using Mod File:  [06nov2024 19:13:41.063] [main/WARN] [net.minecraftforge.jarjar.selection.JarSelector/]: Attempted to select a dependency jar for JarJar which was passed in as source: curios. Using Mod File: C:\Users\zappi\OneDrive\Desktop\server forge\mods\curios-forge-5.10.0+1.20.1.jar [06nov2024 19:13:41.063] [main/WARN] [net.minecraftforge.jarjar.selection.JarSelector/]: Attempted to select a dependency jar for JarJar which was passed in as source: terrablender. Using Mod File: C:\Users\zappi\OneDrive\Desktop\server forge\mods\TerraBlender-forge-1.20.1-3.0.1.7.jar [06nov2024 19:13:41.063] [main/WARN] [net.minecraftforge.jarjar.selection.JarSelector/]: Attempted to select a dependency jar for JarJar which was passed in as source: aeroblender. Using Mod File: C:\Users\zappi\OneDrive\Desktop\server forge\mods\aeroblender-1.20.1-1.0.1-neoforge.jar [06nov2024 19:13:41.063] [main/INFO] [net.minecraftforge.fml.loading.moddiscovery.JarInJarDependencyLocator/]: Found 97 dependencies adding them to mods collection [06nov2024 19:13:42.637] [main/INFO] [dev.su5ed.sinytra.connector.locator.DependencyResolver/]: Dependency resolution found 11 candidates to load [06nov2024 19:13:43.954] [main/INFO] [Configured Defaults/]: Applying default files...
  • Topics

×
×
  • Create New...

Important Information

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