/** * 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 com.mrcrayfish.furniture.blocks.tv.Channels; import io.netty.buffer.ByteBuf; import net.minecraft.client.Minecraft; import net.minecraft.util.math.BlockPos; import net.minecraftforge.fml.common.network.simpleimpl.IMessage; import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; public class MessageTVClient implements IMessage, IMessageHandler<MessageTVClient, IMessage> { private int channel, x, y, z; public MessageTVClient() { } public MessageTVClient(int channel, BlockPos pos) { this.channel = channel; this.x = pos.getX(); this.y = pos.getY(); this.z = pos.getZ(); } @Override public void fromBytes(ByteBuf buf) { this.channel = buf.readInt(); this.x = buf.readInt(); this.y = buf.readInt(); this.z = buf.readInt(); } @Override public void toBytes(ByteBuf buf) { buf.writeInt(channel); buf.writeInt(x); buf.writeInt(y); buf.writeInt(z); } @Override public IMessage onMessage(MessageTVClient message, MessageContext ctx) { if (ctx.side.isClient()) { BlockPos pos = new BlockPos(message.x, message.y, message.z); Minecraft.getMinecraft().theWorld.markBlockRangeForRenderUpdate(pos, pos); Channels.getChannel(message.channel).play(pos); } return null; } }