Jump to content

[1.10.2]help getting BlockPos and Breaking adjacent blocks...


Recommended Posts

Posted

So, heres the code I have:

 

package tutorial;

import java.util.Set;

import com.google.common.collect.Multimap;
import com.google.common.collect.Sets;

import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.ai.attributes.AttributeModifier;
import net.minecraft.init.Blocks;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.*;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

public class MultiTool extends ItemTool {

private static final Set<Block> effectiveBlocks = Sets.newHashSet(new Block[] {Blocks.PLANKS, Blocks.BOOKSHELF, Blocks.LOG, Blocks.LOG2, Blocks.CHEST, Blocks.PUMPKIN, Blocks.LIT_PUMPKIN, Blocks.MELON_BLOCK, Blocks.LADDER, Blocks.WOODEN_BUTTON, Blocks.WOODEN_PRESSURE_PLATE, Blocks.ACTIVATOR_RAIL, Blocks.COAL_ORE, Blocks.COBBLESTONE, Blocks.DETECTOR_RAIL, Blocks.DIAMOND_BLOCK, Blocks.DIAMOND_ORE, Blocks.DOUBLE_STONE_SLAB, Blocks.GOLDEN_RAIL, Blocks.GOLD_BLOCK, Blocks.GOLD_ORE, Blocks.ICE, Blocks.IRON_BLOCK, Blocks.IRON_ORE, Blocks.LAPIS_BLOCK, Blocks.LAPIS_ORE, Blocks.LIT_REDSTONE_ORE, Blocks.MOSSY_COBBLESTONE, Blocks.NETHERRACK, Blocks.PACKED_ICE, Blocks.RAIL, Blocks.REDSTONE_ORE, Blocks.SANDSTONE, Blocks.RED_SANDSTONE, Blocks.STONE, Blocks.STONE_SLAB, Blocks.STONE_BUTTON, Blocks.STONE_PRESSURE_PLATE, Blocks.CLAY, Blocks.DIRT, Blocks.FARMLAND, Blocks.GRASS, Blocks.GRAVEL, Blocks.MYCELIUM, Blocks.SAND, Blocks.SNOW, Blocks.SNOW_LAYER, Blocks.SOUL_SAND, Blocks.GRASS_PATH});;

    protected MultiTool(ToolMaterial material)
    {
       super(10.0F, -2.8F, material, effectiveBlocks);
    }

public boolean canHarvestBlock(IBlockState blockIn){
	return true;	
}

public boolean onBlockisDestroyed(ItemStack stack, World worldIn, IBlockState state, BlockPos pos, EntityLivingBase entityLiving){
	BlockPos top = pos.up();
	BlockPos bottom = pos.down();

	worldIn.destroyBlock(top, true);
	worldIn.setBlockToAir(bottom);

	return true;
}


}

 

 

That is actually a tool that breaks every block, but I'm trying to make it break a 3x3 area. I know it may sound simple for some of you, but I just started modding yestarday, and although I have some java knowledge, I'm not the most skillfull programmer.

 

I'd really apreciate if any of you guys could give me a hint on how to do this.

(Sorry for the spelling mistakes I may have commited, English is not my main language)

Posted

The thing is, this should have replaced the bottom block and the top block with air, but it doesn't...

 

Atleast this part should've worked:

public boolean onBlockisDestroyed(ItemStack stack, World worldIn, IBlockState state, BlockPos pos, EntityLivingBase entityLiving){
	BlockPos top = pos.up();
	BlockPos bottom = pos.down();

	worldIn.destroyBlock(top, true);
	worldIn.setBlockToAir(bottom);

	return true;
}

Posted

Got it to work, thanks for the help!

 

Heres the code, if anyone needs it:

public boolean onBlockDestroyed(ItemStack stack, World worldIn, IBlockState state, BlockPos pos, EntityLivingBase entityLiving){
	BlockPos top = pos.up();
	BlockPos bottom = pos.down();

	worldIn.destroyBlock(top, true);
	worldIn.setBlockToAir(bottom);

	return true;
}

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.