Package electricexpansion.common.blocks

Source Code of electricexpansion.common.blocks.BlockMultimeter

package electricexpansion.common.blocks;

import java.util.HashMap;

import net.minecraft.block.Block;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Icon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import universalelectricity.core.UniversalElectricity;
import universalelectricity.prefab.block.BlockAdvanced;
import universalelectricity.prefab.tile.TileEntityAdvanced;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import electricexpansion.common.ElectricExpansion;
import electricexpansion.common.misc.EETab;
import electricexpansion.common.tile.TileEntityMultimeter;

public class BlockMultimeter extends BlockAdvanced implements ITileEntityProvider
{
  private HashMap<String, Icon> icons = new HashMap<String, Icon>();

  public BlockMultimeter(int id, int textureIndex)
  {
    super(id, UniversalElectricity.machine);
    this.setStepSound(Block.soundMetalFootstep);
    this.setCreativeTab(EETab.INSTANCE);
    this.setUnlocalizedName("multimeter");
  }

  @Override
  @SideOnly(Side.CLIENT)
  public Icon getIcon(int side, int metadata)
  {
    if (side == 3)
      return this.icons.get("front");
    else
      return this.icons.get("machine");
  }

  @Override
  public Icon getBlockTexture(IBlockAccess par1IBlockAccess, int x, int y, int z, int side)
  {
    int metadata = par1IBlockAccess.getBlockMetadata(x, y, z);

    if (side == TileEntityMultimeter.ROTATION_MATRIX[metadata])
      return this.icons.get("output");
    else
      return this.icons.get("machine");
  }

  @Override
  @SideOnly(Side.CLIENT)
  public void registerIcons(IconRegister par1IconRegister)
  {
    this.icons.put("output", par1IconRegister.registerIcon(ElectricExpansion.PREFIX + "machineOutput"));
    this.icons.put("machine", par1IconRegister.registerIcon(ElectricExpansion.PREFIX + "machine"));
    this.icons.put("front", par1IconRegister.registerIcon(ElectricExpansion.PREFIX + "multimeter"));
  }

  /**
   * Called when the block is placed in the world.
   */
  @Override
  public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase par5EntityLiving, ItemStack itemStack)
  {
    int angle = MathHelper.floor_double(par5EntityLiving.rotationYaw * 4.0F / 360.0F + 0.5D) & 3;

    world.setBlock(x, y, z, this.blockID, angle + 2, 0);
    ((TileEntityAdvanced) world.getBlockTileEntity(x, y, z)).initiate();
    world.notifyBlocksOfNeighborChange(x, y, z, this.blockID);
  }

  @Override
  public boolean onUseWrench(World world, int x, int y, int z, EntityPlayer par5EntityPlayer, int side, float hitX, float hitY, float hitZ)
  {
    int original = world.getBlockMetadata(x, y, z);

    if (++original > 5)
      world.setBlock(x, y, z, this.blockID, 0, 0);
    else
      world.setBlock(x, y, z, this.blockID, original, 0);

    world.markBlockForRenderUpdate(x, y, z);
    ((TileEntityAdvanced) world.getBlockTileEntity(x, y, z)).initiate();
    world.notifyBlocksOfNeighborChange(x, y, z, this.blockID);
    return true;
  }

  @Override
  public boolean isOpaqueCube()
  {
    return true;
  }

  @Override
  public boolean renderAsNormalBlock()
  {
    return false;
  }

  @Override
  public TileEntity createNewTileEntity(World var1)
  {
    return new TileEntityMultimeter();
  }
}
TOP

Related Classes of electricexpansion.common.blocks.BlockMultimeter

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.