Modderuy Posted June 18, 2022 Posted June 18, 2022 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) { } } } } } Quote
Luis_ST Posted June 18, 2022 Posted June 18, 2022 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 Quote
Modderuy Posted June 18, 2022 Author Posted June 18, 2022 Can you give an example of what that might look like? Quote
Modderuy Posted June 19, 2022 Author Posted June 19, 2022 if (pLevel == 5) { getDamageBonus(4.5f) } Quote
Luis_ST Posted June 19, 2022 Posted June 19, 2022 override Enchantment#getDamageBonus, and return (not call) the additional damage you want Quote
Modderuy Posted June 19, 2022 Author Posted June 19, 2022 you cannot overide inside curly brackets Quote
Luis_ST Posted June 19, 2022 Posted June 19, 2022 yeah but you should overide the method in your Enchantment (Razor) class Quote
Modderuy Posted June 19, 2022 Author Posted June 19, 2022 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); Quote
Luis_ST Posted June 19, 2022 Posted June 19, 2022 please use the Forum code feature or a past website to upload your code do you know basic java? Quote
Modderuy Posted June 19, 2022 Author Posted June 19, 2022 I just learned it, so I don't know much Quote
Luis_ST Posted June 19, 2022 Posted June 19, 2022 (edited) 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, 2022 by Luis_ST Quote
Recommended Posts
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.