Guest User

BlockOven.java

a guest
Jun 21st, 2014
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.61 KB | None | 0 0
  1. package tk.yteditors.requiredstuffz.block;
  2.  
  3. import net.minecraft.block.Block;
  4. import net.minecraft.block.material.Material;
  5. import net.minecraft.client.renderer.texture.IIconRegister;
  6. import net.minecraft.creativetab.CreativeTabs;
  7. import net.minecraft.entity.EntityLivingBase;
  8. import net.minecraft.init.Blocks;
  9. import net.minecraft.item.Item;
  10. import net.minecraft.item.ItemStack;
  11. import net.minecraft.tileentity.TileEntity;
  12. import net.minecraft.tileentity.TileEntityFurnace;
  13. import net.minecraft.util.IIcon;
  14. import net.minecraft.util.MathHelper;
  15. import net.minecraft.world.World;
  16. import tk.yteditors.requiredstuffz.reference.ModInfo;
  17. import cpw.mods.fml.relauncher.Side;
  18. import cpw.mods.fml.relauncher.SideOnly;
  19.  
  20. public class BlockOven extends Block {
  21.    
  22.     @SideOnly(Side.CLIENT)
  23.     private IIcon   blockIconFront,
  24.                     blockIconTop,
  25.                     blockIconSide;
  26.  
  27.     int rotation;
  28.  
  29.     public BlockOven() {
  30.         super(Material.rock);
  31.         setBlockName("blockOven");
  32.         setCreativeTab(CreativeTabs.tabBlock);
  33.         setStepSound(this.soundTypeStone);
  34.         setHardness(2f);
  35.         setResistance(3.5f);
  36.         setHarvestLevel("pickaxe", 0);
  37.     }
  38.    
  39.     @SideOnly(Side.CLIENT)
  40.     public void registerBlockIcons(IIconRegister register) {
  41.         blockIconFront = register.registerIcon(ModInfo.modId + ":" + getUnlocalizedName().substring(5) + "_front");
  42.         blockIconTop = register.registerIcon(ModInfo.modId + ":" + getUnlocalizedName().substring(5) + "_top");
  43.         blockIconSide = register.registerIcon(ModInfo.modId + ":" + getUnlocalizedName().substring(5) + "_side");
  44.     }
  45.    
  46.     /**
  47.      * Return icons
  48.      */
  49.     @SideOnly(Side.CLIENT)
  50.     public IIcon getIcon(int side, int metadata) {
  51.         System.out.println(side);
  52.         if (side == 0 || side == 1) {
  53.             return blockIconTop;
  54.         } else if (metadata == side) {
  55.             return blockIconFront;
  56.         }
  57.         return blockIconSide;
  58.     }
  59.    
  60.     /**
  61.      * Set block orientation according to player's face
  62.      */
  63.     @Override
  64.     public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityliving, ItemStack itemStack) {
  65.         byte direction = 0;
  66.         int facing = MathHelper.floor_double((double) ((entityliving.rotationYaw * 4F) / 360F) + 0.5D) & 3;
  67.        
  68.         if (facing == 0) {
  69.             direction = 2;
  70.         }
  71.         if (facing == 1) {
  72.             direction = 5;
  73.         }
  74.         if (facing == 2) {
  75.             direction = 3;
  76.         }
  77.         if (facing == 3) {
  78.             direction = 4;
  79.         }
  80.        
  81.         world.setBlockMetadataWithNotify(x, y, z, direction, 2);
  82.         System.out.println(direction);
  83.     }
  84.    
  85.     /**
  86.      * Gets an item for the block being called on.
  87.      */
  88.     @SideOnly(Side.CLIENT)
  89.     public Item getItem(World world, int x, int y, int z){
  90.         return Item.getItemFromBlock(this);
  91.     }
  92.    
  93. }
Advertisement
Add Comment
Please, Sign In to add comment