Jump to content

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


Recommended Posts

Posted (edited)

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!
Posted

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!

Posted

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)

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



×
×
  • Create New...

Important Information

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