Guest User

Alloy Oven Class

a guest
Oct 22nd, 2014
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.72 KB | None | 0 0
  1. package com.arucraft.blocks;
  2.  
  3. import java.util.Random;
  4.  
  5. import net.minecraft.block.Block;
  6. import net.minecraft.block.BlockContainer;
  7. import net.minecraft.block.material.Material;
  8. import net.minecraft.client.renderer.texture.IIconRegister;
  9. import net.minecraft.entity.EntityLivingBase;
  10. import net.minecraft.entity.player.EntityPlayer;
  11. import net.minecraft.item.ItemStack;
  12. import net.minecraft.tileentity.TileEntity;
  13. import net.minecraft.util.IIcon;
  14. import net.minecraft.util.MathHelper;
  15. import net.minecraft.world.World;
  16.  
  17. import com.arucraft.ArucraftMain;
  18. import com.arucraft.tileentity.TileEntityAlloyOven;
  19.  
  20. import cpw.mods.fml.common.network.internal.FMLNetworkHandler;
  21. import cpw.mods.fml.relauncher.Side;
  22. import cpw.mods.fml.relauncher.SideOnly;
  23.  
  24. public class AlloyOven extends BlockContainer {
  25.  
  26.     private Random rand;
  27.     private final boolean isActive;
  28.     private static boolean keepInventory = true;
  29.  
  30.     @SideOnly(Side.CLIENT)
  31.     private IIcon iconFront;
  32.  
  33.     public AlloyOven(boolean blockState) {
  34.         super(Material.iron);
  35.         rand = new Random();
  36.         isActive = blockState;
  37.  
  38.     }
  39.  
  40.     @SideOnly(Side.CLIENT)
  41.     public void registerBlockIcons(IIconRegister iconRegister) {
  42.         this.blockIcon = iconRegister.registerIcon(ArucraftMain.modID + ":" + (this.isActive ? "AlloyOvenSideOn" : "AlloyOvenSideOff"));
  43.         this.iconFront = iconRegister.registerIcon(ArucraftMain.modID + ":" + (this.isActive ? "AlloyOvenFrontOn" : "AlloyOvenFrontOff"));
  44.     }
  45.  
  46.     public void onBlockAdded(World world, int x, int y, int z) {
  47.         super.onBlockAdded(world, x, y, z);
  48.         this.setDefaultDirection(world, x, y, z);      
  49.     }
  50.  
  51.     private void setDefaultDirection(World world, int x, int y, int z) {
  52.  
  53.         if(!world.isRemote) {
  54.             Block block1 = world.getBlock(x, y, z -1);
  55.             Block block2 = world.getBlock(x, y, z + 1);
  56.             Block block3 = world.getBlock(x - 1, y, z);
  57.             Block block4 = world.getBlock(x + 1, y, z);
  58.  
  59.             byte b0 = 3;
  60.  
  61.             if(block1.func_149730_j() && !block2.func_149730_j()) {
  62.                 b0 = 3;
  63.             }
  64.  
  65.             if(block2.func_149730_j() && !block1.func_149730_j()) {
  66.                 b0 = 2;
  67.             }
  68.             if(block3.func_149730_j() && !block4.func_149730_j()) {
  69.                 b0 = 5;
  70.             }
  71.  
  72.             if(block4.func_149730_j() && !block3.func_149730_j()) {
  73.                 b0 = 4;
  74.             }
  75.  
  76.             world.setBlockMetadataWithNotify(x, y, z, b0, 2);
  77.  
  78.         }
  79.     }
  80.  
  81.     public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityPlayer, ItemStack itemstack) {
  82.         int i = MathHelper.floor_double((double)(entityPlayer.rotationYaw * 4.0F / 360F) + 0.5D) & 3;
  83.  
  84.         if (i == 0) {
  85.             world.setBlockMetadataWithNotify(x, y, z, 2, 2);
  86.         }
  87.  
  88.         if (i == 1) {
  89.             world.setBlockMetadataWithNotify(x, y, z, 5, 2);
  90.         }
  91.         if (i == 2) {
  92.             world.setBlockMetadataWithNotify(x, y, z, 3, 2);
  93.         }
  94.         if (i == 3) {
  95.             world.setBlockMetadataWithNotify(x, y, z, 4, 2);
  96.         }
  97.  
  98.         if(itemstack.hasDisplayName()) {
  99.             //((TileEntityAlloyOver)world.getTileEntity(x, y, z)).setCustomName(itemstack.getDisplayName());
  100.         }
  101.     }
  102.  
  103.     public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
  104.         if (world.isRemote) {
  105.             return true;
  106.         }else if (!player.isSneaking()) {
  107.             TileEntityAlloyOven entity = (TileEntityAlloyOven) world.getTileEntity(x, y, z);
  108.             if (entity != null) {
  109.                 FMLNetworkHandler.openGui(player, ArucraftMain.instance, ArucraftMain.guiIDAlloyOven, world, x, y, z);
  110.             }
  111.  
  112.             return true;
  113.         }else{
  114.             return false;
  115.         }
  116.     }
  117.  
  118.  
  119.  
  120.     @Override
  121.     public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_) {
  122.         return new TileEntityAlloyOven();
  123.     }
  124.  
  125.     @SideOnly(Side.CLIENT)
  126.     public IIcon getIcon(int side, int metadata) {
  127.         return metadata == 0 ? this.iconFront : (side == metadata ? this.iconFront : this.blockIcon);
  128.     }
  129.  
  130. }
Advertisement
Add Comment
Please, Sign In to add comment