/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  meteordevelopment.orbit.ICancellable
 *  net.minecraft.class_1747
 *  net.minecraft.class_1750
 *  net.minecraft.class_2680
 *  org.spongepowered.asm.mixin.Mixin
 *  org.spongepowered.asm.mixin.Shadow
 *  org.spongepowered.asm.mixin.injection.At
 *  org.spongepowered.asm.mixin.injection.Inject
 *  org.spongepowered.asm.mixin.injection.ModifyVariable
 *  org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable
 */
package meteordevelopment.meteorclient.mixin;

import meteordevelopment.meteorclient.MeteorClient;
import meteordevelopment.meteorclient.events.entity.player.PlaceBlockEvent;
import meteordevelopment.meteorclient.systems.modules.Modules;
import meteordevelopment.meteorclient.systems.modules.world.NoGhostBlocks;
import meteordevelopment.orbit.ICancellable;
import net.minecraft.class_1747;
import net.minecraft.class_1750;
import net.minecraft.class_2680;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(value={class_1747.class})
public abstract class BlockItemMixin {
    @Shadow
    protected abstract class_2680 method_7707(class_1750 var1);

    @Inject(method={"method_7708(Lnet/minecraft/class_1750;Lnet/minecraft/class_2680;)Z"}, at={@At(value="HEAD")}, cancellable=true)
    private void onPlace(class_1750 context, class_2680 state, CallbackInfoReturnable<Boolean> info) {
        if (!context.method_8045().method_8608()) {
            return;
        }
        if (((PlaceBlockEvent)MeteorClient.EVENT_BUS.post((ICancellable)PlaceBlockEvent.get(context.method_8037(), state.method_26204()))).isCancelled()) {
            info.setReturnValue((Object)true);
        }
    }

    @ModifyVariable(method={"method_7712(Lnet/minecraft/class_1750;)Lnet/minecraft/class_1269;"}, ordinal=1, at=@At(value="INVOKE", target="Lnet/minecraft/class_2680;method_27852(Lnet/minecraft/class_2248;)Z"))
    private class_2680 modifyState(class_2680 state, class_1750 context) {
        NoGhostBlocks noGhostBlocks = Modules.get().get(NoGhostBlocks.class);
        if (noGhostBlocks.isActive() && noGhostBlocks.placing.get().booleanValue()) {
            return this.method_7707(context);
        }
        return state;
    }
}

