Posted June 18, 20223 yr I am making a custom enchant that makes a sword do more damage. Does anyone know how I could make this? I already have the beginning down. package com.idtech.enchantment; import com.idtech.Utils; import net.minecraft.core.BlockPos; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.*; import net.minecraft.world.item.enchantment.Enchantment; import net.minecraft.world.item.enchantment.EnchantmentCategory; import net.minecraft.world.level.Level; public class Razor extends Enchantment { private static EquipmentSlot[] slots = {EquipmentSlot.MAINHAND}; public static final Razor INSTANCE = (Razor) (new Razor(Rarity.RARE, EnchantmentCategory.WEAPON, slots).setRegistryName("razor")); protected Razor(Rarity p_44676_, EnchantmentCategory p_44677_, EquipmentSlot[] p_44678_) { super(p_44676_, p_44677_, p_44678_); } @ Overide public void doPostAttack(LivingEntity pAttacker, Entity pTarget, int pLevel) { if (!pAttacker.level.isClientSide()) { ServerLevel world = (ServerLevel) pAttacker.level; ServerPlayer player = ((ServerPlayer) pAttacker); BlockPos position = pTarget.blockPosition(); if (pLevel == 5) { } } } } }
June 18, 20223 yr 1 hour ago, Modderuy said: public static final Razor INSTANCE = (Razor) (new Razor(Rarity.RARE, EnchantmentCategory.WEAPON, slots).setRegistryName("razor")); you can not create Enchantments in static initializer, you should use DeferredRegister (recommend) 1 hour ago, Modderuy said: I am making a custom enchant that makes a sword do more damage. you can override Enchantment#getDamageBonus, and return the additional damage you want
June 19, 20223 yr override Enchantment#getDamageBonus, and return (not call) the additional damage you want
June 19, 20223 yr Author i did @Override public void doPostAttack(LivingEntity pAttacker, Entity pTarget, int pLevel) { if (!pAttacker.level.isClientSide()) { ServerLevel world = (ServerLevel) pAttacker.level; ServerPlayer player = ((ServerPlayer) pAttacker); BlockPos position = pTarget.blockPosition(); double val = Math.random(); if (pLevel == 5) { public float getDamageBonus(0.05);
June 19, 20223 yr please use the Forum code feature or a past website to upload your code do you know basic java?
June 19, 20223 yr i would recommend you to learn the java basics first before modding minecraft you can start here: Official documentation: https://docs.oracle.com/javase/tutorial/ Absolute basics with an interactive editor: https://www.codecademy.com/learn/learn-java Ongoing online course with assignments: https://java-programming.mooc.fi/ Edited June 19, 20223 yr by Luis_ST
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.