Skip to content

Commit

Permalink
break rule stop players from trampling farmland & stop player-roles d…
Browse files Browse the repository at this point in the history
…ependency from being transitive
  • Loading branch information
Gegy committed Nov 29, 2020
1 parent 5acfab0 commit a72c019
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ dependencies {

modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

modImplementation "dev.gegy:player-roles:1.2.0"
modCompileOnly "dev.gegy:player-roles:1.2.0"

modRuntime("com.github.SuperCoder7979:databreaker:0.2.6") {
exclude module: "fabric-loader"
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ yarn_mappings=1.16.4+build.7
loader_version=0.10.8

# Mod Properties
mod_version=0.1.0
mod_version=0.1.1
maven_group=xyz.nucleoid
archives_base_name=leukocyte

Expand Down
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();
}
}
}
}
}
1 change: 1 addition & 0 deletions src/main/resources/leukocyte.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"mixins": [
"rule.AreaHelperMixin",
"rule.CraftingResultInventoryMixin",
"rule.FarmlandBlockMixin",
"rule.HungerManagerMixin",
"rule.PlayerEntityMixin",
"rule.ScreenHandlerMixin",
Expand Down

0 comments on commit a72c019

Please sign in to comment.