Jump to content

Special Ability Tools


kenoba10

Recommended Posts

Hi. I'm working on making a mod and in it I want there to be tools with really cool abilitys:

 

  • Sword that shoots fireballs
    Pickaxe with auto smelting
    Axe with a feature similar to TreeCapacitator

 

The only one I have any idea to go about making is the sword a bit but I still vould use some help

 

Any help please?

Link to comment
Share on other sites

  • Replies 73
  • Created
  • Last Reply

Top Posters In This Topic

For pickaxe you'll want to change the way it handles blocks being harvested/destroyed. It should be handled to check whether the item being dropped has a smelting recipe, and if it does, it should drop that instead of the normal drop (look at FurnaceRecipes.java).

 

For axe just check all above blocks and see if they are also wood/logs, etc, and have them affected as well.

Link to comment
Share on other sites

For pickaxe you'll want to change the way it handles blocks being harvested/destroyed. It should be handled to check whether the item being dropped has a smelting recipe, and if it does, it should drop that instead of the normal drop (look at FurnaceRecipes.java).

 

For axe just check all above blocks and see if they are also wood/logs, etc, and have them affected as well.

Is is possible you could send me a code example?

Link to comment
Share on other sites

What did you come up with?

I found a  tutorial about making your own mod block so it destorys all other blocks of the same block around it which you put in the block class, but how could i do this for a pre existing block and only putting it in my pickaxe class without editing base classes

Link to comment
Share on other sites

Whoops, this is what I meant:

 

@Override
public boolean onBlockDestroyed(ItemStack stack, World world, int id, int i, int j, int k, EntityLivingBase entity)
{
        //code
return true;
}

Oh I see would I override this method in my axe class and then put the code for breaking the wood in this method?

 

Link to comment
Share on other sites

You got it.

Ok is there anyway i could alter this code to work inside the method?

  @Override
        public void breakBlock(World world, int i, int j, int k, int par5, int par6){
                //Reading the gag's tile entity.
                TileEntityGag tileEntity = (TileEntityGag)world.getBlockTileEntity(i, j, k);
                //If not make this check, the game may crash if there's no tile entity at i, j, k.
                if (tileEntity != null){
                        //Actually destroys primary block.
                        world.destroyBlock(tileEntity.primary_x, tileEntity.primary_y, tileEntity.primary_z, false);
                        //Forces removing tile entity from primary block coordinates,
                        //cause sometimes minecraft forgets to do that.
                        world.removeBlockTileEntity(tileEntity.primary_x, tileEntity.primary_y, tileEntity.primary_z);
                }
                //Same as above, but for the gag block tile entity.
                world.removeBlockTileEntity(i, j, k);
        }
        //This method checks if primary block exists. 
        @Override
        public void onNeighborBlockChange(World world, int i, int j, int k, int par5){
                TileEntityGag tileEntity = (TileEntityGag)world.getBlockTileEntity(i, j, k);
                if (tileEntity != null){
                        //No need to check if block's Id matches the Id of our primary block, 
                        //because if a player want to change a block, he needs to brake it first, 
                        //and in this case block will be set to Air (Id = 0)
                        if(world.getBlockId(tileEntity.primary_x, tileEntity.primary_y, 
                                        tileEntity.primary_z) < 1){
                                world.destroyBlock(i, j, k, false);
                                world.removeBlockTileEntity(i, j, k);
                        }
                }
        }

Link to comment
Share on other sites

You're trying to make an axe that destroys an entire tree, correct? I don't see how your code there with the TileEntity actually correlates to that concept, so I don't know what it does, let alone how it would be possible to put on an item.

Link to comment
Share on other sites

You're trying to make an axe that destroys an entire tree, correct? I don't see how your code there with the TileEntity actually correlates to that concept, so I don't know what it does, let alone how it would be possible to put on an item.

oh ok do you have any idea how i could destory the tree then?

Link to comment
Share on other sites

It'd be easiest to check an area, perhaps a 3x15x3 region to check if the blocks are logs, and then make them drop a log at that position (for-loops).

Ok I've never actually done anything with deleting blocks and checking areas I'll look some stuff up unless you can help me in any way

Link to comment
Share on other sites

Nested for-loops, one for each x, y, and z range. Use -1 to <= 1 as each range for x and z, and 0 to <= 15 for y. Then check if(world.getBlockId(par4 + x, par5 + y, par6 + z) == Block.log.blockID), and then get the metadata, create a new ItemStack of Block, set the block to 0 and then spawn an EntityItem at par4 + x, par5 + y, par6 + z.

Link to comment
Share on other sites

Nested for-loops, one for each x, y, and z range. Use -1 to <= 1 as each range for x and z, and 0 to <= 15 for y. Then check if(world.getBlockId(par4 + x, par5 + y, par6 + z) == Block.log.blockID), and then get the metadata, create a new ItemStack of Block, set the block to 0 and then spawn an EntityItem at par4 + x, par5 + y, par6 + z.

Ok well it would be nice if it was a bit simpler i cant really understand it exactly

Link to comment
Share on other sites

if(world.getBlockId(i, j, k) == Block.wood.blockID)
	{
		for(int x = -1; x <= 1; x++)
		{
			for(int y = 0; y <= 15; y++)
			{
				for(int z = -1; z <= 1; z++)
				{
					if(world.getBlockId(i + x, j + y, k + z) == Block.wood.blockID)
					{
						int meta = world.getBlockMetadata(i + x, j + y, k + z);
						ItemStack drop = new ItemStack(Block.wood, 1, meta);
						EntityItem item = new EntityItem(world, i + x, j + y, k + z, drop);
						world.setBlock(i + x, j + y, k + z, 0);
						world.spawnEntityInWorld(item);
					}
				}
			}
		}
	}

Link to comment
Share on other sites

if(world.getBlockId(i, j, k) == Block.wood.blockID)
	{
		for(int x = -1; x <= 1; x++)
		{
			for(int y = 0; y <= 15; y++)
			{
				for(int z = -1; z <= 1; z++)
				{
					if(world.getBlockId(i + x, j + y, k + z) == Block.wood.blockID)
					{
						int meta = world.getBlockMetadata(i + x, j + y, k + z);
						ItemStack drop = new ItemStack(Block.wood, 1, meta);
						EntityItem item = new EntityItem(world, i + x, j + y, k + z, drop);
						world.setBlock(i + x, j + y, k + z, 0);
						world.spawnEntityInWorld(item);
					}
				}
			}
		}
	}

Thanks so much for the help!

Link to comment
Share on other sites

Nested for-loops, one for each x, y, and z range. Use -1 to <= 1 as each range for x and z, and 0 to <= 15 for y. Then check if(world.getBlockId(par4 + x, par5 + y, par6 + z) == Block.log.blockID), and then get the metadata, create a new ItemStack of Block, set the block to 0 and then spawn an EntityItem at par4 + x, par5 + y, par6 + z.

Ok for the auto smelting pickaxe what would i override in my pickaxe class?

Link to comment
Share on other sites

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




  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • They were already updated, and just to double check I even did a cleanup and fresh update from that same page. I'm quite sure drivers are not the problem here. 
    • i tried downloading the drivers but it says no AMD graphics hardware has been detected    
    • Update your AMD/ATI drivers - get the drivers from their website - do not update via system  
    • As the title says i keep on crashing on forge 1.20.1 even without any mods downloaded, i have the latest drivers (nvidia) and vanilla minecraft works perfectly fine for me logs: https://pastebin.com/5UR01yG9
    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
  • Topics

×
×
  • Create New...

Important Information

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