Jump to content

Recommended Posts

Posted

Hi, I am actually trying to make a mod including the money with a special hammer which stamps coins and taking damage, when I do the craft it's work, the hammer come back in my inventory and the durability decreased, but, it work only one time, can somebody help me ?

 

There's my hammer class :

 

package fr.raydeur.MoneyMod.common;

 

import net.minecraft.item.Item;

import net.minecraft.item.ItemStack;

 

public class bankerHammer extends Item

{

public bankerHammer()

{

super();

this.setMaxStackSize(1);

this.setFull3D();

this.setMaxDamage(5); //I made only 5 for tests

this.setNoRepair();

}

 

@Override

public boolean doesContainerItemLeaveCraftingGrid(ItemStack itemstack)

{

return true;

}

 

@Override

public ItemStack getContainerItem(ItemStack itemStack)

{

ItemStack cStack = itemStack.copy();

cStack.setItemDamage(cStack.getItemDamage() + 1);

cStack.stackSize = 1;

return cStack;

}

 

public boolean hasContainerItem(ItemStack stack)

    {

        return stack.getItemDamage()<5;

    }

}

 

 

And there's my main code:

 

 

package fr.raydeur.MoneyMod.common;

 

import net.minecraft.block.Block;

import net.minecraft.block.material.Material;

import net.minecraft.creativetab.CreativeTabs;

import net.minecraft.init.Items;

import net.minecraft.item.Item;

import net.minecraft.item.ItemStack;

import net.minecraft.util.WeightedRandomChestContent;

import net.minecraftforge.common.ChestGenHooks;

import net.minecraftforge.common.util.EnumHelper;

import cpw.mods.fml.common.Mod;

import cpw.mods.fml.common.Mod.EventHandler;

import cpw.mods.fml.common.Mod.Instance;

import cpw.mods.fml.common.SidedProxy;

import cpw.mods.fml.common.event.FMLInitializationEvent;

import cpw.mods.fml.common.event.FMLPostInitializationEvent;

import cpw.mods.fml.common.event.FMLPreInitializationEvent;

import cpw.mods.fml.common.registry.GameRegistry;

import fr.raydeur.MoneyMod.blocks.SilverOre;

import fr.raydeur.MoneyMod.proxy.CommonProxy;

 

@Mod(modid = "moneymod", name = "MoneyMod", version = "1.0.0")

 

public class MoneyMod

{

@Instance("moneymod")

public static MoneyMod instance;

 

@SidedProxy(clientSide = "fr.raydeur.MoneyMod.proxy.ClientProxy", serverSide = "fr.raydeur.MoneyMod.proxy.CommonProxy")

public static CommonProxy proxy;

 

//Creation

 

//Items

//Coins

public static Item copperCoin, silverCoin, goldenCoin;

//Hammer

public static Item emeraldStick, diamondStick, glue, hammerHandle, goldenBall, hammerPommel, hammerHead;

//Ingots

public static Item silverIngot, renforcedSilverIngot;

//Banker's Hammer

public static Item bankerHammer;

 

public static final Item.ToolMaterial bankerHammerTool = EnumHelper.addToolMaterial("bankerHammer", 0, 1024, 1.0F, 2.0F, 10);

 

//Blocks

//Ore

public static Block silverOre;

 

//Creative Tab

public static CreativeTabs moneyModTab = new CreativeTabs("moneyModTab"){

public Item getTabIconItem() {

return new ItemStack(copperCoin).getItem();

}

 

};

 

@EventHandler

public void preInit(FMLPreInitializationEvent event)

{

//Items

copperCoin = new copperCoin().setUnlocalizedName("copperCoin").setTextureName("moneymod:copper_coin").setCreativeTab(moneyModTab);

silverCoin = new silverCoin().setUnlocalizedName("silverCoin").setTextureName("moneymod:silver_coin").setCreativeTab(moneyModTab);

goldenCoin = new goldenCoin().setUnlocalizedName("goldenCoin").setTextureName("moneymod:golden_coin").setCreativeTab(moneyModTab);

emeraldStick = new stick().setUnlocalizedName("emeraldStick").setTextureName("moneymod:emerald_stick").setCreativeTab(moneyModTab);

diamondStick = new stick().setUnlocalizedName("diamondStick").setTextureName("moneymod:diamond_stick").setCreativeTab(moneyModTab);

glue = new material().setUnlocalizedName("glue").setTextureName("moneymod:glue").setCreativeTab(moneyModTab);

hammerHandle = new HammerMaterial().setUnlocalizedName("hammerHandle").setTextureName("moneymod:hammer's_handle").setCreativeTab(moneyModTab);

goldenBall = new material().setUnlocalizedName("goldenBall").setTextureName("moneymod:golden_ball").setCreativeTab(moneyModTab);

hammerPommel = new HammerMaterial().setUnlocalizedName("hammerPommel").setTextureName("moneymod:hammer's_pommel").setCreativeTab(moneyModTab);

silverIngot = new ingot().setUnlocalizedName("silverIngot").setTextureName("moneymod:silver_ingot").setCreativeTab(moneyModTab);

renforcedSilverIngot = new ingot().setUnlocalizedName("renforcedSilverIngot").setTextureName("moneymod:renforced_silver_ingot").setCreativeTab(moneyModTab);

hammerHead = new HammerMaterial().setUnlocalizedName("hammerHead").setTextureName("moneymod:hammer's_head").setCreativeTab(moneyModTab);

bankerHammer = new bankerHammer().setUnlocalizedName("bankerHammer").setTextureName("moneymod:banker's_hammer").setCreativeTab(moneyModTab);

 

//Blocks

silverOre = new SilverOre(Material.rock).setBlockName("silverOre").setBlockTextureName("moneymod:silver_ore").setCreativeTab(moneyModTab);

 

//Register

 

//Items

GameRegistry.registerItem(copperCoin, "copper_coin");

GameRegistry.registerItem(silverCoin, "silver_coin");

GameRegistry.registerItem(goldenCoin, "golden_coin");

GameRegistry.registerItem(emeraldStick, "emerald_stick");

GameRegistry.registerItem(diamondStick, "diamond_stick");

GameRegistry.registerItem(glue, "glue");

GameRegistry.registerItem(hammerHandle, "hammer_handle");

GameRegistry.registerItem(goldenBall, "golden_ball");

GameRegistry.registerItem(hammerPommel, "hammer_pommel");

GameRegistry.registerItem(silverIngot, "silver_ingot");

GameRegistry.registerItem(renforcedSilverIngot, "renforced_silver_ingot");

GameRegistry.registerItem(hammerHead, "hammer_head");

//Banker's Hammer

GameRegistry.registerItem(bankerHammer, "banker_hammer");

//Blocks

GameRegistry.registerBlock(silverOre, "silver_ore");

 

}

 

@EventHandler

public void Init(FMLInitializationEvent event)

{

proxy.registerRenderThings();

 

//Gen Chests

ChestGenHooks.addItem(ChestGenHooks.DUNGEON_CHEST, new WeightedRandomChestContent(new ItemStack(copperCoin), 1, 3, 5));

ChestGenHooks.addItem(ChestGenHooks.DUNGEON_CHEST, new WeightedRandomChestContent(new ItemStack(copperCoin), 1, 20, 1));

ChestGenHooks.addItem(ChestGenHooks.VILLAGE_BLACKSMITH, new WeightedRandomChestContent(new ItemStack(copperCoin), 1, 5, 20));

 

//Crafting Table

 

//Coins

GameRegistry.addRecipe(new ItemStack(silverCoin), new Object[]{" C ","CCC"," C ", 'C', copperCoin});

GameRegistry.addRecipe(new ItemStack(goldenCoin), new Object[]{" S ","SSS"," S ",'S', silverCoin});

GameRegistry.addRecipe(new ItemStack(silverCoin), new Object[]{"HC", 'C', copperCoin, 'H', bankerHammer});

//Coins backups

GameRegistry.addRecipe(new ItemStack(copperCoin, 5), new Object[]{"S", 'S', silverCoin});

GameRegistry.addRecipe(new ItemStack(silverCoin, 5), new Object[]{"G",'G', goldenCoin});

//Sticks

GameRegistry.addRecipe(new ItemStack(emeraldStick), new Object[]{"E", "E", 'E', Items.emerald});

GameRegistry.addRecipe(new ItemStack(diamondStick), new Object[]{"D", "D", 'D', Items.diamond});

//Material

GameRegistry.addRecipe(new ItemStack(hammerHandle), new Object[]{"  D", " G ", "E  ", 'D', diamondStick, 'G', glue, 'E', emeraldStick});

GameRegistry.addRecipe(new ItemStack(goldenBall), new Object[]{" I ", "III", " I ", 'I', Items.gold_ingot});

GameRegistry.addRecipe(new ItemStack(hammerPommel), new Object[]{"  B", " N ", 'B', goldenBall, 'N', Items.gold_nugget});

GameRegistry.addRecipe(new ItemStack(hammerPommel), new Object[]{" B ", "N  ", 'B', goldenBall, 'N', Items.gold_nugget});

GameRegistry.addRecipe(new ItemStack(hammerHead), new Object []{"III", "III", 'I', renforcedSilverIngot});

//Ingots

GameRegistry.addRecipe(new ItemStack(renforcedSilverIngot), new Object[]{"II", "II", 'I', silverIngot});

//Banker's Hammer

GameRegistry.addRecipe(new ItemStack(bankerHammer), new Object[]{"  H", " / ", "P  ", 'H', hammerHead, '/', hammerHandle, 'P', hammerPommel});

 

//Furnace

 

//Material

GameRegistry.addSmelting(Items.slime_ball, new ItemStack(glue),0F);

//Ore

GameRegistry.addSmelting(silverOre, new ItemStack(silverIngot), 0F);

}

 

@EventHandler

public void postInit(FMLPostInitializationEvent event)

{

 

}

}

 

 

Posted

This is the code I use to decrease an Items durability. It also breaks the Item and plays the breaking sound:

    @Override
    public boolean hasContainerItem(ItemStack stack) {
        return true;
    }

    @Override
    public ItemStack getContainerItem(ItemStack itemStack) {
        if (itemStack.attemptDamageItem(1, rand)) {
            itemStack.stackSize--;
            if (itemStack.stackSize < 0)
                itemStack.stackSize = 0;
            itemStack.setItemDamage(0);
            itemStack = null;
            Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.func_147673_a(new ResourceLocation("random.break")));
        }
        return itemStack;
    }

PM's regarding modding questions should belong in the Modder Support sub-forum and won't be answered.

Posted

Oh sorry I forgot that...

put this in your class and intitialize it:

    private Random rand;

    public ItemDamageCrafting() {
        rand = new Random();
    }

PM's regarding modding questions should belong in the Modder Support sub-forum and won't be answered.

Posted

Your recipe for coins need to be registered to an ItemStack with a meta value of "OreDictionary.WILDCARD_VALUE" instead of bankerHammer in order for you to use the hammer multiple times in crafting with any damage value.

Posted
Your recipe for coins need to be registered to an ItemStack with a meta value of "OreDictionary.WILDCARD_VALUE" instead of bankerHammer in order for you to use the hammer multiple times in crafting with any damage value.

 

I don't really understand what to do  :-\

Posted

You would have to replace the ItemDamageCrafting() with your constructor (The place where you set the creative Tab and name and so on)

So it would be

public bankerHammer()

PM's regarding modding questions should belong in the Modder Support sub-forum and won't be answered.

Posted

You have to create an ItemStack with an "infinite" damage value for the crafting to work with any damage value

 

PM's regarding modding questions should belong in the Modder Support sub-forum and won't be answered.

Posted

Your recipe for coins need to be registered to an ItemStack with a meta value of "OreDictionary.WILDCARD_VALUE" instead of bankerHammer in order for you to use the hammer multiple times in crafting with any damage value.

 

I don't really understand what to do  :-\

 

In your code

GameRegistry.addRecipe(new ItemStack(silverCoin), new Object[]{"HC", 'C', copperCoin, 'H', bankerHammer});

 

needs to be

GameRegistry.addRecipe(new ItemStack(silverCoin), new Object[]{"HC", 'C', copperCoin, 'H', new ItemStack(bankerHammer, 1, OreDictionary.WILDCARD_VALUE)});

 

or like Busti said you can use Short.MAX_VALUE instead of OreDictionary.WILDCARD_VALUE if your absolutely bothered by 13 extra letters and 1 extra import. :rollseyes:

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.