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 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 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 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"));

View File

@ -334,4 +334,12 @@ public class EntityInteractEvents {
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 {
@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)) {
info.cancel();
}

View File

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

View File

@ -13,7 +13,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
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)
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))
info.cancel();
}

View File

@ -18,14 +18,14 @@ import java.util.Random;
public abstract class FireBlockMixin {
@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)) {
info.cancel();
}
}
@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)) {
info.setReturnValue(0);
info.cancel();

View File

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

View File

@ -13,7 +13,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
public abstract class ItemStackMixin {
@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);
if (result != ActionResult.PASS) {
info.setReturnValue(result);

View File

@ -20,7 +20,7 @@ public abstract class PlayerMixin {
}
@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)) {
info.cancel();
}

View File

@ -10,10 +10,10 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(RaidManager.class)
public class RaidManagerMixin {
public abstract class RaidManagerMixin {
@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)) {
info.setReturnValue(null);
info.cancel();

View File

@ -14,7 +14,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
public abstract class TurtleEggMixin {
@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)) {
info.cancel();
}

View File

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

View File

@ -20,7 +20,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
public abstract class EntityDamageMixin {
@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)) {
info.setReturnValue(false);
info.cancel();

View File

@ -13,10 +13,10 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.util.Random;
@Mixin(FireBlock.class)
public class FabricFireMixin {
public abstract class FabricFireMixin {
@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)) {
info.cancel();
}

View File

@ -12,7 +12,7 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(PistonBlock.class)
public class PistonMixin {
public abstract class PistonMixin {
@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) {

View File

@ -13,7 +13,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
public abstract class PlayerDropMixin {
@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)) {
info.setReturnValue(null);
info.cancel();

View File

@ -17,7 +17,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
public abstract class ProjectileMixin {
@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)) {
info.cancel();
}

View File

@ -23,7 +23,7 @@ public abstract class ServerPlayNetworkHandlerMixin {
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)
public void onPlayerInteractEntity(PlayerInteractEntityC2SPacket packet, CallbackInfo info) {
private void onPlayerInteractEntity(PlayerInteractEntityC2SPacket packet, CallbackInfo info) {
World world = this.player.getEntityWorld();
Entity entity = packet.getEntity(world);
if (entity != null) {

View File

@ -10,7 +10,7 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@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)
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;
@Inject(method = "mobTick", at = @At(value = "HEAD"))
public void preventClaimDmg(CallbackInfo info) {
private void preventClaimDmg(CallbackInfo info) {
if (!EntityInteractEvents.witherCanDestroy((WitherEntity) (Object) this))
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;
@Mixin(ExperienceOrbEntity.class)
public class XpEntityMixin {
public abstract class XpEntityMixin {
@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)) {
info.cancel();
}

View File

@ -14,10 +14,10 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.util.Random;
@Mixin(FireBlock.class)
public class ForgeFireMixin {
public abstract class ForgeFireMixin {
@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)) {
info.cancel();
}