Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.halestormxv.blocks;
- import java.util.Random;
- import com.halestormxv.Main.MainRegistry;
- import com.halestormxv.lib.RefStrings;
- import com.halestormxv.tile_entity.TileEntityCelestialFurnace;
- import cpw.mods.fml.common.network.internal.FMLNetworkHandler;
- import cpw.mods.fml.relauncher.Side;
- import cpw.mods.fml.relauncher.SideOnly;
- 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.item.EntityItem;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.item.Item;
- import net.minecraft.item.ItemStack;
- import net.minecraft.nbt.NBTTagCompound;
- 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;
- public class CelestialFurnace extends BlockContainer{
- @SideOnly(Side.CLIENT)
- private IIcon top;
- @SideOnly(Side.CLIENT)
- private IIcon front;
- private IIcon frontAlt;
- private final boolean isActive;
- private final Random random = new Random();
- private static boolean keepInventory;
- public CelestialFurnace(boolean isActive)
- {
- super(Material.iron);
- this.setHardness(12.0F);
- this.setResistance(15.0F);
- this.setHarvestLevel("pickaxe", 3);
- this.isActive = isActive;
- }
- @SideOnly(Side.CLIENT)
- public void registerBlockIcons(IIconRegister iconregister){
- this.blockIcon = iconregister.registerIcon(RefStrings.MODID + ":CelestialFurnaceSide");
- this.front = iconregister.registerIcon(this.isActive ? RefStrings.MODID + ":CelestialFurnaceActive" : RefStrings.MODID + ":CelestialFurnaceInactive");
- this.top = iconregister.registerIcon(RefStrings.MODID + ":CelestialFurnaceTop");
- this.frontAlt = iconregister.registerIcon(this.isActive ? RefStrings.MODID + ":CelestialFurnaceCelestalModeActive" : RefStrings.MODID + ":CelestialFurnaceInactive");
- }
- //Set Sides
- /*
- @SideOnly(Side.CLIENT)
- public IIcon getIcon(int side, int meta){
- return side == 1 ? this.top : (side == 0 ? this.top : (side != meta ? this.blockIcon : this.front));
- }
- */
- @SideOnly(Side.CLIENT)
- public IIcon getIcon(int side, int meta)
- {
- if(side == 1){
- return this.top; // Side 0 = Bottom
- }else if (side == 2 && meta != 6){
- return this.front;
- }else if (side == 2 && meta == 6){
- return this.frontAlt;
- }else{
- return this.blockIcon; // Side 5 = East/Right
- }
- }
- 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, MainRegistry.modInstance, CelestialCraft_blocks.guiIDCelestialFurnace, world, x, y, z);
- }
- return true;
- }
- //ToDO RandomDisplayTick
- public Item getItemDropped(int par1, Random random, int par3){
- return Item.getItemFromBlock(CelestialCraft_blocks.celestialFurnace);
- }
- public Item getItem(World world, int par2, int par3, int par4){
- return Item.getItemFromBlock(CelestialCraft_blocks.celestialFurnace);
- }
- public TileEntity createNewTileEntity(World world, int par2) {
- return new TileEntityCelestialFurnace();
- }
- public void onBlockAdded(World world, int x, int y, int z){
- super.onBlockAdded(world, x, y, z);
- this.defaultDirection(world, x, y, z); //Set Default Direction
- }
- private void defaultDirection(World world, int x, int y, int z) {
- if(!world.isRemote){
- Block direction1 = world.getBlock(x, y, z - 1);
- Block direction2 = world.getBlock(x, y, z + 1);
- Block direction3 = world.getBlock(x - 1, y, z);
- Block direction4 = world.getBlock(x + 1, y, z);
- byte byte0 = 3;
- if(direction1.func_149730_j() && !direction2.func_149730_j()){
- byte0 = 3;
- }
- if(direction2.func_149730_j() && !direction1.func_149730_j()){
- byte0 = 2;
- }
- if(direction3.func_149730_j() && !direction4.func_149730_j()){
- byte0 = 5;
- }
- if(direction4.func_149730_j() && !direction3.func_149730_j()){
- byte0 = 4;
- }
- world.setBlockMetadataWithNotify(x, y, z, byte0, 2);
- }
- }
- //Rotate Furnace
- public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entity, ItemStack itemstack){
- int direction = MathHelper.floor_double((double)(entity.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
- if (direction == 0){
- world.setBlockMetadataWithNotify(x, y, z, 2, 2);
- }
- if (direction == 1){
- world.setBlockMetadataWithNotify(x, y, z, 5, 2);
- }
- if (direction == 2){
- world.setBlockMetadataWithNotify(x, y, z, 3, 2);
- }
- if (direction == 3){
- world.setBlockMetadataWithNotify(x, y, z, 4, 2);
- }
- if(itemstack.hasDisplayName()){
- ((TileEntityCelestialFurnace) world.getTileEntity(x, y, z)).setGuiDisplayName(itemstack.getDisplayName());
- }
- }
- public static void updateCelestialFurnaceBlockState(boolean burning, World world, int x, int y, int z){
- int direction = world.getBlockMetadata(x, y, z);
- TileEntity tileentity = world.getTileEntity(x, y, z);
- keepInventory = true;
- if(burning){
- world.setBlock(x, y, z, CelestialCraft_blocks.celestialFurnaceActive);
- }else{
- world.setBlock(x, y, z, CelestialCraft_blocks.celestialFurnace);
- }
- keepInventory = false;
- world.setBlockMetadataWithNotify(x, y, z, direction, 2);
- if(tileentity != null){
- tileentity.validate();
- world.setTileEntity(x, y, z, tileentity);
- }
- }
- public void breakBlock(World world, int x, int y, int z, Block block, int meta){
- if(!keepInventory){
- TileEntityCelestialFurnace tileentitycelestialfurnace = (TileEntityCelestialFurnace) world.getTileEntity(x, y, z);
- if (tileentitycelestialfurnace != null){
- for(int i = 0; i < tileentitycelestialfurnace.getSizeInventory(); ++i){
- ItemStack itemstack = tileentitycelestialfurnace.getStackInSlot(i);
- if(itemstack != null){
- float f = this.random.nextFloat() * 0.6F + 0.1F;
- float f1 = this.random.nextFloat() * 0.6F + 0.1F;
- float f2 = this.random.nextFloat() * 0.6F + 0.1F;
- while(itemstack.stackSize > 0){
- int j = this.random.nextInt(21) + 10;
- if (j > itemstack.stackSize){
- j = itemstack.stackSize;
- }
- itemstack.stackSize -= j;
- EntityItem entityitem = new EntityItem(world, (double) ((float) x + f), (double) ((float) y + f1), (double) ((float) z + f2), new ItemStack(itemstack.getItem(), j, itemstack.getItemDamage()));
- if(itemstack.hasTagCompound()){
- entityitem.getEntityItem().setTagCompound(((NBTTagCompound) itemstack.getTagCompound().copy()));
- }
- float f3 = 0.025F;
- entityitem.motionX = (double) ((float) this.random.nextGaussian() * f3);
- entityitem.motionY = (double) ((float) this.random.nextGaussian() * f3 + 0.1F);
- entityitem.motionZ = (double) ((float) this.random.nextGaussian() * f3);
- world.spawnEntityInWorld(entityitem);
- }
- }
- }
- world.func_147453_f(x, y, z, block);
- }
- }
- super.breakBlock(world, x, y, z, block, meta);
- }
- @SideOnly(Side.CLIENT)
- public void randomDisplayTick(World world, int x, int y, int z, Random random){
- if(this.isActive){
- int direction = world.getBlockMetadata(x, y, z);
- float x1 = (float) x + 0.5F;
- float y1 = (float) y + random.nextFloat();
- float z1 = (float) z + 0.5F;
- float f = 0.52F;
- float f1 = random.nextFloat() * 0.6F - 0.3F;
- if (direction == 4){
- world.spawnParticle("smoke", (double) (x1 - f), (double) y1, (double) (z1 + f1), 0D, 0D, 0D);
- world.spawnParticle("portal", (double) (x1 - f), (double) y1, (double) (z1 + f1), 0D, 0D, 0D);
- }if(direction == 5){
- world.spawnParticle("smoke", (double) (x1 + f), (double) y1, (double) (z1 + f1), 0D, 0D, 0D);
- world.spawnParticle("portal", (double) (x1 + f), (double) y1, (double) (z1 + f1), 0D, 0D, 0D);
- }if(direction == 2){
- world.spawnParticle("smoke", (double) (x1 + f1), (double) y1, (double) (z1 - f1), 0D, 0D, 0D);
- world.spawnParticle("portal", (double) (x1 + f1), (double) y1, (double) (z1 - f1), 0D, 0D, 0D);
- }if(direction == 3){
- world.spawnParticle("smoke", (double) (x1 + f1), (double) y1, (double) (z1 + f1), 0D, 0D, 0D);
- world.spawnParticle("portal", (double) (x1 + f1), (double) y1, (double) (z1 + f1), 0D, 0D, 0D);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement