Search in sources :

Example 1 with IModData_Collisions

use of org.spongepowered.common.mixin.plugin.entitycollisions.interfaces.IModData_Collisions in project SpongeCommon by SpongePowered.

the class MixinChunk_Collisions method allowEntityCollision.

private <T extends Entity> boolean allowEntityCollision(List<T> listToFill) {
    if (this.world instanceof IMixinWorldServer) {
        IMixinWorldServer spongeWorld = (IMixinWorldServer) this.world;
        if (spongeWorld.isProcessingExplosion()) {
            // allow explosions
            return true;
        }
        final PhaseContext<?> phaseContext = PhaseTracker.getInstance().getCurrentContext();
        LocatableBlock locatable = phaseContext.getSource(LocatableBlock.class).orElse(null);
        if (locatable != null) {
            BlockType blockType = locatable.getLocation().getBlockType();
            IModData_Collisions spongeBlock = (IModData_Collisions) blockType;
            if (spongeBlock.requiresCollisionsCacheRefresh()) {
                spongeBlock.initializeCollisionState(this.world);
                spongeBlock.requiresCollisionsCacheRefresh(false);
            }
            return !((spongeBlock.getMaxCollisions() >= 0) && (listToFill.size() >= spongeBlock.getMaxCollisions()));
        }
        IModData_Collisions spongeEntity = phaseContext.getSource(IModData_Collisions.class).orElse(null);
        if (spongeEntity != null) {
            if (spongeEntity.requiresCollisionsCacheRefresh()) {
                spongeEntity.initializeCollisionState(this.world);
                spongeEntity.requiresCollisionsCacheRefresh(false);
            }
            return !((spongeEntity.getMaxCollisions() >= 0) && (listToFill.size() >= spongeEntity.getMaxCollisions()));
        }
        return true;
    }
    return true;
}
Also used : IModData_Collisions(org.spongepowered.common.mixin.plugin.entitycollisions.interfaces.IModData_Collisions) BlockType(org.spongepowered.api.block.BlockType) IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer) LocatableBlock(org.spongepowered.api.world.LocatableBlock)

Aggregations

BlockType (org.spongepowered.api.block.BlockType)1 LocatableBlock (org.spongepowered.api.world.LocatableBlock)1 IMixinWorldServer (org.spongepowered.common.interfaces.world.IMixinWorldServer)1 IModData_Collisions (org.spongepowered.common.mixin.plugin.entitycollisions.interfaces.IModData_Collisions)1