Jump to content

[SOLVED] [1.8][1.7.10] Custom tool harvesting some blocks slowly


Recommended Posts

Posted

I've created a tool that can function as a pickaxe, axe or shovel; but for some reason it's harvesting specific blocks much slower than the effective vanilla tool does while harvesting other blocks at the same speed as the vanilla tool.

 

The slow blocks include Block of Coal, Dispenser, Note Block, Bricks, Obsidian, Redstone Ore, Monster Spawner, Stairs, Doors and Pressure Plates. I can't see any pattern in which blocks are slow and which are normal speed.

 

My code can be found here: 1.7.10, 1.8.

 

Does anyone know what's going wrong? Is there some vanilla method I need to implement?

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

Have you tried to override ItemTool.getStrVsBlock()?

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Posted

In 1.8,

Item#getStrVsBlock

is only used in

Item#getDigSpeed

(which

ItemTool

overrides to use tool classes) and

InventoryPlayer#getStrVsBlock

(which isn't used anywhere).

 

In 1.7.10,

Item#func_150893_a

(the equivalent method) is only used in

EntityPlayer#isCurrentToolAdventureModeExempt

(which should use my override of

Item#canHarvestBlock

first) and

Inventory#func_146023_a

(which again isn't used anywhere).

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

Here is the code for a custom tool that i made. Ignore the most part of the code and check what may help you. By the way this is for 1.7.10

 

 

package net.aop.items;

 

import java.util.List;

import java.util.Set;

 

import net.aop.main.ageofpower;

import net.minecraft.block.Block;

import net.minecraft.block.material.Material;

import net.minecraft.entity.Entity;

import net.minecraft.entity.EntityLivingBase;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.init.Blocks;

import net.minecraft.item.Item;

import net.minecraft.item.ItemPickaxe;

import net.minecraft.item.ItemStack;

import net.minecraft.nbt.NBTTagCompound;

import net.minecraft.util.ChatComponentText;

import net.minecraft.util.DamageSource;

import net.minecraft.util.EnumChatFormatting;

import net.minecraft.util.IChatComponent;

import net.minecraft.world.World;

 

public class PTool extends Item{

 

public PTool() {

super();

this.setMaxDamage(0);

this.setMaxStackSize(1);

this.setCreativeTab(ageofpower.AgeOfPower);

this.setTextureName("aop:powertool");

}

 

float damage = 60.0F;

float efficiency = 8000.0F;

 

@Override

public boolean canHarvestBlock(Block block, ItemStack itemStack) {

 

return true;

 

}

 

@Override

public float func_150893_a(ItemStack itemstack, Block block) {

 

return efficiency;

 

}

 

@Override

public void onCreated(ItemStack itemstack, World world, EntityPlayer player) {

 

itemstack.stackTagCompound = new NBTTagCompound();

itemstack.stackTagCompound.setBoolean("BetterInventory", false);

itemstack.stackTagCompound.setBoolean("TreeMode", false);

 

super.onCreated(itemstack, world, player);

}

 

@Override

public void addInformation(ItemStack itemstack, EntityPlayer player, List list, boolean bool) {

 

if(itemstack.stackTagCompound != null){

boolean BI = itemstack.stackTagCompound.getBoolean("BetterInventory");

boolean TM = itemstack.stackTagCompound.getBoolean("TreeMode");

list.add("With this tool on your");

list.add("hand you feel so " + EnumChatFormatting.DARK_PURPLE + "POWERFUL");

list.add(" ");

if(BI){

list.add("BetterInventory: " + EnumChatFormatting.GREEN + "Enabled");

}else{

list.add("BetterInventory: " + EnumChatFormatting.RED + "Disabled");

}

if{

list.add("Tree Mode: " + EnumChatFormatting.GREEN + "Enabled");

}else{

list.add("Tree Mode: " + EnumChatFormatting.RED + "Disabled");

}

}

 

super.addInformation(itemstack, player, list, bool);

}

 

@Override

public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer player) {

 

if(player.isSneaking()){

if(itemstack.stackTagCompound != null){

if(itemstack.stackTagCompound.getBoolean("BetterInventory") == false){

itemstack.stackTagCompound.setBoolean("BetterInventory", true);

if(!world.isRemote){

player.addChatMessage(new ChatComponentText("BetterInventory: " + EnumChatFormatting.GREEN + "Enabled"));

}

}else if(itemstack.stackTagCompound.getBoolean("BetterInventory") == true){

itemstack.stackTagCompound.setBoolean("BetterInventory", false);

if(!world.isRemote){

player.addChatMessage(new ChatComponentText("BetterInventory: " + EnumChatFormatting.RED + "Disabled"));

}

}

}

}else{

if(itemstack.stackTagCompound != null){

if(itemstack.stackTagCompound.getBoolean("TreeMode") == false){

itemstack.stackTagCompound.setBoolean("TreeMode", true);

if(!world.isRemote){

player.addChatMessage(new ChatComponentText("Tree Mode: " + EnumChatFormatting.GREEN + "Enabled"));

}

}else if(itemstack.stackTagCompound.getBoolean("TreeMode") == true){

itemstack.stackTagCompound.setBoolean("TreeMode", false);

if(!world.isRemote){

player.addChatMessage(new ChatComponentText("Tree Mode: " + EnumChatFormatting.RED + "Disabled"));

}

}

}

}

 

return super.onItemRightClick(itemstack, world, player);

}

 

 

@Override

public boolean hitEntity(ItemStack stack, EntityLivingBase lb, EntityLivingBase lb2) {

lb.attackEntityFrom(DamageSource.cactus, damage);

return super.hitEntity(stack, lb, lb2);

}

 

@Override

public boolean onBlockDestroyed(ItemStack itemstack, World world, Block block, int x,int y, int z, EntityLivingBase lb) {

 

if(itemstack.stackTagCompound != null){

if(itemstack.stackTagCompound.getBoolean("TreeMode") == true){

if(world.getBlock(x, y, z).getMaterial() == Material.wood){

treemode(x, y, z, world);

}

}

}

 

return super.onBlockDestroyed(itemstack, world, block, x, y, z, lb);

}

 

@Override

public boolean onBlockStartBreak(ItemStack itemstack, int X, int Y, int Z, EntityPlayer player) {

 

if(itemstack.stackTagCompound != null){

if(itemstack.stackTagCompound.getBoolean("BetterInventory") == true){

Block block = player.worldObj.getBlock(X, Y, Z);

if(block == Blocks.stone || block == Blocks.cobblestone){

player.worldObj.setBlockToAir(X, Y, Z);

}

}

}

 

return super.onBlockStartBreak(itemstack, X, Y, Z, player);

}

 

@Override

public boolean isFull3D() {

 

return true;

}

 

@Override

public boolean isRepairable() {

 

return true;

}

 

@Override

public void onUpdate(ItemStack itemstack, World world, Entity player, int intpar1, boolean bool) {

 

if(!itemstack.hasTagCompound()){

itemstack.stackTagCompound = new NBTTagCompound();

itemstack.stackTagCompound.setBoolean("BetterInventory", false);

itemstack.stackTagCompound.setBoolean("TreeMode", false);

}

 

super.onUpdate(itemstack, world, player, intpar1, bool);

}

 

public void treemode(int x , int y , int z, World world)

{

for(int xpos = -1; xpos <= 1; xpos ++){

for(int ypos = -1; ypos <= 1; ypos++){

for(int zpos = -1; zpos <= 1; zpos++){

if(world.getBlock(x + xpos, y + ypos, z + zpos).getMaterial() == Material.wood){

world.func_147480_a(x + xpos, y + ypos, z + zpos, true);

this.treemode(x + xpos, y+ ypos, z+ zpos, world);

}

}

}

}

}

 

 

}

 

 

 

 

Posted

I found the source of the problem: not all blocks have a harvest tool/level set, so you need to override

Item#canHarvestBlock

and

Item#getDigSpeed

to check the block's

Material

like the vanilla tools do.

 

You can see my new code here: 1.7.10, 1.8

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

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.