Jump to content

Recommended Posts

Posted

i've made an pickaxe and an block but the problem is that i want to make the block only be harvestable by that particulair pickaxe and no other but it want succeed with setharvestlevel here the code:

pickaxe:

package com.CloudyProductions.DreamMod.heaven.items;

import com.CloudyProductions.DreamMod.Main;
import com.CloudyProductions.DreamMod.init.ItemInit;
import com.CloudyProductions.DreamMod.util.DevMode;
import com.CloudyProductions.DreamMod.util.IHasModel;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.ItemPickaxe;

public class ToolPickaxe extends ItemPickaxe implements IHasModel
{
    public ToolPickaxe(String name, ToolMaterial material, CreativeTabs tab)
    {
        super(material);
        setUnlocalizedName(name);
        setRegistryName(name);
        setCreativeTab(tab);
        setMaxDamage(1000);
        setMaxStackSize(1);

        DevMode.DevMode("Pickaxe: " + name + " tab: " + tab + " maxdamage: " + 1000 + " stacksize: " + 1);


        ItemInit.ITEMS.add(this);
    }

    @Override
    public void registerModels()
    {
        Main.proxy.registerItemRendere(this, 0, "inventory");
    }
}
the block class:

package com.CloudyProductions.DreamMod.heaven.blocks;


import com.CloudyProductions.DreamMod.Main;
import com.CloudyProductions.DreamMod.init.BlockInit;
import com.CloudyProductions.DreamMod.init.ItemInit;
import com.CloudyProductions.DreamMod.util.DevMode;
import com.CloudyProductions.DreamMod.util.IHasModel;
import net.minecraft.block.Block;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;

import java.util.Random;

public class CloudBlock extends Block implements IHasModel {

    public CloudBlock(String name, Material material, CreativeTabs tab) {
      super(material);


      setUnlocalizedName(name);
      setRegistryName(name);
      setCreativeTab(tab);
      setSoundType(SoundType.STONE);
      setHardness(100f);
      setResistance(18000000f);
      setHarvestLevel("pickaxe", 10);
      setLightLevel(0f);
      setLightOpacity(0);


        BlockInit.BLOCKS.add(this);
        ItemInit.ITEMS.add(new ItemBlock(this).setRegistryName(this.getRegistryName()));

        DevMode.DevMode("name: " + name
                + " material: " + material
                + " tab: " + tab);

    }
    public void registerModels() {
        Main.proxy.registerItemRendere(Item.getItemFromBlock(this), 0, "inventory");
    }

    @Override
    public Item getItemDropped(IBlockState state, Random rand, int fortune) {
        return Item.getItemFromBlock(this);
    }
    @Override
    public int quantityDropped(Random random) {
        return 1;
    }

}
the material code:

    public static final Item.ToolMaterial CLOUD_TOOL = EnumHelper.addToolMaterial("cloud_tool", 10, 1000, 15.0f, 30.0f, 20);

Posted (edited)

This is what i did:

package com.diamondminer88.mod.character.blocks.a.glass;

import com.diamondminer88.mod.character.blocks.blockbases.a.BlockBaseGlassA;
import com.diamondminer88.mod.character.init.ModBlocks;
import com.diamondminer88.mod.character.init.ModItems;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;

import java.util.Random;

public class AGlassBlack extends BlockBaseGlassA {
    public Item item;
    public EntityPlayer entityPlayer;
    public AGlassBlack(String name, Material material) {
        super(name, material);
    }
    @Override
    public Item getItemDropped(IBlockState state, Random rand, int fortune) {
        if (harvesters.get() !=  null) {
            entityPlayer = harvesters.get();
            Item MainHandHeldItem = entityPlayer.getHeldItemMainhand().getItem();
            if (MainHandHeldItem.equals(ModItems.TOOL_DIAMOND_GLASS_CUTTER) || MainHandHeldItem.equals(ModItems.TOOL_IRON_GLASS_CUTTER)) {
                this.item = Item.getItemFromBlock(ModBlocks.A_GLASS_BLACK);
            }
            else {
                this.item = ModItems.GLASS_SHARD_BLACK;
            }
        }
        return this.item;
    }
    @Override
    protected ItemStack getSilkTouchDrop(IBlockState state) {
        return new ItemStack(ModBlocks.A_GLASS_BLACK);
    }

}

 

And please when you are posting code onto the forum use the "code" function like i did. I made it so if you break the "AGlassBlack" block by my GlassCutter, it drops the block but if not, drops shards. As for the quantity, there there is only point to do quantityDropped if you're making it drop more than one of that item. The default is 1.

Edited by DiamondMiner88
Submitted to fast
Posted

did it already with 

if (harvesters.get() != null) {
    player = harvesters.get();
    Item pickaxe = player.getHeldItemMainhand().getItem();
    if (pickaxe.equals(ItemInit.CLOUD_PICKAXE)) {
        return;
    } else {
        setBlockUnbreakable();
    }
} 

but didn't work

Posted (edited)
@Override
    public boolean canHarvestBlock(IBlockAccess world, BlockPos pos, EntityPlayer player) {
            Item MainHandHeldItem = player.getHeldItemMainhand().getItem();
            if (MainHandHeldItem.equals(ItemInit.CLOUD_PICKAXE)) {
                return true;
            } else {
                return false;
            }
    }

In your block class

Edited by DiamondMiner88
Posted

i don't want to make an github don't want to make it open-source it's still in development gonna realease it soon and what i did imported IBlockState needs to be IBlockAccess. about open-source maybe in the feature i'm gonna make some sort of api or something for my mod and that you can use it for you're mod

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.