Interface IChunkProtectionAPI
The methods provided here should enable you to implement basic support for claim protection on your mod's end.
Only use this if the Forge/Fabric events and injections this mod uses by default are not already protecting claims.
If a claim is overprotected from your mod, you might want to giveFullPass(UUID)
to an entity to circumvent
all protection except when using methods from this API. If you only want temporary protection circumvention,
please use removeFullPass(UUID)
after you're done.
-
Method Summary
Modifier and TypeMethodDescriptionboolean
checkExceptionLeveledOption
(IPlayerConfigOptionSpecAPI<Integer> option, IPlayerConfigAPI claimConfig, UUID accessorId) Checks whether a player/claim config option with multiple exception levels includes the entity with a specified UUID.boolean
checkExceptionLeveledOption
(IPlayerConfigOptionSpecAPI<Integer> option, IPlayerConfigAPI claimConfig, net.minecraft.world.entity.Entity accessor) Checks whether a player/claim config option with multiple exception levels includes a specified entity.boolean
checkProtectionLeveledOption
(IPlayerConfigOptionSpecAPI<Integer> option, IPlayerConfigAPI claimConfig, UUID accessorId) Checks whether a player/claim config option with multiple protection levels protects from the entity with a specified UUID.boolean
checkProtectionLeveledOption
(IPlayerConfigOptionSpecAPI<Integer> option, IPlayerConfigAPI claimConfig, net.minecraft.world.entity.Entity accessor) Checks whether a player/claim config option with multiple protection levels protects from a specified entity.Gets the player/claim config used for a specified claim state.void
giveFullPass
(UUID entityId) Gives an entity UUID a full pass to circumvent claim protection when affecting entities/blocks/items, except when the methods of this API are used, e.g.boolean
hasChunkAccess
(IPlayerConfigAPI claimConfig, UUID accessorId) Directly checks whether the entity with a specified UUID has full access to a claim with the specified config.boolean
hasChunkAccess
(IPlayerConfigAPI claimConfig, net.minecraft.world.entity.Entity accessor) Directly checks whether a specified entity has full access to a claim with the specified config.boolean
onBlockInteraction
(net.minecraft.world.entity.Entity entity, net.minecraft.world.InteractionHand hand, net.minecraft.world.item.ItemStack heldItem, net.minecraft.server.level.ServerLevel world, net.minecraft.core.BlockPos pos, net.minecraft.core.Direction direction, boolean breaking, boolean messages) Deprecated.boolean
onBlockInteraction
(net.minecraft.world.entity.Entity entity, net.minecraft.world.InteractionHand hand, net.minecraft.world.item.ItemStack heldItem, net.minecraft.server.level.ServerLevel world, net.minecraft.core.BlockPos pos, net.minecraft.core.Direction direction, boolean breaking, boolean messages, boolean targetExceptions) Checks whether a specified block interaction should be protected against.boolean
onEntityInteraction
(net.minecraft.world.entity.Entity interactingEntityIndirect, net.minecraft.world.entity.Entity interactingEntity, net.minecraft.world.entity.Entity targetEntity, net.minecraft.world.item.ItemStack heldItem, net.minecraft.world.InteractionHand hand, boolean attack, boolean messages) Deprecated.boolean
onEntityInteraction
(net.minecraft.world.entity.Entity interactingEntityIndirect, net.minecraft.world.entity.Entity interactingEntity, net.minecraft.world.entity.Entity targetEntity, net.minecraft.world.item.ItemStack heldItem, net.minecraft.world.InteractionHand hand, boolean attack, boolean messages, boolean targetExceptions) Checks whether an entity interaction should be protected against.boolean
onEntityPlaceBlock
(net.minecraft.world.entity.Entity entity, net.minecraft.server.level.ServerLevel world, net.minecraft.core.BlockPos pos) Checks whether a specified block placement should be protected against.boolean
onItemPickup
(net.minecraft.world.entity.Entity entity, net.minecraft.world.entity.item.ItemEntity itemEntity) Checks whether a specified entity picking up a specified item entity should be protected against.boolean
onPosAffectedByAnotherPos
(net.minecraft.server.level.ServerLevel toWorld, net.minecraft.world.level.ChunkPos toChunk, net.minecraft.server.level.ServerLevel fromWorld, net.minecraft.world.level.ChunkPos fromChunk, boolean includeWilderness, boolean affectsBlocks, boolean affectsEntities) Checks whether an anonymous action coming from one chunk position to another should be protected against, based on protection that affects placing blocks and using items in both positions.boolean
onProjectileHitSpawnedEntity
(net.minecraft.world.entity.Entity projectile, net.minecraft.world.entity.Entity entity) Checks whether a landing projectile spawning an entity should be protected against.void
removeFullPass
(UUID entityId) Removes a pass given withgiveFullPass(UUID)
from an entity UUID.
-
Method Details
-
onBlockInteraction
@Deprecated boolean onBlockInteraction(@Nullable net.minecraft.world.entity.Entity entity, @Nullable net.minecraft.world.InteractionHand hand, @Nullable net.minecraft.world.item.ItemStack heldItem, @Nonnull net.minecraft.server.level.ServerLevel world, @Nonnull net.minecraft.core.BlockPos pos, @Nonnull net.minecraft.core.Direction direction, boolean breaking, boolean messages) Deprecated.UseonBlockInteraction(Entity, InteractionHand, ItemStack, ServerLevel, BlockPos, Direction, boolean, boolean, boolean)
instead.Checks whether a specified block interaction should be protected against.
Whenever possible, use the built-in block interaction events provided by the mod loader (Fabric/Forge) instead of this method, unless they aren't specific enough, or the entity has a full protection pass (
giveFullPass(UUID)
).- Parameters:
entity
- the entity to interact with the block, can be nullhand
- the hand that the entity is to interact with, can be nullheldItem
- the item stack that the entity is to interact with, null to fetch it from the handworld
- the world that the entity is to interact with, not nullpos
- the block position that the entity is to interact with, not nulldirection
- the direction which the entity is to interact from, not nullbreaking
- whether the interaction is to break the blockmessages
- whether to send the player system chat messages on protection- Returns:
- true if the block interaction should be protected against, otherwise false
-
onBlockInteraction
boolean onBlockInteraction(@Nullable net.minecraft.world.entity.Entity entity, @Nullable net.minecraft.world.InteractionHand hand, @Nullable net.minecraft.world.item.ItemStack heldItem, @Nonnull net.minecraft.server.level.ServerLevel world, @Nonnull net.minecraft.core.BlockPos pos, @Nonnull net.minecraft.core.Direction direction, boolean breaking, boolean messages, boolean targetExceptions) Checks whether a specified block interaction should be protected against.Whenever possible, use the built-in block interaction events provided by the mod loader (Fabric/Forge) instead of this method, unless they aren't specific enough, or the entity has a full protection pass (
giveFullPass(UUID)
).- Parameters:
entity
- the entity to interact with the block, can be nullhand
- the hand that the entity is to interact with, can be nullheldItem
- the item stack that the entity is to interact with, null to fetch it from the handworld
- the world that the entity is to interact with, not nullpos
- the block position that the entity is to interact with, not nulldirection
- the direction which the entity is to interact from, not nullbreaking
- whether the interaction is to break the blockmessages
- whether to send the player system chat messages on protectiontargetExceptions
- whether to check the target block for protection exceptions- Returns:
- true if the block interaction should be protected against, otherwise false
-
onEntityPlaceBlock
boolean onEntityPlaceBlock(@Nullable net.minecraft.world.entity.Entity entity, @Nonnull net.minecraft.server.level.ServerLevel world, @Nonnull net.minecraft.core.BlockPos pos) Checks whether a specified block placement should be protected against.Whenever possible, use the built-in block placement event provided by Forge instead of this method, unless it isn't specific enough, you're on Fabric, or the entity has a full protection pass (
giveFullPass(UUID)
).- Parameters:
entity
- the entity to place the block, can be nullworld
- the world to place the block in, not nullpos
- the block position to place the block at, not null- Returns:
- true if the block placement should be protected against, otherwise false
-
onEntityInteraction
@Deprecated boolean onEntityInteraction(@Nullable net.minecraft.world.entity.Entity interactingEntityIndirect, @Nullable net.minecraft.world.entity.Entity interactingEntity, @Nonnull net.minecraft.world.entity.Entity targetEntity, @Nullable net.minecraft.world.item.ItemStack heldItem, @Nullable net.minecraft.world.InteractionHand hand, boolean attack, boolean messages) Deprecated.UseonEntityInteraction(Entity, Entity, Entity, ItemStack, InteractionHand, boolean, boolean, boolean)
instead.Checks whether an entity interaction should be protected against.
Whenever possible, use the built-in entity interaction event provided by Forge instead of this method, unless it isn't specific enough, you're on Fabric, or the interacting entity has a full protection pass (
giveFullPass(UUID)
).- Parameters:
interactingEntityIndirect
- the entity that is to interact indirectly, can be nullinteractingEntity
- the directly interacting entity, can be nulltargetEntity
- the entity to interact with, not nullheldItem
- the item stack to interact with, null to fetch it from the handhand
- the hand to interact with, can be nullattack
- whether the interaction is to attack the target entitymessages
- whether to send the player system chat messages on protection- Returns:
- true if the entity interaction should be protected against, otherwise false
-
onEntityInteraction
boolean onEntityInteraction(@Nullable net.minecraft.world.entity.Entity interactingEntityIndirect, @Nullable net.minecraft.world.entity.Entity interactingEntity, @Nonnull net.minecraft.world.entity.Entity targetEntity, @Nullable net.minecraft.world.item.ItemStack heldItem, @Nullable net.minecraft.world.InteractionHand hand, boolean attack, boolean messages, boolean targetExceptions) Checks whether an entity interaction should be protected against.Whenever possible, use the built-in entity interaction event provided by Forge instead of this method, unless it isn't specific enough, you're on Fabric, or the interacting entity has a full protection pass (
giveFullPass(UUID)
).- Parameters:
interactingEntityIndirect
- the entity that is to interact indirectly, can be nullinteractingEntity
- the directly interacting entity, can be nulltargetEntity
- the entity to interact with, not nullheldItem
- the item stack to interact with, null to fetch it from the handhand
- the hand to interact with, can be nullattack
- whether the interaction is to attack the target entitymessages
- whether to send the player system chat messages on protectiontargetExceptions
- whether to check the target entity for protection exceptions- Returns:
- true if the entity interaction should be protected against, otherwise false
-
onItemPickup
boolean onItemPickup(@Nonnull net.minecraft.world.entity.Entity entity, @Nonnull net.minecraft.world.entity.item.ItemEntity itemEntity) Checks whether a specified entity picking up a specified item entity should be protected against.- Parameters:
entity
- the entity to pick up the item, not nullitemEntity
- the item entity to pick up, not null- Returns:
- true if the item should be protected from being picked up, otherwise false
-
onPosAffectedByAnotherPos
boolean onPosAffectedByAnotherPos(@Nonnull net.minecraft.server.level.ServerLevel toWorld, @Nonnull net.minecraft.world.level.ChunkPos toChunk, @Nonnull net.minecraft.server.level.ServerLevel fromWorld, @Nonnull net.minecraft.world.level.ChunkPos fromChunk, boolean includeWilderness, boolean affectsBlocks, boolean affectsEntities) Checks whether an anonymous action coming from one chunk position to another should be protected against, based on protection that affects placing blocks and using items in both positions.This is meant for mechanics that don't necessarily have a usable owner to plug into the entity/block/item interaction checks but can be associated with a block position that they operate from, e.g. when a certain placed block affects other blocks around it. This check will prohibit actions coming from chunks that have lesser block interaction, item use or some barrier protection.
The idea is that an action is considered safe, if any player that can find a way to place a block or a stationary entity in the chunk that the action is coming from, can also do it under the current protection configured for the chunk that is to be affected. For example, actions coming from already placed blocks/entities would circumvent all protection within a claim that they are positioned in but a player must first have been able to place the block/entity in the claim, which ideally means that the player was at one point trusted. Obviously, this leaves a lot of room for user error.
- Parameters:
toWorld
- the world to be affected by the action, not nulltoChunk
- the chunk position to be affected by the action, not nullfromWorld
- the world that the action is coming from, not nullfromChunk
- the chunk position that the action is coming from, not nullincludeWilderness
- whether to even consider protecting the wildernessaffectsBlocks
- whether the action is able to affect blocksaffectsEntities
- whether the action is able to affect entities- Returns:
- true if the action should be protected against, otherwise false
-
onProjectileHitSpawnedEntity
boolean onProjectileHitSpawnedEntity(@Nonnull net.minecraft.world.entity.Entity projectile, @Nonnull net.minecraft.world.entity.Entity entity) Checks whether a landing projectile spawning an entity should be protected against.Projectiles implementing
AbstractArrow
,AbstractHurtingProjectile
orThrowableProjectile
are usually already checking the protection by default, so make sure that using this is even necessary before you do.As of writing this, this only ever protects against living entities being spawned.
- Parameters:
projectile
- the projectile that spawns the entity, not nullentity
- the entity spawned by the projectile, not null- Returns:
- true if the spawn should be prevented, otherwise false
-
giveFullPass
Gives an entity UUID a full pass to circumvent claim protection when affecting entities/blocks/items, except when the methods of this API are used, e.g.onEntityPlaceBlock(Entity, ServerLevel, BlockPos)
.- Parameters:
entityId
- the entity UUID, not null
-
removeFullPass
Removes a pass given withgiveFullPass(UUID)
from an entity UUID.- Parameters:
entityId
- the entity UUID, not null
-
getClaimConfig
Gets the player/claim config used for a specified claim state.You can fetch claim states of chunks from the
IServerClaimsManagerAPI
.- Parameters:
claim
- the claim state to get the used config of, null for wilderness- Returns:
- the player config used by the claim
-
hasChunkAccess
boolean hasChunkAccess(@Nonnull IPlayerConfigAPI claimConfig, @Nonnull net.minecraft.world.entity.Entity accessor) Directly checks whether a specified entity has full access to a claim with the specified config.You most likely don't have to use this method at all. The action-specific protection check methods already do it. This is meant for things that are not covered by the rest of the API.
- Parameters:
claimConfig
- the claim config to check access for, not nullaccessor
- the entity to check access for, not null- Returns:
- true if accessor has full access to the claim, otherwise false
-
hasChunkAccess
Directly checks whether the entity with a specified UUID has full access to a claim with the specified config.Please use
hasChunkAccess(IPlayerConfigAPI, Entity)
when you have an actual entity reference.You most likely don't have to use this method at all. The action-specific protection check methods already do it. This is meant for things that are not covered by the rest of the API.
- Parameters:
claimConfig
- the claim config to check access for, not nullaccessorId
- the entity UUID to check access for, not null- Returns:
- true if accessor has full access to the claim, otherwise false
-
checkProtectionLeveledOption
boolean checkProtectionLeveledOption(@Nonnull IPlayerConfigOptionSpecAPI<Integer> option, @Nonnull IPlayerConfigAPI claimConfig, @Nonnull net.minecraft.world.entity.Entity accessor) Checks whether a player/claim config option with multiple protection levels protects from a specified entity.You most likely don't have to use this method at all. The action-specific protection check methods already use option values. This is meant for things that are not covered by the rest of the API.
- Parameters:
option
- the protection option to check, not nullclaimConfig
- the claim config to check the option value for, not nullaccessor
- the entity to check against the current value of the option, not null- Returns:
- true if the option is set to protect from the specified entity, false otherwise
-
checkProtectionLeveledOption
boolean checkProtectionLeveledOption(@Nonnull IPlayerConfigOptionSpecAPI<Integer> option, @Nonnull IPlayerConfigAPI claimConfig, @Nonnull UUID accessorId) Checks whether a player/claim config option with multiple protection levels protects from the entity with a specified UUID.Please use
checkProtectionLeveledOption(IPlayerConfigOptionSpecAPI, IPlayerConfigAPI, Entity)
when you have an actual entity reference.You most likely don't have to use this method at all. The action-specific protection check methods already use option values. This is meant for things that are not covered by the rest of the API.
- Parameters:
option
- the protection option to check, not nullclaimConfig
- the claim config to check the option value for, not nullaccessorId
- the UUID of the entity to check against the current value of the option, not null- Returns:
- true if the option is set to protect from the specified entity, false otherwise
-
checkExceptionLeveledOption
boolean checkExceptionLeveledOption(@Nonnull IPlayerConfigOptionSpecAPI<Integer> option, @Nonnull IPlayerConfigAPI claimConfig, @Nonnull net.minecraft.world.entity.Entity accessor) Checks whether a player/claim config option with multiple exception levels includes a specified entity.You most likely don't have to use this method at all. The action-specific protection check methods already use option values. This is meant for things that are not covered by the rest of the API.
- Parameters:
option
- the exception option to check, not nullclaimConfig
- the claim config to check the option value for, not nullaccessor
- the entity to check against the current value of the option, not null- Returns:
- true if the option is set to include the specified entity, false otherwise
-
checkExceptionLeveledOption
boolean checkExceptionLeveledOption(@Nonnull IPlayerConfigOptionSpecAPI<Integer> option, @Nonnull IPlayerConfigAPI claimConfig, @Nonnull UUID accessorId) Checks whether a player/claim config option with multiple exception levels includes the entity with a specified UUID.Please use
checkExceptionLeveledOption(IPlayerConfigOptionSpecAPI, IPlayerConfigAPI, Entity)
when you have an actual entity reference.You most likely don't have to use this method at all. The action-specific protection check methods already use option values. This is meant for things that are not covered by the rest of the API.
- Parameters:
option
- the exception option to check, not nullclaimConfig
- the claim config to check the option value for, not nullaccessorId
- the UUID of the entity to check against the current value of the option, not null- Returns:
- true if the option is set to include the specified entity, false otherwise
-
onBlockInteraction(Entity, InteractionHand, ItemStack, ServerLevel, BlockPos, Direction, boolean, boolean, boolean)
instead.