Posted January 29, 201411 yr I'm making a block (specifically a Stove) and I want it to face the direction that I'm standing. I think I have to use something related to ForgeDirection. FYI it is a TileEntity The Block Code: package majhenriquboss.cuisinecraft.blocks; import majhenriquboss.cuisinecraft.lib.BlockInfo; import majhenriquboss.cuisinecraft.lib.Reference; import majhenriquboss.cuisinecraft.tileEntities.TileEntityStove; 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.creativetab.CreativeTabs; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Icon; import net.minecraft.world.World; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; public class BlockStove extends BlockContainer { //Constructor public BlockStove(int id, Material material) { super(id, material); setHardness(2F); setStepSound(Block.soundMetalFootstep); setUnlocalizedName(BlockInfo.STOVE_UNLOCALIZED); setCreativeTab(CreativeTabs.tabRedstone); } //Icon variables @SideOnly(Side.CLIENT) private Icon[] frontIcon; @SideOnly(Side.CLIENT) private Icon bottomIcon; @SideOnly(Side.CLIENT) private Icon[] topIcon; @SideOnly(Side.CLIENT) private Icon sideIcon; //Registers the icon textures @Override @SideOnly(Side.CLIENT) public void registerIcons(IconRegister register) { bottomIcon = register.registerIcon(Reference.TEXTURE_LOCATION + ":" + BlockInfo.STOVE_BOTTOM); sideIcon = register.registerIcon(Reference.TEXTURE_LOCATION + ":" + BlockInfo.STOVE_SIDE); frontIcon = new Icon[blockInfo.STOVE_FRONT.length]; for (int i = 0; i < frontIcon.length; i++) { frontIcon[i] = register.registerIcon(Reference.TEXTURE_LOCATION + ":" + BlockInfo.STOVE_FRONT[i]); } topIcon = new Icon[blockInfo.STOVE_TOP.length]; for (int i = 0; i < topIcon.length; i++) { topIcon[i] = register.registerIcon(Reference.TEXTURE_LOCATION + ":" + BlockInfo.STOVE_TOP[i]); } } //Sets the Icon depending on the side @Override @SideOnly(Side.CLIENT) public Icon getIcon(int side, int meta) { TileEntityStove stove = new TileEntityStove(); switch (side){ //Bottom case 0: return bottomIcon; //Top case 1: if (stove.getIsActive() == true) { return topIcon[1]; }else if (stove.getIsActive() == false) { return topIcon[0]; } //Front case 2: if (stove.getIsActive() == true) { return frontIcon[1]; }else if (stove.getIsActive() == false) { return frontIcon[0]; } //Back case 3: return sideIcon; //Left case 4: return sideIcon; //Right case 5: return sideIcon; default: return null; } } //@Override public void updateIcons(IconRegister register) { } @Override public TileEntity createNewTileEntity(World world) { return new TileEntityStove(); } } The TileEntity Code: package majhenriquboss.cuisinecraft.tileEntities; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.ForgeDirection; public class TileEntityStove extends TileEntity { private boolean isActive; private int cookingTime = 120; protected ForgeDirection orientation; public TileEntityStove() { isActive = false; } @Override public void updateEntity() { if (cookingTime == 0 && !worldObj.isRemote) { isActive = true; //worldObj.destroyBlock(xCoord + 1, yCoord, zCoord, false); } if (worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord)) { cookingTime--; } /*if (cookingTime == 100) { worldObj.setBlock(xCoord + 3, yCoord, zCoord, 1); }if (cookingTime == 80) { worldObj.setBlock(xCoord + 3, yCoord + 1, zCoord, 1); }if (cookingTime == 60) { worldObj.setBlock(xCoord + 3, yCoord + 2, zCoord, 1); }if (cookingTime == 40) { worldObj.setBlock(xCoord + 2, yCoord + 3, zCoord, 1); }if (cookingTime == 20) { worldObj.setBlock(xCoord + 1, yCoord + 3, zCoord, 1); }*/ if (isActive == true) {worldObj.spawnParticle("smoke", xCoord, yCoord, zCoord, 1.0D /*red*/, 0.0D /*green*/, 0.0D /*blue*/);} } public boolean getIsActive() { return isActive; } } I'm new to modding so I'm probably a noob. Thanks in advance!
January 29, 201411 yr Look at BlockDispenser. You'll learn more. {Method to Activate} : in your block class. public void onBlockAdded(World par1World, int par2, int par3, int par4) { super.onBlockAdded(par1World, par2, par3, par4); this.setDirectionOfBlock(par1World, par2, par3, par4); } setDirectionOfBlock private void setDirectionOfBlock(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); } } Now all you got to do is register the textures on each side of the block corresponding to BlockMetadata. Maybe next time you can look at HOW some vanilla blocks do that first, before asking
January 30, 201411 yr Hi This link might help get some of the basic concepts straight (the sections on Blocks) http://greyminecraftcoder.blogspot.com.au/p/list-of-topics.html especially http://greyminecraftcoder.blogspot.com.au/2013/07/blocks.html http://greyminecraftcoder.blogspot.com.au/2013/07/rendering-non-standard-blocks.html -TGG
January 30, 201411 yr Hi sorry dude, I don't think there's any more help I can give you than what's in this thread already. -TGG
January 31, 201411 yr I'm making a block (specifically a Stove) and I want it to face the direction that I'm standing. I think I have to use something related to ForgeDirection. FYI it is a TileEntity The Block Code: package majhenriquboss.cuisinecraft.blocks; import majhenriquboss.cuisinecraft.lib.BlockInfo; import majhenriquboss.cuisinecraft.lib.Reference; import majhenriquboss.cuisinecraft.tileEntities.TileEntityStove; 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.creativetab.CreativeTabs; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Icon; import net.minecraft.world.World; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; public class BlockStove extends BlockContainer { //Constructor public BlockStove(int id, Material material) { super(id, material); setHardness(2F); setStepSound(Block.soundMetalFootstep); setUnlocalizedName(BlockInfo.STOVE_UNLOCALIZED); setCreativeTab(CreativeTabs.tabRedstone); } //Icon variables @SideOnly(Side.CLIENT) private Icon[] frontIcon; @SideOnly(Side.CLIENT) private Icon bottomIcon; @SideOnly(Side.CLIENT) private Icon[] topIcon; @SideOnly(Side.CLIENT) private Icon sideIcon; //Registers the icon textures @Override @SideOnly(Side.CLIENT) public void registerIcons(IconRegister register) { bottomIcon = register.registerIcon(Reference.TEXTURE_LOCATION + ":" + BlockInfo.STOVE_BOTTOM); sideIcon = register.registerIcon(Reference.TEXTURE_LOCATION + ":" + BlockInfo.STOVE_SIDE); frontIcon = new Icon[blockInfo.STOVE_FRONT.length]; for (int i = 0; i < frontIcon.length; i++) { frontIcon[i] = register.registerIcon(Reference.TEXTURE_LOCATION + ":" + BlockInfo.STOVE_FRONT[i]); } topIcon = new Icon[blockInfo.STOVE_TOP.length]; for (int i = 0; i < topIcon.length; i++) { topIcon[i] = register.registerIcon(Reference.TEXTURE_LOCATION + ":" + BlockInfo.STOVE_TOP[i]); } } //Sets the Icon depending on the side @Override @SideOnly(Side.CLIENT) public Icon getIcon(int side, int meta) { TileEntityStove stove = new TileEntityStove(); switch (side){ //Bottom case 0: return bottomIcon; //Top case 1: if (stove.getIsActive() == true) { return topIcon[1]; }else if (stove.getIsActive() == false) { return topIcon[0]; } //Front case 2: if (stove.getIsActive() == true) { return frontIcon[1]; }else if (stove.getIsActive() == false) { return frontIcon[0]; } //Back case 3: return sideIcon; //Left case 4: return sideIcon; //Right case 5: return sideIcon; default: return null; } } //@Override public void updateIcons(IconRegister register) { } @Override public TileEntity createNewTileEntity(World world) { return new TileEntityStove(); } } The TileEntity Code: package majhenriquboss.cuisinecraft.tileEntities; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.ForgeDirection; public class TileEntityStove extends TileEntity { private boolean isActive; private int cookingTime = 120; protected ForgeDirection orientation; public TileEntityStove() { isActive = false; } @Override public void updateEntity() { if (cookingTime == 0 && !worldObj.isRemote) { isActive = true; //worldObj.destroyBlock(xCoord + 1, yCoord, zCoord, false); } if (worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord)) { cookingTime--; } /*if (cookingTime == 100) { worldObj.setBlock(xCoord + 3, yCoord, zCoord, 1); }if (cookingTime == 80) { worldObj.setBlock(xCoord + 3, yCoord + 1, zCoord, 1); }if (cookingTime == 60) { worldObj.setBlock(xCoord + 3, yCoord + 2, zCoord, 1); }if (cookingTime == 40) { worldObj.setBlock(xCoord + 2, yCoord + 3, zCoord, 1); }if (cookingTime == 20) { worldObj.setBlock(xCoord + 1, yCoord + 3, zCoord, 1); }*/ if (isActive == true) {worldObj.spawnParticle("smoke", xCoord, yCoord, zCoord, 1.0D /*red*/, 0.0D /*green*/, 0.0D /*blue*/);} } public boolean getIsActive() { return isActive; } } I'm new to modding so I'm probably a noob. Thanks in advance! I'm using that code. Put it in BlockName.class file. public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLiving par5EntityLiving, ItemStack par6ItemStack) { int var7 = MathHelper.floor_double((double)(par5EntityLiving.rotationYaw * 4.0F / 360.0F) + 2.5D) & 3; par1World.setBlockMetadataWithNotify(par2, par3, par4, var7, 2); }
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.