Jump to content

[1.7.10] My custom furnace doesn't change his texture when it's active


TheTroop

Recommended Posts

My custom furnace doesn't change his texture when it's active

 

Block class

package com.TheTroop.legendrymod;

import java.util.Random;

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.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;

public class blockOven extends BlockContainer{

private Random rand;
private final boolean isActive;
private static boolean keepInventory = false;

@SideOnly(Side.CLIENT)
private IIcon iconFront;

public blockOven(boolean blockState) {
	super(Material.iron);
	rand =  new Random();
	isActive = blockState;
}

@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister iconRegister) {
	this.blockIcon = iconRegister.registerIcon("lm" + ":" + (this.isActive ? "blockOvenSideOn" : "blockOvenSideOff"));
	this.iconFront = iconRegister.registerIcon("lm" + ":" + (this.isActive ? "blockOvenFrontOn" : "blockOvenFrontOff"));
}

@SideOnly(Side.CLIENT)
public IIcon getIcon(int side, int metadata) {
	return metadata == 0 && side == 3 ? this.iconFront : (side == metadata ? this.iconFront : this.blockIcon);
}

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 block1 = world.getBlock(x, y, z - 1);
		Block block2 = world.getBlock(x, y, z +1);
		Block block3 = world.getBlock(x - 1, y, z);
		Block block4 = world.getBlock(x + 1, y, z);

		byte b0 = 3;

		if(block1.func_149730_j() && !block2.func_149730_j()) {
			b0 = 3;
		}

		if(block1.func_149730_j() && !block1.func_149730_j()) {
			b0 = 2;
		}

		if(block1.func_149730_j() && !block4.func_149730_j()) {
			b0 = 5;
		}

		if(block1.func_149730_j() && !block3.func_149730_j()) {
			b0 = 4;
		}

		world.setBlockMetadataWithNotify(x, y, z, b0, 2);
	}
}

public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityPlayer, ItemStack itemstack) {
	int i = MathHelper.floor_double((double)(entityPlayer.rotationYaw * 4.0F / 360F) + 0.5D) & 3;

	if(i == 0) {
		world.setBlockMetadataWithNotify(x, y, z, 2, 2);
	}
	if(i == 1) {
		world.setBlockMetadataWithNotify(x, y, z, 5, 2);
	}
	if(i == 2) {
		world.setBlockMetadataWithNotify(x, y, z, 3, 2);
	}
	if(i == 3) {
		world.setBlockMetadataWithNotify(x, y, z, 4, 2);
	}

	if(itemstack.hasDisplayName()) {
		//((TileEntityblockOven)world.getTileEntity(x, y, z)).setCustomName(itemstack.getDisplayName());
	}

}

public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
	if (world.isRemote) {
		return true;
	}else if (!player.isSneaking()) {
		TileEntityblockOven entity = (TileEntityblockOven) world.getTileEntity(x, y, z);
		if (entity != null) {
			FMLNetworkHandler.openGui(player, LegendryMod.instance, LegendryMod.guiIDblockOven, world, x, y, z);
		}
		return true;
	}else{
		return false;
	}
}

@Override
public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_) {
	return new TileEntityblockOven();
}

public static void updateBlockState(boolean isMashing, World world, int xCoord, int yCoord, int zCoord) {
  
	int i = world.getBlockMetadata(xCoord, yCoord, zCoord);
	TileEntity entity = world.getTileEntity(xCoord, yCoord, zCoord);
	keepInventory = true;

	if (isMashing) {
		world.setBlock(yCoord, yCoord, zCoord, LegendryMod.blockOvenActive);
	}else{
		world.setBlock(yCoord, yCoord, zCoord, LegendryMod.blockOvenIdle);

	}
	keepInventory = false;
	world.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, i, 2);

	if (entity != null) {
		entity.validate();
		world.setTileEntity(xCoord, yCoord, zCoord, entity);
	}
}

}

Link to comment
Share on other sites

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.