9

I'm making a map and there's gonna be a lot of blasting going on and I don't want it to damage blocks.

I've done /gamerule mobGriefing false, but there's still gonna be TNT block damage.

Is there a way I can turn that off too?

pppery
  • 3,876
  • 8
  • 27
  • 47
FireStrike289
  • 1,301
  • 9
  • 21
  • 33

7 Answers7

12

So this is complicated, but not much worse than preventing a player from crafting a diamond sword. The biggest difference here is that everything must happen on the same tick, and it must happen every tick. This precludes the strategy I used in the linked answer; a 20hz fill clock is pretty much a necessity, whereas I could use a slower, simpler clock in that other answer. For this to work, you're still going to want to disable mob griefing, as I'm using ghast fireballs to create the actual explosion. It's also possible to have the effect, but cause 0 damage to players or other entities, and I'll add the commands for that at the end.

The first step is to set up a scoreboard objective to track TNT that's about to explode:

/scoreboard objectives add TNTGoBoom dummy

Next, we need to set up a fill clock. You'll need two command blocks in a column with an air block separating them. In the bottom, enter the following command:

fill ~ ~1 ~ ~3 ~1 ~ air

and in the top one, enter this command:

fill ~ ~-1 ~ ~3 ~-1 ~ redstone_block

Put a redstone block between the two, and you have your fill clock. Ideally, this won't be near a chunk boundary, but mine was and it still worked fine. Funny stuff can start happening if part of a fill clock gets unloaded from memory, but if it's a spawn chunk or you're always near the clock, you don't have to worry.

You should see three more redstone blocks out one side. You're going to put down three more command blocks adjacent to the redstone blocks (preferably above or below). In order of closest to the first two command blocks, the commands you want to use are:

scoreboard players set @e[type=PrimedTnt] TNTGoBoom 1 {Fuse:0b}
execute @e[type=PrimedTnt,score_TNTGoBoom=1] ~ ~ ~ summon Fireball ~ ~ ~ {direction:[0.0,-1.0,0.0],ExplosionPower:4,Fuse:0,Time:-1,TileEntityData:{CustomName:"TNT"},ActiveEffects:[{Id:14,Duration:10,Amplifier:10,Ambient:1}]}
kill @e[type=PrimedTnt,score_TNTGoBoom=1]

Okay, let's go over those three commands. The first sets the scoreboard value for the TNTGoBoom objective to 1 for every TNT that's ready to explode on the next tick. This is how we track the TNT. The next command summons an invisible fireball at the exact location of the TNT, moving directly downwards, and with the same explosive power of a piece of TNT. This is what will actually cause the explosion effect and damage to players/entities, but since mob griefing is turned off it won't damage the terrain. Finally, we kill (effectively delete) the TNT that's about to explode so that it doesn't damage the terrain.


Now if you want to still have the explosion effect without causing any damage, then you need to replace the fireball summon command with 2 command blocks (and therefore extend your fill clock by one more block):

execute @e[type=PrimedTnt,score_TNTGoBoom=1] ~ ~ ~ particle hugeexplosion ~ ~ ~ 0 0 0 1
execute @e[type=PrimedTnt,score_TNTGoBoom=1] ~ ~ ~ playsound random.explode @a ~ ~ ~

These two commands create the particle effect and sound of TNT exploding, but that's it. There's no damage to the world, players, or entities if you use this instead of the fireball method.


Addendum: So this is really going to mess up things like TNT cannons. I had this running in my creative world where I was previously testing an infinite TNT cannon, and while it kinda works (the projectile TNT still shoots out a bit), it has a tendency to send a fireball into the sky. Also, using this means that each TNT block needs to be lit individually, since with mob-griefing off, the fireball won't light others nearby. I'm sure there's a way around this with a little more command-block-fu. Actually, I know there's a way to do this, I'm just not 100% on the details yet.

MBraedley
  • 16,403
  • 20
  • 101
  • 149
  • I tried and that didn't work, is there something I'm missing like with the 3 commands are they meant to be in a specific order? Also are the redstone blocks meant to be flashing? – FireStrike289 Nov 15 '14 at 03:31
  • Nvm I got it. Thanx – FireStrike289 Nov 15 '14 at 04:11
  • Is there a way I can make the fireball do more damage or instead of a fireball make it a creeper because it doesn't do enough damage for it to be used as an efficient weapon – FireStrike289 Nov 15 '14 at 14:13
  • Yeah, just up the explosion power attribute. I can look into using a creeper instead, but I initially didn't have success with that. – MBraedley Nov 15 '14 at 14:16
  • Nah the explosion power is fine I just need it to do more damage. – FireStrike289 Nov 15 '14 at 14:21
  • There's this weird thing where when the TNT finishes exploding you have to wait for about 5 secs before the fireball spawns – FireStrike289 Nov 15 '14 at 14:28
  • @FireStrike289: Yeah, I'm seeing that too now. Not sure what's going on with that. – MBraedley Nov 15 '14 at 15:11
  • Is that because it's been used multiple times? Also if you find a solution please tell me. – FireStrike289 Nov 15 '14 at 15:13
  • I've updated my answer with the commands that I'm currently using, and everything seems to be working again. I don't know why I was seeing the delay before the fireball exploded, but when I was, it seemed to lag out and crash my game. – MBraedley Nov 15 '14 at 15:52
  • It's still doing it for me. If you can't come up with a solution it's better than nothing – FireStrike289 Nov 15 '14 at 16:06
  • @FireStrike289: It kinda just went away for me. I did up the allowed memory for java, but I don't think that's the culprit. I think it's more like a freaky accident that it started happening to me at all. – MBraedley Nov 15 '14 at 22:51
  • @MBraedley if you replace the command block that summons the fireball with one that summons a creeper like so: execute @e[type=PrimedTnt,score_TNTGoBoom=1] ~ ~ ~ summon Creeper ~ ~0.5 ~ {ExplosionRadius:4,Fuse:0b,Invulnerable:1,NoAI:1,ActiveEffects:[{Id:14,Amplifier‌​:0,Duration:32167,Ambient:1}]} then you will get the equivalent of a TNT explosion just without block damage when mobGriefing is set to false. Also, you will not need the two command blocks that create the particles and sound for the explosion. – 1000000000 Dec 03 '14 at 06:32
  • I tried that, but was still seeing the creeper. I think it's more distracting than my alternative. – MBraedley Dec 03 '14 at 12:14
  • Using the creeper makes TNT cannons work better though. – 1000000000 Dec 03 '14 at 12:37
  • @MBraedley even though creepers are more distracting than the fireballs, using creepers causes TNT cannons to function properly (so long as they dont depend on TNT being lit by other TNT) – 1000000000 Dec 05 '14 at 01:28
  • The execute command is missing a .0 on the third number on direction, without the .0 minecraft fails to execute the command. The correct command is: execute @e[type=PrimedTnt,score_TNTGoBoom=1] ~ ~ ~ summon Fireball ~ ~ ~ {direction:[0.0,-1.0,0.0],ExplosionPower:4,Fuse:0,Time:-1,TileEntityData:{CustomName:"TNT"},ActiveEffects:[{Id:14,Duration:10,Amplifier:10,Ambient:1}]} – Polyana Fontes Feb 24 '16 at 07:44
5

I think I have the solution you're looking for.

First, run this command to disable mob griefing:

/gamerule mobGriefing false

Then you need to create a scoreboard:

/scoreboard objectives add TntTimer dummy

TntTimer is just what I named it, you can name it anything.


Then you need to put this command in a repeating command block:

execute if entity @e[type=tnt] run scoreboard players add TntTimer TntTimer 1

This will add 1 to the Player TntTimer to the score TntTimer. The first part is the name and you can put anything in, doesn't need to be an actual player.

You will then have another repeating command block with this command:

execute at @e[type=tnt] if score TntTimer TntTimer matches 79 run summon creeper ~ ~ ~ {Invulnerable:1b,ExplosionRadius:4b,Fuse:1,ignited:1b}

This will summon a Creeper that explodes basically immediately. Also, I changed the ExplosionRadius to 4, a tnt is set to 4 but a Creeper has a default of 3.

Then next I would recommend you use a chain command block so you don't have too many 'lose' command blocks, with this command:

execute as @e[type=tnt] if score TntTimer TntTimer matches 79 run kill @s

This command will kill the tnt so it doesn't explode, this will happen basically at the same time as the Creeper explodes.

And the last command to reset the score:

execute if score TntTimer TntTimer matches 79 run scoreboard players set TntTimer TntTimer 0

This will also make it so any tnt that is fused will explode when the first one has reached 79 game ticks. So if I activated a piece of TNT and another one 2 seconds later they would explode at the same time, 4 seconds after the first one was primed.

This is where your command comes in, ether you repeat the execute if score TntTimer TntTimer matches 79 for every one of your commands before you run the last command that resets the score.

Or you could add this command, which also needs to be before the score reset:

execute if score TntTimer TntTimer matches 79 run setblock x y z redstone_block

This will then place a Redstone block next to your command blocks and activate them. This is the easier way so you don't need to test for the score for each of your commands.


This is a screenshot of my setup:

setup

Here it is in action:

animated GIF of setup

galacticninja
  • 46,036
  • 98
  • 303
  • 557
Semlan Bakelsen
  • 1,598
  • 5
  • 15
  • For anyone who had the same problem when trying to recreate this setup: the two chain command blocks have to go on top of the repeating command block that summons the creeper so it doesn't kill the TNT before the creeper spawns and also not reset the scoreboard before the creeper has been spawned. It makes sense but I didnt think about it. – CrocDog Aug 20 '21 at 18:30
  • I did show it in the image tho... :( – Semlan Bakelsen Aug 20 '21 at 19:35
  • Also if this was the answer you needed could you mark the answer with the checkmark so it gets marked as Completed. – Semlan Bakelsen Aug 20 '21 at 19:36
2

This is a theory I have had, it's a little confusing and I am still working on making it work. If you can make it so a command blocks finds the TNT ( with the test for command) and makes it so it spawns a creeper with a no explosion delay, and makes the creeper's explosion off (game rule mob griefing off). After it is spawned make it so that the entity of lit TNT is killed. In short you would lite a TNT the TNT would disappear and replace with a creeper that instantly explodes.

-1

Not in Vanilla Minecraft, no.

You would need a server plugin or a mod (preferably WorldGuard) to do this.

There is a good question here that shows how you can do this with World Guard.


Source

Chantola
  • 3,563
  • 15
  • 24
-1

Make a contraption that makes a command block go on and off and on and off and on, etc, etc. now, type /kill @e[type=PrimedTnt] in the command block. This will destroy TNT as soon as it is set. Simple.

pppery
  • 3,876
  • 8
  • 27
  • 47
Rooki_Boi
  • 29
  • 2
-1

Do not use TNT, just use an instant exploding creeper by using

/summon creeper x y z {Fuse:0}

or if you want all TNT is not damaging any block, summon a charged creeper at the location of the TNT by putting /execute @e[type=PrimedTNT] ~ ~ ~ summon creeper ~ ~ ~ {Fuse:0} in a clock, and use /kill @e[type=PrimedTNT] in a clock too.

pppery
  • 3,876
  • 8
  • 27
  • 47
-3

When a PrimedTnt is about to explode (fuse is 1 or 0) replace it with an invisible creeper. I'm not going to put the commands, but I saw a youtube video by Sethbling called "Zelda Bombs in Minecraft" which uses that mechanism, among others

  • For this to be a decent answer, at the very least link the video, or better yet include the commands used. – DBS Dec 25 '15 at 17:06