Search in sources :

Example 1 with CollisionCapabilityBridge

use of org.spongepowered.common.bridge.entitycollision.CollisionCapabilityBridge in project SpongeCommon by SpongePowered.

the class LevelChunkMixin_EntityCollision method entityCollision$allowEntityCollision.

private <T extends Entity> boolean entityCollision$allowEntityCollision(final List<T> entities) {
    if (((LevelBridge) this.shadow$getLevel()).bridge$isFake()) {
        return true;
    }
    final PhaseContext<@NonNull ?> phaseContext = PhaseTracker.getInstance().getPhaseContext();
    if (!phaseContext.allowsEntityCollisionEvents()) {
        // allow explosions
        return true;
    }
    final Object source = phaseContext.getSource();
    if (source == null) {
        return true;
    }
    CollisionCapabilityBridge collisionBridge = null;
    if (source instanceof LocatableBlock) {
        final LocatableBlock locatable = (LocatableBlock) source;
        final BlockType blockType = locatable.location().block().type();
        collisionBridge = (CollisionCapabilityBridge) blockType;
    } else if (source instanceof CollisionCapabilityBridge) {
        collisionBridge = (CollisionCapabilityBridge) source;
    }
    if (collisionBridge == null) {
        return true;
    }
    if (collisionBridge.collision$requiresCollisionsCacheRefresh()) {
        collisionBridge.collision$initializeCollisionState(this.shadow$getLevel());
        collisionBridge.collision$requiresCollisionsCacheRefresh(false);
    }
    return !((collisionBridge.collision$getMaxCollisions() >= 0) && (entities.size() >= collisionBridge.collision$getMaxCollisions()));
}
Also used : LevelBridge(org.spongepowered.common.bridge.world.level.LevelBridge) BlockType(org.spongepowered.api.block.BlockType) CollisionCapabilityBridge(org.spongepowered.common.bridge.entitycollision.CollisionCapabilityBridge) LocatableBlock(org.spongepowered.api.world.LocatableBlock)

Aggregations

BlockType (org.spongepowered.api.block.BlockType)1 LocatableBlock (org.spongepowered.api.world.LocatableBlock)1 CollisionCapabilityBridge (org.spongepowered.common.bridge.entitycollision.CollisionCapabilityBridge)1 LevelBridge (org.spongepowered.common.bridge.world.level.LevelBridge)1