-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
break rule stop players from trampling farmland & stop player-roles d…
…ependency from being transitive
- Loading branch information
Showing
4 changed files
with
33 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/main/java/xyz/nucleoid/leukocyte/mixin/rule/FarmlandBlockMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package xyz.nucleoid.leukocyte.mixin.rule; | ||
|
||
import net.minecraft.block.FarmlandBlock; | ||
import net.minecraft.entity.Entity; | ||
import net.minecraft.server.network.ServerPlayerEntity; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.world.World; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
import xyz.nucleoid.leukocyte.Leukocyte; | ||
import xyz.nucleoid.leukocyte.RuleQuery; | ||
import xyz.nucleoid.leukocyte.rule.ProtectionRule; | ||
|
||
@Mixin(FarmlandBlock.class) | ||
public class FarmlandBlockMixin { | ||
@Inject(method = "onLandedUpon", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/FarmlandBlock;setToDirt(Lnet/minecraft/block/BlockState;Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;)V", shift = At.Shift.BEFORE), cancellable = true) | ||
private void breakFarmland(World world, BlockPos pos, Entity entity, float distance, CallbackInfo ci) { | ||
if (entity instanceof ServerPlayerEntity) { | ||
Leukocyte leukocyte = Leukocyte.byWorld(world); | ||
if (leukocyte != null) { | ||
RuleQuery query = RuleQuery.forPlayerAt((ServerPlayerEntity) entity, pos); | ||
if (leukocyte.denies(query, ProtectionRule.BREAK)) { | ||
ci.cancel(); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters