Jump to content

Recommended Posts

Posted

Ok so I updated to the most recent version of forge for 1.5.1 and the whole texturing system is kind of new. Im making logs for my dimension trees, and in recent versions this kind of code would work fine:

package tutorial;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.util.Icon;

public class SLog extends Block{

public SLog(int par1, Material par2Material)
{
super(par1, par2Material);
}

private Icon sides,bottom,top;

public void registerIcon(IconRegister par1IconRegister)
{
this.sides = par1IconRegister.registerIcon("shinetree3");
this.bottom = par1IconRegister.registerIcon("shinetree2");
this.top = par1IconRegister.registerIcon("shinetree1");
}

public Icon getBlockTextureFromSideAndMetadata(int i, int j)
{
if (i == 0)
{
return bottom;
}
if (i == 1)
{
return top;
}
else
{
return sides;
}
}
}

 

In the newer version the code doesnt work like that, here is the VANILLA coded log class is like:

package net.minecraft.block;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.List;
import java.util.Random;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Icon;
import net.minecraft.world.World;

public class BlockLog extends Block
{
    /** The type of tree this log came from. */
    public static final String[] woodType = new String[] {"oak", "spruce", "birch", "jungle"};
    public static final String[] treeTextureTypes = new String[] {"tree_side", "tree_spruce", "tree_birch", "tree_jungle"};
    @SideOnly(Side.CLIENT)
    private Icon[] iconArray;
    @SideOnly(Side.CLIENT)
    private Icon tree_top;

    protected BlockLog(int par1)
    {
        super(par1, Material.wood);
        this.setCreativeTab(CreativeTabs.tabBlock);
    }

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

    /**
     * Returns the quantity of items to drop on block destruction.
     */
    public int quantityDropped(Random par1Random)
    {
        return 1;
    }

    /**
     * Returns the ID of the items to drop on destruction.
     */
    public int idDropped(int par1, Random par2Random, int par3)
    {
        return Block.wood.blockID;
    }

    /**
     * ejects contained items into the world, and notifies neighbours of an update, as appropriate
     */
    public void breakBlock(World par1World, int par2, int par3, int par4, int par5, int par6)
    {
        byte b0 = 4;
        int j1 = b0 + 1;

        if (par1World.checkChunksExist(par2 - j1, par3 - j1, par4 - j1, par2 + j1, par3 + j1, par4 + j1))
        {
            for (int k1 = -b0; k1 <= b0; ++k1)
            {
                for (int l1 = -b0; l1 <= b0; ++l1)
                {
                    for (int i2 = -b0; i2 <= b0; ++i2)
                    {
                        int j2 = par1World.getBlockId(par2 + k1, par3 + l1, par4 + i2);

                        if (Block.blocksList[j2] != null)
                        {
                            Block.blocksList[j2].beginLeavesDecay(par1World, par2 + k1, par3 + l1, par4 + i2);
                        }
                    }
                }
            }
        }
    }

    /**
     * Called when a block is placed using its ItemBlock. Args: World, X, Y, Z, side, hitX, hitY, hitZ, block metadata
     */
    public int onBlockPlaced(World par1World, int par2, int par3, int par4, int par5, float par6, float par7, float par8, int par9)
    {
        int j1 = par9 & 3;
        byte b0 = 0;

        switch (par5)
        {
            case 0:
            case 1:
                b0 = 0;
                break;
            case 2:
            case 3:
                b0 = 8;
                break;
            case 4:
            case 5:
                b0 = 4;
        }

        return j1 | b0;
    }

    @SideOnly(Side.CLIENT)

    /**
     * From the specified side and block metadata retrieves the blocks texture. Args: side, metadata
     */
    public Icon getIcon(int par1, int par2)
    {
        int k = par2 & 12;
        int l = par2 & 3;
        return k == 0 && (par1 == 1 || par1 == 0) ? this.tree_top : (k == 4 && (par1 == 5 || par1 == 4) ? this.tree_top : (k == 8 && (par1 == 2 || par1 == 3) ? this.tree_top : this.iconArray[l]));
    }

    /**
     * Determines the damage on the item the block drops. Used in cloth and wood.
     */
    public int damageDropped(int par1)
    {
        return par1 & 3;
    }

    /**
     * returns a number between 0 and 3
     */
    public static int limitToValidMetadata(int par0)
    {
        return par0 & 3;
    }

    @SideOnly(Side.CLIENT)

    /**
     * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
     */
    public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, List par3List)
    {
        par3List.add(new ItemStack(par1, 1, 0));
        par3List.add(new ItemStack(par1, 1, 1));
        par3List.add(new ItemStack(par1, 1, 2));
        par3List.add(new ItemStack(par1, 1, 3));
    }

    /**
     * Returns an item stack containing a single instance of the current block type. 'i' is the block's subtype/damage
     * and is ignored for blocks which do not support subtypes. Blocks which cannot be harvested should return null.
     */
    protected ItemStack createStackedBlock(int par1)
    {
        return new ItemStack(this.blockID, 1, limitToValidMetadata(par1));
    }

    @SideOnly(Side.CLIENT)

    /**
     * When this method is called, your block should register all the icons it needs with the given IconRegister. This
     * is the only chance you get to register icons.
     */
    public void registerIcons(IconRegister par1IconRegister)
    {
        this.tree_top = par1IconRegister.registerIcon("tree_top");
        this.iconArray = new Icon[treeTextureTypes.length];

        for (int i = 0; i < this.iconArray.length; ++i)
        {
            this.iconArray[i] = par1IconRegister.registerIcon(treeTextureTypes[i]);
        }
    }

    @Override
    public boolean canSustainLeaves(World world, int x, int y, int z)
    {
        return true;
    }

    @Override
    public boolean isWood(World world, int x, int y, int z)
    {
        return true;
    }
}

 

I tried editing this and adding in my stuff but it ended up being a failure, and my game crashed, or the texture wasent working. Ive looked everywhere on youtube and forms but no one seems to have the code for multi-textured blocks in the updated 1.5.1 forge and mcp versions. Hope you can help! Thanks!

Posted

Well lets think, if I wanted a log that would mean just the top and sides are different. But I also need a grass block, which means i need different top and bottom but all sides remain the same.

Posted

You need to alter the getIcon method. Mine acts to place a single texture facing the player when the block is placed and the texture of cobblestone on every other side. blockIcon is a variable in my parent class and faceIcon is a variable in my block's class.

 

  Reveal hidden contents

 

What you need to do is go through and replace all of my getIcon method with

        	if (side == 0)
        		return faceIcon;
        	return blockIcon;

And start the game and see what side your texture shows up on. Make a note of which side it is on your block so you can map out where everything is. Then run it again for side == 1, 2, 3, 4, and 5, then meta 0-3. meta, or the second parameter, is the direction a player is facing when the block is placed. I don't know what happens when the world generates it. Play around with that and you'll figure it out I'm sure.  :)

 

That answer your question? Just add more icons to have more textures on your block.

Read my thoughts on my summer mod work and tell me what you think!

http://www.minecraftforge.net/forum/index.php/topic,8396.0.html

 

I absolutely love her when she smiles

Posted

Yeah I think this should work. Also which meta is which side, and on the block what side is what? So like if side == 1, will that be the top bottom or some random side?!

 

Edit: I don't totally understand yet how to use textures and metadata for them. I wish I knew or if there was a tutorial out there on it. Also whenever I add code to the Icon getIcon method it says "unreachable code" even if I use all param's or not.

 

Posted
  On 5/11/2013 at 4:04 PM, vandy22 said:

Yeah I think this should work. Also which meta is which side, and on the block what side is what? So like if side == 1, will that be the top bottom or some random side?!

 

Edit: I don't totally understand yet how to use textures and metadata for them. I wish I knew or if there was a tutorial out there on it. Also whenever I add code to the Icon getIcon method it says "unreachable code" even if I use all param's or not.

 

getIcon is not a function defined in class Block.

 

You're looking for getBlockTextureFromSideAndMetadata

 

(Also, side 1 is the top.  0 is the bottom.  2 through 5 are the sides)

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

getIcon is definitely the method to use. I don't know which version of forge/minecraft you are using Draco, but in 1.5.1/1.5.2 getIcon is the method to use to put different textures on different sides.

 

vandy-Read carefully through your getIcon code (or post it so we can see). You are probably trying to add code after you have returned a value. If you look through your code and at any point it says "return ***" where *** is some icon, then if your code reaches that point it will never reach anything beyond that point.

So if you want to have multiple return possibilities, you need to put your return statements in conditionals, like an if statement.

return thisIcon;
//code that will never be reached
return thatIcon;

can never return thatIcon. However,

if (butts == true)
{
    return thisIcon;
}
return thatIcon;
//more code that will never be reached

if your boolean value butts is set to true, then thisIcon will be returned. If butts is set to false, then thatIcon will be returned.

Does this make sense?

Read my thoughts on my summer mod work and tell me what you think!

http://www.minecraftforge.net/forum/index.php/topic,8396.0.html

 

I absolutely love her when she smiles

Posted
  On 5/12/2013 at 12:59 AM, redria7 said:

getIcon is definitely the method to use. I don't know which version of forge/minecraft you are using Draco, but in 1.5.1/1.5.2 getIcon is the method to use to put different textures on different sides.

 

Uh.  1.5.1

I opened up my environment with Forge 639, there is no "getIcon" method.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

It is getIcon. My code (which works) to prove it:

@Override
public Icon getIcon(int s, int meta) {
	return this.icons[meta][s];
}

@Override
public void registerIcons(IconRegister par1IconRegister) {
	for (int i = 0; i < 6; i++)
		for (int j = 0; j < 4; j++)
			this.icons[j][i] = par1IconRegister.registerIcon("RotaryCraft:steel");
	icons[0][4] = par1IconRegister.registerIcon("RotaryCraft:borer_front");
	icons[1][5] = par1IconRegister.registerIcon("RotaryCraft:borer_front");
	icons[3][2] = par1IconRegister.registerIcon("RotaryCraft:borer_front");
	icons[2][3] = par1IconRegister.registerIcon("RotaryCraft:borer_front");

	icons[0][5] = par1IconRegister.registerIcon("RotaryCraft:borer_back");
	icons[1][4] = par1IconRegister.registerIcon("RotaryCraft:borer_back");
	icons[3][3] = par1IconRegister.registerIcon("RotaryCraft:borer_back");
	icons[2][2] = par1IconRegister.registerIcon("RotaryCraft:borer_back");
}

Posted

And you didn't indicate what version of Forge you're working with.

Because my code works too.

So clearly they renamed things, which plays havoc on our ability to support each other.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
  On 5/12/2013 at 2:51 AM, Draco18s said:

And you didn't indicate what version of Forge you're working with.

Because my code works too.

So clearly they renamed things, which plays havoc on our ability to support each other.

I am using the recommended build (or, at least as of a few days ago).

 

As for name changing, I agree - I HATE that. @Override helps, but it still means we have to go in and change names manually all the time...

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Add the crash-report or latest.log (logs-folder) with sites like https://mclo.gs/ and paste the link to it here  
    • I removed yetanotherchance booster and now it says Invalid player identity
    • Cracked Launchers are not supported
    • After some time minecraft crashes with an error. Here is the log https://drive.google.com/file/d/1o-2R6KZaC8sxjtLaw5qj0A-GkG_SuoB5/view?usp=sharing
    • The specific issue is that items in my inventory wont stack properly. For instance, if I punch a tree down to collect wood, the first block I collected goes to my hand. So when I punch the second block of wood to collect it, it drops, but instead of stacking with the piece of wood already in my hand, it goes to the second slot in my hotbar instead. Another example is that I'll get some dirt, and then when I'm placing it down later I'll accidentally place a block where I don't want it. When I harvest it again, it doesn't go back to the stack that it came from on my hotbar, where it should have gone, but rather into my inventory. That means that if my inventory is full, then the dirt wont be picked up even though there should be space available in the stack I'm holding. The forge version I'm using is 40.3.0, for java 1.18.2. I'll leave the mods I'm using here, and I'd appreciate it if anybody can point me in the right direction in regards to figuring out how to fix this. I forgot to mention that I think it only happens on my server but I&#39;m not entirely sure. PLEASE HELP ME! LIST OF THE MODS. aaa_particles Adorn AdvancementPlaques AI-Improvements AkashicTome alexsdelight alexsmobs AmbientSounds amwplushies Animalistic another_furniture AppleSkin Aquaculture aquamirae architectury artifacts Atlas-Lib AutoLeveling AutoRegLib auudio balm betterfpsdist biggerstacks biomancy BiomesOPlenty blockui blueprint Bookshelf born_in_chaos Botania braincell BrassAmberBattleTowers brutalbosses camera CasinoCraft cfm (MrCrayfish’s Furniture Mod) chat_heads citadel cloth-config Clumps CMDCam CNB cobweb collective comforts convenientcurioscontainer cookingforblockheads coroutil CosmeticArmorReworked CozyHome CrabbersDelight crashexploitfixer crashutilities Create CreativeCore creeperoverhaul cristellib crittersandcompanions Croptopia CroptopiaAdditions CullLessLeaves curios curiouslanterns curiouslights Curses' Naturals CustomNPCs CyclopsCore dannys_expansion decocraft Decoration Mod DecorationDelightRefurbished Decorative Blocks Disenchanting DistantHorizons doubledoors DramaticDoors drippyloadingscreen durabilitytooltip dynamic-fps dynamiclights DynamicTrees DynamicTreesBOP DynamicTreesPlus Easy Dungeons EasyAnvils EasyMagic easy_npc eatinganimation ecologics effective_fg elevatorid embeddium emotecraft enchantlimiter EnchantmentDescriptions EnderMail engineersdecor entityculling entity_model_features entity_texture_features epicfight EvilCraft exlinefurniture expandability explosiveenhancement factory-blocks fairylights fancymenu FancyVideo FarmersDelight fast-ip-ping FastSuite ferritecore finsandtails FixMySpawnR Forge Middle Ages fossil FpsReducer2 furnish GamingDeco geckolib goblintraders goldenfood goodall H.e.b habitat harvest-with-ease hexerei hole_filler huge-structure-blocks HunterIllager iammusicplayer Iceberg illuminations immersive_paintings incubation infinitybuttons inventoryhud InventoryProfilesNext invocore ItemBorders itemzoom Jade jei (Just Enough Items) JetAndEliasArmors journeymap JRFTL justzoom kiwiboi Kobolds konkrete kotlinforforge lazydfu LegendaryTooltips libIPN lightspeed lmft lodestone LongNbtKiller LuckPerms Lucky77 MagmaMonsters malum ManyIdeasCore ManyIdeasDoors marbledsarsenal marg mcw-furniture mcw-lights mcw-paths mcw-stairs mcw-trapdoors mcw-windows meetyourfight melody memoryleakfix Mimic minecraft-comes-alive MineTraps minibosses MmmMmmMmmMmm MOAdecor (ART, BATH, COOKERY, GARDEN, HOLIDAYS, LIGHTS, SCIENCE) MobCatcher modonomicon mods_optimizer morehitboxes mowziesmobs MutantMonsters mysticalworld naturalist NaturesAura neapolitan NekosEnchantedBooks neoncraft2 nerb nifty NightConfigFixes nightlights nocube's_villagers_sell_animals NoSeeNoTick notenoughanimations obscure_api oculus oresabovediamonds otyacraftengine Paraglider Patchouli physics-mod Pillagers Gun PizzaCraft placeableitems Placebo player-animation-lib pneumaticcraft-repressurized polymorph PrettyPipes Prism projectbrazier Psychadelic-Chemistry PuzzlesLib realmrpg_imps_and_demons RecipesLibrary reeves-furniture RegionsUnexplored restrictedportals revive-me Scary_Mobs_And_Bosses selene shetiphiancore ShoulderSurfing smoothboot
  • Topics

×
×
  • Create New...

Important Information

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