tterrag1098

Untitled

Nov 4th, 2013
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.17 KB | None | 0 0
  1. package stevesExample.block;
  2.  
  3. import java.util.List;
  4.  
  5. import net.minecraft.block.Block;
  6. import net.minecraft.block.material.Material;
  7. import net.minecraft.client.renderer.texture.IconRegister;
  8. import net.minecraft.creativetab.CreativeTabs;
  9. import net.minecraft.entity.Entity;
  10. import net.minecraft.entity.player.EntityPlayer;
  11. import net.minecraft.item.Item;
  12. import net.minecraft.item.ItemStack;
  13. import net.minecraft.util.Icon;
  14. import net.minecraft.world.World;
  15. import stevesExample.item.ItemInfo;
  16. import cpw.mods.fml.relauncher.Side;
  17. import cpw.mods.fml.relauncher.SideOnly;
  18.  
  19. public class BlockMachine extends Block
  20. {
  21.     public BlockMachine(int id)
  22.     {
  23.         super(id , Material.rock);
  24.  
  25.         setCreativeTab(CreativeTabs.tabRedstone);
  26.         setHardness(2F);
  27.         setStepSound(Block.soundStoneFootstep);
  28.         setUnlocalizedName(BlockInfo.MACHINE_UNLOC_NAME);
  29.  
  30.     }
  31.  
  32.     @SideOnly(Side.CLIENT)
  33.     private Icon topIcon;
  34.     @SideOnly(Side.CLIENT)
  35.     private Icon bottomIcon;
  36.     @SideOnly(Side.CLIENT)
  37.     private Icon[] sideIcons;
  38.     @SideOnly(Side.CLIENT)
  39.     private Icon disableIcon;
  40.  
  41.     @SideOnly(Side.CLIENT)
  42.     @Override
  43.     public void registerIcons(IconRegister register)
  44.     {
  45.         topIcon = register.registerIcon(BlockInfo.TEXTURE_LOC + ":"
  46.                 + BlockInfo.MACHINE_TOP);
  47.         bottomIcon = register.registerIcon(BlockInfo.TEXTURE_LOC + ":"
  48.                 + BlockInfo.MACHINE_BOTTOM);
  49.         sideIcons = new Icon[BlockInfo.MACHINE_SIDES.length];
  50.         for (int i = 0; i < sideIcons.length; i++)
  51.         {
  52.             sideIcons[i] = register.registerIcon(BlockInfo.TEXTURE_LOC + ":"
  53.                     + BlockInfo.MACHINE_SIDES[i]);
  54.         }
  55.         disableIcon = register.registerIcon(BlockInfo.TEXTURE_LOC + ":"
  56.                 + BlockInfo.MACHINE_DISABLED);
  57.     }
  58.  
  59.     @SideOnly(Side.CLIENT)
  60.     @Override
  61.     public Icon getIcon(int side, int meta)
  62.     {
  63.         if (side == 0)
  64.             return bottomIcon;
  65.         else if (side == 1)
  66.             return isDisabled(meta) ? disableIcon : topIcon;
  67.         else
  68.         {
  69.             int type = meta / 2;
  70.             if (type == 4)
  71.                 type = 0;
  72.             return sideIcons[type];
  73.         }
  74.     }
  75.  
  76.     private boolean isDisabled(int meta)
  77.     {
  78.         return meta % 2 == 1;
  79.     }
  80.  
  81.     @Override
  82.     public void onEntityWalking(World world, int x, int y, int z, Entity entity)
  83.     {
  84.         if (!world.isRemote && !isDisabled(world.getBlockMetadata(x , y , z)))
  85.         {
  86.             spawnAnvil(world , x , y + 20 , z);
  87.         }
  88.     }
  89.  
  90.     @Override
  91.     public void onNeighborBlockChange(World world, int x, int y, int z, int id)
  92.     {
  93.         int meta = world.getBlockMetadata(x , y , z);
  94.  
  95.         if (world.isBlockIndirectlyGettingPowered(x , y , z) && !world.isRemote
  96.                 && !isDisabled(meta))
  97.         {
  98.             switch (meta / 2)
  99.             {
  100.                 case 1:
  101.                     for (int i = 0; i < 5; i++)
  102.                         spawnAnvil(world , x , y + 20 + i , z);
  103.                     break;
  104.                 case 2:
  105.                     for (int i = -1; i <= 1; i++)
  106.                     {
  107.                         spawnAnvil(world , x + i , y + 20 + i , z - 2);
  108.                         spawnAnvil(world , x + i , y + 20 + i , z + 2);
  109.                         spawnAnvil(world , x - 2 , y + 20 + i , z + i);
  110.                         spawnAnvil(world , x + 2 , y + 20 + i , z + i);
  111.                     }
  112.  
  113.                     break;
  114.                 case 3:
  115.                     for (int i = 1; i <= 3; i++)
  116.                     {
  117.                         spawnAnvil(world , x + i , y + 20 + i , z);
  118.                         spawnAnvil(world , x - i , y + 20 + i , z);
  119.                         spawnAnvil(world , x , y + 20 + i , z + i);
  120.                         spawnAnvil(world , x , y + 20 + i , z - i);
  121.                     }
  122.                     break;
  123.                 default:
  124.                     // spawnAnvil(world, x, y + 20, z);
  125.                     for (int i = 0; i < 5; i++)
  126.                         for (int j = 0; j < 5; j++)
  127.                             spawnAnvil(world , x - 2 + i , y + 20 , z - 2 + j);
  128.             }
  129.             world.setBlockMetadataWithNotify(x , y , z , 1 , 3);
  130.         }
  131.     }
  132.  
  133.     private void spawnAnvil(World world, int x, int y, int z)
  134.     {
  135.         if (world.isAirBlock(x , y , z))
  136.             world.setBlock(x , y , z , Block.anvil.blockID);
  137.     }
  138.  
  139.     @Override
  140.     public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ)
  141.     {
  142.         if (!world.isRemote)
  143.         {
  144.             int meta = world.getBlockMetadata(x , y , z);
  145.  
  146.             int type = meta / 2;
  147.  
  148.             int disabled = meta % 2 == 0 ? 1 : 0;
  149.  
  150.             int newMeta = type * 2 + disabled;
  151.  
  152.             ItemStack itemStack = player.getItemInUse();
  153.  
  154.             if (meta == 0)
  155.             {
  156.                 world.setBlockMetadataWithNotify(x , y , z , meta + 1 , 3);
  157.                 player.dropItem(ItemInfo.CARD_ID + 256 , 1).getEntityItem()
  158.                         .setItemDamage(3);
  159.             }
  160.             else if (meta != 1)
  161.             {
  162.                 setMetaAndDropItem(world , x , y , z , player , disabled , meta);
  163.             }
  164.         }
  165.         return true;
  166.     }
  167.  
  168.     public static void setMetaAndDropItem(World world, int x, int y, int z, EntityPlayer player, int disabled, int meta)
  169.     {
  170.         ItemStack stack = player.getItemInUse();
  171.  
  172.         if (meta % 2 == 0 && stack == null)
  173.         {
  174.             player.dropItem(ItemInfo.CARD_ID + 256, 1).getEntityItem().setItemDamage(3);
  175.             world.setBlockMetadataWithNotify(x , y , z , meta + 1 , 3);
  176.         }
  177.         else if (meta % 2 == 1 && stack == null && meta != 1)
  178.         {
  179.             player.dropItem(ItemInfo.CARD_ID + 256 , 1).getEntityItem().setItemDamage(meta / 2 - 1);
  180.             world.setBlockMetadataWithNotify(x , y , z , 1 , 3);
  181.         }
  182.     }
  183.  
  184.     @Override
  185.     public int damageDropped(int meta)
  186.     {
  187.         return meta;
  188.     }
  189.  
  190.     @Override
  191.     @SideOnly(Side.CLIENT)
  192.     public void getSubBlocks(int id, CreativeTabs tab, List list)
  193.     {
  194.         for (int i = 0; i < BlockInfo.MACHINE_SIDES.length; i++)
  195.         {
  196.             list.add(new ItemStack(id , 1 , i * 2));
  197.         }
  198.     }
  199. }
Advertisement
Add Comment
Please, Sign In to add comment