Jump to content

Recommended Posts

Posted (edited)

NEW CODE FOR METHOD

	private boolean DoDropsOB(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand) {
		if (player.getHeldItem(hand) != null) {
			Item item = player.getHeldItem(hand).getItem();
			if (item != ItemInit.INGOT_SAW && item != ItemInit.ENCHANTED_SAW) {
				return false;
			}else if(item == ItemInit.INGOT_SAW && item.getDamage(player.getHeldItem(hand)) == player.getHeldItem(hand).getMaxDamage()) {
				player.inventory.deleteStack(player.getHeldItem(hand));
				worldIn.destroyBlock(pos, false);
				player.addItemStackToInventory(new ItemStack(ItemInit.OBSIDIAN_INGOT, 9));
				return true;
			}else if (item == ItemInit.INGOT_SAW && item.getDamage(player.getHeldItem(hand)) != player.getHeldItem(hand).getMaxDamage()) {
				player.getHeldItem(hand).setItemDamage(player.getHeldItem(hand).getItemDamage() + 1);
				worldIn.destroyBlock(pos, false);
				player.addItemStackToInventory(new ItemStack(ItemInit.OBSIDIAN_INGOT, 9));
				return true;
			}else if (item == ItemInit.ENCHANTED_SAW) {
				worldIn.destroyBlock(pos, false);
				player.addItemStackToInventory(new ItemStack(ItemInit.OBSIDIAN_INGOT, 9));
				return true;
			}
		}
		return true;
	}

The code below still does not seem to work, like it reverts back to normal.

				worldIn.destroyBlock(pos, false);
				player.addItemStackToInventory(new ItemStack(ItemInit.OBSIDIAN_INGOT, 9));

 

Edited by xTekBlue
Posted

Problem solved, i wasn't calling the method on client's. 

package xtekblue.mod.objects.blocks;

import java.util.Random;

import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.oredict.OreDictionary;
import xtekblue.mod.Main;
import xtekblue.mod.init.ItemInit;

public class SmoothObsidian extends BlockBase {

	public SmoothObsidian(String name, Material material) {
		super(name, material);

		setCreativeTab(Main.xtrablocks);
		setHardness(50.0F);
		setHarvestLevel("pickaxe", 3);
		setResistance(2000.0F);
	}
	
	public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
		if(worldIn.isRemote) {
				return this.DoDropsOB(worldIn, pos, state, playerIn, hand);
		}else {
			return this.DoDropsOB(worldIn, pos, state, playerIn, hand);
		}
	}
	
	private boolean DoDropsOB(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand) {
		if (player.getHeldItem(hand) != null) {
			Item item = player.getHeldItem(hand).getItem();
			if (item != ItemInit.INGOT_SAW && item != ItemInit.ENCHANTED_SAW) {
				return false;
			}else if(item == ItemInit.INGOT_SAW && item.getDamage(player.getHeldItem(hand)) == player.getHeldItem(hand).getMaxDamage()) {
				player.inventory.deleteStack(player.getHeldItem(hand));
				worldIn.destroyBlock(pos, false);
				player.addItemStackToInventory(new ItemStack(ItemInit.OBSIDIAN_INGOT, 9));
				return true;
			}else if (item == ItemInit.INGOT_SAW && item.getDamage(player.getHeldItem(hand)) != player.getHeldItem(hand).getMaxDamage()) {
				player.getHeldItem(hand).setItemDamage(player.getHeldItem(hand).getItemDamage() + 1);
				worldIn.destroyBlock(pos, false);
				player.addItemStackToInventory(new ItemStack(ItemInit.OBSIDIAN_INGOT, 9));
				return true;
			}else if (item == ItemInit.ENCHANTED_SAW) {
				worldIn.destroyBlock(pos, false);
				player.addItemStackToInventory(new ItemStack(ItemInit.OBSIDIAN_INGOT, 9));
				return true;
			}
		}
		return true;
	}
}

Working code ^^^

Last thing, is there a method i'm missing to allow a item to harvest a block regardless of level or even whether its a tool period? I can not find it.

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.