03-07-2014, 05:38 AM
package electro.blocks;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityFurnace;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import cpw.mods.fml.common.network.internal.FMLNetworkHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import electro.lib.Referance;
import electro.mod.Electrocuted;
import electro.tileentity.TileEntityCompressionFurnace;
public class BlockCompressionFurnace extends BlockContainer {
private final boolean isActive;
@SideOnly(Side.CLIENT)
private IIcon iconFront;
@SideOnly(Side.CLIENT)
private IIcon iconTop;
public BlockCompressionFurnace(boolean isActive) {
super(Material.rock);
this.setCreativeTab(Electrocuted.ElectrocutedTab);
this.isActive = isActive;
}
public Item idDropped(int par1, Random random, int par3) {
return Item.getItemFromBlock(Electrocuted.CompressionFurnaceIdle);
}
public void onBlockAdded(World world, int x, int y, int z) {
super.onBlockAdded(world, x, y, z);
this.setDefaultDirection(world, x, y, z);
}
private void setDefaultDirection(World world, int x, int y, int z)
{
if (!world.isRemote)
{
Block block = world.getBlock(x, y, z - 1);
Block block1 = world.getBlock(x, y, z + 1);
Block block2 = world.getBlock(x - 1, y, z);
Block block3 = world.getBlock(x + 1, y, z);
byte b0 = 3;
if (block.func_149730_j() && !block1.func_149730_j())
{
b0 = 3;
}
if (block1.func_149730_j() && !block.func_149730_j())
{
b0 = 2;
}
if (block2.func_149730_j() && !block3.func_149730_j())
{
b0 = 5;
}
if (block3.func_149730_j() && !block2.func_149730_j())
{
b0 = 4;
}
world.setBlockMetadataWithNotify(x, y, z, b0, 2);
}
}
@SideOnly(Side.CLIENT)
public IIcon getIcon(int p_149691_1_, int p_149691_2_) {
return p_149691_1_ == 1 ? this.iconTop : (p_149691_1_ == 0 ? this.iconTop : (p_149691_1_ != p_149691_2_ ? this.blockIcon : this.iconFront));
}
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister iconRegister) {
this.blockIcon = iconRegister.registerIcon("electrocuted:CompressionFurnace_side");
this.iconFront = iconRegister.registerIcon(this.isActive ? "electrocuted:CompressionFurnace_Active_front" : "electrocuted:CompressionFurnace_Idle_Front");
this.iconTop = iconRegister.registerIcon("electrocuted:CompressionFurnace_top");
}
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
if(world.isRemote) {
FMLNetworkHandler.openGui(player, Electrocuted.instance, Electrocuted.guiIdCompressionFurnace, world, x, y, z);
}
return true;
}
public TileEntity createNewTileEntity(World world, int var1) {
return new TileEntityCompressionFurnace();
}
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityLivingBase, ItemStack itemstack) {
int l = MathHelper.floor_double((double)(entityLivingBase.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
if (l == 0)
{
world.setBlockMetadataWithNotify(x, y, z, 2, 2);
}
if (l == 1)
{
world.setBlockMetadataWithNotify(x, y, z, 5, 2);
}
if (l == 2)
{
world.setBlockMetadataWithNotify(x, y, z, 3, 2);
}
if (l == 3)
{
world.setBlockMetadataWithNotify(x, y, z, 4, 2);
}
if (itemstack.hasDisplayName())
{
((TileEntityCompressionFurnace)world.getTileEntity(x, y, z)).setGuiDisplayName(itemstack.getDisplayName());
}
}
}
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityFurnace;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import cpw.mods.fml.common.network.internal.FMLNetworkHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import electro.lib.Referance;
import electro.mod.Electrocuted;
import electro.tileentity.TileEntityCompressionFurnace;
public class BlockCompressionFurnace extends BlockContainer {
private final boolean isActive;
@SideOnly(Side.CLIENT)
private IIcon iconFront;
@SideOnly(Side.CLIENT)
private IIcon iconTop;
public BlockCompressionFurnace(boolean isActive) {
super(Material.rock);
this.setCreativeTab(Electrocuted.ElectrocutedTab);
this.isActive = isActive;
}
public Item idDropped(int par1, Random random, int par3) {
return Item.getItemFromBlock(Electrocuted.CompressionFurnaceIdle);
}
public void onBlockAdded(World world, int x, int y, int z) {
super.onBlockAdded(world, x, y, z);
this.setDefaultDirection(world, x, y, z);
}
private void setDefaultDirection(World world, int x, int y, int z)
{
if (!world.isRemote)
{
Block block = world.getBlock(x, y, z - 1);
Block block1 = world.getBlock(x, y, z + 1);
Block block2 = world.getBlock(x - 1, y, z);
Block block3 = world.getBlock(x + 1, y, z);
byte b0 = 3;
if (block.func_149730_j() && !block1.func_149730_j())
{
b0 = 3;
}
if (block1.func_149730_j() && !block.func_149730_j())
{
b0 = 2;
}
if (block2.func_149730_j() && !block3.func_149730_j())
{
b0 = 5;
}
if (block3.func_149730_j() && !block2.func_149730_j())
{
b0 = 4;
}
world.setBlockMetadataWithNotify(x, y, z, b0, 2);
}
}
@SideOnly(Side.CLIENT)
public IIcon getIcon(int p_149691_1_, int p_149691_2_) {
return p_149691_1_ == 1 ? this.iconTop : (p_149691_1_ == 0 ? this.iconTop : (p_149691_1_ != p_149691_2_ ? this.blockIcon : this.iconFront));
}
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister iconRegister) {
this.blockIcon = iconRegister.registerIcon("electrocuted:CompressionFurnace_side");
this.iconFront = iconRegister.registerIcon(this.isActive ? "electrocuted:CompressionFurnace_Active_front" : "electrocuted:CompressionFurnace_Idle_Front");
this.iconTop = iconRegister.registerIcon("electrocuted:CompressionFurnace_top");
}
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
if(world.isRemote) {
FMLNetworkHandler.openGui(player, Electrocuted.instance, Electrocuted.guiIdCompressionFurnace, world, x, y, z);
}
return true;
}
public TileEntity createNewTileEntity(World world, int var1) {
return new TileEntityCompressionFurnace();
}
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityLivingBase, ItemStack itemstack) {
int l = MathHelper.floor_double((double)(entityLivingBase.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
if (l == 0)
{
world.setBlockMetadataWithNotify(x, y, z, 2, 2);
}
if (l == 1)
{
world.setBlockMetadataWithNotify(x, y, z, 5, 2);
}
if (l == 2)
{
world.setBlockMetadataWithNotify(x, y, z, 3, 2);
}
if (l == 3)
{
world.setBlockMetadataWithNotify(x, y, z, 4, 2);
}
if (itemstack.hasDisplayName())
{
((TileEntityCompressionFurnace)world.getTileEntity(x, y, z)).setGuiDisplayName(itemstack.getDisplayName());
}
}
}