Jump to content

Recommended Posts

Posted

Hi,

My custom furnace is not working the way i would like it to still, I made a post yesterday about it and fixed it but now i have another problem. :'(

The furnace is not facing the way i want it to. Instead of acting like a normal furnace where the side your looking at will be the front, it is the block you click on. For example, i click on the west side of a block and the front is towards the west, even though i was standing north.

 

Block class

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());
        }
    }
}

 

 

TileEntity class (not done)

package electro.tileentity;

import net.minecraft.tileentity.TileEntity;

public class TileEntityCompressionFurnace extends TileEntity {

private String localizedName;

public void setGuiDisplayName(String displayName) {
	this.localizedName = displayName;
}

}

If I helped then you help, hit that Thank You button or Applaud.

Posted

here is a pretty good tutorial for a custom furnace:

 

 

he explains everything. follow this tutorial and everything will be fine.

only one thing is not up to date, and that is:

public boolean onBlockActivated(World p_149727_1_, int p_149727_2_, int p_149727_3_, int p_149727_4_, EntityPlayer p_149727_5_, int p_149727_6_, float p_149727_7_, float p_149727_8_, float p_149727_9_)

 

i copied it from the BlockFurnace.class, then it worked.

*********************************

**  Always remember you are unique,  **

**  just like everyone else                   **     

**********************************

Was my post helpful? Say thanks and

press the thank you button, on my post!!

God, damn it!

Posted

here is a pretty good tutorial for a custom furnace:

 

 

Thats the series i watched... ;)

But, I still don't understand where i'm steeing the metadata again...

If I helped then you help, hit that Thank You button or Applaud.

Posted

here is a pretty good tutorial for a custom furnace:

 

 

Thats the series i watched... ;)

But, I still don't understand where i'm steeing the metadata again...

 

OnBlockPlacedBy() and setDefaultDirection() are both setting the metadata for the block. One function sets direction based on furnace surroundings (so it doesn't face a block). The other bases it on the facing of the player (like a door or stairs). They should agree?

Posted

here is a pretty good tutorial for a custom furnace:

 

 

Thats the series i watched... ;)

But, I still don't understand where i'm steeing the metadata again...

Ohh ok.

I looked at the code from the normal furnace and thats what i got.

 

 

OnBlockPlacedBy() and setDefaultDirection() are both setting the metadata for the block. One function sets direction based on furnace surroundings (so it doesn't face a block). The other bases it on the facing of the player (like a door or stairs). They should agree?

If I helped then you help, hit that Thank You button or Applaud.

Posted

They should but i got the code form the normal furnace, so could you point out exactly where my problem is?

If I helped then you help, hit that Thank You button or Applaud.

  • 1 month later...
Posted

Hello,

 

your problem is that the set default direction function works based on the surrounding blocks,

not on you

 

i had the same problem

 

i left the on block added function out completely and added a function (in the block class) and call it in the on block placed by function like so:

onBlockPlacedBy(World world, int i, int j, int k, EntityLivingBase, ItemStack p_149689_6_){
byte b0 = 3;
b0=rotateBlock(b0, entity);//call my function
world.setBlockMetadataWithNotify(i, j, k, b0, 2);
}

 

and here is the function:

public byte rotateBlock(byte b0, EntityLivingBase entity){

	if((entity.rotationYaw>=135&&entity.rotationYaw<=181)||(entity.rotationYaw<=-135&&entity.rotationYaw>=-181)){
		//if entity is faceing north
		b0 = 3;
	}else if(entity.rotationYaw>-135&&entity.rotationYaw<-45){
		//if entity is faceing east
		b0 = 4;
	}else if(entity.rotationYaw>=-45&&entity.rotationYaw<=45){
		//if entity is faceing south
		b0 = 2;
	}else if(entity.rotationYaw>45&&entity.rotationYaw<135){
		//if entity is faceing west
		b0 = 5;

		//sometimes rotationYaw gets over 180 or under -180
		//for example 185 equals the rotation at -175
		//so im fixing that by subtracting 360 if it is over 180 or under -180

	}else if(entity.rotationYaw>=181){
		entity.rotationYaw=entity.rotationYaw-360;
		b0=rotateBlock(b0, entity);
	}else if(entity.rotationYaw<=-181){
		entity.rotationYaw=entity.rotationYaw+360;
		b0=rotateBlock(b0, entity);
	}
	return b0;
}

 

i hope that helps you

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.