/*
 *  This file is part of Cubic Chunks Mod, licensed under the MIT License (MIT).
 *
 *  Copyright (c) 2015-2019 OpenCubicChunks
 *  Copyright (c) 2015-2019 contributors
 *
 *  Permission is hereby granted, free of charge, to any person obtaining a copy
 *  of this software and associated documentation files (the "Software"), to deal
 *  in the Software without restriction, including without limitation the rights
 *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 *  copies of the Software, and to permit persons to whom the Software is
 *  furnished to do so, subject to the following conditions:
 *
 *  The above copyright notice and this permission notice shall be included in
 *  all copies or substantial portions of the Software.
 *
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 *  THE SOFTWARE.
 */
package io.github.opencubicchunks.cubicchunks.core.asm.mixin.fixes.common;

import com.google.common.primitives.Doubles;
import com.google.common.primitives.Floats;
import net.minecraft.network.NetHandlerPlayServer;
import net.minecraft.network.play.client.CPacketPlayer;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;

@Mixin(NetHandlerPlayServer.class)
public class MixinNetHandlerPlayServer {

    /**
     * @author Barteks2x
     * @reason modify to check for infinite Y and not check for limited Y
     */
    @Overwrite
    private static boolean isMovePlayerPacketInvalid(CPacketPlayer packetIn) {
        if (Doubles.isFinite(packetIn.getX(0.0D)) && Doubles.isFinite(packetIn.getY(0.0D)) && Doubles.isFinite(packetIn.getZ(0.0D)) && Floats
                .isFinite(packetIn.getPitch(0.0F)) && Floats.isFinite(packetIn.getYaw(0.0F))) {
            return Math.abs(packetIn.getX(0.0D)) > 3.0E7D /*|| Math.abs(packetIn.getY(0.0D)) > 3.0E7D*/ || Math.abs(packetIn.getZ(0.0D)) > 3.0E7D;
        } else {
            return true;
        }
    }
}

@@ -1346,195 +1346,196 @@
 ort 
-com.google.common.primitives.Doubles;%0Aimport com.google.common.primitives.Floats;%0Aimport net.minecraft.network.NetHandlerPlayServer;%0Aimport net.minecraft.network.play.client.CPacketPlayer
+net.minecraft.network.NetHandlerPlayServer;%0Aimport org.spongepowered.asm.mixin.Mixin;%0Aimport org.spongepowered.asm.mixin.injection.At;%0Aimport org.spongepowered.asm.mixin.injection.Constant
 ;%0Aim
@@ -1559,37 +1559,56 @@
 wered.asm.mixin.
-Mixin
+injection.ModifyConstant
 ;%0Aimport org.spo
@@ -1628,24 +1628,30 @@
 m.mixin.
-Overwrit
+injection.Slic
 e;%0A%0A@Mix
@@ -1731,649 +1731,526 @@
     
-/**%0A     * @author Barteks2x%0A     * @reason modify to check for infinite Y and not check for limited Y%0A
+@ModifyConstant(method = %22isMovePlayerPacketInvalid%22,%0A            slice = @Slice(%0A       
      
-*/%0A
     
-@Overwrite%0A    private static boolean isMovePlayerPacketInvalid(CPacketPlayer packetIn) %7B%0A        if (Doubles.isFinite(packetIn.getX(0.0D)) && Doubles.isFinite(packetIn.getY(0.0D)) && Doubles.isFinite(packetIn.getZ(0.0D)) && Floats%0A                .isFinite(packetIn.getPitch(0.0F)) && Floats.isFinite(packetIn.getYaw(0.0F))) %7B%0A            return Math.abs(packetIn.getX(0.0D)) %3E 3.0E7D /*%7C%7C Math.abs(packetIn.getY(0.0D)) %3E 3.0E7D*/ %7C%7C Math.abs(packetIn.getZ(0.0D)) %3E 3.0E7D;%0A        %7D else %7B%0A            return true;%0A        %7D
+    from = @At(value = %22INVOKE:LAST%22, target = %22Lnet/minecraft/network/play/client/CPacketPlayer;getY(D)D%22),%0A                    to = @At(value = %22INVOKE:LAST%22, target = %22Lnet/minecraft/network/play/client/CPacketPlayer;getZ(D)D%22)%0A            ),%0A            constant = @Constant(doubleValue = 3.0E7D),%0A            require = 0%0A    )%0A    private static double getMaxY(double old) %7B%0A        return Integer.MAX_VALUE - 4096;
 %0A   

Fix #461 - use ModifyConstant instead of Overwrite