Record Class FlagEvaluator
-
Constructor Summary
ConstructorsConstructorDescriptionFlagEvaluator(FlagCheckResult result) Creates an instance of aFlagEvaluatorrecord class. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcheckMobGrief(net.minecraft.world.entity.Entity entity, org.spongepowered.asm.mixin.injection.callback.CallbackInfo ci) static voidcheckMobGrief(net.minecraft.world.entity.Entity entity, org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable<Boolean> cir) static voidcheckMobGrief(net.minecraft.world.level.Level world, net.minecraft.core.BlockPos pos, org.spongepowered.asm.mixin.injection.callback.CallbackInfo ci) static voidcheckMobGrief(net.minecraft.world.level.Level world, net.minecraft.core.BlockPos pos, org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable<Boolean> cir) final booleanIndicates whether some other object is "equal to" this one.static FlagCheckResultevaluate(FlagCheckEvent checkEvent) Evaluates a flag check event by determining the responsible region, resolving the flag context, and computing the resulting flag state.static @Nullable IProtectedRegionfindResponsibleRegion(@NotNull net.minecraft.core.BlockPos pos, @NotNull net.minecraft.resources.ResourceKey<net.minecraft.world.level.Level> dim) Determines the region responsible for the given position and dimension.final inthashCode()Returns a hash code value for this object.static booleanisRootRegion(@NotNull IProtectedRegion region) Checks whether the given region is its own parent.onAllow(Consumer<FlagCheckResult> action) onDefault(Consumer<FlagCheckResult> action) onDeny(Consumer<FlagCheckResult> action) onDenyWithMsg(Consumer<FlagCheckResult> action) static FlagEvaluatorprocess(@NotNull FlagCheckEvent checkEvent) static FlagStateprocessCheck(@NotNull FlagCheckEvent checkEvent) Processes the given flag check event with default behavior.static FlagStateprocessCheck(@NotNull FlagCheckEvent checkEvent, @Nullable Consumer<FlagCheckResult> onDeny) Processes the given flag check event and executes the given consumer if the flag is denied.static FlagStateprocessCheck(@NotNull FlagCheckEvent checkEvent, @Nullable Consumer<FlagCheckResult> onAllow, @Nullable Consumer<FlagCheckResult> onDeny) Processes a flag check event and executes the corresponding consumer based on the result.static FlagStateprocessCheckF(@NotNull FlagCheckEvent checkEvent, @Nullable Function<FlagCheckResult, FlagState> handleResult) static FlagContextresolveFlag(IProtectedRegion region, FlagContext flagContext) Resolves the finalFlagContextfor a given region by considering flag inheritance from parent regions.result()Returns the value of theresultrecord component.state()final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
FlagEvaluator
Creates an instance of aFlagEvaluatorrecord class.- Parameters:
result- the value for theresultrecord component
-
-
Method Details
-
state
-
onAllow
-
onDeny
-
onDenyWithMsg
-
onDefault
-
processCheck
public static FlagState processCheck(@NotNull @NotNull FlagCheckEvent checkEvent, @Nullable @Nullable Consumer<FlagCheckResult> onAllow, @Nullable @Nullable Consumer<FlagCheckResult> onDeny) Processes a flag check event and executes the corresponding consumer based on the result.The given flag check event is evaluated to determine the flag state and then posted to the event bus for further processing. If the flag state is
ALLOWED, theonAllowconsumer is executed. If the flag state isDENIED, theonDenyconsumer is executed.- Parameters:
checkEvent- the flag check event to process, must not benullonAllow- the consumer to execute if the flag is allowed, may benullonDeny- the consumer to execute if the flag is denied, may benull- Returns:
- the resulting
FlagStateafter processing the event
-
process
-
processCheckF
public static FlagState processCheckF(@NotNull @NotNull FlagCheckEvent checkEvent, @Nullable @Nullable Function<FlagCheckResult, FlagState> handleResult) -
processCheck
public static FlagState processCheck(@NotNull @NotNull FlagCheckEvent checkEvent, @Nullable @Nullable Consumer<FlagCheckResult> onDeny) Processes the given flag check event and executes the given consumer if the flag is denied.This overload is equivalent to calling
processCheck(FlagCheckEvent, Consumer, Consumer)withonAllowset tonull.- Parameters:
checkEvent- the flag check event to process, must not benullonDeny- the consumer to execute if the flag is denied- Returns:
- the resulting
FlagStateafter processing - See Also:
-
processCheck
Processes the given flag check event with default behavior.This overload is equivalent to calling
processCheck(FlagCheckEvent, Consumer, Consumer)with both consumers set tonull.- Parameters:
checkEvent- the flag check event to process, must not benull- Returns:
- the resulting
FlagStateafter processing - See Also:
-
evaluate
Evaluates a flag check event by determining the responsible region, resolving the flag context, and computing the resulting flag state.The evaluation follows these steps:
- Finds the responsible region for the given target and dimension.
- If no region is found, returns an undefined
FlagCheckResult. - Constructs a
FlagContextusing the region, flag, and player information. - Resolves the effective flag context by considering inheritance and overrides.
- Returns a
FlagCheckResultcontaining the determined flag state and context details.
- Parameters:
checkEvent- the flag check event containing information about the target, dimension, and flag.- Returns:
- a
FlagCheckResultrepresenting the evaluated flag state and context.
-
resolveFlag
Resolves the finalFlagContextfor a given region by considering flag inheritance from parent regions. The initial flag context needs to be the flag context corresponding to the given region.This method follows a recursive approach to determine the effective flag context:
- If the region is a root region, it returns the given
flagContext. - Otherwise, it retrieves the
FlagContextof the parent region. - The current flag context is merged with the parent's context using
FlagContext.inheritContext(de.z0rdak.yawp.core.flag.FlagContext). - The process continues recursively up the region hierarchy until the root is reached.
- Parameters:
region- the region for which the flag context is being resolved.flagContext- the initial flag context for the region.- Returns:
- the resolved
FlagContext, considering inheritance from parent regions.
- If the region is a root region, it returns the given
-
isRootRegion
Checks whether the given region is its own parent. This indicates that the region is the global region.- Parameters:
region- the region to check, must not benull- Returns:
trueif the region's parent is itself, otherwisefalse
-
findResponsibleRegion
@Nullable public static @Nullable IProtectedRegion findResponsibleRegion(@NotNull @NotNull net.minecraft.core.BlockPos pos, @NotNull @NotNull net.minecraft.resources.ResourceKey<net.minecraft.world.level.Level> dim) Determines the region responsible for the given position and dimension. The responsible region is the one with the highest priority among all regions that cover the specified location.If no specific region is found, this method falls back to the dimensional region. If the dimensional region is inactive, it further falls back to the global region if it is active.
- Parameters:
pos- the position for which to find the responsible region, must not benulldim- the dimension in which to search for the responsible region, must not benull- Returns:
- the highest-priority active region covering the given position and dimension,
or
nullif no active region is found
-
checkMobGrief
public static void checkMobGrief(net.minecraft.world.entity.Entity entity, org.spongepowered.asm.mixin.injection.callback.CallbackInfo ci) -
checkMobGrief
public static void checkMobGrief(net.minecraft.world.entity.Entity entity, org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable<Boolean> cir) -
checkMobGrief
public static void checkMobGrief(net.minecraft.world.level.Level world, net.minecraft.core.BlockPos pos, org.spongepowered.asm.mixin.injection.callback.CallbackInfo ci) -
checkMobGrief
public static void checkMobGrief(net.minecraft.world.level.Level world, net.minecraft.core.BlockPos pos, org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable<Boolean> cir) -
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object). -
result
Returns the value of theresultrecord component.- Returns:
- the value of the
resultrecord component
-