Jump to content

Hammer for my mod


Fergoman007

Recommended Posts

1. Learn Java, if you don't know it already

 

2. Do what Busti said.

 

3. Once you have the block coordinates, use World#destroyBlock(x, y, z, true/false) to destroy the block. It is called "func_147480_a" in 1.7.2, if that's the version you are using.

 

4. If you want to destroy more than one block, destroy the blocks +/- 1 each from x and z to get your 3x3 pattern, as in (x + 1, y, z), (x + 1, y, z + 1), (x - 1, y, z - 1) <-- that's one row, you need three

Link to comment
Share on other sites

@Override
    public void onBlockDestroyedByPlayer(World world, int x, int y, int z, int meta) {
        for (int ix = -1; x < 2; x++) {
            for (int iy = -1; x < 2; x++) {
                for (int iz = -1; x < 2; x++) {
                    //Do all the block break stuff...
                    world.setBlock(x+ix, y+iy, z+iz, Blocks.air); //This will just delete the blocks in a 3x3 area around the broken block but it won't drop anything.
                }
            }
        }
    }

 

EDIT: @coolAlias Oh I haven't noticed the destroyBlock method in World...

PM's regarding modding questions should belong in the Modder Support sub-forum and won't be answered.

Link to comment
Share on other sites

EDIT: @coolAlias Oh I haven't noticed the destroyBlock method in World...

Did you see my note? If you are working in 1.7.2, "destroyBlock" is called "func_147480_a".

 

The final boolean parameter determines whether the block will drop items, so if you pass true, you can destroy the blocks and get the drops, or false to just destroy the blocks. Using the destroyBlock (a.k.a func_147480_a in 1.7.2) will also automatically give you a sound and particle effects.

Link to comment
Share on other sites

Where exactly would I put the onBlockDestroyedByPlayer method

You don't, unless you are making a custom Block instead of an Item, but you're making a Hammer, right? Use what Busti suggested earlier, the onItemUse method in the Item class. The example with onBlockDestroyedByPlayer was likely just some code he had sitting around to demonstrate how to break all the blocks in a 3x3 area using "for" loops, but that's not the method you want.

Link to comment
Share on other sites

You could also use the onBlockDestroyed() method wich is called when a Block is broken by the Item and not when the Item is Used (right clicked...)

Your full code would be:

@Override
    public boolean onBlockDestroyed(ItemStack item, World world, Block destroyedBlock, int x, int y, int z, EntityLivingBase entity) {
        for (int ix = -1; x < 2; x++) {
            for (int iy = -1; x < 2; x++) {
                for (int iz = -1; x < 2; x++) {
                    world.func_147480_a(x+ix, y+iy, z+iz, true);
                }
            }
        }
        return true;
    }

 

You could also damage the ItemStack after that happens...

PM's regarding modding questions should belong in the Modder Support sub-forum and won't be answered.

Link to comment
Share on other sites

You could also use the onBlockDestroyed() method wich is called when a Block is broken by the Item and not when the Item is Used (right clicked...)

Your full code would be:

@Override
    public boolean onBlockDestroyed(ItemStack item, World world, Block destroyedBlock, int x, int y, int z, EntityLivingBase entity) {
        for (int ix = -1; x < 2; x++) {
            for (int iy = -1; x < 2; x++) {
                for (int iz = -1; x < 2; x++) {
                    world.func_147480_a(x+ix, y+iy, z+iz, true);
                }
            }
        }
        return true;
    }

 

You could also damage the ItemStack after that happens...

Oh right, derp... forgot there is also that method in Item! Lol, sorry about that. @OP just listen to Busti, he knows what's up.

Link to comment
Share on other sites

@Fergoman, instead of asking other people to write all your code for you, you'll only learn modding by trying things.  People here then will be happy to help you out.  But you need to show what you've tried.

 

If you want to make a special hammer, can you show your code so far?  Even if the hammer doesn't do the 3x3 block damage yet, show what you have and what you've tried.

 

Some of the things you'll need to do before getting to the breaking part:

- create and register your hammer item class, either as an extension of vanilla hammer or depending on how much different you want it to be an extension of a generic tool class.

- make sure it works as a regular hammer -- is it registered, breaking blocks normally, does it show up in the creative tab you want, does it have the right model and texture you want, does it have the right sounds you want?

- create and register the crafting recipe to make it.

- make sure the crafting recipe works

 

Have you done all that already?

 

Only after all the above works, should you be trying to make it do special stuff like the 3x3 destruction.  And usually, if you have all the above working, it will be pretty obvious what needs to be modified (i.e. find the method activated when you break blocks normally and then modify that) -- in this case the onBlockDestroyed() method looks promising as indicated by Busti.

 

So can you post your code you've got so far (even if it only works like vanilla hammer so far) so we can better help you?

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

Link to comment
Share on other sites

ok this is what i have tried

 

this has not worked

 

public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float px, float py, float pz)
    {
        boolean isCobble =  world.getBlock(x, y, z) == Blocks.cobblestone;
        boolean isStone = world.getBlock(x, y, z) == Blocks.stone;
        boolean isStoneBrick = world.getBlock(x, y, z) == Blocks.stonebrick;
        if(isCobble || isStone || isStoneBrick){

            for (int ix = -1; x < 2; x++) {
                for (int iy = -1; x < 2; x++) {
                    for (int iz = -1; x < 2; x++) {
                        world.func_147480_a(x + ix, y + iy, z + iz, true);
                    }
                }
            }
            return true;
        }
        else
        {
            System.out.println("[FergoTools] False");
            return false;
        }
    }

Link to comment
Share on other sites

what i meant was that it is breaking two sets of 3x3 on the x/z

 

public boolean onBlockDestroyed(ItemStack stack, World world, Block block, int x, int y, int z, EntityLivingBase elb)
    {
        // Vanilla Blocks
        boolean isCobble =  world.getBlock(x, y, z) == Blocks.cobblestone;
        boolean isStone = world.getBlock(x, y, z) == Blocks.stone;
        boolean isStoneBrick = world.getBlock(x, y, z) == Blocks.stonebrick;
        boolean isSandtone = world.getBlock(x, y, z) == Blocks.sandstone;

        boolean isOreExperience = world.getBlock(x, y, z) == ModBlocks.oreExperience;
        boolean isOreObsidian = world.getBlock(x, y, z) == ModBlocks.oreObsidian;
        boolean isOreEmeraldCrystal = world.getBlock(x, y, z) == ModBlocks.oreEmeraldCrystal;
        boolean isOreLapisCrystal = world.getBlock(x, y, z) == ModBlocks.oreLapisCrystal;
        boolean isOreBronze = world.getBlock(x, y, z) == ModBlocks.oreBronze;
        boolean isOreAdamantium = world.getBlock(x, y, z) == ModBlocks.oreAdamantium;

        boolean[] vanillaBlocks = new boolean[]{isCobble, isStone, isStoneBrick, isSandtone};
        boolean[] fergoToolsOres = new boolean[]{isOreExperience, isOreObsidian, isOreEmeraldCrystal, isOreLapisCrystal, isOreBronze, isOreAdamantium};


        if(vanillaBlocks[0] || vanillaBlocks[1] || vanillaBlocks[2] || fergoToolsOres[0] || fergoToolsOres[1] || fergoToolsOres[2] || fergoToolsOres[3] || fergoToolsOres[4] || fergoToolsOres[5] || world.getBlock(x, y, z) != Blocks.bedrock)
        {
            for(int ix = -1; ix < 2; ++ix)
            {
                for (int iy = -1; iy < 2; ++iy)
                {
                    for (int iz = -1; iz < 2; ++iz)
                    {
                        world.func_147480_a(x + ix, y + iy, z + iz, true);
                        stack.setItemDamage(stack.getItemDamage() - 9);
                    }
                }
            }

            return true;
        }
        else
        {
            return false;
        }
    }

 

Edit: added Code to Reply

Link to comment
Share on other sites

Yes, the way you have your code it will break one 3x3 layer where you strike, plus one 3x3 layer both above and below that position, but the one above you'd only notice if you hit next to a wall or something. That's caused by the 'y' for loop that I pointed out earlier.

 

One other point: you should only add/destroy blocks on the server (when the world is not remote), otherwise you can get ghost blocks - ones that either look like they exist but don't (when you add on the client), or are invisible but still block your path (when destroyed on the client).

Link to comment
Share on other sites

it played around with it a bit and still getting the the extra set of 3x3

 

Edit corrected spelling

Did you try removing the y loop like I suggested? Like this:

for(int ix = -1; ix < 2; ++ix) {
        for (int iz = -1; iz < 2; ++iz) {
                world.func_147480_a(x + ix, y, z + iz, true);
                stack.setItemDamage(stack.getItemDamage() - 9);
         }
}

Link to comment
Share on other sites

Honestly I do not understand why anyone is helping this person. He/She clearly does not know Java or doesn't know how to mod or is lazy and should figure this simple task out him/her self. The rules for the modders support also say that you should know Java to post. If you just give him/her the code he/she will learn nothing and this part of his/her mod would be your work, not theirs. I ask of everyone to please not responding to people who what other people to do all the work for them because it's a waste of time and they will get the idea that they can get other people to do work for them.

Don't be afraid to ask question when modding, there are no stupid question! Unless you don't know java then all your questions are stupid!

Link to comment
Share on other sites

Honestly I do not understand why anyone is helping this person. He/She clearly does not know Java or doesn't know how to mod or is lazy and should figure this simple task out him/her self. The rules for the modders support also say that you should know Java to post. If you just give him/her the code he/she will learn nothing and this part of his/her mod would be your work, not theirs. I ask of everyone to please not responding to people who what other people to do all the work for them because it's a waste of time and they will get the idea that they can get other people to do work for them.

I say its fine if we help him through this, as long as we don't give him code directly. He will at least learn something that way.

I like to make mods, just like you. Here's one worth checking out

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

    • Slot depo 5k merupakan situs slot depo 5k yang menyediakan slot minimal deposit 5rb atau 5k via dana yang super gacor, dimana para pemain hanya butuh modal depo sebesar 5k untuk bisa bermain di link slot gacor thailand terbaru tahun 2024 yang gampang menang ini.   DAFTAR & LOGIN AKUN PRO SLOT DEPO 5K ⭐⭐⭐ KLIK DISINI ⭐⭐⭐  
    • Slot deposit 3000 adalah situs slot deposit 3000 via dana yang super gacor dimana para pemain dijamin garansi wd hari ini juga hanya dengan modal receh berupa deposit sebesar 3000 baik via dana, ovo, gopay maupun linkaja untuk para pemain pengguna e-wallet di seluruh Indonesia.   DAFTAR & LOGIN AKUN PRO SLOT DEPOSIT 3000 ⭐⭐⭐ KLIK DISINI ⭐⭐⭐  
    • OLXTOTO: Menikmati Sensasi Bermain Togel dan Slot dengan Aman dan Mengasyikkan Dunia perjudian daring terus berkembang dengan cepat, dan salah satu situs yang telah menonjol dalam pasar adalah OLXTOTO. Sebagai platform resmi untuk permainan togel dan slot, OLXTOTO telah memenangkan kepercayaan banyak pemain dengan menyediakan pengalaman bermain yang aman, adil, dan mengasyikkan. DAFTAR OLXTOTO DISINI Keamanan Sebagai Prioritas Utama Salah satu aspek utama yang membuat OLXTOTO begitu menonjol adalah komitmennya terhadap keamanan pemain. Dengan menggunakan teknologi enkripsi terkini, situs ini memastikan bahwa semua informasi pribadi dan keuangan para pemain tetap aman dan terlindungi dari akses yang tidak sah. Beragam Permainan yang Menarik Di OLXTOTO, pemain dapat menemukan beragam permainan yang menarik untuk dinikmati. Mulai dari permainan klasik seperti togel hingga slot modern dengan fitur-fitur inovatif, ada sesuatu untuk setiap selera dan preferensi. Grafik yang memukau dan efek suara yang mengagumkan menambah keseruan setiap putaran. Peluang Menang yang Tinggi Salah satu hal yang paling menarik bagi para pemain adalah peluang menang yang tinggi yang ditawarkan oleh OLXTOTO. Dengan pembayaran yang adil dan peluang yang setara bagi semua pemain, setiap taruhan memberikan kesempatan nyata untuk memenangkan hadiah besar. Layanan Pelanggan yang Responsif Tim layanan pelanggan OLXTOTO siap membantu para pemain dengan setiap pertanyaan atau masalah yang mereka hadapi. Dengan layanan yang ramah dan responsif, pemain dapat yakin bahwa mereka akan mendapatkan bantuan yang mereka butuhkan dengan cepat dan efisien. Kesimpulan OLXTOTO telah membuktikan dirinya sebagai salah satu situs terbaik untuk penggemar togel dan slot online. Dengan fokus pada keamanan, beragam permainan yang menarik, peluang menang yang tinggi, dan layanan pelanggan yang luar biasa, tidak mengherankan bahwa situs ini telah menjadi pilihan utama bagi banyak pemain. Jadi, jika Anda mencari pengalaman bermain yang aman, adil, dan mengasyikkan, jangan ragu untuk bergabung dengan OLXTOTO hari ini dan rasakan sensasi kemenangan!
    • Slot deposit dana adalah situs slot deposit dana yang juga menerima dari e-wallet lain seperti deposit via dana, ovo, gopay & linkaja terlengkap saat ini, sehingga para pemain yang tidak memiliki rekening bank lokal bisa tetap bermain slot dan terbantu dengan adanya fitur tersebut.   DAFTAR & LOGIN AKUN PRO SLOT DEPOSIT DANA ⭐⭐⭐ KLIK DISINI ⭐⭐⭐  
    • Slot deposit dana adalah situs slot deposit dana minimal 5000 yang dijamin garansi super gacor dan gampang menang, dimana para pemain yang tidak memiliki rekening bank lokal tetap dalam bermain slot dengan melakukan deposit dana serta e-wallet lainnya seperti ovo, gopay maupun linkaja lengkap. Agar para pecinta slot di seluruh Indonesia tetap dapat menikmati permainan tanpa halangan apapun khususnya metode deposit, dimana ketersediaan cara deposit saat ini yang lebih beragam tentunya sangat membantu para pecinta slot.   DAFTAR & LOGIN AKUN PRO SLOT DEPOSIT DANA ⭐⭐⭐ KLIK DISINI ⭐⭐⭐  
×
×
  • Create New...

Important Information

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