Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

New enchantment hasn`t been added


RonMine
 Share

Recommended Posts

package com.hamedalgim.newmod.enchantment;

import net.minecraft.block.BlockLiquid;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentFireAspect;
import net.minecraft.enchantment.EnchantmentFrostWalker;
import net.minecraft.enchantment.EnumEnchantmentType;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.init.Blocks;
import net.minecraft.init.Enchantments;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;

public class EnchantmentFirstEnchant extends Enchantment {
    
     public EnchantmentFirstEnchant(Enchantment.Rarity rarityIn, EntityEquipmentSlot... slots)
        {
            super(rarityIn, EnumEnchantmentType.ARMOR_FEET, slots);
            this.setName("FirstEnchant");
        }

        /**
         * Returns the minimal value of enchantability needed on the enchantment level passed.
         */
        public int getMinEnchantability(int enchantmentLevel)
        {
            return enchantmentLevel * 10;
        }

        /**
         * Returns the maximum value of enchantability nedded on the enchantment level passed.
         */
        public int getMaxEnchantability(int enchantmentLevel)
        {
            return this.getMinEnchantability(enchantmentLevel) + 25;
        }

        public boolean isTreasureEnchantment()
        {
            return true;
        }

        /**
         * Returns the maximum level that the enchantment can have.
         */
        public int getMaxLevel()
        {
            return 2;
        }

        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.LAVA && (iblockstate1.getBlock() == net.minecraft.init.Blocks.LAVA || iblockstate1.getBlock() == net.minecraft.init.Blocks.FLOWING_LAVA) && ((Integer)iblockstate1.getValue(BlockLiquid.LEVEL)).intValue() == 0 && worldIn.mayPlace(Blocks.DIAMOND_BLOCK, blockpos$mutableblockpos1, false, EnumFacing.DOWN, (Entity)null))
                            {
                                worldIn.setBlockState(blockpos$mutableblockpos1, Blocks.DIAMOND_BLOCK.getDefaultState());
                                worldIn.scheduleUpdate(blockpos$mutableblockpos1.toImmutable(), Blocks.DIAMOND_BLOCK, MathHelper.getInt(living.getRNG(), 20, 10));
                            }
                        }
                    }
                }
            }
        }

        /**
         * Determines if the enchantment passed can be applyied together with this enchantment.
         */
        public boolean canApplyTogether(Enchantment ench)
        {
            return super.canApplyTogether(ench) && ench != Enchantments.FROST_WALKER;
        }

}
 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Could you explain what you mean by that, just to clarify I am trying to create a recipe type that handles potions and I'm pretty sure the standard recipe type cannot handle nbt data within the recipe. Do you mean use minecraft:crafting_shapeless as the type in the json file or am I misinterpreting 
    • Use the same recipe type as the crafting table. The recipe and serializer is the only thing that needs to be unique.
    • I have a custom recipe type that has successfully registered into minecraft, however I am trying to get it to work on the standard crafting table as it doesn't need a custom table for it.   { "type": "randomfhings:potion_edible", "ingredients": [ { "item" : "minecraft:glass", "data": "" }, { "item" : "minecraft:diamond" } ], "output": { "item": "randomfhings:ruby", "count": 3 } } This is a test recipe so far . package org.multicoder.randomfhings.recipe; import com.google.gson.JsonArray; import com.google.gson.JsonObject; import net.minecraft.core.NonNullList; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.GsonHelper; import net.minecraft.world.inventory.CraftingContainer; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.*; import net.minecraft.world.level.Level; import org.multicoder.randomfhings.RandomFhings; import javax.annotation.Nullable; public class PotionRecipe implements Recipe<CraftingContainer> { private final ResourceLocation id; private final ItemStack output; private final NonNullList<Ingredient> input; public PotionRecipe(ResourceLocation id, ItemStack output, NonNullList<Ingredient> input) { this.id = id; this.output = output; this.input = input; } @Override public NonNullList<Ingredient> getIngredients() { return input; } @Override public boolean matches(CraftingContainer p_44002_, Level p_44003_) { return input.get(0).test(p_44002_.getItem(0)); } @Override public ItemStack assemble(CraftingContainer p_44001_) { return output.copy(); } @Override public boolean canCraftInDimensions(int p_43999_, int p_44000_) { return true; } @Override public ItemStack getResultItem() { return output; } @Override public ResourceLocation getId() { return id; } @Override public RecipeSerializer<?> getSerializer() { return Serializer.INSTANCE; } @Override public RecipeType<?> getType() { return Type.INSTANCE; } public static class Type implements RecipeType<PotionRecipe> { private Type() { } public static final Type INSTANCE = new Type(); public static final String ID = "potion_edible"; } public static class Serializer implements RecipeSerializer<PotionRecipe> { public static final Serializer INSTANCE = new Serializer(); public static final ResourceLocation ID = new ResourceLocation(RandomFhings.MOD_ID,"potion_edible"); @Override public PotionRecipe fromJson(ResourceLocation id, JsonObject json) { ItemStack output = ShapedRecipe.itemStackFromJson(GsonHelper.getAsJsonObject(json, "output")); JsonArray ingredients = GsonHelper.getAsJsonArray(json, "ingredients"); NonNullList<Ingredient> inputs = NonNullList.withSize(2, Ingredient.EMPTY); for (int i = 0; i < inputs.size(); i++) { inputs.set(i, Ingredient.fromJson(ingredients.get(i))); } return new PotionRecipe(id, output, inputs); } @Override public PotionRecipe fromNetwork(ResourceLocation id, FriendlyByteBuf buf) { NonNullList<Ingredient> inputs = NonNullList.withSize(buf.readInt(), Ingredient.EMPTY); for (int i = 0; i < inputs.size(); i++) { inputs.set(i, Ingredient.fromNetwork(buf)); } ItemStack output = buf.readItem(); return new PotionRecipe(id, output, inputs); } @Override public void toNetwork(FriendlyByteBuf buf, PotionRecipe recipe) { buf.writeInt(recipe.getIngredients().size()); for (Ingredient ing : recipe.getIngredients()) { ing.toNetwork(buf); } buf.writeItemStack(recipe.getResultItem(), false); } @Override public RecipeSerializer<?> setRegistryName(ResourceLocation name) { return INSTANCE; } @Nullable @Override public ResourceLocation getRegistryName() { return ID; } @Override public Class<RecipeSerializer<?>> getRegistryType() { return Serializer.castClass(RecipeSerializer.class); } @SuppressWarnings("unchecked") // Need this wrapper, because generics private static <G> Class<G> castClass(Class<?> cls) { return (Class<G>)cls; } } } This is my recipe type class and it is registered via a deferred register.
    • The version you are using is no longer supported on this forum. Please update to a modern version of Minecraft to receive support. Currently supported versions are 1.19.2 (Latest) and 1.18.2 (LTS).
    • The version you are using is no longer supported on this forum. Please update to a modern version of Minecraft to receive support. Currently supported versions are 1.19.2 (Latest) and 1.18.2 (LTS).
  • Topics

×
×
  • Create New...

Important Information

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