ActuallyAdditions/src/main/java/ellpeck/actuallyadditions/network/PacketCheckBook.java
2015-09-20 21:00:19 +02:00

59 lines
1.8 KiB
Java

/*
* This file ("PacketCheckBook.java") is part of the Actually Additions Mod for Minecraft.
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
* http://github.com/Ellpeck/ActuallyAdditions/blob/master/README.md
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
* © 2015 Ellpeck
*/
package ellpeck.actuallyadditions.network;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import ellpeck.actuallyadditions.util.PersistantVariables;
import io.netty.buffer.ByteBuf;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
public class PacketCheckBook implements IMessage{
@SuppressWarnings("unused")
public PacketCheckBook(){
}
private EntityPlayer player;
public PacketCheckBook(EntityPlayer player){
this.player = player;
}
@Override
public void fromBytes(ByteBuf buf){
this.player = (EntityPlayer)Minecraft.getMinecraft().theWorld.getEntityByID(buf.readInt());
}
@Override
public void toBytes(ByteBuf buf){
buf.writeInt(this.player.getEntityId());
}
public static class Handler implements IMessageHandler<PacketCheckBook, IMessage>{
@Override
@SideOnly(Side.CLIENT)
public IMessage onMessage(PacketCheckBook message, MessageContext ctx){
if(!PersistantVariables.getBoolean("BookGotten")){
PacketHandler.theNetwork.sendToServer(new PacketGiveBook(message.player));
PersistantVariables.setBoolean("BookGotten", true);
}
return null;
}
}
}