// 
// Decompiled by Procyon v0.6.0
// 

package com.hypixel.hytale.builtin.hytalegenerator.materialproviders;

import javax.annotation.Nullable;
import java.util.List;
import javax.annotation.Nonnull;

public class StripedMaterialProvider<V> extends MaterialProvider<V>
{
    @Nonnull
    private final MaterialProvider<V> materialProvider;
    @Nonnull
    private final Stripe[] stripes;
    
    public StripedMaterialProvider(@Nonnull final MaterialProvider<V> materialProvider, @Nonnull final List<Stripe> stripes) {
        this.materialProvider = materialProvider;
        this.stripes = new Stripe[stripes.size()];
        for (int i = 0; i < stripes.size(); ++i) {
            final Stripe s = stripes.get(i);
            this.stripes[i] = s;
        }
    }
    
    @Nullable
    @Override
    public V getVoxelTypeAt(@Nonnull final Context context) {
        for (final Stripe s : this.stripes) {
            if (s.contains(context.position.y)) {
                return this.materialProvider.getVoxelTypeAt(context);
            }
        }
        return null;
    }
    
    public static class Stripe
    {
        private final int topY;
        private final int bottomY;
        
        public Stripe(final int topY, final int bottomY) {
            this.topY = topY;
            this.bottomY = bottomY;
        }
        
        public boolean contains(final int y) {
            return y >= this.bottomY && y <= this.topY;
        }
    }
}
