Skip to content

Commit

Permalink
feat: re-enable mob griefing after 60 ticks instead of using proximit…
Browse files Browse the repository at this point in the history
…y test

BREAKING CHANGE: In the previous implementation mob griefing would be
disabled until the player who got close to a creeper was at least 26
blocks away from any creeper. The new logic disables mob griefing for
a fixed perioud of time instead which resets every time a player gets
within 3 blocks of a creeper.
  • Loading branch information
hallettj committed May 28, 2020
1 parent 15df712 commit 26a5cfd
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 13 deletions.
7 changes: 3 additions & 4 deletions README.md
Expand Up @@ -12,10 +12,9 @@ Download the pack from the [releases][] page.

The pack works by temporarily disabling the [`mobGriefing`][mobGriefing] game
rule whenever a player gets close enough to a creeper to cause it to explode.
`mobGriefing` remains disabled until the same player is at least 26 blocks away
from any creeper to ensure that the creeper that got close either has already
exploded,
or is not going to explode before `mobGriefing` is switched back on.
`mobGriefing` remains disabled for 60 ticks,
which is the time it takes for a creeper to explode,
and then it is re-enabled.

[mobGriefing]: https://gaming.stackexchange.com/questions/308246/what-does-turning-off-mob-griefing-actually-do/308257

Expand Down
4 changes: 4 additions & 0 deletions datapack/data/minecraft/tags/functions/load.json
@@ -0,0 +1,4 @@
{
"replace": false,
"values": ["no_creeper_griefing:install"]
}
4 changes: 4 additions & 0 deletions datapack/data/minecraft/tags/functions/uninstall.json
@@ -0,0 +1,4 @@
{
"replace": false,
"values": ["no_creeper_griefing:uninstall"]
}
@@ -0,0 +1 @@
scoreboard objectives add creeperCountdown dummy
19 changes: 10 additions & 9 deletions datapack/data/no_creeper_griefing/functions/tick.mcfunction
@@ -1,11 +1,12 @@
# Tag a player if they get close enough to a creeper to cause it to explode.
execute as @a[gamemode=survival,tag=!nearCreeper] at @s if entity @e[type=minecraft:creeper,distance=..4,limit=1] run tag @s add nearCreeper
# Decrement creeperCountdown every tick while the value is greater than zero.
# This is the countdown that determines when mobGriefing will be re-enabled.
execute if score #creeperCountdown creeperCountdown matches 1.. run scoreboard players remove #creeperCountdown creeperCountdown 1

# Untag a tagged player if they are far enough from any creeper to guarantee
# that the creeper they were previously close to either has already exploded, or
# is not going to.
execute as @a[tag=nearCreeper] at @s unless entity @e[type=minecraft:creeper,distance=..25,limit=1] run tag @s remove nearCreeper
# Whenever a player is within 3 blocks of a creeper reset creeperCountdown to 60 which
# is the number of ticks it takes a creeper to explode.
execute as @a[gamemode=survival] at @s if entity @e[type=minecraft:creeper,distance=..3,limit=1] run scoreboard players set #creeperCountdown creeperCountdown 60

# Disable mobGriefing as long as there is a player with the "nearCreeper" tag.
execute if entity @a[tag=nearCreeper] run gamerule mobGriefing false
execute unless entity @a[tag=nearCreeper] run gamerule mobGriefing true
# If creeperCountdown is still counting down (the value is greater than zero)
# disable mobGriefing. Otherwise re-enable mobGriefing.
execute if score #creeperCountdown creeperCountdown matches 1.. run gamerule mobGriefing false
execute unless score #creeperCountdown creeperCountdown matches 1.. run gamerule mobGriefing true
@@ -0,0 +1,2 @@
datapack disable "file/no_creeper_griefing.zip"
scoreboard objectives remove creeperCountdown

0 comments on commit 26a5cfd

Please sign in to comment.