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

Posted

Hello, I have a tool that destroys a 3x3x3 area. The problem is that the blocks that are set to air are replaced with phantom blocks.

 

Phantom blocks are blocks that look like they're just air, but whenever walked into, teleports the player backwards.

 

ItemScythe:

package tooldles.item;

import java.util.List;
import java.util.Set;

import net.minecraft.block.Block;
import net.minecraft.block.Block.SoundType;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemTool;
import net.minecraft.world.World;
import tooldles.ReferenceOT;

import com.google.common.collect.Sets;

public class ItemScythe extends ItemTool {
private static final Set MINABLE_BLOCKS = Sets.newHashSet(new Block[] { Blocks.tallgrass, Blocks.deadbush, Blocks.leaves, Blocks.leaves2, Blocks.vine, Blocks.red_flower, Blocks.yellow_flower, Blocks.double_plant, Blocks.web });

public ItemScythe(ToolMaterial material, String name) {
	super(3F, material, MINABLE_BLOCKS);

	this.setUnlocalizedName(name);
	this.setTextureName(ReferenceOT.ID + ":" + name);
}

@Override
public boolean func_150897_b(Block block) {
	return block == Blocks.tallgrass || block == Blocks.deadbush || block == Blocks.leaves || block == Blocks.leaves2 || block == Blocks.vine || block == Blocks.red_flower || block == Blocks.yellow_flower || block == Blocks.double_plant || block == Blocks.web;
}

@Override
public boolean onBlockDestroyed(ItemStack itemStack, World world, Block block, int x, int y, int z, EntityLivingBase entity) {
	return super.onBlockDestroyed(itemStack, world, block, x, y, z, entity);
}

@Override
public boolean onBlockStartBreak(ItemStack itemStack, int x, int y, int z, EntityPlayer player) {
	World world = player.worldObj;
	Block block = world.getBlock(x, y, z);

	if(this.canHarvestBlock(block, itemStack)) {
		SoundType sound = block.stepSound;
		world.playSoundAtEntity(player, sound.getBreakSound(), sound.volume, 0.8F);

		itemStack.damageItem(1, player);

		breakBlock(world, itemStack, x - 1, y, z, player);
		breakBlock(world, itemStack, x + 1, y, z, player);
		breakBlock(world, itemStack, x - 1, y + 1, z, player);
		breakBlock(world, itemStack, x + 1, y + 1, z, player);
		breakBlock(world, itemStack, x - 1, y - 1, z, player);
		breakBlock(world, itemStack, x + 1, y - 1, z, player);

		breakBlock(world, itemStack, x, y, z - 1, player);
		breakBlock(world, itemStack, x, y, z + 1, player);
		breakBlock(world, itemStack, x, y + 1, z - 1, player);
		breakBlock(world, itemStack, x, y + 1, z + 1, player);
		breakBlock(world, itemStack, x, y - 1, z - 1, player);
		breakBlock(world, itemStack, x, y - 1, z + 1, player);

		breakBlock(world, itemStack, x + 1, y, z + 1, player);
		breakBlock(world, itemStack, x - 1, y, z - 1, player);
		breakBlock(world, itemStack, x + 1, y + 1, z + 1, player);
		breakBlock(world, itemStack, x - 1, y + 1, z - 1, player);
		breakBlock(world, itemStack, x + 1, y - 1, z + 1, player);
		breakBlock(world, itemStack, x - 1, y - 1, z - 1, player);

		breakBlock(world, itemStack, x + 1, y, z - 1, player);
		breakBlock(world, itemStack, x - 1, y, z + 1, player);
		breakBlock(world, itemStack, x + 1, y + 1, z - 1, player);
		breakBlock(world, itemStack, x - 1, y + 1, z + 1, player);
		breakBlock(world, itemStack, x + 1, y - 1, z - 1, player);
		breakBlock(world, itemStack, x - 1, y - 1, z + 1, player);

		breakBlock(world, itemStack, x, y + 1, z, player);
		breakBlock(world, itemStack, x, y - 1, z, player);

		return true;
	}
	return false;
}

private void breakBlock(World world, ItemStack itemStack, int x, int y, int z, EntityLivingBase entity) {
	Block block = world.getBlock(x, y, z);

	if(this.canHarvestBlock(block, itemStack)) {
		world.setBlock(x, y, z, Blocks.air);

		if(!world.isRemote) {
			List<ItemStack> loot = block.getDrops(world, x, y, z, world.getBlockMetadata(x, y, z), 2 + EnchantmentHelper.getFortuneModifier(entity));

			for(ItemStack lootItem : loot) {
				EntityItem lootEntity = new EntityItem(world, x, y, z, lootItem);

				world.spawnEntityInWorld(lootEntity);
			}
		}
	}
}
}

Kain

you are probably setting them to air client-side only, you need to do it server-side

 

move

"if(!world.isRemote) { "

up a few lines

  • Author

Nothing :(

 

package tooldles.item;

import java.util.List;
import java.util.Set;

import net.minecraft.block.Block;
import net.minecraft.block.Block.SoundType;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemTool;
import net.minecraft.world.World;
import tooldles.ReferenceOT;

import com.google.common.collect.Sets;

public class ItemScythe extends ItemTool {
private static final Set MINABLE_BLOCKS = Sets.newHashSet(new Block[] { Blocks.tallgrass, Blocks.deadbush, Blocks.leaves, Blocks.leaves2, Blocks.vine, Blocks.red_flower, Blocks.yellow_flower, Blocks.double_plant, Blocks.web });

public ItemScythe(ToolMaterial material, String name) {
	super(3F, material, MINABLE_BLOCKS);

	this.setUnlocalizedName(name);
	this.setTextureName(ReferenceOT.ID + ":" + name);
}

@Override
public boolean func_150897_b(Block block) {
	return block == Blocks.tallgrass || block == Blocks.deadbush || block == Blocks.leaves || block == Blocks.leaves2 || block == Blocks.vine || block == Blocks.red_flower || block == Blocks.yellow_flower || block == Blocks.double_plant || block == Blocks.web;
}

@Override
public boolean onBlockDestroyed(ItemStack itemStack, World world, Block block, int x, int y, int z, EntityLivingBase entity) {
	return super.onBlockDestroyed(itemStack, world, block, x, y, z, entity);
}

@Override
public boolean onBlockStartBreak(ItemStack itemStack, int x, int y, int z, EntityPlayer player) {
	World world = player.worldObj;
	Block block = world.getBlock(x, y, z);

	if(this.canHarvestBlock(block, itemStack)) {
		SoundType sound = block.stepSound;
		world.playSoundAtEntity(player, sound.getBreakSound(), sound.volume, 0.8F);

		itemStack.damageItem(1, player);

		breakBlock(world, itemStack, x - 1, y, z, player);
		breakBlock(world, itemStack, x + 1, y, z, player);
		breakBlock(world, itemStack, x - 1, y + 1, z, player);
		breakBlock(world, itemStack, x + 1, y + 1, z, player);
		breakBlock(world, itemStack, x - 1, y - 1, z, player);
		breakBlock(world, itemStack, x + 1, y - 1, z, player);

		breakBlock(world, itemStack, x, y, z - 1, player);
		breakBlock(world, itemStack, x, y, z + 1, player);
		breakBlock(world, itemStack, x, y + 1, z - 1, player);
		breakBlock(world, itemStack, x, y + 1, z + 1, player);
		breakBlock(world, itemStack, x, y - 1, z - 1, player);
		breakBlock(world, itemStack, x, y - 1, z + 1, player);

		breakBlock(world, itemStack, x + 1, y, z + 1, player);
		breakBlock(world, itemStack, x - 1, y, z - 1, player);
		breakBlock(world, itemStack, x + 1, y + 1, z + 1, player);
		breakBlock(world, itemStack, x - 1, y + 1, z - 1, player);
		breakBlock(world, itemStack, x + 1, y - 1, z + 1, player);
		breakBlock(world, itemStack, x - 1, y - 1, z - 1, player);

		breakBlock(world, itemStack, x + 1, y, z - 1, player);
		breakBlock(world, itemStack, x - 1, y, z + 1, player);
		breakBlock(world, itemStack, x + 1, y + 1, z - 1, player);
		breakBlock(world, itemStack, x - 1, y + 1, z + 1, player);
		breakBlock(world, itemStack, x + 1, y - 1, z - 1, player);
		breakBlock(world, itemStack, x - 1, y - 1, z + 1, player);

		breakBlock(world, itemStack, x, y + 1, z, player);
		breakBlock(world, itemStack, x, y - 1, z, player);

		return true;
	}
	return false;
}

private void breakBlock(World world, ItemStack itemStack, int x, int y, int z, EntityLivingBase entity) {
	Block block = world.getBlock(x, y, z);

	if(!world.isRemote && this.canHarvestBlock(block, itemStack)) {
		List<ItemStack> loot = block.getDrops(world, x, y, z, world.getBlockMetadata(x, y, z), 2 + EnchantmentHelper.getFortuneModifier(entity));

		for(ItemStack lootItem : loot) {
			EntityItem lootEntity = new EntityItem(world, x, y, z, lootItem);

			world.spawnEntityInWorld(lootEntity);
		}

		world.setBlock(x, y, z, Blocks.air);
	}
}
}

Kain

 

can you use

 

@Override

public boolean onBlockDestroyed(ItemStack itm, World wld,Block blk, int x, int y,int z, EntityLivingBase plr) {

 

to break the blocks

 

onBlockStartBreak might be client side only, and causing the problems

 

 

  • Author

That fixed it, thanks.

 

I have no clue why I overrided that method and just returned super's implementation. shocked.gif

Kain

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.