Jump to content

Recommended Posts

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

Posted

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

Posted

 

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

 

 

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.