Jump to content

Recommended Posts

Posted

Override the onItemUse() method in your Item... It will give you coordinates and a world object...

Then just break the blocks around the item

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

Posted

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

Posted

@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.

Posted

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.

Posted

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.

Posted

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.

Posted

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.

Posted

@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/

Posted

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;
        }
    }

Posted

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

Posted

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).

Posted

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);
         }
}

Posted

@Fergoman

 

Your current code breaks a 3x3x3 cube of blocks, but sounds like you only want to break one vertical layer in a 3x3 area?  Like CoolAlias says, you don't need three loops in your code then, you just want to loop in the two dimensions you want the break to occur. 

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

Posted

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!

Posted

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

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

    • Im trying to build my mod using shade since i use the luaj library however i keep getting this error Reason: Task ':reobfJar' uses this output of task ':shadowJar' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. So i try adding reobfJar.dependsOn shadowJar  Could not get unknown property 'reobfJar' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler. my gradle file plugins { id 'eclipse' id 'idea' id 'maven-publish' id 'net.minecraftforge.gradle' version '[6.0,6.2)' id 'com.github.johnrengelman.shadow' version '7.1.2' id 'org.spongepowered.mixin' version '0.7.+' } apply plugin: 'net.minecraftforge.gradle' apply plugin: 'org.spongepowered.mixin' apply plugin: 'com.github.johnrengelman.shadow' version = mod_version group = mod_group_id base { archivesName = mod_id } // Mojang ships Java 17 to end users in 1.18+, so your mod should target Java 17. java.toolchain.languageVersion = JavaLanguageVersion.of(17) //jarJar.enable() println "Java: ${System.getProperty 'java.version'}, JVM: ${System.getProperty 'java.vm.version'} (${System.getProperty 'java.vendor'}), Arch: ${System.getProperty 'os.arch'}" minecraft { mappings channel: mapping_channel, version: mapping_version copyIdeResources = true runs { configureEach { workingDirectory project.file('run') property 'forge.logging.markers', 'REGISTRIES' property 'forge.logging.console.level', 'debug' arg "-mixin.config=derp.mixin.json" mods { "${mod_id}" { source sourceSets.main } } } client { // Comma-separated list of namespaces to load gametests from. Empty = all namespaces. property 'forge.enabledGameTestNamespaces', mod_id } server { property 'forge.enabledGameTestNamespaces', mod_id args '--nogui' } gameTestServer { property 'forge.enabledGameTestNamespaces', mod_id } data { workingDirectory project.file('run-data') args '--mod', mod_id, '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/') } } } sourceSets.main.resources { srcDir 'src/generated/resources' } repositories { flatDir { dirs './libs' } maven { url = "https://jitpack.io" } } configurations { shade implementation.extendsFrom shade } dependencies { minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}" implementation 'org.luaj:luaj-jse-3.0.2' implementation fg.deobf("com.github.Virtuoel:Pehkui:${pehkui_version}") annotationProcessor 'org.spongepowered:mixin:0.8.5:processor' minecraftLibrary 'luaj:luaj-jse:3.0.2' shade 'luaj:luaj-jse:3.0.2' } // Example for how to get properties into the manifest for reading at runtime. tasks.named('jar', Jar).configure { manifest { attributes([ 'Specification-Title' : mod_id, 'Specification-Vendor' : mod_authors, 'Specification-Version' : '1', // We are version 1 of ourselves 'Implementation-Title' : project.name, 'Implementation-Version' : project.jar.archiveVersion, 'Implementation-Vendor' : mod_authors, 'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), "TweakClass" : "org.spongepowered.asm.launch.MixinTweaker", "TweakOrder" : 0, "MixinConfigs" : "derp.mixin.json" ]) } rename 'mixin.refmap.json', 'derp.mixin-refmap.json' } shadowJar { archiveClassifier = '' configurations = [project.configurations.shade] finalizedBy 'reobfShadowJar' } assemble.dependsOn shadowJar reobf { re shadowJar {} } publishing { publications { mavenJava(MavenPublication) { artifact jar } } repositories { maven { url "file://${project.projectDir}/mcmodsrepo" } } }  
    • All versions of Minecraft Forge suddenly black screen even without mods (tried reinstalling original Minecraft, Java, updating drivers doesn't work)
    • When i join minecraft all ok, when i join world all working fine, but when i open indentity menu, i get this The game crashed whilst unexpected error Error: java.lang.NullPointerException: Cannot invoke "top.ribs.scguns.common.Gun$Projectile.getDamage()" because "this.projectile" is null crash report here https://paste.ee/p/0vKaf
  • Topics

×
×
  • Create New...

Important Information

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