Jump to content

Custom Torch Texture only shows when breaking.


Revolution

Recommended Posts

I've been looking for setting up blocks with textures (tried a few "fixes" here and there but none of them worked so i just deleted them.)

Anyway the texture I'm looking for only loads when I place the block.

(Also note there's two types of the block. The item carbonTorch, and the block carbonTorch. The item is throwable, and if it hits a block spawns the block. That is the only way the block can be placed for now, until I add in the item right clicking too anyway).

(Also yes some of my code may be inefficient i'll clean that up later I just want this texture to work :P)

 

Code below:

 

Main Class:

import java.util.Map;

import com.rev.entity.CarbonTorchEntity;
import com.rev.item.block.CarbonTubeBlockTorch;
import com.rev.item.block.CarbonTubeItemTorch;
import com.rev.items.tools.*;
import com.rev.render.RenderBase;

import cpw.mods.fml.client.registry.RenderingRegistry;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.registry.EntityRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;
import net.minecraft.block.Block;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.Item.ToolMaterial;
import net.minecraftforge.common.util.EnumHelper;


@Mod(modid = "carbontubes", version = "1.0")
public class CarbonTubes
{   

@SidedProxy(clientSide = "com.rev.render.TorchClient", serverSide = "com.rev.render.RenderBase")
public static RenderBase proxy;
static ToolMaterial carbonPick = EnumHelper.addToolMaterial("CARBON", 69, 2000, 12F, 2000, 0);
static ToolMaterial carbonShov = EnumHelper.addToolMaterial("CARBON", 69, 2000, 12F, 1500, 0);
static ToolMaterial carbonA = EnumHelper.addToolMaterial("CARBON", 69, 2000, 12F, 3000, 0);
static ToolMaterial carbonH = EnumHelper.addToolMaterial("CARBON", 69, 2000, 12F, 1000, 0);
static ToolMaterial carbonSw = EnumHelper.addToolMaterial("CARBON", 69, 2000, 12F, 5000, 0);
public static CreativeTabs carbonTools;
public static final Item carbonShovel = (new CarbonTubeItemSpade(carbonShov)).setMaxStackSize(1).setUnlocalizedName("carbonSpade").setTextureName("carbontubes:carbonShovel");
public static final Item carbonPickaxe = (new CarbonTubeItemPick(carbonPick)).setMaxStackSize(1).setUnlocalizedName("carbonPick").setTextureName("carbontubes:carbonPick");
public static final Item carbonAxe = (new CarbonTubeItemAxe(carbonA)).setMaxStackSize(1).setUnlocalizedName("carbonAxe").setTextureName("carbontubes:carbonAxe");
public static final Item carbonHoe = (new CarbonTubeItemHoe(carbonH)).setMaxStackSize(1).setUnlocalizedName("carbonHoe").setTextureName("carbontubes:carbonHoe");
public static final Item carbonSword = (new CarbonTubeItemSword(carbonSw)).setMaxStackSize(1).setUnlocalizedName("carbonSword").setTextureName("carbontubes:carbonSword");
public static final Item carbonITorch = (new CarbonTubeItemTorch()).setMaxStackSize(16).setUnlocalizedName("carbonTorch").setTextureName("carbontubes:carbonTorch");
public static final Block carbonTorch = (new CarbonTubeBlockTorch(Material.redstoneLight)).setBlockName("CarbonTorch").setLightLevel(100.0F).setBlockTextureName("carbontubes:carbonTorch");;

@EventHandler
public void preInit(FMLPreInitializationEvent event) {

}

    @EventHandler
    public void Init(FMLInitializationEvent event){
    	
    	registerGame();
    	registerEntity();
    	
    	carbonTools = new CreativeTabs("Carbon Tools")
    	{
    		public Item getTabIconItem()
    		{
    			return carbonShovel;
    		}
    	};
    	
    	carbonShovel.setCreativeTab(carbonTools);
    	carbonPickaxe.setCreativeTab(carbonTools);
    	carbonAxe.setCreativeTab(carbonTools);
    	carbonHoe.setCreativeTab(carbonTools);
    	carbonSword.setCreativeTab(carbonTools);
    	carbonITorch.setCreativeTab(carbonTools);
    	registerLanguage();
    	proxy.registerRenderThings();
    	proxy.registerSounds();
    	
    }
    
    public void registerLanguage() {
    	LanguageRegistry.addName(carbonShovel, "Carbon Shovel");
    	LanguageRegistry.addName(carbonPickaxe, "Carbon Pickaxe");
    	LanguageRegistry.addName(carbonAxe, "Carbon Axe");
    	LanguageRegistry.addName(carbonHoe, "Carbon Hoe");
    	LanguageRegistry.addName(carbonSword, "Carbon Sword");
    	LanguageRegistry.addName(carbonITorch, "Carbon Torch");
    	LanguageRegistry.addName(carbonTorch, "Carbon  Torch");
    	LanguageRegistry.instance().addStringLocalization("itemGroup.Carbon Tools", "en_US", "Carbon Tools");
    }
    
    public void registerGame() {
    	GameRegistry.registerItem(carbonShovel, "Carbon Shovel");
    	GameRegistry.registerItem(carbonPickaxe, "Carbon Pickaxe");
    	GameRegistry.registerItem(carbonAxe, "Carbon Axe");
    	GameRegistry.registerItem(carbonHoe, "Carbon Hoe");
    	GameRegistry.registerItem(carbonSword, "Carbon Sword");
    	GameRegistry.registerItem(carbonITorch, "Carbon Torch");
    	GameRegistry.registerBlock(carbonTorch, "Carbon  Torch");
    }
    
    public void registerEntity() {
    	EntityRegistry.registerModEntity(CarbonTorchEntity.class, "Carbon Torch", 4, this, 80, 3, true);
    }
    
}

 

Block Class:

import net.minecraft.block.Block;
import net.minecraft.block.BlockTorch;

import java.util.Random;

import javax.swing.Icon;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Blocks;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.IIcon;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;

public class CarbonTubeBlockTorch extends Block {

@SideOnly(Side.CLIENT)
protected IIcon blockIcon;

public CarbonTubeBlockTorch(Material p_i45394_1_) {
	super(p_i45394_1_);
}

public AxisAlignedBB getCollisionBoundingBoxFromPool(World p_149668_1_, int p_149668_2_, int p_149668_3_, int p_149668_4_)
    {
        return null;
    }

    public boolean isOpaqueCube()
    {
        return false;
    }

    public boolean renderAsNormalBlock()
    {
        return false;
    }

    /**
     * The type of render function that is called for this block
     */
    public int getRenderType()
    {
        return 1;
    }

    private boolean func_150107_m(World p_150107_1_, int p_150107_2_, int p_150107_3_, int p_150107_4_)
    {
        if (World.doesBlockHaveSolidTopSurface(p_150107_1_, p_150107_2_, p_150107_3_, p_150107_4_))
        {
            return true;
        }
        else
        {
            Block var5 = p_150107_1_.getBlock(p_150107_2_, p_150107_3_, p_150107_4_);
            return var5 == Blocks.fence || var5 == Blocks.nether_brick_fence || var5 == Blocks.glass || var5 == Blocks.cobblestone_wall;
        }
    }

    public boolean canPlaceBlockAt(World p_149742_1_, int p_149742_2_, int p_149742_3_, int p_149742_4_)
    {
        return p_149742_1_.isBlockNormalCubeDefault(p_149742_2_ - 1, p_149742_3_, p_149742_4_, true) ? true : (p_149742_1_.isBlockNormalCubeDefault(p_149742_2_ + 1, p_149742_3_, p_149742_4_, true) ? true : (p_149742_1_.isBlockNormalCubeDefault(p_149742_2_, p_149742_3_, p_149742_4_ - 1, true) ? true : (p_149742_1_.isBlockNormalCubeDefault(p_149742_2_, p_149742_3_, p_149742_4_ + 1, true) ? true : this.func_150107_m(p_149742_1_, p_149742_2_, p_149742_3_ - 1, p_149742_4_))));
    }

    public int onBlockPlaced(World p_149660_1_, int p_149660_2_, int p_149660_3_, int p_149660_4_, int p_149660_5_, float p_149660_6_, float p_149660_7_, float p_149660_8_, int p_149660_9_)
    {
        int var10 = p_149660_9_;

        if (p_149660_5_ == 1 && this.func_150107_m(p_149660_1_, p_149660_2_, p_149660_3_ - 1, p_149660_4_))
        {
            var10 = 5;
        }

        if (p_149660_5_ == 2 && p_149660_1_.isBlockNormalCubeDefault(p_149660_2_, p_149660_3_, p_149660_4_ + 1, true))
        {
            var10 = 4;
        }

        if (p_149660_5_ == 3 && p_149660_1_.isBlockNormalCubeDefault(p_149660_2_, p_149660_3_, p_149660_4_ - 1, true))
        {
            var10 = 3;
        }

        if (p_149660_5_ == 4 && p_149660_1_.isBlockNormalCubeDefault(p_149660_2_ + 1, p_149660_3_, p_149660_4_, true))
        {
            var10 = 2;
        }

        if (p_149660_5_ == 5 && p_149660_1_.isBlockNormalCubeDefault(p_149660_2_ - 1, p_149660_3_, p_149660_4_, true))
        {
            var10 = 1;
        }

        return var10;
    }

    /**
     * Ticks the block if it's been scheduled
     */
    public void updateTick(World p_149674_1_, int p_149674_2_, int p_149674_3_, int p_149674_4_, Random p_149674_5_)
    {
        super.updateTick(p_149674_1_, p_149674_2_, p_149674_3_, p_149674_4_, p_149674_5_);

        if (p_149674_1_.getBlockMetadata(p_149674_2_, p_149674_3_, p_149674_4_) == 0)
        {
            this.onBlockAdded(p_149674_1_, p_149674_2_, p_149674_3_, p_149674_4_);
        }
    }

    public void onBlockAdded(World p_149726_1_, int p_149726_2_, int p_149726_3_, int p_149726_4_)
    {
        if (p_149726_1_.getBlockMetadata(p_149726_2_, p_149726_3_, p_149726_4_) == 0)
        {
            if (p_149726_1_.isBlockNormalCubeDefault(p_149726_2_ - 1, p_149726_3_, p_149726_4_, true))
            {
                p_149726_1_.setBlockMetadataWithNotify(p_149726_2_, p_149726_3_, p_149726_4_, 1, 2);
            }
            else if (p_149726_1_.isBlockNormalCubeDefault(p_149726_2_ + 1, p_149726_3_, p_149726_4_, true))
            {
                p_149726_1_.setBlockMetadataWithNotify(p_149726_2_, p_149726_3_, p_149726_4_, 2, 2);
            }
            else if (p_149726_1_.isBlockNormalCubeDefault(p_149726_2_, p_149726_3_, p_149726_4_ - 1, true))
            {
                p_149726_1_.setBlockMetadataWithNotify(p_149726_2_, p_149726_3_, p_149726_4_, 3, 2);
            }
            else if (p_149726_1_.isBlockNormalCubeDefault(p_149726_2_, p_149726_3_, p_149726_4_ + 1, true))
            {
                p_149726_1_.setBlockMetadataWithNotify(p_149726_2_, p_149726_3_, p_149726_4_, 4, 2);
            }
            else if (this.func_150107_m(p_149726_1_, p_149726_2_, p_149726_3_ - 1, p_149726_4_))
            {
                p_149726_1_.setBlockMetadataWithNotify(p_149726_2_, p_149726_3_, p_149726_4_, 5, 2);
            }
        }

        this.func_150109_e(p_149726_1_, p_149726_2_, p_149726_3_, p_149726_4_);
    }

    public void onNeighborBlockChange(World p_149695_1_, int p_149695_2_, int p_149695_3_, int p_149695_4_, Block p_149695_5_)
    {
        this.func_150108_b(p_149695_1_, p_149695_2_, p_149695_3_, p_149695_4_, p_149695_5_);
    }

    protected boolean func_150108_b(World p_150108_1_, int p_150108_2_, int p_150108_3_, int p_150108_4_, Block p_150108_5_)
    {
        if (this.func_150109_e(p_150108_1_, p_150108_2_, p_150108_3_, p_150108_4_))
        {
            int var6 = p_150108_1_.getBlockMetadata(p_150108_2_, p_150108_3_, p_150108_4_);
            boolean var7 = false;

            if (!p_150108_1_.isBlockNormalCubeDefault(p_150108_2_ - 1, p_150108_3_, p_150108_4_, true) && var6 == 1)
            {
                var7 = true;
            }

            if (!p_150108_1_.isBlockNormalCubeDefault(p_150108_2_ + 1, p_150108_3_, p_150108_4_, true) && var6 == 2)
            {
                var7 = true;
            }

            if (!p_150108_1_.isBlockNormalCubeDefault(p_150108_2_, p_150108_3_, p_150108_4_ - 1, true) && var6 == 3)
            {
                var7 = true;
            }

            if (!p_150108_1_.isBlockNormalCubeDefault(p_150108_2_, p_150108_3_, p_150108_4_ + 1, true) && var6 == 4)
            {
                var7 = true;
            }

            if (!this.func_150107_m(p_150108_1_, p_150108_2_, p_150108_3_ - 1, p_150108_4_) && var6 == 5)
            {
                var7 = true;
            }

            if (var7)
            {
                this.dropBlockAsItem(p_150108_1_, p_150108_2_, p_150108_3_, p_150108_4_, p_150108_1_.getBlockMetadata(p_150108_2_, p_150108_3_, p_150108_4_), 0);
                p_150108_1_.setBlockToAir(p_150108_2_, p_150108_3_, p_150108_4_);
                return true;
            }
            else
            {
                return false;
            }
        }
        else
        {
            return true;
        }
    }

    protected boolean func_150109_e(World p_150109_1_, int p_150109_2_, int p_150109_3_, int p_150109_4_)
    {
        if (!this.canPlaceBlockAt(p_150109_1_, p_150109_2_, p_150109_3_, p_150109_4_))
        {
            if (p_150109_1_.getBlock(p_150109_2_, p_150109_3_, p_150109_4_) == this)
            {
                this.dropBlockAsItem(p_150109_1_, p_150109_2_, p_150109_3_, p_150109_4_, p_150109_1_.getBlockMetadata(p_150109_2_, p_150109_3_, p_150109_4_), 0);
                p_150109_1_.setBlockToAir(p_150109_2_, p_150109_3_, p_150109_4_);
            }

            return false;
        }
        else
        {
            return true;
        }
    }

    public MovingObjectPosition collisionRayTrace(World p_149731_1_, int p_149731_2_, int p_149731_3_, int p_149731_4_, Vec3 p_149731_5_, Vec3 p_149731_6_)
    {
        int var7 = p_149731_1_.getBlockMetadata(p_149731_2_, p_149731_3_, p_149731_4_) & 7;
        float var8 = 0.15F;

        if (var7 == 1)
        {
            this.setBlockBounds(0.0F, 0.2F, 0.5F - var8, var8 * 2.0F, 0.8F, 0.5F + var8);
        }
        else if (var7 == 2)
        {
            this.setBlockBounds(1.0F - var8 * 2.0F, 0.2F, 0.5F - var8, 1.0F, 0.8F, 0.5F + var8);
        }
        else if (var7 == 3)
        {
            this.setBlockBounds(0.5F - var8, 0.2F, 0.0F, 0.5F + var8, 0.8F, var8 * 2.0F);
        }
        else if (var7 == 4)
        {
            this.setBlockBounds(0.5F - var8, 0.2F, 1.0F - var8 * 2.0F, 0.5F + var8, 0.8F, 1.0F);
        }
        else
        {
            var8 = 0.1F;
            this.setBlockBounds(0.5F - var8, 0.0F, 0.5F - var8, 0.5F + var8, 0.6F, 0.5F + var8);
        }

        return super.collisionRayTrace(p_149731_1_, p_149731_2_, p_149731_3_, p_149731_4_, p_149731_5_, p_149731_6_);
    }

    /**
     * A randomly called display update to be able to add particles or other items for display
     */
    public void randomDisplayTick(World p_149734_1_, int p_149734_2_, int p_149734_3_, int p_149734_4_, Random p_149734_5_)
    {
        int var6 = p_149734_1_.getBlockMetadata(p_149734_2_, p_149734_3_, p_149734_4_);
        double var7 = (double)((float)p_149734_2_ + 0.5F);
        double var9 = (double)((float)p_149734_3_ + 0.7F);
        double var11 = (double)((float)p_149734_4_ + 0.5F);
        double var13 = 0.2199999988079071D;
        double var15 = 0.27000001072883606D;

        if (var6 == 1)
        {
            p_149734_1_.spawnParticle("smoke", var7 - var15, var9 + var13, var11, 0.0D, 0.0D, 0.0D);
            p_149734_1_.spawnParticle("flame", var7 - var15, var9 + var13, var11, 0.0D, 0.0D, 0.0D);
        }
        else if (var6 == 2)
        {
            p_149734_1_.spawnParticle("smoke", var7 + var15, var9 + var13, var11, 0.0D, 0.0D, 0.0D);
            p_149734_1_.spawnParticle("flame", var7 + var15, var9 + var13, var11, 0.0D, 0.0D, 0.0D);
        }
        else if (var6 == 3)
        {
            p_149734_1_.spawnParticle("smoke", var7, var9 + var13, var11 - var15, 0.0D, 0.0D, 0.0D);
            p_149734_1_.spawnParticle("flame", var7, var9 + var13, var11 - var15, 0.0D, 0.0D, 0.0D);
        }
        else if (var6 == 4)
        {
            p_149734_1_.spawnParticle("smoke", var7, var9 + var13, var11 + var15, 0.0D, 0.0D, 0.0D);
            p_149734_1_.spawnParticle("flame", var7, var9 + var13, var11 + var15, 0.0D, 0.0D, 0.0D);
        }
        else
        {
            p_149734_1_.spawnParticle("smoke", var7, var9, var11, 0.0D, 0.0D, 0.0D);
            p_149734_1_.spawnParticle("flame", var7, var9, var11, 0.0D, 0.0D, 0.0D);
        }
      
    }

}

 

The texture is in my : carbontubes/textures/blocks/carbonTorch.png

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.