Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package RUMatter.blocks;
- import net.minecraft.block.Block;
- import net.minecraft.block.BlockContainer;
- import net.minecraft.block.material.Material;
- 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.World;
- import RUMatter.RUCraft;
- import RUMatter.RUCreativeTabs;
- import RUMatter.tileEntities.TileEntityRUMad;
- import cpw.mods.fml.relauncher.Side;
- import cpw.mods.fml.relauncher.SideOnly;
- public class BlockRUMad extends BlockContainer {
- public BlockRUMad(int id) {
- super(id, Material.iron);
- this.setCreativeTab(RUCreativeTabs.RUTab);
- this.setHardness(2F);
- this.setStepSound(soundMetalFootstep);
- this.setUnlocalizedName(BlockInfo.RUMad_UNLOCALISED_NAME);
- }
- @Override
- public void onBlockAdded(World world, int x, int y, int z) {
- super.onBlockAdded(world, x, y, z);
- setDefaultDirection(world, x, y, z);
- }
- // @param World, the world instance,
- // @param int x, y, z, the blocks x, y, and z coords
- // @param EntityPlayer, the player
- // @param int i, this is not really used in this along with the rest (float
- // f, float g, and float t)
- @Override
- public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int i, float f, float g, float t) {
- TileEntityRUMad tile = (TileEntityRUMad) world.getBlockTileEntity(x, y, z);
- if (tile != null || player.isSneaking()) {
- if (!world.isRemote) {
- player.addChatMessage("RUMad energy level: " + tile.energy);
- return true;
- } else if (world.isRemote) player.openGui(RUCraft.instance, 1, world, x, y, z);
- }
- return false;
- }
- @SideOnly(Side.CLIENT)
- Icon bottomTexture;
- @SideOnly(Side.CLIENT)
- Icon frontTexture;
- @SideOnly(Side.CLIENT)
- Icon sideTexture;
- @Override
- @SideOnly(Side.CLIENT)
- public void registerIcons(IconRegister register) {
- this.blockIcon = register.registerIcon(BlockInfo.Textures.RUMadTop.toString());
- this.bottomTexture = register.registerIcon(BlockInfo.Textures.RUMadBottom.toString());
- this.frontTexture = register.registerIcon(BlockInfo.Textures.RUMadFront.toString());
- this.sideTexture = register.registerIcon(BlockInfo.Textures.RUMadSide.toString());
- }
- @Override
- @SideOnly(Side.CLIENT)
- public Icon getIcon(int side, int metadata) {
- if (side == 0)
- return bottomTexture;
- else if (side == 1)
- return blockIcon;
- else if (side == metadata)
- return frontTexture;
- else return sideTexture;
- }
- /**
- * set a blocks direction
- */
- private void setDefaultDirection(World par1World, int par2, int par3, int par4) {
- if (!par1World.isRemote) {
- int l = par1World.getBlockId(par2, par3, par4 - 1);
- int i1 = par1World.getBlockId(par2, par3, par4 + 1);
- int j1 = par1World.getBlockId(par2 - 1, par3, par4);
- int k1 = par1World.getBlockId(par2 + 1, par3, par4);
- byte b0 = 3;
- if (Block.opaqueCubeLookup[l] && !Block.opaqueCubeLookup[i1]) {
- b0 = 3;
- }
- if (Block.opaqueCubeLookup[i1] && !Block.opaqueCubeLookup[l]) {
- b0 = 2;
- }
- if (Block.opaqueCubeLookup[j1] && !Block.opaqueCubeLookup[k1]) {
- b0 = 5;
- }
- if (Block.opaqueCubeLookup[k1] && !Block.opaqueCubeLookup[j1]) {
- b0 = 4;
- }
- par1World.setBlockMetadataWithNotify(par2, par3, par4, b0, 2);
- }
- }
- /**
- * Called when the block is placed in the world.
- */
- public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLivingBase par5EntityLivingBase, ItemStack par6ItemStack) {
- int l = MathHelper.floor_double((double) (par5EntityLivingBase.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
- if (l == 0) {
- par1World.setBlockMetadataWithNotify(par2, par3, par4, 2, 2);
- }
- if (l == 1) {
- par1World.setBlockMetadataWithNotify(par2, par3, par4, 5, 2);
- }
- if (l == 2) {
- par1World.setBlockMetadataWithNotify(par2, par3, par4, 3, 2);
- }
- if (l == 3) {
- par1World.setBlockMetadataWithNotify(par2, par3, par4, 4, 2);
- }
- }
- @Override
- public TileEntity createNewTileEntity(World world) {
- return new TileEntityRUMad();
- }
- @Override
- public boolean hasTileEntity() {
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment