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

    • When I first heard about Bitcoin back in 2018, I was skeptical. The idea of a decentralized, digital currency seemed too good to be true. But I was intrigued as I learned more about the technology behind it and its potential. I started small, investing just a few hundred dollars, dipping my toes into the cryptocurrency waters. At first, it was exhilarating to watch the value of my investment grow exponentially. I felt like I was part of the future, an early adopter of this revolutionary new asset. But that euphoria was short-lived. One day, I logged into my digital wallet only to find it empty - my Bitcoin had vanished without a trace. It turned out that the online exchange I had trusted had been hacked, and my funds were stolen. I was devastated, both financially and emotionally. All the potential I had seen in Bitcoin was tainted by the harsh reality that with decentralization came a lack of regulation and oversight. My hard-earned money was gone, lost to the ether of the digital world. This experience taught me a painful lesson about the price of trust in the uncharted territory of cryptocurrency. While the technology holds incredible promise, the risks can be catastrophic if you don't approach it with extreme caution. My Bitcoin investment gamble had failed, and I was left to pick up the pieces, wiser but poorer for having placed my faith in the wrong hands. My sincere appreciation goes to MUYERN TRUST HACKER. You are my hero in recovering my lost funds. Send a direct m a i l ( muyerntrusted ( @ ) mail-me ( . )c o m ) or message on whats app : + 1 ( 4-4-0 ) ( 3 -3 -5 ) ( 0-2-0-5 )
    • You could try posting a log (if there is no log at all, it may be the launcher you are using, the FAQ may have info on how to enable the log) as described in the FAQ, however this will probably need to be reported to/remedied by the mod author.
    • So me and a couple of friends are playing with a shitpost mod pack and one of the mods in the pack is corail tombstone and for some reason there is a problem with it, where on death to fire the player will get kicked out of the server and the tombstone will not spawn basically deleting an entire inventory, it doesn't matter what type of fire it is, whether it's from vanilla fire/lava, or from modded fire like ice&fire/lycanites and it's common enough to where everyone on the server has experienced at least once or twice and it doesn't give any crash log. a solution to this would be much appreciated thank you!
    • It is 1.12.2 - I have no idea if there is a 1.12 pack
  • Topics

×
×
  • Create New...

Important Information

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