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

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

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

public class SmootherOperation extends ToolOperation
{
    private final float strength;
    
    public SmootherOperation(@Nonnull final Ref<EntityStore> ref, @Nonnull final Player player, @Nonnull final BuilderToolOnUseInteraction packet, @Nonnull final ComponentAccessor<EntityStore> componentAccessor) {
        super(ref, packet, componentAccessor);
        final boolean removing = packet.type == InteractionType.Primary;
        final int baseStrength = removing ? this.args.tool().get("RemoveStrength") : ((int)this.args.tool().get("AddStrength"));
        this.strength = 1.0f + (removing ? baseStrength : (-baseStrength)) * 0.01f;
    }
    
    @Override
    boolean execute0(final int x, final int y, final int z) {
        final int currentBlock = this.edit.getBlock(x, y, z);
        final BuilderToolsPlugin.BuilderState.SmoothSampleData data = this.builderState.getBlocksSmoothData(this.edit.getAccessor(), x, y, z);
        if (data.solidStrength > this.strength) {
            if (currentBlock != data.solidBlock) {
                this.edit.setBlock(x, y, z, data.solidBlock);
            }
        }
        else if (currentBlock != data.fillerBlock) {
            this.edit.setBlock(x, y, z, data.fillerBlock);
        }
        return true;
    }
}
