Jump to content

Recommended Posts

Posted

Every "Make a new tool" tutorial I can find is about making an existing tool template out of a new material. Fie on that I say, why try something simple when I can try something I can't find any information about!

 

I'm making a new tool type, a jackhammer or sledgehammer (haven't decided, currently calling it a sledgehammer), that works like an enhanced pick. When you break a block with it, it (ideally) breaks each block around that block that is of the same type.

So if you break a stone, it only breaks adjacent stone blocks, not cobblestone or sandstone or ore or dirt or sand or whatever. It takes damage for each block broken - if only one, then x1, if 6, then x6, etc. The breakage is not a chain reaction - it doesn't explode an entire ore seam or mountain at once, just a maximum of a 3x3 cube (how you'd attack the centre block while having each block around it populated I don't know.

 

I have most of the behaviour I'm looking for but I can't figure out how to break the adjacent blocks. I've been transforming them to air for testing purposes, but that's not really helpful - the blocks don't drop whatever if I do that.

 

I want to trigger regular block breakage without firing off the onBlockDestroyed() event on my tool again (because I don't want the chain reaction, eep). What method(s) am I looking for, and where are they hiding?

Posted

Every "Make a new tool" tutorial I can find is about making an existing tool template out of a new material. Fie on that I say, why try something simple when I can try something I can't find any information about!

 

I'm making a new tool type, a jackhammer or sledgehammer (haven't decided, currently calling it a sledgehammer), that works like an enhanced pick. When you break a block with it, it (ideally) breaks each block around that block that is of the same type.

So if you break a stone, it only breaks adjacent stone blocks, not cobblestone or sandstone or ore or dirt or sand or whatever. It takes damage for each block broken - if only one, then x1, if 6, then x6, etc. The breakage is not a chain reaction - it doesn't explode an entire ore seam or mountain at once, just a maximum of a 3x3 cube (how you'd attack the centre block while having each block around it populated I don't know.

 

I have most of the behaviour I'm looking for but I can't figure out how to break the adjacent blocks. I've been transforming them to air for testing purposes, but that's not really helpful - the blocks don't drop whatever if I do that.

 

I want to trigger regular block breakage without firing off the onBlockDestroyed() event on my tool again (because I don't want the chain reaction, eep). What method(s) am I looking for, and where are they hiding?

 

i think i have seen something like world.breakBlock() or world.destroy() somewhere but i can't remember where.

I would use world.setBlock() to set air and then i would use e.g.: Blocks.stone.getDrops() to spawn the items manually. But thats mostlikely not the best way to do this.

Here could be your advertisement!

Posted

i think i have seen something like world.breakBlock() or world.destroy() somewhere but i can't remember where.

I would use world.setBlock() to set air and then i would use e.g.: Blocks.stone.getDrops() to spawn the items manually. But thats mostlikely not the best way to do this.

 

I've found gameWorld_.destroyBlockInWorldPartially(actor.getEntityId(), x, y, z, damage) but I can't seem to figure out how much damage to apply to explode anything but the block hit. EDIT: Like, I tried getBlockHardness * 5000 and THAT didn't do it.

 

I'm having a poke at <block>.removedByPlayer() right now, but I can't get it to drop either, even when I set the last argument (canHarvest) to true;

Posted

Welp. I'm baffled.

 

onBlockDestroyed() is called twice every time I break a block, for reasons not obvious to me, meaning my home-rolled "drop item and destroy block" method is being called twice.

 

Weirder still, for some reason the second set of objects dropped appear to be a bit derpy - I can see them, they react to having a block plonked down in their space, but I can't pick them up and they don't save with a server restart. I suppose it's good they're noninteractive since I'm not supposed to have 2x drops, but wut?

Posted

"for reasons not obvious to me"

Break event is called twice because it's both client and server side method, so if you want to make some calculations you can always make it server side. (Every client has "client" and "server" which is virtually taking care of most things)

 

In the end client will always sync with server, unless you make some radical error.

 

EDIT: As to finding method, if you won't find it until i get back home, I will write how to make it.

 

1.7.10 is no longer supported by forge, you are on your own.

Posted

Aha! That makes sense, I really need to remember about the client/server side split, for when I see "it's being done twice !?!" again.

 

I haven't found the "proper" function so I wrote my own to serve until I get it. I can just sub in the real function call once I find it.

 

 

		private void breakBlock(World gameWorld_,
		BlockWithLocation blockXYZ) {
	// System.out.println(String.format("breakBlock() dropping at %d %d %d", blockXYZ.x, blockXYZ.y, blockXYZ.z));
        int fortune = 0; // figure out how to get my Fortune enchant level later
	ItemStack dropedItemStack = new ItemStack( blockXYZ.b.getItemDropped(0, new Random(), fortune));

	EntityItem drop = new EntityItem(gameWorld_, blockXYZ.x, blockXYZ.y, blockXYZ.z, dropedItemStack);
	gameWorld_.spawnEntityInWorld(drop);
	gameWorld_.setBlockToAir(blockXYZ.x, blockXYZ.y, blockXYZ.z);
}

 

BlockWithLocation is just a custom object that has 4 fields: a block, and an x, y, and z int.

Posted

OK, that's weirder. If I make it server side only, it never gets called at all.

 

And if I make it client side only, it STILL gets called twice and produces the "junk" ghost blocks.

 

@SideOnly(Side.SERVER)
    public boolean onBlockDestroyed(ItemStack toolInstance, World gameWorld_, Block blockStruck, int worldX, int worldY, int worldZ, EntityLivingBase actor)
    {
	System.out.println(String.format("onBlockDestroyed() nuking block at %d %d %d", worldX, worldY, worldZ));
        Deque<BlockWithLocation> blockDeck = new LinkedList<BlockWithLocation>();
        getNeighboringBlocksToDeque(gameWorld_, blockStruck, worldX, worldY,
			worldZ, blockDeck);
	System.out.println(String.format("getNeighboringBlocksToDeque(): returned deck of %d", blockDeck.size()));
        hitManyBlocks(toolInstance, gameWorld_, worldX, worldY, worldZ,
			actor, blockDeck);

        
        return true;
    }

Posted

I was simply explaining that it should be that way. There is a reason they are being called on both sides by vanilla and it should stay that way. Only real fact is that when you for e.g generate random it will be different on both sides - BUT the server side value will most likely take over - I was having fun with those some time ago and I simply said "nah, it works so better leave it".

 

And back to issue:

You want to have a tool that when it breaks block, the block broken will scan blocks around and if block == blockaround it will break too giving loot (without recurrency/chain reaction)?

 

If so - take a look at BlockEvent.class

You have two events you can use - both seem good for what you want to do.

 

How would i do it?

1. Subscribe to BreakEvent.

2. Read neat documentation with nice addnotation: Reference to the Player who broke the block.

3. If (equipeditem == sledgehammer) - BAM, launch "reaction"

4. Scan blocks around with simple +/- x/y/z scanner

5. If (blockaround == sameblock)

6. Wait... <miracles happening>

7. BOOOOOOOM!!! Stomp, crush, destroy, smash! Set(0) and drop!

8. Profit!

 

And yes... this is me in free time:

 

 

 

Hope it helped :)

 

P.S - you can probably do that all from tool side of code, but I am too lazy to look into that, unless you want me to.

Using event will cost you one "get" (itemequiped) and one "if" statement per block broken (the rest of actual code would be launched anyway), so I guess that's not worst way to do it, but there is better.

  • Like 1

1.7.10 is no longer supported by forge, you are on your own.

Posted

How many times we have to say do NOT use @$ideOnly.

Its not what it looks like.

 

So I see! Unfortunately there's a lot of tutorials floating around still using it that claim to have been "updated" for 1.7 :(

 

Use if(!world.isRemote)!

 

That indeed did the trick. Thank you sir!

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.