Jump to content

Recommended Posts

Posted

MinecraftForge.setToolClass(myItemTool, "pickaxe", 3);
...
public float getStrVsBlock(ItemStack par1ItemStack, Block par2Block) {
	System.out.println("Str: " +par1ItemStack.stackTagCompound.getInteger("material"));
	...
	return someValue;
}

 

For stone bricks and bricks, getStrVsBlock is not being called.  It is for other materials, like stone, ores, and such, but NOT bricks, which pickaxes are supposed to be the tool class for.

 

What gives?

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

Hi

 

Never used this method, so this is a random guess - isToolEffective is returning true?

 

ItemTool.
    /** FORGE: Overridden to allow custom tool effectiveness */
    @Override
    public float getStrVsBlock(ItemStack stack, Block block, int meta) 
    {
        if (ForgeHooks.isToolEffective(stack, block, meta))
        {
            return efficiencyOnProperMaterial;
        }
        return getStrVsBlock(stack, block);
    }

 

-TGG

Posted

I'm not actually using ItemTool, I have an item that is like a tool.

 

Plus that's already inside getStrVsBlock which is NOT being called.

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

Item#canHarvestBlock(Block, ItemStack)

If you return true, you won't get the str check.

Same goes if the block Material#isAdventureModeExempt().

Vanilla material for bricks is rock, which is not exempt, IIRC.

 

From EntityPlayer:

if (block.blockMaterial.isAdventureModeExempt()) {
				return true;
			}
			if (this.getCurrentEquippedItem() != null) {
				ItemStack itemstack = this.getCurrentEquippedItem();
				if (itemstack.canHarvestBlock(block) || itemstack.getStrVsBlock(block) > 1.0F) {
					return true;
				}
			}

 

Posted

Here's my canHarvestBlock function, which was yoinked strait from the pickaxe:

 

        public boolean canHarvestBlock(Block par1Block, ItemStack itemStack) {
                EnumToolMaterial toolMaterial = EnumToolMaterial.values()[itemStack.stackTagCompound.getInteger("material")];
                return par1Block == Block.obsidian ? toolMaterial.getHarvestLevel() == 3 : (par1Block != Block.blockDiamond && par1Block != Block.oreDiamond ? (par1Block != Block.oreEmerald && par1Block != Block.blockEmerald ? (par1Block != Block.blockGold && par1Block != Block.oreGold ? (par1Block != Block.blockIron && par1Block != Block.oreIron ? (par1Block != Block.blockLapis && par1Block != Block.oreLapis ? (par1Block != Block.oreRedstone && par1Block != Block.oreRedstoneGlowing ? (par1Block.blockMaterial == Material.rock ? true : (par1Block.blockMaterial == Material.iron ? true : par1Block.blockMaterial == Material.anvil)) : toolMaterial.getHarvestLevel() >= 2) : toolMaterial.getHarvestLevel() >= 1) : toolMaterial.getHarvestLevel() >= 1) : toolMaterial.getHarvestLevel() >= 2) : toolMaterial.getHarvestLevel() >= 2) : toolMaterial.getHarvestLevel() >= 2);
        }

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

Make a Arraylist with BlockMaterials or /and a Arraylist with blocks

Then you only check if the arraylist contains this block/blockmaterial.

 

Then you handle your action.

 

Hope it helps^^"

Posted

par1Block.blockMaterial == Material.rock ? true:

If that is from the ItemPickaxe, then you get the expected result.

You might want to do things differently.

 

It is from ItemPickaxe:

 

package net.minecraft.item;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;

public class ItemPickaxe extends ItemTool
{
    /** an array of the blocks this pickaxe is effective against */
    public static final Block[] blocksEffectiveAgainst = new Block[] {Block.cobblestone, Block.stoneDoubleSlab, Block.stoneSingleSlab, Block.stone, Block.sandStone, Block.cobblestoneMossy, Block.oreIron, Block.blockIron, Block.oreCoal, Block.blockGold, Block.oreGold, Block.oreDiamond, Block.blockDiamond, Block.ice, Block.netherrack, Block.oreLapis, Block.blockLapis, Block.oreRedstone, Block.oreRedstoneGlowing, Block.rail, Block.railDetector, Block.railPowered, Block.railActivator};

    public ItemPickaxe(int par1, EnumToolMaterial par2EnumToolMaterial)
    {
        super(par1, 2.0F, par2EnumToolMaterial, blocksEffectiveAgainst);
    }

    /**
     * Returns if the item (tool) can harvest results from the block type.
     */
    public boolean canHarvestBlock(Block par1Block)
    {
        return par1Block == Block.obsidian ? this.toolMaterial.getHarvestLevel() == 3 : (par1Block != Block.blockDiamond && par1Block != Block.oreDiamond ? (par1Block != Block.oreEmerald && par1Block != Block.blockEmerald ? (par1Block != Block.blockGold && par1Block != Block.oreGold ? (par1Block != Block.blockIron && par1Block != Block.oreIron ? (par1Block != Block.blockLapis && par1Block != Block.oreLapis ? (par1Block != Block.oreRedstone && par1Block != Block.oreRedstoneGlowing ? (par1Block.blockMaterial == Material.rock ? true : (par1Block.blockMaterial == Material.iron ? true : par1Block.blockMaterial == Material.anvil)) : this.toolMaterial.getHarvestLevel() >= 2) : this.toolMaterial.getHarvestLevel() >= 1) : this.toolMaterial.getHarvestLevel() >= 1) : this.toolMaterial.getHarvestLevel() >= 2) : this.toolMaterial.getHarvestLevel() >= 2) : this.toolMaterial.getHarvestLevel() >= 2);
    }

    /**
     * Returns the strength of the stack against a given block. 1.0F base, (Quality+1)*2 if correct blocktype, 1.5F if
     * sword
     */
    public float getStrVsBlock(ItemStack par1ItemStack, Block par2Block)
    {
        return par2Block != null && (par2Block.blockMaterial == Material.iron || par2Block.blockMaterial == Material.anvil || par2Block.blockMaterial == Material.rock) ? this.efficiencyOnProperMaterial : super.getStrVsBlock(par1ItemStack, par2Block);
    }
}

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

The bad thing is i have at the moment no access to my pneumatic drill.

But my custom tool i have access to. Here this is the way i made it:

 

Here how i made my tool: its a multitool. but you can do it as you want

package speiger.src.api.common.items;

import java.util.HashMap;
import java.util.List;
import java.util.Random;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.MinecraftForge;
import speiger.src.api.api.BlockStack;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class ItemSpecialTool extends ItemSpmod
{
public Random rand = new Random();
public HashMap<Material, Boolean> validPick = new HashMap<Material, Boolean>();
public HashMap<Material, Boolean> validShovel = new HashMap<Material, Boolean>();
public HashMap<Material, Boolean> validAxe = new HashMap<Material, Boolean>();

public ItemSpecialTool(int par1) 
{
	super(par1, true);
	this.setAPICreativeTap();
	MinecraftForge.setToolClass(this, "pickaxe", 1000);
	MinecraftForge.setToolClass(this, "axe", 1000);
	MinecraftForge.setToolClass(this, "shovel", 1000);
	addPickMaterial();
}

public Material[] pickList = new Material[]{Material.anvil, Material.iron, Material.piston, Material.redstoneLight, Material.rock, Material.ice};
public Material[] shovelList = new Material[]{Material.cake, Material.clay, Material.craftedSnow, Material.glass, Material.grass, Material.ground, Material.materialCarpet, Material.sand, Material.snow};
public Material[] axeList = new Material[]{Material.cactus, Material.cloth, Material.coral, Material.leaves, Material.plants, Material.vine, Material.pumpkin, Material.wood};

public void addPickMaterial()
{
	//Pickaxes
	for(int i = 0;i<pickList.length;i++)
	{
		validPick.put(pickList[i], true);
	}
	for(int i = 0;i<shovelList.length;i++)
	{
		validShovel.put(shovelList[i], true);
	}
	for(int i = 0;i<axeList.length;i++)
	{
		validAxe.put(axeList[i], true);
	}

}







@Override
public boolean onBlockStartBreak(ItemStack itemstack, int X, int Y, int Z, EntityPlayer player)
{
	BlockStack block = new BlockStack(X, Y, Z, player.worldObj);
	NBTTagCompound nbt = itemstack.getTagCompound().getCompoundTag("Tool");
	if(validPick.containsKey(block.getBlockFromStack().blockMaterial))
	{

		int pick = nbt.getInteger("PickaxeSpeed");
		nbt.setInteger("PickaxeSpeed", pick+1);
		return false;
	}
	else if(validShovel.containsKey(block.getBlockFromStack().blockMaterial))
	{
		int shovel = nbt.getInteger("ShovelSpeed");
		nbt.setInteger("ShovelSpeed", shovel+1);
		return false;
	}
	else if(validAxe.containsKey(block.getBlockFromStack().blockMaterial))
	{
		int axe = nbt.getInteger("AxeSpeed");
		nbt.setInteger("AxeSpeed", axe+1);
		return false;
	}
	else
	{


		return false;
	}



}




public static ItemStack createSpecialTool(int par1)
{
	NBTTagCompound nbt = new NBTTagCompound();
	nbt.setCompoundTag("Tool", new NBTTagCompound());
	nbt.getCompoundTag("Tool").setInteger("AxeSpeed", 0);
	nbt.getCompoundTag("Tool").setInteger("ShovelSpeed", 0);
	nbt.getCompoundTag("Tool").setInteger("PickaxeSpeed", 0);
	ItemStack stack = new ItemStack(par1, 1, 0);
	stack.setTagCompound(nbt);
	return stack;
}




@Override
public boolean canHarvestBlock(Block par1Block)
{
	return par1Block.blockHardness != -1;
}







@Override
public float getStrVsBlock(ItemStack itemstack, Block block, int metadata)
{
	NBTTagCompound nbt = itemstack.getTagCompound().getCompoundTag("Tool");

	if(validPick.containsKey(block.blockMaterial))
	{
		int pick = nbt.getInteger("PickaxeSpeed");
		float end = (float) (0.001 * pick);
		if(end < 2F)
		{
			end+=2F;
		}
		return end;
	}
	else if(validAxe.containsKey(block.blockMaterial))
	{
		int axe = nbt.getInteger("AxeSpeed");
		float end = (float) (0.001 * axe);
		if(end < 2F)
		{
			end+=2F;
		}
		return end;
	}
	else if(validShovel.containsKey(block.blockMaterial))
	{
		int shovel = nbt.getInteger("ShovelSpeed");
		float end = (float) (0.001 * shovel);
		if(end < 2F)
		{
			end+=2F;
		}
		return end;
	}
	return 1F;
}




@Override
@SideOnly(Side.CLIENT)
public void getSubItems(int par1, CreativeTabs par2CreativeTabs, List par3)
{
	ItemStack out = createSpecialTool(par1);
	par3.add(out);
}




@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack par1, EntityPlayer par2, List par3, boolean par4)
{
	NBTTagCompound nbt = par1.getTagCompound().getCompoundTag("Tool");
	par3.add("Pickaxe Points: "+nbt.getInteger("PickaxeSpeed"));
	par3.add("Axe Points: "+nbt.getInteger("AxeSpeed"));
	par3.add("Shovel Points: "+nbt.getInteger("ShovelSpeed"));
	this.getInformation(par1, par2, par3, par4);

}




}

Posted

Hi

 

Plus that's already inside getStrVsBlock which is NOT being called.

your getStrVsBlock code has a different signature, the forge code is called first

 

Item.
   /**
     * Metadata-sensitive version of getStrVsBlock
     * @param itemstack The Item Stack
     * @param block The block the item is trying to break
     * @param metadata The items current metadata
     * @return The damage strength
     */
    public float getStrVsBlock(ItemStack itemstack, Block block, int metadata)
    {
        return getStrVsBlock(itemstack, block);
    }

- however only overridden in ItemTool

 

I'm not actually using ItemTool, I have an item that is like a tool.

Show us your code?

 

-TGG

 

 

 

Posted

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

Hi

 

Using my IDE to refactor that canHarvestBlock statement - looks to me like GotoLink is right and it will always return true when material is rock, so your getStrVsRock will never be called-?

 

    if (par1Block == Block.obsidian) {
      return toolMaterial.getHarvestLevel() == 3;
    } else if (par1Block == Block.blockDiamond || par1Block == Block.oreDiamond) {
      return toolMaterial.getHarvestLevel() >= 2;
    } else if (par1Block == Block.oreEmerald || par1Block == Block.blockEmerald) {
      return toolMaterial.getHarvestLevel() >= 2;
    } else if (par1Block == Block.blockGold || par1Block == Block.oreGold) {
      return toolMaterial.getHarvestLevel() >= 2;
    } else if (par1Block == Block.blockIron || par1Block == Block.oreIron) {
      return toolMaterial.getHarvestLevel() >= 1;
    } else if (par1Block == Block.blockLapis || par1Block == Block.oreLapis) {
      return toolMaterial.getHarvestLevel() >= 1;
    } else if (par1Block == Block.oreRedstone || par1Block == Block.oreRedstoneGlowing) {
      return toolMaterial.getHarvestLevel() >= 2;
    } else if (par1Block.blockMaterial == Material.rock) {
      return true;
    } else if (par1Block.blockMaterial == Material.iron) {
      return true;
    } else return par1Block.blockMaterial == Material.anvil;

-TGG

Posted
canHarvestBlock [...] will always return true when material is rock, so your getStrVsRock will never be called

 

 

Wait, so "can harvest -> true" means "don't call str vs. block" ?

 

That seems backwards.

 

Especially when it works just fine for obsidian and so on.

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

Not really backwards you know...if you can harvest a block without any str, then you don't need to check the str required ;)

If you try a diamond pickaxe on obsidian, it won't get the str check. That is expected.

 

Always return false, and you'll always get the str check.

Posted

Not really backwards you know...if you can harvest a block without any str, then you don't need to check the str required ;)

If you try a diamond pickaxe on obsidian, it won't get the str check. That is expected.

 

Always return false, and you'll always get the str check.

 

Incorrect.

 

The item I'm testing with should have the same speed and material harvesting as iron (because of NBT tags; the item has a tag for its material and it's saying iron).

 

It doesn't matter if I return true OR false in canHarvest, it has the same speed and harvest level as stone (and does not call getStrVsBlock in either case for the troublesome materials).  With the exception of brick and stone brick, which it acts like bare fists (no speed, no drops), which stone picks CAN harvest.

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

MinecraftForge.setToolClass(myItemTool, "pickaxe", 3);

I did miss that on your post.

This ForgeHooks thing only applies to Item, not ItemStack with NBT and all that.

You'd better use PlayerEvent.HarvestCheck and PlayerEvent.BreakSpeed rather than this.

 

If you still want to use it, you'd have to set the bricks harvest level too.

MinecraftForge.setBlockHarvestLevel(Block.bricks, "pickaxe", 0);

 

I've already explained why any pick can harvest bricks, without relying on this hook. With ItemPickaxe#canHarvestBlock returning true for any block with material as rock, except a few ores block.

Posted

Gah.

 

I am not going to add an event handler for this.  The goal of the project was to only use NBT driven effects.

 

There's a few holes in that plan, but for the most part it works.

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.

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.