Posted November 19, 20186 yr I have recently been playing around with enchantments, and I setup the book/enchantment attributes in no time, but I'm having trouble mimicking the Frost Walker enchantment. For now, I am just trying to get it to act exactly like Frost Walker. Not sure if I'm registering wrong or just have overlooked something (I have never coded a functional enchantment). The enchantment book shows up fine, and applies to items in an anvil just as it should. No errors are logged, just nothing happens when I walk on ice. Thanks. UPDATE: I never called the freezeNearby class, so after adding to this to EnchantmentInit MyEnchantment.freezeNearby(livingBase, world, pos, 1); it works. However it does it whenever a player steps on ice, not when the enchanted boots are equipped. Spoiler public class MyEnchantment extends Enchantment { public MyEnchantment() { super(Rarity.RARE, EnumEnchantmentType.ARMOR_FEET, new EntityEquipmentSlot[] {EntityEquipmentSlot.FEET}); this.setName("myenchantment"); this.setRegistryName(new ResourceLocation(Reference.MOD_ID + ":" + "myenchantment")); EnchantmentInit.ENCHANTMENTS.add(this); } @Override public int getMinEnchantability(int enchantmentLevel) { return 20 * enchantmentLevel; } @Override public int getMaxEnchantability(int enchantmentLevel) { return this.getMinEnchantability(enchantmentLevel) + 10; } @Override public boolean isTreasureEnchantment() { return true; } //Copied from FrostWalkerEnchantment.java public static void freezeNearby(EntityLivingBase living, World worldIn, BlockPos pos, int level) { if (living.onGround) { float f = (float)Math.min(16, 2 + level); BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos(0, 0, 0); for (BlockPos.MutableBlockPos blockpos$mutableblockpos1 : BlockPos.getAllInBoxMutable(pos.add((double)(-f), -1.0D, (double)(-f)), pos.add((double)f, -1.0D, (double)f))) { if (blockpos$mutableblockpos1.distanceSqToCenter(living.posX, living.posY, living.posZ) <= (double)(f * f)) { blockpos$mutableblockpos.setPos(blockpos$mutableblockpos1.getX(), blockpos$mutableblockpos1.getY() + 1, blockpos$mutableblockpos1.getZ()); IBlockState iblockstate = worldIn.getBlockState(blockpos$mutableblockpos); if (iblockstate.getMaterial() == Material.AIR) { IBlockState iblockstate1 = worldIn.getBlockState(blockpos$mutableblockpos1); if (iblockstate1.getMaterial() == Material.WATER && (iblockstate1.getBlock() == net.minecraft.init.Blocks.WATER || iblockstate1.getBlock() == net.minecraft.init.Blocks.FLOWING_WATER) && ((Integer)iblockstate1.getValue(BlockLiquid.LEVEL)).intValue() == 0 && worldIn.mayPlace(Blocks.FROSTED_ICE, blockpos$mutableblockpos1, false, EnumFacing.DOWN, (Entity)null)) { worldIn.setBlockState(blockpos$mutableblockpos1, Blocks.FROSTED_ICE.getDefaultState()); worldIn.scheduleUpdate(blockpos$mutableblockpos1.toImmutable(), Blocks.FROSTED_ICE, MathHelper.getInt(living.getRNG(), 60, 120)); } } } } } } @Override protected boolean canApplyTogether(Enchantment ench) { return super.canApplyTogether(ench) && ench != Enchantments.DEPTH_STRIDER; } } Spoiler public class EnchantmentInit { public static final List<Enchantment> ENCHANTMENTS = new ArrayList<Enchantment>(); public static final Enchantment MY_ENCHANTMENT = new MyEnchantment(); @SubscribeEvent public static void setEnchantment(LivingUpdateEvent event) { EntityLivingBase livingBase = event.getEntityLiving(); int level = EnchantmentHelper.getMaxEnchantmentLevel(MY_ENCHANTMENT, livingBase); BlockPos pos = livingBase.getPosition(); World world = event.getEntity().world; MyEnchantment.freezeNearby(livingBase, world, pos, 1); } } Spoiler @SubscribeEvent public static void onEnchantmentRegister(RegistryEvent.Register<Enchantment> event) { event.getRegistry().registerAll(EnchantmentInit.ENCHANTMENTS.toArray(new Enchantment[0])); } Edited November 19, 20186 yr by Siqhter
November 19, 20186 yr 39 minutes ago, Siqhter said: int level = EnchantmentHelper.getMaxEnchantmentLevel(MY_ENCHANTMENT, livingBase); You never use this variable, I assume you want to. Plus there aren't any if statements in that block of code so of course it always happens. VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
November 19, 20186 yr Author Right, I figured that out and was just adding a conditional to check whether or not the player is wearing the boots. How can I check for a specific enchantment?
November 19, 20186 yr 1 minute ago, Siqhter said: Right, I figured that out and was just adding a conditional to check whether or not the player is wearing the boots. How can I check for a specific enchantment? Well if the level is 0 there cant be an enchantment can there? VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
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.