Jump to content

Recommended Posts

Posted

Hello,

After creating a custom item, as well as a custom tool material & custom tools, I realised I can't repair them, as they have no defined repair material.

How would I set the repair material? I have the tools to be repaired, and the item I would like to set as the repair material already there.

If I'm asking a whole bunch of questions, please don't get angry. I'm trying to learn.

Posted

Take a look at the EnumToolMaterial class and see if you can figure it out.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

Okay, got something basic set up. It's returning a NullPointerException on first tool that it loads.

Here's the init class:

[spoiler=ModItems.class]

package com.t10a.minedran.init;

import com.t10a.minedran.item.material.ItemTutorial;
import com.t10a.minedran.item.tools.*;
import com.t10a.minedran.item.weapons.ItemCustomSword;
import com.t10a.minedran.item.weapons.ItemMace;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.util.EnumHelper;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.oredict.OreDictionary;

public class ModItems
{
    public static Item mace_wood;
    public static Item mace_stone;
    public static Item mace_iron;
    public static Item mace_gold;
    public static Item mace_diamond;
    public static Item mace_tutorial;
    public static Item axe_tutorial;
    public static Item sword_tutorial;
    public static Item pickaxe_tutorial;
    public static Item shovel_tutorial;
    public static Item hoe_tutorial;
    public static Item item_tutorial;
    public static Item shears_gold;
    public static Item shears_diamond;
    public static Item shears_tutorial;
    public static Item.ToolMaterial TUTORIAL;

    public static void init()
    {
        /*<unlocalized name>=new Item<name>();
	 * NOTICE: Because of how Mojang coded axes, any future item that extends ItemAxe HAS to be registered as follows:
	 *<unlocalized name>=new Item<name>(MATERIAL,DAMAGE_FLOAT,ATTACKSPEED_FLOAT);
	 */
        mace_wood=new ItemMace(Item.ToolMaterial.WOOD);
        mace_stone=new ItemMace(Item.ToolMaterial.STONE);
        mace_iron=new ItemMace(Item.ToolMaterial.IRON);
        mace_diamond=new ItemMace(Item.ToolMaterial.DIAMOND);
        mace_gold=new ItemMace(Item.ToolMaterial.GOLD);
        mace_tutorial=new ItemMace(TUTORIAL);
        axe_tutorial=new ItemCustomAxe(TUTORIAL, 9F, -3.0F);
        sword_tutorial=new ItemCustomSword(TUTORIAL);
        pickaxe_tutorial=new ItemCustomPickaxe(TUTORIAL);
        shovel_tutorial=new ItemCustomShovel(TUTORIAL);
        hoe_tutorial=new ItemCustomHoe(TUTORIAL);
        item_tutorial=new ItemTutorial();
        shears_gold=new ItemCustomShears(Item.ToolMaterial.GOLD);
        shears_diamond=new ItemCustomShears(Item.ToolMaterial.DIAMOND);
        shears_tutorial=new ItemCustomShears(TUTORIAL);

        Item.ToolMaterial TUTORIAL = EnumHelper.addToolMaterial("TUTORIAL", 3, 1000, 15.0F, 4.0F, 30);
        TUTORIAL.setRepairItem(new ItemStack(ModItems.item_tutorial));
    }

    public static void register()
    {
        //GameRegistry.register(<unlocalized name>);
        //NOTICE: THIS IS VERY LIKELY TO CHANGE ONCE I FIGURE OUT HOW TO REGISTER STUFF PROPERLY
        GameRegistry.register(mace_wood);
        GameRegistry.register(mace_stone);
        GameRegistry.register(mace_iron);
        GameRegistry.register(mace_diamond);
        GameRegistry.register(mace_gold);
        GameRegistry.register(mace_tutorial);
        GameRegistry.register(axe_tutorial);
        GameRegistry.register(sword_tutorial);
        GameRegistry.register(pickaxe_tutorial);
        GameRegistry.register(shovel_tutorial);
        GameRegistry.register(hoe_tutorial);
        GameRegistry.register(item_tutorial);
        GameRegistry.register(shears_diamond);
        GameRegistry.register(shears_gold);
        GameRegistry.register(shears_tutorial);
    }

    public static void registerRenders()
    {
        //registerRender(<unlocalized name>);
        registerRender(mace_wood);
        registerRender(mace_stone);
        registerRender(mace_iron);
        registerRender(mace_diamond);
        registerRender(mace_gold);
        registerRender(mace_tutorial);
        registerRender(axe_tutorial);
        registerRender(sword_tutorial);
        registerRender(pickaxe_tutorial);
        registerRender(shovel_tutorial);
        registerRender(hoe_tutorial);
        registerRender(item_tutorial);
        registerRender(shears_diamond);
        registerRender(shears_gold);
        registerRender(shears_tutorial);
    }

    public static void registerOreDictionary()
    {
        OreDictionary.registerOre("tutorial", new ItemStack(ModItems.item_tutorial));
    }

    private static void registerRender(Item item)
    {
        //Is likely to change. It'll be a pain in the ass to fix though.
        Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, new ModelResourceLocation(item.getRegistryName(),"inventory"));
    }
}

 

And here's the item that it crashes on:

[spoiler=ItemMace.class]

package com.t10a.minedran.item.weapons;

import com.google.common.collect.Sets;
import com.t10a.minedran.item.MaterialEffects;
import com.t10a.minedran.reference.Reference;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.MobEffects;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemTool;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

import java.util.List;
import java.util.Set;

public class ItemMace extends ItemTool
{
    //Dummy set to get the tool class to shut up. Also, stops the crashing. I know, I could set a custom item like the sword.
    private static final Set<Block> MaceBlocks = Sets.newHashSet(new Block[] {Blocks.BEDROCK});
    public final Item.ToolMaterial material;

    public ItemMace(ToolMaterial material) {
        super(1.0F, -2.8F, material, MaceBlocks);
        setMaxStackSize(1);
        this.material = material;
        this.efficiencyOnProperMaterial = 0.0F;

        setCreativeTab(CreativeTabs.COMBAT);
        //It's a good idea to put the mod id in front of the unlocalised name. Otherwise, naming conflicts may arise.
        setUnlocalizedName(Reference.MOD_ID + "." + Reference.ItemBase.MACE.getUnlocalizedName() + "_" + getToolMaterialName().toLowerCase());
        setRegistryName(Reference.ItemBase.MACE.getRegistryName()  + "_" + getToolMaterialName().toLowerCase());
    }

    @Override
    public void addInformation(ItemStack stack, EntityPlayer player, List<String> list, boolean par4)
    {
        list.add("Hit enemies for a chance to inflict Slowness!");
    }

    @Override
    public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker)
    {
        MaterialEffects.effectsOnAttack(material, target, attacker);
        int pow=(int)(Math.random()*4+1);
        if (pow == 1)
            target.addPotionEffect(new PotionEffect(MobEffects.SLOWNESS, 80));
        stack.damageItem(1, attacker);
        return super.hitEntity(stack, target, attacker);
    }

    @Override
    public boolean onBlockDestroyed(ItemStack stack, World worldIn, IBlockState state, BlockPos pos, EntityLivingBase entityLiving)
    {
        if ((double)state.getBlockHardness(worldIn, pos) != 0.0D)
        {
            stack.damageItem(2, entityLiving);
        }

        return true;
    }
}

 

If I'm asking a whole bunch of questions, please don't get angry. I'm trying to learn.

Posted

Okay, it loads now, and repairs just fine in an anvil. What do I add to a shapeless recipe for it to repair an item?

If I'm asking a whole bunch of questions, please don't get angry. I'm trying to learn.

Posted

Something like this will require an event handler this way.

// Add the Recipe
GameRegistry.addShapelessRecipe(new ItemStack(Items.IRON_PICKAXE), new Object[]{Items.IRON_INGOT, new ItemStack(Items.IRON_PICKAXE, 1, OreDictionary.WILDCARD_VALUE)});
// Register Event Class
MinecraftForge.EVENT_BUS.register(new EventHandlerClass());
// Then handle the repairing
@SubscribeEvent
public void onCrafting(ItemCraftedEvent event) {
	// TODO Handle Item Repair here.
}

 

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.

Posted

Added that shapeless recipe code to the recipes class, and it works! Thanks!

If I'm asking a whole bunch of questions, please don't get angry. I'm trying to learn.

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.