Guest User

Untitled

a guest
Aug 3rd, 2014
345
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.38 KB | None | 0 0
  1. package lrrp.compat.block;
  2.  
  3. import cpw.mods.fml.common.registry.GameRegistry;
  4. import cpw.mods.fml.common.registry.LanguageRegistry;
  5. import lrrp.compat.tile.TileEntityCCRedNetInterface;
  6. import dan200.computercraft.api.ComputerCraftAPI;
  7. import dan200.computercraft.api.redstone.IBundledRedstoneProvider;
  8. import net.minecraft.block.BlockContainer;
  9. import net.minecraft.block.material.Material;
  10. import net.minecraft.creativetab.CreativeTabs;
  11. import net.minecraft.tileentity.TileEntity;
  12. import net.minecraft.world.World;
  13. import net.minecraftforge.common.ForgeDirection;
  14. import powercrystals.minefactoryreloaded.api.rednet.IConnectableRedNet;
  15. import powercrystals.minefactoryreloaded.api.rednet.RedNetConnectionType;
  16.  
  17. public class BlockCCRedNetInterface extends BlockContainer implements IConnectableRedNet, IBundledRedstoneProvider {
  18.  
  19.     public static final String BLOCK_NAME = "ccrednetinterface";
  20.     public static int blockID;
  21.    
  22.     public BlockCCRedNetInterface(int blockID)
  23.     {
  24.         super(blockID, Material.wood);
  25.         BlockCCRedNetInterface.blockID = blockID;      
  26.        
  27.         setUnlocalizedName(BLOCK_NAME);    
  28.         setCreativeTab(CreativeTabs.tabBlock);
  29.         setHardness(2.0f);
  30.         setResistance(5.0f);
  31.         setStepSound(soundWoodFootstep);       
  32.        
  33.         GameRegistry.registerBlock     (this, BLOCK_NAME);
  34.         LanguageRegistry.addName       (this, "CC/RedNet Interface");
  35.         GameRegistry.registerTileEntity(TileEntityCCRedNetInterface.class, BLOCK_NAME + ":TileEntityCCRedNetInterface");
  36.        
  37.         ComputerCraftAPI.registerBundledRedstoneProvider(this);
  38.     }
  39.    
  40.     @Override
  41.     public TileEntity createNewTileEntity(World world)
  42.     {
  43.         return new TileEntityCCRedNetInterface();
  44.     }
  45.  
  46.     /* MineFactoryReloaded API */  
  47.     @Override
  48.     public RedNetConnectionType getConnectionType(World world, int x, int y, int z, ForgeDirection side)
  49.     {
  50.         return RedNetConnectionType.CableAll;
  51.     }
  52.  
  53.     @Override
  54.     public int[] getOutputValues(World world, int x, int y, int z, ForgeDirection side)
  55.     {
  56.         TileEntity te = world.getBlockTileEntity(x, y, z);
  57.         if (!(te instanceof TileEntityCCRedNetInterface))
  58.           return new int[16];
  59.        
  60.         return ((TileEntityCCRedNetInterface)te).getOutputValues();
  61.     }
  62.  
  63.     @Override
  64.     public int getOutputValue(World world, int x, int y, int z, ForgeDirection side, int subnet)
  65.     {
  66.         TileEntity te = world.getBlockTileEntity(x, y, z);
  67.         if (!(te instanceof TileEntityCCRedNetInterface))
  68.           return 0;    
  69.        
  70.         return ((TileEntityCCRedNetInterface)te).getOutputValue(subnet);   
  71.     }
  72.  
  73.     @Override
  74.     public void onInputsChanged(World world, int x, int y, int z, ForgeDirection side, int[] inputValues)
  75.     {
  76.         TileEntity te = world.getBlockTileEntity(x, y, z);
  77.         if (!(te instanceof TileEntityCCRedNetInterface))
  78.           return;      
  79.        
  80.         ((TileEntityCCRedNetInterface)te).setOutputValues(inputValues);
  81.     }
  82.  
  83.     @Override
  84.     public void onInputChanged(World world, int x, int y, int z, ForgeDirection side, int inputValue)
  85.     {
  86.         /* not used as we are not in single mode */
  87.     }
  88.  
  89.     /* ComputerCraft API */
  90.     @Override
  91.     public int getBundledRedstoneOutput(World world, int x, int y, int z, int side)
  92.     {
  93.         TileEntity te = world.getBlockTileEntity(x, y, z);
  94.         if (!(te instanceof TileEntityCCRedNetInterface))
  95.           return 0;    
  96.        
  97.         int[] values = ((TileEntityCCRedNetInterface)te).getOutputValues();
  98.         int output = 0;
  99.        
  100.         for(int i = 0; i < values.length; ++i)
  101.             if (values[i] > 0)
  102.                 output |= 1 << i;
  103.        
  104.         return output;
  105.     }  
  106. }
Advertisement
Add Comment
Please, Sign In to add comment