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

package com.hypixel.hytale.builtin.buildertools.tooloperations;

import com.hypixel.hytale.server.core.universe.world.accessor.ChunkAccessor;
import com.hypixel.hytale.builtin.buildertools.BuilderToolsPlugin;
import com.hypixel.hytale.component.ComponentAccessor;
import com.hypixel.hytale.protocol.packets.buildertools.BuilderToolOnUseInteraction;
import javax.annotation.Nonnull;
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
import com.hypixel.hytale.component.Ref;

public class SmoothOperation extends ToolOperation
{
    private final int smoothVolume;
    
    public SmoothOperation(@Nonnull final Ref<EntityStore> ref, @Nonnull final BuilderToolOnUseInteraction packet, @Nonnull final ComponentAccessor<EntityStore> componentAccessor) {
        super(ref, packet, componentAccessor);
        final int smoothStrength = this.args.tool().get("SmoothStrength");
        final int smoothRange = Math.min(smoothStrength, 4) * 2 + 1;
        this.smoothVolume = smoothRange * smoothRange * smoothRange;
    }
    
    @Override
    boolean execute0(final int x, final int y, final int z) {
        final int currentBlock = this.edit.getBlock(x, y, z);
        final BuilderToolsPlugin.BuilderState.BlocksSampleData data = BuilderToolsPlugin.getState(this.player, this.player.getPlayerRef()).getBlocksSampleData(this.edit.getAccessor(), x, y, z, 2);
        if (currentBlock != data.mainBlock && data.mainBlockCount > this.smoothVolume * 0.5f) {
            this.edit.setBlock(x, y, z, data.mainBlock);
        }
        return true;
    }
}
