From 15e1e8374e9fe8d0440137219954cbf7ea1e2ace Mon Sep 17 00:00:00 2001 From: haykam821 <24855774+haykam821@users.noreply.github.com> Date: Sun, 12 Mar 2023 16:11:48 -0400 Subject: [PATCH] Add rules relating to random ticks (#53) * Add the block random tick rule * Add the fluid random tick rule --- README.md | 2 ++ .../java/xyz/nucleoid/leukocyte/rule/ProtectionRule.java | 3 +++ .../leukocyte/rule/enforcer/LeukocyteRuleEnforcer.java | 8 ++++++++ 3 files changed, 13 insertions(+) diff --git a/README.md b/README.md index 9a442cb..4d55f99 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,8 @@ Leukocyte provides various rules that can be applied within authorities. These r - `coral_death` controls whether coral and coral fan blocks can die - `throw_projectiles` controls whether players can throw eggs, snowballs, or tridents - `shear_entities` controls whether entities such as sheep and mooshrooms can be sheared by players and dispensers + - `block_random_tick` controls whether random ticks will apply to blocks + - `fluid_random_tick` controls whether random ticks will apply to fluids To set a rule as `allow` or `deny` on an authority, use `/protect set rule `. diff --git a/src/main/java/xyz/nucleoid/leukocyte/rule/ProtectionRule.java b/src/main/java/xyz/nucleoid/leukocyte/rule/ProtectionRule.java index bf4479d..6889144 100644 --- a/src/main/java/xyz/nucleoid/leukocyte/rule/ProtectionRule.java +++ b/src/main/java/xyz/nucleoid/leukocyte/rule/ProtectionRule.java @@ -57,6 +57,9 @@ public final class ProtectionRule { public static final ProtectionRule EXPLOSION = register("explosion"); + public static final ProtectionRule BLOCK_RANDOM_TICK = register("block_random_tick"); + public static final ProtectionRule FLUID_RANDOM_TICK = register("fluid_random_tick"); + private final String key; ProtectionRule(String key) { diff --git a/src/main/java/xyz/nucleoid/leukocyte/rule/enforcer/LeukocyteRuleEnforcer.java b/src/main/java/xyz/nucleoid/leukocyte/rule/enforcer/LeukocyteRuleEnforcer.java index b033292..5589790 100644 --- a/src/main/java/xyz/nucleoid/leukocyte/rule/enforcer/LeukocyteRuleEnforcer.java +++ b/src/main/java/xyz/nucleoid/leukocyte/rule/enforcer/LeukocyteRuleEnforcer.java @@ -18,9 +18,11 @@ import xyz.nucleoid.stimuli.event.block.BlockBreakEvent; import xyz.nucleoid.stimuli.event.block.BlockDropItemsEvent; import xyz.nucleoid.stimuli.event.block.BlockPlaceEvent; +import xyz.nucleoid.stimuli.event.block.BlockRandomTickEvent; import xyz.nucleoid.stimuli.event.block.BlockUseEvent; import xyz.nucleoid.stimuli.event.block.CoralDeathEvent; import xyz.nucleoid.stimuli.event.block.DispenserActivateEvent; +import xyz.nucleoid.stimuli.event.block.FluidRandomTickEvent; import xyz.nucleoid.stimuli.event.entity.EntityShearEvent; import xyz.nucleoid.stimuli.event.entity.EntitySpawnEvent; import xyz.nucleoid.stimuli.event.entity.EntityUseEvent; @@ -142,6 +144,12 @@ private void applyBlockRules(ProtectionRuleMap rules, EventRegistrar events) { this.forRule(events, rules.test(ProtectionRule.EXPLOSION)) .applySimple(ExplosionDetonatedEvent.EVENT, rule -> (explosion, particles) -> explosion.clearAffectedBlocks()); + + this.forRule(events, rules.test(ProtectionRule.BLOCK_RANDOM_TICK)) + .applySimple(BlockRandomTickEvent.EVENT, rule -> (world, pos, state) -> rule); + + this.forRule(events, rules.test(ProtectionRule.FLUID_RANDOM_TICK)) + .applySimple(FluidRandomTickEvent.EVENT, rule -> (world, pos, state) -> rule); } private void applyInteractionRules(ProtectionRuleMap rules, EventRegistrar events) {