package mcjty.rftools.blocks.logic.wireless;

import mcjty.lib.container.GenericItemBlock;
import mcjty.lib.varia.Logging;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.World;

public class RedstoneReceiverItemBlock extends GenericItemBlock {
    public RedstoneReceiverItemBlock(Block block) {
        super(block);
    }

    @Override
    public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
        ItemStack stack = player.getHeldItem(hand);
        TileEntity te = world.getTileEntity(pos);
        if (te instanceof RedstoneTransmitterTileEntity) {
            RedstoneTransmitterTileEntity redstoneTransmitterTileEntity = (RedstoneTransmitterTileEntity) te;
            int channel = redstoneTransmitterTileEntity.getChannel();
            if (channel == -1) {
                Logging.message(player, TextFormatting.YELLOW + "This transmitter has no channel!");
            } else {
                NBTTagCompound tagCompound = stack.getTagCompound();
                if (tagCompound == null) {
                    tagCompound = new NBTTagCompound();
                }
                tagCompound.setInteger("channel", channel);
                stack.setTagCompound(tagCompound);
                if (world.isRemote) {
                    Logging.message(player, TextFormatting.YELLOW + "Channel set to " + channel + "!");
                }
            }
        } else if (te instanceof RedstoneReceiverTileEntity) {
            RedstoneReceiverTileEntity redstoneReceiverTileEntity = (RedstoneReceiverTileEntity) te;
            int channel = redstoneReceiverTileEntity.getChannel();
            if (channel == -1) {
                Logging.message(player, TextFormatting.YELLOW + "This receiver has no channel!");
            } else {
                NBTTagCompound tagCompound = stack.getTagCompound();
                if (tagCompound == null) {
                    tagCompound = new NBTTagCompound();
                }
                tagCompound.setInteger("channel", channel);
                stack.setTagCompound(tagCompound);
                if (world.isRemote) {
                    Logging.message(player, TextFormatting.YELLOW + "Channel set to " + channel + "!");
                }
                if (world.isRemote) {
                    Logging.message(player, TextFormatting.YELLOW + "Channel set to " + channel + "!");
                }
            }
        } else {
            return super.onItemUse(player, world, pos, hand, facing, hitX, hitY, hitZ);
        }
        return EnumActionResult.SUCCESS;
    }
}

@@ -1013,35 +1013,31 @@
 eof Redstone
-Transmitter
+Channel
 TileEntity) 
@@ -1062,49 +1062,15 @@
 tone
-TransmitterTileEntity redstoneTransmitter
+Channel
 Tile
@@ -1076,27 +1076,24 @@
 eEntity 
-= (
 Redstone
 Transmit
@@ -1088,871 +1088,94 @@
 tone
-TransmitterTileEntity) te;%0A            int channel = redstoneTransmitterTileEntity.getChannel();%0A            if (channel == -1) %7B%0A                Logging.message(player, TextFormatting.YELLOW + %22This transmitter has no channel!%22);%0A            %7D else %7B%0A                NBTTagCompound tagCompound = stack.getTagCompound();%0A                if (tagCompound == null) %7B%0A                    tagCompound = new NBTTagCompound();%0A                %7D%0A                tagCompound.setInteger(%22channel%22, channel);%0A                stack.setTagCompound(tagCompound);%0A                if (world.isRemote) %7B%0A                    Logging.message(player, TextFormatting.YELLOW + %22Channel set to %22 + channel + %22!%22);%0A                %7D%0A            %7D%0A        %7D else if (te instanceof RedstoneReceiverTileEntity) %7B%0A            RedstoneReceiverTileEntity redstoneReceiverTileEntity
+ChannelTileEntity = (RedstoneChannelTileEntity) te;%0A            int channel
  = 
-(
 Redstone
 Rece
@@ -1174,74 +1174,15 @@
 tone
-ReceiverTileEntity) te;%0A            int channel = redstoneReceiver
+Channel
 Tile
@@ -1309,16 +1309,13 @@
 his 
-receiver
+block
  has
@@ -1812,168 +1812,8 @@
   %7D%0A
-                if (world.isRemote) %7B%0A                    Logging.message(player, TextFormatting.YELLOW + %22Channel set to %22 + channel + %22!%22);%0A                %7D%0A
     

Remove duplication in RedstoneReceiverItemBlock