flan/common/src/main/java/io/github/flemmli97/flan/event/EntityInteractEvents.java

396 lines
21 KiB
Java
Raw Normal View History

package io.github.flemmli97.flan.event;
2020-08-23 12:52:36 +00:00
import io.github.flemmli97.flan.api.data.IPermissionContainer;
import io.github.flemmli97.flan.api.permission.ClaimPermission;
import io.github.flemmli97.flan.api.permission.ObjectToPermissionMap;
import io.github.flemmli97.flan.api.permission.PermissionRegistry;
import io.github.flemmli97.flan.claim.Claim;
import io.github.flemmli97.flan.claim.ClaimStorage;
2021-06-09 10:49:19 +00:00
import io.github.flemmli97.flan.config.ConfigHandler;
2021-06-12 22:21:31 +00:00
import io.github.flemmli97.flan.mixin.IHungerAccessor;
import io.github.flemmli97.flan.mixin.IPersistentProjectileVars;
import io.github.flemmli97.flan.platform.CrossPlatformStuff;
import io.github.flemmli97.flan.player.IOwnedItem;
2021-06-09 10:49:19 +00:00
import io.github.flemmli97.flan.player.PlayerClaimData;
import io.github.flemmli97.flan.player.TeleportUtils;
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
2021-12-03 21:37:35 +00:00
import net.minecraft.core.BlockPos;
import net.minecraft.core.NonNullList;
import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket;
import net.minecraft.network.protocol.game.ClientboundPlayerAbilitiesPacket;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundEvents;
2023-05-06 13:58:42 +00:00
import net.minecraft.tags.DamageTypeTags;
2021-12-03 21:37:35 +00:00
import net.minecraft.util.Mth;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.Mob;
2022-01-12 12:15:44 +00:00
import net.minecraft.world.entity.OwnableEntity;
2021-12-03 21:37:35 +00:00
import net.minecraft.world.entity.animal.SnowGolem;
import net.minecraft.world.entity.boss.wither.WitherBoss;
import net.minecraft.world.entity.decoration.ArmorStand;
import net.minecraft.world.entity.decoration.ItemFrame;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.monster.EnderMan;
import net.minecraft.world.entity.monster.Enemy;
import net.minecraft.world.entity.npc.Villager;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.projectile.AbstractArrow;
import net.minecraft.world.entity.projectile.Projectile;
import net.minecraft.world.entity.projectile.ThrownEgg;
import net.minecraft.world.entity.projectile.ThrownEnderpearl;
import net.minecraft.world.entity.projectile.ThrownPotion;
import net.minecraft.world.entity.vehicle.AbstractMinecart;
import net.minecraft.world.entity.vehicle.AbstractMinecartContainer;
import net.minecraft.world.entity.vehicle.Boat;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.EntityHitResult;
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.Vec3;
2021-05-12 11:29:29 +00:00
import java.util.function.Consumer;
2020-08-23 12:52:36 +00:00
public class EntityInteractEvents {
2021-12-03 21:37:35 +00:00
public static InteractionResult attackEntity(Player player, Level world, InteractionHand hand, Entity entity, EntityHitResult hitResult) {
return attackSimple(player, entity, true);
2020-08-23 12:52:36 +00:00
}
2021-12-03 21:37:35 +00:00
public static InteractionResult useAtEntity(Player player, Level world, InteractionHand hand, Entity entity, /* Nullable */ EntityHitResult hitResult) {
if (!(player instanceof ServerPlayer) || player.isSpectator() || canInteract(entity))
2021-12-03 21:37:35 +00:00
return InteractionResult.PASS;
if (entity instanceof Enemy)
return InteractionResult.PASS;
2021-12-03 21:37:35 +00:00
ClaimStorage storage = ClaimStorage.get((ServerLevel) world);
BlockPos pos = entity.blockPosition();
2020-10-30 14:09:57 +00:00
IPermissionContainer claim = storage.getForPermissionCheck(pos);
2020-08-23 12:52:36 +00:00
if (claim != null) {
2021-12-03 21:37:35 +00:00
if (entity instanceof ArmorStand) {
if (!claim.canInteract((ServerPlayer) player, PermissionRegistry.ARMORSTAND, pos, true))
return InteractionResult.FAIL;
2020-08-23 12:52:36 +00:00
}
if (entity instanceof Mob)
return claim.canInteract((ServerPlayer) player, PermissionRegistry.ANIMALINTERACT, pos, true) ? InteractionResult.PASS : InteractionResult.FAIL;
2020-08-23 12:52:36 +00:00
}
2021-12-03 21:37:35 +00:00
return InteractionResult.PASS;
2020-08-23 12:52:36 +00:00
}
2021-12-03 21:37:35 +00:00
public static InteractionResult useEntity(Player p, Level world, InteractionHand hand, Entity entity) {
if (!(p instanceof ServerPlayer player) || p.isSpectator() || canInteract(entity))
2021-12-03 21:37:35 +00:00
return InteractionResult.PASS;
if (entity instanceof Enemy)
return InteractionResult.PASS;
2021-12-03 21:37:35 +00:00
ClaimStorage storage = ClaimStorage.get((ServerLevel) world);
BlockPos pos = entity.blockPosition();
2020-10-30 14:09:57 +00:00
IPermissionContainer claim = storage.getForPermissionCheck(pos);
2020-08-23 12:52:36 +00:00
if (claim != null) {
2021-12-03 21:37:35 +00:00
if (entity instanceof Boat)
return claim.canInteract(player, PermissionRegistry.BOAT, pos, true) ? InteractionResult.PASS : InteractionResult.FAIL;
if (entity instanceof AbstractMinecart) {
if (entity instanceof AbstractMinecartContainer)
return claim.canInteract(player, PermissionRegistry.OPENCONTAINER, pos, true) ? InteractionResult.PASS : InteractionResult.FAIL;
return claim.canInteract(player, PermissionRegistry.MINECART, pos, true) ? InteractionResult.PASS : InteractionResult.FAIL;
2020-08-23 12:52:36 +00:00
}
2021-12-03 21:37:35 +00:00
if (entity instanceof Villager)
return claim.canInteract(player, PermissionRegistry.TRADING, pos, true) ? InteractionResult.PASS : InteractionResult.FAIL;
if (entity instanceof ItemFrame)
return claim.canInteract(player, PermissionRegistry.ITEMFRAMEROTATE, pos, true) ? InteractionResult.PASS : InteractionResult.FAIL;
2022-01-12 12:15:44 +00:00
if (entity instanceof OwnableEntity tame) {
if (tame.getOwnerUUID() != null && tame.getOwnerUUID().equals(player.getUUID()))
2021-12-03 21:37:35 +00:00
return InteractionResult.PASS;
2020-09-18 20:29:11 +00:00
}
2021-12-03 21:37:35 +00:00
return claim.canInteract(player, PermissionRegistry.ANIMALINTERACT, pos, true) ? InteractionResult.PASS : InteractionResult.FAIL;
2020-08-23 12:52:36 +00:00
}
2021-12-03 21:37:35 +00:00
return InteractionResult.PASS;
2020-08-23 12:52:36 +00:00
}
public static boolean canInteract(Entity entity) {
2022-02-27 16:25:31 +00:00
ResourceLocation id = CrossPlatformStuff.INSTANCE.registryEntities().getIDFrom(entity.getType());
return ConfigHandler.config.ignoredEntityTypes.contains(id.getNamespace())
|| ConfigHandler.config.ignoredEntityTypes.contains(id.toString())
2021-12-03 21:37:35 +00:00
|| entity.getTags().stream().anyMatch(ConfigHandler.config.entityTagIgnore::contains);
}
2021-12-03 21:37:35 +00:00
public static boolean projectileHit(Projectile proj, HitResult res) {
2023-06-11 19:47:12 +00:00
if (proj.level().isClientSide)
2020-08-23 12:52:36 +00:00
return false;
Entity owner = proj.getOwner();
if (owner instanceof ServerPlayer player) {
2020-08-23 12:52:36 +00:00
if (res.getType() == HitResult.Type.BLOCK) {
BlockHitResult blockRes = (BlockHitResult) res;
BlockPos pos = blockRes.getBlockPos();
2023-06-11 19:47:12 +00:00
BlockState state = proj.level().getBlockState(pos);
ClaimPermission perm;
2021-12-03 21:37:35 +00:00
if (proj instanceof ThrownEnderpearl)
perm = PermissionRegistry.ENDERPEARL;
2021-12-03 21:37:35 +00:00
else if (proj instanceof ThrownEgg || proj instanceof ThrownPotion)
perm = PermissionRegistry.PROJECTILES;
else
perm = ObjectToPermissionMap.getFromBlock(state.getBlock());
if (perm != PermissionRegistry.ENDERPEARL && perm != PermissionRegistry.TARGETBLOCK && perm != PermissionRegistry.PROJECTILES)
2020-08-23 12:52:36 +00:00
return false;
2023-06-11 19:47:12 +00:00
ClaimStorage storage = ClaimStorage.get((ServerLevel) proj.level());
2020-10-30 14:09:57 +00:00
IPermissionContainer claim = storage.getForPermissionCheck(pos);
2020-08-23 12:52:36 +00:00
if (claim == null)
return false;
2020-08-24 19:03:06 +00:00
boolean flag = !claim.canInteract(player, perm, pos, true);
if (flag) {
if (proj instanceof AbstractArrow pers) {
2023-06-11 19:47:12 +00:00
((IPersistentProjectileVars) pers).setInBlockState(pers.level().getBlockState(pos));
2021-12-03 21:37:35 +00:00
Vec3 vec3d = blockRes.getLocation().subtract(pers.getX(), pers.getY(), pers.getZ());
pers.setDeltaMovement(vec3d);
Vec3 vec3d2 = vec3d.normalize().scale(0.05000000074505806D);
pers.setPosRaw(pers.getX() - vec3d2.x, pers.getY() - vec3d2.y, pers.getZ() - vec3d2.z);
2023-06-11 19:47:12 +00:00
pers.playSound(((IPersistentProjectileVars) pers).getSoundEvent(), 1.0F, 1.2F / (pers.level().random.nextFloat() * 0.2F + 0.9F));
((IPersistentProjectileVars) pers).setInGround(true);
2021-12-03 21:37:35 +00:00
pers.shakeTime = 7;
pers.setCritArrow(false);
pers.setPierceLevel((byte) 0);
2021-12-03 21:37:35 +00:00
pers.setSoundEvent(SoundEvents.ARROW_HIT);
pers.setShotFromCrossbow(false);
((IPersistentProjectileVars) pers).resetPiercingStatus();
}
2021-12-03 21:37:35 +00:00
if (proj instanceof ThrownEnderpearl)
proj.remove(Entity.RemovalReason.KILLED);
//TODO: find a way to properly update chorus fruit break on hit
//player.getServer().send(new ServerTask(player.getServer().getTicks()+2, ()->player.world.updateListeners(pos, state, state, 2)));
2020-08-23 12:52:36 +00:00
}
return flag;
2020-08-25 17:43:52 +00:00
} else if (res.getType() == HitResult.Type.ENTITY) {
2021-12-03 21:37:35 +00:00
if (proj instanceof ThrownEnderpearl) {
2023-06-11 19:47:12 +00:00
ClaimStorage storage = ClaimStorage.get((ServerLevel) proj.level());
2021-12-03 21:37:35 +00:00
IPermissionContainer claim = storage.getForPermissionCheck(proj.blockPosition());
return claim.canInteract(player, PermissionRegistry.ENDERPEARL, proj.blockPosition(), true);
}
Entity hit = ((EntityHitResult) res).getEntity();
2021-12-03 21:37:35 +00:00
boolean fail = attackSimple(player, hit, true) != InteractionResult.PASS;
if (fail && proj instanceof AbstractArrow pers && ((AbstractArrow) proj).getPierceLevel() > 0) {
IntOpenHashSet pierced = ((IPersistentProjectileVars) pers).getPiercedEntities();
if (pierced == null)
pierced = new IntOpenHashSet(5);
2021-12-03 21:37:35 +00:00
pierced.add(hit.getId());
((IPersistentProjectileVars) pers).setPiercedEntities(pierced);
pers.setPierceLevel((byte) (pers.getPierceLevel() + 1));
}
return fail;
}
}
return false;
}
public static boolean preventDamage(Entity entity, DamageSource source) {
2021-12-03 21:37:35 +00:00
if (source.getEntity() instanceof ServerPlayer)
return attackSimple((ServerPlayer) source.getEntity(), entity, true) != InteractionResult.PASS;
2023-06-11 19:47:12 +00:00
else if (source.is(DamageTypeTags.IS_EXPLOSION) && !entity.level().isClientSide && !(entity instanceof ServerPlayer || entity instanceof Enemy)) {
IPermissionContainer claim = ClaimStorage.get((ServerLevel) entity.level()).getForPermissionCheck(entity.blockPosition());
2021-12-03 21:37:35 +00:00
return claim != null && !claim.canInteract(null, PermissionRegistry.EXPLOSIONS, entity.blockPosition());
2020-08-23 12:52:36 +00:00
}
return false;
}
2021-12-03 21:37:35 +00:00
public static InteractionResult attackSimple(Player p, Entity entity, boolean message) {
if (!(p instanceof ServerPlayer player) || p.isSpectator() || canInteract(entity))
2021-12-03 21:37:35 +00:00
return InteractionResult.PASS;
if (entity instanceof Enemy)
return InteractionResult.PASS;
2023-06-11 19:47:12 +00:00
ClaimStorage storage = ClaimStorage.get(player.serverLevel());
2021-12-03 21:37:35 +00:00
BlockPos pos = entity.blockPosition();
2020-10-30 14:09:57 +00:00
IPermissionContainer claim = storage.getForPermissionCheck(pos);
2020-08-23 12:52:36 +00:00
if (claim != null) {
if (entity instanceof ArmorStand || !(entity instanceof LivingEntity))
2021-12-03 21:37:35 +00:00
return claim.canInteract(player, PermissionRegistry.BREAKNONLIVING, pos, message) ? InteractionResult.PASS : InteractionResult.FAIL;
if (entity instanceof Player)
return claim.canInteract(player, PermissionRegistry.HURTPLAYER, pos, message) ? InteractionResult.PASS : InteractionResult.FAIL;
return claim.canInteract(player, PermissionRegistry.HURTANIMAL, pos, message) ? InteractionResult.PASS : InteractionResult.FAIL;
2020-08-23 12:52:36 +00:00
}
2021-12-03 21:37:35 +00:00
return InteractionResult.PASS;
2020-08-23 12:52:36 +00:00
}
2021-12-03 21:37:35 +00:00
public static boolean xpAbsorb(Player player) {
if (player instanceof ServerPlayer) {
2023-06-11 19:47:12 +00:00
ClaimStorage storage = ClaimStorage.get((ServerLevel) player.level());
2021-12-03 21:37:35 +00:00
BlockPos pos = player.blockPosition();
2020-10-30 14:09:57 +00:00
IPermissionContainer claim = storage.getForPermissionCheck(pos);
2020-08-23 12:52:36 +00:00
if (claim != null)
2021-12-03 21:37:35 +00:00
return !claim.canInteract((ServerPlayer) player, PermissionRegistry.XP, pos, false);
2020-08-23 12:52:36 +00:00
}
return false;
}
2021-12-03 21:37:35 +00:00
public static boolean canCollideWith(Player player, Entity entity) {
if (player instanceof ServerPlayer sPlayer) {
2021-04-11 23:50:31 +00:00
if (entity instanceof ItemEntity) {
2021-06-09 10:49:19 +00:00
IOwnedItem ownedItem = (IOwnedItem) entity;
2021-07-31 15:56:43 +00:00
if (ownedItem.getDeathPlayer() != null) {
2021-12-03 21:37:35 +00:00
ServerPlayer other = sPlayer.getServer().getPlayerList().getPlayer(ownedItem.getDeathPlayer());
2021-06-09 10:49:19 +00:00
if (other == null)
return false;
2021-12-03 21:37:35 +00:00
return ownedItem.getDeathPlayer().equals(player.getUUID()) || PlayerClaimData.get(other).deathItemsUnlocked();
2021-06-09 10:49:19 +00:00
}
2021-12-03 21:37:35 +00:00
if (sPlayer.getUUID().equals(ownedItem.getPlayerOrigin()))
2021-04-11 23:50:31 +00:00
return true;
2023-06-11 19:47:12 +00:00
ClaimStorage storage = ClaimStorage.get(sPlayer.serverLevel());
2021-12-03 21:37:35 +00:00
BlockPos pos = sPlayer.blockPosition();
2021-04-11 23:50:31 +00:00
IPermissionContainer claim = storage.getForPermissionCheck(pos);
if (claim != null)
2021-06-09 10:49:19 +00:00
return claim.canInteract(sPlayer, PermissionRegistry.PICKUP, pos, false);
2021-04-11 23:50:31 +00:00
}
}
return true;
}
2021-12-03 21:37:35 +00:00
public static boolean canDropItem(Player player, ItemStack stack) {
if (!player.isDeadOrDying() && player instanceof ServerPlayer) {
2023-06-11 19:47:12 +00:00
ClaimStorage storage = ClaimStorage.get((ServerLevel) player.level());
2021-12-03 21:37:35 +00:00
BlockPos pos = player.blockPosition();
2021-04-11 23:50:31 +00:00
IPermissionContainer claim = storage.getForPermissionCheck(pos);
boolean allow = true;
if (claim != null)
2021-12-03 21:37:35 +00:00
allow = claim.canInteract((ServerPlayer) player, PermissionRegistry.DROP, pos, false);
2021-04-11 23:50:31 +00:00
if (!allow) {
2021-12-03 21:37:35 +00:00
player.getInventory().add(stack);
NonNullList<ItemStack> stacks = NonNullList.create();
for (int j = 0; j < player.containerMenu.slots.size(); ++j) {
ItemStack itemStack2 = player.containerMenu.slots.get(j).getItem();
2021-04-11 23:50:31 +00:00
stacks.add(itemStack2.isEmpty() ? ItemStack.EMPTY : itemStack2);
}
2021-12-03 21:37:35 +00:00
((ServerPlayer) player).connection.send(new ClientboundContainerSetContentPacket(player.containerMenu.containerId, 0, stacks, player.inventoryMenu.getCarried()));
2021-04-11 23:50:31 +00:00
}
return allow;
}
return true;
}
2021-12-03 21:37:35 +00:00
public static boolean witherCanDestroy(WitherBoss wither) {
2023-06-11 19:47:12 +00:00
if (wither.level().isClientSide)
2020-08-23 12:52:36 +00:00
return true;
2023-06-11 19:47:12 +00:00
ClaimStorage storage = ClaimStorage.get((ServerLevel) wither.level());
2021-12-03 21:37:35 +00:00
BlockPos.MutableBlockPos pos = new BlockPos.MutableBlockPos();
2020-08-23 12:52:36 +00:00
for (int x = -1; x <= 1; x++)
for (int z = -1; z <= 1; z++) {
2021-12-03 21:37:35 +00:00
pos.setWithOffset(wither.blockPosition(), x, 3, z);
2021-09-15 09:56:30 +00:00
IPermissionContainer claim = storage.getForPermissionCheck(pos);
if (!claim.canInteract(null, PermissionRegistry.WITHER, pos, false))
2020-08-23 12:52:36 +00:00
return false;
}
return true;
}
2021-12-03 21:37:35 +00:00
public static boolean canEndermanInteract(EnderMan enderman, BlockPos pos) {
2023-06-11 19:47:12 +00:00
if (enderman.level().isClientSide)
return true;
2023-06-11 19:47:12 +00:00
ClaimStorage storage = ClaimStorage.get((ServerLevel) enderman.level());
IPermissionContainer claim = storage.getForPermissionCheck(pos);
return claim.canInteract(null, PermissionRegistry.ENDERMAN, pos, false);
}
2021-12-03 21:37:35 +00:00
public static boolean canSnowGolemInteract(SnowGolem snowgolem) {
2023-06-11 19:47:12 +00:00
if (snowgolem.level().isClientSide)
return true;
int x, y, z;
for (int l = 0; l < 4; ++l) {
2021-12-03 21:37:35 +00:00
x = Mth.floor(snowgolem.getX() + (l % 2 * 2 - 1) * 0.25F);
y = Mth.floor(snowgolem.getY());
z = Mth.floor(snowgolem.getZ() + (l / 2 % 2 * 2 - 1) * 0.25F);
BlockPos pos = new BlockPos(x, y, z);
2023-06-11 19:47:12 +00:00
IPermissionContainer claim = ClaimStorage.get((ServerLevel) snowgolem.level()).getForPermissionCheck(pos);
if (!claim.canInteract(null, PermissionRegistry.SNOWGOLEM, pos, false))
return false;
}
return true;
}
2021-12-03 21:37:35 +00:00
public static void updateDroppedItem(Player player, ItemEntity entity) {
2021-06-09 10:49:19 +00:00
((IOwnedItem) entity).setOriginPlayer((player));
}
2021-12-03 21:37:35 +00:00
public static void updateClaim(ServerPlayer player, Claim currentClaim, Consumer<Claim> cons) {
Vec3 pos = player.position();
BlockPos rounded = TeleportUtils.roundedBlockPos(pos.add(0, player.getStandingEyeHeight(player.getPose(), player.getDimensions(player.getPose())), 0));
2023-06-11 19:47:12 +00:00
ClaimStorage storage = ClaimStorage.get(player.serverLevel());
2021-06-08 19:01:38 +00:00
if (currentClaim != null) {
2021-06-12 22:21:31 +00:00
if (!currentClaim.intersects(player.getBoundingBox())) {
2022-05-12 20:06:10 +00:00
boolean isSub = currentClaim.parentClaim() != null;
Claim claim = isSub ? storage.getClaimAt(rounded) : currentClaim.parentClaim();
2021-09-14 15:26:41 +00:00
if (claim == null)
currentClaim.displayLeaveTitle(player);
2022-05-12 20:06:10 +00:00
else {
Claim sub = claim.getSubClaim(rounded);
boolean display = true;
if (sub != null)
claim = sub;
else {
display = currentClaim.enterTitle != null;
if (claim.enterTitle == null)
currentClaim.displayLeaveTitle(player);
}
if (display)
claim.displayEnterTitle(player);
}
cons.accept(claim);
2021-06-08 19:01:38 +00:00
} else {
2022-05-12 20:06:10 +00:00
if (currentClaim.parentClaim() == null) {
Claim sub = currentClaim.getSubClaim(rounded);
if (sub != null) {
currentClaim = sub;
currentClaim.displayEnterTitle(player);
cons.accept(currentClaim);
}
}
2021-06-08 19:01:38 +00:00
if (!player.isSpectator()) {
2021-12-03 21:37:35 +00:00
BlockPos.MutableBlockPos bPos = rounded.mutable();
2022-05-12 20:06:10 +00:00
boolean isSub = currentClaim.parentClaim() != null;
Claim mainClaim = isSub ? currentClaim.parentClaim() : currentClaim;
if (!mainClaim.canInteract(player, PermissionRegistry.CANSTAY, bPos, true)) {
Claim sub = isSub ? currentClaim : null;
Vec3 tp = TeleportUtils.getTeleportPos(player, pos, storage, sub != null ? sub.getDimensions() : mainClaim.getDimensions(), true, bPos, (claim, nPos) -> claim.canInteract(player, PermissionRegistry.CANSTAY, nPos, false));
if (player.isPassenger())
player.stopRiding();
2021-12-03 21:37:35 +00:00
player.teleportToWithTicket(tp.x(), tp.y(), tp.z());
2021-06-08 19:01:38 +00:00
}
2022-05-12 20:06:10 +00:00
if (player.getAbilities().flying && !player.isCreative() && !mainClaim.canInteract(player, PermissionRegistry.FLIGHT, rounded, true)) {
2021-12-03 21:37:35 +00:00
player.getAbilities().flying = false;
player.connection.send(new ClientboundPlayerAbilitiesPacket(player.getAbilities()));
2021-06-08 19:01:38 +00:00
}
2022-05-12 20:06:10 +00:00
if (player.getFoodData().getSaturationLevel() < 2 && mainClaim.canInteract(player, PermissionRegistry.NOHUNGER, bPos, false)) {
2021-12-03 21:37:35 +00:00
((IHungerAccessor) player.getFoodData()).setSaturation(2);
2021-06-12 22:21:31 +00:00
}
2021-06-12 23:49:10 +00:00
currentClaim.applyEffects(player);
2021-05-12 11:29:29 +00:00
}
}
2021-12-03 21:37:35 +00:00
} else if (player.tickCount % 3 == 0) {
2021-06-08 19:01:38 +00:00
Claim claim = storage.getClaimAt(rounded);
2022-05-12 20:06:10 +00:00
Claim sub = claim != null ? claim.getSubClaim(rounded) : null;
if (sub != null)
claim = sub;
2021-09-14 15:26:41 +00:00
if (claim != null)
claim.displayEnterTitle(player);
2022-05-12 20:06:10 +00:00
cons.accept(claim);
2021-05-12 11:29:29 +00:00
}
}
2021-06-29 16:42:59 +00:00
2021-12-03 21:37:35 +00:00
public static boolean canFrostwalkerFreeze(ServerLevel world, BlockPos pos, LivingEntity entity) {
if (entity instanceof ServerPlayer) {
2021-06-29 16:42:59 +00:00
IPermissionContainer claim = ClaimStorage.get(world).getForPermissionCheck(pos);
2021-12-03 21:37:35 +00:00
return claim.canInteract((ServerPlayer) entity, PermissionRegistry.FROSTWALKER, pos, false);
2021-06-29 16:42:59 +00:00
}
return true;
}
2021-07-02 15:43:12 +00:00
public static boolean preventLightningConvert(Entity entity) {
2023-06-11 19:47:12 +00:00
if (entity.level().isClientSide || entity instanceof Enemy)
2021-07-02 15:43:12 +00:00
return false;
2023-06-11 19:47:12 +00:00
ClaimStorage storage = ClaimStorage.get((ServerLevel) entity.level());
2021-12-03 21:37:35 +00:00
IPermissionContainer claim = storage.getForPermissionCheck(entity.blockPosition());
return !claim.canInteract(null, PermissionRegistry.LIGHTNING, entity.blockPosition(), false);
2021-07-02 15:43:12 +00:00
}
2020-08-23 12:52:36 +00:00
}