hellfirepvp.astralsorcery.common.network.packet.server.PktSyncStepAssist.java Source code

Java tutorial

Introduction

Here is the source code for hellfirepvp.astralsorcery.common.network.packet.server.PktSyncStepAssist.java

Source

/*******************************************************************************
 * HellFirePvP / Astral Sorcery 2017
 *
 * This project is licensed under GNU GENERAL PUBLIC LICENSE Version 3.
 * The source code is available on github: https://github.com/HellFirePvP/AstralSorcery
 * For further details, see the License file there.
 ******************************************************************************/

package hellfirepvp.astralsorcery.common.network.packet.server;

import io.netty.buffer.ByteBuf;
import net.minecraft.client.Minecraft;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

/**
 * This class is part of the Astral Sorcery Mod
 * The complete source code for this mod can be found on github.
 * Class: PktSyncStepAssist
 * Created by HellFirePvP
 * Date: 06.04.2017 / 23:44
 */
public class PktSyncStepAssist implements IMessage, IMessageHandler<PktSyncStepAssist, IMessage> {

    public float stepHeight;

    public PktSyncStepAssist() {
    }

    public PktSyncStepAssist(float stepHeight) {
        this.stepHeight = stepHeight;
    }

    @Override
    public void fromBytes(ByteBuf buf) {
        this.stepHeight = buf.readFloat();
    }

    @Override
    public void toBytes(ByteBuf buf) {
        buf.writeFloat(this.stepHeight);
    }

    @Override
    public IMessage onMessage(PktSyncStepAssist message, MessageContext ctx) {
        apply(message.stepHeight);
        return null;
    }

    @SideOnly(Side.CLIENT)
    public void apply(float stepHeight) {
        Minecraft.getMinecraft().player.stepHeight = stepHeight;
    }

}