Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

  • Author

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

  • Author

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.

27 minutes ago, xTekBlue said:

 

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.

I think you can handle the harvest block event.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

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...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.