/**
* MrCrayfish's Furniture Mod
* Copyright (C) 2016 MrCrayfish (http://www.mrcrayfish.com/)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.mrcrayfish.furniture.network.message;
import java.util.Random;
import com.mrcrayfish.furniture.entity.EntitySittableBlock;
import com.mrcrayfish.furniture.init.FurnitureAchievements;
import io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
//Server Packet
public class MessageFart implements IMessage, IMessageHandler<MessageFart, IMessage>
{
private Random rand = new Random();
private double x, y, z;
public MessageFart()
{
}
public MessageFart(double posX, double posY, double posZ)
{
this.x = posX;
this.y = posY;
this.z = posZ;
}
@Override
public void fromBytes(ByteBuf buf)
{
this.x = buf.readDouble();
this.y = buf.readDouble();
this.z = buf.readDouble();
}
@Override
public void toBytes(ByteBuf buf)
{
buf.writeDouble(x);
buf.writeDouble(y);
buf.writeDouble(z);
}
@Override
public IMessage onMessage(MessageFart message, MessageContext ctx)
{
EntityPlayerMP player = ctx.getServerHandler().playerEntity;
if (player.ridingEntity instanceof EntitySittableBlock)
{
player.worldObj.playSoundEffect(message.x, message.y, message.z, "cfm:fart" + (rand.nextInt(3) + 1), 0.75F, 1.0F);
player.triggerAchievement(FurnitureAchievements.whatDidYouEat);
}
return null;
}
}