add frostwalker permission close #69

This commit is contained in:
Flemmli97 2021-06-29 18:42:59 +02:00
parent ec626d78db
commit 3874abe08c
24 changed files with 60 additions and 27 deletions

View File

@ -53,6 +53,7 @@ public class PermissionRegistry {
public static ClaimPermission TARGETBLOCK = register(new ClaimPermission("TARGETBLOCK", () -> new ItemStack(Items.TARGET), "Permission to trigger target blocks")); public static ClaimPermission TARGETBLOCK = register(new ClaimPermission("TARGETBLOCK", () -> new ItemStack(Items.TARGET), "Permission to trigger target blocks"));
public static ClaimPermission PROJECTILES = register(new ClaimPermission("PROJECTILES", () -> new ItemStack(Items.ARROW), "Permission to let shot projectiles", "interact with blocks (e.g. arrow on button)")); public static ClaimPermission PROJECTILES = register(new ClaimPermission("PROJECTILES", () -> new ItemStack(Items.ARROW), "Permission to let shot projectiles", "interact with blocks (e.g. arrow on button)"));
public static ClaimPermission TRAMPLE = register(new ClaimPermission("TRAMPLE", () -> new ItemStack(Items.FARMLAND), "Permission to enable block trampling", "(farmland, turtle eggs)")); public static ClaimPermission TRAMPLE = register(new ClaimPermission("TRAMPLE", () -> new ItemStack(Items.FARMLAND), "Permission to enable block trampling", "(farmland, turtle eggs)"));
public static ClaimPermission FROSTWALKER = register(new ClaimPermission("FROSTWALKER", () -> new ItemStack(Items.LEATHER_BOOTS), "Permission for frostwalker to activate"));
public static ClaimPermission PORTAL = register(new ClaimPermission("PORTAL", () -> new ItemStack(Items.OBSIDIAN), true, "Permission to use nether portals")); public static ClaimPermission PORTAL = register(new ClaimPermission("PORTAL", () -> new ItemStack(Items.OBSIDIAN), true, "Permission to use nether portals"));
public static ClaimPermission RAID = register(new ClaimPermission("RAID", Raid::getOminousBanner, "Permission to trigger raids in claim.", "Wont prevent raids (just) outside")); public static ClaimPermission RAID = register(new ClaimPermission("RAID", Raid::getOminousBanner, "Permission to trigger raids in claim.", "Wont prevent raids (just) outside"));
public static ClaimPermission BOAT = register(new ClaimPermission("BOAT", () -> new ItemStack(Items.OAK_BOAT), "Permission to sit in boats")); public static ClaimPermission BOAT = register(new ClaimPermission("BOAT", () -> new ItemStack(Items.OAK_BOAT), "Permission to sit in boats"));

View File

@ -334,4 +334,12 @@ public class EntityInteractEvents {
cons.accept(claim); cons.accept(claim);
} }
} }
public static boolean canFrostwalkerFreeze(ServerWorld world, BlockPos pos, LivingEntity entity) {
if (entity instanceof ServerPlayerEntity) {
IPermissionContainer claim = ClaimStorage.get(world).getForPermissionCheck(pos);
return claim.canInteract((ServerPlayerEntity) entity, PermissionRegistry.FROSTWALKER, pos, false);
}
return true;
}
} }

View File

@ -16,7 +16,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
public abstract class AbstractBlockStateMixin { public abstract class AbstractBlockStateMixin {
@Inject(method = "onEntityCollision", at = @At(value = "HEAD"), cancellable = true) @Inject(method = "onEntityCollision", at = @At(value = "HEAD"), cancellable = true)
public void collision(World world, BlockPos pos, Entity entity, CallbackInfo info) { private void collision(World world, BlockPos pos, Entity entity, CallbackInfo info) {
if (BlockInteractEvents.cancelEntityBlockCollision(this.asBlockState(), world, pos, entity)) { if (BlockInteractEvents.cancelEntityBlockCollision(this.asBlockState(), world, pos, entity)) {
info.cancel(); info.cancel();
} }

View File

@ -12,7 +12,7 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(targets = "net/minecraft/entity/mob/EndermanEntity$PlaceBlockGoal") @Mixin(targets = "net/minecraft/entity/mob/EndermanEntity$PlaceBlockGoal")
public class EndermanPlaceMixin { public abstract class EndermanPlaceMixin {
@Shadow @Shadow
private EndermanEntity enderman; private EndermanEntity enderman;

View File

@ -13,7 +13,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
public abstract class EntityMixin { public abstract class EntityMixin {
@Inject(method = "fall", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/Block;onLandedUpon(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/entity/Entity;F)V"), cancellable = true) @Inject(method = "fall", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/Block;onLandedUpon(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/entity/Entity;F)V"), cancellable = true)
public void fallOnBlock(double heightDifference, boolean onGround, BlockState landedState, BlockPos landedPosition, CallbackInfo info) { private void fallOnBlock(double heightDifference, boolean onGround, BlockState landedState, BlockPos landedPosition, CallbackInfo info) {
if (BlockInteractEvents.preventFallOn((Entity) (Object) this, heightDifference, onGround, landedState, landedPosition)) if (BlockInteractEvents.preventFallOn((Entity) (Object) this, heightDifference, onGround, landedState, landedPosition))
info.cancel(); info.cancel();
} }

View File

@ -18,14 +18,14 @@ import java.util.Random;
public abstract class FireBlockMixin { public abstract class FireBlockMixin {
@Inject(method = "scheduledTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ServerWorld;getGameRules()Lnet/minecraft/world/GameRules;"), cancellable = true) @Inject(method = "scheduledTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ServerWorld;getGameRules()Lnet/minecraft/world/GameRules;"), cancellable = true)
public void tick(BlockState state, ServerWorld world, BlockPos pos, Random random, CallbackInfo info) { private void tick(BlockState state, ServerWorld world, BlockPos pos, Random random, CallbackInfo info) {
if (!WorldEvents.canFireSpread(world, pos)) { if (!WorldEvents.canFireSpread(world, pos)) {
info.cancel(); info.cancel();
} }
} }
@Inject(method = "getBurnChance(Lnet/minecraft/world/WorldView;Lnet/minecraft/util/math/BlockPos;)I", at = @At(value = "HEAD"), cancellable = true) @Inject(method = "getBurnChance(Lnet/minecraft/world/WorldView;Lnet/minecraft/util/math/BlockPos;)I", at = @At(value = "HEAD"), cancellable = true)
public void burn(WorldView worldView, BlockPos pos, CallbackInfoReturnable<Integer> info) { private void burn(WorldView worldView, BlockPos pos, CallbackInfoReturnable<Integer> info) {
if (worldView instanceof ServerWorld && !WorldEvents.canFireSpread((ServerWorld) worldView, pos)) { if (worldView instanceof ServerWorld && !WorldEvents.canFireSpread((ServerWorld) worldView, pos)) {
info.setReturnValue(0); info.setReturnValue(0);
info.cancel(); info.cancel();

View File

@ -17,8 +17,8 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
public abstract class FluidMixin { public abstract class FluidMixin {
@Inject(method = "canFlow", at = @At(value = "HEAD"), cancellable = true) @Inject(method = "canFlow", at = @At(value = "HEAD"), cancellable = true)
public void crossClaimFlow(BlockView world, BlockPos fluidPos, BlockState fluidBlockState, Direction flowDirection, BlockPos flowTo, private void crossClaimFlow(BlockView world, BlockPos fluidPos, BlockState fluidBlockState, Direction flowDirection, BlockPos flowTo,
BlockState flowToBlockState, FluidState fluidState, Fluid fluid, CallbackInfoReturnable<Boolean> info) { BlockState flowToBlockState, FluidState fluidState, Fluid fluid, CallbackInfoReturnable<Boolean> info) {
if (!WorldEvents.canFlow(fluidBlockState, world, fluidPos, flowDirection)) { if (!WorldEvents.canFlow(fluidBlockState, world, fluidPos, flowDirection)) {
info.setReturnValue(false); info.setReturnValue(false);
info.cancel(); info.cancel();

View File

@ -0,0 +1,23 @@
package io.github.flemmli97.flan.mixin;
import io.github.flemmli97.flan.event.EntityInteractEvents;
import net.minecraft.block.BlockState;
import net.minecraft.enchantment.FrostWalkerEnchantment;
import net.minecraft.entity.LivingEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.WorldView;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(FrostWalkerEnchantment.class)
public abstract class FrostWalkerMixin {
@Redirect(method = "freezeWater", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/BlockState;canPlaceAt(Lnet/minecraft/world/WorldView;Lnet/minecraft/util/math/BlockPos;)Z"))
private static boolean freeze(BlockState state, WorldView world, BlockPos pos, LivingEntity entity) {
if (world instanceof ServerWorld && !EntityInteractEvents.canFrostwalkerFreeze((ServerWorld) world, pos, entity))
return false;
return state.canPlaceAt(world, pos);
}
}

View File

@ -13,7 +13,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.util.UUID; import java.util.UUID;
@Mixin(ItemEntity.class) @Mixin(ItemEntity.class)
public class ItemEntityMixin implements IOwnedItem { public abstract class ItemEntityMixin implements IOwnedItem {
@Unique @Unique
private UUID playerOrigin; private UUID playerOrigin;

View File

@ -13,7 +13,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
public abstract class ItemStackMixin { public abstract class ItemStackMixin {
@Inject(method = "useOnBlock", at = @At(value = "HEAD"), cancellable = true) @Inject(method = "useOnBlock", at = @At(value = "HEAD"), cancellable = true)
public void blockUse(ItemUsageContext context, CallbackInfoReturnable<ActionResult> info) { private void blockUse(ItemUsageContext context, CallbackInfoReturnable<ActionResult> info) {
ActionResult result = ItemInteractEvents.onItemUseBlock(context); ActionResult result = ItemInteractEvents.onItemUseBlock(context);
if (result != ActionResult.PASS) { if (result != ActionResult.PASS) {
info.setReturnValue(result); info.setReturnValue(result);

View File

@ -20,7 +20,7 @@ public abstract class PlayerMixin {
} }
@Inject(method = "collideWithEntity", at = @At(value = "HEAD"), cancellable = true) @Inject(method = "collideWithEntity", at = @At(value = "HEAD"), cancellable = true)
public void entityCollide(Entity entity, CallbackInfo info) { private void entityCollide(Entity entity, CallbackInfo info) {
if (!EntityInteractEvents.canCollideWith((PlayerEntity) (Object) this, entity)) { if (!EntityInteractEvents.canCollideWith((PlayerEntity) (Object) this, entity)) {
info.cancel(); info.cancel();
} }

View File

@ -10,10 +10,10 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(RaidManager.class) @Mixin(RaidManager.class)
public class RaidManagerMixin { public abstract class RaidManagerMixin {
@Inject(method = "startRaid", at = @At(value = "HEAD"), cancellable = true) @Inject(method = "startRaid", at = @At(value = "HEAD"), cancellable = true)
public void checkRaid(ServerPlayerEntity player, CallbackInfoReturnable<Raid> info) { private void checkRaid(ServerPlayerEntity player, CallbackInfoReturnable<Raid> info) {
if (!WorldEvents.canStartRaid(player)) { if (!WorldEvents.canStartRaid(player)) {
info.setReturnValue(null); info.setReturnValue(null);
info.cancel(); info.cancel();

View File

@ -14,7 +14,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
public abstract class TurtleEggMixin { public abstract class TurtleEggMixin {
@Inject(method = "onSteppedOn", at = @At(value = "HEAD"), cancellable = true) @Inject(method = "onSteppedOn", at = @At(value = "HEAD"), cancellable = true)
public void collision(World world, BlockPos pos, Entity entity, CallbackInfo info) { private void collision(World world, BlockPos pos, Entity entity, CallbackInfo info) {
if (BlockInteractEvents.canBreakTurtleEgg(world, pos, entity)) { if (BlockInteractEvents.canBreakTurtleEgg(world, pos, entity)) {
info.cancel(); info.cancel();
} }

View File

@ -20,7 +20,8 @@
"EndermanPickupMixin", "EndermanPickupMixin",
"EndermanPlaceMixin", "EndermanPlaceMixin",
"IItemAccessor", "IItemAccessor",
"IHungerAccessor" "IHungerAccessor",
"FrostWalkerMixin"
], ],
"server": [ "server": [
], ],

View File

@ -20,7 +20,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
public abstract class EntityDamageMixin { public abstract class EntityDamageMixin {
@Inject(method = "damage", at = @At(value = "HEAD"), cancellable = true) @Inject(method = "damage", at = @At(value = "HEAD"), cancellable = true)
public void onDamage(DamageSource source, float amount, CallbackInfoReturnable<Boolean> info) { private void onDamage(DamageSource source, float amount, CallbackInfoReturnable<Boolean> info) {
if (EntityInteractEvents.preventDamage((Entity) (Object) this, source)) { if (EntityInteractEvents.preventDamage((Entity) (Object) this, source)) {
info.setReturnValue(false); info.setReturnValue(false);
info.cancel(); info.cancel();

View File

@ -13,10 +13,10 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.util.Random; import java.util.Random;
@Mixin(FireBlock.class) @Mixin(FireBlock.class)
public class FabricFireMixin { public abstract class FabricFireMixin {
@Inject(method = "trySpreadingFire", at = @At(value = "HEAD"), cancellable = true) @Inject(method = "trySpreadingFire", at = @At(value = "HEAD"), cancellable = true)
public void spread(World world, BlockPos pos, int spreadFactor, Random rand, int currentAge, CallbackInfo info) { private void spread(World world, BlockPos pos, int spreadFactor, Random rand, int currentAge, CallbackInfo info) {
if (!world.isClient && !WorldEvents.canFireSpread((ServerWorld) world, pos)) { if (!world.isClient && !WorldEvents.canFireSpread((ServerWorld) world, pos)) {
info.cancel(); info.cancel();
} }

View File

@ -12,7 +12,7 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(PistonBlock.class) @Mixin(PistonBlock.class)
public class PistonMixin { public abstract class PistonMixin {
@Inject(method = "isMovable", at = @At(value = "HEAD"), cancellable = true) @Inject(method = "isMovable", at = @At(value = "HEAD"), cancellable = true)
private static void checkMovable(BlockState blockState, World world, BlockPos blockPos, Direction direction, boolean canBreak, Direction pistonDir, CallbackInfoReturnable<Boolean> info) { private static void checkMovable(BlockState blockState, World world, BlockPos blockPos, Direction direction, boolean canBreak, Direction pistonDir, CallbackInfoReturnable<Boolean> info) {

View File

@ -13,7 +13,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
public abstract class PlayerDropMixin { public abstract class PlayerDropMixin {
@Inject(method = "dropItem(Lnet/minecraft/item/ItemStack;ZZ)Lnet/minecraft/entity/ItemEntity;", at = @At(value = "HEAD"), cancellable = true) @Inject(method = "dropItem(Lnet/minecraft/item/ItemStack;ZZ)Lnet/minecraft/entity/ItemEntity;", at = @At(value = "HEAD"), cancellable = true)
public void drop(ItemStack stack, boolean throwRandomly, boolean retainOwnership, CallbackInfoReturnable<ItemEntity> info) { private void drop(ItemStack stack, boolean throwRandomly, boolean retainOwnership, CallbackInfoReturnable<ItemEntity> info) {
if (!EntityInteractEvents.canDropItem((PlayerEntity) (Object) this, stack)) { if (!EntityInteractEvents.canDropItem((PlayerEntity) (Object) this, stack)) {
info.setReturnValue(null); info.setReturnValue(null);
info.cancel(); info.cancel();

View File

@ -17,7 +17,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
public abstract class ProjectileMixin { public abstract class ProjectileMixin {
@Inject(method = "onCollision", at = @At(value = "HEAD"), cancellable = true) @Inject(method = "onCollision", at = @At(value = "HEAD"), cancellable = true)
public void collision(HitResult hitResult, CallbackInfo info) { private void collision(HitResult hitResult, CallbackInfo info) {
if (EntityInteractEvents.projectileHit((ProjectileEntity) (Object) this, hitResult)) { if (EntityInteractEvents.projectileHit((ProjectileEntity) (Object) this, hitResult)) {
info.cancel(); info.cancel();
} }

View File

@ -23,7 +23,7 @@ public abstract class ServerPlayNetworkHandlerMixin {
private ServerPlayerEntity player; private ServerPlayerEntity player;
@Inject(method = "onPlayerInteractEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayerEntity;interact(Lnet/minecraft/entity/Entity;Lnet/minecraft/util/Hand;)Lnet/minecraft/util/ActionResult;"), cancellable = true) @Inject(method = "onPlayerInteractEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayerEntity;interact(Lnet/minecraft/entity/Entity;Lnet/minecraft/util/Hand;)Lnet/minecraft/util/ActionResult;"), cancellable = true)
public void onPlayerInteractEntity(PlayerInteractEntityC2SPacket packet, CallbackInfo info) { private void onPlayerInteractEntity(PlayerInteractEntityC2SPacket packet, CallbackInfo info) {
World world = this.player.getEntityWorld(); World world = this.player.getEntityWorld();
Entity entity = packet.getEntity(world); Entity entity = packet.getEntity(world);
if (entity != null) { if (entity != null) {

View File

@ -10,7 +10,7 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(SpawnHelper.class) @Mixin(SpawnHelper.class)
public class SpawnHelperMixin { public abstract class SpawnHelperMixin {
@Inject(method = "isValidSpawn", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/mob/MobEntity;canSpawn(Lnet/minecraft/world/WorldAccess;Lnet/minecraft/entity/SpawnReason;)Z"), cancellable = true) @Inject(method = "isValidSpawn", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/mob/MobEntity;canSpawn(Lnet/minecraft/world/WorldAccess;Lnet/minecraft/entity/SpawnReason;)Z"), cancellable = true)
private static void isValidSpawn(ServerWorld world, MobEntity entity, double squaredDistance, CallbackInfoReturnable<Boolean> info) { private static void isValidSpawn(ServerWorld world, MobEntity entity, double squaredDistance, CallbackInfoReturnable<Boolean> info) {

View File

@ -15,7 +15,7 @@ public abstract class WitherMixin {
private int field_7082; private int field_7082;
@Inject(method = "mobTick", at = @At(value = "HEAD")) @Inject(method = "mobTick", at = @At(value = "HEAD"))
public void preventClaimDmg(CallbackInfo info) { private void preventClaimDmg(CallbackInfo info) {
if (!EntityInteractEvents.witherCanDestroy((WitherEntity) (Object) this)) if (!EntityInteractEvents.witherCanDestroy((WitherEntity) (Object) this))
this.field_7082 = -1; this.field_7082 = -1;
} }

View File

@ -9,10 +9,10 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(ExperienceOrbEntity.class) @Mixin(ExperienceOrbEntity.class)
public class XpEntityMixin { public abstract class XpEntityMixin {
@Inject(method = "onPlayerCollision", at = @At(value = "HEAD"), cancellable = true) @Inject(method = "onPlayerCollision", at = @At(value = "HEAD"), cancellable = true)
public void collision(PlayerEntity player, CallbackInfo info) { private void collision(PlayerEntity player, CallbackInfo info) {
if (EntityInteractEvents.xpAbsorb(player)) { if (EntityInteractEvents.xpAbsorb(player)) {
info.cancel(); info.cancel();
} }

View File

@ -14,10 +14,10 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.util.Random; import java.util.Random;
@Mixin(FireBlock.class) @Mixin(FireBlock.class)
public class ForgeFireMixin { public abstract class ForgeFireMixin {
@Inject(method = "tryCatchFire", at = @At(value = "HEAD"), cancellable = true) @Inject(method = "tryCatchFire", at = @At(value = "HEAD"), cancellable = true)
public void spread(World world, BlockPos pos, int spreadFactor, Random rand, int currentAge, Direction dir, CallbackInfo info) { private void spread(World world, BlockPos pos, int spreadFactor, Random rand, int currentAge, Direction dir, CallbackInfo info) {
if (!world.isClient && !WorldEvents.canFireSpread((ServerWorld) world, pos)) { if (!world.isClient && !WorldEvents.canFireSpread((ServerWorld) world, pos)) {
info.cancel(); info.cancel();
} }