Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.scratchforfun.mod.block;
- import java.util.Random;
- import cpw.mods.fml.common.network.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.IconRegister;
- import net.minecraft.entity.EntityLivingBase;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.inventory.Container;
- import net.minecraft.inventory.IInventory;
- 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 net.scratchforfun.mod.ScratchForFun;
- import net.scratchforfun.mod.tileentity.TileEntityQuartzFurnace;
- public class BlockQuartzFurnace extends BlockContainer{
- private final boolean isActive;
- @SideOnly(Side.CLIENT)
- private Icon iconFront;
- private static boolean keepInventory;
- public BlockQuartzFurnace(int id, boolean isActive) {
- super(id, Material.rock);
- this.isActive = isActive;
- }
- @SideOnly(Side.CLIENT)
- public void registerIcons(IconRegister iconRegister){
- this.blockIcon = iconRegister.registerIcon(ScratchForFun.modid + ":" + "furnace_Side");
- this.iconFront = iconRegister.registerIcon(ScratchForFun.modid + ":" + (this.isActive ? "furnace_Front_Active" : "furnace_Front_Idle"));
- }
- @SideOnly(Side.CLIENT)
- public Icon getIcon(int side, int metadata){
- return side == metadata ? this.iconFront : this.blockIcon;
- }
- public int idDropped(int par1, Random random, int par3){
- return ScratchForFun.blockQuartzFurnaceIdle.blockID;
- }
- 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){
- int l = world.getBlockId(x, y, z - 1);
- int il = world.getBlockId(x, y, z + 1);
- int jl = world.getBlockId(x - 1, y, z);
- int kl = world.getBlockId(x + 1, y, z);
- byte b0 = 3;
- if(Block.opaqueCubeLookup[l] && !Block.opaqueCubeLookup[il]){
- b0 = 3;
- }
- if(Block.opaqueCubeLookup[il] && !Block.opaqueCubeLookup[l]){
- b0 = 2;
- }
- if(Block.opaqueCubeLookup[jl] && !Block.opaqueCubeLookup[kl]){
- b0 = 5;
- }
- if(Block.opaqueCubeLookup[kl] && !Block.opaqueCubeLookup[jl]){
- b0 = 4;
- }
- world.setBlockMetadataWithNotify(x, y, z, b0, 2);
- }
- }
- 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, ScratchForFun.instance, ScratchForFun.guiIdQuartzFurnace, world, x, y, z);
- }
- return true;
- }
- public TileEntity createNewTileEntity(World world){
- return new TileEntityQuartzFurnace();
- }
- 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()){
- ((TileEntityQuartzFurnace)world.getBlockTileEntity(x, y, z)).setGuiDisplayName(itemStack.getDisplayName());
- }
- }
- public static void updateQuartzFurnaceBlockState(boolean active, World worldObj, int xCoord, int yCoord, int zCoord) {//makes it so when the furnace updates it keeps its inventory
- int i = worldObj.getBlockMetadata(xCoord, yCoord, zCoord);//sets the metadata to the one we had before
- TileEntity tileentity = worldObj.getBlockTileEntity(xCoord, yCoord, zCoord);//sets the title entity to the one we had before
- keepInventory = true;//
- if(active){//if the furnace is active its going to set it to a Active block ID else a Idle block ID
- worldObj.setBlock(xCoord, yCoord, zCoord, ScratchForFun.blockQuartzFurnaceActive.blockID);
- }else{
- worldObj.setBlock(xCoord, yCoord, zCoord, ScratchForFun.blockQuartzFurnaceIdle.blockID);
- }
- keepInventory = false;
- worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, i, 2); // 2 is a change to the client
- if(tileentity != null){//makes sure there was a tile entity
- tileentity.validate();
- worldObj.setBlockTileEntity(xCoord, yCoord, zCoord, tileentity);
- }
- }
- public boolean hasComparatorInputOverride(){//allows for there to be a comparator used on the furnace
- return true;
- }
- public int getComparatorInputOverride(World world, int x, int y, int z, int i){
- return Container.calcRedstoneFromInventory((IInventory)world.getBlockTileEntity(x, y, z));
- }
- public int idPicked(World world, int x, int y, int z){//when you hit it with the middle mouse button it will allow it to be picked
- return ScratchForFun.blockQuartzFurnaceIdle.blockID;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement